Donate to e Foundation | Murena handsets with /e/OS | Own a part of Murena! Learn more

Commit 25692880 authored by Ahmed ElArabawy's avatar Ahmed ElArabawy Committed by Android (Google) Code Review
Browse files

Merge "Wifi: Add VTS tests for Vendor HAL 1.6" into tm-dev

parents 98112251 b2c8852c
Loading
Loading
Loading
Loading

wifi/1.6/vts/OWNERS

0 → 100644
+2 −0
Original line number Diff line number Diff line
# Bug component: 33618
include ../../1.0/vts/OWNERS
+98 −0
Original line number Diff line number Diff line
//
// Copyright (C) 2022 The Android Open Source Project
//
// Licensed under the Apache 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.
//

package {
    // See: http://go/android-license-faq
    // A large-scale-change added 'default_applicable_licenses' to import
    // all of the 'license_kinds' from "hardware_interfaces_license"
    // to get the below license kinds:
    //   SPDX-license-identifier-Apache-2.0
    default_applicable_licenses: ["hardware_interfaces_license"],
}

cc_test {
    name: "VtsHalWifiV1_6TargetTest",
    defaults: ["VtsHalTargetTestDefaults"],
    srcs: [
        "wifi_chip_hidl_test.cpp",
        "wifi_sta_iface_hidl_test.cpp",
    ],
    static_libs: [
        "VtsHalWifiV1_0TargetTestUtil",
        "android.hardware.wifi@1.0",
        "android.hardware.wifi@1.1",
        "android.hardware.wifi@1.2",
        "android.hardware.wifi@1.3",
        "android.hardware.wifi@1.4",
        "android.hardware.wifi@1.5",
        "android.hardware.wifi@1.6",
        "libwifi-system-iface",
    ],
    test_suites: [
        "general-tests",
        "vts",
    ],
}

// These tests are split out so that they can be conditioned on presence of the
// "android.hardware.wifi.rtt" feature.
cc_test {
    name: "VtsHalWifiRttV1_6TargetTest",
    defaults: ["VtsHalTargetTestDefaults"],
    srcs: [
        "wifi_rtt_controller_hidl_test.cpp",
    ],
    static_libs: [
        "VtsHalWifiV1_0TargetTestUtil",
        "android.hardware.wifi@1.0",
        "android.hardware.wifi@1.1",
        "android.hardware.wifi@1.2",
        "android.hardware.wifi@1.3",
        "android.hardware.wifi@1.4",
        "android.hardware.wifi@1.5",
        "android.hardware.wifi@1.6",
        "libwifi-system-iface",
    ],
    test_suites: [
        "general-tests",
        "vts",
    ],
}

// These tests are split out so that they can be conditioned on presence of the
// "android.hardware.wifi.aware" feature.
cc_test {
    name: "VtsHalWifiNanV1_6TargetTest",
    defaults: ["VtsHalTargetTestDefaults"],
    srcs: [
        "wifi_nan_iface_hidl_test.cpp",
    ],
    static_libs: [
        "VtsHalWifiV1_0TargetTestUtil",
        "android.hardware.wifi@1.0",
        "android.hardware.wifi@1.1",
        "android.hardware.wifi@1.2",
        "android.hardware.wifi@1.3",
        "android.hardware.wifi@1.4",
        "android.hardware.wifi@1.5",
        "android.hardware.wifi@1.6",
        "libwifi-system-iface",
    ],
    test_suites: [
        "general-tests",
        "vts",
    ],
}
+102 −0
Original line number Diff line number Diff line
/*
 * Copyright (C) 2022 The Android Open Source Project
 *
 * Licensed under the Apache 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 <VtsHalHidlTargetCallbackBase.h>
#include <android-base/logging.h>

#undef NAN  // NAN is defined in bionic/libc/include/math.h:38

#include <android/hardware/wifi/1.4/IWifiChipEventCallback.h>
#include <android/hardware/wifi/1.6/IWifi.h>
#include <android/hardware/wifi/1.6/IWifiChip.h>
#include <android/hardware/wifi/1.6/IWifiStaIface.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_string;
using ::android::hardware::hidl_vec;
using ::android::hardware::Return;
using ::android::hardware::Void;
using ::android::hardware::wifi::V1_0::ChipModeId;
using ::android::hardware::wifi::V1_0::IfaceType;
using ::android::hardware::wifi::V1_0::IWifiIface;
using ::android::hardware::wifi::V1_0::IWifiStaIface;
using ::android::hardware::wifi::V1_0::WifiDebugRingBufferStatus;
using ::android::hardware::wifi::V1_0::WifiStatus;
using ::android::hardware::wifi::V1_0::WifiStatusCode;
using ::android::hardware::wifi::V1_4::IWifiChipEventCallback;
using ::android::hardware::wifi::V1_5::WifiBand;
using ::android::hardware::wifi::V1_5::WifiIfaceMode;
using ::android::hardware::wifi::V1_6::IWifiChip;

/**
 * Fixture to use for all Wifi chip HIDL interface tests.
 */
class WifiChipHidlTest : public ::testing::TestWithParam<std::string> {
  public:
    virtual void SetUp() override {
        // Make sure to start with a clean state
        stopWifi(GetInstanceName());

        wifi_chip_ = IWifiChip::castFrom(getWifiChip(GetInstanceName()));
        ASSERT_NE(nullptr, wifi_chip_.get());
    }

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

  protected:
    // Helper function to configure the Chip in one of the supported modes.
    // Most of the non-mode-configuration-related methods require chip
    // to be first configured.
    ChipModeId configureChipForIfaceType(IfaceType type, bool expectSuccess) {
        ChipModeId mode_id;
        EXPECT_EQ(expectSuccess, configureChipToSupportIfaceType(wifi_chip_, type, &mode_id));
        return mode_id;
    }

    sp<IWifiChip> wifi_chip_;

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

/* getUsableChannels_1_6:
 * Ensure that a call to getUsableChannels_1_6 will return with a success
 * status for valid inputs.
 */
TEST_P(WifiChipHidlTest, getUsableChannels_1_6) {
    uint32_t ifaceModeMask =
            WifiIfaceMode::IFACE_MODE_P2P_CLIENT | WifiIfaceMode::IFACE_MODE_P2P_GO;
    uint32_t filterMask = IWifiChip::UsableChannelFilter::CELLULAR_COEXISTENCE |
                          IWifiChip::UsableChannelFilter::CONCURRENCY;
    configureChipForIfaceType(IfaceType::STA, true);
    WifiBand band = WifiBand::BAND_24GHZ_5GHZ_6GHZ;
    const auto& statusNonEmpty =
            HIDL_INVOKE(wifi_chip_, getUsableChannels_1_6, band, ifaceModeMask, filterMask);

    EXPECT_EQ(WifiStatusCode::SUCCESS, statusNonEmpty.first.code);
}

GTEST_ALLOW_UNINSTANTIATED_PARAMETERIZED_TEST(WifiChipHidlTest);
INSTANTIATE_TEST_SUITE_P(PerInstance, WifiChipHidlTest,
                         testing::ValuesIn(android::hardware::getAllHalInstanceNames(
                                 ::android::hardware::wifi::V1_6::IWifi::descriptor)),
                         android::hardware::PrintInstanceNameToString);
+611 −0

File added.

Preview size limit exceeded, changes collapsed.

+295 −0
Original line number Diff line number Diff line
/*
 * Copyright (C) 2022 The Android Open Source Project
 *
 * Licensed under the Apache 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 <VtsHalHidlTargetCallbackBase.h>
#include <android-base/logging.h>

#undef NAN  // NAN is defined in bionic/libc/include/math.h:38

#include <VtsCoreUtil.h>
#include <android/hardware/wifi/1.6/IWifi.h>
#include <android/hardware/wifi/1.6/IWifiChip.h>
#include <android/hardware/wifi/1.6/IWifiRttController.h>
#include <android/hardware/wifi/1.6/IWifiRttControllerEventCallback.h>
#include <android/hardware/wifi/1.6/IWifiStaIface.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_vec;
using ::android::hardware::Return;
using ::android::hardware::Void;
using ::android::hardware::wifi::V1_0::CommandId;
using ::android::hardware::wifi::V1_0::RttPeerType;
using ::android::hardware::wifi::V1_0::RttType;
using ::android::hardware::wifi::V1_0::WifiStatus;
using ::android::hardware::wifi::V1_0::WifiStatusCode;
using ::android::hardware::wifi::V1_6::IWifiChip;
using ::android::hardware::wifi::V1_6::IWifiRttController;
using ::android::hardware::wifi::V1_6::IWifiRttControllerEventCallback;
using ::android::hardware::wifi::V1_6::IWifiStaIface;
using ::android::hardware::wifi::V1_6::RttBw;
using ::android::hardware::wifi::V1_6::RttCapabilities;
using ::android::hardware::wifi::V1_6::RttConfig;
using ::android::hardware::wifi::V1_6::RttPreamble;
using ::android::hardware::wifi::V1_6::RttResponder;
using ::android::hardware::wifi::V1_6::RttResult;
using ::android::hardware::wifi::V1_6::WifiChannelInfo;
using ::android::hardware::wifi::V1_6::WifiChannelWidthInMhz;

/**
 * Fixture to use for all RTT controller HIDL interface tests.
 */
class WifiRttControllerHidlTest : public ::testing::TestWithParam<std::string> {
  public:
    virtual void SetUp() override {
        if (!::testing::deviceSupportsFeature("android.hardware.wifi.rtt"))
            GTEST_SKIP() << "Skipping this test since RTT is not supported.";
        // Make sure to start with a clean state
        stopWifi(GetInstanceName());

        wifi_rtt_controller_ = getWifiRttController();
        ASSERT_NE(nullptr, wifi_rtt_controller_.get());

        // Check RTT support before we run the test.
        std::pair<WifiStatus, RttCapabilities> status_and_caps;
        status_and_caps = HIDL_INVOKE(wifi_rtt_controller_, getCapabilities_1_6);
        if (status_and_caps.first.code == WifiStatusCode::ERROR_NOT_SUPPORTED) {
            GTEST_SKIP() << "Skipping this test since RTT is not supported.";
        }
    }

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

    // A simple test implementation of WifiRttControllerEventCallback.
    class WifiRttControllerEventCallback
        : public ::testing::VtsHalHidlTargetCallbackBase<WifiRttControllerHidlTest>,
          public IWifiRttControllerEventCallback {
      public:
        WifiRttControllerEventCallback(){};

        virtual ~WifiRttControllerEventCallback() = default;

        Return<void> onResults(CommandId cmdId __unused,
                               const hidl_vec<::android::hardware::wifi::V1_0::RttResult>& results
                                       __unused) {
            return Void();
        };

        Return<void> onResults_1_4(
                CommandId cmdId __unused,
                const hidl_vec<::android::hardware::wifi::V1_4::RttResult>& results __unused) {
            return Void();
        };

        Return<void> onResults_1_6(CommandId cmdId __unused,
                                   const hidl_vec<RttResult>& results __unused) {
            return Void();
        };
    };

  protected:
    sp<IWifiRttController> wifi_rtt_controller_;

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

    sp<IWifiRttController> getWifiRttController() {
        const std::string& instance_name = GetInstanceName();

        sp<IWifiChip> wifi_chip = IWifiChip::castFrom(getWifiChip(instance_name));
        EXPECT_NE(nullptr, wifi_chip.get());

        sp<IWifiStaIface> wifi_sta_iface = IWifiStaIface::castFrom(getWifiStaIface(instance_name));
        EXPECT_NE(nullptr, wifi_sta_iface.get());

        const auto& status_and_controller =
                HIDL_INVOKE(wifi_chip, createRttController_1_6, wifi_sta_iface);
        EXPECT_EQ(WifiStatusCode::SUCCESS, status_and_controller.first.code);
        EXPECT_NE(nullptr, status_and_controller.second.get());

        return status_and_controller.second.get();
    }
};

/*
 * registerEventCallback_1_6
 * This test case tests the registerEventCallback_1_6() API which registers
 * a call back function with the hal implementation
 *
 * Note: it is not feasible to test the invocation of the call back function
 * since event is triggered internally in the HAL implementation, and can not be
 * triggered from the test case
 */
TEST_P(WifiRttControllerHidlTest, RegisterEventCallback_1_6) {
    sp<WifiRttControllerEventCallback> wifiRttControllerEventCallback =
            new WifiRttControllerEventCallback();
    const auto& status = HIDL_INVOKE(wifi_rtt_controller_, registerEventCallback_1_6,
                                     wifiRttControllerEventCallback);
    EXPECT_EQ(WifiStatusCode::SUCCESS, status.code);
}

/*
 * Request2SidedRangeMeasurement
 * This test case tests the two sided ranging - 802.11mc FTM protocol.
 */
TEST_P(WifiRttControllerHidlTest, Request2SidedRangeMeasurement) {
    std::pair<WifiStatus, RttCapabilities> status_and_caps;

    // Get the Capabilities
    status_and_caps = HIDL_INVOKE(wifi_rtt_controller_, getCapabilities_1_6);
    EXPECT_EQ(WifiStatusCode::SUCCESS, status_and_caps.first.code);
    if (!status_and_caps.second.rttFtmSupported) {
        GTEST_SKIP() << "Skipping two sided RTT since driver/fw doesn't support";
    }
    std::vector<RttConfig> configs;
    RttConfig config;
    int cmdId = 55;
    // Set the config with test data
    for (int i = 0; i < 6; i++) {
        config.addr[i] = i;
    }
    config.type = RttType::TWO_SIDED;
    config.peer = RttPeerType::AP;
    config.channel.width = WifiChannelWidthInMhz::WIDTH_80;
    config.channel.centerFreq = 5180;
    config.channel.centerFreq0 = 5210;
    config.channel.centerFreq1 = 0;
    config.bw = RttBw::BW_20MHZ;
    config.preamble = RttPreamble::HT;
    config.mustRequestLci = false;
    config.mustRequestLcr = false;
    config.burstPeriod = 0;
    config.numBurst = 0;
    config.numFramesPerBurst = 8;
    config.numRetriesPerRttFrame = 0;
    config.numRetriesPerFtmr = 0;
    config.burstDuration = 9;
    // Insert config in the vector
    configs.push_back(config);

    // Invoke the call
    const auto& status = HIDL_INVOKE(wifi_rtt_controller_, rangeRequest_1_6, cmdId, configs);
    EXPECT_EQ(WifiStatusCode::SUCCESS, status.code);
    // sleep for 2 seconds to wait for driver/firmware to complete RTT
    sleep(2);
}

/*
 * rangeRequest_1_6
 */
TEST_P(WifiRttControllerHidlTest, RangeRequest_1_6) {
    std::pair<WifiStatus, RttCapabilities> status_and_caps;

    // Get the Capabilities
    status_and_caps = HIDL_INVOKE(wifi_rtt_controller_, getCapabilities_1_6);
    EXPECT_EQ(WifiStatusCode::SUCCESS, status_and_caps.first.code);
    if (!status_and_caps.second.rttOneSidedSupported) {
        GTEST_SKIP() << "Skipping one sided RTT since driver/fw doesn't support";
    }
    // Get the highest support preamble
    int preamble = 1;
    status_and_caps.second.preambleSupport >>= 1;
    while (status_and_caps.second.preambleSupport != 0) {
        status_and_caps.second.preambleSupport >>= 1;
        preamble <<= 1;
    }
    std::vector<RttConfig> configs;
    RttConfig config;
    int cmdId = 55;
    // Set the config with test data
    for (int i = 0; i < 6; i++) {
        config.addr[i] = i;
    }
    config.type = RttType::ONE_SIDED;
    config.peer = RttPeerType::AP;
    config.channel.width = WifiChannelWidthInMhz::WIDTH_80;
    config.channel.centerFreq = 5765;
    config.channel.centerFreq0 = 5775;
    config.channel.centerFreq1 = 0;
    config.bw = RttBw::BW_80MHZ;
    config.preamble = (RttPreamble)preamble;
    config.mustRequestLci = false;
    config.mustRequestLcr = false;
    config.burstPeriod = 0;
    config.numBurst = 0;
    config.numFramesPerBurst = 8;
    config.numRetriesPerRttFrame = 3;
    config.numRetriesPerFtmr = 3;
    config.burstDuration = 9;
    // Insert config in the vector
    configs.push_back(config);

    // Invoke the call
    const auto& status = HIDL_INVOKE(wifi_rtt_controller_, rangeRequest_1_6, cmdId, configs);
    EXPECT_EQ(WifiStatusCode::SUCCESS, status.code);
    // sleep for 2 seconds to wait for driver/firmware to complete RTT
    sleep(2);
}

/*
 * getCapabilities_1_6
 */
TEST_P(WifiRttControllerHidlTest, GetCapabilities_1_6) {
    std::pair<WifiStatus, RttCapabilities> status_and_caps;

    // Invoke the call
    status_and_caps = HIDL_INVOKE(wifi_rtt_controller_, getCapabilities_1_6);
    EXPECT_EQ(WifiStatusCode::SUCCESS, status_and_caps.first.code);
}

/*
 * getResponderInfo_1_6
 */
TEST_P(WifiRttControllerHidlTest, GetResponderInfo_1_6) {
    std::pair<WifiStatus, RttResponder> status_and_info;

    // Invoke the call
    status_and_info = HIDL_INVOKE(wifi_rtt_controller_, getResponderInfo_1_6);
    EXPECT_EQ(WifiStatusCode::SUCCESS, status_and_info.first.code);
}

/*
 * enableResponder_1_6
 */
TEST_P(WifiRttControllerHidlTest, EnableResponder_1_6) {
    std::pair<WifiStatus, RttResponder> status_and_info;
    int cmdId = 55;
    WifiChannelInfo channelInfo;
    channelInfo.width = WifiChannelWidthInMhz::WIDTH_80;
    channelInfo.centerFreq = 5660;
    channelInfo.centerFreq0 = 5660;
    channelInfo.centerFreq1 = 0;

    // Get the responder first
    status_and_info = HIDL_INVOKE(wifi_rtt_controller_, getResponderInfo_1_6);
    EXPECT_EQ(WifiStatusCode::SUCCESS, status_and_info.first.code);

    // Invoke the call
    const auto& status = HIDL_INVOKE(wifi_rtt_controller_, enableResponder_1_6, cmdId, channelInfo,
                                     10, status_and_info.second);
    EXPECT_EQ(WifiStatusCode::SUCCESS, status.code);
}

GTEST_ALLOW_UNINSTANTIATED_PARAMETERIZED_TEST(WifiRttControllerHidlTest);
INSTANTIATE_TEST_SUITE_P(PerInstance, WifiRttControllerHidlTest,
                         testing::ValuesIn(android::hardware::getAllHalInstanceNames(
                                 ::android::hardware::wifi::V1_6::IWifi::descriptor)),
                         android::hardware::PrintInstanceNameToString);
Loading