blob: 1e6a49f80da7250d6cc7abf412247f25db46d368 [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 Yao65c7c702024-01-09 20:50:53 +0000611// Verify Parameters kept after reset.
612TEST_P(AudioEffectTest, SetCommonParameterAndReopen) {
613 ASSERT_NO_FATAL_FAILURE(create(mFactory, mEffect, mDescriptor));
614
615 Parameter::Common common = EffectHelper::createParamCommon(
616 0 /* session */, 1 /* ioHandle */, 44100 /* iSampleRate */, 44100 /* oSampleRate */,
617 kInputFrameCount /* iFrameCount */, kOutputFrameCount /* oFrameCount */);
618 IEffect::OpenEffectReturn ret;
619 ASSERT_NO_FATAL_FAILURE(open(mEffect, common, std::nullopt /* specific */, &ret, EX_NONE));
620 auto statusMQ = std::make_unique<EffectHelper::StatusMQ>(ret.statusMQ);
621 ASSERT_TRUE(statusMQ->isValid());
622 auto inputMQ = std::make_unique<EffectHelper::DataMQ>(ret.inputDataMQ);
623 ASSERT_TRUE(inputMQ->isValid());
624 auto outputMQ = std::make_unique<EffectHelper::DataMQ>(ret.outputDataMQ);
625 ASSERT_TRUE(outputMQ->isValid());
626
627 Parameter::Id id = Parameter::Id::make<Parameter::Id::commonTag>(Parameter::common);
628 common.input.frameCount++;
629 ASSERT_NO_FATAL_FAILURE(setAndGetParameter(id, Parameter::make<Parameter::common>(common)));
630 ASSERT_TRUE(statusMQ->isValid());
631 expectDataMqUpdateEventFlag(statusMQ);
632 EXPECT_IS_OK(mEffect->reopen(&ret));
633 inputMQ = std::make_unique<EffectHelper::DataMQ>(ret.inputDataMQ);
634 outputMQ = std::make_unique<EffectHelper::DataMQ>(ret.outputDataMQ);
635 ASSERT_TRUE(statusMQ->isValid());
636 ASSERT_TRUE(inputMQ->isValid());
637 ASSERT_TRUE(outputMQ->isValid());
638
639 common.output.frameCount++;
640 ASSERT_NO_FATAL_FAILURE(setAndGetParameter(id, Parameter::make<Parameter::common>(common)));
641 ASSERT_TRUE(statusMQ->isValid());
642 expectDataMqUpdateEventFlag(statusMQ);
643 EXPECT_IS_OK(mEffect->reopen(&ret));
644 inputMQ = std::make_unique<EffectHelper::DataMQ>(ret.inputDataMQ);
645 outputMQ = std::make_unique<EffectHelper::DataMQ>(ret.outputDataMQ);
646 ASSERT_TRUE(statusMQ->isValid());
647 ASSERT_TRUE(inputMQ->isValid());
648 ASSERT_TRUE(outputMQ->isValid());
649
650 ASSERT_NO_FATAL_FAILURE(close(mEffect));
651 ASSERT_NO_FATAL_FAILURE(destroy(mFactory, mEffect));
652}
653
Shunkai Yao812d5b42022-11-16 18:08:50 +0000654/// Data processing test
655// Send data to effects and expect it to be consumed by checking statusMQ.
Jaideep Sharmacba42862023-06-23 10:27:39 +0530656// Effects exposing bypass flags or operating in offload mode will be skipped.
657TEST_P(AudioEffectDataPathTest, ConsumeDataInProcessingState) {
Shunkai Yaocb0fc412022-12-15 20:34:32 +0000658 ASSERT_NO_FATAL_FAILURE(create(mFactory, mEffect, mDescriptor));
Shunkai Yao812d5b42022-11-16 18:08:50 +0000659
660 Parameter::Common common = EffectHelper::createParamCommon(
661 0 /* session */, 1 /* ioHandle */, 44100 /* iSampleRate */, 44100 /* oSampleRate */,
662 kInputFrameCount /* iFrameCount */, kOutputFrameCount /* oFrameCount */);
663 IEffect::OpenEffectReturn ret;
Shunkai Yaocb0fc412022-12-15 20:34:32 +0000664 ASSERT_NO_FATAL_FAILURE(open(mEffect, common, std::nullopt /* specific */, &ret, EX_NONE));
Shunkai Yao812d5b42022-11-16 18:08:50 +0000665 auto statusMQ = std::make_unique<EffectHelper::StatusMQ>(ret.statusMQ);
Shunkai Yaocb0fc412022-12-15 20:34:32 +0000666 ASSERT_TRUE(statusMQ->isValid());
Shunkai Yao812d5b42022-11-16 18:08:50 +0000667 auto inputMQ = std::make_unique<EffectHelper::DataMQ>(ret.inputDataMQ);
Shunkai Yaocb0fc412022-12-15 20:34:32 +0000668 ASSERT_TRUE(inputMQ->isValid());
Shunkai Yao812d5b42022-11-16 18:08:50 +0000669 auto outputMQ = std::make_unique<EffectHelper::DataMQ>(ret.outputDataMQ);
Shunkai Yaocb0fc412022-12-15 20:34:32 +0000670 ASSERT_TRUE(outputMQ->isValid());
Shunkai Yao812d5b42022-11-16 18:08:50 +0000671
Shunkai Yaocb0fc412022-12-15 20:34:32 +0000672 ASSERT_NO_FATAL_FAILURE(command(mEffect, CommandId::START));
673 ASSERT_NO_FATAL_FAILURE(expectState(mEffect, State::PROCESSING));
Shunkai Yao812d5b42022-11-16 18:08:50 +0000674
675 std::vector<float> buffer;
Shunkai Yaob49631f2023-02-03 01:44:32 +0000676 EXPECT_NO_FATAL_FAILURE(EffectHelper::allocateInputData(common, inputMQ, buffer));
Shunkai Yao41888a22023-04-10 17:13:30 +0000677 EXPECT_NO_FATAL_FAILURE(EffectHelper::writeToFmq(statusMQ, inputMQ, buffer));
Shunkai Yaob49631f2023-02-03 01:44:32 +0000678 EXPECT_NO_FATAL_FAILURE(
679 EffectHelper::readFromFmq(statusMQ, 1, outputMQ, buffer.size(), buffer));
Shunkai Yao812d5b42022-11-16 18:08:50 +0000680
Shunkai Yaocb0fc412022-12-15 20:34:32 +0000681 ASSERT_NO_FATAL_FAILURE(command(mEffect, CommandId::STOP));
682 ASSERT_NO_FATAL_FAILURE(expectState(mEffect, State::IDLE));
Shunkai Yaob49631f2023-02-03 01:44:32 +0000683 EXPECT_NO_FATAL_FAILURE(EffectHelper::readFromFmq(statusMQ, 0, outputMQ, 0, buffer));
Shunkai Yao812d5b42022-11-16 18:08:50 +0000684
Shunkai Yaocb0fc412022-12-15 20:34:32 +0000685 ASSERT_NO_FATAL_FAILURE(close(mEffect));
686 ASSERT_NO_FATAL_FAILURE(destroy(mFactory, mEffect));
Shunkai Yao812d5b42022-11-16 18:08:50 +0000687}
688
689// Send data to effects and expect it to be consumed after effect restart.
Jaideep Sharmacba42862023-06-23 10:27:39 +0530690// Effects exposing bypass flags or operating in offload mode will be skipped.
691TEST_P(AudioEffectDataPathTest, ConsumeDataAfterRestart) {
Shunkai Yaocb0fc412022-12-15 20:34:32 +0000692 ASSERT_NO_FATAL_FAILURE(create(mFactory, mEffect, mDescriptor));
Shunkai Yao812d5b42022-11-16 18:08:50 +0000693
694 Parameter::Common common = EffectHelper::createParamCommon(
695 0 /* session */, 1 /* ioHandle */, 44100 /* iSampleRate */, 44100 /* oSampleRate */,
696 kInputFrameCount /* iFrameCount */, kOutputFrameCount /* oFrameCount */);
697 IEffect::OpenEffectReturn ret;
Shunkai Yaocb0fc412022-12-15 20:34:32 +0000698 ASSERT_NO_FATAL_FAILURE(open(mEffect, common, std::nullopt /* specific */, &ret, EX_NONE));
Shunkai Yao812d5b42022-11-16 18:08:50 +0000699 auto statusMQ = std::make_unique<EffectHelper::StatusMQ>(ret.statusMQ);
Shunkai Yaocb0fc412022-12-15 20:34:32 +0000700 ASSERT_TRUE(statusMQ->isValid());
Shunkai Yao812d5b42022-11-16 18:08:50 +0000701 auto inputMQ = std::make_unique<EffectHelper::DataMQ>(ret.inputDataMQ);
Shunkai Yaocb0fc412022-12-15 20:34:32 +0000702 ASSERT_TRUE(inputMQ->isValid());
Shunkai Yao812d5b42022-11-16 18:08:50 +0000703 auto outputMQ = std::make_unique<EffectHelper::DataMQ>(ret.outputDataMQ);
Shunkai Yaocb0fc412022-12-15 20:34:32 +0000704 ASSERT_TRUE(outputMQ->isValid());
Shunkai Yao812d5b42022-11-16 18:08:50 +0000705
Shunkai Yao812d5b42022-11-16 18:08:50 +0000706 std::vector<float> buffer;
Shunkai Yaob49631f2023-02-03 01:44:32 +0000707 ASSERT_NO_FATAL_FAILURE(command(mEffect, CommandId::START));
708 ASSERT_NO_FATAL_FAILURE(expectState(mEffect, State::PROCESSING));
709 ASSERT_NO_FATAL_FAILURE(command(mEffect, CommandId::STOP));
710 ASSERT_NO_FATAL_FAILURE(expectState(mEffect, State::IDLE));
711 EXPECT_NO_FATAL_FAILURE(
712 EffectHelper::readFromFmq(statusMQ, 0, outputMQ, buffer.size(), buffer));
713 ASSERT_NO_FATAL_FAILURE(command(mEffect, CommandId::START));
714 ASSERT_NO_FATAL_FAILURE(expectState(mEffect, State::PROCESSING));
715
716 EXPECT_NO_FATAL_FAILURE(EffectHelper::allocateInputData(common, inputMQ, buffer));
Shunkai Yao41888a22023-04-10 17:13:30 +0000717 EXPECT_NO_FATAL_FAILURE(EffectHelper::writeToFmq(statusMQ, inputMQ, buffer));
Shunkai Yaob49631f2023-02-03 01:44:32 +0000718 EXPECT_NO_FATAL_FAILURE(
719 EffectHelper::readFromFmq(statusMQ, 1, outputMQ, buffer.size(), buffer));
Shunkai Yao812d5b42022-11-16 18:08:50 +0000720
Shunkai Yaocb0fc412022-12-15 20:34:32 +0000721 ASSERT_NO_FATAL_FAILURE(command(mEffect, CommandId::STOP));
722 ASSERT_NO_FATAL_FAILURE(expectState(mEffect, State::IDLE));
Shunkai Yaob49631f2023-02-03 01:44:32 +0000723 EXPECT_NO_FATAL_FAILURE(EffectHelper::readFromFmq(statusMQ, 0, outputMQ, 0, buffer));
Shunkai Yao812d5b42022-11-16 18:08:50 +0000724
Shunkai Yaocb0fc412022-12-15 20:34:32 +0000725 ASSERT_NO_FATAL_FAILURE(close(mEffect));
726 ASSERT_NO_FATAL_FAILURE(destroy(mFactory, mEffect));
Shunkai Yao812d5b42022-11-16 18:08:50 +0000727}
728
Shunkai Yao65c7c702024-01-09 20:50:53 +0000729// Send data to effects and expect it to be consumed after effect reopen (IO AudioConfig change).
730// Effects exposing bypass flags or operating in offload mode will be skipped.
731TEST_P(AudioEffectDataPathTest, ConsumeDataAfterReopen) {
732 ASSERT_NO_FATAL_FAILURE(create(mFactory, mEffect, mDescriptor));
733
734 Parameter::Common common = EffectHelper::createParamCommon(
735 0 /* session */, 1 /* ioHandle */, 44100 /* iSampleRate */, 44100 /* oSampleRate */,
736 kInputFrameCount /* iFrameCount */, kOutputFrameCount /* oFrameCount */);
737 IEffect::OpenEffectReturn ret;
738 ASSERT_NO_FATAL_FAILURE(open(mEffect, common, std::nullopt /* specific */, &ret, EX_NONE));
739 auto statusMQ = std::make_unique<EffectHelper::StatusMQ>(ret.statusMQ);
740 ASSERT_TRUE(statusMQ->isValid());
741 auto inputMQ = std::make_unique<EffectHelper::DataMQ>(ret.inputDataMQ);
742 ASSERT_TRUE(inputMQ->isValid());
743 auto outputMQ = std::make_unique<EffectHelper::DataMQ>(ret.outputDataMQ);
744 ASSERT_TRUE(outputMQ->isValid());
745
746 std::vector<float> buffer;
747 ASSERT_NO_FATAL_FAILURE(command(mEffect, CommandId::START));
748 ASSERT_NO_FATAL_FAILURE(expectState(mEffect, State::PROCESSING));
749 EXPECT_NO_FATAL_FAILURE(EffectHelper::allocateInputData(common, inputMQ, buffer));
750 EXPECT_NO_FATAL_FAILURE(EffectHelper::writeToFmq(statusMQ, inputMQ, buffer));
751 EXPECT_NO_FATAL_FAILURE(
752 EffectHelper::readFromFmq(statusMQ, 1, outputMQ, buffer.size(), buffer));
753
754 // set a new common parameter with different IO frameCount, reopen
755 Parameter::Id id = Parameter::Id::make<Parameter::Id::commonTag>(Parameter::common);
756 common.input.frameCount += 4;
757 common.output.frameCount += 4;
758 ASSERT_NO_FATAL_FAILURE(setAndGetParameter(id, Parameter::make<Parameter::common>(common)));
759 ASSERT_TRUE(statusMQ->isValid());
760 expectDataMqUpdateEventFlag(statusMQ);
761 EXPECT_IS_OK(mEffect->reopen(&ret));
762 inputMQ = std::make_unique<EffectHelper::DataMQ>(ret.inputDataMQ);
763 outputMQ = std::make_unique<EffectHelper::DataMQ>(ret.outputDataMQ);
764 ASSERT_TRUE(statusMQ->isValid());
765 ASSERT_TRUE(inputMQ->isValid());
766 ASSERT_TRUE(outputMQ->isValid());
767
768 // verify data consume again
769 EXPECT_NO_FATAL_FAILURE(EffectHelper::allocateInputData(common, inputMQ, buffer));
770 EXPECT_NO_FATAL_FAILURE(EffectHelper::writeToFmq(statusMQ, inputMQ, buffer));
771 EXPECT_NO_FATAL_FAILURE(
772 EffectHelper::readFromFmq(statusMQ, 1, outputMQ, buffer.size(), buffer));
773
774 ASSERT_NO_FATAL_FAILURE(command(mEffect, CommandId::STOP));
775 ASSERT_NO_FATAL_FAILURE(expectState(mEffect, State::IDLE));
776 EXPECT_NO_FATAL_FAILURE(EffectHelper::readFromFmq(statusMQ, 0, outputMQ, 0, buffer));
777
778 ASSERT_NO_FATAL_FAILURE(close(mEffect));
779 ASSERT_NO_FATAL_FAILURE(destroy(mFactory, mEffect));
780}
781
Shunkai Yao812d5b42022-11-16 18:08:50 +0000782// Send data to IDLE effects and expect it to be consumed after effect start.
Jaideep Sharmacba42862023-06-23 10:27:39 +0530783// Effects exposing bypass flags or operating in offload mode will be skipped.
784TEST_P(AudioEffectDataPathTest, SendDataAtIdleAndConsumeDataInProcessing) {
Shunkai Yaocb0fc412022-12-15 20:34:32 +0000785 ASSERT_NO_FATAL_FAILURE(create(mFactory, mEffect, mDescriptor));
Shunkai Yao812d5b42022-11-16 18:08:50 +0000786
787 Parameter::Common common = EffectHelper::createParamCommon(
788 0 /* session */, 1 /* ioHandle */, 44100 /* iSampleRate */, 44100 /* oSampleRate */,
789 kInputFrameCount /* iFrameCount */, kOutputFrameCount /* oFrameCount */);
790 IEffect::OpenEffectReturn ret;
Shunkai Yaocb0fc412022-12-15 20:34:32 +0000791 ASSERT_NO_FATAL_FAILURE(open(mEffect, common, std::nullopt /* specific */, &ret, EX_NONE));
Shunkai Yao812d5b42022-11-16 18:08:50 +0000792 auto statusMQ = std::make_unique<EffectHelper::StatusMQ>(ret.statusMQ);
Shunkai Yaocb0fc412022-12-15 20:34:32 +0000793 ASSERT_TRUE(statusMQ->isValid());
Shunkai Yao812d5b42022-11-16 18:08:50 +0000794 auto inputMQ = std::make_unique<EffectHelper::DataMQ>(ret.inputDataMQ);
Shunkai Yaocb0fc412022-12-15 20:34:32 +0000795 ASSERT_TRUE(inputMQ->isValid());
Shunkai Yao812d5b42022-11-16 18:08:50 +0000796 auto outputMQ = std::make_unique<EffectHelper::DataMQ>(ret.outputDataMQ);
Shunkai Yaocb0fc412022-12-15 20:34:32 +0000797 ASSERT_TRUE(outputMQ->isValid());
Shunkai Yao812d5b42022-11-16 18:08:50 +0000798
799 std::vector<float> buffer;
Shunkai Yaob49631f2023-02-03 01:44:32 +0000800 EXPECT_NO_FATAL_FAILURE(EffectHelper::allocateInputData(common, inputMQ, buffer));
Shunkai Yao41888a22023-04-10 17:13:30 +0000801 EXPECT_NO_FATAL_FAILURE(EffectHelper::writeToFmq(statusMQ, inputMQ, buffer));
Shunkai Yao812d5b42022-11-16 18:08:50 +0000802
Shunkai Yaocb0fc412022-12-15 20:34:32 +0000803 ASSERT_NO_FATAL_FAILURE(command(mEffect, CommandId::START));
804 ASSERT_NO_FATAL_FAILURE(expectState(mEffect, State::PROCESSING));
Shunkai Yao812d5b42022-11-16 18:08:50 +0000805
Shunkai Yaob49631f2023-02-03 01:44:32 +0000806 EXPECT_NO_FATAL_FAILURE(
807 EffectHelper::readFromFmq(statusMQ, 1, outputMQ, buffer.size(), buffer));
Shunkai Yao812d5b42022-11-16 18:08:50 +0000808
Shunkai Yaocb0fc412022-12-15 20:34:32 +0000809 ASSERT_NO_FATAL_FAILURE(command(mEffect, CommandId::STOP));
810 ASSERT_NO_FATAL_FAILURE(expectState(mEffect, State::IDLE));
Shunkai Yao812d5b42022-11-16 18:08:50 +0000811
Shunkai Yaocb0fc412022-12-15 20:34:32 +0000812 ASSERT_NO_FATAL_FAILURE(close(mEffect));
813 ASSERT_NO_FATAL_FAILURE(destroy(mFactory, mEffect));
Shunkai Yao812d5b42022-11-16 18:08:50 +0000814}
815
816// Send data multiple times.
Jaideep Sharmacba42862023-06-23 10:27:39 +0530817// Effects exposing bypass flags or operating in offload mode will be skipped.
818TEST_P(AudioEffectDataPathTest, ProcessDataMultipleTimes) {
Shunkai Yaocb0fc412022-12-15 20:34:32 +0000819 ASSERT_NO_FATAL_FAILURE(create(mFactory, mEffect, mDescriptor));
Shunkai Yao812d5b42022-11-16 18:08:50 +0000820
821 Parameter::Common common = EffectHelper::createParamCommon(
822 0 /* session */, 1 /* ioHandle */, 44100 /* iSampleRate */, 44100 /* oSampleRate */,
823 kInputFrameCount /* iFrameCount */, kOutputFrameCount /* oFrameCount */);
824 IEffect::OpenEffectReturn ret;
Shunkai Yaocb0fc412022-12-15 20:34:32 +0000825 ASSERT_NO_FATAL_FAILURE(open(mEffect, common, std::nullopt /* specific */, &ret, EX_NONE));
Shunkai Yao812d5b42022-11-16 18:08:50 +0000826 auto statusMQ = std::make_unique<EffectHelper::StatusMQ>(ret.statusMQ);
Shunkai Yaocb0fc412022-12-15 20:34:32 +0000827 ASSERT_TRUE(statusMQ->isValid());
Shunkai Yao812d5b42022-11-16 18:08:50 +0000828 auto inputMQ = std::make_unique<EffectHelper::DataMQ>(ret.inputDataMQ);
Shunkai Yaocb0fc412022-12-15 20:34:32 +0000829 ASSERT_TRUE(inputMQ->isValid());
Shunkai Yao812d5b42022-11-16 18:08:50 +0000830 auto outputMQ = std::make_unique<EffectHelper::DataMQ>(ret.outputDataMQ);
Shunkai Yaocb0fc412022-12-15 20:34:32 +0000831 ASSERT_TRUE(outputMQ->isValid());
Shunkai Yao812d5b42022-11-16 18:08:50 +0000832
833 std::vector<float> buffer;
Shunkai Yaob49631f2023-02-03 01:44:32 +0000834 EXPECT_NO_FATAL_FAILURE(EffectHelper::allocateInputData(common, inputMQ, buffer));
Shunkai Yao41888a22023-04-10 17:13:30 +0000835 EXPECT_NO_FATAL_FAILURE(EffectHelper::writeToFmq(statusMQ, inputMQ, buffer));
Shunkai Yaob49631f2023-02-03 01:44:32 +0000836 EXPECT_NO_FATAL_FAILURE(EffectHelper::readFromFmq(statusMQ, 0, outputMQ, 0, buffer));
Shunkai Yao812d5b42022-11-16 18:08:50 +0000837
Shunkai Yaocb0fc412022-12-15 20:34:32 +0000838 ASSERT_NO_FATAL_FAILURE(command(mEffect, CommandId::START));
839 ASSERT_NO_FATAL_FAILURE(expectState(mEffect, State::PROCESSING));
Shunkai Yao812d5b42022-11-16 18:08:50 +0000840
Shunkai Yaob49631f2023-02-03 01:44:32 +0000841 EXPECT_NO_FATAL_FAILURE(
842 EffectHelper::readFromFmq(statusMQ, 1, outputMQ, buffer.size(), buffer));
Shunkai Yao812d5b42022-11-16 18:08:50 +0000843
Shunkai Yao41888a22023-04-10 17:13:30 +0000844 EXPECT_NO_FATAL_FAILURE(EffectHelper::writeToFmq(statusMQ, inputMQ, buffer));
Shunkai Yaob49631f2023-02-03 01:44:32 +0000845 EXPECT_NO_FATAL_FAILURE(
846 EffectHelper::readFromFmq(statusMQ, 1, outputMQ, buffer.size(), buffer));
Shunkai Yao812d5b42022-11-16 18:08:50 +0000847
Shunkai Yaocb0fc412022-12-15 20:34:32 +0000848 ASSERT_NO_FATAL_FAILURE(command(mEffect, CommandId::STOP));
849 ASSERT_NO_FATAL_FAILURE(expectState(mEffect, State::IDLE));
Shunkai Yaob49631f2023-02-03 01:44:32 +0000850 EXPECT_NO_FATAL_FAILURE(EffectHelper::readFromFmq(statusMQ, 0, outputMQ, 0, buffer));
Shunkai Yao812d5b42022-11-16 18:08:50 +0000851
Shunkai Yaocb0fc412022-12-15 20:34:32 +0000852 ASSERT_NO_FATAL_FAILURE(close(mEffect));
853 ASSERT_NO_FATAL_FAILURE(destroy(mFactory, mEffect));
Shunkai Yao812d5b42022-11-16 18:08:50 +0000854}
855
Shunkai Yaob49631f2023-02-03 01:44:32 +0000856// Send data to processing state effects, stop, and restart.
Jaideep Sharmacba42862023-06-23 10:27:39 +0530857// Effects exposing bypass flags or operating in offload mode will be skipped.
858TEST_P(AudioEffectDataPathTest, ConsumeDataAndRestart) {
Shunkai Yaocb0fc412022-12-15 20:34:32 +0000859 ASSERT_NO_FATAL_FAILURE(create(mFactory, mEffect, mDescriptor));
Shunkai Yao812d5b42022-11-16 18:08:50 +0000860
861 Parameter::Common common = EffectHelper::createParamCommon(
862 0 /* session */, 1 /* ioHandle */, 44100 /* iSampleRate */, 44100 /* oSampleRate */,
863 kInputFrameCount /* iFrameCount */, kOutputFrameCount /* oFrameCount */);
864 IEffect::OpenEffectReturn ret;
Shunkai Yaocb0fc412022-12-15 20:34:32 +0000865 ASSERT_NO_FATAL_FAILURE(open(mEffect, common, std::nullopt /* specific */, &ret, EX_NONE));
Shunkai Yao812d5b42022-11-16 18:08:50 +0000866 auto statusMQ = std::make_unique<EffectHelper::StatusMQ>(ret.statusMQ);
Shunkai Yaocb0fc412022-12-15 20:34:32 +0000867 ASSERT_TRUE(statusMQ->isValid());
Shunkai Yao812d5b42022-11-16 18:08:50 +0000868 auto inputMQ = std::make_unique<EffectHelper::DataMQ>(ret.inputDataMQ);
Shunkai Yaocb0fc412022-12-15 20:34:32 +0000869 ASSERT_TRUE(inputMQ->isValid());
Shunkai Yao812d5b42022-11-16 18:08:50 +0000870 auto outputMQ = std::make_unique<EffectHelper::DataMQ>(ret.outputDataMQ);
Shunkai Yaocb0fc412022-12-15 20:34:32 +0000871 ASSERT_TRUE(outputMQ->isValid());
Shunkai Yao812d5b42022-11-16 18:08:50 +0000872
Shunkai Yaocb0fc412022-12-15 20:34:32 +0000873 ASSERT_NO_FATAL_FAILURE(command(mEffect, CommandId::START));
874 ASSERT_NO_FATAL_FAILURE(expectState(mEffect, State::PROCESSING));
Shunkai Yaob49631f2023-02-03 01:44:32 +0000875 std::vector<float> buffer;
876 EXPECT_NO_FATAL_FAILURE(EffectHelper::allocateInputData(common, inputMQ, buffer));
Shunkai Yao41888a22023-04-10 17:13:30 +0000877 EXPECT_NO_FATAL_FAILURE(EffectHelper::writeToFmq(statusMQ, inputMQ, buffer));
Shunkai Yaob49631f2023-02-03 01:44:32 +0000878 EXPECT_NO_FATAL_FAILURE(
879 EffectHelper::readFromFmq(statusMQ, 1, outputMQ, buffer.size(), buffer));
880
Shunkai Yaocb0fc412022-12-15 20:34:32 +0000881 ASSERT_NO_FATAL_FAILURE(command(mEffect, CommandId::STOP));
882 ASSERT_NO_FATAL_FAILURE(expectState(mEffect, State::IDLE));
Shunkai Yao41888a22023-04-10 17:13:30 +0000883 EXPECT_NO_FATAL_FAILURE(EffectHelper::writeToFmq(statusMQ, inputMQ, buffer));
Shunkai Yaob49631f2023-02-03 01:44:32 +0000884 EXPECT_NO_FATAL_FAILURE(EffectHelper::readFromFmq(statusMQ, 0, outputMQ, 0, buffer));
Shunkai Yao812d5b42022-11-16 18:08:50 +0000885
Shunkai Yaocb0fc412022-12-15 20:34:32 +0000886 ASSERT_NO_FATAL_FAILURE(command(mEffect, CommandId::START));
887 ASSERT_NO_FATAL_FAILURE(expectState(mEffect, State::PROCESSING));
Shunkai Yaob49631f2023-02-03 01:44:32 +0000888 EXPECT_NO_FATAL_FAILURE(
889 EffectHelper::readFromFmq(statusMQ, 1, outputMQ, buffer.size(), buffer));
Shunkai Yao812d5b42022-11-16 18:08:50 +0000890
Shunkai Yaocb0fc412022-12-15 20:34:32 +0000891 ASSERT_NO_FATAL_FAILURE(command(mEffect, CommandId::STOP));
892 ASSERT_NO_FATAL_FAILURE(expectState(mEffect, State::IDLE));
Shunkai Yao812d5b42022-11-16 18:08:50 +0000893
Shunkai Yaocb0fc412022-12-15 20:34:32 +0000894 ASSERT_NO_FATAL_FAILURE(close(mEffect));
895 ASSERT_NO_FATAL_FAILURE(destroy(mFactory, mEffect));
Shunkai Yao812d5b42022-11-16 18:08:50 +0000896}
897
898// Send data to closed effects and expect it not be consumed.
Jaideep Sharmacba42862023-06-23 10:27:39 +0530899// Effects exposing bypass flags or operating in offload mode will be skipped.
900TEST_P(AudioEffectDataPathTest, NotConsumeDataByClosedEffect) {
Shunkai Yaocb0fc412022-12-15 20:34:32 +0000901 ASSERT_NO_FATAL_FAILURE(create(mFactory, mEffect, mDescriptor));
Shunkai Yao812d5b42022-11-16 18:08:50 +0000902
903 Parameter::Common common = EffectHelper::createParamCommon(
904 0 /* session */, 1 /* ioHandle */, 44100 /* iSampleRate */, 44100 /* oSampleRate */,
905 kInputFrameCount /* iFrameCount */, kOutputFrameCount /* oFrameCount */);
906 IEffect::OpenEffectReturn ret;
Shunkai Yaocb0fc412022-12-15 20:34:32 +0000907 ASSERT_NO_FATAL_FAILURE(open(mEffect, common, std::nullopt /* specific */, &ret, EX_NONE));
908 ASSERT_NO_FATAL_FAILURE(close(mEffect));
Shunkai Yao812d5b42022-11-16 18:08:50 +0000909
910 auto statusMQ = std::make_unique<EffectHelper::StatusMQ>(ret.statusMQ);
Shunkai Yaocb0fc412022-12-15 20:34:32 +0000911 ASSERT_TRUE(statusMQ->isValid());
Shunkai Yao812d5b42022-11-16 18:08:50 +0000912 auto inputMQ = std::make_unique<EffectHelper::DataMQ>(ret.inputDataMQ);
Shunkai Yaocb0fc412022-12-15 20:34:32 +0000913 ASSERT_TRUE(inputMQ->isValid());
Shunkai Yao812d5b42022-11-16 18:08:50 +0000914 auto outputMQ = std::make_unique<EffectHelper::DataMQ>(ret.outputDataMQ);
Shunkai Yaocb0fc412022-12-15 20:34:32 +0000915 ASSERT_TRUE(outputMQ->isValid());
Shunkai Yao812d5b42022-11-16 18:08:50 +0000916
917 std::vector<float> buffer;
Shunkai Yaob49631f2023-02-03 01:44:32 +0000918 EXPECT_NO_FATAL_FAILURE(EffectHelper::allocateInputData(common, inputMQ, buffer));
Shunkai Yao41888a22023-04-10 17:13:30 +0000919 EXPECT_NO_FATAL_FAILURE(EffectHelper::writeToFmq(statusMQ, inputMQ, buffer));
Shunkai Yaob49631f2023-02-03 01:44:32 +0000920 EXPECT_NO_FATAL_FAILURE(EffectHelper::readFromFmq(statusMQ, 0, outputMQ, 0, buffer));
Shunkai Yao812d5b42022-11-16 18:08:50 +0000921
Shunkai Yaocb0fc412022-12-15 20:34:32 +0000922 ASSERT_NO_FATAL_FAILURE(destroy(mFactory, mEffect));
Shunkai Yao812d5b42022-11-16 18:08:50 +0000923}
924
925// Send data to multiple effects.
Jaideep Sharmacba42862023-06-23 10:27:39 +0530926// Effects exposing bypass flags or operating in offload mode will be skipped.
927TEST_P(AudioEffectDataPathTest, ConsumeDataMultipleEffects) {
Shunkai Yao812d5b42022-11-16 18:08:50 +0000928 std::shared_ptr<IEffect> effect1, effect2;
Shunkai Yaocb0fc412022-12-15 20:34:32 +0000929 ASSERT_NO_FATAL_FAILURE(create(mFactory, effect1, mDescriptor));
930 ASSERT_NO_FATAL_FAILURE(create(mFactory, effect2, mDescriptor));
Shunkai Yao812d5b42022-11-16 18:08:50 +0000931
932 Parameter::Common common1 = EffectHelper::createParamCommon(
933 0 /* session */, 1 /* ioHandle */, 44100 /* iSampleRate */, 44100 /* oSampleRate */,
934 kInputFrameCount /* iFrameCount */, kOutputFrameCount /* oFrameCount */);
935 Parameter::Common common2 = EffectHelper::createParamCommon(
936 1 /* session */, 1 /* ioHandle */, 48000 /* iSampleRate */, 48000 /* oSampleRate */,
937 2 * kInputFrameCount /* iFrameCount */, 2 * kOutputFrameCount /* oFrameCount */);
938 IEffect::OpenEffectReturn ret1, ret2;
939 ASSERT_NO_FATAL_FAILURE(open(effect1, common1, std::nullopt /* specific */, &ret1, EX_NONE));
940 ASSERT_NO_FATAL_FAILURE(open(effect2, common2, std::nullopt /* specific */, &ret2, EX_NONE));
941 ASSERT_NO_FATAL_FAILURE(command(effect1, CommandId::START));
942 ASSERT_NO_FATAL_FAILURE(expectState(effect1, State::PROCESSING));
943 ASSERT_NO_FATAL_FAILURE(command(effect2, CommandId::START));
944 ASSERT_NO_FATAL_FAILURE(expectState(effect2, State::PROCESSING));
945
946 auto statusMQ1 = std::make_unique<EffectHelper::StatusMQ>(ret1.statusMQ);
Shunkai Yaocb0fc412022-12-15 20:34:32 +0000947 ASSERT_TRUE(statusMQ1->isValid());
Shunkai Yao812d5b42022-11-16 18:08:50 +0000948 auto inputMQ1 = std::make_unique<EffectHelper::DataMQ>(ret1.inputDataMQ);
Shunkai Yaocb0fc412022-12-15 20:34:32 +0000949 ASSERT_TRUE(inputMQ1->isValid());
Shunkai Yao812d5b42022-11-16 18:08:50 +0000950 auto outputMQ1 = std::make_unique<EffectHelper::DataMQ>(ret1.outputDataMQ);
Shunkai Yaocb0fc412022-12-15 20:34:32 +0000951 ASSERT_TRUE(outputMQ1->isValid());
Shunkai Yao812d5b42022-11-16 18:08:50 +0000952
953 std::vector<float> buffer1, buffer2;
Shunkai Yaob49631f2023-02-03 01:44:32 +0000954 EXPECT_NO_FATAL_FAILURE(EffectHelper::allocateInputData(common1, inputMQ1, buffer1));
Shunkai Yao41888a22023-04-10 17:13:30 +0000955 EXPECT_NO_FATAL_FAILURE(EffectHelper::writeToFmq(statusMQ1, inputMQ1, buffer1));
Shunkai Yaob49631f2023-02-03 01:44:32 +0000956 EXPECT_NO_FATAL_FAILURE(
957 EffectHelper::readFromFmq(statusMQ1, 1, outputMQ1, buffer1.size(), buffer1));
Shunkai Yao812d5b42022-11-16 18:08:50 +0000958
959 auto statusMQ2 = std::make_unique<EffectHelper::StatusMQ>(ret2.statusMQ);
Shunkai Yaocb0fc412022-12-15 20:34:32 +0000960 ASSERT_TRUE(statusMQ2->isValid());
Shunkai Yao812d5b42022-11-16 18:08:50 +0000961 auto inputMQ2 = std::make_unique<EffectHelper::DataMQ>(ret2.inputDataMQ);
Shunkai Yaocb0fc412022-12-15 20:34:32 +0000962 ASSERT_TRUE(inputMQ2->isValid());
Shunkai Yao812d5b42022-11-16 18:08:50 +0000963 auto outputMQ2 = std::make_unique<EffectHelper::DataMQ>(ret2.outputDataMQ);
Shunkai Yaocb0fc412022-12-15 20:34:32 +0000964 ASSERT_TRUE(outputMQ2->isValid());
Shunkai Yaob49631f2023-02-03 01:44:32 +0000965 EXPECT_NO_FATAL_FAILURE(EffectHelper::allocateInputData(common2, inputMQ2, buffer2));
Shunkai Yao41888a22023-04-10 17:13:30 +0000966 EXPECT_NO_FATAL_FAILURE(EffectHelper::writeToFmq(statusMQ2, inputMQ2, buffer2));
Shunkai Yaob49631f2023-02-03 01:44:32 +0000967 EXPECT_NO_FATAL_FAILURE(
968 EffectHelper::readFromFmq(statusMQ2, 1, outputMQ2, buffer2.size(), buffer2));
Shunkai Yao812d5b42022-11-16 18:08:50 +0000969
970 ASSERT_NO_FATAL_FAILURE(command(effect1, CommandId::STOP));
971 ASSERT_NO_FATAL_FAILURE(expectState(effect1, State::IDLE));
972 ASSERT_NO_FATAL_FAILURE(close(effect1));
973 ASSERT_NO_FATAL_FAILURE(destroy(mFactory, effect1));
974
975 ASSERT_NO_FATAL_FAILURE(command(effect2, CommandId::STOP));
976 ASSERT_NO_FATAL_FAILURE(expectState(effect2, State::IDLE));
977 ASSERT_NO_FATAL_FAILURE(close(effect2));
978 ASSERT_NO_FATAL_FAILURE(destroy(mFactory, effect2));
979}
980
981INSTANTIATE_TEST_SUITE_P(
982 SingleEffectInstanceTest, AudioEffectTest,
983 ::testing::Combine(testing::ValuesIn(
984 EffectFactoryHelper::getAllEffectDescriptors(IFactory::descriptor))),
985 [](const testing::TestParamInfo<AudioEffectTest::ParamType>& info) {
Shunkai Yaocb0fc412022-12-15 20:34:32 +0000986 auto descriptor = std::get<PARAM_INSTANCE_NAME>(info.param).second;
Jaideep Sharmae4c7a962023-06-14 19:14:44 +0530987 std::string name = getPrefix(descriptor);
Shunkai Yao812d5b42022-11-16 18:08:50 +0000988 std::replace_if(
989 name.begin(), name.end(), [](const char c) { return !std::isalnum(c); }, '_');
990 return name;
991 });
Shunkai Yaoa4ab38c2022-10-14 01:07:47 +0000992GTEST_ALLOW_UNINSTANTIATED_PARAMETERIZED_TEST(AudioEffectTest);
Shunkai Yao67b1be62022-07-13 05:01:42 +0000993
Jaideep Sharmacba42862023-06-23 10:27:39 +0530994INSTANTIATE_TEST_SUITE_P(
995 SingleEffectInstanceTest, AudioEffectDataPathTest,
996 ::testing::Combine(testing::ValuesIn(
997 EffectFactoryHelper::getAllEffectDescriptors(IFactory::descriptor))),
998 [](const testing::TestParamInfo<AudioEffectDataPathTest::ParamType>& info) {
999 auto descriptor = std::get<PARAM_INSTANCE_NAME>(info.param).second;
1000 std::string name = getPrefix(descriptor);
1001 std::replace_if(
1002 name.begin(), name.end(), [](const char c) { return !std::isalnum(c); }, '_');
1003 return name;
1004 });
1005
1006GTEST_ALLOW_UNINSTANTIATED_PARAMETERIZED_TEST(AudioEffectDataPathTest);
1007
Shunkai Yao67b1be62022-07-13 05:01:42 +00001008int main(int argc, char** argv) {
1009 ::testing::InitGoogleTest(&argc, argv);
Jaideep Sharma74498412023-09-13 15:25:25 +05301010 ::testing::UnitTest::GetInstance()->listeners().Append(new TestExecutionTracer());
Shunkai Yao67b1be62022-07-13 05:01:42 +00001011 ABinderProcess_setThreadPoolMaxThreadCount(1);
1012 ABinderProcess_startThreadPool();
1013 return RUN_ALL_TESTS();
Shunkai Yaoa4ab38c2022-10-14 01:07:47 +00001014}