Skip to content

Commit 8eff15b

Browse files
Jordan Yatescarlescufi
authored andcommitted
tests: pm: device: test pm_device_is_powered
Add tests for the function that checks whether a device is currently powered. Signed-off-by: Jordan Yates <[email protected]>
1 parent 319ffae commit 8eff15b

File tree

1 file changed

+16
-0
lines changed
  • tests/subsys/pm/device_power_domains/src

1 file changed

+16
-0
lines changed

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

Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -15,25 +15,41 @@ static void test_demo(void)
1515
const struct device *reg_1 = DEVICE_DT_GET(DT_NODELABEL(test_reg_1));
1616
const struct device *reg_chained = DEVICE_DT_GET(DT_NODELABEL(test_reg_chained));
1717

18+
/* Initial power state */
19+
zassert_true(pm_device_is_powered(reg_0), "");
20+
zassert_true(pm_device_is_powered(reg_1), "");
21+
zassert_false(pm_device_is_powered(reg_chained), "");
22+
1823
TC_PRINT("Enabling runtime power management on regulators\n");
1924

2025
pm_device_runtime_enable(reg_0);
2126
pm_device_runtime_enable(reg_1);
2227
pm_device_runtime_enable(reg_chained);
2328

29+
/* State shouldn't have changed */
30+
zassert_true(pm_device_is_powered(reg_0), "");
31+
zassert_true(pm_device_is_powered(reg_1), "");
32+
zassert_false(pm_device_is_powered(reg_chained), "");
33+
2434
TC_PRINT("Cycling: %s\n", reg_0->name);
2535

36+
/* reg_chained is powered off reg_0, so it's power state should change */
2637
pm_device_runtime_get(reg_0);
38+
zassert_true(pm_device_is_powered(reg_chained), "");
2739
pm_device_runtime_put(reg_0);
40+
zassert_false(pm_device_is_powered(reg_chained), "");
2841

2942
TC_PRINT("Cycling: %s\n", reg_1->name);
3043

3144
pm_device_runtime_get(reg_1);
45+
zassert_false(pm_device_is_powered(reg_chained), "");
3246
pm_device_runtime_put(reg_1);
3347

3448
TC_PRINT("Cycling: %s\n", reg_chained->name);
3549

50+
/* reg_chained should be powered after being requested */
3651
pm_device_runtime_get(reg_chained);
52+
zassert_true(pm_device_is_powered(reg_chained), "");
3753
pm_device_runtime_put(reg_chained);
3854

3955
TC_PRINT("DONE\n");

0 commit comments

Comments
 (0)