• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
1 /*
2  * Copyright (C) 2022 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 <vector>
18 
19 #include <VtsCoreUtil.h>
20 #include <aidl/Gtest.h>
21 #include <aidl/Vintf.h>
22 #include <aidl/android/hardware/wifi/BnWifi.h>
23 #include <android/binder_manager.h>
24 #include <android/binder_status.h>
25 #include <binder/IServiceManager.h>
26 #include <binder/ProcessState.h>
27 
28 #include "wifi_aidl_test_utils.h"
29 
30 using aidl::android::hardware::wifi::IWifiApIface;
31 using aidl::android::hardware::wifi::WifiBand;
32 
33 class WifiApIfaceAidlTest : public testing::TestWithParam<std::string> {
34   public:
SetUp()35     void SetUp() override {
36         isBridgedSupport_ = testing::checkSubstringInCommandOutput(
37                 "/system/bin/cmd wifi get-softap-supported-features",
38                 "wifi_softap_bridged_ap_supported");
39         stopWifiService(getInstanceName());
40     }
41 
TearDown()42     void TearDown() override { stopWifiService(getInstanceName()); }
43 
44   protected:
45     bool isBridgedSupport_ = false;
getInstanceName()46     const char* getInstanceName() { return GetParam().c_str(); }
47 };
48 
49 /*
50  * SetMacAddress
51  */
TEST_P(WifiApIfaceAidlTest,SetMacAddress)52 TEST_P(WifiApIfaceAidlTest, SetMacAddress) {
53     std::shared_ptr<IWifiApIface> wifi_ap_iface = getWifiApIface(getInstanceName());
54     ASSERT_NE(nullptr, wifi_ap_iface.get());
55     std::array<uint8_t, 6> mac = {0x12, 0x22, 0x33, 0x52, 0x10, 0x44};
56     EXPECT_TRUE(wifi_ap_iface->setMacAddress(mac).isOk());
57 }
58 
59 /*
60  * SetCountryCode
61  */
TEST_P(WifiApIfaceAidlTest,SetCountryCode)62 TEST_P(WifiApIfaceAidlTest, SetCountryCode) {
63     std::shared_ptr<IWifiApIface> wifi_ap_iface = getWifiApIface(getInstanceName());
64     ASSERT_NE(nullptr, wifi_ap_iface.get());
65 
66     const std::array<uint8_t, 2> country_code = {0x55, 0x53};
67     EXPECT_TRUE(wifi_ap_iface->setCountryCode(country_code).isOk());
68 }
69 
70 /*
71  * GetFactoryMacAddress
72  */
TEST_P(WifiApIfaceAidlTest,GetFactoryMacAddress)73 TEST_P(WifiApIfaceAidlTest, GetFactoryMacAddress) {
74     std::shared_ptr<IWifiApIface> wifi_ap_iface = getWifiApIface(getInstanceName());
75     ASSERT_NE(nullptr, wifi_ap_iface.get());
76 
77     std::array<uint8_t, 6> mac;
78     EXPECT_TRUE(wifi_ap_iface->getFactoryMacAddress(&mac).isOk());
79     std::array<uint8_t, 6> all_zero_mac = {0, 0, 0, 0, 0, 0};
80     EXPECT_NE(mac, all_zero_mac);
81 }
82 
83 /**
84  * GetBridgedInstances - non-bridged mode
85  */
TEST_P(WifiApIfaceAidlTest,GetBridgedInstances)86 TEST_P(WifiApIfaceAidlTest, GetBridgedInstances) {
87     std::shared_ptr<IWifiApIface> wifi_ap_iface = getWifiApIface(getInstanceName());
88     ASSERT_NE(nullptr, wifi_ap_iface.get());
89 
90     std::vector<std::string> instances;
91     EXPECT_TRUE(wifi_ap_iface->getBridgedInstances(&instances).isOk());
92     EXPECT_EQ(instances.size(), 0);
93 }
94 
95 /**
96  * GetBridgedInstances - bridged AP mode.
97  */
TEST_P(WifiApIfaceAidlTest,GetBridgedInstances_Bridged)98 TEST_P(WifiApIfaceAidlTest, GetBridgedInstances_Bridged) {
99     if (!isBridgedSupport_) {
100         GTEST_SKIP() << "Missing Bridged AP support";
101     }
102     std::shared_ptr<IWifiApIface> wifi_ap_iface = getBridgedWifiApIface(getInstanceName());
103     ASSERT_NE(nullptr, wifi_ap_iface.get());
104 
105     std::vector<std::string> instances;
106     EXPECT_TRUE(wifi_ap_iface->getBridgedInstances(&instances).isOk());
107     EXPECT_EQ(instances.size(), 2);
108 }
109 
110 /**
111  * ResetToFactoryMacAddress - non-bridged mode
112  */
TEST_P(WifiApIfaceAidlTest,ResetToFactoryMacAddress)113 TEST_P(WifiApIfaceAidlTest, ResetToFactoryMacAddress) {
114     std::shared_ptr<IWifiApIface> wifi_ap_iface = getWifiApIface(getInstanceName());
115     ASSERT_NE(nullptr, wifi_ap_iface.get());
116     EXPECT_TRUE(wifi_ap_iface->resetToFactoryMacAddress().isOk());
117 }
118 
119 /**
120  * ResetToFactoryMacAddress - bridged AP mode
121  */
TEST_P(WifiApIfaceAidlTest,ResetToFactoryMacAddress_Bridged)122 TEST_P(WifiApIfaceAidlTest, ResetToFactoryMacAddress_Bridged) {
123     if (!isBridgedSupport_) {
124         GTEST_SKIP() << "Missing Bridged AP support";
125     }
126     std::shared_ptr<IWifiApIface> wifi_ap_iface = getBridgedWifiApIface(getInstanceName());
127     ASSERT_NE(nullptr, wifi_ap_iface.get());
128     EXPECT_TRUE(wifi_ap_iface->resetToFactoryMacAddress().isOk());
129 }
130 
131 GTEST_ALLOW_UNINSTANTIATED_PARAMETERIZED_TEST(WifiApIfaceAidlTest);
132 INSTANTIATE_TEST_SUITE_P(WifiTest, WifiApIfaceAidlTest,
133                          testing::ValuesIn(android::getAidlHalInstanceNames(IWifi::descriptor)),
134                          android::PrintInstanceNameToString);
135 
main(int argc,char ** argv)136 int main(int argc, char** argv) {
137     ::testing::InitGoogleTest(&argc, argv);
138     android::ProcessState::self()->setThreadPoolMaxThreadCount(1);
139     android::ProcessState::self()->startThreadPool();
140     return RUN_ALL_TESTS();
141 }
142