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.
10 #include "mbedtls/timing.h"
15 * depends_on:MBEDTLS_TIMING_C
20 void timing_hardclock( )
22 (void) mbedtls_timing_hardclock();
23 /* This goto is added to avoid warnings from the generated code. */
29 void timing_get_timer( )
31 struct mbedtls_timing_hr_time time;
32 (void) mbedtls_timing_get_timer( &time, 1 );
33 (void) mbedtls_timing_get_timer( &time, 0 );
34 /* This goto is added to avoid warnings from the generated code. */
40 void timing_set_alarm( int seconds )
44 mbedtls_set_alarm( seconds );
45 TEST_ASSERT( mbedtls_timing_alarmed == 1 );
49 mbedtls_set_alarm( seconds );
50 TEST_ASSERT( mbedtls_timing_alarmed == 0 ||
51 mbedtls_timing_alarmed == 1 );
57 void timing_delay( int fin_ms )
59 mbedtls_timing_delay_context ctx;
63 mbedtls_timing_set_delay( &ctx, 0, 0 );
64 result = mbedtls_timing_get_delay( &ctx );
65 TEST_ASSERT( result == -1 );
69 mbedtls_timing_set_delay( &ctx, fin_ms / 2, fin_ms );
70 result = mbedtls_timing_get_delay( &ctx );
71 TEST_ASSERT( result >= 0 && result <= 2 );