Skip to content

Commit

Permalink
Fix #1080, add range to OS_TaskDelay checks
Browse files Browse the repository at this point in the history
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.
  • Loading branch information
jphickey committed Jun 24, 2021
1 parent 64a6b31 commit 396d8ac
Showing 1 changed file with 8 additions and 2 deletions.
10 changes: 8 additions & 2 deletions src/unit-tests/oscore-test/ut_oscore_task_test.c
Original file line number Diff line number Diff line change
Expand Up @@ -398,14 +398,20 @@ 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));
UT_NOMINAL(OS_TaskDelay(100));
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 */
Expand All @@ -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);
}

/*--------------------------------------------------------------------------------*
Expand Down

0 comments on commit 396d8ac

Please sign in to comment.