Commit 6c545a87 authored by Simon Butcher's avatar Simon Butcher

Parameterised the test suite applications

All test suites can now take an arbitrary test file.
parent 1b6044de
......@@ -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 );
file = fopen( test_filename, "r" );
if( file == NULL )
{
mbedtls_fprintf( stderr, "Failed to open test file: %s\n",
test_filename );
return( 1 );
}
total_tests++;
while( !feof( file ) )
{
int skip = 0;
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;
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 );
if( strcmp( params[0], "depends_on" ) == 0 )
{
for( i = 1; i < cnt; i++ )
if( dep_check( params[i] ) != 0 )
skip = 1;
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 )
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment