diff --git a/tests/suites/main_test.function b/tests/suites/main_test.function index 420ee7697..61c7337a6 100644 --- a/tests/suites/main_test.function +++ b/tests/suites/main_test.function @@ -240,10 +240,13 @@ static int run_test_snprintf( void ) test_snprintf( 5, "123", 3 ) != 0 ); } -int main() +int main(int argc, const char *argv[]) { - int ret, i, cnt, total_errors = 0, total_tests = 0, total_skipped = 0; - const char *filename = "TEST_FILENAME"; + int testfile_index, testfile_count, ret, i, cnt; + int total_errors = 0, total_tests = 0, total_skipped = 0; + const char *default_filename = "TEST_FILENAME"; + const char *test_filename = NULL; + const char **test_files = NULL; FILE *file; char buf[5000]; char *params[50]; @@ -276,78 +279,98 @@ int main() return( 0 ); } - file = fopen( filename, "r" ); - if( file == NULL ) + if ( argc <= 1 ) { - mbedtls_fprintf( stderr, "Failed to open\n" ); - return( 1 ); + test_files = &default_filename; + testfile_count = 1; + } + else + { + test_files = &argv[1]; + testfile_count = argc - 1; } - while( !feof( file ) ) + for ( testfile_index = 0; + testfile_index < testfile_count; + testfile_index++ ) { - int skip = 0; + test_filename = test_files[ testfile_index ]; - if( ( ret = get_line( file, buf, sizeof(buf) ) ) != 0 ) - break; - mbedtls_fprintf( stdout, "%s%.66s", test_errors ? "\n" : "", buf ); - mbedtls_fprintf( stdout, " " ); - for( i = strlen( buf ) + 1; i < 67; i++ ) - mbedtls_fprintf( stdout, "." ); - mbedtls_fprintf( stdout, " " ); - fflush( stdout ); - - total_tests++; - - if( ( ret = get_line( file, buf, sizeof(buf) ) ) != 0 ) - break; - cnt = parse_arguments( buf, strlen(buf), params ); - - if( strcmp( params[0], "depends_on" ) == 0 ) + file = fopen( test_filename, "r" ); + if( file == NULL ) { - for( i = 1; i < cnt; i++ ) - if( dep_check( params[i] ) != 0 ) - skip = 1; + mbedtls_fprintf( stderr, "Failed to open test file: %s\n", + test_filename ); + return( 1 ); + } + + while( !feof( file ) ) + { + int skip = 0; + + if( ( ret = get_line( file, buf, sizeof(buf) ) ) != 0 ) + break; + mbedtls_fprintf( stdout, "%s%.66s", test_errors ? "\n" : "", buf ); + mbedtls_fprintf( stdout, " " ); + for( i = strlen( buf ) + 1; i < 67; i++ ) + mbedtls_fprintf( stdout, "." ); + mbedtls_fprintf( stdout, " " ); + fflush( stdout ); + + total_tests++; if( ( ret = get_line( file, buf, sizeof(buf) ) ) != 0 ) break; cnt = parse_arguments( buf, strlen(buf), params ); - } - if( skip == 0 ) - { - test_errors = 0; - ret = dispatch_test( cnt, params ); - } + if( strcmp( params[0], "depends_on" ) == 0 ) + { + for( i = 1; i < cnt; i++ ) + if( dep_check( params[i] ) != 0 ) + skip = 1; - if( skip == 1 || ret == 3 ) - { - total_skipped++; - mbedtls_fprintf( stdout, "----\n" ); - fflush( stdout ); - } - else if( ret == 0 && test_errors == 0 ) - { - mbedtls_fprintf( stdout, "PASS\n" ); - fflush( stdout ); - } - else if( ret == 2 ) - { - mbedtls_fprintf( stderr, "FAILED: FATAL PARSE ERROR\n" ); - fclose(file); - mbedtls_exit( 2 ); - } - else - total_errors++; + if( ( ret = get_line( file, buf, sizeof(buf) ) ) != 0 ) + break; + cnt = parse_arguments( buf, strlen(buf), params ); + } - if( ( ret = get_line( file, buf, sizeof(buf) ) ) != 0 ) - break; - if( strlen(buf) != 0 ) - { - mbedtls_fprintf( stderr, "Should be empty %d\n", (int) strlen(buf) ); - return( 1 ); + if( skip == 0 ) + { + test_errors = 0; + ret = dispatch_test( cnt, params ); + } + + if( skip == 1 || ret == 3 ) + { + total_skipped++; + mbedtls_fprintf( stdout, "----\n" ); + fflush( stdout ); + } + else if( ret == 0 && test_errors == 0 ) + { + mbedtls_fprintf( stdout, "PASS\n" ); + fflush( stdout ); + } + else if( ret == 2 ) + { + mbedtls_fprintf( stderr, "FAILED: FATAL PARSE ERROR\n" ); + fclose(file); + mbedtls_exit( 2 ); + } + else + total_errors++; + + if( ( ret = get_line( file, buf, sizeof(buf) ) ) != 0 ) + break; + if( strlen(buf) != 0 ) + { + mbedtls_fprintf( stderr, "Should be empty %d\n", + (int) strlen(buf) ); + return( 1 ); + } } + fclose(file); } - fclose(file); mbedtls_fprintf( stdout, "\n----------------------------------------------------------------------------\n\n"); if( total_errors == 0 )