blob: 5b83d73dfde43882cb35a4d6ac5e92313c3960d1 [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));
203 ASSERT_NO_FATAL_FAILURE(expectState(mEffect, State::INIT));
204 ASSERT_NO_FATAL_FAILURE(destroy(mFactory, mEffect));
Shunkai Yaoea24c1a2022-09-28 17:39:23 +0000205}
206
Shunkai Yao812d5b42022-11-16 18:08:50 +0000207// An effect instance transfer to IDLE state after IEffect.ASSERT_NO_FATAL_FAILURE(open().
Shunkai Yaoa4ab38c2022-10-14 01:07:47 +0000208TEST_P(AudioEffectTest, IdleStateAfterOpen) {
Shunkai Yaocb0fc412022-12-15 20:34:32 +0000209 ASSERT_NO_FATAL_FAILURE(create(mFactory, mEffect, mDescriptor));
210 ASSERT_NO_FATAL_FAILURE(open(mEffect));
211 ASSERT_NO_FATAL_FAILURE(expectState(mEffect, State::IDLE));
212 ASSERT_NO_FATAL_FAILURE(close(mEffect));
213 ASSERT_NO_FATAL_FAILURE(destroy(mFactory, mEffect));
Shunkai Yaoea24c1a2022-09-28 17:39:23 +0000214}
215
216// An effect instance is in PROCESSING state after it receive an START command.
Shunkai Yaoa4ab38c2022-10-14 01:07:47 +0000217TEST_P(AudioEffectTest, ProcessingStateAfterStart) {
Shunkai Yaocb0fc412022-12-15 20:34:32 +0000218 ASSERT_NO_FATAL_FAILURE(create(mFactory, mEffect, mDescriptor));
219 ASSERT_NO_FATAL_FAILURE(expectState(mEffect, State::INIT));
220 ASSERT_NO_FATAL_FAILURE(open(mEffect));
221 ASSERT_NO_FATAL_FAILURE(expectState(mEffect, State::IDLE));
222 ASSERT_NO_FATAL_FAILURE(command(mEffect, CommandId::START));
223 ASSERT_NO_FATAL_FAILURE(expectState(mEffect, State::PROCESSING));
224 ASSERT_NO_FATAL_FAILURE(command(mEffect, CommandId::STOP));
225 ASSERT_NO_FATAL_FAILURE(close(mEffect));
226 ASSERT_NO_FATAL_FAILURE(destroy(mFactory, mEffect));
Shunkai Yaoea24c1a2022-09-28 17:39:23 +0000227}
228
229// An effect instance transfer to IDLE state after Command.Id.STOP in PROCESSING state.
Shunkai Yaoa4ab38c2022-10-14 01:07:47 +0000230TEST_P(AudioEffectTest, IdleStateAfterStop) {
Shunkai Yaocb0fc412022-12-15 20:34:32 +0000231 ASSERT_NO_FATAL_FAILURE(create(mFactory, mEffect, mDescriptor));
232 ASSERT_NO_FATAL_FAILURE(open(mEffect));
233 ASSERT_NO_FATAL_FAILURE(command(mEffect, CommandId::START));
234 ASSERT_NO_FATAL_FAILURE(expectState(mEffect, State::PROCESSING));
235 ASSERT_NO_FATAL_FAILURE(command(mEffect, CommandId::STOP));
236 ASSERT_NO_FATAL_FAILURE(expectState(mEffect, State::IDLE));
237 ASSERT_NO_FATAL_FAILURE(close(mEffect));
238 ASSERT_NO_FATAL_FAILURE(destroy(mFactory, mEffect));
Shunkai Yaoea24c1a2022-09-28 17:39:23 +0000239}
240
241// An effect instance transfer to IDLE state after Command.Id.RESET in PROCESSING state.
Shunkai Yaoa4ab38c2022-10-14 01:07:47 +0000242TEST_P(AudioEffectTest, IdleStateAfterReset) {
Shunkai Yaocb0fc412022-12-15 20:34:32 +0000243 ASSERT_NO_FATAL_FAILURE(create(mFactory, mEffect, mDescriptor));
244 ASSERT_NO_FATAL_FAILURE(open(mEffect));
245 ASSERT_NO_FATAL_FAILURE(command(mEffect, CommandId::START));
246 ASSERT_NO_FATAL_FAILURE(expectState(mEffect, State::PROCESSING));
247 ASSERT_NO_FATAL_FAILURE(command(mEffect, CommandId::RESET));
248 ASSERT_NO_FATAL_FAILURE(expectState(mEffect, State::IDLE));
249 ASSERT_NO_FATAL_FAILURE(close(mEffect));
250 ASSERT_NO_FATAL_FAILURE(destroy(mFactory, mEffect));
Shunkai Yaoea24c1a2022-09-28 17:39:23 +0000251}
252
Shunkai Yao812d5b42022-11-16 18:08:50 +0000253// An effect instance transfer to INIT after IEffect.ASSERT_NO_FATAL_FAILURE(close().
Shunkai Yaoa4ab38c2022-10-14 01:07:47 +0000254TEST_P(AudioEffectTest, InitStateAfterClose) {
Shunkai Yaocb0fc412022-12-15 20:34:32 +0000255 ASSERT_NO_FATAL_FAILURE(create(mFactory, mEffect, mDescriptor));
256 ASSERT_NO_FATAL_FAILURE(open(mEffect));
257 ASSERT_NO_FATAL_FAILURE(command(mEffect, CommandId::START));
258 ASSERT_NO_FATAL_FAILURE(command(mEffect, CommandId::STOP));
259 ASSERT_NO_FATAL_FAILURE(close(mEffect));
260 ASSERT_NO_FATAL_FAILURE(expectState(mEffect, State::INIT));
261 ASSERT_NO_FATAL_FAILURE(destroy(mFactory, mEffect));
Shunkai Yaoea24c1a2022-09-28 17:39:23 +0000262}
263
264// An effect instance shouldn't accept any command before open.
Shunkai Yaoa4ab38c2022-10-14 01:07:47 +0000265TEST_P(AudioEffectTest, NoCommandAcceptedBeforeOpen) {
Shunkai Yaocb0fc412022-12-15 20:34:32 +0000266 ASSERT_NO_FATAL_FAILURE(create(mFactory, mEffect, mDescriptor));
267 ASSERT_NO_FATAL_FAILURE(command(mEffect, CommandId::START, EX_ILLEGAL_STATE));
268 ASSERT_NO_FATAL_FAILURE(command(mEffect, CommandId::STOP, EX_ILLEGAL_STATE));
269 ASSERT_NO_FATAL_FAILURE(command(mEffect, CommandId::RESET, EX_ILLEGAL_STATE));
270 ASSERT_NO_FATAL_FAILURE(destroy(mFactory, mEffect));
Shunkai Yaoea24c1a2022-09-28 17:39:23 +0000271}
272
273// No-op when receive STOP command in IDLE state.
Shunkai Yaoa4ab38c2022-10-14 01:07:47 +0000274TEST_P(AudioEffectTest, StopCommandInIdleStateNoOp) {
Shunkai Yaocb0fc412022-12-15 20:34:32 +0000275 ASSERT_NO_FATAL_FAILURE(create(mFactory, mEffect, mDescriptor));
276 ASSERT_NO_FATAL_FAILURE(open(mEffect));
277 ASSERT_NO_FATAL_FAILURE(expectState(mEffect, State::IDLE));
278 ASSERT_NO_FATAL_FAILURE(command(mEffect, CommandId::STOP));
279 ASSERT_NO_FATAL_FAILURE(expectState(mEffect, State::IDLE));
280 ASSERT_NO_FATAL_FAILURE(close(mEffect));
281 ASSERT_NO_FATAL_FAILURE(destroy(mFactory, mEffect));
Shunkai Yaoea24c1a2022-09-28 17:39:23 +0000282}
283
Shunkai Yao812d5b42022-11-16 18:08:50 +0000284// No-op when receive RESET command in IDLE state.
Shunkai Yaoa4ab38c2022-10-14 01:07:47 +0000285TEST_P(AudioEffectTest, ResetCommandInIdleStateNoOp) {
Shunkai Yaocb0fc412022-12-15 20:34:32 +0000286 ASSERT_NO_FATAL_FAILURE(create(mFactory, mEffect, mDescriptor));
287 ASSERT_NO_FATAL_FAILURE(open(mEffect));
288 ASSERT_NO_FATAL_FAILURE(expectState(mEffect, State::IDLE));
289 ASSERT_NO_FATAL_FAILURE(command(mEffect, CommandId::RESET));
290 ASSERT_NO_FATAL_FAILURE(expectState(mEffect, State::IDLE));
291 ASSERT_NO_FATAL_FAILURE(close(mEffect));
292 ASSERT_NO_FATAL_FAILURE(destroy(mFactory, mEffect));
Shunkai Yaoea24c1a2022-09-28 17:39:23 +0000293}
294
295// Repeat START and STOP command.
Shunkai Yaoa4ab38c2022-10-14 01:07:47 +0000296TEST_P(AudioEffectTest, RepeatStartAndStop) {
Shunkai Yaocb0fc412022-12-15 20:34:32 +0000297 ASSERT_NO_FATAL_FAILURE(create(mFactory, mEffect, mDescriptor));
298 ASSERT_NO_FATAL_FAILURE(open(mEffect));
299 ASSERT_NO_FATAL_FAILURE(expectState(mEffect, State::IDLE));
300 ASSERT_NO_FATAL_FAILURE(command(mEffect, CommandId::START));
301 ASSERT_NO_FATAL_FAILURE(expectState(mEffect, State::PROCESSING));
302 ASSERT_NO_FATAL_FAILURE(command(mEffect, CommandId::STOP));
303 ASSERT_NO_FATAL_FAILURE(expectState(mEffect, State::IDLE));
Shunkai Yao812d5b42022-11-16 18:08:50 +0000304
Shunkai Yaocb0fc412022-12-15 20:34:32 +0000305 ASSERT_NO_FATAL_FAILURE(command(mEffect, CommandId::START));
306 ASSERT_NO_FATAL_FAILURE(expectState(mEffect, State::PROCESSING));
307 ASSERT_NO_FATAL_FAILURE(command(mEffect, CommandId::STOP));
308 ASSERT_NO_FATAL_FAILURE(expectState(mEffect, State::IDLE));
309 ASSERT_NO_FATAL_FAILURE(close(mEffect));
310 ASSERT_NO_FATAL_FAILURE(destroy(mFactory, mEffect));
Shunkai Yaoea24c1a2022-09-28 17:39:23 +0000311}
312
313// Repeat START and RESET command.
Shunkai Yaoa4ab38c2022-10-14 01:07:47 +0000314TEST_P(AudioEffectTest, RepeatStartAndReset) {
Shunkai Yaocb0fc412022-12-15 20:34:32 +0000315 ASSERT_NO_FATAL_FAILURE(create(mFactory, mEffect, mDescriptor));
316 ASSERT_NO_FATAL_FAILURE(open(mEffect));
317 ASSERT_NO_FATAL_FAILURE(expectState(mEffect, State::IDLE));
318 ASSERT_NO_FATAL_FAILURE(command(mEffect, CommandId::START));
319 ASSERT_NO_FATAL_FAILURE(expectState(mEffect, State::PROCESSING));
320 ASSERT_NO_FATAL_FAILURE(command(mEffect, CommandId::RESET));
321 ASSERT_NO_FATAL_FAILURE(expectState(mEffect, State::IDLE));
Shunkai Yao812d5b42022-11-16 18:08:50 +0000322
Shunkai Yaocb0fc412022-12-15 20:34:32 +0000323 ASSERT_NO_FATAL_FAILURE(command(mEffect, CommandId::START));
324 ASSERT_NO_FATAL_FAILURE(expectState(mEffect, State::PROCESSING));
325 ASSERT_NO_FATAL_FAILURE(command(mEffect, CommandId::RESET));
326 ASSERT_NO_FATAL_FAILURE(expectState(mEffect, State::IDLE));
327 ASSERT_NO_FATAL_FAILURE(close(mEffect));
328 ASSERT_NO_FATAL_FAILURE(destroy(mFactory, mEffect));
Shunkai Yaoea24c1a2022-09-28 17:39:23 +0000329}
330
Shunkai Yao812d5b42022-11-16 18:08:50 +0000331// Try to close an effect instance at PROCESSING state.
Shunkai Yaoa4ab38c2022-10-14 01:07:47 +0000332TEST_P(AudioEffectTest, CloseProcessingStateEffects) {
Shunkai Yaocb0fc412022-12-15 20:34:32 +0000333 ASSERT_NO_FATAL_FAILURE(create(mFactory, mEffect, mDescriptor));
334 ASSERT_NO_FATAL_FAILURE(open(mEffect));
335 ASSERT_NO_FATAL_FAILURE(expectState(mEffect, State::IDLE));
336 ASSERT_NO_FATAL_FAILURE(command(mEffect, CommandId::START));
337 ASSERT_NO_FATAL_FAILURE(expectState(mEffect, State::PROCESSING));
Shunkai Yao812d5b42022-11-16 18:08:50 +0000338
Shunkai Yaocb0fc412022-12-15 20:34:32 +0000339 ASSERT_NO_FATAL_FAILURE(close(mEffect, EX_ILLEGAL_STATE));
Shunkai Yao812d5b42022-11-16 18:08:50 +0000340
Shunkai Yaocb0fc412022-12-15 20:34:32 +0000341 ASSERT_NO_FATAL_FAILURE(command(mEffect, CommandId::STOP));
342 ASSERT_NO_FATAL_FAILURE(expectState(mEffect, State::IDLE));
343 ASSERT_NO_FATAL_FAILURE(close(mEffect));
344 ASSERT_NO_FATAL_FAILURE(destroy(mFactory, mEffect));
Shunkai Yaoea24c1a2022-09-28 17:39:23 +0000345}
346
347// Expect EX_ILLEGAL_STATE if the effect instance is not in a proper state to be destroyed.
Shunkai Yaoa4ab38c2022-10-14 01:07:47 +0000348TEST_P(AudioEffectTest, DestroyOpenEffects) {
Shunkai Yaocb0fc412022-12-15 20:34:32 +0000349 ASSERT_NO_FATAL_FAILURE(create(mFactory, mEffect, mDescriptor));
350 ASSERT_NO_FATAL_FAILURE(open(mEffect));
351 ASSERT_NO_FATAL_FAILURE(expectState(mEffect, State::IDLE));
Shunkai Yaoea24c1a2022-09-28 17:39:23 +0000352
Shunkai Yaocb0fc412022-12-15 20:34:32 +0000353 ASSERT_NO_FATAL_FAILURE(destroy(mFactory, mEffect, EX_ILLEGAL_STATE));
354
355 // cleanup
356 ASSERT_NO_FATAL_FAILURE(close(mEffect));
357 ASSERT_NO_FATAL_FAILURE(destroy(mFactory, mEffect));
Shunkai Yao812d5b42022-11-16 18:08:50 +0000358}
359
360// Expect EX_ILLEGAL_STATE if the effect instance is not in a proper state to be destroyed.
361TEST_P(AudioEffectTest, DestroyProcessingEffects) {
Shunkai Yaocb0fc412022-12-15 20:34:32 +0000362 ASSERT_NO_FATAL_FAILURE(create(mFactory, mEffect, mDescriptor));
363 ASSERT_NO_FATAL_FAILURE(open(mEffect));
364 ASSERT_NO_FATAL_FAILURE(expectState(mEffect, State::IDLE));
365 ASSERT_NO_FATAL_FAILURE(command(mEffect, CommandId::START));
366 ASSERT_NO_FATAL_FAILURE(expectState(mEffect, State::PROCESSING));
Shunkai Yao812d5b42022-11-16 18:08:50 +0000367
Shunkai Yaocb0fc412022-12-15 20:34:32 +0000368 ASSERT_NO_FATAL_FAILURE(destroy(mFactory, mEffect, EX_ILLEGAL_STATE));
369
370 // cleanup
371 ASSERT_NO_FATAL_FAILURE(command(mEffect, CommandId::STOP));
372 ASSERT_NO_FATAL_FAILURE(expectState(mEffect, State::IDLE));
373 ASSERT_NO_FATAL_FAILURE(close(mEffect));
374 ASSERT_NO_FATAL_FAILURE(destroy(mFactory, mEffect));
Shunkai Yao812d5b42022-11-16 18:08:50 +0000375}
376
377TEST_P(AudioEffectTest, NormalSequenceStates) {
Shunkai Yaocb0fc412022-12-15 20:34:32 +0000378 ASSERT_NO_FATAL_FAILURE(create(mFactory, mEffect, mDescriptor));
379 ASSERT_NO_FATAL_FAILURE(expectState(mEffect, State::INIT));
380 ASSERT_NO_FATAL_FAILURE(open(mEffect));
381 ASSERT_NO_FATAL_FAILURE(expectState(mEffect, State::IDLE));
382 ASSERT_NO_FATAL_FAILURE(command(mEffect, CommandId::START));
383 ASSERT_NO_FATAL_FAILURE(expectState(mEffect, State::PROCESSING));
384 ASSERT_NO_FATAL_FAILURE(command(mEffect, CommandId::STOP));
385 ASSERT_NO_FATAL_FAILURE(expectState(mEffect, State::IDLE));
386 ASSERT_NO_FATAL_FAILURE(command(mEffect, CommandId::START));
387 ASSERT_NO_FATAL_FAILURE(expectState(mEffect, State::PROCESSING));
388 ASSERT_NO_FATAL_FAILURE(command(mEffect, CommandId::RESET));
389 ASSERT_NO_FATAL_FAILURE(expectState(mEffect, State::IDLE));
390 ASSERT_NO_FATAL_FAILURE(close(mEffect));
391 ASSERT_NO_FATAL_FAILURE(destroy(mFactory, mEffect));
Shunkai Yaoea24c1a2022-09-28 17:39:23 +0000392}
393
394/// Parameter testing.
395// Verify parameters pass in open can be successfully get.
Shunkai Yao812d5b42022-11-16 18:08:50 +0000396TEST_P(AudioEffectTest, VerifyCommonParametersAfterOpen) {
Shunkai Yaocb0fc412022-12-15 20:34:32 +0000397 ASSERT_NO_FATAL_FAILURE(create(mFactory, mEffect, mDescriptor));
Shunkai Yao812d5b42022-11-16 18:08:50 +0000398
399 Parameter::Common common = EffectHelper::createParamCommon();
400 IEffect::OpenEffectReturn ret;
Shunkai Yaocb0fc412022-12-15 20:34:32 +0000401 ASSERT_NO_FATAL_FAILURE(open(mEffect, common, std::nullopt /* specific */, &ret, EX_NONE));
Shunkai Yao812d5b42022-11-16 18:08:50 +0000402
403 Parameter get = Parameter(), expect = Parameter();
404 expect.set<Parameter::common>(common);
405 Parameter::Id id;
406 id.set<Parameter::Id::commonTag>(Parameter::common);
Shunkai Yaocb0fc412022-12-15 20:34:32 +0000407 EXPECT_IS_OK(mEffect->getParameter(id, &get));
Shunkai Yaoeea19942023-02-16 02:31:24 +0000408 EXPECT_EQ(expect, get) << expect.toString() << "\n vs \n" << get.toString();
Shunkai Yao812d5b42022-11-16 18:08:50 +0000409
Shunkai Yaocb0fc412022-12-15 20:34:32 +0000410 ASSERT_NO_FATAL_FAILURE(close(mEffect));
411 ASSERT_NO_FATAL_FAILURE(destroy(mFactory, mEffect));
Shunkai Yaoea24c1a2022-09-28 17:39:23 +0000412}
413
414// Verify parameters pass in set can be successfully get.
Shunkai Yao812d5b42022-11-16 18:08:50 +0000415TEST_P(AudioEffectTest, SetAndGetCommonParameter) {
Shunkai Yaocb0fc412022-12-15 20:34:32 +0000416 ASSERT_NO_FATAL_FAILURE(create(mFactory, mEffect, mDescriptor));
417 ASSERT_NO_FATAL_FAILURE(open(mEffect));
Shunkai Yao812d5b42022-11-16 18:08:50 +0000418
419 Parameter::Common common = EffectHelper::createParamCommon(
420 0 /* session */, 1 /* ioHandle */, 44100 /* iSampleRate */, 44100 /* oSampleRate */);
Shunkai Yao5df4e6c2023-01-10 03:20:00 +0000421 Parameter::Id id = Parameter::Id::make<Parameter::Id::commonTag>(Parameter::common);
422 ASSERT_NO_FATAL_FAILURE(setAndGetParameter(id, Parameter::make<Parameter::common>(common)));
Shunkai Yao812d5b42022-11-16 18:08:50 +0000423
Shunkai Yaocb0fc412022-12-15 20:34:32 +0000424 ASSERT_NO_FATAL_FAILURE(close(mEffect));
425 ASSERT_NO_FATAL_FAILURE(destroy(mFactory, mEffect));
Shunkai Yaoea24c1a2022-09-28 17:39:23 +0000426}
427
Shunkai Yao812d5b42022-11-16 18:08:50 +0000428// Verify parameters set and get in PROCESSING state.
Shunkai Yaoa4ab38c2022-10-14 01:07:47 +0000429TEST_P(AudioEffectTest, SetAndGetParameterInProcessing) {
Shunkai Yaocb0fc412022-12-15 20:34:32 +0000430 ASSERT_NO_FATAL_FAILURE(create(mFactory, mEffect, mDescriptor));
431 ASSERT_NO_FATAL_FAILURE(open(mEffect));
432 ASSERT_NO_FATAL_FAILURE(command(mEffect, CommandId::START));
433 ASSERT_NO_FATAL_FAILURE(expectState(mEffect, State::PROCESSING));
Shunkai Yao812d5b42022-11-16 18:08:50 +0000434
435 Parameter::Common common = EffectHelper::createParamCommon(
436 0 /* session */, 1 /* ioHandle */, 44100 /* iSampleRate */, 44100 /* oSampleRate */);
Shunkai Yao5df4e6c2023-01-10 03:20:00 +0000437 Parameter::Id id = Parameter::Id::make<Parameter::Id::commonTag>(Parameter::common);
438 ASSERT_NO_FATAL_FAILURE(setAndGetParameter(id, Parameter::make<Parameter::common>(common)));
Shunkai Yao812d5b42022-11-16 18:08:50 +0000439
Shunkai Yaocb0fc412022-12-15 20:34:32 +0000440 ASSERT_NO_FATAL_FAILURE(command(mEffect, CommandId::STOP));
441 ASSERT_NO_FATAL_FAILURE(close(mEffect));
442 ASSERT_NO_FATAL_FAILURE(destroy(mFactory, mEffect));
Shunkai Yaoea24c1a2022-09-28 17:39:23 +0000443}
444
Shunkai Yao812d5b42022-11-16 18:08:50 +0000445// Verify parameters set and get in IDLE state.
446TEST_P(AudioEffectTest, SetAndGetParameterInIdle) {
Shunkai Yaocb0fc412022-12-15 20:34:32 +0000447 ASSERT_NO_FATAL_FAILURE(create(mFactory, mEffect, mDescriptor));
448 ASSERT_NO_FATAL_FAILURE(open(mEffect));
449 ASSERT_NO_FATAL_FAILURE(command(mEffect, CommandId::START));
450 ASSERT_NO_FATAL_FAILURE(expectState(mEffect, State::PROCESSING));
451 ASSERT_NO_FATAL_FAILURE(command(mEffect, CommandId::STOP));
452 ASSERT_NO_FATAL_FAILURE(expectState(mEffect, State::IDLE));
Shunkai Yao812d5b42022-11-16 18:08:50 +0000453
454 Parameter::Common common = EffectHelper::createParamCommon(
455 0 /* session */, 1 /* ioHandle */, 44100 /* iSampleRate */, 44100 /* oSampleRate */);
Shunkai Yao5df4e6c2023-01-10 03:20:00 +0000456 Parameter::Id id = Parameter::Id::make<Parameter::Id::commonTag>(Parameter::common);
457 ASSERT_NO_FATAL_FAILURE(setAndGetParameter(id, Parameter::make<Parameter::common>(common)));
Shunkai Yao812d5b42022-11-16 18:08:50 +0000458
Shunkai Yaocb0fc412022-12-15 20:34:32 +0000459 ASSERT_NO_FATAL_FAILURE(close(mEffect));
460 ASSERT_NO_FATAL_FAILURE(destroy(mFactory, mEffect));
Shunkai Yaoea24c1a2022-09-28 17:39:23 +0000461}
462
Shunkai Yao812d5b42022-11-16 18:08:50 +0000463// Verify Parameters kept after stop.
464TEST_P(AudioEffectTest, SetAndGetParameterAfterStop) {
Shunkai Yaocb0fc412022-12-15 20:34:32 +0000465 ASSERT_NO_FATAL_FAILURE(create(mFactory, mEffect, mDescriptor));
466 ASSERT_NO_FATAL_FAILURE(open(mEffect));
467 ASSERT_NO_FATAL_FAILURE(command(mEffect, CommandId::START));
468 ASSERT_NO_FATAL_FAILURE(expectState(mEffect, State::PROCESSING));
Shunkai Yaoea24c1a2022-09-28 17:39:23 +0000469
Shunkai Yao812d5b42022-11-16 18:08:50 +0000470 Parameter::Common common = EffectHelper::createParamCommon(
471 0 /* session */, 1 /* ioHandle */, 44100 /* iSampleRate */, 44100 /* oSampleRate */);
Shunkai Yao5df4e6c2023-01-10 03:20:00 +0000472 Parameter::Id id = Parameter::Id::make<Parameter::Id::commonTag>(Parameter::common);
473 ASSERT_NO_FATAL_FAILURE(setAndGetParameter(id, Parameter::make<Parameter::common>(common)));
Shunkai Yaoa4ab38c2022-10-14 01:07:47 +0000474
Shunkai Yaocb0fc412022-12-15 20:34:32 +0000475 ASSERT_NO_FATAL_FAILURE(command(mEffect, CommandId::STOP));
476 ASSERT_NO_FATAL_FAILURE(expectState(mEffect, State::IDLE));
Shunkai Yaocb0fc412022-12-15 20:34:32 +0000477 ASSERT_NO_FATAL_FAILURE(close(mEffect));
478 ASSERT_NO_FATAL_FAILURE(destroy(mFactory, mEffect));
Shunkai Yaoa4ab38c2022-10-14 01:07:47 +0000479}
480
Shunkai Yao812d5b42022-11-16 18:08:50 +0000481// Verify Parameters kept after reset.
482TEST_P(AudioEffectTest, SetAndGetParameterAfterReset) {
Shunkai Yaocb0fc412022-12-15 20:34:32 +0000483 ASSERT_NO_FATAL_FAILURE(create(mFactory, mEffect, mDescriptor));
484 ASSERT_NO_FATAL_FAILURE(open(mEffect));
Shunkai Yao812d5b42022-11-16 18:08:50 +0000485
Shunkai Yaocb0fc412022-12-15 20:34:32 +0000486 ASSERT_NO_FATAL_FAILURE(command(mEffect, CommandId::START));
487 ASSERT_NO_FATAL_FAILURE(expectState(mEffect, State::PROCESSING));
Shunkai Yao812d5b42022-11-16 18:08:50 +0000488
489 Parameter::Common common = EffectHelper::createParamCommon(
490 0 /* session */, 1 /* ioHandle */, 44100 /* iSampleRate */, 44100 /* oSampleRate */);
Shunkai Yao5df4e6c2023-01-10 03:20:00 +0000491 Parameter::Id id = Parameter::Id::make<Parameter::Id::commonTag>(Parameter::common);
492 ASSERT_NO_FATAL_FAILURE(setAndGetParameter(id, Parameter::make<Parameter::common>(common)));
Shunkai Yao812d5b42022-11-16 18:08:50 +0000493
Shunkai Yaocb0fc412022-12-15 20:34:32 +0000494 ASSERT_NO_FATAL_FAILURE(command(mEffect, CommandId::RESET));
495 ASSERT_NO_FATAL_FAILURE(expectState(mEffect, State::IDLE));
Shunkai Yao812d5b42022-11-16 18:08:50 +0000496
Shunkai Yao5df4e6c2023-01-10 03:20:00 +0000497 ASSERT_NO_FATAL_FAILURE(setAndGetParameter(id, Parameter::make<Parameter::common>(common)));
Shunkai Yao812d5b42022-11-16 18:08:50 +0000498
Shunkai Yao5df4e6c2023-01-10 03:20:00 +0000499 ASSERT_NO_FATAL_FAILURE(command(mEffect, CommandId::STOP));
500 ASSERT_NO_FATAL_FAILURE(expectState(mEffect, State::IDLE));
Shunkai Yaocb0fc412022-12-15 20:34:32 +0000501 ASSERT_NO_FATAL_FAILURE(close(mEffect));
502 ASSERT_NO_FATAL_FAILURE(destroy(mFactory, mEffect));
Shunkai Yao812d5b42022-11-16 18:08:50 +0000503}
Shunkai Yao5df4e6c2023-01-10 03:20:00 +0000504
505// Set and get AudioDeviceDescription in Parameter
506TEST_P(AudioEffectTest, SetAndGetParameterDeviceDescription) {
Shunkai Yao92cd7482023-09-18 17:37:45 +0000507 if (!mDescriptor.common.flags.deviceIndication) {
508 GTEST_SKIP() << "Skipping test as effect does not support deviceIndication"
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));
514
515 ASSERT_NO_FATAL_FAILURE(command(mEffect, CommandId::START));
516 ASSERT_NO_FATAL_FAILURE(expectState(mEffect, State::PROCESSING));
517
518 std::vector<AudioDeviceDescription> deviceDescs = {
519 {.type = AudioDeviceType::IN_DEFAULT,
520 .connection = AudioDeviceDescription::CONNECTION_ANALOG},
521 {.type = AudioDeviceType::IN_DEVICE,
522 .connection = AudioDeviceDescription::CONNECTION_BT_A2DP}};
523 Parameter::Id id = Parameter::Id::make<Parameter::Id::commonTag>(Parameter::deviceDescription);
524 ASSERT_NO_FATAL_FAILURE(
525 setAndGetParameter(id, Parameter::make<Parameter::deviceDescription>(deviceDescs)));
526
527 ASSERT_NO_FATAL_FAILURE(command(mEffect, CommandId::STOP));
528 ASSERT_NO_FATAL_FAILURE(expectState(mEffect, State::IDLE));
529 ASSERT_NO_FATAL_FAILURE(close(mEffect));
530 ASSERT_NO_FATAL_FAILURE(destroy(mFactory, mEffect));
531}
532
533// Set and get AudioMode in Parameter
534TEST_P(AudioEffectTest, SetAndGetParameterAudioMode) {
Shunkai Yao92cd7482023-09-18 17:37:45 +0000535 if (!mDescriptor.common.flags.audioModeIndication) {
536 GTEST_SKIP() << "Skipping test as effect does not support audioModeIndication"
537 << mDescriptor.common.flags.toString();
538 }
539
Shunkai Yao5df4e6c2023-01-10 03:20:00 +0000540 ASSERT_NO_FATAL_FAILURE(create(mFactory, mEffect, mDescriptor));
541 ASSERT_NO_FATAL_FAILURE(open(mEffect));
542
543 ASSERT_NO_FATAL_FAILURE(command(mEffect, CommandId::START));
544 ASSERT_NO_FATAL_FAILURE(expectState(mEffect, State::PROCESSING));
545
546 Parameter::Id id = Parameter::Id::make<Parameter::Id::commonTag>(Parameter::mode);
547 ASSERT_NO_FATAL_FAILURE(
548 setAndGetParameter(id, Parameter::make<Parameter::mode>(AudioMode::NORMAL)));
549 ASSERT_NO_FATAL_FAILURE(
550 setAndGetParameter(id, Parameter::make<Parameter::mode>(AudioMode::IN_COMMUNICATION)));
551
552 ASSERT_NO_FATAL_FAILURE(command(mEffect, CommandId::STOP));
553 ASSERT_NO_FATAL_FAILURE(expectState(mEffect, State::IDLE));
554 ASSERT_NO_FATAL_FAILURE(close(mEffect));
555 ASSERT_NO_FATAL_FAILURE(destroy(mFactory, mEffect));
556}
557
558// Set and get AudioSource in Parameter
559TEST_P(AudioEffectTest, SetAndGetParameterAudioSource) {
Shunkai Yao92cd7482023-09-18 17:37:45 +0000560 if (!mDescriptor.common.flags.audioSourceIndication) {
561 GTEST_SKIP() << "Skipping test as effect does not support audioSourceIndication"
562 << mDescriptor.common.flags.toString();
563 }
564
Shunkai Yao5df4e6c2023-01-10 03:20:00 +0000565 ASSERT_NO_FATAL_FAILURE(create(mFactory, mEffect, mDescriptor));
566 ASSERT_NO_FATAL_FAILURE(open(mEffect));
567
568 ASSERT_NO_FATAL_FAILURE(command(mEffect, CommandId::START));
569 ASSERT_NO_FATAL_FAILURE(expectState(mEffect, State::PROCESSING));
570
571 Parameter::Id id = Parameter::Id::make<Parameter::Id::commonTag>(Parameter::source);
572 ASSERT_NO_FATAL_FAILURE(
573 setAndGetParameter(id, Parameter::make<Parameter::source>(AudioSource::DEFAULT)));
574 ASSERT_NO_FATAL_FAILURE(setAndGetParameter(
575 id, Parameter::make<Parameter::source>(AudioSource::VOICE_RECOGNITION)));
576
577 ASSERT_NO_FATAL_FAILURE(command(mEffect, CommandId::STOP));
578 ASSERT_NO_FATAL_FAILURE(expectState(mEffect, State::IDLE));
579 ASSERT_NO_FATAL_FAILURE(close(mEffect));
580 ASSERT_NO_FATAL_FAILURE(destroy(mFactory, mEffect));
581}
582
583// Set and get VolumeStereo in Parameter
584TEST_P(AudioEffectTest, SetAndGetParameterVolume) {
Shunkai Yao92cd7482023-09-18 17:37:45 +0000585 if (mDescriptor.common.flags.volume == Flags::Volume::NONE) {
586 GTEST_SKIP() << "Skipping test as effect does not support volume"
587 << mDescriptor.common.flags.toString();
588 }
589
Shunkai Yao5df4e6c2023-01-10 03:20:00 +0000590 ASSERT_NO_FATAL_FAILURE(create(mFactory, mEffect, mDescriptor));
591 ASSERT_NO_FATAL_FAILURE(open(mEffect));
592
593 ASSERT_NO_FATAL_FAILURE(command(mEffect, CommandId::START));
594 ASSERT_NO_FATAL_FAILURE(expectState(mEffect, State::PROCESSING));
595
596 Parameter::Id id = Parameter::Id::make<Parameter::Id::commonTag>(Parameter::volumeStereo);
597 Parameter::VolumeStereo volume = {.left = 10.0, .right = 10.0};
David Li1a56fdd2023-11-14 23:31:53 +0800598 if (mDescriptor.common.flags.volume == Flags::Volume::CTRL) {
599 Parameter get;
600 EXPECT_IS_OK(mEffect->setParameter(volume));
601 EXPECT_IS_OK(mEffect->getParameter(id, &get));
602 } else {
603 ASSERT_NO_FATAL_FAILURE(
604 setAndGetParameter(id, Parameter::make<Parameter::volumeStereo>(volume)));
605 }
Shunkai Yao5df4e6c2023-01-10 03:20:00 +0000606
607 ASSERT_NO_FATAL_FAILURE(command(mEffect, CommandId::STOP));
608 ASSERT_NO_FATAL_FAILURE(expectState(mEffect, State::IDLE));
609 ASSERT_NO_FATAL_FAILURE(close(mEffect));
610 ASSERT_NO_FATAL_FAILURE(destroy(mFactory, mEffect));
611}
612
Shunkai Yaod685aed2024-01-30 18:27:38 +0000613/**
614 * Verify DataMqUpdateEventFlag after common parameter setting.
615 * verify reopen sequence.
616 */
617TEST_P(AudioEffectDataPathTest, SetCommonParameterAndReopen) {
Shunkai Yao9f9fe922024-03-04 21:23:04 +0000618 if (!EffectFactoryHelper::isReopenSupported(mFactory)) {
619 GTEST_SKIP() << "Skipping test as effect does not support reopen";
620 }
621
Shunkai Yao65c7c702024-01-09 20:50:53 +0000622 ASSERT_NO_FATAL_FAILURE(create(mFactory, mEffect, mDescriptor));
623
624 Parameter::Common common = EffectHelper::createParamCommon(
625 0 /* session */, 1 /* ioHandle */, 44100 /* iSampleRate */, 44100 /* oSampleRate */,
626 kInputFrameCount /* iFrameCount */, kOutputFrameCount /* oFrameCount */);
627 IEffect::OpenEffectReturn ret;
628 ASSERT_NO_FATAL_FAILURE(open(mEffect, common, std::nullopt /* specific */, &ret, EX_NONE));
629 auto statusMQ = std::make_unique<EffectHelper::StatusMQ>(ret.statusMQ);
630 ASSERT_TRUE(statusMQ->isValid());
631 auto inputMQ = std::make_unique<EffectHelper::DataMQ>(ret.inputDataMQ);
632 ASSERT_TRUE(inputMQ->isValid());
633 auto outputMQ = std::make_unique<EffectHelper::DataMQ>(ret.outputDataMQ);
634 ASSERT_TRUE(outputMQ->isValid());
635
636 Parameter::Id id = Parameter::Id::make<Parameter::Id::commonTag>(Parameter::common);
637 common.input.frameCount++;
638 ASSERT_NO_FATAL_FAILURE(setAndGetParameter(id, Parameter::make<Parameter::common>(common)));
639 ASSERT_TRUE(statusMQ->isValid());
640 expectDataMqUpdateEventFlag(statusMQ);
641 EXPECT_IS_OK(mEffect->reopen(&ret));
642 inputMQ = std::make_unique<EffectHelper::DataMQ>(ret.inputDataMQ);
643 outputMQ = std::make_unique<EffectHelper::DataMQ>(ret.outputDataMQ);
644 ASSERT_TRUE(statusMQ->isValid());
645 ASSERT_TRUE(inputMQ->isValid());
646 ASSERT_TRUE(outputMQ->isValid());
647
648 common.output.frameCount++;
649 ASSERT_NO_FATAL_FAILURE(setAndGetParameter(id, Parameter::make<Parameter::common>(common)));
650 ASSERT_TRUE(statusMQ->isValid());
651 expectDataMqUpdateEventFlag(statusMQ);
652 EXPECT_IS_OK(mEffect->reopen(&ret));
653 inputMQ = std::make_unique<EffectHelper::DataMQ>(ret.inputDataMQ);
654 outputMQ = std::make_unique<EffectHelper::DataMQ>(ret.outputDataMQ);
655 ASSERT_TRUE(statusMQ->isValid());
656 ASSERT_TRUE(inputMQ->isValid());
657 ASSERT_TRUE(outputMQ->isValid());
658
659 ASSERT_NO_FATAL_FAILURE(close(mEffect));
660 ASSERT_NO_FATAL_FAILURE(destroy(mFactory, mEffect));
661}
662
Shunkai Yao812d5b42022-11-16 18:08:50 +0000663/// Data processing test
664// Send data to effects and expect it to be consumed by checking statusMQ.
Jaideep Sharmacba42862023-06-23 10:27:39 +0530665// Effects exposing bypass flags or operating in offload mode will be skipped.
666TEST_P(AudioEffectDataPathTest, ConsumeDataInProcessingState) {
Shunkai Yaocb0fc412022-12-15 20:34:32 +0000667 ASSERT_NO_FATAL_FAILURE(create(mFactory, mEffect, mDescriptor));
Shunkai Yao812d5b42022-11-16 18:08:50 +0000668
669 Parameter::Common common = EffectHelper::createParamCommon(
670 0 /* session */, 1 /* ioHandle */, 44100 /* iSampleRate */, 44100 /* oSampleRate */,
671 kInputFrameCount /* iFrameCount */, kOutputFrameCount /* oFrameCount */);
672 IEffect::OpenEffectReturn ret;
Shunkai Yaocb0fc412022-12-15 20:34:32 +0000673 ASSERT_NO_FATAL_FAILURE(open(mEffect, common, std::nullopt /* specific */, &ret, EX_NONE));
Shunkai Yao812d5b42022-11-16 18:08:50 +0000674 auto statusMQ = std::make_unique<EffectHelper::StatusMQ>(ret.statusMQ);
Shunkai Yaocb0fc412022-12-15 20:34:32 +0000675 ASSERT_TRUE(statusMQ->isValid());
Shunkai Yao812d5b42022-11-16 18:08:50 +0000676 auto inputMQ = std::make_unique<EffectHelper::DataMQ>(ret.inputDataMQ);
Shunkai Yaocb0fc412022-12-15 20:34:32 +0000677 ASSERT_TRUE(inputMQ->isValid());
Shunkai Yao812d5b42022-11-16 18:08:50 +0000678 auto outputMQ = std::make_unique<EffectHelper::DataMQ>(ret.outputDataMQ);
Shunkai Yaocb0fc412022-12-15 20:34:32 +0000679 ASSERT_TRUE(outputMQ->isValid());
Shunkai Yao812d5b42022-11-16 18:08:50 +0000680
Shunkai Yaocb0fc412022-12-15 20:34:32 +0000681 ASSERT_NO_FATAL_FAILURE(command(mEffect, CommandId::START));
682 ASSERT_NO_FATAL_FAILURE(expectState(mEffect, State::PROCESSING));
Shunkai Yao812d5b42022-11-16 18:08:50 +0000683
684 std::vector<float> buffer;
Shunkai Yaob49631f2023-02-03 01:44:32 +0000685 EXPECT_NO_FATAL_FAILURE(EffectHelper::allocateInputData(common, inputMQ, buffer));
Shunkai Yaoef683a92024-04-18 04:38:17 +0000686 EXPECT_NO_FATAL_FAILURE(EffectHelper::writeToFmq(statusMQ, inputMQ, buffer, mVersion));
Shunkai Yaob49631f2023-02-03 01:44:32 +0000687 EXPECT_NO_FATAL_FAILURE(
688 EffectHelper::readFromFmq(statusMQ, 1, outputMQ, buffer.size(), buffer));
Shunkai Yao812d5b42022-11-16 18:08:50 +0000689
Shunkai Yaocb0fc412022-12-15 20:34:32 +0000690 ASSERT_NO_FATAL_FAILURE(command(mEffect, CommandId::STOP));
691 ASSERT_NO_FATAL_FAILURE(expectState(mEffect, State::IDLE));
Shunkai Yaob49631f2023-02-03 01:44:32 +0000692 EXPECT_NO_FATAL_FAILURE(EffectHelper::readFromFmq(statusMQ, 0, outputMQ, 0, buffer));
Shunkai Yao812d5b42022-11-16 18:08:50 +0000693
Shunkai Yaocb0fc412022-12-15 20:34:32 +0000694 ASSERT_NO_FATAL_FAILURE(close(mEffect));
695 ASSERT_NO_FATAL_FAILURE(destroy(mFactory, mEffect));
Shunkai Yao812d5b42022-11-16 18:08:50 +0000696}
697
698// Send data to effects and expect it to be consumed after effect restart.
Jaideep Sharmacba42862023-06-23 10:27:39 +0530699// Effects exposing bypass flags or operating in offload mode will be skipped.
700TEST_P(AudioEffectDataPathTest, ConsumeDataAfterRestart) {
Shunkai Yaocb0fc412022-12-15 20:34:32 +0000701 ASSERT_NO_FATAL_FAILURE(create(mFactory, mEffect, mDescriptor));
Shunkai Yao812d5b42022-11-16 18:08:50 +0000702
703 Parameter::Common common = EffectHelper::createParamCommon(
704 0 /* session */, 1 /* ioHandle */, 44100 /* iSampleRate */, 44100 /* oSampleRate */,
705 kInputFrameCount /* iFrameCount */, kOutputFrameCount /* oFrameCount */);
706 IEffect::OpenEffectReturn ret;
Shunkai Yaocb0fc412022-12-15 20:34:32 +0000707 ASSERT_NO_FATAL_FAILURE(open(mEffect, common, std::nullopt /* specific */, &ret, EX_NONE));
Shunkai Yao812d5b42022-11-16 18:08:50 +0000708 auto statusMQ = std::make_unique<EffectHelper::StatusMQ>(ret.statusMQ);
Shunkai Yaocb0fc412022-12-15 20:34:32 +0000709 ASSERT_TRUE(statusMQ->isValid());
Shunkai Yao812d5b42022-11-16 18:08:50 +0000710 auto inputMQ = std::make_unique<EffectHelper::DataMQ>(ret.inputDataMQ);
Shunkai Yaocb0fc412022-12-15 20:34:32 +0000711 ASSERT_TRUE(inputMQ->isValid());
Shunkai Yao812d5b42022-11-16 18:08:50 +0000712 auto outputMQ = std::make_unique<EffectHelper::DataMQ>(ret.outputDataMQ);
Shunkai Yaocb0fc412022-12-15 20:34:32 +0000713 ASSERT_TRUE(outputMQ->isValid());
Shunkai Yao812d5b42022-11-16 18:08:50 +0000714
Shunkai Yao812d5b42022-11-16 18:08:50 +0000715 std::vector<float> buffer;
Shunkai Yaob49631f2023-02-03 01:44:32 +0000716 ASSERT_NO_FATAL_FAILURE(command(mEffect, CommandId::START));
717 ASSERT_NO_FATAL_FAILURE(expectState(mEffect, State::PROCESSING));
718 ASSERT_NO_FATAL_FAILURE(command(mEffect, CommandId::STOP));
719 ASSERT_NO_FATAL_FAILURE(expectState(mEffect, State::IDLE));
720 EXPECT_NO_FATAL_FAILURE(
721 EffectHelper::readFromFmq(statusMQ, 0, outputMQ, buffer.size(), buffer));
722 ASSERT_NO_FATAL_FAILURE(command(mEffect, CommandId::START));
723 ASSERT_NO_FATAL_FAILURE(expectState(mEffect, State::PROCESSING));
724
725 EXPECT_NO_FATAL_FAILURE(EffectHelper::allocateInputData(common, inputMQ, buffer));
Shunkai Yaoef683a92024-04-18 04:38:17 +0000726 EXPECT_NO_FATAL_FAILURE(EffectHelper::writeToFmq(statusMQ, inputMQ, buffer, mVersion));
Shunkai Yaob49631f2023-02-03 01:44:32 +0000727 EXPECT_NO_FATAL_FAILURE(
728 EffectHelper::readFromFmq(statusMQ, 1, outputMQ, buffer.size(), buffer));
Shunkai Yao812d5b42022-11-16 18:08:50 +0000729
Shunkai Yaocb0fc412022-12-15 20:34:32 +0000730 ASSERT_NO_FATAL_FAILURE(command(mEffect, CommandId::STOP));
731 ASSERT_NO_FATAL_FAILURE(expectState(mEffect, State::IDLE));
Shunkai Yaob49631f2023-02-03 01:44:32 +0000732 EXPECT_NO_FATAL_FAILURE(EffectHelper::readFromFmq(statusMQ, 0, outputMQ, 0, buffer));
Shunkai Yao812d5b42022-11-16 18:08:50 +0000733
Shunkai Yaocb0fc412022-12-15 20:34:32 +0000734 ASSERT_NO_FATAL_FAILURE(close(mEffect));
735 ASSERT_NO_FATAL_FAILURE(destroy(mFactory, mEffect));
Shunkai Yao812d5b42022-11-16 18:08:50 +0000736}
737
Shunkai Yao65c7c702024-01-09 20:50:53 +0000738// Send data to effects and expect it to be consumed after effect reopen (IO AudioConfig change).
739// Effects exposing bypass flags or operating in offload mode will be skipped.
740TEST_P(AudioEffectDataPathTest, ConsumeDataAfterReopen) {
Shunkai Yao9f9fe922024-03-04 21:23:04 +0000741 if (!EffectFactoryHelper::isReopenSupported(mFactory)) {
742 GTEST_SKIP() << "Skipping test as effect does not support reopen";
743 }
744
Shunkai Yao65c7c702024-01-09 20:50:53 +0000745 ASSERT_NO_FATAL_FAILURE(create(mFactory, mEffect, mDescriptor));
746
747 Parameter::Common common = EffectHelper::createParamCommon(
748 0 /* session */, 1 /* ioHandle */, 44100 /* iSampleRate */, 44100 /* oSampleRate */,
749 kInputFrameCount /* iFrameCount */, kOutputFrameCount /* oFrameCount */);
750 IEffect::OpenEffectReturn ret;
751 ASSERT_NO_FATAL_FAILURE(open(mEffect, common, std::nullopt /* specific */, &ret, EX_NONE));
752 auto statusMQ = std::make_unique<EffectHelper::StatusMQ>(ret.statusMQ);
753 ASSERT_TRUE(statusMQ->isValid());
754 auto inputMQ = std::make_unique<EffectHelper::DataMQ>(ret.inputDataMQ);
755 ASSERT_TRUE(inputMQ->isValid());
756 auto outputMQ = std::make_unique<EffectHelper::DataMQ>(ret.outputDataMQ);
757 ASSERT_TRUE(outputMQ->isValid());
758
759 std::vector<float> buffer;
760 ASSERT_NO_FATAL_FAILURE(command(mEffect, CommandId::START));
761 ASSERT_NO_FATAL_FAILURE(expectState(mEffect, State::PROCESSING));
762 EXPECT_NO_FATAL_FAILURE(EffectHelper::allocateInputData(common, inputMQ, buffer));
Shunkai Yaoef683a92024-04-18 04:38:17 +0000763 EXPECT_NO_FATAL_FAILURE(EffectHelper::writeToFmq(statusMQ, inputMQ, buffer, mVersion));
Shunkai Yao65c7c702024-01-09 20:50:53 +0000764 EXPECT_NO_FATAL_FAILURE(
765 EffectHelper::readFromFmq(statusMQ, 1, outputMQ, buffer.size(), buffer));
766
767 // set a new common parameter with different IO frameCount, reopen
768 Parameter::Id id = Parameter::Id::make<Parameter::Id::commonTag>(Parameter::common);
769 common.input.frameCount += 4;
770 common.output.frameCount += 4;
771 ASSERT_NO_FATAL_FAILURE(setAndGetParameter(id, Parameter::make<Parameter::common>(common)));
772 ASSERT_TRUE(statusMQ->isValid());
773 expectDataMqUpdateEventFlag(statusMQ);
774 EXPECT_IS_OK(mEffect->reopen(&ret));
775 inputMQ = std::make_unique<EffectHelper::DataMQ>(ret.inputDataMQ);
776 outputMQ = std::make_unique<EffectHelper::DataMQ>(ret.outputDataMQ);
777 ASSERT_TRUE(statusMQ->isValid());
778 ASSERT_TRUE(inputMQ->isValid());
779 ASSERT_TRUE(outputMQ->isValid());
780
781 // verify data consume again
782 EXPECT_NO_FATAL_FAILURE(EffectHelper::allocateInputData(common, inputMQ, buffer));
Shunkai Yaoef683a92024-04-18 04:38:17 +0000783 EXPECT_NO_FATAL_FAILURE(EffectHelper::writeToFmq(statusMQ, inputMQ, buffer, mVersion));
Shunkai Yao65c7c702024-01-09 20:50:53 +0000784 EXPECT_NO_FATAL_FAILURE(
785 EffectHelper::readFromFmq(statusMQ, 1, outputMQ, buffer.size(), buffer));
786
787 ASSERT_NO_FATAL_FAILURE(command(mEffect, CommandId::STOP));
788 ASSERT_NO_FATAL_FAILURE(expectState(mEffect, State::IDLE));
789 EXPECT_NO_FATAL_FAILURE(EffectHelper::readFromFmq(statusMQ, 0, outputMQ, 0, buffer));
790
791 ASSERT_NO_FATAL_FAILURE(close(mEffect));
792 ASSERT_NO_FATAL_FAILURE(destroy(mFactory, mEffect));
793}
794
Shunkai Yao812d5b42022-11-16 18:08:50 +0000795// Send data to IDLE effects and expect it to be consumed after effect start.
Jaideep Sharmacba42862023-06-23 10:27:39 +0530796// Effects exposing bypass flags or operating in offload mode will be skipped.
797TEST_P(AudioEffectDataPathTest, SendDataAtIdleAndConsumeDataInProcessing) {
Shunkai Yaocb0fc412022-12-15 20:34:32 +0000798 ASSERT_NO_FATAL_FAILURE(create(mFactory, mEffect, mDescriptor));
Shunkai Yao812d5b42022-11-16 18:08:50 +0000799
800 Parameter::Common common = EffectHelper::createParamCommon(
801 0 /* session */, 1 /* ioHandle */, 44100 /* iSampleRate */, 44100 /* oSampleRate */,
802 kInputFrameCount /* iFrameCount */, kOutputFrameCount /* oFrameCount */);
803 IEffect::OpenEffectReturn ret;
Shunkai Yaocb0fc412022-12-15 20:34:32 +0000804 ASSERT_NO_FATAL_FAILURE(open(mEffect, common, std::nullopt /* specific */, &ret, EX_NONE));
Shunkai Yao812d5b42022-11-16 18:08:50 +0000805 auto statusMQ = std::make_unique<EffectHelper::StatusMQ>(ret.statusMQ);
Shunkai Yaocb0fc412022-12-15 20:34:32 +0000806 ASSERT_TRUE(statusMQ->isValid());
Shunkai Yao812d5b42022-11-16 18:08:50 +0000807 auto inputMQ = std::make_unique<EffectHelper::DataMQ>(ret.inputDataMQ);
Shunkai Yaocb0fc412022-12-15 20:34:32 +0000808 ASSERT_TRUE(inputMQ->isValid());
Shunkai Yao812d5b42022-11-16 18:08:50 +0000809 auto outputMQ = std::make_unique<EffectHelper::DataMQ>(ret.outputDataMQ);
Shunkai Yaocb0fc412022-12-15 20:34:32 +0000810 ASSERT_TRUE(outputMQ->isValid());
Shunkai Yao812d5b42022-11-16 18:08:50 +0000811
812 std::vector<float> buffer;
Shunkai Yaob49631f2023-02-03 01:44:32 +0000813 EXPECT_NO_FATAL_FAILURE(EffectHelper::allocateInputData(common, inputMQ, buffer));
Shunkai Yaoef683a92024-04-18 04:38:17 +0000814 EXPECT_NO_FATAL_FAILURE(EffectHelper::writeToFmq(statusMQ, inputMQ, buffer, mVersion));
Shunkai Yao812d5b42022-11-16 18:08:50 +0000815
Shunkai Yaocb0fc412022-12-15 20:34:32 +0000816 ASSERT_NO_FATAL_FAILURE(command(mEffect, CommandId::START));
817 ASSERT_NO_FATAL_FAILURE(expectState(mEffect, State::PROCESSING));
Shunkai Yao812d5b42022-11-16 18:08:50 +0000818
Shunkai Yaob49631f2023-02-03 01:44:32 +0000819 EXPECT_NO_FATAL_FAILURE(
820 EffectHelper::readFromFmq(statusMQ, 1, outputMQ, buffer.size(), buffer));
Shunkai Yao812d5b42022-11-16 18:08:50 +0000821
Shunkai Yaocb0fc412022-12-15 20:34:32 +0000822 ASSERT_NO_FATAL_FAILURE(command(mEffect, CommandId::STOP));
823 ASSERT_NO_FATAL_FAILURE(expectState(mEffect, State::IDLE));
Shunkai Yao812d5b42022-11-16 18:08:50 +0000824
Shunkai Yaocb0fc412022-12-15 20:34:32 +0000825 ASSERT_NO_FATAL_FAILURE(close(mEffect));
826 ASSERT_NO_FATAL_FAILURE(destroy(mFactory, mEffect));
Shunkai Yao812d5b42022-11-16 18:08:50 +0000827}
828
829// Send data multiple times.
Jaideep Sharmacba42862023-06-23 10:27:39 +0530830// Effects exposing bypass flags or operating in offload mode will be skipped.
831TEST_P(AudioEffectDataPathTest, ProcessDataMultipleTimes) {
Shunkai Yaocb0fc412022-12-15 20:34:32 +0000832 ASSERT_NO_FATAL_FAILURE(create(mFactory, mEffect, mDescriptor));
Shunkai Yao812d5b42022-11-16 18:08:50 +0000833
834 Parameter::Common common = EffectHelper::createParamCommon(
835 0 /* session */, 1 /* ioHandle */, 44100 /* iSampleRate */, 44100 /* oSampleRate */,
836 kInputFrameCount /* iFrameCount */, kOutputFrameCount /* oFrameCount */);
837 IEffect::OpenEffectReturn ret;
Shunkai Yaocb0fc412022-12-15 20:34:32 +0000838 ASSERT_NO_FATAL_FAILURE(open(mEffect, common, std::nullopt /* specific */, &ret, EX_NONE));
Shunkai Yao812d5b42022-11-16 18:08:50 +0000839 auto statusMQ = std::make_unique<EffectHelper::StatusMQ>(ret.statusMQ);
Shunkai Yaocb0fc412022-12-15 20:34:32 +0000840 ASSERT_TRUE(statusMQ->isValid());
Shunkai Yao812d5b42022-11-16 18:08:50 +0000841 auto inputMQ = std::make_unique<EffectHelper::DataMQ>(ret.inputDataMQ);
Shunkai Yaocb0fc412022-12-15 20:34:32 +0000842 ASSERT_TRUE(inputMQ->isValid());
Shunkai Yao812d5b42022-11-16 18:08:50 +0000843 auto outputMQ = std::make_unique<EffectHelper::DataMQ>(ret.outputDataMQ);
Shunkai Yaocb0fc412022-12-15 20:34:32 +0000844 ASSERT_TRUE(outputMQ->isValid());
Shunkai Yao812d5b42022-11-16 18:08:50 +0000845
846 std::vector<float> buffer;
Shunkai Yaob49631f2023-02-03 01:44:32 +0000847 EXPECT_NO_FATAL_FAILURE(EffectHelper::allocateInputData(common, inputMQ, buffer));
Shunkai Yaoef683a92024-04-18 04:38:17 +0000848 EXPECT_NO_FATAL_FAILURE(EffectHelper::writeToFmq(statusMQ, inputMQ, buffer, mVersion));
Shunkai Yaob49631f2023-02-03 01:44:32 +0000849 EXPECT_NO_FATAL_FAILURE(EffectHelper::readFromFmq(statusMQ, 0, outputMQ, 0, buffer));
Shunkai Yao812d5b42022-11-16 18:08:50 +0000850
Shunkai Yaocb0fc412022-12-15 20:34:32 +0000851 ASSERT_NO_FATAL_FAILURE(command(mEffect, CommandId::START));
852 ASSERT_NO_FATAL_FAILURE(expectState(mEffect, State::PROCESSING));
Shunkai Yao812d5b42022-11-16 18:08:50 +0000853
Shunkai Yaob49631f2023-02-03 01:44:32 +0000854 EXPECT_NO_FATAL_FAILURE(
855 EffectHelper::readFromFmq(statusMQ, 1, outputMQ, buffer.size(), buffer));
Shunkai Yao812d5b42022-11-16 18:08:50 +0000856
Shunkai Yaoef683a92024-04-18 04:38:17 +0000857 EXPECT_NO_FATAL_FAILURE(EffectHelper::writeToFmq(statusMQ, inputMQ, buffer, mVersion));
Shunkai Yaob49631f2023-02-03 01:44:32 +0000858 EXPECT_NO_FATAL_FAILURE(
859 EffectHelper::readFromFmq(statusMQ, 1, outputMQ, buffer.size(), buffer));
Shunkai Yao812d5b42022-11-16 18:08:50 +0000860
Shunkai Yaocb0fc412022-12-15 20:34:32 +0000861 ASSERT_NO_FATAL_FAILURE(command(mEffect, CommandId::STOP));
862 ASSERT_NO_FATAL_FAILURE(expectState(mEffect, State::IDLE));
Shunkai Yaob49631f2023-02-03 01:44:32 +0000863 EXPECT_NO_FATAL_FAILURE(EffectHelper::readFromFmq(statusMQ, 0, outputMQ, 0, buffer));
Shunkai Yao812d5b42022-11-16 18:08:50 +0000864
Shunkai Yaocb0fc412022-12-15 20:34:32 +0000865 ASSERT_NO_FATAL_FAILURE(close(mEffect));
866 ASSERT_NO_FATAL_FAILURE(destroy(mFactory, mEffect));
Shunkai Yao812d5b42022-11-16 18:08:50 +0000867}
868
Shunkai Yaob49631f2023-02-03 01:44:32 +0000869// Send data to processing state effects, stop, and restart.
Jaideep Sharmacba42862023-06-23 10:27:39 +0530870// Effects exposing bypass flags or operating in offload mode will be skipped.
871TEST_P(AudioEffectDataPathTest, ConsumeDataAndRestart) {
Shunkai Yaocb0fc412022-12-15 20:34:32 +0000872 ASSERT_NO_FATAL_FAILURE(create(mFactory, mEffect, mDescriptor));
Shunkai Yao812d5b42022-11-16 18:08:50 +0000873
874 Parameter::Common common = EffectHelper::createParamCommon(
875 0 /* session */, 1 /* ioHandle */, 44100 /* iSampleRate */, 44100 /* oSampleRate */,
876 kInputFrameCount /* iFrameCount */, kOutputFrameCount /* oFrameCount */);
877 IEffect::OpenEffectReturn ret;
Shunkai Yaocb0fc412022-12-15 20:34:32 +0000878 ASSERT_NO_FATAL_FAILURE(open(mEffect, common, std::nullopt /* specific */, &ret, EX_NONE));
Shunkai Yao812d5b42022-11-16 18:08:50 +0000879 auto statusMQ = std::make_unique<EffectHelper::StatusMQ>(ret.statusMQ);
Shunkai Yaocb0fc412022-12-15 20:34:32 +0000880 ASSERT_TRUE(statusMQ->isValid());
Shunkai Yao812d5b42022-11-16 18:08:50 +0000881 auto inputMQ = std::make_unique<EffectHelper::DataMQ>(ret.inputDataMQ);
Shunkai Yaocb0fc412022-12-15 20:34:32 +0000882 ASSERT_TRUE(inputMQ->isValid());
Shunkai Yao812d5b42022-11-16 18:08:50 +0000883 auto outputMQ = std::make_unique<EffectHelper::DataMQ>(ret.outputDataMQ);
Shunkai Yaocb0fc412022-12-15 20:34:32 +0000884 ASSERT_TRUE(outputMQ->isValid());
Shunkai Yao812d5b42022-11-16 18:08:50 +0000885
Shunkai Yaocb0fc412022-12-15 20:34:32 +0000886 ASSERT_NO_FATAL_FAILURE(command(mEffect, CommandId::START));
887 ASSERT_NO_FATAL_FAILURE(expectState(mEffect, State::PROCESSING));
Shunkai Yaob49631f2023-02-03 01:44:32 +0000888 std::vector<float> buffer;
889 EXPECT_NO_FATAL_FAILURE(EffectHelper::allocateInputData(common, inputMQ, buffer));
Shunkai Yaoef683a92024-04-18 04:38:17 +0000890 EXPECT_NO_FATAL_FAILURE(EffectHelper::writeToFmq(statusMQ, inputMQ, buffer, mVersion));
Shunkai Yaob49631f2023-02-03 01:44:32 +0000891 EXPECT_NO_FATAL_FAILURE(
892 EffectHelper::readFromFmq(statusMQ, 1, outputMQ, buffer.size(), buffer));
893
Shunkai Yaocb0fc412022-12-15 20:34:32 +0000894 ASSERT_NO_FATAL_FAILURE(command(mEffect, CommandId::STOP));
895 ASSERT_NO_FATAL_FAILURE(expectState(mEffect, State::IDLE));
Shunkai Yaoef683a92024-04-18 04:38:17 +0000896 EXPECT_NO_FATAL_FAILURE(EffectHelper::writeToFmq(statusMQ, inputMQ, buffer, mVersion));
Shunkai Yaob49631f2023-02-03 01:44:32 +0000897 EXPECT_NO_FATAL_FAILURE(EffectHelper::readFromFmq(statusMQ, 0, outputMQ, 0, buffer));
Shunkai Yao812d5b42022-11-16 18:08:50 +0000898
Shunkai Yaocb0fc412022-12-15 20:34:32 +0000899 ASSERT_NO_FATAL_FAILURE(command(mEffect, CommandId::START));
900 ASSERT_NO_FATAL_FAILURE(expectState(mEffect, State::PROCESSING));
Shunkai Yaob49631f2023-02-03 01:44:32 +0000901 EXPECT_NO_FATAL_FAILURE(
902 EffectHelper::readFromFmq(statusMQ, 1, outputMQ, buffer.size(), buffer));
Shunkai Yao812d5b42022-11-16 18:08:50 +0000903
Shunkai Yaocb0fc412022-12-15 20:34:32 +0000904 ASSERT_NO_FATAL_FAILURE(command(mEffect, CommandId::STOP));
905 ASSERT_NO_FATAL_FAILURE(expectState(mEffect, State::IDLE));
Shunkai Yao812d5b42022-11-16 18:08:50 +0000906
Shunkai Yaocb0fc412022-12-15 20:34:32 +0000907 ASSERT_NO_FATAL_FAILURE(close(mEffect));
908 ASSERT_NO_FATAL_FAILURE(destroy(mFactory, mEffect));
Shunkai Yao812d5b42022-11-16 18:08:50 +0000909}
910
911// Send data to closed effects and expect it not be consumed.
Jaideep Sharmacba42862023-06-23 10:27:39 +0530912// Effects exposing bypass flags or operating in offload mode will be skipped.
913TEST_P(AudioEffectDataPathTest, NotConsumeDataByClosedEffect) {
Shunkai Yaocb0fc412022-12-15 20:34:32 +0000914 ASSERT_NO_FATAL_FAILURE(create(mFactory, mEffect, mDescriptor));
Shunkai Yao812d5b42022-11-16 18:08:50 +0000915
916 Parameter::Common common = EffectHelper::createParamCommon(
917 0 /* session */, 1 /* ioHandle */, 44100 /* iSampleRate */, 44100 /* oSampleRate */,
918 kInputFrameCount /* iFrameCount */, kOutputFrameCount /* oFrameCount */);
919 IEffect::OpenEffectReturn ret;
Shunkai Yaocb0fc412022-12-15 20:34:32 +0000920 ASSERT_NO_FATAL_FAILURE(open(mEffect, common, std::nullopt /* specific */, &ret, EX_NONE));
921 ASSERT_NO_FATAL_FAILURE(close(mEffect));
Shunkai Yao812d5b42022-11-16 18:08:50 +0000922
923 auto statusMQ = std::make_unique<EffectHelper::StatusMQ>(ret.statusMQ);
Shunkai Yaocb0fc412022-12-15 20:34:32 +0000924 ASSERT_TRUE(statusMQ->isValid());
Shunkai Yao812d5b42022-11-16 18:08:50 +0000925 auto inputMQ = std::make_unique<EffectHelper::DataMQ>(ret.inputDataMQ);
Shunkai Yaocb0fc412022-12-15 20:34:32 +0000926 ASSERT_TRUE(inputMQ->isValid());
Shunkai Yao812d5b42022-11-16 18:08:50 +0000927 auto outputMQ = std::make_unique<EffectHelper::DataMQ>(ret.outputDataMQ);
Shunkai Yaocb0fc412022-12-15 20:34:32 +0000928 ASSERT_TRUE(outputMQ->isValid());
Shunkai Yao812d5b42022-11-16 18:08:50 +0000929
930 std::vector<float> buffer;
Shunkai Yaob49631f2023-02-03 01:44:32 +0000931 EXPECT_NO_FATAL_FAILURE(EffectHelper::allocateInputData(common, inputMQ, buffer));
Shunkai Yaoef683a92024-04-18 04:38:17 +0000932 EXPECT_NO_FATAL_FAILURE(EffectHelper::writeToFmq(statusMQ, inputMQ, buffer, mVersion));
Shunkai Yaob49631f2023-02-03 01:44:32 +0000933 EXPECT_NO_FATAL_FAILURE(EffectHelper::readFromFmq(statusMQ, 0, outputMQ, 0, buffer));
Shunkai Yao812d5b42022-11-16 18:08:50 +0000934
Shunkai Yaocb0fc412022-12-15 20:34:32 +0000935 ASSERT_NO_FATAL_FAILURE(destroy(mFactory, mEffect));
Shunkai Yao812d5b42022-11-16 18:08:50 +0000936}
937
938// Send data to multiple effects.
Jaideep Sharmacba42862023-06-23 10:27:39 +0530939// Effects exposing bypass flags or operating in offload mode will be skipped.
940TEST_P(AudioEffectDataPathTest, ConsumeDataMultipleEffects) {
Shunkai Yao812d5b42022-11-16 18:08:50 +0000941 std::shared_ptr<IEffect> effect1, effect2;
Shunkai Yaocb0fc412022-12-15 20:34:32 +0000942 ASSERT_NO_FATAL_FAILURE(create(mFactory, effect1, mDescriptor));
943 ASSERT_NO_FATAL_FAILURE(create(mFactory, effect2, mDescriptor));
Shunkai Yao812d5b42022-11-16 18:08:50 +0000944
945 Parameter::Common common1 = EffectHelper::createParamCommon(
946 0 /* session */, 1 /* ioHandle */, 44100 /* iSampleRate */, 44100 /* oSampleRate */,
947 kInputFrameCount /* iFrameCount */, kOutputFrameCount /* oFrameCount */);
948 Parameter::Common common2 = EffectHelper::createParamCommon(
949 1 /* session */, 1 /* ioHandle */, 48000 /* iSampleRate */, 48000 /* oSampleRate */,
950 2 * kInputFrameCount /* iFrameCount */, 2 * kOutputFrameCount /* oFrameCount */);
951 IEffect::OpenEffectReturn ret1, ret2;
952 ASSERT_NO_FATAL_FAILURE(open(effect1, common1, std::nullopt /* specific */, &ret1, EX_NONE));
953 ASSERT_NO_FATAL_FAILURE(open(effect2, common2, std::nullopt /* specific */, &ret2, EX_NONE));
954 ASSERT_NO_FATAL_FAILURE(command(effect1, CommandId::START));
955 ASSERT_NO_FATAL_FAILURE(expectState(effect1, State::PROCESSING));
956 ASSERT_NO_FATAL_FAILURE(command(effect2, CommandId::START));
957 ASSERT_NO_FATAL_FAILURE(expectState(effect2, State::PROCESSING));
958
959 auto statusMQ1 = std::make_unique<EffectHelper::StatusMQ>(ret1.statusMQ);
Shunkai Yaocb0fc412022-12-15 20:34:32 +0000960 ASSERT_TRUE(statusMQ1->isValid());
Shunkai Yao812d5b42022-11-16 18:08:50 +0000961 auto inputMQ1 = std::make_unique<EffectHelper::DataMQ>(ret1.inputDataMQ);
Shunkai Yaocb0fc412022-12-15 20:34:32 +0000962 ASSERT_TRUE(inputMQ1->isValid());
Shunkai Yao812d5b42022-11-16 18:08:50 +0000963 auto outputMQ1 = std::make_unique<EffectHelper::DataMQ>(ret1.outputDataMQ);
Shunkai Yaocb0fc412022-12-15 20:34:32 +0000964 ASSERT_TRUE(outputMQ1->isValid());
Shunkai Yao812d5b42022-11-16 18:08:50 +0000965
966 std::vector<float> buffer1, buffer2;
Shunkai Yaob49631f2023-02-03 01:44:32 +0000967 EXPECT_NO_FATAL_FAILURE(EffectHelper::allocateInputData(common1, inputMQ1, buffer1));
Shunkai Yaoef683a92024-04-18 04:38:17 +0000968 EXPECT_NO_FATAL_FAILURE(EffectHelper::writeToFmq(statusMQ1, inputMQ1, buffer1, mVersion));
Shunkai Yaob49631f2023-02-03 01:44:32 +0000969 EXPECT_NO_FATAL_FAILURE(
970 EffectHelper::readFromFmq(statusMQ1, 1, outputMQ1, buffer1.size(), buffer1));
Shunkai Yao812d5b42022-11-16 18:08:50 +0000971
972 auto statusMQ2 = std::make_unique<EffectHelper::StatusMQ>(ret2.statusMQ);
Shunkai Yaocb0fc412022-12-15 20:34:32 +0000973 ASSERT_TRUE(statusMQ2->isValid());
Shunkai Yao812d5b42022-11-16 18:08:50 +0000974 auto inputMQ2 = std::make_unique<EffectHelper::DataMQ>(ret2.inputDataMQ);
Shunkai Yaocb0fc412022-12-15 20:34:32 +0000975 ASSERT_TRUE(inputMQ2->isValid());
Shunkai Yao812d5b42022-11-16 18:08:50 +0000976 auto outputMQ2 = std::make_unique<EffectHelper::DataMQ>(ret2.outputDataMQ);
Shunkai Yaocb0fc412022-12-15 20:34:32 +0000977 ASSERT_TRUE(outputMQ2->isValid());
Shunkai Yaob49631f2023-02-03 01:44:32 +0000978 EXPECT_NO_FATAL_FAILURE(EffectHelper::allocateInputData(common2, inputMQ2, buffer2));
Shunkai Yaoef683a92024-04-18 04:38:17 +0000979 EXPECT_NO_FATAL_FAILURE(EffectHelper::writeToFmq(statusMQ2, inputMQ2, buffer2, mVersion));
Shunkai Yaob49631f2023-02-03 01:44:32 +0000980 EXPECT_NO_FATAL_FAILURE(
981 EffectHelper::readFromFmq(statusMQ2, 1, outputMQ2, buffer2.size(), buffer2));
Shunkai Yao812d5b42022-11-16 18:08:50 +0000982
983 ASSERT_NO_FATAL_FAILURE(command(effect1, CommandId::STOP));
984 ASSERT_NO_FATAL_FAILURE(expectState(effect1, State::IDLE));
985 ASSERT_NO_FATAL_FAILURE(close(effect1));
986 ASSERT_NO_FATAL_FAILURE(destroy(mFactory, effect1));
987
988 ASSERT_NO_FATAL_FAILURE(command(effect2, CommandId::STOP));
989 ASSERT_NO_FATAL_FAILURE(expectState(effect2, State::IDLE));
990 ASSERT_NO_FATAL_FAILURE(close(effect2));
991 ASSERT_NO_FATAL_FAILURE(destroy(mFactory, effect2));
992}
993
994INSTANTIATE_TEST_SUITE_P(
995 SingleEffectInstanceTest, AudioEffectTest,
996 ::testing::Combine(testing::ValuesIn(
997 EffectFactoryHelper::getAllEffectDescriptors(IFactory::descriptor))),
998 [](const testing::TestParamInfo<AudioEffectTest::ParamType>& info) {
Shunkai Yaocb0fc412022-12-15 20:34:32 +0000999 auto descriptor = std::get<PARAM_INSTANCE_NAME>(info.param).second;
Jaideep Sharmae4c7a962023-06-14 19:14:44 +05301000 std::string name = getPrefix(descriptor);
Shunkai Yao812d5b42022-11-16 18:08:50 +00001001 std::replace_if(
1002 name.begin(), name.end(), [](const char c) { return !std::isalnum(c); }, '_');
1003 return name;
1004 });
Shunkai Yaoa4ab38c2022-10-14 01:07:47 +00001005GTEST_ALLOW_UNINSTANTIATED_PARAMETERIZED_TEST(AudioEffectTest);
Shunkai Yao67b1be62022-07-13 05:01:42 +00001006
Jaideep Sharmacba42862023-06-23 10:27:39 +05301007INSTANTIATE_TEST_SUITE_P(
1008 SingleEffectInstanceTest, AudioEffectDataPathTest,
1009 ::testing::Combine(testing::ValuesIn(
1010 EffectFactoryHelper::getAllEffectDescriptors(IFactory::descriptor))),
1011 [](const testing::TestParamInfo<AudioEffectDataPathTest::ParamType>& info) {
1012 auto descriptor = std::get<PARAM_INSTANCE_NAME>(info.param).second;
1013 std::string name = getPrefix(descriptor);
1014 std::replace_if(
1015 name.begin(), name.end(), [](const char c) { return !std::isalnum(c); }, '_');
1016 return name;
1017 });
1018
1019GTEST_ALLOW_UNINSTANTIATED_PARAMETERIZED_TEST(AudioEffectDataPathTest);
1020
Shunkai Yao67b1be62022-07-13 05:01:42 +00001021int main(int argc, char** argv) {
1022 ::testing::InitGoogleTest(&argc, argv);
Jaideep Sharma74498412023-09-13 15:25:25 +05301023 ::testing::UnitTest::GetInstance()->listeners().Append(new TestExecutionTracer());
Shunkai Yao67b1be62022-07-13 05:01:42 +00001024 ABinderProcess_setThreadPoolMaxThreadCount(1);
1025 ABinderProcess_startThreadPool();
1026 return RUN_ALL_TESTS();
Shunkai Yaoa4ab38c2022-10-14 01:07:47 +00001027}