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