Sham Rathod | 40f55bd | 2022-11-14 14:24:49 +0530 | [diff] [blame] | 1 | /* |
| 2 | * Copyright (C) 2022 The Android Open Source Project |
| 3 | * |
| 4 | * Licensed under the Apache License, Version 2.0 (the "License"); |
| 5 | * you may not use this file except in compliance with the License. |
| 6 | * You may obtain a copy of the License at |
| 7 | * |
| 8 | * http://www.apache.org/licenses/LICENSE-2.0 |
| 9 | * |
| 10 | * Unless required by applicable law or agreed to in writing, software |
| 11 | * distributed under the License is distributed on an "AS IS" BASIS, |
| 12 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. |
| 13 | * See the License for the specific language governing permissions and |
| 14 | * limitations under the License. |
| 15 | */ |
| 16 | |
Sham Rathod | 40f55bd | 2022-11-14 14:24:49 +0530 | [diff] [blame] | 17 | #include <aidl/Vintf.h> |
Mikhail Naganov | 872d4a6 | 2023-03-09 18:19:01 -0800 | [diff] [blame] | 18 | #define LOG_TAG "VtsHalDownmixTargetTest" |
| 19 | #include <android-base/logging.h> |
| 20 | |
Sham Rathod | 40f55bd | 2022-11-14 14:24:49 +0530 | [diff] [blame] | 21 | #include "EffectHelper.h" |
| 22 | |
| 23 | using namespace android; |
| 24 | |
Sham Rathod | 40f55bd | 2022-11-14 14:24:49 +0530 | [diff] [blame] | 25 | using aidl::android::hardware::audio::effect::Descriptor; |
| 26 | using aidl::android::hardware::audio::effect::Downmix; |
Shunkai Yao | f8be1ac | 2023-03-06 18:41:27 +0000 | [diff] [blame] | 27 | using aidl::android::hardware::audio::effect::getEffectTypeUuidDownmix; |
Sham Rathod | 40f55bd | 2022-11-14 14:24:49 +0530 | [diff] [blame] | 28 | using aidl::android::hardware::audio::effect::IEffect; |
| 29 | using aidl::android::hardware::audio::effect::IFactory; |
Sham Rathod | 40f55bd | 2022-11-14 14:24:49 +0530 | [diff] [blame] | 30 | using aidl::android::hardware::audio::effect::Parameter; |
Jaideep Sharma | 7449841 | 2023-09-13 15:25:25 +0530 | [diff] [blame] | 31 | using android::hardware::audio::common::testing::detail::TestExecutionTracer; |
Sham Rathod | 40f55bd | 2022-11-14 14:24:49 +0530 | [diff] [blame] | 32 | /** |
| 33 | * Here we focus on specific parameter checking, general IEffect interfaces testing performed in |
| 34 | * VtsAudioEffectTargetTest. |
| 35 | */ |
| 36 | enum ParamName { PARAM_INSTANCE_NAME, PARAM_TYPE }; |
| 37 | using DownmixParamTestParam = |
| 38 | std::tuple<std::pair<std::shared_ptr<IFactory>, Descriptor>, Downmix::Type>; |
| 39 | |
| 40 | // Testing for enum values |
| 41 | const std::vector<Downmix::Type> kTypeValues = {Downmix::Type::STRIP, Downmix::Type::FOLD}; |
| 42 | |
| 43 | class DownmixParamTest : public ::testing::TestWithParam<DownmixParamTestParam>, |
| 44 | public EffectHelper { |
| 45 | public: |
| 46 | DownmixParamTest() : mParamType(std::get<PARAM_TYPE>(GetParam())) { |
| 47 | std::tie(mFactory, mDescriptor) = std::get<PARAM_INSTANCE_NAME>(GetParam()); |
| 48 | } |
| 49 | |
| 50 | void SetUp() override { |
| 51 | ASSERT_NE(nullptr, mFactory); |
| 52 | ASSERT_NO_FATAL_FAILURE(create(mFactory, mEffect, mDescriptor)); |
| 53 | |
| 54 | Parameter::Specific specific = getDefaultParamSpecific(); |
| 55 | Parameter::Common common = EffectHelper::createParamCommon( |
| 56 | 0 /* session */, 1 /* ioHandle */, 44100 /* iSampleRate */, 44100 /* oSampleRate */, |
| 57 | kInputFrameCount /* iFrameCount */, kOutputFrameCount /* oFrameCount */); |
| 58 | IEffect::OpenEffectReturn ret; |
| 59 | ASSERT_NO_FATAL_FAILURE(open(mEffect, common, specific, &ret, EX_NONE)); |
| 60 | ASSERT_NE(nullptr, mEffect); |
| 61 | } |
| 62 | |
| 63 | void TearDown() override { |
| 64 | ASSERT_NO_FATAL_FAILURE(close(mEffect)); |
| 65 | ASSERT_NO_FATAL_FAILURE(destroy(mFactory, mEffect)); |
| 66 | } |
| 67 | |
| 68 | static const long kInputFrameCount = 0x100, kOutputFrameCount = 0x100; |
| 69 | std::shared_ptr<IFactory> mFactory; |
| 70 | std::shared_ptr<IEffect> mEffect; |
| 71 | Descriptor mDescriptor; |
| 72 | Downmix::Type mParamType = Downmix::Type::STRIP; |
| 73 | |
| 74 | void SetAndGetDownmixParameters() { |
| 75 | for (auto& it : mTags) { |
| 76 | auto& tag = it.first; |
| 77 | auto& dm = it.second; |
| 78 | |
| 79 | // set parameter |
| 80 | Parameter expectParam; |
| 81 | Parameter::Specific specific; |
| 82 | specific.set<Parameter::Specific::downmix>(dm); |
| 83 | expectParam.set<Parameter::specific>(specific); |
| 84 | // All values are valid, set parameter should succeed |
| 85 | EXPECT_STATUS(EX_NONE, mEffect->setParameter(expectParam)) << expectParam.toString(); |
| 86 | |
| 87 | // get parameter |
| 88 | Parameter getParam; |
| 89 | Parameter::Id id; |
| 90 | Downmix::Id dmId; |
| 91 | dmId.set<Downmix::Id::commonTag>(tag); |
| 92 | id.set<Parameter::Id::downmixTag>(dmId); |
| 93 | EXPECT_STATUS(EX_NONE, mEffect->getParameter(id, &getParam)); |
| 94 | |
| 95 | EXPECT_EQ(expectParam, getParam); |
| 96 | } |
| 97 | } |
| 98 | |
| 99 | void addTypeParam(Downmix::Type type) { |
| 100 | Downmix dm; |
| 101 | dm.set<Downmix::type>(type); |
| 102 | mTags.push_back({Downmix::type, dm}); |
| 103 | } |
| 104 | |
| 105 | Parameter::Specific getDefaultParamSpecific() { |
| 106 | Downmix dm = Downmix::make<Downmix::type>(Downmix::Type::STRIP); |
| 107 | Parameter::Specific specific = Parameter::Specific::make<Parameter::Specific::downmix>(dm); |
| 108 | return specific; |
| 109 | } |
| 110 | |
| 111 | private: |
| 112 | std::vector<std::pair<Downmix::Tag, Downmix>> mTags; |
| 113 | void CleanUp() { mTags.clear(); } |
| 114 | }; |
| 115 | |
| 116 | TEST_P(DownmixParamTest, SetAndGetType) { |
| 117 | EXPECT_NO_FATAL_FAILURE(addTypeParam(mParamType)); |
| 118 | SetAndGetDownmixParameters(); |
| 119 | } |
| 120 | |
| 121 | INSTANTIATE_TEST_SUITE_P( |
| 122 | DownmixTest, DownmixParamTest, |
| 123 | ::testing::Combine(testing::ValuesIn(EffectFactoryHelper::getAllEffectDescriptors( |
Shunkai Yao | f8be1ac | 2023-03-06 18:41:27 +0000 | [diff] [blame] | 124 | IFactory::descriptor, getEffectTypeUuidDownmix())), |
Sham Rathod | 40f55bd | 2022-11-14 14:24:49 +0530 | [diff] [blame] | 125 | testing::ValuesIn(kTypeValues)), |
| 126 | [](const testing::TestParamInfo<DownmixParamTest::ParamType>& info) { |
| 127 | auto descriptor = std::get<PARAM_INSTANCE_NAME>(info.param).second; |
| 128 | std::string type = std::to_string(static_cast<int>(std::get<PARAM_TYPE>(info.param))); |
Jaideep Sharma | e4c7a96 | 2023-06-14 19:14:44 +0530 | [diff] [blame] | 129 | std::string name = getPrefix(descriptor) + "_type" + type; |
Sham Rathod | 40f55bd | 2022-11-14 14:24:49 +0530 | [diff] [blame] | 130 | std::replace_if( |
| 131 | name.begin(), name.end(), [](const char c) { return !std::isalnum(c); }, '_'); |
| 132 | return name; |
| 133 | }); |
| 134 | |
| 135 | GTEST_ALLOW_UNINSTANTIATED_PARAMETERIZED_TEST(DownmixParamTest); |
| 136 | |
| 137 | int main(int argc, char** argv) { |
| 138 | ::testing::InitGoogleTest(&argc, argv); |
Jaideep Sharma | 7449841 | 2023-09-13 15:25:25 +0530 | [diff] [blame] | 139 | ::testing::UnitTest::GetInstance()->listeners().Append(new TestExecutionTracer()); |
Sham Rathod | 40f55bd | 2022-11-14 14:24:49 +0530 | [diff] [blame] | 140 | ABinderProcess_setThreadPoolMaxThreadCount(1); |
| 141 | ABinderProcess_startThreadPool(); |
| 142 | return RUN_ALL_TESTS(); |
| 143 | } |