1 /*
2 * Copyright (c) 2021-2022 Huawei Device Co., Ltd.
3 *
4 * HDF is dual licensed: you can use it either under the terms of
5 * the GPL, or the BSD license, at your option.
6 * See the LICENSE file in the root of this repository for complete details.
7 */
8
9 #include "hdf_pm_driver_test.h"
10 #include "devsvc_manager.h"
11 #include "devsvc_manager_clnt.h"
12 #include "hdf_device_desc.h"
13 #include "hdf_device_node.h"
14 #include "hdf_log.h"
15 #include "hdf_pm.h"
16 #include "hdf_power_manager.h"
17 #include "hdf_task_queue.h"
18 #include "osal_time.h"
19 #include "power_state_token.h"
20
21 #define HDF_LOG_TAG pm_driver_test
22
23 #define PM_TEST_COUNT_ONE 1
24 #define PM_TEST_COUNT_TWO 2
25 #define PM_TEST_COUNT_TEN 10
26 #define PM_TEST_COUNT_HUNDRED 100
27 #define PM_TEST_COUNT_THOUSAND 1000
28
29 #define PM_WAIT_TIME 10
30 #define PM_WAIT_TIME_OUT 100
31 #define PM_WAIT_LOAD_TIME 30
32
33 #define CHECK_VALUE(index, cnt) \
34 (g_pmTestType[(index)].resumeCnt == (cnt) && g_pmTestType[(index)].suspendCnt == (cnt))
35
36 #define WAIT_TEST_END(value, idx) \
37 while ((value) == false && (idx) < PM_WAIT_TIME_OUT) { \
38 OsalMSleep(PM_WAIT_TIME); \
39 (idx)++; \
40 } \
41
42 enum {
43 HDF_TEST_DRIVER,
44 SAMPLE_TEST_DRIVER,
45 PM_TEST_DRIVER,
46 };
47
48 struct PmDriverPmListener {
49 struct IPowerEventListener powerListener;
50 void *p;
51 };
52 typedef int32_t (*TestFunc)(void);
53
54 struct TestCaseType {
55 uint32_t cmd;
56 TestFunc testFunc;
57 };
58 static int32_t HdfPmTestBegin(void);
59 static int32_t HdfPmTestOneDriverOnce(void);
60 static int32_t HdfPmTestOneDriverTwice(void);
61 static int32_t HdfPmTestOneDriverTen(void);
62 static int32_t HdfPmTestOneDriverHundred(void);
63 static int32_t HdfPmTestOneDriverThousand(void);
64 static int32_t HdfPmTestTwoDriverOnce(void);
65 static int32_t HdfPmTestTwoDriverTwice(void);
66 static int32_t HdfPmTestTwoDriverTen(void);
67 static int32_t HdfPmTestTwoDriverHundred(void);
68 static int32_t HdfPmTestTwoDriverThousand(void);
69 static int32_t HdfPmTestThreeDriverOnce(void);
70 static int32_t HdfPmTestThreeDriverTwice(void);
71 static int32_t HdfPmTestThreeDriverTen(void);
72 static int32_t HdfPmTestThreeDriverHundred(void);
73 static int32_t HdfPmTestThreeDriverThousand(void);
74 static int32_t HdfPmTestThreeDriverSeqHundred(void);
75 static int32_t HdfPmTestThreeDriverHundredWithSync(void);
76 static int32_t HdfPmTestEnd(void);
77
78 static const struct TestCaseType g_testCases[] = {
79 { HDF_PM_TEST_BEGEN, HdfPmTestBegin },
80 { HDF_PM_TEST_ONE_DRIVER_ONCE, HdfPmTestOneDriverOnce },
81 { HDF_PM_TEST_ONE_DRIVER_TWICE, HdfPmTestOneDriverTwice },
82 { HDF_PM_TEST_ONE_DRIVER_TEN, HdfPmTestOneDriverTen },
83 { HDF_PM_TEST_ONE_DRIVER_HUNDRED, HdfPmTestOneDriverHundred },
84 { HDF_PM_TEST_ONE_DRIVER_THOUSAND, HdfPmTestOneDriverThousand },
85 { HDF_PM_TEST_TWO_DRIVER_ONCE, HdfPmTestTwoDriverOnce },
86 { HDF_PM_TEST_TWO_DRIVER_TWICE, HdfPmTestTwoDriverTwice },
87 { HDF_PM_TEST_TWO_DRIVER_TEN, HdfPmTestTwoDriverTen },
88 { HDF_PM_TEST_TWO_DRIVER_HUNDRED, HdfPmTestTwoDriverHundred },
89 { HDF_PM_TEST_TWO_DRIVER_THOUSAND, HdfPmTestTwoDriverThousand },
90 { HDF_PM_TEST_THREE_DRIVER_ONCE, HdfPmTestThreeDriverOnce },
91 { HDF_PM_TEST_THREE_DRIVER_TWICE, HdfPmTestThreeDriverTwice },
92 { HDF_PM_TEST_THREE_DRIVER_TEN, HdfPmTestThreeDriverTen },
93 { HDF_PM_TEST_THREE_DRIVER_HUNDRED, HdfPmTestThreeDriverHundred },
94 { HDF_PM_TEST_THREE_DRIVER_THOUSAND, HdfPmTestThreeDriverThousand },
95 { HDF_PM_TEST_THREE_DRIVER_SEQ_HUNDRED, HdfPmTestThreeDriverSeqHundred },
96 { HDF_PM_TEST_THREE_DRIVER_HUNDRED_WITH_SYNC, HdfPmTestThreeDriverHundredWithSync },
97 { HDF_PM_TEST_END, HdfPmTestEnd },
98 };
99
100 static const char *g_serviceName[] = { "khdf_ut", "sample_service", "pm_ut_service" };
101
102 struct PmTestType {
103 const char *serviceName;
104 struct HdfDeviceObject *obj;
105 struct PmDriverPmListener listener;
106 const struct IPowerEventListener *listenerBak;
107 uint32_t resumeCnt;
108 uint32_t suspendCnt;
109 };
110
111 static struct PmTestType g_pmTestType[PM_TEST_DRIVER + 1];
112
113 static bool loopTest = false;
114
HdfPmHdfTestDozeResume(struct HdfDeviceObject * deviceObject)115 static int HdfPmHdfTestDozeResume(struct HdfDeviceObject *deviceObject)
116 {
117 (void)deviceObject;
118 HDF_LOGI("%s called", __func__);
119 return HDF_SUCCESS;
120 }
121
HdfPmHdfTestDozeSuspend(struct HdfDeviceObject * deviceObject)122 static int HdfPmHdfTestDozeSuspend(struct HdfDeviceObject *deviceObject)
123 {
124 (void)deviceObject;
125 HDF_LOGI("%s called", __func__);
126 return HDF_SUCCESS;
127 }
128
HdfPmHdfTestResume(struct HdfDeviceObject * deviceObject)129 static int HdfPmHdfTestResume(struct HdfDeviceObject *deviceObject)
130 {
131 (void)deviceObject;
132 if (loopTest == false) {
133 HDF_LOGI("%s called", __func__);
134 }
135
136 g_pmTestType[HDF_TEST_DRIVER].resumeCnt++;
137 return HDF_SUCCESS;
138 }
139
HdfPmHdfTestSuspend(struct HdfDeviceObject * deviceObject)140 static int HdfPmHdfTestSuspend(struct HdfDeviceObject *deviceObject)
141 {
142 (void)deviceObject;
143 if (loopTest == false) {
144 HDF_LOGI("%s called", __func__);
145 }
146 g_pmTestType[HDF_TEST_DRIVER].suspendCnt++;
147 return HDF_SUCCESS;
148 }
149
HdfPmSampleDozeResume(struct HdfDeviceObject * deviceObject)150 static int HdfPmSampleDozeResume(struct HdfDeviceObject *deviceObject)
151 {
152 (void)deviceObject;
153 HDF_LOGI("%s called", __func__);
154 return HDF_SUCCESS;
155 }
156
HdfPmSampleDozeSuspend(struct HdfDeviceObject * deviceObject)157 static int HdfPmSampleDozeSuspend(struct HdfDeviceObject *deviceObject)
158 {
159 (void)deviceObject;
160 HDF_LOGI("%s called", __func__);
161 return HDF_SUCCESS;
162 }
163
HdfPmSampleResume(struct HdfDeviceObject * deviceObject)164 static int HdfPmSampleResume(struct HdfDeviceObject *deviceObject)
165 {
166 (void)deviceObject;
167 if (loopTest == false) {
168 HDF_LOGI("%s called", __func__);
169 }
170 g_pmTestType[SAMPLE_TEST_DRIVER].resumeCnt++;
171 return HDF_SUCCESS;
172 }
173
HdfPmSampleSuspend(struct HdfDeviceObject * deviceObject)174 static int HdfPmSampleSuspend(struct HdfDeviceObject *deviceObject)
175 {
176 (void)deviceObject;
177 if (loopTest == false) {
178 HDF_LOGI("%s called", __func__);
179 }
180 g_pmTestType[SAMPLE_TEST_DRIVER].suspendCnt++;
181 return HDF_SUCCESS;
182 }
183
HdfPmTestDozeResume(struct HdfDeviceObject * deviceObject)184 static int HdfPmTestDozeResume(struct HdfDeviceObject *deviceObject)
185 {
186 (void)deviceObject;
187 HDF_LOGI("%s called", __func__);
188 return HDF_SUCCESS;
189 }
190
HdfPmTestDozeSuspend(struct HdfDeviceObject * deviceObject)191 static int HdfPmTestDozeSuspend(struct HdfDeviceObject *deviceObject)
192 {
193 (void)deviceObject;
194 HDF_LOGI("%s called", __func__);
195 return HDF_SUCCESS;
196 }
197
HdfPmTestResume(struct HdfDeviceObject * deviceObject)198 static int HdfPmTestResume(struct HdfDeviceObject *deviceObject)
199 {
200 (void)deviceObject;
201 if (loopTest == false) {
202 HDF_LOGI("%s called", __func__);
203 }
204 g_pmTestType[PM_TEST_DRIVER].resumeCnt++;
205 return HDF_SUCCESS;
206 }
207
HdfPmTestSuspend(struct HdfDeviceObject * deviceObject)208 static int HdfPmTestSuspend(struct HdfDeviceObject *deviceObject)
209 {
210 (void)deviceObject;
211 if (loopTest == false) {
212 HDF_LOGI("%s called", __func__);
213 }
214 g_pmTestType[PM_TEST_DRIVER].suspendCnt++;
215 return HDF_SUCCESS;
216 }
217
HdfPmSetListeners(void)218 static void HdfPmSetListeners(void)
219 {
220 g_pmTestType[HDF_TEST_DRIVER].listener.powerListener.DozeResume = HdfPmHdfTestDozeResume;
221 g_pmTestType[HDF_TEST_DRIVER].listener.powerListener.DozeSuspend = HdfPmHdfTestDozeSuspend;
222 g_pmTestType[HDF_TEST_DRIVER].listener.powerListener.Resume = HdfPmHdfTestResume;
223 g_pmTestType[HDF_TEST_DRIVER].listener.powerListener.Suspend = HdfPmHdfTestSuspend;
224
225 g_pmTestType[SAMPLE_TEST_DRIVER].listener.powerListener.DozeResume = HdfPmSampleDozeResume;
226 g_pmTestType[SAMPLE_TEST_DRIVER].listener.powerListener.DozeSuspend = HdfPmSampleDozeSuspend;
227 g_pmTestType[SAMPLE_TEST_DRIVER].listener.powerListener.Resume = HdfPmSampleResume;
228 g_pmTestType[SAMPLE_TEST_DRIVER].listener.powerListener.Suspend = HdfPmSampleSuspend;
229
230 g_pmTestType[PM_TEST_DRIVER].listener.powerListener.DozeResume = HdfPmTestDozeResume;
231 g_pmTestType[PM_TEST_DRIVER].listener.powerListener.DozeSuspend = HdfPmTestDozeSuspend;
232 g_pmTestType[PM_TEST_DRIVER].listener.powerListener.Resume = HdfPmTestResume;
233 g_pmTestType[PM_TEST_DRIVER].listener.powerListener.Suspend = HdfPmTestSuspend;
234 }
235
HdfPmClearTestCnt(void)236 static void HdfPmClearTestCnt(void)
237 {
238 uint32_t index;
239
240 for (index = 0; index <= PM_TEST_DRIVER; index++) {
241 g_pmTestType[index].resumeCnt = 0;
242 g_pmTestType[index].suspendCnt = 0;
243 }
244 }
245
HdfPmRegisterTestListener(int32_t index)246 static void HdfPmRegisterTestListener(int32_t index)
247 {
248 struct SubscriberCallback callback = {NULL};
249 struct HdfDeviceNode *devNode = NULL;
250
251 g_pmTestType[index].serviceName = g_serviceName[index];
252 g_pmTestType[index].obj = DevSvcManagerClntGetDeviceObject(g_pmTestType[index].serviceName);
253 if (g_pmTestType[index].obj == NULL) {
254 DevSvcManagerClntSubscribeService(g_pmTestType[index].serviceName, callback);
255 OsalMSleep(PM_WAIT_LOAD_TIME);
256 g_pmTestType[index].obj = DevSvcManagerClntGetDeviceObject(g_pmTestType[index].serviceName);
257 }
258
259 if (g_pmTestType[index].obj) {
260 devNode = (struct HdfDeviceNode *)HDF_SLIST_CONTAINER_OF(
261 struct HdfDeviceObject, g_pmTestType[index].obj, struct HdfDeviceNode, deviceObject);
262 if ((devNode->powerToken != NULL) && (devNode->powerToken->listener != NULL)) {
263 g_pmTestType[index].listenerBak = devNode->powerToken->listener;
264 HdfPmUnregisterPowerListener(g_pmTestType[index].obj, g_pmTestType[index].listenerBak);
265 } else {
266 g_pmTestType[index].listenerBak = NULL;
267 }
268
269 HdfPmRegisterPowerListener(g_pmTestType[index].obj, &g_pmTestType[index].listener.powerListener);
270 }
271 HdfPmSetMode(g_pmTestType[index].obj, HDF_POWER_DYNAMIC_CTRL);
272 }
273
HdfPmBakListener(int32_t index)274 static void HdfPmBakListener(int32_t index)
275 {
276 HdfPmUnregisterPowerListener(g_pmTestType[index].obj, &g_pmTestType[index].listener.powerListener);
277 if (g_pmTestType[index].listenerBak != NULL) {
278 HdfPmRegisterPowerListener(g_pmTestType[index].obj, g_pmTestType[index].listenerBak);
279 HdfPmSetMode(g_pmTestType[index].obj, HDF_POWER_SYS_CTRL);
280 }
281 }
282
HdfPmTestAcquire(uint32_t index)283 static void HdfPmTestAcquire(uint32_t index)
284 {
285 HdfPmAcquireDeviceAsync(g_pmTestType[index].obj);
286 }
287
HdfPmTestRelease(uint32_t index)288 static void HdfPmTestRelease(uint32_t index)
289 {
290 HdfPmReleaseDeviceAsync(g_pmTestType[index].obj);
291 }
292
HdfPmTestAcquireSync(uint32_t index)293 static void HdfPmTestAcquireSync(uint32_t index)
294 {
295 HdfPmAcquireDevice(g_pmTestType[index].obj);
296 }
297
HdfPmTestReleaseSync(uint32_t index)298 static void HdfPmTestReleaseSync(uint32_t index)
299 {
300 HdfPmReleaseDevice(g_pmTestType[index].obj);
301 }
302
HdfPmTestBegin(void)303 static int32_t HdfPmTestBegin(void)
304 {
305 uint32_t index;
306
307 HdfPmTaskQueueInit(NULL);
308 HdfPmSetListeners();
309 HdfPmClearTestCnt();
310
311 for (index = 0; index <= PM_TEST_DRIVER; index++) {
312 HdfPmRegisterTestListener(index);
313 }
314 return HDF_SUCCESS;
315 }
316
HdfPmTestEnd(void)317 static int32_t HdfPmTestEnd(void)
318 {
319 uint32_t index;
320
321 for (index = 0; index <= PM_TEST_DRIVER; index++) {
322 HdfPmBakListener(index);
323 }
324
325 HdfPowerManagerExit();
326 HdfPmTaskQueueInit(NULL);
327 loopTest = false;
328
329 return HDF_SUCCESS;
330 }
331
HdfPmTestOneDriver(const uint32_t times)332 static int32_t HdfPmTestOneDriver(const uint32_t times)
333 {
334 uint32_t index;
335 uint32_t waitTime = 0;
336 uint64_t beginTimes = OsalGetSysTimeMs();
337 uint32_t expendTimes;
338
339 HdfPmClearTestCnt();
340
341 for (index = 0; index < times; index++) {
342 HdfPmTestAcquire(PM_TEST_DRIVER);
343 HdfPmTestRelease(PM_TEST_DRIVER);
344 }
345
346 WAIT_TEST_END(CHECK_VALUE(PM_TEST_DRIVER, times), waitTime);
347
348 HDF_LOGI("%s %d %d", __func__, g_pmTestType[PM_TEST_DRIVER].resumeCnt, g_pmTestType[PM_TEST_DRIVER].suspendCnt);
349
350 expendTimes = OsalGetSysTimeMs() - beginTimes;
351 HDF_LOGI("%s test expend times:%u ms", __func__, expendTimes);
352
353 return CHECK_VALUE(PM_TEST_DRIVER, times) ? HDF_SUCCESS : HDF_FAILURE;
354 }
355
HdfPmTestTwoDriver(const uint32_t times)356 static int32_t HdfPmTestTwoDriver(const uint32_t times)
357 {
358 uint32_t index;
359 uint32_t waitTime = 0;
360 uint64_t beginTimes = OsalGetSysTimeMs();
361 uint32_t expendTimes;
362
363 HdfPmClearTestCnt();
364
365 for (index = 0; index < times; index++) {
366 HdfPmTestAcquire(PM_TEST_DRIVER);
367 HdfPmTestAcquire(HDF_TEST_DRIVER);
368 HdfPmTestRelease(PM_TEST_DRIVER);
369 HdfPmTestRelease(HDF_TEST_DRIVER);
370 }
371
372 WAIT_TEST_END(CHECK_VALUE(PM_TEST_DRIVER, times) && CHECK_VALUE(HDF_TEST_DRIVER, times), waitTime);
373
374 HDF_LOGI("%s %d %d", __func__, g_pmTestType[PM_TEST_DRIVER].resumeCnt, g_pmTestType[PM_TEST_DRIVER].suspendCnt);
375 HDF_LOGI("%s %d %d", __func__, g_pmTestType[HDF_TEST_DRIVER].resumeCnt, g_pmTestType[HDF_TEST_DRIVER].suspendCnt);
376
377 expendTimes = OsalGetSysTimeMs() - beginTimes;
378 HDF_LOGI("%s test expend times:%d ms", __func__, expendTimes);
379
380 return (CHECK_VALUE(PM_TEST_DRIVER, times) && CHECK_VALUE(HDF_TEST_DRIVER, times)) ? HDF_SUCCESS : HDF_FAILURE;
381 }
382
HdfPmTestThreeDriver(const uint32_t times,bool sync)383 static int32_t HdfPmTestThreeDriver(const uint32_t times, bool sync)
384 {
385 uint32_t index;
386 uint32_t total = times;
387 uint32_t waitTime = 0;
388 uint64_t beginTimes = OsalGetSysTimeMs();
389 uint32_t expendTimes;
390
391 HdfPmClearTestCnt();
392
393 if (sync) {
394 total += PM_TEST_COUNT_ONE;
395 HdfPmTestAcquireSync(PM_TEST_DRIVER);
396 HdfPmTestAcquireSync(HDF_TEST_DRIVER);
397 HdfPmTestAcquireSync(SAMPLE_TEST_DRIVER);
398 HdfPmTestReleaseSync(PM_TEST_DRIVER);
399 HdfPmTestReleaseSync(HDF_TEST_DRIVER);
400 HdfPmTestReleaseSync(SAMPLE_TEST_DRIVER);
401 }
402
403 for (index = 0; index < times; index++) {
404 HdfPmTestAcquire(PM_TEST_DRIVER);
405 HdfPmTestAcquire(HDF_TEST_DRIVER);
406 HdfPmTestAcquire(SAMPLE_TEST_DRIVER);
407
408 HdfPmTestRelease(PM_TEST_DRIVER);
409 HdfPmTestRelease(HDF_TEST_DRIVER);
410 HdfPmTestRelease(SAMPLE_TEST_DRIVER);
411 }
412
413 WAIT_TEST_END(CHECK_VALUE(PM_TEST_DRIVER, total) &&
414 CHECK_VALUE(HDF_TEST_DRIVER, total) &&
415 CHECK_VALUE(SAMPLE_TEST_DRIVER, total), waitTime);
416
417 HDF_LOGI("%s %d %d", __func__, g_pmTestType[PM_TEST_DRIVER].resumeCnt, g_pmTestType[PM_TEST_DRIVER].suspendCnt);
418 HDF_LOGI("%s %d %d", __func__, g_pmTestType[HDF_TEST_DRIVER].resumeCnt, g_pmTestType[HDF_TEST_DRIVER].suspendCnt);
419 HDF_LOGI("%s %d %d", __func__,
420 g_pmTestType[SAMPLE_TEST_DRIVER].resumeCnt, g_pmTestType[SAMPLE_TEST_DRIVER].suspendCnt);
421
422 expendTimes = OsalGetSysTimeMs() - beginTimes;
423 HDF_LOGI("%s test expend times:%d ms", __func__, expendTimes);
424
425 return (CHECK_VALUE(PM_TEST_DRIVER, total) && CHECK_VALUE(HDF_TEST_DRIVER, total) &&
426 CHECK_VALUE(SAMPLE_TEST_DRIVER, total)) ? HDF_SUCCESS : HDF_FAILURE;
427 }
428
HdfPmTestThreeDriverSeqHundred(void)429 static int32_t HdfPmTestThreeDriverSeqHundred(void)
430 {
431 uint32_t index;
432 uint32_t waitTime = 0;
433 uint64_t beginTimes = OsalGetSysTimeMs();
434 uint32_t expendTimes;
435
436 HdfPmClearTestCnt();
437
438 for (index = 0; index < PM_TEST_COUNT_TWO; index++) {
439 HdfPmTestAcquire(PM_TEST_DRIVER);
440 HdfPmTestAcquire(HDF_TEST_DRIVER);
441 HdfPmTestAcquire(SAMPLE_TEST_DRIVER);
442 }
443
444 for (index = 0; index < PM_TEST_COUNT_TWO; index++) {
445 HdfPmTestRelease(PM_TEST_DRIVER);
446 HdfPmTestRelease(HDF_TEST_DRIVER);
447 HdfPmTestRelease(SAMPLE_TEST_DRIVER);
448 }
449
450 WAIT_TEST_END(CHECK_VALUE(PM_TEST_DRIVER, PM_TEST_COUNT_ONE) &&
451 CHECK_VALUE(HDF_TEST_DRIVER, PM_TEST_COUNT_ONE) &&
452 CHECK_VALUE(SAMPLE_TEST_DRIVER, PM_TEST_COUNT_ONE), waitTime);
453
454 HDF_LOGI("%s %d %d", __func__, g_pmTestType[PM_TEST_DRIVER].resumeCnt, g_pmTestType[PM_TEST_DRIVER].suspendCnt);
455 HDF_LOGI("%s %d %d", __func__, g_pmTestType[HDF_TEST_DRIVER].resumeCnt, g_pmTestType[HDF_TEST_DRIVER].suspendCnt);
456 HDF_LOGI("%s %d %d", __func__,
457 g_pmTestType[SAMPLE_TEST_DRIVER].resumeCnt, g_pmTestType[SAMPLE_TEST_DRIVER].suspendCnt);
458
459 expendTimes = OsalGetSysTimeMs() - beginTimes;
460 HDF_LOGI("%s test expend times:%u ms", __func__, expendTimes);
461
462 return (CHECK_VALUE(PM_TEST_DRIVER, PM_TEST_COUNT_ONE) && CHECK_VALUE(HDF_TEST_DRIVER, PM_TEST_COUNT_ONE) &&
463 CHECK_VALUE(SAMPLE_TEST_DRIVER, PM_TEST_COUNT_ONE)) ? HDF_SUCCESS : HDF_FAILURE;
464 }
465
HdfPmTestOneDriverOnce(void)466 static int32_t HdfPmTestOneDriverOnce(void)
467 {
468 loopTest = false;
469 return HdfPmTestOneDriver(PM_TEST_COUNT_ONE);
470 }
471
HdfPmTestOneDriverTwice(void)472 static int32_t HdfPmTestOneDriverTwice(void)
473 {
474 loopTest = false;
475 return HdfPmTestOneDriver(PM_TEST_COUNT_TWO);
476 }
477
HdfPmTestOneDriverTen(void)478 static int32_t HdfPmTestOneDriverTen(void)
479 {
480 loopTest = true;
481 return HdfPmTestOneDriver(PM_TEST_COUNT_TEN);
482 }
483
HdfPmTestOneDriverHundred(void)484 static int32_t HdfPmTestOneDriverHundred(void)
485 {
486 loopTest = true;
487 return HdfPmTestOneDriver(PM_TEST_COUNT_HUNDRED);
488 }
489
HdfPmTestOneDriverThousand(void)490 static int32_t HdfPmTestOneDriverThousand(void)
491 {
492 loopTest = true;
493 return HdfPmTestOneDriver(PM_TEST_COUNT_THOUSAND);
494 }
495
HdfPmTestTwoDriverOnce(void)496 static int32_t HdfPmTestTwoDriverOnce(void)
497 {
498 loopTest = false;
499 return HdfPmTestTwoDriver(PM_TEST_COUNT_ONE);
500 }
501
HdfPmTestTwoDriverTwice(void)502 static int32_t HdfPmTestTwoDriverTwice(void)
503 {
504 loopTest = false;
505 return HdfPmTestTwoDriver(PM_TEST_COUNT_TWO);
506 }
507
HdfPmTestTwoDriverTen(void)508 static int32_t HdfPmTestTwoDriverTen(void)
509 {
510 loopTest = true;
511 return HdfPmTestTwoDriver(PM_TEST_COUNT_TEN);
512 }
513
HdfPmTestTwoDriverHundred(void)514 static int32_t HdfPmTestTwoDriverHundred(void)
515 {
516 loopTest = true;
517 return HdfPmTestTwoDriver(PM_TEST_COUNT_HUNDRED);
518 }
519
HdfPmTestTwoDriverThousand(void)520 static int32_t HdfPmTestTwoDriverThousand(void)
521 {
522 loopTest = true;
523 return HdfPmTestTwoDriver(PM_TEST_COUNT_THOUSAND);
524 }
525
HdfPmTestThreeDriverOnce(void)526 static int32_t HdfPmTestThreeDriverOnce(void)
527 {
528 loopTest = false;
529 return HdfPmTestThreeDriver(PM_TEST_COUNT_ONE, false);
530 }
531
HdfPmTestThreeDriverTwice(void)532 static int32_t HdfPmTestThreeDriverTwice(void)
533 {
534 loopTest = false;
535 return HdfPmTestThreeDriver(PM_TEST_COUNT_TWO, false);
536 }
537
HdfPmTestThreeDriverTen(void)538 static int32_t HdfPmTestThreeDriverTen(void)
539 {
540 loopTest = true;
541 return HdfPmTestThreeDriver(PM_TEST_COUNT_TEN, false);
542 }
543
HdfPmTestThreeDriverHundred(void)544 static int32_t HdfPmTestThreeDriverHundred(void)
545 {
546 loopTest = true;
547 return HdfPmTestThreeDriver(PM_TEST_COUNT_HUNDRED, false);
548 }
549
HdfPmTestThreeDriverThousand(void)550 static int32_t HdfPmTestThreeDriverThousand(void)
551 {
552 loopTest = true;
553 return HdfPmTestThreeDriver(PM_TEST_COUNT_THOUSAND, false);
554 }
555
HdfPmTestThreeDriverHundredWithSync(void)556 static int32_t HdfPmTestThreeDriverHundredWithSync(void)
557 {
558 loopTest = true;
559 return HdfPmTestThreeDriver(PM_TEST_COUNT_HUNDRED, true);
560 }
561
HdfPmDriverRelease(struct HdfDeviceObject * deviceObject)562 static void HdfPmDriverRelease(struct HdfDeviceObject *deviceObject)
563 {
564 (void)deviceObject;
565 return;
566 }
567
HdfPmDriverDispatch(struct HdfDeviceIoClient * client,int cmdId,struct HdfSBuf * data,struct HdfSBuf * reply)568 static int32_t HdfPmDriverDispatch(
569 struct HdfDeviceIoClient *client, int cmdId, struct HdfSBuf *data, struct HdfSBuf *reply)
570 {
571 int32_t ret = HDF_FAILURE;
572 uint32_t index;
573
574 (void)client;
575 (void)data;
576 (void)reply;
577 HDF_LOGI("%s %d enter!", __func__, cmdId);
578
579 for (index = 0; index <= HDF_PM_TEST_END; index++) {
580 if (cmdId == g_testCases[index].cmd) {
581 ret = g_testCases[cmdId].testFunc();
582 break;
583 }
584 }
585
586 return ret;
587 }
588
HdfPmDriverBind(struct HdfDeviceObject * deviceObject)589 static int HdfPmDriverBind(struct HdfDeviceObject *deviceObject)
590 {
591 HDF_LOGI("%s enter", __func__);
592 if (deviceObject == NULL) {
593 return HDF_FAILURE;
594 }
595 static struct IDeviceIoService testService = {
596 .Dispatch = HdfPmDriverDispatch,
597 .Open = NULL,
598 .Release = NULL,
599 };
600 deviceObject->service = &testService;
601 return HDF_SUCCESS;
602 }
603
HdfPmDriverInit(struct HdfDeviceObject * deviceObject)604 static int HdfPmDriverInit(struct HdfDeviceObject *deviceObject)
605 {
606 static struct PmDriverPmListener pmListener = {0};
607
608 HDF_LOGI("%s enter!", __func__);
609 if (deviceObject == NULL) {
610 HDF_LOGE("%s ptr is null!", __func__);
611 return HDF_FAILURE;
612 }
613 HDF_LOGD("%s Init success", __func__);
614
615 pmListener.powerListener.DozeResume = HdfPmTestDozeResume;
616 pmListener.powerListener.DozeSuspend = HdfPmTestDozeSuspend;
617 pmListener.powerListener.Resume = HdfPmTestResume;
618 pmListener.powerListener.Suspend = HdfPmTestSuspend;
619
620 int ret = HdfPmRegisterPowerListener(deviceObject, &pmListener.powerListener);
621 HDF_LOGI("%s register power listener, ret = %d", __func__, ret);
622
623 return HDF_SUCCESS;
624 }
625
626 struct HdfDriverEntry g_pmDriverEntry = {
627 .moduleVersion = 1,
628 .moduleName = "pm_test_driver",
629 .Bind = HdfPmDriverBind,
630 .Init = HdfPmDriverInit,
631 .Release = HdfPmDriverRelease,
632 };
633
634 HDF_INIT(g_pmDriverEntry);
635
636