summaryrefslogtreecommitdiff
path: root/wifi/1.4/vts/functional/wifi_ap_iface_hidl_test.cpp
blob: 756afa512224502e7cfa6a0f1e139dafd0d1a797 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
/*
 * Copyright (C) 2019 The Android Open Source Project
 *
 * Licensed under the Staache License, Version 2.0 (the "License");
 * you may not use this file except in compliance with the License.
 * You may obtain a copy of the License at
 *
 *      http://www.apache.org/licenses/LICENSE-2.0
 *
 * Unless required by applicable law or agreed to in writing, software
 * distributed under the License is distributed on an "AS IS" BASIS,
 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
 * See the License for the specific language governing permissions and
 * limitations under the License.
 */

#include <android/hardware/wifi/1.4/IWifi.h>
#include <android/hardware/wifi/1.4/IWifiApIface.h>
#include <android/hardware/wifi/hostapd/1.0/IHostapd.h>
#include <gtest/gtest.h>
#include <hidl/GtestPrinter.h>
#include <hidl/ServiceManagement.h>

#include "wifi_hidl_call_util.h"
#include "wifi_hidl_test_utils.h"

using ::android::sp;
using ::android::hardware::hidl_array;
using ::android::hardware::wifi::hostapd::V1_0::IHostapd;
using ::android::hardware::wifi::V1_0::WifiStatus;
using ::android::hardware::wifi::V1_0::WifiStatusCode;
using ::android::hardware::wifi::V1_4::IWifi;
using ::android::hardware::wifi::V1_4::IWifiApIface;

/**
 * Fixture to use for all STA Iface HIDL interface tests.
 */
class WifiApIfaceHidlTest : public ::testing::TestWithParam<std::string> {
   public:
    virtual void SetUp() override {
        if (android::hardware::getAllHalInstanceNames(IHostapd::descriptor)
                .empty()) {
            GTEST_SKIP() << "Device does not support AP";
        }
        // Make sure to start with a clean state
        stopWifi(GetInstanceName());

        wifi_ap_iface_ =
            IWifiApIface::castFrom(getWifiApIface(GetInstanceName()));
        ASSERT_NE(nullptr, wifi_ap_iface_.get());
    }

    virtual void TearDown() override { stopWifi(GetInstanceName()); }

   protected:
    sp<IWifiApIface> wifi_ap_iface_;

   private:
    std::string GetInstanceName() { return GetParam(); }
};

/*
 * SetMacAddress:
 * Ensures that calls to set MAC address will return a success status
 * code.
 */
TEST_P(WifiApIfaceHidlTest, SetMacAddress) {
    const hidl_array<uint8_t, 6> kMac{{0x12, 0x22, 0x33, 0x52, 0x10, 0x44}};
    EXPECT_EQ(WifiStatusCode::SUCCESS,
              HIDL_INVOKE(wifi_ap_iface_, setMacAddress, kMac).code);
}

/*
 * GetFactoryMacAddress:
 * Ensures that calls to get factory MAC address will retrieve a non-zero MAC
 * and return a success status code.
 */
TEST_P(WifiApIfaceHidlTest, GetFactoryMacAddress) {
    std::pair<WifiStatus, hidl_array<uint8_t, 6> > status_and_mac =
        HIDL_INVOKE(wifi_ap_iface_, getFactoryMacAddress);
    EXPECT_EQ(WifiStatusCode::SUCCESS, status_and_mac.first.code);
    hidl_array<uint8_t, 6> all_zero{};
    EXPECT_NE(all_zero, status_and_mac.second);
}

GTEST_ALLOW_UNINSTANTIATED_PARAMETERIZED_TEST(WifiApIfaceHidlTest);
INSTANTIATE_TEST_SUITE_P(
    PerInstance, WifiApIfaceHidlTest,
    testing::ValuesIn(
        android::hardware::getAllHalInstanceNames(IWifi::descriptor)),
    android::hardware::PrintInstanceNameToString);