Add hostapd_test_utils helper methods for the am: 3454ce179a
am: b3a1c6260f
am: 1539083a4d
Original change: https://googleplex-android-review.googlesource.com/c/platform/hardware/interfaces/+/24589589 Change-Id: I19e2c08a465b37c464e19b79a1424222096b81e7 Signed-off-by: Automerger Merge Worker <android-build-automerger-merge-worker@system.gserviceaccount.com>
This commit is contained in:
commit
61ae64167c
6 changed files with 283 additions and 7 deletions
|
@ -41,10 +41,9 @@ using ::android::hardware::wifi::V1_0::IWifiChip;
|
||||||
using ::android::wifi_system::HostapdManager;
|
using ::android::wifi_system::HostapdManager;
|
||||||
using ::android::wifi_system::SupplicantManager;
|
using ::android::wifi_system::SupplicantManager;
|
||||||
|
|
||||||
namespace {
|
|
||||||
// Helper function to initialize the driver and firmware to AP mode
|
// Helper function to initialize the driver and firmware to AP mode
|
||||||
// using the vendor HAL HIDL interface.
|
// 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) {
|
if (getWifi(wifi_instance_name) != nullptr) {
|
||||||
sp<IWifiChip> wifi_chip = getWifiChip(wifi_instance_name);
|
sp<IWifiChip> wifi_chip = getWifiChip(wifi_instance_name);
|
||||||
ChipModeId mode_id;
|
ChipModeId mode_id;
|
||||||
|
@ -57,21 +56,20 @@ void initilializeDriverAndFirmware(const std::string& wifi_instance_name) {
|
||||||
|
|
||||||
// Helper function to deinitialize the driver and firmware
|
// Helper function to deinitialize the driver and firmware
|
||||||
// using the vendor HAL HIDL interface.
|
// 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) {
|
if (getWifi(wifi_instance_name) != nullptr) {
|
||||||
stopWifi(wifi_instance_name);
|
stopWifi(wifi_instance_name);
|
||||||
} else {
|
} else {
|
||||||
LOG(WARNING) << __func__ << ": Vendor HAL not supported";
|
LOG(WARNING) << __func__ << ": Vendor HAL not supported";
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
} // namespace
|
|
||||||
|
|
||||||
void stopSupplicantIfNeeded(const std::string& instance_name) {
|
void stopSupplicantIfNeeded(const std::string& instance_name) {
|
||||||
SupplicantManager supplicant_manager;
|
SupplicantManager supplicant_manager;
|
||||||
if (supplicant_manager.IsSupplicantRunning()) {
|
if (supplicant_manager.IsSupplicantRunning()) {
|
||||||
LOG(INFO) << "Supplicant is running, stop supplicant first.";
|
LOG(INFO) << "Supplicant is running, stop supplicant first.";
|
||||||
ASSERT_TRUE(supplicant_manager.StopSupplicant());
|
ASSERT_TRUE(supplicant_manager.StopSupplicant());
|
||||||
deInitilializeDriverAndFirmware(instance_name);
|
deInitializeDriverAndFirmware(instance_name);
|
||||||
ASSERT_FALSE(supplicant_manager.IsSupplicantRunning());
|
ASSERT_FALSE(supplicant_manager.IsSupplicantRunning());
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -80,13 +78,13 @@ void stopHostapd(const std::string& instance_name) {
|
||||||
HostapdManager hostapd_manager;
|
HostapdManager hostapd_manager;
|
||||||
|
|
||||||
ASSERT_TRUE(hostapd_manager.StopHostapd());
|
ASSERT_TRUE(hostapd_manager.StopHostapd());
|
||||||
deInitilializeDriverAndFirmware(instance_name);
|
deInitializeDriverAndFirmware(instance_name);
|
||||||
}
|
}
|
||||||
|
|
||||||
void startHostapdAndWaitForHidlService(
|
void startHostapdAndWaitForHidlService(
|
||||||
const std::string& wifi_instance_name,
|
const std::string& wifi_instance_name,
|
||||||
const std::string& hostapd_instance_name) {
|
const std::string& hostapd_instance_name) {
|
||||||
initilializeDriverAndFirmware(wifi_instance_name);
|
initializeDriverAndFirmware(wifi_instance_name);
|
||||||
|
|
||||||
HostapdManager hostapd_manager;
|
HostapdManager hostapd_manager;
|
||||||
ASSERT_TRUE(hostapd_manager.StartHostapd());
|
ASSERT_TRUE(hostapd_manager.StartHostapd());
|
||||||
|
|
|
@ -33,5 +33,9 @@ void startHostapdAndWaitForHidlService(
|
||||||
|
|
||||||
bool is_1_1(const android::sp<android::hardware::wifi::hostapd::V1_0::IHostapd>&
|
bool is_1_1(const android::sp<android::hardware::wifi::hostapd::V1_0::IHostapd>&
|
||||||
hostapd);
|
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 */
|
#endif /* HOSTAPD_HIDL_TEST_UTILS_H */
|
||||||
|
|
|
@ -37,6 +37,7 @@ cc_test {
|
||||||
"android.hardware.wifi@1.5",
|
"android.hardware.wifi@1.5",
|
||||||
"android.hardware.wifi@1.6",
|
"android.hardware.wifi@1.6",
|
||||||
"android.hardware.wifi-V1-ndk",
|
"android.hardware.wifi-V1-ndk",
|
||||||
|
"libwifi-system",
|
||||||
"libwifi-system-iface",
|
"libwifi-system-iface",
|
||||||
"VtsHalWifiTargetTestUtil",
|
"VtsHalWifiTargetTestUtil",
|
||||||
],
|
],
|
||||||
|
|
80
wifi/hostapd/aidl/vts/functional/hostapd_aidl_test_utils.h
Normal file
80
wifi/hostapd/aidl/vts/functional/hostapd_aidl_test_utils.h
Normal file
|
@ -0,0 +1,80 @@
|
||||||
|
/*
|
||||||
|
* 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
wifi/hostapd/aidl/vts/functional/hostapd_legacy_test_utils.h
Normal file
71
wifi/hostapd/aidl/vts/functional/hostapd_legacy_test_utils.h
Normal file
|
@ -0,0 +1,71 @@
|
||||||
|
/*
|
||||||
|
* 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
|
122
wifi/hostapd/aidl/vts/functional/hostapd_test_utils.h
Normal file
122
wifi/hostapd/aidl/vts/functional/hostapd_test_utils.h
Normal file
|
@ -0,0 +1,122 @@
|
||||||
|
/*
|
||||||
|
* 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/hostapd/BnHostapd.h>
|
||||||
|
#include <android-base/logging.h>
|
||||||
|
#include <wifi_system/hostapd_manager.h>
|
||||||
|
#include <wifi_system/supplicant_manager.h>
|
||||||
|
|
||||||
|
#include "hostapd_aidl_test_utils.h"
|
||||||
|
#include "hostapd_legacy_test_utils.h"
|
||||||
|
|
||||||
|
using aidl::android::hardware::wifi::hostapd::IHostapd;
|
||||||
|
using android::wifi_system::HostapdManager;
|
||||||
|
using android::wifi_system::SupplicantManager;
|
||||||
|
|
||||||
|
namespace {
|
||||||
|
|
||||||
|
void startAndConfigureVendorHal() {
|
||||||
|
if (HostapdAidlTestUtils::useAidlService()) {
|
||||||
|
HostapdAidlTestUtils::startAndConfigureVendorHal();
|
||||||
|
} else {
|
||||||
|
HostapdLegacyTestUtils::startAndConfigureVendorHal();
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
void stopVendorHal() {
|
||||||
|
if (HostapdAidlTestUtils::useAidlService()) {
|
||||||
|
HostapdAidlTestUtils::stopVendorHal();
|
||||||
|
} else {
|
||||||
|
HostapdLegacyTestUtils::stopVendorHal();
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
void stopHostapd() {
|
||||||
|
HostapdManager hostapd_manager;
|
||||||
|
ASSERT_TRUE(hostapd_manager.StopHostapd());
|
||||||
|
}
|
||||||
|
|
||||||
|
void waitForSupplicantState(bool enable) {
|
||||||
|
SupplicantManager supplicant_manager;
|
||||||
|
int count = 50; // wait at most 5 seconds
|
||||||
|
while (count-- > 0) {
|
||||||
|
if (supplicant_manager.IsSupplicantRunning() == enable) {
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
usleep(100000); // 100 ms
|
||||||
|
}
|
||||||
|
LOG(ERROR) << "Unable to " << (enable ? "start" : "stop") << " supplicant";
|
||||||
|
}
|
||||||
|
|
||||||
|
void toggleWifiFramework(bool enable) {
|
||||||
|
if (enable) {
|
||||||
|
std::system("svc wifi enable");
|
||||||
|
std::system("cmd wifi set-scan-always-available enabled");
|
||||||
|
waitForSupplicantState(true);
|
||||||
|
} else {
|
||||||
|
std::system("svc wifi disable");
|
||||||
|
std::system("cmd wifi set-scan-always-available disabled");
|
||||||
|
waitForSupplicantState(false);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
} // namespace
|
||||||
|
|
||||||
|
std::shared_ptr<IHostapd> getHostapd(const std::string& hostapd_instance_name) {
|
||||||
|
return IHostapd::fromBinder(
|
||||||
|
ndk::SpAIBinder(AServiceManager_waitForService(hostapd_instance_name.c_str())));
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Disable the Wifi framework, hostapd, and vendor HAL.
|
||||||
|
*
|
||||||
|
* Note: The framework should be disabled to avoid having
|
||||||
|
* any other clients to the HALs during testing.
|
||||||
|
*/
|
||||||
|
void disableHalsAndFramework() {
|
||||||
|
toggleWifiFramework(false);
|
||||||
|
stopHostapd();
|
||||||
|
stopVendorHal();
|
||||||
|
|
||||||
|
// Wait for the services to stop.
|
||||||
|
sleep(3);
|
||||||
|
}
|
||||||
|
|
||||||
|
void initializeHostapdAndVendorHal(const std::string& hostapd_instance_name) {
|
||||||
|
startAndConfigureVendorHal();
|
||||||
|
HostapdManager hostapd_manager;
|
||||||
|
ASSERT_TRUE(hostapd_manager.StartHostapd());
|
||||||
|
getHostapd(hostapd_instance_name);
|
||||||
|
}
|
||||||
|
|
||||||
|
void stopHostapdAndVendorHal() {
|
||||||
|
stopHostapd();
|
||||||
|
stopVendorHal();
|
||||||
|
}
|
||||||
|
|
||||||
|
void startWifiFramework() {
|
||||||
|
toggleWifiFramework(true);
|
||||||
|
}
|
||||||
|
|
||||||
|
std::string setupApIfaceAndGetName(bool isBridged) {
|
||||||
|
if (HostapdAidlTestUtils::useAidlService()) {
|
||||||
|
return HostapdAidlTestUtils::setupApIfaceAndGetName(isBridged);
|
||||||
|
} else {
|
||||||
|
return HostapdLegacyTestUtils::setupApIfaceAndGetName(isBridged);
|
||||||
|
}
|
||||||
|
}
|
Loading…
Reference in a new issue