Make the hardclock test optional

Known to fail on VMs (such as the buildbots), see eg
http://blog.badtrace.com/post/rdtsc-x86-instruction-to-detect-vms/
parent 9bd0afdb
......@@ -62,6 +62,10 @@ extern volatile int mbedtls_timing_alarmed;
/**
* \brief Return the CPU cycle counter value
*
* \warning This is only a best effort! Do not rely on this!
* In particular, it is known to be unreliable on virtual
* machines.
*/
unsigned long mbedtls_timing_hardclock( void );
......
......@@ -427,7 +427,42 @@ int mbedtls_timing_self_test( int verbose )
mbedtls_printf( "passed\n" );
if( verbose != 0 )
mbedtls_printf( " TIMING test #2 (hardclock / get_timer): " );
mbedtls_printf( " TIMING test #2 (set/get_delay ): " );
for( a = 100; a <= 200; a += 100 )
{
for( b = 100; b <= 200; b += 100 )
{
mbedtls_timing_set_delay( &ctx, a, a + b );
busy_msleep( a - a / 10 );
if( mbedtls_timing_get_delay( &ctx ) != 0 )
FAIL;
busy_msleep( a / 5 );
if( mbedtls_timing_get_delay( &ctx ) != 1 )
FAIL;
busy_msleep( b - a / 5 );
if( mbedtls_timing_get_delay( &ctx ) != 1 )
FAIL;
busy_msleep( b / 5 );
if( mbedtls_timing_get_delay( &ctx ) != 2 )
FAIL;
}
}
mbedtls_timing_set_delay( &ctx, 0, 0 );
busy_msleep( 200 );
if( mbedtls_timing_get_delay( &ctx ) != -1 )
FAIL;
if( verbose != 0 )
mbedtls_printf( "passed\n" );
if( verbose != 0 )
mbedtls_printf( " TIMING test #3 (hardclock / get_timer): " );
/*
* Allow one failure for possible counter wrapping.
......@@ -440,9 +475,9 @@ hard_test:
if( hardfail > 1 )
{
if( verbose != 0 )
mbedtls_printf( "failed\n" );
mbedtls_printf( "failed (ignored)\n" );
return( 1 );
goto hard_test_done;
}
/* Get a reference ratio cycles/ms */
......@@ -471,40 +506,7 @@ hard_test:
if( verbose != 0 )
mbedtls_printf( "passed\n" );
if( verbose != 0 )
mbedtls_printf( " TIMING test #3 (set/get_delay ): " );
for( a = 100; a <= 200; a += 100 )
{
for( b = 100; b <= 200; b += 100 )
{
mbedtls_timing_set_delay( &ctx, a, a + b );
busy_msleep( a - a / 10 );
if( mbedtls_timing_get_delay( &ctx ) != 0 )
FAIL;
busy_msleep( a / 5 );
if( mbedtls_timing_get_delay( &ctx ) != 1 )
FAIL;
busy_msleep( b - a / 5 );
if( mbedtls_timing_get_delay( &ctx ) != 1 )
FAIL;
busy_msleep( b / 5 );
if( mbedtls_timing_get_delay( &ctx ) != 2 )
FAIL;
}
}
mbedtls_timing_set_delay( &ctx, 0, 0 );
busy_msleep( 200 );
if( mbedtls_timing_get_delay( &ctx ) != -1 )
FAIL;
if( verbose != 0 )
mbedtls_printf( "passed\n" );
hard_test_done:
if( verbose != 0 )
mbedtls_printf( "\n" );
......
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