Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 4 additions & 0 deletions ChangeLog.d/test-suites-heap.txt
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
Changes
* Running the unit tests now requires a heap (possibly from
MBEDTLS_MEMORY_BUFFER_ALLOC_C). They now use less stack (almost
5000 bytes less).
2 changes: 1 addition & 1 deletion framework
Submodule framework updated 37 files
+3 −3 psasim/src/aut_psa_key_agreement.c
+0 −9 scripts/assemble_changelog.py
+6 −1 scripts/check-python-files.sh
+8 −0 scripts/check_names.py
+1 −1 scripts/generate_test_code.py
+5 −208 scripts/generate_tls_handshake_tests.py
+6 −162 scripts/make_generated_files.py
+13 −3 scripts/mbedtls_framework/c_wrapper_generator.py
+22 −2 scripts/mbedtls_framework/config_macros.py
+182 −0 scripts/mbedtls_framework/generate_files_helper.py
+167 −0 scripts/mbedtls_framework/generated_files.py
+13 −7 scripts/mbedtls_framework/test_case.py
+30 −5 scripts/mbedtls_framework/test_data_generation.py
+228 −0 scripts/mbedtls_framework/tls_handshake_tests.py
+1 −1 tests/include/test/arguments.h
+1 −0 tests/include/test/asn1_helpers.h
+2 −0 tests/include/test/bignum_codepath_check.h
+1 −1 tests/include/test/bignum_helpers.h
+1 −1 tests/include/test/constant_flow.h
+1 −1 tests/include/test/fake_external_rng_for_test.h
+14 −6 tests/include/test/helpers.h
+16 −1 tests/include/test/macros.h
+2 −1 tests/include/test/memory.h
+2 −0 tests/include/test/pk_helpers.h
+1 −0 tests/include/test/psa_crypto_helpers.h
+1 −0 tests/include/test/psa_exercise_key.h
+2 −0 tests/include/test/psa_helpers.h
+2 −0 tests/include/test/psa_memory_poisoning_wrappers.h
+1 −1 tests/include/test/random.h
+34 −0 tests/include/test/test_common.h
+1 −7 tests/include/test/threading_helpers.h
+12 −10 tests/programs/metatest.c
+26 −0 tests/src/helpers.c
+1 −1 tests/src/pk_helpers.c
+206 −0 util/generate_mldsa_tests.py
+5 −0 util/requirements.txt
+18 −0 util/scripts_path.py
6 changes: 6 additions & 0 deletions scripts/ci.requirements.txt
Original file line number Diff line number Diff line change
Expand Up @@ -26,3 +26,9 @@ cryptography >= 35.0.0; platform_system == 'Linux'
# For building `framework/data_files/server9-bad-saltlen.crt` and check python
# files.
asn1crypto; platform_system == 'Linux'

# More requirements for scripts in the framework that might not work in
# older versions of Python. Note that requirements that are not available
# in the oldest version of Python on our CI must be annodated with
# "python >= ...".
-r ../framework/util/requirements.txt
21 changes: 21 additions & 0 deletions tests/scripts/check_committed_generated_files.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,21 @@
#!/usr/bin/env python3

"""
Check that TF-PSA-Crypto files that can be regenerated are up-to-date, or update them.
"""

# Copyright The Mbed TLS Contributors
# SPDX-License-Identifier: Apache-2.0 OR GPL-2.0-or-later

import scripts_path # pylint: disable=unused-import
from mbedtls_framework import config_macros
from mbedtls_framework import generate_files_helper

GENERATORS = [
config_macros.Current(shadow_missing_ok=True),
generate_files_helper.TestDataGenerator('framework/util/generate_mldsa_tests.py'),
]

if __name__ == '__main__':
generate_files_helper.main(generators=GENERATORS,
description=__doc__)
46 changes: 0 additions & 46 deletions tests/scripts/check_option_lists.py

This file was deleted.

13 changes: 12 additions & 1 deletion tests/scripts/components-basic-checks.sh
Original file line number Diff line number Diff line change
Expand Up @@ -39,9 +39,20 @@ component_tf_psa_crypto_check_generated_files () {

cd $TF_PSA_CRYPTO_ROOT_DIR
$FRAMEWORK/scripts/make_generated_files.py --root $OUT_OF_SOURCE_DIR --check
}

support_tf_psa_crypto_check_committed_generated_files () {
# check_committed_generated_files.py runs generate_mldsa_tests.py,
# which requires dilithium-py, which requires Python >=3.9.
# Check the Python version, not the presence of the package,
# because the CI runs `all.sh --list-components` outside of the
# venv that has our desired packages.
python3 -c 'import sys; exit(1 if sys.version_info < (3, 9) else 0)'
}

component_tf_psa_crypto_check_committed_generated_files () {
msg "Check committed generated files"
tests/scripts/check_option_lists.py
tests/scripts/check_committed_generated_files.py
}

component_tf_psa_crypto_check_recursion () {
Expand Down
133 changes: 83 additions & 50 deletions tests/suites/host_test.function
Original file line number Diff line number Diff line change
@@ -1,12 +1,5 @@
#line 2 "suites/host_test.function"

/* Buffer size used to read one line from a .datax file. */
#if defined(TF_PSA_CRYPTO_PQCP_MLDSA_ENABLED)
#define MBEDTLS_TEST_DATAX_MAX_LINE_LENGTH 22000
#else
#define MBEDTLS_TEST_DATAX_MAX_LINE_LENGTH 5000
#endif

/**
* \brief Verifies that string is in string parameter format i.e. "<str>"
* It also strips enclosing '"' from the input string.
Expand Down Expand Up @@ -78,54 +71,81 @@ static int verify_int(char *str, intmax_t *p_value)
"TESTCASE_FILENAME"


/** A variable-size text buffer. */
typedef struct {
/** Null-terminated string, or NULL if not allocated. */
char *content;
/** Number of allocated bytes. \c 0 if not allocated. */
size_t size;
} string_buffer_t;

/**
* \brief Read a line from the passed file pointer.
* \brief Read a line from the passed file pointer.
* Empty lines and comments are skipped.
*
* \param f FILE pointer
* \param buf Pointer to memory to hold read line.
* \param len Length of the buf.
* \param f FILE pointer
* \param buffer Buffer for the line content.
* It is filled with a null-terminated string.
*
* \return 0 if success else -1
* \return The number of bytes of the resulting line, not
* including the terminating null byte.
* On end of file, (size_t) -1.
*/
static int get_line(FILE *f, char *buf, size_t len)
static size_t get_line(FILE *f, string_buffer_t *buffer)
{
char *ret;
int i = 0, str_len = 0, has_string = 0;
char *ret = NULL;
size_t offset = 0;
size_t length = 0;
int have_full_line = 0;

/* Read until we get a valid line */
do {
ret = fgets(buf, len, f);
ret = fgets(buffer->content + offset, buffer->size - offset, f);
if (ret == NULL) {
return -1;
return (size_t) -1;
}
length = offset + strlen(buffer->content + offset);

if (length == buffer->size - 1 && buffer->content[length - 1] != '\n') {
/* Unfinished line. Enlarge the buffer. */
/* We don't use realloc() because it may not be available
* (e.g. MBEDTLS_MEMORY_BUFFER_ALLOC_C doesn't provide it). */
size_t new_size = buffer->size * 2;
char *new_buffer = mbedtls_calloc(1, new_size);
if (new_buffer == NULL) {
fprintf(stderr, "FATAL: failed to allocate %zu bytes\n", new_size);
mbedtls_exit(MBEDTLS_EXIT_FAILURE);
}
memcpy(new_buffer, buffer->content, length);
mbedtls_free(buffer->content);
buffer->content = new_buffer;
buffer->size = new_size;
offset = length;
continue;
}

str_len = strlen(buf);
/* Now we have a full line. */
offset = 0;
Comment thread
mpg marked this conversation as resolved.

/* Skip empty line and comment */
if (str_len == 0 || buf[0] == '#') {
/* Strip new line and carriage return. */
while (length > 0 && (buffer->content[length - 1] == '\n' ||
buffer->content[length - 1] == '\r')) {
--length;
buffer->content[length] = 0;
}

if (length == 0) {
/* Skip empty line */
continue;
}
has_string = 0;
for (i = 0; i < str_len; i++) {
char c = buf[i];
if (c != ' ' && c != '\t' && c != '\n' &&
Comment thread
mpg marked this conversation as resolved.
c != '\v' && c != '\f' && c != '\r') {
has_string = 1;
break;
}
if (buffer->content[0] == '#') {
/* Skip comment line */
continue;
}
} while (!has_string);

/* Strip new line and carriage return */
ret = buf + strlen(buf);
if (ret-- > buf && *ret == '\n') {
*ret = '\0';
}
if (ret-- > buf && *ret == '\r') {
*ret = '\0';
}
have_full_line = 1;
} while (!have_full_line);

return 0;
return length;
}

/**
Expand Down Expand Up @@ -506,10 +526,9 @@ static int execute_tests(int argc, const char **argv)
int arg_index = 1;
const char *next_arg;
size_t testfile_index, i, cnt;
int ret;
unsigned total_errors = 0, total_tests = 0, total_skipped = 0;
FILE *file;
char buf[MBEDTLS_TEST_DATAX_MAX_LINE_LENGTH];
string_buffer_t line = { NULL, 0 };
char *params[50];
/* Store for processed integer params. */
mbedtls_test_argument_t int_params[50];
Expand Down Expand Up @@ -556,6 +575,13 @@ static int execute_tests(int argc, const char **argv)
}
}

line.size = 256;
line.content = mbedtls_calloc(1, line.size);
if (line.content == NULL) {
fprintf(stderr, "FATAL: failed to allocate %zu bytes\n", line.size);
mbedtls_exit(MBEDTLS_EXIT_FAILURE);
}

while (arg_index < argc) {
next_arg = argv[arg_index];

Expand Down Expand Up @@ -616,26 +642,28 @@ static int execute_tests(int argc, const char **argv)
unmet_dep_count = 0;
missing_unmet_dependencies = 0;

if ((ret = get_line(file, buf, sizeof(buf))) != 0) {
size_t length = get_line(file, &line);
if (length == (size_t) -1) {
break;
}
mbedtls_fprintf(stdout, "%s%.66s",
mbedtls_test_get_result() == MBEDTLS_TEST_RESULT_FAILED ?
"\n" : "", buf);
"\n" : "", line.content);
mbedtls_fprintf(stdout, " ");
for (i = strlen(buf) + 1; i < 67; i++) {
for (i = length + 1; i < 67; i++) {
mbedtls_fprintf(stdout, ".");
}
mbedtls_fprintf(stdout, " ");
fflush(stdout);
write_outcome_entry(outcome_file, argv[0], buf);
write_outcome_entry(outcome_file, argv[0], line.content);

total_tests++;

if ((ret = get_line(file, buf, sizeof(buf))) != 0) {
length = get_line(file, &line);
if (length == (size_t) -1) {
break;
}
cnt = parse_arguments(buf, strlen(buf), params,
cnt = parse_arguments(line.content, length, params,
sizeof(params) / sizeof(params[0]));

if (strcmp(params[0], "depends_on") == 0) {
Expand All @@ -652,14 +680,16 @@ static int execute_tests(int argc, const char **argv)
}
}

if ((ret = get_line(file, buf, sizeof(buf))) != 0) {
length = get_line(file, &line);
if (length == (size_t) -1) {
break;
}
cnt = parse_arguments(buf, strlen(buf), params,
cnt = parse_arguments(line.content, length, params,
sizeof(params) / sizeof(params[0]));
}

// If there are no unmet dependencies execute the test
int ret = DISPATCH_TEST_SUCCESS; /*also covers test case skip*/
if (unmet_dep_count == 0) {
mbedtls_test_info_reset();

Expand All @@ -677,7 +707,8 @@ static int execute_tests(int argc, const char **argv)
#endif /* __unix__ || __APPLE__ __MACH__ */

function_id = strtoul(params[0], NULL, 10);
if ((ret = check_test(function_id)) == DISPATCH_TEST_SUCCESS) {
ret = check_test(function_id);
if (ret == DISPATCH_TEST_SUCCESS) {
ret = convert_params(cnt - 1, params + 1, int_params);
if (DISPATCH_TEST_SUCCESS == ret) {
ret = dispatch_test(function_id, (void **) (params + 1));
Expand Down Expand Up @@ -785,6 +816,8 @@ static int execute_tests(int argc, const char **argv)
mbedtls_test_mutex_usage_end();
#endif

mbedtls_free(line.content);

#if defined(MBEDTLS_MEMORY_BUFFER_ALLOC_C) && \
!defined(TEST_SUITE_MEMORY_BUFFER_ALLOC)
#if defined(MBEDTLS_MEMORY_DEBUG)
Expand Down
Loading