blob: a1862d21ac024ec6ffe178775195d31fa08fc878 [file] [log] [blame]
Shraddha Basantwanif627d802022-11-08 14:45:07 +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 "VtsHalBassBoostTest"
18
19#include <Utils.h>
20#include <aidl/Vintf.h>
21#include <limits.h>
22
23#include "EffectHelper.h"
24
25using namespace android;
26
27using aidl::android::hardware::audio::effect::BassBoost;
28using aidl::android::hardware::audio::effect::Capability;
29using aidl::android::hardware::audio::effect::Descriptor;
30using aidl::android::hardware::audio::effect::IEffect;
31using aidl::android::hardware::audio::effect::IFactory;
32using aidl::android::hardware::audio::effect::kBassBoostTypeUUID;
33using aidl::android::hardware::audio::effect::Parameter;
Shunkai Yao0a0c45e2023-02-13 17:41:11 +000034using aidl::android::hardware::audio::effect::Range;
Shraddha Basantwanif627d802022-11-08 14:45:07 +053035
36/**
37 * Here we focus on specific parameter checking, general IEffect interfaces testing performed in
38 * VtsAudioEffectTargetTest.
39 */
40enum ParamName { PARAM_INSTANCE_NAME, PARAM_STRENGTH };
Shunkai Yaocb0fc412022-12-15 20:34:32 +000041using BassBoostParamTestParam = std::tuple<std::pair<std::shared_ptr<IFactory>, Descriptor>, int>;
Shraddha Basantwanif627d802022-11-08 14:45:07 +053042
43/*
44 * Testing parameter range, assuming the parameter supported by effect is in this range.
45 * Parameter should be within the valid range defined in the documentation,
46 * for any supported value test expects EX_NONE from IEffect.setParameter(),
47 * otherwise expect EX_ILLEGAL_ARGUMENT.
48 */
49
Shraddha Basantwanif627d802022-11-08 14:45:07 +053050class BassBoostParamTest : public ::testing::TestWithParam<BassBoostParamTestParam>,
51 public EffectHelper {
52 public:
53 BassBoostParamTest() : mParamStrength(std::get<PARAM_STRENGTH>(GetParam())) {
Shunkai Yaocb0fc412022-12-15 20:34:32 +000054 std::tie(mFactory, mDescriptor) = std::get<PARAM_INSTANCE_NAME>(GetParam());
Shraddha Basantwanif627d802022-11-08 14:45:07 +053055 }
56
57 void SetUp() override {
58 ASSERT_NE(nullptr, mFactory);
Shunkai Yaocb0fc412022-12-15 20:34:32 +000059 ASSERT_NO_FATAL_FAILURE(create(mFactory, mEffect, mDescriptor));
Shraddha Basantwanif627d802022-11-08 14:45:07 +053060
61 Parameter::Specific specific = getDefaultParamSpecific();
62 Parameter::Common common = EffectHelper::createParamCommon(
63 0 /* session */, 1 /* ioHandle */, 44100 /* iSampleRate */, 44100 /* oSampleRate */,
64 kInputFrameCount /* iFrameCount */, kOutputFrameCount /* oFrameCount */);
65 IEffect::OpenEffectReturn ret;
66 ASSERT_NO_FATAL_FAILURE(open(mEffect, common, specific, &ret, EX_NONE));
67 ASSERT_NE(nullptr, mEffect);
68 }
69
70 void TearDown() override {
71 ASSERT_NO_FATAL_FAILURE(close(mEffect));
72 ASSERT_NO_FATAL_FAILURE(destroy(mFactory, mEffect));
73 }
74
75 Parameter::Specific getDefaultParamSpecific() {
Sham Rathod8411fd22022-12-27 10:27:03 +053076 BassBoost bb = BassBoost::make<BassBoost::strengthPm>(0);
Shraddha Basantwanif627d802022-11-08 14:45:07 +053077 Parameter::Specific specific =
78 Parameter::Specific::make<Parameter::Specific::bassBoost>(bb);
79 return specific;
80 }
81
82 static const long kInputFrameCount = 0x100, kOutputFrameCount = 0x100;
83 std::shared_ptr<IFactory> mFactory;
84 std::shared_ptr<IEffect> mEffect;
Shunkai Yaocb0fc412022-12-15 20:34:32 +000085 Descriptor mDescriptor;
Sham Rathod8411fd22022-12-27 10:27:03 +053086 int mParamStrength = 0;
Shraddha Basantwanif627d802022-11-08 14:45:07 +053087
88 void SetAndGetBassBoostParameters() {
89 for (auto& it : mTags) {
90 auto& tag = it.first;
91 auto& bb = it.second;
92
93 // validate parameter
94 Descriptor desc;
95 ASSERT_STATUS(EX_NONE, mEffect->getDescriptor(&desc));
Shunkai Yao0a0c45e2023-02-13 17:41:11 +000096 const bool valid = isParameterValid<BassBoost, Range::bassBoost>(it.second, desc);
Shraddha Basantwanif627d802022-11-08 14:45:07 +053097 const binder_exception_t expected = valid ? EX_NONE : EX_ILLEGAL_ARGUMENT;
98
99 // set parameter
100 Parameter expectParam;
101 Parameter::Specific specific;
102 specific.set<Parameter::Specific::bassBoost>(bb);
103 expectParam.set<Parameter::specific>(specific);
104 EXPECT_STATUS(expected, mEffect->setParameter(expectParam)) << expectParam.toString();
105
106 // only get if parameter in range and set success
107 if (expected == EX_NONE) {
108 Parameter getParam;
109 Parameter::Id id;
110 BassBoost::Id bbId;
111 bbId.set<BassBoost::Id::commonTag>(tag);
112 id.set<Parameter::Id::bassBoostTag>(bbId);
113 // if set success, then get should match
114 EXPECT_STATUS(expected, mEffect->getParameter(id, &getParam));
115 EXPECT_EQ(expectParam, getParam);
116 }
117 }
118 }
119
120 void addStrengthParam(int strength) {
121 BassBoost bb;
122 bb.set<BassBoost::strengthPm>(strength);
123 mTags.push_back({BassBoost::strengthPm, bb});
124 }
125
Shraddha Basantwanif627d802022-11-08 14:45:07 +0530126 private:
127 std::vector<std::pair<BassBoost::Tag, BassBoost>> mTags;
128 void CleanUp() { mTags.clear(); }
129};
130
131TEST_P(BassBoostParamTest, SetAndGetStrength) {
132 EXPECT_NO_FATAL_FAILURE(addStrengthParam(mParamStrength));
133 SetAndGetBassBoostParameters();
134}
135
Shunkai Yao0a0c45e2023-02-13 17:41:11 +0000136std::vector<std::pair<std::shared_ptr<IFactory>, Descriptor>> kDescPair;
Shraddha Basantwanif627d802022-11-08 14:45:07 +0530137INSTANTIATE_TEST_SUITE_P(
138 BassBoostTest, BassBoostParamTest,
Sham Rathod8411fd22022-12-27 10:27:03 +0530139 ::testing::Combine(
Shunkai Yao0a0c45e2023-02-13 17:41:11 +0000140 testing::ValuesIn(kDescPair = EffectFactoryHelper::getAllEffectDescriptors(
141 IFactory::descriptor, kBassBoostTypeUUID)),
142 testing::ValuesIn(EffectHelper::getTestValueSet<BassBoost, int, Range::bassBoost,
143 BassBoost::strengthPm>(
144 kDescPair, EffectHelper::expandTestValueBasic<int>))),
Shraddha Basantwanif627d802022-11-08 14:45:07 +0530145 [](const testing::TestParamInfo<BassBoostParamTest::ParamType>& info) {
Shunkai Yaocb0fc412022-12-15 20:34:32 +0000146 auto descriptor = std::get<PARAM_INSTANCE_NAME>(info.param).second;
Shraddha Basantwanif627d802022-11-08 14:45:07 +0530147 std::string strength = std::to_string(std::get<PARAM_STRENGTH>(info.param));
Shunkai Yaocb0fc412022-12-15 20:34:32 +0000148 std::string name = "Implementor_" + descriptor.common.implementor + "_name_" +
149 descriptor.common.name + "_UUID_" +
150 descriptor.common.id.uuid.toString() + "_strength_" + strength;
Shraddha Basantwanif627d802022-11-08 14:45:07 +0530151 std::replace_if(
152 name.begin(), name.end(), [](const char c) { return !std::isalnum(c); }, '_');
153 return name;
154 });
155
156GTEST_ALLOW_UNINSTANTIATED_PARAMETERIZED_TEST(BassBoostParamTest);
157
158int main(int argc, char** argv) {
159 ::testing::InitGoogleTest(&argc, argv);
160 ABinderProcess_setThreadPoolMaxThreadCount(1);
161 ABinderProcess_startThreadPool();
162 return RUN_ALL_TESTS();
163}