Skip to content

Commit

Permalink
Merge pull request #1081 from jphickey/fix-1080-taskdelay-range
Browse files Browse the repository at this point in the history
Fix #1080, add range to OS_TaskDelay checks
  • Loading branch information
astrogeco authored Jul 2, 2021
2 parents 64a6b31 + 396d8ac commit 7777892
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 7777892

Please sign in to comment.