1 /*
2  * Copyright (C) 2016 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 <VtsCoreUtil.h>
20 #include <android/hardware/wifi/1.0/IWifi.h>
21 #include <android/hardware/wifi/1.0/IWifiRttController.h>
22 #include <gtest/gtest.h>
23 #include <hidl/GtestPrinter.h>
24 #include <hidl/ServiceManagement.h>
25 
26 #include "wifi_hidl_call_util.h"
27 #include "wifi_hidl_test_utils.h"
28 
29 using ::android::sp;
30 using ::android::hardware::wifi::V1_0::IWifi;
31 using ::android::hardware::wifi::V1_0::IWifiChip;
32 using ::android::hardware::wifi::V1_0::IWifiRttController;
33 using ::android::hardware::wifi::V1_0::IWifiStaIface;
34 using ::android::hardware::wifi::V1_0::WifiStatusCode;
35 
36 /**
37  * Fixture to use for all RTT controller HIDL interface tests.
38  */
39 class WifiRttControllerHidlTest : public ::testing::TestWithParam<std::string> {
40    public:
SetUp()41     virtual void SetUp() override {
42         if (!::testing::deviceSupportsFeature("android.hardware.wifi.rtt"))
43             GTEST_SKIP() << "Skipping this test since RTT is not supported.";
44         // Make sure test starts with a clean state
45         stopWifi(GetInstanceName());
46     }
47 
TearDown()48     virtual void TearDown() override { stopWifi(GetInstanceName()); }
49 
50    protected:
GetInstanceName()51     std::string GetInstanceName() { return GetParam(); }
52 };
53 
54 /*
55  * Create:
56  * Ensures that an instance of the IWifiRttController proxy object is
57  * successfully created.
58  */
TEST_P(WifiRttControllerHidlTest,Create)59 TEST_P(WifiRttControllerHidlTest, Create) {
60     stopWifi(GetInstanceName());
61 
62     const std::string& instance_name = GetInstanceName();
63 
64     sp<IWifiChip> wifi_chip = getWifiChip(instance_name);
65     ASSERT_NE(nullptr, wifi_chip.get());
66 
67     sp<IWifiStaIface> wifi_sta_iface = getWifiStaIface(instance_name);
68     ASSERT_NE(nullptr, wifi_sta_iface.get());
69 
70     const auto& status_and_controller =
71         HIDL_INVOKE(wifi_chip, createRttController, wifi_sta_iface);
72     if (status_and_controller.first.code !=
73         WifiStatusCode::ERROR_NOT_SUPPORTED) {
74         EXPECT_EQ(WifiStatusCode::SUCCESS, status_and_controller.first.code);
75         EXPECT_NE(nullptr, status_and_controller.second.get());
76     }
77 }
78 
79 GTEST_ALLOW_UNINSTANTIATED_PARAMETERIZED_TEST(WifiRttControllerHidlTest);
80 INSTANTIATE_TEST_SUITE_P(
81     PerInstance, WifiRttControllerHidlTest,
82     testing::ValuesIn(
83         android::hardware::getAllHalInstanceNames(IWifi::descriptor)),
84     android::hardware::PrintInstanceNameToString);
85