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