From 22c83f0f971b16b0a1ae62523c465d524df2bc36 Mon Sep 17 00:00:00 2001 From: Alberto Escolar Piedras Date: Fri, 3 May 2024 14:43:34 +0200 Subject: [PATCH] tests/kernel/context: Detect spurious wakes during timeout check In 972a4d9f6f82c811281fd53ef27a028bf2880955 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 --- tests/kernel/context/src/main.c | 3 +++ 1 file changed, 3 insertions(+) diff --git a/tests/kernel/context/src/main.c b/tests/kernel/context/src/main.c index ff0e0196c90..516ddb1ef5b 100644 --- a/tests/kernel/context/src/main.c +++ b/tests/kernel/context/src/main.c @@ -245,6 +245,9 @@ static void _test_kernel_cpu_idle(int atomic) k_cpu_idle(); } } 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; zassert_true(abs((int32_t) (dt - dur)) <= slop, "Inaccurate wakeup, idled for %d ticks, expected %d",