From 5cd54b5b0dbcf9a4ee92c3e17d635705d0a55417 Mon Sep 17 00:00:00 2001 From: Dan Shi Date: Fri, 3 Apr 2020 13:19:50 -0700 Subject: [PATCH] Convert VtsHalAudioControlV1_0TargetTest to parameterized gtest Bug: 150383827 Bug: 150381814 Test: atest VtsHalAudioControlV1_0TargetTest Change-Id: I900f6a540c44d13f5f8a8882b573fa5669c1732f --- .../1.0/vts/functional/Android.bp | 5 ++- .../VtsHalAudioControlV1_0TargetTest.cpp | 42 +++++++------------ 2 files changed, 19 insertions(+), 28 deletions(-) diff --git a/automotive/audiocontrol/1.0/vts/functional/Android.bp b/automotive/audiocontrol/1.0/vts/functional/Android.bp index 3cb6340ee8..1bb8e88fbc 100644 --- a/automotive/audiocontrol/1.0/vts/functional/Android.bp +++ b/automotive/audiocontrol/1.0/vts/functional/Android.bp @@ -25,5 +25,8 @@ cc_test { static_libs: [ "android.hardware.automotive.audiocontrol@1.0", ], - test_suites: ["general-tests"], + test_suites: [ + "general-tests", + "vts", + ], } diff --git a/automotive/audiocontrol/1.0/vts/functional/VtsHalAudioControlV1_0TargetTest.cpp b/automotive/audiocontrol/1.0/vts/functional/VtsHalAudioControlV1_0TargetTest.cpp index fc0deb94c3..de1ec02072 100644 --- a/automotive/audiocontrol/1.0/vts/functional/VtsHalAudioControlV1_0TargetTest.cpp +++ b/automotive/audiocontrol/1.0/vts/functional/VtsHalAudioControlV1_0TargetTest.cpp @@ -25,11 +25,12 @@ #include #include -#include #include +#include #include - -#include +#include +#include +#include using namespace ::android::hardware::automotive::audiocontrol::V1_0; using ::android::hardware::Return; @@ -40,30 +41,12 @@ using ::android::hardware::hidl_string; using ::android::hardware::hidl_vec; using ::android::sp; - -// Boiler plate for test harness -class CarAudioControlHidlEnvironment : public ::testing::VtsHalHidlTargetTestEnvBase { - public: - // get the test environment singleton - static CarAudioControlHidlEnvironment* Instance() { - static CarAudioControlHidlEnvironment* instance = new CarAudioControlHidlEnvironment; - return instance; - } - - virtual void registerTestServices() override { registerTestService(); } - private: - CarAudioControlHidlEnvironment() {} -}; - - // The main test class for the automotive AudioControl HAL -class CarAudioControlHidlTest : public ::testing::VtsHalHidlTargetTestBase { -public: +class CarAudioControlHidlTest : public ::testing::TestWithParam { + public: virtual void SetUp() override { // Make sure we can connect to the driver - pAudioControl = ::testing::VtsHalHidlTargetTestBase::getService( - CarAudioControlHidlEnvironment::Instance()-> - getServiceName()); + pAudioControl = IAudioControl::getService(GetParam()); ASSERT_NE(pAudioControl.get(), nullptr); } @@ -82,7 +65,7 @@ public: * fader actually works. The only thing we can do is exercise the HAL and if the HAL crashes, * we _might_ get a test failure if that breaks the connection to the driver. */ -TEST_F(CarAudioControlHidlTest, FaderExercise) { +TEST_P(CarAudioControlHidlTest, FaderExercise) { ALOGI("Fader exercise test (silent)"); // Set the fader all the way to the back @@ -104,7 +87,7 @@ TEST_F(CarAudioControlHidlTest, FaderExercise) { /* * Balance exercise test. */ -TEST_F(CarAudioControlHidlTest, BalanceExercise) { +TEST_P(CarAudioControlHidlTest, BalanceExercise) { ALOGI("Balance exercise test (silent)"); // Set the balance all the way to the left @@ -126,7 +109,7 @@ TEST_F(CarAudioControlHidlTest, BalanceExercise) { /* * Context mapping test. */ -TEST_F(CarAudioControlHidlTest, ContextMapping) { +TEST_P(CarAudioControlHidlTest, ContextMapping) { ALOGI("Context mapping test"); int bus = -1; @@ -156,3 +139,8 @@ TEST_F(CarAudioControlHidlTest, ContextMapping) { bus = pAudioControl->getBusForContext((ContextNumber)~0); EXPECT_EQ(bus, -1); } + +INSTANTIATE_TEST_SUITE_P( + PerInstance, CarAudioControlHidlTest, + testing::ValuesIn(android::hardware::getAllHalInstanceNames(IAudioControl::descriptor)), + android::hardware::PrintInstanceNameToString); \ No newline at end of file