blob: b6e3104063b13a817cdbeabc336f5449fd5d69b3 [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
Mohammad Azim Khan0b3f00c2018-05-01 10:17:48 +0100229#if defined(__GNUC__)
230/* At high optimization levels (e.g. gcc -O3), this function may be
231 * inlined in run_test_snprintf. This can trigger a spurious warning about
232 * potential misuse of snprintf from gcc -Wformat-truncation (observed with
233 * gcc 7.2). This warning makes tests in run_test_snprintf redundant on gcc
234 * only. They are still valid for other compilers. Avoid this warning by
235 * forbidding inlining of this function by gcc. */
236__attribute__((__noinline__))
237#endif
Manuel Pégourié-Gonnard7b6dcbe2015-06-22 10:48:01 +0200238static int test_snprintf( size_t n, const char ref_buf[10], int ref_ret )
239{
240 int ret;
241 char buf[10] = "xxxxxxxxx";
Manuel Pégourié-Gonnard4b00f082015-06-26 11:24:32 +0200242 const char ref[10] = "xxxxxxxxx";
Manuel Pégourié-Gonnard7b6dcbe2015-06-22 10:48:01 +0200243
Mohammad Azim Khan0b3f00c2018-05-01 10:17:48 +0100244 if( n >= sizeof( buf ) )
245 return( -1 );
Manuel Pégourié-Gonnard7b6dcbe2015-06-22 10:48:01 +0200246 ret = mbedtls_snprintf( buf, n, "%s", "123" );
247 if( ret < 0 || (size_t) ret >= n )
248 ret = -1;
249
Manuel Pégourié-Gonnard4b00f082015-06-26 11:24:32 +0200250 if( strncmp( ref_buf, buf, sizeof( buf ) ) != 0 ||
251 ref_ret != ret ||
252 memcmp( buf + n, ref + n, sizeof( buf ) - n ) != 0 )
Manuel Pégourié-Gonnard7b6dcbe2015-06-22 10:48:01 +0200253 {
254 return( 1 );
255 }
256
257 return( 0 );
258}
259
260static int run_test_snprintf( void )
261{
262 return( test_snprintf( 0, "xxxxxxxxx", -1 ) != 0 ||
Manuel Pégourié-Gonnard4b00f082015-06-26 11:24:32 +0200263 test_snprintf( 1, "", -1 ) != 0 ||
264 test_snprintf( 2, "1", -1 ) != 0 ||
265 test_snprintf( 3, "12", -1 ) != 0 ||
266 test_snprintf( 4, "123", 3 ) != 0 ||
267 test_snprintf( 5, "123", 3 ) != 0 );
Manuel Pégourié-Gonnard7b6dcbe2015-06-22 10:48:01 +0200268}
269
Simon Butcheraad787f2016-01-26 22:13:58 +0000270int main(int argc, const char *argv[])
Paul Bakker19343182013-08-16 13:31:10 +0200271{
SimonB8ca7bc42016-04-17 23:24:50 +0100272 /* Local Configurations and options */
SimonB15942102016-04-25 21:34:49 +0100273 const char *default_filename = "TESTCASE_FILENAME";
Simon Butcheraad787f2016-01-26 22:13:58 +0000274 const char *test_filename = NULL;
275 const char **test_files = NULL;
SimonB8ca7bc42016-04-17 23:24:50 +0100276 int testfile_count = 0;
277 int option_verbose = 0;
278
279 /* Other Local variables */
280 int arg_index = 1;
281 const char *next_arg;
282 int testfile_index, ret, i, cnt;
283 int total_errors = 0, total_tests = 0, total_skipped = 0;
Paul Bakker19343182013-08-16 13:31:10 +0200284 FILE *file;
285 char buf[5000];
286 char *params[50];
Manuel Pégourié-Gonnardd14acbc2015-05-29 11:26:37 +0200287 void *pointer;
Andres AGea67eeb2016-11-02 10:17:00 +0000288#if defined(__unix__) || (defined(__APPLE__) && defined(__MACH__))
Simon Butchere0192962016-10-12 23:07:30 +0100289 int stdout_fd = -1;
Andres AGea67eeb2016-11-02 10:17:00 +0000290#endif /* __unix__ || __APPLE__ __MACH__ */
Paul Bakker19343182013-08-16 13:31:10 +0200291
Manuel Pégourié-Gonnard2cf5a7c2015-04-08 12:49:31 +0200292#if defined(MBEDTLS_MEMORY_BUFFER_ALLOC_C) && \
Manuel Pégourié-Gonnard765bb312014-11-27 11:55:27 +0100293 !defined(TEST_SUITE_MEMORY_BUFFER_ALLOC)
Paul Bakker1337aff2013-09-29 14:45:34 +0200294 unsigned char alloc_buf[1000000];
Darryl Green11999bb2018-03-13 15:22:58 +0000295#endif
Andrzej Kurekf13ca952018-04-18 04:14:31 -0400296 /* Platform setup should be called in the beginning */
297 ret = platform_setup();
298 if( ret != 0 )
Andrzej Kurek1152fa82018-04-13 05:15:17 -0400299 {
Andrzej Kurekf13ca952018-04-18 04:14:31 -0400300 mbedtls_fprintf( stderr,
301 "FATAL: Failed to initialize platform - error %d\n",
302 ret );
303 return( -1 );
Andrzej Kurek1152fa82018-04-13 05:15:17 -0400304 }
305#if defined(MBEDTLS_MEMORY_BUFFER_ALLOC_C) && \
306 !defined(TEST_SUITE_MEMORY_BUFFER_ALLOC)
Manuel Pégourié-Gonnard2cf5a7c2015-04-08 12:49:31 +0200307 mbedtls_memory_buffer_alloc_init( alloc_buf, sizeof(alloc_buf) );
Paul Bakker19343182013-08-16 13:31:10 +0200308#endif
309
Manuel Pégourié-Gonnardd14acbc2015-05-29 11:26:37 +0200310 /*
311 * The C standard doesn't guarantee that all-bits-0 is the representation
312 * of a NULL pointer. We do however use that in our code for initializing
313 * structures, which should work on every modern platform. Let's be sure.
314 */
315 memset( &pointer, 0, sizeof( void * ) );
316 if( pointer != NULL )
317 {
318 mbedtls_fprintf( stderr, "all-bits-zero is not a NULL pointer\n" );
Andrzej Kurek32a675f2018-04-13 06:16:04 -0400319 platform_teardown();
Manuel Pégourié-Gonnardd14acbc2015-05-29 11:26:37 +0200320 return( 1 );
321 }
322
Manuel Pégourié-Gonnard7b6dcbe2015-06-22 10:48:01 +0200323 /*
324 * Make sure we have a snprintf that correctly zero-terminates
325 */
326 if( run_test_snprintf() != 0 )
327 {
328 mbedtls_fprintf( stderr, "the snprintf implementation is broken\n" );
Andrzej Kurek32a675f2018-04-13 06:16:04 -0400329 platform_teardown();
Andrzej Kurekf13ca952018-04-18 04:14:31 -0400330 return( 1 );
Manuel Pégourié-Gonnard7b6dcbe2015-06-22 10:48:01 +0200331 }
332
SimonB8ca7bc42016-04-17 23:24:50 +0100333 while( arg_index < argc)
334 {
335 next_arg = argv[ arg_index ];
336
337 if( strcmp(next_arg, "--verbose" ) == 0 ||
338 strcmp(next_arg, "-v" ) == 0 )
339 {
340 option_verbose = 1;
341 }
342 else if( strcmp(next_arg, "--help" ) == 0 ||
343 strcmp(next_arg, "-h" ) == 0 )
344 {
345 mbedtls_fprintf( stdout, USAGE );
Andrzej Kurek32a675f2018-04-13 06:16:04 -0400346 platform_teardown();
SimonB8ca7bc42016-04-17 23:24:50 +0100347 mbedtls_exit( EXIT_SUCCESS );
348 }
349 else
350 {
351 /* Not an option, therefore treat all further arguments as the file
352 * list.
353 */
354 test_files = &argv[ arg_index ];
355 testfile_count = argc - arg_index;
356 }
357
358 arg_index++;
359 }
360
361 /* If no files were specified, assume a default */
362 if ( test_files == NULL || testfile_count == 0 )
Paul Bakker19343182013-08-16 13:31:10 +0200363 {
Simon Butcheraad787f2016-01-26 22:13:58 +0000364 test_files = &default_filename;
365 testfile_count = 1;
366 }
Paul Bakker19343182013-08-16 13:31:10 +0200367
Andres Amaya Garcia3f50f512017-10-01 16:42:29 +0100368 /* Initialize the struct that holds information about the last test */
369 memset( &test_info, 0, sizeof( test_info ) );
370
SimonB8ca7bc42016-04-17 23:24:50 +0100371 /* Now begin to execute the tests in the testfiles */
Simon Butcheraad787f2016-01-26 22:13:58 +0000372 for ( testfile_index = 0;
373 testfile_index < testfile_count;
374 testfile_index++ )
Paul Bakker19343182013-08-16 13:31:10 +0200375 {
Paul Bakker774180e2016-05-12 15:59:48 +0100376 int unmet_dep_count = 0;
377 char *unmet_dependencies[20];
378
Simon Butcheraad787f2016-01-26 22:13:58 +0000379 test_filename = test_files[ testfile_index ];
Paul Bakker19343182013-08-16 13:31:10 +0200380
Simon Butcheraad787f2016-01-26 22:13:58 +0000381 file = fopen( test_filename, "r" );
382 if( file == NULL )
Paul Bakker19343182013-08-16 13:31:10 +0200383 {
Simon Butcheraad787f2016-01-26 22:13:58 +0000384 mbedtls_fprintf( stderr, "Failed to open test file: %s\n",
385 test_filename );
Andrzej Kurek32a675f2018-04-13 06:16:04 -0400386 platform_teardown();
Simon Butcheraad787f2016-01-26 22:13:58 +0000387 return( 1 );
388 }
389
390 while( !feof( file ) )
391 {
Paul Bakker774180e2016-05-12 15:59:48 +0100392 if( unmet_dep_count > 0 )
393 {
Simon Butcher25731362016-09-30 13:11:29 +0100394 mbedtls_fprintf( stderr,
Janos Follath8ca53b52016-10-05 10:57:49 +0100395 "FATAL: Dep count larger than zero at start of loop\n" );
Andrzej Kurek32a675f2018-04-13 06:16:04 -0400396 platform_teardown();
Paul Bakker774180e2016-05-12 15:59:48 +0100397 mbedtls_exit( MBEDTLS_EXIT_FAILURE );
398 }
399 unmet_dep_count = 0;
Simon Butcheraad787f2016-01-26 22:13:58 +0000400
401 if( ( ret = get_line( file, buf, sizeof(buf) ) ) != 0 )
402 break;
Andres Amaya Garcia3f50f512017-10-01 16:42:29 +0100403 mbedtls_fprintf( stdout, "%s%.66s", test_info.failed ? "\n" : "", buf );
Simon Butcheraad787f2016-01-26 22:13:58 +0000404 mbedtls_fprintf( stdout, " " );
405 for( i = strlen( buf ) + 1; i < 67; i++ )
406 mbedtls_fprintf( stdout, "." );
407 mbedtls_fprintf( stdout, " " );
408 fflush( stdout );
409
410 total_tests++;
Paul Bakker19343182013-08-16 13:31:10 +0200411
412 if( ( ret = get_line( file, buf, sizeof(buf) ) ) != 0 )
413 break;
414 cnt = parse_arguments( buf, strlen(buf), params );
Paul Bakker19343182013-08-16 13:31:10 +0200415
Simon Butcheraad787f2016-01-26 22:13:58 +0000416 if( strcmp( params[0], "depends_on" ) == 0 )
417 {
418 for( i = 1; i < cnt; i++ )
SimonB8ca7bc42016-04-17 23:24:50 +0100419 {
420 if( dep_check( params[i] ) != DEPENDENCY_SUPPORTED )
421 {
Paul Bakker26b60bf2016-05-12 15:55:37 +0100422 if( 0 == option_verbose )
423 {
424 /* Only one count is needed if not verbose */
425 unmet_dep_count++;
426 break;
427 }
428
Paul Bakkera30a72f2016-05-12 15:52:48 +0100429 unmet_dependencies[ unmet_dep_count ] = strdup(params[i]);
430 if( unmet_dependencies[ unmet_dep_count ] == NULL )
SimonB8ca7bc42016-04-17 23:24:50 +0100431 {
Janos Follath8ca53b52016-10-05 10:57:49 +0100432 mbedtls_fprintf( stderr, "FATAL: Out of memory\n" );
Andrzej Kurek32a675f2018-04-13 06:16:04 -0400433 platform_teardown();
Janos Follath55abc212016-04-18 18:18:48 +0100434 mbedtls_exit( MBEDTLS_EXIT_FAILURE );
SimonB8ca7bc42016-04-17 23:24:50 +0100435 }
436 unmet_dep_count++;
437 }
438 }
Paul Bakker19343182013-08-16 13:31:10 +0200439
Simon Butcheraad787f2016-01-26 22:13:58 +0000440 if( ( ret = get_line( file, buf, sizeof(buf) ) ) != 0 )
441 break;
442 cnt = parse_arguments( buf, strlen(buf), params );
443 }
Andres Amaya Garcia3f50f512017-10-01 16:42:29 +0100444
SimonB8ca7bc42016-04-17 23:24:50 +0100445 // If there are no unmet dependencies execute the test
446 if( unmet_dep_count == 0 )
Simon Butcheraad787f2016-01-26 22:13:58 +0000447 {
Andres Amaya Garcia3f50f512017-10-01 16:42:29 +0100448 test_info.failed = 0;
Simon Butcher25731362016-09-30 13:11:29 +0100449
450#if defined(__unix__) || (defined(__APPLE__) && defined(__MACH__))
451 /* Suppress all output from the library unless we're verbose
452 * mode
453 */
454 if( !option_verbose )
455 {
Janos Follath8ca53b52016-10-05 10:57:49 +0100456 stdout_fd = redirect_output( &stdout, "/dev/null" );
457 if( stdout_fd == -1 )
Simon Butcher25731362016-09-30 13:11:29 +0100458 {
Andrzej Kurek32a675f2018-04-13 06:16:04 -0400459 platform_teardown();
Simon Butcher25731362016-09-30 13:11:29 +0100460 /* Redirection has failed with no stdout so exit */
Janos Follath8ca53b52016-10-05 10:57:49 +0100461 exit( 1 );
Simon Butcher25731362016-09-30 13:11:29 +0100462 }
463 }
464#endif /* __unix__ || __APPLE__ __MACH__ */
465
Simon Butcheraad787f2016-01-26 22:13:58 +0000466 ret = dispatch_test( cnt, params );
Simon Butcher25731362016-09-30 13:11:29 +0100467
468#if defined(__unix__) || (defined(__APPLE__) && defined(__MACH__))
Janos Follath8ca53b52016-10-05 10:57:49 +0100469 if( !option_verbose && restore_output( &stdout, stdout_fd ) )
Simon Butcher25731362016-09-30 13:11:29 +0100470 {
Simon Butcher25731362016-09-30 13:11:29 +0100471 /* Redirection has failed with no stdout so exit */
Andrzej Kurek32a675f2018-04-13 06:16:04 -0400472 platform_teardown();
Janos Follath8ca53b52016-10-05 10:57:49 +0100473 exit( 1 );
Simon Butcher25731362016-09-30 13:11:29 +0100474 }
475#endif /* __unix__ || __APPLE__ __MACH__ */
476
Simon Butcheraad787f2016-01-26 22:13:58 +0000477 }
478
SimonB8ca7bc42016-04-17 23:24:50 +0100479 if( unmet_dep_count > 0 || ret == DISPATCH_UNSUPPORTED_SUITE )
Simon Butcheraad787f2016-01-26 22:13:58 +0000480 {
481 total_skipped++;
Hanno Becker910f6622017-07-23 10:23:24 +0100482 mbedtls_fprintf( stdout, "----" );
SimonB8ca7bc42016-04-17 23:24:50 +0100483
484 if( 1 == option_verbose && ret == DISPATCH_UNSUPPORTED_SUITE )
485 {
Hanno Becker910f6622017-07-23 10:23:24 +0100486 mbedtls_fprintf( stdout, "\n Test Suite not enabled" );
SimonB8ca7bc42016-04-17 23:24:50 +0100487 }
488
489 if( 1 == option_verbose && unmet_dep_count > 0 )
490 {
Hanno Becker910f6622017-07-23 10:23:24 +0100491 mbedtls_fprintf( stdout, "\n Unmet dependencies: " );
Paul Bakker774180e2016-05-12 15:59:48 +0100492 for( i = 0; i < unmet_dep_count; i++ )
SimonB8ca7bc42016-04-17 23:24:50 +0100493 {
494 mbedtls_fprintf(stdout, "%s ",
Paul Bakker774180e2016-05-12 15:59:48 +0100495 unmet_dependencies[i]);
496 free(unmet_dependencies[i]);
SimonB8ca7bc42016-04-17 23:24:50 +0100497 }
SimonB8ca7bc42016-04-17 23:24:50 +0100498 }
Hanno Becker910f6622017-07-23 10:23:24 +0100499 mbedtls_fprintf( stdout, "\n" );
Simon Butcheraad787f2016-01-26 22:13:58 +0000500 fflush( stdout );
Paul Bakker774180e2016-05-12 15:59:48 +0100501
502 unmet_dep_count = 0;
Simon Butcheraad787f2016-01-26 22:13:58 +0000503 }
Andres Amaya Garcia3f50f512017-10-01 16:42:29 +0100504 else if( ret == DISPATCH_TEST_SUCCESS )
Simon Butcheraad787f2016-01-26 22:13:58 +0000505 {
Andres Amaya Garcia3f50f512017-10-01 16:42:29 +0100506 if( test_info.failed == 0 )
507 {
508 mbedtls_fprintf( stdout, "PASS\n" );
509 }
510 else
511 {
512 total_errors++;
513 mbedtls_fprintf( stdout, "FAILED\n" );
514 mbedtls_fprintf( stdout, " %s\n at line %d, %s\n",
515 test_info.test, test_info.line_no,
516 test_info.filename );
517 }
Simon Butcheraad787f2016-01-26 22:13:58 +0000518 fflush( stdout );
519 }
SimonB8ca7bc42016-04-17 23:24:50 +0100520 else if( ret == DISPATCH_INVALID_TEST_DATA )
Simon Butcheraad787f2016-01-26 22:13:58 +0000521 {
522 mbedtls_fprintf( stderr, "FAILED: FATAL PARSE ERROR\n" );
Hanno Becker75efa792017-07-23 10:23:43 +0100523 fclose( file );
Andrzej Kurek32a675f2018-04-13 06:16:04 -0400524 platform_teardown();
Simon Butcheraad787f2016-01-26 22:13:58 +0000525 mbedtls_exit( 2 );
526 }
527 else
528 total_errors++;
529
Hanno Becker75efa792017-07-23 10:23:43 +0100530 if( ( ret = get_line( file, buf, sizeof( buf ) ) ) != 0 )
Simon Butcheraad787f2016-01-26 22:13:58 +0000531 break;
Hanno Becker75efa792017-07-23 10:23:43 +0100532 if( strlen( buf ) != 0 )
Simon Butcheraad787f2016-01-26 22:13:58 +0000533 {
534 mbedtls_fprintf( stderr, "Should be empty %d\n",
Hanno Becker75efa792017-07-23 10:23:43 +0100535 (int) strlen( buf ) );
Andrzej Kurek32a675f2018-04-13 06:16:04 -0400536 platform_teardown();
Simon Butcheraad787f2016-01-26 22:13:58 +0000537 return( 1 );
538 }
Paul Bakker19343182013-08-16 13:31:10 +0200539 }
Hanno Becker75efa792017-07-23 10:23:43 +0100540 fclose( file );
Paul Bakker774180e2016-05-12 15:59:48 +0100541
542 /* In case we encounter early end of file */
543 for( i = 0; i < unmet_dep_count; i++ )
544 free( unmet_dependencies[i] );
Paul Bakker19343182013-08-16 13:31:10 +0200545 }
Paul Bakker19343182013-08-16 13:31:10 +0200546
Manuel Pégourié-Gonnard2cf5a7c2015-04-08 12:49:31 +0200547 mbedtls_fprintf( stdout, "\n----------------------------------------------------------------------------\n\n");
Paul Bakker19343182013-08-16 13:31:10 +0200548 if( total_errors == 0 )
Manuel Pégourié-Gonnard2cf5a7c2015-04-08 12:49:31 +0200549 mbedtls_fprintf( stdout, "PASSED" );
Paul Bakker19343182013-08-16 13:31:10 +0200550 else
Manuel Pégourié-Gonnard2cf5a7c2015-04-08 12:49:31 +0200551 mbedtls_fprintf( stdout, "FAILED" );
Paul Bakker19343182013-08-16 13:31:10 +0200552
Manuel Pégourié-Gonnard2cf5a7c2015-04-08 12:49:31 +0200553 mbedtls_fprintf( stdout, " (%d / %d tests (%d skipped))\n",
Paul Bakker19343182013-08-16 13:31:10 +0200554 total_tests - total_errors, total_tests, total_skipped );
555
Manuel Pégourié-Gonnard2cf5a7c2015-04-08 12:49:31 +0200556#if defined(MBEDTLS_MEMORY_BUFFER_ALLOC_C) && \
Manuel Pégourié-Gonnard765bb312014-11-27 11:55:27 +0100557 !defined(TEST_SUITE_MEMORY_BUFFER_ALLOC)
Manuel Pégourié-Gonnard2cf5a7c2015-04-08 12:49:31 +0200558#if defined(MBEDTLS_MEMORY_DEBUG)
559 mbedtls_memory_buffer_alloc_status();
Paul Bakker19343182013-08-16 13:31:10 +0200560#endif
Manuel Pégourié-Gonnard2cf5a7c2015-04-08 12:49:31 +0200561 mbedtls_memory_buffer_alloc_free();
Paul Bakker1337aff2013-09-29 14:45:34 +0200562#endif
Paul Bakker19343182013-08-16 13:31:10 +0200563
Simon Butchere0192962016-10-12 23:07:30 +0100564#if defined(__unix__) || (defined(__APPLE__) && defined(__MACH__))
565 if( stdout_fd != -1 )
566 close_output( stdout );
567#endif /* __unix__ || __APPLE__ __MACH__ */
568
Andrzej Kurek32a675f2018-04-13 06:16:04 -0400569 platform_teardown();
Paul Bakker19343182013-08-16 13:31:10 +0200570 return( total_errors != 0 );
571}