From 5f2568b2e1d010c8a24519ee360eec1141f6c859 Mon Sep 17 00:00:00 2001 From: Scott Randolph Date: Fri, 9 Feb 2018 17:40:32 -0800 Subject: [PATCH] Add VTS test for automotive AudioControl HAL Difficult to verify results, but at least exercises the APIs. Bug: 71614544 Test: adb push ...VtsHalAudioControlV1_0TargetTest /data/actst; adb shell /data/actst Merged-In: Ie900a4e47483ef881e00a4753097dbd09a0730a0 Change-Id: Ie900a4e47483ef881e00a4753097dbd09a0730a0 --- automotive/audiocontrol/1.0/IAudioControl.hal | 4 +- .../audiocontrol/1.0/default/AudioControl.cpp | 3 +- .../audiocontrol/1.0/default/AudioControl.h | 2 +- .../1.0/vts/functional/Android.bp | 31 ++++ .../VtsHalAudioControlV1_0TargetTest.cpp | 158 ++++++++++++++++++ 5 files changed, 193 insertions(+), 5 deletions(-) create mode 100644 automotive/audiocontrol/1.0/vts/functional/Android.bp create mode 100644 automotive/audiocontrol/1.0/vts/functional/VtsHalAudioControlV1_0TargetTest.cpp diff --git a/automotive/audiocontrol/1.0/IAudioControl.hal b/automotive/audiocontrol/1.0/IAudioControl.hal index c02949962a..3c8b086bc6 100644 --- a/automotive/audiocontrol/1.0/IAudioControl.hal +++ b/automotive/audiocontrol/1.0/IAudioControl.hal @@ -29,10 +29,8 @@ interface IAudioControl { * * For every context, a valid bus number (0 - num busses-1) must be returned. If an * unrecognized contextNumber is encountered, then -1 shall be returned. - * - * Any context for which an invalid busNumber is returned must be routed to bus 0. */ - getBusForContext(uint32_t contextNumber) + getBusForContext(ContextNumber contextNumber) generates (int32_t busNumber); diff --git a/automotive/audiocontrol/1.0/default/AudioControl.cpp b/automotive/audiocontrol/1.0/default/AudioControl.cpp index b40f2ae7b2..c96580e160 100644 --- a/automotive/audiocontrol/1.0/default/AudioControl.cpp +++ b/automotive/audiocontrol/1.0/default/AudioControl.cpp @@ -36,7 +36,8 @@ AudioControl::AudioControl() { }; -Return AudioControl::getBusForContext(uint32_t contextNumber) { +Return AudioControl::getBusForContext(ContextNumber ctxt) { + unsigned contextNumber = static_cast(ctxt); if (contextNumber > sContextNumberMax) { ALOGE("Unexpected context number %d (max expected is %d)", contextNumber, sContextCount); return -1; diff --git a/automotive/audiocontrol/1.0/default/AudioControl.h b/automotive/audiocontrol/1.0/default/AudioControl.h index 89e41f9d0e..37f43c6942 100644 --- a/automotive/audiocontrol/1.0/default/AudioControl.h +++ b/automotive/audiocontrol/1.0/default/AudioControl.h @@ -23,7 +23,7 @@ using ::android::sp; struct AudioControl : public IAudioControl { public: // Methods from ::android::hardware::automotive::audiocontrol::V1_0::IAudioControl follow. - Return getBusForContext(uint32_t contextNumber) override; + Return getBusForContext(ContextNumber contextNumber) override; Return setBalanceTowardRight(float value) override; Return setFadeTowardFront(float value) override; diff --git a/automotive/audiocontrol/1.0/vts/functional/Android.bp b/automotive/audiocontrol/1.0/vts/functional/Android.bp new file mode 100644 index 0000000000..c6e0d8ea81 --- /dev/null +++ b/automotive/audiocontrol/1.0/vts/functional/Android.bp @@ -0,0 +1,31 @@ +// +// Copyright (C) 2016 The Android Open Source Project +// +// Licensed under the Apache License, Version 2.0 (the "License"); +// you may not use this file except in compliance with the License. +// You may obtain a copy of the License at +// +// http://www.apache.org/licenses/LICENSE-2.0 +// +// Unless required by applicable law or agreed to in writing, software +// distributed under the License is distributed on an "AS IS" BASIS, +// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +// See the License for the specific language governing permissions and +// limitations under the License. +// + +cc_test { + name: "VtsHalAudioControlV1_0TargetTest", + + srcs: [ + "VtsHalAudioControlV1_0TargetTest.cpp", + ], + + defaults: [ + "VtsHalTargetTestDefaults", + ], + + static_libs: [ + "android.hardware.automotive.audiocontrol@1.0", + ], +} diff --git a/automotive/audiocontrol/1.0/vts/functional/VtsHalAudioControlV1_0TargetTest.cpp b/automotive/audiocontrol/1.0/vts/functional/VtsHalAudioControlV1_0TargetTest.cpp new file mode 100644 index 0000000000..68ed77803c --- /dev/null +++ b/automotive/audiocontrol/1.0/vts/functional/VtsHalAudioControlV1_0TargetTest.cpp @@ -0,0 +1,158 @@ +/* + * Copyright (C) 2018 The Android Open Source Project + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +#define LOG_TAG "VtsHalAudioControlTest" + +#include +#include + +#include +#include +#include +#include +#include + +#include +#include +#include + +#include + +using namespace ::android::hardware::automotive::audiocontrol::V1_0; +using ::android::hardware::Return; +using ::android::hardware::Void; +using ::android::hardware::hidl_enum_iterator; +using ::android::hardware::hidl_handle; +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: + virtual void SetUp() override { + // Make sure we can connect to the driver + pAudioControl = ::testing::VtsHalHidlTargetTestBase::getService( + CarAudioControlHidlEnvironment::Instance()-> + getServiceName()); + ASSERT_NE(pAudioControl.get(), nullptr); + } + + virtual void TearDown() override {} + + protected: + sp pAudioControl; // Every test needs access to the service +}; + +// +// Tests start here... +// + +/* + * Fader exercise test. Note that only a subjective observer could determine if the + * 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) { + ALOGI("Fader exercise test (silent)"); + + // Set the fader all the way to the back + pAudioControl->setFadeTowardFront(-1.0f); + + // Set the fader all the way to the front + pAudioControl->setFadeTowardFront(1.0f); + + // Set the fader part way toward the back + pAudioControl->setFadeTowardFront(-0.333f); + + // Set the fader to a out of bounds value (driver should clamp) + pAudioControl->setFadeTowardFront(99999.9f); + + // Set the fader back to the middle + pAudioControl->setFadeTowardFront(0.0f); +} + +/* + * Balance exercise test. + */ +TEST_F(CarAudioControlHidlTest, BalanceExercise) { + ALOGI("Balance exercise test (silent)"); + + // Set the balance all the way to the left + pAudioControl->setBalanceTowardRight(-1.0f); + + // Set the balance all the way to the right + pAudioControl->setBalanceTowardRight(1.0f); + + // Set the balance part way toward the left + pAudioControl->setBalanceTowardRight(-0.333f); + + // Set the balance to a out of bounds value (driver should clamp) + pAudioControl->setBalanceTowardRight(99999.9f); + + // Set the balance back to the middle + pAudioControl->setBalanceTowardRight(0.0f); +} + +/* + * Context mapping test. + */ +TEST_F(CarAudioControlHidlTest, ContextMapping) { + ALOGI("Context mapping test"); + + int bus = -1; + + // For each defined context, query the driver for the BUS on which it should be delivered + for (const auto& ctxt : hidl_enum_iterator()) { + bus = pAudioControl->getBusForContext(ctxt); + + if (ctxt == ContextNumber::INVALID) { + // Invalid context should never be mapped to a bus + EXPECT_EQ(bus, -1); + } else { + EXPECT_GE(bus, 0); + // TODO: Consider enumerating the devices on the actual audio hal to validate the + // bus IDs. This would introduce an dependency on the audio HAL, however. Would that + // even work while Android is up and running? + } + } + + // Try asking about an invalid context one beyond the last defined to see that it gets back a -1 + int contextRange = std::distance(hidl_enum_iterator().begin(), + hidl_enum_iterator().end()); + bus = pAudioControl->getBusForContext((ContextNumber)contextRange); + EXPECT_EQ(bus, -1); + + // Try asking about an invalid context WAY out of range to see that it gets back a -1 + bus = pAudioControl->getBusForContext((ContextNumber)~0); + EXPECT_EQ(bus, -1); +}