tests: power_mgmt: Use DTS overlay for power state

Define the power state needed in the test in DT.

Signed-off-by: Flavio Ceolin <flavio.ceolin@intel.com>
This commit is contained in:
Flavio Ceolin 2023-07-29 13:07:24 -07:00 committed by Anas Nashif
commit 45e9c2eed3
2 changed files with 19 additions and 9 deletions

View file

@ -5,6 +5,15 @@
*/ */
/ { / {
cpus {
power-states {
state0: state0 {
compatible = "zephyr,power-state";
power-state-name = "suspend-to-idle";
};
};
};
device_a: device_a { device_a: device_a {
compatible = "test-device-pm"; compatible = "test-device-pm";
}; };
@ -25,3 +34,7 @@
compatible = "test-device-pm"; compatible = "test-device-pm";
}; };
}; };
&cpu0 {
cpu-power-states = <&state0>;
};

View file

@ -229,9 +229,10 @@ void pm_state_exit_post_ops(enum pm_state state, uint8_t substate_id)
/* Our PM policy handler */ /* Our PM policy handler */
const struct pm_state_info *pm_policy_next_state(uint8_t cpu, int32_t ticks) 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 */ /* make sure this is idle thread */
zassert_true(z_is_idle_thread_object(_current)); 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) { if (enter_low_power) {
enter_low_power = false; enter_low_power = false;
notify_app_entry = true; notify_app_entry = true;
info.state = PM_STATE_SUSPEND_TO_IDLE; return &cpu_states[0];
} else {
/* only test pm_policy_next_state()
* no PM operation done
*/
info.state = PM_STATE_ACTIVE;
} }
return &info;
return NULL;
} }
/* implement in application, called by idle thread */ /* implement in application, called by idle thread */