From 4d9b6fef99242e23978bb4a788a9831da0356cef Mon Sep 17 00:00:00 2001 From: Dan Shi Date: Mon, 2 Dec 2019 11:21:06 -0800 Subject: [PATCH] Convert VtsHalBluetoothAudioV2_0TargetTest to be parameterized test Bug: 142397658 Test: atest VtsHalBluetoothAudioV2_0TargetTest Change-Id: I024abca2330ffb1fab709c97b01896ce9decba76 --- bluetooth/audio/2.0/vts/functional/Android.bp | 1 + .../VtsHalBluetoothAudioV2_0TargetTest.cpp | 87 +++++++++---------- 2 files changed, 41 insertions(+), 47 deletions(-) diff --git a/bluetooth/audio/2.0/vts/functional/Android.bp b/bluetooth/audio/2.0/vts/functional/Android.bp index b672fe4970..b778b97b09 100644 --- a/bluetooth/audio/2.0/vts/functional/Android.bp +++ b/bluetooth/audio/2.0/vts/functional/Android.bp @@ -9,4 +9,5 @@ cc_test { shared_libs: [ "libfmq", ], + test_suites: ["general-tests", "vts-core"], } diff --git a/bluetooth/audio/2.0/vts/functional/VtsHalBluetoothAudioV2_0TargetTest.cpp b/bluetooth/audio/2.0/vts/functional/VtsHalBluetoothAudioV2_0TargetTest.cpp index 9572d3f47b..b3cb6f7267 100644 --- a/bluetooth/audio/2.0/vts/functional/VtsHalBluetoothAudioV2_0TargetTest.cpp +++ b/bluetooth/audio/2.0/vts/functional/VtsHalBluetoothAudioV2_0TargetTest.cpp @@ -21,12 +21,13 @@ #include #include #include +#include +#include #include +#include #include #include -#include -#include using ::android::sp; using ::android::hardware::hidl_vec; @@ -105,34 +106,13 @@ std::vector ExtractValuesFromBitmask(T bitmasks, uint32_t bitfield, } } // namespace -// Test environment for Bluetooth Audio HAL. -class BluetoothAudioHidlEnvironment - : public ::testing::VtsHalHidlTargetTestEnvBase { - public: - // get the test environment singleton - static BluetoothAudioHidlEnvironment* Instance() { - static BluetoothAudioHidlEnvironment* instance = - new BluetoothAudioHidlEnvironment; - return instance; - } - - virtual void registerTestServices() override { - registerTestService(); - } - - private: - BluetoothAudioHidlEnvironment() {} -}; - // The base test class for Bluetooth Audio HAL. class BluetoothAudioProvidersFactoryHidlTest - : public ::testing::VtsHalHidlTargetTestBase { + : public ::testing::TestWithParam { public: virtual void SetUp() override { - providers_factory_ = ::testing::VtsHalHidlTargetTestBase::getService< - IBluetoothAudioProvidersFactory>( - BluetoothAudioHidlEnvironment::Instance() - ->getServiceName()); + providers_factory_ = + IBluetoothAudioProvidersFactory::getService(GetParam()); ASSERT_NE(providers_factory_, nullptr); } @@ -300,13 +280,13 @@ class BluetoothAudioProvidersFactoryHidlTest /** * Test whether we can get the FactoryService from HIDL */ -TEST_F(BluetoothAudioProvidersFactoryHidlTest, GetProvidersFactoryService) {} +TEST_P(BluetoothAudioProvidersFactoryHidlTest, GetProvidersFactoryService) {} /** * Test whether we can open a provider for each provider returned by * getProviderCapabilities() with non-empty capabalities */ -TEST_F(BluetoothAudioProvidersFactoryHidlTest, +TEST_P(BluetoothAudioProvidersFactoryHidlTest, OpenProviderAndCheckCapabilitiesBySession) { for (auto session_type : session_types_) { GetProviderCapabilitiesHelper(session_type); @@ -341,14 +321,14 @@ class BluetoothAudioProviderA2dpSoftwareHidlTest /** * Test whether we can open a provider of type */ -TEST_F(BluetoothAudioProviderA2dpSoftwareHidlTest, OpenA2dpSoftwareProvider) {} +TEST_P(BluetoothAudioProviderA2dpSoftwareHidlTest, OpenA2dpSoftwareProvider) {} /** * Test whether each provider of type * SessionType::A2DP_SOFTWARE_ENCODING_DATAPATH can be started and stopped with * different PCM config */ -TEST_F(BluetoothAudioProviderA2dpSoftwareHidlTest, +TEST_P(BluetoothAudioProviderA2dpSoftwareHidlTest, StartAndEndA2dpSoftwareSessionWithPossiblePcmConfig) { bool is_codec_config_valid; std::unique_ptr tempDataMQ; @@ -616,14 +596,14 @@ class BluetoothAudioProviderA2dpHardwareHidlTest /** * Test whether we can open a provider of type */ -TEST_F(BluetoothAudioProviderA2dpHardwareHidlTest, OpenA2dpHardwareProvider) {} +TEST_P(BluetoothAudioProviderA2dpHardwareHidlTest, OpenA2dpHardwareProvider) {} /** * Test whether each provider of type * SessionType::A2DP_HARDWARE_ENCODING_DATAPATH can be started and stopped with * SBC hardware encoding config */ -TEST_F(BluetoothAudioProviderA2dpHardwareHidlTest, +TEST_P(BluetoothAudioProviderA2dpHardwareHidlTest, StartAndEndA2dpSbcHardwareSession) { if (!IsOffloadSupported()) { return; @@ -658,7 +638,7 @@ TEST_F(BluetoothAudioProviderA2dpHardwareHidlTest, * SessionType::A2DP_HARDWARE_ENCODING_DATAPATH can be started and stopped with * AAC hardware encoding config */ -TEST_F(BluetoothAudioProviderA2dpHardwareHidlTest, +TEST_P(BluetoothAudioProviderA2dpHardwareHidlTest, StartAndEndA2dpAacHardwareSession) { if (!IsOffloadSupported()) { return; @@ -693,7 +673,7 @@ TEST_F(BluetoothAudioProviderA2dpHardwareHidlTest, * SessionType::A2DP_HARDWARE_ENCODING_DATAPATH can be started and stopped with * LDAC hardware encoding config */ -TEST_F(BluetoothAudioProviderA2dpHardwareHidlTest, +TEST_P(BluetoothAudioProviderA2dpHardwareHidlTest, StartAndEndA2dpLdacHardwareSession) { if (!IsOffloadSupported()) { return; @@ -728,7 +708,7 @@ TEST_F(BluetoothAudioProviderA2dpHardwareHidlTest, * SessionType::A2DP_HARDWARE_ENCODING_DATAPATH can be started and stopped with * AptX hardware encoding config */ -TEST_F(BluetoothAudioProviderA2dpHardwareHidlTest, +TEST_P(BluetoothAudioProviderA2dpHardwareHidlTest, StartAndEndA2dpAptxHardwareSession) { if (!IsOffloadSupported()) { return; @@ -767,7 +747,7 @@ TEST_F(BluetoothAudioProviderA2dpHardwareHidlTest, * SessionType::A2DP_HARDWARE_ENCODING_DATAPATH can be started and stopped with * an invalid codec config */ -TEST_F(BluetoothAudioProviderA2dpHardwareHidlTest, +TEST_P(BluetoothAudioProviderA2dpHardwareHidlTest, StartAndEndA2dpHardwareSessionInvalidCodecConfig) { if (!IsOffloadSupported()) { return; @@ -857,7 +837,7 @@ class BluetoothAudioProviderHearingAidSoftwareHidlTest * SessionType::HEARING_AID_HARDWARE_ENCODING_DATAPATH can be started and * stopped with SBC hardware encoding config */ -TEST_F(BluetoothAudioProviderHearingAidSoftwareHidlTest, +TEST_P(BluetoothAudioProviderHearingAidSoftwareHidlTest, OpenHearingAidSoftwareProvider) {} /** @@ -865,7 +845,7 @@ TEST_F(BluetoothAudioProviderHearingAidSoftwareHidlTest, * SessionType::HEARING_AID_SOFTWARE_ENCODING_DATAPATH can be started and * stopped with different PCM config */ -TEST_F(BluetoothAudioProviderHearingAidSoftwareHidlTest, +TEST_P(BluetoothAudioProviderHearingAidSoftwareHidlTest, StartAndEndHearingAidSessionWithPossiblePcmConfig) { bool is_codec_config_valid; std::unique_ptr tempDataMQ; @@ -904,12 +884,25 @@ TEST_F(BluetoothAudioProviderHearingAidSoftwareHidlTest, } // SampleRate } -int main(int argc, char** argv) { - ::testing::AddGlobalTestEnvironment( - BluetoothAudioHidlEnvironment::Instance()); - ::testing::InitGoogleTest(&argc, argv); - BluetoothAudioHidlEnvironment::Instance()->init(&argc, argv); - int status = RUN_ALL_TESTS(); - LOG(INFO) << "Test result = " << status; - return status; -} +static const std::vector kAudioInstances = + android::hardware::getAllHalInstanceNames( + IBluetoothAudioProvidersFactory::descriptor); + +INSTANTIATE_TEST_SUITE_P(PerInstance, BluetoothAudioProvidersFactoryHidlTest, + testing::ValuesIn(kAudioInstances), + android::hardware::PrintInstanceNameToString); + +INSTANTIATE_TEST_SUITE_P(PerInstance, + BluetoothAudioProviderA2dpSoftwareHidlTest, + testing::ValuesIn(kAudioInstances), + android::hardware::PrintInstanceNameToString); + +INSTANTIATE_TEST_SUITE_P(PerInstance, + BluetoothAudioProviderA2dpHardwareHidlTest, + testing::ValuesIn(kAudioInstances), + android::hardware::PrintInstanceNameToString); + +INSTANTIATE_TEST_SUITE_P(PerInstance, + BluetoothAudioProviderHearingAidSoftwareHidlTest, + testing::ValuesIn(kAudioInstances), + android::hardware::PrintInstanceNameToString); \ No newline at end of file