mirror of
https://github.com/yuzu-emu/mbedtls.git
synced 2024-11-23 12:15:42 +01:00
Parameterised the test suite applications
All test suites can now take an arbitrary test file.
This commit is contained in:
parent
1b6044ded2
commit
6c545a87c2
@ -240,10 +240,13 @@ static int run_test_snprintf( void )
|
|||||||
test_snprintf( 5, "123", 3 ) != 0 );
|
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;
|
int testfile_index, testfile_count, ret, i, cnt;
|
||||||
const char *filename = "TEST_FILENAME";
|
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;
|
FILE *file;
|
||||||
char buf[5000];
|
char buf[5000];
|
||||||
char *params[50];
|
char *params[50];
|
||||||
@ -276,78 +279,98 @@ int main()
|
|||||||
return( 0 );
|
return( 0 );
|
||||||
}
|
}
|
||||||
|
|
||||||
file = fopen( filename, "r" );
|
if ( argc <= 1 )
|
||||||
if( file == NULL )
|
|
||||||
{
|
{
|
||||||
mbedtls_fprintf( stderr, "Failed to open\n" );
|
test_files = &default_filename;
|
||||||
return( 1 );
|
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 )
|
file = fopen( test_filename, "r" );
|
||||||
break;
|
if( file == NULL )
|
||||||
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 )
|
|
||||||
{
|
{
|
||||||
for( i = 1; i < cnt; i++ )
|
mbedtls_fprintf( stderr, "Failed to open test file: %s\n",
|
||||||
if( dep_check( params[i] ) != 0 )
|
test_filename );
|
||||||
skip = 1;
|
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 )
|
if( ( ret = get_line( file, buf, sizeof(buf) ) ) != 0 )
|
||||||
break;
|
break;
|
||||||
cnt = parse_arguments( buf, strlen(buf), params );
|
cnt = parse_arguments( buf, strlen(buf), params );
|
||||||
}
|
|
||||||
|
|
||||||
if( skip == 0 )
|
if( strcmp( params[0], "depends_on" ) == 0 )
|
||||||
{
|
{
|
||||||
test_errors = 0;
|
for( i = 1; i < cnt; i++ )
|
||||||
ret = dispatch_test( cnt, params );
|
if( dep_check( params[i] ) != 0 )
|
||||||
}
|
skip = 1;
|
||||||
|
|
||||||
if( skip == 1 || ret == 3 )
|
if( ( ret = get_line( file, buf, sizeof(buf) ) ) != 0 )
|
||||||
{
|
break;
|
||||||
total_skipped++;
|
cnt = parse_arguments( buf, strlen(buf), params );
|
||||||
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 )
|
if( skip == 0 )
|
||||||
break;
|
{
|
||||||
if( strlen(buf) != 0 )
|
test_errors = 0;
|
||||||
{
|
ret = dispatch_test( cnt, params );
|
||||||
mbedtls_fprintf( stderr, "Should be empty %d\n", (int) strlen(buf) );
|
}
|
||||||
return( 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;
|
||||||
|
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");
|
mbedtls_fprintf( stdout, "\n----------------------------------------------------------------------------\n\n");
|
||||||
if( total_errors == 0 )
|
if( total_errors == 0 )
|
||||||
|
Loading…
Reference in New Issue
Block a user