• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
1 /*
2  * Copyright (C) 2016 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 
19 #include <VtsCoreUtil.h>
20 #include <android/hardware/wifi/1.0/IWifi.h>
21 #include <android/hardware/wifi/supplicant/1.0/ISupplicant.h>
22 #include <gtest/gtest.h>
23 #include <hidl/GtestPrinter.h>
24 #include <hidl/ServiceManagement.h>
25 
26 #include "supplicant_hidl_test_utils.h"
27 
28 using ::android::sp;
29 using ::android::hardware::hidl_vec;
30 using ::android::hardware::wifi::supplicant::V1_0::IfaceType;
31 using ::android::hardware::wifi::supplicant::V1_0::ISupplicant;
32 using ::android::hardware::wifi::supplicant::V1_0::ISupplicantIface;
33 using ::android::hardware::wifi::supplicant::V1_0::SupplicantStatus;
34 using ::android::hardware::wifi::supplicant::V1_0::SupplicantStatusCode;
35 using ::android::hardware::wifi::V1_0::IWifi;
36 
37 class SupplicantHidlTest
38     : public ::testing::TestWithParam<std::tuple<std::string, std::string>> {
39    public:
SetUp()40     virtual void SetUp() override {
41         wifi_instance_name_ = std::get<0>(GetParam());
42         supplicant_instance_name_ = std::get<1>(GetParam());
43 
44         // Stop & wait for wifi to shutdown.
45         ASSERT_TRUE(stopWifiFramework(wifi_instance_name_));
46 
47         std::system("/system/bin/start");
48         ASSERT_TRUE(waitForFrameworkReady());
49         isP2pOn_ =
50             testing::deviceSupportsFeature("android.hardware.wifi.direct");
51         stopSupplicant(wifi_instance_name_);
52         startSupplicantAndWaitForHidlService(wifi_instance_name_,
53                                              supplicant_instance_name_);
54         supplicant_ = getSupplicant(supplicant_instance_name_, isP2pOn_);
55         ASSERT_NE(supplicant_.get(), nullptr);
56     }
57 
TearDown()58     virtual void TearDown() override {
59         stopSupplicant(wifi_instance_name_);
60         // Start Wi-Fi
61         startWifiFramework();
62     }
63 
64    protected:
65     // ISupplicant object used for all tests in this fixture.
66     sp<ISupplicant> supplicant_;
67     bool isP2pOn_ = false;
68     std::string wifi_instance_name_;
69     std::string supplicant_instance_name_;
70 };
71 
72 /*
73  * Create:
74  * Ensures that an instance of the ISupplicant proxy object is
75  * successfully created.
76  */
TEST_P(SupplicantHidlTest,Create)77 TEST_P(SupplicantHidlTest, Create) {
78     // Stop the proxy object created in setup.
79     stopSupplicant(wifi_instance_name_);
80     startSupplicantAndWaitForHidlService(wifi_instance_name_,
81                                          supplicant_instance_name_);
82     EXPECT_NE(nullptr,
83               getSupplicant(supplicant_instance_name_, isP2pOn_).get());
84 }
85 
86 /*
87  * ListInterfaces
88  */
TEST_P(SupplicantHidlTest,ListInterfaces)89 TEST_P(SupplicantHidlTest, ListInterfaces) {
90     std::vector<ISupplicant::IfaceInfo> ifaces;
91     supplicant_->listInterfaces(
92         [&](const SupplicantStatus& status,
93             const hidl_vec<ISupplicant::IfaceInfo>& hidl_ifaces) {
94             EXPECT_EQ(SupplicantStatusCode::SUCCESS, status.code);
95             ifaces = hidl_ifaces;
96         });
97 
98     EXPECT_NE(ifaces.end(),
99               std::find_if(ifaces.begin(), ifaces.end(), [](const auto& iface) {
100                   return iface.type == IfaceType::STA;
101               }));
102     if (isP2pOn_) {
103         EXPECT_NE(
104             ifaces.end(),
105             std::find_if(ifaces.begin(), ifaces.end(), [](const auto& iface) {
106                 return iface.type == IfaceType::P2P;
107             }));
108     }
109 }
110 
111 /*
112  * GetInterface
113  */
TEST_P(SupplicantHidlTest,GetInterface)114 TEST_P(SupplicantHidlTest, GetInterface) {
115     std::vector<ISupplicant::IfaceInfo> ifaces;
116     supplicant_->listInterfaces(
117         [&](const SupplicantStatus& status,
118             const hidl_vec<ISupplicant::IfaceInfo>& hidl_ifaces) {
119             EXPECT_EQ(SupplicantStatusCode::SUCCESS, status.code);
120             ifaces = hidl_ifaces;
121         });
122 
123     ASSERT_NE(0u, ifaces.size());
124     supplicant_->getInterface(
125         ifaces[0],
126         [&](const SupplicantStatus& status, const sp<ISupplicantIface>& iface) {
127             EXPECT_EQ(SupplicantStatusCode::SUCCESS, status.code);
128             EXPECT_NE(nullptr, iface.get());
129         });
130 }
131 
132 /*
133  * SetDebugParams
134  */
TEST_P(SupplicantHidlTest,SetDebugParams)135 TEST_P(SupplicantHidlTest, SetDebugParams) {
136     bool show_timestamp = true;
137     bool show_keys = true;
138     ISupplicant::DebugLevel level = ISupplicant::DebugLevel::EXCESSIVE;
139 
140     supplicant_->setDebugParams(level,
141                                 show_timestamp,  // show timestamps
142                                 show_keys,       // show keys
143                                 [](const SupplicantStatus& status) {
144                                     EXPECT_EQ(SupplicantStatusCode::SUCCESS,
145                                               status.code);
146                                 });
147 }
148 
149 /*
150  * GetDebugLevel
151  */
TEST_P(SupplicantHidlTest,GetDebugLevel)152 TEST_P(SupplicantHidlTest, GetDebugLevel) {
153     bool show_timestamp = true;
154     bool show_keys = true;
155     ISupplicant::DebugLevel level = ISupplicant::DebugLevel::EXCESSIVE;
156 
157     supplicant_->setDebugParams(level,
158                                 show_timestamp,  // show timestamps
159                                 show_keys,       // show keys
160                                 [](const SupplicantStatus& status) {
161                                     EXPECT_EQ(SupplicantStatusCode::SUCCESS,
162                                               status.code);
163                                 });
164     EXPECT_EQ(level, supplicant_->getDebugLevel());
165 }
166 
167 /*
168  * IsDebugShowTimestampEnabled
169  */
TEST_P(SupplicantHidlTest,IsDebugShowTimestampEnabled)170 TEST_P(SupplicantHidlTest, IsDebugShowTimestampEnabled) {
171     bool show_timestamp = true;
172     bool show_keys = true;
173     ISupplicant::DebugLevel level = ISupplicant::DebugLevel::EXCESSIVE;
174 
175     supplicant_->setDebugParams(level,
176                                 show_timestamp,  // show timestamps
177                                 show_keys,       // show keys
178                                 [](const SupplicantStatus& status) {
179                                     EXPECT_EQ(SupplicantStatusCode::SUCCESS,
180                                               status.code);
181                                 });
182     EXPECT_EQ(show_timestamp, supplicant_->isDebugShowTimestampEnabled());
183 }
184 
185 /*
186  * IsDebugShowKeysEnabled
187  */
TEST_P(SupplicantHidlTest,IsDebugShowKeysEnabled)188 TEST_P(SupplicantHidlTest, IsDebugShowKeysEnabled) {
189     bool show_timestamp = true;
190     bool show_keys = true;
191     ISupplicant::DebugLevel level = ISupplicant::DebugLevel::EXCESSIVE;
192 
193     supplicant_->setDebugParams(level,
194                                 show_timestamp,  // show timestamps
195                                 show_keys,       // show keys
196                                 [](const SupplicantStatus& status) {
197                                     EXPECT_EQ(SupplicantStatusCode::SUCCESS,
198                                               status.code);
199                                 });
200     EXPECT_EQ(show_keys, supplicant_->isDebugShowKeysEnabled());
201 }
202 
203 /*
204  * SetConcurrenyPriority
205  */
TEST_P(SupplicantHidlTest,SetConcurrencyPriority)206 TEST_P(SupplicantHidlTest, SetConcurrencyPriority) {
207     supplicant_->setConcurrencyPriority(
208         IfaceType::STA, [](const SupplicantStatus& status) {
209             EXPECT_EQ(SupplicantStatusCode::SUCCESS, status.code);
210         });
211     if (isP2pOn_) {
212         supplicant_->setConcurrencyPriority(
213             IfaceType::P2P, [](const SupplicantStatus& status) {
214                 EXPECT_EQ(SupplicantStatusCode::SUCCESS, status.code);
215             });
216     }
217 }
218 
219 GTEST_ALLOW_UNINSTANTIATED_PARAMETERIZED_TEST(SupplicantHidlTest);
220 INSTANTIATE_TEST_CASE_P(
221     PerInstance, SupplicantHidlTest,
222     testing::Combine(
223         testing::ValuesIn(
224             android::hardware::getAllHalInstanceNames(IWifi::descriptor)),
225         testing::ValuesIn(android::hardware::getAllHalInstanceNames(
226             ISupplicant::descriptor))),
227     android::hardware::PrintInstanceTupleNameToString<>);
228