Ensure failed test_suite output is sent to stdout

The change modifies the template code in tests/suites/helpers.function
and tests/suites/main.function so that error messages are printed to
stdout instead of being discarded. This makes errors visible regardless
of the --verbose flag being passed or not to the test suite programs.
This commit is contained in:
Andres Amaya Garcia 2017-10-01 16:42:29 +01:00 committed by Simon Butcher
parent acdae0cb33
commit def0339db2
2 changed files with 32 additions and 11 deletions

View file

@ -99,7 +99,15 @@ typedef UINT32 uint32_t;
/*----------------------------------------------------------------------------*/ /*----------------------------------------------------------------------------*/
/* Global variables */ /* Global variables */
static int test_errors = 0;
static struct
{
int failed;
const char *test;
const char *filename;
int line_no;
}
test_info;
/*----------------------------------------------------------------------------*/ /*----------------------------------------------------------------------------*/
@ -395,10 +403,9 @@ static int rnd_pseudo_rand( void *rng_state, unsigned char *output, size_t len )
static void test_fail( const char *test, int line_no, const char* filename ) static void test_fail( const char *test, int line_no, const char* filename )
{ {
test_errors++; test_info.failed = 1;
if( test_errors == 1 ) test_info.test = test;
mbedtls_fprintf( stdout, "FAILED\n" ); test_info.line_no = line_no;
mbedtls_fprintf( stdout, " %s\n at line %d, %s\n", test, line_no, test_info.filename = filename;
filename );
} }

View file

@ -339,6 +339,9 @@ int main(int argc, const char *argv[])
testfile_count = 1; testfile_count = 1;
} }
/* Initialize the struct that holds information about the last test */
memset( &test_info, 0, sizeof( test_info ) );
/* Now begin to execute the tests in the testfiles */ /* Now begin to execute the tests in the testfiles */
for ( testfile_index = 0; for ( testfile_index = 0;
testfile_index < testfile_count; testfile_index < testfile_count;
@ -369,7 +372,7 @@ int main(int argc, const char *argv[])
if( ( ret = get_line( file, buf, sizeof(buf) ) ) != 0 ) if( ( ret = get_line( file, buf, sizeof(buf) ) ) != 0 )
break; break;
mbedtls_fprintf( stdout, "%s%.66s", test_errors ? "\n" : "", buf ); mbedtls_fprintf( stdout, "%s%.66s", test_info.failed ? "\n" : "", buf );
mbedtls_fprintf( stdout, " " ); mbedtls_fprintf( stdout, " " );
for( i = strlen( buf ) + 1; i < 67; i++ ) for( i = strlen( buf ) + 1; i < 67; i++ )
mbedtls_fprintf( stdout, "." ); mbedtls_fprintf( stdout, "." );
@ -409,11 +412,11 @@ int main(int argc, const char *argv[])
break; break;
cnt = parse_arguments( buf, strlen(buf), params ); cnt = parse_arguments( buf, strlen(buf), params );
} }
// If there are no unmet dependencies execute the test // If there are no unmet dependencies execute the test
if( unmet_dep_count == 0 ) if( unmet_dep_count == 0 )
{ {
test_errors = 0; test_info.failed = 0;
#if defined(__unix__) || (defined(__APPLE__) && defined(__MACH__)) #if defined(__unix__) || (defined(__APPLE__) && defined(__MACH__))
/* Suppress all output from the library unless we're verbose /* Suppress all output from the library unless we're verbose
@ -467,9 +470,20 @@ int main(int argc, const char *argv[])
unmet_dep_count = 0; unmet_dep_count = 0;
} }
else if( ret == DISPATCH_TEST_SUCCESS && test_errors == 0 ) else if( ret == DISPATCH_TEST_SUCCESS )
{ {
mbedtls_fprintf( stdout, "PASS\n" ); if( test_info.failed == 0 )
{
mbedtls_fprintf( stdout, "PASS\n" );
}
else
{
total_errors++;
mbedtls_fprintf( stdout, "FAILED\n" );
mbedtls_fprintf( stdout, " %s\n at line %d, %s\n",
test_info.test, test_info.line_no,
test_info.filename );
}
fflush( stdout ); fflush( stdout );
} }
else if( ret == DISPATCH_INVALID_TEST_DATA ) else if( ret == DISPATCH_INVALID_TEST_DATA )