Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fix #1080, add range to OS_TaskDelay checks #1081

Merged
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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