Improve initialization sequence for supplicant

AIDL VTS tests.

Bug: 215298798
Bug: 215467859
Test: atest VtsHalWifiSupplicantStaIfaceTargetTest \
            VtsHalWifiSupplicantStaNetworkTargetTest \
            VtsHalWifiSupplicantP2pIfaceTargetTest
      (Tested on both a Coral and Oriole device)
Change-Id: I435e16a447af16d9cd619c5bc8883ed24151080a
This commit is contained in:
Gabriel Biren 2022-01-31 22:26:08 +00:00
parent 71af5c2da9
commit 4e6c9a2b80
7 changed files with 128 additions and 91 deletions

View file

@ -69,37 +69,6 @@ bool waitForSupplicantStart() { return waitForSupplicantState(true); }
// disable. // disable.
bool waitForSupplicantStop() { return waitForSupplicantState(false); } bool waitForSupplicantStop() { return waitForSupplicantState(false); }
// Helper function to initialize the driver and firmware to STA mode
// using the vendor HAL HIDL interface.
void initilializeDriverAndFirmware(const std::string& wifi_instance_name) {
// Skip if wifi instance is not set.
if (wifi_instance_name == "") {
return;
}
if (getWifi(wifi_instance_name) != nullptr) {
sp<IWifiChip> wifi_chip = getWifiChip(wifi_instance_name);
ChipModeId mode_id;
EXPECT_TRUE(configureChipToSupportIfaceType(
wifi_chip, ::android::hardware::wifi::V1_0::IfaceType::STA, &mode_id));
} else {
LOG(WARNING) << __func__ << ": Vendor HAL not supported";
}
}
// Helper function to deinitialize the driver and firmware
// using the vendor HAL HIDL interface.
void deInitilializeDriverAndFirmware(const std::string& wifi_instance_name) {
// Skip if wifi instance is not set.
if (wifi_instance_name == "") {
return;
}
if (getWifi(wifi_instance_name) != nullptr) {
stopWifi(wifi_instance_name);
} else {
LOG(WARNING) << __func__ << ": Vendor HAL not supported";
}
}
// Helper function to find any iface of the desired type exposed. // Helper function to find any iface of the desired type exposed.
bool findIfaceOfType(sp<ISupplicant> supplicant, IfaceType desired_type, bool findIfaceOfType(sp<ISupplicant> supplicant, IfaceType desired_type,
ISupplicant::IfaceInfo* out_info) { ISupplicant::IfaceInfo* out_info) {
@ -156,14 +125,46 @@ void stopSupplicant(const std::string& wifi_instance_name) {
SupplicantManager supplicant_manager; SupplicantManager supplicant_manager;
ASSERT_TRUE(supplicant_manager.StopSupplicant()); ASSERT_TRUE(supplicant_manager.StopSupplicant());
deInitilializeDriverAndFirmware(wifi_instance_name); deInitializeDriverAndFirmware(wifi_instance_name);
ASSERT_FALSE(supplicant_manager.IsSupplicantRunning()); ASSERT_FALSE(supplicant_manager.IsSupplicantRunning());
} }
// Helper function to initialize the driver and firmware to STA mode
// using the vendor HAL HIDL interface.
void initializeDriverAndFirmware(const std::string& wifi_instance_name) {
// Skip if wifi instance is not set.
if (wifi_instance_name == "") {
return;
}
if (getWifi(wifi_instance_name) != nullptr) {
sp<IWifiChip> wifi_chip = getWifiChip(wifi_instance_name);
ChipModeId mode_id;
EXPECT_TRUE(configureChipToSupportIfaceType(
wifi_chip, ::android::hardware::wifi::V1_0::IfaceType::STA,
&mode_id));
} else {
LOG(WARNING) << __func__ << ": Vendor HAL not supported";
}
}
// Helper function to deinitialize the driver and firmware
// using the vendor HAL HIDL interface.
void deInitializeDriverAndFirmware(const std::string& wifi_instance_name) {
// Skip if wifi instance is not set.
if (wifi_instance_name == "") {
return;
}
if (getWifi(wifi_instance_name) != nullptr) {
stopWifi(wifi_instance_name);
} else {
LOG(WARNING) << __func__ << ": Vendor HAL not supported";
}
}
void startSupplicantAndWaitForHidlService( void startSupplicantAndWaitForHidlService(
const std::string& wifi_instance_name, const std::string& wifi_instance_name,
const std::string& supplicant_instance_name) { const std::string& supplicant_instance_name) {
initilializeDriverAndFirmware(wifi_instance_name); initializeDriverAndFirmware(wifi_instance_name);
SupplicantManager supplicant_manager; SupplicantManager supplicant_manager;
ASSERT_TRUE(supplicant_manager.StartSupplicant()); ASSERT_TRUE(supplicant_manager.StartSupplicant());

View file

@ -42,6 +42,11 @@ void startSupplicantAndWaitForHidlService(
const std::string& wifi_instance_name, const std::string& wifi_instance_name,
const std::string& supplicant_instance_name); const std::string& supplicant_instance_name);
// 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);
// Helper functions to obtain references to the various HIDL interface objects. // Helper functions to obtain references to the various HIDL interface objects.
// Note: We only have a single instance of each of these objects currently. // Note: We only have a single instance of each of these objects currently.
// These helper functions should be modified to return vectors if we support // These helper functions should be modified to return vectors if we support

View file

@ -33,11 +33,23 @@ cc_test {
shared_libs: [ shared_libs: [
"libbinder", "libbinder",
"libbinder_ndk", "libbinder_ndk",
"libvndksupport",
], ],
static_libs: [ static_libs: [
"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.supplicant@1.0",
"android.hardware.wifi.supplicant@1.1",
"android.hardware.wifi.supplicant-V1-ndk", "android.hardware.wifi.supplicant-V1-ndk",
"libwifi-system", "libwifi-system",
"libwifi-system-iface", "libwifi-system-iface",
"VtsHalWifiV1_0TargetTestUtil",
"VtsHalWifiV1_5TargetTestUtil",
"VtsHalWifiSupplicantV1_0TargetTestUtil",
], ],
test_suites: [ test_suites: [
"general-tests", "general-tests",
@ -55,11 +67,23 @@ cc_test {
shared_libs: [ shared_libs: [
"libbinder", "libbinder",
"libbinder_ndk", "libbinder_ndk",
"libvndksupport",
], ],
static_libs: [ static_libs: [
"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.supplicant@1.0",
"android.hardware.wifi.supplicant@1.1",
"android.hardware.wifi.supplicant-V1-ndk", "android.hardware.wifi.supplicant-V1-ndk",
"libwifi-system", "libwifi-system",
"libwifi-system-iface", "libwifi-system-iface",
"VtsHalWifiV1_0TargetTestUtil",
"VtsHalWifiV1_5TargetTestUtil",
"VtsHalWifiSupplicantV1_0TargetTestUtil",
], ],
test_suites: [ test_suites: [
"general-tests", "general-tests",
@ -77,11 +101,23 @@ cc_test {
shared_libs: [ shared_libs: [
"libbinder", "libbinder",
"libbinder_ndk", "libbinder_ndk",
"libvndksupport",
], ],
static_libs: [ static_libs: [
"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.supplicant@1.0",
"android.hardware.wifi.supplicant@1.1",
"android.hardware.wifi.supplicant-V1-ndk", "android.hardware.wifi.supplicant-V1-ndk",
"libwifi-system", "libwifi-system",
"libwifi-system-iface", "libwifi-system-iface",
"VtsHalWifiV1_0TargetTestUtil",
"VtsHalWifiV1_5TargetTestUtil",
"VtsHalWifiSupplicantV1_0TargetTestUtil",
], ],
test_suites: [ test_suites: [
"general-tests", "general-tests",

View file

@ -165,8 +165,7 @@ class SupplicantP2pIfaceAidlTest : public testing::TestWithParam<std::string> {
public: public:
void SetUp() override { void SetUp() override {
initializeService(); initializeService();
supplicant_ = ISupplicant::fromBinder(ndk::SpAIBinder( supplicant_ = getSupplicant(GetParam().c_str());
AServiceManager_waitForService(GetParam().c_str())));
ASSERT_NE(supplicant_, nullptr); ASSERT_NE(supplicant_, nullptr);
ASSERT_TRUE(supplicant_ ASSERT_TRUE(supplicant_
->setDebugParams(DebugLevel::EXCESSIVE, ->setDebugParams(DebugLevel::EXCESSIVE,
@ -180,13 +179,13 @@ class SupplicantP2pIfaceAidlTest : public testing::TestWithParam<std::string> {
GTEST_SKIP() << "Wi-Fi Direct is not supported, skip this test."; GTEST_SKIP() << "Wi-Fi Direct is not supported, skip this test.";
} }
EXPECT_TRUE(supplicant_->addP2pInterface(getP2pIfaceName(), &p2p_iface_) EXPECT_TRUE(supplicant_->getP2pInterface(getP2pIfaceName(), &p2p_iface_)
.isOk()); .isOk());
ASSERT_NE(p2p_iface_, nullptr); ASSERT_NE(p2p_iface_, nullptr);
} }
void TearDown() override { void TearDown() override {
stopSupplicant(); stopSupplicantService();
startWifiFramework(); startWifiFramework();
} }

View file

@ -197,21 +197,20 @@ class SupplicantStaIfaceAidlTest : public testing::TestWithParam<std::string> {
public: public:
void SetUp() override { void SetUp() override {
initializeService(); initializeService();
supplicant_ = ISupplicant::fromBinder(ndk::SpAIBinder( supplicant_ = getSupplicant(GetParam().c_str());
AServiceManager_waitForService(GetParam().c_str())));
ASSERT_NE(supplicant_, nullptr); ASSERT_NE(supplicant_, nullptr);
ASSERT_TRUE(supplicant_ ASSERT_TRUE(supplicant_
->setDebugParams(DebugLevel::EXCESSIVE, ->setDebugParams(DebugLevel::EXCESSIVE,
true, // show timestamps true, // show timestamps
true) true)
.isOk()); .isOk());
EXPECT_TRUE(supplicant_->addStaInterface(getStaIfaceName(), &sta_iface_) EXPECT_TRUE(supplicant_->getStaInterface(getStaIfaceName(), &sta_iface_)
.isOk()); .isOk());
ASSERT_NE(sta_iface_, nullptr); ASSERT_NE(sta_iface_, nullptr);
} }
void TearDown() override { void TearDown() override {
stopSupplicant(); stopSupplicantService();
startWifiFramework(); startWifiFramework();
} }

View file

@ -99,15 +99,14 @@ class SupplicantStaNetworkAidlTest
public: public:
void SetUp() override { void SetUp() override {
initializeService(); initializeService();
supplicant_ = ISupplicant::fromBinder(ndk::SpAIBinder( supplicant_ = getSupplicant(GetParam().c_str());
AServiceManager_waitForService(GetParam().c_str())));
ASSERT_NE(supplicant_, nullptr); ASSERT_NE(supplicant_, nullptr);
ASSERT_TRUE(supplicant_ ASSERT_TRUE(supplicant_
->setDebugParams(DebugLevel::EXCESSIVE, ->setDebugParams(DebugLevel::EXCESSIVE,
true, // show timestamps true, // show timestamps
true) true)
.isOk()); .isOk());
EXPECT_TRUE(supplicant_->addStaInterface(getStaIfaceName(), &sta_iface_) EXPECT_TRUE(supplicant_->getStaInterface(getStaIfaceName(), &sta_iface_)
.isOk()); .isOk());
ASSERT_NE(sta_iface_, nullptr); ASSERT_NE(sta_iface_, nullptr);
EXPECT_TRUE(sta_iface_->addNetwork(&sta_network_).isOk()); EXPECT_TRUE(sta_iface_->addNetwork(&sta_network_).isOk());
@ -115,7 +114,7 @@ class SupplicantStaNetworkAidlTest
} }
void TearDown() override { void TearDown() override {
stopSupplicant(); stopSupplicantService();
startWifiFramework(); startWifiFramework();
} }

View file

@ -19,8 +19,14 @@
#include <VtsCoreUtil.h> #include <VtsCoreUtil.h>
#include <android-base/logging.h> #include <android-base/logging.h>
#include <android/hardware/wifi/1.0/IWifi.h>
#include <hidl/ServiceManagement.h>
#include <supplicant_hidl_test_utils.h>
#include <wifi_system/supplicant_manager.h> #include <wifi_system/supplicant_manager.h>
using aidl::android::hardware::wifi::supplicant::IfaceInfo;
using aidl::android::hardware::wifi::supplicant::ISupplicant;
using aidl::android::hardware::wifi::supplicant::ISupplicantP2pIface;
using aidl::android::hardware::wifi::supplicant::ISupplicantStaIface; using aidl::android::hardware::wifi::supplicant::ISupplicantStaIface;
using aidl::android::hardware::wifi::supplicant::KeyMgmtMask; using aidl::android::hardware::wifi::supplicant::KeyMgmtMask;
using android::wifi_system::SupplicantManager; using android::wifi_system::SupplicantManager;
@ -37,6 +43,14 @@ std::string getP2pIfaceName() {
return std::string(buffer.data()); return std::string(buffer.data());
} }
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] : "";
}
bool keyMgmtSupported(std::shared_ptr<ISupplicantStaIface> iface, bool keyMgmtSupported(std::shared_ptr<ISupplicantStaIface> iface,
KeyMgmtMask expected) { KeyMgmtMask expected) {
KeyMgmtMask caps; KeyMgmtMask caps;
@ -53,60 +67,44 @@ bool isFilsSupported(std::shared_ptr<ISupplicantStaIface> iface) {
return keyMgmtSupported(iface, filsMask); return keyMgmtSupported(iface, filsMask);
} }
bool waitForSupplicantState(bool is_running) { void startSupplicant() {
initializeDriverAndFirmware(getWifiInstanceName());
SupplicantManager supplicant_manager; SupplicantManager supplicant_manager;
int count = 50; /* wait at most 5 seconds for completion */ ASSERT_TRUE(supplicant_manager.StartSupplicant());
while (count-- > 0) { ASSERT_TRUE(supplicant_manager.IsSupplicantRunning());
if (supplicant_manager.IsSupplicantRunning() == is_running) {
return true;
}
usleep(100000);
}
LOG(ERROR) << "Supplicant not " << (is_running ? "running" : "stopped");
return false;
} }
bool waitForFrameworkReady() { // Wrapper around the implementation in supplicant_hidl_test_util.
int waitCount = 15; void stopSupplicantService() { stopSupplicant(getWifiInstanceName()); }
do {
// Check whether package service is ready or not.
if (!testing::checkSubstringInCommandOutput(
"/system/bin/service check package", ": not found")) {
return true;
}
LOG(INFO) << "Framework is not ready";
sleep(1);
} while (waitCount-- > 0);
return false;
}
bool waitForSupplicantStart() { return waitForSupplicantState(true); }
bool waitForSupplicantStop() { return waitForSupplicantState(false); }
void stopSupplicant() {
SupplicantManager supplicant_manager;
ASSERT_TRUE(supplicant_manager.StopSupplicant());
ASSERT_FALSE(supplicant_manager.IsSupplicantRunning());
}
bool startWifiFramework() {
std::system("svc wifi enable");
std::system("cmd wifi set-scan-always-available enabled");
return waitForSupplicantStart();
}
bool stopWifiFramework() {
std::system("svc wifi disable");
std::system("cmd wifi set-scan-always-available disabled");
return waitForSupplicantStop();
}
void initializeService() { void initializeService() {
ASSERT_TRUE(stopWifiFramework()); ASSERT_TRUE(stopWifiFramework());
std::system("/system/bin/start"); std::system("/system/bin/start");
ASSERT_TRUE(waitForFrameworkReady()); ASSERT_TRUE(waitForFrameworkReady());
stopSupplicant(); stopSupplicantService();
startSupplicant();
}
void addStaIface(const std::shared_ptr<ISupplicant> supplicant) {
ASSERT_TRUE(supplicant.get());
std::shared_ptr<ISupplicantStaIface> iface;
ASSERT_TRUE(supplicant->addStaInterface(getStaIfaceName(), &iface).isOk());
}
void addP2pIface(const std::shared_ptr<ISupplicant> supplicant) {
ASSERT_TRUE(supplicant.get());
std::shared_ptr<ISupplicantP2pIface> iface;
ASSERT_TRUE(supplicant->addP2pInterface(getP2pIfaceName(), &iface).isOk());
}
std::shared_ptr<ISupplicant> getSupplicant(const char* supplicant_name) {
std::shared_ptr<ISupplicant> supplicant = ISupplicant::fromBinder(
ndk::SpAIBinder(AServiceManager_waitForService(supplicant_name)));
addStaIface(supplicant);
if (testing::deviceSupportsFeature("android.hardware.wifi.direct")) {
addP2pIface(supplicant);
}
return supplicant;
} }
#endif // SUPPLICANT_TEST_UTILS_H #endif // SUPPLICANT_TEST_UTILS_H