From d39496233b5430be16c853f9bf8d7447c2ec86a6 Mon Sep 17 00:00:00 2001 From: Gilles Peskine Date: Fri, 27 Oct 2017 18:42:32 +0200 Subject: [PATCH] Timing self test: increased duration Increase the duration of the self test, otherwise it tends to fail on a busy machine even with the recently upped tolerance. But run the loop only once, it's enough for a simple smoke test. --- ChangeLog | 2 ++ library/timing.c | 30 ++++++++++++------------------ 2 files changed, 14 insertions(+), 18 deletions(-) diff --git a/ChangeLog b/ChangeLog index 9fd8cce093..c6031b4184 100644 --- a/ChangeLog +++ b/ChangeLog @@ -16,6 +16,8 @@ Features * Allow comments in test data files. * The selftest program can execute a subset of the tests based on command line arguments. + * Improve the timing self-tests to be more robust when run on a + heavily-loaded machine. Bugfix * Fix ssl_parse_record_header() to silently discard invalid DTLS records diff --git a/library/timing.c b/library/timing.c index 93e1826d9c..2c8d4bbbfa 100644 --- a/library/timing.c +++ b/library/timing.c @@ -439,28 +439,22 @@ int mbedtls_timing_self_test( int verbose ) if( verbose != 0 ) mbedtls_printf( " TIMING test #2 (set/get_delay ): " ); - for( a = 200; a <= 400; a += 200 ) { - for( b = 200; b <= 400; b += 200 ) - { - mbedtls_timing_set_delay( &ctx, a, a + b ); + a = 800; + b = 400; + mbedtls_timing_set_delay( &ctx, a, a + b ); /* T = 0 */ - busy_msleep( a - a / 4 ); - if( mbedtls_timing_get_delay( &ctx ) != 0 ) - FAIL; + busy_msleep( a - a / 4 ); /* T = a - a/4 */ + if( mbedtls_timing_get_delay( &ctx ) != 0 ) + FAIL; - busy_msleep( a / 2 ); - if( mbedtls_timing_get_delay( &ctx ) != 1 ) - FAIL; + busy_msleep( a / 4 + b / 4 ); /* T = a + b/4 */ + if( mbedtls_timing_get_delay( &ctx ) != 1 ) + FAIL; - busy_msleep( b - a / 4 - b / 4 ); - if( mbedtls_timing_get_delay( &ctx ) != 1 ) - FAIL; - - busy_msleep( b / 2 ); - if( mbedtls_timing_get_delay( &ctx ) != 2 ) - FAIL; - } + busy_msleep( b ); /* T = a + b + b/4 */ + if( mbedtls_timing_get_delay( &ctx ) != 2 ) + FAIL; } mbedtls_timing_set_delay( &ctx, 0, 0 );