From 2236b96bf451bdf131643c5e64cf627be0f91143 Mon Sep 17 00:00:00 2001 From: Ye Jiao Date: Mon, 28 Aug 2023 15:22:43 +0800 Subject: [PATCH] Disable Wi-Fi framework during VTS When VTS case kills supplicant in SetUp, Wi-Fi framework will trigger recovery process and causes races between VTS and Wi-Fi framework. Disable Wi-Fi framework using 'cmd wifi' in SetUp. Bug: 297820612 Test: run vts -m VtsHalWifiHostapdV1_0TargetTest with new case (cherry picked from https://android-review.googlesource.com/q/commit:46538346af90bf93dcafa36206fc2ea5c545dd93) Merged-In: I5ea7f00cfebf79021185f66766454d053c973b31 Change-Id: I5ea7f00cfebf79021185f66766454d053c973b31 --- .../1.0/vts/functional/hostapd_hidl_test.cpp | 18 ++++++++++++++-- .../functional/hostapd_hidl_test_utils.cpp | 21 +++++++++++++++++++ .../vts/functional/hostapd_hidl_test_utils.h | 7 +++++-- 3 files changed, 42 insertions(+), 4 deletions(-) diff --git a/wifi/hostapd/1.0/vts/functional/hostapd_hidl_test.cpp b/wifi/hostapd/1.0/vts/functional/hostapd_hidl_test.cpp index bb99ae4d6b..46cba93c72 100644 --- a/wifi/hostapd/1.0/vts/functional/hostapd_hidl_test.cpp +++ b/wifi/hostapd/1.0/vts/functional/hostapd_hidl_test.cpp @@ -48,6 +48,13 @@ class HostapdHidlTest virtual void SetUp() override { wifi_instance_name_ = std::get<0>(GetParam()); hostapd_instance_name_ = std::get<1>(GetParam()); + + // Disable Wi-Fi framework to avoid interference + isWifiEnabled_ = isWifiFrameworkEnabled(); + isScanAlwaysEnabled_ = isWifiScanAlwaysAvailable(); + toggleWifiFramework(false); + toggleWifiScanAlwaysAvailable(false); + stopSupplicantIfNeeded(wifi_instance_name_); startHostapdAndWaitForHidlService(wifi_instance_name_, hostapd_instance_name_); @@ -58,14 +65,21 @@ class HostapdHidlTest virtual void TearDown() override { HIDL_INVOKE_VOID_WITHOUT_ARGUMENTS(hostapd_, terminate); stopHostapd(wifi_instance_name_); + + // Restore Wi-Fi framework state + toggleWifiFramework(isWifiEnabled_); + toggleWifiScanAlwaysAvailable(isScanAlwaysEnabled_); } protected: - std::string getPrimaryWlanIfaceName() { + bool isWifiEnabled_ = false; + bool isScanAlwaysEnabled_ = false; + + std::string getPrimaryWlanIfaceName() { std::array buffer; property_get("wifi.interface", buffer.data(), "wlan0"); return buffer.data(); - } + } IHostapd::IfaceParams getIfaceParamsWithAcs() { IHostapd::IfaceParams iface_params; diff --git a/wifi/hostapd/1.0/vts/functional/hostapd_hidl_test_utils.cpp b/wifi/hostapd/1.0/vts/functional/hostapd_hidl_test_utils.cpp index 56f285d147..4c452fbd86 100644 --- a/wifi/hostapd/1.0/vts/functional/hostapd_hidl_test_utils.cpp +++ b/wifi/hostapd/1.0/vts/functional/hostapd_hidl_test_utils.cpp @@ -98,3 +98,24 @@ bool is_1_1(const sp& hostapd) { ::android::hardware::wifi::hostapd::V1_1::IHostapd::castFrom(hostapd); return hostapd_1_1.get() != nullptr; } + +void toggleWifiFramework(bool enable) { + std::string cmd = "/system/bin/cmd wifi set-wifi-enabled "; + cmd += enable ? "enabled" : "disabled"; + testing::checkSubstringInCommandOutput(cmd.c_str(), "X"); +} + +void toggleWifiScanAlwaysAvailable(bool enable) { + std::string cmd = "/system/bin/cmd wifi set-scan-always-available "; + cmd += enable ? "enabled" : "disabled"; + testing::checkSubstringInCommandOutput(cmd.c_str(), "X"); +} + +bool isWifiFrameworkEnabled() { + return testing::checkSubstringInCommandOutput("/system/bin/cmd wifi status", "Wifi is enabled"); +} + +bool isWifiScanAlwaysAvailable() { + return testing::checkSubstringInCommandOutput("/system/bin/cmd wifi status", + "Wifi scanning is always available"); +} diff --git a/wifi/hostapd/1.0/vts/functional/hostapd_hidl_test_utils.h b/wifi/hostapd/1.0/vts/functional/hostapd_hidl_test_utils.h index 893de1e334..aa34c9a98f 100644 --- a/wifi/hostapd/1.0/vts/functional/hostapd_hidl_test_utils.h +++ b/wifi/hostapd/1.0/vts/functional/hostapd_hidl_test_utils.h @@ -17,14 +17,17 @@ #ifndef HOSTAPD_HIDL_TEST_UTILS_H #define HOSTAPD_HIDL_TEST_UTILS_H +#include #include #include // Used to stop the android wifi framework before every test. -void stopWifiFramework(const std::string& instance_name); -void startWifiFramework(const std::string& instance_name); void stopSupplicantIfNeeded(const std::string& instance_name); void stopHostapd(const std::string& instance_name); +void toggleWifiFramework(bool enable); +void toggleWifiScanAlwaysAvailable(bool enable); +bool isWifiFrameworkEnabled(); +bool isWifiScanAlwaysAvailable(); // Used to configure the chip, driver and start wpa_hostapd before every // test. void startHostapdAndWaitForHidlService(