• 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.1/IWifi.h>
20 #include <android/hardware/wifi/1.1/IWifiChip.h>
21 
22 #include <VtsHalHidlTargetTestBase.h>
23 
24 #include "wifi_hidl_call_util.h"
25 #include "wifi_hidl_test_utils.h"
26 
27 using ::android::sp;
28 using ::android::hardware::hidl_string;
29 using ::android::hardware::hidl_vec;
30 using ::android::hardware::wifi::V1_0::IfaceType;
31 using ::android::hardware::wifi::V1_0::ChipId;
32 using ::android::hardware::wifi::V1_0::ChipModeId;
33 using ::android::hardware::wifi::V1_0::WifiStatus;
34 using ::android::hardware::wifi::V1_0::WifiStatusCode;
35 using ::android::hardware::wifi::V1_1::IWifi;
36 using ::android::hardware::wifi::V1_1::IWifiChip;
37 using ::android::hardware::wifi::V1_0::IWifiStaIface;
38 
39 namespace {
40 constexpr IWifiChip::TxPowerScenario kFakePowerScenario =
41     IWifiChip::TxPowerScenario::VOICE_CALL;
42 }; //namespace
43 
44 /**
45  * Fixture to use for all Wifi chip HIDL interface tests.
46  */
47 class WifiChipHidlTest : public ::testing::VtsHalHidlTargetTestBase {
48    public:
SetUp()49     virtual void SetUp() override {
50         wifi_chip_ = IWifiChip::castFrom(getWifiChip());
51         ASSERT_NE(nullptr, wifi_chip_.get());
52     }
53 
TearDown()54     virtual void TearDown() override { stopWifi(); }
55 
56    protected:
configureChipForStaIfaceAndGetCapabilities()57     uint32_t configureChipForStaIfaceAndGetCapabilities() {
58         ChipModeId mode_id;
59         EXPECT_TRUE(configureChipToSupportIfaceType(
60             wifi_chip_, IfaceType::STA, &mode_id));
61         const auto& status_and_caps = HIDL_INVOKE(wifi_chip_, getCapabilities);
62         EXPECT_EQ(WifiStatusCode::SUCCESS, status_and_caps.first.code);
63         return status_and_caps.second;
64     }
65 
66     sp<IWifiChip> wifi_chip_;
67 };
68 
69 /*
70  * SelectTxPowerScenario
71  */
TEST_F(WifiChipHidlTest,SelectTxPowerScenario)72 TEST_F(WifiChipHidlTest, SelectTxPowerScenario) {
73     uint32_t caps = configureChipForStaIfaceAndGetCapabilities();
74     const auto& status =
75         HIDL_INVOKE(wifi_chip_, selectTxPowerScenario, kFakePowerScenario);
76     if (caps & IWifiChip::ChipCapabilityMask::SET_TX_POWER_LIMIT) {
77         EXPECT_EQ(WifiStatusCode::SUCCESS, status.code);
78     } else {
79         EXPECT_EQ(WifiStatusCode::ERROR_NOT_SUPPORTED, status.code);
80     }
81 }
82 
83 /*
84  * ResetTxPowerScenario
85  */
TEST_F(WifiChipHidlTest,ResetTxPowerScenario)86 TEST_F(WifiChipHidlTest, ResetTxPowerScenario) {
87     uint32_t caps = configureChipForStaIfaceAndGetCapabilities();
88     const auto& status =
89         HIDL_INVOKE(wifi_chip_, resetTxPowerScenario);
90     if (caps & IWifiChip::ChipCapabilityMask::SET_TX_POWER_LIMIT) {
91         EXPECT_EQ(WifiStatusCode::SUCCESS, status.code);
92     } else {
93         EXPECT_EQ(WifiStatusCode::ERROR_NOT_SUPPORTED, status.code);
94     }
95 }
96