88#include <pm/device.h>
99#include <pm/device_runtime.h>
1010
11- static int testing_domain_on_notitication ;
12- static int testing_domain_off_notitication ;
11+ #define NUMBER_OF_DEVICES 3
1312
1413#define TEST_DOMAIN DT_NODELABEL(test_domain)
1514#define TEST_DEVA DT_NODELABEL(test_dev_a)
1615#define TEST_DEVB DT_NODELABEL(test_dev_b)
1716
18- static const struct device * domain , * deva , * devb ;
17+ static const struct device * domain , * deva , * devb , * devc ;
18+ static int testing_domain_on_notitication ;
19+ static int testing_domain_off_notitication ;
1920
2021static int dev_init (const struct device * dev )
2122{
@@ -106,6 +107,11 @@ PM_DEVICE_DT_DEFINE(TEST_DEVB, devb_pm_action);
106107DEVICE_DT_DEFINE (TEST_DEVB , dev_init , PM_DEVICE_DT_GET (TEST_DEVB ),
107108 NULL , NULL , POST_KERNEL , 30 , NULL );
108109
110+ PM_DEVICE_DEFINE (devc , deva_pm_action );
111+ DEVICE_DEFINE (devc , "devc" , dev_init , PM_DEVICE_GET (devc ),
112+ NULL , NULL ,
113+ APPLICATION , CONFIG_KERNEL_INIT_PRIORITY_DEVICE , NULL );
114+
109115/**
110116 * @brief Test the power domain behavior
111117 *
@@ -122,14 +128,23 @@ static void test_power_domain_device_runtime(void)
122128 domain = DEVICE_DT_GET (TEST_DOMAIN );
123129 deva = DEVICE_DT_GET (TEST_DEVA );
124130 devb = DEVICE_DT_GET (TEST_DEVB );
131+ devc = DEVICE_GET (devc );
125132
126133 pm_device_init_suspended (domain );
127134 pm_device_init_suspended (deva );
128135 pm_device_init_suspended (devb );
136+ pm_device_init_suspended (devc );
129137
130138 pm_device_runtime_enable (domain );
131139 pm_device_runtime_enable (deva );
132140 pm_device_runtime_enable (devb );
141+ pm_device_runtime_enable (devc );
142+
143+ ret = pm_device_power_domain_remove (devc , domain );
144+ zassert_equal (ret , - ENOENT , NULL );
145+
146+ ret = pm_device_power_domain_add (devc , domain );
147+ zassert_equal (ret , 0 , NULL );
133148
134149 /* At this point all devices should be SUSPENDED */
135150 pm_device_state_get (domain , & state );
@@ -141,6 +156,9 @@ static void test_power_domain_device_runtime(void)
141156 pm_device_state_get (devb , & state );
142157 zassert_equal (state , PM_DEVICE_STATE_SUSPENDED , NULL );
143158
159+ pm_device_state_get (devc , & state );
160+ zassert_equal (state , PM_DEVICE_STATE_SUSPENDED , NULL );
161+
144162 /* Now test if "get" a device will resume the domain */
145163 ret = pm_device_runtime_get (deva );
146164 zassert_equal (ret , 0 , NULL );
@@ -151,6 +169,9 @@ static void test_power_domain_device_runtime(void)
151169 pm_device_state_get (domain , & state );
152170 zassert_equal (state , PM_DEVICE_STATE_ACTIVE , NULL );
153171
172+ ret = pm_device_runtime_get (devc );
173+ zassert_equal (ret , 0 , NULL );
174+
154175 ret = pm_device_runtime_get (devb );
155176 zassert_equal (ret , 0 , NULL );
156177
@@ -171,6 +192,9 @@ static void test_power_domain_device_runtime(void)
171192 ret = pm_device_runtime_put (devb );
172193 zassert_equal (ret , 0 , NULL );
173194
195+ ret = pm_device_runtime_put (devc );
196+ zassert_equal (ret , 0 , NULL );
197+
174198 pm_device_state_get (domain , & state );
175199 zassert_equal (state , PM_DEVICE_STATE_SUSPENDED , NULL );
176200
@@ -190,17 +214,20 @@ static void test_power_domain_device_runtime(void)
190214 */
191215
192216 /* Three devices has to get the notification */
193- testing_domain_on_notitication = 2 ;
217+ testing_domain_on_notitication = NUMBER_OF_DEVICES ;
194218 ret = pm_device_runtime_get (domain );
195219 zassert_equal (ret , 0 , NULL );
196220
197221 zassert_equal (testing_domain_on_notitication , 0 , NULL );
198222
199- testing_domain_off_notitication = 2 ;
223+ testing_domain_off_notitication = NUMBER_OF_DEVICES ;
200224 ret = pm_device_runtime_put (domain );
201225 zassert_equal (ret , 0 , NULL );
202226
203227 zassert_equal (testing_domain_off_notitication , 0 , NULL );
228+
229+ ret = pm_device_power_domain_remove (devc , domain );
230+ zassert_equal (ret , 0 , NULL );
204231}
205232
206233void test_main (void )
0 commit comments