From 79e58421be7222ca7d1df824571eb05749f5cfda Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Manuel=20P=C3=A9gouri=C3=A9-Gonnard?= Date: Wed, 2 Apr 2014 18:42:01 +0200 Subject: [PATCH] Also test net_usleep in timing_selttest() --- library/timing.c | 34 ++++++++++++++++++++++++++++++++-- 1 file changed, 32 insertions(+), 2 deletions(-) diff --git a/library/timing.c b/library/timing.c index 9a6129bf8..7085b3b6a 100644 --- a/library/timing.c +++ b/library/timing.c @@ -319,6 +319,11 @@ void m_sleep( int milliseconds ) #if defined(POLARSSL_SELF_TEST) +/* To test net_usleep against our functions */ +#if defined(POLARSSL_NET_C) +#include "polarssl/net.h" +#endif + /* * Checkup routine */ @@ -339,11 +344,11 @@ int timing_self_test( int verbose ) { (void) get_timer( &hires, 1 ); - m_sleep( 1000 * secs ); + m_sleep( 500 * secs ); millisecs = get_timer( &hires, 0 ); - if( millisecs < 900 * secs || millisecs > 1100 * secs ) + if( millisecs < 450 * secs || millisecs > 550 * secs ) { if( verbose != 0 ) polarssl_printf( "failed\n" ); @@ -426,6 +431,31 @@ hard_test: if( verbose != 0 ) polarssl_printf( "\n" ); +#if defined(POLARSSL_NET_C) + if( verbose != 0 ) + polarssl_printf( " TIMING test #4 (net_usleep/ get_timer): " ); + + for( secs = 1; secs <= 3; secs++ ) + { + (void) get_timer( &hires, 1 ); + + net_usleep( 500000 * secs ); + + millisecs = get_timer( &hires, 0 ); + + if( millisecs < 450 * secs || millisecs > 550 * secs ) + { + if( verbose != 0 ) + polarssl_printf( "failed\n" ); + + return( 1 ); + } + } + + if( verbose != 0 ) + polarssl_printf( "passed\n" ); +#endif + return( 0 ); }