blob: 5b78981d8677213853721579319d4c0c5dc52dbf [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 Yao11420442024-12-02 18:37:16 +000045using aidl::android::hardware::audio::effect::kDestroyAnyStateSupportedVersion;
Shunkai Yaoea24c1a2022-09-28 17:39:23 +000046using aidl::android::hardware::audio::effect::Parameter;
47using aidl::android::hardware::audio::effect::State;
Shunkai Yao5df4e6c2023-01-10 03:20:00 +000048using aidl::android::media::audio::common::AudioDeviceDescription;
49using aidl::android::media::audio::common::AudioDeviceType;
50using aidl::android::media::audio::common::AudioMode;
51using aidl::android::media::audio::common::AudioSource;
Jaideep Sharma74498412023-09-13 15:25:25 +053052using android::hardware::audio::common::testing::detail::TestExecutionTracer;
Shunkai Yao67b1be62022-07-13 05:01:42 +000053
Shunkai Yao812d5b42022-11-16 18:08:50 +000054enum ParamName { PARAM_INSTANCE_NAME };
Shunkai Yaocb0fc412022-12-15 20:34:32 +000055using EffectTestParam = std::tuple<std::pair<std::shared_ptr<IFactory>, Descriptor>>;
Shunkai Yao812d5b42022-11-16 18:08:50 +000056
57class AudioEffectTest : public testing::TestWithParam<EffectTestParam>, public EffectHelper {
Shunkai Yao45905172022-08-24 18:14:02 +000058 public:
Shunkai Yaocb0fc412022-12-15 20:34:32 +000059 AudioEffectTest() {
60 std::tie(mFactory, mDescriptor) = std::get<PARAM_INSTANCE_NAME>(GetParam());
Shunkai Yaoef683a92024-04-18 04:38:17 +000061 mVersion = EffectFactoryHelper::getHalVersion(mFactory);
Shunkai Yaocb0fc412022-12-15 20:34:32 +000062 }
Shunkai Yaoa4ab38c2022-10-14 01:07:47 +000063
Shunkai Yao812d5b42022-11-16 18:08:50 +000064 void SetUp() override {}
Shunkai Yaocb0fc412022-12-15 20:34:32 +000065
66 void TearDown() override {
67 // Do the cleanup for every test case
68 if (mEffect) {
69 ASSERT_NO_FATAL_FAILURE(commandIgnoreRet(mEffect, CommandId::STOP));
70 ASSERT_NO_FATAL_FAILURE(closeIgnoreRet(mEffect));
71 ASSERT_NO_FATAL_FAILURE(destroyIgnoreRet(mFactory, mEffect));
72 mEffect.reset();
73 }
74 }
Shunkai Yao45905172022-08-24 18:14:02 +000075
Shunkai Yao812d5b42022-11-16 18:08:50 +000076 static const long kInputFrameCount = 0x100, kOutputFrameCount = 0x100;
77 std::shared_ptr<IFactory> mFactory;
Shunkai Yaocb0fc412022-12-15 20:34:32 +000078 std::shared_ptr<IEffect> mEffect;
79 Descriptor mDescriptor;
Shunkai Yaoef683a92024-04-18 04:38:17 +000080 int mVersion = 0;
Shunkai Yao5df4e6c2023-01-10 03:20:00 +000081
82 void setAndGetParameter(Parameter::Id id, const Parameter& set) {
83 Parameter get;
84 EXPECT_IS_OK(mEffect->setParameter(set));
85 EXPECT_IS_OK(mEffect->getParameter(id, &get));
Shunkai Yaoeea19942023-02-16 02:31:24 +000086 EXPECT_EQ(set, get) << set.toString() << "\n vs \n" << get.toString();
Shunkai Yao5df4e6c2023-01-10 03:20:00 +000087 }
Shunkai Yao45905172022-08-24 18:14:02 +000088};
89
Jaideep Sharmacba42862023-06-23 10:27:39 +053090class AudioEffectDataPathTest : public AudioEffectTest {
Shunkai Yao8771cec2023-09-20 22:46:59 +000091 public:
92 void SetUp() override {
93 AudioEffectTest::SetUp();
94 SKIP_TEST_IF_DATA_UNSUPPORTED(mDescriptor.common.flags);
95 }
Jaideep Sharmacba42862023-06-23 10:27:39 +053096};
97
Shunkai Yao812d5b42022-11-16 18:08:50 +000098TEST_P(AudioEffectTest, SetupAndTearDown) {
99 // Intentionally empty test body.
Shunkai Yao45905172022-08-24 18:14:02 +0000100}
101
Shunkai Yao812d5b42022-11-16 18:08:50 +0000102TEST_P(AudioEffectTest, CreateAndDestroy) {
Shunkai Yaocb0fc412022-12-15 20:34:32 +0000103 ASSERT_NO_FATAL_FAILURE(create(mFactory, mEffect, mDescriptor));
104 ASSERT_NO_FATAL_FAILURE(destroy(mFactory, mEffect));
Shunkai Yao45905172022-08-24 18:14:02 +0000105}
106
Shunkai Yao812d5b42022-11-16 18:08:50 +0000107TEST_P(AudioEffectTest, OpenAndClose) {
Shunkai Yaocb0fc412022-12-15 20:34:32 +0000108 ASSERT_NO_FATAL_FAILURE(create(mFactory, mEffect, mDescriptor));
109 ASSERT_NO_FATAL_FAILURE(open(mEffect));
110 ASSERT_NO_FATAL_FAILURE(close(mEffect));
111 ASSERT_NO_FATAL_FAILURE(destroy(mFactory, mEffect));
Shunkai Yao45905172022-08-24 18:14:02 +0000112}
113
Shunkai Yao812d5b42022-11-16 18:08:50 +0000114TEST_P(AudioEffectTest, CloseUnopenedEffect) {
Shunkai Yaocb0fc412022-12-15 20:34:32 +0000115 ASSERT_NO_FATAL_FAILURE(create(mFactory, mEffect, mDescriptor));
116 ASSERT_NO_FATAL_FAILURE(close(mEffect));
117 ASSERT_NO_FATAL_FAILURE(destroy(mFactory, mEffect));
Shunkai Yao45905172022-08-24 18:14:02 +0000118}
119
Shunkai Yao812d5b42022-11-16 18:08:50 +0000120TEST_P(AudioEffectTest, DoubleOpenAndClose) {
121 std::shared_ptr<IEffect> effect1, effect2;
Shunkai Yaocb0fc412022-12-15 20:34:32 +0000122 ASSERT_NO_FATAL_FAILURE(create(mFactory, effect1, mDescriptor));
123 ASSERT_NO_FATAL_FAILURE(create(mFactory, effect2, mDescriptor));
Shunkai Yao812d5b42022-11-16 18:08:50 +0000124 ASSERT_NO_FATAL_FAILURE(open(effect1));
125 ASSERT_NO_FATAL_FAILURE(open(effect2, 1 /* session */));
126 ASSERT_NO_FATAL_FAILURE(close(effect1));
127 ASSERT_NO_FATAL_FAILURE(close(effect2));
128 ASSERT_NO_FATAL_FAILURE(destroy(mFactory, effect1));
129 ASSERT_NO_FATAL_FAILURE(destroy(mFactory, effect2));
Shunkai Yao45905172022-08-24 18:14:02 +0000130}
131
Shunkai Yao812d5b42022-11-16 18:08:50 +0000132TEST_P(AudioEffectTest, TripleOpenAndClose) {
133 std::shared_ptr<IEffect> effect1, effect2, effect3;
Shunkai Yaocb0fc412022-12-15 20:34:32 +0000134 ASSERT_NO_FATAL_FAILURE(create(mFactory, effect1, mDescriptor));
135 ASSERT_NO_FATAL_FAILURE(create(mFactory, effect2, mDescriptor));
136 ASSERT_NO_FATAL_FAILURE(create(mFactory, effect3, mDescriptor));
Shunkai Yao812d5b42022-11-16 18:08:50 +0000137 ASSERT_NO_FATAL_FAILURE(open(effect1));
138 ASSERT_NO_FATAL_FAILURE(open(effect2, 1 /* session */));
139 ASSERT_NO_FATAL_FAILURE(open(effect3, 2 /* session */));
140 ASSERT_NO_FATAL_FAILURE(close(effect1));
141 ASSERT_NO_FATAL_FAILURE(close(effect2));
142 ASSERT_NO_FATAL_FAILURE(close(effect3));
143 ASSERT_NO_FATAL_FAILURE(destroy(mFactory, effect1));
144 ASSERT_NO_FATAL_FAILURE(destroy(mFactory, effect2));
145 ASSERT_NO_FATAL_FAILURE(destroy(mFactory, effect3));
146}
Shunkai Yao45905172022-08-24 18:14:02 +0000147
Shunkai Yao812d5b42022-11-16 18:08:50 +0000148TEST_P(AudioEffectTest, GetDescritorBeforeOpen) {
Shunkai Yao812d5b42022-11-16 18:08:50 +0000149 Descriptor desc;
Shunkai Yaocb0fc412022-12-15 20:34:32 +0000150 ASSERT_NO_FATAL_FAILURE(create(mFactory, mEffect, mDescriptor));
151 ASSERT_NO_FATAL_FAILURE(getDescriptor(mEffect, desc));
Shunkai Yao4c4f3cd2023-02-28 01:50:40 +0000152 EXPECT_EQ(mDescriptor.common.id.type, desc.common.id.type);
153 EXPECT_EQ(mDescriptor.common.id.uuid, desc.common.id.uuid);
154 EXPECT_EQ(mDescriptor.common.name, desc.common.name);
155 EXPECT_EQ(mDescriptor.common.implementor, desc.common.implementor);
Shunkai Yaocb0fc412022-12-15 20:34:32 +0000156 // Effect implementation Must fill in implementor and name
Shunkai Yao812d5b42022-11-16 18:08:50 +0000157 EXPECT_NE("", desc.common.name);
158 EXPECT_NE("", desc.common.implementor);
Shunkai Yaocb0fc412022-12-15 20:34:32 +0000159 ASSERT_NO_FATAL_FAILURE(destroy(mFactory, mEffect));
Shunkai Yao812d5b42022-11-16 18:08:50 +0000160}
161
162TEST_P(AudioEffectTest, GetDescritorAfterOpen) {
Shunkai Yao812d5b42022-11-16 18:08:50 +0000163 Descriptor beforeOpen, afterOpen, afterClose;
Shunkai Yaocb0fc412022-12-15 20:34:32 +0000164 ASSERT_NO_FATAL_FAILURE(create(mFactory, mEffect, mDescriptor));
165 ASSERT_NO_FATAL_FAILURE(getDescriptor(mEffect, beforeOpen));
166 ASSERT_NO_FATAL_FAILURE(open(mEffect));
167 ASSERT_NO_FATAL_FAILURE(getDescriptor(mEffect, afterOpen));
Shunkai Yao812d5b42022-11-16 18:08:50 +0000168 EXPECT_EQ(beforeOpen.toString(), afterOpen.toString()) << "\n"
169 << beforeOpen.toString() << "\n"
170 << afterOpen.toString();
Shunkai Yaocb0fc412022-12-15 20:34:32 +0000171 ASSERT_NO_FATAL_FAILURE(close(mEffect));
172 ASSERT_NO_FATAL_FAILURE(getDescriptor(mEffect, afterClose));
Shunkai Yao812d5b42022-11-16 18:08:50 +0000173 EXPECT_EQ(beforeOpen.toString(), afterClose.toString()) << "\n"
174 << beforeOpen.toString() << "\n"
175 << afterClose.toString();
Shunkai Yaocb0fc412022-12-15 20:34:32 +0000176 ASSERT_NO_FATAL_FAILURE(destroy(mFactory, mEffect));
Shunkai Yao812d5b42022-11-16 18:08:50 +0000177}
178
179TEST_P(AudioEffectTest, DescriptorExistAndUnique) {
Shunkai Yao812d5b42022-11-16 18:08:50 +0000180 Descriptor desc;
181
182 auto descList = EffectFactoryHelper::getAllEffectDescriptors(IFactory::descriptor);
183 std::set<Descriptor::Identity> idSet;
184 for (const auto& it : descList) {
Shunkai Yaocb0fc412022-12-15 20:34:32 +0000185 auto& id = it.second.common.id;
Shunkai Yao812d5b42022-11-16 18:08:50 +0000186 EXPECT_EQ(0ul, idSet.count(id));
187 idSet.insert(id);
Shunkai Yao45905172022-08-24 18:14:02 +0000188 }
Shunkai Yao812d5b42022-11-16 18:08:50 +0000189
Shunkai Yaocb0fc412022-12-15 20:34:32 +0000190 ASSERT_NO_FATAL_FAILURE(create(mFactory, mEffect, mDescriptor));
191 ASSERT_NO_FATAL_FAILURE(getDescriptor(mEffect, desc));
Shunkai Yao4c4f3cd2023-02-28 01:50:40 +0000192 int uuidCount = std::count_if(idSet.begin(), idSet.end(), [&](const auto& id) {
193 return id.uuid == desc.common.id.uuid && id.type == desc.common.id.type;
194 });
195
196 EXPECT_EQ(1, uuidCount);
Shunkai Yaocb0fc412022-12-15 20:34:32 +0000197 ASSERT_NO_FATAL_FAILURE(destroy(mFactory, mEffect));
Shunkai Yao45905172022-08-24 18:14:02 +0000198}
199
Shunkai Yaoea24c1a2022-09-28 17:39:23 +0000200/// State testing.
201// An effect instance is in INIT state by default after it was created.
Shunkai Yaoa4ab38c2022-10-14 01:07:47 +0000202TEST_P(AudioEffectTest, InitStateAfterCreation) {
Shunkai Yaocb0fc412022-12-15 20:34:32 +0000203 ASSERT_NO_FATAL_FAILURE(create(mFactory, mEffect, mDescriptor));
Shunkai Yaocb0fc412022-12-15 20:34:32 +0000204 ASSERT_NO_FATAL_FAILURE(destroy(mFactory, mEffect));
Shunkai Yaoea24c1a2022-09-28 17:39:23 +0000205}
206
Shunkai Yao812d5b42022-11-16 18:08:50 +0000207// An effect instance transfer to IDLE state after IEffect.ASSERT_NO_FATAL_FAILURE(open().
Shunkai Yaoa4ab38c2022-10-14 01:07:47 +0000208TEST_P(AudioEffectTest, IdleStateAfterOpen) {
Shunkai Yaocb0fc412022-12-15 20:34:32 +0000209 ASSERT_NO_FATAL_FAILURE(create(mFactory, mEffect, mDescriptor));
210 ASSERT_NO_FATAL_FAILURE(open(mEffect));
Shunkai Yaocb0fc412022-12-15 20:34:32 +0000211 ASSERT_NO_FATAL_FAILURE(close(mEffect));
212 ASSERT_NO_FATAL_FAILURE(destroy(mFactory, mEffect));
Shunkai Yaoea24c1a2022-09-28 17:39:23 +0000213}
214
215// An effect instance is in PROCESSING state after it receive an START command.
Shunkai Yaoa4ab38c2022-10-14 01:07:47 +0000216TEST_P(AudioEffectTest, ProcessingStateAfterStart) {
Shunkai Yaocb0fc412022-12-15 20:34:32 +0000217 ASSERT_NO_FATAL_FAILURE(create(mFactory, mEffect, mDescriptor));
Shunkai Yaocb0fc412022-12-15 20:34:32 +0000218 ASSERT_NO_FATAL_FAILURE(open(mEffect));
Shunkai Yaocb0fc412022-12-15 20:34:32 +0000219 ASSERT_NO_FATAL_FAILURE(command(mEffect, CommandId::START));
Shunkai Yaocb0fc412022-12-15 20:34:32 +0000220 ASSERT_NO_FATAL_FAILURE(command(mEffect, CommandId::STOP));
221 ASSERT_NO_FATAL_FAILURE(close(mEffect));
222 ASSERT_NO_FATAL_FAILURE(destroy(mFactory, mEffect));
Shunkai Yaoea24c1a2022-09-28 17:39:23 +0000223}
224
225// An effect instance transfer to IDLE state after Command.Id.STOP in PROCESSING state.
Shunkai Yaoa4ab38c2022-10-14 01:07:47 +0000226TEST_P(AudioEffectTest, IdleStateAfterStop) {
Shunkai Yaocb0fc412022-12-15 20:34:32 +0000227 ASSERT_NO_FATAL_FAILURE(create(mFactory, mEffect, mDescriptor));
228 ASSERT_NO_FATAL_FAILURE(open(mEffect));
229 ASSERT_NO_FATAL_FAILURE(command(mEffect, CommandId::START));
Shunkai Yaocb0fc412022-12-15 20:34:32 +0000230 ASSERT_NO_FATAL_FAILURE(command(mEffect, CommandId::STOP));
Shunkai Yaocb0fc412022-12-15 20:34:32 +0000231 ASSERT_NO_FATAL_FAILURE(close(mEffect));
232 ASSERT_NO_FATAL_FAILURE(destroy(mFactory, mEffect));
Shunkai Yaoea24c1a2022-09-28 17:39:23 +0000233}
234
235// An effect instance transfer to IDLE state after Command.Id.RESET in PROCESSING state.
Shunkai Yaoa4ab38c2022-10-14 01:07:47 +0000236TEST_P(AudioEffectTest, IdleStateAfterReset) {
Shunkai Yaocb0fc412022-12-15 20:34:32 +0000237 ASSERT_NO_FATAL_FAILURE(create(mFactory, mEffect, mDescriptor));
238 ASSERT_NO_FATAL_FAILURE(open(mEffect));
239 ASSERT_NO_FATAL_FAILURE(command(mEffect, CommandId::START));
Shunkai Yaocb0fc412022-12-15 20:34:32 +0000240 ASSERT_NO_FATAL_FAILURE(command(mEffect, CommandId::RESET));
Shunkai Yaocb0fc412022-12-15 20:34:32 +0000241 ASSERT_NO_FATAL_FAILURE(close(mEffect));
242 ASSERT_NO_FATAL_FAILURE(destroy(mFactory, mEffect));
Shunkai Yaoea24c1a2022-09-28 17:39:23 +0000243}
244
Shunkai Yao812d5b42022-11-16 18:08:50 +0000245// An effect instance transfer to INIT after IEffect.ASSERT_NO_FATAL_FAILURE(close().
Shunkai Yaoa4ab38c2022-10-14 01:07:47 +0000246TEST_P(AudioEffectTest, InitStateAfterClose) {
Shunkai Yaocb0fc412022-12-15 20:34:32 +0000247 ASSERT_NO_FATAL_FAILURE(create(mFactory, mEffect, mDescriptor));
248 ASSERT_NO_FATAL_FAILURE(open(mEffect));
249 ASSERT_NO_FATAL_FAILURE(command(mEffect, CommandId::START));
250 ASSERT_NO_FATAL_FAILURE(command(mEffect, CommandId::STOP));
251 ASSERT_NO_FATAL_FAILURE(close(mEffect));
Shunkai Yaocb0fc412022-12-15 20:34:32 +0000252 ASSERT_NO_FATAL_FAILURE(destroy(mFactory, mEffect));
Shunkai Yaoea24c1a2022-09-28 17:39:23 +0000253}
254
255// An effect instance shouldn't accept any command before open.
Shunkai Yaoa4ab38c2022-10-14 01:07:47 +0000256TEST_P(AudioEffectTest, NoCommandAcceptedBeforeOpen) {
Shunkai Yaocb0fc412022-12-15 20:34:32 +0000257 ASSERT_NO_FATAL_FAILURE(create(mFactory, mEffect, mDescriptor));
258 ASSERT_NO_FATAL_FAILURE(command(mEffect, CommandId::START, EX_ILLEGAL_STATE));
259 ASSERT_NO_FATAL_FAILURE(command(mEffect, CommandId::STOP, EX_ILLEGAL_STATE));
260 ASSERT_NO_FATAL_FAILURE(command(mEffect, CommandId::RESET, EX_ILLEGAL_STATE));
261 ASSERT_NO_FATAL_FAILURE(destroy(mFactory, mEffect));
Shunkai Yaoea24c1a2022-09-28 17:39:23 +0000262}
263
264// No-op when receive STOP command in IDLE state.
Shunkai Yaoa4ab38c2022-10-14 01:07:47 +0000265TEST_P(AudioEffectTest, StopCommandInIdleStateNoOp) {
Shunkai Yaocb0fc412022-12-15 20:34:32 +0000266 ASSERT_NO_FATAL_FAILURE(create(mFactory, mEffect, mDescriptor));
267 ASSERT_NO_FATAL_FAILURE(open(mEffect));
Shunkai Yaocb0fc412022-12-15 20:34:32 +0000268 ASSERT_NO_FATAL_FAILURE(command(mEffect, CommandId::STOP));
Shunkai Yaocb0fc412022-12-15 20:34:32 +0000269 ASSERT_NO_FATAL_FAILURE(close(mEffect));
270 ASSERT_NO_FATAL_FAILURE(destroy(mFactory, mEffect));
Shunkai Yaoea24c1a2022-09-28 17:39:23 +0000271}
272
Shunkai Yao812d5b42022-11-16 18:08:50 +0000273// No-op when receive RESET command in IDLE state.
Shunkai Yaoa4ab38c2022-10-14 01:07:47 +0000274TEST_P(AudioEffectTest, ResetCommandInIdleStateNoOp) {
Shunkai Yaocb0fc412022-12-15 20:34:32 +0000275 ASSERT_NO_FATAL_FAILURE(create(mFactory, mEffect, mDescriptor));
276 ASSERT_NO_FATAL_FAILURE(open(mEffect));
Shunkai Yaocb0fc412022-12-15 20:34:32 +0000277 ASSERT_NO_FATAL_FAILURE(command(mEffect, CommandId::RESET));
Shunkai Yaocb0fc412022-12-15 20:34:32 +0000278 ASSERT_NO_FATAL_FAILURE(close(mEffect));
279 ASSERT_NO_FATAL_FAILURE(destroy(mFactory, mEffect));
Shunkai Yaoea24c1a2022-09-28 17:39:23 +0000280}
281
282// Repeat START and STOP command.
Shunkai Yaoa4ab38c2022-10-14 01:07:47 +0000283TEST_P(AudioEffectTest, RepeatStartAndStop) {
Shunkai Yaocb0fc412022-12-15 20:34:32 +0000284 ASSERT_NO_FATAL_FAILURE(create(mFactory, mEffect, mDescriptor));
285 ASSERT_NO_FATAL_FAILURE(open(mEffect));
Shunkai Yaocb0fc412022-12-15 20:34:32 +0000286 ASSERT_NO_FATAL_FAILURE(command(mEffect, CommandId::START));
Shunkai Yaocb0fc412022-12-15 20:34:32 +0000287 ASSERT_NO_FATAL_FAILURE(command(mEffect, CommandId::STOP));
Shunkai Yao812d5b42022-11-16 18:08:50 +0000288
Shunkai Yaocb0fc412022-12-15 20:34:32 +0000289 ASSERT_NO_FATAL_FAILURE(command(mEffect, CommandId::START));
Shunkai Yaocb0fc412022-12-15 20:34:32 +0000290 ASSERT_NO_FATAL_FAILURE(command(mEffect, CommandId::STOP));
Shunkai Yaocb0fc412022-12-15 20:34:32 +0000291 ASSERT_NO_FATAL_FAILURE(close(mEffect));
292 ASSERT_NO_FATAL_FAILURE(destroy(mFactory, mEffect));
Shunkai Yaoea24c1a2022-09-28 17:39:23 +0000293}
294
295// Repeat START and RESET command.
Shunkai Yaoa4ab38c2022-10-14 01:07:47 +0000296TEST_P(AudioEffectTest, RepeatStartAndReset) {
Shunkai Yaocb0fc412022-12-15 20:34:32 +0000297 ASSERT_NO_FATAL_FAILURE(create(mFactory, mEffect, mDescriptor));
298 ASSERT_NO_FATAL_FAILURE(open(mEffect));
Shunkai Yaocb0fc412022-12-15 20:34:32 +0000299 ASSERT_NO_FATAL_FAILURE(command(mEffect, CommandId::START));
Shunkai Yaocb0fc412022-12-15 20:34:32 +0000300 ASSERT_NO_FATAL_FAILURE(command(mEffect, CommandId::RESET));
Shunkai Yaocb0fc412022-12-15 20:34:32 +0000301 ASSERT_NO_FATAL_FAILURE(command(mEffect, CommandId::START));
Shunkai Yaocb0fc412022-12-15 20:34:32 +0000302 ASSERT_NO_FATAL_FAILURE(command(mEffect, CommandId::RESET));
Shunkai Yaocb0fc412022-12-15 20:34:32 +0000303 ASSERT_NO_FATAL_FAILURE(close(mEffect));
304 ASSERT_NO_FATAL_FAILURE(destroy(mFactory, mEffect));
Shunkai Yaoea24c1a2022-09-28 17:39:23 +0000305}
306
Shunkai Yao812d5b42022-11-16 18:08:50 +0000307// Try to close an effect instance at PROCESSING state.
Shunkai Yaoa4ab38c2022-10-14 01:07:47 +0000308TEST_P(AudioEffectTest, CloseProcessingStateEffects) {
Shunkai Yaocb0fc412022-12-15 20:34:32 +0000309 ASSERT_NO_FATAL_FAILURE(create(mFactory, mEffect, mDescriptor));
310 ASSERT_NO_FATAL_FAILURE(open(mEffect));
Shunkai Yaocb0fc412022-12-15 20:34:32 +0000311 ASSERT_NO_FATAL_FAILURE(command(mEffect, CommandId::START));
Shunkai Yao812d5b42022-11-16 18:08:50 +0000312
Shunkai Yaocb0fc412022-12-15 20:34:32 +0000313 ASSERT_NO_FATAL_FAILURE(close(mEffect, EX_ILLEGAL_STATE));
Shunkai Yao812d5b42022-11-16 18:08:50 +0000314
Shunkai Yaocb0fc412022-12-15 20:34:32 +0000315 ASSERT_NO_FATAL_FAILURE(command(mEffect, CommandId::STOP));
Shunkai Yaocb0fc412022-12-15 20:34:32 +0000316 ASSERT_NO_FATAL_FAILURE(close(mEffect));
317 ASSERT_NO_FATAL_FAILURE(destroy(mFactory, mEffect));
Shunkai Yaoea24c1a2022-09-28 17:39:23 +0000318}
319
Shunkai Yao11420442024-12-02 18:37:16 +0000320// Expect EX_ILLEGAL_STATE if the effect instance is not in a proper state to be destroyed before
321// `kDestroyAnyStateSupportedVersion`.
322// For any version after `kDestroyAnyStateSupportedVersion`, expect `destroy` to always success.
Shunkai Yaoa4ab38c2022-10-14 01:07:47 +0000323TEST_P(AudioEffectTest, DestroyOpenEffects) {
Shunkai Yaocb0fc412022-12-15 20:34:32 +0000324 ASSERT_NO_FATAL_FAILURE(create(mFactory, mEffect, mDescriptor));
325 ASSERT_NO_FATAL_FAILURE(open(mEffect));
Shunkai Yao11420442024-12-02 18:37:16 +0000326 if (mVersion < kDestroyAnyStateSupportedVersion) {
327 ASSERT_NO_FATAL_FAILURE(destroy(mFactory, mEffect, EX_ILLEGAL_STATE));
328 // cleanup
329 ASSERT_NO_FATAL_FAILURE(close(mEffect));
330 ASSERT_NO_FATAL_FAILURE(destroy(mFactory, mEffect));
331 } else {
332 ASSERT_NO_FATAL_FAILURE(destroy(mFactory, mEffect));
333 }
Shunkai Yao812d5b42022-11-16 18:08:50 +0000334}
335
Shunkai Yao11420442024-12-02 18:37:16 +0000336// Expect EX_ILLEGAL_STATE if the effect instance is not in a proper state to be destroyed before
337// `kDestroyAnyStateSupportedVersion`.
338// For any version after `kDestroyAnyStateSupportedVersion`, expect `destroy` to always success.
Shunkai Yao812d5b42022-11-16 18:08:50 +0000339TEST_P(AudioEffectTest, DestroyProcessingEffects) {
Shunkai Yaocb0fc412022-12-15 20:34:32 +0000340 ASSERT_NO_FATAL_FAILURE(create(mFactory, mEffect, mDescriptor));
341 ASSERT_NO_FATAL_FAILURE(open(mEffect));
Shunkai Yaocb0fc412022-12-15 20:34:32 +0000342 ASSERT_NO_FATAL_FAILURE(command(mEffect, CommandId::START));
Shunkai Yaocb0fc412022-12-15 20:34:32 +0000343
Shunkai Yao11420442024-12-02 18:37:16 +0000344 if (mVersion < kDestroyAnyStateSupportedVersion) {
345 ASSERT_NO_FATAL_FAILURE(destroy(mFactory, mEffect, EX_ILLEGAL_STATE));
346 // cleanup
347 ASSERT_NO_FATAL_FAILURE(command(mEffect, CommandId::STOP));
348 ASSERT_NO_FATAL_FAILURE(close(mEffect));
349 ASSERT_NO_FATAL_FAILURE(destroy(mFactory, mEffect));
350 } else {
351 ASSERT_NO_FATAL_FAILURE(destroy(mFactory, mEffect));
352 }
Shunkai Yao812d5b42022-11-16 18:08:50 +0000353}
354
355TEST_P(AudioEffectTest, NormalSequenceStates) {
Shunkai Yaocb0fc412022-12-15 20:34:32 +0000356 ASSERT_NO_FATAL_FAILURE(create(mFactory, mEffect, mDescriptor));
Shunkai Yaocb0fc412022-12-15 20:34:32 +0000357 ASSERT_NO_FATAL_FAILURE(open(mEffect));
Shunkai Yaocb0fc412022-12-15 20:34:32 +0000358 ASSERT_NO_FATAL_FAILURE(command(mEffect, CommandId::START));
Shunkai Yaocb0fc412022-12-15 20:34:32 +0000359 ASSERT_NO_FATAL_FAILURE(command(mEffect, CommandId::STOP));
Shunkai Yaocb0fc412022-12-15 20:34:32 +0000360 ASSERT_NO_FATAL_FAILURE(command(mEffect, CommandId::START));
Shunkai Yaocb0fc412022-12-15 20:34:32 +0000361 ASSERT_NO_FATAL_FAILURE(command(mEffect, CommandId::RESET));
Shunkai Yaocb0fc412022-12-15 20:34:32 +0000362 ASSERT_NO_FATAL_FAILURE(close(mEffect));
363 ASSERT_NO_FATAL_FAILURE(destroy(mFactory, mEffect));
Shunkai Yaoea24c1a2022-09-28 17:39:23 +0000364}
365
366/// Parameter testing.
367// Verify parameters pass in open can be successfully get.
Shunkai Yao812d5b42022-11-16 18:08:50 +0000368TEST_P(AudioEffectTest, VerifyCommonParametersAfterOpen) {
Shunkai Yaocb0fc412022-12-15 20:34:32 +0000369 ASSERT_NO_FATAL_FAILURE(create(mFactory, mEffect, mDescriptor));
Shunkai Yao812d5b42022-11-16 18:08:50 +0000370
Shunkai Yao61f9dd22024-05-08 22:34:36 +0000371 Parameter::Common common = createParamCommon();
Shunkai Yao812d5b42022-11-16 18:08:50 +0000372 IEffect::OpenEffectReturn ret;
Shunkai Yaocb0fc412022-12-15 20:34:32 +0000373 ASSERT_NO_FATAL_FAILURE(open(mEffect, common, std::nullopt /* specific */, &ret, EX_NONE));
Shunkai Yao812d5b42022-11-16 18:08:50 +0000374
375 Parameter get = Parameter(), expect = Parameter();
376 expect.set<Parameter::common>(common);
377 Parameter::Id id;
378 id.set<Parameter::Id::commonTag>(Parameter::common);
Shunkai Yaocb0fc412022-12-15 20:34:32 +0000379 EXPECT_IS_OK(mEffect->getParameter(id, &get));
Shunkai Yaoeea19942023-02-16 02:31:24 +0000380 EXPECT_EQ(expect, get) << expect.toString() << "\n vs \n" << get.toString();
Shunkai Yao812d5b42022-11-16 18:08:50 +0000381
Shunkai Yaocb0fc412022-12-15 20:34:32 +0000382 ASSERT_NO_FATAL_FAILURE(close(mEffect));
383 ASSERT_NO_FATAL_FAILURE(destroy(mFactory, mEffect));
Shunkai Yaoea24c1a2022-09-28 17:39:23 +0000384}
385
386// Verify parameters pass in set can be successfully get.
Shunkai Yao812d5b42022-11-16 18:08:50 +0000387TEST_P(AudioEffectTest, SetAndGetCommonParameter) {
Shunkai Yaocb0fc412022-12-15 20:34:32 +0000388 ASSERT_NO_FATAL_FAILURE(create(mFactory, mEffect, mDescriptor));
389 ASSERT_NO_FATAL_FAILURE(open(mEffect));
Shunkai Yao812d5b42022-11-16 18:08:50 +0000390
Shunkai Yao61f9dd22024-05-08 22:34:36 +0000391 Parameter::Common common = createParamCommon(0 /* session */, 1 /* ioHandle */,
392 44100 /* iSampleRate */, 44100 /* oSampleRate */);
Shunkai Yao5df4e6c2023-01-10 03:20:00 +0000393 Parameter::Id id = Parameter::Id::make<Parameter::Id::commonTag>(Parameter::common);
394 ASSERT_NO_FATAL_FAILURE(setAndGetParameter(id, Parameter::make<Parameter::common>(common)));
Shunkai Yao812d5b42022-11-16 18:08:50 +0000395
Shunkai Yaocb0fc412022-12-15 20:34:32 +0000396 ASSERT_NO_FATAL_FAILURE(close(mEffect));
397 ASSERT_NO_FATAL_FAILURE(destroy(mFactory, mEffect));
Shunkai Yaoea24c1a2022-09-28 17:39:23 +0000398}
399
Shunkai Yao812d5b42022-11-16 18:08:50 +0000400// Verify parameters set and get in PROCESSING state.
Shunkai Yaoa4ab38c2022-10-14 01:07:47 +0000401TEST_P(AudioEffectTest, SetAndGetParameterInProcessing) {
Shunkai Yaocb0fc412022-12-15 20:34:32 +0000402 ASSERT_NO_FATAL_FAILURE(create(mFactory, mEffect, mDescriptor));
403 ASSERT_NO_FATAL_FAILURE(open(mEffect));
404 ASSERT_NO_FATAL_FAILURE(command(mEffect, CommandId::START));
Shunkai Yao812d5b42022-11-16 18:08:50 +0000405
Shunkai Yao61f9dd22024-05-08 22:34:36 +0000406 Parameter::Common common = createParamCommon(0 /* session */, 1 /* ioHandle */,
407 44100 /* iSampleRate */, 44100 /* oSampleRate */);
Shunkai Yao5df4e6c2023-01-10 03:20:00 +0000408 Parameter::Id id = Parameter::Id::make<Parameter::Id::commonTag>(Parameter::common);
409 ASSERT_NO_FATAL_FAILURE(setAndGetParameter(id, Parameter::make<Parameter::common>(common)));
Shunkai Yao812d5b42022-11-16 18:08:50 +0000410
Shunkai Yaocb0fc412022-12-15 20:34:32 +0000411 ASSERT_NO_FATAL_FAILURE(command(mEffect, CommandId::STOP));
412 ASSERT_NO_FATAL_FAILURE(close(mEffect));
413 ASSERT_NO_FATAL_FAILURE(destroy(mFactory, mEffect));
Shunkai Yaoea24c1a2022-09-28 17:39:23 +0000414}
415
Shunkai Yao812d5b42022-11-16 18:08:50 +0000416// Verify parameters set and get in IDLE state.
417TEST_P(AudioEffectTest, SetAndGetParameterInIdle) {
Shunkai Yaocb0fc412022-12-15 20:34:32 +0000418 ASSERT_NO_FATAL_FAILURE(create(mFactory, mEffect, mDescriptor));
419 ASSERT_NO_FATAL_FAILURE(open(mEffect));
420 ASSERT_NO_FATAL_FAILURE(command(mEffect, CommandId::START));
Shunkai Yaocb0fc412022-12-15 20:34:32 +0000421 ASSERT_NO_FATAL_FAILURE(command(mEffect, CommandId::STOP));
Shunkai Yao812d5b42022-11-16 18:08:50 +0000422
Shunkai Yao61f9dd22024-05-08 22:34:36 +0000423 Parameter::Common common = createParamCommon(0 /* session */, 1 /* ioHandle */,
424 44100 /* iSampleRate */, 44100 /* oSampleRate */);
Shunkai Yao5df4e6c2023-01-10 03:20:00 +0000425 Parameter::Id id = Parameter::Id::make<Parameter::Id::commonTag>(Parameter::common);
426 ASSERT_NO_FATAL_FAILURE(setAndGetParameter(id, Parameter::make<Parameter::common>(common)));
Shunkai Yao812d5b42022-11-16 18:08:50 +0000427
Shunkai Yaocb0fc412022-12-15 20:34:32 +0000428 ASSERT_NO_FATAL_FAILURE(close(mEffect));
429 ASSERT_NO_FATAL_FAILURE(destroy(mFactory, mEffect));
Shunkai Yaoea24c1a2022-09-28 17:39:23 +0000430}
431
Shunkai Yao812d5b42022-11-16 18:08:50 +0000432// Verify Parameters kept after stop.
433TEST_P(AudioEffectTest, SetAndGetParameterAfterStop) {
Shunkai Yaocb0fc412022-12-15 20:34:32 +0000434 ASSERT_NO_FATAL_FAILURE(create(mFactory, mEffect, mDescriptor));
435 ASSERT_NO_FATAL_FAILURE(open(mEffect));
436 ASSERT_NO_FATAL_FAILURE(command(mEffect, CommandId::START));
Shunkai Yaoea24c1a2022-09-28 17:39:23 +0000437
Shunkai Yao61f9dd22024-05-08 22:34:36 +0000438 Parameter::Common common = createParamCommon(0 /* session */, 1 /* ioHandle */,
439 44100 /* iSampleRate */, 44100 /* oSampleRate */);
Shunkai Yao5df4e6c2023-01-10 03:20:00 +0000440 Parameter::Id id = Parameter::Id::make<Parameter::Id::commonTag>(Parameter::common);
441 ASSERT_NO_FATAL_FAILURE(setAndGetParameter(id, Parameter::make<Parameter::common>(common)));
Shunkai Yaoa4ab38c2022-10-14 01:07:47 +0000442
Shunkai Yaocb0fc412022-12-15 20:34:32 +0000443 ASSERT_NO_FATAL_FAILURE(command(mEffect, CommandId::STOP));
Shunkai Yaocb0fc412022-12-15 20:34:32 +0000444 ASSERT_NO_FATAL_FAILURE(close(mEffect));
445 ASSERT_NO_FATAL_FAILURE(destroy(mFactory, mEffect));
Shunkai Yaoa4ab38c2022-10-14 01:07:47 +0000446}
447
Shunkai Yao812d5b42022-11-16 18:08:50 +0000448// Verify Parameters kept after reset.
449TEST_P(AudioEffectTest, SetAndGetParameterAfterReset) {
Shunkai Yaocb0fc412022-12-15 20:34:32 +0000450 ASSERT_NO_FATAL_FAILURE(create(mFactory, mEffect, mDescriptor));
451 ASSERT_NO_FATAL_FAILURE(open(mEffect));
Shunkai Yao812d5b42022-11-16 18:08:50 +0000452
Shunkai Yaocb0fc412022-12-15 20:34:32 +0000453 ASSERT_NO_FATAL_FAILURE(command(mEffect, CommandId::START));
Shunkai Yao812d5b42022-11-16 18:08:50 +0000454
Shunkai Yao61f9dd22024-05-08 22:34:36 +0000455 Parameter::Common common = createParamCommon(0 /* session */, 1 /* ioHandle */,
456 44100 /* iSampleRate */, 44100 /* oSampleRate */);
Shunkai Yao5df4e6c2023-01-10 03:20:00 +0000457 Parameter::Id id = Parameter::Id::make<Parameter::Id::commonTag>(Parameter::common);
458 ASSERT_NO_FATAL_FAILURE(setAndGetParameter(id, Parameter::make<Parameter::common>(common)));
Shunkai Yao812d5b42022-11-16 18:08:50 +0000459
Shunkai Yaocb0fc412022-12-15 20:34:32 +0000460 ASSERT_NO_FATAL_FAILURE(command(mEffect, CommandId::RESET));
Shunkai Yao812d5b42022-11-16 18:08:50 +0000461
Shunkai Yao5df4e6c2023-01-10 03:20:00 +0000462 ASSERT_NO_FATAL_FAILURE(setAndGetParameter(id, Parameter::make<Parameter::common>(common)));
Shunkai Yao812d5b42022-11-16 18:08:50 +0000463
Shunkai Yao5df4e6c2023-01-10 03:20:00 +0000464 ASSERT_NO_FATAL_FAILURE(command(mEffect, CommandId::STOP));
Shunkai Yaocb0fc412022-12-15 20:34:32 +0000465 ASSERT_NO_FATAL_FAILURE(close(mEffect));
466 ASSERT_NO_FATAL_FAILURE(destroy(mFactory, mEffect));
Shunkai Yao812d5b42022-11-16 18:08:50 +0000467}
Shunkai Yao5df4e6c2023-01-10 03:20:00 +0000468
469// Set and get AudioDeviceDescription in Parameter
470TEST_P(AudioEffectTest, SetAndGetParameterDeviceDescription) {
Shunkai Yao92cd7482023-09-18 17:37:45 +0000471 if (!mDescriptor.common.flags.deviceIndication) {
472 GTEST_SKIP() << "Skipping test as effect does not support deviceIndication"
473 << mDescriptor.common.flags.toString();
474 }
475
Shunkai Yao5df4e6c2023-01-10 03:20:00 +0000476 ASSERT_NO_FATAL_FAILURE(create(mFactory, mEffect, mDescriptor));
477 ASSERT_NO_FATAL_FAILURE(open(mEffect));
Shunkai Yao5df4e6c2023-01-10 03:20:00 +0000478 ASSERT_NO_FATAL_FAILURE(command(mEffect, CommandId::START));
Shunkai Yao5df4e6c2023-01-10 03:20:00 +0000479
480 std::vector<AudioDeviceDescription> deviceDescs = {
481 {.type = AudioDeviceType::IN_DEFAULT,
482 .connection = AudioDeviceDescription::CONNECTION_ANALOG},
483 {.type = AudioDeviceType::IN_DEVICE,
484 .connection = AudioDeviceDescription::CONNECTION_BT_A2DP}};
485 Parameter::Id id = Parameter::Id::make<Parameter::Id::commonTag>(Parameter::deviceDescription);
486 ASSERT_NO_FATAL_FAILURE(
487 setAndGetParameter(id, Parameter::make<Parameter::deviceDescription>(deviceDescs)));
488
489 ASSERT_NO_FATAL_FAILURE(command(mEffect, CommandId::STOP));
Shunkai Yao5df4e6c2023-01-10 03:20:00 +0000490 ASSERT_NO_FATAL_FAILURE(close(mEffect));
491 ASSERT_NO_FATAL_FAILURE(destroy(mFactory, mEffect));
492}
493
494// Set and get AudioMode in Parameter
495TEST_P(AudioEffectTest, SetAndGetParameterAudioMode) {
Shunkai Yao92cd7482023-09-18 17:37:45 +0000496 if (!mDescriptor.common.flags.audioModeIndication) {
497 GTEST_SKIP() << "Skipping test as effect does not support audioModeIndication"
498 << mDescriptor.common.flags.toString();
499 }
500
Shunkai Yao5df4e6c2023-01-10 03:20:00 +0000501 ASSERT_NO_FATAL_FAILURE(create(mFactory, mEffect, mDescriptor));
502 ASSERT_NO_FATAL_FAILURE(open(mEffect));
503
504 ASSERT_NO_FATAL_FAILURE(command(mEffect, CommandId::START));
Shunkai Yao5df4e6c2023-01-10 03:20:00 +0000505
506 Parameter::Id id = Parameter::Id::make<Parameter::Id::commonTag>(Parameter::mode);
507 ASSERT_NO_FATAL_FAILURE(
508 setAndGetParameter(id, Parameter::make<Parameter::mode>(AudioMode::NORMAL)));
509 ASSERT_NO_FATAL_FAILURE(
510 setAndGetParameter(id, Parameter::make<Parameter::mode>(AudioMode::IN_COMMUNICATION)));
511
512 ASSERT_NO_FATAL_FAILURE(command(mEffect, CommandId::STOP));
Shunkai Yao5df4e6c2023-01-10 03:20:00 +0000513 ASSERT_NO_FATAL_FAILURE(close(mEffect));
514 ASSERT_NO_FATAL_FAILURE(destroy(mFactory, mEffect));
515}
516
517// Set and get AudioSource in Parameter
518TEST_P(AudioEffectTest, SetAndGetParameterAudioSource) {
Shunkai Yao92cd7482023-09-18 17:37:45 +0000519 if (!mDescriptor.common.flags.audioSourceIndication) {
520 GTEST_SKIP() << "Skipping test as effect does not support audioSourceIndication"
521 << mDescriptor.common.flags.toString();
522 }
523
Shunkai Yao5df4e6c2023-01-10 03:20:00 +0000524 ASSERT_NO_FATAL_FAILURE(create(mFactory, mEffect, mDescriptor));
525 ASSERT_NO_FATAL_FAILURE(open(mEffect));
Shunkai Yao5df4e6c2023-01-10 03:20:00 +0000526 ASSERT_NO_FATAL_FAILURE(command(mEffect, CommandId::START));
Shunkai Yao5df4e6c2023-01-10 03:20:00 +0000527
528 Parameter::Id id = Parameter::Id::make<Parameter::Id::commonTag>(Parameter::source);
529 ASSERT_NO_FATAL_FAILURE(
530 setAndGetParameter(id, Parameter::make<Parameter::source>(AudioSource::DEFAULT)));
531 ASSERT_NO_FATAL_FAILURE(setAndGetParameter(
532 id, Parameter::make<Parameter::source>(AudioSource::VOICE_RECOGNITION)));
533
534 ASSERT_NO_FATAL_FAILURE(command(mEffect, CommandId::STOP));
Shunkai Yao5df4e6c2023-01-10 03:20:00 +0000535 ASSERT_NO_FATAL_FAILURE(close(mEffect));
536 ASSERT_NO_FATAL_FAILURE(destroy(mFactory, mEffect));
537}
538
539// Set and get VolumeStereo in Parameter
540TEST_P(AudioEffectTest, SetAndGetParameterVolume) {
Shunkai Yao92cd7482023-09-18 17:37:45 +0000541 if (mDescriptor.common.flags.volume == Flags::Volume::NONE) {
542 GTEST_SKIP() << "Skipping test as effect does not support volume"
543 << mDescriptor.common.flags.toString();
544 }
545
Shunkai Yao5df4e6c2023-01-10 03:20:00 +0000546 ASSERT_NO_FATAL_FAILURE(create(mFactory, mEffect, mDescriptor));
547 ASSERT_NO_FATAL_FAILURE(open(mEffect));
Shunkai Yao5df4e6c2023-01-10 03:20:00 +0000548 ASSERT_NO_FATAL_FAILURE(command(mEffect, CommandId::START));
Shunkai Yao5df4e6c2023-01-10 03:20:00 +0000549
550 Parameter::Id id = Parameter::Id::make<Parameter::Id::commonTag>(Parameter::volumeStereo);
551 Parameter::VolumeStereo volume = {.left = 10.0, .right = 10.0};
David Li1a56fdd2023-11-14 23:31:53 +0800552 if (mDescriptor.common.flags.volume == Flags::Volume::CTRL) {
553 Parameter get;
554 EXPECT_IS_OK(mEffect->setParameter(volume));
555 EXPECT_IS_OK(mEffect->getParameter(id, &get));
556 } else {
557 ASSERT_NO_FATAL_FAILURE(
558 setAndGetParameter(id, Parameter::make<Parameter::volumeStereo>(volume)));
559 }
Shunkai Yao5df4e6c2023-01-10 03:20:00 +0000560
561 ASSERT_NO_FATAL_FAILURE(command(mEffect, CommandId::STOP));
Shunkai Yao5df4e6c2023-01-10 03:20:00 +0000562 ASSERT_NO_FATAL_FAILURE(close(mEffect));
563 ASSERT_NO_FATAL_FAILURE(destroy(mFactory, mEffect));
564}
565
Shunkai Yaod685aed2024-01-30 18:27:38 +0000566/**
567 * Verify DataMqUpdateEventFlag after common parameter setting.
568 * verify reopen sequence.
569 */
570TEST_P(AudioEffectDataPathTest, SetCommonParameterAndReopen) {
Shunkai Yao9f9fe922024-03-04 21:23:04 +0000571 if (!EffectFactoryHelper::isReopenSupported(mFactory)) {
572 GTEST_SKIP() << "Skipping test as effect does not support reopen";
573 }
574
Shunkai Yao65c7c702024-01-09 20:50:53 +0000575 ASSERT_NO_FATAL_FAILURE(create(mFactory, mEffect, mDescriptor));
576
Shunkai Yao61f9dd22024-05-08 22:34:36 +0000577 Parameter::Common common = createParamCommon(
Shunkai Yao65c7c702024-01-09 20:50:53 +0000578 0 /* session */, 1 /* ioHandle */, 44100 /* iSampleRate */, 44100 /* oSampleRate */,
579 kInputFrameCount /* iFrameCount */, kOutputFrameCount /* oFrameCount */);
580 IEffect::OpenEffectReturn ret;
581 ASSERT_NO_FATAL_FAILURE(open(mEffect, common, std::nullopt /* specific */, &ret, EX_NONE));
582 auto statusMQ = std::make_unique<EffectHelper::StatusMQ>(ret.statusMQ);
583 ASSERT_TRUE(statusMQ->isValid());
584 auto inputMQ = std::make_unique<EffectHelper::DataMQ>(ret.inputDataMQ);
585 ASSERT_TRUE(inputMQ->isValid());
586 auto outputMQ = std::make_unique<EffectHelper::DataMQ>(ret.outputDataMQ);
587 ASSERT_TRUE(outputMQ->isValid());
588
589 Parameter::Id id = Parameter::Id::make<Parameter::Id::commonTag>(Parameter::common);
590 common.input.frameCount++;
591 ASSERT_NO_FATAL_FAILURE(setAndGetParameter(id, Parameter::make<Parameter::common>(common)));
592 ASSERT_TRUE(statusMQ->isValid());
593 expectDataMqUpdateEventFlag(statusMQ);
Shunkai Yao28aff3d2024-06-15 03:16:06 +0000594 ASSERT_NO_FATAL_FAILURE(reopen(mEffect, common, &ret));
Shunkai Yao65c7c702024-01-09 20:50:53 +0000595 inputMQ = std::make_unique<EffectHelper::DataMQ>(ret.inputDataMQ);
596 outputMQ = std::make_unique<EffectHelper::DataMQ>(ret.outputDataMQ);
597 ASSERT_TRUE(statusMQ->isValid());
598 ASSERT_TRUE(inputMQ->isValid());
599 ASSERT_TRUE(outputMQ->isValid());
600
601 common.output.frameCount++;
602 ASSERT_NO_FATAL_FAILURE(setAndGetParameter(id, Parameter::make<Parameter::common>(common)));
603 ASSERT_TRUE(statusMQ->isValid());
604 expectDataMqUpdateEventFlag(statusMQ);
Shunkai Yao28aff3d2024-06-15 03:16:06 +0000605 ASSERT_NO_FATAL_FAILURE(reopen(mEffect, common, &ret));
Shunkai Yao65c7c702024-01-09 20:50:53 +0000606 inputMQ = std::make_unique<EffectHelper::DataMQ>(ret.inputDataMQ);
607 outputMQ = std::make_unique<EffectHelper::DataMQ>(ret.outputDataMQ);
608 ASSERT_TRUE(statusMQ->isValid());
609 ASSERT_TRUE(inputMQ->isValid());
610 ASSERT_TRUE(outputMQ->isValid());
611
612 ASSERT_NO_FATAL_FAILURE(close(mEffect));
613 ASSERT_NO_FATAL_FAILURE(destroy(mFactory, mEffect));
614}
615
Shunkai Yao812d5b42022-11-16 18:08:50 +0000616/// Data processing test
617// Send data to effects and expect it to be consumed by checking statusMQ.
Jaideep Sharmacba42862023-06-23 10:27:39 +0530618// Effects exposing bypass flags or operating in offload mode will be skipped.
619TEST_P(AudioEffectDataPathTest, ConsumeDataInProcessingState) {
Shunkai Yaocb0fc412022-12-15 20:34:32 +0000620 ASSERT_NO_FATAL_FAILURE(create(mFactory, mEffect, mDescriptor));
Shunkai Yao812d5b42022-11-16 18:08:50 +0000621
Shunkai Yao61f9dd22024-05-08 22:34:36 +0000622 Parameter::Common common = createParamCommon(
Shunkai Yao812d5b42022-11-16 18:08:50 +0000623 0 /* session */, 1 /* ioHandle */, 44100 /* iSampleRate */, 44100 /* oSampleRate */,
624 kInputFrameCount /* iFrameCount */, kOutputFrameCount /* oFrameCount */);
625 IEffect::OpenEffectReturn ret;
Shunkai Yaocb0fc412022-12-15 20:34:32 +0000626 ASSERT_NO_FATAL_FAILURE(open(mEffect, common, std::nullopt /* specific */, &ret, EX_NONE));
Shunkai Yao28aff3d2024-06-15 03:16:06 +0000627 std::vector<float> inputBuffer(mInputSamples), outputBuffer(mOutputSamples);
628 ASSERT_NO_FATAL_FAILURE(
629 processAndWriteToOutput(inputBuffer, outputBuffer, mEffect, &ret, mVersion));
Shunkai Yaocb0fc412022-12-15 20:34:32 +0000630 ASSERT_NO_FATAL_FAILURE(close(mEffect));
631 ASSERT_NO_FATAL_FAILURE(destroy(mFactory, mEffect));
Shunkai Yao812d5b42022-11-16 18:08:50 +0000632}
633
634// Send data to effects and expect it to be consumed after effect restart.
Jaideep Sharmacba42862023-06-23 10:27:39 +0530635// Effects exposing bypass flags or operating in offload mode will be skipped.
636TEST_P(AudioEffectDataPathTest, ConsumeDataAfterRestart) {
Shunkai Yaocb0fc412022-12-15 20:34:32 +0000637 ASSERT_NO_FATAL_FAILURE(create(mFactory, mEffect, mDescriptor));
Shunkai Yao812d5b42022-11-16 18:08:50 +0000638
Shunkai Yao61f9dd22024-05-08 22:34:36 +0000639 Parameter::Common common = createParamCommon(
Shunkai Yao812d5b42022-11-16 18:08:50 +0000640 0 /* session */, 1 /* ioHandle */, 44100 /* iSampleRate */, 44100 /* oSampleRate */,
641 kInputFrameCount /* iFrameCount */, kOutputFrameCount /* oFrameCount */);
642 IEffect::OpenEffectReturn ret;
Shunkai Yaocb0fc412022-12-15 20:34:32 +0000643 ASSERT_NO_FATAL_FAILURE(open(mEffect, common, std::nullopt /* specific */, &ret, EX_NONE));
Shunkai Yao812d5b42022-11-16 18:08:50 +0000644
Shunkai Yao28aff3d2024-06-15 03:16:06 +0000645 std::vector<float> inputBuffer(mInputSamples), outputBuffer(mOutputSamples);
646 ASSERT_NO_FATAL_FAILURE(
647 processAndWriteToOutput(inputBuffer, outputBuffer, mEffect, &ret, mVersion));
648 ASSERT_NO_FATAL_FAILURE(
649 processAndWriteToOutput(inputBuffer, outputBuffer, mEffect, &ret, mVersion));
Shunkai Yao812d5b42022-11-16 18:08:50 +0000650
Shunkai Yaocb0fc412022-12-15 20:34:32 +0000651 ASSERT_NO_FATAL_FAILURE(close(mEffect));
652 ASSERT_NO_FATAL_FAILURE(destroy(mFactory, mEffect));
Shunkai Yao812d5b42022-11-16 18:08:50 +0000653}
654
Shunkai Yao65c7c702024-01-09 20:50:53 +0000655// Send data to effects and expect it to be consumed after effect reopen (IO AudioConfig change).
656// Effects exposing bypass flags or operating in offload mode will be skipped.
657TEST_P(AudioEffectDataPathTest, ConsumeDataAfterReopen) {
Shunkai Yao9f9fe922024-03-04 21:23:04 +0000658 if (!EffectFactoryHelper::isReopenSupported(mFactory)) {
659 GTEST_SKIP() << "Skipping test as effect does not support reopen";
660 }
661
Shunkai Yao65c7c702024-01-09 20:50:53 +0000662 ASSERT_NO_FATAL_FAILURE(create(mFactory, mEffect, mDescriptor));
663
Shunkai Yao61f9dd22024-05-08 22:34:36 +0000664 Parameter::Common common = createParamCommon(
Shunkai Yao65c7c702024-01-09 20:50:53 +0000665 0 /* session */, 1 /* ioHandle */, 44100 /* iSampleRate */, 44100 /* oSampleRate */,
666 kInputFrameCount /* iFrameCount */, kOutputFrameCount /* oFrameCount */);
667 IEffect::OpenEffectReturn ret;
668 ASSERT_NO_FATAL_FAILURE(open(mEffect, common, std::nullopt /* specific */, &ret, EX_NONE));
669 auto statusMQ = std::make_unique<EffectHelper::StatusMQ>(ret.statusMQ);
670 ASSERT_TRUE(statusMQ->isValid());
Shunkai Yao65c7c702024-01-09 20:50:53 +0000671
Shunkai Yao28aff3d2024-06-15 03:16:06 +0000672 std::vector<float> inputBuffer(mInputSamples), outputBuffer(mOutputSamples);
673 ASSERT_NO_FATAL_FAILURE(
674 processAndWriteToOutput(inputBuffer, outputBuffer, mEffect, &ret, mVersion));
Shunkai Yao65c7c702024-01-09 20:50:53 +0000675
676 // set a new common parameter with different IO frameCount, reopen
677 Parameter::Id id = Parameter::Id::make<Parameter::Id::commonTag>(Parameter::common);
678 common.input.frameCount += 4;
679 common.output.frameCount += 4;
680 ASSERT_NO_FATAL_FAILURE(setAndGetParameter(id, Parameter::make<Parameter::common>(common)));
681 ASSERT_TRUE(statusMQ->isValid());
682 expectDataMqUpdateEventFlag(statusMQ);
Shunkai Yao28aff3d2024-06-15 03:16:06 +0000683 ASSERT_NO_FATAL_FAILURE(reopen(mEffect, common, &ret));
Shunkai Yao65c7c702024-01-09 20:50:53 +0000684
Shunkai Yao28aff3d2024-06-15 03:16:06 +0000685 inputBuffer.resize(mInputSamples);
686 outputBuffer.resize(mOutputSamples);
687 ASSERT_NO_FATAL_FAILURE(
688 processAndWriteToOutput(inputBuffer, outputBuffer, mEffect, &ret, mVersion));
Shunkai Yao65c7c702024-01-09 20:50:53 +0000689
690 ASSERT_NO_FATAL_FAILURE(close(mEffect));
691 ASSERT_NO_FATAL_FAILURE(destroy(mFactory, mEffect));
692}
693
Shunkai Yao812d5b42022-11-16 18:08:50 +0000694// Send data to IDLE effects and expect it to be consumed after effect start.
Jaideep Sharmacba42862023-06-23 10:27:39 +0530695// Effects exposing bypass flags or operating in offload mode will be skipped.
696TEST_P(AudioEffectDataPathTest, SendDataAtIdleAndConsumeDataInProcessing) {
Shunkai Yaocb0fc412022-12-15 20:34:32 +0000697 ASSERT_NO_FATAL_FAILURE(create(mFactory, mEffect, mDescriptor));
Shunkai Yao812d5b42022-11-16 18:08:50 +0000698
Shunkai Yao61f9dd22024-05-08 22:34:36 +0000699 Parameter::Common common = createParamCommon(
Shunkai Yao812d5b42022-11-16 18:08:50 +0000700 0 /* session */, 1 /* ioHandle */, 44100 /* iSampleRate */, 44100 /* oSampleRate */,
701 kInputFrameCount /* iFrameCount */, kOutputFrameCount /* oFrameCount */);
702 IEffect::OpenEffectReturn ret;
Shunkai Yaocb0fc412022-12-15 20:34:32 +0000703 ASSERT_NO_FATAL_FAILURE(open(mEffect, common, std::nullopt /* specific */, &ret, EX_NONE));
Shunkai Yao812d5b42022-11-16 18:08:50 +0000704 auto statusMQ = std::make_unique<EffectHelper::StatusMQ>(ret.statusMQ);
Shunkai Yaocb0fc412022-12-15 20:34:32 +0000705 ASSERT_TRUE(statusMQ->isValid());
Shunkai Yao812d5b42022-11-16 18:08:50 +0000706 auto inputMQ = std::make_unique<EffectHelper::DataMQ>(ret.inputDataMQ);
Shunkai Yaocb0fc412022-12-15 20:34:32 +0000707 ASSERT_TRUE(inputMQ->isValid());
Shunkai Yao812d5b42022-11-16 18:08:50 +0000708 auto outputMQ = std::make_unique<EffectHelper::DataMQ>(ret.outputDataMQ);
Shunkai Yaocb0fc412022-12-15 20:34:32 +0000709 ASSERT_TRUE(outputMQ->isValid());
Shunkai Yao812d5b42022-11-16 18:08:50 +0000710
Shunkai Yao28aff3d2024-06-15 03:16:06 +0000711 std::vector<float> inputBuffer(mInputSamples), outputBuffer(mOutputSamples);
712 ASSERT_NO_FATAL_FAILURE(
713 processAndWriteToOutput(inputBuffer, outputBuffer, mEffect, &ret, mVersion));
Shunkai Yao812d5b42022-11-16 18:08:50 +0000714
Shunkai Yao28aff3d2024-06-15 03:16:06 +0000715 EXPECT_NO_FATAL_FAILURE(EffectHelper::writeToFmq(statusMQ, inputMQ, inputBuffer, mVersion));
Shunkai Yaocb0fc412022-12-15 20:34:32 +0000716 ASSERT_NO_FATAL_FAILURE(command(mEffect, CommandId::START));
Shunkai Yaob49631f2023-02-03 01:44:32 +0000717 EXPECT_NO_FATAL_FAILURE(
Shunkai Yao28aff3d2024-06-15 03:16:06 +0000718 EffectHelper::readFromFmq(statusMQ, 1, outputMQ, outputBuffer.size(), outputBuffer));
Shunkai Yaocb0fc412022-12-15 20:34:32 +0000719 ASSERT_NO_FATAL_FAILURE(command(mEffect, CommandId::STOP));
Shunkai Yaocb0fc412022-12-15 20:34:32 +0000720 ASSERT_NO_FATAL_FAILURE(close(mEffect));
721 ASSERT_NO_FATAL_FAILURE(destroy(mFactory, mEffect));
Shunkai Yao812d5b42022-11-16 18:08:50 +0000722}
723
724// Send data multiple times.
Jaideep Sharmacba42862023-06-23 10:27:39 +0530725// Effects exposing bypass flags or operating in offload mode will be skipped.
726TEST_P(AudioEffectDataPathTest, ProcessDataMultipleTimes) {
Shunkai Yaocb0fc412022-12-15 20:34:32 +0000727 ASSERT_NO_FATAL_FAILURE(create(mFactory, mEffect, mDescriptor));
Shunkai Yao812d5b42022-11-16 18:08:50 +0000728
Shunkai Yao61f9dd22024-05-08 22:34:36 +0000729 Parameter::Common common = createParamCommon(
Shunkai Yao812d5b42022-11-16 18:08:50 +0000730 0 /* session */, 1 /* ioHandle */, 44100 /* iSampleRate */, 44100 /* oSampleRate */,
731 kInputFrameCount /* iFrameCount */, kOutputFrameCount /* oFrameCount */);
732 IEffect::OpenEffectReturn ret;
Shunkai Yaocb0fc412022-12-15 20:34:32 +0000733 ASSERT_NO_FATAL_FAILURE(open(mEffect, common, std::nullopt /* specific */, &ret, EX_NONE));
Shunkai Yao28aff3d2024-06-15 03:16:06 +0000734 std::vector<float> inputBuffer(mInputSamples), outputBuffer(mOutputSamples);
Shunkai Yao812d5b42022-11-16 18:08:50 +0000735
Shunkai Yao28aff3d2024-06-15 03:16:06 +0000736 ASSERT_NO_FATAL_FAILURE(
737 processAndWriteToOutput(inputBuffer, outputBuffer, mEffect, &ret, mVersion, 2));
Shunkai Yao812d5b42022-11-16 18:08:50 +0000738
Shunkai Yaocb0fc412022-12-15 20:34:32 +0000739 ASSERT_NO_FATAL_FAILURE(close(mEffect));
740 ASSERT_NO_FATAL_FAILURE(destroy(mFactory, mEffect));
Shunkai Yao812d5b42022-11-16 18:08:50 +0000741}
742
Shunkai Yaob49631f2023-02-03 01:44:32 +0000743// Send data to processing state effects, stop, and restart.
Jaideep Sharmacba42862023-06-23 10:27:39 +0530744// Effects exposing bypass flags or operating in offload mode will be skipped.
745TEST_P(AudioEffectDataPathTest, ConsumeDataAndRestart) {
Shunkai Yaocb0fc412022-12-15 20:34:32 +0000746 ASSERT_NO_FATAL_FAILURE(create(mFactory, mEffect, mDescriptor));
Shunkai Yao812d5b42022-11-16 18:08:50 +0000747
Shunkai Yao61f9dd22024-05-08 22:34:36 +0000748 Parameter::Common common = createParamCommon(
Shunkai Yao812d5b42022-11-16 18:08:50 +0000749 0 /* session */, 1 /* ioHandle */, 44100 /* iSampleRate */, 44100 /* oSampleRate */,
750 kInputFrameCount /* iFrameCount */, kOutputFrameCount /* oFrameCount */);
751 IEffect::OpenEffectReturn ret;
Shunkai Yaocb0fc412022-12-15 20:34:32 +0000752 ASSERT_NO_FATAL_FAILURE(open(mEffect, common, std::nullopt /* specific */, &ret, EX_NONE));
Shunkai Yao28aff3d2024-06-15 03:16:06 +0000753 std::vector<float> inputBuffer(mInputSamples), outputBuffer(mOutputSamples);
Shunkai Yao812d5b42022-11-16 18:08:50 +0000754
Shunkai Yao28aff3d2024-06-15 03:16:06 +0000755 ASSERT_NO_FATAL_FAILURE(
756 processAndWriteToOutput(inputBuffer, outputBuffer, mEffect, &ret, mVersion, 2));
757 ASSERT_NO_FATAL_FAILURE(
758 processAndWriteToOutput(inputBuffer, outputBuffer, mEffect, &ret, mVersion, 2));
Shunkai Yao812d5b42022-11-16 18:08:50 +0000759
Shunkai Yaocb0fc412022-12-15 20:34:32 +0000760 ASSERT_NO_FATAL_FAILURE(close(mEffect));
761 ASSERT_NO_FATAL_FAILURE(destroy(mFactory, mEffect));
Shunkai Yao812d5b42022-11-16 18:08:50 +0000762}
763
764// Send data to closed effects and expect it not be consumed.
Jaideep Sharmacba42862023-06-23 10:27:39 +0530765// Effects exposing bypass flags or operating in offload mode will be skipped.
766TEST_P(AudioEffectDataPathTest, NotConsumeDataByClosedEffect) {
Shunkai Yaocb0fc412022-12-15 20:34:32 +0000767 ASSERT_NO_FATAL_FAILURE(create(mFactory, mEffect, mDescriptor));
Shunkai Yao812d5b42022-11-16 18:08:50 +0000768
Shunkai Yao61f9dd22024-05-08 22:34:36 +0000769 Parameter::Common common = createParamCommon(
Shunkai Yao812d5b42022-11-16 18:08:50 +0000770 0 /* session */, 1 /* ioHandle */, 44100 /* iSampleRate */, 44100 /* oSampleRate */,
771 kInputFrameCount /* iFrameCount */, kOutputFrameCount /* oFrameCount */);
772 IEffect::OpenEffectReturn ret;
Shunkai Yaocb0fc412022-12-15 20:34:32 +0000773 ASSERT_NO_FATAL_FAILURE(open(mEffect, common, std::nullopt /* specific */, &ret, EX_NONE));
Shunkai Yao28aff3d2024-06-15 03:16:06 +0000774 std::vector<float> inputBuffer(mInputSamples), outputBuffer(mOutputSamples);
Shunkai Yaocb0fc412022-12-15 20:34:32 +0000775 ASSERT_NO_FATAL_FAILURE(close(mEffect));
Shunkai Yao812d5b42022-11-16 18:08:50 +0000776
777 auto statusMQ = std::make_unique<EffectHelper::StatusMQ>(ret.statusMQ);
Shunkai Yaocb0fc412022-12-15 20:34:32 +0000778 ASSERT_TRUE(statusMQ->isValid());
Shunkai Yao812d5b42022-11-16 18:08:50 +0000779 auto inputMQ = std::make_unique<EffectHelper::DataMQ>(ret.inputDataMQ);
Shunkai Yaocb0fc412022-12-15 20:34:32 +0000780 ASSERT_TRUE(inputMQ->isValid());
Shunkai Yao812d5b42022-11-16 18:08:50 +0000781 auto outputMQ = std::make_unique<EffectHelper::DataMQ>(ret.outputDataMQ);
Shunkai Yaocb0fc412022-12-15 20:34:32 +0000782 ASSERT_TRUE(outputMQ->isValid());
Shunkai Yao812d5b42022-11-16 18:08:50 +0000783
Shunkai Yao28aff3d2024-06-15 03:16:06 +0000784 EXPECT_NO_FATAL_FAILURE(EffectHelper::writeToFmq(statusMQ, inputMQ, inputBuffer, mVersion));
785 EXPECT_NO_FATAL_FAILURE(EffectHelper::readFromFmq(statusMQ, 0, outputMQ, 0, outputBuffer));
Shunkai Yao812d5b42022-11-16 18:08:50 +0000786
Shunkai Yaocb0fc412022-12-15 20:34:32 +0000787 ASSERT_NO_FATAL_FAILURE(destroy(mFactory, mEffect));
Shunkai Yao812d5b42022-11-16 18:08:50 +0000788}
789
790// Send data to multiple effects.
Jaideep Sharmacba42862023-06-23 10:27:39 +0530791// Effects exposing bypass flags or operating in offload mode will be skipped.
792TEST_P(AudioEffectDataPathTest, ConsumeDataMultipleEffects) {
Shunkai Yao812d5b42022-11-16 18:08:50 +0000793 std::shared_ptr<IEffect> effect1, effect2;
Shunkai Yaocb0fc412022-12-15 20:34:32 +0000794 ASSERT_NO_FATAL_FAILURE(create(mFactory, effect1, mDescriptor));
795 ASSERT_NO_FATAL_FAILURE(create(mFactory, effect2, mDescriptor));
Shunkai Yao812d5b42022-11-16 18:08:50 +0000796
Shunkai Yao61f9dd22024-05-08 22:34:36 +0000797 Parameter::Common common1 = createParamCommon(
Shunkai Yao812d5b42022-11-16 18:08:50 +0000798 0 /* session */, 1 /* ioHandle */, 44100 /* iSampleRate */, 44100 /* oSampleRate */,
799 kInputFrameCount /* iFrameCount */, kOutputFrameCount /* oFrameCount */);
Shunkai Yao61f9dd22024-05-08 22:34:36 +0000800 Parameter::Common common2 = createParamCommon(
Shunkai Yao812d5b42022-11-16 18:08:50 +0000801 1 /* session */, 1 /* ioHandle */, 48000 /* iSampleRate */, 48000 /* oSampleRate */,
802 2 * kInputFrameCount /* iFrameCount */, 2 * kOutputFrameCount /* oFrameCount */);
803 IEffect::OpenEffectReturn ret1, ret2;
804 ASSERT_NO_FATAL_FAILURE(open(effect1, common1, std::nullopt /* specific */, &ret1, EX_NONE));
805 ASSERT_NO_FATAL_FAILURE(open(effect2, common2, std::nullopt /* specific */, &ret2, EX_NONE));
Shunkai Yao28aff3d2024-06-15 03:16:06 +0000806 std::vector<float> inputBuffer1(kInputFrameCount * mInputFrameSize / sizeof(float)),
807 outputBuffer1(kOutputFrameCount * mOutputFrameSize / sizeof(float));
808 std::vector<float> inputBuffer2(2 * kInputFrameCount * mInputFrameSize / sizeof(float)),
809 outputBuffer2(2 * kOutputFrameCount * mOutputFrameSize / sizeof(float));
Shunkai Yao812d5b42022-11-16 18:08:50 +0000810
Shunkai Yao28aff3d2024-06-15 03:16:06 +0000811 ASSERT_NO_FATAL_FAILURE(
812 processAndWriteToOutput(inputBuffer1, outputBuffer1, effect1, &ret1, mVersion, 2));
813 ASSERT_NO_FATAL_FAILURE(
814 processAndWriteToOutput(inputBuffer2, outputBuffer2, effect2, &ret2, mVersion, 2));
Shunkai Yao812d5b42022-11-16 18:08:50 +0000815
Shunkai Yao812d5b42022-11-16 18:08:50 +0000816 ASSERT_NO_FATAL_FAILURE(close(effect1));
817 ASSERT_NO_FATAL_FAILURE(destroy(mFactory, effect1));
818
Shunkai Yao812d5b42022-11-16 18:08:50 +0000819 ASSERT_NO_FATAL_FAILURE(close(effect2));
820 ASSERT_NO_FATAL_FAILURE(destroy(mFactory, effect2));
821}
822
823INSTANTIATE_TEST_SUITE_P(
824 SingleEffectInstanceTest, AudioEffectTest,
825 ::testing::Combine(testing::ValuesIn(
826 EffectFactoryHelper::getAllEffectDescriptors(IFactory::descriptor))),
827 [](const testing::TestParamInfo<AudioEffectTest::ParamType>& info) {
Shunkai Yaocb0fc412022-12-15 20:34:32 +0000828 auto descriptor = std::get<PARAM_INSTANCE_NAME>(info.param).second;
Jaideep Sharmae4c7a962023-06-14 19:14:44 +0530829 std::string name = getPrefix(descriptor);
Shunkai Yao812d5b42022-11-16 18:08:50 +0000830 std::replace_if(
831 name.begin(), name.end(), [](const char c) { return !std::isalnum(c); }, '_');
832 return name;
833 });
Shunkai Yaoa4ab38c2022-10-14 01:07:47 +0000834GTEST_ALLOW_UNINSTANTIATED_PARAMETERIZED_TEST(AudioEffectTest);
Shunkai Yao67b1be62022-07-13 05:01:42 +0000835
Jaideep Sharmacba42862023-06-23 10:27:39 +0530836INSTANTIATE_TEST_SUITE_P(
837 SingleEffectInstanceTest, AudioEffectDataPathTest,
838 ::testing::Combine(testing::ValuesIn(
839 EffectFactoryHelper::getAllEffectDescriptors(IFactory::descriptor))),
840 [](const testing::TestParamInfo<AudioEffectDataPathTest::ParamType>& info) {
841 auto descriptor = std::get<PARAM_INSTANCE_NAME>(info.param).second;
842 std::string name = getPrefix(descriptor);
843 std::replace_if(
844 name.begin(), name.end(), [](const char c) { return !std::isalnum(c); }, '_');
845 return name;
846 });
847
848GTEST_ALLOW_UNINSTANTIATED_PARAMETERIZED_TEST(AudioEffectDataPathTest);
849
Shunkai Yao67b1be62022-07-13 05:01:42 +0000850int main(int argc, char** argv) {
851 ::testing::InitGoogleTest(&argc, argv);
Jaideep Sharma74498412023-09-13 15:25:25 +0530852 ::testing::UnitTest::GetInstance()->listeners().Append(new TestExecutionTracer());
Shunkai Yao67b1be62022-07-13 05:01:42 +0000853 ABinderProcess_setThreadPoolMaxThreadCount(1);
854 ABinderProcess_startThreadPool();
855 return RUN_ALL_TESTS();
Shunkai Yaoa4ab38c2022-10-14 01:07:47 +0000856}