Loading audio/Android.bp +1 −0 Original line number Diff line number Diff line Loading @@ -3,4 +3,5 @@ subdirs = [ "2.0", "common/2.0", "effect/2.0", "effect/2.0/vts/functional", ] audio/effect/2.0/vts/functional/Android.bp 0 → 100644 +36 −0 Original line number Diff line number Diff line // // 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", ], } audio/effect/2.0/vts/functional/audio_effect_hidl_hal_test.cpp 0 → 100644 +168 −0 Original line number Diff line number Diff line /* * 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 <android-base/logging.h> #include <cutils/native_handle.h> #include <android/hardware/audio/effect/2.0/IEffectsFactory.h> #include <android/hardware/audio/effect/2.0/types.h> #include <gtest/gtest.h> 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<IEffectsFactory> 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<void> ret = effectsFactory->getAllDescriptors( [&](Result r, const hidl_vec<EffectDescriptor>& 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<void> ret = effectsFactory->getAllDescriptors( [&](Result r, const hidl_vec<EffectDescriptor>& 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<IEffect> effect; ret = effectsFactory->createEffect(effectUuid, 1, 1, [&](Result r, const sp<IEffect>& 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<EffectDescriptor> allDescriptors; Return<void> ret = effectsFactory->getAllDescriptors( [&](Result r, const hidl_vec<EffectDescriptor>& 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; } Loading
audio/Android.bp +1 −0 Original line number Diff line number Diff line Loading @@ -3,4 +3,5 @@ subdirs = [ "2.0", "common/2.0", "effect/2.0", "effect/2.0/vts/functional", ]
audio/effect/2.0/vts/functional/Android.bp 0 → 100644 +36 −0 Original line number Diff line number Diff line // // 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", ], }
audio/effect/2.0/vts/functional/audio_effect_hidl_hal_test.cpp 0 → 100644 +168 −0 Original line number Diff line number Diff line /* * 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 <android-base/logging.h> #include <cutils/native_handle.h> #include <android/hardware/audio/effect/2.0/IEffectsFactory.h> #include <android/hardware/audio/effect/2.0/types.h> #include <gtest/gtest.h> 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<IEffectsFactory> 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<void> ret = effectsFactory->getAllDescriptors( [&](Result r, const hidl_vec<EffectDescriptor>& 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<void> ret = effectsFactory->getAllDescriptors( [&](Result r, const hidl_vec<EffectDescriptor>& 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<IEffect> effect; ret = effectsFactory->createEffect(effectUuid, 1, 1, [&](Result r, const sp<IEffect>& 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<EffectDescriptor> allDescriptors; Return<void> ret = effectsFactory->getAllDescriptors( [&](Result r, const hidl_vec<EffectDescriptor>& 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; }