blob: 9b2fa2b97ed69df329ead9106a9f1272dea67ef8 [file] [log] [blame]
SimonB15942102016-04-25 21:34:49 +01001#line 1 "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 }
Paul Bakkerb34fef22013-08-20 12:06:33 +0200114#else
SimonB8ca7bc42016-04-17 23:24:50 +0100115 ret = DISPATCH_UNSUPPORTED_SUITE;
Paul Bakkerb34fef22013-08-20 12:06:33 +0200116#endif
Paul Bakker19343182013-08-16 13:31:10 +0200117 return( ret );
118}
119
SimonB152ea182016-02-15 23:27:28 +0000120
121/*----------------------------------------------------------------------------*/
122/* Main Test code */
123
SimonB15942102016-04-25 21:34:49 +0100124#line !LINE_NO! "main_test.function"
125
SimonB8ca7bc42016-04-17 23:24:50 +0100126#define USAGE \
127 "Usage: %s [OPTIONS] files...\n\n" \
128 " Command line arguments:\n" \
129 " files... One or more test data file. If no file is specified\n" \
130 " the followimg default test case is used:\n" \
131 " %s\n\n" \
132 " Options:\n" \
133 " -v | --verbose Display full information about each test\n" \
134 " -h | --help Display this information\n\n", \
135 argv[0], \
SimonB15942102016-04-25 21:34:49 +0100136 "TESTCASE_FILENAME"
SimonB8ca7bc42016-04-17 23:24:50 +0100137
138
Gilles Peskine964faeb2017-09-29 18:00:25 +0200139/** Retrieve one input line into buf, which must have room for len
140 * bytes. The trailing line break (if any) is stripped from the result.
141 * Lines beginning with the character '#' are skipped. Lines that are
142 * more than len-1 bytes long including the trailing line break are
143 * truncated; note that the following bytes remain in the input stream.
144 *
145 * \return 0 on success, -1 on error or end of file
146 */
Paul Bakker19343182013-08-16 13:31:10 +0200147int get_line( FILE *f, char *buf, size_t len )
148{
149 char *ret;
150
Gilles Peskine964faeb2017-09-29 18:00:25 +0200151 do
Gilles Peskineb04e2c32017-09-29 15:45:12 +0200152 {
153 ret = fgets( buf, len, f );
154 if( ret == NULL )
155 return( -1 );
Gilles Peskineb04e2c32017-09-29 15:45:12 +0200156 }
Gilles Peskine964faeb2017-09-29 18:00:25 +0200157 while( buf[0] == '#' );
158
159 ret = buf + strlen( buf );
160 if( ret-- > buf && *ret == '\n' )
161 *ret = '\0';
162 if( ret-- > buf && *ret == '\r' )
163 *ret = '\0';
Paul Bakker19343182013-08-16 13:31:10 +0200164
165 return( 0 );
166}
167
168int parse_arguments( char *buf, size_t len, char *params[50] )
169{
170 int cnt = 0, i;
171 char *cur = buf;
172 char *p = buf, *q;
173
174 params[cnt++] = cur;
175
176 while( *p != '\0' && p < buf + len )
177 {
178 if( *p == '\\' )
179 {
Manuel Pégourié-Gonnard2d5f1422014-01-22 16:01:17 +0100180 p++;
181 p++;
Paul Bakker19343182013-08-16 13:31:10 +0200182 continue;
183 }
184 if( *p == ':' )
185 {
186 if( p + 1 < buf + len )
187 {
188 cur = p + 1;
189 params[cnt++] = cur;
190 }
191 *p = '\0';
192 }
193
Manuel Pégourié-Gonnard2d5f1422014-01-22 16:01:17 +0100194 p++;
Paul Bakker19343182013-08-16 13:31:10 +0200195 }
196
SimonB0269dad2016-02-17 23:34:30 +0000197 /* Replace newlines, question marks and colons in strings */
Paul Bakker19343182013-08-16 13:31:10 +0200198 for( i = 0; i < cnt; i++ )
199 {
200 p = params[i];
201 q = params[i];
202
203 while( *p != '\0' )
204 {
205 if( *p == '\\' && *(p + 1) == 'n' )
206 {
207 p += 2;
208 *(q++) = '\n';
209 }
210 else if( *p == '\\' && *(p + 1) == ':' )
211 {
212 p += 2;
213 *(q++) = ':';
214 }
215 else if( *p == '\\' && *(p + 1) == '?' )
216 {
217 p += 2;
218 *(q++) = '?';
219 }
220 else
221 *(q++) = *(p++);
222 }
223 *q = '\0';
224 }
225
226 return( cnt );
227}
228
Manuel Pégourié-Gonnard7b6dcbe2015-06-22 10:48:01 +0200229static int test_snprintf( size_t n, const char ref_buf[10], int ref_ret )
230{
231 int ret;
232 char buf[10] = "xxxxxxxxx";
Manuel Pégourié-Gonnard4b00f082015-06-26 11:24:32 +0200233 const char ref[10] = "xxxxxxxxx";
Manuel Pégourié-Gonnard7b6dcbe2015-06-22 10:48:01 +0200234
235 ret = mbedtls_snprintf( buf, n, "%s", "123" );
236 if( ret < 0 || (size_t) ret >= n )
237 ret = -1;
238
Manuel Pégourié-Gonnard4b00f082015-06-26 11:24:32 +0200239 if( strncmp( ref_buf, buf, sizeof( buf ) ) != 0 ||
240 ref_ret != ret ||
241 memcmp( buf + n, ref + n, sizeof( buf ) - n ) != 0 )
Manuel Pégourié-Gonnard7b6dcbe2015-06-22 10:48:01 +0200242 {
243 return( 1 );
244 }
245
246 return( 0 );
247}
248
249static int run_test_snprintf( void )
250{
251 return( test_snprintf( 0, "xxxxxxxxx", -1 ) != 0 ||
Manuel Pégourié-Gonnard4b00f082015-06-26 11:24:32 +0200252 test_snprintf( 1, "", -1 ) != 0 ||
253 test_snprintf( 2, "1", -1 ) != 0 ||
254 test_snprintf( 3, "12", -1 ) != 0 ||
255 test_snprintf( 4, "123", 3 ) != 0 ||
256 test_snprintf( 5, "123", 3 ) != 0 );
Manuel Pégourié-Gonnard7b6dcbe2015-06-22 10:48:01 +0200257}
258
Simon Butcheraad787f2016-01-26 22:13:58 +0000259int main(int argc, const char *argv[])
Paul Bakker19343182013-08-16 13:31:10 +0200260{
SimonB8ca7bc42016-04-17 23:24:50 +0100261 /* Local Configurations and options */
SimonB15942102016-04-25 21:34:49 +0100262 const char *default_filename = "TESTCASE_FILENAME";
Simon Butcheraad787f2016-01-26 22:13:58 +0000263 const char *test_filename = NULL;
264 const char **test_files = NULL;
Ronald Cron59f21392020-04-06 14:16:25 +0200265 size_t testfile_count = 0;
SimonB8ca7bc42016-04-17 23:24:50 +0100266 int option_verbose = 0;
267
268 /* Other Local variables */
269 int arg_index = 1;
270 const char *next_arg;
Ronald Cron59f21392020-04-06 14:16:25 +0200271 size_t testfile_index, i, cnt;
272 int ret;
273 unsigned total_errors = 0, total_tests = 0, total_skipped = 0;
Paul Bakker19343182013-08-16 13:31:10 +0200274 FILE *file;
275 char buf[5000];
276 char *params[50];
Manuel Pégourié-Gonnardd14acbc2015-05-29 11:26:37 +0200277 void *pointer;
Andres AGea67eeb2016-11-02 10:17:00 +0000278#if defined(__unix__) || (defined(__APPLE__) && defined(__MACH__))
Simon Butchere0192962016-10-12 23:07:30 +0100279 int stdout_fd = -1;
Andres AGea67eeb2016-11-02 10:17:00 +0000280#endif /* __unix__ || __APPLE__ __MACH__ */
Paul Bakker19343182013-08-16 13:31:10 +0200281
Manuel Pégourié-Gonnard2cf5a7c2015-04-08 12:49:31 +0200282#if defined(MBEDTLS_MEMORY_BUFFER_ALLOC_C) && \
Manuel Pégourié-Gonnard765bb312014-11-27 11:55:27 +0100283 !defined(TEST_SUITE_MEMORY_BUFFER_ALLOC)
Paul Bakker1337aff2013-09-29 14:45:34 +0200284 unsigned char alloc_buf[1000000];
Manuel Pégourié-Gonnard2cf5a7c2015-04-08 12:49:31 +0200285 mbedtls_memory_buffer_alloc_init( alloc_buf, sizeof(alloc_buf) );
Paul Bakker19343182013-08-16 13:31:10 +0200286#endif
287
Manuel Pégourié-Gonnardd14acbc2015-05-29 11:26:37 +0200288 /*
289 * The C standard doesn't guarantee that all-bits-0 is the representation
290 * of a NULL pointer. We do however use that in our code for initializing
291 * structures, which should work on every modern platform. Let's be sure.
292 */
293 memset( &pointer, 0, sizeof( void * ) );
294 if( pointer != NULL )
295 {
296 mbedtls_fprintf( stderr, "all-bits-zero is not a NULL pointer\n" );
297 return( 1 );
298 }
299
Manuel Pégourié-Gonnard7b6dcbe2015-06-22 10:48:01 +0200300 /*
301 * Make sure we have a snprintf that correctly zero-terminates
302 */
303 if( run_test_snprintf() != 0 )
304 {
305 mbedtls_fprintf( stderr, "the snprintf implementation is broken\n" );
306 return( 0 );
307 }
308
SimonB8ca7bc42016-04-17 23:24:50 +0100309 while( arg_index < argc)
310 {
311 next_arg = argv[ arg_index ];
312
313 if( strcmp(next_arg, "--verbose" ) == 0 ||
314 strcmp(next_arg, "-v" ) == 0 )
315 {
316 option_verbose = 1;
317 }
318 else if( strcmp(next_arg, "--help" ) == 0 ||
319 strcmp(next_arg, "-h" ) == 0 )
320 {
321 mbedtls_fprintf( stdout, USAGE );
322 mbedtls_exit( EXIT_SUCCESS );
323 }
324 else
325 {
326 /* Not an option, therefore treat all further arguments as the file
327 * list.
328 */
329 test_files = &argv[ arg_index ];
330 testfile_count = argc - arg_index;
331 }
332
333 arg_index++;
334 }
335
336 /* If no files were specified, assume a default */
337 if ( test_files == NULL || testfile_count == 0 )
Paul Bakker19343182013-08-16 13:31:10 +0200338 {
Simon Butcheraad787f2016-01-26 22:13:58 +0000339 test_files = &default_filename;
340 testfile_count = 1;
341 }
Paul Bakker19343182013-08-16 13:31:10 +0200342
Andres Amaya Garcia3f50f512017-10-01 16:42:29 +0100343 /* Initialize the struct that holds information about the last test */
344 memset( &test_info, 0, sizeof( test_info ) );
345
SimonB8ca7bc42016-04-17 23:24:50 +0100346 /* Now begin to execute the tests in the testfiles */
Simon Butcheraad787f2016-01-26 22:13:58 +0000347 for ( testfile_index = 0;
348 testfile_index < testfile_count;
349 testfile_index++ )
Paul Bakker19343182013-08-16 13:31:10 +0200350 {
Ronald Cron59f21392020-04-06 14:16:25 +0200351 size_t unmet_dep_count = 0;
Gilles Peskine67665502020-03-31 10:57:53 +0200352 char *unmet_dependencies[20]; /* only filled when verbose != 0 */
Ronald Cron75d26b52020-04-03 15:46:53 +0200353 int missing_unmet_dependencies = 0;
Paul Bakker774180e2016-05-12 15:59:48 +0100354
Simon Butcheraad787f2016-01-26 22:13:58 +0000355 test_filename = test_files[ testfile_index ];
Paul Bakker19343182013-08-16 13:31:10 +0200356
Simon Butcheraad787f2016-01-26 22:13:58 +0000357 file = fopen( test_filename, "r" );
358 if( file == NULL )
Paul Bakker19343182013-08-16 13:31:10 +0200359 {
Simon Butcheraad787f2016-01-26 22:13:58 +0000360 mbedtls_fprintf( stderr, "Failed to open test file: %s\n",
361 test_filename );
362 return( 1 );
363 }
364
365 while( !feof( file ) )
366 {
Paul Bakker774180e2016-05-12 15:59:48 +0100367 if( unmet_dep_count > 0 )
368 {
Simon Butcher25731362016-09-30 13:11:29 +0100369 mbedtls_fprintf( stderr,
Janos Follath8ca53b52016-10-05 10:57:49 +0100370 "FATAL: Dep count larger than zero at start of loop\n" );
Paul Bakker774180e2016-05-12 15:59:48 +0100371 mbedtls_exit( MBEDTLS_EXIT_FAILURE );
372 }
373 unmet_dep_count = 0;
Gilles Peskine67665502020-03-31 10:57:53 +0200374 memset( unmet_dependencies, 0, sizeof( unmet_dependencies ) );
Ronald Cron75d26b52020-04-03 15:46:53 +0200375 missing_unmet_dependencies = 0;
Simon Butcheraad787f2016-01-26 22:13:58 +0000376
377 if( ( ret = get_line( file, buf, sizeof(buf) ) ) != 0 )
378 break;
Andres Amaya Garcia3f50f512017-10-01 16:42:29 +0100379 mbedtls_fprintf( stdout, "%s%.66s", test_info.failed ? "\n" : "", buf );
Simon Butcheraad787f2016-01-26 22:13:58 +0000380 mbedtls_fprintf( stdout, " " );
381 for( i = strlen( buf ) + 1; i < 67; i++ )
382 mbedtls_fprintf( stdout, "." );
383 mbedtls_fprintf( stdout, " " );
384 fflush( stdout );
385
386 total_tests++;
Paul Bakker19343182013-08-16 13:31:10 +0200387
388 if( ( ret = get_line( file, buf, sizeof(buf) ) ) != 0 )
389 break;
390 cnt = parse_arguments( buf, strlen(buf), params );
Paul Bakker19343182013-08-16 13:31:10 +0200391
Simon Butcheraad787f2016-01-26 22:13:58 +0000392 if( strcmp( params[0], "depends_on" ) == 0 )
393 {
394 for( i = 1; i < cnt; i++ )
SimonB8ca7bc42016-04-17 23:24:50 +0100395 {
396 if( dep_check( params[i] ) != DEPENDENCY_SUPPORTED )
397 {
Ronald Cron1d3eab62020-04-03 15:36:16 +0200398 if( unmet_dep_count <
399 ARRAY_LENGTH( unmet_dependencies ) )
Paul Bakker26b60bf2016-05-12 15:55:37 +0100400 {
Ronald Cron1d3eab62020-04-03 15:36:16 +0200401 if( 0 != option_verbose )
Gilles Peskine67665502020-03-31 10:57:53 +0200402 {
Ronald Cron1d3eab62020-04-03 15:36:16 +0200403 unmet_dependencies[unmet_dep_count] =
404 strdup( params[i] );
405 if( unmet_dependencies[unmet_dep_count] == NULL )
406 {
407 mbedtls_fprintf( stderr,
408 "FATAL: Out of memory\n" );
409 mbedtls_exit( MBEDTLS_EXIT_FAILURE );
410 }
Gilles Peskine67665502020-03-31 10:57:53 +0200411 }
Ronald Cron1d3eab62020-04-03 15:36:16 +0200412 unmet_dep_count++;
SimonB8ca7bc42016-04-17 23:24:50 +0100413 }
Ronald Cron75d26b52020-04-03 15:46:53 +0200414 else
415 {
416 missing_unmet_dependencies = 1;
417 }
SimonB8ca7bc42016-04-17 23:24:50 +0100418 }
419 }
Paul Bakker19343182013-08-16 13:31:10 +0200420
Simon Butcheraad787f2016-01-26 22:13:58 +0000421 if( ( ret = get_line( file, buf, sizeof(buf) ) ) != 0 )
422 break;
423 cnt = parse_arguments( buf, strlen(buf), params );
424 }
Andres Amaya Garcia3f50f512017-10-01 16:42:29 +0100425
SimonB8ca7bc42016-04-17 23:24:50 +0100426 // If there are no unmet dependencies execute the test
427 if( unmet_dep_count == 0 )
Simon Butcheraad787f2016-01-26 22:13:58 +0000428 {
Andres Amaya Garcia3f50f512017-10-01 16:42:29 +0100429 test_info.failed = 0;
Simon Butcher25731362016-09-30 13:11:29 +0100430
431#if defined(__unix__) || (defined(__APPLE__) && defined(__MACH__))
432 /* Suppress all output from the library unless we're verbose
433 * mode
434 */
435 if( !option_verbose )
436 {
Janos Follath8ca53b52016-10-05 10:57:49 +0100437 stdout_fd = redirect_output( &stdout, "/dev/null" );
438 if( stdout_fd == -1 )
Simon Butcher25731362016-09-30 13:11:29 +0100439 {
440 /* Redirection has failed with no stdout so exit */
Janos Follath8ca53b52016-10-05 10:57:49 +0100441 exit( 1 );
Simon Butcher25731362016-09-30 13:11:29 +0100442 }
443 }
444#endif /* __unix__ || __APPLE__ __MACH__ */
445
Simon Butcheraad787f2016-01-26 22:13:58 +0000446 ret = dispatch_test( cnt, params );
Simon Butcher25731362016-09-30 13:11:29 +0100447
448#if defined(__unix__) || (defined(__APPLE__) && defined(__MACH__))
Janos Follath8ca53b52016-10-05 10:57:49 +0100449 if( !option_verbose && restore_output( &stdout, stdout_fd ) )
Simon Butcher25731362016-09-30 13:11:29 +0100450 {
Simon Butcher25731362016-09-30 13:11:29 +0100451 /* Redirection has failed with no stdout so exit */
Janos Follath8ca53b52016-10-05 10:57:49 +0100452 exit( 1 );
Simon Butcher25731362016-09-30 13:11:29 +0100453 }
454#endif /* __unix__ || __APPLE__ __MACH__ */
455
Simon Butcheraad787f2016-01-26 22:13:58 +0000456 }
457
SimonB8ca7bc42016-04-17 23:24:50 +0100458 if( unmet_dep_count > 0 || ret == DISPATCH_UNSUPPORTED_SUITE )
Simon Butcheraad787f2016-01-26 22:13:58 +0000459 {
460 total_skipped++;
Hanno Becker910f6622017-07-23 10:23:24 +0100461 mbedtls_fprintf( stdout, "----" );
SimonB8ca7bc42016-04-17 23:24:50 +0100462
463 if( 1 == option_verbose && ret == DISPATCH_UNSUPPORTED_SUITE )
464 {
Hanno Becker910f6622017-07-23 10:23:24 +0100465 mbedtls_fprintf( stdout, "\n Test Suite not enabled" );
SimonB8ca7bc42016-04-17 23:24:50 +0100466 }
467
468 if( 1 == option_verbose && unmet_dep_count > 0 )
469 {
Hanno Becker910f6622017-07-23 10:23:24 +0100470 mbedtls_fprintf( stdout, "\n Unmet dependencies: " );
Paul Bakker774180e2016-05-12 15:59:48 +0100471 for( i = 0; i < unmet_dep_count; i++ )
SimonB8ca7bc42016-04-17 23:24:50 +0100472 {
473 mbedtls_fprintf(stdout, "%s ",
Paul Bakker774180e2016-05-12 15:59:48 +0100474 unmet_dependencies[i]);
475 free(unmet_dependencies[i]);
SimonB8ca7bc42016-04-17 23:24:50 +0100476 }
Ronald Cron75d26b52020-04-03 15:46:53 +0200477 if( missing_unmet_dependencies )
478 mbedtls_fprintf( stdout, "..." );
SimonB8ca7bc42016-04-17 23:24:50 +0100479 }
Hanno Becker910f6622017-07-23 10:23:24 +0100480 mbedtls_fprintf( stdout, "\n" );
Simon Butcheraad787f2016-01-26 22:13:58 +0000481 fflush( stdout );
Paul Bakker774180e2016-05-12 15:59:48 +0100482
483 unmet_dep_count = 0;
Ronald Cron75d26b52020-04-03 15:46:53 +0200484 missing_unmet_dependencies = 0;
Simon Butcheraad787f2016-01-26 22:13:58 +0000485 }
Andres Amaya Garcia3f50f512017-10-01 16:42:29 +0100486 else if( ret == DISPATCH_TEST_SUCCESS )
Simon Butcheraad787f2016-01-26 22:13:58 +0000487 {
Andres Amaya Garcia3f50f512017-10-01 16:42:29 +0100488 if( test_info.failed == 0 )
489 {
490 mbedtls_fprintf( stdout, "PASS\n" );
491 }
492 else
493 {
494 total_errors++;
495 mbedtls_fprintf( stdout, "FAILED\n" );
496 mbedtls_fprintf( stdout, " %s\n at line %d, %s\n",
497 test_info.test, test_info.line_no,
498 test_info.filename );
499 }
Simon Butcheraad787f2016-01-26 22:13:58 +0000500 fflush( stdout );
501 }
SimonB8ca7bc42016-04-17 23:24:50 +0100502 else if( ret == DISPATCH_INVALID_TEST_DATA )
Simon Butcheraad787f2016-01-26 22:13:58 +0000503 {
504 mbedtls_fprintf( stderr, "FAILED: FATAL PARSE ERROR\n" );
Hanno Becker75efa792017-07-23 10:23:43 +0100505 fclose( file );
Simon Butcheraad787f2016-01-26 22:13:58 +0000506 mbedtls_exit( 2 );
507 }
508 else
509 total_errors++;
510
Hanno Becker75efa792017-07-23 10:23:43 +0100511 if( ( ret = get_line( file, buf, sizeof( buf ) ) ) != 0 )
Simon Butcheraad787f2016-01-26 22:13:58 +0000512 break;
Hanno Becker75efa792017-07-23 10:23:43 +0100513 if( strlen( buf ) != 0 )
Simon Butcheraad787f2016-01-26 22:13:58 +0000514 {
515 mbedtls_fprintf( stderr, "Should be empty %d\n",
Hanno Becker75efa792017-07-23 10:23:43 +0100516 (int) strlen( buf ) );
Simon Butcheraad787f2016-01-26 22:13:58 +0000517 return( 1 );
518 }
Paul Bakker19343182013-08-16 13:31:10 +0200519 }
Hanno Becker75efa792017-07-23 10:23:43 +0100520 fclose( file );
Paul Bakker774180e2016-05-12 15:59:48 +0100521
522 /* In case we encounter early end of file */
523 for( i = 0; i < unmet_dep_count; i++ )
524 free( unmet_dependencies[i] );
Paul Bakker19343182013-08-16 13:31:10 +0200525 }
Paul Bakker19343182013-08-16 13:31:10 +0200526
Manuel Pégourié-Gonnard2cf5a7c2015-04-08 12:49:31 +0200527 mbedtls_fprintf( stdout, "\n----------------------------------------------------------------------------\n\n");
Paul Bakker19343182013-08-16 13:31:10 +0200528 if( total_errors == 0 )
Manuel Pégourié-Gonnard2cf5a7c2015-04-08 12:49:31 +0200529 mbedtls_fprintf( stdout, "PASSED" );
Paul Bakker19343182013-08-16 13:31:10 +0200530 else
Manuel Pégourié-Gonnard2cf5a7c2015-04-08 12:49:31 +0200531 mbedtls_fprintf( stdout, "FAILED" );
Paul Bakker19343182013-08-16 13:31:10 +0200532
Ronald Cron59f21392020-04-06 14:16:25 +0200533 mbedtls_fprintf( stdout, " (%u / %u tests (%u skipped))\n",
Paul Bakker19343182013-08-16 13:31:10 +0200534 total_tests - total_errors, total_tests, total_skipped );
535
Manuel Pégourié-Gonnard2cf5a7c2015-04-08 12:49:31 +0200536#if defined(MBEDTLS_MEMORY_BUFFER_ALLOC_C) && \
Manuel Pégourié-Gonnard765bb312014-11-27 11:55:27 +0100537 !defined(TEST_SUITE_MEMORY_BUFFER_ALLOC)
Manuel Pégourié-Gonnard2cf5a7c2015-04-08 12:49:31 +0200538#if defined(MBEDTLS_MEMORY_DEBUG)
539 mbedtls_memory_buffer_alloc_status();
Paul Bakker19343182013-08-16 13:31:10 +0200540#endif
Manuel Pégourié-Gonnard2cf5a7c2015-04-08 12:49:31 +0200541 mbedtls_memory_buffer_alloc_free();
Paul Bakker1337aff2013-09-29 14:45:34 +0200542#endif
Paul Bakker19343182013-08-16 13:31:10 +0200543
Simon Butchere0192962016-10-12 23:07:30 +0100544#if defined(__unix__) || (defined(__APPLE__) && defined(__MACH__))
545 if( stdout_fd != -1 )
546 close_output( stdout );
547#endif /* __unix__ || __APPLE__ __MACH__ */
548
Paul Bakker19343182013-08-16 13:31:10 +0200549 return( total_errors != 0 );
550}