blob: 4f14bf0b07a1cbdcf02b152cc612da93cc09bd50 [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 Yao812d5b42022-11-16 18:08:50 +000019#include <chrono>
Shunkai Yao45905172022-08-24 18:14:02 +000020#include <memory>
Shunkai Yao67b1be62022-07-13 05:01:42 +000021#include <string>
Shunkai Yao45905172022-08-24 18:14:02 +000022#include <vector>
Shunkai Yao67b1be62022-07-13 05:01:42 +000023
Shunkai Yao812d5b42022-11-16 18:08:50 +000024#include <Utils.h>
Shunkai Yao67b1be62022-07-13 05:01:42 +000025#include <aidl/Gtest.h>
26#include <aidl/Vintf.h>
Shunkai Yao812d5b42022-11-16 18:08:50 +000027#include <aidl/android/hardware/audio/effect/IEffect.h>
28#include <aidl/android/hardware/audio/effect/IFactory.h>
Shunkai Yao67b1be62022-07-13 05:01:42 +000029#include <android-base/logging.h>
Shunkai Yao67b1be62022-07-13 05:01:42 +000030#include <android/binder_interface_utils.h>
31#include <android/binder_manager.h>
32#include <android/binder_process.h>
Shunkai Yao812d5b42022-11-16 18:08:50 +000033#include <fmq/AidlMessageQueue.h>
Shunkai Yao67b1be62022-07-13 05:01:42 +000034
35#include "AudioHalBinderServiceUtil.h"
Shunkai Yao812d5b42022-11-16 18:08:50 +000036#include "EffectFactoryHelper.h"
Shunkai Yaoa4ab38c2022-10-14 01:07:47 +000037#include "EffectHelper.h"
Shunkai Yao121c6dd2022-09-21 23:42:08 +000038#include "TestUtils.h"
Shunkai Yao67b1be62022-07-13 05:01:42 +000039
40using namespace android;
41
42using ndk::ScopedAStatus;
43
Shunkai Yaoea24c1a2022-09-28 17:39:23 +000044using aidl::android::hardware::audio::effect::CommandId;
Shunkai Yao67b1be62022-07-13 05:01:42 +000045using aidl::android::hardware::audio::effect::Descriptor;
Shunkai Yao45905172022-08-24 18:14:02 +000046using aidl::android::hardware::audio::effect::IEffect;
Shunkai Yao67b1be62022-07-13 05:01:42 +000047using aidl::android::hardware::audio::effect::IFactory;
Shunkai Yaoea24c1a2022-09-28 17:39:23 +000048using aidl::android::hardware::audio::effect::Parameter;
49using aidl::android::hardware::audio::effect::State;
Shunkai Yao67b1be62022-07-13 05:01:42 +000050
Shunkai Yao812d5b42022-11-16 18:08:50 +000051enum ParamName { PARAM_INSTANCE_NAME };
52using EffectTestParam = std::tuple<std::pair<std::shared_ptr<IFactory>, Descriptor::Identity>>;
53
54class AudioEffectTest : public testing::TestWithParam<EffectTestParam>, public EffectHelper {
Shunkai Yao45905172022-08-24 18:14:02 +000055 public:
Shunkai Yao812d5b42022-11-16 18:08:50 +000056 AudioEffectTest() { std::tie(mFactory, mIdentity) = std::get<PARAM_INSTANCE_NAME>(GetParam()); }
Shunkai Yaoa4ab38c2022-10-14 01:07:47 +000057
Shunkai Yao812d5b42022-11-16 18:08:50 +000058 void SetUp() override {}
59 void TearDown() override {}
Shunkai Yao45905172022-08-24 18:14:02 +000060
Shunkai Yao812d5b42022-11-16 18:08:50 +000061 static const long kInputFrameCount = 0x100, kOutputFrameCount = 0x100;
62 std::shared_ptr<IFactory> mFactory;
63 Descriptor::Identity mIdentity;
Shunkai Yao45905172022-08-24 18:14:02 +000064};
65
Shunkai Yao812d5b42022-11-16 18:08:50 +000066TEST_P(AudioEffectTest, SetupAndTearDown) {
67 // Intentionally empty test body.
Shunkai Yao45905172022-08-24 18:14:02 +000068}
69
Shunkai Yao812d5b42022-11-16 18:08:50 +000070TEST_P(AudioEffectTest, CreateAndDestroy) {
71 std::shared_ptr<IEffect> effect;
72 ASSERT_NO_FATAL_FAILURE(create(mFactory, effect, mIdentity));
73 ASSERT_NO_FATAL_FAILURE(destroy(mFactory, effect));
Shunkai Yao45905172022-08-24 18:14:02 +000074}
75
Shunkai Yao812d5b42022-11-16 18:08:50 +000076TEST_P(AudioEffectTest, OpenAndClose) {
77 std::shared_ptr<IEffect> effect;
78 ASSERT_NO_FATAL_FAILURE(create(mFactory, effect, mIdentity));
79 ASSERT_NO_FATAL_FAILURE(open(effect));
80 ASSERT_NO_FATAL_FAILURE(close(effect));
81 ASSERT_NO_FATAL_FAILURE(destroy(mFactory, effect));
Shunkai Yao45905172022-08-24 18:14:02 +000082}
83
Shunkai Yao812d5b42022-11-16 18:08:50 +000084TEST_P(AudioEffectTest, CloseUnopenedEffect) {
85 std::shared_ptr<IEffect> effect;
86 ASSERT_NO_FATAL_FAILURE(create(mFactory, effect, mIdentity));
87 ASSERT_NO_FATAL_FAILURE(close(effect));
88 ASSERT_NO_FATAL_FAILURE(destroy(mFactory, effect));
Shunkai Yao45905172022-08-24 18:14:02 +000089}
90
Shunkai Yao812d5b42022-11-16 18:08:50 +000091TEST_P(AudioEffectTest, DoubleOpenAndClose) {
92 std::shared_ptr<IEffect> effect1, effect2;
93 ASSERT_NO_FATAL_FAILURE(create(mFactory, effect1, mIdentity));
94 ASSERT_NO_FATAL_FAILURE(create(mFactory, effect2, mIdentity));
95 ASSERT_NO_FATAL_FAILURE(open(effect1));
96 ASSERT_NO_FATAL_FAILURE(open(effect2, 1 /* session */));
97 ASSERT_NO_FATAL_FAILURE(close(effect1));
98 ASSERT_NO_FATAL_FAILURE(close(effect2));
99 ASSERT_NO_FATAL_FAILURE(destroy(mFactory, effect1));
100 ASSERT_NO_FATAL_FAILURE(destroy(mFactory, effect2));
Shunkai Yao45905172022-08-24 18:14:02 +0000101}
102
Shunkai Yao812d5b42022-11-16 18:08:50 +0000103TEST_P(AudioEffectTest, TripleOpenAndClose) {
104 std::shared_ptr<IEffect> effect1, effect2, effect3;
105 ASSERT_NO_FATAL_FAILURE(create(mFactory, effect1, mIdentity));
106 ASSERT_NO_FATAL_FAILURE(create(mFactory, effect2, mIdentity));
107 ASSERT_NO_FATAL_FAILURE(create(mFactory, effect3, mIdentity));
108 ASSERT_NO_FATAL_FAILURE(open(effect1));
109 ASSERT_NO_FATAL_FAILURE(open(effect2, 1 /* session */));
110 ASSERT_NO_FATAL_FAILURE(open(effect3, 2 /* session */));
111 ASSERT_NO_FATAL_FAILURE(close(effect1));
112 ASSERT_NO_FATAL_FAILURE(close(effect2));
113 ASSERT_NO_FATAL_FAILURE(close(effect3));
114 ASSERT_NO_FATAL_FAILURE(destroy(mFactory, effect1));
115 ASSERT_NO_FATAL_FAILURE(destroy(mFactory, effect2));
116 ASSERT_NO_FATAL_FAILURE(destroy(mFactory, effect3));
117}
Shunkai Yao45905172022-08-24 18:14:02 +0000118
Shunkai Yao812d5b42022-11-16 18:08:50 +0000119TEST_P(AudioEffectTest, GetDescritorBeforeOpen) {
120 std::shared_ptr<IEffect> effect;
121 Descriptor desc;
122 ASSERT_NO_FATAL_FAILURE(create(mFactory, effect, mIdentity));
123 ASSERT_NO_FATAL_FAILURE(getDescriptor(effect, desc));
124 EXPECT_EQ(mIdentity.toString(), desc.common.id.toString());
125 EXPECT_NE("", desc.common.name);
126 EXPECT_NE("", desc.common.implementor);
127 ASSERT_NO_FATAL_FAILURE(destroy(mFactory, effect));
128}
129
130TEST_P(AudioEffectTest, GetDescritorAfterOpen) {
131 std::shared_ptr<IEffect> effect;
132 Descriptor beforeOpen, afterOpen, afterClose;
133 ASSERT_NO_FATAL_FAILURE(create(mFactory, effect, mIdentity));
134 ASSERT_NO_FATAL_FAILURE(getDescriptor(effect, beforeOpen));
135 ASSERT_NO_FATAL_FAILURE(open(effect));
136 ASSERT_NO_FATAL_FAILURE(getDescriptor(effect, afterOpen));
137 EXPECT_EQ(beforeOpen.toString(), afterOpen.toString()) << "\n"
138 << beforeOpen.toString() << "\n"
139 << afterOpen.toString();
140 ASSERT_NO_FATAL_FAILURE(close(effect));
141 ASSERT_NO_FATAL_FAILURE(getDescriptor(effect, afterClose));
142 EXPECT_EQ(beforeOpen.toString(), afterClose.toString()) << "\n"
143 << beforeOpen.toString() << "\n"
144 << afterClose.toString();
145 ASSERT_NO_FATAL_FAILURE(destroy(mFactory, effect));
146}
147
148TEST_P(AudioEffectTest, DescriptorExistAndUnique) {
149 std::shared_ptr<IEffect> effect;
150 Descriptor desc;
151
152 auto descList = EffectFactoryHelper::getAllEffectDescriptors(IFactory::descriptor);
153 std::set<Descriptor::Identity> idSet;
154 for (const auto& it : descList) {
155 auto& id = it.second;
156 EXPECT_EQ(0ul, idSet.count(id));
157 idSet.insert(id);
Shunkai Yao45905172022-08-24 18:14:02 +0000158 }
Shunkai Yao812d5b42022-11-16 18:08:50 +0000159
160 ASSERT_NO_FATAL_FAILURE(create(mFactory, effect, mIdentity));
161 ASSERT_NO_FATAL_FAILURE(getDescriptor(effect, desc));
162 EXPECT_EQ(1ul, idSet.count(desc.common.id));
163 ASSERT_NO_FATAL_FAILURE(destroy(mFactory, effect));
Shunkai Yao45905172022-08-24 18:14:02 +0000164}
165
Shunkai Yaoea24c1a2022-09-28 17:39:23 +0000166/// State testing.
167// An effect instance is in INIT state by default after it was created.
Shunkai Yaoa4ab38c2022-10-14 01:07:47 +0000168TEST_P(AudioEffectTest, InitStateAfterCreation) {
Shunkai Yao812d5b42022-11-16 18:08:50 +0000169 std::shared_ptr<IEffect> effect;
170 ASSERT_NO_FATAL_FAILURE(create(mFactory, effect, mIdentity));
171 ASSERT_NO_FATAL_FAILURE(expectState(effect, State::INIT));
172 ASSERT_NO_FATAL_FAILURE(destroy(mFactory, effect));
Shunkai Yaoea24c1a2022-09-28 17:39:23 +0000173}
174
Shunkai Yao812d5b42022-11-16 18:08:50 +0000175// An effect instance transfer to IDLE state after IEffect.ASSERT_NO_FATAL_FAILURE(open().
Shunkai Yaoa4ab38c2022-10-14 01:07:47 +0000176TEST_P(AudioEffectTest, IdleStateAfterOpen) {
Shunkai Yao812d5b42022-11-16 18:08:50 +0000177 std::shared_ptr<IEffect> effect;
178 ASSERT_NO_FATAL_FAILURE(create(mFactory, effect, mIdentity));
179 ASSERT_NO_FATAL_FAILURE(open(effect));
180 ASSERT_NO_FATAL_FAILURE(expectState(effect, State::IDLE));
181 ASSERT_NO_FATAL_FAILURE(close(effect));
182 ASSERT_NO_FATAL_FAILURE(destroy(mFactory, effect));
Shunkai Yaoea24c1a2022-09-28 17:39:23 +0000183}
184
185// An effect instance is in PROCESSING state after it receive an START command.
Shunkai Yaoa4ab38c2022-10-14 01:07:47 +0000186TEST_P(AudioEffectTest, ProcessingStateAfterStart) {
Shunkai Yao812d5b42022-11-16 18:08:50 +0000187 std::shared_ptr<IEffect> effect;
188 ASSERT_NO_FATAL_FAILURE(create(mFactory, effect, mIdentity));
189 ASSERT_NO_FATAL_FAILURE(expectState(effect, State::INIT));
190 ASSERT_NO_FATAL_FAILURE(open(effect));
191 ASSERT_NO_FATAL_FAILURE(expectState(effect, State::IDLE));
192 ASSERT_NO_FATAL_FAILURE(command(effect, CommandId::START));
193 ASSERT_NO_FATAL_FAILURE(expectState(effect, State::PROCESSING));
194 ASSERT_NO_FATAL_FAILURE(command(effect, CommandId::STOP));
195 ASSERT_NO_FATAL_FAILURE(close(effect));
196 ASSERT_NO_FATAL_FAILURE(destroy(mFactory, effect));
Shunkai Yaoea24c1a2022-09-28 17:39:23 +0000197}
198
199// An effect instance transfer to IDLE state after Command.Id.STOP in PROCESSING state.
Shunkai Yaoa4ab38c2022-10-14 01:07:47 +0000200TEST_P(AudioEffectTest, IdleStateAfterStop) {
Shunkai Yao812d5b42022-11-16 18:08:50 +0000201 std::shared_ptr<IEffect> effect;
202 ASSERT_NO_FATAL_FAILURE(create(mFactory, effect, mIdentity));
203 ASSERT_NO_FATAL_FAILURE(open(effect));
204 ASSERT_NO_FATAL_FAILURE(command(effect, CommandId::START));
205 ASSERT_NO_FATAL_FAILURE(expectState(effect, State::PROCESSING));
206 ASSERT_NO_FATAL_FAILURE(command(effect, CommandId::STOP));
207 ASSERT_NO_FATAL_FAILURE(expectState(effect, State::IDLE));
208 ASSERT_NO_FATAL_FAILURE(close(effect));
209 ASSERT_NO_FATAL_FAILURE(destroy(mFactory, effect));
Shunkai Yaoea24c1a2022-09-28 17:39:23 +0000210}
211
212// An effect instance transfer to IDLE state after Command.Id.RESET in PROCESSING state.
Shunkai Yaoa4ab38c2022-10-14 01:07:47 +0000213TEST_P(AudioEffectTest, IdleStateAfterReset) {
Shunkai Yao812d5b42022-11-16 18:08:50 +0000214 std::shared_ptr<IEffect> effect;
215 ASSERT_NO_FATAL_FAILURE(create(mFactory, effect, mIdentity));
216 ASSERT_NO_FATAL_FAILURE(open(effect));
217 ASSERT_NO_FATAL_FAILURE(command(effect, CommandId::START));
218 ASSERT_NO_FATAL_FAILURE(expectState(effect, State::PROCESSING));
219 ASSERT_NO_FATAL_FAILURE(command(effect, CommandId::RESET));
220 ASSERT_NO_FATAL_FAILURE(expectState(effect, State::IDLE));
221 ASSERT_NO_FATAL_FAILURE(close(effect));
222 ASSERT_NO_FATAL_FAILURE(destroy(mFactory, effect));
Shunkai Yaoea24c1a2022-09-28 17:39:23 +0000223}
224
Shunkai Yao812d5b42022-11-16 18:08:50 +0000225// An effect instance transfer to INIT after IEffect.ASSERT_NO_FATAL_FAILURE(close().
Shunkai Yaoa4ab38c2022-10-14 01:07:47 +0000226TEST_P(AudioEffectTest, InitStateAfterClose) {
Shunkai Yao812d5b42022-11-16 18:08:50 +0000227 std::shared_ptr<IEffect> effect;
228 ASSERT_NO_FATAL_FAILURE(create(mFactory, effect, mIdentity));
229 ASSERT_NO_FATAL_FAILURE(open(effect));
230 ASSERT_NO_FATAL_FAILURE(command(effect, CommandId::START));
231 ASSERT_NO_FATAL_FAILURE(command(effect, CommandId::STOP));
232 ASSERT_NO_FATAL_FAILURE(close(effect));
233 ASSERT_NO_FATAL_FAILURE(expectState(effect, State::INIT));
234 ASSERT_NO_FATAL_FAILURE(destroy(mFactory, effect));
Shunkai Yaoea24c1a2022-09-28 17:39:23 +0000235}
236
237// An effect instance shouldn't accept any command before open.
Shunkai Yaoa4ab38c2022-10-14 01:07:47 +0000238TEST_P(AudioEffectTest, NoCommandAcceptedBeforeOpen) {
Shunkai Yao812d5b42022-11-16 18:08:50 +0000239 std::shared_ptr<IEffect> effect;
240 ASSERT_NO_FATAL_FAILURE(create(mFactory, effect, mIdentity));
241 ASSERT_NO_FATAL_FAILURE(command(effect, CommandId::START, EX_ILLEGAL_STATE));
242 ASSERT_NO_FATAL_FAILURE(command(effect, CommandId::STOP, EX_ILLEGAL_STATE));
243 ASSERT_NO_FATAL_FAILURE(command(effect, CommandId::RESET, EX_ILLEGAL_STATE));
244 ASSERT_NO_FATAL_FAILURE(open(effect));
245 ASSERT_NO_FATAL_FAILURE(close(effect));
246 ASSERT_NO_FATAL_FAILURE(destroy(mFactory, effect));
Shunkai Yaoea24c1a2022-09-28 17:39:23 +0000247}
248
249// No-op when receive STOP command in IDLE state.
Shunkai Yaoa4ab38c2022-10-14 01:07:47 +0000250TEST_P(AudioEffectTest, StopCommandInIdleStateNoOp) {
Shunkai Yao812d5b42022-11-16 18:08:50 +0000251 std::shared_ptr<IEffect> effect;
252 ASSERT_NO_FATAL_FAILURE(create(mFactory, effect, mIdentity));
253 ASSERT_NO_FATAL_FAILURE(open(effect));
254 ASSERT_NO_FATAL_FAILURE(expectState(effect, State::IDLE));
255 ASSERT_NO_FATAL_FAILURE(command(effect, CommandId::STOP));
256 ASSERT_NO_FATAL_FAILURE(expectState(effect, State::IDLE));
257 ASSERT_NO_FATAL_FAILURE(close(effect));
258 ASSERT_NO_FATAL_FAILURE(destroy(mFactory, effect));
Shunkai Yaoea24c1a2022-09-28 17:39:23 +0000259}
260
Shunkai Yao812d5b42022-11-16 18:08:50 +0000261// No-op when receive RESET command in IDLE state.
Shunkai Yaoa4ab38c2022-10-14 01:07:47 +0000262TEST_P(AudioEffectTest, ResetCommandInIdleStateNoOp) {
Shunkai Yao812d5b42022-11-16 18:08:50 +0000263 std::shared_ptr<IEffect> effect;
264 ASSERT_NO_FATAL_FAILURE(create(mFactory, effect, mIdentity));
265 ASSERT_NO_FATAL_FAILURE(open(effect));
266 ASSERT_NO_FATAL_FAILURE(expectState(effect, State::IDLE));
267 ASSERT_NO_FATAL_FAILURE(command(effect, CommandId::RESET));
268 ASSERT_NO_FATAL_FAILURE(expectState(effect, State::IDLE));
269 ASSERT_NO_FATAL_FAILURE(close(effect));
270 ASSERT_NO_FATAL_FAILURE(destroy(mFactory, effect));
Shunkai Yaoea24c1a2022-09-28 17:39:23 +0000271}
272
273// Repeat START and STOP command.
Shunkai Yaoa4ab38c2022-10-14 01:07:47 +0000274TEST_P(AudioEffectTest, RepeatStartAndStop) {
Shunkai Yao812d5b42022-11-16 18:08:50 +0000275 std::shared_ptr<IEffect> effect;
276 ASSERT_NO_FATAL_FAILURE(create(mFactory, effect, mIdentity));
277 ASSERT_NO_FATAL_FAILURE(open(effect));
278 ASSERT_NO_FATAL_FAILURE(expectState(effect, State::IDLE));
279 ASSERT_NO_FATAL_FAILURE(command(effect, CommandId::START));
280 ASSERT_NO_FATAL_FAILURE(expectState(effect, State::PROCESSING));
281 ASSERT_NO_FATAL_FAILURE(command(effect, CommandId::STOP));
282 ASSERT_NO_FATAL_FAILURE(expectState(effect, State::IDLE));
283
284 ASSERT_NO_FATAL_FAILURE(command(effect, CommandId::START));
285 ASSERT_NO_FATAL_FAILURE(expectState(effect, State::PROCESSING));
286 ASSERT_NO_FATAL_FAILURE(command(effect, CommandId::STOP));
287 ASSERT_NO_FATAL_FAILURE(expectState(effect, State::IDLE));
288 ASSERT_NO_FATAL_FAILURE(close(effect));
289 ASSERT_NO_FATAL_FAILURE(destroy(mFactory, effect));
Shunkai Yaoea24c1a2022-09-28 17:39:23 +0000290}
291
292// Repeat START and RESET command.
Shunkai Yaoa4ab38c2022-10-14 01:07:47 +0000293TEST_P(AudioEffectTest, RepeatStartAndReset) {
Shunkai Yao812d5b42022-11-16 18:08:50 +0000294 std::shared_ptr<IEffect> effect;
295 ASSERT_NO_FATAL_FAILURE(create(mFactory, effect, mIdentity));
296 ASSERT_NO_FATAL_FAILURE(open(effect));
297 ASSERT_NO_FATAL_FAILURE(expectState(effect, State::IDLE));
298 ASSERT_NO_FATAL_FAILURE(command(effect, CommandId::START));
299 ASSERT_NO_FATAL_FAILURE(expectState(effect, State::PROCESSING));
300 ASSERT_NO_FATAL_FAILURE(command(effect, CommandId::RESET));
301 ASSERT_NO_FATAL_FAILURE(expectState(effect, State::IDLE));
302
303 ASSERT_NO_FATAL_FAILURE(command(effect, CommandId::START));
304 ASSERT_NO_FATAL_FAILURE(expectState(effect, State::PROCESSING));
305 ASSERT_NO_FATAL_FAILURE(command(effect, CommandId::RESET));
306 ASSERT_NO_FATAL_FAILURE(expectState(effect, State::IDLE));
307 ASSERT_NO_FATAL_FAILURE(close(effect));
308 ASSERT_NO_FATAL_FAILURE(destroy(mFactory, effect));
Shunkai Yaoea24c1a2022-09-28 17:39:23 +0000309}
310
Shunkai Yao812d5b42022-11-16 18:08:50 +0000311// Try to close an effect instance at PROCESSING state.
Shunkai Yaoa4ab38c2022-10-14 01:07:47 +0000312TEST_P(AudioEffectTest, CloseProcessingStateEffects) {
Shunkai Yao812d5b42022-11-16 18:08:50 +0000313 std::shared_ptr<IEffect> effect;
314 ASSERT_NO_FATAL_FAILURE(create(mFactory, effect, mIdentity));
315 ASSERT_NO_FATAL_FAILURE(open(effect));
316 ASSERT_NO_FATAL_FAILURE(expectState(effect, State::IDLE));
317 ASSERT_NO_FATAL_FAILURE(command(effect, CommandId::START));
318 ASSERT_NO_FATAL_FAILURE(expectState(effect, State::PROCESSING));
319
320 ASSERT_NO_FATAL_FAILURE(close(effect, EX_ILLEGAL_STATE));
321
322 ASSERT_NO_FATAL_FAILURE(command(effect, CommandId::STOP));
323 ASSERT_NO_FATAL_FAILURE(expectState(effect, State::IDLE));
324 ASSERT_NO_FATAL_FAILURE(close(effect));
325 ASSERT_NO_FATAL_FAILURE(destroy(mFactory, effect));
Shunkai Yaoea24c1a2022-09-28 17:39:23 +0000326}
327
328// Expect EX_ILLEGAL_STATE if the effect instance is not in a proper state to be destroyed.
Shunkai Yaoa4ab38c2022-10-14 01:07:47 +0000329TEST_P(AudioEffectTest, DestroyOpenEffects) {
Shunkai Yao812d5b42022-11-16 18:08:50 +0000330 std::shared_ptr<IEffect> effect;
331 ASSERT_NO_FATAL_FAILURE(create(mFactory, effect, mIdentity));
332 ASSERT_NO_FATAL_FAILURE(open(effect));
333 ASSERT_NO_FATAL_FAILURE(expectState(effect, State::IDLE));
Shunkai Yaoea24c1a2022-09-28 17:39:23 +0000334
Shunkai Yao812d5b42022-11-16 18:08:50 +0000335 ASSERT_NO_FATAL_FAILURE(destroy(mFactory, effect, EX_ILLEGAL_STATE));
336}
337
338// Expect EX_ILLEGAL_STATE if the effect instance is not in a proper state to be destroyed.
339TEST_P(AudioEffectTest, DestroyProcessingEffects) {
340 std::shared_ptr<IEffect> effect;
341 ASSERT_NO_FATAL_FAILURE(create(mFactory, effect, mIdentity));
342 ASSERT_NO_FATAL_FAILURE(open(effect));
343 ASSERT_NO_FATAL_FAILURE(expectState(effect, State::IDLE));
344 ASSERT_NO_FATAL_FAILURE(command(effect, CommandId::START));
345 ASSERT_NO_FATAL_FAILURE(expectState(effect, State::PROCESSING));
346
347 ASSERT_NO_FATAL_FAILURE(destroy(mFactory, effect, EX_ILLEGAL_STATE));
348}
349
350TEST_P(AudioEffectTest, NormalSequenceStates) {
351 std::shared_ptr<IEffect> effect;
352 ASSERT_NO_FATAL_FAILURE(create(mFactory, effect, mIdentity));
353 ASSERT_NO_FATAL_FAILURE(expectState(effect, State::INIT));
354 ASSERT_NO_FATAL_FAILURE(open(effect));
355 ASSERT_NO_FATAL_FAILURE(expectState(effect, State::IDLE));
356 ASSERT_NO_FATAL_FAILURE(command(effect, CommandId::START));
357 ASSERT_NO_FATAL_FAILURE(expectState(effect, State::PROCESSING));
358 ASSERT_NO_FATAL_FAILURE(command(effect, CommandId::STOP));
359 ASSERT_NO_FATAL_FAILURE(expectState(effect, State::IDLE));
360 ASSERT_NO_FATAL_FAILURE(command(effect, CommandId::START));
361 ASSERT_NO_FATAL_FAILURE(expectState(effect, State::PROCESSING));
362 ASSERT_NO_FATAL_FAILURE(command(effect, CommandId::RESET));
363 ASSERT_NO_FATAL_FAILURE(expectState(effect, State::IDLE));
364 ASSERT_NO_FATAL_FAILURE(close(effect));
365 ASSERT_NO_FATAL_FAILURE(destroy(mFactory, effect));
Shunkai Yaoea24c1a2022-09-28 17:39:23 +0000366}
367
368/// Parameter testing.
369// Verify parameters pass in open can be successfully get.
Shunkai Yao812d5b42022-11-16 18:08:50 +0000370TEST_P(AudioEffectTest, VerifyCommonParametersAfterOpen) {
371 std::shared_ptr<IEffect> effect;
372 ASSERT_NO_FATAL_FAILURE(create(mFactory, effect, mIdentity));
373
374 Parameter::Common common = EffectHelper::createParamCommon();
375 IEffect::OpenEffectReturn ret;
376 ASSERT_NO_FATAL_FAILURE(open(effect, common, std::nullopt /* specific */, &ret, EX_NONE));
377
378 Parameter get = Parameter(), expect = Parameter();
379 expect.set<Parameter::common>(common);
380 Parameter::Id id;
381 id.set<Parameter::Id::commonTag>(Parameter::common);
382 EXPECT_IS_OK(effect->getParameter(id, &get));
383 EXPECT_EQ(expect, get) << expect.toString() << " vs " << get.toString();
384
385 ASSERT_NO_FATAL_FAILURE(close(effect));
386 ASSERT_NO_FATAL_FAILURE(destroy(mFactory, effect));
Shunkai Yaoea24c1a2022-09-28 17:39:23 +0000387}
388
389// Verify parameters pass in set can be successfully get.
Shunkai Yao812d5b42022-11-16 18:08:50 +0000390TEST_P(AudioEffectTest, SetAndGetCommonParameter) {
391 std::shared_ptr<IEffect> effect;
392 ASSERT_NO_FATAL_FAILURE(create(mFactory, effect, mIdentity));
393 ASSERT_NO_FATAL_FAILURE(open(effect));
394
395 Parameter::Common common = EffectHelper::createParamCommon(
396 0 /* session */, 1 /* ioHandle */, 44100 /* iSampleRate */, 44100 /* oSampleRate */);
397 Parameter get = Parameter(), set = Parameter();
398 set.set<Parameter::common>(common);
399 EXPECT_IS_OK(effect->setParameter(set));
400
401 Parameter::Id id;
402 id.set<Parameter::Id::commonTag>(Parameter::common);
403 EXPECT_IS_OK(effect->getParameter(id, &get));
404 EXPECT_EQ(set, get) << set.toString() << " vs " << get.toString();
405
406 ASSERT_NO_FATAL_FAILURE(close(effect));
407 ASSERT_NO_FATAL_FAILURE(destroy(mFactory, effect));
Shunkai Yaoea24c1a2022-09-28 17:39:23 +0000408}
409
Shunkai Yao812d5b42022-11-16 18:08:50 +0000410// Verify parameters set and get in PROCESSING state.
Shunkai Yaoa4ab38c2022-10-14 01:07:47 +0000411TEST_P(AudioEffectTest, SetAndGetParameterInProcessing) {
Shunkai Yao812d5b42022-11-16 18:08:50 +0000412 std::shared_ptr<IEffect> effect;
413 ASSERT_NO_FATAL_FAILURE(create(mFactory, effect, mIdentity));
414 ASSERT_NO_FATAL_FAILURE(open(effect));
415 ASSERT_NO_FATAL_FAILURE(command(effect, CommandId::START));
416 ASSERT_NO_FATAL_FAILURE(expectState(effect, State::PROCESSING));
417
418 Parameter::Common common = EffectHelper::createParamCommon(
419 0 /* session */, 1 /* ioHandle */, 44100 /* iSampleRate */, 44100 /* oSampleRate */);
420 Parameter get = Parameter(), set = Parameter();
421 set.set<Parameter::common>(common);
422 EXPECT_IS_OK(effect->setParameter(set));
423
424 Parameter::Id id;
425 id.set<Parameter::Id::commonTag>(Parameter::common);
426 EXPECT_IS_OK(effect->getParameter(id, &get));
427 EXPECT_EQ(set, get) << set.toString() << " vs " << get.toString();
428
429 ASSERT_NO_FATAL_FAILURE(command(effect, CommandId::STOP));
430 ASSERT_NO_FATAL_FAILURE(close(effect));
431 ASSERT_NO_FATAL_FAILURE(destroy(mFactory, effect));
Shunkai Yaoea24c1a2022-09-28 17:39:23 +0000432}
433
Shunkai Yao812d5b42022-11-16 18:08:50 +0000434// Verify parameters set and get in IDLE state.
435TEST_P(AudioEffectTest, SetAndGetParameterInIdle) {
436 std::shared_ptr<IEffect> effect;
437 ASSERT_NO_FATAL_FAILURE(create(mFactory, effect, mIdentity));
438 ASSERT_NO_FATAL_FAILURE(open(effect));
439 ASSERT_NO_FATAL_FAILURE(command(effect, CommandId::START));
440 ASSERT_NO_FATAL_FAILURE(expectState(effect, State::PROCESSING));
441 ASSERT_NO_FATAL_FAILURE(command(effect, CommandId::STOP));
442 ASSERT_NO_FATAL_FAILURE(expectState(effect, State::IDLE));
443
444 Parameter::Common common = EffectHelper::createParamCommon(
445 0 /* session */, 1 /* ioHandle */, 44100 /* iSampleRate */, 44100 /* oSampleRate */);
446 Parameter get = Parameter(), set = Parameter();
447 set.set<Parameter::common>(common);
448 EXPECT_IS_OK(effect->setParameter(set));
449
450 Parameter::Id id;
451 id.set<Parameter::Id::commonTag>(Parameter::common);
452 EXPECT_IS_OK(effect->getParameter(id, &get));
453 EXPECT_EQ(set, get) << set.toString() << " vs " << get.toString();
454
455 ASSERT_NO_FATAL_FAILURE(close(effect));
456 ASSERT_NO_FATAL_FAILURE(destroy(mFactory, effect));
Shunkai Yaoea24c1a2022-09-28 17:39:23 +0000457}
458
Shunkai Yao812d5b42022-11-16 18:08:50 +0000459// Verify Parameters kept after stop.
460TEST_P(AudioEffectTest, SetAndGetParameterAfterStop) {
461 std::shared_ptr<IEffect> effect;
462 ASSERT_NO_FATAL_FAILURE(create(mFactory, effect, mIdentity));
463 ASSERT_NO_FATAL_FAILURE(open(effect));
464 ASSERT_NO_FATAL_FAILURE(command(effect, CommandId::START));
465 ASSERT_NO_FATAL_FAILURE(expectState(effect, State::PROCESSING));
Shunkai Yaoea24c1a2022-09-28 17:39:23 +0000466
Shunkai Yao812d5b42022-11-16 18:08:50 +0000467 Parameter::Common common = EffectHelper::createParamCommon(
468 0 /* session */, 1 /* ioHandle */, 44100 /* iSampleRate */, 44100 /* oSampleRate */);
469 Parameter get = Parameter(), set = Parameter();
470 set.set<Parameter::common>(common);
471 EXPECT_IS_OK(effect->setParameter(set));
Shunkai Yaoa4ab38c2022-10-14 01:07:47 +0000472
Shunkai Yao812d5b42022-11-16 18:08:50 +0000473 ASSERT_NO_FATAL_FAILURE(command(effect, CommandId::STOP));
474 ASSERT_NO_FATAL_FAILURE(expectState(effect, State::IDLE));
Shunkai Yaoa4ab38c2022-10-14 01:07:47 +0000475
Shunkai Yao812d5b42022-11-16 18:08:50 +0000476 Parameter::Id id;
477 id.set<Parameter::Id::commonTag>(Parameter::common);
478 EXPECT_IS_OK(effect->getParameter(id, &get));
479 EXPECT_EQ(set, get) << set.toString() << " vs " << get.toString();
480
481 ASSERT_NO_FATAL_FAILURE(close(effect));
482 ASSERT_NO_FATAL_FAILURE(destroy(mFactory, effect));
Shunkai Yaoa4ab38c2022-10-14 01:07:47 +0000483}
484
Shunkai Yao812d5b42022-11-16 18:08:50 +0000485// Verify Parameters kept after reset.
486TEST_P(AudioEffectTest, SetAndGetParameterAfterReset) {
487 std::shared_ptr<IEffect> effect;
488 ASSERT_NO_FATAL_FAILURE(create(mFactory, effect, mIdentity));
489 ASSERT_NO_FATAL_FAILURE(open(effect));
490
491 ASSERT_NO_FATAL_FAILURE(command(effect, CommandId::START));
492 ASSERT_NO_FATAL_FAILURE(expectState(effect, State::PROCESSING));
493
494 Parameter::Common common = EffectHelper::createParamCommon(
495 0 /* session */, 1 /* ioHandle */, 44100 /* iSampleRate */, 44100 /* oSampleRate */);
496 Parameter get = Parameter(), set = Parameter();
497 set.set<Parameter::common>(common);
498 EXPECT_IS_OK(effect->setParameter(set));
499
500 ASSERT_NO_FATAL_FAILURE(command(effect, CommandId::RESET));
501 ASSERT_NO_FATAL_FAILURE(expectState(effect, State::IDLE));
502
503 Parameter::Id id;
504 id.set<Parameter::Id::commonTag>(Parameter::common);
505 EXPECT_IS_OK(effect->getParameter(id, &get));
506 EXPECT_EQ(set, get) << set.toString() << " vs " << get.toString();
507
508 ASSERT_NO_FATAL_FAILURE(close(effect));
509 ASSERT_NO_FATAL_FAILURE(destroy(mFactory, effect));
510}
511
512/// Data processing test
513// Send data to effects and expect it to be consumed by checking statusMQ.
514TEST_P(AudioEffectTest, ConsumeDataInProcessingState) {
515 std::shared_ptr<IEffect> effect;
516 ASSERT_NO_FATAL_FAILURE(create(mFactory, effect, mIdentity));
517
518 Parameter::Common common = EffectHelper::createParamCommon(
519 0 /* session */, 1 /* ioHandle */, 44100 /* iSampleRate */, 44100 /* oSampleRate */,
520 kInputFrameCount /* iFrameCount */, kOutputFrameCount /* oFrameCount */);
521 IEffect::OpenEffectReturn ret;
522 ASSERT_NO_FATAL_FAILURE(open(effect, common, std::nullopt /* specific */, &ret, EX_NONE));
523 auto statusMQ = std::make_unique<EffectHelper::StatusMQ>(ret.statusMQ);
524 auto inputMQ = std::make_unique<EffectHelper::DataMQ>(ret.inputDataMQ);
525 auto outputMQ = std::make_unique<EffectHelper::DataMQ>(ret.outputDataMQ);
526
527 ASSERT_NO_FATAL_FAILURE(command(effect, CommandId::START));
528 ASSERT_NO_FATAL_FAILURE(expectState(effect, State::PROCESSING));
529
530 std::vector<float> buffer;
531 EffectHelper::allocateInputData(common, inputMQ, buffer);
532 EffectHelper::writeToFmq(inputMQ, buffer);
533 EffectHelper::readFromFmq(statusMQ, 1, outputMQ, buffer.size(), buffer);
534
535 ASSERT_NO_FATAL_FAILURE(command(effect, CommandId::STOP));
536 ASSERT_NO_FATAL_FAILURE(expectState(effect, State::IDLE));
537
538 ASSERT_NO_FATAL_FAILURE(close(effect));
539 ASSERT_NO_FATAL_FAILURE(destroy(mFactory, effect));
540}
541
542// Send data to effects and expect it to be consumed after effect restart.
543TEST_P(AudioEffectTest, ConsumeDataAfterRestart) {
544 std::shared_ptr<IEffect> effect;
545 ASSERT_NO_FATAL_FAILURE(create(mFactory, effect, mIdentity));
546
547 Parameter::Common common = EffectHelper::createParamCommon(
548 0 /* session */, 1 /* ioHandle */, 44100 /* iSampleRate */, 44100 /* oSampleRate */,
549 kInputFrameCount /* iFrameCount */, kOutputFrameCount /* oFrameCount */);
550 IEffect::OpenEffectReturn ret;
551 ASSERT_NO_FATAL_FAILURE(open(effect, common, std::nullopt /* specific */, &ret, EX_NONE));
552 auto statusMQ = std::make_unique<EffectHelper::StatusMQ>(ret.statusMQ);
553 auto inputMQ = std::make_unique<EffectHelper::DataMQ>(ret.inputDataMQ);
554 auto outputMQ = std::make_unique<EffectHelper::DataMQ>(ret.outputDataMQ);
555
556 ASSERT_NO_FATAL_FAILURE(command(effect, CommandId::START));
557 ASSERT_NO_FATAL_FAILURE(expectState(effect, State::PROCESSING));
558 ASSERT_NO_FATAL_FAILURE(command(effect, CommandId::STOP));
559 ASSERT_NO_FATAL_FAILURE(expectState(effect, State::IDLE));
560 ASSERT_NO_FATAL_FAILURE(command(effect, CommandId::START));
561 ASSERT_NO_FATAL_FAILURE(expectState(effect, State::PROCESSING));
562
563 std::vector<float> buffer;
564 EffectHelper::allocateInputData(common, inputMQ, buffer);
565 EffectHelper::writeToFmq(inputMQ, buffer);
566 EffectHelper::readFromFmq(statusMQ, 1, outputMQ, buffer.size(), buffer);
567
568 ASSERT_NO_FATAL_FAILURE(command(effect, CommandId::STOP));
569 ASSERT_NO_FATAL_FAILURE(expectState(effect, State::IDLE));
570
571 ASSERT_NO_FATAL_FAILURE(close(effect));
572 ASSERT_NO_FATAL_FAILURE(destroy(mFactory, effect));
573}
574
575// Send data to IDLE effects and expect it to be consumed after effect start.
576TEST_P(AudioEffectTest, SendDataAtIdleAndConsumeDataInProcessing) {
577 std::shared_ptr<IEffect> effect;
578 ASSERT_NO_FATAL_FAILURE(create(mFactory, effect, mIdentity));
579
580 Parameter::Common common = EffectHelper::createParamCommon(
581 0 /* session */, 1 /* ioHandle */, 44100 /* iSampleRate */, 44100 /* oSampleRate */,
582 kInputFrameCount /* iFrameCount */, kOutputFrameCount /* oFrameCount */);
583 IEffect::OpenEffectReturn ret;
584 ASSERT_NO_FATAL_FAILURE(open(effect, common, std::nullopt /* specific */, &ret, EX_NONE));
585 auto statusMQ = std::make_unique<EffectHelper::StatusMQ>(ret.statusMQ);
586 auto inputMQ = std::make_unique<EffectHelper::DataMQ>(ret.inputDataMQ);
587 auto outputMQ = std::make_unique<EffectHelper::DataMQ>(ret.outputDataMQ);
588
589 std::vector<float> buffer;
590 EffectHelper::allocateInputData(common, inputMQ, buffer);
591 EffectHelper::writeToFmq(inputMQ, buffer);
592 EffectHelper::readFromFmq(statusMQ, 0, outputMQ, 0, buffer);
593
594 ASSERT_NO_FATAL_FAILURE(command(effect, CommandId::START));
595 ASSERT_NO_FATAL_FAILURE(expectState(effect, State::PROCESSING));
596
597 EffectHelper::readFromFmq(statusMQ, 1, outputMQ, buffer.size(), buffer);
598
599 ASSERT_NO_FATAL_FAILURE(command(effect, CommandId::STOP));
600 ASSERT_NO_FATAL_FAILURE(expectState(effect, State::IDLE));
601
602 ASSERT_NO_FATAL_FAILURE(close(effect));
603 ASSERT_NO_FATAL_FAILURE(destroy(mFactory, effect));
604}
605
606// Send data multiple times.
607TEST_P(AudioEffectTest, ProcessDataMultipleTimes) {
608 std::shared_ptr<IEffect> effect;
609 ASSERT_NO_FATAL_FAILURE(create(mFactory, effect, mIdentity));
610
611 Parameter::Common common = EffectHelper::createParamCommon(
612 0 /* session */, 1 /* ioHandle */, 44100 /* iSampleRate */, 44100 /* oSampleRate */,
613 kInputFrameCount /* iFrameCount */, kOutputFrameCount /* oFrameCount */);
614 IEffect::OpenEffectReturn ret;
615 ASSERT_NO_FATAL_FAILURE(open(effect, common, std::nullopt /* specific */, &ret, EX_NONE));
616 auto statusMQ = std::make_unique<EffectHelper::StatusMQ>(ret.statusMQ);
617 auto inputMQ = std::make_unique<EffectHelper::DataMQ>(ret.inputDataMQ);
618 auto outputMQ = std::make_unique<EffectHelper::DataMQ>(ret.outputDataMQ);
619
620 std::vector<float> buffer;
621 EffectHelper::allocateInputData(common, inputMQ, buffer);
622 EffectHelper::writeToFmq(inputMQ, buffer);
623 EffectHelper::readFromFmq(statusMQ, 0, outputMQ, 0, buffer);
624
625 ASSERT_NO_FATAL_FAILURE(command(effect, CommandId::START));
626 ASSERT_NO_FATAL_FAILURE(expectState(effect, State::PROCESSING));
627
628 EffectHelper::readFromFmq(statusMQ, 1, outputMQ, buffer.size(), buffer);
629 // expect no status and data after consume
630 EffectHelper::readFromFmq(statusMQ, 0, outputMQ, 0, buffer);
631
632 EffectHelper::writeToFmq(inputMQ, buffer);
633 EffectHelper::readFromFmq(statusMQ, 1, outputMQ, buffer.size(), buffer);
634 // expect no status and data after consume
635 EffectHelper::readFromFmq(statusMQ, 0, outputMQ, 0, buffer);
636
637 ASSERT_NO_FATAL_FAILURE(command(effect, CommandId::STOP));
638 ASSERT_NO_FATAL_FAILURE(expectState(effect, State::IDLE));
639
640 ASSERT_NO_FATAL_FAILURE(close(effect));
641 ASSERT_NO_FATAL_FAILURE(destroy(mFactory, effect));
642}
643
644// Send data to IDLE state effects and expect it not be consumed.
645TEST_P(AudioEffectTest, NotConsumeDataInIdleState) {
646 std::shared_ptr<IEffect> effect;
647 ASSERT_NO_FATAL_FAILURE(create(mFactory, effect, mIdentity));
648
649 Parameter::Common common = EffectHelper::createParamCommon(
650 0 /* session */, 1 /* ioHandle */, 44100 /* iSampleRate */, 44100 /* oSampleRate */,
651 kInputFrameCount /* iFrameCount */, kOutputFrameCount /* oFrameCount */);
652 IEffect::OpenEffectReturn ret;
653 ASSERT_NO_FATAL_FAILURE(open(effect, common, std::nullopt /* specific */, &ret, EX_NONE));
654 auto statusMQ = std::make_unique<EffectHelper::StatusMQ>(ret.statusMQ);
655 auto inputMQ = std::make_unique<EffectHelper::DataMQ>(ret.inputDataMQ);
656 auto outputMQ = std::make_unique<EffectHelper::DataMQ>(ret.outputDataMQ);
657
658 ASSERT_NO_FATAL_FAILURE(command(effect, CommandId::START));
659 ASSERT_NO_FATAL_FAILURE(expectState(effect, State::PROCESSING));
660 ASSERT_NO_FATAL_FAILURE(command(effect, CommandId::STOP));
661 ASSERT_NO_FATAL_FAILURE(expectState(effect, State::IDLE));
662
663 std::vector<float> buffer;
664 EffectHelper::allocateInputData(common, inputMQ, buffer);
665 EffectHelper::writeToFmq(inputMQ, buffer);
666 EffectHelper::readFromFmq(statusMQ, 0, outputMQ, 0, buffer);
667
668 ASSERT_NO_FATAL_FAILURE(command(effect, CommandId::START));
669 ASSERT_NO_FATAL_FAILURE(expectState(effect, State::PROCESSING));
670 EffectHelper::readFromFmq(statusMQ, 1, outputMQ, buffer.size(), buffer);
671
672 ASSERT_NO_FATAL_FAILURE(command(effect, CommandId::STOP));
673 ASSERT_NO_FATAL_FAILURE(expectState(effect, State::IDLE));
674
675 ASSERT_NO_FATAL_FAILURE(close(effect));
676 ASSERT_NO_FATAL_FAILURE(destroy(mFactory, effect));
677}
678
679// Send data to closed effects and expect it not be consumed.
680TEST_P(AudioEffectTest, NotConsumeDataByClosedEffect) {
681 std::shared_ptr<IEffect> effect;
682 ASSERT_NO_FATAL_FAILURE(create(mFactory, effect, mIdentity));
683
684 Parameter::Common common = EffectHelper::createParamCommon(
685 0 /* session */, 1 /* ioHandle */, 44100 /* iSampleRate */, 44100 /* oSampleRate */,
686 kInputFrameCount /* iFrameCount */, kOutputFrameCount /* oFrameCount */);
687 IEffect::OpenEffectReturn ret;
688 ASSERT_NO_FATAL_FAILURE(open(effect, common, std::nullopt /* specific */, &ret, EX_NONE));
689 ASSERT_NO_FATAL_FAILURE(close(effect));
690
691 auto statusMQ = std::make_unique<EffectHelper::StatusMQ>(ret.statusMQ);
692 auto inputMQ = std::make_unique<EffectHelper::DataMQ>(ret.inputDataMQ);
693 auto outputMQ = std::make_unique<EffectHelper::DataMQ>(ret.outputDataMQ);
694
695 std::vector<float> buffer;
696 EffectHelper::allocateInputData(common, inputMQ, buffer);
697 EffectHelper::writeToFmq(inputMQ, buffer);
698 EffectHelper::readFromFmq(statusMQ, 0, outputMQ, 0, buffer);
699
700 ASSERT_NO_FATAL_FAILURE(destroy(mFactory, effect));
701}
702
703// Send data to multiple effects.
704TEST_P(AudioEffectTest, ConsumeDataMultipleEffects) {
705 std::shared_ptr<IEffect> effect1, effect2;
706 ASSERT_NO_FATAL_FAILURE(create(mFactory, effect1, mIdentity));
707 ASSERT_NO_FATAL_FAILURE(create(mFactory, effect2, mIdentity));
708
709 Parameter::Common common1 = EffectHelper::createParamCommon(
710 0 /* session */, 1 /* ioHandle */, 44100 /* iSampleRate */, 44100 /* oSampleRate */,
711 kInputFrameCount /* iFrameCount */, kOutputFrameCount /* oFrameCount */);
712 Parameter::Common common2 = EffectHelper::createParamCommon(
713 1 /* session */, 1 /* ioHandle */, 48000 /* iSampleRate */, 48000 /* oSampleRate */,
714 2 * kInputFrameCount /* iFrameCount */, 2 * kOutputFrameCount /* oFrameCount */);
715 IEffect::OpenEffectReturn ret1, ret2;
716 ASSERT_NO_FATAL_FAILURE(open(effect1, common1, std::nullopt /* specific */, &ret1, EX_NONE));
717 ASSERT_NO_FATAL_FAILURE(open(effect2, common2, std::nullopt /* specific */, &ret2, EX_NONE));
718 ASSERT_NO_FATAL_FAILURE(command(effect1, CommandId::START));
719 ASSERT_NO_FATAL_FAILURE(expectState(effect1, State::PROCESSING));
720 ASSERT_NO_FATAL_FAILURE(command(effect2, CommandId::START));
721 ASSERT_NO_FATAL_FAILURE(expectState(effect2, State::PROCESSING));
722
723 auto statusMQ1 = std::make_unique<EffectHelper::StatusMQ>(ret1.statusMQ);
724 auto inputMQ1 = std::make_unique<EffectHelper::DataMQ>(ret1.inputDataMQ);
725 auto outputMQ1 = std::make_unique<EffectHelper::DataMQ>(ret1.outputDataMQ);
726
727 std::vector<float> buffer1, buffer2;
728 EffectHelper::allocateInputData(common1, inputMQ1, buffer1);
729 EffectHelper::writeToFmq(inputMQ1, buffer1);
730 EffectHelper::readFromFmq(statusMQ1, 1, outputMQ1, buffer1.size(), buffer1);
731
732 auto statusMQ2 = std::make_unique<EffectHelper::StatusMQ>(ret2.statusMQ);
733 auto inputMQ2 = std::make_unique<EffectHelper::DataMQ>(ret2.inputDataMQ);
734 auto outputMQ2 = std::make_unique<EffectHelper::DataMQ>(ret2.outputDataMQ);
735 EffectHelper::allocateInputData(common2, inputMQ2, buffer2);
736 EffectHelper::writeToFmq(inputMQ2, buffer2);
737 EffectHelper::readFromFmq(statusMQ2, 1, outputMQ2, buffer2.size(), buffer2);
738
739 ASSERT_NO_FATAL_FAILURE(command(effect1, CommandId::STOP));
740 ASSERT_NO_FATAL_FAILURE(expectState(effect1, State::IDLE));
741 ASSERT_NO_FATAL_FAILURE(close(effect1));
742 ASSERT_NO_FATAL_FAILURE(destroy(mFactory, effect1));
743
744 ASSERT_NO_FATAL_FAILURE(command(effect2, CommandId::STOP));
745 ASSERT_NO_FATAL_FAILURE(expectState(effect2, State::IDLE));
746 ASSERT_NO_FATAL_FAILURE(close(effect2));
747 ASSERT_NO_FATAL_FAILURE(destroy(mFactory, effect2));
748}
749
750INSTANTIATE_TEST_SUITE_P(
751 SingleEffectInstanceTest, AudioEffectTest,
752 ::testing::Combine(testing::ValuesIn(
753 EffectFactoryHelper::getAllEffectDescriptors(IFactory::descriptor))),
754 [](const testing::TestParamInfo<AudioEffectTest::ParamType>& info) {
Shunkai Yao812d5b42022-11-16 18:08:50 +0000755 auto instance = std::get<PARAM_INSTANCE_NAME>(info.param);
Shunkai Yaof0803cd2022-12-08 00:07:13 +0000756 std::string name = "TYPE_" + instance.second.type.toString() + "_UUID_" +
757 instance.second.uuid.toString();
Shunkai Yao812d5b42022-11-16 18:08:50 +0000758 std::replace_if(
759 name.begin(), name.end(), [](const char c) { return !std::isalnum(c); }, '_');
760 return name;
761 });
Shunkai Yaoa4ab38c2022-10-14 01:07:47 +0000762GTEST_ALLOW_UNINSTANTIATED_PARAMETERIZED_TEST(AudioEffectTest);
Shunkai Yao67b1be62022-07-13 05:01:42 +0000763
764int main(int argc, char** argv) {
765 ::testing::InitGoogleTest(&argc, argv);
766 ABinderProcess_setThreadPoolMaxThreadCount(1);
767 ABinderProcess_startThreadPool();
768 return RUN_ALL_TESTS();
Shunkai Yaoa4ab38c2022-10-14 01:07:47 +0000769}