mirror of
https://github.com/yuzu-emu/mbedtls.git
synced 2024-12-23 00:05:35 +00:00
selftest: allow running a subset of the tests
If given command line arguments, interpret them as test names and only run those tests.
This commit is contained in:
parent
319ac801a8
commit
c82fbb4e14
|
@ -4,6 +4,8 @@ mbed TLS ChangeLog (Sorted per branch, date)
|
|||
|
||||
Features
|
||||
* Allow comments in test data files.
|
||||
* The selftest program can execute a subset of the tests based on command
|
||||
line arguments.
|
||||
|
||||
Bugfix
|
||||
* Fix memory leak in mbedtls_ssl_set_hostname() when called multiple times.
|
||||
|
|
|
@ -256,10 +256,14 @@ const selftest_t selftests[] =
|
|||
#endif
|
||||
{NULL, NULL}
|
||||
};
|
||||
#endif /* MBEDTLS_SELF_TEST */
|
||||
|
||||
int main( int argc, char *argv[] )
|
||||
{
|
||||
#if defined(MBEDTLS_SELF_TEST)
|
||||
const selftest_t *test;
|
||||
#endif /* MBEDTLS_SELF_TEST */
|
||||
char **argp = argc >= 1 ? argv + 1 : argv;
|
||||
int v, suites_tested = 0, suites_failed = 0;
|
||||
#if defined(MBEDTLS_MEMORY_BUFFER_ALLOC_C) && defined(MBEDTLS_SELF_TEST)
|
||||
unsigned char buf[1000000];
|
||||
|
@ -287,10 +291,11 @@ int main( int argc, char *argv[] )
|
|||
mbedtls_exit( MBEDTLS_EXIT_FAILURE );
|
||||
}
|
||||
|
||||
if( argc == 2 && ( strcmp( argv[1], "--quiet" ) == 0 ||
|
||||
if( argc >= 2 && ( strcmp( argv[1], "--quiet" ) == 0 ||
|
||||
strcmp( argv[1], "-q" ) == 0 ) )
|
||||
{
|
||||
v = 0;
|
||||
++argp;
|
||||
}
|
||||
else
|
||||
{
|
||||
|
@ -304,6 +309,33 @@ int main( int argc, char *argv[] )
|
|||
mbedtls_memory_buffer_alloc_init( buf, sizeof(buf) );
|
||||
#endif
|
||||
|
||||
if( *argp != NULL )
|
||||
{
|
||||
/* Run the specified tests */
|
||||
for( ; *argp != NULL; argp++ )
|
||||
{
|
||||
for( test = selftests; test->name != NULL; test++ )
|
||||
{
|
||||
if( !strcmp( *argp, test->name ) )
|
||||
{
|
||||
if( test->function( v ) != 0 )
|
||||
{
|
||||
suites_failed++;
|
||||
}
|
||||
suites_tested++;
|
||||
break;
|
||||
}
|
||||
}
|
||||
if( test->name == NULL )
|
||||
{
|
||||
mbedtls_printf( " Test suite %s not available -> failed\n\n", *argp );
|
||||
suites_failed++;
|
||||
}
|
||||
}
|
||||
}
|
||||
else
|
||||
{
|
||||
/* Run all the tests */
|
||||
for( test = selftests; test->name != NULL; test++ )
|
||||
{
|
||||
if( test->function( v ) != 0 )
|
||||
|
@ -312,6 +344,7 @@ int main( int argc, char *argv[] )
|
|||
}
|
||||
suites_tested++;
|
||||
}
|
||||
}
|
||||
|
||||
#else
|
||||
mbedtls_printf( " MBEDTLS_SELF_TEST not defined.\n" );
|
||||
|
|
Loading…
Reference in a new issue