From 45e9c2eed34c12ee6cba4c2d783641c0b50fd26b Mon Sep 17 00:00:00 2001 From: Flavio Ceolin Date: Sat, 29 Jul 2023 13:07:24 -0700 Subject: [PATCH] tests: power_mgmt: Use DTS overlay for power state Define the power state needed in the test in DT. Signed-off-by: Flavio Ceolin --- .../pm/power_mgmt/boards/native_sim.overlay | 13 +++++++++++++ tests/subsys/pm/power_mgmt/src/main.c | 15 ++++++--------- 2 files changed, 19 insertions(+), 9 deletions(-) diff --git a/tests/subsys/pm/power_mgmt/boards/native_sim.overlay b/tests/subsys/pm/power_mgmt/boards/native_sim.overlay index a66ce9d0025..a5eb7f26234 100644 --- a/tests/subsys/pm/power_mgmt/boards/native_sim.overlay +++ b/tests/subsys/pm/power_mgmt/boards/native_sim.overlay @@ -5,6 +5,15 @@ */ / { + cpus { + power-states { + state0: state0 { + compatible = "zephyr,power-state"; + power-state-name = "suspend-to-idle"; + }; + }; + }; + device_a: device_a { compatible = "test-device-pm"; }; @@ -25,3 +34,7 @@ compatible = "test-device-pm"; }; }; + +&cpu0 { + cpu-power-states = <&state0>; +}; diff --git a/tests/subsys/pm/power_mgmt/src/main.c b/tests/subsys/pm/power_mgmt/src/main.c index 10746b49021..f3a6904e2b2 100644 --- a/tests/subsys/pm/power_mgmt/src/main.c +++ b/tests/subsys/pm/power_mgmt/src/main.c @@ -229,9 +229,10 @@ void pm_state_exit_post_ops(enum pm_state state, uint8_t substate_id) /* Our PM policy handler */ const struct pm_state_info *pm_policy_next_state(uint8_t cpu, int32_t ticks) { - static struct pm_state_info info; + const struct pm_state_info *cpu_states; - ARG_UNUSED(cpu); + zassert_true(pm_state_cpu_get_all(cpu, &cpu_states) == 1, + "There is no power state defined"); /* make sure this is idle thread */ zassert_true(z_is_idle_thread_object(_current)); @@ -242,14 +243,10 @@ const struct pm_state_info *pm_policy_next_state(uint8_t cpu, int32_t ticks) if (enter_low_power) { enter_low_power = false; notify_app_entry = true; - info.state = PM_STATE_SUSPEND_TO_IDLE; - } else { - /* only test pm_policy_next_state() - * no PM operation done - */ - info.state = PM_STATE_ACTIVE; + return &cpu_states[0]; } - return &info; + + return NULL; } /* implement in application, called by idle thread */