test_suite_timing.function 1.1 KB

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