From bf39317f3793a04ab43e921ee2cbb9f72ef003c9 Mon Sep 17 00:00:00 2001 From: Mikhail Naganov Date: Fri, 11 Nov 2016 16:24:50 -0800 Subject: [PATCH] Add simple target-side VTS test for IEffectFactory.hal Bug: 32022706 Change-Id: Id8a5a3ba8d48967beba0ef2e232624ebc185e5c6 Test: build & run test --- audio/Android.bp | 1 + audio/effect/2.0/vts/functional/Android.bp | 36 ++++ .../functional/audio_effect_hidl_hal_test.cpp | 168 ++++++++++++++++++ 3 files changed, 205 insertions(+) create mode 100644 audio/effect/2.0/vts/functional/Android.bp create mode 100644 audio/effect/2.0/vts/functional/audio_effect_hidl_hal_test.cpp diff --git a/audio/Android.bp b/audio/Android.bp index 4117288b52..3121a361f3 100644 --- a/audio/Android.bp +++ b/audio/Android.bp @@ -3,4 +3,5 @@ subdirs = [ "2.0", "common/2.0", "effect/2.0", + "effect/2.0/vts/functional", ] diff --git a/audio/effect/2.0/vts/functional/Android.bp b/audio/effect/2.0/vts/functional/Android.bp new file mode 100644 index 0000000000..fc198e5c87 --- /dev/null +++ b/audio/effect/2.0/vts/functional/Android.bp @@ -0,0 +1,36 @@ +// +// 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: "audio_effect_hidl_hal_test", + gtest: true, + srcs: ["audio_effect_hidl_hal_test.cpp"], + shared_libs: [ + "libbase", + "liblog", + "libcutils", + "libhidl", + "libhwbinder", + "libnativehelper", + "libutils", + "android.hardware.audio.effect@2.0", + ], + static_libs: ["libgtest"], + cflags: [ + "-O0", + "-g", + ], +} diff --git a/audio/effect/2.0/vts/functional/audio_effect_hidl_hal_test.cpp b/audio/effect/2.0/vts/functional/audio_effect_hidl_hal_test.cpp new file mode 100644 index 0000000000..ddd5eacec3 --- /dev/null +++ b/audio/effect/2.0/vts/functional/audio_effect_hidl_hal_test.cpp @@ -0,0 +1,168 @@ +/* + * 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. + */ + +#define LOG_TAG "AudioEffectHidlHalTest" +#include +#include + +#include +#include + +#include + +using ::android::hardware::audio::common::V2_0::Uuid; +using ::android::hardware::audio::effect::V2_0::EffectDescriptor; +using ::android::hardware::audio::effect::V2_0::IEffect; +using ::android::hardware::audio::effect::V2_0::IEffectsFactory; +using ::android::hardware::audio::effect::V2_0::Result; +using ::android::hardware::Return; +using ::android::hardware::Status; +using ::android::hardware::Void; +using ::android::hardware::hidl_vec; +using ::android::sp; + +// The main test class for Audio Effect HIDL HAL. +class AudioEffectHidlTest : public ::testing::Test { + public: + virtual void SetUp() override { + // currently test passthrough mode only + effectsFactory = IEffectsFactory::getService("audio_effects_factory", true); + ASSERT_NE(effectsFactory, nullptr); + } + + virtual void TearDown() override {} + + sp effectsFactory; +}; + +// A class for test environment setup (kept since this file is a template). +class AudioEffectHidlEnvironment : public ::testing::Environment { + public: + virtual void SetUp() {} + virtual void TearDown() {} + + private: +}; + +TEST_F(AudioEffectHidlTest, EnumerateEffects) { + Result retval = Result::NOT_INITIALIZED; + size_t effectCount = 0; + Return ret = effectsFactory->getAllDescriptors( + [&](Result r, const hidl_vec& result) { + retval = r; + effectCount = result.size(); + }); + EXPECT_EQ(ret.getStatus().exceptionCode(), Status::EX_NONE); + EXPECT_EQ(retval, Result::OK); + EXPECT_GT(effectCount, 0u); +} + +TEST_F(AudioEffectHidlTest, CreateEffect) { + bool gotEffect = false; + Uuid effectUuid; + Return ret = effectsFactory->getAllDescriptors( + [&](Result r, const hidl_vec& result) { + if (r == Result::OK && result.size() > 0) { + gotEffect = true; + effectUuid = result[0].uuid; + } + }); + ASSERT_EQ(ret.getStatus().exceptionCode(), Status::EX_NONE); + ASSERT_TRUE(gotEffect); + Result retval = Result::NOT_INITIALIZED; + sp effect; + ret = effectsFactory->createEffect(effectUuid, 1, 1, + [&](Result r, const sp& result) { + retval = r; + if (r == Result::OK) { + effect = result; + } + }); + EXPECT_EQ(ret.getStatus().exceptionCode(), Status::EX_NONE); + EXPECT_EQ(retval, Result::OK); + EXPECT_NE(effect, nullptr); +} + +// See b/32834072 -- we should have those operator== generated by hidl-gen. + +namespace android { +namespace hardware { +namespace audio { +namespace common { +namespace V2_0 { + +static bool operator==(const Uuid& lhs, const Uuid& rhs) { + return lhs.timeLow == rhs.timeLow && lhs.timeMid == rhs.timeMid && + lhs.versionAndTimeHigh == rhs.versionAndTimeHigh && + lhs.variantAndClockSeqHigh == rhs.variantAndClockSeqHigh && + memcmp(lhs.node.data(), rhs.node.data(), lhs.node.size()) == 0; +} + +} // namespace V2_0 +} // namespace common +} // namespace audio +} // namespace hardware +} // namespace android + +namespace android { +namespace hardware { +namespace audio { +namespace effect { +namespace V2_0 { + +static bool operator==(const EffectDescriptor& lhs, + const EffectDescriptor& rhs) { + return lhs.type == rhs.type && lhs.uuid == rhs.uuid && + lhs.flags == rhs.flags && lhs.cpuLoad == rhs.cpuLoad && + lhs.memoryUsage == rhs.memoryUsage && + memcmp(lhs.name.data(), rhs.name.data(), lhs.name.size()) == 0 && + memcmp(lhs.implementor.data(), rhs.implementor.data(), + lhs.implementor.size()) == 0; +} + +} // namespace V2_0 +} // namespace effect +} // namespace audio +} // namespace hardware +} // namespace android + +TEST_F(AudioEffectHidlTest, GetDescriptor) { + hidl_vec allDescriptors; + Return ret = effectsFactory->getAllDescriptors( + [&](Result r, const hidl_vec& result) { + if (r == Result::OK) { + allDescriptors = result; + } + }); + ASSERT_EQ(ret.getStatus().exceptionCode(), Status::EX_NONE); + ASSERT_GT(allDescriptors.size(), 0u); + for (size_t i = 0; i < allDescriptors.size(); ++i) { + ret = effectsFactory->getDescriptor( + allDescriptors[i].uuid, [&](Result r, const EffectDescriptor& result) { + EXPECT_EQ(r, Result::OK); + EXPECT_EQ(result, allDescriptors[i]); + }); + } + EXPECT_EQ(ret.getStatus().exceptionCode(), Status::EX_NONE); +} + +int main(int argc, char** argv) { + ::testing::AddGlobalTestEnvironment(new AudioEffectHidlEnvironment); + ::testing::InitGoogleTest(&argc, argv); + int status = RUN_ALL_TESTS(); + ALOGI("Test result = %d", status); + return status; +}