• 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 <android/hardware/wifi/1.0/IWifi.h>
19 #include <android/hardware/wifi/1.0/IWifiApIface.h>
20 #include <android/hardware/wifi/hostapd/1.0/IHostapd.h>
21 #include <gtest/gtest.h>
22 #include <hidl/GtestPrinter.h>
23 #include <hidl/ServiceManagement.h>
24 
25 #include "wifi_hidl_call_util.h"
26 #include "wifi_hidl_test_utils.h"
27 
28 using ::android::sp;
29 using ::android::hardware::wifi::hostapd::V1_0::IHostapd;
30 using ::android::hardware::wifi::V1_0::IfaceType;
31 using ::android::hardware::wifi::V1_0::IWifi;
32 using ::android::hardware::wifi::V1_0::IWifiApIface;
33 using ::android::hardware::wifi::V1_0::WifiBand;
34 using ::android::hardware::wifi::V1_0::WifiStatusCode;
35 
36 /**
37  * Fixture to use for all AP Iface HIDL interface tests.
38  */
39 class WifiApIfaceHidlTest : public ::testing::TestWithParam<std::string> {
40    public:
SetUp()41     virtual void SetUp() override {
42         if (android::hardware::getAllHalInstanceNames(IHostapd::descriptor)
43                 .empty()) {
44             GTEST_SKIP() << "Device does not support AP";
45         }
46         // Make sure test starts with a clean state
47         stopWifi(GetInstanceName());
48 
49         wifi_ap_iface_ = getWifiApIface(GetInstanceName());
50         ASSERT_NE(nullptr, wifi_ap_iface_.get());
51     }
52 
TearDown()53     virtual void TearDown() override { stopWifi(GetInstanceName()); }
54 
55    protected:
56     sp<IWifiApIface> wifi_ap_iface_;
GetInstanceName()57     std::string GetInstanceName() { return GetParam(); }
58 };
59 
60 /*
61  * Create:
62  * Ensures that an instance of the IWifiApIface proxy object is
63  * successfully created.
64  */
TEST_P(WifiApIfaceHidlTest,Create)65 TEST_P(WifiApIfaceHidlTest, Create) {
66     // The creation of a proxy object is tested as part of SetUp method.
67 }
68 
69 /*
70  * GetType:
71  * Ensures that the correct interface type is returned for AP interface.
72  */
TEST_P(WifiApIfaceHidlTest,GetType)73 TEST_P(WifiApIfaceHidlTest, GetType) {
74     const auto& status_and_type = HIDL_INVOKE(wifi_ap_iface_, getType);
75     EXPECT_EQ(WifiStatusCode::SUCCESS, status_and_type.first.code);
76     EXPECT_EQ(IfaceType::AP, status_and_type.second);
77 }
78 
79 /*
80  * SetCountryCode:
81  * Ensures that a call to set the country code will return with a success
82  * status code.
83  */
TEST_P(WifiApIfaceHidlTest,SetCountryCode)84 TEST_P(WifiApIfaceHidlTest, SetCountryCode) {
85     const android::hardware::hidl_array<int8_t, 2> kCountryCode{
86         std::array<int8_t, 2>{{0x55, 0x53}}};
87     EXPECT_EQ(WifiStatusCode::SUCCESS,
88               HIDL_INVOKE(wifi_ap_iface_, setCountryCode, kCountryCode).code);
89 }
90 
91 /*
92  * GetValidFrequenciesForBand:
93  * Ensures that we can retrieve valid frequencies for 2.4 GHz band.
94  */
TEST_P(WifiApIfaceHidlTest,GetValidFrequenciesForBand)95 TEST_P(WifiApIfaceHidlTest, GetValidFrequenciesForBand) {
96     const auto& status_and_freqs = HIDL_INVOKE(
97         wifi_ap_iface_, getValidFrequenciesForBand, WifiBand::BAND_24GHZ);
98     EXPECT_EQ(WifiStatusCode::SUCCESS, status_and_freqs.first.code);
99     EXPECT_GT(status_and_freqs.second.size(), 0u);
100 }
101 
102 GTEST_ALLOW_UNINSTANTIATED_PARAMETERIZED_TEST(WifiApIfaceHidlTest);
103 INSTANTIATE_TEST_SUITE_P(
104     PerInstance, WifiApIfaceHidlTest,
105     testing::ValuesIn(
106         android::hardware::getAllHalInstanceNames(IWifi::descriptor)),
107     android::hardware::PrintInstanceNameToString);
108