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; |
| 27 | using aidl::android::hardware::audio::effect::IEffect; |
| 28 | using aidl::android::hardware::audio::effect::IFactory; |
| 29 | using aidl::android::hardware::audio::effect::kDownmixTypeUUID; |
| 30 | using aidl::android::hardware::audio::effect::kEffectNullUuid; |
| 31 | using aidl::android::hardware::audio::effect::Parameter; |
| 32 | |
| 33 | /** |
| 34 | * Here we focus on specific parameter checking, general IEffect interfaces testing performed in |
| 35 | * VtsAudioEffectTargetTest. |
| 36 | */ |
| 37 | enum ParamName { PARAM_INSTANCE_NAME, PARAM_TYPE }; |
| 38 | using DownmixParamTestParam = |
| 39 | std::tuple<std::pair<std::shared_ptr<IFactory>, Descriptor>, Downmix::Type>; |
| 40 | |
| 41 | // Testing for enum values |
| 42 | const std::vector<Downmix::Type> kTypeValues = {Downmix::Type::STRIP, Downmix::Type::FOLD}; |
| 43 | |
| 44 | class DownmixParamTest : public ::testing::TestWithParam<DownmixParamTestParam>, |
| 45 | public EffectHelper { |
| 46 | public: |
| 47 | DownmixParamTest() : mParamType(std::get<PARAM_TYPE>(GetParam())) { |
| 48 | std::tie(mFactory, mDescriptor) = std::get<PARAM_INSTANCE_NAME>(GetParam()); |
| 49 | } |
| 50 | |
| 51 | void SetUp() override { |
| 52 | ASSERT_NE(nullptr, mFactory); |
| 53 | ASSERT_NO_FATAL_FAILURE(create(mFactory, mEffect, mDescriptor)); |
| 54 | |
| 55 | Parameter::Specific specific = getDefaultParamSpecific(); |
| 56 | Parameter::Common common = EffectHelper::createParamCommon( |
| 57 | 0 /* session */, 1 /* ioHandle */, 44100 /* iSampleRate */, 44100 /* oSampleRate */, |
| 58 | kInputFrameCount /* iFrameCount */, kOutputFrameCount /* oFrameCount */); |
| 59 | IEffect::OpenEffectReturn ret; |
| 60 | ASSERT_NO_FATAL_FAILURE(open(mEffect, common, specific, &ret, EX_NONE)); |
| 61 | ASSERT_NE(nullptr, mEffect); |
| 62 | } |
| 63 | |
| 64 | void TearDown() override { |
| 65 | ASSERT_NO_FATAL_FAILURE(close(mEffect)); |
| 66 | ASSERT_NO_FATAL_FAILURE(destroy(mFactory, mEffect)); |
| 67 | } |
| 68 | |
| 69 | static const long kInputFrameCount = 0x100, kOutputFrameCount = 0x100; |
| 70 | std::shared_ptr<IFactory> mFactory; |
| 71 | std::shared_ptr<IEffect> mEffect; |
| 72 | Descriptor mDescriptor; |
| 73 | Downmix::Type mParamType = Downmix::Type::STRIP; |
| 74 | |
| 75 | void SetAndGetDownmixParameters() { |
| 76 | for (auto& it : mTags) { |
| 77 | auto& tag = it.first; |
| 78 | auto& dm = it.second; |
| 79 | |
| 80 | // set parameter |
| 81 | Parameter expectParam; |
| 82 | Parameter::Specific specific; |
| 83 | specific.set<Parameter::Specific::downmix>(dm); |
| 84 | expectParam.set<Parameter::specific>(specific); |
| 85 | // All values are valid, set parameter should succeed |
| 86 | EXPECT_STATUS(EX_NONE, mEffect->setParameter(expectParam)) << expectParam.toString(); |
| 87 | |
| 88 | // get parameter |
| 89 | Parameter getParam; |
| 90 | Parameter::Id id; |
| 91 | Downmix::Id dmId; |
| 92 | dmId.set<Downmix::Id::commonTag>(tag); |
| 93 | id.set<Parameter::Id::downmixTag>(dmId); |
| 94 | EXPECT_STATUS(EX_NONE, mEffect->getParameter(id, &getParam)); |
| 95 | |
| 96 | EXPECT_EQ(expectParam, getParam); |
| 97 | } |
| 98 | } |
| 99 | |
| 100 | void addTypeParam(Downmix::Type type) { |
| 101 | Downmix dm; |
| 102 | dm.set<Downmix::type>(type); |
| 103 | mTags.push_back({Downmix::type, dm}); |
| 104 | } |
| 105 | |
| 106 | Parameter::Specific getDefaultParamSpecific() { |
| 107 | Downmix dm = Downmix::make<Downmix::type>(Downmix::Type::STRIP); |
| 108 | Parameter::Specific specific = Parameter::Specific::make<Parameter::Specific::downmix>(dm); |
| 109 | return specific; |
| 110 | } |
| 111 | |
| 112 | private: |
| 113 | std::vector<std::pair<Downmix::Tag, Downmix>> mTags; |
| 114 | void CleanUp() { mTags.clear(); } |
| 115 | }; |
| 116 | |
| 117 | TEST_P(DownmixParamTest, SetAndGetType) { |
| 118 | EXPECT_NO_FATAL_FAILURE(addTypeParam(mParamType)); |
| 119 | SetAndGetDownmixParameters(); |
| 120 | } |
| 121 | |
| 122 | INSTANTIATE_TEST_SUITE_P( |
| 123 | DownmixTest, DownmixParamTest, |
| 124 | ::testing::Combine(testing::ValuesIn(EffectFactoryHelper::getAllEffectDescriptors( |
| 125 | IFactory::descriptor, kDownmixTypeUUID)), |
| 126 | testing::ValuesIn(kTypeValues)), |
| 127 | [](const testing::TestParamInfo<DownmixParamTest::ParamType>& info) { |
| 128 | auto descriptor = std::get<PARAM_INSTANCE_NAME>(info.param).second; |
| 129 | std::string type = std::to_string(static_cast<int>(std::get<PARAM_TYPE>(info.param))); |
| 130 | std::string name = "Implementor_" + descriptor.common.implementor + "_name_" + |
| 131 | descriptor.common.name + "_UUID_" + |
| 132 | descriptor.common.id.uuid.toString() + "_type" + type; |
| 133 | std::replace_if( |
| 134 | name.begin(), name.end(), [](const char c) { return !std::isalnum(c); }, '_'); |
| 135 | return name; |
| 136 | }); |
| 137 | |
| 138 | GTEST_ALLOW_UNINSTANTIATED_PARAMETERIZED_TEST(DownmixParamTest); |
| 139 | |
| 140 | int main(int argc, char** argv) { |
| 141 | ::testing::InitGoogleTest(&argc, argv); |
| 142 | ABinderProcess_setThreadPoolMaxThreadCount(1); |
| 143 | ABinderProcess_startThreadPool(); |
| 144 | return RUN_ALL_TESTS(); |
| 145 | } |