• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
1#line 2 "suites/host_test.function"
2
3/**
4 * \brief       Verifies that string is in string parameter format i.e. "<str>"
5 *              It also strips enclosing '"' from the input string.
6 *
7 * \param str   String parameter.
8 *
9 * \return      0 if success else 1
10 */
11int verify_string( char **str )
12{
13    if( ( *str )[0] != '"' ||
14        ( *str )[strlen( *str ) - 1] != '"' )
15    {
16        mbedtls_fprintf( stderr,
17            "Expected string (with \"\") for parameter and got: %s\n", *str );
18        return( -1 );
19    }
20
21    ( *str )++;
22    ( *str )[strlen( *str ) - 1] = '\0';
23
24    return( 0 );
25}
26
27/**
28 * \brief       Verifies that string is an integer. Also gives the converted
29 *              integer value.
30 *
31 * \param str   Input string.
32 * \param value Pointer to int for output value.
33 *
34 * \return      0 if success else 1
35 */
36int verify_int( char *str, int32_t *value )
37{
38    size_t i;
39    int minus = 0;
40    int digits = 1;
41    int hex = 0;
42
43    for( i = 0; i < strlen( str ); i++ )
44    {
45        if( i == 0 && str[i] == '-' )
46        {
47            minus = 1;
48            continue;
49        }
50
51        if( ( ( minus && i == 2 ) || ( !minus && i == 1 ) ) &&
52            str[i - 1] == '0' && ( str[i] == 'x' || str[i] == 'X' ) )
53        {
54            hex = 1;
55            continue;
56        }
57
58        if( ! ( ( str[i] >= '0' && str[i] <= '9' ) ||
59                ( hex && ( ( str[i] >= 'a' && str[i] <= 'f' ) ||
60                           ( str[i] >= 'A' && str[i] <= 'F' ) ) ) ) )
61        {
62            digits = 0;
63            break;
64        }
65    }
66
67    if( digits )
68    {
69        if( hex )
70            *value = strtol( str, NULL, 16 );
71        else
72            *value = strtol( str, NULL, 10 );
73
74        return( 0 );
75    }
76
77    mbedtls_fprintf( stderr,
78                    "Expected integer for parameter and got: %s\n", str );
79    return( KEY_VALUE_MAPPING_NOT_FOUND );
80}
81
82
83/**
84 * \brief       Usage string.
85 *
86 */
87#define USAGE \
88    "Usage: %s [OPTIONS] files...\n\n" \
89    "   Command line arguments:\n" \
90    "     files...          One or more test data files. If no file is\n" \
91    "                       specified the following default test case\n" \
92    "                       file is used:\n" \
93    "                           %s\n\n" \
94    "   Options:\n" \
95    "     -v | --verbose    Display full information about each test\n" \
96    "     -h | --help       Display this information\n\n", \
97    argv[0], \
98    "TESTCASE_FILENAME"
99
100
101/**
102 * \brief       Read a line from the passed file pointer.
103 *
104 * \param f     FILE pointer
105 * \param buf   Pointer to memory to hold read line.
106 * \param len   Length of the buf.
107 *
108 * \return      0 if success else -1
109 */
110int get_line( FILE *f, char *buf, size_t len )
111{
112    char *ret;
113    int i = 0, str_len = 0, has_string = 0;
114
115    /* Read until we get a valid line */
116    do
117    {
118        ret = fgets( buf, len, f );
119        if( ret == NULL )
120            return( -1 );
121
122        str_len = strlen( buf );
123
124        /* Skip empty line and comment */
125        if ( str_len == 0 || buf[0] == '#' )
126            continue;
127        has_string = 0;
128        for ( i = 0; i < str_len; i++ )
129        {
130            char c = buf[i];
131            if ( c != ' ' && c != '\t' && c != '\n' &&
132                 c != '\v' && c != '\f' && c != '\r' )
133            {
134                has_string = 1;
135                break;
136            }
137        }
138    } while( !has_string );
139
140    /* Strip new line and carriage return */
141    ret = buf + strlen( buf );
142    if( ret-- > buf && *ret == '\n' )
143        *ret = '\0';
144    if( ret-- > buf && *ret == '\r' )
145        *ret = '\0';
146
147    return( 0 );
148}
149
150/**
151 * \brief       Splits string delimited by ':'. Ignores '\:'.
152 *
153 * \param buf           Input string
154 * \param len           Input string length
155 * \param params        Out params found
156 * \param params_len    Out params array len
157 *
158 * \return      Count of strings found.
159 */
160static int parse_arguments( char *buf, size_t len, char **params,
161                            size_t params_len )
162{
163    size_t cnt = 0, i;
164    char *cur = buf;
165    char *p = buf, *q;
166
167    params[cnt++] = cur;
168
169    while( *p != '\0' && p < ( buf + len ) )
170    {
171        if( *p == '\\' )
172        {
173            p++;
174            p++;
175            continue;
176        }
177        if( *p == ':' )
178        {
179            if( p + 1 < buf + len )
180            {
181                cur = p + 1;
182                TEST_HELPER_ASSERT( cnt < params_len );
183                params[cnt++] = cur;
184            }
185            *p = '\0';
186        }
187
188        p++;
189    }
190
191    /* Replace newlines, question marks and colons in strings */
192    for( i = 0; i < cnt; i++ )
193    {
194        p = params[i];
195        q = params[i];
196
197        while( *p != '\0' )
198        {
199            if( *p == '\\' && *( p + 1 ) == 'n' )
200            {
201                p += 2;
202                *( q++ ) = '\n';
203            }
204            else if( *p == '\\' && *( p + 1 ) == ':' )
205            {
206                p += 2;
207                *( q++ ) = ':';
208            }
209            else if( *p == '\\' && *( p + 1 ) == '?' )
210            {
211                p += 2;
212                *( q++ ) = '?';
213            }
214            else
215                *( q++ ) = *( p++ );
216        }
217        *q = '\0';
218    }
219
220    return( cnt );
221}
222
223/**
224 * \brief       Converts parameters into test function consumable parameters.
225 *              Example: Input:  {"int", "0", "char*", "Hello",
226 *                                "hex", "abef", "exp", "1"}
227 *                      Output:  {
228 *                                0,                // Verified int
229 *                                "Hello",          // Verified string
230 *                                2, { 0xab, 0xef },// Converted len,hex pair
231 *                                9600              // Evaluated expression
232 *                               }
233 *
234 *
235 * \param cnt               Parameter array count.
236 * \param params            Out array of found parameters.
237 * \param int_params_store  Memory for storing processed integer parameters.
238 *
239 * \return      0 for success else 1
240 */
241static int convert_params( size_t cnt , char ** params , int32_t * int_params_store )
242{
243    char ** cur = params;
244    char ** out = params;
245    int ret = DISPATCH_TEST_SUCCESS;
246
247    while ( cur < params + cnt )
248    {
249        char * type = *cur++;
250        char * val = *cur++;
251
252        if ( strcmp( type, "char*" ) == 0 )
253        {
254            if ( verify_string( &val ) == 0 )
255            {
256              *out++ = val;
257            }
258            else
259            {
260                ret = ( DISPATCH_INVALID_TEST_DATA );
261                break;
262            }
263        }
264        else if ( strcmp( type, "int" ) == 0 )
265        {
266            if ( verify_int( val, int_params_store ) == 0 )
267            {
268              *out++ = (char *) int_params_store++;
269            }
270            else
271            {
272                ret = ( DISPATCH_INVALID_TEST_DATA );
273                break;
274            }
275        }
276        else if ( strcmp( type, "hex" ) == 0 )
277        {
278            if ( verify_string( &val ) == 0 )
279            {
280                size_t len;
281
282                TEST_HELPER_ASSERT(
283                  mbedtls_test_unhexify( (unsigned char *) val, strlen( val ),
284                                         val, &len ) == 0 );
285
286                *int_params_store = len;
287                *out++ = val;
288                *out++ = (char *)(int_params_store++);
289            }
290            else
291            {
292                ret = ( DISPATCH_INVALID_TEST_DATA );
293                break;
294            }
295        }
296        else if ( strcmp( type, "exp" ) == 0 )
297        {
298            int exp_id = strtol( val, NULL, 10 );
299            if ( get_expression ( exp_id, int_params_store ) == 0 )
300            {
301              *out++ = (char *)int_params_store++;
302            }
303            else
304            {
305              ret = ( DISPATCH_INVALID_TEST_DATA );
306              break;
307            }
308        }
309        else
310        {
311          ret = ( DISPATCH_INVALID_TEST_DATA );
312          break;
313        }
314    }
315    return( ret );
316}
317
318/**
319 * \brief       Tests snprintf implementation with test input.
320 *
321 * \note
322 * At high optimization levels (e.g. gcc -O3), this function may be
323 * inlined in run_test_snprintf. This can trigger a spurious warning about
324 * potential misuse of snprintf from gcc -Wformat-truncation (observed with
325 * gcc 7.2). This warning makes tests in run_test_snprintf redundant on gcc
326 * only. They are still valid for other compilers. Avoid this warning by
327 * forbidding inlining of this function by gcc.
328 *
329 * \param n         Buffer test length.
330 * \param ref_buf   Expected buffer.
331 * \param ref_ret   Expected snprintf return value.
332 *
333 * \return      0 for success else 1
334 */
335#if defined(__GNUC__)
336__attribute__((__noinline__))
337#endif
338static int test_snprintf( size_t n, const char *ref_buf, int ref_ret )
339{
340    int ret;
341    char buf[10] = "xxxxxxxxx";
342    const char ref[10] = "xxxxxxxxx";
343
344    if( n >= sizeof( buf ) )
345        return( -1 );
346    ret = mbedtls_snprintf( buf, n, "%s", "123" );
347    if( ret < 0 || (size_t) ret >= n )
348        ret = -1;
349
350    if( strncmp( ref_buf, buf, sizeof( buf ) ) != 0 ||
351        ref_ret != ret ||
352        memcmp( buf + n, ref + n, sizeof( buf ) - n ) != 0 )
353    {
354        return( 1 );
355    }
356
357    return( 0 );
358}
359
360/**
361 * \brief       Tests snprintf implementation.
362 *
363 * \return      0 for success else 1
364 */
365static int run_test_snprintf( void )
366{
367    return( test_snprintf( 0, "xxxxxxxxx",  -1 ) != 0 ||
368            test_snprintf( 1, "",           -1 ) != 0 ||
369            test_snprintf( 2, "1",          -1 ) != 0 ||
370            test_snprintf( 3, "12",         -1 ) != 0 ||
371            test_snprintf( 4, "123",         3 ) != 0 ||
372            test_snprintf( 5, "123",         3 ) != 0 );
373}
374
375/** \brief Write the description of the test case to the outcome CSV file.
376 *
377 * \param outcome_file  The file to write to.
378 *                      If this is \c NULL, this function does nothing.
379 * \param argv0         The test suite name.
380 * \param test_case     The test case description.
381 */
382static void write_outcome_entry( FILE *outcome_file,
383                                 const char *argv0,
384                                 const char *test_case )
385{
386    /* The non-varying fields are initialized on first use. */
387    static const char *platform = NULL;
388    static const char *configuration = NULL;
389    static const char *test_suite = NULL;
390
391    if( outcome_file == NULL )
392        return;
393
394    if( platform == NULL )
395    {
396        platform = getenv( "MBEDTLS_TEST_PLATFORM" );
397        if( platform == NULL )
398            platform = "unknown";
399    }
400    if( configuration == NULL )
401    {
402        configuration = getenv( "MBEDTLS_TEST_CONFIGURATION" );
403        if( configuration == NULL )
404            configuration = "unknown";
405    }
406    if( test_suite == NULL )
407    {
408        test_suite = strrchr( argv0, '/' );
409        if( test_suite != NULL )
410            test_suite += 1; // skip the '/'
411        else
412            test_suite = argv0;
413    }
414
415    /* Write the beginning of the outcome line.
416     * Ignore errors: writing the outcome file is on a best-effort basis. */
417    mbedtls_fprintf( outcome_file, "%s;%s;%s;%s;",
418                     platform, configuration, test_suite, test_case );
419}
420
421/** \brief Write the result of the test case to the outcome CSV file.
422 *
423 * \param outcome_file  The file to write to.
424 *                      If this is \c NULL, this function does nothing.
425 * \param unmet_dep_count            The number of unmet dependencies.
426 * \param unmet_dependencies         The array of unmet dependencies.
427 * \param missing_unmet_dependencies Non-zero if there was a problem tracking
428 *                                   all unmet dependencies, 0 otherwise.
429 * \param ret                        The test dispatch status (DISPATCH_xxx).
430 * \param info                       A pointer to the test info structure.
431 */
432static void write_outcome_result( FILE *outcome_file,
433                                  size_t unmet_dep_count,
434                                  int unmet_dependencies[],
435                                  int missing_unmet_dependencies,
436                                  int ret,
437                                  const mbedtls_test_info_t *info )
438{
439    if( outcome_file == NULL )
440        return;
441
442    /* Write the end of the outcome line.
443     * Ignore errors: writing the outcome file is on a best-effort basis. */
444    switch( ret )
445    {
446        case DISPATCH_TEST_SUCCESS:
447            if( unmet_dep_count > 0 )
448            {
449                size_t i;
450                mbedtls_fprintf( outcome_file, "SKIP" );
451                for( i = 0; i < unmet_dep_count; i++ )
452                {
453                    mbedtls_fprintf( outcome_file, "%c%d",
454                                     i == 0 ? ';' : ':',
455                                     unmet_dependencies[i] );
456                }
457                if( missing_unmet_dependencies )
458                    mbedtls_fprintf( outcome_file, ":..." );
459                break;
460            }
461            switch( info->result )
462            {
463                case MBEDTLS_TEST_RESULT_SUCCESS:
464                    mbedtls_fprintf( outcome_file, "PASS;" );
465                    break;
466                case MBEDTLS_TEST_RESULT_SKIPPED:
467                    mbedtls_fprintf( outcome_file, "SKIP;Runtime skip" );
468                    break;
469                default:
470                    mbedtls_fprintf( outcome_file, "FAIL;%s:%d:%s",
471                                     info->filename, info->line_no,
472                                     info->test );
473                    break;
474            }
475            break;
476        case DISPATCH_TEST_FN_NOT_FOUND:
477            mbedtls_fprintf( outcome_file, "FAIL;Test function not found" );
478            break;
479        case DISPATCH_INVALID_TEST_DATA:
480            mbedtls_fprintf( outcome_file, "FAIL;Invalid test data" );
481            break;
482        case DISPATCH_UNSUPPORTED_SUITE:
483            mbedtls_fprintf( outcome_file, "SKIP;Unsupported suite" );
484            break;
485        default:
486            mbedtls_fprintf( outcome_file, "FAIL;Unknown cause" );
487            break;
488    }
489    mbedtls_fprintf( outcome_file, "\n" );
490    fflush( outcome_file );
491}
492
493/**
494 * \brief       Desktop implementation of execute_tests().
495 *              Parses command line and executes tests from
496 *              supplied or default data file.
497 *
498 * \param argc  Command line argument count.
499 * \param argv  Argument array.
500 *
501 * \return      Program exit status.
502 */
503int execute_tests( int argc , const char ** argv )
504{
505    /* Local Configurations and options */
506    const char *default_filename = "DATA_FILE";
507    const char *test_filename = NULL;
508    const char **test_files = NULL;
509    size_t testfile_count = 0;
510    int option_verbose = 0;
511    size_t function_id = 0;
512
513    /* Other Local variables */
514    int arg_index = 1;
515    const char *next_arg;
516    size_t testfile_index, i, cnt;
517    int ret;
518    unsigned total_errors = 0, total_tests = 0, total_skipped = 0;
519    FILE *file;
520    char buf[5000];
521    char *params[50];
522    /* Store for processed integer params. */
523    int32_t int_params[50];
524    void *pointer;
525#if defined(__unix__) || (defined(__APPLE__) && defined(__MACH__))
526    int stdout_fd = -1;
527#endif /* __unix__ || __APPLE__ __MACH__ */
528    const char *outcome_file_name = getenv( "MBEDTLS_TEST_OUTCOME_FILE" );
529    FILE *outcome_file = NULL;
530
531#if defined(MBEDTLS_MEMORY_BUFFER_ALLOC_C) && \
532    !defined(TEST_SUITE_MEMORY_BUFFER_ALLOC)
533    unsigned char alloc_buf[1000000];
534    mbedtls_memory_buffer_alloc_init( alloc_buf, sizeof( alloc_buf ) );
535#endif
536
537#if defined(MBEDTLS_TEST_MUTEX_USAGE)
538    mbedtls_test_mutex_usage_init( );
539#endif
540
541    /*
542     * The C standard doesn't guarantee that all-bits-0 is the representation
543     * of a NULL pointer. We do however use that in our code for initializing
544     * structures, which should work on every modern platform. Let's be sure.
545     */
546    memset( &pointer, 0, sizeof( void * ) );
547    if( pointer != NULL )
548    {
549        mbedtls_fprintf( stderr, "all-bits-zero is not a NULL pointer\n" );
550        return( 1 );
551    }
552
553    /*
554     * Make sure we have a snprintf that correctly zero-terminates
555     */
556    if( run_test_snprintf() != 0 )
557    {
558        mbedtls_fprintf( stderr, "the snprintf implementation is broken\n" );
559        return( 1 );
560    }
561
562    if( outcome_file_name != NULL && *outcome_file_name != '\0' )
563    {
564        outcome_file = fopen( outcome_file_name, "a" );
565        if( outcome_file == NULL )
566        {
567            mbedtls_fprintf( stderr, "Unable to open outcome file. Continuing anyway.\n" );
568        }
569    }
570
571    while( arg_index < argc )
572    {
573        next_arg = argv[arg_index];
574
575        if( strcmp( next_arg, "--verbose" ) == 0 ||
576                 strcmp( next_arg, "-v" ) == 0 )
577        {
578            option_verbose = 1;
579        }
580        else if( strcmp(next_arg, "--help" ) == 0 ||
581                 strcmp(next_arg, "-h" ) == 0 )
582        {
583            mbedtls_fprintf( stdout, USAGE );
584            mbedtls_exit( EXIT_SUCCESS );
585        }
586        else
587        {
588            /* Not an option, therefore treat all further arguments as the file
589             * list.
590             */
591            test_files = &argv[ arg_index ];
592            testfile_count = argc - arg_index;
593            break;
594        }
595
596        arg_index++;
597    }
598
599    /* If no files were specified, assume a default */
600    if ( test_files == NULL || testfile_count == 0 )
601    {
602        test_files = &default_filename;
603        testfile_count = 1;
604    }
605
606    /* Initialize the struct that holds information about the last test */
607    mbedtls_test_info_reset( );
608
609    /* Now begin to execute the tests in the testfiles */
610    for ( testfile_index = 0;
611          testfile_index < testfile_count;
612          testfile_index++ )
613    {
614        size_t unmet_dep_count = 0;
615        int unmet_dependencies[20];
616        int missing_unmet_dependencies = 0;
617
618        test_filename = test_files[ testfile_index ];
619
620        file = fopen( test_filename, "r" );
621        if( file == NULL )
622        {
623            mbedtls_fprintf( stderr, "Failed to open test file: %s\n",
624                             test_filename );
625            if( outcome_file != NULL )
626                fclose( outcome_file );
627            return( 1 );
628        }
629
630        while( !feof( file ) )
631        {
632            if( unmet_dep_count > 0 )
633            {
634                mbedtls_fprintf( stderr,
635                    "FATAL: Dep count larger than zero at start of loop\n" );
636                mbedtls_exit( MBEDTLS_EXIT_FAILURE );
637            }
638            unmet_dep_count = 0;
639            missing_unmet_dependencies = 0;
640
641            if( ( ret = get_line( file, buf, sizeof(buf) ) ) != 0 )
642                break;
643            mbedtls_fprintf( stdout, "%s%.66s",
644                    mbedtls_test_info.result == MBEDTLS_TEST_RESULT_FAILED ?
645                    "\n" : "", buf );
646            mbedtls_fprintf( stdout, " " );
647            for( i = strlen( buf ) + 1; i < 67; i++ )
648                mbedtls_fprintf( stdout, "." );
649            mbedtls_fprintf( stdout, " " );
650            fflush( stdout );
651            write_outcome_entry( outcome_file, argv[0], buf );
652
653            total_tests++;
654
655            if( ( ret = get_line( file, buf, sizeof( buf ) ) ) != 0 )
656                break;
657            cnt = parse_arguments( buf, strlen( buf ), params,
658                                   sizeof( params ) / sizeof( params[0] ) );
659
660            if( strcmp( params[0], "depends_on" ) == 0 )
661            {
662                for( i = 1; i < cnt; i++ )
663                {
664                    int dep_id = strtol( params[i], NULL, 10 );
665                    if( dep_check( dep_id ) != DEPENDENCY_SUPPORTED )
666                    {
667                        if( unmet_dep_count <
668                            ARRAY_LENGTH( unmet_dependencies ) )
669                        {
670                            unmet_dependencies[unmet_dep_count] = dep_id;
671                            unmet_dep_count++;
672                        }
673                        else
674                        {
675                            missing_unmet_dependencies = 1;
676                        }
677                    }
678                }
679
680                if( ( ret = get_line( file, buf, sizeof( buf ) ) ) != 0 )
681                    break;
682                cnt = parse_arguments( buf, strlen( buf ), params,
683                                       sizeof( params ) / sizeof( params[0] ) );
684            }
685
686            // If there are no unmet dependencies execute the test
687            if( unmet_dep_count == 0 )
688            {
689                mbedtls_test_info_reset( );
690
691#if defined(__unix__) || (defined(__APPLE__) && defined(__MACH__))
692                /* Suppress all output from the library unless we're verbose
693                 * mode
694                 */
695                if( !option_verbose )
696                {
697                    stdout_fd = redirect_output( stdout, "/dev/null" );
698                    if( stdout_fd == -1 )
699                    {
700                        /* Redirection has failed with no stdout so exit */
701                        exit( 1 );
702                    }
703                }
704#endif /* __unix__ || __APPLE__ __MACH__ */
705
706                function_id = strtoul( params[0], NULL, 10 );
707                if ( (ret = check_test( function_id )) == DISPATCH_TEST_SUCCESS )
708                {
709                    ret = convert_params( cnt - 1, params + 1, int_params );
710                    if ( DISPATCH_TEST_SUCCESS == ret )
711                    {
712                        ret = dispatch_test( function_id, (void **)( params + 1 ) );
713                    }
714                }
715
716#if defined(__unix__) || (defined(__APPLE__) && defined(__MACH__))
717                if( !option_verbose && restore_output( stdout, stdout_fd ) )
718                {
719                        /* Redirection has failed with no stdout so exit */
720                        exit( 1 );
721                }
722#endif /* __unix__ || __APPLE__ __MACH__ */
723
724            }
725
726            write_outcome_result( outcome_file,
727                                  unmet_dep_count, unmet_dependencies,
728                                  missing_unmet_dependencies,
729                                  ret, &mbedtls_test_info );
730            if( unmet_dep_count > 0 || ret == DISPATCH_UNSUPPORTED_SUITE )
731            {
732                total_skipped++;
733                mbedtls_fprintf( stdout, "----" );
734
735                if( 1 == option_verbose && ret == DISPATCH_UNSUPPORTED_SUITE )
736                {
737                    mbedtls_fprintf( stdout, "\n   Test Suite not enabled" );
738                }
739
740                if( 1 == option_verbose && unmet_dep_count > 0 )
741                {
742                    mbedtls_fprintf( stdout, "\n   Unmet dependencies: " );
743                    for( i = 0; i < unmet_dep_count; i++ )
744                    {
745                        mbedtls_fprintf( stdout, "%d ",
746                                        unmet_dependencies[i] );
747                    }
748                    if( missing_unmet_dependencies )
749                        mbedtls_fprintf( stdout, "..." );
750                }
751                mbedtls_fprintf( stdout, "\n" );
752                fflush( stdout );
753
754                unmet_dep_count = 0;
755                missing_unmet_dependencies = 0;
756            }
757            else if( ret == DISPATCH_TEST_SUCCESS )
758            {
759                if( mbedtls_test_info.result == MBEDTLS_TEST_RESULT_SUCCESS )
760                {
761                    mbedtls_fprintf( stdout, "PASS\n" );
762                }
763                else if( mbedtls_test_info.result == MBEDTLS_TEST_RESULT_SKIPPED )
764                {
765                    mbedtls_fprintf( stdout, "----\n" );
766                    total_skipped++;
767                }
768                else
769                {
770                    total_errors++;
771                    mbedtls_fprintf( stdout, "FAILED\n" );
772                    mbedtls_fprintf( stdout, "  %s\n  at ",
773                                     mbedtls_test_info.test );
774                    if( mbedtls_test_info.step != (unsigned long)( -1 ) )
775                    {
776                        mbedtls_fprintf( stdout, "step %lu, ",
777                                         mbedtls_test_info.step );
778                    }
779                    mbedtls_fprintf( stdout, "line %d, %s",
780                                     mbedtls_test_info.line_no,
781                                     mbedtls_test_info.filename );
782                    if( mbedtls_test_info.line1[0] != 0 )
783                        mbedtls_fprintf( stdout, "\n  %s",
784                                         mbedtls_test_info.line1 );
785                    if( mbedtls_test_info.line2[0] != 0 )
786                        mbedtls_fprintf( stdout, "\n  %s",
787                                         mbedtls_test_info.line2 );
788                }
789                fflush( stdout );
790            }
791            else if( ret == DISPATCH_INVALID_TEST_DATA )
792            {
793                mbedtls_fprintf( stderr, "FAILED: FATAL PARSE ERROR\n" );
794                fclose( file );
795                mbedtls_exit( 2 );
796            }
797            else if( ret == DISPATCH_TEST_FN_NOT_FOUND )
798            {
799                mbedtls_fprintf( stderr, "FAILED: FATAL TEST FUNCTION NOT FOUND\n" );
800                fclose( file );
801                mbedtls_exit( 2 );
802            }
803            else
804                total_errors++;
805        }
806        fclose( file );
807    }
808
809    if( outcome_file != NULL )
810        fclose( outcome_file );
811
812    mbedtls_fprintf( stdout, "\n----------------------------------------------------------------------------\n\n");
813    if( total_errors == 0 )
814        mbedtls_fprintf( stdout, "PASSED" );
815    else
816        mbedtls_fprintf( stdout, "FAILED" );
817
818    mbedtls_fprintf( stdout, " (%u / %u tests (%u skipped))\n",
819                     total_tests - total_errors, total_tests, total_skipped );
820
821#if defined(MBEDTLS_MEMORY_BUFFER_ALLOC_C) && \
822    !defined(TEST_SUITE_MEMORY_BUFFER_ALLOC)
823#if defined(MBEDTLS_MEMORY_DEBUG)
824    mbedtls_memory_buffer_alloc_status();
825#endif
826    mbedtls_memory_buffer_alloc_free();
827#endif
828
829    return( total_errors != 0 );
830}
831