blob: 01cdd816f5644e1fe95dbb82134d0994d905a60a [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
32#include "AudioHalBinderServiceUtil.h"
Shunkai Yao812d5b42022-11-16 18:08:50 +000033#include "EffectFactoryHelper.h"
Shunkai Yaoa4ab38c2022-10-14 01:07:47 +000034#include "EffectHelper.h"
Shunkai Yao121c6dd2022-09-21 23:42:08 +000035#include "TestUtils.h"
Shunkai Yao67b1be62022-07-13 05:01:42 +000036
37using namespace android;
38
39using ndk::ScopedAStatus;
40
Shunkai Yaoea24c1a2022-09-28 17:39:23 +000041using aidl::android::hardware::audio::effect::CommandId;
Shunkai Yao67b1be62022-07-13 05:01:42 +000042using aidl::android::hardware::audio::effect::Descriptor;
Shunkai Yao8771cec2023-09-20 22:46:59 +000043using aidl::android::hardware::audio::effect::Flags;
Shunkai Yao45905172022-08-24 18:14:02 +000044using aidl::android::hardware::audio::effect::IEffect;
Shunkai Yao67b1be62022-07-13 05:01:42 +000045using aidl::android::hardware::audio::effect::IFactory;
Shunkai Yaoea24c1a2022-09-28 17:39:23 +000046using aidl::android::hardware::audio::effect::Parameter;
47using aidl::android::hardware::audio::effect::State;
Shunkai Yao5df4e6c2023-01-10 03:20:00 +000048using aidl::android::media::audio::common::AudioDeviceDescription;
49using aidl::android::media::audio::common::AudioDeviceType;
50using aidl::android::media::audio::common::AudioMode;
51using aidl::android::media::audio::common::AudioSource;
Jaideep Sharma74498412023-09-13 15:25:25 +053052using android::hardware::audio::common::testing::detail::TestExecutionTracer;
Shunkai Yao67b1be62022-07-13 05:01:42 +000053
Shunkai Yao812d5b42022-11-16 18:08:50 +000054enum ParamName { PARAM_INSTANCE_NAME };
Shunkai Yaocb0fc412022-12-15 20:34:32 +000055using EffectTestParam = std::tuple<std::pair<std::shared_ptr<IFactory>, Descriptor>>;
Shunkai Yao812d5b42022-11-16 18:08:50 +000056
57class AudioEffectTest : public testing::TestWithParam<EffectTestParam>, public EffectHelper {
Shunkai Yao45905172022-08-24 18:14:02 +000058 public:
Shunkai Yaocb0fc412022-12-15 20:34:32 +000059 AudioEffectTest() {
60 std::tie(mFactory, mDescriptor) = std::get<PARAM_INSTANCE_NAME>(GetParam());
61 }
Shunkai Yaoa4ab38c2022-10-14 01:07:47 +000062
Shunkai Yao812d5b42022-11-16 18:08:50 +000063 void SetUp() override {}
Shunkai Yaocb0fc412022-12-15 20:34:32 +000064
65 void TearDown() override {
66 // Do the cleanup for every test case
67 if (mEffect) {
68 ASSERT_NO_FATAL_FAILURE(commandIgnoreRet(mEffect, CommandId::STOP));
69 ASSERT_NO_FATAL_FAILURE(closeIgnoreRet(mEffect));
70 ASSERT_NO_FATAL_FAILURE(destroyIgnoreRet(mFactory, mEffect));
71 mEffect.reset();
72 }
73 }
Shunkai Yao45905172022-08-24 18:14:02 +000074
Shunkai Yao812d5b42022-11-16 18:08:50 +000075 static const long kInputFrameCount = 0x100, kOutputFrameCount = 0x100;
76 std::shared_ptr<IFactory> mFactory;
Shunkai Yaocb0fc412022-12-15 20:34:32 +000077 std::shared_ptr<IEffect> mEffect;
78 Descriptor mDescriptor;
Shunkai Yao5df4e6c2023-01-10 03:20:00 +000079
80 void setAndGetParameter(Parameter::Id id, const Parameter& set) {
81 Parameter get;
82 EXPECT_IS_OK(mEffect->setParameter(set));
83 EXPECT_IS_OK(mEffect->getParameter(id, &get));
Shunkai Yaoeea19942023-02-16 02:31:24 +000084 EXPECT_EQ(set, get) << set.toString() << "\n vs \n" << get.toString();
Shunkai Yao5df4e6c2023-01-10 03:20:00 +000085 }
Shunkai Yao45905172022-08-24 18:14:02 +000086};
87
Jaideep Sharmacba42862023-06-23 10:27:39 +053088class AudioEffectDataPathTest : public AudioEffectTest {
Shunkai Yao8771cec2023-09-20 22:46:59 +000089 public:
90 void SetUp() override {
91 AudioEffectTest::SetUp();
92 SKIP_TEST_IF_DATA_UNSUPPORTED(mDescriptor.common.flags);
93 }
Jaideep Sharmacba42862023-06-23 10:27:39 +053094};
95
Shunkai Yao812d5b42022-11-16 18:08:50 +000096TEST_P(AudioEffectTest, SetupAndTearDown) {
97 // Intentionally empty test body.
Shunkai Yao45905172022-08-24 18:14:02 +000098}
99
Shunkai Yao812d5b42022-11-16 18:08:50 +0000100TEST_P(AudioEffectTest, CreateAndDestroy) {
Shunkai Yaocb0fc412022-12-15 20:34:32 +0000101 ASSERT_NO_FATAL_FAILURE(create(mFactory, mEffect, mDescriptor));
102 ASSERT_NO_FATAL_FAILURE(destroy(mFactory, mEffect));
Shunkai Yao45905172022-08-24 18:14:02 +0000103}
104
Shunkai Yao812d5b42022-11-16 18:08:50 +0000105TEST_P(AudioEffectTest, OpenAndClose) {
Shunkai Yaocb0fc412022-12-15 20:34:32 +0000106 ASSERT_NO_FATAL_FAILURE(create(mFactory, mEffect, mDescriptor));
107 ASSERT_NO_FATAL_FAILURE(open(mEffect));
108 ASSERT_NO_FATAL_FAILURE(close(mEffect));
109 ASSERT_NO_FATAL_FAILURE(destroy(mFactory, mEffect));
Shunkai Yao45905172022-08-24 18:14:02 +0000110}
111
Shunkai Yao812d5b42022-11-16 18:08:50 +0000112TEST_P(AudioEffectTest, CloseUnopenedEffect) {
Shunkai Yaocb0fc412022-12-15 20:34:32 +0000113 ASSERT_NO_FATAL_FAILURE(create(mFactory, mEffect, mDescriptor));
114 ASSERT_NO_FATAL_FAILURE(close(mEffect));
115 ASSERT_NO_FATAL_FAILURE(destroy(mFactory, mEffect));
Shunkai Yao45905172022-08-24 18:14:02 +0000116}
117
Shunkai Yao812d5b42022-11-16 18:08:50 +0000118TEST_P(AudioEffectTest, DoubleOpenAndClose) {
119 std::shared_ptr<IEffect> effect1, effect2;
Shunkai Yaocb0fc412022-12-15 20:34:32 +0000120 ASSERT_NO_FATAL_FAILURE(create(mFactory, effect1, mDescriptor));
121 ASSERT_NO_FATAL_FAILURE(create(mFactory, effect2, mDescriptor));
Shunkai Yao812d5b42022-11-16 18:08:50 +0000122 ASSERT_NO_FATAL_FAILURE(open(effect1));
123 ASSERT_NO_FATAL_FAILURE(open(effect2, 1 /* session */));
124 ASSERT_NO_FATAL_FAILURE(close(effect1));
125 ASSERT_NO_FATAL_FAILURE(close(effect2));
126 ASSERT_NO_FATAL_FAILURE(destroy(mFactory, effect1));
127 ASSERT_NO_FATAL_FAILURE(destroy(mFactory, effect2));
Shunkai Yao45905172022-08-24 18:14:02 +0000128}
129
Shunkai Yao812d5b42022-11-16 18:08:50 +0000130TEST_P(AudioEffectTest, TripleOpenAndClose) {
131 std::shared_ptr<IEffect> effect1, effect2, effect3;
Shunkai Yaocb0fc412022-12-15 20:34:32 +0000132 ASSERT_NO_FATAL_FAILURE(create(mFactory, effect1, mDescriptor));
133 ASSERT_NO_FATAL_FAILURE(create(mFactory, effect2, mDescriptor));
134 ASSERT_NO_FATAL_FAILURE(create(mFactory, effect3, mDescriptor));
Shunkai Yao812d5b42022-11-16 18:08:50 +0000135 ASSERT_NO_FATAL_FAILURE(open(effect1));
136 ASSERT_NO_FATAL_FAILURE(open(effect2, 1 /* session */));
137 ASSERT_NO_FATAL_FAILURE(open(effect3, 2 /* session */));
138 ASSERT_NO_FATAL_FAILURE(close(effect1));
139 ASSERT_NO_FATAL_FAILURE(close(effect2));
140 ASSERT_NO_FATAL_FAILURE(close(effect3));
141 ASSERT_NO_FATAL_FAILURE(destroy(mFactory, effect1));
142 ASSERT_NO_FATAL_FAILURE(destroy(mFactory, effect2));
143 ASSERT_NO_FATAL_FAILURE(destroy(mFactory, effect3));
144}
Shunkai Yao45905172022-08-24 18:14:02 +0000145
Shunkai Yao812d5b42022-11-16 18:08:50 +0000146TEST_P(AudioEffectTest, GetDescritorBeforeOpen) {
Shunkai Yao812d5b42022-11-16 18:08:50 +0000147 Descriptor desc;
Shunkai Yaocb0fc412022-12-15 20:34:32 +0000148 ASSERT_NO_FATAL_FAILURE(create(mFactory, mEffect, mDescriptor));
149 ASSERT_NO_FATAL_FAILURE(getDescriptor(mEffect, desc));
Shunkai Yao4c4f3cd2023-02-28 01:50:40 +0000150 EXPECT_EQ(mDescriptor.common.id.type, desc.common.id.type);
151 EXPECT_EQ(mDescriptor.common.id.uuid, desc.common.id.uuid);
152 EXPECT_EQ(mDescriptor.common.name, desc.common.name);
153 EXPECT_EQ(mDescriptor.common.implementor, desc.common.implementor);
Shunkai Yaocb0fc412022-12-15 20:34:32 +0000154 // Effect implementation Must fill in implementor and name
Shunkai Yao812d5b42022-11-16 18:08:50 +0000155 EXPECT_NE("", desc.common.name);
156 EXPECT_NE("", desc.common.implementor);
Shunkai Yaocb0fc412022-12-15 20:34:32 +0000157 ASSERT_NO_FATAL_FAILURE(destroy(mFactory, mEffect));
Shunkai Yao812d5b42022-11-16 18:08:50 +0000158}
159
160TEST_P(AudioEffectTest, GetDescritorAfterOpen) {
Shunkai Yao812d5b42022-11-16 18:08:50 +0000161 Descriptor beforeOpen, afterOpen, afterClose;
Shunkai Yaocb0fc412022-12-15 20:34:32 +0000162 ASSERT_NO_FATAL_FAILURE(create(mFactory, mEffect, mDescriptor));
163 ASSERT_NO_FATAL_FAILURE(getDescriptor(mEffect, beforeOpen));
164 ASSERT_NO_FATAL_FAILURE(open(mEffect));
165 ASSERT_NO_FATAL_FAILURE(getDescriptor(mEffect, afterOpen));
Shunkai Yao812d5b42022-11-16 18:08:50 +0000166 EXPECT_EQ(beforeOpen.toString(), afterOpen.toString()) << "\n"
167 << beforeOpen.toString() << "\n"
168 << afterOpen.toString();
Shunkai Yaocb0fc412022-12-15 20:34:32 +0000169 ASSERT_NO_FATAL_FAILURE(close(mEffect));
170 ASSERT_NO_FATAL_FAILURE(getDescriptor(mEffect, afterClose));
Shunkai Yao812d5b42022-11-16 18:08:50 +0000171 EXPECT_EQ(beforeOpen.toString(), afterClose.toString()) << "\n"
172 << beforeOpen.toString() << "\n"
173 << afterClose.toString();
Shunkai Yaocb0fc412022-12-15 20:34:32 +0000174 ASSERT_NO_FATAL_FAILURE(destroy(mFactory, mEffect));
Shunkai Yao812d5b42022-11-16 18:08:50 +0000175}
176
177TEST_P(AudioEffectTest, DescriptorExistAndUnique) {
Shunkai Yao812d5b42022-11-16 18:08:50 +0000178 Descriptor desc;
179
180 auto descList = EffectFactoryHelper::getAllEffectDescriptors(IFactory::descriptor);
181 std::set<Descriptor::Identity> idSet;
182 for (const auto& it : descList) {
Shunkai Yaocb0fc412022-12-15 20:34:32 +0000183 auto& id = it.second.common.id;
Shunkai Yao812d5b42022-11-16 18:08:50 +0000184 EXPECT_EQ(0ul, idSet.count(id));
185 idSet.insert(id);
Shunkai Yao45905172022-08-24 18:14:02 +0000186 }
Shunkai Yao812d5b42022-11-16 18:08:50 +0000187
Shunkai Yaocb0fc412022-12-15 20:34:32 +0000188 ASSERT_NO_FATAL_FAILURE(create(mFactory, mEffect, mDescriptor));
189 ASSERT_NO_FATAL_FAILURE(getDescriptor(mEffect, desc));
Shunkai Yao4c4f3cd2023-02-28 01:50:40 +0000190 int uuidCount = std::count_if(idSet.begin(), idSet.end(), [&](const auto& id) {
191 return id.uuid == desc.common.id.uuid && id.type == desc.common.id.type;
192 });
193
194 EXPECT_EQ(1, uuidCount);
Shunkai Yaocb0fc412022-12-15 20:34:32 +0000195 ASSERT_NO_FATAL_FAILURE(destroy(mFactory, mEffect));
Shunkai Yao45905172022-08-24 18:14:02 +0000196}
197
Shunkai Yaoea24c1a2022-09-28 17:39:23 +0000198/// State testing.
199// An effect instance is in INIT state by default after it was created.
Shunkai Yaoa4ab38c2022-10-14 01:07:47 +0000200TEST_P(AudioEffectTest, InitStateAfterCreation) {
Shunkai Yaocb0fc412022-12-15 20:34:32 +0000201 ASSERT_NO_FATAL_FAILURE(create(mFactory, mEffect, mDescriptor));
202 ASSERT_NO_FATAL_FAILURE(expectState(mEffect, State::INIT));
203 ASSERT_NO_FATAL_FAILURE(destroy(mFactory, mEffect));
Shunkai Yaoea24c1a2022-09-28 17:39:23 +0000204}
205
Shunkai Yao812d5b42022-11-16 18:08:50 +0000206// An effect instance transfer to IDLE state after IEffect.ASSERT_NO_FATAL_FAILURE(open().
Shunkai Yaoa4ab38c2022-10-14 01:07:47 +0000207TEST_P(AudioEffectTest, IdleStateAfterOpen) {
Shunkai Yaocb0fc412022-12-15 20:34:32 +0000208 ASSERT_NO_FATAL_FAILURE(create(mFactory, mEffect, mDescriptor));
209 ASSERT_NO_FATAL_FAILURE(open(mEffect));
210 ASSERT_NO_FATAL_FAILURE(expectState(mEffect, State::IDLE));
211 ASSERT_NO_FATAL_FAILURE(close(mEffect));
212 ASSERT_NO_FATAL_FAILURE(destroy(mFactory, mEffect));
Shunkai Yaoea24c1a2022-09-28 17:39:23 +0000213}
214
215// An effect instance is in PROCESSING state after it receive an START command.
Shunkai Yaoa4ab38c2022-10-14 01:07:47 +0000216TEST_P(AudioEffectTest, ProcessingStateAfterStart) {
Shunkai Yaocb0fc412022-12-15 20:34:32 +0000217 ASSERT_NO_FATAL_FAILURE(create(mFactory, mEffect, mDescriptor));
218 ASSERT_NO_FATAL_FAILURE(expectState(mEffect, State::INIT));
219 ASSERT_NO_FATAL_FAILURE(open(mEffect));
220 ASSERT_NO_FATAL_FAILURE(expectState(mEffect, State::IDLE));
221 ASSERT_NO_FATAL_FAILURE(command(mEffect, CommandId::START));
222 ASSERT_NO_FATAL_FAILURE(expectState(mEffect, State::PROCESSING));
223 ASSERT_NO_FATAL_FAILURE(command(mEffect, CommandId::STOP));
224 ASSERT_NO_FATAL_FAILURE(close(mEffect));
225 ASSERT_NO_FATAL_FAILURE(destroy(mFactory, mEffect));
Shunkai Yaoea24c1a2022-09-28 17:39:23 +0000226}
227
228// An effect instance transfer to IDLE state after Command.Id.STOP in PROCESSING state.
Shunkai Yaoa4ab38c2022-10-14 01:07:47 +0000229TEST_P(AudioEffectTest, IdleStateAfterStop) {
Shunkai Yaocb0fc412022-12-15 20:34:32 +0000230 ASSERT_NO_FATAL_FAILURE(create(mFactory, mEffect, mDescriptor));
231 ASSERT_NO_FATAL_FAILURE(open(mEffect));
232 ASSERT_NO_FATAL_FAILURE(command(mEffect, CommandId::START));
233 ASSERT_NO_FATAL_FAILURE(expectState(mEffect, State::PROCESSING));
234 ASSERT_NO_FATAL_FAILURE(command(mEffect, CommandId::STOP));
235 ASSERT_NO_FATAL_FAILURE(expectState(mEffect, State::IDLE));
236 ASSERT_NO_FATAL_FAILURE(close(mEffect));
237 ASSERT_NO_FATAL_FAILURE(destroy(mFactory, mEffect));
Shunkai Yaoea24c1a2022-09-28 17:39:23 +0000238}
239
240// An effect instance transfer to IDLE state after Command.Id.RESET in PROCESSING state.
Shunkai Yaoa4ab38c2022-10-14 01:07:47 +0000241TEST_P(AudioEffectTest, IdleStateAfterReset) {
Shunkai Yaocb0fc412022-12-15 20:34:32 +0000242 ASSERT_NO_FATAL_FAILURE(create(mFactory, mEffect, mDescriptor));
243 ASSERT_NO_FATAL_FAILURE(open(mEffect));
244 ASSERT_NO_FATAL_FAILURE(command(mEffect, CommandId::START));
245 ASSERT_NO_FATAL_FAILURE(expectState(mEffect, State::PROCESSING));
246 ASSERT_NO_FATAL_FAILURE(command(mEffect, CommandId::RESET));
247 ASSERT_NO_FATAL_FAILURE(expectState(mEffect, State::IDLE));
248 ASSERT_NO_FATAL_FAILURE(close(mEffect));
249 ASSERT_NO_FATAL_FAILURE(destroy(mFactory, mEffect));
Shunkai Yaoea24c1a2022-09-28 17:39:23 +0000250}
251
Shunkai Yao812d5b42022-11-16 18:08:50 +0000252// An effect instance transfer to INIT after IEffect.ASSERT_NO_FATAL_FAILURE(close().
Shunkai Yaoa4ab38c2022-10-14 01:07:47 +0000253TEST_P(AudioEffectTest, InitStateAfterClose) {
Shunkai Yaocb0fc412022-12-15 20:34:32 +0000254 ASSERT_NO_FATAL_FAILURE(create(mFactory, mEffect, mDescriptor));
255 ASSERT_NO_FATAL_FAILURE(open(mEffect));
256 ASSERT_NO_FATAL_FAILURE(command(mEffect, CommandId::START));
257 ASSERT_NO_FATAL_FAILURE(command(mEffect, CommandId::STOP));
258 ASSERT_NO_FATAL_FAILURE(close(mEffect));
259 ASSERT_NO_FATAL_FAILURE(expectState(mEffect, State::INIT));
260 ASSERT_NO_FATAL_FAILURE(destroy(mFactory, mEffect));
Shunkai Yaoea24c1a2022-09-28 17:39:23 +0000261}
262
263// An effect instance shouldn't accept any command before open.
Shunkai Yaoa4ab38c2022-10-14 01:07:47 +0000264TEST_P(AudioEffectTest, NoCommandAcceptedBeforeOpen) {
Shunkai Yaocb0fc412022-12-15 20:34:32 +0000265 ASSERT_NO_FATAL_FAILURE(create(mFactory, mEffect, mDescriptor));
266 ASSERT_NO_FATAL_FAILURE(command(mEffect, CommandId::START, EX_ILLEGAL_STATE));
267 ASSERT_NO_FATAL_FAILURE(command(mEffect, CommandId::STOP, EX_ILLEGAL_STATE));
268 ASSERT_NO_FATAL_FAILURE(command(mEffect, CommandId::RESET, EX_ILLEGAL_STATE));
269 ASSERT_NO_FATAL_FAILURE(destroy(mFactory, mEffect));
Shunkai Yaoea24c1a2022-09-28 17:39:23 +0000270}
271
272// No-op when receive STOP command in IDLE state.
Shunkai Yaoa4ab38c2022-10-14 01:07:47 +0000273TEST_P(AudioEffectTest, StopCommandInIdleStateNoOp) {
Shunkai Yaocb0fc412022-12-15 20:34:32 +0000274 ASSERT_NO_FATAL_FAILURE(create(mFactory, mEffect, mDescriptor));
275 ASSERT_NO_FATAL_FAILURE(open(mEffect));
276 ASSERT_NO_FATAL_FAILURE(expectState(mEffect, State::IDLE));
277 ASSERT_NO_FATAL_FAILURE(command(mEffect, CommandId::STOP));
278 ASSERT_NO_FATAL_FAILURE(expectState(mEffect, State::IDLE));
279 ASSERT_NO_FATAL_FAILURE(close(mEffect));
280 ASSERT_NO_FATAL_FAILURE(destroy(mFactory, mEffect));
Shunkai Yaoea24c1a2022-09-28 17:39:23 +0000281}
282
Shunkai Yao812d5b42022-11-16 18:08:50 +0000283// No-op when receive RESET command in IDLE state.
Shunkai Yaoa4ab38c2022-10-14 01:07:47 +0000284TEST_P(AudioEffectTest, ResetCommandInIdleStateNoOp) {
Shunkai Yaocb0fc412022-12-15 20:34:32 +0000285 ASSERT_NO_FATAL_FAILURE(create(mFactory, mEffect, mDescriptor));
286 ASSERT_NO_FATAL_FAILURE(open(mEffect));
287 ASSERT_NO_FATAL_FAILURE(expectState(mEffect, State::IDLE));
288 ASSERT_NO_FATAL_FAILURE(command(mEffect, CommandId::RESET));
289 ASSERT_NO_FATAL_FAILURE(expectState(mEffect, State::IDLE));
290 ASSERT_NO_FATAL_FAILURE(close(mEffect));
291 ASSERT_NO_FATAL_FAILURE(destroy(mFactory, mEffect));
Shunkai Yaoea24c1a2022-09-28 17:39:23 +0000292}
293
294// Repeat START and STOP command.
Shunkai Yaoa4ab38c2022-10-14 01:07:47 +0000295TEST_P(AudioEffectTest, RepeatStartAndStop) {
Shunkai Yaocb0fc412022-12-15 20:34:32 +0000296 ASSERT_NO_FATAL_FAILURE(create(mFactory, mEffect, mDescriptor));
297 ASSERT_NO_FATAL_FAILURE(open(mEffect));
298 ASSERT_NO_FATAL_FAILURE(expectState(mEffect, State::IDLE));
299 ASSERT_NO_FATAL_FAILURE(command(mEffect, CommandId::START));
300 ASSERT_NO_FATAL_FAILURE(expectState(mEffect, State::PROCESSING));
301 ASSERT_NO_FATAL_FAILURE(command(mEffect, CommandId::STOP));
302 ASSERT_NO_FATAL_FAILURE(expectState(mEffect, State::IDLE));
Shunkai Yao812d5b42022-11-16 18:08:50 +0000303
Shunkai Yaocb0fc412022-12-15 20:34:32 +0000304 ASSERT_NO_FATAL_FAILURE(command(mEffect, CommandId::START));
305 ASSERT_NO_FATAL_FAILURE(expectState(mEffect, State::PROCESSING));
306 ASSERT_NO_FATAL_FAILURE(command(mEffect, CommandId::STOP));
307 ASSERT_NO_FATAL_FAILURE(expectState(mEffect, State::IDLE));
308 ASSERT_NO_FATAL_FAILURE(close(mEffect));
309 ASSERT_NO_FATAL_FAILURE(destroy(mFactory, mEffect));
Shunkai Yaoea24c1a2022-09-28 17:39:23 +0000310}
311
312// Repeat START and RESET command.
Shunkai Yaoa4ab38c2022-10-14 01:07:47 +0000313TEST_P(AudioEffectTest, RepeatStartAndReset) {
Shunkai Yaocb0fc412022-12-15 20:34:32 +0000314 ASSERT_NO_FATAL_FAILURE(create(mFactory, mEffect, mDescriptor));
315 ASSERT_NO_FATAL_FAILURE(open(mEffect));
316 ASSERT_NO_FATAL_FAILURE(expectState(mEffect, State::IDLE));
317 ASSERT_NO_FATAL_FAILURE(command(mEffect, CommandId::START));
318 ASSERT_NO_FATAL_FAILURE(expectState(mEffect, State::PROCESSING));
319 ASSERT_NO_FATAL_FAILURE(command(mEffect, CommandId::RESET));
320 ASSERT_NO_FATAL_FAILURE(expectState(mEffect, State::IDLE));
Shunkai Yao812d5b42022-11-16 18:08:50 +0000321
Shunkai Yaocb0fc412022-12-15 20:34:32 +0000322 ASSERT_NO_FATAL_FAILURE(command(mEffect, CommandId::START));
323 ASSERT_NO_FATAL_FAILURE(expectState(mEffect, State::PROCESSING));
324 ASSERT_NO_FATAL_FAILURE(command(mEffect, CommandId::RESET));
325 ASSERT_NO_FATAL_FAILURE(expectState(mEffect, State::IDLE));
326 ASSERT_NO_FATAL_FAILURE(close(mEffect));
327 ASSERT_NO_FATAL_FAILURE(destroy(mFactory, mEffect));
Shunkai Yaoea24c1a2022-09-28 17:39:23 +0000328}
329
Shunkai Yao812d5b42022-11-16 18:08:50 +0000330// Try to close an effect instance at PROCESSING state.
Shunkai Yaoa4ab38c2022-10-14 01:07:47 +0000331TEST_P(AudioEffectTest, CloseProcessingStateEffects) {
Shunkai Yaocb0fc412022-12-15 20:34:32 +0000332 ASSERT_NO_FATAL_FAILURE(create(mFactory, mEffect, mDescriptor));
333 ASSERT_NO_FATAL_FAILURE(open(mEffect));
334 ASSERT_NO_FATAL_FAILURE(expectState(mEffect, State::IDLE));
335 ASSERT_NO_FATAL_FAILURE(command(mEffect, CommandId::START));
336 ASSERT_NO_FATAL_FAILURE(expectState(mEffect, State::PROCESSING));
Shunkai Yao812d5b42022-11-16 18:08:50 +0000337
Shunkai Yaocb0fc412022-12-15 20:34:32 +0000338 ASSERT_NO_FATAL_FAILURE(close(mEffect, EX_ILLEGAL_STATE));
Shunkai Yao812d5b42022-11-16 18:08:50 +0000339
Shunkai Yaocb0fc412022-12-15 20:34:32 +0000340 ASSERT_NO_FATAL_FAILURE(command(mEffect, CommandId::STOP));
341 ASSERT_NO_FATAL_FAILURE(expectState(mEffect, State::IDLE));
342 ASSERT_NO_FATAL_FAILURE(close(mEffect));
343 ASSERT_NO_FATAL_FAILURE(destroy(mFactory, mEffect));
Shunkai Yaoea24c1a2022-09-28 17:39:23 +0000344}
345
346// Expect EX_ILLEGAL_STATE if the effect instance is not in a proper state to be destroyed.
Shunkai Yaoa4ab38c2022-10-14 01:07:47 +0000347TEST_P(AudioEffectTest, DestroyOpenEffects) {
Shunkai Yaocb0fc412022-12-15 20:34:32 +0000348 ASSERT_NO_FATAL_FAILURE(create(mFactory, mEffect, mDescriptor));
349 ASSERT_NO_FATAL_FAILURE(open(mEffect));
350 ASSERT_NO_FATAL_FAILURE(expectState(mEffect, State::IDLE));
Shunkai Yaoea24c1a2022-09-28 17:39:23 +0000351
Shunkai Yaocb0fc412022-12-15 20:34:32 +0000352 ASSERT_NO_FATAL_FAILURE(destroy(mFactory, mEffect, EX_ILLEGAL_STATE));
353
354 // cleanup
355 ASSERT_NO_FATAL_FAILURE(close(mEffect));
356 ASSERT_NO_FATAL_FAILURE(destroy(mFactory, mEffect));
Shunkai Yao812d5b42022-11-16 18:08:50 +0000357}
358
359// Expect EX_ILLEGAL_STATE if the effect instance is not in a proper state to be destroyed.
360TEST_P(AudioEffectTest, DestroyProcessingEffects) {
Shunkai Yaocb0fc412022-12-15 20:34:32 +0000361 ASSERT_NO_FATAL_FAILURE(create(mFactory, mEffect, mDescriptor));
362 ASSERT_NO_FATAL_FAILURE(open(mEffect));
363 ASSERT_NO_FATAL_FAILURE(expectState(mEffect, State::IDLE));
364 ASSERT_NO_FATAL_FAILURE(command(mEffect, CommandId::START));
365 ASSERT_NO_FATAL_FAILURE(expectState(mEffect, State::PROCESSING));
Shunkai Yao812d5b42022-11-16 18:08:50 +0000366
Shunkai Yaocb0fc412022-12-15 20:34:32 +0000367 ASSERT_NO_FATAL_FAILURE(destroy(mFactory, mEffect, EX_ILLEGAL_STATE));
368
369 // cleanup
370 ASSERT_NO_FATAL_FAILURE(command(mEffect, CommandId::STOP));
371 ASSERT_NO_FATAL_FAILURE(expectState(mEffect, State::IDLE));
372 ASSERT_NO_FATAL_FAILURE(close(mEffect));
373 ASSERT_NO_FATAL_FAILURE(destroy(mFactory, mEffect));
Shunkai Yao812d5b42022-11-16 18:08:50 +0000374}
375
376TEST_P(AudioEffectTest, NormalSequenceStates) {
Shunkai Yaocb0fc412022-12-15 20:34:32 +0000377 ASSERT_NO_FATAL_FAILURE(create(mFactory, mEffect, mDescriptor));
378 ASSERT_NO_FATAL_FAILURE(expectState(mEffect, State::INIT));
379 ASSERT_NO_FATAL_FAILURE(open(mEffect));
380 ASSERT_NO_FATAL_FAILURE(expectState(mEffect, State::IDLE));
381 ASSERT_NO_FATAL_FAILURE(command(mEffect, CommandId::START));
382 ASSERT_NO_FATAL_FAILURE(expectState(mEffect, State::PROCESSING));
383 ASSERT_NO_FATAL_FAILURE(command(mEffect, CommandId::STOP));
384 ASSERT_NO_FATAL_FAILURE(expectState(mEffect, State::IDLE));
385 ASSERT_NO_FATAL_FAILURE(command(mEffect, CommandId::START));
386 ASSERT_NO_FATAL_FAILURE(expectState(mEffect, State::PROCESSING));
387 ASSERT_NO_FATAL_FAILURE(command(mEffect, CommandId::RESET));
388 ASSERT_NO_FATAL_FAILURE(expectState(mEffect, State::IDLE));
389 ASSERT_NO_FATAL_FAILURE(close(mEffect));
390 ASSERT_NO_FATAL_FAILURE(destroy(mFactory, mEffect));
Shunkai Yaoea24c1a2022-09-28 17:39:23 +0000391}
392
393/// Parameter testing.
394// Verify parameters pass in open can be successfully get.
Shunkai Yao812d5b42022-11-16 18:08:50 +0000395TEST_P(AudioEffectTest, VerifyCommonParametersAfterOpen) {
Shunkai Yaocb0fc412022-12-15 20:34:32 +0000396 ASSERT_NO_FATAL_FAILURE(create(mFactory, mEffect, mDescriptor));
Shunkai Yao812d5b42022-11-16 18:08:50 +0000397
398 Parameter::Common common = EffectHelper::createParamCommon();
399 IEffect::OpenEffectReturn ret;
Shunkai Yaocb0fc412022-12-15 20:34:32 +0000400 ASSERT_NO_FATAL_FAILURE(open(mEffect, common, std::nullopt /* specific */, &ret, EX_NONE));
Shunkai Yao812d5b42022-11-16 18:08:50 +0000401
402 Parameter get = Parameter(), expect = Parameter();
403 expect.set<Parameter::common>(common);
404 Parameter::Id id;
405 id.set<Parameter::Id::commonTag>(Parameter::common);
Shunkai Yaocb0fc412022-12-15 20:34:32 +0000406 EXPECT_IS_OK(mEffect->getParameter(id, &get));
Shunkai Yaoeea19942023-02-16 02:31:24 +0000407 EXPECT_EQ(expect, get) << expect.toString() << "\n vs \n" << get.toString();
Shunkai Yao812d5b42022-11-16 18:08:50 +0000408
Shunkai Yaocb0fc412022-12-15 20:34:32 +0000409 ASSERT_NO_FATAL_FAILURE(close(mEffect));
410 ASSERT_NO_FATAL_FAILURE(destroy(mFactory, mEffect));
Shunkai Yaoea24c1a2022-09-28 17:39:23 +0000411}
412
413// Verify parameters pass in set can be successfully get.
Shunkai Yao812d5b42022-11-16 18:08:50 +0000414TEST_P(AudioEffectTest, SetAndGetCommonParameter) {
Shunkai Yaocb0fc412022-12-15 20:34:32 +0000415 ASSERT_NO_FATAL_FAILURE(create(mFactory, mEffect, mDescriptor));
416 ASSERT_NO_FATAL_FAILURE(open(mEffect));
Shunkai Yao812d5b42022-11-16 18:08:50 +0000417
418 Parameter::Common common = EffectHelper::createParamCommon(
419 0 /* session */, 1 /* ioHandle */, 44100 /* iSampleRate */, 44100 /* oSampleRate */);
Shunkai Yao5df4e6c2023-01-10 03:20:00 +0000420 Parameter::Id id = Parameter::Id::make<Parameter::Id::commonTag>(Parameter::common);
421 ASSERT_NO_FATAL_FAILURE(setAndGetParameter(id, Parameter::make<Parameter::common>(common)));
Shunkai Yao812d5b42022-11-16 18:08:50 +0000422
Shunkai Yaocb0fc412022-12-15 20:34:32 +0000423 ASSERT_NO_FATAL_FAILURE(close(mEffect));
424 ASSERT_NO_FATAL_FAILURE(destroy(mFactory, mEffect));
Shunkai Yaoea24c1a2022-09-28 17:39:23 +0000425}
426
Shunkai Yao812d5b42022-11-16 18:08:50 +0000427// Verify parameters set and get in PROCESSING state.
Shunkai Yaoa4ab38c2022-10-14 01:07:47 +0000428TEST_P(AudioEffectTest, SetAndGetParameterInProcessing) {
Shunkai Yaocb0fc412022-12-15 20:34:32 +0000429 ASSERT_NO_FATAL_FAILURE(create(mFactory, mEffect, mDescriptor));
430 ASSERT_NO_FATAL_FAILURE(open(mEffect));
431 ASSERT_NO_FATAL_FAILURE(command(mEffect, CommandId::START));
432 ASSERT_NO_FATAL_FAILURE(expectState(mEffect, State::PROCESSING));
Shunkai Yao812d5b42022-11-16 18:08:50 +0000433
434 Parameter::Common common = EffectHelper::createParamCommon(
435 0 /* session */, 1 /* ioHandle */, 44100 /* iSampleRate */, 44100 /* oSampleRate */);
Shunkai Yao5df4e6c2023-01-10 03:20:00 +0000436 Parameter::Id id = Parameter::Id::make<Parameter::Id::commonTag>(Parameter::common);
437 ASSERT_NO_FATAL_FAILURE(setAndGetParameter(id, Parameter::make<Parameter::common>(common)));
Shunkai Yao812d5b42022-11-16 18:08:50 +0000438
Shunkai Yaocb0fc412022-12-15 20:34:32 +0000439 ASSERT_NO_FATAL_FAILURE(command(mEffect, CommandId::STOP));
440 ASSERT_NO_FATAL_FAILURE(close(mEffect));
441 ASSERT_NO_FATAL_FAILURE(destroy(mFactory, mEffect));
Shunkai Yaoea24c1a2022-09-28 17:39:23 +0000442}
443
Shunkai Yao812d5b42022-11-16 18:08:50 +0000444// Verify parameters set and get in IDLE state.
445TEST_P(AudioEffectTest, SetAndGetParameterInIdle) {
Shunkai Yaocb0fc412022-12-15 20:34:32 +0000446 ASSERT_NO_FATAL_FAILURE(create(mFactory, mEffect, mDescriptor));
447 ASSERT_NO_FATAL_FAILURE(open(mEffect));
448 ASSERT_NO_FATAL_FAILURE(command(mEffect, CommandId::START));
449 ASSERT_NO_FATAL_FAILURE(expectState(mEffect, State::PROCESSING));
450 ASSERT_NO_FATAL_FAILURE(command(mEffect, CommandId::STOP));
451 ASSERT_NO_FATAL_FAILURE(expectState(mEffect, State::IDLE));
Shunkai Yao812d5b42022-11-16 18:08:50 +0000452
453 Parameter::Common common = EffectHelper::createParamCommon(
454 0 /* session */, 1 /* ioHandle */, 44100 /* iSampleRate */, 44100 /* oSampleRate */);
Shunkai Yao5df4e6c2023-01-10 03:20:00 +0000455 Parameter::Id id = Parameter::Id::make<Parameter::Id::commonTag>(Parameter::common);
456 ASSERT_NO_FATAL_FAILURE(setAndGetParameter(id, Parameter::make<Parameter::common>(common)));
Shunkai Yao812d5b42022-11-16 18:08:50 +0000457
Shunkai Yaocb0fc412022-12-15 20:34:32 +0000458 ASSERT_NO_FATAL_FAILURE(close(mEffect));
459 ASSERT_NO_FATAL_FAILURE(destroy(mFactory, mEffect));
Shunkai Yaoea24c1a2022-09-28 17:39:23 +0000460}
461
Shunkai Yao812d5b42022-11-16 18:08:50 +0000462// Verify Parameters kept after stop.
463TEST_P(AudioEffectTest, SetAndGetParameterAfterStop) {
Shunkai Yaocb0fc412022-12-15 20:34:32 +0000464 ASSERT_NO_FATAL_FAILURE(create(mFactory, mEffect, mDescriptor));
465 ASSERT_NO_FATAL_FAILURE(open(mEffect));
466 ASSERT_NO_FATAL_FAILURE(command(mEffect, CommandId::START));
467 ASSERT_NO_FATAL_FAILURE(expectState(mEffect, State::PROCESSING));
Shunkai Yaoea24c1a2022-09-28 17:39:23 +0000468
Shunkai Yao812d5b42022-11-16 18:08:50 +0000469 Parameter::Common common = EffectHelper::createParamCommon(
470 0 /* session */, 1 /* ioHandle */, 44100 /* iSampleRate */, 44100 /* oSampleRate */);
Shunkai Yao5df4e6c2023-01-10 03:20:00 +0000471 Parameter::Id id = Parameter::Id::make<Parameter::Id::commonTag>(Parameter::common);
472 ASSERT_NO_FATAL_FAILURE(setAndGetParameter(id, Parameter::make<Parameter::common>(common)));
Shunkai Yaoa4ab38c2022-10-14 01:07:47 +0000473
Shunkai Yaocb0fc412022-12-15 20:34:32 +0000474 ASSERT_NO_FATAL_FAILURE(command(mEffect, CommandId::STOP));
475 ASSERT_NO_FATAL_FAILURE(expectState(mEffect, State::IDLE));
Shunkai Yaocb0fc412022-12-15 20:34:32 +0000476 ASSERT_NO_FATAL_FAILURE(close(mEffect));
477 ASSERT_NO_FATAL_FAILURE(destroy(mFactory, mEffect));
Shunkai Yaoa4ab38c2022-10-14 01:07:47 +0000478}
479
Shunkai Yao812d5b42022-11-16 18:08:50 +0000480// Verify Parameters kept after reset.
481TEST_P(AudioEffectTest, SetAndGetParameterAfterReset) {
Shunkai Yaocb0fc412022-12-15 20:34:32 +0000482 ASSERT_NO_FATAL_FAILURE(create(mFactory, mEffect, mDescriptor));
483 ASSERT_NO_FATAL_FAILURE(open(mEffect));
Shunkai Yao812d5b42022-11-16 18:08:50 +0000484
Shunkai Yaocb0fc412022-12-15 20:34:32 +0000485 ASSERT_NO_FATAL_FAILURE(command(mEffect, CommandId::START));
486 ASSERT_NO_FATAL_FAILURE(expectState(mEffect, State::PROCESSING));
Shunkai Yao812d5b42022-11-16 18:08:50 +0000487
488 Parameter::Common common = EffectHelper::createParamCommon(
489 0 /* session */, 1 /* ioHandle */, 44100 /* iSampleRate */, 44100 /* oSampleRate */);
Shunkai Yao5df4e6c2023-01-10 03:20:00 +0000490 Parameter::Id id = Parameter::Id::make<Parameter::Id::commonTag>(Parameter::common);
491 ASSERT_NO_FATAL_FAILURE(setAndGetParameter(id, Parameter::make<Parameter::common>(common)));
Shunkai Yao812d5b42022-11-16 18:08:50 +0000492
Shunkai Yaocb0fc412022-12-15 20:34:32 +0000493 ASSERT_NO_FATAL_FAILURE(command(mEffect, CommandId::RESET));
494 ASSERT_NO_FATAL_FAILURE(expectState(mEffect, State::IDLE));
Shunkai Yao812d5b42022-11-16 18:08:50 +0000495
Shunkai Yao5df4e6c2023-01-10 03:20:00 +0000496 ASSERT_NO_FATAL_FAILURE(setAndGetParameter(id, Parameter::make<Parameter::common>(common)));
Shunkai Yao812d5b42022-11-16 18:08:50 +0000497
Shunkai Yao5df4e6c2023-01-10 03:20:00 +0000498 ASSERT_NO_FATAL_FAILURE(command(mEffect, CommandId::STOP));
499 ASSERT_NO_FATAL_FAILURE(expectState(mEffect, State::IDLE));
Shunkai Yaocb0fc412022-12-15 20:34:32 +0000500 ASSERT_NO_FATAL_FAILURE(close(mEffect));
501 ASSERT_NO_FATAL_FAILURE(destroy(mFactory, mEffect));
Shunkai Yao812d5b42022-11-16 18:08:50 +0000502}
Shunkai Yao5df4e6c2023-01-10 03:20:00 +0000503
504// Set and get AudioDeviceDescription in Parameter
505TEST_P(AudioEffectTest, SetAndGetParameterDeviceDescription) {
Shunkai Yao92cd7482023-09-18 17:37:45 +0000506 if (!mDescriptor.common.flags.deviceIndication) {
507 GTEST_SKIP() << "Skipping test as effect does not support deviceIndication"
508 << mDescriptor.common.flags.toString();
509 }
510
Shunkai Yao5df4e6c2023-01-10 03:20:00 +0000511 ASSERT_NO_FATAL_FAILURE(create(mFactory, mEffect, mDescriptor));
512 ASSERT_NO_FATAL_FAILURE(open(mEffect));
513
514 ASSERT_NO_FATAL_FAILURE(command(mEffect, CommandId::START));
515 ASSERT_NO_FATAL_FAILURE(expectState(mEffect, State::PROCESSING));
516
517 std::vector<AudioDeviceDescription> deviceDescs = {
518 {.type = AudioDeviceType::IN_DEFAULT,
519 .connection = AudioDeviceDescription::CONNECTION_ANALOG},
520 {.type = AudioDeviceType::IN_DEVICE,
521 .connection = AudioDeviceDescription::CONNECTION_BT_A2DP}};
522 Parameter::Id id = Parameter::Id::make<Parameter::Id::commonTag>(Parameter::deviceDescription);
523 ASSERT_NO_FATAL_FAILURE(
524 setAndGetParameter(id, Parameter::make<Parameter::deviceDescription>(deviceDescs)));
525
526 ASSERT_NO_FATAL_FAILURE(command(mEffect, CommandId::STOP));
527 ASSERT_NO_FATAL_FAILURE(expectState(mEffect, State::IDLE));
528 ASSERT_NO_FATAL_FAILURE(close(mEffect));
529 ASSERT_NO_FATAL_FAILURE(destroy(mFactory, mEffect));
530}
531
532// Set and get AudioMode in Parameter
533TEST_P(AudioEffectTest, SetAndGetParameterAudioMode) {
Shunkai Yao92cd7482023-09-18 17:37:45 +0000534 if (!mDescriptor.common.flags.audioModeIndication) {
535 GTEST_SKIP() << "Skipping test as effect does not support audioModeIndication"
536 << mDescriptor.common.flags.toString();
537 }
538
Shunkai Yao5df4e6c2023-01-10 03:20:00 +0000539 ASSERT_NO_FATAL_FAILURE(create(mFactory, mEffect, mDescriptor));
540 ASSERT_NO_FATAL_FAILURE(open(mEffect));
541
542 ASSERT_NO_FATAL_FAILURE(command(mEffect, CommandId::START));
543 ASSERT_NO_FATAL_FAILURE(expectState(mEffect, State::PROCESSING));
544
545 Parameter::Id id = Parameter::Id::make<Parameter::Id::commonTag>(Parameter::mode);
546 ASSERT_NO_FATAL_FAILURE(
547 setAndGetParameter(id, Parameter::make<Parameter::mode>(AudioMode::NORMAL)));
548 ASSERT_NO_FATAL_FAILURE(
549 setAndGetParameter(id, Parameter::make<Parameter::mode>(AudioMode::IN_COMMUNICATION)));
550
551 ASSERT_NO_FATAL_FAILURE(command(mEffect, CommandId::STOP));
552 ASSERT_NO_FATAL_FAILURE(expectState(mEffect, State::IDLE));
553 ASSERT_NO_FATAL_FAILURE(close(mEffect));
554 ASSERT_NO_FATAL_FAILURE(destroy(mFactory, mEffect));
555}
556
557// Set and get AudioSource in Parameter
558TEST_P(AudioEffectTest, SetAndGetParameterAudioSource) {
Shunkai Yao92cd7482023-09-18 17:37:45 +0000559 if (!mDescriptor.common.flags.audioSourceIndication) {
560 GTEST_SKIP() << "Skipping test as effect does not support audioSourceIndication"
561 << mDescriptor.common.flags.toString();
562 }
563
Shunkai Yao5df4e6c2023-01-10 03:20:00 +0000564 ASSERT_NO_FATAL_FAILURE(create(mFactory, mEffect, mDescriptor));
565 ASSERT_NO_FATAL_FAILURE(open(mEffect));
566
567 ASSERT_NO_FATAL_FAILURE(command(mEffect, CommandId::START));
568 ASSERT_NO_FATAL_FAILURE(expectState(mEffect, State::PROCESSING));
569
570 Parameter::Id id = Parameter::Id::make<Parameter::Id::commonTag>(Parameter::source);
571 ASSERT_NO_FATAL_FAILURE(
572 setAndGetParameter(id, Parameter::make<Parameter::source>(AudioSource::DEFAULT)));
573 ASSERT_NO_FATAL_FAILURE(setAndGetParameter(
574 id, Parameter::make<Parameter::source>(AudioSource::VOICE_RECOGNITION)));
575
576 ASSERT_NO_FATAL_FAILURE(command(mEffect, CommandId::STOP));
577 ASSERT_NO_FATAL_FAILURE(expectState(mEffect, State::IDLE));
578 ASSERT_NO_FATAL_FAILURE(close(mEffect));
579 ASSERT_NO_FATAL_FAILURE(destroy(mFactory, mEffect));
580}
581
582// Set and get VolumeStereo in Parameter
583TEST_P(AudioEffectTest, SetAndGetParameterVolume) {
Shunkai Yao92cd7482023-09-18 17:37:45 +0000584 if (mDescriptor.common.flags.volume == Flags::Volume::NONE) {
585 GTEST_SKIP() << "Skipping test as effect does not support volume"
586 << mDescriptor.common.flags.toString();
587 }
588
Shunkai Yao5df4e6c2023-01-10 03:20:00 +0000589 ASSERT_NO_FATAL_FAILURE(create(mFactory, mEffect, mDescriptor));
590 ASSERT_NO_FATAL_FAILURE(open(mEffect));
591
592 ASSERT_NO_FATAL_FAILURE(command(mEffect, CommandId::START));
593 ASSERT_NO_FATAL_FAILURE(expectState(mEffect, State::PROCESSING));
594
595 Parameter::Id id = Parameter::Id::make<Parameter::Id::commonTag>(Parameter::volumeStereo);
596 Parameter::VolumeStereo volume = {.left = 10.0, .right = 10.0};
David Li1a56fdd2023-11-14 23:31:53 +0800597 if (mDescriptor.common.flags.volume == Flags::Volume::CTRL) {
598 Parameter get;
599 EXPECT_IS_OK(mEffect->setParameter(volume));
600 EXPECT_IS_OK(mEffect->getParameter(id, &get));
601 } else {
602 ASSERT_NO_FATAL_FAILURE(
603 setAndGetParameter(id, Parameter::make<Parameter::volumeStereo>(volume)));
604 }
Shunkai Yao5df4e6c2023-01-10 03:20:00 +0000605
606 ASSERT_NO_FATAL_FAILURE(command(mEffect, CommandId::STOP));
607 ASSERT_NO_FATAL_FAILURE(expectState(mEffect, State::IDLE));
608 ASSERT_NO_FATAL_FAILURE(close(mEffect));
609 ASSERT_NO_FATAL_FAILURE(destroy(mFactory, mEffect));
610}
611
Shunkai Yao65c7c702024-01-09 20:50:53 +0000612// Verify Parameters kept after reset.
613TEST_P(AudioEffectTest, SetCommonParameterAndReopen) {
614 ASSERT_NO_FATAL_FAILURE(create(mFactory, mEffect, mDescriptor));
615
616 Parameter::Common common = EffectHelper::createParamCommon(
617 0 /* session */, 1 /* ioHandle */, 44100 /* iSampleRate */, 44100 /* oSampleRate */,
618 kInputFrameCount /* iFrameCount */, kOutputFrameCount /* oFrameCount */);
619 IEffect::OpenEffectReturn ret;
620 ASSERT_NO_FATAL_FAILURE(open(mEffect, common, std::nullopt /* specific */, &ret, EX_NONE));
621 auto statusMQ = std::make_unique<EffectHelper::StatusMQ>(ret.statusMQ);
622 ASSERT_TRUE(statusMQ->isValid());
623 auto inputMQ = std::make_unique<EffectHelper::DataMQ>(ret.inputDataMQ);
624 ASSERT_TRUE(inputMQ->isValid());
625 auto outputMQ = std::make_unique<EffectHelper::DataMQ>(ret.outputDataMQ);
626 ASSERT_TRUE(outputMQ->isValid());
627
628 Parameter::Id id = Parameter::Id::make<Parameter::Id::commonTag>(Parameter::common);
629 common.input.frameCount++;
630 ASSERT_NO_FATAL_FAILURE(setAndGetParameter(id, Parameter::make<Parameter::common>(common)));
631 ASSERT_TRUE(statusMQ->isValid());
632 expectDataMqUpdateEventFlag(statusMQ);
633 EXPECT_IS_OK(mEffect->reopen(&ret));
634 inputMQ = std::make_unique<EffectHelper::DataMQ>(ret.inputDataMQ);
635 outputMQ = std::make_unique<EffectHelper::DataMQ>(ret.outputDataMQ);
636 ASSERT_TRUE(statusMQ->isValid());
637 ASSERT_TRUE(inputMQ->isValid());
638 ASSERT_TRUE(outputMQ->isValid());
639
640 common.output.frameCount++;
641 ASSERT_NO_FATAL_FAILURE(setAndGetParameter(id, Parameter::make<Parameter::common>(common)));
642 ASSERT_TRUE(statusMQ->isValid());
643 expectDataMqUpdateEventFlag(statusMQ);
644 EXPECT_IS_OK(mEffect->reopen(&ret));
645 inputMQ = std::make_unique<EffectHelper::DataMQ>(ret.inputDataMQ);
646 outputMQ = std::make_unique<EffectHelper::DataMQ>(ret.outputDataMQ);
647 ASSERT_TRUE(statusMQ->isValid());
648 ASSERT_TRUE(inputMQ->isValid());
649 ASSERT_TRUE(outputMQ->isValid());
650
651 ASSERT_NO_FATAL_FAILURE(close(mEffect));
652 ASSERT_NO_FATAL_FAILURE(destroy(mFactory, mEffect));
653}
654
Shunkai Yao812d5b42022-11-16 18:08:50 +0000655/// Data processing test
656// Send data to effects and expect it to be consumed by checking statusMQ.
Jaideep Sharmacba42862023-06-23 10:27:39 +0530657// Effects exposing bypass flags or operating in offload mode will be skipped.
658TEST_P(AudioEffectDataPathTest, ConsumeDataInProcessingState) {
Shunkai Yaocb0fc412022-12-15 20:34:32 +0000659 ASSERT_NO_FATAL_FAILURE(create(mFactory, mEffect, mDescriptor));
Shunkai Yao812d5b42022-11-16 18:08:50 +0000660
661 Parameter::Common common = EffectHelper::createParamCommon(
662 0 /* session */, 1 /* ioHandle */, 44100 /* iSampleRate */, 44100 /* oSampleRate */,
663 kInputFrameCount /* iFrameCount */, kOutputFrameCount /* oFrameCount */);
664 IEffect::OpenEffectReturn ret;
Shunkai Yaocb0fc412022-12-15 20:34:32 +0000665 ASSERT_NO_FATAL_FAILURE(open(mEffect, common, std::nullopt /* specific */, &ret, EX_NONE));
Shunkai Yao812d5b42022-11-16 18:08:50 +0000666 auto statusMQ = std::make_unique<EffectHelper::StatusMQ>(ret.statusMQ);
Shunkai Yaocb0fc412022-12-15 20:34:32 +0000667 ASSERT_TRUE(statusMQ->isValid());
Shunkai Yao812d5b42022-11-16 18:08:50 +0000668 auto inputMQ = std::make_unique<EffectHelper::DataMQ>(ret.inputDataMQ);
Shunkai Yaocb0fc412022-12-15 20:34:32 +0000669 ASSERT_TRUE(inputMQ->isValid());
Shunkai Yao812d5b42022-11-16 18:08:50 +0000670 auto outputMQ = std::make_unique<EffectHelper::DataMQ>(ret.outputDataMQ);
Shunkai Yaocb0fc412022-12-15 20:34:32 +0000671 ASSERT_TRUE(outputMQ->isValid());
Shunkai Yao812d5b42022-11-16 18:08:50 +0000672
Shunkai Yaocb0fc412022-12-15 20:34:32 +0000673 ASSERT_NO_FATAL_FAILURE(command(mEffect, CommandId::START));
674 ASSERT_NO_FATAL_FAILURE(expectState(mEffect, State::PROCESSING));
Shunkai Yao812d5b42022-11-16 18:08:50 +0000675
676 std::vector<float> buffer;
Shunkai Yaob49631f2023-02-03 01:44:32 +0000677 EXPECT_NO_FATAL_FAILURE(EffectHelper::allocateInputData(common, inputMQ, buffer));
Shunkai Yao41888a22023-04-10 17:13:30 +0000678 EXPECT_NO_FATAL_FAILURE(EffectHelper::writeToFmq(statusMQ, inputMQ, buffer));
Shunkai Yaob49631f2023-02-03 01:44:32 +0000679 EXPECT_NO_FATAL_FAILURE(
680 EffectHelper::readFromFmq(statusMQ, 1, outputMQ, buffer.size(), buffer));
Shunkai Yao812d5b42022-11-16 18:08:50 +0000681
Shunkai Yaocb0fc412022-12-15 20:34:32 +0000682 ASSERT_NO_FATAL_FAILURE(command(mEffect, CommandId::STOP));
683 ASSERT_NO_FATAL_FAILURE(expectState(mEffect, State::IDLE));
Shunkai Yaob49631f2023-02-03 01:44:32 +0000684 EXPECT_NO_FATAL_FAILURE(EffectHelper::readFromFmq(statusMQ, 0, outputMQ, 0, buffer));
Shunkai Yao812d5b42022-11-16 18:08:50 +0000685
Shunkai Yaocb0fc412022-12-15 20:34:32 +0000686 ASSERT_NO_FATAL_FAILURE(close(mEffect));
687 ASSERT_NO_FATAL_FAILURE(destroy(mFactory, mEffect));
Shunkai Yao812d5b42022-11-16 18:08:50 +0000688}
689
690// Send data to effects and expect it to be consumed after effect restart.
Jaideep Sharmacba42862023-06-23 10:27:39 +0530691// Effects exposing bypass flags or operating in offload mode will be skipped.
692TEST_P(AudioEffectDataPathTest, ConsumeDataAfterRestart) {
Shunkai Yaocb0fc412022-12-15 20:34:32 +0000693 ASSERT_NO_FATAL_FAILURE(create(mFactory, mEffect, mDescriptor));
Shunkai Yao812d5b42022-11-16 18:08:50 +0000694
695 Parameter::Common common = EffectHelper::createParamCommon(
696 0 /* session */, 1 /* ioHandle */, 44100 /* iSampleRate */, 44100 /* oSampleRate */,
697 kInputFrameCount /* iFrameCount */, kOutputFrameCount /* oFrameCount */);
698 IEffect::OpenEffectReturn ret;
Shunkai Yaocb0fc412022-12-15 20:34:32 +0000699 ASSERT_NO_FATAL_FAILURE(open(mEffect, common, std::nullopt /* specific */, &ret, EX_NONE));
Shunkai Yao812d5b42022-11-16 18:08:50 +0000700 auto statusMQ = std::make_unique<EffectHelper::StatusMQ>(ret.statusMQ);
Shunkai Yaocb0fc412022-12-15 20:34:32 +0000701 ASSERT_TRUE(statusMQ->isValid());
Shunkai Yao812d5b42022-11-16 18:08:50 +0000702 auto inputMQ = std::make_unique<EffectHelper::DataMQ>(ret.inputDataMQ);
Shunkai Yaocb0fc412022-12-15 20:34:32 +0000703 ASSERT_TRUE(inputMQ->isValid());
Shunkai Yao812d5b42022-11-16 18:08:50 +0000704 auto outputMQ = std::make_unique<EffectHelper::DataMQ>(ret.outputDataMQ);
Shunkai Yaocb0fc412022-12-15 20:34:32 +0000705 ASSERT_TRUE(outputMQ->isValid());
Shunkai Yao812d5b42022-11-16 18:08:50 +0000706
Shunkai Yao812d5b42022-11-16 18:08:50 +0000707 std::vector<float> buffer;
Shunkai Yaob49631f2023-02-03 01:44:32 +0000708 ASSERT_NO_FATAL_FAILURE(command(mEffect, CommandId::START));
709 ASSERT_NO_FATAL_FAILURE(expectState(mEffect, State::PROCESSING));
710 ASSERT_NO_FATAL_FAILURE(command(mEffect, CommandId::STOP));
711 ASSERT_NO_FATAL_FAILURE(expectState(mEffect, State::IDLE));
712 EXPECT_NO_FATAL_FAILURE(
713 EffectHelper::readFromFmq(statusMQ, 0, outputMQ, buffer.size(), buffer));
714 ASSERT_NO_FATAL_FAILURE(command(mEffect, CommandId::START));
715 ASSERT_NO_FATAL_FAILURE(expectState(mEffect, State::PROCESSING));
716
717 EXPECT_NO_FATAL_FAILURE(EffectHelper::allocateInputData(common, inputMQ, buffer));
Shunkai Yao41888a22023-04-10 17:13:30 +0000718 EXPECT_NO_FATAL_FAILURE(EffectHelper::writeToFmq(statusMQ, inputMQ, buffer));
Shunkai Yaob49631f2023-02-03 01:44:32 +0000719 EXPECT_NO_FATAL_FAILURE(
720 EffectHelper::readFromFmq(statusMQ, 1, outputMQ, buffer.size(), buffer));
Shunkai Yao812d5b42022-11-16 18:08:50 +0000721
Shunkai Yaocb0fc412022-12-15 20:34:32 +0000722 ASSERT_NO_FATAL_FAILURE(command(mEffect, CommandId::STOP));
723 ASSERT_NO_FATAL_FAILURE(expectState(mEffect, State::IDLE));
Shunkai Yaob49631f2023-02-03 01:44:32 +0000724 EXPECT_NO_FATAL_FAILURE(EffectHelper::readFromFmq(statusMQ, 0, outputMQ, 0, buffer));
Shunkai Yao812d5b42022-11-16 18:08:50 +0000725
Shunkai Yaocb0fc412022-12-15 20:34:32 +0000726 ASSERT_NO_FATAL_FAILURE(close(mEffect));
727 ASSERT_NO_FATAL_FAILURE(destroy(mFactory, mEffect));
Shunkai Yao812d5b42022-11-16 18:08:50 +0000728}
729
Shunkai Yao65c7c702024-01-09 20:50:53 +0000730// Send data to effects and expect it to be consumed after effect reopen (IO AudioConfig change).
731// Effects exposing bypass flags or operating in offload mode will be skipped.
732TEST_P(AudioEffectDataPathTest, ConsumeDataAfterReopen) {
733 ASSERT_NO_FATAL_FAILURE(create(mFactory, mEffect, mDescriptor));
734
735 Parameter::Common common = EffectHelper::createParamCommon(
736 0 /* session */, 1 /* ioHandle */, 44100 /* iSampleRate */, 44100 /* oSampleRate */,
737 kInputFrameCount /* iFrameCount */, kOutputFrameCount /* oFrameCount */);
738 IEffect::OpenEffectReturn ret;
739 ASSERT_NO_FATAL_FAILURE(open(mEffect, common, std::nullopt /* specific */, &ret, EX_NONE));
740 auto statusMQ = std::make_unique<EffectHelper::StatusMQ>(ret.statusMQ);
741 ASSERT_TRUE(statusMQ->isValid());
742 auto inputMQ = std::make_unique<EffectHelper::DataMQ>(ret.inputDataMQ);
743 ASSERT_TRUE(inputMQ->isValid());
744 auto outputMQ = std::make_unique<EffectHelper::DataMQ>(ret.outputDataMQ);
745 ASSERT_TRUE(outputMQ->isValid());
746
747 std::vector<float> buffer;
748 ASSERT_NO_FATAL_FAILURE(command(mEffect, CommandId::START));
749 ASSERT_NO_FATAL_FAILURE(expectState(mEffect, State::PROCESSING));
750 EXPECT_NO_FATAL_FAILURE(EffectHelper::allocateInputData(common, inputMQ, buffer));
751 EXPECT_NO_FATAL_FAILURE(EffectHelper::writeToFmq(statusMQ, inputMQ, buffer));
752 EXPECT_NO_FATAL_FAILURE(
753 EffectHelper::readFromFmq(statusMQ, 1, outputMQ, buffer.size(), buffer));
754
755 // set a new common parameter with different IO frameCount, reopen
756 Parameter::Id id = Parameter::Id::make<Parameter::Id::commonTag>(Parameter::common);
757 common.input.frameCount += 4;
758 common.output.frameCount += 4;
759 ASSERT_NO_FATAL_FAILURE(setAndGetParameter(id, Parameter::make<Parameter::common>(common)));
760 ASSERT_TRUE(statusMQ->isValid());
761 expectDataMqUpdateEventFlag(statusMQ);
762 EXPECT_IS_OK(mEffect->reopen(&ret));
763 inputMQ = std::make_unique<EffectHelper::DataMQ>(ret.inputDataMQ);
764 outputMQ = std::make_unique<EffectHelper::DataMQ>(ret.outputDataMQ);
765 ASSERT_TRUE(statusMQ->isValid());
766 ASSERT_TRUE(inputMQ->isValid());
767 ASSERT_TRUE(outputMQ->isValid());
768
769 // verify data consume again
770 EXPECT_NO_FATAL_FAILURE(EffectHelper::allocateInputData(common, inputMQ, buffer));
771 EXPECT_NO_FATAL_FAILURE(EffectHelper::writeToFmq(statusMQ, inputMQ, buffer));
772 EXPECT_NO_FATAL_FAILURE(
773 EffectHelper::readFromFmq(statusMQ, 1, outputMQ, buffer.size(), buffer));
774
775 ASSERT_NO_FATAL_FAILURE(command(mEffect, CommandId::STOP));
776 ASSERT_NO_FATAL_FAILURE(expectState(mEffect, State::IDLE));
777 EXPECT_NO_FATAL_FAILURE(EffectHelper::readFromFmq(statusMQ, 0, outputMQ, 0, buffer));
778
779 ASSERT_NO_FATAL_FAILURE(close(mEffect));
780 ASSERT_NO_FATAL_FAILURE(destroy(mFactory, mEffect));
781}
782
Shunkai Yao812d5b42022-11-16 18:08:50 +0000783// Send data to IDLE effects and expect it to be consumed after effect start.
Jaideep Sharmacba42862023-06-23 10:27:39 +0530784// Effects exposing bypass flags or operating in offload mode will be skipped.
785TEST_P(AudioEffectDataPathTest, SendDataAtIdleAndConsumeDataInProcessing) {
Shunkai Yaocb0fc412022-12-15 20:34:32 +0000786 ASSERT_NO_FATAL_FAILURE(create(mFactory, mEffect, mDescriptor));
Shunkai Yao812d5b42022-11-16 18:08:50 +0000787
788 Parameter::Common common = EffectHelper::createParamCommon(
789 0 /* session */, 1 /* ioHandle */, 44100 /* iSampleRate */, 44100 /* oSampleRate */,
790 kInputFrameCount /* iFrameCount */, kOutputFrameCount /* oFrameCount */);
791 IEffect::OpenEffectReturn ret;
Shunkai Yaocb0fc412022-12-15 20:34:32 +0000792 ASSERT_NO_FATAL_FAILURE(open(mEffect, common, std::nullopt /* specific */, &ret, EX_NONE));
Shunkai Yao812d5b42022-11-16 18:08:50 +0000793 auto statusMQ = std::make_unique<EffectHelper::StatusMQ>(ret.statusMQ);
Shunkai Yaocb0fc412022-12-15 20:34:32 +0000794 ASSERT_TRUE(statusMQ->isValid());
Shunkai Yao812d5b42022-11-16 18:08:50 +0000795 auto inputMQ = std::make_unique<EffectHelper::DataMQ>(ret.inputDataMQ);
Shunkai Yaocb0fc412022-12-15 20:34:32 +0000796 ASSERT_TRUE(inputMQ->isValid());
Shunkai Yao812d5b42022-11-16 18:08:50 +0000797 auto outputMQ = std::make_unique<EffectHelper::DataMQ>(ret.outputDataMQ);
Shunkai Yaocb0fc412022-12-15 20:34:32 +0000798 ASSERT_TRUE(outputMQ->isValid());
Shunkai Yao812d5b42022-11-16 18:08:50 +0000799
800 std::vector<float> buffer;
Shunkai Yaob49631f2023-02-03 01:44:32 +0000801 EXPECT_NO_FATAL_FAILURE(EffectHelper::allocateInputData(common, inputMQ, buffer));
Shunkai Yao41888a22023-04-10 17:13:30 +0000802 EXPECT_NO_FATAL_FAILURE(EffectHelper::writeToFmq(statusMQ, inputMQ, buffer));
Shunkai Yao812d5b42022-11-16 18:08:50 +0000803
Shunkai Yaocb0fc412022-12-15 20:34:32 +0000804 ASSERT_NO_FATAL_FAILURE(command(mEffect, CommandId::START));
805 ASSERT_NO_FATAL_FAILURE(expectState(mEffect, State::PROCESSING));
Shunkai Yao812d5b42022-11-16 18:08:50 +0000806
Shunkai Yaob49631f2023-02-03 01:44:32 +0000807 EXPECT_NO_FATAL_FAILURE(
808 EffectHelper::readFromFmq(statusMQ, 1, outputMQ, buffer.size(), buffer));
Shunkai Yao812d5b42022-11-16 18:08:50 +0000809
Shunkai Yaocb0fc412022-12-15 20:34:32 +0000810 ASSERT_NO_FATAL_FAILURE(command(mEffect, CommandId::STOP));
811 ASSERT_NO_FATAL_FAILURE(expectState(mEffect, State::IDLE));
Shunkai Yao812d5b42022-11-16 18:08:50 +0000812
Shunkai Yaocb0fc412022-12-15 20:34:32 +0000813 ASSERT_NO_FATAL_FAILURE(close(mEffect));
814 ASSERT_NO_FATAL_FAILURE(destroy(mFactory, mEffect));
Shunkai Yao812d5b42022-11-16 18:08:50 +0000815}
816
817// Send data multiple times.
Jaideep Sharmacba42862023-06-23 10:27:39 +0530818// Effects exposing bypass flags or operating in offload mode will be skipped.
819TEST_P(AudioEffectDataPathTest, ProcessDataMultipleTimes) {
Shunkai Yaocb0fc412022-12-15 20:34:32 +0000820 ASSERT_NO_FATAL_FAILURE(create(mFactory, mEffect, mDescriptor));
Shunkai Yao812d5b42022-11-16 18:08:50 +0000821
822 Parameter::Common common = EffectHelper::createParamCommon(
823 0 /* session */, 1 /* ioHandle */, 44100 /* iSampleRate */, 44100 /* oSampleRate */,
824 kInputFrameCount /* iFrameCount */, kOutputFrameCount /* oFrameCount */);
825 IEffect::OpenEffectReturn ret;
Shunkai Yaocb0fc412022-12-15 20:34:32 +0000826 ASSERT_NO_FATAL_FAILURE(open(mEffect, common, std::nullopt /* specific */, &ret, EX_NONE));
Shunkai Yao812d5b42022-11-16 18:08:50 +0000827 auto statusMQ = std::make_unique<EffectHelper::StatusMQ>(ret.statusMQ);
Shunkai Yaocb0fc412022-12-15 20:34:32 +0000828 ASSERT_TRUE(statusMQ->isValid());
Shunkai Yao812d5b42022-11-16 18:08:50 +0000829 auto inputMQ = std::make_unique<EffectHelper::DataMQ>(ret.inputDataMQ);
Shunkai Yaocb0fc412022-12-15 20:34:32 +0000830 ASSERT_TRUE(inputMQ->isValid());
Shunkai Yao812d5b42022-11-16 18:08:50 +0000831 auto outputMQ = std::make_unique<EffectHelper::DataMQ>(ret.outputDataMQ);
Shunkai Yaocb0fc412022-12-15 20:34:32 +0000832 ASSERT_TRUE(outputMQ->isValid());
Shunkai Yao812d5b42022-11-16 18:08:50 +0000833
834 std::vector<float> buffer;
Shunkai Yaob49631f2023-02-03 01:44:32 +0000835 EXPECT_NO_FATAL_FAILURE(EffectHelper::allocateInputData(common, inputMQ, buffer));
Shunkai Yao41888a22023-04-10 17:13:30 +0000836 EXPECT_NO_FATAL_FAILURE(EffectHelper::writeToFmq(statusMQ, inputMQ, buffer));
Shunkai Yaob49631f2023-02-03 01:44:32 +0000837 EXPECT_NO_FATAL_FAILURE(EffectHelper::readFromFmq(statusMQ, 0, outputMQ, 0, buffer));
Shunkai Yao812d5b42022-11-16 18:08:50 +0000838
Shunkai Yaocb0fc412022-12-15 20:34:32 +0000839 ASSERT_NO_FATAL_FAILURE(command(mEffect, CommandId::START));
840 ASSERT_NO_FATAL_FAILURE(expectState(mEffect, State::PROCESSING));
Shunkai Yao812d5b42022-11-16 18:08:50 +0000841
Shunkai Yaob49631f2023-02-03 01:44:32 +0000842 EXPECT_NO_FATAL_FAILURE(
843 EffectHelper::readFromFmq(statusMQ, 1, outputMQ, buffer.size(), buffer));
Shunkai Yao812d5b42022-11-16 18:08:50 +0000844
Shunkai Yao41888a22023-04-10 17:13:30 +0000845 EXPECT_NO_FATAL_FAILURE(EffectHelper::writeToFmq(statusMQ, inputMQ, buffer));
Shunkai Yaob49631f2023-02-03 01:44:32 +0000846 EXPECT_NO_FATAL_FAILURE(
847 EffectHelper::readFromFmq(statusMQ, 1, outputMQ, buffer.size(), buffer));
Shunkai Yao812d5b42022-11-16 18:08:50 +0000848
Shunkai Yaocb0fc412022-12-15 20:34:32 +0000849 ASSERT_NO_FATAL_FAILURE(command(mEffect, CommandId::STOP));
850 ASSERT_NO_FATAL_FAILURE(expectState(mEffect, State::IDLE));
Shunkai Yaob49631f2023-02-03 01:44:32 +0000851 EXPECT_NO_FATAL_FAILURE(EffectHelper::readFromFmq(statusMQ, 0, outputMQ, 0, buffer));
Shunkai Yao812d5b42022-11-16 18:08:50 +0000852
Shunkai Yaocb0fc412022-12-15 20:34:32 +0000853 ASSERT_NO_FATAL_FAILURE(close(mEffect));
854 ASSERT_NO_FATAL_FAILURE(destroy(mFactory, mEffect));
Shunkai Yao812d5b42022-11-16 18:08:50 +0000855}
856
Shunkai Yaob49631f2023-02-03 01:44:32 +0000857// Send data to processing state effects, stop, and restart.
Jaideep Sharmacba42862023-06-23 10:27:39 +0530858// Effects exposing bypass flags or operating in offload mode will be skipped.
859TEST_P(AudioEffectDataPathTest, ConsumeDataAndRestart) {
Shunkai Yaocb0fc412022-12-15 20:34:32 +0000860 ASSERT_NO_FATAL_FAILURE(create(mFactory, mEffect, mDescriptor));
Shunkai Yao812d5b42022-11-16 18:08:50 +0000861
862 Parameter::Common common = EffectHelper::createParamCommon(
863 0 /* session */, 1 /* ioHandle */, 44100 /* iSampleRate */, 44100 /* oSampleRate */,
864 kInputFrameCount /* iFrameCount */, kOutputFrameCount /* oFrameCount */);
865 IEffect::OpenEffectReturn ret;
Shunkai Yaocb0fc412022-12-15 20:34:32 +0000866 ASSERT_NO_FATAL_FAILURE(open(mEffect, common, std::nullopt /* specific */, &ret, EX_NONE));
Shunkai Yao812d5b42022-11-16 18:08:50 +0000867 auto statusMQ = std::make_unique<EffectHelper::StatusMQ>(ret.statusMQ);
Shunkai Yaocb0fc412022-12-15 20:34:32 +0000868 ASSERT_TRUE(statusMQ->isValid());
Shunkai Yao812d5b42022-11-16 18:08:50 +0000869 auto inputMQ = std::make_unique<EffectHelper::DataMQ>(ret.inputDataMQ);
Shunkai Yaocb0fc412022-12-15 20:34:32 +0000870 ASSERT_TRUE(inputMQ->isValid());
Shunkai Yao812d5b42022-11-16 18:08:50 +0000871 auto outputMQ = std::make_unique<EffectHelper::DataMQ>(ret.outputDataMQ);
Shunkai Yaocb0fc412022-12-15 20:34:32 +0000872 ASSERT_TRUE(outputMQ->isValid());
Shunkai Yao812d5b42022-11-16 18:08:50 +0000873
Shunkai Yaocb0fc412022-12-15 20:34:32 +0000874 ASSERT_NO_FATAL_FAILURE(command(mEffect, CommandId::START));
875 ASSERT_NO_FATAL_FAILURE(expectState(mEffect, State::PROCESSING));
Shunkai Yaob49631f2023-02-03 01:44:32 +0000876 std::vector<float> buffer;
877 EXPECT_NO_FATAL_FAILURE(EffectHelper::allocateInputData(common, inputMQ, buffer));
Shunkai Yao41888a22023-04-10 17:13:30 +0000878 EXPECT_NO_FATAL_FAILURE(EffectHelper::writeToFmq(statusMQ, inputMQ, buffer));
Shunkai Yaob49631f2023-02-03 01:44:32 +0000879 EXPECT_NO_FATAL_FAILURE(
880 EffectHelper::readFromFmq(statusMQ, 1, outputMQ, buffer.size(), buffer));
881
Shunkai Yaocb0fc412022-12-15 20:34:32 +0000882 ASSERT_NO_FATAL_FAILURE(command(mEffect, CommandId::STOP));
883 ASSERT_NO_FATAL_FAILURE(expectState(mEffect, State::IDLE));
Shunkai Yao41888a22023-04-10 17:13:30 +0000884 EXPECT_NO_FATAL_FAILURE(EffectHelper::writeToFmq(statusMQ, inputMQ, buffer));
Shunkai Yaob49631f2023-02-03 01:44:32 +0000885 EXPECT_NO_FATAL_FAILURE(EffectHelper::readFromFmq(statusMQ, 0, outputMQ, 0, buffer));
Shunkai Yao812d5b42022-11-16 18:08:50 +0000886
Shunkai Yaocb0fc412022-12-15 20:34:32 +0000887 ASSERT_NO_FATAL_FAILURE(command(mEffect, CommandId::START));
888 ASSERT_NO_FATAL_FAILURE(expectState(mEffect, State::PROCESSING));
Shunkai Yaob49631f2023-02-03 01:44:32 +0000889 EXPECT_NO_FATAL_FAILURE(
890 EffectHelper::readFromFmq(statusMQ, 1, outputMQ, buffer.size(), buffer));
Shunkai Yao812d5b42022-11-16 18:08:50 +0000891
Shunkai Yaocb0fc412022-12-15 20:34:32 +0000892 ASSERT_NO_FATAL_FAILURE(command(mEffect, CommandId::STOP));
893 ASSERT_NO_FATAL_FAILURE(expectState(mEffect, State::IDLE));
Shunkai Yao812d5b42022-11-16 18:08:50 +0000894
Shunkai Yaocb0fc412022-12-15 20:34:32 +0000895 ASSERT_NO_FATAL_FAILURE(close(mEffect));
896 ASSERT_NO_FATAL_FAILURE(destroy(mFactory, mEffect));
Shunkai Yao812d5b42022-11-16 18:08:50 +0000897}
898
899// Send data to closed effects and expect it not be consumed.
Jaideep Sharmacba42862023-06-23 10:27:39 +0530900// Effects exposing bypass flags or operating in offload mode will be skipped.
901TEST_P(AudioEffectDataPathTest, NotConsumeDataByClosedEffect) {
Shunkai Yaocb0fc412022-12-15 20:34:32 +0000902 ASSERT_NO_FATAL_FAILURE(create(mFactory, mEffect, mDescriptor));
Shunkai Yao812d5b42022-11-16 18:08:50 +0000903
904 Parameter::Common common = EffectHelper::createParamCommon(
905 0 /* session */, 1 /* ioHandle */, 44100 /* iSampleRate */, 44100 /* oSampleRate */,
906 kInputFrameCount /* iFrameCount */, kOutputFrameCount /* oFrameCount */);
907 IEffect::OpenEffectReturn ret;
Shunkai Yaocb0fc412022-12-15 20:34:32 +0000908 ASSERT_NO_FATAL_FAILURE(open(mEffect, common, std::nullopt /* specific */, &ret, EX_NONE));
909 ASSERT_NO_FATAL_FAILURE(close(mEffect));
Shunkai Yao812d5b42022-11-16 18:08:50 +0000910
911 auto statusMQ = std::make_unique<EffectHelper::StatusMQ>(ret.statusMQ);
Shunkai Yaocb0fc412022-12-15 20:34:32 +0000912 ASSERT_TRUE(statusMQ->isValid());
Shunkai Yao812d5b42022-11-16 18:08:50 +0000913 auto inputMQ = std::make_unique<EffectHelper::DataMQ>(ret.inputDataMQ);
Shunkai Yaocb0fc412022-12-15 20:34:32 +0000914 ASSERT_TRUE(inputMQ->isValid());
Shunkai Yao812d5b42022-11-16 18:08:50 +0000915 auto outputMQ = std::make_unique<EffectHelper::DataMQ>(ret.outputDataMQ);
Shunkai Yaocb0fc412022-12-15 20:34:32 +0000916 ASSERT_TRUE(outputMQ->isValid());
Shunkai Yao812d5b42022-11-16 18:08:50 +0000917
918 std::vector<float> buffer;
Shunkai Yaob49631f2023-02-03 01:44:32 +0000919 EXPECT_NO_FATAL_FAILURE(EffectHelper::allocateInputData(common, inputMQ, buffer));
Shunkai Yao41888a22023-04-10 17:13:30 +0000920 EXPECT_NO_FATAL_FAILURE(EffectHelper::writeToFmq(statusMQ, inputMQ, buffer));
Shunkai Yaob49631f2023-02-03 01:44:32 +0000921 EXPECT_NO_FATAL_FAILURE(EffectHelper::readFromFmq(statusMQ, 0, outputMQ, 0, buffer));
Shunkai Yao812d5b42022-11-16 18:08:50 +0000922
Shunkai Yaocb0fc412022-12-15 20:34:32 +0000923 ASSERT_NO_FATAL_FAILURE(destroy(mFactory, mEffect));
Shunkai Yao812d5b42022-11-16 18:08:50 +0000924}
925
926// Send data to multiple effects.
Jaideep Sharmacba42862023-06-23 10:27:39 +0530927// Effects exposing bypass flags or operating in offload mode will be skipped.
928TEST_P(AudioEffectDataPathTest, ConsumeDataMultipleEffects) {
Shunkai Yao812d5b42022-11-16 18:08:50 +0000929 std::shared_ptr<IEffect> effect1, effect2;
Shunkai Yaocb0fc412022-12-15 20:34:32 +0000930 ASSERT_NO_FATAL_FAILURE(create(mFactory, effect1, mDescriptor));
931 ASSERT_NO_FATAL_FAILURE(create(mFactory, effect2, mDescriptor));
Shunkai Yao812d5b42022-11-16 18:08:50 +0000932
933 Parameter::Common common1 = EffectHelper::createParamCommon(
934 0 /* session */, 1 /* ioHandle */, 44100 /* iSampleRate */, 44100 /* oSampleRate */,
935 kInputFrameCount /* iFrameCount */, kOutputFrameCount /* oFrameCount */);
936 Parameter::Common common2 = EffectHelper::createParamCommon(
937 1 /* session */, 1 /* ioHandle */, 48000 /* iSampleRate */, 48000 /* oSampleRate */,
938 2 * kInputFrameCount /* iFrameCount */, 2 * kOutputFrameCount /* oFrameCount */);
939 IEffect::OpenEffectReturn ret1, ret2;
940 ASSERT_NO_FATAL_FAILURE(open(effect1, common1, std::nullopt /* specific */, &ret1, EX_NONE));
941 ASSERT_NO_FATAL_FAILURE(open(effect2, common2, std::nullopt /* specific */, &ret2, EX_NONE));
942 ASSERT_NO_FATAL_FAILURE(command(effect1, CommandId::START));
943 ASSERT_NO_FATAL_FAILURE(expectState(effect1, State::PROCESSING));
944 ASSERT_NO_FATAL_FAILURE(command(effect2, CommandId::START));
945 ASSERT_NO_FATAL_FAILURE(expectState(effect2, State::PROCESSING));
946
947 auto statusMQ1 = std::make_unique<EffectHelper::StatusMQ>(ret1.statusMQ);
Shunkai Yaocb0fc412022-12-15 20:34:32 +0000948 ASSERT_TRUE(statusMQ1->isValid());
Shunkai Yao812d5b42022-11-16 18:08:50 +0000949 auto inputMQ1 = std::make_unique<EffectHelper::DataMQ>(ret1.inputDataMQ);
Shunkai Yaocb0fc412022-12-15 20:34:32 +0000950 ASSERT_TRUE(inputMQ1->isValid());
Shunkai Yao812d5b42022-11-16 18:08:50 +0000951 auto outputMQ1 = std::make_unique<EffectHelper::DataMQ>(ret1.outputDataMQ);
Shunkai Yaocb0fc412022-12-15 20:34:32 +0000952 ASSERT_TRUE(outputMQ1->isValid());
Shunkai Yao812d5b42022-11-16 18:08:50 +0000953
954 std::vector<float> buffer1, buffer2;
Shunkai Yaob49631f2023-02-03 01:44:32 +0000955 EXPECT_NO_FATAL_FAILURE(EffectHelper::allocateInputData(common1, inputMQ1, buffer1));
Shunkai Yao41888a22023-04-10 17:13:30 +0000956 EXPECT_NO_FATAL_FAILURE(EffectHelper::writeToFmq(statusMQ1, inputMQ1, buffer1));
Shunkai Yaob49631f2023-02-03 01:44:32 +0000957 EXPECT_NO_FATAL_FAILURE(
958 EffectHelper::readFromFmq(statusMQ1, 1, outputMQ1, buffer1.size(), buffer1));
Shunkai Yao812d5b42022-11-16 18:08:50 +0000959
960 auto statusMQ2 = std::make_unique<EffectHelper::StatusMQ>(ret2.statusMQ);
Shunkai Yaocb0fc412022-12-15 20:34:32 +0000961 ASSERT_TRUE(statusMQ2->isValid());
Shunkai Yao812d5b42022-11-16 18:08:50 +0000962 auto inputMQ2 = std::make_unique<EffectHelper::DataMQ>(ret2.inputDataMQ);
Shunkai Yaocb0fc412022-12-15 20:34:32 +0000963 ASSERT_TRUE(inputMQ2->isValid());
Shunkai Yao812d5b42022-11-16 18:08:50 +0000964 auto outputMQ2 = std::make_unique<EffectHelper::DataMQ>(ret2.outputDataMQ);
Shunkai Yaocb0fc412022-12-15 20:34:32 +0000965 ASSERT_TRUE(outputMQ2->isValid());
Shunkai Yaob49631f2023-02-03 01:44:32 +0000966 EXPECT_NO_FATAL_FAILURE(EffectHelper::allocateInputData(common2, inputMQ2, buffer2));
Shunkai Yao41888a22023-04-10 17:13:30 +0000967 EXPECT_NO_FATAL_FAILURE(EffectHelper::writeToFmq(statusMQ2, inputMQ2, buffer2));
Shunkai Yaob49631f2023-02-03 01:44:32 +0000968 EXPECT_NO_FATAL_FAILURE(
969 EffectHelper::readFromFmq(statusMQ2, 1, outputMQ2, buffer2.size(), buffer2));
Shunkai Yao812d5b42022-11-16 18:08:50 +0000970
971 ASSERT_NO_FATAL_FAILURE(command(effect1, CommandId::STOP));
972 ASSERT_NO_FATAL_FAILURE(expectState(effect1, State::IDLE));
973 ASSERT_NO_FATAL_FAILURE(close(effect1));
974 ASSERT_NO_FATAL_FAILURE(destroy(mFactory, effect1));
975
976 ASSERT_NO_FATAL_FAILURE(command(effect2, CommandId::STOP));
977 ASSERT_NO_FATAL_FAILURE(expectState(effect2, State::IDLE));
978 ASSERT_NO_FATAL_FAILURE(close(effect2));
979 ASSERT_NO_FATAL_FAILURE(destroy(mFactory, effect2));
980}
981
982INSTANTIATE_TEST_SUITE_P(
983 SingleEffectInstanceTest, AudioEffectTest,
984 ::testing::Combine(testing::ValuesIn(
985 EffectFactoryHelper::getAllEffectDescriptors(IFactory::descriptor))),
986 [](const testing::TestParamInfo<AudioEffectTest::ParamType>& info) {
Shunkai Yaocb0fc412022-12-15 20:34:32 +0000987 auto descriptor = std::get<PARAM_INSTANCE_NAME>(info.param).second;
Jaideep Sharmae4c7a962023-06-14 19:14:44 +0530988 std::string name = getPrefix(descriptor);
Shunkai Yao812d5b42022-11-16 18:08:50 +0000989 std::replace_if(
990 name.begin(), name.end(), [](const char c) { return !std::isalnum(c); }, '_');
991 return name;
992 });
Shunkai Yaoa4ab38c2022-10-14 01:07:47 +0000993GTEST_ALLOW_UNINSTANTIATED_PARAMETERIZED_TEST(AudioEffectTest);
Shunkai Yao67b1be62022-07-13 05:01:42 +0000994
Jaideep Sharmacba42862023-06-23 10:27:39 +0530995INSTANTIATE_TEST_SUITE_P(
996 SingleEffectInstanceTest, AudioEffectDataPathTest,
997 ::testing::Combine(testing::ValuesIn(
998 EffectFactoryHelper::getAllEffectDescriptors(IFactory::descriptor))),
999 [](const testing::TestParamInfo<AudioEffectDataPathTest::ParamType>& info) {
1000 auto descriptor = std::get<PARAM_INSTANCE_NAME>(info.param).second;
1001 std::string name = getPrefix(descriptor);
1002 std::replace_if(
1003 name.begin(), name.end(), [](const char c) { return !std::isalnum(c); }, '_');
1004 return name;
1005 });
1006
1007GTEST_ALLOW_UNINSTANTIATED_PARAMETERIZED_TEST(AudioEffectDataPathTest);
1008
Shunkai Yao67b1be62022-07-13 05:01:42 +00001009int main(int argc, char** argv) {
1010 ::testing::InitGoogleTest(&argc, argv);
Jaideep Sharma74498412023-09-13 15:25:25 +05301011 ::testing::UnitTest::GetInstance()->listeners().Append(new TestExecutionTracer());
Shunkai Yao67b1be62022-07-13 05:01:42 +00001012 ABinderProcess_setThreadPoolMaxThreadCount(1);
1013 ABinderProcess_startThreadPool();
1014 return RUN_ALL_TESTS();
Shunkai Yaoa4ab38c2022-10-14 01:07:47 +00001015}