tests/kernel/context: Detect spurious wakes during timeout check

In 972a4d9f6f
the test was relaxed to allow a possible parallel thread
waking the CPU during the idle timeout checks.

How this was done though, a system timer driver
which wakes the kernel spuriously a bit before the
correct deadline would not be detected, even
though it should.

Let's fix this, ensuring the timer has been
called when we check the wake time in inside the
expected range.

Signed-off-by: Alberto Escolar Piedras <alberto.escolar.piedras@nordicsemi.no>
This commit is contained in:
Alberto Escolar Piedras 2024-05-03 14:43:34 +02:00 committed by Anas Nashif
commit 22c83f0f97

View file

@ -245,6 +245,9 @@ static void _test_kernel_cpu_idle(int atomic)
k_cpu_idle(); k_cpu_idle();
} }
} while ((idle_loops++ < CONFIG_MAX_IDLE_WAKES) && (idle_timer_done == false)); } while ((idle_loops++ < CONFIG_MAX_IDLE_WAKES) && (idle_timer_done == false));
zassert_true(idle_timer_done,
"The CPU was waken spuriously too many times (%d > %d)",
idle_loops, CONFIG_MAX_IDLE_WAKES);
dt = k_uptime_ticks() - t0; dt = k_uptime_ticks() - t0;
zassert_true(abs((int32_t) (dt - dur)) <= slop, zassert_true(abs((int32_t) (dt - dur)) <= slop,
"Inaccurate wakeup, idled for %d ticks, expected %d", "Inaccurate wakeup, idled for %d ticks, expected %d",