From b49f8ae686cefea47ea8f983602f63743e0afd60 Mon Sep 17 00:00:00 2001 From: Flavio Ceolin Date: Fri, 19 Apr 2024 14:16:15 -0700 Subject: [PATCH] tests: power_mgmt: Test system-managed disabled per state Check that a power state that has system-managed device power management disabled does not trigger device power management when the system sleeps. Signed-off-by: Flavio Ceolin --- .../pm/power_mgmt/boards/native_sim.overlay | 7 ++++++- tests/subsys/pm/power_mgmt/src/main.c | 15 ++++++++++++--- 2 files changed, 18 insertions(+), 4 deletions(-) diff --git a/tests/subsys/pm/power_mgmt/boards/native_sim.overlay b/tests/subsys/pm/power_mgmt/boards/native_sim.overlay index a5eb7f26234cbad..eee1b914540fb15 100644 --- a/tests/subsys/pm/power_mgmt/boards/native_sim.overlay +++ b/tests/subsys/pm/power_mgmt/boards/native_sim.overlay @@ -11,6 +11,11 @@ compatible = "zephyr,power-state"; power-state-name = "suspend-to-idle"; }; + state1: state1 { + compatible = "zephyr,power-state"; + power-state-name = "standby"; + zephyr,pm-device-disabled; + }; }; }; @@ -36,5 +41,5 @@ }; &cpu0 { - cpu-power-states = <&state0>; + cpu-power-states = <&state0 &state1>; }; diff --git a/tests/subsys/pm/power_mgmt/src/main.c b/tests/subsys/pm/power_mgmt/src/main.c index c93a1d43e84ccab..3c75e44587fc77c 100644 --- a/tests/subsys/pm/power_mgmt/src/main.c +++ b/tests/subsys/pm/power_mgmt/src/main.c @@ -199,6 +199,12 @@ void pm_state_set(enum pm_state state, uint8_t substate_id) set_pm = true; zassert_equal(state, forced_state, NULL); testing_force_state = false; + + /* We have forced a state that does not trigger device power management. + * The device should still be active. + */ + pm_device_state_get(device_c, &device_power_state); + zassert_true(device_power_state == PM_DEVICE_STATE_ACTIVE); } /* at this point, notify_pm_state_entry() implemented in @@ -244,7 +250,7 @@ const struct pm_state_info *pm_policy_next_state(uint8_t cpu, int32_t ticks) { const struct pm_state_info *cpu_states; - zassert_true(pm_state_cpu_get_all(cpu, &cpu_states) == 1, + zassert_true(pm_state_cpu_get_all(cpu, &cpu_states) == 2, "There is no power state defined"); /* make sure this is idle thread */ @@ -457,8 +463,11 @@ ZTEST(power_management_1cpu, test_empty_states) ZTEST(power_management_1cpu, test_force_state) { - forced_state = PM_STATE_STANDBY; - bool ret = pm_state_force(0, &(struct pm_state_info) {forced_state, 0, 0}); + const struct pm_state_info *cpu_states; + + pm_state_cpu_get_all(0, &cpu_states); + forced_state = cpu_states[1].state; + bool ret = pm_state_force(0, &cpu_states[1]); zassert_equal(ret, true, "Error in force state");