• 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/IWifiApIface.h>
20 
21 #include <VtsHalHidlTargetTestBase.h>
22 
23 #include "wifi_hidl_call_util.h"
24 #include "wifi_hidl_test_utils.h"
25 
26 using ::android::hardware::wifi::V1_0::IfaceType;
27 using ::android::hardware::wifi::V1_0::IWifiApIface;
28 using ::android::hardware::wifi::V1_0::WifiBand;
29 using ::android::hardware::wifi::V1_0::WifiStatusCode;
30 using ::android::sp;
31 
32 extern WifiHidlEnvironment* gEnv;
33 
34 /**
35  * Fixture to use for all AP Iface HIDL interface tests.
36  */
37 class WifiApIfaceHidlTest : public ::testing::VtsHalHidlTargetTestBase {
38    public:
SetUp()39     virtual void SetUp() override {
40         if (!gEnv->isSoftApOn) return;
41         wifi_ap_iface_ = getWifiApIface();
42         ASSERT_NE(nullptr, wifi_ap_iface_.get());
43     }
44 
TearDown()45     virtual void TearDown() override {
46         if (!gEnv->isSoftApOn) return;
47         stopWifi();
48     }
49 
50    protected:
51     sp<IWifiApIface> wifi_ap_iface_;
52 };
53 
54 /*
55  * Create:
56  * Ensures that an instance of the IWifiApIface proxy object is
57  * successfully created.
58  */
TEST(WifiApIfaceHidlTestNoFixture,Create)59 TEST(WifiApIfaceHidlTestNoFixture, Create) {
60     if (!gEnv->isSoftApOn) return;
61     EXPECT_NE(nullptr, getWifiApIface().get());
62     stopWifi();
63 }
64 
65 /*
66  * GetType:
67  * Ensures that the correct interface type is returned for AP interface.
68  */
TEST_F(WifiApIfaceHidlTest,GetType)69 TEST_F(WifiApIfaceHidlTest, GetType) {
70     if (!gEnv->isSoftApOn) return;
71     const auto& status_and_type = HIDL_INVOKE(wifi_ap_iface_, getType);
72     EXPECT_EQ(WifiStatusCode::SUCCESS, status_and_type.first.code);
73     EXPECT_EQ(IfaceType::AP, status_and_type.second);
74 }
75 
76 /*
77  * SetCountryCode:
78  * Ensures that a call to set the country code will return with a success
79  * status code.
80  */
TEST_F(WifiApIfaceHidlTest,SetCountryCode)81 TEST_F(WifiApIfaceHidlTest, SetCountryCode) {
82     if (!gEnv->isSoftApOn) return;
83     const android::hardware::hidl_array<int8_t, 2> kCountryCode{
84         std::array<int8_t, 2>{{0x55, 0x53}}};
85     EXPECT_EQ(WifiStatusCode::SUCCESS,
86               HIDL_INVOKE(wifi_ap_iface_, setCountryCode, kCountryCode).code);
87 }
88 
89 /*
90  * GetValidFrequenciesForBand:
91  * Ensures that we can retrieve valid frequencies for 2.4 GHz band.
92  */
TEST_F(WifiApIfaceHidlTest,GetValidFrequenciesForBand)93 TEST_F(WifiApIfaceHidlTest, GetValidFrequenciesForBand) {
94     if (!gEnv->isSoftApOn) return;
95     const auto& status_and_freqs = HIDL_INVOKE(
96         wifi_ap_iface_, getValidFrequenciesForBand, WifiBand::BAND_24GHZ);
97     EXPECT_EQ(WifiStatusCode::SUCCESS, status_and_freqs.first.code);
98     EXPECT_GT(status_and_freqs.second.size(), 0u);
99 }
100