• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
1 /*
2  * Copyright (C) 2019 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 <android/hardware/wifi/1.4/IWifi.h>
18 #include <android/hardware/wifi/1.4/IWifiApIface.h>
19 #include <gtest/gtest.h>
20 #include <hidl/GtestPrinter.h>
21 #include <hidl/ServiceManagement.h>
22 
23 #include "wifi_hidl_call_util.h"
24 #include "wifi_hidl_test_utils.h"
25 
26 using ::android::sp;
27 using ::android::hardware::hidl_array;
28 using ::android::hardware::wifi::V1_0::WifiStatus;
29 using ::android::hardware::wifi::V1_0::WifiStatusCode;
30 using ::android::hardware::wifi::V1_4::IWifi;
31 using ::android::hardware::wifi::V1_4::IWifiApIface;
32 
33 /**
34  * Fixture to use for all STA Iface HIDL interface tests.
35  */
36 class WifiApIfaceHidlTest : public ::testing::TestWithParam<std::string> {
37    public:
SetUp()38     virtual void SetUp() override {
39         // Make sure to start with a clean state
40         stopWifi(GetInstanceName());
41 
42         wifi_ap_iface_ =
43             IWifiApIface::castFrom(getWifiApIface(GetInstanceName()));
44         ASSERT_NE(nullptr, wifi_ap_iface_.get());
45     }
46 
TearDown()47     virtual void TearDown() override { stopWifi(GetInstanceName()); }
48 
49    protected:
50     sp<IWifiApIface> wifi_ap_iface_;
51 
52    private:
GetInstanceName()53     std::string GetInstanceName() { return GetParam(); }
54 };
55 
56 /*
57  * SetMacAddress:
58  * Ensures that calls to set MAC address will return a success status
59  * code.
60  */
TEST_P(WifiApIfaceHidlTest,SetMacAddress)61 TEST_P(WifiApIfaceHidlTest, SetMacAddress) {
62     const hidl_array<uint8_t, 6> kMac{{0x12, 0x22, 0x33, 0x52, 0x10, 0x44}};
63     EXPECT_EQ(WifiStatusCode::SUCCESS,
64               HIDL_INVOKE(wifi_ap_iface_, setMacAddress, kMac).code);
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(WifiApIfaceHidlTest,GetFactoryMacAddress)72 TEST_P(WifiApIfaceHidlTest, GetFactoryMacAddress) {
73     std::pair<WifiStatus, hidl_array<uint8_t, 6> > status_and_mac =
74         HIDL_INVOKE(wifi_ap_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 GTEST_ALLOW_UNINSTANTIATED_PARAMETERIZED_TEST(WifiApIfaceHidlTest);
81 INSTANTIATE_TEST_SUITE_P(
82     PerInstance, WifiApIfaceHidlTest,
83     testing::ValuesIn(
84         android::hardware::getAllHalInstanceNames(IWifi::descriptor)),
85     android::hardware::PrintInstanceNameToString);
86