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