Skip to content
Permalink
Browse files

tests/kernel/context: Fix sleep test for fast ticks

The sleep test was checking that the sleep took no longer than "2
ticks" longer than requested.  But "2 ticks" for fast tick rate
configurations can be "zero ms", and for aliasing reasons it's always
possible to delay for 1 unit more than requested (becuase you can
cross a millisecond/tick/whatever boundary in your own code on either
side of the sleep).  So that "slop" value needs to be no less than
1ms.

Signed-off-by: Andy Ross <andrew.j.ross@intel.com>
  • Loading branch information...
andyross authored and nashif committed Jun 12, 2019
1 parent 8bd8663 commit f4803bf117aae948f05f4e404fd41834db5f5403
Showing with 3 additions and 1 deletion.
  1. +3 −1 tests/kernel/context/src/main.c
@@ -697,7 +697,9 @@ static void thread_sleep(void *delta, void *arg2, void *arg3)
timestamp = k_uptime_get() - timestamp;
TC_PRINT(" thread back from sleep\n");

if (timestamp < timeout || timestamp > timeout + __ticks_to_ms(2)) {
int slop = MAX(__ticks_to_ms(2), 1);

if (timestamp < timeout || timestamp > timeout + slop) {
TC_ERROR("timestamp out of range, got %d\n", (int)timestamp);
return;
}

0 comments on commit f4803bf

Please sign in to comment.
You can’t perform that action at this time.