1 /*
2 * Copyright (C) 2018 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.2/IWifiChip.h>
20 #include <android/hardware/wifi/1.2/IWifiChipEventCallback.h>
21
22 #include <VtsHalHidlTargetCallbackBase.h>
23 #include <VtsHalHidlTargetTestBase.h>
24
25 #include "wifi_hidl_call_util.h"
26 #include "wifi_hidl_test_utils.h"
27
28 using ::android::hardware::hidl_string;
29 using ::android::hardware::hidl_vec;
30 using ::android::hardware::Return;
31 using ::android::hardware::wifi::V1_0::ChipModeId;
32 using ::android::hardware::wifi::V1_0::IfaceType;
33 using ::android::hardware::wifi::V1_0::WifiStatus;
34 using ::android::hardware::wifi::V1_0::WifiDebugRingBufferStatus;
35 using ::android::hardware::wifi::V1_0::WifiStatusCode;
36 using ::android::hardware::wifi::V1_2::IWifiChip;
37 using ::android::hardware::wifi::V1_2::IWifiChipEventCallback;
38 using ::android::hardware::Void;
39 using ::android::sp;
40
41 namespace {
42 constexpr IWifiChip::TxPowerScenario kPowerScenarioBody =
43 IWifiChip::TxPowerScenario::ON_BODY_CELL_OFF;
44
45 constexpr IWifiChip::TxPowerScenario kPowerScenarioVoiceCall =
46 IWifiChip::TxPowerScenario::VOICE_CALL;
47 }; // namespace
48
49 /**
50 * Fixture to use for all Wifi chip HIDL interface tests.
51 */
52 class WifiChipHidlTest : public ::testing::VtsHalHidlTargetTestBase {
53 public:
SetUp()54 virtual void SetUp() override {
55 wifi_chip_ = IWifiChip::castFrom(getWifiChip());
56 ASSERT_NE(nullptr, wifi_chip_.get());
57 }
58
TearDown()59 virtual void TearDown() override { stopWifi(); }
60
61 // A simple test implementation of WifiChipEventCallback.
62 class WifiChipEventCallback
63 : public ::testing::VtsHalHidlTargetCallbackBase<WifiChipHidlTest>,
64 public IWifiChipEventCallback {
65
66 public:
WifiChipEventCallback()67 WifiChipEventCallback() {};
68
69 virtual ~WifiChipEventCallback() = default;
70
onChipReconfigured(uint32_t modeId __unused)71 Return<void> onChipReconfigured(uint32_t modeId __unused) {
72 return Void();
73 };
74
onChipReconfigureFailure(const WifiStatus & status __unused)75 Return<void> onChipReconfigureFailure(const WifiStatus& status __unused) {
76 return Void();
77 };
78
onIfaceAdded(IfaceType type __unused,const hidl_string & name __unused)79 Return<void> onIfaceAdded(IfaceType type __unused, const hidl_string& name __unused) {
80 return Void();
81 };
82
onIfaceRemoved(IfaceType type __unused,const hidl_string & name __unused)83 Return<void> onIfaceRemoved(IfaceType type __unused, const hidl_string& name __unused) {
84 return Void();
85 };
86
onDebugRingBufferDataAvailable(const WifiDebugRingBufferStatus & status __unused,const hidl_vec<uint8_t> & data __unused)87 Return<void> onDebugRingBufferDataAvailable(const WifiDebugRingBufferStatus& status __unused,
88 const hidl_vec<uint8_t>& data __unused) {
89 return Void();
90 };
91
onDebugErrorAlert(int32_t errorCode __unused,const hidl_vec<uint8_t> & debugData __unused)92 Return<void> onDebugErrorAlert(int32_t errorCode __unused,
93 const hidl_vec<uint8_t>& debugData __unused) {
94 return Void();
95 };
96
onRadioModeChange(const hidl_vec<RadioModeInfo> & radioModeInfos __unused)97 Return<void> onRadioModeChange(const hidl_vec<RadioModeInfo>& radioModeInfos __unused) {
98 return Void();
99 };
100 };
101
102 protected:
configureChipForStaIfaceAndGetCapabilities()103 uint32_t configureChipForStaIfaceAndGetCapabilities() {
104 ChipModeId mode_id;
105 EXPECT_TRUE(
106 configureChipToSupportIfaceType(wifi_chip_, IfaceType::STA, &mode_id));
107 const auto& status_and_caps = HIDL_INVOKE(wifi_chip_, getCapabilities);
108 EXPECT_EQ(WifiStatusCode::SUCCESS, status_and_caps.first.code);
109 return status_and_caps.second;
110 }
111
112 sp<IWifiChip> wifi_chip_;
113 };
114
115 /*
116 * SelectTxPowerScenario_1_2_body
117 * This test case tests the selectTxPowerScenario_1_2() API with SAR scenarios
118 * newly defined in 1.2
119 */
TEST_F(WifiChipHidlTest,SelectTxPowerScenario_1_2_body)120 TEST_F(WifiChipHidlTest, SelectTxPowerScenario_1_2_body) {
121 uint32_t caps = configureChipForStaIfaceAndGetCapabilities();
122 const auto& status =
123 HIDL_INVOKE(wifi_chip_, selectTxPowerScenario_1_2, kPowerScenarioBody);
124 if (caps & (IWifiChip::ChipCapabilityMask::SET_TX_POWER_LIMIT |
125 IWifiChip::ChipCapabilityMask::USE_BODY_HEAD_SAR)) {
126 EXPECT_EQ(WifiStatusCode::SUCCESS, status.code);
127 } else {
128 EXPECT_EQ(WifiStatusCode::ERROR_NOT_SUPPORTED, status.code);
129 }
130 }
131
132 /*
133 * SelectTxPowerScenario_1_2_voiceCall
134 * This test case tests the selectTxPowerScenario_1_2() API with previously
135 * defined SAR scenarios
136 */
TEST_F(WifiChipHidlTest,SelectTxPowerScenario_1_2_voiceCall)137 TEST_F(WifiChipHidlTest, SelectTxPowerScenario_1_2_voiceCall) {
138 uint32_t caps = configureChipForStaIfaceAndGetCapabilities();
139 const auto& status =
140 HIDL_INVOKE(wifi_chip_, selectTxPowerScenario_1_2, kPowerScenarioVoiceCall);
141 if (caps & (IWifiChip::ChipCapabilityMask::SET_TX_POWER_LIMIT)) {
142 EXPECT_EQ(WifiStatusCode::SUCCESS, status.code);
143 } else {
144 EXPECT_EQ(WifiStatusCode::ERROR_NOT_SUPPORTED, status.code);
145 }
146 }
147
148 /*
149 * registerEventCallback_1_2
150 * This test case tests the registerEventCallback_1_2() API which registers
151 * a call back function with the hal implementation
152 *
153 * Note: it is not feasible to test the invocation of the call back function
154 * since event is triggered internally in the HAL implementation, and can not be
155 * triggered from the test case
156 */
TEST_F(WifiChipHidlTest,registerEventCallback_1_2)157 TEST_F(WifiChipHidlTest, registerEventCallback_1_2) {
158 sp<WifiChipEventCallback> wifiChipEventCallback = new WifiChipEventCallback();
159 const auto& status =
160 HIDL_INVOKE(wifi_chip_, registerEventCallback_1_2, wifiChipEventCallback);
161 EXPECT_EQ(WifiStatusCode::SUCCESS, status.code);
162 }
163