2017-07-19 11:15:54 +02:00
|
|
|
#line 2 "suites/host_test.function"
|
2017-03-28 02:48:31 +02:00
|
|
|
|
|
|
|
/**
|
2018-07-05 00:29:46 +02:00
|
|
|
* \brief Verifies that string is in string parameter format i.e. "<str>"
|
2017-03-28 02:48:31 +02:00
|
|
|
* It also strips enclosing '"' from the input string.
|
|
|
|
*
|
|
|
|
* \param str String parameter.
|
|
|
|
*
|
|
|
|
* \return 0 if success else 1
|
|
|
|
*/
|
2023-01-11 14:50:10 +01:00
|
|
|
int verify_string(char **str)
|
2017-03-28 02:48:31 +02:00
|
|
|
{
|
2023-01-11 14:50:10 +01:00
|
|
|
if ((*str)[0] != '"' ||
|
|
|
|
(*str)[strlen(*str) - 1] != '"') {
|
|
|
|
mbedtls_fprintf(stderr,
|
|
|
|
"Expected string (with \"\") for parameter and got: %s\n", *str);
|
|
|
|
return -1;
|
2017-03-28 02:48:31 +02:00
|
|
|
}
|
|
|
|
|
2023-01-11 14:50:10 +01:00
|
|
|
(*str)++;
|
|
|
|
(*str)[strlen(*str) - 1] = '\0';
|
2017-03-28 02:48:31 +02:00
|
|
|
|
2023-01-11 14:50:10 +01:00
|
|
|
return 0;
|
2017-03-28 02:48:31 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
2018-07-05 00:29:46 +02:00
|
|
|
* \brief Verifies that string is an integer. Also gives the converted
|
2017-03-28 02:48:31 +02:00
|
|
|
* integer value.
|
|
|
|
*
|
|
|
|
* \param str Input string.
|
2022-12-04 13:10:55 +01:00
|
|
|
* \param p_value Pointer to output value.
|
2017-03-28 02:48:31 +02:00
|
|
|
*
|
|
|
|
* \return 0 if success else 1
|
|
|
|
*/
|
2022-12-04 15:32:54 +01:00
|
|
|
int verify_int(char *str, intmax_t *p_value)
|
2017-03-28 02:48:31 +02:00
|
|
|
{
|
Simplify parsing of integers in .datax files
In the .datax parser, since we're calling strtol() anyway, rely on it for
verification. This makes the .datax parser very slightly more
liberal (leading spaces and '+' are now accepted), and changes the
interpretation of numbers with leading zeros to octal.
Before, an argument like :0123: was parsed as decimal, but an argument like
:0123+1: was parsed as a C expression and hence the leading zero marked an
octal representation. Now, a leading zero is always interpreted according to
C syntax, namely indicating octal. There are no nonzero integer constants
with a leading zero in a .data file, so this does not affect existing test
cases.
In the .datax generator, allow negative arguments to be 'int' (before, they
were systematically treated as 'exp' even though they didn't need to be).
In the .datax parser, validate the range of integer constants. They have to
fit in int32_t. In the .datax generator, use 'exp' instead of 'int' for
integer constants that are out of range.
Signed-off-by: Gilles Peskine <Gilles.Peskine@arm.com>
2022-12-04 00:28:56 +01:00
|
|
|
char *end = NULL;
|
|
|
|
errno = 0;
|
2022-12-04 15:32:54 +01:00
|
|
|
/* Limit the range to long: for large integers, the test framework will
|
|
|
|
* use expressions anyway. */
|
Simplify parsing of integers in .datax files
In the .datax parser, since we're calling strtol() anyway, rely on it for
verification. This makes the .datax parser very slightly more
liberal (leading spaces and '+' are now accepted), and changes the
interpretation of numbers with leading zeros to octal.
Before, an argument like :0123: was parsed as decimal, but an argument like
:0123+1: was parsed as a C expression and hence the leading zero marked an
octal representation. Now, a leading zero is always interpreted according to
C syntax, namely indicating octal. There are no nonzero integer constants
with a leading zero in a .data file, so this does not affect existing test
cases.
In the .datax generator, allow negative arguments to be 'int' (before, they
were systematically treated as 'exp' even though they didn't need to be).
In the .datax parser, validate the range of integer constants. They have to
fit in int32_t. In the .datax generator, use 'exp' instead of 'int' for
integer constants that are out of range.
Signed-off-by: Gilles Peskine <Gilles.Peskine@arm.com>
2022-12-04 00:28:56 +01:00
|
|
|
long value = strtol(str, &end, 0);
|
|
|
|
if (errno == EINVAL || *end != '\0') {
|
|
|
|
mbedtls_fprintf(stderr,
|
|
|
|
"Expected integer for parameter and got: %s\n", str);
|
|
|
|
return KEY_VALUE_MAPPING_NOT_FOUND;
|
2017-03-28 02:48:31 +02:00
|
|
|
}
|
2022-12-04 15:32:54 +01:00
|
|
|
if (errno == ERANGE) {
|
Simplify parsing of integers in .datax files
In the .datax parser, since we're calling strtol() anyway, rely on it for
verification. This makes the .datax parser very slightly more
liberal (leading spaces and '+' are now accepted), and changes the
interpretation of numbers with leading zeros to octal.
Before, an argument like :0123: was parsed as decimal, but an argument like
:0123+1: was parsed as a C expression and hence the leading zero marked an
octal representation. Now, a leading zero is always interpreted according to
C syntax, namely indicating octal. There are no nonzero integer constants
with a leading zero in a .data file, so this does not affect existing test
cases.
In the .datax generator, allow negative arguments to be 'int' (before, they
were systematically treated as 'exp' even though they didn't need to be).
In the .datax parser, validate the range of integer constants. They have to
fit in int32_t. In the .datax generator, use 'exp' instead of 'int' for
integer constants that are out of range.
Signed-off-by: Gilles Peskine <Gilles.Peskine@arm.com>
2022-12-04 00:28:56 +01:00
|
|
|
mbedtls_fprintf(stderr, "Integer out of range: %s\n", str);
|
|
|
|
return KEY_VALUE_MAPPING_NOT_FOUND;
|
2017-03-28 02:48:31 +02:00
|
|
|
}
|
Simplify parsing of integers in .datax files
In the .datax parser, since we're calling strtol() anyway, rely on it for
verification. This makes the .datax parser very slightly more
liberal (leading spaces and '+' are now accepted), and changes the
interpretation of numbers with leading zeros to octal.
Before, an argument like :0123: was parsed as decimal, but an argument like
:0123+1: was parsed as a C expression and hence the leading zero marked an
octal representation. Now, a leading zero is always interpreted according to
C syntax, namely indicating octal. There are no nonzero integer constants
with a leading zero in a .data file, so this does not affect existing test
cases.
In the .datax generator, allow negative arguments to be 'int' (before, they
were systematically treated as 'exp' even though they didn't need to be).
In the .datax parser, validate the range of integer constants. They have to
fit in int32_t. In the .datax generator, use 'exp' instead of 'int' for
integer constants that are out of range.
Signed-off-by: Gilles Peskine <Gilles.Peskine@arm.com>
2022-12-04 00:28:56 +01:00
|
|
|
*p_value = value;
|
|
|
|
return 0;
|
2017-03-28 02:48:31 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
/**
|
|
|
|
* \brief Usage string.
|
|
|
|
*
|
|
|
|
*/
|
|
|
|
#define USAGE \
|
|
|
|
"Usage: %s [OPTIONS] files...\n\n" \
|
|
|
|
" Command line arguments:\n" \
|
2018-07-18 18:48:37 +02:00
|
|
|
" files... One or more test data files. If no file is\n" \
|
|
|
|
" specified the following default test case\n" \
|
|
|
|
" file is used:\n" \
|
2017-03-28 02:48:31 +02:00
|
|
|
" %s\n\n" \
|
|
|
|
" Options:\n" \
|
|
|
|
" -v | --verbose Display full information about each test\n" \
|
|
|
|
" -h | --help Display this information\n\n", \
|
|
|
|
argv[0], \
|
|
|
|
"TESTCASE_FILENAME"
|
|
|
|
|
|
|
|
|
|
|
|
/**
|
|
|
|
* \brief Read a line from the passed file pointer.
|
|
|
|
*
|
|
|
|
* \param f FILE pointer
|
|
|
|
* \param buf Pointer to memory to hold read line.
|
|
|
|
* \param len Length of the buf.
|
|
|
|
*
|
|
|
|
* \return 0 if success else -1
|
|
|
|
*/
|
2023-01-11 14:50:10 +01:00
|
|
|
int get_line(FILE *f, char *buf, size_t len)
|
2017-03-28 02:48:31 +02:00
|
|
|
{
|
|
|
|
char *ret;
|
|
|
|
int i = 0, str_len = 0, has_string = 0;
|
|
|
|
|
|
|
|
/* Read until we get a valid line */
|
2023-01-11 14:50:10 +01:00
|
|
|
do {
|
|
|
|
ret = fgets(buf, len, f);
|
|
|
|
if (ret == NULL) {
|
|
|
|
return -1;
|
|
|
|
}
|
2017-03-28 02:48:31 +02:00
|
|
|
|
2023-01-11 14:50:10 +01:00
|
|
|
str_len = strlen(buf);
|
2017-03-28 02:48:31 +02:00
|
|
|
|
|
|
|
/* Skip empty line and comment */
|
2023-01-11 14:50:10 +01:00
|
|
|
if (str_len == 0 || buf[0] == '#') {
|
2017-03-28 02:48:31 +02:00
|
|
|
continue;
|
2023-01-11 14:50:10 +01:00
|
|
|
}
|
2017-03-28 02:48:31 +02:00
|
|
|
has_string = 0;
|
2023-01-11 14:50:10 +01:00
|
|
|
for (i = 0; i < str_len; i++) {
|
2017-03-28 02:48:31 +02:00
|
|
|
char c = buf[i];
|
2023-01-11 14:50:10 +01:00
|
|
|
if (c != ' ' && c != '\t' && c != '\n' &&
|
|
|
|
c != '\v' && c != '\f' && c != '\r') {
|
2017-03-28 02:48:31 +02:00
|
|
|
has_string = 1;
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
}
|
2023-01-11 14:50:10 +01:00
|
|
|
} while (!has_string);
|
2017-03-28 02:48:31 +02:00
|
|
|
|
|
|
|
/* Strip new line and carriage return */
|
2023-01-11 14:50:10 +01:00
|
|
|
ret = buf + strlen(buf);
|
|
|
|
if (ret-- > buf && *ret == '\n') {
|
2017-03-28 02:48:31 +02:00
|
|
|
*ret = '\0';
|
2023-01-11 14:50:10 +01:00
|
|
|
}
|
|
|
|
if (ret-- > buf && *ret == '\r') {
|
2017-03-28 02:48:31 +02:00
|
|
|
*ret = '\0';
|
2023-01-11 14:50:10 +01:00
|
|
|
}
|
2017-03-28 02:48:31 +02:00
|
|
|
|
2023-01-11 14:50:10 +01:00
|
|
|
return 0;
|
2017-03-28 02:48:31 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
* \brief Splits string delimited by ':'. Ignores '\:'.
|
|
|
|
*
|
|
|
|
* \param buf Input string
|
|
|
|
* \param len Input string length
|
|
|
|
* \param params Out params found
|
|
|
|
* \param params_len Out params array len
|
|
|
|
*
|
|
|
|
* \return Count of strings found.
|
|
|
|
*/
|
2023-01-11 14:50:10 +01:00
|
|
|
static int parse_arguments(char *buf, size_t len, char **params,
|
|
|
|
size_t params_len)
|
2017-03-28 02:48:31 +02:00
|
|
|
{
|
|
|
|
size_t cnt = 0, i;
|
|
|
|
char *cur = buf;
|
|
|
|
char *p = buf, *q;
|
|
|
|
|
|
|
|
params[cnt++] = cur;
|
|
|
|
|
2023-01-11 14:50:10 +01:00
|
|
|
while (*p != '\0' && p < (buf + len)) {
|
|
|
|
if (*p == '\\') {
|
2017-03-28 02:48:31 +02:00
|
|
|
p++;
|
|
|
|
p++;
|
|
|
|
continue;
|
|
|
|
}
|
2023-01-11 14:50:10 +01:00
|
|
|
if (*p == ':') {
|
|
|
|
if (p + 1 < buf + len) {
|
2017-03-28 02:48:31 +02:00
|
|
|
cur = p + 1;
|
2023-01-11 14:50:10 +01:00
|
|
|
TEST_HELPER_ASSERT(cnt < params_len);
|
2017-03-28 02:48:31 +02:00
|
|
|
params[cnt++] = cur;
|
|
|
|
}
|
|
|
|
*p = '\0';
|
|
|
|
}
|
|
|
|
|
|
|
|
p++;
|
|
|
|
}
|
|
|
|
|
2022-12-03 23:48:25 +01:00
|
|
|
/* Replace backslash escapes in strings */
|
2023-01-11 14:50:10 +01:00
|
|
|
for (i = 0; i < cnt; i++) {
|
2017-03-28 02:48:31 +02:00
|
|
|
p = params[i];
|
|
|
|
q = params[i];
|
|
|
|
|
2023-01-11 14:50:10 +01:00
|
|
|
while (*p != '\0') {
|
2022-12-03 23:48:25 +01:00
|
|
|
if (*p == '\\') {
|
|
|
|
++p;
|
|
|
|
switch (*p) {
|
|
|
|
case 'n':
|
|
|
|
*p = '\n';
|
|
|
|
break;
|
|
|
|
default:
|
|
|
|
// Fall through to copying *p
|
|
|
|
break;
|
|
|
|
}
|
2017-03-28 02:48:31 +02:00
|
|
|
}
|
2022-12-03 23:48:25 +01:00
|
|
|
*(q++) = *(p++);
|
2017-03-28 02:48:31 +02:00
|
|
|
}
|
|
|
|
*q = '\0';
|
|
|
|
}
|
|
|
|
|
2023-01-11 14:50:10 +01:00
|
|
|
return cnt;
|
2017-03-28 02:48:31 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
* \brief Converts parameters into test function consumable parameters.
|
|
|
|
* Example: Input: {"int", "0", "char*", "Hello",
|
|
|
|
* "hex", "abef", "exp", "1"}
|
|
|
|
* Output: {
|
|
|
|
* 0, // Verified int
|
|
|
|
* "Hello", // Verified string
|
|
|
|
* 2, { 0xab, 0xef },// Converted len,hex pair
|
|
|
|
* 9600 // Evaluated expression
|
|
|
|
* }
|
|
|
|
*
|
|
|
|
*
|
2018-07-18 18:48:37 +02:00
|
|
|
* \param cnt Parameter array count.
|
|
|
|
* \param params Out array of found parameters.
|
2017-03-28 02:48:31 +02:00
|
|
|
* \param int_params_store Memory for storing processed integer parameters.
|
|
|
|
*
|
|
|
|
* \return 0 for success else 1
|
|
|
|
*/
|
2022-12-04 13:10:55 +01:00
|
|
|
static int convert_params(size_t cnt, char **params,
|
|
|
|
mbedtls_test_argument_t *int_params_store)
|
2017-03-28 02:48:31 +02:00
|
|
|
{
|
2023-01-11 14:50:10 +01:00
|
|
|
char **cur = params;
|
|
|
|
char **out = params;
|
2018-07-18 18:48:37 +02:00
|
|
|
int ret = DISPATCH_TEST_SUCCESS;
|
2017-03-28 02:48:31 +02:00
|
|
|
|
2023-01-11 14:50:10 +01:00
|
|
|
while (cur < params + cnt) {
|
|
|
|
char *type = *cur++;
|
|
|
|
char *val = *cur++;
|
2017-03-28 02:48:31 +02:00
|
|
|
|
2023-01-11 14:50:10 +01:00
|
|
|
if (strcmp(type, "char*") == 0) {
|
|
|
|
if (verify_string(&val) == 0) {
|
|
|
|
*out++ = val;
|
|
|
|
} else {
|
|
|
|
ret = (DISPATCH_INVALID_TEST_DATA);
|
2017-03-28 02:48:31 +02:00
|
|
|
break;
|
|
|
|
}
|
2023-01-11 14:50:10 +01:00
|
|
|
} else if (strcmp(type, "int") == 0) {
|
2022-12-04 15:32:54 +01:00
|
|
|
if (verify_int(val, &int_params_store->sint) == 0) {
|
2023-01-11 14:50:10 +01:00
|
|
|
*out++ = (char *) int_params_store++;
|
|
|
|
} else {
|
|
|
|
ret = (DISPATCH_INVALID_TEST_DATA);
|
2017-03-28 02:48:31 +02:00
|
|
|
break;
|
|
|
|
}
|
2023-01-11 14:50:10 +01:00
|
|
|
} else if (strcmp(type, "hex") == 0) {
|
|
|
|
if (verify_string(&val) == 0) {
|
2020-06-18 10:10:46 +02:00
|
|
|
size_t len;
|
|
|
|
|
|
|
|
TEST_HELPER_ASSERT(
|
2023-01-11 14:50:10 +01:00
|
|
|
mbedtls_test_unhexify((unsigned char *) val, strlen(val),
|
|
|
|
val, &len) == 0);
|
2020-06-18 10:10:46 +02:00
|
|
|
|
2022-12-04 13:10:55 +01:00
|
|
|
int_params_store->len = len;
|
2017-05-31 21:29:36 +02:00
|
|
|
*out++ = val;
|
2023-01-11 14:50:10 +01:00
|
|
|
*out++ = (char *) (int_params_store++);
|
|
|
|
} else {
|
|
|
|
ret = (DISPATCH_INVALID_TEST_DATA);
|
2017-05-31 21:29:36 +02:00
|
|
|
break;
|
|
|
|
}
|
2023-01-11 14:50:10 +01:00
|
|
|
} else if (strcmp(type, "exp") == 0) {
|
|
|
|
int exp_id = strtol(val, NULL, 10);
|
2022-12-04 15:32:54 +01:00
|
|
|
if (get_expression(exp_id, &int_params_store->sint) == 0) {
|
2023-01-11 14:50:10 +01:00
|
|
|
*out++ = (char *) int_params_store++;
|
|
|
|
} else {
|
|
|
|
ret = (DISPATCH_INVALID_TEST_DATA);
|
|
|
|
break;
|
2017-03-28 02:48:31 +02:00
|
|
|
}
|
2023-01-11 14:50:10 +01:00
|
|
|
} else {
|
|
|
|
ret = (DISPATCH_INVALID_TEST_DATA);
|
|
|
|
break;
|
2017-03-28 02:48:31 +02:00
|
|
|
}
|
|
|
|
}
|
2023-01-11 14:50:10 +01:00
|
|
|
return ret;
|
2017-03-28 02:48:31 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
* \brief Tests snprintf implementation with test input.
|
|
|
|
*
|
2017-06-09 13:39:00 +02:00
|
|
|
* \note
|
|
|
|
* At high optimization levels (e.g. gcc -O3), this function may be
|
|
|
|
* inlined in run_test_snprintf. This can trigger a spurious warning about
|
|
|
|
* potential misuse of snprintf from gcc -Wformat-truncation (observed with
|
|
|
|
* gcc 7.2). This warning makes tests in run_test_snprintf redundant on gcc
|
|
|
|
* only. They are still valid for other compilers. Avoid this warning by
|
|
|
|
* forbidding inlining of this function by gcc.
|
|
|
|
*
|
2017-03-28 02:48:31 +02:00
|
|
|
* \param n Buffer test length.
|
|
|
|
* \param ref_buf Expected buffer.
|
|
|
|
* \param ref_ret Expected snprintf return value.
|
|
|
|
*
|
|
|
|
* \return 0 for success else 1
|
|
|
|
*/
|
2017-06-09 13:39:00 +02:00
|
|
|
#if defined(__GNUC__)
|
|
|
|
__attribute__((__noinline__))
|
|
|
|
#endif
|
2023-01-11 14:50:10 +01:00
|
|
|
static int test_snprintf(size_t n, const char *ref_buf, int ref_ret)
|
2017-03-28 02:48:31 +02:00
|
|
|
{
|
|
|
|
int ret;
|
|
|
|
char buf[10] = "xxxxxxxxx";
|
|
|
|
const char ref[10] = "xxxxxxxxx";
|
|
|
|
|
2023-01-11 14:50:10 +01:00
|
|
|
if (n >= sizeof(buf)) {
|
|
|
|
return -1;
|
|
|
|
}
|
|
|
|
ret = mbedtls_snprintf(buf, n, "%s", "123");
|
|
|
|
if (ret < 0 || (size_t) ret >= n) {
|
2017-03-28 02:48:31 +02:00
|
|
|
ret = -1;
|
2023-01-11 14:50:10 +01:00
|
|
|
}
|
2017-03-28 02:48:31 +02:00
|
|
|
|
2023-01-11 14:50:10 +01:00
|
|
|
if (strncmp(ref_buf, buf, sizeof(buf)) != 0 ||
|
2017-03-28 02:48:31 +02:00
|
|
|
ref_ret != ret ||
|
2023-01-11 14:50:10 +01:00
|
|
|
memcmp(buf + n, ref + n, sizeof(buf) - n) != 0) {
|
|
|
|
return 1;
|
2017-03-28 02:48:31 +02:00
|
|
|
}
|
|
|
|
|
2023-01-11 14:50:10 +01:00
|
|
|
return 0;
|
2017-03-28 02:48:31 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
* \brief Tests snprintf implementation.
|
|
|
|
*
|
|
|
|
* \return 0 for success else 1
|
|
|
|
*/
|
2023-01-11 14:50:10 +01:00
|
|
|
static int run_test_snprintf(void)
|
2017-03-28 02:48:31 +02:00
|
|
|
{
|
2023-01-11 14:50:10 +01:00
|
|
|
return test_snprintf(0, "xxxxxxxxx", -1) != 0 ||
|
|
|
|
test_snprintf(1, "", -1) != 0 ||
|
|
|
|
test_snprintf(2, "1", -1) != 0 ||
|
|
|
|
test_snprintf(3, "12", -1) != 0 ||
|
|
|
|
test_snprintf(4, "123", 3) != 0 ||
|
|
|
|
test_snprintf(5, "123", 3) != 0;
|
2017-03-28 02:48:31 +02:00
|
|
|
}
|
|
|
|
|
2019-09-16 15:13:48 +02:00
|
|
|
/** \brief Write the description of the test case to the outcome CSV file.
|
|
|
|
*
|
|
|
|
* \param outcome_file The file to write to.
|
|
|
|
* If this is \c NULL, this function does nothing.
|
|
|
|
* \param argv0 The test suite name.
|
|
|
|
* \param test_case The test case description.
|
|
|
|
*/
|
2023-01-11 14:50:10 +01:00
|
|
|
static void write_outcome_entry(FILE *outcome_file,
|
|
|
|
const char *argv0,
|
|
|
|
const char *test_case)
|
2019-09-16 15:13:48 +02:00
|
|
|
{
|
|
|
|
/* The non-varying fields are initialized on first use. */
|
|
|
|
static const char *platform = NULL;
|
|
|
|
static const char *configuration = NULL;
|
|
|
|
static const char *test_suite = NULL;
|
|
|
|
|
2023-01-11 14:50:10 +01:00
|
|
|
if (outcome_file == NULL) {
|
2019-09-16 15:13:48 +02:00
|
|
|
return;
|
2023-01-11 14:50:10 +01:00
|
|
|
}
|
2019-09-16 15:13:48 +02:00
|
|
|
|
2023-01-11 14:50:10 +01:00
|
|
|
if (platform == NULL) {
|
|
|
|
platform = getenv("MBEDTLS_TEST_PLATFORM");
|
|
|
|
if (platform == NULL) {
|
2019-09-16 15:13:48 +02:00
|
|
|
platform = "unknown";
|
2023-01-11 14:50:10 +01:00
|
|
|
}
|
2019-09-16 15:13:48 +02:00
|
|
|
}
|
2023-01-11 14:50:10 +01:00
|
|
|
if (configuration == NULL) {
|
|
|
|
configuration = getenv("MBEDTLS_TEST_CONFIGURATION");
|
|
|
|
if (configuration == NULL) {
|
2019-09-16 15:13:48 +02:00
|
|
|
configuration = "unknown";
|
2023-01-11 14:50:10 +01:00
|
|
|
}
|
2019-09-16 15:13:48 +02:00
|
|
|
}
|
2023-01-11 14:50:10 +01:00
|
|
|
if (test_suite == NULL) {
|
|
|
|
test_suite = strrchr(argv0, '/');
|
|
|
|
if (test_suite != NULL) {
|
2019-09-16 15:13:48 +02:00
|
|
|
test_suite += 1; // skip the '/'
|
2023-01-11 14:50:10 +01:00
|
|
|
} else {
|
2019-09-16 15:13:48 +02:00
|
|
|
test_suite = argv0;
|
2023-01-11 14:50:10 +01:00
|
|
|
}
|
2019-09-16 15:13:48 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
/* Write the beginning of the outcome line.
|
|
|
|
* Ignore errors: writing the outcome file is on a best-effort basis. */
|
2023-01-11 14:50:10 +01:00
|
|
|
mbedtls_fprintf(outcome_file, "%s;%s;%s;%s;",
|
|
|
|
platform, configuration, test_suite, test_case);
|
2019-09-16 15:13:48 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
/** \brief Write the result of the test case to the outcome CSV file.
|
|
|
|
*
|
|
|
|
* \param outcome_file The file to write to.
|
|
|
|
* If this is \c NULL, this function does nothing.
|
2020-04-01 16:04:41 +02:00
|
|
|
* \param unmet_dep_count The number of unmet dependencies.
|
|
|
|
* \param unmet_dependencies The array of unmet dependencies.
|
|
|
|
* \param missing_unmet_dependencies Non-zero if there was a problem tracking
|
|
|
|
* all unmet dependencies, 0 otherwise.
|
2021-02-23 13:40:19 +01:00
|
|
|
* \param ret The test dispatch status (DISPATCH_xxx).
|
|
|
|
* \param info A pointer to the test info structure.
|
2019-09-16 15:13:48 +02:00
|
|
|
*/
|
2023-01-11 14:50:10 +01:00
|
|
|
static void write_outcome_result(FILE *outcome_file,
|
|
|
|
size_t unmet_dep_count,
|
|
|
|
int unmet_dependencies[],
|
|
|
|
int missing_unmet_dependencies,
|
|
|
|
int ret,
|
|
|
|
const mbedtls_test_info_t *info)
|
2019-09-16 15:13:48 +02:00
|
|
|
{
|
2023-01-11 14:50:10 +01:00
|
|
|
if (outcome_file == NULL) {
|
2019-09-16 15:13:48 +02:00
|
|
|
return;
|
2023-01-11 14:50:10 +01:00
|
|
|
}
|
2019-09-16 15:13:48 +02:00
|
|
|
|
|
|
|
/* Write the end of the outcome line.
|
|
|
|
* Ignore errors: writing the outcome file is on a best-effort basis. */
|
2023-01-11 14:50:10 +01:00
|
|
|
switch (ret) {
|
2019-09-16 15:13:48 +02:00
|
|
|
case DISPATCH_TEST_SUCCESS:
|
2023-01-11 14:50:10 +01:00
|
|
|
if (unmet_dep_count > 0) {
|
2019-09-16 15:13:48 +02:00
|
|
|
size_t i;
|
2023-01-11 14:50:10 +01:00
|
|
|
mbedtls_fprintf(outcome_file, "SKIP");
|
|
|
|
for (i = 0; i < unmet_dep_count; i++) {
|
|
|
|
mbedtls_fprintf(outcome_file, "%c%d",
|
|
|
|
i == 0 ? ';' : ':',
|
|
|
|
unmet_dependencies[i]);
|
|
|
|
}
|
|
|
|
if (missing_unmet_dependencies) {
|
|
|
|
mbedtls_fprintf(outcome_file, ":...");
|
2019-09-16 15:13:48 +02:00
|
|
|
}
|
|
|
|
break;
|
|
|
|
}
|
2023-01-11 14:50:10 +01:00
|
|
|
switch (info->result) {
|
2021-01-20 18:51:47 +01:00
|
|
|
case MBEDTLS_TEST_RESULT_SUCCESS:
|
2023-01-11 14:50:10 +01:00
|
|
|
mbedtls_fprintf(outcome_file, "PASS;");
|
2019-09-16 15:13:48 +02:00
|
|
|
break;
|
2021-01-20 18:51:47 +01:00
|
|
|
case MBEDTLS_TEST_RESULT_SKIPPED:
|
2023-01-11 14:50:10 +01:00
|
|
|
mbedtls_fprintf(outcome_file, "SKIP;Runtime skip");
|
2019-09-16 15:13:48 +02:00
|
|
|
break;
|
|
|
|
default:
|
2023-01-11 14:50:10 +01:00
|
|
|
mbedtls_fprintf(outcome_file, "FAIL;%s:%d:%s",
|
|
|
|
info->filename, info->line_no,
|
|
|
|
info->test);
|
2019-09-16 15:13:48 +02:00
|
|
|
break;
|
|
|
|
}
|
|
|
|
break;
|
|
|
|
case DISPATCH_TEST_FN_NOT_FOUND:
|
2023-01-11 14:50:10 +01:00
|
|
|
mbedtls_fprintf(outcome_file, "FAIL;Test function not found");
|
2019-09-16 15:13:48 +02:00
|
|
|
break;
|
|
|
|
case DISPATCH_INVALID_TEST_DATA:
|
2023-01-11 14:50:10 +01:00
|
|
|
mbedtls_fprintf(outcome_file, "FAIL;Invalid test data");
|
2019-09-16 15:13:48 +02:00
|
|
|
break;
|
|
|
|
case DISPATCH_UNSUPPORTED_SUITE:
|
2023-01-11 14:50:10 +01:00
|
|
|
mbedtls_fprintf(outcome_file, "SKIP;Unsupported suite");
|
2019-09-16 15:13:48 +02:00
|
|
|
break;
|
|
|
|
default:
|
2023-01-11 14:50:10 +01:00
|
|
|
mbedtls_fprintf(outcome_file, "FAIL;Unknown cause");
|
2019-09-16 15:13:48 +02:00
|
|
|
break;
|
|
|
|
}
|
2023-01-11 14:50:10 +01:00
|
|
|
mbedtls_fprintf(outcome_file, "\n");
|
|
|
|
fflush(outcome_file);
|
2019-09-16 15:13:48 +02:00
|
|
|
}
|
2017-03-28 02:48:31 +02:00
|
|
|
|
|
|
|
/**
|
|
|
|
* \brief Desktop implementation of execute_tests().
|
|
|
|
* Parses command line and executes tests from
|
|
|
|
* supplied or default data file.
|
|
|
|
*
|
|
|
|
* \param argc Command line argument count.
|
|
|
|
* \param argv Argument array.
|
|
|
|
*
|
|
|
|
* \return Program exit status.
|
|
|
|
*/
|
2023-01-11 14:50:10 +01:00
|
|
|
int execute_tests(int argc, const char **argv)
|
2017-03-28 02:48:31 +02:00
|
|
|
{
|
|
|
|
/* Local Configurations and options */
|
|
|
|
const char *default_filename = "DATA_FILE";
|
|
|
|
const char *test_filename = NULL;
|
|
|
|
const char **test_files = NULL;
|
2019-09-16 15:10:47 +02:00
|
|
|
size_t testfile_count = 0;
|
2017-03-28 02:48:31 +02:00
|
|
|
int option_verbose = 0;
|
2019-09-16 10:23:10 +02:00
|
|
|
size_t function_id = 0;
|
2017-03-28 02:48:31 +02:00
|
|
|
|
|
|
|
/* Other Local variables */
|
|
|
|
int arg_index = 1;
|
|
|
|
const char *next_arg;
|
2019-09-16 15:10:47 +02:00
|
|
|
size_t testfile_index, i, cnt;
|
|
|
|
int ret;
|
|
|
|
unsigned total_errors = 0, total_tests = 0, total_skipped = 0;
|
2017-03-28 02:48:31 +02:00
|
|
|
FILE *file;
|
|
|
|
char buf[5000];
|
|
|
|
char *params[50];
|
2021-12-21 06:14:10 +01:00
|
|
|
/* Store for processed integer params. */
|
2022-12-04 13:10:55 +01:00
|
|
|
mbedtls_test_argument_t int_params[50];
|
2017-03-28 02:48:31 +02:00
|
|
|
void *pointer;
|
|
|
|
#if defined(__unix__) || (defined(__APPLE__) && defined(__MACH__))
|
|
|
|
int stdout_fd = -1;
|
|
|
|
#endif /* __unix__ || __APPLE__ __MACH__ */
|
2023-01-11 14:50:10 +01:00
|
|
|
const char *outcome_file_name = getenv("MBEDTLS_TEST_OUTCOME_FILE");
|
2019-09-16 15:13:48 +02:00
|
|
|
FILE *outcome_file = NULL;
|
2017-03-28 02:48:31 +02:00
|
|
|
|
|
|
|
#if defined(MBEDTLS_MEMORY_BUFFER_ALLOC_C) && \
|
|
|
|
!defined(TEST_SUITE_MEMORY_BUFFER_ALLOC)
|
|
|
|
unsigned char alloc_buf[1000000];
|
2023-01-11 14:50:10 +01:00
|
|
|
mbedtls_memory_buffer_alloc_init(alloc_buf, sizeof(alloc_buf));
|
2017-03-28 02:48:31 +02:00
|
|
|
#endif
|
|
|
|
|
2021-01-29 21:17:11 +01:00
|
|
|
#if defined(MBEDTLS_TEST_MUTEX_USAGE)
|
2023-01-11 14:50:10 +01:00
|
|
|
mbedtls_test_mutex_usage_init();
|
2021-01-29 21:17:11 +01:00
|
|
|
#endif
|
|
|
|
|
2017-03-28 02:48:31 +02:00
|
|
|
/*
|
|
|
|
* The C standard doesn't guarantee that all-bits-0 is the representation
|
|
|
|
* of a NULL pointer. We do however use that in our code for initializing
|
|
|
|
* structures, which should work on every modern platform. Let's be sure.
|
|
|
|
*/
|
2023-01-11 14:50:10 +01:00
|
|
|
memset(&pointer, 0, sizeof(void *));
|
|
|
|
if (pointer != NULL) {
|
|
|
|
mbedtls_fprintf(stderr, "all-bits-zero is not a NULL pointer\n");
|
|
|
|
return 1;
|
2017-03-28 02:48:31 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
/*
|
|
|
|
* Make sure we have a snprintf that correctly zero-terminates
|
|
|
|
*/
|
2023-01-11 14:50:10 +01:00
|
|
|
if (run_test_snprintf() != 0) {
|
|
|
|
mbedtls_fprintf(stderr, "the snprintf implementation is broken\n");
|
|
|
|
return 1;
|
2017-03-28 02:48:31 +02:00
|
|
|
}
|
|
|
|
|
2023-01-11 14:50:10 +01:00
|
|
|
if (outcome_file_name != NULL && *outcome_file_name != '\0') {
|
|
|
|
outcome_file = fopen(outcome_file_name, "a");
|
|
|
|
if (outcome_file == NULL) {
|
|
|
|
mbedtls_fprintf(stderr, "Unable to open outcome file. Continuing anyway.\n");
|
2020-01-21 18:03:56 +01:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2023-01-11 14:50:10 +01:00
|
|
|
while (arg_index < argc) {
|
2018-07-18 18:48:37 +02:00
|
|
|
next_arg = argv[arg_index];
|
2017-03-28 02:48:31 +02:00
|
|
|
|
2023-01-11 14:50:10 +01:00
|
|
|
if (strcmp(next_arg, "--verbose") == 0 ||
|
|
|
|
strcmp(next_arg, "-v") == 0) {
|
2017-03-28 02:48:31 +02:00
|
|
|
option_verbose = 1;
|
2023-01-11 14:50:10 +01:00
|
|
|
} else if (strcmp(next_arg, "--help") == 0 ||
|
|
|
|
strcmp(next_arg, "-h") == 0) {
|
|
|
|
mbedtls_fprintf(stdout, USAGE);
|
|
|
|
mbedtls_exit(EXIT_SUCCESS);
|
|
|
|
} else {
|
2017-03-28 02:48:31 +02:00
|
|
|
/* Not an option, therefore treat all further arguments as the file
|
|
|
|
* list.
|
|
|
|
*/
|
2023-01-11 14:50:10 +01:00
|
|
|
test_files = &argv[arg_index];
|
2017-03-28 02:48:31 +02:00
|
|
|
testfile_count = argc - arg_index;
|
2022-06-17 11:19:56 +02:00
|
|
|
break;
|
2017-03-28 02:48:31 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
arg_index++;
|
|
|
|
}
|
|
|
|
|
|
|
|
/* If no files were specified, assume a default */
|
2023-01-11 14:50:10 +01:00
|
|
|
if (test_files == NULL || testfile_count == 0) {
|
2017-03-28 02:48:31 +02:00
|
|
|
test_files = &default_filename;
|
|
|
|
testfile_count = 1;
|
|
|
|
}
|
|
|
|
|
|
|
|
/* Initialize the struct that holds information about the last test */
|
2023-01-11 14:50:10 +01:00
|
|
|
mbedtls_test_info_reset();
|
2017-03-28 02:48:31 +02:00
|
|
|
|
|
|
|
/* Now begin to execute the tests in the testfiles */
|
2023-01-11 14:50:10 +01:00
|
|
|
for (testfile_index = 0;
|
|
|
|
testfile_index < testfile_count;
|
|
|
|
testfile_index++) {
|
2019-09-16 15:10:47 +02:00
|
|
|
size_t unmet_dep_count = 0;
|
2020-03-30 21:39:09 +02:00
|
|
|
int unmet_dependencies[20];
|
2020-04-01 16:04:41 +02:00
|
|
|
int missing_unmet_dependencies = 0;
|
2017-03-28 02:48:31 +02:00
|
|
|
|
2023-01-11 14:50:10 +01:00
|
|
|
test_filename = test_files[testfile_index];
|
2017-03-28 02:48:31 +02:00
|
|
|
|
2023-01-11 14:50:10 +01:00
|
|
|
file = fopen(test_filename, "r");
|
|
|
|
if (file == NULL) {
|
|
|
|
mbedtls_fprintf(stderr, "Failed to open test file: %s\n",
|
|
|
|
test_filename);
|
|
|
|
if (outcome_file != NULL) {
|
|
|
|
fclose(outcome_file);
|
|
|
|
}
|
|
|
|
return 1;
|
2017-03-28 02:48:31 +02:00
|
|
|
}
|
|
|
|
|
2023-01-11 14:50:10 +01:00
|
|
|
while (!feof(file)) {
|
|
|
|
if (unmet_dep_count > 0) {
|
|
|
|
mbedtls_fprintf(stderr,
|
|
|
|
"FATAL: Dep count larger than zero at start of loop\n");
|
|
|
|
mbedtls_exit(MBEDTLS_EXIT_FAILURE);
|
2017-03-28 02:48:31 +02:00
|
|
|
}
|
|
|
|
unmet_dep_count = 0;
|
2020-04-01 16:04:41 +02:00
|
|
|
missing_unmet_dependencies = 0;
|
2017-03-28 02:48:31 +02:00
|
|
|
|
2023-01-11 14:50:10 +01:00
|
|
|
if ((ret = get_line(file, buf, sizeof(buf))) != 0) {
|
2017-03-28 02:48:31 +02:00
|
|
|
break;
|
2023-01-11 14:50:10 +01:00
|
|
|
}
|
|
|
|
mbedtls_fprintf(stdout, "%s%.66s",
|
|
|
|
mbedtls_test_info.result == MBEDTLS_TEST_RESULT_FAILED ?
|
|
|
|
"\n" : "", buf);
|
|
|
|
mbedtls_fprintf(stdout, " ");
|
|
|
|
for (i = strlen(buf) + 1; i < 67; i++) {
|
|
|
|
mbedtls_fprintf(stdout, ".");
|
|
|
|
}
|
|
|
|
mbedtls_fprintf(stdout, " ");
|
|
|
|
fflush(stdout);
|
|
|
|
write_outcome_entry(outcome_file, argv[0], buf);
|
2017-03-28 02:48:31 +02:00
|
|
|
|
|
|
|
total_tests++;
|
|
|
|
|
2023-01-11 14:50:10 +01:00
|
|
|
if ((ret = get_line(file, buf, sizeof(buf))) != 0) {
|
2017-03-28 02:48:31 +02:00
|
|
|
break;
|
2023-01-11 14:50:10 +01:00
|
|
|
}
|
|
|
|
cnt = parse_arguments(buf, strlen(buf), params,
|
|
|
|
sizeof(params) / sizeof(params[0]));
|
|
|
|
|
|
|
|
if (strcmp(params[0], "depends_on") == 0) {
|
|
|
|
for (i = 1; i < cnt; i++) {
|
|
|
|
int dep_id = strtol(params[i], NULL, 10);
|
|
|
|
if (dep_check(dep_id) != DEPENDENCY_SUPPORTED) {
|
|
|
|
if (unmet_dep_count <
|
|
|
|
ARRAY_LENGTH(unmet_dependencies)) {
|
2020-04-01 15:52:06 +02:00
|
|
|
unmet_dependencies[unmet_dep_count] = dep_id;
|
|
|
|
unmet_dep_count++;
|
2023-01-11 14:50:10 +01:00
|
|
|
} else {
|
2020-04-01 16:04:41 +02:00
|
|
|
missing_unmet_dependencies = 1;
|
|
|
|
}
|
2017-03-28 02:48:31 +02:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2023-01-11 14:50:10 +01:00
|
|
|
if ((ret = get_line(file, buf, sizeof(buf))) != 0) {
|
2017-03-28 02:48:31 +02:00
|
|
|
break;
|
2023-01-11 14:50:10 +01:00
|
|
|
}
|
|
|
|
cnt = parse_arguments(buf, strlen(buf), params,
|
|
|
|
sizeof(params) / sizeof(params[0]));
|
2017-03-28 02:48:31 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
// If there are no unmet dependencies execute the test
|
2023-01-11 14:50:10 +01:00
|
|
|
if (unmet_dep_count == 0) {
|
|
|
|
mbedtls_test_info_reset();
|
2017-03-28 02:48:31 +02:00
|
|
|
|
|
|
|
#if defined(__unix__) || (defined(__APPLE__) && defined(__MACH__))
|
|
|
|
/* Suppress all output from the library unless we're verbose
|
|
|
|
* mode
|
|
|
|
*/
|
2023-01-11 14:50:10 +01:00
|
|
|
if (!option_verbose) {
|
|
|
|
stdout_fd = redirect_output(stdout, "/dev/null");
|
|
|
|
if (stdout_fd == -1) {
|
2017-03-28 02:48:31 +02:00
|
|
|
/* Redirection has failed with no stdout so exit */
|
2023-01-11 14:50:10 +01:00
|
|
|
exit(1);
|
2017-03-28 02:48:31 +02:00
|
|
|
}
|
|
|
|
}
|
|
|
|
#endif /* __unix__ || __APPLE__ __MACH__ */
|
|
|
|
|
2023-01-11 14:50:10 +01:00
|
|
|
function_id = strtoul(params[0], NULL, 10);
|
|
|
|
if ((ret = check_test(function_id)) == 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));
|
2017-06-15 15:45:56 +02:00
|
|
|
}
|
2017-03-28 02:48:31 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
#if defined(__unix__) || (defined(__APPLE__) && defined(__MACH__))
|
2023-01-11 14:50:10 +01:00
|
|
|
if (!option_verbose && restore_output(stdout, stdout_fd)) {
|
|
|
|
/* Redirection has failed with no stdout so exit */
|
|
|
|
exit(1);
|
2017-03-28 02:48:31 +02:00
|
|
|
}
|
|
|
|
#endif /* __unix__ || __APPLE__ __MACH__ */
|
|
|
|
|
|
|
|
}
|
|
|
|
|
2023-01-11 14:50:10 +01:00
|
|
|
write_outcome_result(outcome_file,
|
|
|
|
unmet_dep_count, unmet_dependencies,
|
|
|
|
missing_unmet_dependencies,
|
|
|
|
ret, &mbedtls_test_info);
|
|
|
|
if (unmet_dep_count > 0 || ret == DISPATCH_UNSUPPORTED_SUITE) {
|
2017-03-28 02:48:31 +02:00
|
|
|
total_skipped++;
|
2023-01-11 14:50:10 +01:00
|
|
|
mbedtls_fprintf(stdout, "----");
|
2017-03-28 02:48:31 +02:00
|
|
|
|
2023-01-11 14:50:10 +01:00
|
|
|
if (1 == option_verbose && ret == DISPATCH_UNSUPPORTED_SUITE) {
|
|
|
|
mbedtls_fprintf(stdout, "\n Test Suite not enabled");
|
2017-03-28 02:48:31 +02:00
|
|
|
}
|
|
|
|
|
2023-01-11 14:50:10 +01:00
|
|
|
if (1 == option_verbose && unmet_dep_count > 0) {
|
|
|
|
mbedtls_fprintf(stdout, "\n Unmet dependencies: ");
|
|
|
|
for (i = 0; i < unmet_dep_count; i++) {
|
|
|
|
mbedtls_fprintf(stdout, "%d ",
|
|
|
|
unmet_dependencies[i]);
|
|
|
|
}
|
|
|
|
if (missing_unmet_dependencies) {
|
|
|
|
mbedtls_fprintf(stdout, "...");
|
2017-03-28 02:48:31 +02:00
|
|
|
}
|
|
|
|
}
|
2023-01-11 14:50:10 +01:00
|
|
|
mbedtls_fprintf(stdout, "\n");
|
|
|
|
fflush(stdout);
|
2017-03-28 02:48:31 +02:00
|
|
|
|
|
|
|
unmet_dep_count = 0;
|
2020-04-01 16:04:41 +02:00
|
|
|
missing_unmet_dependencies = 0;
|
2023-01-11 14:50:10 +01:00
|
|
|
} else if (ret == DISPATCH_TEST_SUCCESS) {
|
|
|
|
if (mbedtls_test_info.result == MBEDTLS_TEST_RESULT_SUCCESS) {
|
|
|
|
mbedtls_fprintf(stdout, "PASS\n");
|
|
|
|
} else if (mbedtls_test_info.result == MBEDTLS_TEST_RESULT_SKIPPED) {
|
|
|
|
mbedtls_fprintf(stdout, "----\n");
|
2019-07-05 14:31:30 +02:00
|
|
|
total_skipped++;
|
2023-01-11 14:50:10 +01:00
|
|
|
} else {
|
2017-03-28 02:48:31 +02:00
|
|
|
total_errors++;
|
2023-01-11 14:50:10 +01:00
|
|
|
mbedtls_fprintf(stdout, "FAILED\n");
|
|
|
|
mbedtls_fprintf(stdout, " %s\n at ",
|
|
|
|
mbedtls_test_info.test);
|
|
|
|
if (mbedtls_test_info.step != (unsigned long) (-1)) {
|
|
|
|
mbedtls_fprintf(stdout, "step %lu, ",
|
|
|
|
mbedtls_test_info.step);
|
|
|
|
}
|
|
|
|
mbedtls_fprintf(stdout, "line %d, %s",
|
|
|
|
mbedtls_test_info.line_no,
|
|
|
|
mbedtls_test_info.filename);
|
|
|
|
if (mbedtls_test_info.line1[0] != 0) {
|
|
|
|
mbedtls_fprintf(stdout, "\n %s",
|
|
|
|
mbedtls_test_info.line1);
|
|
|
|
}
|
|
|
|
if (mbedtls_test_info.line2[0] != 0) {
|
|
|
|
mbedtls_fprintf(stdout, "\n %s",
|
|
|
|
mbedtls_test_info.line2);
|
2019-03-01 14:26:30 +01:00
|
|
|
}
|
2017-03-28 02:48:31 +02:00
|
|
|
}
|
2023-01-11 14:50:10 +01:00
|
|
|
fflush(stdout);
|
|
|
|
} else if (ret == DISPATCH_INVALID_TEST_DATA) {
|
|
|
|
mbedtls_fprintf(stderr, "FAILED: FATAL PARSE ERROR\n");
|
|
|
|
fclose(file);
|
|
|
|
mbedtls_exit(2);
|
|
|
|
} else if (ret == DISPATCH_TEST_FN_NOT_FOUND) {
|
|
|
|
mbedtls_fprintf(stderr, "FAILED: FATAL TEST FUNCTION NOT FOUND\n");
|
|
|
|
fclose(file);
|
|
|
|
mbedtls_exit(2);
|
|
|
|
} else {
|
2017-03-28 02:48:31 +02:00
|
|
|
total_errors++;
|
2023-01-11 14:50:10 +01:00
|
|
|
}
|
2017-03-28 02:48:31 +02:00
|
|
|
}
|
2023-01-11 14:50:10 +01:00
|
|
|
fclose(file);
|
2017-03-28 02:48:31 +02:00
|
|
|
}
|
|
|
|
|
2023-01-11 14:50:10 +01:00
|
|
|
if (outcome_file != NULL) {
|
|
|
|
fclose(outcome_file);
|
|
|
|
}
|
2019-09-16 15:13:48 +02:00
|
|
|
|
2023-01-11 14:50:10 +01:00
|
|
|
mbedtls_fprintf(stdout,
|
|
|
|
"\n----------------------------------------------------------------------------\n\n");
|
|
|
|
if (total_errors == 0) {
|
|
|
|
mbedtls_fprintf(stdout, "PASSED");
|
|
|
|
} else {
|
|
|
|
mbedtls_fprintf(stdout, "FAILED");
|
|
|
|
}
|
2017-03-28 02:48:31 +02:00
|
|
|
|
2023-01-11 14:50:10 +01:00
|
|
|
mbedtls_fprintf(stdout, " (%u / %u tests (%u skipped))\n",
|
|
|
|
total_tests - total_errors, total_tests, total_skipped);
|
2017-03-28 02:48:31 +02:00
|
|
|
|
|
|
|
#if defined(MBEDTLS_MEMORY_BUFFER_ALLOC_C) && \
|
|
|
|
!defined(TEST_SUITE_MEMORY_BUFFER_ALLOC)
|
|
|
|
#if defined(MBEDTLS_MEMORY_DEBUG)
|
|
|
|
mbedtls_memory_buffer_alloc_status();
|
|
|
|
#endif
|
|
|
|
mbedtls_memory_buffer_alloc_free();
|
|
|
|
#endif
|
|
|
|
|
2023-01-11 14:50:10 +01:00
|
|
|
return total_errors != 0;
|
2017-03-28 02:48:31 +02:00
|
|
|
}
|