• 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 
16 #include <gtest/gtest.h>
17 #include <osal_mem.h>
18 #include "wifi_driver_client.h"
19 
20 using namespace testing::ext;
21 
22 namespace ClientTest {
23 const uint32_t DEFAULT_COMBO_SIZE = 10;
24 const char *WLAN_IFNAME = "wlan0";
25 const uint32_t RESET_TIME = 20;
26 class WifiClientTest : public testing::Test {
27 public:
28     static void SetUpTestCase();
29     static void TearDownTestCase();
30     void SetUp();
31     void TearDown();
32 };
33 
SetUpTestCase()34 void WifiClientTest::SetUpTestCase()
35 {
36 }
37 
TearDownTestCase()38 void WifiClientTest::TearDownTestCase()
39 {
40 }
41 
SetUp()42 void WifiClientTest::SetUp()
43 {
44     WifiDriverClientInit();
45 }
46 
TearDown()47 void WifiClientTest::TearDown()
48 {
49     WifiDriverClientDeinit();
50 }
51 
52 /**
53  * @tc.name: WifiClientSetCountryCode001
54  * @tc.desc: Wifi client set country code function test
55  * @tc.type: FUNC
56  * @tc.require: AR000FRMJC
57  */
58 HWTEST_F(WifiClientTest, WifiClientSetCountryCode001, TestSize.Level1)
59 {
60     int32_t ret;
61     const char *code = "CN";
62     const char *codeDigital = "99";
63     uint32_t len = 2;
64 
65     ret = WifiSetCountryCode(WLAN_IFNAME, code, len);
66     EXPECT_EQ(RET_CODE_SUCCESS, ret);
67     ret = WifiSetCountryCode(WLAN_IFNAME, codeDigital, len);
68     bool flag = (ret == HDF_SUCCESS || ret == HDF_ERR_NOT_SUPPORT);
69     ASSERT_TRUE(flag);
70 }
71 
72 /**
73  * @tc.name: WifiClientGetUsableNetworkInfo001
74  * @tc.desc: Wifi client get usable networkInfo function test
75  * @tc.type: FUNC
76  * @tc.require: AR000FRMJC
77  */
78 HWTEST_F(WifiClientTest, WifiClientGetUsableNetworkInfo001, TestSize.Level1)
79 {
80     int32_t ret;
81     struct NetworkInfoResult networkInfo;
82 
83     ret = GetUsableNetworkInfo(&networkInfo);
84     EXPECT_EQ(RET_CODE_SUCCESS, ret);
85 }
86 
87 /**
88  * @tc.name: WifiClientIsSupportCombo001
89  * @tc.desc: Wifi client is support combo function test
90  * @tc.type: FUNC
91  * @tc.require: AR000FRMJC
92  */
93 HWTEST_F(WifiClientTest, WifiClientIsSupportCombo001, TestSize.Level1)
94 {
95     int32_t ret;
96     uint8_t isSupportCombo;
97 
98     ret = IsSupportCombo(&isSupportCombo);
99     EXPECT_EQ(RET_CODE_SUCCESS, ret);
100 }
101 
102 /**
103  * @tc.name: WifiClientGetComboInfo001
104  * @tc.desc: Wifi client get combo info function test
105  * @tc.type: FUNC
106  * @tc.require: AR000FRMJC
107  */
108 HWTEST_F(WifiClientTest, WifiClientGetComboInfo001, TestSize.Level1)
109 {
110     int32_t ret;
111     uint64_t comboInfo[DEFAULT_COMBO_SIZE] = {};
112 
113     ret = GetComboInfo(comboInfo, DEFAULT_COMBO_SIZE);
114     bool flag = (ret == RET_CODE_SUCCESS || ret == RET_CODE_NOT_SUPPORT);
115     ASSERT_TRUE(flag);
116 }
117 
118 /**
119  * @tc.name: WifiClientSetMacAddr001
120  * @tc.desc: Wifi client set mac addr function test
121  * @tc.type: FUNC
122  * @tc.require: AR000FRMJC
123  */
124 HWTEST_F(WifiClientTest, WifiClientSetMacAddr001, TestSize.Level1)
125 {
126     int32_t ret;
127     unsigned char mac[ETH_ADDR_LEN] = {0x12, 0x34, 0x56, 0x78, 0xab, 0xcd};
128     unsigned char errorMac[ETH_ADDR_LEN] = {0x11, 0x34, 0x56, 0x78, 0xab, 0xcd};
129 
130     ret = SetMacAddr(WLAN_IFNAME, mac, ETH_ADDR_LEN);
131     bool flag = (ret == HDF_SUCCESS || ret == HDF_ERR_NOT_SUPPORT || ret == HDF_ERR_DEVICE_BUSY);
132     ASSERT_TRUE(flag);
133     ret = SetMacAddr(WLAN_IFNAME, errorMac, ETH_ADDR_LEN);
134     EXPECT_NE(RET_CODE_SUCCESS, ret);
135 }
136 
137 /**
138  * @tc.name: WifiClientGetDevMacAddr001
139  * @tc.desc: Wifi client get mac addr function test
140  * @tc.type: FUNC
141  * @tc.require: AR000FRMJC
142  */
143 HWTEST_F(WifiClientTest, WifiClientGetDevMacAddr001, TestSize.Level1)
144 {
145     int32_t ret;
146     unsigned char mac[ETH_ADDR_LEN] = {};
147     int32_t type = WIFI_IFTYPE_STATION;
148 
149     ret = GetDevMacAddr(WLAN_IFNAME, type, mac, ETH_ADDR_LEN);
150     EXPECT_NE(RET_CODE_FAILURE, ret);
151 }
152 
153 /**
154  * @tc.name: WifiClientGetDevMacAddr002
155  * @tc.desc: Wifi client get mac addr function test
156  * @tc.type: FUNC
157  * @tc.require: AR000H603L
158  */
159 HWTEST_F(WifiClientTest, WifiClientGetDevMacAddr002, TestSize.Level1)
160 {
161     int32_t ret;
162     unsigned char mac[ETH_ADDR_LEN] = {};
163     int32_t type = WIFI_IFTYPE_AP;
164 
165     ret = GetDevMacAddr(WLAN_IFNAME, type, mac, ETH_ADDR_LEN);
166     EXPECT_NE(RET_CODE_FAILURE, ret);
167 }
168 
169 /**
170  * @tc.name: WifiClientGetValidFreqByBand001
171  * @tc.desc: Wifi client get valid freq function test
172  * @tc.type: FUNC
173  * @tc.require: AR000FRMJC
174  */
175 HWTEST_F(WifiClientTest, WifiClientGetValidFreqByBand001, TestSize.Level1)
176 {
177     int32_t ret;
178     int32_t band = IEEE80211_BAND_2GHZ;
179     int32_t bandNotSupport = IEEE80211_NUM_BANDS;
180     struct FreqInfoResult result;
181     uint32_t size = 14;
182     uint32_t i;
183 
184     result.freqs = (uint32_t *)OsalMemCalloc(35 * sizeof(uint32_t));
185     if (result.freqs == NULL) {
186         printf("%s: OsalMemCalloc failed", __FUNCTION__);
187         return;
188     }
189 
190     result.txPower = (uint32_t *)OsalMemCalloc(35 * sizeof(uint32_t));
191     if (result.txPower == NULL) {
192         printf("%s: OsalMemCalloc failed", __FUNCTION__);
193         OsalMemFree(result.freqs);
194         return;
195     }
196 
197     ret = GetValidFreqByBand(WLAN_IFNAME, bandNotSupport, &result, size);
198     EXPECT_NE(RET_CODE_SUCCESS, ret);
199     ret = GetValidFreqByBand(WLAN_IFNAME, band, &result, size);
200     EXPECT_EQ(RET_CODE_SUCCESS, ret);
201     if (ret == RET_CODE_SUCCESS) {
202         printf("%s: num = %u\n", __func__, result.nums);
203         for (i = 0; i < result.nums; i++) {
204             printf("%s: freq[%d] = %d\n", __func__, i, result.freqs[i]);
205         }
206     }
207 
208     OsalMemFree(result.txPower);
209     OsalMemFree(result.freqs);
210 }
211 
212 /**
213  * @tc.name: WifiClientSetTxPower001
214  * @tc.desc: Wifi client set tx power function test
215  * @tc.type: FUNC
216  * @tc.require: AR000FRMJC
217  */
218 HWTEST_F(WifiClientTest, WifiClientSetTxPower001, TestSize.Level1)
219 {
220     int32_t ret;
221     int32_t power = 10;
222 
223     ret = SetTxPower(WLAN_IFNAME, power);
224     EXPECT_EQ(RET_CODE_SUCCESS, ret);
225 }
226 
227 /**
228  * @tc.name: WifiClientGetAssociatedStas001
229  * @tc.desc: Wifi client get associated status function test
230  * @tc.type: FUNC
231  * @tc.require: AR000H603L
232  */
233 HWTEST_F(WifiClientTest, WifiClientGetAssociatedStas001, TestSize.Level1)
234 {
235     int32_t ret;
236     struct AssocStaInfoResult result;
237 
238     ret = GetAssociatedStas(WLAN_IFNAME, &result);
239     EXPECT_EQ(RET_CODE_SUCCESS, ret);
240 }
241 
242 /**
243  * @tc.name: WifiClientSetScanMacAddr001
244  * @tc.desc: Wifi client set scan MAC address function test
245  * @tc.type: FUNC
246  * @tc.require: AR000H603L
247  */
248 HWTEST_F(WifiClientTest, WifiClientSetScanMacAddr001, TestSize.Level1)
249 {
250     int32_t ret;
251     unsigned char scanMac[ETH_ADDR_LEN] = {0x12, 0x34, 0x56, 0x78, 0xab, 0xcd};
252 
253     ret = SetScanMacAddr(WLAN_IFNAME, scanMac, ETH_ADDR_LEN);
254     bool flag = (ret == RET_CODE_SUCCESS || ret == RET_CODE_NOT_SUPPORT);
255     ASSERT_TRUE(flag);
256 }
257 
258 /**
259  * @tc.name: WifiClientAcquireChipId001
260  * @tc.desc: Wifi client get chipId function test
261  * @tc.type: FUNC
262  * @tc.require: AR000H603L
263  */
264 HWTEST_F(WifiClientTest, WifiClientAcquireChipId001, TestSize.Level1)
265 {
266     int32_t ret;
267     const char *ifNameInvalid = "wlanTest";
268     uint8_t chipId = 0;
269 
270     ret = AcquireChipId(ifNameInvalid, &chipId);
271     EXPECT_NE(RET_CODE_SUCCESS, ret);
272     ret = AcquireChipId(WLAN_IFNAME, &chipId);
273     ASSERT_TRUE(chipId < MAX_WLAN_DEVICE);
274     EXPECT_EQ(RET_CODE_SUCCESS, ret);
275 }
276 
277 /**
278  * @tc.name: WifiClientGetIfNamesByChipId001
279  * @tc.desc: Wifi client get ifName by chipId function test
280  * @tc.type: FUNC
281  * @tc.require: AR000H603L
282  */
283 HWTEST_F(WifiClientTest, WifiClientGetIfNamesByChipId001, TestSize.Level1)
284 {
285     int32_t ret;
286     uint8_t chipId = 0;
287     uint8_t chipIdInvalid = 100;
288     char *ifNames = nullptr;
289     uint32_t num = 0;
290 
291     ret = AcquireChipId(WLAN_IFNAME, &chipId);
292     ASSERT_TRUE(chipId < MAX_WLAN_DEVICE);
293     EXPECT_EQ(RET_CODE_SUCCESS, ret);
294     ret = GetIfNamesByChipId(chipIdInvalid, &ifNames, &num);
295     EXPECT_NE(RET_CODE_SUCCESS, ret);
296     ret = GetIfNamesByChipId(chipId, &ifNames, &num);
297     EXPECT_NE(ifNames, nullptr);
298     EXPECT_EQ(RET_CODE_SUCCESS, ret);
299     free(ifNames);
300 }
301 
302 /**
303  * @tc.name: WifiClientGetNetDeviceInfo001
304  * @tc.desc: Wifi client get netDevice information function test
305  * @tc.type: FUNC
306  * @tc.require: AR000H603L
307  */
308 HWTEST_F(WifiClientTest, WifiClientGetNetDeviceInfo001, TestSize.Level1)
309 {
310     int32_t ret;
311     struct NetDeviceInfoResult netDeviceInfoResult;
312 
313     ret = GetNetDeviceInfo(&netDeviceInfoResult);
314     EXPECT_EQ(RET_CODE_SUCCESS, ret);
315 }
316 
317 /**
318  * @tc.name: WifiClientGetCurrentPowerMode001
319  * @tc.desc: Wifi client get current power mode function test
320  * @tc.type: FUNC
321  * @tc.require: AR000H603L
322  */
323 HWTEST_F(WifiClientTest, WifiClientGetCurrentPowerMode001, TestSize.Level1)
324 {
325     int32_t ret;
326     uint8_t mode = 0;
327     const char *ifNameInvalid = "wlanTest";
328 
329     ret = GetCurrentPowerMode(ifNameInvalid, &mode);
330     EXPECT_NE(RET_CODE_SUCCESS, ret);
331     ret = GetCurrentPowerMode(WLAN_IFNAME, &mode);
332     bool flag = (ret == RET_CODE_SUCCESS || ret == RET_CODE_NOT_SUPPORT);
333     ASSERT_TRUE(flag);
334 }
335 
336 /**
337  * @tc.name: WifiClientSetPowerMode001
338  * @tc.desc: Wifi client set power mode function test
339  * @tc.type: FUNC
340  * @tc.require: AR000H603L
341  */
342 HWTEST_F(WifiClientTest, WifiClientSetPowerMode001, TestSize.Level1)
343 {
344     int32_t ret;
345     const char *ifNameInvalid = "wlanTest";
346 
347     ret = SetPowerMode(ifNameInvalid, WIFI_POWER_MODE_SLEEPING);
348     EXPECT_NE(RET_CODE_SUCCESS, ret);
349     ret = SetPowerMode(WLAN_IFNAME, WIFI_POWER_MODE_SLEEPING);
350     bool flag = (ret == RET_CODE_SUCCESS || ret == RET_CODE_NOT_SUPPORT);
351     ASSERT_TRUE(flag);
352 }
353 
354 /**
355  * @tc.name: WifiClientSetPowerMode002
356  * @tc.desc: Wifi client set power mode function test
357  * @tc.type: FUNC
358  * @tc.require: AR000H603L
359  */
360 HWTEST_F(WifiClientTest, WifiClientSetPowerMode002, TestSize.Level1)
361 {
362     int32_t ret;
363 
364     ret = SetPowerMode(WLAN_IFNAME, WIFI_POWER_MODE_GENERAL);
365     bool flag = (ret == RET_CODE_SUCCESS || ret == RET_CODE_NOT_SUPPORT);
366     ASSERT_TRUE(flag);
367 }
368 
369 /**
370  * @tc.name: WifiClientSetPowerMode003
371  * @tc.desc: Wifi client set power mode function test
372  * @tc.type: FUNC
373  * @tc.require: AR000H603L
374  */
375 HWTEST_F(WifiClientTest, WifiClientSetPowerMode003, TestSize.Level1)
376 {
377     int32_t ret;
378 
379     ret = SetPowerMode(WLAN_IFNAME, WIFI_POWER_MODE_THROUGH_WALL);
380     bool flag = (ret == RET_CODE_SUCCESS || ret == RET_CODE_NOT_SUPPORT);
381     ASSERT_TRUE(flag);
382 }
383 
384 /**
385  * @tc.name: WifiClientSetPowerMode004
386  * @tc.desc: Wifi client set power mode function test
387  * @tc.type: FUNC
388  * @tc.require: AR000H603L
389  */
390 HWTEST_F(WifiClientTest, WifiClientSetPowerMode004, TestSize.Level1)
391 {
392     int32_t ret;
393 
394     ret = SetPowerMode(WLAN_IFNAME, WIFI_POWER_MODE_NUM);
395     EXPECT_NE(RET_CODE_SUCCESS, ret);
396 }
397 
398 /**
399  * @tc.name: WifiClientSetResetDriver001
400  * @tc.desc: Wifi client reset driver function test
401  * @tc.type: FUNC
402  * @tc.require: AR000H603L
403  */
404 HWTEST_F(WifiClientTest, WifiClientSetResetDriver001, TestSize.Level1)
405 {
406     int32_t ret;
407     uint8_t chipId = 0;
408 
409     ret = AcquireChipId(WLAN_IFNAME, &chipId);
410     ASSERT_TRUE(chipId < MAX_WLAN_DEVICE);
411     EXPECT_EQ(RET_CODE_SUCCESS, ret);
412 
413     ret = SetResetDriver(chipId, WLAN_IFNAME);
414     EXPECT_EQ(RET_CODE_SUCCESS, ret);
415     sleep(RESET_TIME);
416 }
417 };
418