Skip to content
Permalink
Browse files

tests/kernel/sched/schedule_api: Fix slice time test for fast ticks

When ticks are sub-millisecond, the math produces minimum and maximum
values for the slice duration test that are equal.  But because of
aliasing across tick boundaries, it's always possible (for any time
period, nothing specific to time slicing here) to measure one tick
more than an intended duration.  So make sure there's always at least
a range of 1ms.

Signed-off-by: Andy Ross <andrew.j.ross@intel.com>
  • Loading branch information...
andyross authored and nashif committed Jun 12, 2019
1 parent 05c8e05 commit e019dac77626767eb2b7d64b8c2d73b9f2475e85
Showing with 8 additions and 0 deletions.
  1. +8 −0 tests/kernel/sched/schedule_api/src/test_slice_scheduling.c
@@ -44,6 +44,14 @@ static void thread_tslice(void *p1, void *p2, void *p3)
s64_t expected_slice_min = __ticks_to_ms(z_ms_to_ticks(SLICE_SIZE));
s64_t expected_slice_max = __ticks_to_ms(z_ms_to_ticks(SLICE_SIZE) + 1);

/* Clumsy, but need to handle the precision loss with
* submillisecond ticks. It's always possible to alias and
* produce a tdelta of "1", no matter how fast ticks are.
*/
if (expected_slice_max == expected_slice_min) {
expected_slice_max = expected_slice_min + 1;
}

while (1) {
s64_t tdelta = k_uptime_delta(&elapsed_slice);
TC_PRINT("%c", thread_parameter);

0 comments on commit e019dac

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