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

Commit 54487d90 authored by Gabriel Biren's avatar Gabriel Biren Committed by Automerger Merge Worker
Browse files

Add hostapd_test_utils helper methods for the am: 3454ce17 am: b3a1c626 am: 1539083a

parents d6765e03 1539083a
Loading
Loading
Loading
Loading
+5 −7
Original line number Diff line number Diff line
@@ -41,10 +41,9 @@ using ::android::hardware::wifi::V1_0::IWifiChip;
using ::android::wifi_system::HostapdManager;
using ::android::wifi_system::SupplicantManager;

namespace {
// Helper function to initialize the driver and firmware to AP mode
// using the vendor HAL HIDL interface.
void initilializeDriverAndFirmware(const std::string& wifi_instance_name) {
void initializeDriverAndFirmware(const std::string& wifi_instance_name) {
    if (getWifi(wifi_instance_name) != nullptr) {
        sp<IWifiChip> wifi_chip = getWifiChip(wifi_instance_name);
        ChipModeId mode_id;
@@ -57,21 +56,20 @@ void initilializeDriverAndFirmware(const std::string& wifi_instance_name) {

// Helper function to deinitialize the driver and firmware
// using the vendor HAL HIDL interface.
void deInitilializeDriverAndFirmware(const std::string& wifi_instance_name) {
void deInitializeDriverAndFirmware(const std::string& wifi_instance_name) {
    if (getWifi(wifi_instance_name) != nullptr) {
        stopWifi(wifi_instance_name);
    } else {
        LOG(WARNING) << __func__ << ": Vendor HAL not supported";
    }
}
}  // namespace

void stopSupplicantIfNeeded(const std::string& instance_name) {
    SupplicantManager supplicant_manager;
    if (supplicant_manager.IsSupplicantRunning()) {
        LOG(INFO) << "Supplicant is running, stop supplicant first.";
        ASSERT_TRUE(supplicant_manager.StopSupplicant());
        deInitilializeDriverAndFirmware(instance_name);
        deInitializeDriverAndFirmware(instance_name);
        ASSERT_FALSE(supplicant_manager.IsSupplicantRunning());
    }
}
@@ -80,13 +78,13 @@ void stopHostapd(const std::string& instance_name) {
    HostapdManager hostapd_manager;

    ASSERT_TRUE(hostapd_manager.StopHostapd());
    deInitilializeDriverAndFirmware(instance_name);
    deInitializeDriverAndFirmware(instance_name);
}

void startHostapdAndWaitForHidlService(
    const std::string& wifi_instance_name,
    const std::string& hostapd_instance_name) {
    initilializeDriverAndFirmware(wifi_instance_name);
    initializeDriverAndFirmware(wifi_instance_name);

    HostapdManager hostapd_manager;
    ASSERT_TRUE(hostapd_manager.StartHostapd());
+4 −0
Original line number Diff line number Diff line
@@ -33,5 +33,9 @@ void startHostapdAndWaitForHidlService(

bool is_1_1(const android::sp<android::hardware::wifi::hostapd::V1_0::IHostapd>&
                hostapd);
// Used to initialize/deinitialize the driver and firmware at the
// beginning and end of each test.
void initializeDriverAndFirmware(const std::string& wifi_instance_name);
void deInitializeDriverAndFirmware(const std::string& wifi_instance_name);

#endif /* HOSTAPD_HIDL_TEST_UTILS_H */
+1 −0
Original line number Diff line number Diff line
@@ -37,6 +37,7 @@ cc_test {
        "android.hardware.wifi@1.5",
        "android.hardware.wifi@1.6",
        "android.hardware.wifi-V1-ndk",
        "libwifi-system",
        "libwifi-system-iface",
        "VtsHalWifiTargetTestUtil",
    ],
+80 −0
Original line number Diff line number Diff line
/*
 * Copyright (C) 2023 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.
 */

#pragma once

#include <aidl/android/hardware/wifi/IWifi.h>
#include <android-base/logging.h>

#include "wifi_aidl_test_utils.h"

namespace {

const std::string kWifiInstanceNameStr = std::string() + IWifi::descriptor + "/default";
const char* kWifiInstanceName = kWifiInstanceNameStr.c_str();

}  // namespace

namespace HostapdAidlTestUtils {

bool useAidlService() {
    return isAidlServiceAvailable(kWifiInstanceName);
}

void startAndConfigureVendorHal() {
    if (getWifi(kWifiInstanceName) != nullptr) {
        std::shared_ptr<IWifiChip> wifi_chip = getWifiChip(kWifiInstanceName);
        int mode_id;
        EXPECT_TRUE(configureChipToSupportConcurrencyType(wifi_chip, IfaceConcurrencyType::AP,
                                                          &mode_id));
    } else {
        LOG(ERROR) << "Unable to initialize Vendor HAL";
    }
}

void stopVendorHal() {
    if (getWifi(kWifiInstanceName) != nullptr) {
        stopWifiService(kWifiInstanceName);
    } else {
        LOG(ERROR) << "Unable to stop Vendor HAL";
    }
}

std::string setupApIfaceAndGetName(bool isBridged) {
    std::shared_ptr<IWifiApIface> wifi_ap_iface;
    if (isBridged) {
        wifi_ap_iface = getBridgedWifiApIface(kWifiInstanceName);
    } else {
        wifi_ap_iface = getWifiApIface(kWifiInstanceName);
    }

    EXPECT_TRUE(wifi_ap_iface.get() != nullptr);
    if (!wifi_ap_iface.get()) {
        LOG(ERROR) << "Unable to create iface. isBridged=" << isBridged;
        return "";
    }

    std::string ap_iface_name;
    auto status = wifi_ap_iface->getName(&ap_iface_name);
    EXPECT_TRUE(status.isOk());
    if (!status.isOk()) {
        LOG(ERROR) << "Unable to retrieve iface name. isBridged=" << isBridged;
        return "";
    }
    return ap_iface_name;
}

}  // namespace HostapdAidlTestUtils
+71 −0
Original line number Diff line number Diff line
/*
 * Copyright (C) 2023 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.
 */

#pragma once

#include <android-base/logging.h>

#include "hostapd_hidl_test_utils.h"
#include "wifi_hidl_test_utils.h"

using ::android::hardware::wifi::V1_0::WifiStatus;

namespace {

std::string getWifiInstanceName() {
    const std::vector<std::string> instances = android::hardware::getAllHalInstanceNames(
            ::android::hardware::wifi::V1_0::IWifi::descriptor);
    EXPECT_NE(0, instances.size());
    return instances.size() != 0 ? instances[0] : "";
}

}  // namespace

namespace HostapdLegacyTestUtils {

void startAndConfigureVendorHal() {
    initializeDriverAndFirmware(getWifiInstanceName());
}

void stopVendorHal() {
    deInitializeDriverAndFirmware(getWifiInstanceName());
}

std::string setupApIfaceAndGetName(bool isBridged) {
    android::sp<::android::hardware::wifi::V1_0::IWifiApIface> wifi_ap_iface;
    if (isBridged) {
        wifi_ap_iface = getBridgedWifiApIface_1_6(getWifiInstanceName());
    } else {
        wifi_ap_iface = getWifiApIface_1_5(getWifiInstanceName());
    }

    EXPECT_TRUE(wifi_ap_iface.get() != nullptr);
    if (!wifi_ap_iface.get()) {
        LOG(ERROR) << "Unable to create iface. isBridged=" << isBridged;
        return "";
    }

    const auto& status_and_name = HIDL_INVOKE(wifi_ap_iface, getName);
    EXPECT_TRUE(status_and_name.first.code ==
                android::hardware::wifi::V1_0::WifiStatusCode::SUCCESS);
    if (status_and_name.first.code != android::hardware::wifi::V1_0::WifiStatusCode::SUCCESS) {
        LOG(ERROR) << "Unable to retrieve iface name. isBridged=" << isBridged;
        return "";
    }
    return status_and_name.second;
}

}  // namespace HostapdLegacyTestUtils
Loading