• 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 #include <cutils/properties.h>
19 
20 #include <VtsCoreUtil.h>
21 #include <android/hardware/wifi/1.0/IWifi.h>
22 #include <android/hardware/wifi/supplicant/1.0/types.h>
23 #include <android/hardware/wifi/supplicant/1.1/ISupplicant.h>
24 #include <hidl/GtestPrinter.h>
25 #include <hidl/ServiceManagement.h>
26 
27 #include "supplicant_hidl_test_utils.h"
28 #include "supplicant_hidl_test_utils_1_1.h"
29 
30 using ::android::hardware::hidl_vec;
31 using ::android::hardware::wifi::supplicant::V1_0::ISupplicantIface;
32 using ::android::hardware::wifi::supplicant::V1_0::SupplicantStatus;
33 using ::android::hardware::wifi::supplicant::V1_0::SupplicantStatusCode;
34 using ::android::hardware::wifi::supplicant::V1_0::IfaceType;
35 using ::android::hardware::wifi::supplicant::V1_1::ISupplicant;
36 using ::android::sp;
37 
38 class SupplicantHidlTest : public SupplicantHidlTestBase {
39    public:
SetUp()40     virtual void SetUp() override { SupplicantHidlTestBase::SetUp(); }
41 
42    protected:
getWlan0IfaceName()43     std::string getWlan0IfaceName() {
44         std::array<char, PROPERTY_VALUE_MAX> buffer;
45         property_get("wifi.interface", buffer.data(), "wlan0");
46         return buffer.data();
47     }
48 
getP2pIfaceName()49     std::string getP2pIfaceName() {
50         std::array<char, PROPERTY_VALUE_MAX> buffer;
51         property_get("wifi.direct.interface", buffer.data(), "p2p0");
52         return buffer.data();
53     }
54 };
55 
56 /*
57  * AddStaInterface
58  */
TEST_P(SupplicantHidlTest,AddStaInterface)59 TEST_P(SupplicantHidlTest, AddStaInterface) {
60     ISupplicant::IfaceInfo iface_info;
61     iface_info.name = getWlan0IfaceName();
62     iface_info.type = IfaceType::STA;
63     supplicant_->addInterface(
64         iface_info,
65         [&](const SupplicantStatus& status, const sp<ISupplicantIface>& iface) {
66             EXPECT_TRUE(
67                 (status.code == SupplicantStatusCode::SUCCESS) ||
68                 (status.code == SupplicantStatusCode::FAILURE_IFACE_EXISTS));
69             EXPECT_NE(nullptr, iface.get());
70         });
71 }
72 
73 /*
74  * AddP2pInterface
75  */
TEST_P(SupplicantHidlTest,AddP2pInterface)76 TEST_P(SupplicantHidlTest, AddP2pInterface) {
77     if (isP2pOn_) return;
78     ISupplicant::IfaceInfo iface_info;
79     iface_info.name = getP2pIfaceName();
80     iface_info.type = IfaceType::P2P;
81     supplicant_->addInterface(
82         iface_info,
83         [&](const SupplicantStatus& status, const sp<ISupplicantIface>& iface) {
84             EXPECT_TRUE(
85                 (status.code == SupplicantStatusCode::SUCCESS) ||
86                 (status.code == SupplicantStatusCode::FAILURE_IFACE_EXISTS));
87             EXPECT_NE(nullptr, iface.get());
88         });
89 }
90 
91 /*
92  * RemoveStaInterface
93  */
TEST_P(SupplicantHidlTest,RemoveStaInterface)94 TEST_P(SupplicantHidlTest, RemoveStaInterface) {
95     ISupplicant::IfaceInfo iface_info;
96     iface_info.name = getWlan0IfaceName();
97     iface_info.type = IfaceType::STA;
98 
99     supplicant_->addInterface(
100         iface_info,
101         [&](const SupplicantStatus& status, const sp<ISupplicantIface>& iface) {
102             EXPECT_TRUE(
103                 (status.code == SupplicantStatusCode::SUCCESS) ||
104                 (status.code == SupplicantStatusCode::FAILURE_IFACE_EXISTS));
105             EXPECT_NE(nullptr, iface.get());
106         });
107     supplicant_->removeInterface(
108         iface_info, [&](const SupplicantStatus& status) {
109             EXPECT_EQ(SupplicantStatusCode::SUCCESS, status.code);
110         });
111 }
112 
113 /*
114  * RemoveP2pInterface
115  */
TEST_P(SupplicantHidlTest,RemoveP2pInterface)116 TEST_P(SupplicantHidlTest, RemoveP2pInterface) {
117     if (isP2pOn_) return;
118     ISupplicant::IfaceInfo iface_info;
119     iface_info.name = getP2pIfaceName();
120     iface_info.type = IfaceType::P2P;
121 
122     supplicant_->addInterface(
123         iface_info,
124         [&](const SupplicantStatus& status, const sp<ISupplicantIface>& iface) {
125             EXPECT_TRUE(
126                 (status.code == SupplicantStatusCode::SUCCESS) ||
127                 (status.code == SupplicantStatusCode::FAILURE_IFACE_EXISTS));
128             EXPECT_NE(nullptr, iface.get());
129         });
130     supplicant_->removeInterface(
131         iface_info, [&](const SupplicantStatus& status) {
132             EXPECT_EQ(SupplicantStatusCode::SUCCESS, status.code);
133         });
134 }
135 
136 /*
137  * Terminate
138  * This terminates the service.
139  */
TEST_P(SupplicantHidlTest,Terminate)140 TEST_P(SupplicantHidlTest, Terminate) { supplicant_->terminate(); }
141 
get_wifi_instances()142 static std::vector<std::string> get_wifi_instances() {
143     std::vector<std::string> instances =
144         android::hardware::getAllHalInstanceNames(
145             android::hardware::wifi::V1_0::IWifi::descriptor);
146     // Also test when wifi instance is not set.
147     instances.push_back("");
148 
149     return instances;
150 }
151 
152 INSTANTIATE_TEST_CASE_P(
153     PerInstance, SupplicantHidlTest,
154     testing::Combine(
155         testing::ValuesIn(get_wifi_instances()),
156         testing::ValuesIn(android::hardware::getAllHalInstanceNames(
157             android::hardware::wifi::supplicant::V1_1::ISupplicant::
158                 descriptor))),
159     android::hardware::PrintInstanceTupleNameToString<>);
160