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