Skip to content

Commit 2fde221

Browse files
adrien-lessardcfriedt
authored andcommitted
tests: pm: device_power_domains: failed power pm_action_cb
Added tests to demonstrate a safe rollback when either TURN_ON or RESUME fail. Note: before this PR, rollback would only be valid if TURN_ON failed, not when RESUME failed. Signed-off-by: Adrien Lessard <[email protected]>
1 parent c5229fc commit 2fde221

File tree

1 file changed

+46
-2
lines changed
  • tests/subsys/pm/device_power_domains/src

1 file changed

+46
-2
lines changed

tests/subsys/pm/device_power_domains/src/main.c

Lines changed: 46 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -9,6 +9,9 @@
99
#include <zephyr/pm/device.h>
1010
#include <zephyr/pm/device_runtime.h>
1111

12+
static int dev_pm_control_resume_ret;
13+
static int dev_pm_control_turn_on_ret;
14+
1215
static int dev_init(const struct device *dev)
1316
{
1417
if (!pm_device_is_powered(dev)) {
@@ -20,9 +23,26 @@ static int dev_init(const struct device *dev)
2023
int dev_pm_control(const struct device *dev, enum pm_device_action action)
2124
{
2225
ARG_UNUSED(dev);
23-
ARG_UNUSED(action);
2426

25-
return 0;
27+
int ret = 0;
28+
29+
switch (action) {
30+
case PM_DEVICE_ACTION_SUSPEND:
31+
break;
32+
case PM_DEVICE_ACTION_RESUME:
33+
ret = dev_pm_control_resume_ret;
34+
break;
35+
case PM_DEVICE_ACTION_TURN_ON:
36+
ret = dev_pm_control_turn_on_ret;
37+
break;
38+
case PM_DEVICE_ACTION_TURN_OFF:
39+
break;
40+
default:
41+
ret = -ENOTSUP;
42+
break;
43+
}
44+
45+
return ret;
2646
}
2747

2848
PM_DEVICE_DT_DEFINE(DT_NODELABEL(test_dev), dev_pm_control);
@@ -133,6 +153,30 @@ ZTEST(device_power_domain, test_device_power_domain)
133153
pm_device_state_get(reg_1, &state);
134154
zassert_equal(PM_DEVICE_STATE_SUSPENDED, state, "");
135155

156+
/* Directly request the supported device but turn on fails */
157+
dev_pm_control_turn_on_ret = -EBUSY;
158+
pm_device_runtime_get(dev);
159+
dev_pm_control_turn_on_ret = 0;
160+
zassert_false(pm_device_is_powered(dev), "");
161+
pm_device_state_get(dev, &state);
162+
zassert_equal(PM_DEVICE_STATE_OFF, state, "");
163+
pm_device_state_get(reg_1, &state);
164+
zassert_equal(PM_DEVICE_STATE_SUSPENDED, state, "");
165+
pm_device_state_get(reg_chained, &state);
166+
zassert_equal(PM_DEVICE_STATE_OFF, state, "");
167+
168+
/* Directly request the supported device but resume fails */
169+
dev_pm_control_resume_ret = -EBUSY;
170+
pm_device_runtime_get(dev);
171+
dev_pm_control_resume_ret = 0;
172+
zassert_false(pm_device_is_powered(dev), "");
173+
pm_device_state_get(dev, &state);
174+
zassert_equal(PM_DEVICE_STATE_OFF, state, "");
175+
pm_device_state_get(reg_1, &state);
176+
zassert_equal(PM_DEVICE_STATE_SUSPENDED, state, "");
177+
pm_device_state_get(reg_chained, &state);
178+
zassert_equal(PM_DEVICE_STATE_OFF, state, "");
179+
136180
TC_PRINT("DONE\n");
137181
}
138182

0 commit comments

Comments
 (0)