From d64367312e27eae31523839ae46b5bcc9e66a6b3 Mon Sep 17 00:00:00 2001 From: Dan Shi Date: Tue, 5 Nov 2019 13:11:18 -0800 Subject: [PATCH] Convert VtsHalWifiSupplicantV1_*TargetTest to be parameterized test Bug: 142397658 Test: atest VtsHalWifiSupplicantV1_1TargetTest \ VtsHalWifiSupplicantV1_2TargetTest \ VtsHalWifiSupplicantP2pV1_2TargetTest Change-Id: I14a3e94d0b3681c5a3ebd17435dc36d279790c79 --- .../functional/supplicant_hidl_test_utils.cpp | 10 +++ wifi/supplicant/1.1/vts/functional/Android.bp | 7 +- .../VtsHalWifiSupplicantV1_1TargetTest.cpp | 43 +-------- .../vts/functional/supplicant_hidl_test.cpp | 54 +++++++----- .../supplicant_hidl_test_utils_1_1.cpp | 18 ++-- .../supplicant_hidl_test_utils_1_1.h | 44 ++++++++-- .../supplicant_sta_iface_hidl_test.cpp | 58 ++++++++----- .../supplicant_sta_network_hidl_test.cpp | 87 +++++++++++-------- wifi/supplicant/1.2/vts/functional/Android.bp | 12 ++- .../VtsHalWifiSupplicantV1_2TargetTest.cpp | 45 +--------- .../supplicant_hidl_test_utils_1_2.cpp | 22 +++-- .../supplicant_hidl_test_utils_1_2.h | 49 +++++++++-- .../supplicant_p2p_iface_hidl_test.cpp | 35 +++++--- .../supplicant_sta_iface_hidl_test.cpp | 37 +++++--- .../supplicant_sta_network_hidl_test.cpp | 43 +++++---- 15 files changed, 328 insertions(+), 236 deletions(-) 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 d47e42f43e..d0df4a42a1 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 @@ -57,6 +57,11 @@ namespace { // 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; + } + sp wifi_chip = getWifiChip(wifi_instance_name); ChipModeId mode_id; EXPECT_TRUE(configureChipToSupportIfaceType( @@ -66,6 +71,11 @@ 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) { + // Skip if wifi instance is not set. + if (wifi_instance_name == "") { + return; + } + stopWifi(wifi_instance_name); } diff --git a/wifi/supplicant/1.1/vts/functional/Android.bp b/wifi/supplicant/1.1/vts/functional/Android.bp index 84575321b8..6bcfa8ab5f 100644 --- a/wifi/supplicant/1.1/vts/functional/Android.bp +++ b/wifi/supplicant/1.1/vts/functional/Android.bp @@ -19,7 +19,7 @@ cc_library_static { defaults: ["VtsHalTargetTestDefaults"], srcs: ["supplicant_hidl_test_utils_1_1.cpp"], export_include_dirs: [ - "." + ".", ], static_libs: [ "VtsHalWifiV1_0TargetTestUtil", @@ -54,5 +54,8 @@ cc_test { "libwifi-system", "libwifi-system-iface", ], - test_suites: ["general-tests"], + test_suites: [ + "general-tests", + "vts-core", + ], } diff --git a/wifi/supplicant/1.1/vts/functional/VtsHalWifiSupplicantV1_1TargetTest.cpp b/wifi/supplicant/1.1/vts/functional/VtsHalWifiSupplicantV1_1TargetTest.cpp index 9063a3ba4c..f582cc1ff6 100644 --- a/wifi/supplicant/1.1/vts/functional/VtsHalWifiSupplicantV1_1TargetTest.cpp +++ b/wifi/supplicant/1.1/vts/functional/VtsHalWifiSupplicantV1_1TargetTest.cpp @@ -14,45 +14,8 @@ * limitations under the License. */ -#include -#include -#include - #include "supplicant_hidl_test_utils.h" -#include "wifi_hidl_test_utils.h" -class WifiSupplicantHidlEnvironment_1_1 : public WifiSupplicantHidlEnvironment { - public: - // get the test environment singleton - static WifiSupplicantHidlEnvironment_1_1* Instance() { - static WifiSupplicantHidlEnvironment_1_1* instance = - new WifiSupplicantHidlEnvironment_1_1; - return instance; - } - virtual void registerTestServices() override { - registerTestService<::android::hardware::wifi::V1_0::IWifi>(); - registerTestService<::android::hardware::wifi::V1_1::IWifi>(); - registerTestService< - ::android::hardware::wifi::supplicant::V1_0::ISupplicant>(); - registerTestService< - ::android::hardware::wifi::supplicant::V1_1::ISupplicant>(); - } - - private: - WifiSupplicantHidlEnvironment_1_1() {} -}; - -WifiSupplicantHidlEnvironment* gEnv = - WifiSupplicantHidlEnvironment_1_1::Instance(); - -int main(int argc, char** argv) { - ::testing::AddGlobalTestEnvironment(gEnv); - ::testing::InitGoogleTest(&argc, argv); - gEnv->init(&argc, argv); - int status = gEnv->initFromOptions(argc, argv); - if (status == 0) { - int status = RUN_ALL_TESTS(); - LOG(INFO) << "Test result = " << status; - } - return status; -} +// TODO(b/143892896): Remove this file after wifi_hidl_test_utils.cpp is +// updated. +WifiSupplicantHidlEnvironment* gEnv = nullptr; diff --git a/wifi/supplicant/1.1/vts/functional/supplicant_hidl_test.cpp b/wifi/supplicant/1.1/vts/functional/supplicant_hidl_test.cpp index 28f980cf85..24a7ec31aa 100644 --- a/wifi/supplicant/1.1/vts/functional/supplicant_hidl_test.cpp +++ b/wifi/supplicant/1.1/vts/functional/supplicant_hidl_test.cpp @@ -17,10 +17,12 @@ #include #include -#include - +#include +#include #include #include +#include +#include #include "supplicant_hidl_test_utils.h" #include "supplicant_hidl_test_utils_1_1.h" @@ -33,22 +35,11 @@ using ::android::hardware::wifi::supplicant::V1_0::IfaceType; using ::android::hardware::wifi::supplicant::V1_1::ISupplicant; using ::android::sp; -extern WifiSupplicantHidlEnvironment* gEnv; - -class SupplicantHidlTest : public ::testing::VtsHalHidlTargetTestBase { +class SupplicantHidlTest : public SupplicantHidlTestBase { public: - virtual void SetUp() override { - startSupplicantAndWaitForHidlService(); - supplicant_ = getSupplicant_1_1(); - ASSERT_NE(supplicant_.get(), nullptr); - } - - virtual void TearDown() override { stopSupplicant(); } + virtual void SetUp() override { SupplicantHidlTestBase::SetUp(); } protected: - // ISupplicant object used for all tests in this fixture. - sp supplicant_; - std::string getWlan0IfaceName() { std::array buffer; property_get("wifi.interface", buffer.data(), "wlan0"); @@ -65,7 +56,7 @@ class SupplicantHidlTest : public ::testing::VtsHalHidlTargetTestBase { /* * AddStaInterface */ -TEST_F(SupplicantHidlTest, AddStaInterface) { +TEST_P(SupplicantHidlTest, AddStaInterface) { ISupplicant::IfaceInfo iface_info; iface_info.name = getWlan0IfaceName(); iface_info.type = IfaceType::STA; @@ -82,8 +73,8 @@ TEST_F(SupplicantHidlTest, AddStaInterface) { /* * AddP2pInterface */ -TEST_F(SupplicantHidlTest, AddP2pInterface) { - if (!gEnv->isP2pOn) return; +TEST_P(SupplicantHidlTest, AddP2pInterface) { + if (isP2pOn_) return; ISupplicant::IfaceInfo iface_info; iface_info.name = getP2pIfaceName(); iface_info.type = IfaceType::P2P; @@ -100,7 +91,7 @@ TEST_F(SupplicantHidlTest, AddP2pInterface) { /* * RemoveStaInterface */ -TEST_F(SupplicantHidlTest, RemoveStaInterface) { +TEST_P(SupplicantHidlTest, RemoveStaInterface) { ISupplicant::IfaceInfo iface_info; iface_info.name = getWlan0IfaceName(); iface_info.type = IfaceType::STA; @@ -122,8 +113,8 @@ TEST_F(SupplicantHidlTest, RemoveStaInterface) { /* * RemoveP2pInterface */ -TEST_F(SupplicantHidlTest, RemoveP2pInterface) { - if (!gEnv->isP2pOn) return; +TEST_P(SupplicantHidlTest, RemoveP2pInterface) { + if (isP2pOn_) return; ISupplicant::IfaceInfo iface_info; iface_info.name = getP2pIfaceName(); iface_info.type = IfaceType::P2P; @@ -146,6 +137,23 @@ TEST_F(SupplicantHidlTest, RemoveP2pInterface) { * Terminate * This terminates the service. */ -TEST_F(SupplicantHidlTest, Terminate) { - supplicant_->terminate(); +TEST_P(SupplicantHidlTest, Terminate) { supplicant_->terminate(); } + +static std::vector get_wifi_instances() { + std::vector instances = + android::hardware::getAllHalInstanceNames( + android::hardware::wifi::V1_0::IWifi::descriptor); + // Also test when wifi instance is not set. + instances.push_back(""); + + return instances; } + +INSTANTIATE_TEST_CASE_P( + PerInstance, SupplicantHidlTest, + testing::Combine( + testing::ValuesIn(get_wifi_instances()), + testing::ValuesIn(android::hardware::getAllHalInstanceNames( + android::hardware::wifi::supplicant::V1_1::ISupplicant:: + descriptor))), + android::hardware::PrintInstanceTupleNameToString<>); diff --git a/wifi/supplicant/1.1/vts/functional/supplicant_hidl_test_utils_1_1.cpp b/wifi/supplicant/1.1/vts/functional/supplicant_hidl_test_utils_1_1.cpp index 04a5ed9d1a..b75a2fbccc 100644 --- a/wifi/supplicant/1.1/vts/functional/supplicant_hidl_test_utils_1_1.cpp +++ b/wifi/supplicant/1.1/vts/functional/supplicant_hidl_test_utils_1_1.cpp @@ -14,7 +14,6 @@ * limitations under the License. */ -#include #include #include "supplicant_hidl_test_utils.h" @@ -25,14 +24,19 @@ using ::android::hardware::wifi::supplicant::V1_1::ISupplicantStaIface; using ::android::hardware::wifi::supplicant::V1_1::ISupplicantStaNetwork; using ::android::sp; -sp getSupplicant_1_1() { - return ISupplicant::castFrom(getSupplicant()); +sp getSupplicant_1_1(const std::string& supplicant_instance_name, + bool isP2pOn) { + return ISupplicant::castFrom( + getSupplicant(supplicant_instance_name, isP2pOn)); } -sp getSupplicantStaIface_1_1() { - return ISupplicantStaIface::castFrom(getSupplicantStaIface()); +sp getSupplicantStaIface_1_1( + const sp& supplicant) { + return ISupplicantStaIface::castFrom(getSupplicantStaIface(supplicant)); } -sp createSupplicantStaNetwork_1_1() { - return ISupplicantStaNetwork::castFrom(createSupplicantStaNetwork()); +sp createSupplicantStaNetwork_1_1( + const sp& supplicant) { + return ISupplicantStaNetwork::castFrom( + createSupplicantStaNetwork(supplicant)); } diff --git a/wifi/supplicant/1.1/vts/functional/supplicant_hidl_test_utils_1_1.h b/wifi/supplicant/1.1/vts/functional/supplicant_hidl_test_utils_1_1.h index 1c13325f4f..3629882f94 100644 --- a/wifi/supplicant/1.1/vts/functional/supplicant_hidl_test_utils_1_1.h +++ b/wifi/supplicant/1.1/vts/functional/supplicant_hidl_test_utils_1_1.h @@ -14,20 +14,52 @@ * limitations under the License. */ -#ifndef SUPPLICANT_HIDL_TEST_UTILS_1_1_H -#define SUPPLICANT_HIDL_TEST_UTILS_1_1_H +#pragma once +#pragma clang diagnostic ignored "-Wweak-vtables" +#include #include #include #include +#include android::sp - getSupplicant_1_1(); +getSupplicant_1_1(const std::string& supplicant_instance_name, bool isP2pOn); android::sp - getSupplicantStaIface_1_1(); +getSupplicantStaIface_1_1( + const android::sp& + supplicant); android::sp - createSupplicantStaNetwork_1_1(); +createSupplicantStaNetwork_1_1( + const android::sp& + supplicant); -#endif /* SUPPLICANT_HIDL_TEST_UTILS_1_1_H */ +class SupplicantHidlTestBase + : public ::testing::TestWithParam> { + public: + virtual void SetUp() override { + wifi_v1_0_instance_name_ = std::get<0>(GetParam()); + supplicant_v1_1_instance_name_ = std::get<1>(GetParam()); + isP2pOn_ = + testing::deviceSupportsFeature("android.hardware.wifi.direct"); + stopSupplicant(wifi_v1_0_instance_name_); + startSupplicantAndWaitForHidlService(wifi_v1_0_instance_name_, + supplicant_v1_1_instance_name_); + supplicant_ = + getSupplicant_1_1(supplicant_v1_1_instance_name_, isP2pOn_); + ASSERT_NE(supplicant_.get(), nullptr); + } + + virtual void TearDown() override { + stopSupplicant(wifi_v1_0_instance_name_); + } + + protected: + android::sp + supplicant_; + bool isP2pOn_ = false; + std::string wifi_v1_0_instance_name_; + std::string supplicant_v1_1_instance_name_; +}; diff --git a/wifi/supplicant/1.1/vts/functional/supplicant_sta_iface_hidl_test.cpp b/wifi/supplicant/1.1/vts/functional/supplicant_sta_iface_hidl_test.cpp index c5e6319de9..8a1aeccf7d 100644 --- a/wifi/supplicant/1.1/vts/functional/supplicant_sta_iface_hidl_test.cpp +++ b/wifi/supplicant/1.1/vts/functional/supplicant_sta_iface_hidl_test.cpp @@ -16,9 +16,13 @@ #include -#include - +#include +#include +#include #include +#include +#include +#include #include "supplicant_hidl_test_utils.h" #include "supplicant_hidl_test_utils_1_1.h" @@ -29,26 +33,24 @@ using ::android::hardware::hidl_string; using ::android::hardware::hidl_vec; using ::android::hardware::Return; using ::android::hardware::Void; -using ::android::hardware::wifi::supplicant::V1_1::ISupplicantStaIface; -using ::android::hardware::wifi::supplicant::V1_1::ISupplicantStaIfaceCallback; using ::android::hardware::wifi::supplicant::V1_0::SupplicantStatus; using ::android::hardware::wifi::supplicant::V1_0::SupplicantStatusCode; +using ::android::hardware::wifi::supplicant::V1_1::ISupplicant; +using ::android::hardware::wifi::supplicant::V1_1::ISupplicantStaIface; +using ::android::hardware::wifi::supplicant::V1_1::ISupplicantStaIfaceCallback; -class SupplicantStaIfaceHidlTest - : public ::testing::VtsHalHidlTargetTestBase { - public: - virtual void SetUp() override { - startSupplicantAndWaitForHidlService(); - EXPECT_TRUE(turnOnExcessiveLogging()); - sta_iface_ = getSupplicantStaIface_1_1(); - ASSERT_NE(sta_iface_.get(), nullptr); - } +class SupplicantStaIfaceHidlTest : public SupplicantHidlTestBase { + public: + virtual void SetUp() override { + SupplicantHidlTestBase::SetUp(); + EXPECT_TRUE(turnOnExcessiveLogging(supplicant_)); + sta_iface_ = getSupplicantStaIface_1_1(supplicant_); + ASSERT_NE(sta_iface_.get(), nullptr); + } - virtual void TearDown() override { stopSupplicant(); } - - protected: - // ISupplicantStaIface object used for all tests in this fixture. - sp sta_iface_; + protected: + // ISupplicantStaIface object used for all tests in this fixture. + sp sta_iface_; }; class IfaceCallback : public ISupplicantStaIfaceCallback { @@ -131,9 +133,19 @@ class IfaceCallback : public ISupplicantStaIfaceCallback { /* * RegisterCallback_1_1 */ -TEST_F(SupplicantStaIfaceHidlTest, RegisterCallback_1_1) { - sta_iface_->registerCallback_1_1( - new IfaceCallback(), [](const SupplicantStatus& status) { - EXPECT_EQ(SupplicantStatusCode::SUCCESS, status.code); - }); +TEST_P(SupplicantStaIfaceHidlTest, RegisterCallback_1_1) { + sta_iface_->registerCallback_1_1( + new IfaceCallback(), [](const SupplicantStatus& status) { + EXPECT_EQ(SupplicantStatusCode::SUCCESS, status.code); + }); } + +INSTANTIATE_TEST_CASE_P( + PerInstance, SupplicantStaIfaceHidlTest, + testing::Combine( + testing::ValuesIn(android::hardware::getAllHalInstanceNames( + android::hardware::wifi::V1_0::IWifi::descriptor)), + testing::ValuesIn(android::hardware::getAllHalInstanceNames( + android::hardware::wifi::supplicant::V1_1::ISupplicant:: + descriptor))), + android::hardware::PrintInstanceTupleNameToString<>); \ No newline at end of file diff --git a/wifi/supplicant/1.1/vts/functional/supplicant_sta_network_hidl_test.cpp b/wifi/supplicant/1.1/vts/functional/supplicant_sta_network_hidl_test.cpp index fa52556b7a..a4b7d40b53 100644 --- a/wifi/supplicant/1.1/vts/functional/supplicant_sta_network_hidl_test.cpp +++ b/wifi/supplicant/1.1/vts/functional/supplicant_sta_network_hidl_test.cpp @@ -16,8 +16,11 @@ #include -#include +#include +#include #include +#include +#include #include "supplicant_hidl_test_utils.h" #include "supplicant_hidl_test_utils_1_1.h" @@ -26,27 +29,26 @@ using ::android::sp; using ::android::hardware::hidl_vec; using ::android::hardware::wifi::supplicant::V1_0::SupplicantStatus; using ::android::hardware::wifi::supplicant::V1_0::SupplicantStatusCode; +using ::android::hardware::wifi::supplicant::V1_1::ISupplicant; using ::android::hardware::wifi::supplicant::V1_1::ISupplicantStaNetwork; + namespace { constexpr uint8_t kTestIdentity[] = {0x45, 0x67, 0x98, 0x67, 0x56}; constexpr uint8_t kTestEncryptedIdentity[] = {0x35, 0x37, 0x58, 0x57, 0x26}; } // namespace -class SupplicantStaNetworkHidlTest - : public ::testing::VtsHalHidlTargetTestBase { - public: - virtual void SetUp() override { - startSupplicantAndWaitForHidlService(); - EXPECT_TRUE(turnOnExcessiveLogging()); - sta_network_ = createSupplicantStaNetwork_1_1(); - ASSERT_NE(sta_network_.get(), nullptr); - } +class SupplicantStaNetworkHidlTest : public SupplicantHidlTestBase { + public: + virtual void SetUp() override { + SupplicantHidlTestBase::SetUp(); + EXPECT_TRUE(turnOnExcessiveLogging(supplicant_)); + sta_network_ = createSupplicantStaNetwork_1_1(supplicant_); + ASSERT_NE(sta_network_.get(), nullptr); + } - virtual void TearDown() override { stopSupplicant(); } - - protected: - // ISupplicantStaNetwork object used for all tests in this fixture. - sp sta_network_; + protected: + // ISupplicantStaNetwork object used for all tests in this fixture. + sp sta_network_; }; /* @@ -54,36 +56,49 @@ class SupplicantStaNetworkHidlTest * Ensures that an instance of the ISupplicantStaNetwork proxy object is * successfully created. */ -TEST(SupplicantStaNetworkHidlTestNoFixture, Create) { - startSupplicantAndWaitForHidlService(); - EXPECT_NE(nullptr, createSupplicantStaNetwork_1_1().get()); - stopSupplicant(); +TEST_P(SupplicantStaNetworkHidlTest, Create) { + stopSupplicant(wifi_v1_0_instance_name_); + startSupplicantAndWaitForHidlService(wifi_v1_0_instance_name_, + supplicant_v1_1_instance_name_); + sp supplicant = + getSupplicant_1_1(supplicant_v1_1_instance_name_, isP2pOn_); + EXPECT_NE(nullptr, createSupplicantStaNetwork_1_1(supplicant).get()); } /* * Ensure that the encrypted imsi identity is set successfully. */ -TEST_F(SupplicantStaNetworkHidlTest, setEapEncryptedImsiIdentity) { - std::vector encrypted_identity( - kTestEncryptedIdentity, - kTestEncryptedIdentity + sizeof(kTestEncryptedIdentity)); - sta_network_->setEapEncryptedImsiIdentity( - encrypted_identity, [](const SupplicantStatus &status) { - EXPECT_EQ(SupplicantStatusCode::SUCCESS, status.code); - }); +TEST_P(SupplicantStaNetworkHidlTest, setEapEncryptedImsiIdentity) { + std::vector encrypted_identity( + kTestEncryptedIdentity, + kTestEncryptedIdentity + sizeof(kTestEncryptedIdentity)); + sta_network_->setEapEncryptedImsiIdentity( + encrypted_identity, [](const SupplicantStatus &status) { + EXPECT_EQ(SupplicantStatusCode::SUCCESS, status.code); + }); } /* * Ensure that the identity and the encrypted imsi identity are sent * successfully. */ -TEST_F(SupplicantStaNetworkHidlTest, SendNetworkEapIdentityResponse_1_1) { - sta_network_->sendNetworkEapIdentityResponse_1_1( - std::vector(kTestIdentity, - kTestIdentity + sizeof(kTestIdentity)), - std::vector(kTestEncryptedIdentity, - kTestIdentity + sizeof(kTestEncryptedIdentity)), - [](const SupplicantStatus &status) { - EXPECT_EQ(SupplicantStatusCode::SUCCESS, status.code); - }); +TEST_P(SupplicantStaNetworkHidlTest, SendNetworkEapIdentityResponse_1_1) { + sta_network_->sendNetworkEapIdentityResponse_1_1( + std::vector(kTestIdentity, + kTestIdentity + sizeof(kTestIdentity)), + std::vector(kTestEncryptedIdentity, + kTestIdentity + sizeof(kTestEncryptedIdentity)), + [](const SupplicantStatus &status) { + EXPECT_EQ(SupplicantStatusCode::SUCCESS, status.code); + }); } + +INSTANTIATE_TEST_CASE_P( + PerInstance, SupplicantStaNetworkHidlTest, + testing::Combine( + testing::ValuesIn(android::hardware::getAllHalInstanceNames( + android::hardware::wifi::V1_0::IWifi::descriptor)), + testing::ValuesIn(android::hardware::getAllHalInstanceNames( + android::hardware::wifi::supplicant::V1_1::ISupplicant:: + descriptor))), + android::hardware::PrintInstanceTupleNameToString<>); \ No newline at end of file diff --git a/wifi/supplicant/1.2/vts/functional/Android.bp b/wifi/supplicant/1.2/vts/functional/Android.bp index 7e9d4f6a47..9781074a69 100644 --- a/wifi/supplicant/1.2/vts/functional/Android.bp +++ b/wifi/supplicant/1.2/vts/functional/Android.bp @@ -19,7 +19,7 @@ cc_library_static { defaults: ["VtsHalTargetTestDefaults"], srcs: ["supplicant_hidl_test_utils_1_2.cpp"], export_include_dirs: [ - "." + ".", ], static_libs: [ "VtsHalWifiV1_0TargetTestUtil", @@ -58,7 +58,10 @@ cc_test { "libwifi-system", "libwifi-system-iface", ], - test_suites: ["general-tests"], + test_suites: [ + "general-tests", + "vts-core", + ], } cc_test { @@ -82,5 +85,8 @@ cc_test { "libwifi-system", "libwifi-system-iface", ], + test_suites: [ + "general-tests", + "vts-core", + ], } - diff --git a/wifi/supplicant/1.2/vts/functional/VtsHalWifiSupplicantV1_2TargetTest.cpp b/wifi/supplicant/1.2/vts/functional/VtsHalWifiSupplicantV1_2TargetTest.cpp index 267fa67364..9dbeee104f 100644 --- a/wifi/supplicant/1.2/vts/functional/VtsHalWifiSupplicantV1_2TargetTest.cpp +++ b/wifi/supplicant/1.2/vts/functional/VtsHalWifiSupplicantV1_2TargetTest.cpp @@ -14,47 +14,8 @@ * limitations under the License. */ -#include -#include -#include - #include "supplicant_hidl_test_utils.h" -#include "wifi_hidl_test_utils.h" -class WifiSupplicantHidlEnvironment_1_2 : public WifiSupplicantHidlEnvironment { - public: - // get the test environment singleton - static WifiSupplicantHidlEnvironment_1_2* Instance() { - static WifiSupplicantHidlEnvironment_1_2* instance = - new WifiSupplicantHidlEnvironment_1_2; - return instance; - } - virtual void registerTestServices() override { - registerTestService<::android::hardware::wifi::V1_0::IWifi>(); - registerTestService<::android::hardware::wifi::V1_1::IWifi>(); - registerTestService< - ::android::hardware::wifi::supplicant::V1_0::ISupplicant>(); - registerTestService< - ::android::hardware::wifi::supplicant::V1_1::ISupplicant>(); - registerTestService< - ::android::hardware::wifi::supplicant::V1_2::ISupplicant>(); - } - - private: - WifiSupplicantHidlEnvironment_1_2() {} -}; - -WifiSupplicantHidlEnvironment* gEnv = - WifiSupplicantHidlEnvironment_1_2::Instance(); - -int main(int argc, char** argv) { - ::testing::AddGlobalTestEnvironment(gEnv); - ::testing::InitGoogleTest(&argc, argv); - gEnv->init(&argc, argv); - int status = gEnv->initFromOptions(argc, argv); - if (status == 0) { - int status = RUN_ALL_TESTS(); - LOG(INFO) << "Test result = " << status; - } - return status; -} +// TODO(b/143892896): Remove this file after wifi_hidl_test_utils.cpp is +// updated. +WifiSupplicantHidlEnvironment* gEnv = nullptr; diff --git a/wifi/supplicant/1.2/vts/functional/supplicant_hidl_test_utils_1_2.cpp b/wifi/supplicant/1.2/vts/functional/supplicant_hidl_test_utils_1_2.cpp index f270bff673..480929af2b 100644 --- a/wifi/supplicant/1.2/vts/functional/supplicant_hidl_test_utils_1_2.cpp +++ b/wifi/supplicant/1.2/vts/functional/supplicant_hidl_test_utils_1_2.cpp @@ -26,18 +26,24 @@ using ::android::hardware::wifi::supplicant::V1_2::ISupplicantP2pIface; using ::android::hardware::wifi::supplicant::V1_2::ISupplicantStaIface; using ::android::hardware::wifi::supplicant::V1_2::ISupplicantStaNetwork; -sp getSupplicant_1_2() { - return ISupplicant::castFrom(getSupplicant()); +sp getSupplicant_1_2(const std::string& supplicant_instance_name, + bool isP2pOn) { + return ISupplicant::castFrom( + getSupplicant(supplicant_instance_name, isP2pOn)); } -sp getSupplicantStaIface_1_2() { - return ISupplicantStaIface::castFrom(getSupplicantStaIface()); +sp getSupplicantStaIface_1_2( + const sp& supplicant) { + return ISupplicantStaIface::castFrom(getSupplicantStaIface(supplicant)); } -sp createSupplicantStaNetwork_1_2() { - return ISupplicantStaNetwork::castFrom(createSupplicantStaNetwork()); +sp createSupplicantStaNetwork_1_2( + const sp& supplicant) { + return ISupplicantStaNetwork::castFrom( + createSupplicantStaNetwork(supplicant)); } -sp getSupplicantP2pIface_1_2() { - return ISupplicantP2pIface::castFrom(getSupplicantP2pIface()); +sp getSupplicantP2pIface_1_2( + const sp& supplicant) { + return ISupplicantP2pIface::castFrom(getSupplicantP2pIface(supplicant)); } diff --git a/wifi/supplicant/1.2/vts/functional/supplicant_hidl_test_utils_1_2.h b/wifi/supplicant/1.2/vts/functional/supplicant_hidl_test_utils_1_2.h index 8a7ccc5dac..5ecfdd48ef 100644 --- a/wifi/supplicant/1.2/vts/functional/supplicant_hidl_test_utils_1_2.h +++ b/wifi/supplicant/1.2/vts/functional/supplicant_hidl_test_utils_1_2.h @@ -14,24 +14,59 @@ * limitations under the License. */ -#ifndef SUPPLICANT_HIDL_TEST_UTILS_1_2_H -#define SUPPLICANT_HIDL_TEST_UTILS_1_2_H +#pragma once +#pragma clang diagnostic ignored "-Wweak-vtables" +#include #include #include #include #include +#include android::sp -getSupplicant_1_2(); +getSupplicant_1_2(const std::string& supplicant_instance_name, bool isP2pOn); android::sp -getSupplicantStaIface_1_2(); +getSupplicantStaIface_1_2( + const android::sp& + supplicant); android::sp -createSupplicantStaNetwork_1_2(); +createSupplicantStaNetwork_1_2( + const android::sp& + supplicant); android::sp -getSupplicantP2pIface_1_2(); +getSupplicantP2pIface_1_2( + const android::sp& + supplicant); -#endif /* SUPPLICANT_HIDL_TEST_UTILS_1_2_H */ +class SupplicantHidlTestBase + : public ::testing::TestWithParam> { + public: + virtual void SetUp() override { + wifi_v1_0_instance_name_ = std::get<0>(GetParam()); + supplicant_v1_2_instance_name_ = std::get<1>(GetParam()); + isP2pOn_ = + testing::deviceSupportsFeature("android.hardware.wifi.direct"); + stopSupplicant(wifi_v1_0_instance_name_); + startSupplicantAndWaitForHidlService(wifi_v1_0_instance_name_, + supplicant_v1_2_instance_name_); + supplicant_ = + getSupplicant_1_2(supplicant_v1_2_instance_name_, isP2pOn_); + ASSERT_NE(supplicant_.get(), nullptr); + EXPECT_TRUE(turnOnExcessiveLogging(supplicant_)); + } + + virtual void TearDown() override { + stopSupplicant(wifi_v1_0_instance_name_); + } + + protected: + android::sp + supplicant_; + bool isP2pOn_ = false; + std::string wifi_v1_0_instance_name_; + std::string supplicant_v1_2_instance_name_; +}; diff --git a/wifi/supplicant/1.2/vts/functional/supplicant_p2p_iface_hidl_test.cpp b/wifi/supplicant/1.2/vts/functional/supplicant_p2p_iface_hidl_test.cpp index 1b78ac3e01..2b63ad0ea0 100644 --- a/wifi/supplicant/1.2/vts/functional/supplicant_p2p_iface_hidl_test.cpp +++ b/wifi/supplicant/1.2/vts/functional/supplicant_p2p_iface_hidl_test.cpp @@ -18,7 +18,11 @@ #include +#include +#include #include +#include +#include #include "supplicant_hidl_test_utils.h" #include "supplicant_hidl_test_utils_1_2.h" @@ -26,6 +30,7 @@ using ::android::sp; using ::android::hardware::wifi::supplicant::V1_0::SupplicantStatus; using ::android::hardware::wifi::supplicant::V1_0::SupplicantStatusCode; +using ::android::hardware::wifi::supplicant::V1_2::ISupplicant; using ::android::hardware::wifi::supplicant::V1_2::ISupplicantP2pIface; namespace { @@ -35,17 +40,15 @@ constexpr char kTestPassphrase[] = "P2pWorld1234"; constexpr uint8_t kTestZeroMacAddr[] = {[0 ... 5] = 0x0}; } // namespace -class SupplicantP2pIfaceHidlTest : public ::testing::VtsHalHidlTargetTestBase { +class SupplicantP2pIfaceHidlTest : public SupplicantHidlTestBase { public: virtual void SetUp() override { - startSupplicantAndWaitForHidlService(); - EXPECT_TRUE(turnOnExcessiveLogging()); - p2p_iface_ = getSupplicantP2pIface_1_2(); + SupplicantHidlTestBase::SetUp(); + EXPECT_TRUE(turnOnExcessiveLogging(supplicant_)); + p2p_iface_ = getSupplicantP2pIface_1_2(supplicant_); ASSERT_NE(p2p_iface_.get(), nullptr); } - virtual void TearDown() override { stopSupplicant(); } - protected: // ISupplicantP2pIface object used for all tests in this fixture. sp p2p_iface_; @@ -54,7 +57,7 @@ class SupplicantP2pIfaceHidlTest : public ::testing::VtsHalHidlTargetTestBase { /* * Verify that AddGroup_1_2 could create a group successfully. */ -TEST_F(SupplicantP2pIfaceHidlTest, AddGroup_1_2_Success) { +TEST_P(SupplicantP2pIfaceHidlTest, AddGroup_1_2_Success) { std::vector ssid(kTestSsid, kTestSsid + sizeof(kTestSsid)); std::string passphrase = kTestPassphrase; int freq = 0; @@ -73,7 +76,7 @@ TEST_F(SupplicantP2pIfaceHidlTest, AddGroup_1_2_Success) { /* * Verify that AddGroup_1_2 fails due to invalid SSID. */ -TEST_F(SupplicantP2pIfaceHidlTest, AddGroup_1_2_FailureInvalidSsid) { +TEST_P(SupplicantP2pIfaceHidlTest, AddGroup_1_2_FailureInvalidSsid) { std::vector ssid; std::string passphrase = kTestPassphrase; int freq = 0; @@ -92,7 +95,7 @@ TEST_F(SupplicantP2pIfaceHidlTest, AddGroup_1_2_FailureInvalidSsid) { /* * Verify that AddGroup_1_2 fails due to invalid passphrase. */ -TEST_F(SupplicantP2pIfaceHidlTest, AddGroup_1_2_FailureInvalidPassphrase) { +TEST_P(SupplicantP2pIfaceHidlTest, AddGroup_1_2_FailureInvalidPassphrase) { std::vector ssid(kTestSsid, kTestSsid + sizeof(kTestSsid)); std::string passphrase = "1234"; int freq = 0; @@ -111,7 +114,7 @@ TEST_F(SupplicantP2pIfaceHidlTest, AddGroup_1_2_FailureInvalidPassphrase) { /* * Verify that AddGroup_1_2 fails due to invalid frequency. */ -TEST_F(SupplicantP2pIfaceHidlTest, AddGroup_1_2_FailureInvalidFrequency) { +TEST_P(SupplicantP2pIfaceHidlTest, AddGroup_1_2_FailureInvalidFrequency) { std::vector ssid(kTestSsid, kTestSsid + sizeof(kTestSsid)); std::string passphrase = kTestPassphrase; int freq = 9999; @@ -134,7 +137,7 @@ bool isMacRandomizationSupported(const SupplicantStatus& status) { /* * Verify that setMacRandomization successes. */ -TEST_F(SupplicantP2pIfaceHidlTest, EnableMacRandomization) { +TEST_P(SupplicantP2pIfaceHidlTest, EnableMacRandomization) { p2p_iface_->setMacRandomization(true, [](const SupplicantStatus& status) { if (!isMacRandomizationSupported(status)) return; EXPECT_EQ(SupplicantStatusCode::SUCCESS, status.code); @@ -157,3 +160,13 @@ TEST_F(SupplicantP2pIfaceHidlTest, EnableMacRandomization) { EXPECT_EQ(SupplicantStatusCode::SUCCESS, status.code); }); } + +INSTANTIATE_TEST_CASE_P( + PerInstance, SupplicantP2pIfaceHidlTest, + testing::Combine( + testing::ValuesIn(android::hardware::getAllHalInstanceNames( + android::hardware::wifi::V1_0::IWifi::descriptor)), + testing::ValuesIn(android::hardware::getAllHalInstanceNames( + android::hardware::wifi::supplicant::V1_2::ISupplicant:: + descriptor))), + android::hardware::PrintInstanceTupleNameToString<>); diff --git a/wifi/supplicant/1.2/vts/functional/supplicant_sta_iface_hidl_test.cpp b/wifi/supplicant/1.2/vts/functional/supplicant_sta_iface_hidl_test.cpp index 6272d30a1c..8116c3f21a 100644 --- a/wifi/supplicant/1.2/vts/functional/supplicant_sta_iface_hidl_test.cpp +++ b/wifi/supplicant/1.2/vts/functional/supplicant_sta_iface_hidl_test.cpp @@ -14,7 +14,8 @@ * limitations under the License. */ -#include +#include +#include #include #include #include @@ -24,7 +25,9 @@ #include #include #include +#include #include +#include #include #include "supplicant_hidl_test_utils.h" @@ -42,6 +45,7 @@ using ::android::hardware::wifi::supplicant::V1_2::DppAkm; using ::android::hardware::wifi::supplicant::V1_2::DppFailureCode; using ::android::hardware::wifi::supplicant::V1_2::DppNetRole; using ::android::hardware::wifi::supplicant::V1_2::DppProgressCode; +using ::android::hardware::wifi::supplicant::V1_2::ISupplicant; using ::android::hardware::wifi::supplicant::V1_2::ISupplicantStaIface; using ::android::hardware::wifi::supplicant::V1_2::ISupplicantStaIfaceCallback; using ::android::hardware::wifi::supplicant::V1_2::ISupplicantStaNetwork; @@ -49,18 +53,16 @@ using ::android::hardware::wifi::supplicant::V1_2::ISupplicantStaNetwork; #define TIMEOUT_PERIOD 60 class IfaceDppCallback; -class SupplicantStaIfaceHidlTest : public ::testing::VtsHalHidlTargetTestBase { +class SupplicantStaIfaceHidlTest : public SupplicantHidlTestBase { public: virtual void SetUp() override { - startSupplicantAndWaitForHidlService(); - EXPECT_TRUE(turnOnExcessiveLogging()); - sta_iface_ = getSupplicantStaIface_1_2(); + SupplicantHidlTestBase::SetUp(); + EXPECT_TRUE(turnOnExcessiveLogging(supplicant_)); + sta_iface_ = getSupplicantStaIface_1_2(supplicant_); ASSERT_NE(sta_iface_.get(), nullptr); count_ = 0; } - virtual void TearDown() override { stopSupplicant(); } - enum DppCallbackType { ANY_CALLBACK = -2, INVALID = -1, @@ -101,6 +103,7 @@ class SupplicantStaIfaceHidlTest : public ::testing::VtsHalHidlTargetTestBase { protected: // ISupplicantStaIface object used for all tests in this fixture. sp sta_iface_; + bool isDppSupported() { uint32_t keyMgmtMask = 0; @@ -254,7 +257,7 @@ class IfaceDppCallback : public IfaceCallback { /* * RegisterCallback_1_2 */ -TEST_F(SupplicantStaIfaceHidlTest, RegisterCallback_1_2) { +TEST_P(SupplicantStaIfaceHidlTest, RegisterCallback_1_2) { sta_iface_->registerCallback_1_2( new IfaceCallback(), [](const SupplicantStatus& status) { EXPECT_EQ(SupplicantStatusCode::SUCCESS, status.code); @@ -264,7 +267,7 @@ TEST_F(SupplicantStaIfaceHidlTest, RegisterCallback_1_2) { /* * GetKeyMgmtCapabilities */ -TEST_F(SupplicantStaIfaceHidlTest, GetKeyMgmtCapabilities) { +TEST_P(SupplicantStaIfaceHidlTest, GetKeyMgmtCapabilities) { sta_iface_->getKeyMgmtCapabilities( [&](const SupplicantStatus& status, uint32_t keyMgmtMask) { EXPECT_EQ(SupplicantStatusCode::SUCCESS, status.code); @@ -280,7 +283,7 @@ TEST_F(SupplicantStaIfaceHidlTest, GetKeyMgmtCapabilities) { /* * AddDppPeerUriAndRomveUri */ -TEST_F(SupplicantStaIfaceHidlTest, AddDppPeerUriAndRomveUri) { +TEST_P(SupplicantStaIfaceHidlTest, AddDppPeerUriAndRomveUri) { // We need to first get the key management capabilities from the device. // If DPP is not supported, we just pass the test. if (!isDppSupported()) { @@ -312,7 +315,7 @@ TEST_F(SupplicantStaIfaceHidlTest, AddDppPeerUriAndRomveUri) { /* * StartDppEnrolleeInitiator */ -TEST_F(SupplicantStaIfaceHidlTest, StartDppEnrolleeInitiator) { +TEST_P(SupplicantStaIfaceHidlTest, StartDppEnrolleeInitiator) { // We need to first get the key management capabilities from the device. // If DPP is not supported, we just pass the test. if (!isDppSupported()) { @@ -376,7 +379,7 @@ TEST_F(SupplicantStaIfaceHidlTest, StartDppEnrolleeInitiator) { /* * StartDppConfiguratorInitiator */ -TEST_F(SupplicantStaIfaceHidlTest, StartDppConfiguratorInitiator) { +TEST_P(SupplicantStaIfaceHidlTest, StartDppConfiguratorInitiator) { // We need to first get the key management capabilities from the device. // If DPP is not supported, we just pass the test. if (!isDppSupported()) { @@ -443,3 +446,13 @@ TEST_F(SupplicantStaIfaceHidlTest, StartDppConfiguratorInitiator) { EXPECT_EQ(SupplicantStatusCode::SUCCESS, status.code); }); } + +INSTANTIATE_TEST_CASE_P( + PerInstance, SupplicantStaIfaceHidlTest, + testing::Combine( + testing::ValuesIn(android::hardware::getAllHalInstanceNames( + android::hardware::wifi::V1_0::IWifi::descriptor)), + testing::ValuesIn(android::hardware::getAllHalInstanceNames( + android::hardware::wifi::supplicant::V1_2::ISupplicant:: + descriptor))), + android::hardware::PrintInstanceTupleNameToString<>); \ No newline at end of file diff --git a/wifi/supplicant/1.2/vts/functional/supplicant_sta_network_hidl_test.cpp b/wifi/supplicant/1.2/vts/functional/supplicant_sta_network_hidl_test.cpp index ed421d73d7..4c3d808627 100644 --- a/wifi/supplicant/1.2/vts/functional/supplicant_sta_network_hidl_test.cpp +++ b/wifi/supplicant/1.2/vts/functional/supplicant_sta_network_hidl_test.cpp @@ -16,8 +16,12 @@ #include -#include +#include +#include +#include #include +#include +#include #include "supplicant_hidl_test_utils.h" #include "supplicant_hidl_test_utils_1_2.h" @@ -26,24 +30,21 @@ using ::android::sp; using ::android::hardware::hidl_vec; using ::android::hardware::wifi::supplicant::V1_0::SupplicantStatus; using ::android::hardware::wifi::supplicant::V1_0::SupplicantStatusCode; +using ::android::hardware::wifi::supplicant::V1_2::ISupplicant; using ::android::hardware::wifi::supplicant::V1_2::ISupplicantStaNetwork; // namespace { // constexpr uint8_t kTestIdentity[] = {0x45, 0x67, 0x98, 0x67, 0x56}; // constexpr uint8_t kTestEncryptedIdentity[] = {0x35, 0x37, 0x58, 0x57, 0x26}; //} // namespace -class SupplicantStaNetworkHidlTest - : public ::testing::VtsHalHidlTargetTestBase { +class SupplicantStaNetworkHidlTest : public SupplicantHidlTestBase { public: virtual void SetUp() override { - startSupplicantAndWaitForHidlService(); - EXPECT_TRUE(turnOnExcessiveLogging()); - sta_network_ = createSupplicantStaNetwork_1_2(); + SupplicantHidlTestBase::SetUp(); + sta_network_ = createSupplicantStaNetwork_1_2(supplicant_); ASSERT_NE(sta_network_.get(), nullptr); } - virtual void TearDown() override { stopSupplicant(); } - protected: // ISupplicantStaNetwork object used for all tests in this fixture. sp sta_network_; @@ -52,7 +53,7 @@ class SupplicantStaNetworkHidlTest /* * SetGetSaePassword */ -TEST_F(SupplicantStaNetworkHidlTest, SetGetSaePassword) { +TEST_P(SupplicantStaNetworkHidlTest, SetGetSaePassword) { std::string password = "topsecret"; sta_network_->setSaePassword(password, [](const SupplicantStatus &status) { @@ -69,7 +70,7 @@ TEST_F(SupplicantStaNetworkHidlTest, SetGetSaePassword) { /* * SetGetSaePasswordId */ -TEST_F(SupplicantStaNetworkHidlTest, SetGetSaePasswordId) { +TEST_P(SupplicantStaNetworkHidlTest, SetGetSaePasswordId) { std::string passwordId = "id1"; sta_network_->setSaePasswordId( @@ -87,7 +88,7 @@ TEST_F(SupplicantStaNetworkHidlTest, SetGetSaePasswordId) { /* * SetGetGroupMgmtCipher */ -TEST_F(SupplicantStaNetworkHidlTest, SetGetGroupMgmtCipher) { +TEST_P(SupplicantStaNetworkHidlTest, SetGetGroupMgmtCipher) { uint32_t groupMgmtCipher = (uint32_t)ISupplicantStaNetwork::GroupMgmtCipherMask::BIP_GMAC_256; @@ -107,7 +108,7 @@ TEST_F(SupplicantStaNetworkHidlTest, SetGetGroupMgmtCipher) { /* * SetGetKeyMgmt_1_2 */ -TEST_F(SupplicantStaNetworkHidlTest, SetGetKeyMgmt_1_2) { +TEST_P(SupplicantStaNetworkHidlTest, SetGetKeyMgmt_1_2) { uint32_t keyMgmt = (uint32_t)ISupplicantStaNetwork::KeyMgmtMask::SAE; sta_network_->setKeyMgmt_1_2(keyMgmt, [](const SupplicantStatus &status) { @@ -124,7 +125,7 @@ TEST_F(SupplicantStaNetworkHidlTest, SetGetKeyMgmt_1_2) { /* * SetGetGroupCipher_1_2 */ -TEST_F(SupplicantStaNetworkHidlTest, SetGetGroupCipher_1_2) { +TEST_P(SupplicantStaNetworkHidlTest, SetGetGroupCipher_1_2) { uint32_t groupCipher = (uint32_t)ISupplicantStaNetwork::GroupCipherMask::GCMP_256; @@ -144,7 +145,7 @@ TEST_F(SupplicantStaNetworkHidlTest, SetGetGroupCipher_1_2) { /* * SetGetPairwiseCipher_1_2 */ -TEST_F(SupplicantStaNetworkHidlTest, SetGetPairwiseCipher_1_2) { +TEST_P(SupplicantStaNetworkHidlTest, SetGetPairwiseCipher_1_2) { uint32_t pairwiseCipher = (uint32_t)ISupplicantStaNetwork::PairwiseCipherMask::GCMP_256; @@ -164,7 +165,7 @@ TEST_F(SupplicantStaNetworkHidlTest, SetGetPairwiseCipher_1_2) { /* * EnableSuiteBEapOpenSslCiphers */ -TEST_F(SupplicantStaNetworkHidlTest, EnableSuiteBEapOpenSslCiphers) { +TEST_P(SupplicantStaNetworkHidlTest, EnableSuiteBEapOpenSslCiphers) { sta_network_->enableSuiteBEapOpenSslCiphers( [](const SupplicantStatus &status) { EXPECT_EQ(SupplicantStatusCode::SUCCESS, status.code); @@ -179,7 +180,7 @@ TEST_F(SupplicantStaNetworkHidlTest, EnableSuiteBEapOpenSslCiphers) { /* * EnableTlsSuiteBEapPhase1Param */ -TEST_F(SupplicantStaNetworkHidlTest, EnableTlsSuiteBEapPhase1Param) { +TEST_P(SupplicantStaNetworkHidlTest, EnableTlsSuiteBEapPhase1Param) { sta_network_->enableTlsSuiteBEapPhase1Param( true, [](const SupplicantStatus &status) { EXPECT_EQ(SupplicantStatusCode::SUCCESS, status.code); @@ -190,3 +191,13 @@ TEST_F(SupplicantStaNetworkHidlTest, EnableTlsSuiteBEapPhase1Param) { EXPECT_EQ(SupplicantStatusCode::SUCCESS, status.code); }); } + +INSTANTIATE_TEST_CASE_P( + PerInstance, SupplicantStaNetworkHidlTest, + testing::Combine( + testing::ValuesIn(android::hardware::getAllHalInstanceNames( + android::hardware::wifi::V1_0::IWifi::descriptor)), + testing::ValuesIn(android::hardware::getAllHalInstanceNames( + android::hardware::wifi::supplicant::V1_2::ISupplicant:: + descriptor))), + android::hardware::PrintInstanceTupleNameToString<>);