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