blob: d23bdc99e34f6b48e6667c335f06cf15a0cb2013 [file] [log] [blame]
Shunkai Yao67b1be62022-07-13 05:01:42 +00001/*
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
Shunkai Yaoa4ab38c2022-10-14 01:07:47 +000017#define LOG_TAG "VtsHalAudioEffectTargetTest"
18
Shunkai Yao45905172022-08-24 18:14:02 +000019#include <memory>
Shunkai Yao67b1be62022-07-13 05:01:42 +000020#include <string>
Shunkai Yao45905172022-08-24 18:14:02 +000021#include <vector>
Shunkai Yao67b1be62022-07-13 05:01:42 +000022
Shunkai Yao67b1be62022-07-13 05:01:42 +000023#include <aidl/Gtest.h>
Shunkai Yao812d5b42022-11-16 18:08:50 +000024#include <aidl/android/hardware/audio/effect/IEffect.h>
25#include <aidl/android/hardware/audio/effect/IFactory.h>
Shunkai Yao67b1be62022-07-13 05:01:42 +000026#include <android-base/logging.h>
Shunkai Yao67b1be62022-07-13 05:01:42 +000027#include <android/binder_interface_utils.h>
28#include <android/binder_manager.h>
29#include <android/binder_process.h>
Shunkai Yao812d5b42022-11-16 18:08:50 +000030#include <fmq/AidlMessageQueue.h>
Shunkai Yao67b1be62022-07-13 05:01:42 +000031
Shunkai Yao812d5b42022-11-16 18:08:50 +000032#include "EffectFactoryHelper.h"
Shunkai Yaoa4ab38c2022-10-14 01:07:47 +000033#include "EffectHelper.h"
Shunkai Yao121c6dd2022-09-21 23:42:08 +000034#include "TestUtils.h"
Shunkai Yao67b1be62022-07-13 05:01:42 +000035
36using namespace android;
37
38using ndk::ScopedAStatus;
39
Shunkai Yaoea24c1a2022-09-28 17:39:23 +000040using aidl::android::hardware::audio::effect::CommandId;
Shunkai Yao67b1be62022-07-13 05:01:42 +000041using aidl::android::hardware::audio::effect::Descriptor;
Shunkai Yao8771cec2023-09-20 22:46:59 +000042using aidl::android::hardware::audio::effect::Flags;
Shunkai Yao45905172022-08-24 18:14:02 +000043using aidl::android::hardware::audio::effect::IEffect;
Shunkai Yao67b1be62022-07-13 05:01:42 +000044using aidl::android::hardware::audio::effect::IFactory;
Shunkai Yaoea24c1a2022-09-28 17:39:23 +000045using aidl::android::hardware::audio::effect::Parameter;
46using aidl::android::hardware::audio::effect::State;
Shunkai Yao5df4e6c2023-01-10 03:20:00 +000047using aidl::android::media::audio::common::AudioDeviceDescription;
48using aidl::android::media::audio::common::AudioDeviceType;
49using aidl::android::media::audio::common::AudioMode;
50using aidl::android::media::audio::common::AudioSource;
Jaideep Sharma74498412023-09-13 15:25:25 +053051using android::hardware::audio::common::testing::detail::TestExecutionTracer;
Shunkai Yao67b1be62022-07-13 05:01:42 +000052
Shunkai Yao812d5b42022-11-16 18:08:50 +000053enum ParamName { PARAM_INSTANCE_NAME };
Shunkai Yaocb0fc412022-12-15 20:34:32 +000054using EffectTestParam = std::tuple<std::pair<std::shared_ptr<IFactory>, Descriptor>>;
Shunkai Yao812d5b42022-11-16 18:08:50 +000055
56class AudioEffectTest : public testing::TestWithParam<EffectTestParam>, public EffectHelper {
Shunkai Yao45905172022-08-24 18:14:02 +000057 public:
Shunkai Yaocb0fc412022-12-15 20:34:32 +000058 AudioEffectTest() {
59 std::tie(mFactory, mDescriptor) = std::get<PARAM_INSTANCE_NAME>(GetParam());
Shunkai Yaoef683a92024-04-18 04:38:17 +000060 mVersion = EffectFactoryHelper::getHalVersion(mFactory);
Shunkai Yaocb0fc412022-12-15 20:34:32 +000061 }
Shunkai Yaoa4ab38c2022-10-14 01:07:47 +000062
Shunkai Yao812d5b42022-11-16 18:08:50 +000063 void SetUp() override {}
Shunkai Yaocb0fc412022-12-15 20:34:32 +000064
65 void TearDown() override {
66 // Do the cleanup for every test case
67 if (mEffect) {
68 ASSERT_NO_FATAL_FAILURE(commandIgnoreRet(mEffect, CommandId::STOP));
69 ASSERT_NO_FATAL_FAILURE(closeIgnoreRet(mEffect));
70 ASSERT_NO_FATAL_FAILURE(destroyIgnoreRet(mFactory, mEffect));
71 mEffect.reset();
72 }
73 }
Shunkai Yao45905172022-08-24 18:14:02 +000074
Shunkai Yao812d5b42022-11-16 18:08:50 +000075 static const long kInputFrameCount = 0x100, kOutputFrameCount = 0x100;
76 std::shared_ptr<IFactory> mFactory;
Shunkai Yaocb0fc412022-12-15 20:34:32 +000077 std::shared_ptr<IEffect> mEffect;
78 Descriptor mDescriptor;
Shunkai Yaoef683a92024-04-18 04:38:17 +000079 int mVersion = 0;
Shunkai Yao5df4e6c2023-01-10 03:20:00 +000080
81 void setAndGetParameter(Parameter::Id id, const Parameter& set) {
82 Parameter get;
83 EXPECT_IS_OK(mEffect->setParameter(set));
84 EXPECT_IS_OK(mEffect->getParameter(id, &get));
Shunkai Yaoeea19942023-02-16 02:31:24 +000085 EXPECT_EQ(set, get) << set.toString() << "\n vs \n" << get.toString();
Shunkai Yao5df4e6c2023-01-10 03:20:00 +000086 }
Shunkai Yao45905172022-08-24 18:14:02 +000087};
88
Jaideep Sharmacba42862023-06-23 10:27:39 +053089class AudioEffectDataPathTest : public AudioEffectTest {
Shunkai Yao8771cec2023-09-20 22:46:59 +000090 public:
91 void SetUp() override {
92 AudioEffectTest::SetUp();
93 SKIP_TEST_IF_DATA_UNSUPPORTED(mDescriptor.common.flags);
94 }
Jaideep Sharmacba42862023-06-23 10:27:39 +053095};
96
Shunkai Yao812d5b42022-11-16 18:08:50 +000097TEST_P(AudioEffectTest, SetupAndTearDown) {
98 // Intentionally empty test body.
Shunkai Yao45905172022-08-24 18:14:02 +000099}
100
Shunkai Yao812d5b42022-11-16 18:08:50 +0000101TEST_P(AudioEffectTest, CreateAndDestroy) {
Shunkai Yaocb0fc412022-12-15 20:34:32 +0000102 ASSERT_NO_FATAL_FAILURE(create(mFactory, mEffect, mDescriptor));
103 ASSERT_NO_FATAL_FAILURE(destroy(mFactory, mEffect));
Shunkai Yao45905172022-08-24 18:14:02 +0000104}
105
Shunkai Yao812d5b42022-11-16 18:08:50 +0000106TEST_P(AudioEffectTest, OpenAndClose) {
Shunkai Yaocb0fc412022-12-15 20:34:32 +0000107 ASSERT_NO_FATAL_FAILURE(create(mFactory, mEffect, mDescriptor));
108 ASSERT_NO_FATAL_FAILURE(open(mEffect));
109 ASSERT_NO_FATAL_FAILURE(close(mEffect));
110 ASSERT_NO_FATAL_FAILURE(destroy(mFactory, mEffect));
Shunkai Yao45905172022-08-24 18:14:02 +0000111}
112
Shunkai Yao812d5b42022-11-16 18:08:50 +0000113TEST_P(AudioEffectTest, CloseUnopenedEffect) {
Shunkai Yaocb0fc412022-12-15 20:34:32 +0000114 ASSERT_NO_FATAL_FAILURE(create(mFactory, mEffect, mDescriptor));
115 ASSERT_NO_FATAL_FAILURE(close(mEffect));
116 ASSERT_NO_FATAL_FAILURE(destroy(mFactory, mEffect));
Shunkai Yao45905172022-08-24 18:14:02 +0000117}
118
Shunkai Yao812d5b42022-11-16 18:08:50 +0000119TEST_P(AudioEffectTest, DoubleOpenAndClose) {
120 std::shared_ptr<IEffect> effect1, effect2;
Shunkai Yaocb0fc412022-12-15 20:34:32 +0000121 ASSERT_NO_FATAL_FAILURE(create(mFactory, effect1, mDescriptor));
122 ASSERT_NO_FATAL_FAILURE(create(mFactory, effect2, mDescriptor));
Shunkai Yao812d5b42022-11-16 18:08:50 +0000123 ASSERT_NO_FATAL_FAILURE(open(effect1));
124 ASSERT_NO_FATAL_FAILURE(open(effect2, 1 /* session */));
125 ASSERT_NO_FATAL_FAILURE(close(effect1));
126 ASSERT_NO_FATAL_FAILURE(close(effect2));
127 ASSERT_NO_FATAL_FAILURE(destroy(mFactory, effect1));
128 ASSERT_NO_FATAL_FAILURE(destroy(mFactory, effect2));
Shunkai Yao45905172022-08-24 18:14:02 +0000129}
130
Shunkai Yao812d5b42022-11-16 18:08:50 +0000131TEST_P(AudioEffectTest, TripleOpenAndClose) {
132 std::shared_ptr<IEffect> effect1, effect2, effect3;
Shunkai Yaocb0fc412022-12-15 20:34:32 +0000133 ASSERT_NO_FATAL_FAILURE(create(mFactory, effect1, mDescriptor));
134 ASSERT_NO_FATAL_FAILURE(create(mFactory, effect2, mDescriptor));
135 ASSERT_NO_FATAL_FAILURE(create(mFactory, effect3, mDescriptor));
Shunkai Yao812d5b42022-11-16 18:08:50 +0000136 ASSERT_NO_FATAL_FAILURE(open(effect1));
137 ASSERT_NO_FATAL_FAILURE(open(effect2, 1 /* session */));
138 ASSERT_NO_FATAL_FAILURE(open(effect3, 2 /* session */));
139 ASSERT_NO_FATAL_FAILURE(close(effect1));
140 ASSERT_NO_FATAL_FAILURE(close(effect2));
141 ASSERT_NO_FATAL_FAILURE(close(effect3));
142 ASSERT_NO_FATAL_FAILURE(destroy(mFactory, effect1));
143 ASSERT_NO_FATAL_FAILURE(destroy(mFactory, effect2));
144 ASSERT_NO_FATAL_FAILURE(destroy(mFactory, effect3));
145}
Shunkai Yao45905172022-08-24 18:14:02 +0000146
Shunkai Yao812d5b42022-11-16 18:08:50 +0000147TEST_P(AudioEffectTest, GetDescritorBeforeOpen) {
Shunkai Yao812d5b42022-11-16 18:08:50 +0000148 Descriptor desc;
Shunkai Yaocb0fc412022-12-15 20:34:32 +0000149 ASSERT_NO_FATAL_FAILURE(create(mFactory, mEffect, mDescriptor));
150 ASSERT_NO_FATAL_FAILURE(getDescriptor(mEffect, desc));
Shunkai Yao4c4f3cd2023-02-28 01:50:40 +0000151 EXPECT_EQ(mDescriptor.common.id.type, desc.common.id.type);
152 EXPECT_EQ(mDescriptor.common.id.uuid, desc.common.id.uuid);
153 EXPECT_EQ(mDescriptor.common.name, desc.common.name);
154 EXPECT_EQ(mDescriptor.common.implementor, desc.common.implementor);
Shunkai Yaocb0fc412022-12-15 20:34:32 +0000155 // Effect implementation Must fill in implementor and name
Shunkai Yao812d5b42022-11-16 18:08:50 +0000156 EXPECT_NE("", desc.common.name);
157 EXPECT_NE("", desc.common.implementor);
Shunkai Yaocb0fc412022-12-15 20:34:32 +0000158 ASSERT_NO_FATAL_FAILURE(destroy(mFactory, mEffect));
Shunkai Yao812d5b42022-11-16 18:08:50 +0000159}
160
161TEST_P(AudioEffectTest, GetDescritorAfterOpen) {
Shunkai Yao812d5b42022-11-16 18:08:50 +0000162 Descriptor beforeOpen, afterOpen, afterClose;
Shunkai Yaocb0fc412022-12-15 20:34:32 +0000163 ASSERT_NO_FATAL_FAILURE(create(mFactory, mEffect, mDescriptor));
164 ASSERT_NO_FATAL_FAILURE(getDescriptor(mEffect, beforeOpen));
165 ASSERT_NO_FATAL_FAILURE(open(mEffect));
166 ASSERT_NO_FATAL_FAILURE(getDescriptor(mEffect, afterOpen));
Shunkai Yao812d5b42022-11-16 18:08:50 +0000167 EXPECT_EQ(beforeOpen.toString(), afterOpen.toString()) << "\n"
168 << beforeOpen.toString() << "\n"
169 << afterOpen.toString();
Shunkai Yaocb0fc412022-12-15 20:34:32 +0000170 ASSERT_NO_FATAL_FAILURE(close(mEffect));
171 ASSERT_NO_FATAL_FAILURE(getDescriptor(mEffect, afterClose));
Shunkai Yao812d5b42022-11-16 18:08:50 +0000172 EXPECT_EQ(beforeOpen.toString(), afterClose.toString()) << "\n"
173 << beforeOpen.toString() << "\n"
174 << afterClose.toString();
Shunkai Yaocb0fc412022-12-15 20:34:32 +0000175 ASSERT_NO_FATAL_FAILURE(destroy(mFactory, mEffect));
Shunkai Yao812d5b42022-11-16 18:08:50 +0000176}
177
178TEST_P(AudioEffectTest, DescriptorExistAndUnique) {
Shunkai Yao812d5b42022-11-16 18:08:50 +0000179 Descriptor desc;
180
181 auto descList = EffectFactoryHelper::getAllEffectDescriptors(IFactory::descriptor);
182 std::set<Descriptor::Identity> idSet;
183 for (const auto& it : descList) {
Shunkai Yaocb0fc412022-12-15 20:34:32 +0000184 auto& id = it.second.common.id;
Shunkai Yao812d5b42022-11-16 18:08:50 +0000185 EXPECT_EQ(0ul, idSet.count(id));
186 idSet.insert(id);
Shunkai Yao45905172022-08-24 18:14:02 +0000187 }
Shunkai Yao812d5b42022-11-16 18:08:50 +0000188
Shunkai Yaocb0fc412022-12-15 20:34:32 +0000189 ASSERT_NO_FATAL_FAILURE(create(mFactory, mEffect, mDescriptor));
190 ASSERT_NO_FATAL_FAILURE(getDescriptor(mEffect, desc));
Shunkai Yao4c4f3cd2023-02-28 01:50:40 +0000191 int uuidCount = std::count_if(idSet.begin(), idSet.end(), [&](const auto& id) {
192 return id.uuid == desc.common.id.uuid && id.type == desc.common.id.type;
193 });
194
195 EXPECT_EQ(1, uuidCount);
Shunkai Yaocb0fc412022-12-15 20:34:32 +0000196 ASSERT_NO_FATAL_FAILURE(destroy(mFactory, mEffect));
Shunkai Yao45905172022-08-24 18:14:02 +0000197}
198
Shunkai Yaoea24c1a2022-09-28 17:39:23 +0000199/// State testing.
200// An effect instance is in INIT state by default after it was created.
Shunkai Yaoa4ab38c2022-10-14 01:07:47 +0000201TEST_P(AudioEffectTest, InitStateAfterCreation) {
Shunkai Yaocb0fc412022-12-15 20:34:32 +0000202 ASSERT_NO_FATAL_FAILURE(create(mFactory, mEffect, mDescriptor));
Shunkai Yaocb0fc412022-12-15 20:34:32 +0000203 ASSERT_NO_FATAL_FAILURE(destroy(mFactory, mEffect));
Shunkai Yaoea24c1a2022-09-28 17:39:23 +0000204}
205
Shunkai Yao812d5b42022-11-16 18:08:50 +0000206// An effect instance transfer to IDLE state after IEffect.ASSERT_NO_FATAL_FAILURE(open().
Shunkai Yaoa4ab38c2022-10-14 01:07:47 +0000207TEST_P(AudioEffectTest, IdleStateAfterOpen) {
Shunkai Yaocb0fc412022-12-15 20:34:32 +0000208 ASSERT_NO_FATAL_FAILURE(create(mFactory, mEffect, mDescriptor));
209 ASSERT_NO_FATAL_FAILURE(open(mEffect));
Shunkai Yaocb0fc412022-12-15 20:34:32 +0000210 ASSERT_NO_FATAL_FAILURE(close(mEffect));
211 ASSERT_NO_FATAL_FAILURE(destroy(mFactory, mEffect));
Shunkai Yaoea24c1a2022-09-28 17:39:23 +0000212}
213
214// An effect instance is in PROCESSING state after it receive an START command.
Shunkai Yaoa4ab38c2022-10-14 01:07:47 +0000215TEST_P(AudioEffectTest, ProcessingStateAfterStart) {
Shunkai Yaocb0fc412022-12-15 20:34:32 +0000216 ASSERT_NO_FATAL_FAILURE(create(mFactory, mEffect, mDescriptor));
Shunkai Yaocb0fc412022-12-15 20:34:32 +0000217 ASSERT_NO_FATAL_FAILURE(open(mEffect));
Shunkai Yaocb0fc412022-12-15 20:34:32 +0000218 ASSERT_NO_FATAL_FAILURE(command(mEffect, CommandId::START));
Shunkai Yaocb0fc412022-12-15 20:34:32 +0000219 ASSERT_NO_FATAL_FAILURE(command(mEffect, CommandId::STOP));
220 ASSERT_NO_FATAL_FAILURE(close(mEffect));
221 ASSERT_NO_FATAL_FAILURE(destroy(mFactory, mEffect));
Shunkai Yaoea24c1a2022-09-28 17:39:23 +0000222}
223
224// An effect instance transfer to IDLE state after Command.Id.STOP in PROCESSING state.
Shunkai Yaoa4ab38c2022-10-14 01:07:47 +0000225TEST_P(AudioEffectTest, IdleStateAfterStop) {
Shunkai Yaocb0fc412022-12-15 20:34:32 +0000226 ASSERT_NO_FATAL_FAILURE(create(mFactory, mEffect, mDescriptor));
227 ASSERT_NO_FATAL_FAILURE(open(mEffect));
228 ASSERT_NO_FATAL_FAILURE(command(mEffect, CommandId::START));
Shunkai Yaocb0fc412022-12-15 20:34:32 +0000229 ASSERT_NO_FATAL_FAILURE(command(mEffect, CommandId::STOP));
Shunkai Yaocb0fc412022-12-15 20:34:32 +0000230 ASSERT_NO_FATAL_FAILURE(close(mEffect));
231 ASSERT_NO_FATAL_FAILURE(destroy(mFactory, mEffect));
Shunkai Yaoea24c1a2022-09-28 17:39:23 +0000232}
233
234// An effect instance transfer to IDLE state after Command.Id.RESET in PROCESSING state.
Shunkai Yaoa4ab38c2022-10-14 01:07:47 +0000235TEST_P(AudioEffectTest, IdleStateAfterReset) {
Shunkai Yaocb0fc412022-12-15 20:34:32 +0000236 ASSERT_NO_FATAL_FAILURE(create(mFactory, mEffect, mDescriptor));
237 ASSERT_NO_FATAL_FAILURE(open(mEffect));
238 ASSERT_NO_FATAL_FAILURE(command(mEffect, CommandId::START));
Shunkai Yaocb0fc412022-12-15 20:34:32 +0000239 ASSERT_NO_FATAL_FAILURE(command(mEffect, CommandId::RESET));
Shunkai Yaocb0fc412022-12-15 20:34:32 +0000240 ASSERT_NO_FATAL_FAILURE(close(mEffect));
241 ASSERT_NO_FATAL_FAILURE(destroy(mFactory, mEffect));
Shunkai Yaoea24c1a2022-09-28 17:39:23 +0000242}
243
Shunkai Yao812d5b42022-11-16 18:08:50 +0000244// An effect instance transfer to INIT after IEffect.ASSERT_NO_FATAL_FAILURE(close().
Shunkai Yaoa4ab38c2022-10-14 01:07:47 +0000245TEST_P(AudioEffectTest, InitStateAfterClose) {
Shunkai Yaocb0fc412022-12-15 20:34:32 +0000246 ASSERT_NO_FATAL_FAILURE(create(mFactory, mEffect, mDescriptor));
247 ASSERT_NO_FATAL_FAILURE(open(mEffect));
248 ASSERT_NO_FATAL_FAILURE(command(mEffect, CommandId::START));
249 ASSERT_NO_FATAL_FAILURE(command(mEffect, CommandId::STOP));
250 ASSERT_NO_FATAL_FAILURE(close(mEffect));
Shunkai Yaocb0fc412022-12-15 20:34:32 +0000251 ASSERT_NO_FATAL_FAILURE(destroy(mFactory, mEffect));
Shunkai Yaoea24c1a2022-09-28 17:39:23 +0000252}
253
254// An effect instance shouldn't accept any command before open.
Shunkai Yaoa4ab38c2022-10-14 01:07:47 +0000255TEST_P(AudioEffectTest, NoCommandAcceptedBeforeOpen) {
Shunkai Yaocb0fc412022-12-15 20:34:32 +0000256 ASSERT_NO_FATAL_FAILURE(create(mFactory, mEffect, mDescriptor));
257 ASSERT_NO_FATAL_FAILURE(command(mEffect, CommandId::START, EX_ILLEGAL_STATE));
258 ASSERT_NO_FATAL_FAILURE(command(mEffect, CommandId::STOP, EX_ILLEGAL_STATE));
259 ASSERT_NO_FATAL_FAILURE(command(mEffect, CommandId::RESET, EX_ILLEGAL_STATE));
260 ASSERT_NO_FATAL_FAILURE(destroy(mFactory, mEffect));
Shunkai Yaoea24c1a2022-09-28 17:39:23 +0000261}
262
263// No-op when receive STOP command in IDLE state.
Shunkai Yaoa4ab38c2022-10-14 01:07:47 +0000264TEST_P(AudioEffectTest, StopCommandInIdleStateNoOp) {
Shunkai Yaocb0fc412022-12-15 20:34:32 +0000265 ASSERT_NO_FATAL_FAILURE(create(mFactory, mEffect, mDescriptor));
266 ASSERT_NO_FATAL_FAILURE(open(mEffect));
Shunkai Yaocb0fc412022-12-15 20:34:32 +0000267 ASSERT_NO_FATAL_FAILURE(command(mEffect, CommandId::STOP));
Shunkai Yaocb0fc412022-12-15 20:34:32 +0000268 ASSERT_NO_FATAL_FAILURE(close(mEffect));
269 ASSERT_NO_FATAL_FAILURE(destroy(mFactory, mEffect));
Shunkai Yaoea24c1a2022-09-28 17:39:23 +0000270}
271
Shunkai Yao812d5b42022-11-16 18:08:50 +0000272// No-op when receive RESET command in IDLE state.
Shunkai Yaoa4ab38c2022-10-14 01:07:47 +0000273TEST_P(AudioEffectTest, ResetCommandInIdleStateNoOp) {
Shunkai Yaocb0fc412022-12-15 20:34:32 +0000274 ASSERT_NO_FATAL_FAILURE(create(mFactory, mEffect, mDescriptor));
275 ASSERT_NO_FATAL_FAILURE(open(mEffect));
Shunkai Yaocb0fc412022-12-15 20:34:32 +0000276 ASSERT_NO_FATAL_FAILURE(command(mEffect, CommandId::RESET));
Shunkai Yaocb0fc412022-12-15 20:34:32 +0000277 ASSERT_NO_FATAL_FAILURE(close(mEffect));
278 ASSERT_NO_FATAL_FAILURE(destroy(mFactory, mEffect));
Shunkai Yaoea24c1a2022-09-28 17:39:23 +0000279}
280
281// Repeat START and STOP command.
Shunkai Yaoa4ab38c2022-10-14 01:07:47 +0000282TEST_P(AudioEffectTest, RepeatStartAndStop) {
Shunkai Yaocb0fc412022-12-15 20:34:32 +0000283 ASSERT_NO_FATAL_FAILURE(create(mFactory, mEffect, mDescriptor));
284 ASSERT_NO_FATAL_FAILURE(open(mEffect));
Shunkai Yaocb0fc412022-12-15 20:34:32 +0000285 ASSERT_NO_FATAL_FAILURE(command(mEffect, CommandId::START));
Shunkai Yaocb0fc412022-12-15 20:34:32 +0000286 ASSERT_NO_FATAL_FAILURE(command(mEffect, CommandId::STOP));
Shunkai Yao812d5b42022-11-16 18:08:50 +0000287
Shunkai Yaocb0fc412022-12-15 20:34:32 +0000288 ASSERT_NO_FATAL_FAILURE(command(mEffect, CommandId::START));
Shunkai Yaocb0fc412022-12-15 20:34:32 +0000289 ASSERT_NO_FATAL_FAILURE(command(mEffect, CommandId::STOP));
Shunkai Yaocb0fc412022-12-15 20:34:32 +0000290 ASSERT_NO_FATAL_FAILURE(close(mEffect));
291 ASSERT_NO_FATAL_FAILURE(destroy(mFactory, mEffect));
Shunkai Yaoea24c1a2022-09-28 17:39:23 +0000292}
293
294// Repeat START and RESET command.
Shunkai Yaoa4ab38c2022-10-14 01:07:47 +0000295TEST_P(AudioEffectTest, RepeatStartAndReset) {
Shunkai Yaocb0fc412022-12-15 20:34:32 +0000296 ASSERT_NO_FATAL_FAILURE(create(mFactory, mEffect, mDescriptor));
297 ASSERT_NO_FATAL_FAILURE(open(mEffect));
Shunkai Yaocb0fc412022-12-15 20:34:32 +0000298 ASSERT_NO_FATAL_FAILURE(command(mEffect, CommandId::START));
Shunkai Yaocb0fc412022-12-15 20:34:32 +0000299 ASSERT_NO_FATAL_FAILURE(command(mEffect, CommandId::RESET));
Shunkai Yaocb0fc412022-12-15 20:34:32 +0000300 ASSERT_NO_FATAL_FAILURE(command(mEffect, CommandId::START));
Shunkai Yaocb0fc412022-12-15 20:34:32 +0000301 ASSERT_NO_FATAL_FAILURE(command(mEffect, CommandId::RESET));
Shunkai Yaocb0fc412022-12-15 20:34:32 +0000302 ASSERT_NO_FATAL_FAILURE(close(mEffect));
303 ASSERT_NO_FATAL_FAILURE(destroy(mFactory, mEffect));
Shunkai Yaoea24c1a2022-09-28 17:39:23 +0000304}
305
Shunkai Yao812d5b42022-11-16 18:08:50 +0000306// Try to close an effect instance at PROCESSING state.
Shunkai Yaoa4ab38c2022-10-14 01:07:47 +0000307TEST_P(AudioEffectTest, CloseProcessingStateEffects) {
Shunkai Yaocb0fc412022-12-15 20:34:32 +0000308 ASSERT_NO_FATAL_FAILURE(create(mFactory, mEffect, mDescriptor));
309 ASSERT_NO_FATAL_FAILURE(open(mEffect));
Shunkai Yaocb0fc412022-12-15 20:34:32 +0000310 ASSERT_NO_FATAL_FAILURE(command(mEffect, CommandId::START));
Shunkai Yao812d5b42022-11-16 18:08:50 +0000311
Shunkai Yaocb0fc412022-12-15 20:34:32 +0000312 ASSERT_NO_FATAL_FAILURE(close(mEffect, EX_ILLEGAL_STATE));
Shunkai Yao812d5b42022-11-16 18:08:50 +0000313
Shunkai Yaocb0fc412022-12-15 20:34:32 +0000314 ASSERT_NO_FATAL_FAILURE(command(mEffect, CommandId::STOP));
Shunkai Yaocb0fc412022-12-15 20:34:32 +0000315 ASSERT_NO_FATAL_FAILURE(close(mEffect));
316 ASSERT_NO_FATAL_FAILURE(destroy(mFactory, mEffect));
Shunkai Yaoea24c1a2022-09-28 17:39:23 +0000317}
318
319// Expect EX_ILLEGAL_STATE if the effect instance is not in a proper state to be destroyed.
Shunkai Yaoa4ab38c2022-10-14 01:07:47 +0000320TEST_P(AudioEffectTest, DestroyOpenEffects) {
Shunkai Yaocb0fc412022-12-15 20:34:32 +0000321 ASSERT_NO_FATAL_FAILURE(create(mFactory, mEffect, mDescriptor));
322 ASSERT_NO_FATAL_FAILURE(open(mEffect));
Shunkai Yaocb0fc412022-12-15 20:34:32 +0000323 ASSERT_NO_FATAL_FAILURE(destroy(mFactory, mEffect, EX_ILLEGAL_STATE));
324
325 // cleanup
326 ASSERT_NO_FATAL_FAILURE(close(mEffect));
327 ASSERT_NO_FATAL_FAILURE(destroy(mFactory, mEffect));
Shunkai Yao812d5b42022-11-16 18:08:50 +0000328}
329
330// Expect EX_ILLEGAL_STATE if the effect instance is not in a proper state to be destroyed.
331TEST_P(AudioEffectTest, DestroyProcessingEffects) {
Shunkai Yaocb0fc412022-12-15 20:34:32 +0000332 ASSERT_NO_FATAL_FAILURE(create(mFactory, mEffect, mDescriptor));
333 ASSERT_NO_FATAL_FAILURE(open(mEffect));
Shunkai Yaocb0fc412022-12-15 20:34:32 +0000334 ASSERT_NO_FATAL_FAILURE(command(mEffect, CommandId::START));
Shunkai Yaocb0fc412022-12-15 20:34:32 +0000335 ASSERT_NO_FATAL_FAILURE(destroy(mFactory, mEffect, EX_ILLEGAL_STATE));
336
337 // cleanup
338 ASSERT_NO_FATAL_FAILURE(command(mEffect, CommandId::STOP));
Shunkai Yaocb0fc412022-12-15 20:34:32 +0000339 ASSERT_NO_FATAL_FAILURE(close(mEffect));
340 ASSERT_NO_FATAL_FAILURE(destroy(mFactory, mEffect));
Shunkai Yao812d5b42022-11-16 18:08:50 +0000341}
342
343TEST_P(AudioEffectTest, NormalSequenceStates) {
Shunkai Yaocb0fc412022-12-15 20:34:32 +0000344 ASSERT_NO_FATAL_FAILURE(create(mFactory, mEffect, mDescriptor));
Shunkai Yaocb0fc412022-12-15 20:34:32 +0000345 ASSERT_NO_FATAL_FAILURE(open(mEffect));
Shunkai Yaocb0fc412022-12-15 20:34:32 +0000346 ASSERT_NO_FATAL_FAILURE(command(mEffect, CommandId::START));
Shunkai Yaocb0fc412022-12-15 20:34:32 +0000347 ASSERT_NO_FATAL_FAILURE(command(mEffect, CommandId::STOP));
Shunkai Yaocb0fc412022-12-15 20:34:32 +0000348 ASSERT_NO_FATAL_FAILURE(command(mEffect, CommandId::START));
Shunkai Yaocb0fc412022-12-15 20:34:32 +0000349 ASSERT_NO_FATAL_FAILURE(command(mEffect, CommandId::RESET));
Shunkai Yaocb0fc412022-12-15 20:34:32 +0000350 ASSERT_NO_FATAL_FAILURE(close(mEffect));
351 ASSERT_NO_FATAL_FAILURE(destroy(mFactory, mEffect));
Shunkai Yaoea24c1a2022-09-28 17:39:23 +0000352}
353
354/// Parameter testing.
355// Verify parameters pass in open can be successfully get.
Shunkai Yao812d5b42022-11-16 18:08:50 +0000356TEST_P(AudioEffectTest, VerifyCommonParametersAfterOpen) {
Shunkai Yaocb0fc412022-12-15 20:34:32 +0000357 ASSERT_NO_FATAL_FAILURE(create(mFactory, mEffect, mDescriptor));
Shunkai Yao812d5b42022-11-16 18:08:50 +0000358
Shunkai Yao61f9dd22024-05-08 22:34:36 +0000359 Parameter::Common common = createParamCommon();
Shunkai Yao812d5b42022-11-16 18:08:50 +0000360 IEffect::OpenEffectReturn ret;
Shunkai Yaocb0fc412022-12-15 20:34:32 +0000361 ASSERT_NO_FATAL_FAILURE(open(mEffect, common, std::nullopt /* specific */, &ret, EX_NONE));
Shunkai Yao812d5b42022-11-16 18:08:50 +0000362
363 Parameter get = Parameter(), expect = Parameter();
364 expect.set<Parameter::common>(common);
365 Parameter::Id id;
366 id.set<Parameter::Id::commonTag>(Parameter::common);
Shunkai Yaocb0fc412022-12-15 20:34:32 +0000367 EXPECT_IS_OK(mEffect->getParameter(id, &get));
Shunkai Yaoeea19942023-02-16 02:31:24 +0000368 EXPECT_EQ(expect, get) << expect.toString() << "\n vs \n" << get.toString();
Shunkai Yao812d5b42022-11-16 18:08:50 +0000369
Shunkai Yaocb0fc412022-12-15 20:34:32 +0000370 ASSERT_NO_FATAL_FAILURE(close(mEffect));
371 ASSERT_NO_FATAL_FAILURE(destroy(mFactory, mEffect));
Shunkai Yaoea24c1a2022-09-28 17:39:23 +0000372}
373
374// Verify parameters pass in set can be successfully get.
Shunkai Yao812d5b42022-11-16 18:08:50 +0000375TEST_P(AudioEffectTest, SetAndGetCommonParameter) {
Shunkai Yaocb0fc412022-12-15 20:34:32 +0000376 ASSERT_NO_FATAL_FAILURE(create(mFactory, mEffect, mDescriptor));
377 ASSERT_NO_FATAL_FAILURE(open(mEffect));
Shunkai Yao812d5b42022-11-16 18:08:50 +0000378
Shunkai Yao61f9dd22024-05-08 22:34:36 +0000379 Parameter::Common common = createParamCommon(0 /* session */, 1 /* ioHandle */,
380 44100 /* iSampleRate */, 44100 /* oSampleRate */);
Shunkai Yao5df4e6c2023-01-10 03:20:00 +0000381 Parameter::Id id = Parameter::Id::make<Parameter::Id::commonTag>(Parameter::common);
382 ASSERT_NO_FATAL_FAILURE(setAndGetParameter(id, Parameter::make<Parameter::common>(common)));
Shunkai Yao812d5b42022-11-16 18:08:50 +0000383
Shunkai Yaocb0fc412022-12-15 20:34:32 +0000384 ASSERT_NO_FATAL_FAILURE(close(mEffect));
385 ASSERT_NO_FATAL_FAILURE(destroy(mFactory, mEffect));
Shunkai Yaoea24c1a2022-09-28 17:39:23 +0000386}
387
Shunkai Yao812d5b42022-11-16 18:08:50 +0000388// Verify parameters set and get in PROCESSING state.
Shunkai Yaoa4ab38c2022-10-14 01:07:47 +0000389TEST_P(AudioEffectTest, SetAndGetParameterInProcessing) {
Shunkai Yaocb0fc412022-12-15 20:34:32 +0000390 ASSERT_NO_FATAL_FAILURE(create(mFactory, mEffect, mDescriptor));
391 ASSERT_NO_FATAL_FAILURE(open(mEffect));
392 ASSERT_NO_FATAL_FAILURE(command(mEffect, CommandId::START));
Shunkai Yao812d5b42022-11-16 18:08:50 +0000393
Shunkai Yao61f9dd22024-05-08 22:34:36 +0000394 Parameter::Common common = createParamCommon(0 /* session */, 1 /* ioHandle */,
395 44100 /* iSampleRate */, 44100 /* oSampleRate */);
Shunkai Yao5df4e6c2023-01-10 03:20:00 +0000396 Parameter::Id id = Parameter::Id::make<Parameter::Id::commonTag>(Parameter::common);
397 ASSERT_NO_FATAL_FAILURE(setAndGetParameter(id, Parameter::make<Parameter::common>(common)));
Shunkai Yao812d5b42022-11-16 18:08:50 +0000398
Shunkai Yaocb0fc412022-12-15 20:34:32 +0000399 ASSERT_NO_FATAL_FAILURE(command(mEffect, CommandId::STOP));
400 ASSERT_NO_FATAL_FAILURE(close(mEffect));
401 ASSERT_NO_FATAL_FAILURE(destroy(mFactory, mEffect));
Shunkai Yaoea24c1a2022-09-28 17:39:23 +0000402}
403
Shunkai Yao812d5b42022-11-16 18:08:50 +0000404// Verify parameters set and get in IDLE state.
405TEST_P(AudioEffectTest, SetAndGetParameterInIdle) {
Shunkai Yaocb0fc412022-12-15 20:34:32 +0000406 ASSERT_NO_FATAL_FAILURE(create(mFactory, mEffect, mDescriptor));
407 ASSERT_NO_FATAL_FAILURE(open(mEffect));
408 ASSERT_NO_FATAL_FAILURE(command(mEffect, CommandId::START));
Shunkai Yaocb0fc412022-12-15 20:34:32 +0000409 ASSERT_NO_FATAL_FAILURE(command(mEffect, CommandId::STOP));
Shunkai Yao812d5b42022-11-16 18:08:50 +0000410
Shunkai Yao61f9dd22024-05-08 22:34:36 +0000411 Parameter::Common common = createParamCommon(0 /* session */, 1 /* ioHandle */,
412 44100 /* iSampleRate */, 44100 /* oSampleRate */);
Shunkai Yao5df4e6c2023-01-10 03:20:00 +0000413 Parameter::Id id = Parameter::Id::make<Parameter::Id::commonTag>(Parameter::common);
414 ASSERT_NO_FATAL_FAILURE(setAndGetParameter(id, Parameter::make<Parameter::common>(common)));
Shunkai Yao812d5b42022-11-16 18:08:50 +0000415
Shunkai Yaocb0fc412022-12-15 20:34:32 +0000416 ASSERT_NO_FATAL_FAILURE(close(mEffect));
417 ASSERT_NO_FATAL_FAILURE(destroy(mFactory, mEffect));
Shunkai Yaoea24c1a2022-09-28 17:39:23 +0000418}
419
Shunkai Yao812d5b42022-11-16 18:08:50 +0000420// Verify Parameters kept after stop.
421TEST_P(AudioEffectTest, SetAndGetParameterAfterStop) {
Shunkai Yaocb0fc412022-12-15 20:34:32 +0000422 ASSERT_NO_FATAL_FAILURE(create(mFactory, mEffect, mDescriptor));
423 ASSERT_NO_FATAL_FAILURE(open(mEffect));
424 ASSERT_NO_FATAL_FAILURE(command(mEffect, CommandId::START));
Shunkai Yaoea24c1a2022-09-28 17:39:23 +0000425
Shunkai Yao61f9dd22024-05-08 22:34:36 +0000426 Parameter::Common common = createParamCommon(0 /* session */, 1 /* ioHandle */,
427 44100 /* iSampleRate */, 44100 /* oSampleRate */);
Shunkai Yao5df4e6c2023-01-10 03:20:00 +0000428 Parameter::Id id = Parameter::Id::make<Parameter::Id::commonTag>(Parameter::common);
429 ASSERT_NO_FATAL_FAILURE(setAndGetParameter(id, Parameter::make<Parameter::common>(common)));
Shunkai Yaoa4ab38c2022-10-14 01:07:47 +0000430
Shunkai Yaocb0fc412022-12-15 20:34:32 +0000431 ASSERT_NO_FATAL_FAILURE(command(mEffect, CommandId::STOP));
Shunkai Yaocb0fc412022-12-15 20:34:32 +0000432 ASSERT_NO_FATAL_FAILURE(close(mEffect));
433 ASSERT_NO_FATAL_FAILURE(destroy(mFactory, mEffect));
Shunkai Yaoa4ab38c2022-10-14 01:07:47 +0000434}
435
Shunkai Yao812d5b42022-11-16 18:08:50 +0000436// Verify Parameters kept after reset.
437TEST_P(AudioEffectTest, SetAndGetParameterAfterReset) {
Shunkai Yaocb0fc412022-12-15 20:34:32 +0000438 ASSERT_NO_FATAL_FAILURE(create(mFactory, mEffect, mDescriptor));
439 ASSERT_NO_FATAL_FAILURE(open(mEffect));
Shunkai Yao812d5b42022-11-16 18:08:50 +0000440
Shunkai Yaocb0fc412022-12-15 20:34:32 +0000441 ASSERT_NO_FATAL_FAILURE(command(mEffect, CommandId::START));
Shunkai Yao812d5b42022-11-16 18:08:50 +0000442
Shunkai Yao61f9dd22024-05-08 22:34:36 +0000443 Parameter::Common common = createParamCommon(0 /* session */, 1 /* ioHandle */,
444 44100 /* iSampleRate */, 44100 /* oSampleRate */);
Shunkai Yao5df4e6c2023-01-10 03:20:00 +0000445 Parameter::Id id = Parameter::Id::make<Parameter::Id::commonTag>(Parameter::common);
446 ASSERT_NO_FATAL_FAILURE(setAndGetParameter(id, Parameter::make<Parameter::common>(common)));
Shunkai Yao812d5b42022-11-16 18:08:50 +0000447
Shunkai Yaocb0fc412022-12-15 20:34:32 +0000448 ASSERT_NO_FATAL_FAILURE(command(mEffect, CommandId::RESET));
Shunkai Yao812d5b42022-11-16 18:08:50 +0000449
Shunkai Yao5df4e6c2023-01-10 03:20:00 +0000450 ASSERT_NO_FATAL_FAILURE(setAndGetParameter(id, Parameter::make<Parameter::common>(common)));
Shunkai Yao812d5b42022-11-16 18:08:50 +0000451
Shunkai Yao5df4e6c2023-01-10 03:20:00 +0000452 ASSERT_NO_FATAL_FAILURE(command(mEffect, CommandId::STOP));
Shunkai Yaocb0fc412022-12-15 20:34:32 +0000453 ASSERT_NO_FATAL_FAILURE(close(mEffect));
454 ASSERT_NO_FATAL_FAILURE(destroy(mFactory, mEffect));
Shunkai Yao812d5b42022-11-16 18:08:50 +0000455}
Shunkai Yao5df4e6c2023-01-10 03:20:00 +0000456
457// Set and get AudioDeviceDescription in Parameter
458TEST_P(AudioEffectTest, SetAndGetParameterDeviceDescription) {
Shunkai Yao92cd7482023-09-18 17:37:45 +0000459 if (!mDescriptor.common.flags.deviceIndication) {
460 GTEST_SKIP() << "Skipping test as effect does not support deviceIndication"
461 << mDescriptor.common.flags.toString();
462 }
463
Shunkai Yao5df4e6c2023-01-10 03:20:00 +0000464 ASSERT_NO_FATAL_FAILURE(create(mFactory, mEffect, mDescriptor));
465 ASSERT_NO_FATAL_FAILURE(open(mEffect));
Shunkai Yao5df4e6c2023-01-10 03:20:00 +0000466 ASSERT_NO_FATAL_FAILURE(command(mEffect, CommandId::START));
Shunkai Yao5df4e6c2023-01-10 03:20:00 +0000467
468 std::vector<AudioDeviceDescription> deviceDescs = {
469 {.type = AudioDeviceType::IN_DEFAULT,
470 .connection = AudioDeviceDescription::CONNECTION_ANALOG},
471 {.type = AudioDeviceType::IN_DEVICE,
472 .connection = AudioDeviceDescription::CONNECTION_BT_A2DP}};
473 Parameter::Id id = Parameter::Id::make<Parameter::Id::commonTag>(Parameter::deviceDescription);
474 ASSERT_NO_FATAL_FAILURE(
475 setAndGetParameter(id, Parameter::make<Parameter::deviceDescription>(deviceDescs)));
476
477 ASSERT_NO_FATAL_FAILURE(command(mEffect, CommandId::STOP));
Shunkai Yao5df4e6c2023-01-10 03:20:00 +0000478 ASSERT_NO_FATAL_FAILURE(close(mEffect));
479 ASSERT_NO_FATAL_FAILURE(destroy(mFactory, mEffect));
480}
481
482// Set and get AudioMode in Parameter
483TEST_P(AudioEffectTest, SetAndGetParameterAudioMode) {
Shunkai Yao92cd7482023-09-18 17:37:45 +0000484 if (!mDescriptor.common.flags.audioModeIndication) {
485 GTEST_SKIP() << "Skipping test as effect does not support audioModeIndication"
486 << mDescriptor.common.flags.toString();
487 }
488
Shunkai Yao5df4e6c2023-01-10 03:20:00 +0000489 ASSERT_NO_FATAL_FAILURE(create(mFactory, mEffect, mDescriptor));
490 ASSERT_NO_FATAL_FAILURE(open(mEffect));
491
492 ASSERT_NO_FATAL_FAILURE(command(mEffect, CommandId::START));
Shunkai Yao5df4e6c2023-01-10 03:20:00 +0000493
494 Parameter::Id id = Parameter::Id::make<Parameter::Id::commonTag>(Parameter::mode);
495 ASSERT_NO_FATAL_FAILURE(
496 setAndGetParameter(id, Parameter::make<Parameter::mode>(AudioMode::NORMAL)));
497 ASSERT_NO_FATAL_FAILURE(
498 setAndGetParameter(id, Parameter::make<Parameter::mode>(AudioMode::IN_COMMUNICATION)));
499
500 ASSERT_NO_FATAL_FAILURE(command(mEffect, CommandId::STOP));
Shunkai Yao5df4e6c2023-01-10 03:20:00 +0000501 ASSERT_NO_FATAL_FAILURE(close(mEffect));
502 ASSERT_NO_FATAL_FAILURE(destroy(mFactory, mEffect));
503}
504
505// Set and get AudioSource in Parameter
506TEST_P(AudioEffectTest, SetAndGetParameterAudioSource) {
Shunkai Yao92cd7482023-09-18 17:37:45 +0000507 if (!mDescriptor.common.flags.audioSourceIndication) {
508 GTEST_SKIP() << "Skipping test as effect does not support audioSourceIndication"
509 << mDescriptor.common.flags.toString();
510 }
511
Shunkai Yao5df4e6c2023-01-10 03:20:00 +0000512 ASSERT_NO_FATAL_FAILURE(create(mFactory, mEffect, mDescriptor));
513 ASSERT_NO_FATAL_FAILURE(open(mEffect));
Shunkai Yao5df4e6c2023-01-10 03:20:00 +0000514 ASSERT_NO_FATAL_FAILURE(command(mEffect, CommandId::START));
Shunkai Yao5df4e6c2023-01-10 03:20:00 +0000515
516 Parameter::Id id = Parameter::Id::make<Parameter::Id::commonTag>(Parameter::source);
517 ASSERT_NO_FATAL_FAILURE(
518 setAndGetParameter(id, Parameter::make<Parameter::source>(AudioSource::DEFAULT)));
519 ASSERT_NO_FATAL_FAILURE(setAndGetParameter(
520 id, Parameter::make<Parameter::source>(AudioSource::VOICE_RECOGNITION)));
521
522 ASSERT_NO_FATAL_FAILURE(command(mEffect, CommandId::STOP));
Shunkai Yao5df4e6c2023-01-10 03:20:00 +0000523 ASSERT_NO_FATAL_FAILURE(close(mEffect));
524 ASSERT_NO_FATAL_FAILURE(destroy(mFactory, mEffect));
525}
526
527// Set and get VolumeStereo in Parameter
528TEST_P(AudioEffectTest, SetAndGetParameterVolume) {
Shunkai Yao92cd7482023-09-18 17:37:45 +0000529 if (mDescriptor.common.flags.volume == Flags::Volume::NONE) {
530 GTEST_SKIP() << "Skipping test as effect does not support volume"
531 << mDescriptor.common.flags.toString();
532 }
533
Shunkai Yao5df4e6c2023-01-10 03:20:00 +0000534 ASSERT_NO_FATAL_FAILURE(create(mFactory, mEffect, mDescriptor));
535 ASSERT_NO_FATAL_FAILURE(open(mEffect));
Shunkai Yao5df4e6c2023-01-10 03:20:00 +0000536 ASSERT_NO_FATAL_FAILURE(command(mEffect, CommandId::START));
Shunkai Yao5df4e6c2023-01-10 03:20:00 +0000537
538 Parameter::Id id = Parameter::Id::make<Parameter::Id::commonTag>(Parameter::volumeStereo);
539 Parameter::VolumeStereo volume = {.left = 10.0, .right = 10.0};
David Li1a56fdd2023-11-14 23:31:53 +0800540 if (mDescriptor.common.flags.volume == Flags::Volume::CTRL) {
541 Parameter get;
542 EXPECT_IS_OK(mEffect->setParameter(volume));
543 EXPECT_IS_OK(mEffect->getParameter(id, &get));
544 } else {
545 ASSERT_NO_FATAL_FAILURE(
546 setAndGetParameter(id, Parameter::make<Parameter::volumeStereo>(volume)));
547 }
Shunkai Yao5df4e6c2023-01-10 03:20:00 +0000548
549 ASSERT_NO_FATAL_FAILURE(command(mEffect, CommandId::STOP));
Shunkai Yao5df4e6c2023-01-10 03:20:00 +0000550 ASSERT_NO_FATAL_FAILURE(close(mEffect));
551 ASSERT_NO_FATAL_FAILURE(destroy(mFactory, mEffect));
552}
553
Shunkai Yaod685aed2024-01-30 18:27:38 +0000554/**
555 * Verify DataMqUpdateEventFlag after common parameter setting.
556 * verify reopen sequence.
557 */
558TEST_P(AudioEffectDataPathTest, SetCommonParameterAndReopen) {
Shunkai Yao9f9fe922024-03-04 21:23:04 +0000559 if (!EffectFactoryHelper::isReopenSupported(mFactory)) {
560 GTEST_SKIP() << "Skipping test as effect does not support reopen";
561 }
562
Shunkai Yao65c7c702024-01-09 20:50:53 +0000563 ASSERT_NO_FATAL_FAILURE(create(mFactory, mEffect, mDescriptor));
564
Shunkai Yao61f9dd22024-05-08 22:34:36 +0000565 Parameter::Common common = createParamCommon(
Shunkai Yao65c7c702024-01-09 20:50:53 +0000566 0 /* session */, 1 /* ioHandle */, 44100 /* iSampleRate */, 44100 /* oSampleRate */,
567 kInputFrameCount /* iFrameCount */, kOutputFrameCount /* oFrameCount */);
568 IEffect::OpenEffectReturn ret;
569 ASSERT_NO_FATAL_FAILURE(open(mEffect, common, std::nullopt /* specific */, &ret, EX_NONE));
570 auto statusMQ = std::make_unique<EffectHelper::StatusMQ>(ret.statusMQ);
571 ASSERT_TRUE(statusMQ->isValid());
572 auto inputMQ = std::make_unique<EffectHelper::DataMQ>(ret.inputDataMQ);
573 ASSERT_TRUE(inputMQ->isValid());
574 auto outputMQ = std::make_unique<EffectHelper::DataMQ>(ret.outputDataMQ);
575 ASSERT_TRUE(outputMQ->isValid());
576
577 Parameter::Id id = Parameter::Id::make<Parameter::Id::commonTag>(Parameter::common);
578 common.input.frameCount++;
579 ASSERT_NO_FATAL_FAILURE(setAndGetParameter(id, Parameter::make<Parameter::common>(common)));
580 ASSERT_TRUE(statusMQ->isValid());
581 expectDataMqUpdateEventFlag(statusMQ);
Shunkai Yao28aff3d2024-06-15 03:16:06 +0000582 ASSERT_NO_FATAL_FAILURE(reopen(mEffect, common, &ret));
Shunkai Yao65c7c702024-01-09 20:50:53 +0000583 inputMQ = std::make_unique<EffectHelper::DataMQ>(ret.inputDataMQ);
584 outputMQ = std::make_unique<EffectHelper::DataMQ>(ret.outputDataMQ);
585 ASSERT_TRUE(statusMQ->isValid());
586 ASSERT_TRUE(inputMQ->isValid());
587 ASSERT_TRUE(outputMQ->isValid());
588
589 common.output.frameCount++;
590 ASSERT_NO_FATAL_FAILURE(setAndGetParameter(id, Parameter::make<Parameter::common>(common)));
591 ASSERT_TRUE(statusMQ->isValid());
592 expectDataMqUpdateEventFlag(statusMQ);
Shunkai Yao28aff3d2024-06-15 03:16:06 +0000593 ASSERT_NO_FATAL_FAILURE(reopen(mEffect, common, &ret));
Shunkai Yao65c7c702024-01-09 20:50:53 +0000594 inputMQ = std::make_unique<EffectHelper::DataMQ>(ret.inputDataMQ);
595 outputMQ = std::make_unique<EffectHelper::DataMQ>(ret.outputDataMQ);
596 ASSERT_TRUE(statusMQ->isValid());
597 ASSERT_TRUE(inputMQ->isValid());
598 ASSERT_TRUE(outputMQ->isValid());
599
600 ASSERT_NO_FATAL_FAILURE(close(mEffect));
601 ASSERT_NO_FATAL_FAILURE(destroy(mFactory, mEffect));
602}
603
Shunkai Yao812d5b42022-11-16 18:08:50 +0000604/// Data processing test
605// Send data to effects and expect it to be consumed by checking statusMQ.
Jaideep Sharmacba42862023-06-23 10:27:39 +0530606// Effects exposing bypass flags or operating in offload mode will be skipped.
607TEST_P(AudioEffectDataPathTest, ConsumeDataInProcessingState) {
Shunkai Yaocb0fc412022-12-15 20:34:32 +0000608 ASSERT_NO_FATAL_FAILURE(create(mFactory, mEffect, mDescriptor));
Shunkai Yao812d5b42022-11-16 18:08:50 +0000609
Shunkai Yao61f9dd22024-05-08 22:34:36 +0000610 Parameter::Common common = createParamCommon(
Shunkai Yao812d5b42022-11-16 18:08:50 +0000611 0 /* session */, 1 /* ioHandle */, 44100 /* iSampleRate */, 44100 /* oSampleRate */,
612 kInputFrameCount /* iFrameCount */, kOutputFrameCount /* oFrameCount */);
613 IEffect::OpenEffectReturn ret;
Shunkai Yaocb0fc412022-12-15 20:34:32 +0000614 ASSERT_NO_FATAL_FAILURE(open(mEffect, common, std::nullopt /* specific */, &ret, EX_NONE));
Shunkai Yao28aff3d2024-06-15 03:16:06 +0000615 std::vector<float> inputBuffer(mInputSamples), outputBuffer(mOutputSamples);
616 ASSERT_NO_FATAL_FAILURE(
617 processAndWriteToOutput(inputBuffer, outputBuffer, mEffect, &ret, mVersion));
Shunkai Yaocb0fc412022-12-15 20:34:32 +0000618 ASSERT_NO_FATAL_FAILURE(close(mEffect));
619 ASSERT_NO_FATAL_FAILURE(destroy(mFactory, mEffect));
Shunkai Yao812d5b42022-11-16 18:08:50 +0000620}
621
622// Send data to effects and expect it to be consumed after effect restart.
Jaideep Sharmacba42862023-06-23 10:27:39 +0530623// Effects exposing bypass flags or operating in offload mode will be skipped.
624TEST_P(AudioEffectDataPathTest, ConsumeDataAfterRestart) {
Shunkai Yaocb0fc412022-12-15 20:34:32 +0000625 ASSERT_NO_FATAL_FAILURE(create(mFactory, mEffect, mDescriptor));
Shunkai Yao812d5b42022-11-16 18:08:50 +0000626
Shunkai Yao61f9dd22024-05-08 22:34:36 +0000627 Parameter::Common common = createParamCommon(
Shunkai Yao812d5b42022-11-16 18:08:50 +0000628 0 /* session */, 1 /* ioHandle */, 44100 /* iSampleRate */, 44100 /* oSampleRate */,
629 kInputFrameCount /* iFrameCount */, kOutputFrameCount /* oFrameCount */);
630 IEffect::OpenEffectReturn ret;
Shunkai Yaocb0fc412022-12-15 20:34:32 +0000631 ASSERT_NO_FATAL_FAILURE(open(mEffect, common, std::nullopt /* specific */, &ret, EX_NONE));
Shunkai Yao812d5b42022-11-16 18:08:50 +0000632
Shunkai Yao28aff3d2024-06-15 03:16:06 +0000633 std::vector<float> inputBuffer(mInputSamples), outputBuffer(mOutputSamples);
634 ASSERT_NO_FATAL_FAILURE(
635 processAndWriteToOutput(inputBuffer, outputBuffer, mEffect, &ret, mVersion));
636 ASSERT_NO_FATAL_FAILURE(
637 processAndWriteToOutput(inputBuffer, outputBuffer, mEffect, &ret, mVersion));
Shunkai Yao812d5b42022-11-16 18:08:50 +0000638
Shunkai Yaocb0fc412022-12-15 20:34:32 +0000639 ASSERT_NO_FATAL_FAILURE(close(mEffect));
640 ASSERT_NO_FATAL_FAILURE(destroy(mFactory, mEffect));
Shunkai Yao812d5b42022-11-16 18:08:50 +0000641}
642
Shunkai Yao65c7c702024-01-09 20:50:53 +0000643// Send data to effects and expect it to be consumed after effect reopen (IO AudioConfig change).
644// Effects exposing bypass flags or operating in offload mode will be skipped.
645TEST_P(AudioEffectDataPathTest, ConsumeDataAfterReopen) {
Shunkai Yao9f9fe922024-03-04 21:23:04 +0000646 if (!EffectFactoryHelper::isReopenSupported(mFactory)) {
647 GTEST_SKIP() << "Skipping test as effect does not support reopen";
648 }
649
Shunkai Yao65c7c702024-01-09 20:50:53 +0000650 ASSERT_NO_FATAL_FAILURE(create(mFactory, mEffect, mDescriptor));
651
Shunkai Yao61f9dd22024-05-08 22:34:36 +0000652 Parameter::Common common = createParamCommon(
Shunkai Yao65c7c702024-01-09 20:50:53 +0000653 0 /* session */, 1 /* ioHandle */, 44100 /* iSampleRate */, 44100 /* oSampleRate */,
654 kInputFrameCount /* iFrameCount */, kOutputFrameCount /* oFrameCount */);
655 IEffect::OpenEffectReturn ret;
656 ASSERT_NO_FATAL_FAILURE(open(mEffect, common, std::nullopt /* specific */, &ret, EX_NONE));
657 auto statusMQ = std::make_unique<EffectHelper::StatusMQ>(ret.statusMQ);
658 ASSERT_TRUE(statusMQ->isValid());
Shunkai Yao65c7c702024-01-09 20:50:53 +0000659
Shunkai Yao28aff3d2024-06-15 03:16:06 +0000660 std::vector<float> inputBuffer(mInputSamples), outputBuffer(mOutputSamples);
661 ASSERT_NO_FATAL_FAILURE(
662 processAndWriteToOutput(inputBuffer, outputBuffer, mEffect, &ret, mVersion));
Shunkai Yao65c7c702024-01-09 20:50:53 +0000663
664 // set a new common parameter with different IO frameCount, reopen
665 Parameter::Id id = Parameter::Id::make<Parameter::Id::commonTag>(Parameter::common);
666 common.input.frameCount += 4;
667 common.output.frameCount += 4;
668 ASSERT_NO_FATAL_FAILURE(setAndGetParameter(id, Parameter::make<Parameter::common>(common)));
669 ASSERT_TRUE(statusMQ->isValid());
670 expectDataMqUpdateEventFlag(statusMQ);
Shunkai Yao28aff3d2024-06-15 03:16:06 +0000671 ASSERT_NO_FATAL_FAILURE(reopen(mEffect, common, &ret));
Shunkai Yao65c7c702024-01-09 20:50:53 +0000672
Shunkai Yao28aff3d2024-06-15 03:16:06 +0000673 inputBuffer.resize(mInputSamples);
674 outputBuffer.resize(mOutputSamples);
675 ASSERT_NO_FATAL_FAILURE(
676 processAndWriteToOutput(inputBuffer, outputBuffer, mEffect, &ret, mVersion));
Shunkai Yao65c7c702024-01-09 20:50:53 +0000677
678 ASSERT_NO_FATAL_FAILURE(close(mEffect));
679 ASSERT_NO_FATAL_FAILURE(destroy(mFactory, mEffect));
680}
681
Shunkai Yao812d5b42022-11-16 18:08:50 +0000682// Send data to IDLE effects and expect it to be consumed after effect start.
Jaideep Sharmacba42862023-06-23 10:27:39 +0530683// Effects exposing bypass flags or operating in offload mode will be skipped.
684TEST_P(AudioEffectDataPathTest, SendDataAtIdleAndConsumeDataInProcessing) {
Shunkai Yaocb0fc412022-12-15 20:34:32 +0000685 ASSERT_NO_FATAL_FAILURE(create(mFactory, mEffect, mDescriptor));
Shunkai Yao812d5b42022-11-16 18:08:50 +0000686
Shunkai Yao61f9dd22024-05-08 22:34:36 +0000687 Parameter::Common common = createParamCommon(
Shunkai Yao812d5b42022-11-16 18:08:50 +0000688 0 /* session */, 1 /* ioHandle */, 44100 /* iSampleRate */, 44100 /* oSampleRate */,
689 kInputFrameCount /* iFrameCount */, kOutputFrameCount /* oFrameCount */);
690 IEffect::OpenEffectReturn ret;
Shunkai Yaocb0fc412022-12-15 20:34:32 +0000691 ASSERT_NO_FATAL_FAILURE(open(mEffect, common, std::nullopt /* specific */, &ret, EX_NONE));
Shunkai Yao812d5b42022-11-16 18:08:50 +0000692 auto statusMQ = std::make_unique<EffectHelper::StatusMQ>(ret.statusMQ);
Shunkai Yaocb0fc412022-12-15 20:34:32 +0000693 ASSERT_TRUE(statusMQ->isValid());
Shunkai Yao812d5b42022-11-16 18:08:50 +0000694 auto inputMQ = std::make_unique<EffectHelper::DataMQ>(ret.inputDataMQ);
Shunkai Yaocb0fc412022-12-15 20:34:32 +0000695 ASSERT_TRUE(inputMQ->isValid());
Shunkai Yao812d5b42022-11-16 18:08:50 +0000696 auto outputMQ = std::make_unique<EffectHelper::DataMQ>(ret.outputDataMQ);
Shunkai Yaocb0fc412022-12-15 20:34:32 +0000697 ASSERT_TRUE(outputMQ->isValid());
Shunkai Yao812d5b42022-11-16 18:08:50 +0000698
Shunkai Yao28aff3d2024-06-15 03:16:06 +0000699 std::vector<float> inputBuffer(mInputSamples), outputBuffer(mOutputSamples);
700 ASSERT_NO_FATAL_FAILURE(
701 processAndWriteToOutput(inputBuffer, outputBuffer, mEffect, &ret, mVersion));
Shunkai Yao812d5b42022-11-16 18:08:50 +0000702
Shunkai Yao28aff3d2024-06-15 03:16:06 +0000703 EXPECT_NO_FATAL_FAILURE(EffectHelper::writeToFmq(statusMQ, inputMQ, inputBuffer, mVersion));
Shunkai Yaocb0fc412022-12-15 20:34:32 +0000704 ASSERT_NO_FATAL_FAILURE(command(mEffect, CommandId::START));
Shunkai Yaob49631f2023-02-03 01:44:32 +0000705 EXPECT_NO_FATAL_FAILURE(
Shunkai Yao28aff3d2024-06-15 03:16:06 +0000706 EffectHelper::readFromFmq(statusMQ, 1, outputMQ, outputBuffer.size(), outputBuffer));
Shunkai Yaocb0fc412022-12-15 20:34:32 +0000707 ASSERT_NO_FATAL_FAILURE(command(mEffect, CommandId::STOP));
Shunkai Yaocb0fc412022-12-15 20:34:32 +0000708 ASSERT_NO_FATAL_FAILURE(close(mEffect));
709 ASSERT_NO_FATAL_FAILURE(destroy(mFactory, mEffect));
Shunkai Yao812d5b42022-11-16 18:08:50 +0000710}
711
712// Send data multiple times.
Jaideep Sharmacba42862023-06-23 10:27:39 +0530713// Effects exposing bypass flags or operating in offload mode will be skipped.
714TEST_P(AudioEffectDataPathTest, ProcessDataMultipleTimes) {
Shunkai Yaocb0fc412022-12-15 20:34:32 +0000715 ASSERT_NO_FATAL_FAILURE(create(mFactory, mEffect, mDescriptor));
Shunkai Yao812d5b42022-11-16 18:08:50 +0000716
Shunkai Yao61f9dd22024-05-08 22:34:36 +0000717 Parameter::Common common = createParamCommon(
Shunkai Yao812d5b42022-11-16 18:08:50 +0000718 0 /* session */, 1 /* ioHandle */, 44100 /* iSampleRate */, 44100 /* oSampleRate */,
719 kInputFrameCount /* iFrameCount */, kOutputFrameCount /* oFrameCount */);
720 IEffect::OpenEffectReturn ret;
Shunkai Yaocb0fc412022-12-15 20:34:32 +0000721 ASSERT_NO_FATAL_FAILURE(open(mEffect, common, std::nullopt /* specific */, &ret, EX_NONE));
Shunkai Yao28aff3d2024-06-15 03:16:06 +0000722 std::vector<float> inputBuffer(mInputSamples), outputBuffer(mOutputSamples);
Shunkai Yao812d5b42022-11-16 18:08:50 +0000723
Shunkai Yao28aff3d2024-06-15 03:16:06 +0000724 ASSERT_NO_FATAL_FAILURE(
725 processAndWriteToOutput(inputBuffer, outputBuffer, mEffect, &ret, mVersion, 2));
Shunkai Yao812d5b42022-11-16 18:08:50 +0000726
Shunkai Yaocb0fc412022-12-15 20:34:32 +0000727 ASSERT_NO_FATAL_FAILURE(close(mEffect));
728 ASSERT_NO_FATAL_FAILURE(destroy(mFactory, mEffect));
Shunkai Yao812d5b42022-11-16 18:08:50 +0000729}
730
Shunkai Yaob49631f2023-02-03 01:44:32 +0000731// Send data to processing state effects, stop, and restart.
Jaideep Sharmacba42862023-06-23 10:27:39 +0530732// Effects exposing bypass flags or operating in offload mode will be skipped.
733TEST_P(AudioEffectDataPathTest, ConsumeDataAndRestart) {
Shunkai Yaocb0fc412022-12-15 20:34:32 +0000734 ASSERT_NO_FATAL_FAILURE(create(mFactory, mEffect, mDescriptor));
Shunkai Yao812d5b42022-11-16 18:08:50 +0000735
Shunkai Yao61f9dd22024-05-08 22:34:36 +0000736 Parameter::Common common = createParamCommon(
Shunkai Yao812d5b42022-11-16 18:08:50 +0000737 0 /* session */, 1 /* ioHandle */, 44100 /* iSampleRate */, 44100 /* oSampleRate */,
738 kInputFrameCount /* iFrameCount */, kOutputFrameCount /* oFrameCount */);
739 IEffect::OpenEffectReturn ret;
Shunkai Yaocb0fc412022-12-15 20:34:32 +0000740 ASSERT_NO_FATAL_FAILURE(open(mEffect, common, std::nullopt /* specific */, &ret, EX_NONE));
Shunkai Yao28aff3d2024-06-15 03:16:06 +0000741 std::vector<float> inputBuffer(mInputSamples), outputBuffer(mOutputSamples);
Shunkai Yao812d5b42022-11-16 18:08:50 +0000742
Shunkai Yao28aff3d2024-06-15 03:16:06 +0000743 ASSERT_NO_FATAL_FAILURE(
744 processAndWriteToOutput(inputBuffer, outputBuffer, mEffect, &ret, mVersion, 2));
745 ASSERT_NO_FATAL_FAILURE(
746 processAndWriteToOutput(inputBuffer, outputBuffer, mEffect, &ret, mVersion, 2));
Shunkai Yao812d5b42022-11-16 18:08:50 +0000747
Shunkai Yaocb0fc412022-12-15 20:34:32 +0000748 ASSERT_NO_FATAL_FAILURE(close(mEffect));
749 ASSERT_NO_FATAL_FAILURE(destroy(mFactory, mEffect));
Shunkai Yao812d5b42022-11-16 18:08:50 +0000750}
751
752// Send data to closed effects and expect it not be consumed.
Jaideep Sharmacba42862023-06-23 10:27:39 +0530753// Effects exposing bypass flags or operating in offload mode will be skipped.
754TEST_P(AudioEffectDataPathTest, NotConsumeDataByClosedEffect) {
Shunkai Yaocb0fc412022-12-15 20:34:32 +0000755 ASSERT_NO_FATAL_FAILURE(create(mFactory, mEffect, mDescriptor));
Shunkai Yao812d5b42022-11-16 18:08:50 +0000756
Shunkai Yao61f9dd22024-05-08 22:34:36 +0000757 Parameter::Common common = createParamCommon(
Shunkai Yao812d5b42022-11-16 18:08:50 +0000758 0 /* session */, 1 /* ioHandle */, 44100 /* iSampleRate */, 44100 /* oSampleRate */,
759 kInputFrameCount /* iFrameCount */, kOutputFrameCount /* oFrameCount */);
760 IEffect::OpenEffectReturn ret;
Shunkai Yaocb0fc412022-12-15 20:34:32 +0000761 ASSERT_NO_FATAL_FAILURE(open(mEffect, common, std::nullopt /* specific */, &ret, EX_NONE));
Shunkai Yao28aff3d2024-06-15 03:16:06 +0000762 std::vector<float> inputBuffer(mInputSamples), outputBuffer(mOutputSamples);
Shunkai Yaocb0fc412022-12-15 20:34:32 +0000763 ASSERT_NO_FATAL_FAILURE(close(mEffect));
Shunkai Yao812d5b42022-11-16 18:08:50 +0000764
765 auto statusMQ = std::make_unique<EffectHelper::StatusMQ>(ret.statusMQ);
Shunkai Yaocb0fc412022-12-15 20:34:32 +0000766 ASSERT_TRUE(statusMQ->isValid());
Shunkai Yao812d5b42022-11-16 18:08:50 +0000767 auto inputMQ = std::make_unique<EffectHelper::DataMQ>(ret.inputDataMQ);
Shunkai Yaocb0fc412022-12-15 20:34:32 +0000768 ASSERT_TRUE(inputMQ->isValid());
Shunkai Yao812d5b42022-11-16 18:08:50 +0000769 auto outputMQ = std::make_unique<EffectHelper::DataMQ>(ret.outputDataMQ);
Shunkai Yaocb0fc412022-12-15 20:34:32 +0000770 ASSERT_TRUE(outputMQ->isValid());
Shunkai Yao812d5b42022-11-16 18:08:50 +0000771
Shunkai Yao28aff3d2024-06-15 03:16:06 +0000772 EXPECT_NO_FATAL_FAILURE(EffectHelper::writeToFmq(statusMQ, inputMQ, inputBuffer, mVersion));
773 EXPECT_NO_FATAL_FAILURE(EffectHelper::readFromFmq(statusMQ, 0, outputMQ, 0, outputBuffer));
Shunkai Yao812d5b42022-11-16 18:08:50 +0000774
Shunkai Yaocb0fc412022-12-15 20:34:32 +0000775 ASSERT_NO_FATAL_FAILURE(destroy(mFactory, mEffect));
Shunkai Yao812d5b42022-11-16 18:08:50 +0000776}
777
778// Send data to multiple effects.
Jaideep Sharmacba42862023-06-23 10:27:39 +0530779// Effects exposing bypass flags or operating in offload mode will be skipped.
780TEST_P(AudioEffectDataPathTest, ConsumeDataMultipleEffects) {
Shunkai Yao812d5b42022-11-16 18:08:50 +0000781 std::shared_ptr<IEffect> effect1, effect2;
Shunkai Yaocb0fc412022-12-15 20:34:32 +0000782 ASSERT_NO_FATAL_FAILURE(create(mFactory, effect1, mDescriptor));
783 ASSERT_NO_FATAL_FAILURE(create(mFactory, effect2, mDescriptor));
Shunkai Yao812d5b42022-11-16 18:08:50 +0000784
Shunkai Yao61f9dd22024-05-08 22:34:36 +0000785 Parameter::Common common1 = createParamCommon(
Shunkai Yao812d5b42022-11-16 18:08:50 +0000786 0 /* session */, 1 /* ioHandle */, 44100 /* iSampleRate */, 44100 /* oSampleRate */,
787 kInputFrameCount /* iFrameCount */, kOutputFrameCount /* oFrameCount */);
Shunkai Yao61f9dd22024-05-08 22:34:36 +0000788 Parameter::Common common2 = createParamCommon(
Shunkai Yao812d5b42022-11-16 18:08:50 +0000789 1 /* session */, 1 /* ioHandle */, 48000 /* iSampleRate */, 48000 /* oSampleRate */,
790 2 * kInputFrameCount /* iFrameCount */, 2 * kOutputFrameCount /* oFrameCount */);
791 IEffect::OpenEffectReturn ret1, ret2;
792 ASSERT_NO_FATAL_FAILURE(open(effect1, common1, std::nullopt /* specific */, &ret1, EX_NONE));
793 ASSERT_NO_FATAL_FAILURE(open(effect2, common2, std::nullopt /* specific */, &ret2, EX_NONE));
Shunkai Yao28aff3d2024-06-15 03:16:06 +0000794 std::vector<float> inputBuffer1(kInputFrameCount * mInputFrameSize / sizeof(float)),
795 outputBuffer1(kOutputFrameCount * mOutputFrameSize / sizeof(float));
796 std::vector<float> inputBuffer2(2 * kInputFrameCount * mInputFrameSize / sizeof(float)),
797 outputBuffer2(2 * kOutputFrameCount * mOutputFrameSize / sizeof(float));
Shunkai Yao812d5b42022-11-16 18:08:50 +0000798
Shunkai Yao28aff3d2024-06-15 03:16:06 +0000799 ASSERT_NO_FATAL_FAILURE(
800 processAndWriteToOutput(inputBuffer1, outputBuffer1, effect1, &ret1, mVersion, 2));
801 ASSERT_NO_FATAL_FAILURE(
802 processAndWriteToOutput(inputBuffer2, outputBuffer2, effect2, &ret2, mVersion, 2));
Shunkai Yao812d5b42022-11-16 18:08:50 +0000803
Shunkai Yao812d5b42022-11-16 18:08:50 +0000804 ASSERT_NO_FATAL_FAILURE(close(effect1));
805 ASSERT_NO_FATAL_FAILURE(destroy(mFactory, effect1));
806
Shunkai Yao812d5b42022-11-16 18:08:50 +0000807 ASSERT_NO_FATAL_FAILURE(close(effect2));
808 ASSERT_NO_FATAL_FAILURE(destroy(mFactory, effect2));
809}
810
811INSTANTIATE_TEST_SUITE_P(
812 SingleEffectInstanceTest, AudioEffectTest,
813 ::testing::Combine(testing::ValuesIn(
814 EffectFactoryHelper::getAllEffectDescriptors(IFactory::descriptor))),
815 [](const testing::TestParamInfo<AudioEffectTest::ParamType>& info) {
Shunkai Yaocb0fc412022-12-15 20:34:32 +0000816 auto descriptor = std::get<PARAM_INSTANCE_NAME>(info.param).second;
Jaideep Sharmae4c7a962023-06-14 19:14:44 +0530817 std::string name = getPrefix(descriptor);
Shunkai Yao812d5b42022-11-16 18:08:50 +0000818 std::replace_if(
819 name.begin(), name.end(), [](const char c) { return !std::isalnum(c); }, '_');
820 return name;
821 });
Shunkai Yaoa4ab38c2022-10-14 01:07:47 +0000822GTEST_ALLOW_UNINSTANTIATED_PARAMETERIZED_TEST(AudioEffectTest);
Shunkai Yao67b1be62022-07-13 05:01:42 +0000823
Jaideep Sharmacba42862023-06-23 10:27:39 +0530824INSTANTIATE_TEST_SUITE_P(
825 SingleEffectInstanceTest, AudioEffectDataPathTest,
826 ::testing::Combine(testing::ValuesIn(
827 EffectFactoryHelper::getAllEffectDescriptors(IFactory::descriptor))),
828 [](const testing::TestParamInfo<AudioEffectDataPathTest::ParamType>& info) {
829 auto descriptor = std::get<PARAM_INSTANCE_NAME>(info.param).second;
830 std::string name = getPrefix(descriptor);
831 std::replace_if(
832 name.begin(), name.end(), [](const char c) { return !std::isalnum(c); }, '_');
833 return name;
834 });
835
836GTEST_ALLOW_UNINSTANTIATED_PARAMETERIZED_TEST(AudioEffectDataPathTest);
837
Shunkai Yao67b1be62022-07-13 05:01:42 +0000838int main(int argc, char** argv) {
839 ::testing::InitGoogleTest(&argc, argv);
Jaideep Sharma74498412023-09-13 15:25:25 +0530840 ::testing::UnitTest::GetInstance()->listeners().Append(new TestExecutionTracer());
Shunkai Yao67b1be62022-07-13 05:01:42 +0000841 ABinderProcess_setThreadPoolMaxThreadCount(1);
842 ABinderProcess_startThreadPool();
843 return RUN_ALL_TESTS();
Shunkai Yaoa4ab38c2022-10-14 01:07:47 +0000844}