blob: 4d4f32f6985b0490288bf2dadbe7529c288bc7b9 [file] [log] [blame]
Gilles Peskinee137ebc2021-01-29 21:12:52 +01001#line 2 "main_test.function"
Paul Bakkerde56ca12013-09-15 17:05:21 +02002SUITE_PRE_DEP
3#define TEST_SUITE_ACTIVE
4
Paul Bakker19343182013-08-16 13:31:10 +02005int verify_string( char **str )
6{
7 if( (*str)[0] != '"' ||
8 (*str)[strlen( *str ) - 1] != '"' )
9 {
Simon Butcher25731362016-09-30 13:11:29 +010010 mbedtls_fprintf( stderr,
11 "Expected string (with \"\") for parameter and got: %s\n", *str );
Paul Bakker19343182013-08-16 13:31:10 +020012 return( -1 );
13 }
14
15 (*str)++;
16 (*str)[strlen( *str ) - 1] = '\0';
17
18 return( 0 );
19}
20
21int verify_int( char *str, int *value )
22{
23 size_t i;
24 int minus = 0;
25 int digits = 1;
26 int hex = 0;
27
28 for( i = 0; i < strlen( str ); i++ )
29 {
30 if( i == 0 && str[i] == '-' )
31 {
32 minus = 1;
33 continue;
34 }
35
36 if( ( ( minus && i == 2 ) || ( !minus && i == 1 ) ) &&
37 str[i - 1] == '0' && str[i] == 'x' )
38 {
39 hex = 1;
40 continue;
41 }
42
Manuel Pégourié-Gonnard725afd82014-02-01 11:54:28 +010043 if( ! ( ( str[i] >= '0' && str[i] <= '9' ) ||
44 ( hex && ( ( str[i] >= 'a' && str[i] <= 'f' ) ||
45 ( str[i] >= 'A' && str[i] <= 'F' ) ) ) ) )
Paul Bakker19343182013-08-16 13:31:10 +020046 {
47 digits = 0;
48 break;
49 }
50 }
51
52 if( digits )
53 {
54 if( hex )
55 *value = strtol( str, NULL, 16 );
56 else
57 *value = strtol( str, NULL, 10 );
58
59 return( 0 );
60 }
61
62MAPPING_CODE
63
Simon Butcher25731362016-09-30 13:11:29 +010064 mbedtls_fprintf( stderr,
65 "Expected integer for parameter and got: %s\n", str );
SimonB8ca7bc42016-04-17 23:24:50 +010066 return( KEY_VALUE_MAPPING_NOT_FOUND );
Paul Bakker19343182013-08-16 13:31:10 +020067}
68
SimonB152ea182016-02-15 23:27:28 +000069
70/*----------------------------------------------------------------------------*/
71/* Test Case code */
72
Paul Bakkerde56ca12013-09-15 17:05:21 +020073FUNCTION_CODE
74SUITE_POST_DEP
75
SimonB15942102016-04-25 21:34:49 +010076#line !LINE_NO! "main_test.function"
77
SimonB152ea182016-02-15 23:27:28 +000078
79/*----------------------------------------------------------------------------*/
80/* Test dispatch code */
81
Paul Bakker19343182013-08-16 13:31:10 +020082int dep_check( char *str )
83{
84 if( str == NULL )
85 return( 1 );
86
87DEP_CHECK_CODE
Simon Butcher65b1fa62016-05-23 23:18:26 +010088#line !LINE_NO! "main_test.function"
Paul Bakker19343182013-08-16 13:31:10 +020089
SimonB8ca7bc42016-04-17 23:24:50 +010090 return( DEPENDENCY_NOT_SUPPORTED );
Paul Bakker19343182013-08-16 13:31:10 +020091}
92
Paul Bakker19343182013-08-16 13:31:10 +020093int dispatch_test(int cnt, char *params[50])
94{
95 int ret;
Paul Bakkerb34fef22013-08-20 12:06:33 +020096 ((void) cnt);
97 ((void) params);
Paul Bakker19343182013-08-16 13:31:10 +020098
Paul Bakkerb34fef22013-08-20 12:06:33 +020099#if defined(TEST_SUITE_ACTIVE)
SimonB8ca7bc42016-04-17 23:24:50 +0100100 ret = DISPATCH_TEST_SUCCESS;
101
Simon Butcher65b1fa62016-05-23 23:18:26 +0100102 // Cast to void to avoid compiler warnings
103 (void)ret;
104
Paul Bakker19343182013-08-16 13:31:10 +0200105DISPATCH_FUNCTION
106 {
Simon Butcher65b1fa62016-05-23 23:18:26 +0100107#line !LINE_NO! "main_test.function"
SimonB8ca7bc42016-04-17 23:24:50 +0100108 mbedtls_fprintf( stdout,
109 "FAILED\nSkipping unknown test function '%s'\n",
110 params[0] );
Paul Bakker19343182013-08-16 13:31:10 +0200111 fflush( stdout );
SimonB8ca7bc42016-04-17 23:24:50 +0100112 ret = DISPATCH_TEST_FN_NOT_FOUND;
Paul Bakker19343182013-08-16 13:31:10 +0200113 }
Gilles Peskine0abb8e42021-01-29 21:18:09 +0100114
Paul Bakkerb34fef22013-08-20 12:06:33 +0200115#else
SimonB8ca7bc42016-04-17 23:24:50 +0100116 ret = DISPATCH_UNSUPPORTED_SUITE;
Paul Bakkerb34fef22013-08-20 12:06:33 +0200117#endif
Paul Bakker19343182013-08-16 13:31:10 +0200118 return( ret );
119}
120
SimonB152ea182016-02-15 23:27:28 +0000121
122/*----------------------------------------------------------------------------*/
123/* Main Test code */
124
SimonB15942102016-04-25 21:34:49 +0100125#line !LINE_NO! "main_test.function"
126
SimonB8ca7bc42016-04-17 23:24:50 +0100127#define USAGE \
128 "Usage: %s [OPTIONS] files...\n\n" \
129 " Command line arguments:\n" \
130 " files... One or more test data file. If no file is specified\n" \
131 " the followimg default test case is used:\n" \
132 " %s\n\n" \
133 " Options:\n" \
134 " -v | --verbose Display full information about each test\n" \
135 " -h | --help Display this information\n\n", \
136 argv[0], \
SimonB15942102016-04-25 21:34:49 +0100137 "TESTCASE_FILENAME"
SimonB8ca7bc42016-04-17 23:24:50 +0100138
139
Gilles Peskine964faeb2017-09-29 18:00:25 +0200140/** Retrieve one input line into buf, which must have room for len
141 * bytes. The trailing line break (if any) is stripped from the result.
142 * Lines beginning with the character '#' are skipped. Lines that are
143 * more than len-1 bytes long including the trailing line break are
144 * truncated; note that the following bytes remain in the input stream.
145 *
146 * \return 0 on success, -1 on error or end of file
147 */
Paul Bakker19343182013-08-16 13:31:10 +0200148int get_line( FILE *f, char *buf, size_t len )
149{
150 char *ret;
151
Gilles Peskine964faeb2017-09-29 18:00:25 +0200152 do
Gilles Peskineb04e2c32017-09-29 15:45:12 +0200153 {
154 ret = fgets( buf, len, f );
155 if( ret == NULL )
156 return( -1 );
Gilles Peskineb04e2c32017-09-29 15:45:12 +0200157 }
Gilles Peskine964faeb2017-09-29 18:00:25 +0200158 while( buf[0] == '#' );
159
160 ret = buf + strlen( buf );
161 if( ret-- > buf && *ret == '\n' )
162 *ret = '\0';
163 if( ret-- > buf && *ret == '\r' )
164 *ret = '\0';
Paul Bakker19343182013-08-16 13:31:10 +0200165
166 return( 0 );
167}
168
169int parse_arguments( char *buf, size_t len, char *params[50] )
170{
171 int cnt = 0, i;
172 char *cur = buf;
173 char *p = buf, *q;
174
175 params[cnt++] = cur;
176
177 while( *p != '\0' && p < buf + len )
178 {
179 if( *p == '\\' )
180 {
Manuel Pégourié-Gonnard2d5f1422014-01-22 16:01:17 +0100181 p++;
182 p++;
Paul Bakker19343182013-08-16 13:31:10 +0200183 continue;
184 }
185 if( *p == ':' )
186 {
187 if( p + 1 < buf + len )
188 {
189 cur = p + 1;
190 params[cnt++] = cur;
191 }
192 *p = '\0';
193 }
194
Manuel Pégourié-Gonnard2d5f1422014-01-22 16:01:17 +0100195 p++;
Paul Bakker19343182013-08-16 13:31:10 +0200196 }
197
SimonB0269dad2016-02-17 23:34:30 +0000198 /* Replace newlines, question marks and colons in strings */
Paul Bakker19343182013-08-16 13:31:10 +0200199 for( i = 0; i < cnt; i++ )
200 {
201 p = params[i];
202 q = params[i];
203
204 while( *p != '\0' )
205 {
206 if( *p == '\\' && *(p + 1) == 'n' )
207 {
208 p += 2;
209 *(q++) = '\n';
210 }
211 else if( *p == '\\' && *(p + 1) == ':' )
212 {
213 p += 2;
214 *(q++) = ':';
215 }
216 else if( *p == '\\' && *(p + 1) == '?' )
217 {
218 p += 2;
219 *(q++) = '?';
220 }
221 else
222 *(q++) = *(p++);
223 }
224 *q = '\0';
225 }
226
227 return( cnt );
228}
229
Rodrigo Dias Correa5fb1bd42020-11-10 02:28:50 -0300230static int test_snprintf( size_t n, const char *ref_buf, int ref_ret )
Manuel Pégourié-Gonnard7b6dcbe2015-06-22 10:48:01 +0200231{
232 int ret;
233 char buf[10] = "xxxxxxxxx";
Manuel Pégourié-Gonnard4b00f082015-06-26 11:24:32 +0200234 const char ref[10] = "xxxxxxxxx";
Manuel Pégourié-Gonnard7b6dcbe2015-06-22 10:48:01 +0200235
236 ret = mbedtls_snprintf( buf, n, "%s", "123" );
237 if( ret < 0 || (size_t) ret >= n )
238 ret = -1;
239
Manuel Pégourié-Gonnard4b00f082015-06-26 11:24:32 +0200240 if( strncmp( ref_buf, buf, sizeof( buf ) ) != 0 ||
241 ref_ret != ret ||
242 memcmp( buf + n, ref + n, sizeof( buf ) - n ) != 0 )
Manuel Pégourié-Gonnard7b6dcbe2015-06-22 10:48:01 +0200243 {
244 return( 1 );
245 }
246
247 return( 0 );
248}
249
250static int run_test_snprintf( void )
251{
252 return( test_snprintf( 0, "xxxxxxxxx", -1 ) != 0 ||
Manuel Pégourié-Gonnard4b00f082015-06-26 11:24:32 +0200253 test_snprintf( 1, "", -1 ) != 0 ||
254 test_snprintf( 2, "1", -1 ) != 0 ||
255 test_snprintf( 3, "12", -1 ) != 0 ||
256 test_snprintf( 4, "123", 3 ) != 0 ||
257 test_snprintf( 5, "123", 3 ) != 0 );
Manuel Pégourié-Gonnard7b6dcbe2015-06-22 10:48:01 +0200258}
259
Simon Butcheraad787f2016-01-26 22:13:58 +0000260int main(int argc, const char *argv[])
Paul Bakker19343182013-08-16 13:31:10 +0200261{
SimonB8ca7bc42016-04-17 23:24:50 +0100262 /* Local Configurations and options */
SimonB15942102016-04-25 21:34:49 +0100263 const char *default_filename = "TESTCASE_FILENAME";
Simon Butcheraad787f2016-01-26 22:13:58 +0000264 const char *test_filename = NULL;
265 const char **test_files = NULL;
Ronald Cron59f21392020-04-06 14:16:25 +0200266 size_t testfile_count = 0;
SimonB8ca7bc42016-04-17 23:24:50 +0100267 int option_verbose = 0;
268
269 /* Other Local variables */
270 int arg_index = 1;
271 const char *next_arg;
Ronald Cron59f21392020-04-06 14:16:25 +0200272 size_t testfile_index, i, cnt;
273 int ret;
274 unsigned total_errors = 0, total_tests = 0, total_skipped = 0;
Paul Bakker19343182013-08-16 13:31:10 +0200275 FILE *file;
276 char buf[5000];
277 char *params[50];
Manuel Pégourié-Gonnardd14acbc2015-05-29 11:26:37 +0200278 void *pointer;
Andres AGea67eeb2016-11-02 10:17:00 +0000279#if defined(__unix__) || (defined(__APPLE__) && defined(__MACH__))
Simon Butchere0192962016-10-12 23:07:30 +0100280 int stdout_fd = -1;
Andres AGea67eeb2016-11-02 10:17:00 +0000281#endif /* __unix__ || __APPLE__ __MACH__ */
Paul Bakker19343182013-08-16 13:31:10 +0200282
Manuel Pégourié-Gonnard2cf5a7c2015-04-08 12:49:31 +0200283#if defined(MBEDTLS_MEMORY_BUFFER_ALLOC_C) && \
Manuel Pégourié-Gonnard765bb312014-11-27 11:55:27 +0100284 !defined(TEST_SUITE_MEMORY_BUFFER_ALLOC)
Paul Bakker1337aff2013-09-29 14:45:34 +0200285 unsigned char alloc_buf[1000000];
Manuel Pégourié-Gonnard2cf5a7c2015-04-08 12:49:31 +0200286 mbedtls_memory_buffer_alloc_init( alloc_buf, sizeof(alloc_buf) );
Paul Bakker19343182013-08-16 13:31:10 +0200287#endif
288
Gilles Peskine44498ff2021-01-29 21:17:11 +0100289#if defined(MBEDTLS_TEST_MUTEX_USAGE)
290 mbedtls_test_mutex_usage_init( );
291#endif
292
Manuel Pégourié-Gonnardd14acbc2015-05-29 11:26:37 +0200293 /*
294 * The C standard doesn't guarantee that all-bits-0 is the representation
295 * of a NULL pointer. We do however use that in our code for initializing
296 * structures, which should work on every modern platform. Let's be sure.
297 */
298 memset( &pointer, 0, sizeof( void * ) );
299 if( pointer != NULL )
300 {
301 mbedtls_fprintf( stderr, "all-bits-zero is not a NULL pointer\n" );
302 return( 1 );
303 }
304
Manuel Pégourié-Gonnard7b6dcbe2015-06-22 10:48:01 +0200305 /*
306 * Make sure we have a snprintf that correctly zero-terminates
307 */
308 if( run_test_snprintf() != 0 )
309 {
310 mbedtls_fprintf( stderr, "the snprintf implementation is broken\n" );
311 return( 0 );
312 }
313
SimonB8ca7bc42016-04-17 23:24:50 +0100314 while( arg_index < argc)
315 {
316 next_arg = argv[ arg_index ];
317
318 if( strcmp(next_arg, "--verbose" ) == 0 ||
319 strcmp(next_arg, "-v" ) == 0 )
320 {
321 option_verbose = 1;
322 }
323 else if( strcmp(next_arg, "--help" ) == 0 ||
324 strcmp(next_arg, "-h" ) == 0 )
325 {
326 mbedtls_fprintf( stdout, USAGE );
327 mbedtls_exit( EXIT_SUCCESS );
328 }
329 else
330 {
331 /* Not an option, therefore treat all further arguments as the file
332 * list.
333 */
334 test_files = &argv[ arg_index ];
335 testfile_count = argc - arg_index;
336 }
337
338 arg_index++;
339 }
340
341 /* If no files were specified, assume a default */
342 if ( test_files == NULL || testfile_count == 0 )
Paul Bakker19343182013-08-16 13:31:10 +0200343 {
Simon Butcheraad787f2016-01-26 22:13:58 +0000344 test_files = &default_filename;
345 testfile_count = 1;
346 }
Paul Bakker19343182013-08-16 13:31:10 +0200347
Andres Amaya Garcia3f50f512017-10-01 16:42:29 +0100348 /* Initialize the struct that holds information about the last test */
349 memset( &test_info, 0, sizeof( test_info ) );
350
SimonB8ca7bc42016-04-17 23:24:50 +0100351 /* Now begin to execute the tests in the testfiles */
Simon Butcheraad787f2016-01-26 22:13:58 +0000352 for ( testfile_index = 0;
353 testfile_index < testfile_count;
354 testfile_index++ )
Paul Bakker19343182013-08-16 13:31:10 +0200355 {
Ronald Cron59f21392020-04-06 14:16:25 +0200356 size_t unmet_dep_count = 0;
Gilles Peskine67665502020-03-31 10:57:53 +0200357 char *unmet_dependencies[20]; /* only filled when verbose != 0 */
Ronald Cron75d26b52020-04-03 15:46:53 +0200358 int missing_unmet_dependencies = 0;
Paul Bakker774180e2016-05-12 15:59:48 +0100359
Simon Butcheraad787f2016-01-26 22:13:58 +0000360 test_filename = test_files[ testfile_index ];
Paul Bakker19343182013-08-16 13:31:10 +0200361
Simon Butcheraad787f2016-01-26 22:13:58 +0000362 file = fopen( test_filename, "r" );
363 if( file == NULL )
Paul Bakker19343182013-08-16 13:31:10 +0200364 {
Simon Butcheraad787f2016-01-26 22:13:58 +0000365 mbedtls_fprintf( stderr, "Failed to open test file: %s\n",
366 test_filename );
367 return( 1 );
368 }
369
370 while( !feof( file ) )
371 {
Paul Bakker774180e2016-05-12 15:59:48 +0100372 if( unmet_dep_count > 0 )
373 {
Simon Butcher25731362016-09-30 13:11:29 +0100374 mbedtls_fprintf( stderr,
Janos Follath8ca53b52016-10-05 10:57:49 +0100375 "FATAL: Dep count larger than zero at start of loop\n" );
Paul Bakker774180e2016-05-12 15:59:48 +0100376 mbedtls_exit( MBEDTLS_EXIT_FAILURE );
377 }
378 unmet_dep_count = 0;
Gilles Peskine67665502020-03-31 10:57:53 +0200379 memset( unmet_dependencies, 0, sizeof( unmet_dependencies ) );
Ronald Cron75d26b52020-04-03 15:46:53 +0200380 missing_unmet_dependencies = 0;
Simon Butcheraad787f2016-01-26 22:13:58 +0000381
382 if( ( ret = get_line( file, buf, sizeof(buf) ) ) != 0 )
383 break;
Andres Amaya Garcia3f50f512017-10-01 16:42:29 +0100384 mbedtls_fprintf( stdout, "%s%.66s", test_info.failed ? "\n" : "", buf );
Simon Butcheraad787f2016-01-26 22:13:58 +0000385 mbedtls_fprintf( stdout, " " );
386 for( i = strlen( buf ) + 1; i < 67; i++ )
387 mbedtls_fprintf( stdout, "." );
388 mbedtls_fprintf( stdout, " " );
389 fflush( stdout );
390
391 total_tests++;
Paul Bakker19343182013-08-16 13:31:10 +0200392
393 if( ( ret = get_line( file, buf, sizeof(buf) ) ) != 0 )
394 break;
395 cnt = parse_arguments( buf, strlen(buf), params );
Paul Bakker19343182013-08-16 13:31:10 +0200396
Simon Butcheraad787f2016-01-26 22:13:58 +0000397 if( strcmp( params[0], "depends_on" ) == 0 )
398 {
399 for( i = 1; i < cnt; i++ )
SimonB8ca7bc42016-04-17 23:24:50 +0100400 {
401 if( dep_check( params[i] ) != DEPENDENCY_SUPPORTED )
402 {
Ronald Cron1d3eab62020-04-03 15:36:16 +0200403 if( unmet_dep_count <
404 ARRAY_LENGTH( unmet_dependencies ) )
Paul Bakker26b60bf2016-05-12 15:55:37 +0100405 {
Ronald Cron1d3eab62020-04-03 15:36:16 +0200406 if( 0 != option_verbose )
Gilles Peskine67665502020-03-31 10:57:53 +0200407 {
Ronald Cron1d3eab62020-04-03 15:36:16 +0200408 unmet_dependencies[unmet_dep_count] =
409 strdup( params[i] );
410 if( unmet_dependencies[unmet_dep_count] == NULL )
411 {
412 mbedtls_fprintf( stderr,
413 "FATAL: Out of memory\n" );
414 mbedtls_exit( MBEDTLS_EXIT_FAILURE );
415 }
Gilles Peskine67665502020-03-31 10:57:53 +0200416 }
Ronald Cron1d3eab62020-04-03 15:36:16 +0200417 unmet_dep_count++;
SimonB8ca7bc42016-04-17 23:24:50 +0100418 }
Ronald Cron75d26b52020-04-03 15:46:53 +0200419 else
420 {
421 missing_unmet_dependencies = 1;
422 }
SimonB8ca7bc42016-04-17 23:24:50 +0100423 }
424 }
Paul Bakker19343182013-08-16 13:31:10 +0200425
Simon Butcheraad787f2016-01-26 22:13:58 +0000426 if( ( ret = get_line( file, buf, sizeof(buf) ) ) != 0 )
427 break;
428 cnt = parse_arguments( buf, strlen(buf), params );
429 }
Andres Amaya Garcia3f50f512017-10-01 16:42:29 +0100430
SimonB8ca7bc42016-04-17 23:24:50 +0100431 // If there are no unmet dependencies execute the test
432 if( unmet_dep_count == 0 )
Simon Butcheraad787f2016-01-26 22:13:58 +0000433 {
Andres Amaya Garcia3f50f512017-10-01 16:42:29 +0100434 test_info.failed = 0;
Simon Butcher25731362016-09-30 13:11:29 +0100435
436#if defined(__unix__) || (defined(__APPLE__) && defined(__MACH__))
437 /* Suppress all output from the library unless we're verbose
438 * mode
439 */
440 if( !option_verbose )
441 {
gufe44b0ab8c22020-07-30 09:02:27 +0200442 stdout_fd = redirect_output( stdout, "/dev/null" );
Janos Follath8ca53b52016-10-05 10:57:49 +0100443 if( stdout_fd == -1 )
Simon Butcher25731362016-09-30 13:11:29 +0100444 {
445 /* Redirection has failed with no stdout so exit */
Janos Follath8ca53b52016-10-05 10:57:49 +0100446 exit( 1 );
Simon Butcher25731362016-09-30 13:11:29 +0100447 }
448 }
449#endif /* __unix__ || __APPLE__ __MACH__ */
450
Simon Butcheraad787f2016-01-26 22:13:58 +0000451 ret = dispatch_test( cnt, params );
Simon Butcher25731362016-09-30 13:11:29 +0100452
453#if defined(__unix__) || (defined(__APPLE__) && defined(__MACH__))
gufe44b0ab8c22020-07-30 09:02:27 +0200454 if( !option_verbose && restore_output( stdout, stdout_fd ) )
Simon Butcher25731362016-09-30 13:11:29 +0100455 {
Simon Butcher25731362016-09-30 13:11:29 +0100456 /* Redirection has failed with no stdout so exit */
Janos Follath8ca53b52016-10-05 10:57:49 +0100457 exit( 1 );
Simon Butcher25731362016-09-30 13:11:29 +0100458 }
459#endif /* __unix__ || __APPLE__ __MACH__ */
460
Gilles Peskine0abb8e42021-01-29 21:18:09 +0100461#if defined(MBEDTLS_TEST_MUTEX_USAGE)
462 if( ret == DISPATCH_TEST_SUCCESS )
463 mbedtls_test_mutex_usage_check( );
464#endif /* MBEDTLS_TEST_MUTEX_USAGE */
Simon Butcheraad787f2016-01-26 22:13:58 +0000465 }
466
SimonB8ca7bc42016-04-17 23:24:50 +0100467 if( unmet_dep_count > 0 || ret == DISPATCH_UNSUPPORTED_SUITE )
Simon Butcheraad787f2016-01-26 22:13:58 +0000468 {
469 total_skipped++;
Hanno Becker910f6622017-07-23 10:23:24 +0100470 mbedtls_fprintf( stdout, "----" );
SimonB8ca7bc42016-04-17 23:24:50 +0100471
472 if( 1 == option_verbose && ret == DISPATCH_UNSUPPORTED_SUITE )
473 {
Hanno Becker910f6622017-07-23 10:23:24 +0100474 mbedtls_fprintf( stdout, "\n Test Suite not enabled" );
SimonB8ca7bc42016-04-17 23:24:50 +0100475 }
476
477 if( 1 == option_verbose && unmet_dep_count > 0 )
478 {
Hanno Becker910f6622017-07-23 10:23:24 +0100479 mbedtls_fprintf( stdout, "\n Unmet dependencies: " );
Paul Bakker774180e2016-05-12 15:59:48 +0100480 for( i = 0; i < unmet_dep_count; i++ )
SimonB8ca7bc42016-04-17 23:24:50 +0100481 {
482 mbedtls_fprintf(stdout, "%s ",
Paul Bakker774180e2016-05-12 15:59:48 +0100483 unmet_dependencies[i]);
484 free(unmet_dependencies[i]);
SimonB8ca7bc42016-04-17 23:24:50 +0100485 }
Ronald Cron75d26b52020-04-03 15:46:53 +0200486 if( missing_unmet_dependencies )
487 mbedtls_fprintf( stdout, "..." );
SimonB8ca7bc42016-04-17 23:24:50 +0100488 }
Hanno Becker910f6622017-07-23 10:23:24 +0100489 mbedtls_fprintf( stdout, "\n" );
Simon Butcheraad787f2016-01-26 22:13:58 +0000490 fflush( stdout );
Paul Bakker774180e2016-05-12 15:59:48 +0100491
492 unmet_dep_count = 0;
Ronald Cron75d26b52020-04-03 15:46:53 +0200493 missing_unmet_dependencies = 0;
Simon Butcheraad787f2016-01-26 22:13:58 +0000494 }
Andres Amaya Garcia3f50f512017-10-01 16:42:29 +0100495 else if( ret == DISPATCH_TEST_SUCCESS )
Simon Butcheraad787f2016-01-26 22:13:58 +0000496 {
Andres Amaya Garcia3f50f512017-10-01 16:42:29 +0100497 if( test_info.failed == 0 )
498 {
499 mbedtls_fprintf( stdout, "PASS\n" );
500 }
501 else
502 {
503 total_errors++;
504 mbedtls_fprintf( stdout, "FAILED\n" );
505 mbedtls_fprintf( stdout, " %s\n at line %d, %s\n",
506 test_info.test, test_info.line_no,
507 test_info.filename );
508 }
Simon Butcheraad787f2016-01-26 22:13:58 +0000509 fflush( stdout );
510 }
SimonB8ca7bc42016-04-17 23:24:50 +0100511 else if( ret == DISPATCH_INVALID_TEST_DATA )
Simon Butcheraad787f2016-01-26 22:13:58 +0000512 {
513 mbedtls_fprintf( stderr, "FAILED: FATAL PARSE ERROR\n" );
Hanno Becker75efa792017-07-23 10:23:43 +0100514 fclose( file );
Simon Butcheraad787f2016-01-26 22:13:58 +0000515 mbedtls_exit( 2 );
516 }
517 else
518 total_errors++;
519
Hanno Becker75efa792017-07-23 10:23:43 +0100520 if( ( ret = get_line( file, buf, sizeof( buf ) ) ) != 0 )
Simon Butcheraad787f2016-01-26 22:13:58 +0000521 break;
Hanno Becker75efa792017-07-23 10:23:43 +0100522 if( strlen( buf ) != 0 )
Simon Butcheraad787f2016-01-26 22:13:58 +0000523 {
524 mbedtls_fprintf( stderr, "Should be empty %d\n",
Hanno Becker75efa792017-07-23 10:23:43 +0100525 (int) strlen( buf ) );
Simon Butcheraad787f2016-01-26 22:13:58 +0000526 return( 1 );
527 }
Paul Bakker19343182013-08-16 13:31:10 +0200528 }
Hanno Becker75efa792017-07-23 10:23:43 +0100529 fclose( file );
Paul Bakker774180e2016-05-12 15:59:48 +0100530
531 /* In case we encounter early end of file */
532 for( i = 0; i < unmet_dep_count; i++ )
533 free( unmet_dependencies[i] );
Paul Bakker19343182013-08-16 13:31:10 +0200534 }
Paul Bakker19343182013-08-16 13:31:10 +0200535
Manuel Pégourié-Gonnard2cf5a7c2015-04-08 12:49:31 +0200536 mbedtls_fprintf( stdout, "\n----------------------------------------------------------------------------\n\n");
Paul Bakker19343182013-08-16 13:31:10 +0200537 if( total_errors == 0 )
Manuel Pégourié-Gonnard2cf5a7c2015-04-08 12:49:31 +0200538 mbedtls_fprintf( stdout, "PASSED" );
Paul Bakker19343182013-08-16 13:31:10 +0200539 else
Manuel Pégourié-Gonnard2cf5a7c2015-04-08 12:49:31 +0200540 mbedtls_fprintf( stdout, "FAILED" );
Paul Bakker19343182013-08-16 13:31:10 +0200541
Ronald Cron59f21392020-04-06 14:16:25 +0200542 mbedtls_fprintf( stdout, " (%u / %u tests (%u skipped))\n",
Paul Bakker19343182013-08-16 13:31:10 +0200543 total_tests - total_errors, total_tests, total_skipped );
544
Manuel Pégourié-Gonnard2cf5a7c2015-04-08 12:49:31 +0200545#if defined(MBEDTLS_MEMORY_BUFFER_ALLOC_C) && \
Manuel Pégourié-Gonnard765bb312014-11-27 11:55:27 +0100546 !defined(TEST_SUITE_MEMORY_BUFFER_ALLOC)
Manuel Pégourié-Gonnard2cf5a7c2015-04-08 12:49:31 +0200547#if defined(MBEDTLS_MEMORY_DEBUG)
548 mbedtls_memory_buffer_alloc_status();
Paul Bakker19343182013-08-16 13:31:10 +0200549#endif
Manuel Pégourié-Gonnard2cf5a7c2015-04-08 12:49:31 +0200550 mbedtls_memory_buffer_alloc_free();
Paul Bakker1337aff2013-09-29 14:45:34 +0200551#endif
Paul Bakker19343182013-08-16 13:31:10 +0200552
Paul Bakker19343182013-08-16 13:31:10 +0200553 return( total_errors != 0 );
554}