1/* BEGIN_HEADER */ 2 3/* This test module exercises the timing module. Since, depending on the 4 * underlying operating system, the timing routines are not always reliable, 5 * this suite only performs very basic sanity checks of the timing API. 6 */ 7 8#include <limits.h> 9 10#include "mbedtls/timing.h" 11 12/* END_HEADER */ 13 14/* BEGIN_DEPENDENCIES 15 * depends_on:MBEDTLS_TIMING_C 16 * END_DEPENDENCIES 17 */ 18 19/* BEGIN_CASE */ 20void timing_get_timer( ) 21{ 22 struct mbedtls_timing_hr_time time; 23 (void) mbedtls_timing_get_timer( &time, 1 ); 24 (void) mbedtls_timing_get_timer( &time, 0 ); 25 /* This goto is added to avoid warnings from the generated code. */ 26 goto exit; 27} 28/* END_CASE */ 29 30/* BEGIN_CASE */ 31void timing_delay( int fin_ms ) 32{ 33 mbedtls_timing_delay_context ctx; 34 int result; 35 if( fin_ms == 0 ) 36 { 37 mbedtls_timing_set_delay( &ctx, 0, 0 ); 38 result = mbedtls_timing_get_delay( &ctx ); 39 TEST_ASSERT( result == -1 ); 40 } 41 else 42 { 43 mbedtls_timing_set_delay( &ctx, fin_ms / 2, fin_ms ); 44 result = mbedtls_timing_get_delay( &ctx ); 45 TEST_ASSERT( result >= 0 && result <= 2 ); 46 } 47} 48/* END_CASE */ 49