1 /*
2 * Copyright (C) 2019 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 <VtsHalHidlTargetCallbackBase.h>
18 #include <android-base/logging.h>
19
20 #undef NAN // NAN is defined in bionic/libc/include/math.h:38
21
22 #include <android/hardware/wifi/1.3/IWifiStaIface.h>
23 #include <android/hardware/wifi/1.4/IWifi.h>
24 #include <android/hardware/wifi/1.4/IWifiChip.h>
25 #include <android/hardware/wifi/1.4/IWifiChipEventCallback.h>
26 #include <gtest/gtest.h>
27 #include <hidl/GtestPrinter.h>
28 #include <hidl/ServiceManagement.h>
29
30 #include "wifi_hidl_call_util.h"
31 #include "wifi_hidl_test_utils.h"
32
33 using ::android::sp;
34 using ::android::hardware::hidl_string;
35 using ::android::hardware::hidl_vec;
36 using ::android::hardware::Return;
37 using ::android::hardware::Void;
38 using ::android::hardware::wifi::V1_0::ChipModeId;
39 using ::android::hardware::wifi::V1_0::IfaceType;
40 using ::android::hardware::wifi::V1_0::WifiDebugRingBufferStatus;
41 using ::android::hardware::wifi::V1_0::WifiStatus;
42 using ::android::hardware::wifi::V1_0::WifiStatusCode;
43 using ::android::hardware::wifi::V1_3::IWifiStaIface;
44 using ::android::hardware::wifi::V1_4::IWifiChip;
45 using ::android::hardware::wifi::V1_4::IWifiChipEventCallback;
46
47 /**
48 * Fixture to use for all Wifi chip HIDL interface tests.
49 */
50 class WifiChipHidlTest : public ::testing::TestWithParam<std::string> {
51 public:
SetUp()52 virtual void SetUp() override {
53 // Make sure to start with a clean state
54 stopWifi(GetInstanceName());
55
56 wifi_chip_ = IWifiChip::castFrom(getWifiChip(GetInstanceName()));
57 ASSERT_NE(nullptr, wifi_chip_.get());
58 }
59
TearDown()60 virtual void TearDown() override { stopWifi(GetInstanceName()); }
61
62 // A simple test implementation of WifiChipEventCallback.
63 class WifiChipEventCallback
64 : public ::testing::VtsHalHidlTargetCallbackBase<WifiChipHidlTest>,
65 public IWifiChipEventCallback {
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(
76 const WifiStatus& status __unused) {
77 return Void();
78 };
79
onIfaceAdded(IfaceType type __unused,const hidl_string & name __unused)80 Return<void> onIfaceAdded(IfaceType type __unused,
81 const hidl_string& name __unused) {
82 return Void();
83 };
84
onIfaceRemoved(IfaceType type __unused,const hidl_string & name __unused)85 Return<void> onIfaceRemoved(IfaceType type __unused,
86 const hidl_string& name __unused) {
87 return Void();
88 };
89
onDebugRingBufferDataAvailable(const WifiDebugRingBufferStatus & status __unused,const hidl_vec<uint8_t> & data __unused)90 Return<void> onDebugRingBufferDataAvailable(
91 const WifiDebugRingBufferStatus& status __unused,
92 const hidl_vec<uint8_t>& data __unused) {
93 return Void();
94 };
95
onDebugErrorAlert(int32_t errorCode __unused,const hidl_vec<uint8_t> & debugData __unused)96 Return<void> onDebugErrorAlert(int32_t errorCode __unused,
97 const hidl_vec<uint8_t>& debugData
98 __unused) {
99 return Void();
100 };
101
onRadioModeChange(const hidl_vec<::android::hardware::wifi::V1_2::IWifiChipEventCallback::RadioModeInfo> & radioModeInfos __unused)102 Return<void> onRadioModeChange(
103 const hidl_vec<::android::hardware::wifi::V1_2::
104 IWifiChipEventCallback::RadioModeInfo>&
105 radioModeInfos __unused) {
106 return Void();
107 };
108
onRadioModeChange_1_4(const hidl_vec<RadioModeInfo> & radioModeInfos __unused)109 Return<void> onRadioModeChange_1_4(
110 const hidl_vec<RadioModeInfo>& radioModeInfos __unused) {
111 return Void();
112 };
113 };
114
115 protected:
116 // Helper function to configure the Chip in one of the supported modes.
117 // Most of the non-mode-configuration-related methods require chip
118 // to be first configured.
configureChipForIfaceType(IfaceType type,bool expectSuccess)119 ChipModeId configureChipForIfaceType(IfaceType type, bool expectSuccess) {
120 ChipModeId mode_id;
121 EXPECT_EQ(expectSuccess,
122 configureChipToSupportIfaceType(wifi_chip_, type, &mode_id));
123 return mode_id;
124 }
125
126 sp<IWifiChip> wifi_chip_;
127
128 private:
GetInstanceName()129 std::string GetInstanceName() { return GetParam(); }
130 };
131
132 /*
133 * registerEventCallback_1_4
134 * This test case tests the registerEventCallback_1_4() API which registers
135 * a call back function with the hal implementation
136 *
137 * Note: it is not feasible to test the invocation of the call back function
138 * since event is triggered internally in the HAL implementation, and can not be
139 * triggered from the test case
140 */
TEST_P(WifiChipHidlTest,registerEventCallback_1_4)141 TEST_P(WifiChipHidlTest, registerEventCallback_1_4) {
142 sp<WifiChipEventCallback> wifiChipEventCallback =
143 new WifiChipEventCallback();
144 const auto& status = HIDL_INVOKE(wifi_chip_, registerEventCallback_1_4,
145 wifiChipEventCallback);
146
147 if (status.code != WifiStatusCode::SUCCESS) {
148 EXPECT_EQ(WifiStatusCode::ERROR_NOT_SUPPORTED, status.code);
149 return;
150 }
151 }
152
153 GTEST_ALLOW_UNINSTANTIATED_PARAMETERIZED_TEST(WifiChipHidlTest);
154 INSTANTIATE_TEST_SUITE_P(
155 PerInstance, WifiChipHidlTest,
156 testing::ValuesIn(android::hardware::getAllHalInstanceNames(
157 ::android::hardware::wifi::V1_4::IWifi::descriptor)),
158 android::hardware::PrintInstanceNameToString);
159