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 mbedtls_timing_set_delay(&ctx, 0, 0); 37 result = mbedtls_timing_get_delay(&ctx); 38 TEST_ASSERT(result == -1); 39 } else { 40 mbedtls_timing_set_delay(&ctx, fin_ms / 2, fin_ms); 41 result = mbedtls_timing_get_delay(&ctx); 42 TEST_ASSERT(result >= 0 && result <= 2); 43 } 44} 45/* END_CASE */ 46