1 /*
2 * Copyright (C) 2022 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.4/IWifiChipEventCallback.h>
23 #include <android/hardware/wifi/1.6/IWifi.h>
24 #include <android/hardware/wifi/1.6/IWifiChip.h>
25 #include <android/hardware/wifi/1.6/IWifiStaIface.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::IWifiIface;
41 using ::android::hardware::wifi::V1_0::IWifiStaIface;
42 using ::android::hardware::wifi::V1_0::WifiDebugRingBufferStatus;
43 using ::android::hardware::wifi::V1_0::WifiStatus;
44 using ::android::hardware::wifi::V1_0::WifiStatusCode;
45 using ::android::hardware::wifi::V1_4::IWifiChipEventCallback;
46 using ::android::hardware::wifi::V1_5::WifiBand;
47 using ::android::hardware::wifi::V1_5::WifiIfaceMode;
48 using ::android::hardware::wifi::V1_6::IWifiChip;
49
50 /**
51 * Fixture to use for all Wifi chip HIDL interface tests.
52 */
53 class WifiChipHidlTest : public ::testing::TestWithParam<std::string> {
54 public:
SetUp()55 virtual void SetUp() override {
56 // Make sure to start with a clean state
57 stopWifi(GetInstanceName());
58
59 wifi_chip_ = IWifiChip::castFrom(getWifiChip(GetInstanceName()));
60 ASSERT_NE(nullptr, wifi_chip_.get());
61 }
62
TearDown()63 virtual void TearDown() override { stopWifi(GetInstanceName()); }
64
65 protected:
66 // Helper function to configure the Chip in one of the supported modes.
67 // Most of the non-mode-configuration-related methods require chip
68 // to be first configured.
configureChipForIfaceType(IfaceType type,bool expectSuccess)69 ChipModeId configureChipForIfaceType(IfaceType type, bool expectSuccess) {
70 ChipModeId mode_id;
71 EXPECT_EQ(expectSuccess, configureChipToSupportIfaceType(wifi_chip_, type, &mode_id));
72 return mode_id;
73 }
74
75 sp<IWifiChip> wifi_chip_;
76
77 private:
GetInstanceName()78 std::string GetInstanceName() { return GetParam(); }
79 };
80
81 /* getUsableChannels_1_6:
82 * Ensure that a call to getUsableChannels_1_6 will return with a success
83 * status for valid inputs.
84 */
TEST_P(WifiChipHidlTest,getUsableChannels_1_6)85 TEST_P(WifiChipHidlTest, getUsableChannels_1_6) {
86 uint32_t ifaceModeMask =
87 WifiIfaceMode::IFACE_MODE_P2P_CLIENT | WifiIfaceMode::IFACE_MODE_P2P_GO;
88 uint32_t filterMask = IWifiChip::UsableChannelFilter::CELLULAR_COEXISTENCE |
89 IWifiChip::UsableChannelFilter::CONCURRENCY;
90 configureChipForIfaceType(IfaceType::STA, true);
91 WifiBand band = WifiBand::BAND_24GHZ_5GHZ_6GHZ;
92 const auto& statusNonEmpty =
93 HIDL_INVOKE(wifi_chip_, getUsableChannels_1_6, band, ifaceModeMask, filterMask);
94 if (statusNonEmpty.first.code == WifiStatusCode::ERROR_NOT_SUPPORTED) {
95 GTEST_SKIP() << "Skipping this test since getUsableChannels() is not supported by vendor.";
96 }
97
98 EXPECT_EQ(WifiStatusCode::SUCCESS, statusNonEmpty.first.code);
99 }
100
101 /* getAvailableModes_1_6:
102 * Ensures that a call to getAvailableModes_1_6 will return with a success status code.
103 */
TEST_P(WifiChipHidlTest,getAvailableModes_1_6)104 TEST_P(WifiChipHidlTest, getAvailableModes_1_6) {
105 const auto& status_and_modes = HIDL_INVOKE(wifi_chip_, getAvailableModes_1_6);
106 EXPECT_EQ(WifiStatusCode::SUCCESS, status_and_modes.first.code);
107 EXPECT_LT(0u, status_and_modes.second.size());
108 }
109
110 /*
111 * getSupportedRadioCombinationsMatrix:
112 * Ensure that a call to getSupportedRadioCombinationsMatrix will return
113 * with a success status code.
114 */
TEST_P(WifiChipHidlTest,getSupportedRadioCombinationsMatrix)115 TEST_P(WifiChipHidlTest, getSupportedRadioCombinationsMatrix) {
116 configureChipForIfaceType(IfaceType::STA, true);
117 const auto& statusNonEmpty = HIDL_INVOKE(wifi_chip_, getSupportedRadioCombinationsMatrix);
118 if (statusNonEmpty.first.code == WifiStatusCode::ERROR_NOT_SUPPORTED) {
119 GTEST_SKIP() << "Skipping this test since getSupportedRadioCombinationsMatrix() is not "
120 "supported by vendor.";
121 }
122
123 EXPECT_EQ(WifiStatusCode::SUCCESS, statusNonEmpty.first.code);
124 }
125
126 GTEST_ALLOW_UNINSTANTIATED_PARAMETERIZED_TEST(WifiChipHidlTest);
127 INSTANTIATE_TEST_SUITE_P(PerInstance, WifiChipHidlTest,
128 testing::ValuesIn(android::hardware::getAllHalInstanceNames(
129 ::android::hardware::wifi::V1_6::IWifi::descriptor)),
130 android::hardware::PrintInstanceNameToString);
131