1 /*
2 * Copyright (c) 2021 Huawei Device Co., Ltd.
3 * Licensed under the Apache License, Version 2.0 (the "License");
4 * you may not use this file except in compliance with the License.
5 * You may obtain a copy of the License at
6 *
7 * http://www.apache.org/licenses/LICENSE-2.0
8 *
9 * Unless required by applicable law or agreed to in writing, software
10 * distributed under the License is distributed on an "AS IS" BASIS,
11 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
12 * See the License for the specific language governing permissions and
13 * limitations under the License.
14 */
15
16 #include "wlan_hdi_service_stub.h"
17 #include "wlan_hal_c_proxy.h"
18 #include <gtest/gtest.h>
19 #include <servmgr_hdi.h>
20
21 #define HDF_LOG_TAG service_manager_test
22 using namespace testing::ext;
23
24 namespace HdiTest {
25 const int32_t WLAN_FREQ_MAX_NUM = 14;
26 const int32_t WLAN_TX_POWER = 160;
27 const int32_t DEFAULT_COMBO_SIZE = 6;
28 const int32_t WLAN_MAX_NUM_STA_WITH_AP = 4;
29 const uint32_t RESET_TIME = 20;
30
31 const char *WLAN_SERVICE_NAME = "wlan_hal_c_service";
32
33 class HdfWifiServiceCTest : public testing::Test {
34 public:
35 static void SetUpTestCase();
36 static void TearDownTestCase();
37 void SetUp();
38 void TearDown();
39 };
40
41 static struct IWifiInterface *g_wlanObj = nullptr;
42 static int32_t g_resetStatus = -1;
43
SetUpTestCase()44 void HdfWifiServiceCTest::SetUpTestCase()
45 {
46 g_wlanObj = HdIWifiInterfaceGet(WLAN_SERVICE_NAME);
47 ASSERT_TRUE(g_wlanObj != nullptr);
48 int32_t rc = g_wlanObj->construct(g_wlanObj);
49 ASSERT_EQ(rc, HDF_SUCCESS);
50 }
51
TearDownTestCase()52 void HdfWifiServiceCTest::TearDownTestCase()
53 {
54 int32_t rc = g_wlanObj->destruct(g_wlanObj);
55 ASSERT_EQ(rc, HDF_SUCCESS);
56 HdIWifiInterfaceRelease(g_wlanObj);
57 }
58
SetUp()59 void HdfWifiServiceCTest::SetUp()
60 {
61 int32_t rc = g_wlanObj->start(g_wlanObj);
62 ASSERT_EQ(rc, HDF_SUCCESS);
63 }
64
TearDown()65 void HdfWifiServiceCTest::TearDown()
66 {
67 int32_t rc = g_wlanObj->stop(g_wlanObj);
68 ASSERT_EQ(rc, HDF_SUCCESS);
69 }
70
HdiProcessScanResult(struct HdfSBuf * dataBuf)71 static void HdiProcessScanResult(struct HdfSBuf *dataBuf)
72 {
73 WifiScanResult *scanResult = nullptr;
74 uint32_t dataSize = 0;
75
76 if (!HdfSbufReadBuffer(dataBuf, (const void **)(&scanResult), &dataSize) || dataSize != sizeof(WifiScanResult)) {
77 HDF_LOGE("%s: HdfSbufReadBuffer scanResult failed!", __func__);
78 return;
79 }
80 printf("HdiProcessScanResult: flags=%d, caps=%d, freq=%d, beaconInt=%d,\n",
81 scanResult->flags, scanResult->caps, scanResult->freq, scanResult->beaconInt);
82 printf("HdiProcessScanResult: qual=%d, beaconIeLen=%d, level=%d, age=%d, ieLen=%d,\n",
83 scanResult->qual, scanResult->beaconIeLen, scanResult->level, scanResult->age, scanResult->ieLen);
84 }
85
HalResetCallbackEvent(uint32_t eventId,void * data,const char * ifName)86 static int32_t HalResetCallbackEvent(uint32_t eventId, void *data, const char *ifName)
87 {
88 (void)ifName;
89 struct HdfSBuf *dataBuf = (struct HdfSBuf*)data;
90
91 switch (eventId) {
92 case WIFI_EVENT_RESET_DRIVER:
93 if (!HdfSbufReadInt32(dataBuf, &g_resetStatus)) {
94 HDF_LOGE("%s: feature->type write failed!", __func__);
95 }
96 printf("HalResetCallbackEvent: receive resetStatus=%d \n", g_resetStatus);
97 break;
98 case WIFI_EVENT_SCAN_RESULT:
99 HdiProcessScanResult(dataBuf);
100 break;
101 default:
102 break;
103 }
104 return HDF_SUCCESS;
105 }
106
107 /**
108 * @tc.name: GetSupportFeatureComboTest_001
109 * @tc.desc: Wifi hdi get support feature and combo function test
110 * @tc.type: FUNC
111 * @tc.require: AR000FRMJB
112 */
113 HWTEST_F(HdfWifiServiceCTest, GetSupportFeatureComboTest_001, TestSize.Level1)
114 {
115 uint8_t supType[PROTOCOL_80211_IFTYPE_NUM + 1] = {0};
116 uint64_t combo[DEFAULT_COMBO_SIZE] = {0};
117
118 int32_t rc = g_wlanObj->getSupportFeature(g_wlanObj, supType);
119 ASSERT_EQ(rc, HDF_SUCCESS);
120 rc = g_wlanObj->getSupportCombo(g_wlanObj, combo);
121 ASSERT_EQ(rc, HDF_ERR_NOT_SUPPORT);
122 }
123
124 /**
125 * @tc.name: CreateFeatureTest_002
126 * @tc.desc: Wifi hdi create feature function test
127 * @tc.type: FUNC
128 * @tc.require: AR000FRMJB
129 */
130 HWTEST_F(HdfWifiServiceCTest, CreateFeatureTest_002, TestSize.Level1)
131 {
132 struct WlanFeatureInfo *ifeature = nullptr;
133 const int32_t wlan_type = PROTOCOL_80211_IFTYPE_AP;
134
135 int32_t rc = g_wlanObj->createFeature(g_wlanObj, wlan_type, (struct WlanFeatureInfo **)&ifeature);
136 ASSERT_EQ(rc, HDF_SUCCESS);
137 printf("ifname = %s\n", ifeature->ifName);
138 printf("type = %d\n", ifeature->wlanType);
139 rc = g_wlanObj->destroyFeature(g_wlanObj, (struct WlanFeatureInfo *)ifeature);
140 ASSERT_EQ(rc, HDF_SUCCESS);
141 }
142
143 /**
144 * @tc.name: GetFeatureByIfNameTest_003
145 * @tc.desc: Wifi hdi get feature by ifname function test
146 * @tc.type: FUNC
147 * @tc.require: AR000FRMJB
148 */
149 HWTEST_F(HdfWifiServiceCTest, GetFeatureByIfNameTest_003, TestSize.Level1)
150 {
151 const char *ifName = "wlan0";
152 const int32_t wlan_type = PROTOCOL_80211_IFTYPE_AP;
153 struct WlanFeatureInfo *ifeature = nullptr;
154
155 int32_t rc = g_wlanObj->createFeature(g_wlanObj, wlan_type, (struct WlanFeatureInfo **)&ifeature);
156 ASSERT_EQ(rc, HDF_SUCCESS);
157 rc = g_wlanObj->getFeatureByIfName(g_wlanObj, ifName, (struct WlanFeatureInfo **)&ifeature);
158 ASSERT_EQ(rc, HDF_SUCCESS);
159 rc = g_wlanObj->destroyFeature(g_wlanObj, (struct WlanFeatureInfo *)ifeature);
160 ASSERT_EQ(rc, HDF_SUCCESS);
161 }
162
163 /**
164 * @tc.name: GetAsscociatedStasTest_004
165 * @tc.desc: Wifi hdi get assoc stas function test
166 * @tc.type: FUNC
167 * @tc.require: AR000FRMJB
168 */
169 HWTEST_F(HdfWifiServiceCTest, GetAsscociatedStasTest_004, TestSize.Level1)
170 {
171 const int32_t wlan_type = PROTOCOL_80211_IFTYPE_AP;
172 struct WlanFeatureInfo *ifeature = nullptr;
173 struct StaInfo staInfo[WLAN_MAX_NUM_STA_WITH_AP] = {{0}};
174 uint32_t num = 0;
175
176 int32_t rc = g_wlanObj->createFeature(g_wlanObj, wlan_type, (struct WlanFeatureInfo **)&ifeature);
177 ASSERT_EQ(rc, HDF_SUCCESS);
178 rc = g_wlanObj->getAsscociatedStas(g_wlanObj, ifeature, staInfo, WLAN_MAX_NUM_STA_WITH_AP, &num);
179 ASSERT_EQ(rc, HDF_SUCCESS);
180 rc = g_wlanObj->destroyFeature(g_wlanObj, (struct WlanFeatureInfo *)ifeature);
181 ASSERT_EQ(rc, HDF_SUCCESS);
182 }
183
184 /**
185 * @tc.name: SetCountryCodeTest_005
186 * @tc.desc: Wifi hdi set country code function test
187 * @tc.type: FUNC
188 * @tc.require: AR000FRMJB
189 */
190 HWTEST_F(HdfWifiServiceCTest, SetCountryCodeTest_005, TestSize.Level1)
191 {
192 const char *code = "CN";
193 const int32_t wlan_type = PROTOCOL_80211_IFTYPE_AP;
194 struct WlanFeatureInfo *ifeature = nullptr;
195
196 int32_t rc = g_wlanObj->createFeature(g_wlanObj, wlan_type, (struct WlanFeatureInfo **)&ifeature);
197 ASSERT_EQ(rc, HDF_SUCCESS);
198 rc = g_wlanObj->setCountryCode(g_wlanObj, ifeature, code, sizeof(code));
199 ASSERT_EQ(rc, HDF_SUCCESS);
200 rc = g_wlanObj->destroyFeature(g_wlanObj, (struct WlanFeatureInfo *)ifeature);
201 ASSERT_EQ(rc, HDF_SUCCESS);
202 }
203
204 /**
205 * @tc.name: GetNetworkIfaceNameTest_006
206 * @tc.desc: Wifi hdi get network interface name function test
207 * @tc.type: FUNC
208 * @tc.require: AR000FRMJB
209 */
210 HWTEST_F(HdfWifiServiceCTest, GetNetworkIfaceNameTest_006, TestSize.Level1)
211 {
212 const int32_t wlan_type = PROTOCOL_80211_IFTYPE_AP;
213 struct WlanFeatureInfo *ifeature = nullptr;
214
215 int32_t rc = g_wlanObj->createFeature(g_wlanObj, wlan_type, (struct WlanFeatureInfo **)&ifeature);
216 ASSERT_EQ(rc, HDF_SUCCESS);
217 rc = g_wlanObj->getNetworkIfaceName(g_wlanObj, (struct WlanFeatureInfo *)ifeature);
218 ASSERT_EQ(rc, HDF_SUCCESS);
219 rc = g_wlanObj->destroyFeature(g_wlanObj, (struct WlanFeatureInfo *)ifeature);
220 ASSERT_EQ(rc, HDF_SUCCESS);
221 }
222
223 /**
224 * @tc.name: GetFeatureTypeTest_007
225 * @tc.desc: Wifi hdi get feature type function test
226 * @tc.type: FUNC
227 * @tc.require: AR000FRMJB
228 */
229 HWTEST_F(HdfWifiServiceCTest, GetFeatureTypeTest_007, TestSize.Level1)
230 {
231 const int32_t wlan_type = PROTOCOL_80211_IFTYPE_AP;
232 struct WlanFeatureInfo *ifeature = nullptr;
233
234 int32_t rc = g_wlanObj->createFeature(g_wlanObj, wlan_type, (struct WlanFeatureInfo **)&ifeature);
235 ASSERT_EQ(rc, HDF_SUCCESS);
236 rc = g_wlanObj->getFeatureType(g_wlanObj, (struct WlanFeatureInfo *)ifeature);
237 ASSERT_EQ(rc, HDF_SUCCESS);
238 rc = g_wlanObj->destroyFeature(g_wlanObj, (struct WlanFeatureInfo *)ifeature);
239 ASSERT_EQ(rc, HDF_SUCCESS);
240 }
241
242 /**
243 * @tc.name: SetMacAddressTest_008
244 * @tc.desc: Wifi hdi set mac addr function test
245 * @tc.type: FUNC
246 * @tc.require: AR000FRMJB
247 */
248 HWTEST_F(HdfWifiServiceCTest, SetMacAddressTest_008, TestSize.Level1)
249 {
250 uint8_t mac[ETH_ADDR_LEN] = {0x12, 0x34, 0x56, 0x78, 0xab, 0xcd};
251 const int32_t wlan_type = PROTOCOL_80211_IFTYPE_AP;
252 struct WlanFeatureInfo *ifeature = nullptr;
253
254 int32_t rc = g_wlanObj->createFeature(g_wlanObj, wlan_type, (struct WlanFeatureInfo **)&ifeature);
255 ASSERT_EQ(rc, HDF_SUCCESS);
256 rc = g_wlanObj->setMacAddress(g_wlanObj, (struct WlanFeatureInfo *)ifeature, mac, ETH_ADDR_LEN);
257 ASSERT_EQ(rc, HDF_SUCCESS);
258 rc = g_wlanObj->destroyFeature(g_wlanObj, (struct WlanFeatureInfo *)ifeature);
259 ASSERT_EQ(rc, HDF_SUCCESS);
260 }
261
262 /**
263 * @tc.name: GetDeviceMacAddressTest_009
264 * @tc.desc: Wifi hdi get device mac addr function test
265 * @tc.type: FUNC
266 * @tc.require: AR000FRMJB
267 */
268 HWTEST_F(HdfWifiServiceCTest, GetDeviceMacAddressTest_009, TestSize.Level1)
269 {
270 const int32_t wlan_type = PROTOCOL_80211_IFTYPE_AP;
271 struct WlanFeatureInfo *ifeature = nullptr;
272 uint8_t mac[ETH_ADDR_LEN] = {0};
273
274 int32_t rc = g_wlanObj->createFeature(g_wlanObj, wlan_type, (struct WlanFeatureInfo **)&ifeature);
275 ASSERT_EQ(rc, HDF_SUCCESS);
276 rc = g_wlanObj->getDeviceMacAddress(g_wlanObj, (struct WlanFeatureInfo *)ifeature, mac, ETH_ADDR_LEN);
277 ASSERT_EQ(rc, HDF_SUCCESS);
278 rc = g_wlanObj->destroyFeature(g_wlanObj, (struct WlanFeatureInfo *)ifeature);
279 ASSERT_EQ(rc, HDF_SUCCESS);
280 }
281
282 /**
283 * @tc.name: GetFreqsWithBandTest_010
284 * @tc.desc: Wifi hdi get freqs function test
285 * @tc.type: FUNC
286 * @tc.require: AR000FRMJB
287 */
288 HWTEST_F(HdfWifiServiceCTest, GetFreqsWithBandTest_010, TestSize.Level1)
289 {
290 const int32_t wlan_type = PROTOCOL_80211_IFTYPE_AP;
291 struct WlanFeatureInfo *ifeature = nullptr;
292 int32_t freq[WLAN_FREQ_MAX_NUM] = {0};
293 int32_t wlanBand = 0;
294 uint32_t count = 0;
295
296 int32_t rc = g_wlanObj->createFeature(g_wlanObj, wlan_type, (struct WlanFeatureInfo **)&ifeature);
297 ASSERT_EQ(rc, HDF_SUCCESS);
298 rc = g_wlanObj->getFreqsWithBand(g_wlanObj, (struct WlanFeatureInfo *)ifeature, wlanBand, freq,
299 WLAN_FREQ_MAX_NUM, &count);
300 ASSERT_EQ(rc, HDF_SUCCESS);
301 rc = g_wlanObj->destroyFeature(g_wlanObj, (struct WlanFeatureInfo *)ifeature);
302 ASSERT_EQ(rc, HDF_SUCCESS);
303 }
304
305 /**
306 * @tc.name: SetTxPowerTest_011
307 * @tc.desc: Wifi hdi set tx power function test
308 * @tc.type: FUNC
309 * @tc.require: AR000FRMJB
310 */
311 HWTEST_F(HdfWifiServiceCTest, SetTxPowerTest_011, TestSize.Level1)
312 {
313 const int32_t wlan_type = PROTOCOL_80211_IFTYPE_AP;
314 struct WlanFeatureInfo *ifeature = nullptr;
315 int32_t power = WLAN_TX_POWER;
316
317 int32_t rc = g_wlanObj->createFeature(g_wlanObj, wlan_type, (struct WlanFeatureInfo **)&ifeature);
318 ASSERT_EQ(rc, HDF_SUCCESS);
319 rc = g_wlanObj->setTxPower(g_wlanObj, (struct WlanFeatureInfo *)ifeature, power);
320 ASSERT_EQ(rc, HDF_SUCCESS);
321 rc = g_wlanObj->destroyFeature(g_wlanObj, (struct WlanFeatureInfo *)ifeature);
322 ASSERT_EQ(rc, HDF_SUCCESS);
323 }
324
325 /**
326 * @tc.name: GetChipIdTest_012
327 * @tc.desc: Wifi hdi get chip id function test
328 * @tc.type: FUNC
329 * @tc.require: AR000FRMJB
330 */
331 HWTEST_F(HdfWifiServiceCTest, GetChipIdTest_012, TestSize.Level1)
332 {
333 const int32_t wlan_type = PROTOCOL_80211_IFTYPE_STATION;
334 struct WlanFeatureInfo *ifeature = nullptr;
335 uint8_t chipId = 0;
336 unsigned int num = 0;
337 char *ifNames = nullptr;
338
339 int32_t rc = g_wlanObj->createFeature(g_wlanObj, wlan_type, (struct WlanFeatureInfo **)&ifeature);
340 ASSERT_EQ(rc, HDF_SUCCESS);
341 rc = g_wlanObj->getChipId(g_wlanObj, (struct WlanFeatureInfo *)ifeature, &chipId);
342 ASSERT_EQ(rc, HDF_SUCCESS);
343 rc = g_wlanObj->getIfNamesByChipId(g_wlanObj, chipId, &ifNames, &num);
344 printf("ifnames = %s\n", ifNames);
345 ASSERT_EQ(rc, HDF_SUCCESS);
346 rc = g_wlanObj->destroyFeature(g_wlanObj, (struct WlanFeatureInfo *)ifeature);
347 ASSERT_EQ(rc, HDF_SUCCESS);
348 }
349
350 /**
351 * @tc.name: SetScanningMacAddressTest_013
352 * @tc.desc: Wifi hdi set scanning mac addr function test
353 * @tc.type: FUNC
354 * @tc.require: AR000FRMJB
355 */
356 HWTEST_F(HdfWifiServiceCTest, SetScanningMacAddressTest_013, TestSize.Level1)
357 {
358 const int32_t wlan_type = PROTOCOL_80211_IFTYPE_STATION;
359 struct WlanFeatureInfo *ifeature = nullptr;
360 uint8_t scanMac[ETH_ADDR_LEN] = {0x12, 0x34, 0x56, 0x78, 0xab, 0xcd};
361
362 int32_t rc = g_wlanObj->createFeature(g_wlanObj, wlan_type, (struct WlanFeatureInfo **)&ifeature);
363 ASSERT_EQ(rc, HDF_SUCCESS);
364 rc = g_wlanObj->setScanningMacAddress(g_wlanObj, (struct WlanFeatureInfo *)ifeature, scanMac, ETH_ADDR_LEN);
365 ASSERT_EQ(rc, HDF_ERR_NOT_SUPPORT);
366 rc = g_wlanObj->destroyFeature(g_wlanObj, (struct WlanFeatureInfo *)ifeature);
367 ASSERT_EQ(rc, HDF_SUCCESS);
368 }
369
370 /**
371 * @tc.name: GetNetdevInfoTest_014
372 * @tc.desc: Wifi hdi get netdev info function test
373 * @tc.type: FUNC
374 * @tc.require: AR000FRMJB
375 */
376 HWTEST_F(HdfWifiServiceCTest, GetNetdevInfoTest_014, TestSize.Level1)
377 {
378 int32_t rc;
379 struct NetDeviceInfoResult netDeviceInfoResult;
380
381 (void)memset_s(&netDeviceInfoResult, sizeof(struct NetDeviceInfoResult), 0, sizeof(struct NetDeviceInfoResult));
382 rc = g_wlanObj->getNetDevInfo(g_wlanObj, (struct NetDeviceInfoResult *)&netDeviceInfoResult);
383 ASSERT_EQ(rc, HDF_SUCCESS);
384 }
385
386 /**
387 * @tc.name: RegisterEventCallbackTest_015
388 * @tc.desc: Wifi hdi reister event call back function test
389 * @tc.type: FUNC
390 * @tc.require: AR000FRMJB
391 */
392 HWTEST_F(HdfWifiServiceCTest, RegisterEventCallbackTest_015, TestSize.Level1)
393 {
394 int32_t rc = g_wlanObj->registerEventCallback(g_wlanObj, HalResetCallbackEvent);
395 ASSERT_EQ(rc, HDF_SUCCESS);
396 }
397
398 /**
399 * @tc.name: ResetDriverTest_016
400 * @tc.desc: Wifi hdi reset driver function test
401 * @tc.type: FUNC
402 * @tc.require: AR000FRMJB
403 */
404 HWTEST_F(HdfWifiServiceCTest, ResetDriverTest_016, TestSize.Level1)
405 {
406 int32_t wlan_type = PROTOCOL_80211_IFTYPE_STATION;
407 struct WlanFeatureInfo *ifeature = nullptr;
408 uint8_t chipId= 0;
409 int32_t rc;
410
411 rc = g_wlanObj->createFeature(g_wlanObj, wlan_type, (struct WlanFeatureInfo **)&ifeature);
412 ASSERT_EQ(rc, HDF_SUCCESS);
413 rc = g_wlanObj->getChipId(g_wlanObj, (struct WlanFeatureInfo *)ifeature, &chipId);
414 ASSERT_EQ(rc, HDF_SUCCESS);
415 rc = g_wlanObj->destroyFeature(g_wlanObj, (struct WlanFeatureInfo *)ifeature);
416 ASSERT_EQ(rc, HDF_SUCCESS);
417 rc = g_wlanObj->resetDriver(g_wlanObj, chipId);
418 ASSERT_EQ(rc, HDF_SUCCESS);
419 EXPECT_EQ(HDF_SUCCESS, g_resetStatus);
420 sleep(RESET_TIME);
421 }
422
423 /**
424 * @tc.name: StartScanTest_017
425 * @tc.desc: Wifi hdi start scan function test
426 * @tc.type: FUNC
427 * @tc.require: AR000FRMJB
428 */
429 HWTEST_F(HdfWifiServiceCTest, StartScanTest_017, TestSize.Level1)
430 {
431 int32_t rc;
432 const int32_t wlan_type = PROTOCOL_80211_IFTYPE_STATION;
433 struct WlanFeatureInfo *ifeature = nullptr;
434 WifiScan scan = {0};
435
436 rc = g_wlanObj->createFeature(g_wlanObj, wlan_type, (struct WlanFeatureInfo **)&ifeature);
437 ASSERT_EQ(rc, HDF_SUCCESS);
438 rc = g_wlanObj->startScan(g_wlanObj, (struct WlanFeatureInfo *)ifeature, &scan);
439 ASSERT_EQ(rc, HDF_SUCCESS);
440 rc = g_wlanObj->destroyFeature(g_wlanObj, (struct WlanFeatureInfo *)ifeature);
441 ASSERT_EQ(rc, HDF_SUCCESS);
442 sleep(10);
443 }
444
445 /**
446 * @tc.name: UnregisterEventCallbackTest_018
447 * @tc.desc: Wifi hdi unreister event call back function test
448 * @tc.type: FUNC
449 * @tc.require: AR000FRMJB
450 */
451 HWTEST_F(HdfWifiServiceCTest, UnregisterEventCallbackTest_018, TestSize.Level1)
452 {
453 int32_t rc = g_wlanObj->unregisterEventCallback(g_wlanObj);
454 ASSERT_EQ(rc, HDF_SUCCESS);
455 }
456 };