blob: 257100b9cff6f468b65d73c84edcd811ad443ae9 [file] [log] [blame]
Sham Rathod1b6c1f02022-11-22 17:39:22 +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
Sham Rathod1b6c1f02022-11-22 17:39:22 +053017#include <aidl/Vintf.h>
Mikhail Naganov872d4a62023-03-09 18:19:01 -080018#define LOG_TAG "VtsHalVolumeTest"
19#include <android-base/logging.h>
20
Sham Rathod1b6c1f02022-11-22 17:39:22 +053021#include "EffectHelper.h"
22
23using namespace android;
24
Sham Rathod1b6c1f02022-11-22 17:39:22 +053025using aidl::android::hardware::audio::effect::Descriptor;
Shunkai Yaof8be1ac2023-03-06 18:41:27 +000026using aidl::android::hardware::audio::effect::getEffectTypeUuidVolume;
Sham Rathod1b6c1f02022-11-22 17:39:22 +053027using aidl::android::hardware::audio::effect::IEffect;
28using aidl::android::hardware::audio::effect::IFactory;
Sham Rathod1b6c1f02022-11-22 17:39:22 +053029using aidl::android::hardware::audio::effect::Parameter;
30using aidl::android::hardware::audio::effect::Volume;
Jaideep Sharma74498412023-09-13 15:25:25 +053031using android::hardware::audio::common::testing::detail::TestExecutionTracer;
Sham Rathod1b6c1f02022-11-22 17:39:22 +053032
33/**
34 * Here we focus on specific parameter checking, general IEffect interfaces testing performed in
35 * VtsAudioEffectTargetTest.
36 */
Sham Rathod85793d82022-12-22 19:09:10 +053037enum ParamName { PARAM_INSTANCE_NAME, PARAM_LEVEL, PARAM_MUTE };
Sham Rathod1b6c1f02022-11-22 17:39:22 +053038using VolumeParamTestParam =
39 std::tuple<std::pair<std::shared_ptr<IFactory>, Descriptor>, int, bool>;
40
Sham Rathod1b6c1f02022-11-22 17:39:22 +053041class VolumeParamTest : public ::testing::TestWithParam<VolumeParamTestParam>, public EffectHelper {
42 public:
43 VolumeParamTest()
Sham Rathod85793d82022-12-22 19:09:10 +053044 : mParamLevel(std::get<PARAM_LEVEL>(GetParam())),
Sham Rathod1b6c1f02022-11-22 17:39:22 +053045 mParamMute(std::get<PARAM_MUTE>(GetParam())) {
46 std::tie(mFactory, mDescriptor) = std::get<PARAM_INSTANCE_NAME>(GetParam());
47 }
48
49 void SetUp() override {
50 ASSERT_NE(nullptr, mFactory);
51 ASSERT_NO_FATAL_FAILURE(create(mFactory, mEffect, mDescriptor));
52
53 Parameter::Specific specific = getDefaultParamSpecific();
54 Parameter::Common common = EffectHelper::createParamCommon(
55 0 /* session */, 1 /* ioHandle */, 44100 /* iSampleRate */, 44100 /* oSampleRate */,
56 kInputFrameCount /* iFrameCount */, kOutputFrameCount /* oFrameCount */);
57 IEffect::OpenEffectReturn ret;
58 ASSERT_NO_FATAL_FAILURE(open(mEffect, common, specific, &ret, EX_NONE));
59 ASSERT_NE(nullptr, mEffect);
60 }
61 void TearDown() override {
62 ASSERT_NO_FATAL_FAILURE(close(mEffect));
63 ASSERT_NO_FATAL_FAILURE(destroy(mFactory, mEffect));
64 }
65
66 Parameter::Specific getDefaultParamSpecific() {
Sham Rathod85793d82022-12-22 19:09:10 +053067 Volume vol = Volume::make<Volume::levelDb>(-9600);
Sham Rathod1b6c1f02022-11-22 17:39:22 +053068 Parameter::Specific specific = Parameter::Specific::make<Parameter::Specific::volume>(vol);
69 return specific;
70 }
71
72 static const long kInputFrameCount = 0x100, kOutputFrameCount = 0x100;
73 std::shared_ptr<IFactory> mFactory;
74 std::shared_ptr<IEffect> mEffect;
75 Descriptor mDescriptor;
76 int mParamLevel = 0;
77 bool mParamMute = false;
78
79 void SetAndGetParameters() {
80 for (auto& it : mTags) {
81 auto& tag = it.first;
82 auto& vol = it.second;
83
84 // validate parameter
85 Descriptor desc;
86 ASSERT_STATUS(EX_NONE, mEffect->getDescriptor(&desc));
Shunkai Yao0a0c45e2023-02-13 17:41:11 +000087 const bool valid = isParameterValid<Volume, Range::volume>(it.second, desc);
Sham Rathod1b6c1f02022-11-22 17:39:22 +053088 const binder_exception_t expected = valid ? EX_NONE : EX_ILLEGAL_ARGUMENT;
89
90 // set parameter
91 Parameter expectParam;
92 Parameter::Specific specific;
93 specific.set<Parameter::Specific::volume>(vol);
94 expectParam.set<Parameter::specific>(specific);
95 EXPECT_STATUS(expected, mEffect->setParameter(expectParam)) << expectParam.toString();
96
Sham Rathod85793d82022-12-22 19:09:10 +053097 // only get if parameter is in range and set success
Sham Rathod1b6c1f02022-11-22 17:39:22 +053098 if (expected == EX_NONE) {
99 Parameter getParam;
100 Parameter::Id id;
101 Volume::Id volId;
102 volId.set<Volume::Id::commonTag>(tag);
103 id.set<Parameter::Id::volumeTag>(volId);
104 EXPECT_STATUS(EX_NONE, mEffect->getParameter(id, &getParam));
105
106 EXPECT_EQ(expectParam, getParam) << "\nexpect:" << expectParam.toString()
107 << "\ngetParam:" << getParam.toString();
108 }
109 }
110 }
111
112 void addLevelParam(int level) {
113 Volume vol;
114 vol.set<Volume::levelDb>(level);
115 mTags.push_back({Volume::levelDb, vol});
116 }
117
118 void addMuteParam(bool mute) {
119 Volume vol;
120 vol.set<Volume::mute>(mute);
121 mTags.push_back({Volume::mute, vol});
122 }
123
Sham Rathod1b6c1f02022-11-22 17:39:22 +0530124 private:
125 std::vector<std::pair<Volume::Tag, Volume>> mTags;
126 void CleanUp() { mTags.clear(); }
127};
128
129TEST_P(VolumeParamTest, SetAndGetLevel) {
130 EXPECT_NO_FATAL_FAILURE(addLevelParam(mParamLevel));
131 SetAndGetParameters();
132}
133
134TEST_P(VolumeParamTest, SetAndGetMute) {
135 EXPECT_NO_FATAL_FAILURE(addMuteParam(mParamMute));
136 SetAndGetParameters();
137}
138
Shunkai Yao0a0c45e2023-02-13 17:41:11 +0000139std::vector<std::pair<std::shared_ptr<IFactory>, Descriptor>> kDescPair;
Sham Rathod1b6c1f02022-11-22 17:39:22 +0530140INSTANTIATE_TEST_SUITE_P(
141 VolumeTest, VolumeParamTest,
Sham Rathod85793d82022-12-22 19:09:10 +0530142 ::testing::Combine(
Shunkai Yao0a0c45e2023-02-13 17:41:11 +0000143 testing::ValuesIn(kDescPair = EffectFactoryHelper::getAllEffectDescriptors(
Shunkai Yaof8be1ac2023-03-06 18:41:27 +0000144 IFactory::descriptor, getEffectTypeUuidVolume())),
Shunkai Yao0a0c45e2023-02-13 17:41:11 +0000145 testing::ValuesIn(
146 EffectHelper::getTestValueSet<Volume, int, Range::volume, Volume::levelDb>(
147 kDescPair, EffectHelper::expandTestValueBasic<int>)),
Sham Rathod85793d82022-12-22 19:09:10 +0530148 testing::Bool() /* mute */),
Sham Rathod1b6c1f02022-11-22 17:39:22 +0530149 [](const testing::TestParamInfo<VolumeParamTest::ParamType>& info) {
150 auto descriptor = std::get<PARAM_INSTANCE_NAME>(info.param).second;
Sham Rathod85793d82022-12-22 19:09:10 +0530151 std::string level = std::to_string(std::get<PARAM_LEVEL>(info.param));
Sham Rathod1b6c1f02022-11-22 17:39:22 +0530152 std::string mute = std::to_string(std::get<PARAM_MUTE>(info.param));
Shunkai Yao9e60e632023-06-23 04:34:50 +0000153 std::string name = getPrefix(descriptor) + "_level" + level + "_mute" + mute;
Sham Rathod1b6c1f02022-11-22 17:39:22 +0530154 std::replace_if(
155 name.begin(), name.end(), [](const char c) { return !std::isalnum(c); }, '_');
156 return name;
157 });
158
159GTEST_ALLOW_UNINSTANTIATED_PARAMETERIZED_TEST(VolumeParamTest);
160
161int main(int argc, char** argv) {
162 ::testing::InitGoogleTest(&argc, argv);
Jaideep Sharma74498412023-09-13 15:25:25 +0530163 ::testing::UnitTest::GetInstance()->listeners().Append(new TestExecutionTracer());
Sham Rathod1b6c1f02022-11-22 17:39:22 +0530164 ABinderProcess_setThreadPoolMaxThreadCount(1);
165 ABinderProcess_startThreadPool();
166 return RUN_ALL_TESTS();
167}