Skip to content

Commit 3b43cb3

Browse files
mmahadevan108kartben
authored andcommitted
tests: pm: Test the SoC State Change Power Domain driver
The SoC State Change Power Domain driver issues TURN_ON/ TURN_OFF actions to all devices registered with it for certain power states that can be specified via device tree. This test exercises the functionality of this driver. Signed-off-by: Mahesh Mahadevan <[email protected]>
1 parent b579a90 commit 3b43cb3

File tree

7 files changed

+185
-0
lines changed

7 files changed

+185
-0
lines changed
Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,8 @@
1+
# Copyright 2025 NXP
2+
# SPDX-License-Identifier: Apache-2.0
3+
4+
cmake_minimum_required(VERSION 3.20.0)
5+
find_package(Zephyr REQUIRED HINTS $ENV{ZEPHYR_BASE})
6+
project(power_domain_soc_state_change)
7+
8+
target_sources(app PRIVATE src/main.c)
Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,11 @@
1+
# Copyright (c) 2023 Nordic Semiconductor ASA
2+
# SPDX-License-Identifier: Apache-2.0
3+
4+
menu "Zephyr"
5+
source "Kconfig.zephyr"
6+
endmenu
7+
8+
config TEST_PROVIDE_PM_HOOKS
9+
bool "Provide PM hooks for test purposes"
10+
default y
11+
select HAS_PM
Lines changed: 46 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,46 @@
1+
/*
2+
* Copyright 2025 NXP
3+
* SPDX-License-Identifier: Apache-2.0
4+
*/
5+
6+
/ {
7+
power-states {
8+
state0: state0 {
9+
compatible = "zephyr,power-state";
10+
power-state-name = "runtime-idle";
11+
min-residency-us = <10000>;
12+
exit-latency-us = <100>;
13+
};
14+
15+
state1: state1 {
16+
compatible = "zephyr,power-state";
17+
power-state-name = "suspend-to-idle";
18+
min-residency-us = <50000>;
19+
exit-latency-us = <500>;
20+
};
21+
22+
state2: state2 {
23+
compatible = "zephyr,power-state";
24+
power-state-name = "standby";
25+
min-residency-us = <100000>;
26+
exit-latency-us = <1000>;
27+
};
28+
};
29+
30+
test_soc_state_domain: test_soc_state_domain {
31+
compatible = "power-domain-soc-state-change";
32+
status = "okay";
33+
onoff-power-states = <&state1 &state2>;
34+
#power-domain-cells = <0>;
35+
};
36+
37+
test_dev_soc_state_change: test_dev_soc_state_change {
38+
compatible = "test-device-pm";
39+
status = "okay";
40+
power-domains = <&test_soc_state_domain>;
41+
};
42+
};
43+
44+
&cpu0 {
45+
cpu-power-states = <&state0 &state1 &state2>;
46+
};
Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,10 @@
1+
# Copyright 2025 NXP
2+
# SPDX-License-Identifier: Apache-2.0
3+
4+
include: [base.yaml, pm.yaml]
5+
6+
description: |
7+
This binding provides resources required to build and run the
8+
tests/subsys/pm/power_domain_soc_state_change test in Zephyr.
9+
10+
compatible: "test-device-pm"
Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,7 @@
1+
# Copyright 2025 NXP
2+
# SPDX-License-Identifier: Apache-2.0
3+
4+
CONFIG_ZTEST=y
5+
CONFIG_PM=y
6+
CONFIG_PM_DEVICE=y
7+
CONFIG_POWER_DOMAIN=y
Lines changed: 93 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,93 @@
1+
/*
2+
* Copyright 2025 NXP
3+
*
4+
* SPDX-License-Identifier: Apache-2.0
5+
*/
6+
7+
#include <zephyr/ztest.h>
8+
#include <zephyr/pm/device.h>
9+
10+
#define TEST_DEV DT_NODELABEL(test_dev_soc_state_change)
11+
12+
static int testing_domain_on_notitication;
13+
static int testing_domain_off_notitication;
14+
15+
void pm_state_set(enum pm_state state, uint8_t substate_id)
16+
{
17+
ARG_UNUSED(substate_id);
18+
19+
switch (testing_domain_off_notitication) {
20+
case 1:
21+
zassert_equal(state, PM_STATE_STANDBY, "Wrong system state %d", state);
22+
break;
23+
case 2:
24+
zassert_true(
25+
((state == PM_STATE_SUSPEND_TO_IDLE) || (state == PM_STATE_RUNTIME_IDLE)),
26+
"Wrong system state %d", state);
27+
break;
28+
default:
29+
break;
30+
}
31+
32+
k_cpu_idle();
33+
}
34+
35+
void pm_state_exit_post_ops(enum pm_state state, uint8_t substate_id)
36+
{
37+
ARG_UNUSED(state);
38+
ARG_UNUSED(substate_id);
39+
40+
irq_unlock(0);
41+
}
42+
43+
static int dev_pm_action(const struct device *dev, enum pm_device_action pm_action)
44+
{
45+
ARG_UNUSED(dev);
46+
47+
if (pm_action == PM_DEVICE_ACTION_TURN_ON) {
48+
testing_domain_on_notitication++;
49+
}
50+
51+
if (pm_action == PM_DEVICE_ACTION_TURN_OFF) {
52+
testing_domain_off_notitication++;
53+
}
54+
55+
return 0;
56+
}
57+
58+
PM_DEVICE_DT_DEFINE(TEST_DEV, dev_pm_action);
59+
DEVICE_DT_DEFINE(TEST_DEV, NULL, PM_DEVICE_DT_GET(TEST_DEV), NULL, NULL, POST_KERNEL, 20, NULL);
60+
61+
ZTEST(power_domain_soc_state_change_1cpu, test_power_domain_soc_state_change)
62+
{
63+
const struct pm_state_info *cpu_states, *state;
64+
65+
pm_state_cpu_get_all(_current_cpu->id, &cpu_states);
66+
67+
state = &cpu_states[2];
68+
/* Sleep to transition to STATE: STANDBY */
69+
k_usleep(state->min_residency_us + state->exit_latency_us);
70+
71+
zassert_equal(testing_domain_on_notitication, 1);
72+
zassert_equal(testing_domain_off_notitication, 1);
73+
74+
state = &cpu_states[1];
75+
/* Sleep to transition to STATE: SUSPEND-TO-IDLE */
76+
k_usleep(state->min_residency_us + state->exit_latency_us);
77+
78+
zassert_equal(testing_domain_on_notitication, 2);
79+
zassert_equal(testing_domain_off_notitication, 2);
80+
81+
state = &cpu_states[0];
82+
/* Sleep to transition to STATE: RUNTIME-IDLE */
83+
k_usleep(state->min_residency_us + state->exit_latency_us);
84+
85+
/* The domain notification flags should remain the same as RUNTIME-IDLE
86+
* is not listed as an ON/OFF power state in device-tree.
87+
*/
88+
zassert_equal(testing_domain_on_notitication, 2);
89+
zassert_equal(testing_domain_off_notitication, 2);
90+
}
91+
92+
ZTEST_SUITE(power_domain_soc_state_change_1cpu, NULL, NULL, ztest_simple_1cpu_before,
93+
ztest_simple_1cpu_after, NULL);
Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,10 @@
1+
# Copyright 2025 NXP
2+
# SPDX-License-Identifier: Apache-2.0
3+
4+
tests:
5+
pm.power_domain_soc_state_change:
6+
platform_allow:
7+
- native_sim
8+
integration_platforms:
9+
- native_sim
10+
tags: pm

0 commit comments

Comments
 (0)