blob: 0601cc4e1e94f3b7ecdb7eaea0d0a074325f001f [file] [log] [blame]
Sham Rathod40f55bd2022-11-14 14:24:49 +05301/*
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
17#define LOG_TAG "VtsHalDownmixTargetTest"
18
19#include <Utils.h>
20#include <aidl/Vintf.h>
21#include "EffectHelper.h"
22
23using namespace android;
24
Sham Rathod40f55bd2022-11-14 14:24:49 +053025using aidl::android::hardware::audio::effect::Descriptor;
26using aidl::android::hardware::audio::effect::Downmix;
27using aidl::android::hardware::audio::effect::IEffect;
28using aidl::android::hardware::audio::effect::IFactory;
29using aidl::android::hardware::audio::effect::kDownmixTypeUUID;
30using aidl::android::hardware::audio::effect::kEffectNullUuid;
31using 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 */
37enum ParamName { PARAM_INSTANCE_NAME, PARAM_TYPE };
38using DownmixParamTestParam =
39 std::tuple<std::pair<std::shared_ptr<IFactory>, Descriptor>, Downmix::Type>;
40
41// Testing for enum values
42const std::vector<Downmix::Type> kTypeValues = {Downmix::Type::STRIP, Downmix::Type::FOLD};
43
44class 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
117TEST_P(DownmixParamTest, SetAndGetType) {
118 EXPECT_NO_FATAL_FAILURE(addTypeParam(mParamType));
119 SetAndGetDownmixParameters();
120}
121
122INSTANTIATE_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
138GTEST_ALLOW_UNINSTANTIATED_PARAMETERIZED_TEST(DownmixParamTest);
139
140int main(int argc, char** argv) {
141 ::testing::InitGoogleTest(&argc, argv);
142 ABinderProcess_setThreadPoolMaxThreadCount(1);
143 ABinderProcess_startThreadPool();
144 return RUN_ALL_TESTS();
145}