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