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.3/IWifi.h>
20 #include <android/hardware/wifi/1.3/IWifiChip.h>
21 #include <gtest/gtest.h>
22 #include <hidl/GtestPrinter.h>
23 #include <hidl/ServiceManagement.h>
24
25 #include "wifi_hidl_call_util.h"
26 #include "wifi_hidl_test_utils.h"
27
28 using ::android::sp;
29 using ::android::hardware::wifi::V1_0::ChipModeId;
30 using ::android::hardware::wifi::V1_0::IfaceType;
31 using ::android::hardware::wifi::V1_0::WifiStatusCode;
32 using ::android::hardware::wifi::V1_3::IWifiChip;
33
34 namespace {
35 constexpr IWifiChip::LatencyMode kLatencyModeNormal =
36 IWifiChip::LatencyMode::NORMAL;
37
38 constexpr IWifiChip::LatencyMode kLatencyModeLow = IWifiChip::LatencyMode::LOW;
39 }; // namespace
40
41 /**
42 * Fixture to use for all Wifi chip HIDL interface tests.
43 */
44 class WifiChipHidlTest : public ::testing::TestWithParam<std::string> {
45 public:
SetUp()46 virtual void SetUp() override {
47 // Make sure to start with a clean state
48 stopWifi(GetInstanceName());
49
50 wifi_chip_ = IWifiChip::castFrom(getWifiChip(GetInstanceName()));
51 ASSERT_NE(nullptr, wifi_chip_.get());
52 }
53
TearDown()54 virtual void TearDown() override { stopWifi(GetInstanceName()); }
55
56 protected:
57 // Helper function to configure the Chip in one of the supported modes.
58 // Most of the non-mode-configuration-related methods require chip
59 // to be first configured.
configureChipForIfaceType(IfaceType type,bool expectSuccess)60 ChipModeId configureChipForIfaceType(IfaceType type, bool expectSuccess) {
61 ChipModeId mode_id;
62 EXPECT_EQ(expectSuccess,
63 configureChipToSupportIfaceType(wifi_chip_, type, &mode_id));
64 return mode_id;
65 }
66
configureChipForStaIfaceAndGetCapabilities()67 uint32_t configureChipForStaIfaceAndGetCapabilities() {
68 ChipModeId mode_id;
69 EXPECT_TRUE(configureChipToSupportIfaceType(wifi_chip_, IfaceType::STA,
70 &mode_id));
71 return getChipCapabilitiesLatest(wifi_chip_);
72 }
73
74 sp<IWifiChip> wifi_chip_;
75
76 private:
GetInstanceName()77 std::string GetInstanceName() { return GetParam(); }
78 };
79
80 /*
81 * SetLatencyMode_normal
82 * This test case tests the setLatencyMode() API with
83 * Latency mode NORMAL
84 */
TEST_P(WifiChipHidlTest,SetLatencyMode_normal)85 TEST_P(WifiChipHidlTest, SetLatencyMode_normal) {
86 uint32_t caps = configureChipForStaIfaceAndGetCapabilities();
87 const auto& status =
88 HIDL_INVOKE(wifi_chip_, setLatencyMode, kLatencyModeNormal);
89 if (caps & (IWifiChip::ChipCapabilityMask::SET_LATENCY_MODE)) {
90 EXPECT_EQ(WifiStatusCode::SUCCESS, status.code);
91 } else {
92 EXPECT_EQ(WifiStatusCode::ERROR_NOT_SUPPORTED, status.code);
93 }
94 }
95
96 /*
97 * SetLatencyMode_low
98 * This test case tests the setLatencyMode() API with Latency mode LOW
99 */
TEST_P(WifiChipHidlTest,SetLatencyMode_low)100 TEST_P(WifiChipHidlTest, SetLatencyMode_low) {
101 uint32_t caps = configureChipForStaIfaceAndGetCapabilities();
102 const auto& status =
103 HIDL_INVOKE(wifi_chip_, setLatencyMode, kLatencyModeLow);
104 if (caps & (IWifiChip::ChipCapabilityMask::SET_LATENCY_MODE)) {
105 EXPECT_EQ(WifiStatusCode::SUCCESS, status.code);
106 } else {
107 EXPECT_EQ(WifiStatusCode::ERROR_NOT_SUPPORTED, status.code);
108 }
109 }
110
111 /*
112 * GetCapabilities_1_3
113 */
TEST_P(WifiChipHidlTest,GetCapabilities_1_3)114 TEST_P(WifiChipHidlTest, GetCapabilities_1_3) {
115 configureChipForIfaceType(IfaceType::STA, true);
116 const auto& status_and_caps = HIDL_INVOKE(wifi_chip_, getCapabilities_1_3);
117 if (status_and_caps.first.code != WifiStatusCode::SUCCESS) {
118 EXPECT_EQ(WifiStatusCode::ERROR_NOT_SUPPORTED,
119 status_and_caps.first.code);
120 return;
121 }
122 EXPECT_NE(0u, status_and_caps.second);
123 }
124
125 GTEST_ALLOW_UNINSTANTIATED_PARAMETERIZED_TEST(WifiChipHidlTest);
126 INSTANTIATE_TEST_SUITE_P(
127 PerInstance, WifiChipHidlTest,
128 testing::ValuesIn(android::hardware::getAllHalInstanceNames(
129 ::android::hardware::wifi::V1_3::IWifi::descriptor)),
130 android::hardware::PrintInstanceNameToString);
131