From 2de873436fa24c393707fdaeaf1d715d5deb25c4 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Krzysztof=20Chru=C5=9Bci=C5=84ski?= Date: Mon, 13 Jan 2025 10:12:48 +0100 Subject: [PATCH] tests: benchmarks: power_consumption: Allow controlled thread suspension MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Test was suspending test thread from the timer interrupt at random (but periodic) point. Some drivers which are tested in that framework handles power management in the thread context. Randomly suspending the test thread could lead to a case where driver did not finish requested operation and system goes to s2ram in the middle of the driver operation. Extending the test framework to allow more controlled thread suspension. Timer can indicate to the thread that is shall be suspended and thread calls self suspension when ready. Signed-off-by: Krzysztof Chruściński --- tests/benchmarks/power_consumption/common/main.c | 14 +++++++++++++- 1 file changed, 13 insertions(+), 1 deletion(-) diff --git a/tests/benchmarks/power_consumption/common/main.c b/tests/benchmarks/power_consumption/common/main.c index e46ee0cc1b3b..42d891490338 100644 --- a/tests/benchmarks/power_consumption/common/main.c +++ b/tests/benchmarks/power_consumption/common/main.c @@ -12,6 +12,16 @@ const struct gpio_dt_spec led = GPIO_DT_SPEC_GET(DT_ALIAS(led2), gpios); static bool state = true; extern void thread_definition(void); +/* Some tests require that test thread controls when the moment when it is + * suspended. In that case test implements this function and returns true to + * indicated that test thread will take case of the suspension and it can + * be skipped in the common code. + */ +__weak bool self_suspend_req(void) +{ + return false; +} + K_THREAD_DEFINE(thread_id, 500, thread_definition, NULL, NULL, NULL, 5, 0, 0); @@ -24,7 +34,9 @@ void timer_handler(struct k_timer *dummy) } else { state = true; gpio_pin_set_dt(&led, 0); - k_thread_suspend(thread_id); + if (self_suspend_req() == false) { + k_thread_suspend(thread_id); + } } }