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