blob: 4693f102cb04a55079cf7d8a67234ab33bc74d2d [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 Yao9f9fe922024-03-04 21:23:04 +000045using aidl::android::hardware::audio::effect::kReopenSupportedVersion;
Shunkai Yaoea24c1a2022-09-28 17:39:23 +000046using aidl::android::hardware::audio::effect::Parameter;
47using aidl::android::hardware::audio::effect::State;
Shunkai Yao5df4e6c2023-01-10 03:20:00 +000048using aidl::android::media::audio::common::AudioDeviceDescription;
49using aidl::android::media::audio::common::AudioDeviceType;
50using aidl::android::media::audio::common::AudioMode;
51using aidl::android::media::audio::common::AudioSource;
Jaideep Sharma74498412023-09-13 15:25:25 +053052using android::hardware::audio::common::testing::detail::TestExecutionTracer;
Shunkai Yao67b1be62022-07-13 05:01:42 +000053
Shunkai Yao812d5b42022-11-16 18:08:50 +000054enum ParamName { PARAM_INSTANCE_NAME };
Shunkai Yaocb0fc412022-12-15 20:34:32 +000055using EffectTestParam = std::tuple<std::pair<std::shared_ptr<IFactory>, Descriptor>>;
Shunkai Yao812d5b42022-11-16 18:08:50 +000056
57class AudioEffectTest : public testing::TestWithParam<EffectTestParam>, public EffectHelper {
Shunkai Yao45905172022-08-24 18:14:02 +000058 public:
Shunkai Yaocb0fc412022-12-15 20:34:32 +000059 AudioEffectTest() {
60 std::tie(mFactory, mDescriptor) = std::get<PARAM_INSTANCE_NAME>(GetParam());
61 }
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 Yao5df4e6c2023-01-10 03:20:00 +000079
80 void setAndGetParameter(Parameter::Id id, const Parameter& set) {
81 Parameter get;
82 EXPECT_IS_OK(mEffect->setParameter(set));
83 EXPECT_IS_OK(mEffect->getParameter(id, &get));
Shunkai Yaoeea19942023-02-16 02:31:24 +000084 EXPECT_EQ(set, get) << set.toString() << "\n vs \n" << get.toString();
Shunkai Yao5df4e6c2023-01-10 03:20:00 +000085 }
Shunkai Yao45905172022-08-24 18:14:02 +000086};
87
Jaideep Sharmacba42862023-06-23 10:27:39 +053088class AudioEffectDataPathTest : public AudioEffectTest {
Shunkai Yao8771cec2023-09-20 22:46:59 +000089 public:
90 void SetUp() override {
91 AudioEffectTest::SetUp();
92 SKIP_TEST_IF_DATA_UNSUPPORTED(mDescriptor.common.flags);
93 }
Jaideep Sharmacba42862023-06-23 10:27:39 +053094};
95
Shunkai Yao812d5b42022-11-16 18:08:50 +000096TEST_P(AudioEffectTest, SetupAndTearDown) {
97 // Intentionally empty test body.
Shunkai Yao45905172022-08-24 18:14:02 +000098}
99
Shunkai Yao812d5b42022-11-16 18:08:50 +0000100TEST_P(AudioEffectTest, CreateAndDestroy) {
Shunkai Yaocb0fc412022-12-15 20:34:32 +0000101 ASSERT_NO_FATAL_FAILURE(create(mFactory, mEffect, mDescriptor));
102 ASSERT_NO_FATAL_FAILURE(destroy(mFactory, mEffect));
Shunkai Yao45905172022-08-24 18:14:02 +0000103}
104
Shunkai Yao812d5b42022-11-16 18:08:50 +0000105TEST_P(AudioEffectTest, OpenAndClose) {
Shunkai Yaocb0fc412022-12-15 20:34:32 +0000106 ASSERT_NO_FATAL_FAILURE(create(mFactory, mEffect, mDescriptor));
107 ASSERT_NO_FATAL_FAILURE(open(mEffect));
108 ASSERT_NO_FATAL_FAILURE(close(mEffect));
109 ASSERT_NO_FATAL_FAILURE(destroy(mFactory, mEffect));
Shunkai Yao45905172022-08-24 18:14:02 +0000110}
111
Shunkai Yao812d5b42022-11-16 18:08:50 +0000112TEST_P(AudioEffectTest, CloseUnopenedEffect) {
Shunkai Yaocb0fc412022-12-15 20:34:32 +0000113 ASSERT_NO_FATAL_FAILURE(create(mFactory, mEffect, mDescriptor));
114 ASSERT_NO_FATAL_FAILURE(close(mEffect));
115 ASSERT_NO_FATAL_FAILURE(destroy(mFactory, mEffect));
Shunkai Yao45905172022-08-24 18:14:02 +0000116}
117
Shunkai Yao812d5b42022-11-16 18:08:50 +0000118TEST_P(AudioEffectTest, DoubleOpenAndClose) {
119 std::shared_ptr<IEffect> effect1, effect2;
Shunkai Yaocb0fc412022-12-15 20:34:32 +0000120 ASSERT_NO_FATAL_FAILURE(create(mFactory, effect1, mDescriptor));
121 ASSERT_NO_FATAL_FAILURE(create(mFactory, effect2, mDescriptor));
Shunkai Yao812d5b42022-11-16 18:08:50 +0000122 ASSERT_NO_FATAL_FAILURE(open(effect1));
123 ASSERT_NO_FATAL_FAILURE(open(effect2, 1 /* session */));
124 ASSERT_NO_FATAL_FAILURE(close(effect1));
125 ASSERT_NO_FATAL_FAILURE(close(effect2));
126 ASSERT_NO_FATAL_FAILURE(destroy(mFactory, effect1));
127 ASSERT_NO_FATAL_FAILURE(destroy(mFactory, effect2));
Shunkai Yao45905172022-08-24 18:14:02 +0000128}
129
Shunkai Yao812d5b42022-11-16 18:08:50 +0000130TEST_P(AudioEffectTest, TripleOpenAndClose) {
131 std::shared_ptr<IEffect> effect1, effect2, effect3;
Shunkai Yaocb0fc412022-12-15 20:34:32 +0000132 ASSERT_NO_FATAL_FAILURE(create(mFactory, effect1, mDescriptor));
133 ASSERT_NO_FATAL_FAILURE(create(mFactory, effect2, mDescriptor));
134 ASSERT_NO_FATAL_FAILURE(create(mFactory, effect3, mDescriptor));
Shunkai Yao812d5b42022-11-16 18:08:50 +0000135 ASSERT_NO_FATAL_FAILURE(open(effect1));
136 ASSERT_NO_FATAL_FAILURE(open(effect2, 1 /* session */));
137 ASSERT_NO_FATAL_FAILURE(open(effect3, 2 /* session */));
138 ASSERT_NO_FATAL_FAILURE(close(effect1));
139 ASSERT_NO_FATAL_FAILURE(close(effect2));
140 ASSERT_NO_FATAL_FAILURE(close(effect3));
141 ASSERT_NO_FATAL_FAILURE(destroy(mFactory, effect1));
142 ASSERT_NO_FATAL_FAILURE(destroy(mFactory, effect2));
143 ASSERT_NO_FATAL_FAILURE(destroy(mFactory, effect3));
144}
Shunkai Yao45905172022-08-24 18:14:02 +0000145
Shunkai Yao812d5b42022-11-16 18:08:50 +0000146TEST_P(AudioEffectTest, GetDescritorBeforeOpen) {
Shunkai Yao812d5b42022-11-16 18:08:50 +0000147 Descriptor desc;
Shunkai Yaocb0fc412022-12-15 20:34:32 +0000148 ASSERT_NO_FATAL_FAILURE(create(mFactory, mEffect, mDescriptor));
149 ASSERT_NO_FATAL_FAILURE(getDescriptor(mEffect, desc));
Shunkai Yao4c4f3cd2023-02-28 01:50:40 +0000150 EXPECT_EQ(mDescriptor.common.id.type, desc.common.id.type);
151 EXPECT_EQ(mDescriptor.common.id.uuid, desc.common.id.uuid);
152 EXPECT_EQ(mDescriptor.common.name, desc.common.name);
153 EXPECT_EQ(mDescriptor.common.implementor, desc.common.implementor);
Shunkai Yaocb0fc412022-12-15 20:34:32 +0000154 // Effect implementation Must fill in implementor and name
Shunkai Yao812d5b42022-11-16 18:08:50 +0000155 EXPECT_NE("", desc.common.name);
156 EXPECT_NE("", desc.common.implementor);
Shunkai Yaocb0fc412022-12-15 20:34:32 +0000157 ASSERT_NO_FATAL_FAILURE(destroy(mFactory, mEffect));
Shunkai Yao812d5b42022-11-16 18:08:50 +0000158}
159
160TEST_P(AudioEffectTest, GetDescritorAfterOpen) {
Shunkai Yao812d5b42022-11-16 18:08:50 +0000161 Descriptor beforeOpen, afterOpen, afterClose;
Shunkai Yaocb0fc412022-12-15 20:34:32 +0000162 ASSERT_NO_FATAL_FAILURE(create(mFactory, mEffect, mDescriptor));
163 ASSERT_NO_FATAL_FAILURE(getDescriptor(mEffect, beforeOpen));
164 ASSERT_NO_FATAL_FAILURE(open(mEffect));
165 ASSERT_NO_FATAL_FAILURE(getDescriptor(mEffect, afterOpen));
Shunkai Yao812d5b42022-11-16 18:08:50 +0000166 EXPECT_EQ(beforeOpen.toString(), afterOpen.toString()) << "\n"
167 << beforeOpen.toString() << "\n"
168 << afterOpen.toString();
Shunkai Yaocb0fc412022-12-15 20:34:32 +0000169 ASSERT_NO_FATAL_FAILURE(close(mEffect));
170 ASSERT_NO_FATAL_FAILURE(getDescriptor(mEffect, afterClose));
Shunkai Yao812d5b42022-11-16 18:08:50 +0000171 EXPECT_EQ(beforeOpen.toString(), afterClose.toString()) << "\n"
172 << beforeOpen.toString() << "\n"
173 << afterClose.toString();
Shunkai Yaocb0fc412022-12-15 20:34:32 +0000174 ASSERT_NO_FATAL_FAILURE(destroy(mFactory, mEffect));
Shunkai Yao812d5b42022-11-16 18:08:50 +0000175}
176
177TEST_P(AudioEffectTest, DescriptorExistAndUnique) {
Shunkai Yao812d5b42022-11-16 18:08:50 +0000178 Descriptor desc;
179
180 auto descList = EffectFactoryHelper::getAllEffectDescriptors(IFactory::descriptor);
181 std::set<Descriptor::Identity> idSet;
182 for (const auto& it : descList) {
Shunkai Yaocb0fc412022-12-15 20:34:32 +0000183 auto& id = it.second.common.id;
Shunkai Yao812d5b42022-11-16 18:08:50 +0000184 EXPECT_EQ(0ul, idSet.count(id));
185 idSet.insert(id);
Shunkai Yao45905172022-08-24 18:14:02 +0000186 }
Shunkai Yao812d5b42022-11-16 18:08:50 +0000187
Shunkai Yaocb0fc412022-12-15 20:34:32 +0000188 ASSERT_NO_FATAL_FAILURE(create(mFactory, mEffect, mDescriptor));
189 ASSERT_NO_FATAL_FAILURE(getDescriptor(mEffect, desc));
Shunkai Yao4c4f3cd2023-02-28 01:50:40 +0000190 int uuidCount = std::count_if(idSet.begin(), idSet.end(), [&](const auto& id) {
191 return id.uuid == desc.common.id.uuid && id.type == desc.common.id.type;
192 });
193
194 EXPECT_EQ(1, uuidCount);
Shunkai Yaocb0fc412022-12-15 20:34:32 +0000195 ASSERT_NO_FATAL_FAILURE(destroy(mFactory, mEffect));
Shunkai Yao45905172022-08-24 18:14:02 +0000196}
197
Shunkai Yaoea24c1a2022-09-28 17:39:23 +0000198/// State testing.
199// An effect instance is in INIT state by default after it was created.
Shunkai Yaoa4ab38c2022-10-14 01:07:47 +0000200TEST_P(AudioEffectTest, InitStateAfterCreation) {
Shunkai Yaocb0fc412022-12-15 20:34:32 +0000201 ASSERT_NO_FATAL_FAILURE(create(mFactory, mEffect, mDescriptor));
202 ASSERT_NO_FATAL_FAILURE(expectState(mEffect, State::INIT));
203 ASSERT_NO_FATAL_FAILURE(destroy(mFactory, mEffect));
Shunkai Yaoea24c1a2022-09-28 17:39:23 +0000204}
205
Shunkai Yao812d5b42022-11-16 18:08:50 +0000206// An effect instance transfer to IDLE state after IEffect.ASSERT_NO_FATAL_FAILURE(open().
Shunkai Yaoa4ab38c2022-10-14 01:07:47 +0000207TEST_P(AudioEffectTest, IdleStateAfterOpen) {
Shunkai Yaocb0fc412022-12-15 20:34:32 +0000208 ASSERT_NO_FATAL_FAILURE(create(mFactory, mEffect, mDescriptor));
209 ASSERT_NO_FATAL_FAILURE(open(mEffect));
210 ASSERT_NO_FATAL_FAILURE(expectState(mEffect, State::IDLE));
211 ASSERT_NO_FATAL_FAILURE(close(mEffect));
212 ASSERT_NO_FATAL_FAILURE(destroy(mFactory, mEffect));
Shunkai Yaoea24c1a2022-09-28 17:39:23 +0000213}
214
215// An effect instance is in PROCESSING state after it receive an START command.
Shunkai Yaoa4ab38c2022-10-14 01:07:47 +0000216TEST_P(AudioEffectTest, ProcessingStateAfterStart) {
Shunkai Yaocb0fc412022-12-15 20:34:32 +0000217 ASSERT_NO_FATAL_FAILURE(create(mFactory, mEffect, mDescriptor));
218 ASSERT_NO_FATAL_FAILURE(expectState(mEffect, State::INIT));
219 ASSERT_NO_FATAL_FAILURE(open(mEffect));
220 ASSERT_NO_FATAL_FAILURE(expectState(mEffect, State::IDLE));
221 ASSERT_NO_FATAL_FAILURE(command(mEffect, CommandId::START));
222 ASSERT_NO_FATAL_FAILURE(expectState(mEffect, State::PROCESSING));
223 ASSERT_NO_FATAL_FAILURE(command(mEffect, CommandId::STOP));
224 ASSERT_NO_FATAL_FAILURE(close(mEffect));
225 ASSERT_NO_FATAL_FAILURE(destroy(mFactory, mEffect));
Shunkai Yaoea24c1a2022-09-28 17:39:23 +0000226}
227
228// An effect instance transfer to IDLE state after Command.Id.STOP in PROCESSING state.
Shunkai Yaoa4ab38c2022-10-14 01:07:47 +0000229TEST_P(AudioEffectTest, IdleStateAfterStop) {
Shunkai Yaocb0fc412022-12-15 20:34:32 +0000230 ASSERT_NO_FATAL_FAILURE(create(mFactory, mEffect, mDescriptor));
231 ASSERT_NO_FATAL_FAILURE(open(mEffect));
232 ASSERT_NO_FATAL_FAILURE(command(mEffect, CommandId::START));
233 ASSERT_NO_FATAL_FAILURE(expectState(mEffect, State::PROCESSING));
234 ASSERT_NO_FATAL_FAILURE(command(mEffect, CommandId::STOP));
235 ASSERT_NO_FATAL_FAILURE(expectState(mEffect, State::IDLE));
236 ASSERT_NO_FATAL_FAILURE(close(mEffect));
237 ASSERT_NO_FATAL_FAILURE(destroy(mFactory, mEffect));
Shunkai Yaoea24c1a2022-09-28 17:39:23 +0000238}
239
240// An effect instance transfer to IDLE state after Command.Id.RESET in PROCESSING state.
Shunkai Yaoa4ab38c2022-10-14 01:07:47 +0000241TEST_P(AudioEffectTest, IdleStateAfterReset) {
Shunkai Yaocb0fc412022-12-15 20:34:32 +0000242 ASSERT_NO_FATAL_FAILURE(create(mFactory, mEffect, mDescriptor));
243 ASSERT_NO_FATAL_FAILURE(open(mEffect));
244 ASSERT_NO_FATAL_FAILURE(command(mEffect, CommandId::START));
245 ASSERT_NO_FATAL_FAILURE(expectState(mEffect, State::PROCESSING));
246 ASSERT_NO_FATAL_FAILURE(command(mEffect, CommandId::RESET));
247 ASSERT_NO_FATAL_FAILURE(expectState(mEffect, State::IDLE));
248 ASSERT_NO_FATAL_FAILURE(close(mEffect));
249 ASSERT_NO_FATAL_FAILURE(destroy(mFactory, mEffect));
Shunkai Yaoea24c1a2022-09-28 17:39:23 +0000250}
251
Shunkai Yao812d5b42022-11-16 18:08:50 +0000252// An effect instance transfer to INIT after IEffect.ASSERT_NO_FATAL_FAILURE(close().
Shunkai Yaoa4ab38c2022-10-14 01:07:47 +0000253TEST_P(AudioEffectTest, InitStateAfterClose) {
Shunkai Yaocb0fc412022-12-15 20:34:32 +0000254 ASSERT_NO_FATAL_FAILURE(create(mFactory, mEffect, mDescriptor));
255 ASSERT_NO_FATAL_FAILURE(open(mEffect));
256 ASSERT_NO_FATAL_FAILURE(command(mEffect, CommandId::START));
257 ASSERT_NO_FATAL_FAILURE(command(mEffect, CommandId::STOP));
258 ASSERT_NO_FATAL_FAILURE(close(mEffect));
259 ASSERT_NO_FATAL_FAILURE(expectState(mEffect, State::INIT));
260 ASSERT_NO_FATAL_FAILURE(destroy(mFactory, mEffect));
Shunkai Yaoea24c1a2022-09-28 17:39:23 +0000261}
262
263// An effect instance shouldn't accept any command before open.
Shunkai Yaoa4ab38c2022-10-14 01:07:47 +0000264TEST_P(AudioEffectTest, NoCommandAcceptedBeforeOpen) {
Shunkai Yaocb0fc412022-12-15 20:34:32 +0000265 ASSERT_NO_FATAL_FAILURE(create(mFactory, mEffect, mDescriptor));
266 ASSERT_NO_FATAL_FAILURE(command(mEffect, CommandId::START, EX_ILLEGAL_STATE));
267 ASSERT_NO_FATAL_FAILURE(command(mEffect, CommandId::STOP, EX_ILLEGAL_STATE));
268 ASSERT_NO_FATAL_FAILURE(command(mEffect, CommandId::RESET, EX_ILLEGAL_STATE));
269 ASSERT_NO_FATAL_FAILURE(destroy(mFactory, mEffect));
Shunkai Yaoea24c1a2022-09-28 17:39:23 +0000270}
271
272// No-op when receive STOP command in IDLE state.
Shunkai Yaoa4ab38c2022-10-14 01:07:47 +0000273TEST_P(AudioEffectTest, StopCommandInIdleStateNoOp) {
Shunkai Yaocb0fc412022-12-15 20:34:32 +0000274 ASSERT_NO_FATAL_FAILURE(create(mFactory, mEffect, mDescriptor));
275 ASSERT_NO_FATAL_FAILURE(open(mEffect));
276 ASSERT_NO_FATAL_FAILURE(expectState(mEffect, State::IDLE));
277 ASSERT_NO_FATAL_FAILURE(command(mEffect, CommandId::STOP));
278 ASSERT_NO_FATAL_FAILURE(expectState(mEffect, State::IDLE));
279 ASSERT_NO_FATAL_FAILURE(close(mEffect));
280 ASSERT_NO_FATAL_FAILURE(destroy(mFactory, mEffect));
Shunkai Yaoea24c1a2022-09-28 17:39:23 +0000281}
282
Shunkai Yao812d5b42022-11-16 18:08:50 +0000283// No-op when receive RESET command in IDLE state.
Shunkai Yaoa4ab38c2022-10-14 01:07:47 +0000284TEST_P(AudioEffectTest, ResetCommandInIdleStateNoOp) {
Shunkai Yaocb0fc412022-12-15 20:34:32 +0000285 ASSERT_NO_FATAL_FAILURE(create(mFactory, mEffect, mDescriptor));
286 ASSERT_NO_FATAL_FAILURE(open(mEffect));
287 ASSERT_NO_FATAL_FAILURE(expectState(mEffect, State::IDLE));
288 ASSERT_NO_FATAL_FAILURE(command(mEffect, CommandId::RESET));
289 ASSERT_NO_FATAL_FAILURE(expectState(mEffect, State::IDLE));
290 ASSERT_NO_FATAL_FAILURE(close(mEffect));
291 ASSERT_NO_FATAL_FAILURE(destroy(mFactory, mEffect));
Shunkai Yaoea24c1a2022-09-28 17:39:23 +0000292}
293
294// Repeat START and STOP command.
Shunkai Yaoa4ab38c2022-10-14 01:07:47 +0000295TEST_P(AudioEffectTest, RepeatStartAndStop) {
Shunkai Yaocb0fc412022-12-15 20:34:32 +0000296 ASSERT_NO_FATAL_FAILURE(create(mFactory, mEffect, mDescriptor));
297 ASSERT_NO_FATAL_FAILURE(open(mEffect));
298 ASSERT_NO_FATAL_FAILURE(expectState(mEffect, State::IDLE));
299 ASSERT_NO_FATAL_FAILURE(command(mEffect, CommandId::START));
300 ASSERT_NO_FATAL_FAILURE(expectState(mEffect, State::PROCESSING));
301 ASSERT_NO_FATAL_FAILURE(command(mEffect, CommandId::STOP));
302 ASSERT_NO_FATAL_FAILURE(expectState(mEffect, State::IDLE));
Shunkai Yao812d5b42022-11-16 18:08:50 +0000303
Shunkai Yaocb0fc412022-12-15 20:34:32 +0000304 ASSERT_NO_FATAL_FAILURE(command(mEffect, CommandId::START));
305 ASSERT_NO_FATAL_FAILURE(expectState(mEffect, State::PROCESSING));
306 ASSERT_NO_FATAL_FAILURE(command(mEffect, CommandId::STOP));
307 ASSERT_NO_FATAL_FAILURE(expectState(mEffect, State::IDLE));
308 ASSERT_NO_FATAL_FAILURE(close(mEffect));
309 ASSERT_NO_FATAL_FAILURE(destroy(mFactory, mEffect));
Shunkai Yaoea24c1a2022-09-28 17:39:23 +0000310}
311
312// Repeat START and RESET command.
Shunkai Yaoa4ab38c2022-10-14 01:07:47 +0000313TEST_P(AudioEffectTest, RepeatStartAndReset) {
Shunkai Yaocb0fc412022-12-15 20:34:32 +0000314 ASSERT_NO_FATAL_FAILURE(create(mFactory, mEffect, mDescriptor));
315 ASSERT_NO_FATAL_FAILURE(open(mEffect));
316 ASSERT_NO_FATAL_FAILURE(expectState(mEffect, State::IDLE));
317 ASSERT_NO_FATAL_FAILURE(command(mEffect, CommandId::START));
318 ASSERT_NO_FATAL_FAILURE(expectState(mEffect, State::PROCESSING));
319 ASSERT_NO_FATAL_FAILURE(command(mEffect, CommandId::RESET));
320 ASSERT_NO_FATAL_FAILURE(expectState(mEffect, State::IDLE));
Shunkai Yao812d5b42022-11-16 18:08:50 +0000321
Shunkai Yaocb0fc412022-12-15 20:34:32 +0000322 ASSERT_NO_FATAL_FAILURE(command(mEffect, CommandId::START));
323 ASSERT_NO_FATAL_FAILURE(expectState(mEffect, State::PROCESSING));
324 ASSERT_NO_FATAL_FAILURE(command(mEffect, CommandId::RESET));
325 ASSERT_NO_FATAL_FAILURE(expectState(mEffect, State::IDLE));
326 ASSERT_NO_FATAL_FAILURE(close(mEffect));
327 ASSERT_NO_FATAL_FAILURE(destroy(mFactory, mEffect));
Shunkai Yaoea24c1a2022-09-28 17:39:23 +0000328}
329
Shunkai Yao812d5b42022-11-16 18:08:50 +0000330// Try to close an effect instance at PROCESSING state.
Shunkai Yaoa4ab38c2022-10-14 01:07:47 +0000331TEST_P(AudioEffectTest, CloseProcessingStateEffects) {
Shunkai Yaocb0fc412022-12-15 20:34:32 +0000332 ASSERT_NO_FATAL_FAILURE(create(mFactory, mEffect, mDescriptor));
333 ASSERT_NO_FATAL_FAILURE(open(mEffect));
334 ASSERT_NO_FATAL_FAILURE(expectState(mEffect, State::IDLE));
335 ASSERT_NO_FATAL_FAILURE(command(mEffect, CommandId::START));
336 ASSERT_NO_FATAL_FAILURE(expectState(mEffect, State::PROCESSING));
Shunkai Yao812d5b42022-11-16 18:08:50 +0000337
Shunkai Yaocb0fc412022-12-15 20:34:32 +0000338 ASSERT_NO_FATAL_FAILURE(close(mEffect, EX_ILLEGAL_STATE));
Shunkai Yao812d5b42022-11-16 18:08:50 +0000339
Shunkai Yaocb0fc412022-12-15 20:34:32 +0000340 ASSERT_NO_FATAL_FAILURE(command(mEffect, CommandId::STOP));
341 ASSERT_NO_FATAL_FAILURE(expectState(mEffect, State::IDLE));
342 ASSERT_NO_FATAL_FAILURE(close(mEffect));
343 ASSERT_NO_FATAL_FAILURE(destroy(mFactory, mEffect));
Shunkai Yaoea24c1a2022-09-28 17:39:23 +0000344}
345
346// Expect EX_ILLEGAL_STATE if the effect instance is not in a proper state to be destroyed.
Shunkai Yaoa4ab38c2022-10-14 01:07:47 +0000347TEST_P(AudioEffectTest, DestroyOpenEffects) {
Shunkai Yaocb0fc412022-12-15 20:34:32 +0000348 ASSERT_NO_FATAL_FAILURE(create(mFactory, mEffect, mDescriptor));
349 ASSERT_NO_FATAL_FAILURE(open(mEffect));
350 ASSERT_NO_FATAL_FAILURE(expectState(mEffect, State::IDLE));
Shunkai Yaoea24c1a2022-09-28 17:39:23 +0000351
Shunkai Yaocb0fc412022-12-15 20:34:32 +0000352 ASSERT_NO_FATAL_FAILURE(destroy(mFactory, mEffect, EX_ILLEGAL_STATE));
353
354 // cleanup
355 ASSERT_NO_FATAL_FAILURE(close(mEffect));
356 ASSERT_NO_FATAL_FAILURE(destroy(mFactory, mEffect));
Shunkai Yao812d5b42022-11-16 18:08:50 +0000357}
358
359// Expect EX_ILLEGAL_STATE if the effect instance is not in a proper state to be destroyed.
360TEST_P(AudioEffectTest, DestroyProcessingEffects) {
Shunkai Yaocb0fc412022-12-15 20:34:32 +0000361 ASSERT_NO_FATAL_FAILURE(create(mFactory, mEffect, mDescriptor));
362 ASSERT_NO_FATAL_FAILURE(open(mEffect));
363 ASSERT_NO_FATAL_FAILURE(expectState(mEffect, State::IDLE));
364 ASSERT_NO_FATAL_FAILURE(command(mEffect, CommandId::START));
365 ASSERT_NO_FATAL_FAILURE(expectState(mEffect, State::PROCESSING));
Shunkai Yao812d5b42022-11-16 18:08:50 +0000366
Shunkai Yaocb0fc412022-12-15 20:34:32 +0000367 ASSERT_NO_FATAL_FAILURE(destroy(mFactory, mEffect, EX_ILLEGAL_STATE));
368
369 // cleanup
370 ASSERT_NO_FATAL_FAILURE(command(mEffect, CommandId::STOP));
371 ASSERT_NO_FATAL_FAILURE(expectState(mEffect, State::IDLE));
372 ASSERT_NO_FATAL_FAILURE(close(mEffect));
373 ASSERT_NO_FATAL_FAILURE(destroy(mFactory, mEffect));
Shunkai Yao812d5b42022-11-16 18:08:50 +0000374}
375
376TEST_P(AudioEffectTest, NormalSequenceStates) {
Shunkai Yaocb0fc412022-12-15 20:34:32 +0000377 ASSERT_NO_FATAL_FAILURE(create(mFactory, mEffect, mDescriptor));
378 ASSERT_NO_FATAL_FAILURE(expectState(mEffect, State::INIT));
379 ASSERT_NO_FATAL_FAILURE(open(mEffect));
380 ASSERT_NO_FATAL_FAILURE(expectState(mEffect, State::IDLE));
381 ASSERT_NO_FATAL_FAILURE(command(mEffect, CommandId::START));
382 ASSERT_NO_FATAL_FAILURE(expectState(mEffect, State::PROCESSING));
383 ASSERT_NO_FATAL_FAILURE(command(mEffect, CommandId::STOP));
384 ASSERT_NO_FATAL_FAILURE(expectState(mEffect, State::IDLE));
385 ASSERT_NO_FATAL_FAILURE(command(mEffect, CommandId::START));
386 ASSERT_NO_FATAL_FAILURE(expectState(mEffect, State::PROCESSING));
387 ASSERT_NO_FATAL_FAILURE(command(mEffect, CommandId::RESET));
388 ASSERT_NO_FATAL_FAILURE(expectState(mEffect, State::IDLE));
389 ASSERT_NO_FATAL_FAILURE(close(mEffect));
390 ASSERT_NO_FATAL_FAILURE(destroy(mFactory, mEffect));
Shunkai Yaoea24c1a2022-09-28 17:39:23 +0000391}
392
393/// Parameter testing.
394// Verify parameters pass in open can be successfully get.
Shunkai Yao812d5b42022-11-16 18:08:50 +0000395TEST_P(AudioEffectTest, VerifyCommonParametersAfterOpen) {
Shunkai Yaocb0fc412022-12-15 20:34:32 +0000396 ASSERT_NO_FATAL_FAILURE(create(mFactory, mEffect, mDescriptor));
Shunkai Yao812d5b42022-11-16 18:08:50 +0000397
398 Parameter::Common common = EffectHelper::createParamCommon();
399 IEffect::OpenEffectReturn ret;
Shunkai Yaocb0fc412022-12-15 20:34:32 +0000400 ASSERT_NO_FATAL_FAILURE(open(mEffect, common, std::nullopt /* specific */, &ret, EX_NONE));
Shunkai Yao812d5b42022-11-16 18:08:50 +0000401
402 Parameter get = Parameter(), expect = Parameter();
403 expect.set<Parameter::common>(common);
404 Parameter::Id id;
405 id.set<Parameter::Id::commonTag>(Parameter::common);
Shunkai Yaocb0fc412022-12-15 20:34:32 +0000406 EXPECT_IS_OK(mEffect->getParameter(id, &get));
Shunkai Yaoeea19942023-02-16 02:31:24 +0000407 EXPECT_EQ(expect, get) << expect.toString() << "\n vs \n" << get.toString();
Shunkai Yao812d5b42022-11-16 18:08:50 +0000408
Shunkai Yaocb0fc412022-12-15 20:34:32 +0000409 ASSERT_NO_FATAL_FAILURE(close(mEffect));
410 ASSERT_NO_FATAL_FAILURE(destroy(mFactory, mEffect));
Shunkai Yaoea24c1a2022-09-28 17:39:23 +0000411}
412
413// Verify parameters pass in set can be successfully get.
Shunkai Yao812d5b42022-11-16 18:08:50 +0000414TEST_P(AudioEffectTest, SetAndGetCommonParameter) {
Shunkai Yaocb0fc412022-12-15 20:34:32 +0000415 ASSERT_NO_FATAL_FAILURE(create(mFactory, mEffect, mDescriptor));
416 ASSERT_NO_FATAL_FAILURE(open(mEffect));
Shunkai Yao812d5b42022-11-16 18:08:50 +0000417
418 Parameter::Common common = EffectHelper::createParamCommon(
419 0 /* session */, 1 /* ioHandle */, 44100 /* iSampleRate */, 44100 /* oSampleRate */);
Shunkai Yao5df4e6c2023-01-10 03:20:00 +0000420 Parameter::Id id = Parameter::Id::make<Parameter::Id::commonTag>(Parameter::common);
421 ASSERT_NO_FATAL_FAILURE(setAndGetParameter(id, Parameter::make<Parameter::common>(common)));
Shunkai Yao812d5b42022-11-16 18:08:50 +0000422
Shunkai Yaocb0fc412022-12-15 20:34:32 +0000423 ASSERT_NO_FATAL_FAILURE(close(mEffect));
424 ASSERT_NO_FATAL_FAILURE(destroy(mFactory, mEffect));
Shunkai Yaoea24c1a2022-09-28 17:39:23 +0000425}
426
Shunkai Yao812d5b42022-11-16 18:08:50 +0000427// Verify parameters set and get in PROCESSING state.
Shunkai Yaoa4ab38c2022-10-14 01:07:47 +0000428TEST_P(AudioEffectTest, SetAndGetParameterInProcessing) {
Shunkai Yaocb0fc412022-12-15 20:34:32 +0000429 ASSERT_NO_FATAL_FAILURE(create(mFactory, mEffect, mDescriptor));
430 ASSERT_NO_FATAL_FAILURE(open(mEffect));
431 ASSERT_NO_FATAL_FAILURE(command(mEffect, CommandId::START));
432 ASSERT_NO_FATAL_FAILURE(expectState(mEffect, State::PROCESSING));
Shunkai Yao812d5b42022-11-16 18:08:50 +0000433
434 Parameter::Common common = EffectHelper::createParamCommon(
435 0 /* session */, 1 /* ioHandle */, 44100 /* iSampleRate */, 44100 /* oSampleRate */);
Shunkai Yao5df4e6c2023-01-10 03:20:00 +0000436 Parameter::Id id = Parameter::Id::make<Parameter::Id::commonTag>(Parameter::common);
437 ASSERT_NO_FATAL_FAILURE(setAndGetParameter(id, Parameter::make<Parameter::common>(common)));
Shunkai Yao812d5b42022-11-16 18:08:50 +0000438
Shunkai Yaocb0fc412022-12-15 20:34:32 +0000439 ASSERT_NO_FATAL_FAILURE(command(mEffect, CommandId::STOP));
440 ASSERT_NO_FATAL_FAILURE(close(mEffect));
441 ASSERT_NO_FATAL_FAILURE(destroy(mFactory, mEffect));
Shunkai Yaoea24c1a2022-09-28 17:39:23 +0000442}
443
Shunkai Yao812d5b42022-11-16 18:08:50 +0000444// Verify parameters set and get in IDLE state.
445TEST_P(AudioEffectTest, SetAndGetParameterInIdle) {
Shunkai Yaocb0fc412022-12-15 20:34:32 +0000446 ASSERT_NO_FATAL_FAILURE(create(mFactory, mEffect, mDescriptor));
447 ASSERT_NO_FATAL_FAILURE(open(mEffect));
448 ASSERT_NO_FATAL_FAILURE(command(mEffect, CommandId::START));
449 ASSERT_NO_FATAL_FAILURE(expectState(mEffect, State::PROCESSING));
450 ASSERT_NO_FATAL_FAILURE(command(mEffect, CommandId::STOP));
451 ASSERT_NO_FATAL_FAILURE(expectState(mEffect, State::IDLE));
Shunkai Yao812d5b42022-11-16 18:08:50 +0000452
453 Parameter::Common common = EffectHelper::createParamCommon(
454 0 /* session */, 1 /* ioHandle */, 44100 /* iSampleRate */, 44100 /* oSampleRate */);
Shunkai Yao5df4e6c2023-01-10 03:20:00 +0000455 Parameter::Id id = Parameter::Id::make<Parameter::Id::commonTag>(Parameter::common);
456 ASSERT_NO_FATAL_FAILURE(setAndGetParameter(id, Parameter::make<Parameter::common>(common)));
Shunkai Yao812d5b42022-11-16 18:08:50 +0000457
Shunkai Yaocb0fc412022-12-15 20:34:32 +0000458 ASSERT_NO_FATAL_FAILURE(close(mEffect));
459 ASSERT_NO_FATAL_FAILURE(destroy(mFactory, mEffect));
Shunkai Yaoea24c1a2022-09-28 17:39:23 +0000460}
461
Shunkai Yao812d5b42022-11-16 18:08:50 +0000462// Verify Parameters kept after stop.
463TEST_P(AudioEffectTest, SetAndGetParameterAfterStop) {
Shunkai Yaocb0fc412022-12-15 20:34:32 +0000464 ASSERT_NO_FATAL_FAILURE(create(mFactory, mEffect, mDescriptor));
465 ASSERT_NO_FATAL_FAILURE(open(mEffect));
466 ASSERT_NO_FATAL_FAILURE(command(mEffect, CommandId::START));
467 ASSERT_NO_FATAL_FAILURE(expectState(mEffect, State::PROCESSING));
Shunkai Yaoea24c1a2022-09-28 17:39:23 +0000468
Shunkai Yao812d5b42022-11-16 18:08:50 +0000469 Parameter::Common common = EffectHelper::createParamCommon(
470 0 /* session */, 1 /* ioHandle */, 44100 /* iSampleRate */, 44100 /* oSampleRate */);
Shunkai Yao5df4e6c2023-01-10 03:20:00 +0000471 Parameter::Id id = Parameter::Id::make<Parameter::Id::commonTag>(Parameter::common);
472 ASSERT_NO_FATAL_FAILURE(setAndGetParameter(id, Parameter::make<Parameter::common>(common)));
Shunkai Yaoa4ab38c2022-10-14 01:07:47 +0000473
Shunkai Yaocb0fc412022-12-15 20:34:32 +0000474 ASSERT_NO_FATAL_FAILURE(command(mEffect, CommandId::STOP));
475 ASSERT_NO_FATAL_FAILURE(expectState(mEffect, State::IDLE));
Shunkai Yaocb0fc412022-12-15 20:34:32 +0000476 ASSERT_NO_FATAL_FAILURE(close(mEffect));
477 ASSERT_NO_FATAL_FAILURE(destroy(mFactory, mEffect));
Shunkai Yaoa4ab38c2022-10-14 01:07:47 +0000478}
479
Shunkai Yao812d5b42022-11-16 18:08:50 +0000480// Verify Parameters kept after reset.
481TEST_P(AudioEffectTest, SetAndGetParameterAfterReset) {
Shunkai Yaocb0fc412022-12-15 20:34:32 +0000482 ASSERT_NO_FATAL_FAILURE(create(mFactory, mEffect, mDescriptor));
483 ASSERT_NO_FATAL_FAILURE(open(mEffect));
Shunkai Yao812d5b42022-11-16 18:08:50 +0000484
Shunkai Yaocb0fc412022-12-15 20:34:32 +0000485 ASSERT_NO_FATAL_FAILURE(command(mEffect, CommandId::START));
486 ASSERT_NO_FATAL_FAILURE(expectState(mEffect, State::PROCESSING));
Shunkai Yao812d5b42022-11-16 18:08:50 +0000487
488 Parameter::Common common = EffectHelper::createParamCommon(
489 0 /* session */, 1 /* ioHandle */, 44100 /* iSampleRate */, 44100 /* oSampleRate */);
Shunkai Yao5df4e6c2023-01-10 03:20:00 +0000490 Parameter::Id id = Parameter::Id::make<Parameter::Id::commonTag>(Parameter::common);
491 ASSERT_NO_FATAL_FAILURE(setAndGetParameter(id, Parameter::make<Parameter::common>(common)));
Shunkai Yao812d5b42022-11-16 18:08:50 +0000492
Shunkai Yaocb0fc412022-12-15 20:34:32 +0000493 ASSERT_NO_FATAL_FAILURE(command(mEffect, CommandId::RESET));
494 ASSERT_NO_FATAL_FAILURE(expectState(mEffect, State::IDLE));
Shunkai Yao812d5b42022-11-16 18:08:50 +0000495
Shunkai Yao5df4e6c2023-01-10 03:20:00 +0000496 ASSERT_NO_FATAL_FAILURE(setAndGetParameter(id, Parameter::make<Parameter::common>(common)));
Shunkai Yao812d5b42022-11-16 18:08:50 +0000497
Shunkai Yao5df4e6c2023-01-10 03:20:00 +0000498 ASSERT_NO_FATAL_FAILURE(command(mEffect, CommandId::STOP));
499 ASSERT_NO_FATAL_FAILURE(expectState(mEffect, State::IDLE));
Shunkai Yaocb0fc412022-12-15 20:34:32 +0000500 ASSERT_NO_FATAL_FAILURE(close(mEffect));
501 ASSERT_NO_FATAL_FAILURE(destroy(mFactory, mEffect));
Shunkai Yao812d5b42022-11-16 18:08:50 +0000502}
Shunkai Yao5df4e6c2023-01-10 03:20:00 +0000503
504// Set and get AudioDeviceDescription in Parameter
505TEST_P(AudioEffectTest, SetAndGetParameterDeviceDescription) {
Shunkai Yao92cd7482023-09-18 17:37:45 +0000506 if (!mDescriptor.common.flags.deviceIndication) {
507 GTEST_SKIP() << "Skipping test as effect does not support deviceIndication"
508 << mDescriptor.common.flags.toString();
509 }
510
Shunkai Yao5df4e6c2023-01-10 03:20:00 +0000511 ASSERT_NO_FATAL_FAILURE(create(mFactory, mEffect, mDescriptor));
512 ASSERT_NO_FATAL_FAILURE(open(mEffect));
513
514 ASSERT_NO_FATAL_FAILURE(command(mEffect, CommandId::START));
515 ASSERT_NO_FATAL_FAILURE(expectState(mEffect, State::PROCESSING));
516
517 std::vector<AudioDeviceDescription> deviceDescs = {
518 {.type = AudioDeviceType::IN_DEFAULT,
519 .connection = AudioDeviceDescription::CONNECTION_ANALOG},
520 {.type = AudioDeviceType::IN_DEVICE,
521 .connection = AudioDeviceDescription::CONNECTION_BT_A2DP}};
522 Parameter::Id id = Parameter::Id::make<Parameter::Id::commonTag>(Parameter::deviceDescription);
523 ASSERT_NO_FATAL_FAILURE(
524 setAndGetParameter(id, Parameter::make<Parameter::deviceDescription>(deviceDescs)));
525
526 ASSERT_NO_FATAL_FAILURE(command(mEffect, CommandId::STOP));
527 ASSERT_NO_FATAL_FAILURE(expectState(mEffect, State::IDLE));
528 ASSERT_NO_FATAL_FAILURE(close(mEffect));
529 ASSERT_NO_FATAL_FAILURE(destroy(mFactory, mEffect));
530}
531
532// Set and get AudioMode in Parameter
533TEST_P(AudioEffectTest, SetAndGetParameterAudioMode) {
Shunkai Yao92cd7482023-09-18 17:37:45 +0000534 if (!mDescriptor.common.flags.audioModeIndication) {
535 GTEST_SKIP() << "Skipping test as effect does not support audioModeIndication"
536 << mDescriptor.common.flags.toString();
537 }
538
Shunkai Yao5df4e6c2023-01-10 03:20:00 +0000539 ASSERT_NO_FATAL_FAILURE(create(mFactory, mEffect, mDescriptor));
540 ASSERT_NO_FATAL_FAILURE(open(mEffect));
541
542 ASSERT_NO_FATAL_FAILURE(command(mEffect, CommandId::START));
543 ASSERT_NO_FATAL_FAILURE(expectState(mEffect, State::PROCESSING));
544
545 Parameter::Id id = Parameter::Id::make<Parameter::Id::commonTag>(Parameter::mode);
546 ASSERT_NO_FATAL_FAILURE(
547 setAndGetParameter(id, Parameter::make<Parameter::mode>(AudioMode::NORMAL)));
548 ASSERT_NO_FATAL_FAILURE(
549 setAndGetParameter(id, Parameter::make<Parameter::mode>(AudioMode::IN_COMMUNICATION)));
550
551 ASSERT_NO_FATAL_FAILURE(command(mEffect, CommandId::STOP));
552 ASSERT_NO_FATAL_FAILURE(expectState(mEffect, State::IDLE));
553 ASSERT_NO_FATAL_FAILURE(close(mEffect));
554 ASSERT_NO_FATAL_FAILURE(destroy(mFactory, mEffect));
555}
556
557// Set and get AudioSource in Parameter
558TEST_P(AudioEffectTest, SetAndGetParameterAudioSource) {
Shunkai Yao92cd7482023-09-18 17:37:45 +0000559 if (!mDescriptor.common.flags.audioSourceIndication) {
560 GTEST_SKIP() << "Skipping test as effect does not support audioSourceIndication"
561 << mDescriptor.common.flags.toString();
562 }
563
Shunkai Yao5df4e6c2023-01-10 03:20:00 +0000564 ASSERT_NO_FATAL_FAILURE(create(mFactory, mEffect, mDescriptor));
565 ASSERT_NO_FATAL_FAILURE(open(mEffect));
566
567 ASSERT_NO_FATAL_FAILURE(command(mEffect, CommandId::START));
568 ASSERT_NO_FATAL_FAILURE(expectState(mEffect, State::PROCESSING));
569
570 Parameter::Id id = Parameter::Id::make<Parameter::Id::commonTag>(Parameter::source);
571 ASSERT_NO_FATAL_FAILURE(
572 setAndGetParameter(id, Parameter::make<Parameter::source>(AudioSource::DEFAULT)));
573 ASSERT_NO_FATAL_FAILURE(setAndGetParameter(
574 id, Parameter::make<Parameter::source>(AudioSource::VOICE_RECOGNITION)));
575
576 ASSERT_NO_FATAL_FAILURE(command(mEffect, CommandId::STOP));
577 ASSERT_NO_FATAL_FAILURE(expectState(mEffect, State::IDLE));
578 ASSERT_NO_FATAL_FAILURE(close(mEffect));
579 ASSERT_NO_FATAL_FAILURE(destroy(mFactory, mEffect));
580}
581
582// Set and get VolumeStereo in Parameter
583TEST_P(AudioEffectTest, SetAndGetParameterVolume) {
Shunkai Yao92cd7482023-09-18 17:37:45 +0000584 if (mDescriptor.common.flags.volume == Flags::Volume::NONE) {
585 GTEST_SKIP() << "Skipping test as effect does not support volume"
586 << mDescriptor.common.flags.toString();
587 }
588
Shunkai Yao5df4e6c2023-01-10 03:20:00 +0000589 ASSERT_NO_FATAL_FAILURE(create(mFactory, mEffect, mDescriptor));
590 ASSERT_NO_FATAL_FAILURE(open(mEffect));
591
592 ASSERT_NO_FATAL_FAILURE(command(mEffect, CommandId::START));
593 ASSERT_NO_FATAL_FAILURE(expectState(mEffect, State::PROCESSING));
594
595 Parameter::Id id = Parameter::Id::make<Parameter::Id::commonTag>(Parameter::volumeStereo);
596 Parameter::VolumeStereo volume = {.left = 10.0, .right = 10.0};
David Li1a56fdd2023-11-14 23:31:53 +0800597 if (mDescriptor.common.flags.volume == Flags::Volume::CTRL) {
598 Parameter get;
599 EXPECT_IS_OK(mEffect->setParameter(volume));
600 EXPECT_IS_OK(mEffect->getParameter(id, &get));
601 } else {
602 ASSERT_NO_FATAL_FAILURE(
603 setAndGetParameter(id, Parameter::make<Parameter::volumeStereo>(volume)));
604 }
Shunkai Yao5df4e6c2023-01-10 03:20:00 +0000605
606 ASSERT_NO_FATAL_FAILURE(command(mEffect, CommandId::STOP));
607 ASSERT_NO_FATAL_FAILURE(expectState(mEffect, State::IDLE));
608 ASSERT_NO_FATAL_FAILURE(close(mEffect));
609 ASSERT_NO_FATAL_FAILURE(destroy(mFactory, mEffect));
610}
611
Shunkai Yaod685aed2024-01-30 18:27:38 +0000612/**
613 * Verify DataMqUpdateEventFlag after common parameter setting.
614 * verify reopen sequence.
615 */
616TEST_P(AudioEffectDataPathTest, SetCommonParameterAndReopen) {
Shunkai Yao9f9fe922024-03-04 21:23:04 +0000617 if (!EffectFactoryHelper::isReopenSupported(mFactory)) {
618 GTEST_SKIP() << "Skipping test as effect does not support reopen";
619 }
620
Shunkai Yao65c7c702024-01-09 20:50:53 +0000621 ASSERT_NO_FATAL_FAILURE(create(mFactory, mEffect, mDescriptor));
622
623 Parameter::Common common = EffectHelper::createParamCommon(
624 0 /* session */, 1 /* ioHandle */, 44100 /* iSampleRate */, 44100 /* oSampleRate */,
625 kInputFrameCount /* iFrameCount */, kOutputFrameCount /* oFrameCount */);
626 IEffect::OpenEffectReturn ret;
627 ASSERT_NO_FATAL_FAILURE(open(mEffect, common, std::nullopt /* specific */, &ret, EX_NONE));
628 auto statusMQ = std::make_unique<EffectHelper::StatusMQ>(ret.statusMQ);
629 ASSERT_TRUE(statusMQ->isValid());
630 auto inputMQ = std::make_unique<EffectHelper::DataMQ>(ret.inputDataMQ);
631 ASSERT_TRUE(inputMQ->isValid());
632 auto outputMQ = std::make_unique<EffectHelper::DataMQ>(ret.outputDataMQ);
633 ASSERT_TRUE(outputMQ->isValid());
634
635 Parameter::Id id = Parameter::Id::make<Parameter::Id::commonTag>(Parameter::common);
636 common.input.frameCount++;
637 ASSERT_NO_FATAL_FAILURE(setAndGetParameter(id, Parameter::make<Parameter::common>(common)));
638 ASSERT_TRUE(statusMQ->isValid());
639 expectDataMqUpdateEventFlag(statusMQ);
640 EXPECT_IS_OK(mEffect->reopen(&ret));
641 inputMQ = std::make_unique<EffectHelper::DataMQ>(ret.inputDataMQ);
642 outputMQ = std::make_unique<EffectHelper::DataMQ>(ret.outputDataMQ);
643 ASSERT_TRUE(statusMQ->isValid());
644 ASSERT_TRUE(inputMQ->isValid());
645 ASSERT_TRUE(outputMQ->isValid());
646
647 common.output.frameCount++;
648 ASSERT_NO_FATAL_FAILURE(setAndGetParameter(id, Parameter::make<Parameter::common>(common)));
649 ASSERT_TRUE(statusMQ->isValid());
650 expectDataMqUpdateEventFlag(statusMQ);
651 EXPECT_IS_OK(mEffect->reopen(&ret));
652 inputMQ = std::make_unique<EffectHelper::DataMQ>(ret.inputDataMQ);
653 outputMQ = std::make_unique<EffectHelper::DataMQ>(ret.outputDataMQ);
654 ASSERT_TRUE(statusMQ->isValid());
655 ASSERT_TRUE(inputMQ->isValid());
656 ASSERT_TRUE(outputMQ->isValid());
657
658 ASSERT_NO_FATAL_FAILURE(close(mEffect));
659 ASSERT_NO_FATAL_FAILURE(destroy(mFactory, mEffect));
660}
661
Shunkai Yao812d5b42022-11-16 18:08:50 +0000662/// Data processing test
663// Send data to effects and expect it to be consumed by checking statusMQ.
Jaideep Sharmacba42862023-06-23 10:27:39 +0530664// Effects exposing bypass flags or operating in offload mode will be skipped.
665TEST_P(AudioEffectDataPathTest, ConsumeDataInProcessingState) {
Shunkai Yaocb0fc412022-12-15 20:34:32 +0000666 ASSERT_NO_FATAL_FAILURE(create(mFactory, mEffect, mDescriptor));
Shunkai Yao812d5b42022-11-16 18:08:50 +0000667
668 Parameter::Common common = EffectHelper::createParamCommon(
669 0 /* session */, 1 /* ioHandle */, 44100 /* iSampleRate */, 44100 /* oSampleRate */,
670 kInputFrameCount /* iFrameCount */, kOutputFrameCount /* oFrameCount */);
671 IEffect::OpenEffectReturn ret;
Shunkai Yaocb0fc412022-12-15 20:34:32 +0000672 ASSERT_NO_FATAL_FAILURE(open(mEffect, common, std::nullopt /* specific */, &ret, EX_NONE));
Shunkai Yao812d5b42022-11-16 18:08:50 +0000673 auto statusMQ = std::make_unique<EffectHelper::StatusMQ>(ret.statusMQ);
Shunkai Yaocb0fc412022-12-15 20:34:32 +0000674 ASSERT_TRUE(statusMQ->isValid());
Shunkai Yao812d5b42022-11-16 18:08:50 +0000675 auto inputMQ = std::make_unique<EffectHelper::DataMQ>(ret.inputDataMQ);
Shunkai Yaocb0fc412022-12-15 20:34:32 +0000676 ASSERT_TRUE(inputMQ->isValid());
Shunkai Yao812d5b42022-11-16 18:08:50 +0000677 auto outputMQ = std::make_unique<EffectHelper::DataMQ>(ret.outputDataMQ);
Shunkai Yaocb0fc412022-12-15 20:34:32 +0000678 ASSERT_TRUE(outputMQ->isValid());
Shunkai Yao812d5b42022-11-16 18:08:50 +0000679
Shunkai Yaocb0fc412022-12-15 20:34:32 +0000680 ASSERT_NO_FATAL_FAILURE(command(mEffect, CommandId::START));
681 ASSERT_NO_FATAL_FAILURE(expectState(mEffect, State::PROCESSING));
Shunkai Yao812d5b42022-11-16 18:08:50 +0000682
683 std::vector<float> buffer;
Shunkai Yaob49631f2023-02-03 01:44:32 +0000684 EXPECT_NO_FATAL_FAILURE(EffectHelper::allocateInputData(common, inputMQ, buffer));
Shunkai Yao41888a22023-04-10 17:13:30 +0000685 EXPECT_NO_FATAL_FAILURE(EffectHelper::writeToFmq(statusMQ, inputMQ, buffer));
Shunkai Yaob49631f2023-02-03 01:44:32 +0000686 EXPECT_NO_FATAL_FAILURE(
687 EffectHelper::readFromFmq(statusMQ, 1, outputMQ, buffer.size(), buffer));
Shunkai Yao812d5b42022-11-16 18:08:50 +0000688
Shunkai Yaocb0fc412022-12-15 20:34:32 +0000689 ASSERT_NO_FATAL_FAILURE(command(mEffect, CommandId::STOP));
690 ASSERT_NO_FATAL_FAILURE(expectState(mEffect, State::IDLE));
Shunkai Yaob49631f2023-02-03 01:44:32 +0000691 EXPECT_NO_FATAL_FAILURE(EffectHelper::readFromFmq(statusMQ, 0, outputMQ, 0, buffer));
Shunkai Yao812d5b42022-11-16 18:08:50 +0000692
Shunkai Yaocb0fc412022-12-15 20:34:32 +0000693 ASSERT_NO_FATAL_FAILURE(close(mEffect));
694 ASSERT_NO_FATAL_FAILURE(destroy(mFactory, mEffect));
Shunkai Yao812d5b42022-11-16 18:08:50 +0000695}
696
697// Send data to effects and expect it to be consumed after effect restart.
Jaideep Sharmacba42862023-06-23 10:27:39 +0530698// Effects exposing bypass flags or operating in offload mode will be skipped.
699TEST_P(AudioEffectDataPathTest, ConsumeDataAfterRestart) {
Shunkai Yaocb0fc412022-12-15 20:34:32 +0000700 ASSERT_NO_FATAL_FAILURE(create(mFactory, mEffect, mDescriptor));
Shunkai Yao812d5b42022-11-16 18:08:50 +0000701
702 Parameter::Common common = EffectHelper::createParamCommon(
703 0 /* session */, 1 /* ioHandle */, 44100 /* iSampleRate */, 44100 /* oSampleRate */,
704 kInputFrameCount /* iFrameCount */, kOutputFrameCount /* oFrameCount */);
705 IEffect::OpenEffectReturn ret;
Shunkai Yaocb0fc412022-12-15 20:34:32 +0000706 ASSERT_NO_FATAL_FAILURE(open(mEffect, common, std::nullopt /* specific */, &ret, EX_NONE));
Shunkai Yao812d5b42022-11-16 18:08:50 +0000707 auto statusMQ = std::make_unique<EffectHelper::StatusMQ>(ret.statusMQ);
Shunkai Yaocb0fc412022-12-15 20:34:32 +0000708 ASSERT_TRUE(statusMQ->isValid());
Shunkai Yao812d5b42022-11-16 18:08:50 +0000709 auto inputMQ = std::make_unique<EffectHelper::DataMQ>(ret.inputDataMQ);
Shunkai Yaocb0fc412022-12-15 20:34:32 +0000710 ASSERT_TRUE(inputMQ->isValid());
Shunkai Yao812d5b42022-11-16 18:08:50 +0000711 auto outputMQ = std::make_unique<EffectHelper::DataMQ>(ret.outputDataMQ);
Shunkai Yaocb0fc412022-12-15 20:34:32 +0000712 ASSERT_TRUE(outputMQ->isValid());
Shunkai Yao812d5b42022-11-16 18:08:50 +0000713
Shunkai Yao812d5b42022-11-16 18:08:50 +0000714 std::vector<float> buffer;
Shunkai Yaob49631f2023-02-03 01:44:32 +0000715 ASSERT_NO_FATAL_FAILURE(command(mEffect, CommandId::START));
716 ASSERT_NO_FATAL_FAILURE(expectState(mEffect, State::PROCESSING));
717 ASSERT_NO_FATAL_FAILURE(command(mEffect, CommandId::STOP));
718 ASSERT_NO_FATAL_FAILURE(expectState(mEffect, State::IDLE));
719 EXPECT_NO_FATAL_FAILURE(
720 EffectHelper::readFromFmq(statusMQ, 0, outputMQ, buffer.size(), buffer));
721 ASSERT_NO_FATAL_FAILURE(command(mEffect, CommandId::START));
722 ASSERT_NO_FATAL_FAILURE(expectState(mEffect, State::PROCESSING));
723
724 EXPECT_NO_FATAL_FAILURE(EffectHelper::allocateInputData(common, inputMQ, buffer));
Shunkai Yao41888a22023-04-10 17:13:30 +0000725 EXPECT_NO_FATAL_FAILURE(EffectHelper::writeToFmq(statusMQ, inputMQ, buffer));
Shunkai Yaob49631f2023-02-03 01:44:32 +0000726 EXPECT_NO_FATAL_FAILURE(
727 EffectHelper::readFromFmq(statusMQ, 1, outputMQ, buffer.size(), buffer));
Shunkai Yao812d5b42022-11-16 18:08:50 +0000728
Shunkai Yaocb0fc412022-12-15 20:34:32 +0000729 ASSERT_NO_FATAL_FAILURE(command(mEffect, CommandId::STOP));
730 ASSERT_NO_FATAL_FAILURE(expectState(mEffect, State::IDLE));
Shunkai Yaob49631f2023-02-03 01:44:32 +0000731 EXPECT_NO_FATAL_FAILURE(EffectHelper::readFromFmq(statusMQ, 0, outputMQ, 0, buffer));
Shunkai Yao812d5b42022-11-16 18:08:50 +0000732
Shunkai Yaocb0fc412022-12-15 20:34:32 +0000733 ASSERT_NO_FATAL_FAILURE(close(mEffect));
734 ASSERT_NO_FATAL_FAILURE(destroy(mFactory, mEffect));
Shunkai Yao812d5b42022-11-16 18:08:50 +0000735}
736
Shunkai Yao65c7c702024-01-09 20:50:53 +0000737// Send data to effects and expect it to be consumed after effect reopen (IO AudioConfig change).
738// Effects exposing bypass flags or operating in offload mode will be skipped.
739TEST_P(AudioEffectDataPathTest, ConsumeDataAfterReopen) {
Shunkai Yao9f9fe922024-03-04 21:23:04 +0000740 if (!EffectFactoryHelper::isReopenSupported(mFactory)) {
741 GTEST_SKIP() << "Skipping test as effect does not support reopen";
742 }
743
Shunkai Yao65c7c702024-01-09 20:50:53 +0000744 ASSERT_NO_FATAL_FAILURE(create(mFactory, mEffect, mDescriptor));
745
746 Parameter::Common common = EffectHelper::createParamCommon(
747 0 /* session */, 1 /* ioHandle */, 44100 /* iSampleRate */, 44100 /* oSampleRate */,
748 kInputFrameCount /* iFrameCount */, kOutputFrameCount /* oFrameCount */);
749 IEffect::OpenEffectReturn ret;
750 ASSERT_NO_FATAL_FAILURE(open(mEffect, common, std::nullopt /* specific */, &ret, EX_NONE));
751 auto statusMQ = std::make_unique<EffectHelper::StatusMQ>(ret.statusMQ);
752 ASSERT_TRUE(statusMQ->isValid());
753 auto inputMQ = std::make_unique<EffectHelper::DataMQ>(ret.inputDataMQ);
754 ASSERT_TRUE(inputMQ->isValid());
755 auto outputMQ = std::make_unique<EffectHelper::DataMQ>(ret.outputDataMQ);
756 ASSERT_TRUE(outputMQ->isValid());
757
758 std::vector<float> buffer;
759 ASSERT_NO_FATAL_FAILURE(command(mEffect, CommandId::START));
760 ASSERT_NO_FATAL_FAILURE(expectState(mEffect, State::PROCESSING));
761 EXPECT_NO_FATAL_FAILURE(EffectHelper::allocateInputData(common, inputMQ, buffer));
762 EXPECT_NO_FATAL_FAILURE(EffectHelper::writeToFmq(statusMQ, inputMQ, buffer));
763 EXPECT_NO_FATAL_FAILURE(
764 EffectHelper::readFromFmq(statusMQ, 1, outputMQ, buffer.size(), buffer));
765
766 // set a new common parameter with different IO frameCount, reopen
767 Parameter::Id id = Parameter::Id::make<Parameter::Id::commonTag>(Parameter::common);
768 common.input.frameCount += 4;
769 common.output.frameCount += 4;
770 ASSERT_NO_FATAL_FAILURE(setAndGetParameter(id, Parameter::make<Parameter::common>(common)));
771 ASSERT_TRUE(statusMQ->isValid());
772 expectDataMqUpdateEventFlag(statusMQ);
773 EXPECT_IS_OK(mEffect->reopen(&ret));
774 inputMQ = std::make_unique<EffectHelper::DataMQ>(ret.inputDataMQ);
775 outputMQ = std::make_unique<EffectHelper::DataMQ>(ret.outputDataMQ);
776 ASSERT_TRUE(statusMQ->isValid());
777 ASSERT_TRUE(inputMQ->isValid());
778 ASSERT_TRUE(outputMQ->isValid());
779
780 // verify data consume again
781 EXPECT_NO_FATAL_FAILURE(EffectHelper::allocateInputData(common, inputMQ, buffer));
782 EXPECT_NO_FATAL_FAILURE(EffectHelper::writeToFmq(statusMQ, inputMQ, buffer));
783 EXPECT_NO_FATAL_FAILURE(
784 EffectHelper::readFromFmq(statusMQ, 1, outputMQ, buffer.size(), buffer));
785
786 ASSERT_NO_FATAL_FAILURE(command(mEffect, CommandId::STOP));
787 ASSERT_NO_FATAL_FAILURE(expectState(mEffect, State::IDLE));
788 EXPECT_NO_FATAL_FAILURE(EffectHelper::readFromFmq(statusMQ, 0, outputMQ, 0, buffer));
789
790 ASSERT_NO_FATAL_FAILURE(close(mEffect));
791 ASSERT_NO_FATAL_FAILURE(destroy(mFactory, mEffect));
792}
793
Shunkai Yao812d5b42022-11-16 18:08:50 +0000794// Send data to IDLE effects and expect it to be consumed after effect start.
Jaideep Sharmacba42862023-06-23 10:27:39 +0530795// Effects exposing bypass flags or operating in offload mode will be skipped.
796TEST_P(AudioEffectDataPathTest, SendDataAtIdleAndConsumeDataInProcessing) {
Shunkai Yaocb0fc412022-12-15 20:34:32 +0000797 ASSERT_NO_FATAL_FAILURE(create(mFactory, mEffect, mDescriptor));
Shunkai Yao812d5b42022-11-16 18:08:50 +0000798
799 Parameter::Common common = EffectHelper::createParamCommon(
800 0 /* session */, 1 /* ioHandle */, 44100 /* iSampleRate */, 44100 /* oSampleRate */,
801 kInputFrameCount /* iFrameCount */, kOutputFrameCount /* oFrameCount */);
802 IEffect::OpenEffectReturn ret;
Shunkai Yaocb0fc412022-12-15 20:34:32 +0000803 ASSERT_NO_FATAL_FAILURE(open(mEffect, common, std::nullopt /* specific */, &ret, EX_NONE));
Shunkai Yao812d5b42022-11-16 18:08:50 +0000804 auto statusMQ = std::make_unique<EffectHelper::StatusMQ>(ret.statusMQ);
Shunkai Yaocb0fc412022-12-15 20:34:32 +0000805 ASSERT_TRUE(statusMQ->isValid());
Shunkai Yao812d5b42022-11-16 18:08:50 +0000806 auto inputMQ = std::make_unique<EffectHelper::DataMQ>(ret.inputDataMQ);
Shunkai Yaocb0fc412022-12-15 20:34:32 +0000807 ASSERT_TRUE(inputMQ->isValid());
Shunkai Yao812d5b42022-11-16 18:08:50 +0000808 auto outputMQ = std::make_unique<EffectHelper::DataMQ>(ret.outputDataMQ);
Shunkai Yaocb0fc412022-12-15 20:34:32 +0000809 ASSERT_TRUE(outputMQ->isValid());
Shunkai Yao812d5b42022-11-16 18:08:50 +0000810
811 std::vector<float> buffer;
Shunkai Yaob49631f2023-02-03 01:44:32 +0000812 EXPECT_NO_FATAL_FAILURE(EffectHelper::allocateInputData(common, inputMQ, buffer));
Shunkai Yao41888a22023-04-10 17:13:30 +0000813 EXPECT_NO_FATAL_FAILURE(EffectHelper::writeToFmq(statusMQ, inputMQ, buffer));
Shunkai Yao812d5b42022-11-16 18:08:50 +0000814
Shunkai Yaocb0fc412022-12-15 20:34:32 +0000815 ASSERT_NO_FATAL_FAILURE(command(mEffect, CommandId::START));
816 ASSERT_NO_FATAL_FAILURE(expectState(mEffect, State::PROCESSING));
Shunkai Yao812d5b42022-11-16 18:08:50 +0000817
Shunkai Yaob49631f2023-02-03 01:44:32 +0000818 EXPECT_NO_FATAL_FAILURE(
819 EffectHelper::readFromFmq(statusMQ, 1, outputMQ, buffer.size(), buffer));
Shunkai Yao812d5b42022-11-16 18:08:50 +0000820
Shunkai Yaocb0fc412022-12-15 20:34:32 +0000821 ASSERT_NO_FATAL_FAILURE(command(mEffect, CommandId::STOP));
822 ASSERT_NO_FATAL_FAILURE(expectState(mEffect, State::IDLE));
Shunkai Yao812d5b42022-11-16 18:08:50 +0000823
Shunkai Yaocb0fc412022-12-15 20:34:32 +0000824 ASSERT_NO_FATAL_FAILURE(close(mEffect));
825 ASSERT_NO_FATAL_FAILURE(destroy(mFactory, mEffect));
Shunkai Yao812d5b42022-11-16 18:08:50 +0000826}
827
828// Send data multiple times.
Jaideep Sharmacba42862023-06-23 10:27:39 +0530829// Effects exposing bypass flags or operating in offload mode will be skipped.
830TEST_P(AudioEffectDataPathTest, ProcessDataMultipleTimes) {
Shunkai Yaocb0fc412022-12-15 20:34:32 +0000831 ASSERT_NO_FATAL_FAILURE(create(mFactory, mEffect, mDescriptor));
Shunkai Yao812d5b42022-11-16 18:08:50 +0000832
833 Parameter::Common common = EffectHelper::createParamCommon(
834 0 /* session */, 1 /* ioHandle */, 44100 /* iSampleRate */, 44100 /* oSampleRate */,
835 kInputFrameCount /* iFrameCount */, kOutputFrameCount /* oFrameCount */);
836 IEffect::OpenEffectReturn ret;
Shunkai Yaocb0fc412022-12-15 20:34:32 +0000837 ASSERT_NO_FATAL_FAILURE(open(mEffect, common, std::nullopt /* specific */, &ret, EX_NONE));
Shunkai Yao812d5b42022-11-16 18:08:50 +0000838 auto statusMQ = std::make_unique<EffectHelper::StatusMQ>(ret.statusMQ);
Shunkai Yaocb0fc412022-12-15 20:34:32 +0000839 ASSERT_TRUE(statusMQ->isValid());
Shunkai Yao812d5b42022-11-16 18:08:50 +0000840 auto inputMQ = std::make_unique<EffectHelper::DataMQ>(ret.inputDataMQ);
Shunkai Yaocb0fc412022-12-15 20:34:32 +0000841 ASSERT_TRUE(inputMQ->isValid());
Shunkai Yao812d5b42022-11-16 18:08:50 +0000842 auto outputMQ = std::make_unique<EffectHelper::DataMQ>(ret.outputDataMQ);
Shunkai Yaocb0fc412022-12-15 20:34:32 +0000843 ASSERT_TRUE(outputMQ->isValid());
Shunkai Yao812d5b42022-11-16 18:08:50 +0000844
845 std::vector<float> buffer;
Shunkai Yaob49631f2023-02-03 01:44:32 +0000846 EXPECT_NO_FATAL_FAILURE(EffectHelper::allocateInputData(common, inputMQ, buffer));
Shunkai Yao41888a22023-04-10 17:13:30 +0000847 EXPECT_NO_FATAL_FAILURE(EffectHelper::writeToFmq(statusMQ, inputMQ, buffer));
Shunkai Yaob49631f2023-02-03 01:44:32 +0000848 EXPECT_NO_FATAL_FAILURE(EffectHelper::readFromFmq(statusMQ, 0, outputMQ, 0, buffer));
Shunkai Yao812d5b42022-11-16 18:08:50 +0000849
Shunkai Yaocb0fc412022-12-15 20:34:32 +0000850 ASSERT_NO_FATAL_FAILURE(command(mEffect, CommandId::START));
851 ASSERT_NO_FATAL_FAILURE(expectState(mEffect, State::PROCESSING));
Shunkai Yao812d5b42022-11-16 18:08:50 +0000852
Shunkai Yaob49631f2023-02-03 01:44:32 +0000853 EXPECT_NO_FATAL_FAILURE(
854 EffectHelper::readFromFmq(statusMQ, 1, outputMQ, buffer.size(), buffer));
Shunkai Yao812d5b42022-11-16 18:08:50 +0000855
Shunkai Yao41888a22023-04-10 17:13:30 +0000856 EXPECT_NO_FATAL_FAILURE(EffectHelper::writeToFmq(statusMQ, inputMQ, buffer));
Shunkai Yaob49631f2023-02-03 01:44:32 +0000857 EXPECT_NO_FATAL_FAILURE(
858 EffectHelper::readFromFmq(statusMQ, 1, outputMQ, buffer.size(), buffer));
Shunkai Yao812d5b42022-11-16 18:08:50 +0000859
Shunkai Yaocb0fc412022-12-15 20:34:32 +0000860 ASSERT_NO_FATAL_FAILURE(command(mEffect, CommandId::STOP));
861 ASSERT_NO_FATAL_FAILURE(expectState(mEffect, State::IDLE));
Shunkai Yaob49631f2023-02-03 01:44:32 +0000862 EXPECT_NO_FATAL_FAILURE(EffectHelper::readFromFmq(statusMQ, 0, outputMQ, 0, buffer));
Shunkai Yao812d5b42022-11-16 18:08:50 +0000863
Shunkai Yaocb0fc412022-12-15 20:34:32 +0000864 ASSERT_NO_FATAL_FAILURE(close(mEffect));
865 ASSERT_NO_FATAL_FAILURE(destroy(mFactory, mEffect));
Shunkai Yao812d5b42022-11-16 18:08:50 +0000866}
867
Shunkai Yaob49631f2023-02-03 01:44:32 +0000868// Send data to processing state effects, stop, and restart.
Jaideep Sharmacba42862023-06-23 10:27:39 +0530869// Effects exposing bypass flags or operating in offload mode will be skipped.
870TEST_P(AudioEffectDataPathTest, ConsumeDataAndRestart) {
Shunkai Yaocb0fc412022-12-15 20:34:32 +0000871 ASSERT_NO_FATAL_FAILURE(create(mFactory, mEffect, mDescriptor));
Shunkai Yao812d5b42022-11-16 18:08:50 +0000872
873 Parameter::Common common = EffectHelper::createParamCommon(
874 0 /* session */, 1 /* ioHandle */, 44100 /* iSampleRate */, 44100 /* oSampleRate */,
875 kInputFrameCount /* iFrameCount */, kOutputFrameCount /* oFrameCount */);
876 IEffect::OpenEffectReturn ret;
Shunkai Yaocb0fc412022-12-15 20:34:32 +0000877 ASSERT_NO_FATAL_FAILURE(open(mEffect, common, std::nullopt /* specific */, &ret, EX_NONE));
Shunkai Yao812d5b42022-11-16 18:08:50 +0000878 auto statusMQ = std::make_unique<EffectHelper::StatusMQ>(ret.statusMQ);
Shunkai Yaocb0fc412022-12-15 20:34:32 +0000879 ASSERT_TRUE(statusMQ->isValid());
Shunkai Yao812d5b42022-11-16 18:08:50 +0000880 auto inputMQ = std::make_unique<EffectHelper::DataMQ>(ret.inputDataMQ);
Shunkai Yaocb0fc412022-12-15 20:34:32 +0000881 ASSERT_TRUE(inputMQ->isValid());
Shunkai Yao812d5b42022-11-16 18:08:50 +0000882 auto outputMQ = std::make_unique<EffectHelper::DataMQ>(ret.outputDataMQ);
Shunkai Yaocb0fc412022-12-15 20:34:32 +0000883 ASSERT_TRUE(outputMQ->isValid());
Shunkai Yao812d5b42022-11-16 18:08:50 +0000884
Shunkai Yaocb0fc412022-12-15 20:34:32 +0000885 ASSERT_NO_FATAL_FAILURE(command(mEffect, CommandId::START));
886 ASSERT_NO_FATAL_FAILURE(expectState(mEffect, State::PROCESSING));
Shunkai Yaob49631f2023-02-03 01:44:32 +0000887 std::vector<float> buffer;
888 EXPECT_NO_FATAL_FAILURE(EffectHelper::allocateInputData(common, inputMQ, buffer));
Shunkai Yao41888a22023-04-10 17:13:30 +0000889 EXPECT_NO_FATAL_FAILURE(EffectHelper::writeToFmq(statusMQ, inputMQ, buffer));
Shunkai Yaob49631f2023-02-03 01:44:32 +0000890 EXPECT_NO_FATAL_FAILURE(
891 EffectHelper::readFromFmq(statusMQ, 1, outputMQ, buffer.size(), buffer));
892
Shunkai Yaocb0fc412022-12-15 20:34:32 +0000893 ASSERT_NO_FATAL_FAILURE(command(mEffect, CommandId::STOP));
894 ASSERT_NO_FATAL_FAILURE(expectState(mEffect, State::IDLE));
Shunkai Yao41888a22023-04-10 17:13:30 +0000895 EXPECT_NO_FATAL_FAILURE(EffectHelper::writeToFmq(statusMQ, inputMQ, buffer));
Shunkai Yaob49631f2023-02-03 01:44:32 +0000896 EXPECT_NO_FATAL_FAILURE(EffectHelper::readFromFmq(statusMQ, 0, outputMQ, 0, buffer));
Shunkai Yao812d5b42022-11-16 18:08:50 +0000897
Shunkai Yaocb0fc412022-12-15 20:34:32 +0000898 ASSERT_NO_FATAL_FAILURE(command(mEffect, CommandId::START));
899 ASSERT_NO_FATAL_FAILURE(expectState(mEffect, State::PROCESSING));
Shunkai Yaob49631f2023-02-03 01:44:32 +0000900 EXPECT_NO_FATAL_FAILURE(
901 EffectHelper::readFromFmq(statusMQ, 1, outputMQ, buffer.size(), buffer));
Shunkai Yao812d5b42022-11-16 18:08:50 +0000902
Shunkai Yaocb0fc412022-12-15 20:34:32 +0000903 ASSERT_NO_FATAL_FAILURE(command(mEffect, CommandId::STOP));
904 ASSERT_NO_FATAL_FAILURE(expectState(mEffect, State::IDLE));
Shunkai Yao812d5b42022-11-16 18:08:50 +0000905
Shunkai Yaocb0fc412022-12-15 20:34:32 +0000906 ASSERT_NO_FATAL_FAILURE(close(mEffect));
907 ASSERT_NO_FATAL_FAILURE(destroy(mFactory, mEffect));
Shunkai Yao812d5b42022-11-16 18:08:50 +0000908}
909
910// Send data to closed effects and expect it not be consumed.
Jaideep Sharmacba42862023-06-23 10:27:39 +0530911// Effects exposing bypass flags or operating in offload mode will be skipped.
912TEST_P(AudioEffectDataPathTest, NotConsumeDataByClosedEffect) {
Shunkai Yaocb0fc412022-12-15 20:34:32 +0000913 ASSERT_NO_FATAL_FAILURE(create(mFactory, mEffect, mDescriptor));
Shunkai Yao812d5b42022-11-16 18:08:50 +0000914
915 Parameter::Common common = EffectHelper::createParamCommon(
916 0 /* session */, 1 /* ioHandle */, 44100 /* iSampleRate */, 44100 /* oSampleRate */,
917 kInputFrameCount /* iFrameCount */, kOutputFrameCount /* oFrameCount */);
918 IEffect::OpenEffectReturn ret;
Shunkai Yaocb0fc412022-12-15 20:34:32 +0000919 ASSERT_NO_FATAL_FAILURE(open(mEffect, common, std::nullopt /* specific */, &ret, EX_NONE));
920 ASSERT_NO_FATAL_FAILURE(close(mEffect));
Shunkai Yao812d5b42022-11-16 18:08:50 +0000921
922 auto statusMQ = std::make_unique<EffectHelper::StatusMQ>(ret.statusMQ);
Shunkai Yaocb0fc412022-12-15 20:34:32 +0000923 ASSERT_TRUE(statusMQ->isValid());
Shunkai Yao812d5b42022-11-16 18:08:50 +0000924 auto inputMQ = std::make_unique<EffectHelper::DataMQ>(ret.inputDataMQ);
Shunkai Yaocb0fc412022-12-15 20:34:32 +0000925 ASSERT_TRUE(inputMQ->isValid());
Shunkai Yao812d5b42022-11-16 18:08:50 +0000926 auto outputMQ = std::make_unique<EffectHelper::DataMQ>(ret.outputDataMQ);
Shunkai Yaocb0fc412022-12-15 20:34:32 +0000927 ASSERT_TRUE(outputMQ->isValid());
Shunkai Yao812d5b42022-11-16 18:08:50 +0000928
929 std::vector<float> buffer;
Shunkai Yaob49631f2023-02-03 01:44:32 +0000930 EXPECT_NO_FATAL_FAILURE(EffectHelper::allocateInputData(common, inputMQ, buffer));
Shunkai Yao41888a22023-04-10 17:13:30 +0000931 EXPECT_NO_FATAL_FAILURE(EffectHelper::writeToFmq(statusMQ, inputMQ, buffer));
Shunkai Yaob49631f2023-02-03 01:44:32 +0000932 EXPECT_NO_FATAL_FAILURE(EffectHelper::readFromFmq(statusMQ, 0, outputMQ, 0, buffer));
Shunkai Yao812d5b42022-11-16 18:08:50 +0000933
Shunkai Yaocb0fc412022-12-15 20:34:32 +0000934 ASSERT_NO_FATAL_FAILURE(destroy(mFactory, mEffect));
Shunkai Yao812d5b42022-11-16 18:08:50 +0000935}
936
937// Send data to multiple effects.
Jaideep Sharmacba42862023-06-23 10:27:39 +0530938// Effects exposing bypass flags or operating in offload mode will be skipped.
939TEST_P(AudioEffectDataPathTest, ConsumeDataMultipleEffects) {
Shunkai Yao812d5b42022-11-16 18:08:50 +0000940 std::shared_ptr<IEffect> effect1, effect2;
Shunkai Yaocb0fc412022-12-15 20:34:32 +0000941 ASSERT_NO_FATAL_FAILURE(create(mFactory, effect1, mDescriptor));
942 ASSERT_NO_FATAL_FAILURE(create(mFactory, effect2, mDescriptor));
Shunkai Yao812d5b42022-11-16 18:08:50 +0000943
944 Parameter::Common common1 = EffectHelper::createParamCommon(
945 0 /* session */, 1 /* ioHandle */, 44100 /* iSampleRate */, 44100 /* oSampleRate */,
946 kInputFrameCount /* iFrameCount */, kOutputFrameCount /* oFrameCount */);
947 Parameter::Common common2 = EffectHelper::createParamCommon(
948 1 /* session */, 1 /* ioHandle */, 48000 /* iSampleRate */, 48000 /* oSampleRate */,
949 2 * kInputFrameCount /* iFrameCount */, 2 * kOutputFrameCount /* oFrameCount */);
950 IEffect::OpenEffectReturn ret1, ret2;
951 ASSERT_NO_FATAL_FAILURE(open(effect1, common1, std::nullopt /* specific */, &ret1, EX_NONE));
952 ASSERT_NO_FATAL_FAILURE(open(effect2, common2, std::nullopt /* specific */, &ret2, EX_NONE));
953 ASSERT_NO_FATAL_FAILURE(command(effect1, CommandId::START));
954 ASSERT_NO_FATAL_FAILURE(expectState(effect1, State::PROCESSING));
955 ASSERT_NO_FATAL_FAILURE(command(effect2, CommandId::START));
956 ASSERT_NO_FATAL_FAILURE(expectState(effect2, State::PROCESSING));
957
958 auto statusMQ1 = std::make_unique<EffectHelper::StatusMQ>(ret1.statusMQ);
Shunkai Yaocb0fc412022-12-15 20:34:32 +0000959 ASSERT_TRUE(statusMQ1->isValid());
Shunkai Yao812d5b42022-11-16 18:08:50 +0000960 auto inputMQ1 = std::make_unique<EffectHelper::DataMQ>(ret1.inputDataMQ);
Shunkai Yaocb0fc412022-12-15 20:34:32 +0000961 ASSERT_TRUE(inputMQ1->isValid());
Shunkai Yao812d5b42022-11-16 18:08:50 +0000962 auto outputMQ1 = std::make_unique<EffectHelper::DataMQ>(ret1.outputDataMQ);
Shunkai Yaocb0fc412022-12-15 20:34:32 +0000963 ASSERT_TRUE(outputMQ1->isValid());
Shunkai Yao812d5b42022-11-16 18:08:50 +0000964
965 std::vector<float> buffer1, buffer2;
Shunkai Yaob49631f2023-02-03 01:44:32 +0000966 EXPECT_NO_FATAL_FAILURE(EffectHelper::allocateInputData(common1, inputMQ1, buffer1));
Shunkai Yao41888a22023-04-10 17:13:30 +0000967 EXPECT_NO_FATAL_FAILURE(EffectHelper::writeToFmq(statusMQ1, inputMQ1, buffer1));
Shunkai Yaob49631f2023-02-03 01:44:32 +0000968 EXPECT_NO_FATAL_FAILURE(
969 EffectHelper::readFromFmq(statusMQ1, 1, outputMQ1, buffer1.size(), buffer1));
Shunkai Yao812d5b42022-11-16 18:08:50 +0000970
971 auto statusMQ2 = std::make_unique<EffectHelper::StatusMQ>(ret2.statusMQ);
Shunkai Yaocb0fc412022-12-15 20:34:32 +0000972 ASSERT_TRUE(statusMQ2->isValid());
Shunkai Yao812d5b42022-11-16 18:08:50 +0000973 auto inputMQ2 = std::make_unique<EffectHelper::DataMQ>(ret2.inputDataMQ);
Shunkai Yaocb0fc412022-12-15 20:34:32 +0000974 ASSERT_TRUE(inputMQ2->isValid());
Shunkai Yao812d5b42022-11-16 18:08:50 +0000975 auto outputMQ2 = std::make_unique<EffectHelper::DataMQ>(ret2.outputDataMQ);
Shunkai Yaocb0fc412022-12-15 20:34:32 +0000976 ASSERT_TRUE(outputMQ2->isValid());
Shunkai Yaob49631f2023-02-03 01:44:32 +0000977 EXPECT_NO_FATAL_FAILURE(EffectHelper::allocateInputData(common2, inputMQ2, buffer2));
Shunkai Yao41888a22023-04-10 17:13:30 +0000978 EXPECT_NO_FATAL_FAILURE(EffectHelper::writeToFmq(statusMQ2, inputMQ2, buffer2));
Shunkai Yaob49631f2023-02-03 01:44:32 +0000979 EXPECT_NO_FATAL_FAILURE(
980 EffectHelper::readFromFmq(statusMQ2, 1, outputMQ2, buffer2.size(), buffer2));
Shunkai Yao812d5b42022-11-16 18:08:50 +0000981
982 ASSERT_NO_FATAL_FAILURE(command(effect1, CommandId::STOP));
983 ASSERT_NO_FATAL_FAILURE(expectState(effect1, State::IDLE));
984 ASSERT_NO_FATAL_FAILURE(close(effect1));
985 ASSERT_NO_FATAL_FAILURE(destroy(mFactory, effect1));
986
987 ASSERT_NO_FATAL_FAILURE(command(effect2, CommandId::STOP));
988 ASSERT_NO_FATAL_FAILURE(expectState(effect2, State::IDLE));
989 ASSERT_NO_FATAL_FAILURE(close(effect2));
990 ASSERT_NO_FATAL_FAILURE(destroy(mFactory, effect2));
991}
992
993INSTANTIATE_TEST_SUITE_P(
994 SingleEffectInstanceTest, AudioEffectTest,
995 ::testing::Combine(testing::ValuesIn(
996 EffectFactoryHelper::getAllEffectDescriptors(IFactory::descriptor))),
997 [](const testing::TestParamInfo<AudioEffectTest::ParamType>& info) {
Shunkai Yaocb0fc412022-12-15 20:34:32 +0000998 auto descriptor = std::get<PARAM_INSTANCE_NAME>(info.param).second;
Jaideep Sharmae4c7a962023-06-14 19:14:44 +0530999 std::string name = getPrefix(descriptor);
Shunkai Yao812d5b42022-11-16 18:08:50 +00001000 std::replace_if(
1001 name.begin(), name.end(), [](const char c) { return !std::isalnum(c); }, '_');
1002 return name;
1003 });
Shunkai Yaoa4ab38c2022-10-14 01:07:47 +00001004GTEST_ALLOW_UNINSTANTIATED_PARAMETERIZED_TEST(AudioEffectTest);
Shunkai Yao67b1be62022-07-13 05:01:42 +00001005
Jaideep Sharmacba42862023-06-23 10:27:39 +05301006INSTANTIATE_TEST_SUITE_P(
1007 SingleEffectInstanceTest, AudioEffectDataPathTest,
1008 ::testing::Combine(testing::ValuesIn(
1009 EffectFactoryHelper::getAllEffectDescriptors(IFactory::descriptor))),
1010 [](const testing::TestParamInfo<AudioEffectDataPathTest::ParamType>& info) {
1011 auto descriptor = std::get<PARAM_INSTANCE_NAME>(info.param).second;
1012 std::string name = getPrefix(descriptor);
1013 std::replace_if(
1014 name.begin(), name.end(), [](const char c) { return !std::isalnum(c); }, '_');
1015 return name;
1016 });
1017
1018GTEST_ALLOW_UNINSTANTIATED_PARAMETERIZED_TEST(AudioEffectDataPathTest);
1019
Shunkai Yao67b1be62022-07-13 05:01:42 +00001020int main(int argc, char** argv) {
1021 ::testing::InitGoogleTest(&argc, argv);
Jaideep Sharma74498412023-09-13 15:25:25 +05301022 ::testing::UnitTest::GetInstance()->listeners().Append(new TestExecutionTracer());
Shunkai Yao67b1be62022-07-13 05:01:42 +00001023 ABinderProcess_setThreadPoolMaxThreadCount(1);
1024 ABinderProcess_startThreadPool();
1025 return RUN_ALL_TESTS();
Shunkai Yaoa4ab38c2022-10-14 01:07:47 +00001026}