From 396d8ac87a2be18b90ead5e9bfe585742714c061 Mon Sep 17 00:00:00 2001 From: Joseph Hickey Date: Thu, 24 Jun 2021 12:45:14 -0400 Subject: [PATCH] Fix #1080, add range to OS_TaskDelay checks To account for potential of imprecise timing/clock sampling when running on a VM, allow for a wider range of time values to pass the test. --- src/unit-tests/oscore-test/ut_oscore_task_test.c | 10 ++++++++-- 1 file changed, 8 insertions(+), 2 deletions(-) diff --git a/src/unit-tests/oscore-test/ut_oscore_task_test.c b/src/unit-tests/oscore-test/ut_oscore_task_test.c index 5bb7daac1..19b77ca42 100644 --- a/src/unit-tests/oscore-test/ut_oscore_task_test.c +++ b/src/unit-tests/oscore-test/ut_oscore_task_test.c @@ -398,6 +398,12 @@ void UT_os_task_delay_test() OS_time_t after_time; int64 elapsed; + /* + * Note, if running under a VM/hypervisor, the real time clock may not + * be very precise, depending on its implementation. Therefore the allowed + * ranges are slightly extended here. + */ + /*-----------------------------------------------------*/ /* Nominal, 100ms delay */ UT_SETUP(OS_GetLocalTime(&before_time)); @@ -405,7 +411,7 @@ void UT_os_task_delay_test() UT_SETUP(OS_GetLocalTime(&after_time)); elapsed = OS_TimeGetTotalMilliseconds(OS_TimeSubtract(after_time, before_time)); - UtAssert_True(elapsed >= 100, "Elapsed time %ld msec, expected 100", (long)elapsed); + UtAssert_True(elapsed >= 95, "Elapsed time %ld msec, expected 100", (long)elapsed); /*-----------------------------------------------------*/ /* Nominal, 250ms delay */ @@ -414,7 +420,7 @@ void UT_os_task_delay_test() UT_SETUP(OS_GetLocalTime(&after_time)); elapsed = OS_TimeGetTotalMilliseconds(OS_TimeSubtract(after_time, before_time)); - UtAssert_True(elapsed >= 250, "Elapsed time %ld msec, expected 250", (long)elapsed); + UtAssert_True(elapsed >= 245, "Elapsed time %ld msec, expected 250", (long)elapsed); } /*--------------------------------------------------------------------------------*