• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
1 /*
2  * Copyright (C) 2017, The Android Open Source Project
3  *
4  * Licensed under the Apache License, Version 2.0 (the "License");
5  * you may not use this file except in compliance with the License.
6  * You may obtain a copy of the License at
7  *
8  *     http://www.apache.org/licenses/LICENSE-2.0
9  *
10  * Unless required by applicable law or agreed to in writing, software
11  * distributed under the License is distributed on an "AS IS" BASIS,
12  * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13  * See the License for the specific language governing permissions and
14  * limitations under the License.
15  */
16 
17 #include <android-base/logging.h>
18 #include <android-base/macros.h>
19 #include <gmock/gmock.h>
20 
21 #undef NAN
22 #include "hidl_struct_util.h"
23 
24 using testing::Test;
25 
26 namespace {
27 constexpr uint32_t kMacId1 = 1;
28 constexpr uint32_t kMacId2 = 2;
29 constexpr uint32_t kIfaceChannel1 = 3;
30 constexpr uint32_t kIfaceChannel2 = 5;
31 constexpr char kIfaceName1[] = "wlan0";
32 constexpr char kIfaceName2[] = "wlan1";
33 }  // namespace
34 namespace android {
35 namespace hardware {
36 namespace wifi {
37 namespace V1_3 {
38 namespace implementation {
39 using namespace android::hardware::wifi::V1_0;
40 using ::android::hardware::wifi::V1_0::WifiChannelWidthInMhz;
41 
42 class HidlStructUtilTest : public Test {};
43 
TEST_F(HidlStructUtilTest,CanConvertLegacyWifiMacInfosToHidlWithOneMac)44 TEST_F(HidlStructUtilTest, CanConvertLegacyWifiMacInfosToHidlWithOneMac) {
45     std::vector<legacy_hal::WifiMacInfo> legacy_mac_infos;
46     legacy_hal::WifiMacInfo legacy_mac_info1 = {
47         .wlan_mac_id = kMacId1,
48         .mac_band =
49             legacy_hal::WLAN_MAC_5_0_BAND | legacy_hal::WLAN_MAC_2_4_BAND};
50     legacy_hal::WifiIfaceInfo legacy_iface_info1 = {.name = kIfaceName1,
51                                                     .channel = kIfaceChannel1};
52     legacy_hal::WifiIfaceInfo legacy_iface_info2 = {.name = kIfaceName2,
53                                                     .channel = kIfaceChannel2};
54     legacy_mac_info1.iface_infos.push_back(legacy_iface_info1);
55     legacy_mac_info1.iface_infos.push_back(legacy_iface_info2);
56     legacy_mac_infos.push_back(legacy_mac_info1);
57 
58     std::vector<V1_2::IWifiChipEventCallback::RadioModeInfo>
59         hidl_radio_mode_infos;
60     ASSERT_TRUE(hidl_struct_util::convertLegacyWifiMacInfosToHidl(
61         legacy_mac_infos, &hidl_radio_mode_infos));
62 
63     ASSERT_EQ(1u, hidl_radio_mode_infos.size());
64     auto hidl_radio_mode_info1 = hidl_radio_mode_infos[0];
65     EXPECT_EQ(legacy_mac_info1.wlan_mac_id, hidl_radio_mode_info1.radioId);
66     EXPECT_EQ(WifiBand::BAND_24GHZ_5GHZ, hidl_radio_mode_info1.bandInfo);
67     ASSERT_EQ(2u, hidl_radio_mode_info1.ifaceInfos.size());
68     auto hidl_iface_info1 = hidl_radio_mode_info1.ifaceInfos[0];
69     EXPECT_EQ(legacy_iface_info1.name, hidl_iface_info1.name);
70     EXPECT_EQ(static_cast<uint32_t>(legacy_iface_info1.channel),
71               hidl_iface_info1.channel);
72     auto hidl_iface_info2 = hidl_radio_mode_info1.ifaceInfos[1];
73     EXPECT_EQ(legacy_iface_info2.name, hidl_iface_info2.name);
74     EXPECT_EQ(static_cast<uint32_t>(legacy_iface_info2.channel),
75               hidl_iface_info2.channel);
76 }
77 
TEST_F(HidlStructUtilTest,CanConvertLegacyWifiMacInfosToHidlWithTwoMac)78 TEST_F(HidlStructUtilTest, CanConvertLegacyWifiMacInfosToHidlWithTwoMac) {
79     std::vector<legacy_hal::WifiMacInfo> legacy_mac_infos;
80     legacy_hal::WifiMacInfo legacy_mac_info1 = {
81         .wlan_mac_id = kMacId1, .mac_band = legacy_hal::WLAN_MAC_5_0_BAND};
82     legacy_hal::WifiIfaceInfo legacy_iface_info1 = {.name = kIfaceName1,
83                                                     .channel = kIfaceChannel1};
84     legacy_hal::WifiMacInfo legacy_mac_info2 = {
85         .wlan_mac_id = kMacId2, .mac_band = legacy_hal::WLAN_MAC_2_4_BAND};
86     legacy_hal::WifiIfaceInfo legacy_iface_info2 = {.name = kIfaceName2,
87                                                     .channel = kIfaceChannel2};
88     legacy_mac_info1.iface_infos.push_back(legacy_iface_info1);
89     legacy_mac_infos.push_back(legacy_mac_info1);
90     legacy_mac_info2.iface_infos.push_back(legacy_iface_info2);
91     legacy_mac_infos.push_back(legacy_mac_info2);
92 
93     std::vector<V1_2::IWifiChipEventCallback::RadioModeInfo>
94         hidl_radio_mode_infos;
95     ASSERT_TRUE(hidl_struct_util::convertLegacyWifiMacInfosToHidl(
96         legacy_mac_infos, &hidl_radio_mode_infos));
97 
98     ASSERT_EQ(2u, hidl_radio_mode_infos.size());
99 
100     // Find mac info 1.
101     const auto hidl_radio_mode_info1 =
102         std::find_if(hidl_radio_mode_infos.begin(), hidl_radio_mode_infos.end(),
103                      [&legacy_mac_info1](
104                          const V1_2::IWifiChipEventCallback::RadioModeInfo& x) {
105                          return x.radioId == legacy_mac_info1.wlan_mac_id;
106                      });
107     ASSERT_NE(hidl_radio_mode_infos.end(), hidl_radio_mode_info1);
108     EXPECT_EQ(WifiBand::BAND_5GHZ, hidl_radio_mode_info1->bandInfo);
109     ASSERT_EQ(1u, hidl_radio_mode_info1->ifaceInfos.size());
110     auto hidl_iface_info1 = hidl_radio_mode_info1->ifaceInfos[0];
111     EXPECT_EQ(legacy_iface_info1.name, hidl_iface_info1.name);
112     EXPECT_EQ(static_cast<uint32_t>(legacy_iface_info1.channel),
113               hidl_iface_info1.channel);
114 
115     // Find mac info 2.
116     const auto hidl_radio_mode_info2 =
117         std::find_if(hidl_radio_mode_infos.begin(), hidl_radio_mode_infos.end(),
118                      [&legacy_mac_info2](
119                          const V1_2::IWifiChipEventCallback::RadioModeInfo& x) {
120                          return x.radioId == legacy_mac_info2.wlan_mac_id;
121                      });
122     ASSERT_NE(hidl_radio_mode_infos.end(), hidl_radio_mode_info2);
123     EXPECT_EQ(WifiBand::BAND_24GHZ, hidl_radio_mode_info2->bandInfo);
124     ASSERT_EQ(1u, hidl_radio_mode_info2->ifaceInfos.size());
125     auto hidl_iface_info2 = hidl_radio_mode_info2->ifaceInfos[0];
126     EXPECT_EQ(legacy_iface_info2.name, hidl_iface_info2.name);
127     EXPECT_EQ(static_cast<uint32_t>(legacy_iface_info2.channel),
128               hidl_iface_info2.channel);
129 }
130 
TEST_F(HidlStructUtilTest,canConvertLegacyLinkLayerStatsToHidl)131 TEST_F(HidlStructUtilTest, canConvertLegacyLinkLayerStatsToHidl) {
132     legacy_hal::LinkLayerStats legacy_stats{};
133     legacy_stats.radios.push_back(legacy_hal::LinkLayerRadioStats{});
134     legacy_stats.radios.push_back(legacy_hal::LinkLayerRadioStats{});
135     legacy_stats.iface.beacon_rx = rand();
136     legacy_stats.iface.rssi_mgmt = rand();
137     legacy_stats.iface.ac[legacy_hal::WIFI_AC_BE].rx_mpdu = rand();
138     legacy_stats.iface.ac[legacy_hal::WIFI_AC_BE].tx_mpdu = rand();
139     legacy_stats.iface.ac[legacy_hal::WIFI_AC_BE].mpdu_lost = rand();
140     legacy_stats.iface.ac[legacy_hal::WIFI_AC_BE].retries = rand();
141 
142     legacy_stats.iface.ac[legacy_hal::WIFI_AC_BK].rx_mpdu = rand();
143     legacy_stats.iface.ac[legacy_hal::WIFI_AC_BK].tx_mpdu = rand();
144     legacy_stats.iface.ac[legacy_hal::WIFI_AC_BK].mpdu_lost = rand();
145     legacy_stats.iface.ac[legacy_hal::WIFI_AC_BK].retries = rand();
146 
147     legacy_stats.iface.ac[legacy_hal::WIFI_AC_VI].rx_mpdu = rand();
148     legacy_stats.iface.ac[legacy_hal::WIFI_AC_VI].tx_mpdu = rand();
149     legacy_stats.iface.ac[legacy_hal::WIFI_AC_VI].mpdu_lost = rand();
150     legacy_stats.iface.ac[legacy_hal::WIFI_AC_VI].retries = rand();
151 
152     legacy_stats.iface.ac[legacy_hal::WIFI_AC_VO].rx_mpdu = rand();
153     legacy_stats.iface.ac[legacy_hal::WIFI_AC_VO].tx_mpdu = rand();
154     legacy_stats.iface.ac[legacy_hal::WIFI_AC_VO].mpdu_lost = rand();
155     legacy_stats.iface.ac[legacy_hal::WIFI_AC_VO].retries = rand();
156 
157     for (auto& radio : legacy_stats.radios) {
158         radio.stats.on_time = rand();
159         radio.stats.tx_time = rand();
160         radio.stats.rx_time = rand();
161         radio.stats.on_time_scan = rand();
162         radio.stats.on_time_nbd = rand();
163         radio.stats.on_time_gscan = rand();
164         radio.stats.on_time_roam_scan = rand();
165         radio.stats.on_time_pno_scan = rand();
166         radio.stats.on_time_hs20 = rand();
167         for (int i = 0; i < 4; i++) {
168             radio.tx_time_per_levels.push_back(rand());
169         }
170 
171         legacy_hal::wifi_channel_stat channel_stat1 = {
172             .channel = {legacy_hal::WIFI_CHAN_WIDTH_20, 2437, 2437, 0},
173             .cca_busy_time = 0x55,
174             .on_time = 0x1111};
175         legacy_hal::wifi_channel_stat channel_stat2 = {
176             .channel = {legacy_hal::WIFI_CHAN_WIDTH_20, 5180, 5180, 0},
177             .cca_busy_time = 0x66,
178             .on_time = 0x2222};
179         radio.channel_stats.push_back(channel_stat1);
180         radio.channel_stats.push_back(channel_stat2);
181     }
182 
183     V1_3::StaLinkLayerStats converted{};
184     hidl_struct_util::convertLegacyLinkLayerStatsToHidl(legacy_stats,
185                                                         &converted);
186     EXPECT_EQ(legacy_stats.iface.beacon_rx, converted.iface.beaconRx);
187     EXPECT_EQ(legacy_stats.iface.rssi_mgmt, converted.iface.avgRssiMgmt);
188     EXPECT_EQ(legacy_stats.iface.ac[legacy_hal::WIFI_AC_BE].rx_mpdu,
189               converted.iface.wmeBePktStats.rxMpdu);
190     EXPECT_EQ(legacy_stats.iface.ac[legacy_hal::WIFI_AC_BE].tx_mpdu,
191               converted.iface.wmeBePktStats.txMpdu);
192     EXPECT_EQ(legacy_stats.iface.ac[legacy_hal::WIFI_AC_BE].mpdu_lost,
193               converted.iface.wmeBePktStats.lostMpdu);
194     EXPECT_EQ(legacy_stats.iface.ac[legacy_hal::WIFI_AC_BE].retries,
195               converted.iface.wmeBePktStats.retries);
196 
197     EXPECT_EQ(legacy_stats.iface.ac[legacy_hal::WIFI_AC_BK].rx_mpdu,
198               converted.iface.wmeBkPktStats.rxMpdu);
199     EXPECT_EQ(legacy_stats.iface.ac[legacy_hal::WIFI_AC_BK].tx_mpdu,
200               converted.iface.wmeBkPktStats.txMpdu);
201     EXPECT_EQ(legacy_stats.iface.ac[legacy_hal::WIFI_AC_BK].mpdu_lost,
202               converted.iface.wmeBkPktStats.lostMpdu);
203     EXPECT_EQ(legacy_stats.iface.ac[legacy_hal::WIFI_AC_BK].retries,
204               converted.iface.wmeBkPktStats.retries);
205 
206     EXPECT_EQ(legacy_stats.iface.ac[legacy_hal::WIFI_AC_VI].rx_mpdu,
207               converted.iface.wmeViPktStats.rxMpdu);
208     EXPECT_EQ(legacy_stats.iface.ac[legacy_hal::WIFI_AC_VI].tx_mpdu,
209               converted.iface.wmeViPktStats.txMpdu);
210     EXPECT_EQ(legacy_stats.iface.ac[legacy_hal::WIFI_AC_VI].mpdu_lost,
211               converted.iface.wmeViPktStats.lostMpdu);
212     EXPECT_EQ(legacy_stats.iface.ac[legacy_hal::WIFI_AC_VI].retries,
213               converted.iface.wmeViPktStats.retries);
214 
215     EXPECT_EQ(legacy_stats.iface.ac[legacy_hal::WIFI_AC_VO].rx_mpdu,
216               converted.iface.wmeVoPktStats.rxMpdu);
217     EXPECT_EQ(legacy_stats.iface.ac[legacy_hal::WIFI_AC_VO].tx_mpdu,
218               converted.iface.wmeVoPktStats.txMpdu);
219     EXPECT_EQ(legacy_stats.iface.ac[legacy_hal::WIFI_AC_VO].mpdu_lost,
220               converted.iface.wmeVoPktStats.lostMpdu);
221     EXPECT_EQ(legacy_stats.iface.ac[legacy_hal::WIFI_AC_VO].retries,
222               converted.iface.wmeVoPktStats.retries);
223 
224     EXPECT_EQ(legacy_stats.radios.size(), converted.radios.size());
225     for (size_t i = 0; i < legacy_stats.radios.size(); i++) {
226         EXPECT_EQ(legacy_stats.radios[i].stats.on_time,
227                   converted.radios[i].V1_0.onTimeInMs);
228         EXPECT_EQ(legacy_stats.radios[i].stats.tx_time,
229                   converted.radios[i].V1_0.txTimeInMs);
230         EXPECT_EQ(legacy_stats.radios[i].stats.rx_time,
231                   converted.radios[i].V1_0.rxTimeInMs);
232         EXPECT_EQ(legacy_stats.radios[i].stats.on_time_scan,
233                   converted.radios[i].V1_0.onTimeInMsForScan);
234         EXPECT_EQ(legacy_stats.radios[i].tx_time_per_levels.size(),
235                   converted.radios[i].V1_0.txTimeInMsPerLevel.size());
236         for (size_t j = 0; j < legacy_stats.radios[i].tx_time_per_levels.size();
237              j++) {
238             EXPECT_EQ(legacy_stats.radios[i].tx_time_per_levels[j],
239                       converted.radios[i].V1_0.txTimeInMsPerLevel[j]);
240         }
241         EXPECT_EQ(legacy_stats.radios[i].stats.on_time_nbd,
242                   converted.radios[i].onTimeInMsForNanScan);
243         EXPECT_EQ(legacy_stats.radios[i].stats.on_time_gscan,
244                   converted.radios[i].onTimeInMsForBgScan);
245         EXPECT_EQ(legacy_stats.radios[i].stats.on_time_roam_scan,
246                   converted.radios[i].onTimeInMsForRoamScan);
247         EXPECT_EQ(legacy_stats.radios[i].stats.on_time_pno_scan,
248                   converted.radios[i].onTimeInMsForPnoScan);
249         EXPECT_EQ(legacy_stats.radios[i].stats.on_time_hs20,
250                   converted.radios[i].onTimeInMsForHs20Scan);
251         EXPECT_EQ(legacy_stats.radios[i].channel_stats.size(),
252                   converted.radios[i].channelStats.size());
253         for (size_t k = 0; k < legacy_stats.radios[i].channel_stats.size();
254              k++) {
255             auto& legacy_channel_st = legacy_stats.radios[i].channel_stats[k];
256             EXPECT_EQ(WifiChannelWidthInMhz::WIDTH_20,
257                       converted.radios[i].channelStats[k].channel.width);
258             EXPECT_EQ(WifiChannelInMhz(legacy_channel_st.channel.center_freq),
259                       converted.radios[i].channelStats[k].channel.centerFreq);
260             EXPECT_EQ(WifiChannelInMhz(legacy_channel_st.channel.center_freq0),
261                       converted.radios[i].channelStats[k].channel.centerFreq0);
262             EXPECT_EQ(WifiChannelInMhz(legacy_channel_st.channel.center_freq1),
263                       converted.radios[i].channelStats[k].channel.centerFreq1);
264             EXPECT_EQ(legacy_channel_st.cca_busy_time,
265                       converted.radios[i].channelStats[k].ccaBusyTimeInMs);
266             EXPECT_EQ(legacy_channel_st.on_time,
267                       converted.radios[i].channelStats[k].onTimeInMs);
268         }
269     }
270 }
271 
TEST_F(HidlStructUtilTest,CanConvertLegacyFeaturesToHidl)272 TEST_F(HidlStructUtilTest, CanConvertLegacyFeaturesToHidl) {
273     using HidlChipCaps = V1_3::IWifiChip::ChipCapabilityMask;
274 
275     uint32_t hidle_caps;
276 
277     uint32_t legacy_feature_set =
278             WIFI_FEATURE_D2D_RTT | WIFI_FEATURE_SET_LATENCY_MODE;
279     uint32_t legacy_logger_feature_set =
280             legacy_hal::WIFI_LOGGER_DRIVER_DUMP_SUPPORTED;
281 
282     ASSERT_TRUE(hidl_struct_util::convertLegacyFeaturesToHidlChipCapabilities(
283         legacy_feature_set, legacy_logger_feature_set, &hidle_caps));
284 
285     EXPECT_EQ(HidlChipCaps::DEBUG_RING_BUFFER_VENDOR_DATA |
286                   HidlChipCaps::DEBUG_HOST_WAKE_REASON_STATS |
287                   HidlChipCaps::DEBUG_ERROR_ALERTS | HidlChipCaps::D2D_RTT |
288                   HidlChipCaps::SET_LATENCY_MODE |
289                   HidlChipCaps::DEBUG_MEMORY_DRIVER_DUMP,
290               hidle_caps);
291 }
292 }  // namespace implementation
293 }  // namespace V1_3
294 }  // namespace wifi
295 }  // namespace hardware
296 }  // namespace android
297