diff --git a/wifi/supplicant/1.0/vts/functional/supplicant_hidl_test_utils.cpp b/wifi/supplicant/1.0/vts/functional/supplicant_hidl_test_utils.cpp index 8cb7e22f0e..1606b7bd47 100644 --- a/wifi/supplicant/1.0/vts/functional/supplicant_hidl_test_utils.cpp +++ b/wifi/supplicant/1.0/vts/functional/supplicant_hidl_test_utils.cpp @@ -69,37 +69,6 @@ bool waitForSupplicantStart() { return waitForSupplicantState(true); } // disable. 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 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. bool findIfaceOfType(sp supplicant, IfaceType desired_type, ISupplicant::IfaceInfo* out_info) { @@ -156,14 +125,46 @@ void stopSupplicant(const std::string& wifi_instance_name) { SupplicantManager supplicant_manager; ASSERT_TRUE(supplicant_manager.StopSupplicant()); - deInitilializeDriverAndFirmware(wifi_instance_name); + deInitializeDriverAndFirmware(wifi_instance_name); 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 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( const std::string& wifi_instance_name, const std::string& supplicant_instance_name) { - initilializeDriverAndFirmware(wifi_instance_name); + initializeDriverAndFirmware(wifi_instance_name); SupplicantManager supplicant_manager; ASSERT_TRUE(supplicant_manager.StartSupplicant()); diff --git a/wifi/supplicant/1.0/vts/functional/supplicant_hidl_test_utils.h b/wifi/supplicant/1.0/vts/functional/supplicant_hidl_test_utils.h index 22cea8c14c..72286231b4 100644 --- a/wifi/supplicant/1.0/vts/functional/supplicant_hidl_test_utils.h +++ b/wifi/supplicant/1.0/vts/functional/supplicant_hidl_test_utils.h @@ -42,6 +42,11 @@ void startSupplicantAndWaitForHidlService( const std::string& wifi_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. // 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 diff --git a/wifi/supplicant/aidl/vts/functional/Android.bp b/wifi/supplicant/aidl/vts/functional/Android.bp index 65f96520f3..8e142ec2c0 100644 --- a/wifi/supplicant/aidl/vts/functional/Android.bp +++ b/wifi/supplicant/aidl/vts/functional/Android.bp @@ -33,11 +33,23 @@ cc_test { shared_libs: [ "libbinder", "libbinder_ndk", + "libvndksupport", ], 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", "libwifi-system", "libwifi-system-iface", + "VtsHalWifiV1_0TargetTestUtil", + "VtsHalWifiV1_5TargetTestUtil", + "VtsHalWifiSupplicantV1_0TargetTestUtil", ], test_suites: [ "general-tests", @@ -55,11 +67,23 @@ cc_test { shared_libs: [ "libbinder", "libbinder_ndk", + "libvndksupport", ], 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", "libwifi-system", "libwifi-system-iface", + "VtsHalWifiV1_0TargetTestUtil", + "VtsHalWifiV1_5TargetTestUtil", + "VtsHalWifiSupplicantV1_0TargetTestUtil", ], test_suites: [ "general-tests", @@ -77,11 +101,23 @@ cc_test { shared_libs: [ "libbinder", "libbinder_ndk", + "libvndksupport", ], 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", "libwifi-system", "libwifi-system-iface", + "VtsHalWifiV1_0TargetTestUtil", + "VtsHalWifiV1_5TargetTestUtil", + "VtsHalWifiSupplicantV1_0TargetTestUtil", ], test_suites: [ "general-tests", diff --git a/wifi/supplicant/aidl/vts/functional/supplicant_p2p_iface_aidl_test.cpp b/wifi/supplicant/aidl/vts/functional/supplicant_p2p_iface_aidl_test.cpp index d9d8179626..d5bdde2404 100644 --- a/wifi/supplicant/aidl/vts/functional/supplicant_p2p_iface_aidl_test.cpp +++ b/wifi/supplicant/aidl/vts/functional/supplicant_p2p_iface_aidl_test.cpp @@ -165,8 +165,7 @@ class SupplicantP2pIfaceAidlTest : public testing::TestWithParam { public: void SetUp() override { initializeService(); - supplicant_ = ISupplicant::fromBinder(ndk::SpAIBinder( - AServiceManager_waitForService(GetParam().c_str()))); + supplicant_ = getSupplicant(GetParam().c_str()); ASSERT_NE(supplicant_, nullptr); ASSERT_TRUE(supplicant_ ->setDebugParams(DebugLevel::EXCESSIVE, @@ -180,13 +179,13 @@ class SupplicantP2pIfaceAidlTest : public testing::TestWithParam { 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()); ASSERT_NE(p2p_iface_, nullptr); } void TearDown() override { - stopSupplicant(); + stopSupplicantService(); startWifiFramework(); } diff --git a/wifi/supplicant/aidl/vts/functional/supplicant_sta_iface_aidl_test.cpp b/wifi/supplicant/aidl/vts/functional/supplicant_sta_iface_aidl_test.cpp index 6e6955fd75..b24f5027db 100644 --- a/wifi/supplicant/aidl/vts/functional/supplicant_sta_iface_aidl_test.cpp +++ b/wifi/supplicant/aidl/vts/functional/supplicant_sta_iface_aidl_test.cpp @@ -197,21 +197,20 @@ class SupplicantStaIfaceAidlTest : public testing::TestWithParam { public: void SetUp() override { initializeService(); - supplicant_ = ISupplicant::fromBinder(ndk::SpAIBinder( - AServiceManager_waitForService(GetParam().c_str()))); + supplicant_ = getSupplicant(GetParam().c_str()); ASSERT_NE(supplicant_, nullptr); ASSERT_TRUE(supplicant_ ->setDebugParams(DebugLevel::EXCESSIVE, true, // show timestamps true) .isOk()); - EXPECT_TRUE(supplicant_->addStaInterface(getStaIfaceName(), &sta_iface_) + EXPECT_TRUE(supplicant_->getStaInterface(getStaIfaceName(), &sta_iface_) .isOk()); ASSERT_NE(sta_iface_, nullptr); } void TearDown() override { - stopSupplicant(); + stopSupplicantService(); startWifiFramework(); } diff --git a/wifi/supplicant/aidl/vts/functional/supplicant_sta_network_aidl_test.cpp b/wifi/supplicant/aidl/vts/functional/supplicant_sta_network_aidl_test.cpp index 3d8242b2b9..a19b300da5 100644 --- a/wifi/supplicant/aidl/vts/functional/supplicant_sta_network_aidl_test.cpp +++ b/wifi/supplicant/aidl/vts/functional/supplicant_sta_network_aidl_test.cpp @@ -99,15 +99,14 @@ class SupplicantStaNetworkAidlTest public: void SetUp() override { initializeService(); - supplicant_ = ISupplicant::fromBinder(ndk::SpAIBinder( - AServiceManager_waitForService(GetParam().c_str()))); + supplicant_ = getSupplicant(GetParam().c_str()); ASSERT_NE(supplicant_, nullptr); ASSERT_TRUE(supplicant_ ->setDebugParams(DebugLevel::EXCESSIVE, true, // show timestamps true) .isOk()); - EXPECT_TRUE(supplicant_->addStaInterface(getStaIfaceName(), &sta_iface_) + EXPECT_TRUE(supplicant_->getStaInterface(getStaIfaceName(), &sta_iface_) .isOk()); ASSERT_NE(sta_iface_, nullptr); EXPECT_TRUE(sta_iface_->addNetwork(&sta_network_).isOk()); @@ -115,7 +114,7 @@ class SupplicantStaNetworkAidlTest } void TearDown() override { - stopSupplicant(); + stopSupplicantService(); startWifiFramework(); } diff --git a/wifi/supplicant/aidl/vts/functional/supplicant_test_utils.h b/wifi/supplicant/aidl/vts/functional/supplicant_test_utils.h index b7e1a800b7..17e0394892 100644 --- a/wifi/supplicant/aidl/vts/functional/supplicant_test_utils.h +++ b/wifi/supplicant/aidl/vts/functional/supplicant_test_utils.h @@ -19,8 +19,14 @@ #include #include +#include +#include +#include #include +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::KeyMgmtMask; using android::wifi_system::SupplicantManager; @@ -37,6 +43,14 @@ std::string getP2pIfaceName() { return std::string(buffer.data()); } +std::string getWifiInstanceName() { + const std::vector 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 iface, KeyMgmtMask expected) { KeyMgmtMask caps; @@ -53,60 +67,44 @@ bool isFilsSupported(std::shared_ptr iface) { return keyMgmtSupported(iface, filsMask); } -bool waitForSupplicantState(bool is_running) { +void startSupplicant() { + initializeDriverAndFirmware(getWifiInstanceName()); SupplicantManager supplicant_manager; - int count = 50; /* wait at most 5 seconds for completion */ - while (count-- > 0) { - if (supplicant_manager.IsSupplicantRunning() == is_running) { - return true; - } - usleep(100000); - } - LOG(ERROR) << "Supplicant not " << (is_running ? "running" : "stopped"); - return false; + ASSERT_TRUE(supplicant_manager.StartSupplicant()); + ASSERT_TRUE(supplicant_manager.IsSupplicantRunning()); } -bool waitForFrameworkReady() { - int waitCount = 15; - 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(); -} +// Wrapper around the implementation in supplicant_hidl_test_util. +void stopSupplicantService() { stopSupplicant(getWifiInstanceName()); } void initializeService() { ASSERT_TRUE(stopWifiFramework()); std::system("/system/bin/start"); ASSERT_TRUE(waitForFrameworkReady()); - stopSupplicant(); + stopSupplicantService(); + startSupplicant(); +} + +void addStaIface(const std::shared_ptr supplicant) { + ASSERT_TRUE(supplicant.get()); + std::shared_ptr iface; + ASSERT_TRUE(supplicant->addStaInterface(getStaIfaceName(), &iface).isOk()); +} + +void addP2pIface(const std::shared_ptr supplicant) { + ASSERT_TRUE(supplicant.get()); + std::shared_ptr iface; + ASSERT_TRUE(supplicant->addP2pInterface(getP2pIfaceName(), &iface).isOk()); +} + +std::shared_ptr getSupplicant(const char* supplicant_name) { + std::shared_ptr 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 \ No newline at end of file