blob: 547982523e37b76939b86e59438b1323a28bb14b [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());
60 }
Shunkai Yaoa4ab38c2022-10-14 01:07:47 +000061
Shunkai Yao812d5b42022-11-16 18:08:50 +000062 void SetUp() override {}
Shunkai Yaocb0fc412022-12-15 20:34:32 +000063
64 void TearDown() override {
65 // Do the cleanup for every test case
66 if (mEffect) {
67 ASSERT_NO_FATAL_FAILURE(commandIgnoreRet(mEffect, CommandId::STOP));
68 ASSERT_NO_FATAL_FAILURE(closeIgnoreRet(mEffect));
69 ASSERT_NO_FATAL_FAILURE(destroyIgnoreRet(mFactory, mEffect));
70 mEffect.reset();
71 }
72 }
Shunkai Yao45905172022-08-24 18:14:02 +000073
Shunkai Yao812d5b42022-11-16 18:08:50 +000074 static const long kInputFrameCount = 0x100, kOutputFrameCount = 0x100;
75 std::shared_ptr<IFactory> mFactory;
Shunkai Yaocb0fc412022-12-15 20:34:32 +000076 std::shared_ptr<IEffect> mEffect;
77 Descriptor mDescriptor;
Shunkai Yao5df4e6c2023-01-10 03:20:00 +000078
79 void setAndGetParameter(Parameter::Id id, const Parameter& set) {
80 Parameter get;
81 EXPECT_IS_OK(mEffect->setParameter(set));
82 EXPECT_IS_OK(mEffect->getParameter(id, &get));
Shunkai Yaoeea19942023-02-16 02:31:24 +000083 EXPECT_EQ(set, get) << set.toString() << "\n vs \n" << get.toString();
Shunkai Yao5df4e6c2023-01-10 03:20:00 +000084 }
Shunkai Yao45905172022-08-24 18:14:02 +000085};
86
Jaideep Sharmacba42862023-06-23 10:27:39 +053087class AudioEffectDataPathTest : public AudioEffectTest {
Shunkai Yao8771cec2023-09-20 22:46:59 +000088 public:
89 void SetUp() override {
90 AudioEffectTest::SetUp();
91 SKIP_TEST_IF_DATA_UNSUPPORTED(mDescriptor.common.flags);
92 }
Jaideep Sharmacba42862023-06-23 10:27:39 +053093};
94
Shunkai Yao812d5b42022-11-16 18:08:50 +000095TEST_P(AudioEffectTest, SetupAndTearDown) {
96 // Intentionally empty test body.
Shunkai Yao45905172022-08-24 18:14:02 +000097}
98
Shunkai Yao812d5b42022-11-16 18:08:50 +000099TEST_P(AudioEffectTest, CreateAndDestroy) {
Shunkai Yaocb0fc412022-12-15 20:34:32 +0000100 ASSERT_NO_FATAL_FAILURE(create(mFactory, mEffect, mDescriptor));
101 ASSERT_NO_FATAL_FAILURE(destroy(mFactory, mEffect));
Shunkai Yao45905172022-08-24 18:14:02 +0000102}
103
Shunkai Yao812d5b42022-11-16 18:08:50 +0000104TEST_P(AudioEffectTest, OpenAndClose) {
Shunkai Yaocb0fc412022-12-15 20:34:32 +0000105 ASSERT_NO_FATAL_FAILURE(create(mFactory, mEffect, mDescriptor));
106 ASSERT_NO_FATAL_FAILURE(open(mEffect));
107 ASSERT_NO_FATAL_FAILURE(close(mEffect));
108 ASSERT_NO_FATAL_FAILURE(destroy(mFactory, mEffect));
Shunkai Yao45905172022-08-24 18:14:02 +0000109}
110
Shunkai Yao812d5b42022-11-16 18:08:50 +0000111TEST_P(AudioEffectTest, CloseUnopenedEffect) {
Shunkai Yaocb0fc412022-12-15 20:34:32 +0000112 ASSERT_NO_FATAL_FAILURE(create(mFactory, mEffect, mDescriptor));
113 ASSERT_NO_FATAL_FAILURE(close(mEffect));
114 ASSERT_NO_FATAL_FAILURE(destroy(mFactory, mEffect));
Shunkai Yao45905172022-08-24 18:14:02 +0000115}
116
Shunkai Yao812d5b42022-11-16 18:08:50 +0000117TEST_P(AudioEffectTest, DoubleOpenAndClose) {
118 std::shared_ptr<IEffect> effect1, effect2;
Shunkai Yaocb0fc412022-12-15 20:34:32 +0000119 ASSERT_NO_FATAL_FAILURE(create(mFactory, effect1, mDescriptor));
120 ASSERT_NO_FATAL_FAILURE(create(mFactory, effect2, mDescriptor));
Shunkai Yao812d5b42022-11-16 18:08:50 +0000121 ASSERT_NO_FATAL_FAILURE(open(effect1));
122 ASSERT_NO_FATAL_FAILURE(open(effect2, 1 /* session */));
123 ASSERT_NO_FATAL_FAILURE(close(effect1));
124 ASSERT_NO_FATAL_FAILURE(close(effect2));
125 ASSERT_NO_FATAL_FAILURE(destroy(mFactory, effect1));
126 ASSERT_NO_FATAL_FAILURE(destroy(mFactory, effect2));
Shunkai Yao45905172022-08-24 18:14:02 +0000127}
128
Shunkai Yao812d5b42022-11-16 18:08:50 +0000129TEST_P(AudioEffectTest, TripleOpenAndClose) {
130 std::shared_ptr<IEffect> effect1, effect2, effect3;
Shunkai Yaocb0fc412022-12-15 20:34:32 +0000131 ASSERT_NO_FATAL_FAILURE(create(mFactory, effect1, mDescriptor));
132 ASSERT_NO_FATAL_FAILURE(create(mFactory, effect2, mDescriptor));
133 ASSERT_NO_FATAL_FAILURE(create(mFactory, effect3, mDescriptor));
Shunkai Yao812d5b42022-11-16 18:08:50 +0000134 ASSERT_NO_FATAL_FAILURE(open(effect1));
135 ASSERT_NO_FATAL_FAILURE(open(effect2, 1 /* session */));
136 ASSERT_NO_FATAL_FAILURE(open(effect3, 2 /* session */));
137 ASSERT_NO_FATAL_FAILURE(close(effect1));
138 ASSERT_NO_FATAL_FAILURE(close(effect2));
139 ASSERT_NO_FATAL_FAILURE(close(effect3));
140 ASSERT_NO_FATAL_FAILURE(destroy(mFactory, effect1));
141 ASSERT_NO_FATAL_FAILURE(destroy(mFactory, effect2));
142 ASSERT_NO_FATAL_FAILURE(destroy(mFactory, effect3));
143}
Shunkai Yao45905172022-08-24 18:14:02 +0000144
Shunkai Yao812d5b42022-11-16 18:08:50 +0000145TEST_P(AudioEffectTest, GetDescritorBeforeOpen) {
Shunkai Yao812d5b42022-11-16 18:08:50 +0000146 Descriptor desc;
Shunkai Yaocb0fc412022-12-15 20:34:32 +0000147 ASSERT_NO_FATAL_FAILURE(create(mFactory, mEffect, mDescriptor));
148 ASSERT_NO_FATAL_FAILURE(getDescriptor(mEffect, desc));
Shunkai Yao4c4f3cd2023-02-28 01:50:40 +0000149 EXPECT_EQ(mDescriptor.common.id.type, desc.common.id.type);
150 EXPECT_EQ(mDescriptor.common.id.uuid, desc.common.id.uuid);
151 EXPECT_EQ(mDescriptor.common.name, desc.common.name);
152 EXPECT_EQ(mDescriptor.common.implementor, desc.common.implementor);
Shunkai Yaocb0fc412022-12-15 20:34:32 +0000153 // Effect implementation Must fill in implementor and name
Shunkai Yao812d5b42022-11-16 18:08:50 +0000154 EXPECT_NE("", desc.common.name);
155 EXPECT_NE("", desc.common.implementor);
Shunkai Yaocb0fc412022-12-15 20:34:32 +0000156 ASSERT_NO_FATAL_FAILURE(destroy(mFactory, mEffect));
Shunkai Yao812d5b42022-11-16 18:08:50 +0000157}
158
159TEST_P(AudioEffectTest, GetDescritorAfterOpen) {
Shunkai Yao812d5b42022-11-16 18:08:50 +0000160 Descriptor beforeOpen, afterOpen, afterClose;
Shunkai Yaocb0fc412022-12-15 20:34:32 +0000161 ASSERT_NO_FATAL_FAILURE(create(mFactory, mEffect, mDescriptor));
162 ASSERT_NO_FATAL_FAILURE(getDescriptor(mEffect, beforeOpen));
163 ASSERT_NO_FATAL_FAILURE(open(mEffect));
164 ASSERT_NO_FATAL_FAILURE(getDescriptor(mEffect, afterOpen));
Shunkai Yao812d5b42022-11-16 18:08:50 +0000165 EXPECT_EQ(beforeOpen.toString(), afterOpen.toString()) << "\n"
166 << beforeOpen.toString() << "\n"
167 << afterOpen.toString();
Shunkai Yaocb0fc412022-12-15 20:34:32 +0000168 ASSERT_NO_FATAL_FAILURE(close(mEffect));
169 ASSERT_NO_FATAL_FAILURE(getDescriptor(mEffect, afterClose));
Shunkai Yao812d5b42022-11-16 18:08:50 +0000170 EXPECT_EQ(beforeOpen.toString(), afterClose.toString()) << "\n"
171 << beforeOpen.toString() << "\n"
172 << afterClose.toString();
Shunkai Yaocb0fc412022-12-15 20:34:32 +0000173 ASSERT_NO_FATAL_FAILURE(destroy(mFactory, mEffect));
Shunkai Yao812d5b42022-11-16 18:08:50 +0000174}
175
176TEST_P(AudioEffectTest, DescriptorExistAndUnique) {
Shunkai Yao812d5b42022-11-16 18:08:50 +0000177 Descriptor desc;
178
179 auto descList = EffectFactoryHelper::getAllEffectDescriptors(IFactory::descriptor);
180 std::set<Descriptor::Identity> idSet;
181 for (const auto& it : descList) {
Shunkai Yaocb0fc412022-12-15 20:34:32 +0000182 auto& id = it.second.common.id;
Shunkai Yao812d5b42022-11-16 18:08:50 +0000183 EXPECT_EQ(0ul, idSet.count(id));
184 idSet.insert(id);
Shunkai Yao45905172022-08-24 18:14:02 +0000185 }
Shunkai Yao812d5b42022-11-16 18:08:50 +0000186
Shunkai Yaocb0fc412022-12-15 20:34:32 +0000187 ASSERT_NO_FATAL_FAILURE(create(mFactory, mEffect, mDescriptor));
188 ASSERT_NO_FATAL_FAILURE(getDescriptor(mEffect, desc));
Shunkai Yao4c4f3cd2023-02-28 01:50:40 +0000189 int uuidCount = std::count_if(idSet.begin(), idSet.end(), [&](const auto& id) {
190 return id.uuid == desc.common.id.uuid && id.type == desc.common.id.type;
191 });
192
193 EXPECT_EQ(1, uuidCount);
Shunkai Yaocb0fc412022-12-15 20:34:32 +0000194 ASSERT_NO_FATAL_FAILURE(destroy(mFactory, mEffect));
Shunkai Yao45905172022-08-24 18:14:02 +0000195}
196
Shunkai Yaoea24c1a2022-09-28 17:39:23 +0000197/// State testing.
198// An effect instance is in INIT state by default after it was created.
Shunkai Yaoa4ab38c2022-10-14 01:07:47 +0000199TEST_P(AudioEffectTest, InitStateAfterCreation) {
Shunkai Yaocb0fc412022-12-15 20:34:32 +0000200 ASSERT_NO_FATAL_FAILURE(create(mFactory, mEffect, mDescriptor));
201 ASSERT_NO_FATAL_FAILURE(expectState(mEffect, State::INIT));
202 ASSERT_NO_FATAL_FAILURE(destroy(mFactory, mEffect));
Shunkai Yaoea24c1a2022-09-28 17:39:23 +0000203}
204
Shunkai Yao812d5b42022-11-16 18:08:50 +0000205// An effect instance transfer to IDLE state after IEffect.ASSERT_NO_FATAL_FAILURE(open().
Shunkai Yaoa4ab38c2022-10-14 01:07:47 +0000206TEST_P(AudioEffectTest, IdleStateAfterOpen) {
Shunkai Yaocb0fc412022-12-15 20:34:32 +0000207 ASSERT_NO_FATAL_FAILURE(create(mFactory, mEffect, mDescriptor));
208 ASSERT_NO_FATAL_FAILURE(open(mEffect));
209 ASSERT_NO_FATAL_FAILURE(expectState(mEffect, State::IDLE));
210 ASSERT_NO_FATAL_FAILURE(close(mEffect));
211 ASSERT_NO_FATAL_FAILURE(destroy(mFactory, mEffect));
Shunkai Yaoea24c1a2022-09-28 17:39:23 +0000212}
213
214// An effect instance is in PROCESSING state after it receive an START command.
Shunkai Yaoa4ab38c2022-10-14 01:07:47 +0000215TEST_P(AudioEffectTest, ProcessingStateAfterStart) {
Shunkai Yaocb0fc412022-12-15 20:34:32 +0000216 ASSERT_NO_FATAL_FAILURE(create(mFactory, mEffect, mDescriptor));
217 ASSERT_NO_FATAL_FAILURE(expectState(mEffect, State::INIT));
218 ASSERT_NO_FATAL_FAILURE(open(mEffect));
219 ASSERT_NO_FATAL_FAILURE(expectState(mEffect, State::IDLE));
220 ASSERT_NO_FATAL_FAILURE(command(mEffect, CommandId::START));
221 ASSERT_NO_FATAL_FAILURE(expectState(mEffect, State::PROCESSING));
222 ASSERT_NO_FATAL_FAILURE(command(mEffect, CommandId::STOP));
223 ASSERT_NO_FATAL_FAILURE(close(mEffect));
224 ASSERT_NO_FATAL_FAILURE(destroy(mFactory, mEffect));
Shunkai Yaoea24c1a2022-09-28 17:39:23 +0000225}
226
227// An effect instance transfer to IDLE state after Command.Id.STOP in PROCESSING state.
Shunkai Yaoa4ab38c2022-10-14 01:07:47 +0000228TEST_P(AudioEffectTest, IdleStateAfterStop) {
Shunkai Yaocb0fc412022-12-15 20:34:32 +0000229 ASSERT_NO_FATAL_FAILURE(create(mFactory, mEffect, mDescriptor));
230 ASSERT_NO_FATAL_FAILURE(open(mEffect));
231 ASSERT_NO_FATAL_FAILURE(command(mEffect, CommandId::START));
232 ASSERT_NO_FATAL_FAILURE(expectState(mEffect, State::PROCESSING));
233 ASSERT_NO_FATAL_FAILURE(command(mEffect, CommandId::STOP));
234 ASSERT_NO_FATAL_FAILURE(expectState(mEffect, State::IDLE));
235 ASSERT_NO_FATAL_FAILURE(close(mEffect));
236 ASSERT_NO_FATAL_FAILURE(destroy(mFactory, mEffect));
Shunkai Yaoea24c1a2022-09-28 17:39:23 +0000237}
238
239// An effect instance transfer to IDLE state after Command.Id.RESET in PROCESSING state.
Shunkai Yaoa4ab38c2022-10-14 01:07:47 +0000240TEST_P(AudioEffectTest, IdleStateAfterReset) {
Shunkai Yaocb0fc412022-12-15 20:34:32 +0000241 ASSERT_NO_FATAL_FAILURE(create(mFactory, mEffect, mDescriptor));
242 ASSERT_NO_FATAL_FAILURE(open(mEffect));
243 ASSERT_NO_FATAL_FAILURE(command(mEffect, CommandId::START));
244 ASSERT_NO_FATAL_FAILURE(expectState(mEffect, State::PROCESSING));
245 ASSERT_NO_FATAL_FAILURE(command(mEffect, CommandId::RESET));
246 ASSERT_NO_FATAL_FAILURE(expectState(mEffect, State::IDLE));
247 ASSERT_NO_FATAL_FAILURE(close(mEffect));
248 ASSERT_NO_FATAL_FAILURE(destroy(mFactory, mEffect));
Shunkai Yaoea24c1a2022-09-28 17:39:23 +0000249}
250
Shunkai Yao812d5b42022-11-16 18:08:50 +0000251// An effect instance transfer to INIT after IEffect.ASSERT_NO_FATAL_FAILURE(close().
Shunkai Yaoa4ab38c2022-10-14 01:07:47 +0000252TEST_P(AudioEffectTest, InitStateAfterClose) {
Shunkai Yaocb0fc412022-12-15 20:34:32 +0000253 ASSERT_NO_FATAL_FAILURE(create(mFactory, mEffect, mDescriptor));
254 ASSERT_NO_FATAL_FAILURE(open(mEffect));
255 ASSERT_NO_FATAL_FAILURE(command(mEffect, CommandId::START));
256 ASSERT_NO_FATAL_FAILURE(command(mEffect, CommandId::STOP));
257 ASSERT_NO_FATAL_FAILURE(close(mEffect));
258 ASSERT_NO_FATAL_FAILURE(expectState(mEffect, State::INIT));
259 ASSERT_NO_FATAL_FAILURE(destroy(mFactory, mEffect));
Shunkai Yaoea24c1a2022-09-28 17:39:23 +0000260}
261
262// An effect instance shouldn't accept any command before open.
Shunkai Yaoa4ab38c2022-10-14 01:07:47 +0000263TEST_P(AudioEffectTest, NoCommandAcceptedBeforeOpen) {
Shunkai Yaocb0fc412022-12-15 20:34:32 +0000264 ASSERT_NO_FATAL_FAILURE(create(mFactory, mEffect, mDescriptor));
265 ASSERT_NO_FATAL_FAILURE(command(mEffect, CommandId::START, EX_ILLEGAL_STATE));
266 ASSERT_NO_FATAL_FAILURE(command(mEffect, CommandId::STOP, EX_ILLEGAL_STATE));
267 ASSERT_NO_FATAL_FAILURE(command(mEffect, CommandId::RESET, EX_ILLEGAL_STATE));
268 ASSERT_NO_FATAL_FAILURE(destroy(mFactory, mEffect));
Shunkai Yaoea24c1a2022-09-28 17:39:23 +0000269}
270
271// No-op when receive STOP command in IDLE state.
Shunkai Yaoa4ab38c2022-10-14 01:07:47 +0000272TEST_P(AudioEffectTest, StopCommandInIdleStateNoOp) {
Shunkai Yaocb0fc412022-12-15 20:34:32 +0000273 ASSERT_NO_FATAL_FAILURE(create(mFactory, mEffect, mDescriptor));
274 ASSERT_NO_FATAL_FAILURE(open(mEffect));
275 ASSERT_NO_FATAL_FAILURE(expectState(mEffect, State::IDLE));
276 ASSERT_NO_FATAL_FAILURE(command(mEffect, CommandId::STOP));
277 ASSERT_NO_FATAL_FAILURE(expectState(mEffect, State::IDLE));
278 ASSERT_NO_FATAL_FAILURE(close(mEffect));
279 ASSERT_NO_FATAL_FAILURE(destroy(mFactory, mEffect));
Shunkai Yaoea24c1a2022-09-28 17:39:23 +0000280}
281
Shunkai Yao812d5b42022-11-16 18:08:50 +0000282// No-op when receive RESET command in IDLE state.
Shunkai Yaoa4ab38c2022-10-14 01:07:47 +0000283TEST_P(AudioEffectTest, ResetCommandInIdleStateNoOp) {
Shunkai Yaocb0fc412022-12-15 20:34:32 +0000284 ASSERT_NO_FATAL_FAILURE(create(mFactory, mEffect, mDescriptor));
285 ASSERT_NO_FATAL_FAILURE(open(mEffect));
286 ASSERT_NO_FATAL_FAILURE(expectState(mEffect, State::IDLE));
287 ASSERT_NO_FATAL_FAILURE(command(mEffect, CommandId::RESET));
288 ASSERT_NO_FATAL_FAILURE(expectState(mEffect, State::IDLE));
289 ASSERT_NO_FATAL_FAILURE(close(mEffect));
290 ASSERT_NO_FATAL_FAILURE(destroy(mFactory, mEffect));
Shunkai Yaoea24c1a2022-09-28 17:39:23 +0000291}
292
293// Repeat START and STOP command.
Shunkai Yaoa4ab38c2022-10-14 01:07:47 +0000294TEST_P(AudioEffectTest, RepeatStartAndStop) {
Shunkai Yaocb0fc412022-12-15 20:34:32 +0000295 ASSERT_NO_FATAL_FAILURE(create(mFactory, mEffect, mDescriptor));
296 ASSERT_NO_FATAL_FAILURE(open(mEffect));
297 ASSERT_NO_FATAL_FAILURE(expectState(mEffect, State::IDLE));
298 ASSERT_NO_FATAL_FAILURE(command(mEffect, CommandId::START));
299 ASSERT_NO_FATAL_FAILURE(expectState(mEffect, State::PROCESSING));
300 ASSERT_NO_FATAL_FAILURE(command(mEffect, CommandId::STOP));
301 ASSERT_NO_FATAL_FAILURE(expectState(mEffect, State::IDLE));
Shunkai Yao812d5b42022-11-16 18:08:50 +0000302
Shunkai Yaocb0fc412022-12-15 20:34:32 +0000303 ASSERT_NO_FATAL_FAILURE(command(mEffect, CommandId::START));
304 ASSERT_NO_FATAL_FAILURE(expectState(mEffect, State::PROCESSING));
305 ASSERT_NO_FATAL_FAILURE(command(mEffect, CommandId::STOP));
306 ASSERT_NO_FATAL_FAILURE(expectState(mEffect, State::IDLE));
307 ASSERT_NO_FATAL_FAILURE(close(mEffect));
308 ASSERT_NO_FATAL_FAILURE(destroy(mFactory, mEffect));
Shunkai Yaoea24c1a2022-09-28 17:39:23 +0000309}
310
311// Repeat START and RESET command.
Shunkai Yaoa4ab38c2022-10-14 01:07:47 +0000312TEST_P(AudioEffectTest, RepeatStartAndReset) {
Shunkai Yaocb0fc412022-12-15 20:34:32 +0000313 ASSERT_NO_FATAL_FAILURE(create(mFactory, mEffect, mDescriptor));
314 ASSERT_NO_FATAL_FAILURE(open(mEffect));
315 ASSERT_NO_FATAL_FAILURE(expectState(mEffect, State::IDLE));
316 ASSERT_NO_FATAL_FAILURE(command(mEffect, CommandId::START));
317 ASSERT_NO_FATAL_FAILURE(expectState(mEffect, State::PROCESSING));
318 ASSERT_NO_FATAL_FAILURE(command(mEffect, CommandId::RESET));
319 ASSERT_NO_FATAL_FAILURE(expectState(mEffect, State::IDLE));
Shunkai Yao812d5b42022-11-16 18:08:50 +0000320
Shunkai Yaocb0fc412022-12-15 20:34:32 +0000321 ASSERT_NO_FATAL_FAILURE(command(mEffect, CommandId::START));
322 ASSERT_NO_FATAL_FAILURE(expectState(mEffect, State::PROCESSING));
323 ASSERT_NO_FATAL_FAILURE(command(mEffect, CommandId::RESET));
324 ASSERT_NO_FATAL_FAILURE(expectState(mEffect, State::IDLE));
325 ASSERT_NO_FATAL_FAILURE(close(mEffect));
326 ASSERT_NO_FATAL_FAILURE(destroy(mFactory, mEffect));
Shunkai Yaoea24c1a2022-09-28 17:39:23 +0000327}
328
Shunkai Yao812d5b42022-11-16 18:08:50 +0000329// Try to close an effect instance at PROCESSING state.
Shunkai Yaoa4ab38c2022-10-14 01:07:47 +0000330TEST_P(AudioEffectTest, CloseProcessingStateEffects) {
Shunkai Yaocb0fc412022-12-15 20:34:32 +0000331 ASSERT_NO_FATAL_FAILURE(create(mFactory, mEffect, mDescriptor));
332 ASSERT_NO_FATAL_FAILURE(open(mEffect));
333 ASSERT_NO_FATAL_FAILURE(expectState(mEffect, State::IDLE));
334 ASSERT_NO_FATAL_FAILURE(command(mEffect, CommandId::START));
335 ASSERT_NO_FATAL_FAILURE(expectState(mEffect, State::PROCESSING));
Shunkai Yao812d5b42022-11-16 18:08:50 +0000336
Shunkai Yaocb0fc412022-12-15 20:34:32 +0000337 ASSERT_NO_FATAL_FAILURE(close(mEffect, EX_ILLEGAL_STATE));
Shunkai Yao812d5b42022-11-16 18:08:50 +0000338
Shunkai Yaocb0fc412022-12-15 20:34:32 +0000339 ASSERT_NO_FATAL_FAILURE(command(mEffect, CommandId::STOP));
340 ASSERT_NO_FATAL_FAILURE(expectState(mEffect, State::IDLE));
341 ASSERT_NO_FATAL_FAILURE(close(mEffect));
342 ASSERT_NO_FATAL_FAILURE(destroy(mFactory, mEffect));
Shunkai Yaoea24c1a2022-09-28 17:39:23 +0000343}
344
345// Expect EX_ILLEGAL_STATE if the effect instance is not in a proper state to be destroyed.
Shunkai Yaoa4ab38c2022-10-14 01:07:47 +0000346TEST_P(AudioEffectTest, DestroyOpenEffects) {
Shunkai Yaocb0fc412022-12-15 20:34:32 +0000347 ASSERT_NO_FATAL_FAILURE(create(mFactory, mEffect, mDescriptor));
348 ASSERT_NO_FATAL_FAILURE(open(mEffect));
349 ASSERT_NO_FATAL_FAILURE(expectState(mEffect, State::IDLE));
Shunkai Yaoea24c1a2022-09-28 17:39:23 +0000350
Shunkai Yaocb0fc412022-12-15 20:34:32 +0000351 ASSERT_NO_FATAL_FAILURE(destroy(mFactory, mEffect, EX_ILLEGAL_STATE));
352
353 // cleanup
354 ASSERT_NO_FATAL_FAILURE(close(mEffect));
355 ASSERT_NO_FATAL_FAILURE(destroy(mFactory, mEffect));
Shunkai Yao812d5b42022-11-16 18:08:50 +0000356}
357
358// Expect EX_ILLEGAL_STATE if the effect instance is not in a proper state to be destroyed.
359TEST_P(AudioEffectTest, DestroyProcessingEffects) {
Shunkai Yaocb0fc412022-12-15 20:34:32 +0000360 ASSERT_NO_FATAL_FAILURE(create(mFactory, mEffect, mDescriptor));
361 ASSERT_NO_FATAL_FAILURE(open(mEffect));
362 ASSERT_NO_FATAL_FAILURE(expectState(mEffect, State::IDLE));
363 ASSERT_NO_FATAL_FAILURE(command(mEffect, CommandId::START));
364 ASSERT_NO_FATAL_FAILURE(expectState(mEffect, State::PROCESSING));
Shunkai Yao812d5b42022-11-16 18:08:50 +0000365
Shunkai Yaocb0fc412022-12-15 20:34:32 +0000366 ASSERT_NO_FATAL_FAILURE(destroy(mFactory, mEffect, EX_ILLEGAL_STATE));
367
368 // cleanup
369 ASSERT_NO_FATAL_FAILURE(command(mEffect, CommandId::STOP));
370 ASSERT_NO_FATAL_FAILURE(expectState(mEffect, State::IDLE));
371 ASSERT_NO_FATAL_FAILURE(close(mEffect));
372 ASSERT_NO_FATAL_FAILURE(destroy(mFactory, mEffect));
Shunkai Yao812d5b42022-11-16 18:08:50 +0000373}
374
375TEST_P(AudioEffectTest, NormalSequenceStates) {
Shunkai Yaocb0fc412022-12-15 20:34:32 +0000376 ASSERT_NO_FATAL_FAILURE(create(mFactory, mEffect, mDescriptor));
377 ASSERT_NO_FATAL_FAILURE(expectState(mEffect, State::INIT));
378 ASSERT_NO_FATAL_FAILURE(open(mEffect));
379 ASSERT_NO_FATAL_FAILURE(expectState(mEffect, State::IDLE));
380 ASSERT_NO_FATAL_FAILURE(command(mEffect, CommandId::START));
381 ASSERT_NO_FATAL_FAILURE(expectState(mEffect, State::PROCESSING));
382 ASSERT_NO_FATAL_FAILURE(command(mEffect, CommandId::STOP));
383 ASSERT_NO_FATAL_FAILURE(expectState(mEffect, State::IDLE));
384 ASSERT_NO_FATAL_FAILURE(command(mEffect, CommandId::START));
385 ASSERT_NO_FATAL_FAILURE(expectState(mEffect, State::PROCESSING));
386 ASSERT_NO_FATAL_FAILURE(command(mEffect, CommandId::RESET));
387 ASSERT_NO_FATAL_FAILURE(expectState(mEffect, State::IDLE));
388 ASSERT_NO_FATAL_FAILURE(close(mEffect));
389 ASSERT_NO_FATAL_FAILURE(destroy(mFactory, mEffect));
Shunkai Yaoea24c1a2022-09-28 17:39:23 +0000390}
391
392/// Parameter testing.
393// Verify parameters pass in open can be successfully get.
Shunkai Yao812d5b42022-11-16 18:08:50 +0000394TEST_P(AudioEffectTest, VerifyCommonParametersAfterOpen) {
Shunkai Yaocb0fc412022-12-15 20:34:32 +0000395 ASSERT_NO_FATAL_FAILURE(create(mFactory, mEffect, mDescriptor));
Shunkai Yao812d5b42022-11-16 18:08:50 +0000396
397 Parameter::Common common = EffectHelper::createParamCommon();
398 IEffect::OpenEffectReturn ret;
Shunkai Yaocb0fc412022-12-15 20:34:32 +0000399 ASSERT_NO_FATAL_FAILURE(open(mEffect, common, std::nullopt /* specific */, &ret, EX_NONE));
Shunkai Yao812d5b42022-11-16 18:08:50 +0000400
401 Parameter get = Parameter(), expect = Parameter();
402 expect.set<Parameter::common>(common);
403 Parameter::Id id;
404 id.set<Parameter::Id::commonTag>(Parameter::common);
Shunkai Yaocb0fc412022-12-15 20:34:32 +0000405 EXPECT_IS_OK(mEffect->getParameter(id, &get));
Shunkai Yaoeea19942023-02-16 02:31:24 +0000406 EXPECT_EQ(expect, get) << expect.toString() << "\n vs \n" << get.toString();
Shunkai Yao812d5b42022-11-16 18:08:50 +0000407
Shunkai Yaocb0fc412022-12-15 20:34:32 +0000408 ASSERT_NO_FATAL_FAILURE(close(mEffect));
409 ASSERT_NO_FATAL_FAILURE(destroy(mFactory, mEffect));
Shunkai Yaoea24c1a2022-09-28 17:39:23 +0000410}
411
412// Verify parameters pass in set can be successfully get.
Shunkai Yao812d5b42022-11-16 18:08:50 +0000413TEST_P(AudioEffectTest, SetAndGetCommonParameter) {
Shunkai Yaocb0fc412022-12-15 20:34:32 +0000414 ASSERT_NO_FATAL_FAILURE(create(mFactory, mEffect, mDescriptor));
415 ASSERT_NO_FATAL_FAILURE(open(mEffect));
Shunkai Yao812d5b42022-11-16 18:08:50 +0000416
417 Parameter::Common common = EffectHelper::createParamCommon(
418 0 /* session */, 1 /* ioHandle */, 44100 /* iSampleRate */, 44100 /* oSampleRate */);
Shunkai Yao5df4e6c2023-01-10 03:20:00 +0000419 Parameter::Id id = Parameter::Id::make<Parameter::Id::commonTag>(Parameter::common);
420 ASSERT_NO_FATAL_FAILURE(setAndGetParameter(id, Parameter::make<Parameter::common>(common)));
Shunkai Yao812d5b42022-11-16 18:08:50 +0000421
Shunkai Yaocb0fc412022-12-15 20:34:32 +0000422 ASSERT_NO_FATAL_FAILURE(close(mEffect));
423 ASSERT_NO_FATAL_FAILURE(destroy(mFactory, mEffect));
Shunkai Yaoea24c1a2022-09-28 17:39:23 +0000424}
425
Shunkai Yao812d5b42022-11-16 18:08:50 +0000426// Verify parameters set and get in PROCESSING state.
Shunkai Yaoa4ab38c2022-10-14 01:07:47 +0000427TEST_P(AudioEffectTest, SetAndGetParameterInProcessing) {
Shunkai Yaocb0fc412022-12-15 20:34:32 +0000428 ASSERT_NO_FATAL_FAILURE(create(mFactory, mEffect, mDescriptor));
429 ASSERT_NO_FATAL_FAILURE(open(mEffect));
430 ASSERT_NO_FATAL_FAILURE(command(mEffect, CommandId::START));
431 ASSERT_NO_FATAL_FAILURE(expectState(mEffect, State::PROCESSING));
Shunkai Yao812d5b42022-11-16 18:08:50 +0000432
433 Parameter::Common common = EffectHelper::createParamCommon(
434 0 /* session */, 1 /* ioHandle */, 44100 /* iSampleRate */, 44100 /* oSampleRate */);
Shunkai Yao5df4e6c2023-01-10 03:20:00 +0000435 Parameter::Id id = Parameter::Id::make<Parameter::Id::commonTag>(Parameter::common);
436 ASSERT_NO_FATAL_FAILURE(setAndGetParameter(id, Parameter::make<Parameter::common>(common)));
Shunkai Yao812d5b42022-11-16 18:08:50 +0000437
Shunkai Yaocb0fc412022-12-15 20:34:32 +0000438 ASSERT_NO_FATAL_FAILURE(command(mEffect, CommandId::STOP));
439 ASSERT_NO_FATAL_FAILURE(close(mEffect));
440 ASSERT_NO_FATAL_FAILURE(destroy(mFactory, mEffect));
Shunkai Yaoea24c1a2022-09-28 17:39:23 +0000441}
442
Shunkai Yao812d5b42022-11-16 18:08:50 +0000443// Verify parameters set and get in IDLE state.
444TEST_P(AudioEffectTest, SetAndGetParameterInIdle) {
Shunkai Yaocb0fc412022-12-15 20:34:32 +0000445 ASSERT_NO_FATAL_FAILURE(create(mFactory, mEffect, mDescriptor));
446 ASSERT_NO_FATAL_FAILURE(open(mEffect));
447 ASSERT_NO_FATAL_FAILURE(command(mEffect, CommandId::START));
448 ASSERT_NO_FATAL_FAILURE(expectState(mEffect, State::PROCESSING));
449 ASSERT_NO_FATAL_FAILURE(command(mEffect, CommandId::STOP));
450 ASSERT_NO_FATAL_FAILURE(expectState(mEffect, State::IDLE));
Shunkai Yao812d5b42022-11-16 18:08:50 +0000451
452 Parameter::Common common = EffectHelper::createParamCommon(
453 0 /* session */, 1 /* ioHandle */, 44100 /* iSampleRate */, 44100 /* oSampleRate */);
Shunkai Yao5df4e6c2023-01-10 03:20:00 +0000454 Parameter::Id id = Parameter::Id::make<Parameter::Id::commonTag>(Parameter::common);
455 ASSERT_NO_FATAL_FAILURE(setAndGetParameter(id, Parameter::make<Parameter::common>(common)));
Shunkai Yao812d5b42022-11-16 18:08:50 +0000456
Shunkai Yaocb0fc412022-12-15 20:34:32 +0000457 ASSERT_NO_FATAL_FAILURE(close(mEffect));
458 ASSERT_NO_FATAL_FAILURE(destroy(mFactory, mEffect));
Shunkai Yaoea24c1a2022-09-28 17:39:23 +0000459}
460
Shunkai Yao812d5b42022-11-16 18:08:50 +0000461// Verify Parameters kept after stop.
462TEST_P(AudioEffectTest, SetAndGetParameterAfterStop) {
Shunkai Yaocb0fc412022-12-15 20:34:32 +0000463 ASSERT_NO_FATAL_FAILURE(create(mFactory, mEffect, mDescriptor));
464 ASSERT_NO_FATAL_FAILURE(open(mEffect));
465 ASSERT_NO_FATAL_FAILURE(command(mEffect, CommandId::START));
466 ASSERT_NO_FATAL_FAILURE(expectState(mEffect, State::PROCESSING));
Shunkai Yaoea24c1a2022-09-28 17:39:23 +0000467
Shunkai Yao812d5b42022-11-16 18:08:50 +0000468 Parameter::Common common = EffectHelper::createParamCommon(
469 0 /* session */, 1 /* ioHandle */, 44100 /* iSampleRate */, 44100 /* oSampleRate */);
Shunkai Yao5df4e6c2023-01-10 03:20:00 +0000470 Parameter::Id id = Parameter::Id::make<Parameter::Id::commonTag>(Parameter::common);
471 ASSERT_NO_FATAL_FAILURE(setAndGetParameter(id, Parameter::make<Parameter::common>(common)));
Shunkai Yaoa4ab38c2022-10-14 01:07:47 +0000472
Shunkai Yaocb0fc412022-12-15 20:34:32 +0000473 ASSERT_NO_FATAL_FAILURE(command(mEffect, CommandId::STOP));
474 ASSERT_NO_FATAL_FAILURE(expectState(mEffect, State::IDLE));
Shunkai Yaocb0fc412022-12-15 20:34:32 +0000475 ASSERT_NO_FATAL_FAILURE(close(mEffect));
476 ASSERT_NO_FATAL_FAILURE(destroy(mFactory, mEffect));
Shunkai Yaoa4ab38c2022-10-14 01:07:47 +0000477}
478
Shunkai Yao812d5b42022-11-16 18:08:50 +0000479// Verify Parameters kept after reset.
480TEST_P(AudioEffectTest, SetAndGetParameterAfterReset) {
Shunkai Yaocb0fc412022-12-15 20:34:32 +0000481 ASSERT_NO_FATAL_FAILURE(create(mFactory, mEffect, mDescriptor));
482 ASSERT_NO_FATAL_FAILURE(open(mEffect));
Shunkai Yao812d5b42022-11-16 18:08:50 +0000483
Shunkai Yaocb0fc412022-12-15 20:34:32 +0000484 ASSERT_NO_FATAL_FAILURE(command(mEffect, CommandId::START));
485 ASSERT_NO_FATAL_FAILURE(expectState(mEffect, State::PROCESSING));
Shunkai Yao812d5b42022-11-16 18:08:50 +0000486
487 Parameter::Common common = EffectHelper::createParamCommon(
488 0 /* session */, 1 /* ioHandle */, 44100 /* iSampleRate */, 44100 /* oSampleRate */);
Shunkai Yao5df4e6c2023-01-10 03:20:00 +0000489 Parameter::Id id = Parameter::Id::make<Parameter::Id::commonTag>(Parameter::common);
490 ASSERT_NO_FATAL_FAILURE(setAndGetParameter(id, Parameter::make<Parameter::common>(common)));
Shunkai Yao812d5b42022-11-16 18:08:50 +0000491
Shunkai Yaocb0fc412022-12-15 20:34:32 +0000492 ASSERT_NO_FATAL_FAILURE(command(mEffect, CommandId::RESET));
493 ASSERT_NO_FATAL_FAILURE(expectState(mEffect, State::IDLE));
Shunkai Yao812d5b42022-11-16 18:08:50 +0000494
Shunkai Yao5df4e6c2023-01-10 03:20:00 +0000495 ASSERT_NO_FATAL_FAILURE(setAndGetParameter(id, Parameter::make<Parameter::common>(common)));
Shunkai Yao812d5b42022-11-16 18:08:50 +0000496
Shunkai Yao5df4e6c2023-01-10 03:20:00 +0000497 ASSERT_NO_FATAL_FAILURE(command(mEffect, CommandId::STOP));
498 ASSERT_NO_FATAL_FAILURE(expectState(mEffect, State::IDLE));
Shunkai Yaocb0fc412022-12-15 20:34:32 +0000499 ASSERT_NO_FATAL_FAILURE(close(mEffect));
500 ASSERT_NO_FATAL_FAILURE(destroy(mFactory, mEffect));
Shunkai Yao812d5b42022-11-16 18:08:50 +0000501}
Shunkai Yao5df4e6c2023-01-10 03:20:00 +0000502
503// Set and get AudioDeviceDescription in Parameter
504TEST_P(AudioEffectTest, SetAndGetParameterDeviceDescription) {
Shunkai Yao92cd7482023-09-18 17:37:45 +0000505 if (!mDescriptor.common.flags.deviceIndication) {
506 GTEST_SKIP() << "Skipping test as effect does not support deviceIndication"
507 << mDescriptor.common.flags.toString();
508 }
509
Shunkai Yao5df4e6c2023-01-10 03:20:00 +0000510 ASSERT_NO_FATAL_FAILURE(create(mFactory, mEffect, mDescriptor));
511 ASSERT_NO_FATAL_FAILURE(open(mEffect));
512
513 ASSERT_NO_FATAL_FAILURE(command(mEffect, CommandId::START));
514 ASSERT_NO_FATAL_FAILURE(expectState(mEffect, State::PROCESSING));
515
516 std::vector<AudioDeviceDescription> deviceDescs = {
517 {.type = AudioDeviceType::IN_DEFAULT,
518 .connection = AudioDeviceDescription::CONNECTION_ANALOG},
519 {.type = AudioDeviceType::IN_DEVICE,
520 .connection = AudioDeviceDescription::CONNECTION_BT_A2DP}};
521 Parameter::Id id = Parameter::Id::make<Parameter::Id::commonTag>(Parameter::deviceDescription);
522 ASSERT_NO_FATAL_FAILURE(
523 setAndGetParameter(id, Parameter::make<Parameter::deviceDescription>(deviceDescs)));
524
525 ASSERT_NO_FATAL_FAILURE(command(mEffect, CommandId::STOP));
526 ASSERT_NO_FATAL_FAILURE(expectState(mEffect, State::IDLE));
527 ASSERT_NO_FATAL_FAILURE(close(mEffect));
528 ASSERT_NO_FATAL_FAILURE(destroy(mFactory, mEffect));
529}
530
531// Set and get AudioMode in Parameter
532TEST_P(AudioEffectTest, SetAndGetParameterAudioMode) {
Shunkai Yao92cd7482023-09-18 17:37:45 +0000533 if (!mDescriptor.common.flags.audioModeIndication) {
534 GTEST_SKIP() << "Skipping test as effect does not support audioModeIndication"
535 << mDescriptor.common.flags.toString();
536 }
537
Shunkai Yao5df4e6c2023-01-10 03:20:00 +0000538 ASSERT_NO_FATAL_FAILURE(create(mFactory, mEffect, mDescriptor));
539 ASSERT_NO_FATAL_FAILURE(open(mEffect));
540
541 ASSERT_NO_FATAL_FAILURE(command(mEffect, CommandId::START));
542 ASSERT_NO_FATAL_FAILURE(expectState(mEffect, State::PROCESSING));
543
544 Parameter::Id id = Parameter::Id::make<Parameter::Id::commonTag>(Parameter::mode);
545 ASSERT_NO_FATAL_FAILURE(
546 setAndGetParameter(id, Parameter::make<Parameter::mode>(AudioMode::NORMAL)));
547 ASSERT_NO_FATAL_FAILURE(
548 setAndGetParameter(id, Parameter::make<Parameter::mode>(AudioMode::IN_COMMUNICATION)));
549
550 ASSERT_NO_FATAL_FAILURE(command(mEffect, CommandId::STOP));
551 ASSERT_NO_FATAL_FAILURE(expectState(mEffect, State::IDLE));
552 ASSERT_NO_FATAL_FAILURE(close(mEffect));
553 ASSERT_NO_FATAL_FAILURE(destroy(mFactory, mEffect));
554}
555
556// Set and get AudioSource in Parameter
557TEST_P(AudioEffectTest, SetAndGetParameterAudioSource) {
Shunkai Yao92cd7482023-09-18 17:37:45 +0000558 if (!mDescriptor.common.flags.audioSourceIndication) {
559 GTEST_SKIP() << "Skipping test as effect does not support audioSourceIndication"
560 << mDescriptor.common.flags.toString();
561 }
562
Shunkai Yao5df4e6c2023-01-10 03:20:00 +0000563 ASSERT_NO_FATAL_FAILURE(create(mFactory, mEffect, mDescriptor));
564 ASSERT_NO_FATAL_FAILURE(open(mEffect));
565
566 ASSERT_NO_FATAL_FAILURE(command(mEffect, CommandId::START));
567 ASSERT_NO_FATAL_FAILURE(expectState(mEffect, State::PROCESSING));
568
569 Parameter::Id id = Parameter::Id::make<Parameter::Id::commonTag>(Parameter::source);
570 ASSERT_NO_FATAL_FAILURE(
571 setAndGetParameter(id, Parameter::make<Parameter::source>(AudioSource::DEFAULT)));
572 ASSERT_NO_FATAL_FAILURE(setAndGetParameter(
573 id, Parameter::make<Parameter::source>(AudioSource::VOICE_RECOGNITION)));
574
575 ASSERT_NO_FATAL_FAILURE(command(mEffect, CommandId::STOP));
576 ASSERT_NO_FATAL_FAILURE(expectState(mEffect, State::IDLE));
577 ASSERT_NO_FATAL_FAILURE(close(mEffect));
578 ASSERT_NO_FATAL_FAILURE(destroy(mFactory, mEffect));
579}
580
581// Set and get VolumeStereo in Parameter
582TEST_P(AudioEffectTest, SetAndGetParameterVolume) {
Shunkai Yao92cd7482023-09-18 17:37:45 +0000583 if (mDescriptor.common.flags.volume == Flags::Volume::NONE) {
584 GTEST_SKIP() << "Skipping test as effect does not support volume"
585 << mDescriptor.common.flags.toString();
586 }
587
Shunkai Yao5df4e6c2023-01-10 03:20:00 +0000588 ASSERT_NO_FATAL_FAILURE(create(mFactory, mEffect, mDescriptor));
589 ASSERT_NO_FATAL_FAILURE(open(mEffect));
590
591 ASSERT_NO_FATAL_FAILURE(command(mEffect, CommandId::START));
592 ASSERT_NO_FATAL_FAILURE(expectState(mEffect, State::PROCESSING));
593
594 Parameter::Id id = Parameter::Id::make<Parameter::Id::commonTag>(Parameter::volumeStereo);
595 Parameter::VolumeStereo volume = {.left = 10.0, .right = 10.0};
David Li1a56fdd2023-11-14 23:31:53 +0800596 if (mDescriptor.common.flags.volume == Flags::Volume::CTRL) {
597 Parameter get;
598 EXPECT_IS_OK(mEffect->setParameter(volume));
599 EXPECT_IS_OK(mEffect->getParameter(id, &get));
600 } else {
601 ASSERT_NO_FATAL_FAILURE(
602 setAndGetParameter(id, Parameter::make<Parameter::volumeStereo>(volume)));
603 }
Shunkai Yao5df4e6c2023-01-10 03:20:00 +0000604
605 ASSERT_NO_FATAL_FAILURE(command(mEffect, CommandId::STOP));
606 ASSERT_NO_FATAL_FAILURE(expectState(mEffect, State::IDLE));
607 ASSERT_NO_FATAL_FAILURE(close(mEffect));
608 ASSERT_NO_FATAL_FAILURE(destroy(mFactory, mEffect));
609}
610
Shunkai Yaod685aed2024-01-30 18:27:38 +0000611/**
612 * Verify DataMqUpdateEventFlag after common parameter setting.
613 * verify reopen sequence.
614 */
615TEST_P(AudioEffectDataPathTest, SetCommonParameterAndReopen) {
Shunkai Yao65c7c702024-01-09 20:50:53 +0000616 ASSERT_NO_FATAL_FAILURE(create(mFactory, mEffect, mDescriptor));
617
618 Parameter::Common common = EffectHelper::createParamCommon(
619 0 /* session */, 1 /* ioHandle */, 44100 /* iSampleRate */, 44100 /* oSampleRate */,
620 kInputFrameCount /* iFrameCount */, kOutputFrameCount /* oFrameCount */);
621 IEffect::OpenEffectReturn ret;
622 ASSERT_NO_FATAL_FAILURE(open(mEffect, common, std::nullopt /* specific */, &ret, EX_NONE));
623 auto statusMQ = std::make_unique<EffectHelper::StatusMQ>(ret.statusMQ);
624 ASSERT_TRUE(statusMQ->isValid());
625 auto inputMQ = std::make_unique<EffectHelper::DataMQ>(ret.inputDataMQ);
626 ASSERT_TRUE(inputMQ->isValid());
627 auto outputMQ = std::make_unique<EffectHelper::DataMQ>(ret.outputDataMQ);
628 ASSERT_TRUE(outputMQ->isValid());
629
630 Parameter::Id id = Parameter::Id::make<Parameter::Id::commonTag>(Parameter::common);
631 common.input.frameCount++;
632 ASSERT_NO_FATAL_FAILURE(setAndGetParameter(id, Parameter::make<Parameter::common>(common)));
633 ASSERT_TRUE(statusMQ->isValid());
634 expectDataMqUpdateEventFlag(statusMQ);
635 EXPECT_IS_OK(mEffect->reopen(&ret));
636 inputMQ = std::make_unique<EffectHelper::DataMQ>(ret.inputDataMQ);
637 outputMQ = std::make_unique<EffectHelper::DataMQ>(ret.outputDataMQ);
638 ASSERT_TRUE(statusMQ->isValid());
639 ASSERT_TRUE(inputMQ->isValid());
640 ASSERT_TRUE(outputMQ->isValid());
641
642 common.output.frameCount++;
643 ASSERT_NO_FATAL_FAILURE(setAndGetParameter(id, Parameter::make<Parameter::common>(common)));
644 ASSERT_TRUE(statusMQ->isValid());
645 expectDataMqUpdateEventFlag(statusMQ);
646 EXPECT_IS_OK(mEffect->reopen(&ret));
647 inputMQ = std::make_unique<EffectHelper::DataMQ>(ret.inputDataMQ);
648 outputMQ = std::make_unique<EffectHelper::DataMQ>(ret.outputDataMQ);
649 ASSERT_TRUE(statusMQ->isValid());
650 ASSERT_TRUE(inputMQ->isValid());
651 ASSERT_TRUE(outputMQ->isValid());
652
653 ASSERT_NO_FATAL_FAILURE(close(mEffect));
654 ASSERT_NO_FATAL_FAILURE(destroy(mFactory, mEffect));
655}
656
Shunkai Yao812d5b42022-11-16 18:08:50 +0000657/// Data processing test
658// Send data to effects and expect it to be consumed by checking statusMQ.
Jaideep Sharmacba42862023-06-23 10:27:39 +0530659// Effects exposing bypass flags or operating in offload mode will be skipped.
660TEST_P(AudioEffectDataPathTest, ConsumeDataInProcessingState) {
Shunkai Yaocb0fc412022-12-15 20:34:32 +0000661 ASSERT_NO_FATAL_FAILURE(create(mFactory, mEffect, mDescriptor));
Shunkai Yao812d5b42022-11-16 18:08:50 +0000662
663 Parameter::Common common = EffectHelper::createParamCommon(
664 0 /* session */, 1 /* ioHandle */, 44100 /* iSampleRate */, 44100 /* oSampleRate */,
665 kInputFrameCount /* iFrameCount */, kOutputFrameCount /* oFrameCount */);
666 IEffect::OpenEffectReturn ret;
Shunkai Yaocb0fc412022-12-15 20:34:32 +0000667 ASSERT_NO_FATAL_FAILURE(open(mEffect, common, std::nullopt /* specific */, &ret, EX_NONE));
Shunkai Yao812d5b42022-11-16 18:08:50 +0000668 auto statusMQ = std::make_unique<EffectHelper::StatusMQ>(ret.statusMQ);
Shunkai Yaocb0fc412022-12-15 20:34:32 +0000669 ASSERT_TRUE(statusMQ->isValid());
Shunkai Yao812d5b42022-11-16 18:08:50 +0000670 auto inputMQ = std::make_unique<EffectHelper::DataMQ>(ret.inputDataMQ);
Shunkai Yaocb0fc412022-12-15 20:34:32 +0000671 ASSERT_TRUE(inputMQ->isValid());
Shunkai Yao812d5b42022-11-16 18:08:50 +0000672 auto outputMQ = std::make_unique<EffectHelper::DataMQ>(ret.outputDataMQ);
Shunkai Yaocb0fc412022-12-15 20:34:32 +0000673 ASSERT_TRUE(outputMQ->isValid());
Shunkai Yao812d5b42022-11-16 18:08:50 +0000674
Shunkai Yaocb0fc412022-12-15 20:34:32 +0000675 ASSERT_NO_FATAL_FAILURE(command(mEffect, CommandId::START));
676 ASSERT_NO_FATAL_FAILURE(expectState(mEffect, State::PROCESSING));
Shunkai Yao812d5b42022-11-16 18:08:50 +0000677
678 std::vector<float> buffer;
Shunkai Yaob49631f2023-02-03 01:44:32 +0000679 EXPECT_NO_FATAL_FAILURE(EffectHelper::allocateInputData(common, inputMQ, buffer));
Shunkai Yao41888a22023-04-10 17:13:30 +0000680 EXPECT_NO_FATAL_FAILURE(EffectHelper::writeToFmq(statusMQ, inputMQ, buffer));
Shunkai Yaob49631f2023-02-03 01:44:32 +0000681 EXPECT_NO_FATAL_FAILURE(
682 EffectHelper::readFromFmq(statusMQ, 1, outputMQ, buffer.size(), buffer));
Shunkai Yao812d5b42022-11-16 18:08:50 +0000683
Shunkai Yaocb0fc412022-12-15 20:34:32 +0000684 ASSERT_NO_FATAL_FAILURE(command(mEffect, CommandId::STOP));
685 ASSERT_NO_FATAL_FAILURE(expectState(mEffect, State::IDLE));
Shunkai Yaob49631f2023-02-03 01:44:32 +0000686 EXPECT_NO_FATAL_FAILURE(EffectHelper::readFromFmq(statusMQ, 0, outputMQ, 0, buffer));
Shunkai Yao812d5b42022-11-16 18:08:50 +0000687
Shunkai Yaocb0fc412022-12-15 20:34:32 +0000688 ASSERT_NO_FATAL_FAILURE(close(mEffect));
689 ASSERT_NO_FATAL_FAILURE(destroy(mFactory, mEffect));
Shunkai Yao812d5b42022-11-16 18:08:50 +0000690}
691
692// Send data to effects and expect it to be consumed after effect restart.
Jaideep Sharmacba42862023-06-23 10:27:39 +0530693// Effects exposing bypass flags or operating in offload mode will be skipped.
694TEST_P(AudioEffectDataPathTest, ConsumeDataAfterRestart) {
Shunkai Yaocb0fc412022-12-15 20:34:32 +0000695 ASSERT_NO_FATAL_FAILURE(create(mFactory, mEffect, mDescriptor));
Shunkai Yao812d5b42022-11-16 18:08:50 +0000696
697 Parameter::Common common = EffectHelper::createParamCommon(
698 0 /* session */, 1 /* ioHandle */, 44100 /* iSampleRate */, 44100 /* oSampleRate */,
699 kInputFrameCount /* iFrameCount */, kOutputFrameCount /* oFrameCount */);
700 IEffect::OpenEffectReturn ret;
Shunkai Yaocb0fc412022-12-15 20:34:32 +0000701 ASSERT_NO_FATAL_FAILURE(open(mEffect, common, std::nullopt /* specific */, &ret, EX_NONE));
Shunkai Yao812d5b42022-11-16 18:08:50 +0000702 auto statusMQ = std::make_unique<EffectHelper::StatusMQ>(ret.statusMQ);
Shunkai Yaocb0fc412022-12-15 20:34:32 +0000703 ASSERT_TRUE(statusMQ->isValid());
Shunkai Yao812d5b42022-11-16 18:08:50 +0000704 auto inputMQ = std::make_unique<EffectHelper::DataMQ>(ret.inputDataMQ);
Shunkai Yaocb0fc412022-12-15 20:34:32 +0000705 ASSERT_TRUE(inputMQ->isValid());
Shunkai Yao812d5b42022-11-16 18:08:50 +0000706 auto outputMQ = std::make_unique<EffectHelper::DataMQ>(ret.outputDataMQ);
Shunkai Yaocb0fc412022-12-15 20:34:32 +0000707 ASSERT_TRUE(outputMQ->isValid());
Shunkai Yao812d5b42022-11-16 18:08:50 +0000708
Shunkai Yao812d5b42022-11-16 18:08:50 +0000709 std::vector<float> buffer;
Shunkai Yaob49631f2023-02-03 01:44:32 +0000710 ASSERT_NO_FATAL_FAILURE(command(mEffect, CommandId::START));
711 ASSERT_NO_FATAL_FAILURE(expectState(mEffect, State::PROCESSING));
712 ASSERT_NO_FATAL_FAILURE(command(mEffect, CommandId::STOP));
713 ASSERT_NO_FATAL_FAILURE(expectState(mEffect, State::IDLE));
714 EXPECT_NO_FATAL_FAILURE(
715 EffectHelper::readFromFmq(statusMQ, 0, outputMQ, buffer.size(), buffer));
716 ASSERT_NO_FATAL_FAILURE(command(mEffect, CommandId::START));
717 ASSERT_NO_FATAL_FAILURE(expectState(mEffect, State::PROCESSING));
718
719 EXPECT_NO_FATAL_FAILURE(EffectHelper::allocateInputData(common, inputMQ, buffer));
Shunkai Yao41888a22023-04-10 17:13:30 +0000720 EXPECT_NO_FATAL_FAILURE(EffectHelper::writeToFmq(statusMQ, inputMQ, buffer));
Shunkai Yaob49631f2023-02-03 01:44:32 +0000721 EXPECT_NO_FATAL_FAILURE(
722 EffectHelper::readFromFmq(statusMQ, 1, outputMQ, buffer.size(), buffer));
Shunkai Yao812d5b42022-11-16 18:08:50 +0000723
Shunkai Yaocb0fc412022-12-15 20:34:32 +0000724 ASSERT_NO_FATAL_FAILURE(command(mEffect, CommandId::STOP));
725 ASSERT_NO_FATAL_FAILURE(expectState(mEffect, State::IDLE));
Shunkai Yaob49631f2023-02-03 01:44:32 +0000726 EXPECT_NO_FATAL_FAILURE(EffectHelper::readFromFmq(statusMQ, 0, outputMQ, 0, buffer));
Shunkai Yao812d5b42022-11-16 18:08:50 +0000727
Shunkai Yaocb0fc412022-12-15 20:34:32 +0000728 ASSERT_NO_FATAL_FAILURE(close(mEffect));
729 ASSERT_NO_FATAL_FAILURE(destroy(mFactory, mEffect));
Shunkai Yao812d5b42022-11-16 18:08:50 +0000730}
731
Shunkai Yao65c7c702024-01-09 20:50:53 +0000732// Send data to effects and expect it to be consumed after effect reopen (IO AudioConfig change).
733// Effects exposing bypass flags or operating in offload mode will be skipped.
734TEST_P(AudioEffectDataPathTest, ConsumeDataAfterReopen) {
735 ASSERT_NO_FATAL_FAILURE(create(mFactory, mEffect, mDescriptor));
736
737 Parameter::Common common = EffectHelper::createParamCommon(
738 0 /* session */, 1 /* ioHandle */, 44100 /* iSampleRate */, 44100 /* oSampleRate */,
739 kInputFrameCount /* iFrameCount */, kOutputFrameCount /* oFrameCount */);
740 IEffect::OpenEffectReturn ret;
741 ASSERT_NO_FATAL_FAILURE(open(mEffect, common, std::nullopt /* specific */, &ret, EX_NONE));
742 auto statusMQ = std::make_unique<EffectHelper::StatusMQ>(ret.statusMQ);
743 ASSERT_TRUE(statusMQ->isValid());
744 auto inputMQ = std::make_unique<EffectHelper::DataMQ>(ret.inputDataMQ);
745 ASSERT_TRUE(inputMQ->isValid());
746 auto outputMQ = std::make_unique<EffectHelper::DataMQ>(ret.outputDataMQ);
747 ASSERT_TRUE(outputMQ->isValid());
748
749 std::vector<float> buffer;
750 ASSERT_NO_FATAL_FAILURE(command(mEffect, CommandId::START));
751 ASSERT_NO_FATAL_FAILURE(expectState(mEffect, State::PROCESSING));
752 EXPECT_NO_FATAL_FAILURE(EffectHelper::allocateInputData(common, inputMQ, buffer));
753 EXPECT_NO_FATAL_FAILURE(EffectHelper::writeToFmq(statusMQ, inputMQ, buffer));
754 EXPECT_NO_FATAL_FAILURE(
755 EffectHelper::readFromFmq(statusMQ, 1, outputMQ, buffer.size(), buffer));
756
757 // set a new common parameter with different IO frameCount, reopen
758 Parameter::Id id = Parameter::Id::make<Parameter::Id::commonTag>(Parameter::common);
759 common.input.frameCount += 4;
760 common.output.frameCount += 4;
761 ASSERT_NO_FATAL_FAILURE(setAndGetParameter(id, Parameter::make<Parameter::common>(common)));
762 ASSERT_TRUE(statusMQ->isValid());
763 expectDataMqUpdateEventFlag(statusMQ);
764 EXPECT_IS_OK(mEffect->reopen(&ret));
765 inputMQ = std::make_unique<EffectHelper::DataMQ>(ret.inputDataMQ);
766 outputMQ = std::make_unique<EffectHelper::DataMQ>(ret.outputDataMQ);
767 ASSERT_TRUE(statusMQ->isValid());
768 ASSERT_TRUE(inputMQ->isValid());
769 ASSERT_TRUE(outputMQ->isValid());
770
771 // verify data consume again
772 EXPECT_NO_FATAL_FAILURE(EffectHelper::allocateInputData(common, inputMQ, buffer));
773 EXPECT_NO_FATAL_FAILURE(EffectHelper::writeToFmq(statusMQ, inputMQ, buffer));
774 EXPECT_NO_FATAL_FAILURE(
775 EffectHelper::readFromFmq(statusMQ, 1, outputMQ, buffer.size(), buffer));
776
777 ASSERT_NO_FATAL_FAILURE(command(mEffect, CommandId::STOP));
778 ASSERT_NO_FATAL_FAILURE(expectState(mEffect, State::IDLE));
779 EXPECT_NO_FATAL_FAILURE(EffectHelper::readFromFmq(statusMQ, 0, outputMQ, 0, buffer));
780
781 ASSERT_NO_FATAL_FAILURE(close(mEffect));
782 ASSERT_NO_FATAL_FAILURE(destroy(mFactory, mEffect));
783}
784
Shunkai Yao812d5b42022-11-16 18:08:50 +0000785// Send data to IDLE effects and expect it to be consumed after effect start.
Jaideep Sharmacba42862023-06-23 10:27:39 +0530786// Effects exposing bypass flags or operating in offload mode will be skipped.
787TEST_P(AudioEffectDataPathTest, SendDataAtIdleAndConsumeDataInProcessing) {
Shunkai Yaocb0fc412022-12-15 20:34:32 +0000788 ASSERT_NO_FATAL_FAILURE(create(mFactory, mEffect, mDescriptor));
Shunkai Yao812d5b42022-11-16 18:08:50 +0000789
790 Parameter::Common common = EffectHelper::createParamCommon(
791 0 /* session */, 1 /* ioHandle */, 44100 /* iSampleRate */, 44100 /* oSampleRate */,
792 kInputFrameCount /* iFrameCount */, kOutputFrameCount /* oFrameCount */);
793 IEffect::OpenEffectReturn ret;
Shunkai Yaocb0fc412022-12-15 20:34:32 +0000794 ASSERT_NO_FATAL_FAILURE(open(mEffect, common, std::nullopt /* specific */, &ret, EX_NONE));
Shunkai Yao812d5b42022-11-16 18:08:50 +0000795 auto statusMQ = std::make_unique<EffectHelper::StatusMQ>(ret.statusMQ);
Shunkai Yaocb0fc412022-12-15 20:34:32 +0000796 ASSERT_TRUE(statusMQ->isValid());
Shunkai Yao812d5b42022-11-16 18:08:50 +0000797 auto inputMQ = std::make_unique<EffectHelper::DataMQ>(ret.inputDataMQ);
Shunkai Yaocb0fc412022-12-15 20:34:32 +0000798 ASSERT_TRUE(inputMQ->isValid());
Shunkai Yao812d5b42022-11-16 18:08:50 +0000799 auto outputMQ = std::make_unique<EffectHelper::DataMQ>(ret.outputDataMQ);
Shunkai Yaocb0fc412022-12-15 20:34:32 +0000800 ASSERT_TRUE(outputMQ->isValid());
Shunkai Yao812d5b42022-11-16 18:08:50 +0000801
802 std::vector<float> buffer;
Shunkai Yaob49631f2023-02-03 01:44:32 +0000803 EXPECT_NO_FATAL_FAILURE(EffectHelper::allocateInputData(common, inputMQ, buffer));
Shunkai Yao41888a22023-04-10 17:13:30 +0000804 EXPECT_NO_FATAL_FAILURE(EffectHelper::writeToFmq(statusMQ, inputMQ, buffer));
Shunkai Yao812d5b42022-11-16 18:08:50 +0000805
Shunkai Yaocb0fc412022-12-15 20:34:32 +0000806 ASSERT_NO_FATAL_FAILURE(command(mEffect, CommandId::START));
807 ASSERT_NO_FATAL_FAILURE(expectState(mEffect, State::PROCESSING));
Shunkai Yao812d5b42022-11-16 18:08:50 +0000808
Shunkai Yaob49631f2023-02-03 01:44:32 +0000809 EXPECT_NO_FATAL_FAILURE(
810 EffectHelper::readFromFmq(statusMQ, 1, outputMQ, buffer.size(), buffer));
Shunkai Yao812d5b42022-11-16 18:08:50 +0000811
Shunkai Yaocb0fc412022-12-15 20:34:32 +0000812 ASSERT_NO_FATAL_FAILURE(command(mEffect, CommandId::STOP));
813 ASSERT_NO_FATAL_FAILURE(expectState(mEffect, State::IDLE));
Shunkai Yao812d5b42022-11-16 18:08:50 +0000814
Shunkai Yaocb0fc412022-12-15 20:34:32 +0000815 ASSERT_NO_FATAL_FAILURE(close(mEffect));
816 ASSERT_NO_FATAL_FAILURE(destroy(mFactory, mEffect));
Shunkai Yao812d5b42022-11-16 18:08:50 +0000817}
818
819// Send data multiple times.
Jaideep Sharmacba42862023-06-23 10:27:39 +0530820// Effects exposing bypass flags or operating in offload mode will be skipped.
821TEST_P(AudioEffectDataPathTest, ProcessDataMultipleTimes) {
Shunkai Yaocb0fc412022-12-15 20:34:32 +0000822 ASSERT_NO_FATAL_FAILURE(create(mFactory, mEffect, mDescriptor));
Shunkai Yao812d5b42022-11-16 18:08:50 +0000823
824 Parameter::Common common = EffectHelper::createParamCommon(
825 0 /* session */, 1 /* ioHandle */, 44100 /* iSampleRate */, 44100 /* oSampleRate */,
826 kInputFrameCount /* iFrameCount */, kOutputFrameCount /* oFrameCount */);
827 IEffect::OpenEffectReturn ret;
Shunkai Yaocb0fc412022-12-15 20:34:32 +0000828 ASSERT_NO_FATAL_FAILURE(open(mEffect, common, std::nullopt /* specific */, &ret, EX_NONE));
Shunkai Yao812d5b42022-11-16 18:08:50 +0000829 auto statusMQ = std::make_unique<EffectHelper::StatusMQ>(ret.statusMQ);
Shunkai Yaocb0fc412022-12-15 20:34:32 +0000830 ASSERT_TRUE(statusMQ->isValid());
Shunkai Yao812d5b42022-11-16 18:08:50 +0000831 auto inputMQ = std::make_unique<EffectHelper::DataMQ>(ret.inputDataMQ);
Shunkai Yaocb0fc412022-12-15 20:34:32 +0000832 ASSERT_TRUE(inputMQ->isValid());
Shunkai Yao812d5b42022-11-16 18:08:50 +0000833 auto outputMQ = std::make_unique<EffectHelper::DataMQ>(ret.outputDataMQ);
Shunkai Yaocb0fc412022-12-15 20:34:32 +0000834 ASSERT_TRUE(outputMQ->isValid());
Shunkai Yao812d5b42022-11-16 18:08:50 +0000835
836 std::vector<float> buffer;
Shunkai Yaob49631f2023-02-03 01:44:32 +0000837 EXPECT_NO_FATAL_FAILURE(EffectHelper::allocateInputData(common, inputMQ, buffer));
Shunkai Yao41888a22023-04-10 17:13:30 +0000838 EXPECT_NO_FATAL_FAILURE(EffectHelper::writeToFmq(statusMQ, inputMQ, buffer));
Shunkai Yaob49631f2023-02-03 01:44:32 +0000839 EXPECT_NO_FATAL_FAILURE(EffectHelper::readFromFmq(statusMQ, 0, outputMQ, 0, buffer));
Shunkai Yao812d5b42022-11-16 18:08:50 +0000840
Shunkai Yaocb0fc412022-12-15 20:34:32 +0000841 ASSERT_NO_FATAL_FAILURE(command(mEffect, CommandId::START));
842 ASSERT_NO_FATAL_FAILURE(expectState(mEffect, State::PROCESSING));
Shunkai Yao812d5b42022-11-16 18:08:50 +0000843
Shunkai Yaob49631f2023-02-03 01:44:32 +0000844 EXPECT_NO_FATAL_FAILURE(
845 EffectHelper::readFromFmq(statusMQ, 1, outputMQ, buffer.size(), buffer));
Shunkai Yao812d5b42022-11-16 18:08:50 +0000846
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(
849 EffectHelper::readFromFmq(statusMQ, 1, outputMQ, buffer.size(), buffer));
Shunkai Yao812d5b42022-11-16 18:08:50 +0000850
Shunkai Yaocb0fc412022-12-15 20:34:32 +0000851 ASSERT_NO_FATAL_FAILURE(command(mEffect, CommandId::STOP));
852 ASSERT_NO_FATAL_FAILURE(expectState(mEffect, State::IDLE));
Shunkai Yaob49631f2023-02-03 01:44:32 +0000853 EXPECT_NO_FATAL_FAILURE(EffectHelper::readFromFmq(statusMQ, 0, outputMQ, 0, buffer));
Shunkai Yao812d5b42022-11-16 18:08:50 +0000854
Shunkai Yaocb0fc412022-12-15 20:34:32 +0000855 ASSERT_NO_FATAL_FAILURE(close(mEffect));
856 ASSERT_NO_FATAL_FAILURE(destroy(mFactory, mEffect));
Shunkai Yao812d5b42022-11-16 18:08:50 +0000857}
858
Shunkai Yaob49631f2023-02-03 01:44:32 +0000859// Send data to processing state effects, stop, and restart.
Jaideep Sharmacba42862023-06-23 10:27:39 +0530860// Effects exposing bypass flags or operating in offload mode will be skipped.
861TEST_P(AudioEffectDataPathTest, ConsumeDataAndRestart) {
Shunkai Yaocb0fc412022-12-15 20:34:32 +0000862 ASSERT_NO_FATAL_FAILURE(create(mFactory, mEffect, mDescriptor));
Shunkai Yao812d5b42022-11-16 18:08:50 +0000863
864 Parameter::Common common = EffectHelper::createParamCommon(
865 0 /* session */, 1 /* ioHandle */, 44100 /* iSampleRate */, 44100 /* oSampleRate */,
866 kInputFrameCount /* iFrameCount */, kOutputFrameCount /* oFrameCount */);
867 IEffect::OpenEffectReturn ret;
Shunkai Yaocb0fc412022-12-15 20:34:32 +0000868 ASSERT_NO_FATAL_FAILURE(open(mEffect, common, std::nullopt /* specific */, &ret, EX_NONE));
Shunkai Yao812d5b42022-11-16 18:08:50 +0000869 auto statusMQ = std::make_unique<EffectHelper::StatusMQ>(ret.statusMQ);
Shunkai Yaocb0fc412022-12-15 20:34:32 +0000870 ASSERT_TRUE(statusMQ->isValid());
Shunkai Yao812d5b42022-11-16 18:08:50 +0000871 auto inputMQ = std::make_unique<EffectHelper::DataMQ>(ret.inputDataMQ);
Shunkai Yaocb0fc412022-12-15 20:34:32 +0000872 ASSERT_TRUE(inputMQ->isValid());
Shunkai Yao812d5b42022-11-16 18:08:50 +0000873 auto outputMQ = std::make_unique<EffectHelper::DataMQ>(ret.outputDataMQ);
Shunkai Yaocb0fc412022-12-15 20:34:32 +0000874 ASSERT_TRUE(outputMQ->isValid());
Shunkai Yao812d5b42022-11-16 18:08:50 +0000875
Shunkai Yaocb0fc412022-12-15 20:34:32 +0000876 ASSERT_NO_FATAL_FAILURE(command(mEffect, CommandId::START));
877 ASSERT_NO_FATAL_FAILURE(expectState(mEffect, State::PROCESSING));
Shunkai Yaob49631f2023-02-03 01:44:32 +0000878 std::vector<float> buffer;
879 EXPECT_NO_FATAL_FAILURE(EffectHelper::allocateInputData(common, inputMQ, buffer));
Shunkai Yao41888a22023-04-10 17:13:30 +0000880 EXPECT_NO_FATAL_FAILURE(EffectHelper::writeToFmq(statusMQ, inputMQ, buffer));
Shunkai Yaob49631f2023-02-03 01:44:32 +0000881 EXPECT_NO_FATAL_FAILURE(
882 EffectHelper::readFromFmq(statusMQ, 1, outputMQ, buffer.size(), buffer));
883
Shunkai Yaocb0fc412022-12-15 20:34:32 +0000884 ASSERT_NO_FATAL_FAILURE(command(mEffect, CommandId::STOP));
885 ASSERT_NO_FATAL_FAILURE(expectState(mEffect, State::IDLE));
Shunkai Yao41888a22023-04-10 17:13:30 +0000886 EXPECT_NO_FATAL_FAILURE(EffectHelper::writeToFmq(statusMQ, inputMQ, buffer));
Shunkai Yaob49631f2023-02-03 01:44:32 +0000887 EXPECT_NO_FATAL_FAILURE(EffectHelper::readFromFmq(statusMQ, 0, outputMQ, 0, buffer));
Shunkai Yao812d5b42022-11-16 18:08:50 +0000888
Shunkai Yaocb0fc412022-12-15 20:34:32 +0000889 ASSERT_NO_FATAL_FAILURE(command(mEffect, CommandId::START));
890 ASSERT_NO_FATAL_FAILURE(expectState(mEffect, State::PROCESSING));
Shunkai Yaob49631f2023-02-03 01:44:32 +0000891 EXPECT_NO_FATAL_FAILURE(
892 EffectHelper::readFromFmq(statusMQ, 1, outputMQ, buffer.size(), buffer));
Shunkai Yao812d5b42022-11-16 18:08:50 +0000893
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 Yao812d5b42022-11-16 18:08:50 +0000896
Shunkai Yaocb0fc412022-12-15 20:34:32 +0000897 ASSERT_NO_FATAL_FAILURE(close(mEffect));
898 ASSERT_NO_FATAL_FAILURE(destroy(mFactory, mEffect));
Shunkai Yao812d5b42022-11-16 18:08:50 +0000899}
900
901// Send data to closed effects and expect it not be consumed.
Jaideep Sharmacba42862023-06-23 10:27:39 +0530902// Effects exposing bypass flags or operating in offload mode will be skipped.
903TEST_P(AudioEffectDataPathTest, NotConsumeDataByClosedEffect) {
Shunkai Yaocb0fc412022-12-15 20:34:32 +0000904 ASSERT_NO_FATAL_FAILURE(create(mFactory, mEffect, mDescriptor));
Shunkai Yao812d5b42022-11-16 18:08:50 +0000905
906 Parameter::Common common = EffectHelper::createParamCommon(
907 0 /* session */, 1 /* ioHandle */, 44100 /* iSampleRate */, 44100 /* oSampleRate */,
908 kInputFrameCount /* iFrameCount */, kOutputFrameCount /* oFrameCount */);
909 IEffect::OpenEffectReturn ret;
Shunkai Yaocb0fc412022-12-15 20:34:32 +0000910 ASSERT_NO_FATAL_FAILURE(open(mEffect, common, std::nullopt /* specific */, &ret, EX_NONE));
911 ASSERT_NO_FATAL_FAILURE(close(mEffect));
Shunkai Yao812d5b42022-11-16 18:08:50 +0000912
913 auto statusMQ = std::make_unique<EffectHelper::StatusMQ>(ret.statusMQ);
Shunkai Yaocb0fc412022-12-15 20:34:32 +0000914 ASSERT_TRUE(statusMQ->isValid());
Shunkai Yao812d5b42022-11-16 18:08:50 +0000915 auto inputMQ = std::make_unique<EffectHelper::DataMQ>(ret.inputDataMQ);
Shunkai Yaocb0fc412022-12-15 20:34:32 +0000916 ASSERT_TRUE(inputMQ->isValid());
Shunkai Yao812d5b42022-11-16 18:08:50 +0000917 auto outputMQ = std::make_unique<EffectHelper::DataMQ>(ret.outputDataMQ);
Shunkai Yaocb0fc412022-12-15 20:34:32 +0000918 ASSERT_TRUE(outputMQ->isValid());
Shunkai Yao812d5b42022-11-16 18:08:50 +0000919
920 std::vector<float> buffer;
Shunkai Yaob49631f2023-02-03 01:44:32 +0000921 EXPECT_NO_FATAL_FAILURE(EffectHelper::allocateInputData(common, inputMQ, buffer));
Shunkai Yao41888a22023-04-10 17:13:30 +0000922 EXPECT_NO_FATAL_FAILURE(EffectHelper::writeToFmq(statusMQ, inputMQ, buffer));
Shunkai Yaob49631f2023-02-03 01:44:32 +0000923 EXPECT_NO_FATAL_FAILURE(EffectHelper::readFromFmq(statusMQ, 0, outputMQ, 0, buffer));
Shunkai Yao812d5b42022-11-16 18:08:50 +0000924
Shunkai Yaocb0fc412022-12-15 20:34:32 +0000925 ASSERT_NO_FATAL_FAILURE(destroy(mFactory, mEffect));
Shunkai Yao812d5b42022-11-16 18:08:50 +0000926}
927
928// Send data to multiple effects.
Jaideep Sharmacba42862023-06-23 10:27:39 +0530929// Effects exposing bypass flags or operating in offload mode will be skipped.
930TEST_P(AudioEffectDataPathTest, ConsumeDataMultipleEffects) {
Shunkai Yao812d5b42022-11-16 18:08:50 +0000931 std::shared_ptr<IEffect> effect1, effect2;
Shunkai Yaocb0fc412022-12-15 20:34:32 +0000932 ASSERT_NO_FATAL_FAILURE(create(mFactory, effect1, mDescriptor));
933 ASSERT_NO_FATAL_FAILURE(create(mFactory, effect2, mDescriptor));
Shunkai Yao812d5b42022-11-16 18:08:50 +0000934
935 Parameter::Common common1 = EffectHelper::createParamCommon(
936 0 /* session */, 1 /* ioHandle */, 44100 /* iSampleRate */, 44100 /* oSampleRate */,
937 kInputFrameCount /* iFrameCount */, kOutputFrameCount /* oFrameCount */);
938 Parameter::Common common2 = EffectHelper::createParamCommon(
939 1 /* session */, 1 /* ioHandle */, 48000 /* iSampleRate */, 48000 /* oSampleRate */,
940 2 * kInputFrameCount /* iFrameCount */, 2 * kOutputFrameCount /* oFrameCount */);
941 IEffect::OpenEffectReturn ret1, ret2;
942 ASSERT_NO_FATAL_FAILURE(open(effect1, common1, std::nullopt /* specific */, &ret1, EX_NONE));
943 ASSERT_NO_FATAL_FAILURE(open(effect2, common2, std::nullopt /* specific */, &ret2, EX_NONE));
944 ASSERT_NO_FATAL_FAILURE(command(effect1, CommandId::START));
945 ASSERT_NO_FATAL_FAILURE(expectState(effect1, State::PROCESSING));
946 ASSERT_NO_FATAL_FAILURE(command(effect2, CommandId::START));
947 ASSERT_NO_FATAL_FAILURE(expectState(effect2, State::PROCESSING));
948
949 auto statusMQ1 = std::make_unique<EffectHelper::StatusMQ>(ret1.statusMQ);
Shunkai Yaocb0fc412022-12-15 20:34:32 +0000950 ASSERT_TRUE(statusMQ1->isValid());
Shunkai Yao812d5b42022-11-16 18:08:50 +0000951 auto inputMQ1 = std::make_unique<EffectHelper::DataMQ>(ret1.inputDataMQ);
Shunkai Yaocb0fc412022-12-15 20:34:32 +0000952 ASSERT_TRUE(inputMQ1->isValid());
Shunkai Yao812d5b42022-11-16 18:08:50 +0000953 auto outputMQ1 = std::make_unique<EffectHelper::DataMQ>(ret1.outputDataMQ);
Shunkai Yaocb0fc412022-12-15 20:34:32 +0000954 ASSERT_TRUE(outputMQ1->isValid());
Shunkai Yao812d5b42022-11-16 18:08:50 +0000955
956 std::vector<float> buffer1, buffer2;
Shunkai Yaob49631f2023-02-03 01:44:32 +0000957 EXPECT_NO_FATAL_FAILURE(EffectHelper::allocateInputData(common1, inputMQ1, buffer1));
Shunkai Yao41888a22023-04-10 17:13:30 +0000958 EXPECT_NO_FATAL_FAILURE(EffectHelper::writeToFmq(statusMQ1, inputMQ1, buffer1));
Shunkai Yaob49631f2023-02-03 01:44:32 +0000959 EXPECT_NO_FATAL_FAILURE(
960 EffectHelper::readFromFmq(statusMQ1, 1, outputMQ1, buffer1.size(), buffer1));
Shunkai Yao812d5b42022-11-16 18:08:50 +0000961
962 auto statusMQ2 = std::make_unique<EffectHelper::StatusMQ>(ret2.statusMQ);
Shunkai Yaocb0fc412022-12-15 20:34:32 +0000963 ASSERT_TRUE(statusMQ2->isValid());
Shunkai Yao812d5b42022-11-16 18:08:50 +0000964 auto inputMQ2 = std::make_unique<EffectHelper::DataMQ>(ret2.inputDataMQ);
Shunkai Yaocb0fc412022-12-15 20:34:32 +0000965 ASSERT_TRUE(inputMQ2->isValid());
Shunkai Yao812d5b42022-11-16 18:08:50 +0000966 auto outputMQ2 = std::make_unique<EffectHelper::DataMQ>(ret2.outputDataMQ);
Shunkai Yaocb0fc412022-12-15 20:34:32 +0000967 ASSERT_TRUE(outputMQ2->isValid());
Shunkai Yaob49631f2023-02-03 01:44:32 +0000968 EXPECT_NO_FATAL_FAILURE(EffectHelper::allocateInputData(common2, inputMQ2, buffer2));
Shunkai Yao41888a22023-04-10 17:13:30 +0000969 EXPECT_NO_FATAL_FAILURE(EffectHelper::writeToFmq(statusMQ2, inputMQ2, buffer2));
Shunkai Yaob49631f2023-02-03 01:44:32 +0000970 EXPECT_NO_FATAL_FAILURE(
971 EffectHelper::readFromFmq(statusMQ2, 1, outputMQ2, buffer2.size(), buffer2));
Shunkai Yao812d5b42022-11-16 18:08:50 +0000972
973 ASSERT_NO_FATAL_FAILURE(command(effect1, CommandId::STOP));
974 ASSERT_NO_FATAL_FAILURE(expectState(effect1, State::IDLE));
975 ASSERT_NO_FATAL_FAILURE(close(effect1));
976 ASSERT_NO_FATAL_FAILURE(destroy(mFactory, effect1));
977
978 ASSERT_NO_FATAL_FAILURE(command(effect2, CommandId::STOP));
979 ASSERT_NO_FATAL_FAILURE(expectState(effect2, State::IDLE));
980 ASSERT_NO_FATAL_FAILURE(close(effect2));
981 ASSERT_NO_FATAL_FAILURE(destroy(mFactory, effect2));
982}
983
984INSTANTIATE_TEST_SUITE_P(
985 SingleEffectInstanceTest, AudioEffectTest,
986 ::testing::Combine(testing::ValuesIn(
987 EffectFactoryHelper::getAllEffectDescriptors(IFactory::descriptor))),
988 [](const testing::TestParamInfo<AudioEffectTest::ParamType>& info) {
Shunkai Yaocb0fc412022-12-15 20:34:32 +0000989 auto descriptor = std::get<PARAM_INSTANCE_NAME>(info.param).second;
Jaideep Sharmae4c7a962023-06-14 19:14:44 +0530990 std::string name = getPrefix(descriptor);
Shunkai Yao812d5b42022-11-16 18:08:50 +0000991 std::replace_if(
992 name.begin(), name.end(), [](const char c) { return !std::isalnum(c); }, '_');
993 return name;
994 });
Shunkai Yaoa4ab38c2022-10-14 01:07:47 +0000995GTEST_ALLOW_UNINSTANTIATED_PARAMETERIZED_TEST(AudioEffectTest);
Shunkai Yao67b1be62022-07-13 05:01:42 +0000996
Jaideep Sharmacba42862023-06-23 10:27:39 +0530997INSTANTIATE_TEST_SUITE_P(
998 SingleEffectInstanceTest, AudioEffectDataPathTest,
999 ::testing::Combine(testing::ValuesIn(
1000 EffectFactoryHelper::getAllEffectDescriptors(IFactory::descriptor))),
1001 [](const testing::TestParamInfo<AudioEffectDataPathTest::ParamType>& info) {
1002 auto descriptor = std::get<PARAM_INSTANCE_NAME>(info.param).second;
1003 std::string name = getPrefix(descriptor);
1004 std::replace_if(
1005 name.begin(), name.end(), [](const char c) { return !std::isalnum(c); }, '_');
1006 return name;
1007 });
1008
1009GTEST_ALLOW_UNINSTANTIATED_PARAMETERIZED_TEST(AudioEffectDataPathTest);
1010
Shunkai Yao67b1be62022-07-13 05:01:42 +00001011int main(int argc, char** argv) {
1012 ::testing::InitGoogleTest(&argc, argv);
Jaideep Sharma74498412023-09-13 15:25:25 +05301013 ::testing::UnitTest::GetInstance()->listeners().Append(new TestExecutionTracer());
Shunkai Yao67b1be62022-07-13 05:01:42 +00001014 ABinderProcess_setThreadPoolMaxThreadCount(1);
1015 ABinderProcess_startThreadPool();
1016 return RUN_ALL_TESTS();
Shunkai Yaoa4ab38c2022-10-14 01:07:47 +00001017}