1 /*
2 * Copyright (c) 2020-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 "hcs_parser_test.h"
10 #include "hdf_base.h"
11 #include "hdf_device_desc.h"
12 #include "hdf_log.h"
13 #include "hdf_main_test.h"
14 #include "osal_test_entry.h"
15
16 #if defined(LOSCFG_DRIVERS_HDF_PLATFORM) || defined(CONFIG_DRIVERS_HDF_PLATFORM)
17 #include "hdf_platform_core_entry_test.h"
18 #if defined(LOSCFG_DRIVERS_HDF_PLATFORM_GPIO) || defined(CONFIG_DRIVERS_HDF_PLATFORM_GPIO)
19 #include "hdf_gpio_entry_test.h"
20 #endif
21 #if defined(LOSCFG_DRIVERS_HDF_PLATFORM_PIN) || defined(CONFIG_DRIVERS_HDF_PLATFORM_PIN)
22 #include "hdf_pin_entry_test.h"
23 #endif
24 #if defined(LOSCFG_DRIVERS_HDF_PLATFORM_I2C) || defined(CONFIG_DRIVERS_HDF_PLATFORM_I2C)
25 #include "hdf_i2c_entry_test.h"
26 #endif
27 #if defined(LOSCFG_DRIVERS_HDF_PLATFORM_I2S) || defined(CONFIG_DRIVERS_HDF_PLATFORM_I2S)
28 #include "hdf_i2s_entry_test.h"
29 #endif
30 #if defined(LOSCFG_DRIVERS_HDF_PLATFORM_REGULATOR) || defined(CONFIG_DRIVERS_HDF_PLATFORM_REGULATOR)
31 #include "hdf_regulator_entry_test.h"
32 #endif
33 #if defined(LOSCFG_DRIVERS_HDF_PLATFORM_ADC) || defined(CONFIG_DRIVERS_HDF_PLATFORM_ADC)
34 #include "hdf_adc_entry_test.h"
35 #endif
36 #if defined(LOSCFG_DRIVERS_HDF_PLATFORM_DAC) || defined(CONFIG_DRIVERS_HDF_PLATFORM_DAC)
37 #include "hdf_dac_entry_test.h"
38 #endif
39 #if defined(LOSCFG_DRIVERS_HDF_PLATFORM_I3C) || defined(CONFIG_DRIVERS_HDF_PLATFORM_I3C)
40 #include "hdf_i3c_entry_test.h"
41 #endif
42 #if defined(LOSCFG_DRIVERS_HDF_PLATFORM_SPI) || defined(CONFIG_DRIVERS_HDF_PLATFORM_SPI)
43 #include "hdf_spi_entry_test.h"
44 #endif
45 #if defined(LOSCFG_DRIVERS_HDF_PLATFORM_SDIO) || defined(CONFIG_DRIVERS_HDF_PLATFORM_SDIO)
46 #include "hdf_sdio_entry_test.h"
47 #endif
48 #if defined(LOSCFG_DRIVERS_HDF_PLATFORM_PCIE) || defined(CONFIG_DRIVERS_HDF_PLATFORM_PCIE)
49 #include "hdf_pcie_entry_test.h"
50 #endif
51 #if defined(LOSCFG_DRIVERS_HDF_PLATFORM_UART) || defined(CONFIG_DRIVERS_HDF_PLATFORM_UART)
52 #include "hdf_uart_entry_test.h"
53 #endif
54 #if defined(LOSCFG_DRIVERS_HDF_PLATFORM_WATCHDOG) || defined(CONFIG_DRIVERS_HDF_PLATFORM_WATCHDOG)
55 #include "hdf_watchdog_entry_test.h"
56 #endif
57 #if defined(LOSCFG_DRIVERS_HDF_PLATFORM_RTC) || defined(CONFIG_DRIVERS_HDF_PLATFORM_RTC)
58 #include "hdf_rtc_entry_test.h"
59 #endif
60 #if defined(LOSCFG_DRIVERS_HDF_PLATFORM_MIPI_DSI) || defined(CONFIG_DRIVERS_HDF_PLATFORM_MIPI_DSI)
61 #include "hdf_mipi_dsi_entry_test.h"
62 #endif
63 #if defined(LOSCFG_DRIVERS_HDF_PLATFORM_MIPI_CSI) || defined(CONFIG_DRIVERS_HDF_PLATFORM_MIPI_CSI)
64 #include "hdf_mipi_csi_entry_test.h"
65 #endif
66 #if (defined(LOSCFG_STORAGE_EMMC) && defined(LOSCFG_DRIVERS_HDF_PLATFORM_EMMC)) || \
67 defined(CONFIG_DRIVERS_HDF_PLATFORM_EMMC)
68 #include "hdf_emmc_entry_test.h"
69 #endif
70 #if defined(LOSCFG_DRIVERS_HDF_PLATFORM_PWM) || defined(CONFIG_DRIVERS_HDF_PLATFORM_PWM)
71 #include "hdf_pwm_entry_test.h"
72 #endif
73 #if defined(LOSCFG_DRIVERS_HDF_PLATFORM_TIMER) || defined(CONFIG_DRIVERS_HDF_PLATFORM_TIMER)
74 #include "hdf_timer_entry_test.h"
75 #endif
76 #endif
77 #if defined(LOSCFG_DRIVERS_HDF_WIFI) || defined(CONFIG_DRIVERS_HDF_WIFI)
78 #include "hdf_wifi_test.h"
79 #endif
80 #if defined(LOSCFG_DRIVERS_HDF_AUDIO_TEST) || defined(CONFIG_DRIVERS_HDF_AUDIO_TEST)
81 #include "hdf_audio_test.h"
82 #include "hdf_audio_driver_test.h"
83 #endif
84 #if defined(LOSCFG_DRIVERS_HDF_USB_DDK_DEVICE) || defined(CONFIG_DRIVERS_HDF_USB_DDK_DEVICE)
85 #include "hdf_usb_device_test.h"
86 #endif
87 #if defined(LOSCFG_DRIVERS_HDF_USB_DDK_HOST) || defined(CONFIG_DRIVERS_HDF_USB_DDK_HOST)
88 #include "hdf_usb_entry_test.h"
89 #endif
90
91 #define HDF_LOG_TAG hdf_test
92
93 // add submodule entry
94 HdfTestFuncList g_hdfTestFuncList[] = {
95 #if defined(LOSCFG_DRIVERS_HDF_PLATFORM) || defined(CONFIG_DRIVERS_HDF_PLATFORM)
96 { TEST_PAL_EVENT_TYPE, HdfPlatformEventTestEntry },
97 { TEST_PAL_QUEUE_TYPE, HdfPlatformQueueTestEntry },
98 { TEST_PAL_DEVICE_TYPE, HdfPlatformDeviceTestEntry },
99 { TEST_PAL_MANAGER_TYPE, HdfPlatformManagerTestEntry },
100 #if defined(LOSCFG_DRIVERS_HDF_PLATFORM_GPIO) || defined(CONFIG_DRIVERS_HDF_PLATFORM_GPIO)
101 { TEST_PAL_GPIO_TYPE, HdfGpioTestEntry },
102 #endif
103 #if defined(LOSCFG_DRIVERS_HDF_PLATFORM_PIN) || defined(CONFIG_DRIVERS_HDF_PLATFORM_PIN)
104 { TEST_PAL_PIN_TYPE, HdfPinTestEntry },
105 #endif
106 #if defined(LOSCFG_DRIVERS_HDF_PLATFORM_I2C) || defined(CONFIG_DRIVERS_HDF_PLATFORM_I2C)
107 { TEST_PAL_I2C_TYPE, HdfI2cTestEntry },
108 #endif
109 #if defined(LOSCFG_DRIVERS_HDF_PLATFORM_I2S) || defined(CONFIG_DRIVERS_HDF_PLATFORM_I2S)
110 { TEST_PAL_I2S_TYPE, HdfI2sUnitTestEntry },
111 #endif
112 #if defined(LOSCFG_DRIVERS_HDF_PLATFORM_REGULATOR) || defined(CONFIG_DRIVERS_HDF_PLATFORM_REGULATOR)
113 { TEST_PAL_REGULATOR_TYPE, HdfRegulatorUnitTestEntry },
114 #endif
115 #if defined(LOSCFG_DRIVERS_HDF_PLATFORM_ADC) || defined(CONFIG_DRIVERS_HDF_PLATFORM_ADC)
116 { TEST_PAL_ADC_TYPE, HdfAdcTestEntry },
117 #endif
118 #if defined(LOSCFG_DRIVERS_HDF_PLATFORM_DAC) || defined(CONFIG_DRIVERS_HDF_PLATFORM_DAC)
119 { TEST_PAL_DAC_TYPE, HdfDacTestEntry },
120 #endif
121 #if defined(LOSCFG_DRIVERS_HDF_PLATFORM_I3C) || defined(CONFIG_DRIVERS_HDF_PLATFORM_I3C)
122 { TEST_PAL_I3C_TYPE, HdfI3cTestEntry },
123 #endif
124 #if defined(LOSCFG_DRIVERS_HDF_PLATFORM_SPI) || defined(CONFIG_DRIVERS_HDF_PLATFORM_SPI)
125 { TEST_PAL_SPI_TYPE, HdfSpiUnitTestEntry },
126 #endif
127 #if defined(LOSCFG_DRIVERS_HDF_PLATFORM_UART) || defined(CONFIG_DRIVERS_HDF_PLATFORM_UART)
128 { TEST_PAL_UART_TYPE, HdfUartUnitTestEntry },
129 #endif
130 #if defined(LOSCFG_DRIVERS_HDF_PLATFORM_WATCHDOG) || defined(CONFIG_DRIVERS_HDF_PLATFORM_WATCHDOG)
131 { TEST_PAL_WDT_TYPE, HdfWatchdogTestEntry },
132 #endif
133 #if defined(LOSCFG_DRIVERS_HDF_PLATFORM_RTC) || defined(CONFIG_DRIVERS_HDF_PLATFORM_RTC)
134 { TEST_PAL_RTC_TYPE, HdfRtcTestEntry },
135 #endif
136 #if defined(LOSCFG_DRIVERS_HDF_PLATFORM_MIPI_DSI) || defined(CONFIG_DRIVERS_HDF_PLATFORM_MIPI_DSI)
137 { TEST_PAL_MIPI_DSI_TYPE, HdfMipiDsiEntry },
138 #endif
139 #if defined(LOSCFG_DRIVERS_HDF_PLATFORM_MIPI_CSI) || defined(CONFIG_DRIVERS_HDF_PLATFORM_MIPI_CSI)
140 { TEST_PAL_MIPI_CSI_TYPE, HdfMipiCsiEntry },
141 #endif
142 #if defined(LOSCFG_DRIVERS_HDF_PLATFORM_SDIO) || defined(CONFIG_DRIVERS_HDF_PLATFORM_SDIO)
143 { TEST_PAL_SDIO_TYPE, HdfSdioUnitTestEntry },
144 #endif
145 #if defined(LOSCFG_DRIVERS_HDF_PLATFORM_PCIE) || defined(CONFIG_DRIVERS_HDF_PLATFORM_PCIE)
146 { TEST_PAL_PCIE_TYPE, HdfPcieUnitTestEntry },
147 #endif
148 #if (defined(LOSCFG_STORAGE_EMMC) && defined(LOSCFG_DRIVERS_HDF_PLATFORM_EMMC)) || \
149 defined(CONFIG_DRIVERS_HDF_PLATFORM_EMMC)
150 { TEST_PAL_EMMC_TYPE, HdfEmmcUnitTestEntry },
151 #endif
152 #if defined(LOSCFG_DRIVERS_HDF_PLATFORM_PWM) || defined(CONFIG_DRIVERS_HDF_PLATFORM_PWM)
153 { TEST_PAL_PWM_TYPE, HdfPwmUnitTestEntry },
154 #endif
155 #if defined(LOSCFG_DRIVERS_HDF_PLATFORM_TIMER) || defined(CONFIG_DRIVERS_HDF_PLATFORM_TIMER)
156 { TEST_PAL_TIMER_TYPE, HdfTimerUnitTestEntry },
157 #endif
158 #endif
159 { TEST_CONFIG_TYPE, HdfConfigEntry },
160 { TEST_OSAL_ITEM, HdfOsalEntry },
161 #if defined(LOSCFG_DRIVERS_HDF_WIFI) || defined(CONFIG_DRIVERS_HDF_WIFI)
162 {TEST_WIFI_TYPE, HdfWifiEntry},
163 #endif
164 #if defined(LOSCFG_DRIVERS_HDF_AUDIO_TEST) || defined(CONFIG_DRIVERS_HDF_AUDIO_TEST)
165 {TEST_AUDIO_TYPE, HdfAudioEntry},
166 {TEST_AUDIO_DRIVER_TYPE, HdfAudioDriverEntry},
167 #endif
168 #if defined(LOSCFG_DRIVERS_HDF_USB_DDK_DEVICE) || defined(CONFIG_DRIVERS_HDF_USB_DDK_DEVICE)
169 {TEST_USB_DEVICE_TYPE, HdfUsbDeviceEntry},
170 #endif
171 #if defined(LOSCFG_DRIVERS_HDF_USB_DDK_HOST) || defined(CONFIG_DRIVERS_HDF_USB_DDK_HOST)
172 #if defined(LOSCFG_DRIVERS_HDF_USB_PNP_NOTIFY) || defined(CONFIG_DRIVERS_HDF_USB_PNP_NOTIFY)
173 {TEST_USB_HOST_TYPE, HdfUsbUnitTestEntry},
174 {TEST_USB_HOST_RAW_TYPE, HdfUsbUnitTestEntry},
175 #endif
176 #endif
177 };
178
HdfTestCaseProcess(struct HdfDeviceIoClient * client,int cmdId,struct HdfSBuf * data,struct HdfSBuf * reply)179 static int32_t HdfTestCaseProcess(struct HdfDeviceIoClient *client,
180 int cmdId, struct HdfSBuf *data, struct HdfSBuf *reply)
181 {
182 HdfTestMsg *msg = NULL;
183 HdfTestMsg replyMsg;
184 uint32_t len;
185 int i;
186 struct TestService *testService = NULL;
187
188 if (client == NULL || client->device == NULL) {
189 HDF_LOGE("%s:: client or client->device is NULL", __func__);
190 return HDF_ERR_INVALID_OBJECT;
191 }
192
193 if (data == NULL || reply == NULL) {
194 HDF_LOGE("%s:: data or reply is NULL", __func__);
195 return HDF_ERR_INVALID_PARAM;
196 }
197
198 testService = (struct TestService *)client->device->service;
199 if (testService == NULL) {
200 HDF_LOGE("%s:: service is NULL", __func__);
201 return HDF_ERR_INVALID_OBJECT;
202 }
203
204 if (!HdfSbufReadBuffer(data, (const void **)&msg, &len)) {
205 HDF_LOGE("%s:: msg sbuf read fail", __func__);
206 return HDF_ERR_INVALID_PARAM;
207 }
208
209 replyMsg.cmd = msg->cmd;
210 replyMsg.subCmd = msg->subCmd;
211
212 HDF_LOGE("%s::Hdf test receive cmd: command[%u], subCommand[%u]", __func__, msg->cmd, msg->subCmd);
213
214 replyMsg.result = HDF_FAILURE;
215 for (i = 0; i < sizeof(g_hdfTestFuncList) / sizeof(g_hdfTestFuncList[0]); ++i) {
216 if ((msg->cmd == g_hdfTestFuncList[i].cmd) && (g_hdfTestFuncList[i].testFunc != NULL)) {
217 g_hdfTestFuncList[i].testFunc(&replyMsg);
218 break;
219 }
220 }
221
222 if (!HdfSbufWriteBuffer(reply, &replyMsg, sizeof(replyMsg))) {
223 HDF_LOGE("%s:: hdf test sbuf write fail", __func__);
224 return HDF_ERR_INVALID_PARAM;
225 }
226
227 return HDF_SUCCESS;
228 }
229
HdfTestDriverRelease(struct HdfDeviceObject * device)230 void HdfTestDriverRelease(struct HdfDeviceObject *device)
231 {
232 return;
233 }
234
HdfTestDriverDispatch(struct HdfDeviceObject * device)235 void HdfTestDriverDispatch(struct HdfDeviceObject *device)
236 {
237 return;
238 }
239
HdfTestDriverBind(struct HdfDeviceObject * device)240 int HdfTestDriverBind(struct HdfDeviceObject *device)
241 {
242 static struct TestService testService;
243
244 if (device == NULL) {
245 return -1;
246 }
247
248 testService.testRemoteService.Dispatch = HdfTestCaseProcess;
249
250 device->service = &testService.testRemoteService;
251 return 0;
252 }
253
254 static struct HdfDeviceObject *g_devObject;
GetDeviceObject(void)255 struct HdfDeviceObject *GetDeviceObject(void)
256 {
257 return g_devObject;
258 }
259
HdfTestDriverInit(struct HdfDeviceObject * device)260 int HdfTestDriverInit(struct HdfDeviceObject *device)
261 {
262 if (device == NULL) {
263 HDF_LOGE("%s::ptr is null!\n", __func__);
264 return -1;
265 }
266 g_devObject = device;
267 return 0;
268 }
269
270 struct HdfDriverEntry g_hdfTestDevice = {
271 .moduleVersion = 1,
272 .moduleName = "HDF_TEST",
273 .Bind = HdfTestDriverBind,
274 .Init = HdfTestDriverInit,
275 .Release = HdfTestDriverRelease,
276 };
277
278 HDF_INIT(g_hdfTestDevice);
279