• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
1 /*
2  * Copyright (c) 2021-2022 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 #include <gtest/gtest.h>
16 #include <servmgr_hdi.h>
17 #include "v1_0/iwlan_interface.h"
18 #include "wlan_callback_impl.h"
19 #include "wlan_impl.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 const uint32_t MEAS_CHANNEL_TIME = 10;
31 
32 const char *WLAN_SERVICE_NAME = "wlan_interface_service";
33 
34 class HdfWifiServiceCTest : public testing::Test {
35 public:
36     static void SetUpTestCase();
37     static void TearDownTestCase();
38     void SetUp();
39     void TearDown();
40 };
41 
42 static struct IWlanInterface *g_wlanObj = nullptr;
43 struct IWlanCallback *g_wlanCallbackObj = nullptr;
SetUpTestCase()44 void HdfWifiServiceCTest::SetUpTestCase()
45 {
46     g_wlanObj = IWlanInterfaceGetInstance(WLAN_SERVICE_NAME, false);
47     g_wlanCallbackObj = WlanCallbackServiceGet();
48     ASSERT_TRUE(g_wlanObj != nullptr);
49     ASSERT_TRUE(g_wlanCallbackObj != nullptr);
50 }
51 
TearDownTestCase()52 void HdfWifiServiceCTest::TearDownTestCase()
53 {
54     IWlanInterfaceReleaseInstance(WLAN_SERVICE_NAME, g_wlanObj, false);
55     WlanCallbackServiceRelease(g_wlanCallbackObj);
56 }
57 
SetUp()58 void HdfWifiServiceCTest::SetUp()
59 {
60     int32_t rc = g_wlanObj->Start(g_wlanObj);
61     ASSERT_EQ(rc, HDF_SUCCESS);
62 }
63 
TearDown()64 void HdfWifiServiceCTest::TearDown()
65 {
66     int32_t rc = g_wlanObj->Stop(g_wlanObj);
67     ASSERT_EQ(rc, HDF_SUCCESS);
68 }
69 
70 /**
71  * @tc.name: GetSupportFeatureComboTest_001
72  * @tc.desc: Wifi hdi get support feature and combo function test
73  * @tc.type: FUNC
74  */
75 HWTEST_F(HdfWifiServiceCTest, GetSupportFeatureComboTest_001, Function | MediumTest | Level1)
76 {
77     uint8_t supType[PROTOCOL_80211_IFTYPE_NUM + 1] = {0};
78     uint32_t supTypeLen = PROTOCOL_80211_IFTYPE_NUM + 1;
79     uint64_t combo[DEFAULT_COMBO_SIZE] = {0};
80     uint32_t supTypeLenInvalid = 6;
81 
82     int32_t rc = g_wlanObj->GetSupportFeature(g_wlanObj, supType, &supTypeLenInvalid);
83     ASSERT_EQ(rc, HDF_ERR_INVALID_PARAM);
84     rc = g_wlanObj->GetSupportFeature(g_wlanObj, supType, &supTypeLen);
85     ASSERT_EQ(rc, HDF_SUCCESS);
86     rc = g_wlanObj->GetSupportCombo(g_wlanObj, combo);
87     ASSERT_NE(rc, HDF_FAILURE);
88 }
89 
90 /**
91  * @tc.name: CreateFeatureTest_002
92  * @tc.desc: Wifi hdi create feature function test
93  * @tc.type: FUNC
94  */
95 HWTEST_F(HdfWifiServiceCTest, CreateFeatureTest_002, Function | MediumTest | Level1)
96 {
97     struct HdfFeatureInfo ifeature;
98     const int32_t wlanType = PROTOCOL_80211_IFTYPE_AP;
99 
100     int32_t rc = g_wlanObj->CreateFeature(g_wlanObj, wlanType, &ifeature);
101     ASSERT_EQ(rc, HDF_SUCCESS);
102     printf("ifname = %s\n", ifeature.ifName);
103     printf("type = %d\n", ifeature.type);
104     rc = g_wlanObj->DestroyFeature(g_wlanObj, &ifeature);
105     ASSERT_EQ(rc, HDF_SUCCESS);
106 }
107 
108 /**
109  * @tc.name: GetFeatureByIfNameTest_003
110  * @tc.desc: Wifi hdi get feature by ifname function test
111  * @tc.type: FUNC
112  */
113 HWTEST_F(HdfWifiServiceCTest, GetFeatureByIfNameTest_003, Function | MediumTest | Level1)
114 {
115     const int32_t wlanType = PROTOCOL_80211_IFTYPE_AP;
116     struct HdfFeatureInfo ifeature;
117     const char *ifNameInvalid = "wlanTest";
118 
119     int32_t rc = g_wlanObj->CreateFeature(g_wlanObj, wlanType, &ifeature);
120     ASSERT_EQ(rc, HDF_SUCCESS);
121     rc = g_wlanObj->GetFeatureByIfName(g_wlanObj, ifNameInvalid, &ifeature);
122     ASSERT_NE(rc, HDF_SUCCESS);
123     rc = g_wlanObj->GetFeatureByIfName(g_wlanObj, ifeature.ifName, &ifeature);
124     ASSERT_EQ(rc, HDF_SUCCESS);
125     rc = g_wlanObj->DestroyFeature(g_wlanObj, &ifeature);
126     ASSERT_EQ(rc, HDF_SUCCESS);
127 }
128 
129 /**
130  * @tc.name: GetAssociatedStasTest_004
131  * @tc.desc: Wifi hdi get assoc stas function test
132  * @tc.type: FUNC
133  */
134 HWTEST_F(HdfWifiServiceCTest, GetAssociatedStasTest_004, Function | MediumTest | Level1)
135 {
136     const int32_t wlanType = PROTOCOL_80211_IFTYPE_AP;
137     struct HdfFeatureInfo ifeature;
138     struct HdfStaInfo staInfo[WLAN_MAX_NUM_STA_WITH_AP] = {{0}};
139     uint32_t staInfoLen = WLAN_MAX_NUM_STA_WITH_AP;
140     uint32_t num = 0;
141 
142     int32_t rc = g_wlanObj->CreateFeature(g_wlanObj, wlanType, &ifeature);
143     ASSERT_EQ(rc, HDF_SUCCESS);
144     rc = g_wlanObj->GetAssociatedStas(g_wlanObj, &ifeature, staInfo, &staInfoLen, &num);
145     ASSERT_EQ(rc, HDF_SUCCESS);
146     rc = g_wlanObj->DestroyFeature(g_wlanObj, &ifeature);
147     ASSERT_EQ(rc, HDF_SUCCESS);
148 }
149 
150 /**
151  * @tc.name: SetCountryCodeTest_005
152  * @tc.desc: Wifi hdi set country code function test
153  * @tc.type: FUNC
154  */
155 HWTEST_F(HdfWifiServiceCTest, SetCountryCodeTest_005, Function | MediumTest | Level1)
156 {
157     const char *code = "CN";
158     const int32_t wlanType = PROTOCOL_80211_IFTYPE_AP;
159     struct HdfFeatureInfo ifeature;
160     const char *codeDigital = "99";
161     uint32_t size = 2;
162 
163     int32_t rc = g_wlanObj->CreateFeature(g_wlanObj, wlanType, &ifeature);
164     ASSERT_EQ(rc, HDF_SUCCESS);
165     rc = g_wlanObj->SetCountryCode(g_wlanObj, &ifeature, codeDigital, size);
166     bool flag = (rc == HDF_SUCCESS || rc == HDF_ERR_NOT_SUPPORT);
167     ASSERT_TRUE(flag);
168     rc = g_wlanObj->SetCountryCode(g_wlanObj, &ifeature, code, size);
169     ASSERT_EQ(rc, HDF_SUCCESS);
170     rc = g_wlanObj->DestroyFeature(g_wlanObj, &ifeature);
171     ASSERT_EQ(rc, HDF_SUCCESS);
172 }
173 
174 /**
175  * @tc.name: GetNetworkIfaceNameTest_006
176  * @tc.desc: Wifi hdi get network interface name function test
177  * @tc.type: FUNC
178  */
179 HWTEST_F(HdfWifiServiceCTest, GetNetworkIfaceNameTest_006, Function | MediumTest | Level1)
180 {
181     const int32_t wlanType = PROTOCOL_80211_IFTYPE_AP;
182     struct HdfFeatureInfo ifeature;
183     char ifNames[IFNAMSIZ] = {0};
184 
185     int32_t rc = g_wlanObj->CreateFeature(g_wlanObj, wlanType, &ifeature);
186     ASSERT_EQ(rc, HDF_SUCCESS);
187     rc = g_wlanObj->GetNetworkIfaceName(g_wlanObj, &ifeature, ifNames, IFNAMSIZ);
188     ASSERT_EQ(rc, HDF_SUCCESS);
189     rc = g_wlanObj->DestroyFeature(g_wlanObj, &ifeature);
190     ASSERT_EQ(rc, HDF_SUCCESS);
191 }
192 
193 /**
194  * @tc.name: GetFeatureTypeTest_007
195  * @tc.desc: Wifi hdi get feature type function test
196  * @tc.type: FUNC
197  */
198 HWTEST_F(HdfWifiServiceCTest, GetFeatureTypeTest_007, Function | MediumTest | Level1)
199 {
200     const int32_t wlanType = PROTOCOL_80211_IFTYPE_AP;
201     struct HdfFeatureInfo ifeature;
202     int32_t featureType;
203 
204     int32_t rc = g_wlanObj->CreateFeature(g_wlanObj, wlanType, &ifeature);
205     ASSERT_EQ(rc, HDF_SUCCESS);
206     rc = g_wlanObj->GetFeatureType(g_wlanObj, &ifeature, &featureType);
207     ASSERT_EQ(rc, HDF_SUCCESS);
208     rc = g_wlanObj->DestroyFeature(g_wlanObj, &ifeature);
209     ASSERT_EQ(rc, HDF_SUCCESS);
210 }
211 
212 /**
213  * @tc.name: SetMacAddressTest_008
214  * @tc.desc: Wifi hdi set mac addr function test
215  * @tc.type: FUNC
216  */
217 HWTEST_F(HdfWifiServiceCTest, SetMacAddressTest_008, Function | MediumTest | Level1)
218 {
219     uint8_t mac[ETH_ADDR_LEN] = {0x12, 0x34, 0x56, 0x78, 0xab, 0xcd};
220     const int32_t wlanType = PROTOCOL_80211_IFTYPE_AP;
221     struct HdfFeatureInfo ifeature;
222     uint32_t macLen = ETH_ADDR_LEN;
223     uint8_t errorMac[ETH_ADDR_LEN] = {0x11, 0x34, 0x56, 0x78, 0xab, 0xcd};
224 
225     int32_t rc = g_wlanObj->CreateFeature(g_wlanObj, wlanType, &ifeature);
226     ASSERT_EQ(rc, HDF_SUCCESS);
227     rc = g_wlanObj->SetMacAddress(g_wlanObj, &ifeature, errorMac, macLen);
228     ASSERT_NE(rc, HDF_SUCCESS);
229     rc = g_wlanObj->SetMacAddress(g_wlanObj, &ifeature, mac, macLen);
230     bool flag = (rc == HDF_SUCCESS || rc == HDF_ERR_NOT_SUPPORT || rc == HDF_ERR_DEVICE_BUSY);
231     ASSERT_TRUE(flag);
232     rc = g_wlanObj->DestroyFeature(g_wlanObj, &ifeature);
233     ASSERT_EQ(rc, HDF_SUCCESS);
234 }
235 
236 /**
237  * @tc.name: GetDeviceMacAddressTest_009
238  * @tc.desc: Wifi hdi get device mac addr function test
239  * @tc.type: FUNC
240  */
241 HWTEST_F(HdfWifiServiceCTest, GetDeviceMacAddressTest_009, Function | MediumTest | Level1)
242 {
243     const int32_t wlanType = PROTOCOL_80211_IFTYPE_AP;
244     struct HdfFeatureInfo ifeature;
245     uint8_t mac[ETH_ADDR_LEN] = {0};
246     uint32_t macLen = ETH_ADDR_LEN;
247 
248     int32_t rc = g_wlanObj->CreateFeature(g_wlanObj, wlanType, &ifeature);
249     ASSERT_EQ(rc, HDF_SUCCESS);
250     rc = g_wlanObj->GetDeviceMacAddress(g_wlanObj, &ifeature, mac, &macLen, ETH_ADDR_LEN);
251     ASSERT_EQ(rc, HDF_SUCCESS);
252     rc = g_wlanObj->DestroyFeature(g_wlanObj, &ifeature);
253     ASSERT_EQ(rc, HDF_SUCCESS);
254 }
255 
256 /**
257  * @tc.name: GetFreqsWithBandTest_010
258  * @tc.desc: Wifi hdi get freqs function test
259  * @tc.type: FUNC
260  */
261 HWTEST_F(HdfWifiServiceCTest, GetFreqsWithBandTest_010, Function | MediumTest | Level1)
262 {
263     const int32_t wlanType = PROTOCOL_80211_IFTYPE_AP;
264     struct HdfFeatureInfo ifeature;
265     struct HdfWifiInfo wifiInfo;
266     int32_t freq[WLAN_FREQ_MAX_NUM] = {0};
267     uint32_t freqLen = WLAN_FREQ_MAX_NUM ;
268     wifiInfo.band = IEEE80211_BAND_2GHZ;
269     wifiInfo.size = WLAN_FREQ_MAX_NUM;
270     struct HdfWifiInfo wifiInfoInvalid;
271     wifiInfoInvalid.band = IEEE80211_NUM_BANDS;
272     wifiInfoInvalid.size = WLAN_FREQ_MAX_NUM;
273     uint32_t i;
274 
275     int32_t rc = g_wlanObj->CreateFeature(g_wlanObj, wlanType, &ifeature);
276     ASSERT_EQ(rc, HDF_SUCCESS);
277     rc = g_wlanObj->GetFreqsWithBand(g_wlanObj, &ifeature, &wifiInfoInvalid, freq, &freqLen);
278     ASSERT_NE(rc, HDF_SUCCESS);
279     rc = g_wlanObj->GetFreqsWithBand(g_wlanObj, &ifeature, &wifiInfo, freq, &freqLen);
280     ASSERT_EQ(rc, HDF_SUCCESS);
281     if (rc == HDF_SUCCESS) {
282         for (i = 0; i < freqLen; i++) {
283             printf("%s: freq[%d] = %d\n", __func__, i, freq[i]);
284         }
285     }
286 
287     rc = g_wlanObj->DestroyFeature(g_wlanObj, &ifeature);
288     ASSERT_EQ(rc, HDF_SUCCESS);
289 }
290 
291 /**
292  * @tc.name: SetTxPowerTest_011
293  * @tc.desc: Wifi hdi set tx power function test
294  * @tc.type: FUNC
295  */
296 HWTEST_F(HdfWifiServiceCTest, SetTxPowerTest_011, Function | MediumTest | Level1)
297 {
298     const int32_t wlanType = PROTOCOL_80211_IFTYPE_AP;
299     struct HdfFeatureInfo ifeature;
300     int32_t power = WLAN_TX_POWER;
301 
302     int32_t rc = g_wlanObj->CreateFeature(g_wlanObj, wlanType, &ifeature);
303     ASSERT_EQ(rc, HDF_SUCCESS);
304     rc = g_wlanObj->SetTxPower(g_wlanObj, &ifeature, power);
305     ASSERT_EQ(rc, HDF_SUCCESS);
306     rc = g_wlanObj->DestroyFeature(g_wlanObj, &ifeature);
307     ASSERT_EQ(rc, HDF_SUCCESS);
308 }
309 
310 /**
311  * @tc.name: GetChipIdTest_012
312  * @tc.desc: Wifi hdi get chip id function test
313  * @tc.type: FUNC
314  */
315 HWTEST_F(HdfWifiServiceCTest, GetChipIdTest_012, Function | MediumTest | Level1)
316 {
317     const int32_t wlanType = PROTOCOL_80211_IFTYPE_STATION;
318     struct HdfFeatureInfo ifeature;
319     uint8_t chipId = 0;
320     uint8_t chipIdInvalid = 100;
321     unsigned int num = 0;
322     char ifNames[IFNAMSIZ] = {0};
323 
324     int32_t rc = g_wlanObj->CreateFeature(g_wlanObj, wlanType, &ifeature);
325     ASSERT_EQ(rc, HDF_SUCCESS);
326     rc = g_wlanObj->GetChipId(g_wlanObj, &ifeature, &chipId);
327     ASSERT_EQ(rc, HDF_SUCCESS);
328     rc = g_wlanObj->GetIfNamesByChipId(g_wlanObj, chipIdInvalid, ifNames, IFNAMSIZ, &num);
329     ASSERT_NE(rc, HDF_SUCCESS);
330     rc = g_wlanObj->GetIfNamesByChipId(g_wlanObj, chipId, ifNames, IFNAMSIZ, &num);
331     printf("ifnames = %s\n", ifNames);
332     ASSERT_EQ(rc, HDF_SUCCESS);
333     rc = g_wlanObj->DestroyFeature(g_wlanObj, &ifeature);
334     ASSERT_EQ(rc, HDF_SUCCESS);
335 }
336 
337 /**
338  * @tc.name: SetScanningMacAddressTest_013
339  * @tc.desc: Wifi hdi set scanning mac addr function test
340  * @tc.type: FUNC
341  */
342 HWTEST_F(HdfWifiServiceCTest, SetScanningMacAddressTest_013, Function | MediumTest | Level1)
343 {
344     const int32_t wlanType = PROTOCOL_80211_IFTYPE_STATION;
345     struct HdfFeatureInfo ifeature;
346     uint8_t scanMac[ETH_ADDR_LEN] = {0x12, 0x34, 0x56, 0x78, 0xab, 0xcd};
347     uint32_t macLen = ETH_ADDR_LEN;
348 
349     int32_t rc = g_wlanObj->CreateFeature(g_wlanObj, wlanType, &ifeature);
350     ASSERT_EQ(rc, HDF_SUCCESS);
351     rc = g_wlanObj->SetScanningMacAddress(g_wlanObj, &ifeature, scanMac, macLen);
352     ASSERT_NE(rc, HDF_FAILURE);
353     rc = g_wlanObj->DestroyFeature(g_wlanObj, &ifeature);
354     ASSERT_EQ(rc, HDF_SUCCESS);
355 }
356 
357 /**
358  * @tc.name: GetNetdevInfoTest_014
359  * @tc.desc: Wifi hdi get netdev info function test
360  * @tc.type: FUNC
361  */
362 HWTEST_F(HdfWifiServiceCTest, GetNetdevInfoTest_014, Function | MediumTest | Level1)
363 {
364     int32_t rc;
365     struct HdfNetDeviceInfoResult netDeviceInfoResult;
366 
367     (void)memset_s(
368         &netDeviceInfoResult, sizeof(struct HdfNetDeviceInfoResult), 0, sizeof(struct HdfNetDeviceInfoResult));
369     rc = g_wlanObj->GetNetDevInfo(g_wlanObj, (struct HdfNetDeviceInfoResult *)&netDeviceInfoResult);
370     ASSERT_EQ(rc, HDF_SUCCESS);
371 }
372 
373 /**
374  * @tc.name: GetPowerModeTest_015
375  * @tc.desc: Wifi hdi get power mode function test
376  * @tc.type: FUNC
377  */
378 HWTEST_F(HdfWifiServiceCTest, GetPowerModeTest_015, Function | MediumTest | Level1)
379 {
380     struct HdfFeatureInfo ifeature;
381     uint8_t mode = 0;
382 
383     int32_t rc = g_wlanObj->CreateFeature(g_wlanObj, PROTOCOL_80211_IFTYPE_AP, &ifeature);
384     ASSERT_EQ(rc, HDF_SUCCESS);
385     rc = g_wlanObj->GetPowerMode(g_wlanObj, &ifeature, &mode);
386     bool flag = (rc == HDF_SUCCESS || rc == HDF_ERR_NOT_SUPPORT);
387     ASSERT_TRUE(flag);
388     printf("mode = 0x%02x\n", mode);
389     rc = g_wlanObj->DestroyFeature(g_wlanObj, &ifeature);
390     ASSERT_EQ(rc, HDF_SUCCESS);
391 }
392 
393 /**
394  * @tc.name: SetPowerModeTest_016
395  * @tc.desc: Wifi hdi set power mode function test
396  * @tc.type: FUNC
397  */
398 HWTEST_F(HdfWifiServiceCTest, SetPowerModeTest_016, Function | MediumTest | Level1)
399 {
400     struct HdfFeatureInfo ifeature;
401     uint8_t mode = WIFI_POWER_MODE_SLEEPING;
402 
403     int32_t rc = g_wlanObj->CreateFeature(g_wlanObj, PROTOCOL_80211_IFTYPE_AP, &ifeature);
404     ASSERT_EQ(rc, HDF_SUCCESS);
405     rc = g_wlanObj->SetPowerMode(g_wlanObj, &ifeature, mode);
406     bool flag = (rc == HDF_SUCCESS || rc == HDF_ERR_NOT_SUPPORT);
407     ASSERT_TRUE(flag);
408     rc = g_wlanObj->DestroyFeature(g_wlanObj, &ifeature);
409     ASSERT_EQ(rc, HDF_SUCCESS);
410 }
411 
412 /**
413  * @tc.name: RegisterEventCallbackTest_017
414  * @tc.desc: Wifi hdi register event call back function test
415  * @tc.type: FUNC
416  */
417 HWTEST_F(HdfWifiServiceCTest, RegisterEventCallbackTest_017, Function | MediumTest | Level1)
418 {
419     const char *ifName = "wlan0";
420     int32_t rc = g_wlanObj->RegisterEventCallback(g_wlanObj, g_wlanCallbackObj, ifName);
421     ASSERT_EQ(rc, HDF_SUCCESS);
422 }
423 
424 /**
425  * @tc.name: ResetDriverTest_018
426  * @tc.desc: Wifi hdi reset driver function test
427  * @tc.type: FUNC
428  */
429 HWTEST_F(HdfWifiServiceCTest, ResetDriverTest_018, Function | MediumTest | Level1)
430 {
431     int32_t wlanType = PROTOCOL_80211_IFTYPE_STATION;
432     struct HdfFeatureInfo ifeature;
433     const char *ifName = "wlan0";
434     uint8_t chipId = 0;
435     int32_t rc;
436 
437     rc = g_wlanObj->CreateFeature(g_wlanObj, wlanType, &ifeature);
438     ASSERT_EQ(rc, HDF_SUCCESS);
439     rc = g_wlanObj->GetChipId(g_wlanObj, &ifeature, &chipId);
440     ASSERT_EQ(rc, HDF_SUCCESS);
441     rc = g_wlanObj->DestroyFeature(g_wlanObj, &ifeature);
442     ASSERT_EQ(rc, HDF_SUCCESS);
443     rc = g_wlanObj->ResetDriver(g_wlanObj, chipId, ifName);
444     ASSERT_EQ(rc, HDF_SUCCESS);
445     sleep(RESET_TIME);
446 }
447 
448 /**
449  * @tc.name: StartScanTest_019
450  * @tc.desc: Wifi hdi start scan function test
451  * @tc.type: FUNC
452  */
453 HWTEST_F(HdfWifiServiceCTest, StartScanTest_019, Function | MediumTest | Level1)
454 {
455     int32_t rc;
456     const int32_t wlanType = PROTOCOL_80211_IFTYPE_STATION;
457     struct HdfFeatureInfo ifeature;
458     struct HdfWifiScan scan = {0};
459 
460     rc = g_wlanObj->CreateFeature(g_wlanObj, wlanType, &ifeature);
461     ASSERT_EQ(rc, HDF_SUCCESS);
462     rc = g_wlanObj->StartScan(g_wlanObj, &ifeature, &scan);
463     ASSERT_EQ(rc, HDF_SUCCESS);
464     rc = g_wlanObj->DestroyFeature(g_wlanObj, &ifeature);
465     ASSERT_EQ(rc, HDF_SUCCESS);
466     sleep(10);
467 }
468 
469 /**
470  * @tc.name: UnregisterEventCallbackTest_020
471  * @tc.desc: Wifi hdi unreister event call back function test
472  * @tc.type: FUNC
473  */
474 HWTEST_F(HdfWifiServiceCTest, UnregisterEventCallbackTest_020, Function | MediumTest | Level1)
475 {
476     const char *ifName = "wlan0";
477     int32_t rc = g_wlanObj->UnregisterEventCallback(g_wlanObj, g_wlanCallbackObj, ifName);
478     ASSERT_EQ(rc, HDF_SUCCESS);
479 }
480 /**
481  * @tc.name: CreateFeatureTest_021
482  * @tc.desc: Wifi hdi create feature function test
483  * @tc.type: FUNC
484  */
485 HWTEST_F(HdfWifiServiceCTest, CreateFeatureTest_021, Function | MediumTest | Level1)
486 {
487     struct HdfFeatureInfo ifeature;
488     const int32_t wlanType = PROTOCOL_80211_IFTYPE_STATION;
489     int32_t wlanTypeInvalid = PROTOCOL_80211_IFTYPE_NUM;
490 
491     int32_t rc = g_wlanObj->CreateFeature(g_wlanObj, wlanTypeInvalid, &ifeature);
492     ASSERT_EQ(rc, HDF_FAILURE);
493     rc = g_wlanObj->CreateFeature(g_wlanObj, wlanType, &ifeature);
494     ASSERT_EQ(rc, HDF_SUCCESS);
495     printf("ifname = %s\n", ifeature.ifName);
496     printf("type = %d\n", ifeature.type);
497     rc = g_wlanObj->DestroyFeature(g_wlanObj, &ifeature);
498     ASSERT_EQ(rc, HDF_SUCCESS);
499 }
500 
501 /**
502  * @tc.name: GetChipIdTest_022
503  * @tc.desc: Wifi hdi get chip id function test
504  * @tc.type: FUNC
505  */
506 HWTEST_F(HdfWifiServiceCTest, GetChipIdTest_022, Function | MediumTest | Level1)
507 {
508     const int32_t wlanType = PROTOCOL_80211_IFTYPE_AP;
509     struct HdfFeatureInfo ifeature;
510     uint8_t chipId = 0;
511 
512     int32_t rc = g_wlanObj->CreateFeature(g_wlanObj, wlanType, &ifeature);
513     ASSERT_EQ(rc, HDF_SUCCESS);
514     rc = g_wlanObj->GetChipId(g_wlanObj, &ifeature, &chipId);
515     ASSERT_EQ(rc, HDF_SUCCESS);
516     rc = g_wlanObj->DestroyFeature(g_wlanObj, &ifeature);
517     ASSERT_EQ(rc, HDF_SUCCESS);
518 }
519 
520 /**
521  * @tc.name: GetDeviceMacAddressTest_023
522  * @tc.desc: Wifi hdi get device mac addr function test
523  * @tc.type: FUNC
524  */
525 HWTEST_F(HdfWifiServiceCTest, GetDeviceMacAddressTest_023, Function | MediumTest | Level1)
526 {
527     const int32_t wlanType = PROTOCOL_80211_IFTYPE_STATION;
528     struct HdfFeatureInfo ifeature;
529     uint8_t mac[ETH_ADDR_LEN] = {0};
530     uint32_t macLen = ETH_ADDR_LEN;
531 
532     int32_t rc = g_wlanObj->CreateFeature(g_wlanObj, wlanType, &ifeature);
533     ASSERT_EQ(rc, HDF_SUCCESS);
534     rc = g_wlanObj->GetDeviceMacAddress(g_wlanObj, &ifeature, mac, &macLen, ETH_ADDR_LEN);
535     ASSERT_EQ(rc, HDF_SUCCESS);
536     rc = g_wlanObj->DestroyFeature(g_wlanObj, &ifeature);
537     ASSERT_EQ(rc, HDF_SUCCESS);
538 }
539 
540 /**
541  * @tc.name: GetFeatureByIfNameTest_024
542  * @tc.desc: Wifi hdi get feature by ifname function test
543  * @tc.type: FUNC
544  */
545 HWTEST_F(HdfWifiServiceCTest, GetFeatureByIfNameTest_024, Function | MediumTest | Level1)
546 {
547     const int32_t wlanType = PROTOCOL_80211_IFTYPE_STATION;
548     struct HdfFeatureInfo ifeature;
549     const char *ifNameInvalid = "wlanTest";
550 
551     int32_t rc = g_wlanObj->CreateFeature(g_wlanObj, wlanType, &ifeature);
552     ASSERT_EQ(rc, HDF_SUCCESS);
553     rc = g_wlanObj->GetFeatureByIfName(g_wlanObj, ifNameInvalid, &ifeature);
554     ASSERT_NE(rc, HDF_SUCCESS);
555     rc = g_wlanObj->GetFeatureByIfName(g_wlanObj, ifeature.ifName, &ifeature);
556     ASSERT_EQ(rc, HDF_SUCCESS);
557     rc = g_wlanObj->DestroyFeature(g_wlanObj, &ifeature);
558     ASSERT_EQ(rc, HDF_SUCCESS);
559 }
560 
561 /**
562  * @tc.name: SetMacAddressTest_025
563  * @tc.desc: Wifi hdi set mac addr function test
564  * @tc.type: FUNC
565  */
566 HWTEST_F(HdfWifiServiceCTest, SetMacAddressTest_025, Function | MediumTest | Level1)
567 {
568     uint8_t mac[ETH_ADDR_LEN] = {0x12, 0x34, 0x56, 0x78, 0xab, 0xcd};
569     const int32_t wlanType = PROTOCOL_80211_IFTYPE_STATION;
570     struct HdfFeatureInfo ifeature;
571     uint32_t macLen = ETH_ADDR_LEN;
572     uint8_t errorMac[ETH_ADDR_LEN] = {0x11, 0x34, 0x56, 0x78, 0xab, 0xcd};
573 
574     int32_t rc = g_wlanObj->CreateFeature(g_wlanObj, wlanType, &ifeature);
575     ASSERT_EQ(rc, HDF_SUCCESS);
576     rc = g_wlanObj->SetMacAddress(g_wlanObj, &ifeature, errorMac, macLen);
577     ASSERT_NE(rc, HDF_SUCCESS);
578     rc = g_wlanObj->SetMacAddress(g_wlanObj, &ifeature, mac, macLen);
579     bool flag = (rc == HDF_SUCCESS || rc == HDF_ERR_NOT_SUPPORT || rc == HDF_ERR_DEVICE_BUSY);
580     ASSERT_TRUE(flag);
581     rc = g_wlanObj->DestroyFeature(g_wlanObj, &ifeature);
582     ASSERT_EQ(rc, HDF_SUCCESS);
583 }
584 
585 /**
586  * @tc.name: GetPowerModeTest_026
587  * @tc.desc: Wifi hdi get power mode function test
588  * @tc.type: FUNC
589  */
590 HWTEST_F(HdfWifiServiceCTest, GetPowerModeTest_026, Function | MediumTest | Level1)
591 {
592     struct HdfFeatureInfo ifeature;
593     uint8_t mode = 0;
594 
595     int32_t rc = g_wlanObj->CreateFeature(g_wlanObj, PROTOCOL_80211_IFTYPE_STATION, &ifeature);
596     ASSERT_EQ(rc, HDF_SUCCESS);
597     rc = g_wlanObj->GetPowerMode(g_wlanObj, &ifeature, &mode);
598     bool flag = (rc == HDF_SUCCESS || rc == HDF_ERR_NOT_SUPPORT);
599     ASSERT_TRUE(flag);
600     rc = g_wlanObj->DestroyFeature(g_wlanObj, &ifeature);
601     ASSERT_EQ(rc, HDF_SUCCESS);
602 }
603 
604 /**
605  * @tc.name: SetPowerModeTest_027
606  * @tc.desc: Wifi hdi set power mode function test
607  * @tc.type: FUNC
608  */
609 HWTEST_F(HdfWifiServiceCTest, SetPowerModeTest_027, Function | MediumTest | Level1)
610 {
611     struct HdfFeatureInfo ifeature;
612     uint8_t mode = WIFI_POWER_MODE_GENERAL;
613 
614     int32_t rc = g_wlanObj->CreateFeature(g_wlanObj, PROTOCOL_80211_IFTYPE_AP, &ifeature);
615     ASSERT_EQ(rc, HDF_SUCCESS);
616     rc = g_wlanObj->SetPowerMode(g_wlanObj, &ifeature, mode);
617     bool flag = (rc == HDF_SUCCESS || rc == HDF_ERR_NOT_SUPPORT);
618     ASSERT_TRUE(flag);
619     rc = g_wlanObj->DestroyFeature(g_wlanObj, &ifeature);
620     ASSERT_EQ(rc, HDF_SUCCESS);
621 }
622 
623 /**
624  * @tc.name: SetPowerModeTest_028
625  * @tc.desc: Wifi hdi set power mode function test
626  * @tc.type: FUNC
627  */
628 HWTEST_F(HdfWifiServiceCTest, SetPowerModeTest_028, Function | MediumTest | Level1)
629 {
630     struct HdfFeatureInfo ifeature;
631     uint8_t mode = WIFI_POWER_MODE_THROUGH_WALL;
632 
633     int32_t rc = g_wlanObj->CreateFeature(g_wlanObj, PROTOCOL_80211_IFTYPE_AP, &ifeature);
634     ASSERT_EQ(rc, HDF_SUCCESS);
635     rc = g_wlanObj->SetPowerMode(g_wlanObj, &ifeature, mode);
636     bool flag = (rc == HDF_SUCCESS || rc == HDF_ERR_NOT_SUPPORT);
637     ASSERT_TRUE(flag);
638     rc = g_wlanObj->DestroyFeature(g_wlanObj, &ifeature);
639     ASSERT_EQ(rc, HDF_SUCCESS);
640 }
641 
642 /**
643  * @tc.name: SetPowerModeTest_029
644  * @tc.desc: Wifi hdi set power mode function test
645  * @tc.type: FUNC
646  */
647 HWTEST_F(HdfWifiServiceCTest, SetPowerModeTest_029, Function | MediumTest | Level1)
648 {
649     struct HdfFeatureInfo ifeature;
650     uint8_t mode = WIFI_POWER_MODE_NUM;
651 
652     int32_t rc = g_wlanObj->CreateFeature(g_wlanObj, PROTOCOL_80211_IFTYPE_AP, &ifeature);
653     ASSERT_EQ(rc, HDF_SUCCESS);
654     rc = g_wlanObj->SetPowerMode(g_wlanObj, &ifeature, mode);
655     ASSERT_NE(rc, HDF_SUCCESS);
656     rc = g_wlanObj->DestroyFeature(g_wlanObj, &ifeature);
657     ASSERT_EQ(rc, HDF_SUCCESS);
658 }
659 
660 /**
661  * @tc.name: SetPowerModeTest_30
662  * @tc.desc: Wifi hdi set power mode function test
663  * @tc.type: FUNC
664  */
665 HWTEST_F(HdfWifiServiceCTest, SetPowerModeTest_030, Function | MediumTest | Level1)
666 {
667     struct HdfFeatureInfo ifeature;
668     uint8_t mode = WIFI_POWER_MODE_SLEEPING;
669 
670     int32_t rc = g_wlanObj->CreateFeature(g_wlanObj, PROTOCOL_80211_IFTYPE_STATION, &ifeature);
671     ASSERT_EQ(rc, HDF_SUCCESS);
672     rc = g_wlanObj->SetPowerMode(g_wlanObj, &ifeature, mode);
673     bool flag = (rc == HDF_SUCCESS || rc == HDF_ERR_NOT_SUPPORT);
674     ASSERT_TRUE(flag);
675     rc = g_wlanObj->DestroyFeature(g_wlanObj, &ifeature);
676     ASSERT_EQ(rc, HDF_SUCCESS);
677 }
678 
679 /**
680  * @tc.name: SetPowerModeTest_031
681  * @tc.desc: Wifi hdi set power mode function test
682  * @tc.type: FUNC
683  */
684 HWTEST_F(HdfWifiServiceCTest, SetPowerModeTest_031, Function | MediumTest | Level1)
685 {
686     struct HdfFeatureInfo ifeature;
687     uint8_t mode = WIFI_POWER_MODE_GENERAL;
688 
689     int32_t rc = g_wlanObj->CreateFeature(g_wlanObj, PROTOCOL_80211_IFTYPE_STATION, &ifeature);
690     ASSERT_EQ(rc, HDF_SUCCESS);
691     rc = g_wlanObj->SetPowerMode(g_wlanObj, &ifeature, mode);
692     bool flag = (rc == HDF_SUCCESS || rc == HDF_ERR_NOT_SUPPORT);
693     ASSERT_TRUE(flag);
694     rc = g_wlanObj->DestroyFeature(g_wlanObj, &ifeature);
695     ASSERT_EQ(rc, HDF_SUCCESS);
696 }
697 
698 /**
699  * @tc.name: SetPowerModeTest_032
700  * @tc.desc: Wifi hdi set power mode function test
701  * @tc.type: FUNC
702  */
703 HWTEST_F(HdfWifiServiceCTest, SetPowerModeTest_032, Function | MediumTest | Level1)
704 {
705     struct HdfFeatureInfo ifeature;
706     uint8_t mode = WIFI_POWER_MODE_THROUGH_WALL;
707 
708     int32_t rc = g_wlanObj->CreateFeature(g_wlanObj, PROTOCOL_80211_IFTYPE_STATION, &ifeature);
709     ASSERT_EQ(rc, HDF_SUCCESS);
710     rc = g_wlanObj->SetPowerMode(g_wlanObj, &ifeature, mode);
711     bool flag = (rc == HDF_SUCCESS || rc == HDF_ERR_NOT_SUPPORT);
712     ASSERT_TRUE(flag);
713     rc = g_wlanObj->DestroyFeature(g_wlanObj, &ifeature);
714     ASSERT_EQ(rc, HDF_SUCCESS);
715 }
716 
717 /**
718  * @tc.name: SetPowerModeTest_033
719  * @tc.desc: Wifi hdi set power mode function test
720  * @tc.type: FUNC
721  */
722 HWTEST_F(HdfWifiServiceCTest, SetPowerModeTest_033, Function | MediumTest | Level1)
723 {
724     struct HdfFeatureInfo ifeature;
725     uint8_t mode = WIFI_POWER_MODE_NUM;
726 
727     int32_t rc = g_wlanObj->CreateFeature(g_wlanObj, PROTOCOL_80211_IFTYPE_STATION, &ifeature);
728     ASSERT_EQ(rc, HDF_SUCCESS);
729     rc = g_wlanObj->SetPowerMode(g_wlanObj, &ifeature, mode);
730     ASSERT_NE(rc, HDF_SUCCESS);
731     rc = g_wlanObj->DestroyFeature(g_wlanObj, &ifeature);
732     ASSERT_EQ(rc, HDF_SUCCESS);
733 }
734 
735 /**
736  * @tc.name: StartChannelMeasTest_034
737  * @tc.desc: Wifi hdi start channel meas and get meas result function test
738  * @tc.type: FUNC
739  */
740 HWTEST_F(HdfWifiServiceCTest, StartChannelMeasTest_034, Function | MediumTest | Level1)
741 {
742     const char *ifName = "wlan0";
743     struct MeasChannelParam measChannelParam;
744     struct MeasChannelResult measChannelResult = {0};
745 
746     measChannelParam.channelId = 1;
747     measChannelParam.measTime = 15;
748     int32_t rc = g_wlanObj->StartChannelMeas(g_wlanObj, ifName, &measChannelParam);
749     bool flag = (rc == HDF_SUCCESS || rc == HDF_ERR_NOT_SUPPORT);
750     ASSERT_TRUE(flag);
751     sleep(MEAS_CHANNEL_TIME);
752     rc = g_wlanObj->GetChannelMeasResult(g_wlanObj, ifName, &measChannelResult);
753     flag = (rc == HDF_SUCCESS || rc == HDF_ERR_NOT_SUPPORT || rc == HDF_DEV_ERR_NODATA);
754     ASSERT_TRUE(flag);
755 }
756 
757 /**
758  * @tc.name: SetProjectionScreenParam_035
759  * @tc.desc: Wifi hdi set paramters to optimize projectino screen function test
760  * @tc.type: FUNC
761  */
762 HWTEST_F(HdfWifiServiceCTest, SetProjectionScreenParam_035, Function | MediumTest | Level1)
763 {
764     const char *ifName = "wlan0";
765     int32_t rc;
766     struct ProjectionScreenCmdParam param;
767     int8_t data = 0;
768     param.buf = &data;
769     param.bufLen = sizeof(data);
770 
771     for (int i = CMD_CLOSE_GO_CAC; i <= CMD_ID_CTRL_ROAM_CHANNEL; i++) {
772         param.cmdId = i;
773         rc = g_wlanObj->SetProjectionScreenParam(g_wlanObj, ifName, &param);
774         bool flag = (rc == HDF_SUCCESS || rc == HDF_ERR_NOT_SUPPORT);
775         ASSERT_TRUE(flag);
776     }
777 }
778 
779 /**
780  * @tc.name: SendCmdIoctl_036
781  * @tc.desc: Wifi hdi send ioctl command function test
782  * @tc.type: FUNC
783  */
784 HWTEST_F(HdfWifiServiceCTest, SendCmdIoctl_036, Function | MediumTest | Level1)
785 {
786     const char *ifName = "wlan0";
787     int32_t rc;
788     bool flag;
789 
790     uint8_t deviceType = 5;
791     rc = g_wlanObj->WifiSendCmdIoctl(g_wlanObj, ifName, CMD_HID2D_MODULE_INIT, (const int8_t *)&deviceType,
792         sizeof(deviceType));
793     flag = ((rc == HDF_SUCCESS) || (rc == HDF_ERR_NOT_SUPPORT));
794     ASSERT_TRUE(flag);
795 
796     uint8_t batterylevel = 50;
797     rc = g_wlanObj->WifiSendCmdIoctl(g_wlanObj, ifName, CMD_SET_BATTERY_LEVEL, (const int8_t *)&batterylevel,
798         sizeof(batterylevel));
799     flag = ((rc == HDF_SUCCESS) || (rc == HDF_ERR_NOT_SUPPORT));
800     ASSERT_TRUE(flag);
801 
802     struct AdjustChannelInfo chanInfo;
803     chanInfo.msgId = 5;
804     chanInfo.chanNumber = 36;
805     chanInfo.bandwidth = 80;
806     chanInfo.switchType = 0;
807     rc = g_wlanObj->WifiSendCmdIoctl(g_wlanObj, ifName, CMD_SET_CHAN_ADJUST, (const int8_t *)&chanInfo,
808         sizeof(chanInfo));
809     flag = ((rc == HDF_SUCCESS) || (rc == HDF_ERR_NOT_SUPPORT));
810     ASSERT_TRUE(flag);
811 }
812 
813 /**
814  * @tc.name: GetStaInfo_037
815  * @tc.desc: Wifi hdi get station information function test
816  * @tc.type: FUNC
817  */
818 HWTEST_F(HdfWifiServiceCTest, GetStaInfo_037, Function | MediumTest | Level1)
819 {
820     const char *ifName = "wlan0";
821     int32_t rc;
822     struct WifiStationInfo info;
823     bool flag;
824     uint8_t mac[ETH_ADDR_LEN] = {0};
825 
826     rc = g_wlanObj->GetStaInfo(g_wlanObj, ifName, &info, mac, ETH_ADDR_LEN);
827     flag = (rc == HDF_SUCCESS || rc == HDF_ERR_NOT_SUPPORT);
828     ASSERT_TRUE(flag);
829 }
830 };
831