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 = 35;
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_NE(rc, HDF_FAILURE);
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 int32_t wlan_type = PROTOCOL_80211_IFTYPE_AP;
152 struct WlanFeatureInfo *ifeature = nullptr;
153
154 int32_t rc = g_wlanObj->createFeature(g_wlanObj, wlan_type, (struct WlanFeatureInfo **)&ifeature);
155 ASSERT_EQ(rc, HDF_SUCCESS);
156 rc = g_wlanObj->getFeatureByIfName(g_wlanObj, ifeature->ifName, (struct WlanFeatureInfo **)&ifeature);
157 ASSERT_EQ(rc, HDF_SUCCESS);
158 rc = g_wlanObj->destroyFeature(g_wlanObj, (struct WlanFeatureInfo *)ifeature);
159 ASSERT_EQ(rc, HDF_SUCCESS);
160 }
161
162 /**
163 * @tc.name: GetAsscociatedStasTest_004
164 * @tc.desc: Wifi hdi get assoc stas function test
165 * @tc.type: FUNC
166 * @tc.require: AR000FRMJB
167 */
168 HWTEST_F(HdfWifiServiceCTest, GetAsscociatedStasTest_004, TestSize.Level1)
169 {
170 const int32_t wlan_type = PROTOCOL_80211_IFTYPE_AP;
171 struct WlanFeatureInfo *ifeature = nullptr;
172 struct StaInfo staInfo[WLAN_MAX_NUM_STA_WITH_AP] = {{0}};
173 uint32_t num = 0;
174
175 int32_t rc = g_wlanObj->createFeature(g_wlanObj, wlan_type, (struct WlanFeatureInfo **)&ifeature);
176 ASSERT_EQ(rc, HDF_SUCCESS);
177 rc = g_wlanObj->getAsscociatedStas(g_wlanObj, ifeature, staInfo, WLAN_MAX_NUM_STA_WITH_AP, &num);
178 ASSERT_EQ(rc, HDF_SUCCESS);
179 rc = g_wlanObj->destroyFeature(g_wlanObj, (struct WlanFeatureInfo *)ifeature);
180 ASSERT_EQ(rc, HDF_SUCCESS);
181 }
182
183 /**
184 * @tc.name: SetCountryCodeTest_005
185 * @tc.desc: Wifi hdi set country code function test
186 * @tc.type: FUNC
187 * @tc.require: AR000FRMJB
188 */
189 HWTEST_F(HdfWifiServiceCTest, SetCountryCodeTest_005, TestSize.Level1)
190 {
191 const char *code = "CN";
192 const int32_t wlan_type = PROTOCOL_80211_IFTYPE_AP;
193 struct WlanFeatureInfo *ifeature = nullptr;
194
195 int32_t rc = g_wlanObj->createFeature(g_wlanObj, wlan_type, (struct WlanFeatureInfo **)&ifeature);
196 ASSERT_EQ(rc, HDF_SUCCESS);
197 rc = g_wlanObj->setCountryCode(g_wlanObj, ifeature, code, sizeof(code));
198 ASSERT_EQ(rc, HDF_SUCCESS);
199 rc = g_wlanObj->destroyFeature(g_wlanObj, (struct WlanFeatureInfo *)ifeature);
200 ASSERT_EQ(rc, HDF_SUCCESS);
201 }
202
203 /**
204 * @tc.name: GetNetworkIfaceNameTest_006
205 * @tc.desc: Wifi hdi get network interface name function test
206 * @tc.type: FUNC
207 * @tc.require: AR000FRMJB
208 */
209 HWTEST_F(HdfWifiServiceCTest, GetNetworkIfaceNameTest_006, TestSize.Level1)
210 {
211 const int32_t wlan_type = PROTOCOL_80211_IFTYPE_AP;
212 struct WlanFeatureInfo *ifeature = nullptr;
213
214 int32_t rc = g_wlanObj->createFeature(g_wlanObj, wlan_type, (struct WlanFeatureInfo **)&ifeature);
215 ASSERT_EQ(rc, HDF_SUCCESS);
216 rc = g_wlanObj->getNetworkIfaceName(g_wlanObj, (struct WlanFeatureInfo *)ifeature);
217 ASSERT_EQ(rc, HDF_SUCCESS);
218 rc = g_wlanObj->destroyFeature(g_wlanObj, (struct WlanFeatureInfo *)ifeature);
219 ASSERT_EQ(rc, HDF_SUCCESS);
220 }
221
222 /**
223 * @tc.name: GetFeatureTypeTest_007
224 * @tc.desc: Wifi hdi get feature type function test
225 * @tc.type: FUNC
226 * @tc.require: AR000FRMJB
227 */
228 HWTEST_F(HdfWifiServiceCTest, GetFeatureTypeTest_007, TestSize.Level1)
229 {
230 const int32_t wlan_type = PROTOCOL_80211_IFTYPE_AP;
231 struct WlanFeatureInfo *ifeature = nullptr;
232
233 int32_t rc = g_wlanObj->createFeature(g_wlanObj, wlan_type, (struct WlanFeatureInfo **)&ifeature);
234 ASSERT_EQ(rc, HDF_SUCCESS);
235 rc = g_wlanObj->getFeatureType(g_wlanObj, (struct WlanFeatureInfo *)ifeature);
236 ASSERT_EQ(rc, HDF_SUCCESS);
237 rc = g_wlanObj->destroyFeature(g_wlanObj, (struct WlanFeatureInfo *)ifeature);
238 ASSERT_EQ(rc, HDF_SUCCESS);
239 }
240
241 /**
242 * @tc.name: SetMacAddressTest_008
243 * @tc.desc: Wifi hdi set mac addr function test
244 * @tc.type: FUNC
245 * @tc.require: AR000FRMJB
246 */
247 HWTEST_F(HdfWifiServiceCTest, SetMacAddressTest_008, TestSize.Level1)
248 {
249 uint8_t mac[ETH_ADDR_LEN] = {0x12, 0x34, 0x56, 0x78, 0xab, 0xcd};
250 const int32_t wlan_type = PROTOCOL_80211_IFTYPE_AP;
251 struct WlanFeatureInfo *ifeature = nullptr;
252
253 int32_t rc = g_wlanObj->createFeature(g_wlanObj, wlan_type, (struct WlanFeatureInfo **)&ifeature);
254 ASSERT_EQ(rc, HDF_SUCCESS);
255 rc = g_wlanObj->setMacAddress(g_wlanObj, (struct WlanFeatureInfo *)ifeature, mac, ETH_ADDR_LEN);
256 ASSERT_EQ(rc, HDF_SUCCESS);
257 rc = g_wlanObj->destroyFeature(g_wlanObj, (struct WlanFeatureInfo *)ifeature);
258 ASSERT_EQ(rc, HDF_SUCCESS);
259 }
260
261 /**
262 * @tc.name: GetDeviceMacAddressTest_009
263 * @tc.desc: Wifi hdi get device mac addr function test
264 * @tc.type: FUNC
265 * @tc.require: AR000FRMJB
266 */
267 HWTEST_F(HdfWifiServiceCTest, GetDeviceMacAddressTest_009, TestSize.Level1)
268 {
269 const int32_t wlan_type = PROTOCOL_80211_IFTYPE_AP;
270 struct WlanFeatureInfo *ifeature = nullptr;
271 uint8_t mac[ETH_ADDR_LEN] = {0};
272
273 int32_t rc = g_wlanObj->createFeature(g_wlanObj, wlan_type, (struct WlanFeatureInfo **)&ifeature);
274 ASSERT_EQ(rc, HDF_SUCCESS);
275 rc = g_wlanObj->getDeviceMacAddress(g_wlanObj, (struct WlanFeatureInfo *)ifeature, mac, ETH_ADDR_LEN);
276 ASSERT_EQ(rc, HDF_SUCCESS);
277 rc = g_wlanObj->destroyFeature(g_wlanObj, (struct WlanFeatureInfo *)ifeature);
278 ASSERT_EQ(rc, HDF_SUCCESS);
279 }
280
281 /**
282 * @tc.name: GetFreqsWithBandTest_010
283 * @tc.desc: Wifi hdi get freqs function test
284 * @tc.type: FUNC
285 * @tc.require: AR000FRMJB
286 */
287 HWTEST_F(HdfWifiServiceCTest, GetFreqsWithBandTest_010, TestSize.Level1)
288 {
289 const int32_t wlan_type = PROTOCOL_80211_IFTYPE_AP;
290 struct WlanFeatureInfo *ifeature = nullptr;
291 int32_t freq[WLAN_FREQ_MAX_NUM] = {0};
292 int32_t wlanBand = IEEE80211_BAND_2GHZ;
293 uint32_t count = 0;
294 int i;
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 if (rc == HDF_SUCCESS) {
302 printf("%s: count = %u\n", __func__, count);
303 for (i = 0; i < count; i++) {
304 printf("%s: freq[%d] = %d\n", __func__, i, freq[i]);
305 }
306 }
307
308 rc = g_wlanObj->destroyFeature(g_wlanObj, (struct WlanFeatureInfo *)ifeature);
309 ASSERT_EQ(rc, HDF_SUCCESS);
310 }
311
312 /**
313 * @tc.name: SetTxPowerTest_011
314 * @tc.desc: Wifi hdi set tx power function test
315 * @tc.type: FUNC
316 * @tc.require: AR000FRMJB
317 */
318 HWTEST_F(HdfWifiServiceCTest, SetTxPowerTest_011, TestSize.Level1)
319 {
320 const int32_t wlan_type = PROTOCOL_80211_IFTYPE_AP;
321 struct WlanFeatureInfo *ifeature = nullptr;
322 int32_t power = WLAN_TX_POWER;
323
324 int32_t rc = g_wlanObj->createFeature(g_wlanObj, wlan_type, (struct WlanFeatureInfo **)&ifeature);
325 ASSERT_EQ(rc, HDF_SUCCESS);
326 rc = g_wlanObj->setTxPower(g_wlanObj, (struct WlanFeatureInfo *)ifeature, power);
327 ASSERT_EQ(rc, HDF_SUCCESS);
328 rc = g_wlanObj->destroyFeature(g_wlanObj, (struct WlanFeatureInfo *)ifeature);
329 ASSERT_EQ(rc, HDF_SUCCESS);
330 }
331
332 /**
333 * @tc.name: GetChipIdTest_012
334 * @tc.desc: Wifi hdi get chip id function test
335 * @tc.type: FUNC
336 * @tc.require: AR000FRMJB
337 */
338 HWTEST_F(HdfWifiServiceCTest, GetChipIdTest_012, TestSize.Level1)
339 {
340 const int32_t wlan_type = PROTOCOL_80211_IFTYPE_STATION;
341 struct WlanFeatureInfo *ifeature = nullptr;
342 uint8_t chipId = 0;
343 unsigned int num = 0;
344 char *ifNames = nullptr;
345
346 int32_t rc = g_wlanObj->createFeature(g_wlanObj, wlan_type, (struct WlanFeatureInfo **)&ifeature);
347 ASSERT_EQ(rc, HDF_SUCCESS);
348 rc = g_wlanObj->getChipId(g_wlanObj, (struct WlanFeatureInfo *)ifeature, &chipId);
349 ASSERT_EQ(rc, HDF_SUCCESS);
350 rc = g_wlanObj->getIfNamesByChipId(g_wlanObj, chipId, &ifNames, &num);
351 printf("ifnames = %s\n", ifNames);
352 ASSERT_EQ(rc, HDF_SUCCESS);
353 rc = g_wlanObj->destroyFeature(g_wlanObj, (struct WlanFeatureInfo *)ifeature);
354 ASSERT_EQ(rc, HDF_SUCCESS);
355 }
356
357 /**
358 * @tc.name: SetScanningMacAddressTest_013
359 * @tc.desc: Wifi hdi set scanning mac addr function test
360 * @tc.type: FUNC
361 * @tc.require: AR000FRMJB
362 */
363 HWTEST_F(HdfWifiServiceCTest, SetScanningMacAddressTest_013, TestSize.Level1)
364 {
365 const int32_t wlan_type = PROTOCOL_80211_IFTYPE_STATION;
366 struct WlanFeatureInfo *ifeature = nullptr;
367 uint8_t scanMac[ETH_ADDR_LEN] = {0x12, 0x34, 0x56, 0x78, 0xab, 0xcd};
368
369 int32_t rc = g_wlanObj->createFeature(g_wlanObj, wlan_type, (struct WlanFeatureInfo **)&ifeature);
370 ASSERT_EQ(rc, HDF_SUCCESS);
371 rc = g_wlanObj->setScanningMacAddress(g_wlanObj, (struct WlanFeatureInfo *)ifeature, scanMac, ETH_ADDR_LEN);
372 ASSERT_NE(rc, HDF_FAILURE);
373 rc = g_wlanObj->destroyFeature(g_wlanObj, (struct WlanFeatureInfo *)ifeature);
374 ASSERT_EQ(rc, HDF_SUCCESS);
375 }
376
377 /**
378 * @tc.name: GetNetdevInfoTest_014
379 * @tc.desc: Wifi hdi get netdev info function test
380 * @tc.type: FUNC
381 * @tc.require: AR000FRMJB
382 */
383 HWTEST_F(HdfWifiServiceCTest, GetNetdevInfoTest_014, TestSize.Level1)
384 {
385 int32_t rc;
386 struct NetDeviceInfoResult netDeviceInfoResult;
387
388 (void)memset_s(&netDeviceInfoResult, sizeof(struct NetDeviceInfoResult), 0, sizeof(struct NetDeviceInfoResult));
389 rc = g_wlanObj->getNetDevInfo(g_wlanObj, (struct NetDeviceInfoResult *)&netDeviceInfoResult);
390 ASSERT_EQ(rc, HDF_SUCCESS);
391 }
392
393 /**
394 * @tc.name: RegisterEventCallbackTest_015
395 * @tc.desc: Wifi hdi reister event call back function test
396 * @tc.type: FUNC
397 * @tc.require: AR000FRMJB
398 */
399 HWTEST_F(HdfWifiServiceCTest, RegisterEventCallbackTest_015, TestSize.Level1)
400 {
401 int32_t rc = g_wlanObj->registerEventCallback(g_wlanObj, HalResetCallbackEvent);
402 ASSERT_EQ(rc, HDF_SUCCESS);
403 }
404
405 /**
406 * @tc.name: ResetDriverTest_016
407 * @tc.desc: Wifi hdi reset driver function test
408 * @tc.type: FUNC
409 * @tc.require: AR000FRMJB
410 */
411 HWTEST_F(HdfWifiServiceCTest, ResetDriverTest_016, TestSize.Level1)
412 {
413 int32_t wlan_type = PROTOCOL_80211_IFTYPE_STATION;
414 struct WlanFeatureInfo *ifeature = nullptr;
415 uint8_t chipId = 0;
416 int32_t rc;
417
418 rc = g_wlanObj->createFeature(g_wlanObj, wlan_type, (struct WlanFeatureInfo **)&ifeature);
419 ASSERT_EQ(rc, HDF_SUCCESS);
420 rc = g_wlanObj->getChipId(g_wlanObj, (struct WlanFeatureInfo *)ifeature, &chipId);
421 ASSERT_EQ(rc, HDF_SUCCESS);
422 rc = g_wlanObj->destroyFeature(g_wlanObj, (struct WlanFeatureInfo *)ifeature);
423 ASSERT_EQ(rc, HDF_SUCCESS);
424 rc = g_wlanObj->resetDriver(g_wlanObj, chipId);
425 ASSERT_EQ(rc, HDF_SUCCESS);
426 sleep(RESET_TIME);
427 }
428
429 /**
430 * @tc.name: StartScanTest_017
431 * @tc.desc: Wifi hdi start scan function test
432 * @tc.type: FUNC
433 * @tc.require: AR000FRMJB
434 */
435 HWTEST_F(HdfWifiServiceCTest, StartScanTest_017, TestSize.Level1)
436 {
437 int32_t rc;
438 const int32_t wlan_type = PROTOCOL_80211_IFTYPE_STATION;
439 struct WlanFeatureInfo *ifeature = nullptr;
440 WifiScan scan = {0};
441
442 rc = g_wlanObj->createFeature(g_wlanObj, wlan_type, (struct WlanFeatureInfo **)&ifeature);
443 ASSERT_EQ(rc, HDF_SUCCESS);
444 rc = g_wlanObj->startScan(g_wlanObj, (struct WlanFeatureInfo *)ifeature, &scan);
445 ASSERT_EQ(rc, HDF_SUCCESS);
446 rc = g_wlanObj->destroyFeature(g_wlanObj, (struct WlanFeatureInfo *)ifeature);
447 ASSERT_EQ(rc, HDF_SUCCESS);
448 sleep(10);
449 }
450
451 /**
452 * @tc.name: UnregisterEventCallbackTest_018
453 * @tc.desc: Wifi hdi unreister event call back function test
454 * @tc.type: FUNC
455 * @tc.require: AR000FRMJB
456 */
457 HWTEST_F(HdfWifiServiceCTest, UnregisterEventCallbackTest_018, TestSize.Level1)
458 {
459 int32_t rc = g_wlanObj->unregisterEventCallback(g_wlanObj);
460 ASSERT_EQ(rc, HDF_SUCCESS);
461 }
462 };