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