• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
1 /*
2  * Copyright (c) 2021-2023 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 "hdf_base.h"
18 #include "hdf_sbuf.h"
19 #include "wifi_hal.h"
20 #include "wifi_hal_ap_feature.h"
21 #include "wifi_hal_base_feature.h"
22 #include "wifi_hal_sta_feature.h"
23 
24 using namespace testing::ext;
25 
26 namespace HalTest {
27 struct IWiFi *g_wifi = nullptr;
28 const int32_t USEC_TIME = 1000000;
29 const int32_t MSEC_TIME = 1000;
30 const int32_t COMMON_TIME = 18000;
31 const int32_t MEDIUM_TIME = 20000;
32 const int32_t LONG_TIME = 200000;
33 const int32_t WLAN_BAND_2G = 0;
34 const int32_t WLAN_FREQ_MAX_NUM = 14;
35 const int32_t WLAN_MAX_NUM_STA_WITH_AP = 4;
36 const uint32_t DEFAULT_COMBO_SIZE = 10;
37 const uint32_t RESET_TIME = 3;
38 const uint32_t WLAN_MIN_CHIPID = 0;
39 const uint32_t WLAN_MAX_CHIPID = 2;
40 
41 static int32_t g_resetStatus = -1;
42 
43 class HdfWlanPerformanceTest : public testing::Test {
44 public:
45     static void SetUpTestCase();
46     static void TearDownTestCase();
47     void SetUp();
48     void TearDown();
49 };
50 
SetUpTestCase()51 void HdfWlanPerformanceTest::SetUpTestCase()
52 {
53     int ret;
54 
55     ret = WifiConstruct(&g_wifi);
56     ASSERT_EQ(HDF_SUCCESS, ret);
57 }
58 
TearDownTestCase()59 void HdfWlanPerformanceTest::TearDownTestCase()
60 {
61     int ret;
62 
63     ret = WifiDestruct(&g_wifi);
64     ASSERT_EQ(HDF_SUCCESS, ret);
65 }
66 
SetUp()67 void HdfWlanPerformanceTest::SetUp()
68 {
69     int ret;
70 
71     ret = g_wifi->start(nullptr);
72     ASSERT_EQ(HDF_ERR_INVALID_PARAM, ret);
73     ret = g_wifi->start(g_wifi);
74     ASSERT_EQ(HDF_SUCCESS, ret);
75 }
76 
TearDown()77 void HdfWlanPerformanceTest::TearDown()
78 {
79     int ret;
80 
81     ret = g_wifi->stop(nullptr);
82     ASSERT_EQ(HDF_ERR_INVALID_PARAM, ret);
83     ret = g_wifi->stop(g_wifi);
84     ASSERT_EQ(HDF_SUCCESS, ret);
85 }
86 
HalResetCallbackEvent(uint32_t event,void * data,const char * ifName)87 static int32_t HalResetCallbackEvent(uint32_t event, void *data, const char *ifName)
88 {
89     (void)event;
90     (void)ifName;
91     int *resetStatus = nullptr;
92     resetStatus = (int *)data;
93     printf("HalResetCallbackEvent: receive resetStatus=%d \n", *resetStatus);
94     g_resetStatus = *resetStatus;
95     return HDF_SUCCESS;
96 }
97 
98 /**
99  * @tc.name: WifiHalGetSupportFeature001
100  * @tc.desc: Get supported features
101  * @tc.type: FUNC
102  * @tc.require: AR000F869J
103  */
104 HWTEST_F(HdfWlanPerformanceTest, WifiHalGetSupportFeature001, TestSize.Level1)
105 {
106     int ret;
107     uint8_t supportTest[PROTOCOL_80211_IFTYPE_NUM] = {0};
108     uint8_t support[PROTOCOL_80211_IFTYPE_NUM + 1] = {0};
109     struct timespec tv1 = (struct timespec){0};
110     struct timespec tv2 = (struct timespec){0};
111     int timeUsed = 0;
112 
113     ret = g_wifi->getSupportFeature(nullptr, 0);
114     EXPECT_NE(HDF_SUCCESS, ret);
115     ret = g_wifi->getSupportFeature(supportTest, PROTOCOL_80211_IFTYPE_NUM);
116     EXPECT_NE(HDF_SUCCESS, ret);
117     clock_gettime(CLOCK_REALTIME, &tv1);
118     ret = g_wifi->getSupportFeature(support, PROTOCOL_80211_IFTYPE_NUM + 1);
119     clock_gettime(CLOCK_REALTIME, &tv2);
120     timeUsed = ((tv2.tv_sec * USEC_TIME + tv2.tv_nsec / MSEC_TIME) -
121         (tv1.tv_sec * USEC_TIME + tv1.tv_nsec / MSEC_TIME));
122     EXPECT_GE(COMMON_TIME, timeUsed);
123     EXPECT_EQ(HDF_SUCCESS, ret);
124 }
125 
126 /**
127  * @tc.name: WifiHalGetSupportCombo001
128  * @tc.desc: Get supported combo
129  * @tc.type: FUNC
130  * @tc.require: AR000F869J
131  */
132 HWTEST_F(HdfWlanPerformanceTest, WifiHalGetSupportCombo001, TestSize.Level1)
133 {
134     int ret;
135     uint8_t support[PROTOCOL_80211_IFTYPE_NUM + 1] = {0};
136     uint64_t combo[DEFAULT_COMBO_SIZE] = {0};
137     struct timespec tv1 = (struct timespec){0};
138     struct timespec tv2 = (struct timespec){0};
139     int timeUsed = 0;
140 
141     ret = g_wifi->getSupportFeature(support, PROTOCOL_80211_IFTYPE_NUM + 1);
142     EXPECT_EQ(HDF_SUCCESS, ret);
143     ret = g_wifi->getSupportCombo(nullptr, 0);
144     EXPECT_NE(HDF_SUCCESS, ret);
145     clock_gettime(CLOCK_REALTIME, &tv1);
146     ret = g_wifi->getSupportCombo(combo, DEFAULT_COMBO_SIZE);
147     clock_gettime(CLOCK_REALTIME, &tv2);
148     timeUsed = ((tv2.tv_sec * USEC_TIME + tv2.tv_nsec / MSEC_TIME) -
149         (tv1.tv_sec * USEC_TIME + tv1.tv_nsec / MSEC_TIME));
150     EXPECT_GE(COMMON_TIME, timeUsed);
151     if (support[PROTOCOL_80211_IFTYPE_NUM] == 0) {
152         EXPECT_EQ(HDF_ERR_NOT_SUPPORT, ret);
153     } else {
154         EXPECT_EQ(HDF_SUCCESS, ret);
155     }
156 }
157 
158 /**
159  * @tc.name: WifiHalGetDeviceMacAddress001
160  * @tc.desc: Get device Mac address for ap mode
161  * @tc.type: FUNC
162  * @tc.require: AR000F869G
163  */
164 HWTEST_F(HdfWlanPerformanceTest, WifiHalGetDeviceMacAddress001, TestSize.Level1)
165 {
166     int ret;
167     struct IWiFiAp *apFeature = nullptr;
168     unsigned char mac[ETH_ADDR_LEN] = {0};
169     struct timespec tv1 = (struct timespec){0};
170     struct timespec tv2 = (struct timespec){0};
171     int timeUsed = 0;
172 
173     ret = g_wifi->createFeature(PROTOCOL_80211_IFTYPE_AP, (struct IWiFiBaseFeature **)&apFeature);
174     if (ret == HDF_SUCCESS) {
175         EXPECT_NE(nullptr, apFeature);
176         ret = apFeature->baseFeature.getDeviceMacAddress((struct IWiFiBaseFeature *)apFeature, nullptr, 0);
177         EXPECT_NE(HDF_SUCCESS, ret);
178         ret = apFeature->baseFeature.getDeviceMacAddress((struct IWiFiBaseFeature *)apFeature, mac, ETH_ADDR_LEN - 1);
179         EXPECT_NE(HDF_SUCCESS, ret);
180         clock_gettime(CLOCK_REALTIME, &tv1);
181         ret = apFeature->baseFeature.getDeviceMacAddress((struct IWiFiBaseFeature *)apFeature, mac, ETH_ADDR_LEN);
182         clock_gettime(CLOCK_REALTIME, &tv2);
183         timeUsed = ((tv2.tv_sec * USEC_TIME + tv2.tv_nsec / MSEC_TIME) -
184             (tv1.tv_sec * USEC_TIME + tv1.tv_nsec / MSEC_TIME));
185         EXPECT_GE(LONG_TIME, timeUsed);
186         EXPECT_NE(HDF_FAILURE, ret);
187 
188         ret = g_wifi->destroyFeature((struct IWiFiBaseFeature *)apFeature);
189         EXPECT_EQ(HDF_SUCCESS, ret);
190     }
191 }
192 
193 /**
194  * @tc.name: WifiHalGetDeviceMacAddress002
195  * @tc.desc: Get device Mac address for sta mode
196  * @tc.type: FUNC
197  * @tc.require: AR000F869E
198  */
199 HWTEST_F(HdfWlanPerformanceTest, WifiHalGetDeviceMacAddress002, TestSize.Level1)
200 {
201     int ret;
202     struct IWiFiSta *staFeature = nullptr;
203     unsigned char mac[ETH_ADDR_LEN] = {0};
204     struct timespec tv1 = (struct timespec){0};
205     struct timespec tv2 = (struct timespec){0};
206     int timeUsed = 0;
207 
208     ret = g_wifi->createFeature(PROTOCOL_80211_IFTYPE_STATION, (struct IWiFiBaseFeature **)&staFeature);
209     if (ret == HDF_SUCCESS) {
210         EXPECT_NE(nullptr, staFeature);
211         ret = staFeature->baseFeature.getDeviceMacAddress((struct IWiFiBaseFeature *)staFeature, nullptr, 0);
212         EXPECT_NE(HDF_SUCCESS, ret);
213         ret = staFeature->baseFeature.getDeviceMacAddress((struct IWiFiBaseFeature *)staFeature, mac, ETH_ADDR_LEN - 1);
214         EXPECT_NE(HDF_SUCCESS, ret);
215         clock_gettime(CLOCK_REALTIME, &tv1);
216         ret = staFeature->baseFeature.getDeviceMacAddress((struct IWiFiBaseFeature *)staFeature, mac, ETH_ADDR_LEN);
217         clock_gettime(CLOCK_REALTIME, &tv2);
218         timeUsed = ((tv2.tv_sec * USEC_TIME + tv2.tv_nsec / MSEC_TIME) -
219             (tv1.tv_sec * USEC_TIME + tv1.tv_nsec / MSEC_TIME));
220         EXPECT_GE(LONG_TIME, timeUsed);
221         EXPECT_NE(HDF_FAILURE, ret);
222 
223         ret = g_wifi->destroyFeature((struct IWiFiBaseFeature *)staFeature);
224         EXPECT_EQ(HDF_SUCCESS, ret);
225     }
226 }
227 
228 /**
229  * @tc.name: WifiHaGetValidFreqsWithBand001
230  * @tc.desc: Get available frequencies
231  * @tc.type: FUNC
232  * @tc.require: AR000F869G
233  */
234 HWTEST_F(HdfWlanPerformanceTest, WifiHaGetValidFreqsWithBand001, TestSize.Level1)
235 {
236     int ret;
237     struct IWiFiAp *apFeature = nullptr;
238     int32_t freq[WLAN_FREQ_MAX_NUM] = {0};
239     uint32_t num = 0;
240     struct timespec tv1 = (struct timespec){0};
241     struct timespec tv2 = (struct timespec){0};
242     int timeUsed = 0;
243 
244     ret = g_wifi->createFeature(PROTOCOL_80211_IFTYPE_AP, (struct IWiFiBaseFeature **)&apFeature);
245     if (ret == HDF_SUCCESS) {
246         EXPECT_NE(nullptr, apFeature);
247         ret = apFeature->baseFeature.getValidFreqsWithBand((struct IWiFiBaseFeature *)apFeature,
248         WLAN_BAND_2G, nullptr, 0, nullptr);
249         EXPECT_NE(HDF_SUCCESS, ret);
250         clock_gettime(CLOCK_REALTIME, &tv1);
251         ret = apFeature->baseFeature.getValidFreqsWithBand((struct IWiFiBaseFeature *)apFeature,
252         WLAN_BAND_2G, freq, WLAN_FREQ_MAX_NUM, &num);
253         clock_gettime(CLOCK_REALTIME, &tv2);
254         timeUsed = ((tv2.tv_sec * USEC_TIME + tv2.tv_nsec / MSEC_TIME) -
255             (tv1.tv_sec * USEC_TIME + tv1.tv_nsec / MSEC_TIME));
256         EXPECT_GE(COMMON_TIME, timeUsed);
257         EXPECT_EQ(HDF_SUCCESS, ret);
258 
259         ret = g_wifi->destroyFeature((struct IWiFiBaseFeature *)apFeature);
260         EXPECT_EQ(HDF_SUCCESS, ret);
261     }
262 }
263 
264 /**
265  * @tc.name: WifiHalGetAssociatedStas001
266  * @tc.desc: Get associated STA info
267  * @tc.type: FUNC
268  * @tc.require: AR000F869K
269  */
270 HWTEST_F(HdfWlanPerformanceTest, WifiHalGetAssociatedStas001, TestSize.Level1)
271 {
272     int ret;
273     struct IWiFiAp *apFeature = nullptr;
274     struct StaInfo staInfo[WLAN_MAX_NUM_STA_WITH_AP] = {{0}};
275     uint32_t num = 0;
276     struct timespec tv1 = (struct timespec){0};
277     struct timespec tv2 = (struct timespec){0};
278     int timeUsed = 0;
279     uint8_t chipId = 0;
280 
281     ret = g_wifi->createFeature(PROTOCOL_80211_IFTYPE_AP, (struct IWiFiBaseFeature **)&apFeature);
282     if (ret == HDF_SUCCESS) {
283         EXPECT_NE(nullptr, apFeature);
284         ret = apFeature->baseFeature.getChipId((struct IWiFiBaseFeature *)apFeature, &chipId);
285         EXPECT_EQ(HDF_SUCCESS, ret);
286         ret = g_wifi->resetDriver(chipId, apFeature->baseFeature.ifName);
287         EXPECT_EQ(HDF_SUCCESS, ret);
288         sleep(RESET_TIME);
289 
290         ret = apFeature->getAssociatedStas(apFeature, nullptr, 0, nullptr);
291         EXPECT_NE(HDF_SUCCESS, ret);
292         clock_gettime(CLOCK_REALTIME, &tv1);
293         ret = apFeature->getAssociatedStas(apFeature, staInfo, WLAN_MAX_NUM_STA_WITH_AP, &num);
294         clock_gettime(CLOCK_REALTIME, &tv2);
295         timeUsed = ((tv2.tv_sec * USEC_TIME + tv2.tv_nsec / MSEC_TIME) -
296             (tv1.tv_sec * USEC_TIME + tv1.tv_nsec / MSEC_TIME));
297         EXPECT_GE(COMMON_TIME, timeUsed);
298         EXPECT_EQ(HDF_SUCCESS, ret);
299 
300         ret = g_wifi->destroyFeature((struct IWiFiBaseFeature *)apFeature);
301         EXPECT_EQ(HDF_SUCCESS, ret);
302     }
303 }
304 
305 /**
306  * @tc.name: WifiHalSetScanningMacAddress001
307  * @tc.desc: Set Mac address scanning
308  * @tc.type: FUNC
309  * @tc.require: AR000F869K
310  */
311 HWTEST_F(HdfWlanPerformanceTest, WifiHalSetScanningMacAddress001, TestSize.Level1)
312 {
313     int ret;
314     struct IWiFiSta *staFeature = nullptr;
315     unsigned char scanMac[ETH_ADDR_LEN] = {0x12, 0x34, 0x56, 0x78, 0xab, 0xcd};
316     struct timespec tv1 = (struct timespec){0};
317     struct timespec tv2 = (struct timespec){0};
318     int timeUsed = 0;
319 
320     ret = g_wifi->createFeature(PROTOCOL_80211_IFTYPE_STATION, (struct IWiFiBaseFeature **)&staFeature);
321     if (ret == HDF_SUCCESS) {
322         EXPECT_NE(nullptr, staFeature);
323         ret = staFeature->setScanningMacAddress(staFeature, nullptr, 0);
324         EXPECT_NE(HDF_SUCCESS, ret);
325         clock_gettime(CLOCK_REALTIME, &tv1);
326         ret = staFeature->setScanningMacAddress(staFeature, scanMac, ETH_ADDR_LEN);
327         clock_gettime(CLOCK_REALTIME, &tv2);
328         timeUsed = ((tv2.tv_sec * USEC_TIME + tv2.tv_nsec / MSEC_TIME) -
329             (tv1.tv_sec * USEC_TIME + tv1.tv_nsec / MSEC_TIME));
330         EXPECT_GE(LONG_TIME, timeUsed);
331         EXPECT_NE(HDF_FAILURE, ret);
332 
333         ret = g_wifi->destroyFeature((struct IWiFiBaseFeature *)staFeature);
334         EXPECT_EQ(HDF_SUCCESS, ret);
335     }
336 }
337 
338 /**
339  * @tc.name: WifiHalGetChipId001
340  * @tc.desc: Obtain the chip ID
341  * @tc.type: FUNC
342  * @tc.require: AR000F869G
343  */
344 HWTEST_F(HdfWlanPerformanceTest, WifiHalGetChipId001, TestSize.Level1)
345 {
346     int ret;
347     struct IWiFiSta *staFeature = nullptr;
348     unsigned char chipId = 0;
349     struct timespec tv1 = (struct timespec){0};
350     struct timespec tv2 = (struct timespec){0};
351     int timeUsed = 0;
352 
353     ret = g_wifi->createFeature(PROTOCOL_80211_IFTYPE_STATION, (struct IWiFiBaseFeature **)&staFeature);
354     if (ret == HDF_SUCCESS) {
355         EXPECT_NE(nullptr, staFeature);
356         ret = staFeature->baseFeature.getChipId((struct IWiFiBaseFeature *)staFeature, nullptr);
357         EXPECT_NE(HDF_SUCCESS, ret);
358         clock_gettime(CLOCK_REALTIME, &tv1);
359         ret = staFeature->baseFeature.getChipId((struct IWiFiBaseFeature *)staFeature, &chipId);
360         clock_gettime(CLOCK_REALTIME, &tv2);
361         timeUsed = ((tv2.tv_sec * USEC_TIME + tv2.tv_nsec / MSEC_TIME) -
362             (tv1.tv_sec * USEC_TIME + tv1.tv_nsec / MSEC_TIME));
363         EXPECT_GE(MEDIUM_TIME, timeUsed);
364         ASSERT_TRUE(chipId <= WLAN_MAX_CHIPID && chipId >= WLAN_MIN_CHIPID);
365         EXPECT_EQ(HDF_SUCCESS, ret);
366 
367         ret = g_wifi->destroyFeature((struct IWiFiBaseFeature *)staFeature);
368         EXPECT_EQ(HDF_SUCCESS, ret);
369     }
370 }
371 
372 /**
373  * @tc.name: WifiHalRegisterEventCallback001
374  * @tc.desc: Wifi hal register callback function test
375  * @tc.type: FUNC
376  * @tc.require: AR000F869G
377  */
378 HWTEST_F(HdfWlanPerformanceTest, WifiHalRegisterEventCallback001, TestSize.Level1)
379 {
380     int ret;
381 
382     ret = g_wifi->registerEventCallback(HalResetCallbackEvent, "wlan0");
383     sleep(RESET_TIME);
384     EXPECT_EQ(HDF_SUCCESS, ret);
385 }
386 };
387