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 <VtsHalHidlTargetTestBase.h>
20 
21 #include <android/hardware/wifi/supplicant/1.0/ISupplicant.h>
22 
23 #include "supplicant_hidl_test_utils.h"
24 
25 using ::android::sp;
26 using ::android::hardware::hidl_vec;
27 using ::android::hardware::wifi::supplicant::V1_0::ISupplicant;
28 using ::android::hardware::wifi::supplicant::V1_0::ISupplicantIface;
29 using ::android::hardware::wifi::supplicant::V1_0::SupplicantStatus;
30 using ::android::hardware::wifi::supplicant::V1_0::SupplicantStatusCode;
31 using ::android::hardware::wifi::supplicant::V1_0::IfaceType;
32 
33 class SupplicantHidlTest : public ::testing::VtsHalHidlTargetTestBase {
34    public:
SetUp()35     virtual void SetUp() override {
36         startSupplicantAndWaitForHidlService();
37         supplicant_ = getSupplicant();
38         ASSERT_NE(supplicant_.get(), nullptr);
39     }
40 
TearDown()41     virtual void TearDown() override { stopSupplicant(); }
42 
43    protected:
44     // ISupplicant object used for all tests in this fixture.
45     sp<ISupplicant> supplicant_;
46 };
47 
48 /*
49  * Create:
50  * Ensures that an instance of the ISupplicant proxy object is
51  * successfully created.
52  */
TEST(SupplicantHidlTestNoFixture,Create)53 TEST(SupplicantHidlTestNoFixture, Create) {
54     startSupplicantAndWaitForHidlService();
55     EXPECT_NE(nullptr, getSupplicant().get());
56     stopSupplicant();
57 }
58 
59 /*
60  * ListInterfaces
61  */
TEST_F(SupplicantHidlTest,ListInterfaces)62 TEST_F(SupplicantHidlTest, ListInterfaces) {
63     std::vector<ISupplicant::IfaceInfo> ifaces;
64     supplicant_->listInterfaces(
65         [&](const SupplicantStatus& status,
66             const hidl_vec<ISupplicant::IfaceInfo>& hidl_ifaces) {
67             EXPECT_EQ(SupplicantStatusCode::SUCCESS, status.code);
68             ifaces = hidl_ifaces;
69         });
70 
71     EXPECT_NE(ifaces.end(),
72               std::find_if(ifaces.begin(), ifaces.end(), [](const auto& iface) {
73                   return iface.type == IfaceType::STA;
74               }));
75     EXPECT_NE(ifaces.end(),
76               std::find_if(ifaces.begin(), ifaces.end(), [](const auto& iface) {
77                   return iface.type == IfaceType::P2P;
78               }));
79 }
80 
81 /*
82  * GetInterface
83  */
TEST_F(SupplicantHidlTest,GetInterface)84 TEST_F(SupplicantHidlTest, GetInterface) {
85     std::vector<ISupplicant::IfaceInfo> ifaces;
86     supplicant_->listInterfaces(
87         [&](const SupplicantStatus& status,
88             const hidl_vec<ISupplicant::IfaceInfo>& hidl_ifaces) {
89             EXPECT_EQ(SupplicantStatusCode::SUCCESS, status.code);
90             ifaces = hidl_ifaces;
91         });
92 
93     ASSERT_NE(0u, ifaces.size());
94     supplicant_->getInterface(
95         ifaces[0],
96         [&](const SupplicantStatus& status, const sp<ISupplicantIface>& iface) {
97             EXPECT_EQ(SupplicantStatusCode::SUCCESS, status.code);
98             EXPECT_NE(nullptr, iface.get());
99         });
100 }
101 
102 /*
103  * SetDebugParams
104  */
TEST_F(SupplicantHidlTest,SetDebugParams)105 TEST_F(SupplicantHidlTest, SetDebugParams) {
106     bool show_timestamp = true;
107     bool show_keys = true;
108     ISupplicant::DebugLevel level = ISupplicant::DebugLevel::EXCESSIVE;
109 
110     supplicant_->setDebugParams(level,
111                                 show_timestamp,  // show timestamps
112                                 show_keys,       // show keys
113                                 [](const SupplicantStatus& status) {
114                                     EXPECT_EQ(SupplicantStatusCode::SUCCESS,
115                                               status.code);
116                                 });
117 }
118 
119 /*
120  * GetDebugLevel
121  */
TEST_F(SupplicantHidlTest,GetDebugLevel)122 TEST_F(SupplicantHidlTest, GetDebugLevel) {
123     bool show_timestamp = true;
124     bool show_keys = true;
125     ISupplicant::DebugLevel level = ISupplicant::DebugLevel::EXCESSIVE;
126 
127     supplicant_->setDebugParams(level,
128                                 show_timestamp,  // show timestamps
129                                 show_keys,       // show keys
130                                 [](const SupplicantStatus& status) {
131                                     EXPECT_EQ(SupplicantStatusCode::SUCCESS,
132                                               status.code);
133                                 });
134     EXPECT_EQ(level, supplicant_->getDebugLevel());
135 }
136 
137 /*
138  * IsDebugShowTimestampEnabled
139  */
TEST_F(SupplicantHidlTest,IsDebugShowTimestampEnabled)140 TEST_F(SupplicantHidlTest, IsDebugShowTimestampEnabled) {
141     bool show_timestamp = true;
142     bool show_keys = true;
143     ISupplicant::DebugLevel level = ISupplicant::DebugLevel::EXCESSIVE;
144 
145     supplicant_->setDebugParams(level,
146                                 show_timestamp,  // show timestamps
147                                 show_keys,       // show keys
148                                 [](const SupplicantStatus& status) {
149                                     EXPECT_EQ(SupplicantStatusCode::SUCCESS,
150                                               status.code);
151                                 });
152     EXPECT_EQ(show_timestamp, supplicant_->isDebugShowTimestampEnabled());
153 }
154 
155 /*
156  * IsDebugShowKeysEnabled
157  */
TEST_F(SupplicantHidlTest,IsDebugShowKeysEnabled)158 TEST_F(SupplicantHidlTest, IsDebugShowKeysEnabled) {
159     bool show_timestamp = true;
160     bool show_keys = true;
161     ISupplicant::DebugLevel level = ISupplicant::DebugLevel::EXCESSIVE;
162 
163     supplicant_->setDebugParams(level,
164                                 show_timestamp,  // show timestamps
165                                 show_keys,       // show keys
166                                 [](const SupplicantStatus& status) {
167                                     EXPECT_EQ(SupplicantStatusCode::SUCCESS,
168                                               status.code);
169                                 });
170     EXPECT_EQ(show_keys, supplicant_->isDebugShowKeysEnabled());
171 }
172 
173 /*
174  * SetConcurrenyPriority
175  */
TEST_F(SupplicantHidlTest,SetConcurrencyPriority)176 TEST_F(SupplicantHidlTest, SetConcurrencyPriority) {
177     supplicant_->setConcurrencyPriority(
178         IfaceType::STA, [](const SupplicantStatus& status) {
179             EXPECT_EQ(SupplicantStatusCode::SUCCESS, status.code);
180         });
181     supplicant_->setConcurrencyPriority(
182         IfaceType::P2P, [](const SupplicantStatus& status) {
183             EXPECT_EQ(SupplicantStatusCode::SUCCESS, status.code);
184         });
185 }
186