1 /*
2 * Copyright (c) 2021 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 (pmTestType[(index)].resumeCnt == (cnt) && 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 int32_t HdfPmTestBegin(void);
59 int32_t HdfPmTestOneDriverOnce(void);
60 int32_t HdfPmTestOneDriverTwice(void);
61 int32_t HdfPmTestOneDriverTen(void);
62 int32_t HdfPmTestOneDriverHundred(void);
63 int32_t HdfPmTestOneDriverThousand(void);
64 int32_t HdfPmTestTwoDriverOnce(void);
65 int32_t HdfPmTestTwoDriverTwice(void);
66 int32_t HdfPmTestTwoDriverTen(void);
67 int32_t HdfPmTestTwoDriverHundred(void);
68 int32_t HdfPmTestTwoDriverThousand(void);
69 int32_t HdfPmTestThreeDriverOnce(void);
70 int32_t HdfPmTestThreeDriverTwice(void);
71 int32_t HdfPmTestThreeDriverTen(void);
72 int32_t HdfPmTestThreeDriverHundred(void);
73 int32_t HdfPmTestThreeDriverThousand(void);
74 int32_t HdfPmTestThreeDriverSeqHundred(void);
75 int32_t HdfPmTestThreeDriverHundredWithSync(void);
76 int32_t HdfPmTestEnd(void);
77
78 static const struct TestCaseType 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 *serviceName[] = { "HDF_TEST", "sample_service", "pm_test_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 pmTestType[PM_TEST_DRIVER + 1];
112
113 static bool loopTest = false;
114
HdfPmHdfTestDozeResume(struct HdfDeviceObject * deviceObject)115 int HdfPmHdfTestDozeResume(struct HdfDeviceObject *deviceObject)
116 {
117 HDF_LOGI("%s called", __func__);
118 return HDF_SUCCESS;
119 }
120
HdfPmHdfTestDozeSuspend(struct HdfDeviceObject * deviceObject)121 int HdfPmHdfTestDozeSuspend(struct HdfDeviceObject *deviceObject)
122 {
123 HDF_LOGI("%s called", __func__);
124 return HDF_SUCCESS;
125 }
126
HdfPmHdfTestResume(struct HdfDeviceObject * deviceObject)127 int HdfPmHdfTestResume(struct HdfDeviceObject *deviceObject)
128 {
129 if (loopTest == false) {
130 HDF_LOGI("%s called", __func__);
131 }
132
133 pmTestType[HDF_TEST_DRIVER].resumeCnt++;
134 return HDF_SUCCESS;
135 }
136
HdfPmHdfTestSuspend(struct HdfDeviceObject * deviceObject)137 int HdfPmHdfTestSuspend(struct HdfDeviceObject *deviceObject)
138 {
139 if (loopTest == false) {
140 HDF_LOGI("%s called", __func__);
141 }
142 pmTestType[HDF_TEST_DRIVER].suspendCnt++;
143 return HDF_SUCCESS;
144 }
145
HdfPmSampleDozeResume(struct HdfDeviceObject * deviceObject)146 int HdfPmSampleDozeResume(struct HdfDeviceObject *deviceObject)
147 {
148 HDF_LOGI("%s called", __func__);
149 return HDF_SUCCESS;
150 }
151
HdfPmSampleDozeSuspend(struct HdfDeviceObject * deviceObject)152 int HdfPmSampleDozeSuspend(struct HdfDeviceObject *deviceObject)
153 {
154 HDF_LOGI("%s called", __func__);
155 return HDF_SUCCESS;
156 }
157
HdfPmSampleResume(struct HdfDeviceObject * deviceObject)158 int HdfPmSampleResume(struct HdfDeviceObject *deviceObject)
159 {
160 if (loopTest == false) {
161 HDF_LOGI("%s called", __func__);
162 }
163 pmTestType[SAMPLE_TEST_DRIVER].resumeCnt++;
164 return HDF_SUCCESS;
165 }
166
HdfPmSampleSuspend(struct HdfDeviceObject * deviceObject)167 int HdfPmSampleSuspend(struct HdfDeviceObject *deviceObject)
168 {
169 if (loopTest == false) {
170 HDF_LOGI("%s called", __func__);
171 }
172 pmTestType[SAMPLE_TEST_DRIVER].suspendCnt++;
173 return HDF_SUCCESS;
174 }
175
HdfPmTestDozeResume(struct HdfDeviceObject * deviceObject)176 int HdfPmTestDozeResume(struct HdfDeviceObject *deviceObject)
177 {
178 HDF_LOGI("%s called", __func__);
179 return HDF_SUCCESS;
180 }
181
HdfPmTestDozeSuspend(struct HdfDeviceObject * deviceObject)182 int HdfPmTestDozeSuspend(struct HdfDeviceObject *deviceObject)
183 {
184 HDF_LOGI("%s called", __func__);
185 return HDF_SUCCESS;
186 }
187
HdfPmTestResume(struct HdfDeviceObject * deviceObject)188 int HdfPmTestResume(struct HdfDeviceObject *deviceObject)
189 {
190 if (loopTest == false) {
191 HDF_LOGI("%s called", __func__);
192 }
193 pmTestType[PM_TEST_DRIVER].resumeCnt++;
194 return HDF_SUCCESS;
195 }
196
HdfPmTestSuspend(struct HdfDeviceObject * deviceObject)197 int HdfPmTestSuspend(struct HdfDeviceObject *deviceObject)
198 {
199 if (loopTest == false) {
200 HDF_LOGI("%s called", __func__);
201 }
202 pmTestType[PM_TEST_DRIVER].suspendCnt++;
203 return HDF_SUCCESS;
204 }
205
HdfPmSetListeners(void)206 void HdfPmSetListeners(void)
207 {
208 pmTestType[HDF_TEST_DRIVER].listener.powerListener.DozeResume = HdfPmHdfTestDozeResume;
209 pmTestType[HDF_TEST_DRIVER].listener.powerListener.DozeSuspend = HdfPmHdfTestDozeSuspend;
210 pmTestType[HDF_TEST_DRIVER].listener.powerListener.Resume = HdfPmHdfTestResume;
211 pmTestType[HDF_TEST_DRIVER].listener.powerListener.Suspend = HdfPmHdfTestSuspend;
212
213 pmTestType[SAMPLE_TEST_DRIVER].listener.powerListener.DozeResume = HdfPmSampleDozeResume;
214 pmTestType[SAMPLE_TEST_DRIVER].listener.powerListener.DozeSuspend = HdfPmSampleDozeSuspend;
215 pmTestType[SAMPLE_TEST_DRIVER].listener.powerListener.Resume = HdfPmSampleResume;
216 pmTestType[SAMPLE_TEST_DRIVER].listener.powerListener.Suspend = HdfPmSampleSuspend;
217
218 pmTestType[PM_TEST_DRIVER].listener.powerListener.DozeResume = HdfPmTestDozeResume;
219 pmTestType[PM_TEST_DRIVER].listener.powerListener.DozeSuspend = HdfPmTestDozeSuspend;
220 pmTestType[PM_TEST_DRIVER].listener.powerListener.Resume = HdfPmTestResume;
221 pmTestType[PM_TEST_DRIVER].listener.powerListener.Suspend = HdfPmTestSuspend;
222 }
223
HdfPmClearTestCnt()224 void HdfPmClearTestCnt()
225 {
226 uint32_t index;
227
228 for (index = 0; index <= PM_TEST_DRIVER; index++) {
229 pmTestType[index].resumeCnt = 0;
230 pmTestType[index].suspendCnt = 0;
231 }
232 }
233
HdfPmRegisterTestListener(int32_t index)234 void HdfPmRegisterTestListener(int32_t index)
235 {
236 struct SubscriberCallback callback = {NULL};
237 struct HdfDeviceNode *devNode = NULL;
238
239 pmTestType[index].serviceName = serviceName[index];
240 pmTestType[index].obj = DevSvcManagerClntGetDeviceObject(pmTestType[index].serviceName);
241 if (pmTestType[index].obj == NULL) {
242 DevSvcManagerClntSubscribeService(pmTestType[index].serviceName, callback);
243 OsalMSleep(PM_WAIT_LOAD_TIME);
244 pmTestType[index].obj = DevSvcManagerClntGetDeviceObject(pmTestType[index].serviceName);
245 }
246
247 if (pmTestType[index].obj) {
248 devNode = (struct HdfDeviceNode *)HDF_SLIST_CONTAINER_OF(
249 struct HdfDeviceObject, pmTestType[index].obj, struct HdfDeviceNode, deviceObject);
250 if ((devNode->powerToken != NULL) && (devNode->powerToken->listener != NULL)) {
251 pmTestType[index].listenerBak = devNode->powerToken->listener;
252 HdfPmUnregisterPowerListener(pmTestType[index].obj, pmTestType[index].listenerBak);
253 } else {
254 pmTestType[index].listenerBak = NULL;
255 }
256
257 HdfPmRegisterPowerListener(pmTestType[index].obj, &pmTestType[index].listener.powerListener);
258 }
259 HdfPmSetMode(pmTestType[index].obj, HDF_POWER_DYNAMIC_CTRL);
260 }
261
HdfPmBakListener(int32_t index)262 void HdfPmBakListener(int32_t index)
263 {
264 HdfPmUnregisterPowerListener(pmTestType[index].obj, &pmTestType[index].listener.powerListener);
265 if (pmTestType[index].listenerBak != NULL) {
266 HdfPmRegisterPowerListener(pmTestType[index].obj, pmTestType[index].listenerBak);
267 HdfPmSetMode(pmTestType[index].obj, HDF_POWER_SYS_CTRL);
268 }
269 }
270
HdfPmTestAcquire(uint32_t index)271 void HdfPmTestAcquire(uint32_t index)
272 {
273 HdfPmAcquireDeviceAsync(pmTestType[index].obj);
274 }
275
HdfPmTestRelease(uint32_t index)276 void HdfPmTestRelease(uint32_t index)
277 {
278 HdfPmReleaseDeviceAsync(pmTestType[index].obj);
279 }
280
HdfPmTestAcquireSync(uint32_t index)281 void HdfPmTestAcquireSync(uint32_t index)
282 {
283 HdfPmAcquireDevice(pmTestType[index].obj);
284 }
285
HdfPmTestReleaseSync(uint32_t index)286 void HdfPmTestReleaseSync(uint32_t index)
287 {
288 HdfPmReleaseDevice(pmTestType[index].obj);
289 }
290
HdfPmTestBegin(void)291 int32_t HdfPmTestBegin(void)
292 {
293 uint32_t index;
294
295 HdfPmTaskQueueInit(NULL);
296 HdfPmSetListeners();
297 HdfPmClearTestCnt();
298
299 for (index = 0; index <= PM_TEST_DRIVER; index++) {
300 HdfPmRegisterTestListener(index);
301 }
302 return HDF_SUCCESS;
303 }
304
HdfPmTestEnd(void)305 int32_t HdfPmTestEnd(void)
306 {
307 uint32_t index;
308
309 for (index = 0; index <= PM_TEST_DRIVER; index++) {
310 HdfPmBakListener(index);
311 }
312
313 HdfPowerManagerExit();
314 HdfPmTaskQueueInit(NULL);
315 loopTest = false;
316
317 return HDF_SUCCESS;
318 }
319
HdfPmTestOneDriver(const int32_t times)320 int32_t HdfPmTestOneDriver(const int32_t times)
321 {
322 uint32_t index;
323 uint32_t waitTime = 0;
324 uint64_t beginTimes = OsalGetSysTimeMs();
325 uint32_t expendTimes;
326
327 HdfPmClearTestCnt();
328
329 for (index = 0; index < times; index++) {
330 HdfPmTestAcquire(PM_TEST_DRIVER);
331 HdfPmTestRelease(PM_TEST_DRIVER);
332 }
333
334 WAIT_TEST_END(CHECK_VALUE(PM_TEST_DRIVER, times), waitTime);
335
336 HDF_LOGI("%s %d %d", __func__, pmTestType[PM_TEST_DRIVER].resumeCnt, pmTestType[PM_TEST_DRIVER].suspendCnt);
337
338 expendTimes = OsalGetSysTimeMs() - beginTimes;
339 HDF_LOGI("%s test expend times:%d ms", __func__, expendTimes);
340
341 return CHECK_VALUE(PM_TEST_DRIVER, times) ? HDF_SUCCESS : HDF_FAILURE;
342 }
343
HdfPmTestTwoDriver(const int32_t times)344 int32_t HdfPmTestTwoDriver(const int32_t times)
345 {
346 uint32_t index;
347 uint32_t waitTime = 0;
348 uint64_t beginTimes = OsalGetSysTimeMs();
349 uint32_t expendTimes;
350
351 HdfPmClearTestCnt();
352
353 for (index = 0; index < times; index++) {
354 HdfPmTestAcquire(PM_TEST_DRIVER);
355 HdfPmTestAcquire(HDF_TEST_DRIVER);
356 HdfPmTestRelease(PM_TEST_DRIVER);
357 HdfPmTestRelease(HDF_TEST_DRIVER);
358 }
359
360 WAIT_TEST_END(CHECK_VALUE(PM_TEST_DRIVER, times) && CHECK_VALUE(HDF_TEST_DRIVER, times), waitTime);
361
362 HDF_LOGI("%s %d %d", __func__, pmTestType[PM_TEST_DRIVER].resumeCnt, pmTestType[PM_TEST_DRIVER].suspendCnt);
363 HDF_LOGI("%s %d %d", __func__, pmTestType[HDF_TEST_DRIVER].resumeCnt, pmTestType[HDF_TEST_DRIVER].suspendCnt);
364
365 expendTimes = OsalGetSysTimeMs() - beginTimes;
366 HDF_LOGI("%s test expend times:%d ms", __func__, expendTimes);
367
368 return (CHECK_VALUE(PM_TEST_DRIVER, times) && CHECK_VALUE(HDF_TEST_DRIVER, times)) ? HDF_SUCCESS : HDF_FAILURE;
369 }
370
HdfPmTestThreeDriver(const int32_t times,bool sync)371 int32_t HdfPmTestThreeDriver(const int32_t times, bool sync)
372 {
373 uint32_t index;
374 uint32_t total = times;
375 uint32_t waitTime = 0;
376 uint64_t beginTimes = OsalGetSysTimeMs();
377 uint32_t expendTimes;
378
379 HdfPmClearTestCnt();
380
381 if (sync) {
382 total += PM_TEST_COUNT_ONE;
383 }
384
385 if (sync) {
386 HdfPmTestAcquireSync(PM_TEST_DRIVER);
387 HdfPmTestAcquireSync(HDF_TEST_DRIVER);
388 HdfPmTestAcquireSync(SAMPLE_TEST_DRIVER);
389 HdfPmTestReleaseSync(PM_TEST_DRIVER);
390 HdfPmTestReleaseSync(HDF_TEST_DRIVER);
391 HdfPmTestReleaseSync(SAMPLE_TEST_DRIVER);
392 }
393
394 for (index = 0; index < times; index++) {
395 HdfPmTestAcquire(PM_TEST_DRIVER);
396 HdfPmTestAcquire(HDF_TEST_DRIVER);
397 HdfPmTestAcquire(SAMPLE_TEST_DRIVER);
398
399 HdfPmTestRelease(PM_TEST_DRIVER);
400 HdfPmTestRelease(HDF_TEST_DRIVER);
401 HdfPmTestRelease(SAMPLE_TEST_DRIVER);
402 }
403
404 WAIT_TEST_END(CHECK_VALUE(PM_TEST_DRIVER, total) &&
405 CHECK_VALUE(HDF_TEST_DRIVER, total) &&
406 CHECK_VALUE(SAMPLE_TEST_DRIVER, total), waitTime);
407
408 HDF_LOGI("%s %d %d", __func__, pmTestType[PM_TEST_DRIVER].resumeCnt, pmTestType[PM_TEST_DRIVER].suspendCnt);
409 HDF_LOGI("%s %d %d", __func__, pmTestType[HDF_TEST_DRIVER].resumeCnt, pmTestType[HDF_TEST_DRIVER].suspendCnt);
410 HDF_LOGI("%s %d %d", __func__,
411 pmTestType[SAMPLE_TEST_DRIVER].resumeCnt, pmTestType[SAMPLE_TEST_DRIVER].suspendCnt);
412
413 expendTimes = OsalGetSysTimeMs() - beginTimes;
414 HDF_LOGI("%s test expend times:%d ms", __func__, expendTimes);
415
416 return (CHECK_VALUE(PM_TEST_DRIVER, total) && CHECK_VALUE(HDF_TEST_DRIVER, total) &&
417 CHECK_VALUE(SAMPLE_TEST_DRIVER, total)) ? HDF_SUCCESS : HDF_FAILURE;
418 }
419
HdfPmTestThreeDriverSeqHundred(void)420 int32_t HdfPmTestThreeDriverSeqHundred(void)
421 {
422 uint32_t index;
423 uint32_t waitTime = 0;
424 uint64_t beginTimes = OsalGetSysTimeMs();
425 uint32_t expendTimes;
426
427 HdfPmClearTestCnt();
428
429 for (index = 0; index < PM_TEST_COUNT_TWO; index++) {
430 HdfPmTestAcquire(PM_TEST_DRIVER);
431 HdfPmTestAcquire(HDF_TEST_DRIVER);
432 HdfPmTestAcquire(SAMPLE_TEST_DRIVER);
433 }
434
435 for (index = 0; index < PM_TEST_COUNT_TWO; index++) {
436 HdfPmTestRelease(PM_TEST_DRIVER);
437 HdfPmTestRelease(HDF_TEST_DRIVER);
438 HdfPmTestRelease(SAMPLE_TEST_DRIVER);
439 }
440
441 WAIT_TEST_END(CHECK_VALUE(PM_TEST_DRIVER, PM_TEST_COUNT_ONE) &&
442 CHECK_VALUE(HDF_TEST_DRIVER, PM_TEST_COUNT_ONE) &&
443 CHECK_VALUE(SAMPLE_TEST_DRIVER, PM_TEST_COUNT_ONE), waitTime);
444
445 HDF_LOGI("%s %d %d", __func__, pmTestType[PM_TEST_DRIVER].resumeCnt, pmTestType[PM_TEST_DRIVER].suspendCnt);
446 HDF_LOGI("%s %d %d", __func__, pmTestType[HDF_TEST_DRIVER].resumeCnt, pmTestType[HDF_TEST_DRIVER].suspendCnt);
447 HDF_LOGI("%s %d %d", __func__,
448 pmTestType[SAMPLE_TEST_DRIVER].resumeCnt, pmTestType[SAMPLE_TEST_DRIVER].suspendCnt);
449
450 expendTimes = OsalGetSysTimeMs() - beginTimes;
451 HDF_LOGI("%s test expend times:%d ms", __func__, expendTimes);
452
453 return (CHECK_VALUE(PM_TEST_DRIVER, PM_TEST_COUNT_ONE) && CHECK_VALUE(HDF_TEST_DRIVER, PM_TEST_COUNT_ONE) &&
454 CHECK_VALUE(SAMPLE_TEST_DRIVER, PM_TEST_COUNT_ONE)) ? HDF_SUCCESS : HDF_FAILURE;
455 }
456
HdfPmTestOneDriverOnce(void)457 int32_t HdfPmTestOneDriverOnce(void)
458 {
459 loopTest = false;
460 return HdfPmTestOneDriver(PM_TEST_COUNT_ONE);
461 }
462
HdfPmTestOneDriverTwice(void)463 int32_t HdfPmTestOneDriverTwice(void)
464 {
465 loopTest = false;
466 return HdfPmTestOneDriver(PM_TEST_COUNT_TWO);
467 }
468
HdfPmTestOneDriverTen(void)469 int32_t HdfPmTestOneDriverTen(void)
470 {
471 loopTest = true;
472 return HdfPmTestOneDriver(PM_TEST_COUNT_TEN);
473 }
474
HdfPmTestOneDriverHundred(void)475 int32_t HdfPmTestOneDriverHundred(void)
476 {
477 loopTest = true;
478 return HdfPmTestOneDriver(PM_TEST_COUNT_HUNDRED);
479 }
480
HdfPmTestOneDriverThousand(void)481 int32_t HdfPmTestOneDriverThousand(void)
482 {
483 loopTest = true;
484 return HdfPmTestOneDriver(PM_TEST_COUNT_THOUSAND);
485 }
486
HdfPmTestTwoDriverOnce(void)487 int32_t HdfPmTestTwoDriverOnce(void)
488 {
489 loopTest = false;
490 return HdfPmTestTwoDriver(PM_TEST_COUNT_ONE);
491 }
492
HdfPmTestTwoDriverTwice(void)493 int32_t HdfPmTestTwoDriverTwice(void)
494 {
495 loopTest = false;
496 return HdfPmTestTwoDriver(PM_TEST_COUNT_TWO);
497 }
498
HdfPmTestTwoDriverTen(void)499 int32_t HdfPmTestTwoDriverTen(void)
500 {
501 loopTest = true;
502 return HdfPmTestTwoDriver(PM_TEST_COUNT_TEN);
503 }
504
HdfPmTestTwoDriverHundred(void)505 int32_t HdfPmTestTwoDriverHundred(void)
506 {
507 loopTest = true;
508 return HdfPmTestTwoDriver(PM_TEST_COUNT_HUNDRED);
509 }
510
HdfPmTestTwoDriverThousand(void)511 int32_t HdfPmTestTwoDriverThousand(void)
512 {
513 loopTest = true;
514 return HdfPmTestTwoDriver(PM_TEST_COUNT_THOUSAND);
515 }
516
HdfPmTestThreeDriverOnce(void)517 int32_t HdfPmTestThreeDriverOnce(void)
518 {
519 loopTest = false;
520 return HdfPmTestThreeDriver(PM_TEST_COUNT_ONE, false);
521 }
522
HdfPmTestThreeDriverTwice(void)523 int32_t HdfPmTestThreeDriverTwice(void)
524 {
525 loopTest = false;
526 return HdfPmTestThreeDriver(PM_TEST_COUNT_TWO, false);
527 }
528
HdfPmTestThreeDriverTen(void)529 int32_t HdfPmTestThreeDriverTen(void)
530 {
531 loopTest = true;
532 return HdfPmTestThreeDriver(PM_TEST_COUNT_TEN, false);
533 }
534
HdfPmTestThreeDriverHundred(void)535 int32_t HdfPmTestThreeDriverHundred(void)
536 {
537 loopTest = true;
538 return HdfPmTestThreeDriver(PM_TEST_COUNT_HUNDRED, false);
539 }
540
HdfPmTestThreeDriverThousand(void)541 int32_t HdfPmTestThreeDriverThousand(void)
542 {
543 loopTest = true;
544 return HdfPmTestThreeDriver(PM_TEST_COUNT_THOUSAND, false);
545 }
546
HdfPmTestThreeDriverHundredWithSync(void)547 int32_t HdfPmTestThreeDriverHundredWithSync(void)
548 {
549 loopTest = true;
550 return HdfPmTestThreeDriver(PM_TEST_COUNT_HUNDRED, true);
551 }
552
HdfPmDriverRelease(struct HdfDeviceObject * deviceObject)553 void HdfPmDriverRelease(struct HdfDeviceObject *deviceObject)
554 {
555 (void)deviceObject;
556 return;
557 }
558
HdfPmDriverDispatch(struct HdfDeviceIoClient * client,int cmdId,struct HdfSBuf * data,struct HdfSBuf * reply)559 int32_t HdfPmDriverDispatch(struct HdfDeviceIoClient *client, int cmdId, struct HdfSBuf *data, struct HdfSBuf *reply)
560 {
561 int32_t ret = HDF_FAILURE;
562 uint32_t index;
563
564 HDF_LOGI("%s %d enter!", __func__, cmdId);
565
566 for (index = 0; index <= HDF_PM_TEST_END; index++) {
567 if (cmdId == testCases[index].cmd) {
568 ret = testCases[cmdId].testFunc();
569 break;
570 }
571 }
572
573 return ret;
574 }
575
HdfPmDriverBind(struct HdfDeviceObject * deviceObject)576 int HdfPmDriverBind(struct HdfDeviceObject *deviceObject)
577 {
578 HDF_LOGI("%s enter", __func__);
579 if (deviceObject == NULL) {
580 return HDF_FAILURE;
581 }
582 static struct IDeviceIoService testService = {
583 .Dispatch = HdfPmDriverDispatch,
584 .Open = NULL,
585 .Release = NULL,
586 };
587 deviceObject->service = &testService;
588 return HDF_SUCCESS;
589 }
590
HdfPmDriverInit(struct HdfDeviceObject * deviceObject)591 int HdfPmDriverInit(struct HdfDeviceObject *deviceObject)
592 {
593 static struct PmDriverPmListener pmListener = {0};
594
595 HDF_LOGI("%s enter!", __func__);
596 if (deviceObject == NULL) {
597 HDF_LOGE("%s ptr is null!", __func__);
598 return HDF_FAILURE;
599 }
600 HDF_LOGD("%s Init success", __func__);
601
602 pmListener.powerListener.DozeResume = HdfPmTestDozeResume;
603 pmListener.powerListener.DozeSuspend = HdfPmTestDozeSuspend;
604 pmListener.powerListener.Resume = HdfPmTestResume;
605 pmListener.powerListener.Suspend = HdfPmTestSuspend;
606
607 int ret = HdfPmRegisterPowerListener(deviceObject, &pmListener.powerListener);
608 HDF_LOGI("%s register power listener, ret = %d", __func__, ret);
609
610 return HDF_SUCCESS;
611 }
612
613 struct HdfDriverEntry g_pmDriverEntry = {
614 .moduleVersion = 1,
615 .moduleName = "pm_test_driver",
616 .Bind = HdfPmDriverBind,
617 .Init = HdfPmDriverInit,
618 .Release = HdfPmDriverRelease,
619 };
620
621 HDF_INIT(g_pmDriverEntry);
622
623