1 /*
2 * Copyright (c) 2020-2023 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 #include "usb_device_lite_cdcacm_test.h"
9 #include "hdf_module_test.h"
10 #include "hdf_log.h"
11 #include "hdf_message_test.h"
12 #include "osal.h"
13 #include "hdf_usb_device_test.h"
14
15 // add test case entry
16 static HdfTestCaseList g_hdfUsbDeviceTestCaseList[] = {
17 {USB_DEVICE_CREATE_DEVICE, UsbFnDviceTestCreate},
18 {USB_DEVICE_CREATE_DEVICE002, UsbFnDviceTestCreate002},
19 {USB_DEVICE_CREATE_DEVICE003, UsbFnDviceTestCreate003},
20 {USB_DEVICE_CREATE_DEVICE004, UsbFnDviceTestCreate004},
21 {USB_DEVICE_CREATE_DEVICE005, UsbFnDviceTestCreate005},
22 {USB_DEVICE_CREATE_DEVICE006, UsbFnDviceTestCreate006},
23 {USB_DEVICE_DEVICE_STATUS, UsbFnDviceTestStatus},
24 {USB_DEVICE_DEVICE_STATUS002, UsbFnDviceTestStatus002},
25 {USB_DEVICE_DEVICE_STATUS003, UsbFnDviceTestStatus003},
26 {USB_DEVICE_DEVICE_STATUS004, UsbFnDviceTestStatus004},
27 {USB_DEVICE_DEVICE_STATUS005, UsbFnDviceTestStatus005},
28 {USB_DEVICE_GET_DEVICE, UsbFnDviceTestGetDevice},
29 {USB_DEVICE_GET_DEVICE002, UsbFnDviceTestGetDevice002},
30 {USB_DEVICE_GET_DEVICE003, UsbFnDviceTestGetDevice003},
31 {USB_DEVICE_GET_DEVICE004, UsbFnDviceTestGetDevice004},
32 {USB_DEVICE_GET_DEVICE005, UsbFnDviceTestGetDevice005},
33 {USB_DEVICE_GET_DEVICE006, UsbFnDviceTestGetDevice006},
34 {USB_DEVICE_GET_INTERFACE, UsbFnDviceTestGetInterface},
35 {USB_DEVICE_GET_INTERFACE002, UsbFnDviceTestGetInterface002},
36 {USB_DEVICE_GET_INTERFACE003, UsbFnDviceTestGetInterface003},
37 {USB_DEVICE_GET_INTERFACE004, UsbFnDviceTestGetInterface004},
38 {USB_DEVICE_GET_INTERFACE005, UsbFnDviceTestGetInterface005},
39 {USB_DEVICE_GET_INTERFACE006, UsbFnDviceTestGetInterface006},
40 {USB_DEVICE_GET_PIPEINFO, UsbFnDviceTestGetPipeInfo},
41 {USB_DEVICE_GET_PIPEINFO002, UsbFnDviceTestGetPipeInfo002},
42 {USB_DEVICE_GET_PIPEINFO003, UsbFnDviceTestGetPipeInfo003},
43 {USB_DEVICE_GET_PIPEINFO004, UsbFnDviceTestGetPipeInfo004},
44 {USB_DEVICE_GET_PIPEINFO005, UsbFnDviceTestGetPipeInfo005},
45 {USB_DEVICE_GET_PIPEINFO006, UsbFnDviceTestGetPipeInfo006},
46 {USB_DEVICE_REQUEST_ASYNC, UsbFnDviceTestRequestAsync},
47 {USB_DEVICE_REQUEST_ASYNC002, UsbFnDviceTestRequestAsync002},
48 {USB_DEVICE_REQUEST_ASYNC003, UsbFnDviceTestRequestAsync003},
49 {USB_DEVICE_REQUEST_ASYNC004, UsbFnDviceTestRequestAsync004},
50 {USB_DEVICE_REQUEST_ASYNC005, UsbFnDviceTestRequestAsync005},
51 {USB_DEVICE_REQUEST_ASYNC006, UsbFnDviceTestRequestAsync006},
52 {USB_DEVICE_REQUEST_SYNC, UsbFnDviceTestRequestSync},
53 {USB_DEVICE_REQUEST_SYNC002, UsbFnDviceTestRequestSync002},
54 {USB_DEVICE_REQUEST_SYNC003, UsbFnDviceTestRequestSync003},
55 {USB_DEVICE_REQUEST_SYNC004, UsbFnDviceTestRequestSync004},
56 {USB_DEVICE_REQUEST_SYNC005, UsbFnDviceTestRequestSync005},
57 {USB_DEVICE_REQUEST_SYNC006, UsbFnDviceTestRequestSync006},
58 {USB_DEVICE_REQUEST_SYNC007, UsbFnDviceTestRequestSync007},
59 {USB_DEVICE_REGIST_PROP, UsbFnDviceTestRegistProp},
60 {USB_DEVICE_REGIST_PROP002, UsbFnDviceTestRegistProp002},
61 {USB_DEVICE_REGIST_PROP003, UsbFnDviceTestRegistProp003},
62 {USB_DEVICE_REGIST_PROP004, UsbFnDviceTestRegistProp004},
63 {USB_DEVICE_REGIST_PROP005, UsbFnDviceTestRegistProp005},
64 {USB_DEVICE_REGIST_PROP006, UsbFnDviceTestRegistProp006},
65 {USB_DEVICE_REGIST_PROP007, UsbFnDviceTestRegistProp007},
66 {USB_DEVICE_GET_PROP, UsbFnDviceTestGetProp},
67 {USB_DEVICE_GET_PROP002, UsbFnDviceTestGetProp002},
68 {USB_DEVICE_GET_PROP003, UsbFnDviceTestGetProp003},
69 {USB_DEVICE_GET_PROP004, UsbFnDviceTestGetProp004},
70 {USB_DEVICE_GET_PROP005, UsbFnDviceTestGetProp005},
71 {USB_DEVICE_GET_PROP006, UsbFnDviceTestGetProp006},
72 {USB_DEVICE_GET_PROP007, UsbFnDviceTestGetProp007},
73 {USB_DEVICE_GET_PROP008, UsbFnDviceTestGetProp008},
74 {USB_DEVICE_SET_PROP, UsbFnDviceTestSetProp},
75 {USB_DEVICE_SET_PROP002, UsbFnDviceTestSetProp002},
76 {USB_DEVICE_SET_PROP003, UsbFnDviceTestSetProp003},
77 {USB_DEVICE_SET_PROP004, UsbFnDviceTestSetProp004},
78 {USB_DEVICE_SET_PROP005, UsbFnDviceTestSetProp005},
79 {USB_DEVICE_SET_PROP006, UsbFnDviceTestSetProp006},
80 {USB_DEVICE_SET_PROP007, UsbFnDviceTestSetProp007},
81 {USB_DEVICE_ALLOC_CTRLREQUEST, UsbFnDviceTestAllocCtrlRequest},
82 {USB_DEVICE_ALLOC_CTRLREQUEST002, UsbFnDviceTestAllocCtrlRequest002},
83 {USB_DEVICE_ALLOC_CTRLREQUEST003, UsbFnDviceTestAllocCtrlRequest003},
84 {USB_DEVICE_ALLOC_CTRLREQUEST004, UsbFnDviceTestAllocCtrlRequest004},
85 {USB_DEVICE_ALLOC_CTRLREQUEST005, UsbFnDviceTestAllocCtrlRequest005},
86 {USB_DEVICE_ALLOC_CTRLREQUEST006, UsbFnDviceTestAllocCtrlRequest006},
87 {USB_DEVICE_ALLOC_CTRLREQUEST007, UsbFnDviceTestAllocCtrlRequest007},
88 {USB_DEVICE_ALLOC_CTRLREQUEST008, UsbFnDviceTestAllocCtrlRequest008},
89 {USB_DEVICE_ALLOC_REQUEST, UsbFnDviceTestAllocRequest},
90 {USB_DEVICE_ALLOC_REQUEST002, UsbFnDviceTestAllocRequest002},
91 {USB_DEVICE_ALLOC_REQUEST003, UsbFnDviceTestAllocRequest003},
92 {USB_DEVICE_ALLOC_REQUEST004, UsbFnDviceTestAllocRequest004},
93 {USB_DEVICE_ALLOC_REQUEST005, UsbFnDviceTestAllocRequest005},
94 {USB_DEVICE_ALLOC_REQUEST006, UsbFnDviceTestAllocRequest006},
95 {USB_DEVICE_ALLOC_REQUEST007, UsbFnDviceTestAllocRequest007},
96 {USB_DEVICE_ALLOC_REQUEST008, UsbFnDviceTestAllocRequest008},
97 {USB_DEVICE_ALLOC_REQUEST009, UsbFnDviceTestAllocRequest009},
98 {USB_DEVICE_FREE_REQUEST, UsbFnDviceTestFreeRequest},
99 {USB_DEVICE_FREE_REQUEST002, UsbFnDviceTestFreeRequest002},
100 {USB_DEVICE_FREE_REQUEST003, UsbFnDviceTestFreeRequest003},
101 {USB_DEVICE_FREE_REQUEST004, UsbFnDviceTestFreeRequest004},
102 {USB_DEVICE_FREE_REQUEST005, UsbFnDviceTestFreeRequest005},
103 {USB_DEVICE_FREE_REQUEST006, UsbFnDviceTestFreeRequest006},
104 {USB_DEVICE_GET_REQUEST_STATUS, UsbFnDviceTestGetRequestStatus},
105 {USB_DEVICE_GET_REQUEST_STATUS002, UsbFnDviceTestGetRequestStatus002},
106 {USB_DEVICE_GET_REQUEST_STATUS003, UsbFnDviceTestGetRequestStatus003},
107 {USB_DEVICE_GET_REQUEST_STATUS004, UsbFnDviceTestGetRequestStatus004},
108 {USB_DEVICE_GET_REQUEST_STATUS005, UsbFnDviceTestGetRequestStatus005},
109 {USB_DEVICE_GET_REQUEST_STATUS006, UsbFnDviceTestGetRequestStatus006},
110 {USB_DEVICE_CANCEL_REQUEST, UsbFnDviceTestCancelRequest},
111 {USB_DEVICE_CANCEL_REQUEST002, UsbFnDviceTestCancelRequest002},
112 {USB_DEVICE_CANCEL_REQUEST003, UsbFnDviceTestCancelRequest003},
113 {USB_DEVICE_CANCEL_REQUEST004, UsbFnDviceTestCancelRequest004},
114 {USB_DEVICE_CANCEL_REQUEST005, UsbFnDviceTestCancelRequest005},
115 {USB_DEVICE_CANCEL_REQUEST006, UsbFnDviceTestCancelRequest006},
116 {USB_DEVICE_STOP_EVENT, UsbFnDviceTestStopReceEvent},
117 {USB_DEVICE_STOP_EVENT002, UsbFnDviceTestStopReceEvent002},
118 {USB_DEVICE_STOP_EVENT003, UsbFnDviceTestStopReceEvent003},
119 {USB_DEVICE_STOP_EVENT004, UsbFnDviceTestStopReceEvent004},
120 {USB_DEVICE_START_EVENT, UsbFnDviceTestStartReceEvent},
121 {USB_DEVICE_START_EVENT002, UsbFnDviceTestStartReceEvent002},
122 {USB_DEVICE_START_EVENT003, UsbFnDviceTestStartReceEvent003},
123 {USB_DEVICE_START_EVENT004, UsbFnDviceTestStartReceEvent004},
124 {USB_DEVICE_START_EVENT005, UsbFnDviceTestStartReceEvent005},
125 {USB_DEVICE_START_EVENT006, UsbFnDviceTestStartReceEvent006},
126 {USB_DEVICE_START_EVENT007, UsbFnDviceTestStartReceEvent007},
127 {USB_DEVICE_CLOSE_INTERFACE, UsbFnDviceTestCloseInterface},
128 {USB_DEVICE_CLOSE_INTERFACE002, UsbFnDviceTestCloseInterface002},
129 {USB_DEVICE_CLOSE_INTERFACE003, UsbFnDviceTestCloseInterface003},
130 {USB_DEVICE_CLOSE_INTERFACE004, UsbFnDviceTestCloseInterface004},
131 {USB_DEVICE_OPEN_INTERFACE, UsbFnDviceTestOpenInterface},
132 {USB_DEVICE_OPEN_INTERFACE002, UsbFnDviceTestOpenInterface002},
133 {USB_DEVICE_OPEN_INTERFACE003, UsbFnDviceTestOpenInterface003},
134 {USB_DEVICE_OPEN_INTERFACE004, UsbFnDviceTestOpenInterface004},
135 {USB_DEVICE_OPEN_INTERFACE005, UsbFnDviceTestOpenInterface005},
136 {USB_DEVICE_DELETE_DEVICE, UsbFnDviceTestRemove},
137 {USB_DEVICE_DELETE_DEVICE002, UsbFnDviceTestRemove002},
138 };
139
HdfUsbDeviceEntry(HdfTestMsg * msg)140 int32_t HdfUsbDeviceEntry(HdfTestMsg *msg)
141 {
142 int32_t result;
143 int32_t i;
144
145 if (msg == NULL) {
146 HDF_LOGE("%s is fail: HdfTestMsg is NULL!", __func__);
147 return HDF_SUCCESS;
148 }
149
150 for (i = 0; i < sizeof(g_hdfUsbDeviceTestCaseList) / sizeof(g_hdfUsbDeviceTestCaseList[0]); ++i) {
151 if ((msg->subCmd == g_hdfUsbDeviceTestCaseList[i].subCmd) && (g_hdfUsbDeviceTestCaseList[i].testFunc != NULL)) {
152 result = g_hdfUsbDeviceTestCaseList[i].testFunc();
153 HDF_LOGE("HdfTest:usb device test result[%s-%u]", ((result == 0) ? "pass" : "fail"), msg->subCmd);
154 msg->result = (result == 0) ? HDF_SUCCESS : HDF_FAILURE;
155 return HDF_SUCCESS;
156 }
157 }
158 return HDF_SUCCESS;
159 }