• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
1 /*
2  * Copyright (C) 2018 The Android Open Source Project
3  *
4  * Licensed under the Staache 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 <numeric>
18 #include <vector>
19 
20 #include <android-base/logging.h>
21 
22 #include <android/hardware/wifi/1.3/IWifi.h>
23 #include <android/hardware/wifi/1.3/IWifiStaIface.h>
24 #include <gtest/gtest.h>
25 #include <hidl/GtestPrinter.h>
26 #include <hidl/ServiceManagement.h>
27 
28 #include "wifi_hidl_call_util.h"
29 #include "wifi_hidl_test_utils.h"
30 
31 using ::android::sp;
32 using ::android::hardware::hidl_array;
33 using ::android::hardware::wifi::V1_0::WifiStatus;
34 using ::android::hardware::wifi::V1_0::WifiStatusCode;
35 using ::android::hardware::wifi::V1_3::IWifiStaIface;
36 
37 /**
38  * Fixture to use for all STA Iface HIDL interface tests.
39  */
40 class WifiStaIfaceHidlTest : public ::testing::TestWithParam<std::string> {
41    public:
SetUp()42     virtual void SetUp() override {
43         // Make sure to start with a clean state
44         stopWifi(GetInstanceName());
45 
46         wifi_sta_iface_ =
47             IWifiStaIface::castFrom(getWifiStaIface(GetInstanceName()));
48         ASSERT_NE(nullptr, wifi_sta_iface_.get());
49     }
50 
TearDown()51     virtual void TearDown() override { stopWifi(GetInstanceName()); }
52 
53    protected:
isCapabilitySupported(IWifiStaIface::StaIfaceCapabilityMask cap_mask)54     bool isCapabilitySupported(IWifiStaIface::StaIfaceCapabilityMask cap_mask) {
55         const auto& status_and_caps =
56             HIDL_INVOKE(wifi_sta_iface_, getCapabilities);
57         EXPECT_EQ(WifiStatusCode::SUCCESS, status_and_caps.first.code);
58         return (status_and_caps.second & cap_mask) != 0;
59     }
60 
61     sp<IWifiStaIface> wifi_sta_iface_;
62 
63    private:
GetInstanceName()64     std::string GetInstanceName() { return GetParam(); }
65 };
66 
67 /*
68  * GetFactoryMacAddress:
69  * Ensures that calls to get factory MAC address will retrieve a non-zero MAC
70  * and return a success status code.
71  */
TEST_P(WifiStaIfaceHidlTest,GetFactoryMacAddress)72 TEST_P(WifiStaIfaceHidlTest, GetFactoryMacAddress) {
73     std::pair<WifiStatus, hidl_array<uint8_t, 6> > status_and_mac =
74         HIDL_INVOKE(wifi_sta_iface_, getFactoryMacAddress);
75     EXPECT_EQ(WifiStatusCode::SUCCESS, status_and_mac.first.code);
76     hidl_array<uint8_t, 6> all_zero{};
77     EXPECT_NE(all_zero, status_and_mac.second);
78 }
79 
80 /*
81  * GetLinkLayerStats_1_3
82  * Ensures that calls to get link layer stats V1_3 will retrieve a non-empty
83  * StaLinkLayerStats after link layer stats collection is enabled.
84  */
TEST_P(WifiStaIfaceHidlTest,GetLinkLayerStats_1_3)85 TEST_P(WifiStaIfaceHidlTest, GetLinkLayerStats_1_3) {
86     if (!isCapabilitySupported(
87             IWifiStaIface::StaIfaceCapabilityMask::LINK_LAYER_STATS)) {
88         // No-op if link layer stats is not supported.
89         return;
90     }
91 
92     // Enable link layer stats collection.
93     EXPECT_EQ(WifiStatusCode::SUCCESS,
94               HIDL_INVOKE(wifi_sta_iface_, enableLinkLayerStatsCollection, true)
95                   .code);
96     // Retrieve link layer stats.
97     const auto& status_and_stats =
98         HIDL_INVOKE(wifi_sta_iface_, getLinkLayerStats_1_3);
99     EXPECT_EQ(WifiStatusCode::SUCCESS, status_and_stats.first.code);
100     EXPECT_GT(status_and_stats.second.timeStampInMs, 0u);
101     // Disable link layer stats collection.
102     EXPECT_EQ(
103         WifiStatusCode::SUCCESS,
104         HIDL_INVOKE(wifi_sta_iface_, disableLinkLayerStatsCollection).code);
105 }
106 
107 INSTANTIATE_TEST_SUITE_P(
108     PerInstance, WifiStaIfaceHidlTest,
109     testing::ValuesIn(android::hardware::getAllHalInstanceNames(
110         ::android::hardware::wifi::V1_3::IWifi::descriptor)),
111     android::hardware::PrintInstanceNameToString);
112