Effect AIDL: Add VTS test cases cleanup in TearDown am: cb0fc410d7 am: 7213f6dd4c am: dec53195b7

Original change: https://android-review.googlesource.com/c/platform/hardware/interfaces/+/2360488

Change-Id: If6d189f6414f0af967aaba6ca9fc4fa5724a2678
Signed-off-by: Automerger Merge Worker <android-build-automerger-merge-worker@system.gserviceaccount.com>
This commit is contained in:
Shunkai Yao 2022-12-16 10:42:39 +00:00 committed by Automerger Merge Worker
commit fb317fddc2
8 changed files with 377 additions and 344 deletions

View file

@ -53,8 +53,9 @@ class EqualizerSwContext final : public EffectContext {
LOG(ERROR) << __func__ << " index illegal, skip: " << it.index << " - "
<< it.levelMb;
ret = RetCode::ERROR_ILLEGAL_PARAMETER;
} else {
mBandLevels[it.index] = it.levelMb;
}
mBandLevels[it.index] = it.levelMb;
}
return ret;
}

View file

@ -72,13 +72,11 @@ class EffectContext {
float* getWorkBuffer() { return static_cast<float*>(mWorkBuffer.data()); }
// reset buffer status by abandon all data and status in FMQ
// reset buffer status by abandon input data in FMQ
void resetBuffer() {
auto buffer = static_cast<float*>(mWorkBuffer.data());
std::vector<IEffect::Status> status(mStatusMQ->availableToRead());
mInputMQ->read(buffer, mInputMQ->availableToRead());
mOutputMQ->read(buffer, mOutputMQ->availableToRead());
mStatusMQ->read(status.data(), mStatusMQ->availableToRead());
}
void dupeFmq(IEffect::OpenEffectReturn* effectRet) {

View file

@ -49,11 +49,11 @@ class EffectFactoryHelper {
std::shared_ptr<IFactory> GetFactory() const { return mEffectFactory; }
static std::vector<std::pair<std::shared_ptr<IFactory>, Descriptor::Identity>>
getAllEffectDescriptors(std::string serviceName, std::optional<AudioUuid> type = std::nullopt) {
static std::vector<std::pair<std::shared_ptr<IFactory>, Descriptor>> getAllEffectDescriptors(
std::string serviceName, std::optional<AudioUuid> type = std::nullopt) {
AudioHalBinderServiceUtil util;
auto names = android::getAidlHalInstanceNames(serviceName);
std::vector<std::pair<std::shared_ptr<IFactory>, Descriptor::Identity>> result;
std::vector<std::pair<std::shared_ptr<IFactory>, Descriptor>> result;
for (const auto& name : names) {
auto factory = IFactory::fromBinder(util.connectToService(name));
@ -62,11 +62,10 @@ class EffectFactoryHelper {
factory->queryEffects(std::nullopt, std::nullopt, std::nullopt, &descs)
.isOk()) {
for (const auto& desc : descs) {
const auto& id = desc.common.id;
if (type.has_value() && id.type != type.value()) {
if (type.has_value() && desc.common.id.type != type.value()) {
continue;
}
result.emplace_back(factory, id);
result.emplace_back(factory, desc);
}
}
}

View file

@ -58,26 +58,34 @@ typedef ::android::AidlMessageQueue<float,
class EffectHelper {
public:
static void create(std::shared_ptr<IFactory> factory, std::shared_ptr<IEffect>& effect,
Descriptor::Identity id, binder_status_t status = EX_NONE) {
Descriptor& desc, binder_status_t status = EX_NONE) {
ASSERT_NE(factory, nullptr);
EXPECT_STATUS(status, factory->createEffect(id.uuid, &effect));
auto& id = desc.common.id;
ASSERT_STATUS(status, factory->createEffect(id.uuid, &effect));
if (status == EX_NONE) {
ASSERT_NE(effect, nullptr) << id.uuid.toString();
}
}
static void destroyIgnoreRet(std::shared_ptr<IFactory> factory,
std::shared_ptr<IEffect> effect) {
if (factory && effect) {
factory->destroyEffect(effect);
}
}
static void destroy(std::shared_ptr<IFactory> factory, std::shared_ptr<IEffect> effect,
binder_status_t status = EX_NONE) {
ASSERT_NE(factory, nullptr);
ASSERT_NE(effect, nullptr);
EXPECT_STATUS(status, factory->destroyEffect(effect));
ASSERT_STATUS(status, factory->destroyEffect(effect));
}
static void open(std::shared_ptr<IEffect> effect, const Parameter::Common& common,
const std::optional<Parameter::Specific>& specific,
IEffect::OpenEffectReturn* ret, binder_status_t status = EX_NONE) {
ASSERT_NE(effect, nullptr);
EXPECT_STATUS(status, effect->open(common, specific, ret));
ASSERT_STATUS(status, effect->open(common, specific, ret));
}
static void open(std::shared_ptr<IEffect> effect, int session = 0,
@ -85,30 +93,40 @@ class EffectHelper {
ASSERT_NE(effect, nullptr);
Parameter::Common common = EffectHelper::createParamCommon(session);
IEffect::OpenEffectReturn ret;
open(effect, common, std::nullopt /* specific */, &ret, status);
ASSERT_NO_FATAL_FAILURE(open(effect, common, std::nullopt /* specific */, &ret, status));
}
static void closeIgnoreRet(std::shared_ptr<IEffect> effect) {
if (effect) {
effect->close();
}
}
static void close(std::shared_ptr<IEffect> effect, binder_status_t status = EX_NONE) {
if (effect) {
EXPECT_STATUS(status, effect->close());
ASSERT_STATUS(status, effect->close());
}
}
static void getDescriptor(std::shared_ptr<IEffect> effect, Descriptor& desc,
binder_status_t status = EX_NONE) {
ASSERT_NE(effect, nullptr);
EXPECT_STATUS(status, effect->getDescriptor(&desc));
ASSERT_STATUS(status, effect->getDescriptor(&desc));
}
static void expectState(std::shared_ptr<IEffect> effect, State expectState,
binder_status_t status = EX_NONE) {
ASSERT_NE(effect, nullptr);
State state;
EXPECT_STATUS(status, effect->getState(&state));
EXPECT_EQ(expectState, state);
ASSERT_STATUS(status, effect->getState(&state));
ASSERT_EQ(expectState, state);
}
static void commandIgnoreRet(std::shared_ptr<IEffect> effect, CommandId command) {
if (effect) {
effect->command(command);
}
}
static void command(std::shared_ptr<IEffect> effect, CommandId command,
binder_status_t status = EX_NONE) {
ASSERT_NE(effect, nullptr);
EXPECT_STATUS(status, effect->command(command));
ASSERT_STATUS(status, effect->command(command));
}
static void allocateInputData(const Parameter::Common common, std::unique_ptr<DataMQ>& mq,
std::vector<float>& buffer) {
@ -116,29 +134,29 @@ class EffectHelper {
auto frameSize = android::hardware::audio::common::getFrameSizeInBytes(
common.input.base.format, common.input.base.channelMask);
const size_t floatsToWrite = mq->availableToWrite();
EXPECT_NE(0UL, floatsToWrite);
EXPECT_EQ(frameSize * common.input.frameCount, floatsToWrite * sizeof(float));
ASSERT_NE(0UL, floatsToWrite);
ASSERT_EQ(frameSize * common.input.frameCount, floatsToWrite * sizeof(float));
buffer.resize(floatsToWrite);
std::fill(buffer.begin(), buffer.end(), 0x5a);
}
static void writeToFmq(std::unique_ptr<DataMQ>& mq, const std::vector<float>& buffer) {
const size_t available = mq->availableToWrite();
EXPECT_NE(0Ul, available);
ASSERT_NE(0Ul, available);
auto bufferFloats = buffer.size();
auto floatsToWrite = std::min(available, bufferFloats);
EXPECT_TRUE(mq->write(buffer.data(), floatsToWrite));
ASSERT_TRUE(mq->write(buffer.data(), floatsToWrite));
}
static void readFromFmq(std::unique_ptr<StatusMQ>& statusMq, size_t statusNum,
std::unique_ptr<DataMQ>& dataMq, size_t expectFloats,
std::vector<float>& buffer) {
IEffect::Status status{};
EXPECT_TRUE(statusMq->readBlocking(&status, statusNum));
EXPECT_EQ(STATUS_OK, status.status);
ASSERT_TRUE(statusMq->readBlocking(&status, statusNum));
ASSERT_EQ(STATUS_OK, status.status);
if (statusNum != 0) {
EXPECT_EQ(expectFloats, (unsigned)status.fmqProduced);
EXPECT_EQ(expectFloats, dataMq->availableToRead());
ASSERT_EQ(expectFloats, (unsigned)status.fmqProduced);
ASSERT_EQ(expectFloats, dataMq->availableToRead());
if (expectFloats != 0) {
EXPECT_TRUE(dataMq->read(buffer.data(), expectFloats));
ASSERT_TRUE(dataMq->read(buffer.data(), expectFloats));
}
}
}

View file

@ -49,18 +49,30 @@ using aidl::android::hardware::audio::effect::Parameter;
using aidl::android::hardware::audio::effect::State;
enum ParamName { PARAM_INSTANCE_NAME };
using EffectTestParam = std::tuple<std::pair<std::shared_ptr<IFactory>, Descriptor::Identity>>;
using EffectTestParam = std::tuple<std::pair<std::shared_ptr<IFactory>, Descriptor>>;
class AudioEffectTest : public testing::TestWithParam<EffectTestParam>, public EffectHelper {
public:
AudioEffectTest() { std::tie(mFactory, mIdentity) = std::get<PARAM_INSTANCE_NAME>(GetParam()); }
AudioEffectTest() {
std::tie(mFactory, mDescriptor) = std::get<PARAM_INSTANCE_NAME>(GetParam());
}
void SetUp() override {}
void TearDown() override {}
void TearDown() override {
// Do the cleanup for every test case
if (mEffect) {
ASSERT_NO_FATAL_FAILURE(commandIgnoreRet(mEffect, CommandId::STOP));
ASSERT_NO_FATAL_FAILURE(closeIgnoreRet(mEffect));
ASSERT_NO_FATAL_FAILURE(destroyIgnoreRet(mFactory, mEffect));
mEffect.reset();
}
}
static const long kInputFrameCount = 0x100, kOutputFrameCount = 0x100;
std::shared_ptr<IFactory> mFactory;
Descriptor::Identity mIdentity;
std::shared_ptr<IEffect> mEffect;
Descriptor mDescriptor;
};
TEST_P(AudioEffectTest, SetupAndTearDown) {
@ -68,30 +80,27 @@ TEST_P(AudioEffectTest, SetupAndTearDown) {
}
TEST_P(AudioEffectTest, CreateAndDestroy) {
std::shared_ptr<IEffect> effect;
ASSERT_NO_FATAL_FAILURE(create(mFactory, effect, mIdentity));
ASSERT_NO_FATAL_FAILURE(destroy(mFactory, effect));
ASSERT_NO_FATAL_FAILURE(create(mFactory, mEffect, mDescriptor));
ASSERT_NO_FATAL_FAILURE(destroy(mFactory, mEffect));
}
TEST_P(AudioEffectTest, OpenAndClose) {
std::shared_ptr<IEffect> effect;
ASSERT_NO_FATAL_FAILURE(create(mFactory, effect, mIdentity));
ASSERT_NO_FATAL_FAILURE(open(effect));
ASSERT_NO_FATAL_FAILURE(close(effect));
ASSERT_NO_FATAL_FAILURE(destroy(mFactory, effect));
ASSERT_NO_FATAL_FAILURE(create(mFactory, mEffect, mDescriptor));
ASSERT_NO_FATAL_FAILURE(open(mEffect));
ASSERT_NO_FATAL_FAILURE(close(mEffect));
ASSERT_NO_FATAL_FAILURE(destroy(mFactory, mEffect));
}
TEST_P(AudioEffectTest, CloseUnopenedEffect) {
std::shared_ptr<IEffect> effect;
ASSERT_NO_FATAL_FAILURE(create(mFactory, effect, mIdentity));
ASSERT_NO_FATAL_FAILURE(close(effect));
ASSERT_NO_FATAL_FAILURE(destroy(mFactory, effect));
ASSERT_NO_FATAL_FAILURE(create(mFactory, mEffect, mDescriptor));
ASSERT_NO_FATAL_FAILURE(close(mEffect));
ASSERT_NO_FATAL_FAILURE(destroy(mFactory, mEffect));
}
TEST_P(AudioEffectTest, DoubleOpenAndClose) {
std::shared_ptr<IEffect> effect1, effect2;
ASSERT_NO_FATAL_FAILURE(create(mFactory, effect1, mIdentity));
ASSERT_NO_FATAL_FAILURE(create(mFactory, effect2, mIdentity));
ASSERT_NO_FATAL_FAILURE(create(mFactory, effect1, mDescriptor));
ASSERT_NO_FATAL_FAILURE(create(mFactory, effect2, mDescriptor));
ASSERT_NO_FATAL_FAILURE(open(effect1));
ASSERT_NO_FATAL_FAILURE(open(effect2, 1 /* session */));
ASSERT_NO_FATAL_FAILURE(close(effect1));
@ -102,9 +111,9 @@ TEST_P(AudioEffectTest, DoubleOpenAndClose) {
TEST_P(AudioEffectTest, TripleOpenAndClose) {
std::shared_ptr<IEffect> effect1, effect2, effect3;
ASSERT_NO_FATAL_FAILURE(create(mFactory, effect1, mIdentity));
ASSERT_NO_FATAL_FAILURE(create(mFactory, effect2, mIdentity));
ASSERT_NO_FATAL_FAILURE(create(mFactory, effect3, mIdentity));
ASSERT_NO_FATAL_FAILURE(create(mFactory, effect1, mDescriptor));
ASSERT_NO_FATAL_FAILURE(create(mFactory, effect2, mDescriptor));
ASSERT_NO_FATAL_FAILURE(create(mFactory, effect3, mDescriptor));
ASSERT_NO_FATAL_FAILURE(open(effect1));
ASSERT_NO_FATAL_FAILURE(open(effect2, 1 /* session */));
ASSERT_NO_FATAL_FAILURE(open(effect3, 2 /* session */));
@ -117,513 +126,505 @@ TEST_P(AudioEffectTest, TripleOpenAndClose) {
}
TEST_P(AudioEffectTest, GetDescritorBeforeOpen) {
std::shared_ptr<IEffect> effect;
Descriptor desc;
ASSERT_NO_FATAL_FAILURE(create(mFactory, effect, mIdentity));
ASSERT_NO_FATAL_FAILURE(getDescriptor(effect, desc));
EXPECT_EQ(mIdentity.toString(), desc.common.id.toString());
ASSERT_NO_FATAL_FAILURE(create(mFactory, mEffect, mDescriptor));
ASSERT_NO_FATAL_FAILURE(getDescriptor(mEffect, desc));
EXPECT_EQ(mDescriptor.common, desc.common);
// Effect implementation Must fill in implementor and name
EXPECT_NE("", desc.common.name);
EXPECT_NE("", desc.common.implementor);
ASSERT_NO_FATAL_FAILURE(destroy(mFactory, effect));
ASSERT_NO_FATAL_FAILURE(destroy(mFactory, mEffect));
}
TEST_P(AudioEffectTest, GetDescritorAfterOpen) {
std::shared_ptr<IEffect> effect;
Descriptor beforeOpen, afterOpen, afterClose;
ASSERT_NO_FATAL_FAILURE(create(mFactory, effect, mIdentity));
ASSERT_NO_FATAL_FAILURE(getDescriptor(effect, beforeOpen));
ASSERT_NO_FATAL_FAILURE(open(effect));
ASSERT_NO_FATAL_FAILURE(getDescriptor(effect, afterOpen));
ASSERT_NO_FATAL_FAILURE(create(mFactory, mEffect, mDescriptor));
ASSERT_NO_FATAL_FAILURE(getDescriptor(mEffect, beforeOpen));
ASSERT_NO_FATAL_FAILURE(open(mEffect));
ASSERT_NO_FATAL_FAILURE(getDescriptor(mEffect, afterOpen));
EXPECT_EQ(beforeOpen.toString(), afterOpen.toString()) << "\n"
<< beforeOpen.toString() << "\n"
<< afterOpen.toString();
ASSERT_NO_FATAL_FAILURE(close(effect));
ASSERT_NO_FATAL_FAILURE(getDescriptor(effect, afterClose));
ASSERT_NO_FATAL_FAILURE(close(mEffect));
ASSERT_NO_FATAL_FAILURE(getDescriptor(mEffect, afterClose));
EXPECT_EQ(beforeOpen.toString(), afterClose.toString()) << "\n"
<< beforeOpen.toString() << "\n"
<< afterClose.toString();
ASSERT_NO_FATAL_FAILURE(destroy(mFactory, effect));
ASSERT_NO_FATAL_FAILURE(destroy(mFactory, mEffect));
}
TEST_P(AudioEffectTest, DescriptorExistAndUnique) {
std::shared_ptr<IEffect> effect;
Descriptor desc;
auto descList = EffectFactoryHelper::getAllEffectDescriptors(IFactory::descriptor);
std::set<Descriptor::Identity> idSet;
for (const auto& it : descList) {
auto& id = it.second;
auto& id = it.second.common.id;
EXPECT_EQ(0ul, idSet.count(id));
idSet.insert(id);
}
ASSERT_NO_FATAL_FAILURE(create(mFactory, effect, mIdentity));
ASSERT_NO_FATAL_FAILURE(getDescriptor(effect, desc));
ASSERT_NO_FATAL_FAILURE(create(mFactory, mEffect, mDescriptor));
ASSERT_NO_FATAL_FAILURE(getDescriptor(mEffect, desc));
EXPECT_EQ(1ul, idSet.count(desc.common.id));
ASSERT_NO_FATAL_FAILURE(destroy(mFactory, effect));
ASSERT_NO_FATAL_FAILURE(destroy(mFactory, mEffect));
}
/// State testing.
// An effect instance is in INIT state by default after it was created.
TEST_P(AudioEffectTest, InitStateAfterCreation) {
std::shared_ptr<IEffect> effect;
ASSERT_NO_FATAL_FAILURE(create(mFactory, effect, mIdentity));
ASSERT_NO_FATAL_FAILURE(expectState(effect, State::INIT));
ASSERT_NO_FATAL_FAILURE(destroy(mFactory, effect));
ASSERT_NO_FATAL_FAILURE(create(mFactory, mEffect, mDescriptor));
ASSERT_NO_FATAL_FAILURE(expectState(mEffect, State::INIT));
ASSERT_NO_FATAL_FAILURE(destroy(mFactory, mEffect));
}
// An effect instance transfer to IDLE state after IEffect.ASSERT_NO_FATAL_FAILURE(open().
TEST_P(AudioEffectTest, IdleStateAfterOpen) {
std::shared_ptr<IEffect> effect;
ASSERT_NO_FATAL_FAILURE(create(mFactory, effect, mIdentity));
ASSERT_NO_FATAL_FAILURE(open(effect));
ASSERT_NO_FATAL_FAILURE(expectState(effect, State::IDLE));
ASSERT_NO_FATAL_FAILURE(close(effect));
ASSERT_NO_FATAL_FAILURE(destroy(mFactory, effect));
ASSERT_NO_FATAL_FAILURE(create(mFactory, mEffect, mDescriptor));
ASSERT_NO_FATAL_FAILURE(open(mEffect));
ASSERT_NO_FATAL_FAILURE(expectState(mEffect, State::IDLE));
ASSERT_NO_FATAL_FAILURE(close(mEffect));
ASSERT_NO_FATAL_FAILURE(destroy(mFactory, mEffect));
}
// An effect instance is in PROCESSING state after it receive an START command.
TEST_P(AudioEffectTest, ProcessingStateAfterStart) {
std::shared_ptr<IEffect> effect;
ASSERT_NO_FATAL_FAILURE(create(mFactory, effect, mIdentity));
ASSERT_NO_FATAL_FAILURE(expectState(effect, State::INIT));
ASSERT_NO_FATAL_FAILURE(open(effect));
ASSERT_NO_FATAL_FAILURE(expectState(effect, State::IDLE));
ASSERT_NO_FATAL_FAILURE(command(effect, CommandId::START));
ASSERT_NO_FATAL_FAILURE(expectState(effect, State::PROCESSING));
ASSERT_NO_FATAL_FAILURE(command(effect, CommandId::STOP));
ASSERT_NO_FATAL_FAILURE(close(effect));
ASSERT_NO_FATAL_FAILURE(destroy(mFactory, effect));
ASSERT_NO_FATAL_FAILURE(create(mFactory, mEffect, mDescriptor));
ASSERT_NO_FATAL_FAILURE(expectState(mEffect, State::INIT));
ASSERT_NO_FATAL_FAILURE(open(mEffect));
ASSERT_NO_FATAL_FAILURE(expectState(mEffect, State::IDLE));
ASSERT_NO_FATAL_FAILURE(command(mEffect, CommandId::START));
ASSERT_NO_FATAL_FAILURE(expectState(mEffect, State::PROCESSING));
ASSERT_NO_FATAL_FAILURE(command(mEffect, CommandId::STOP));
ASSERT_NO_FATAL_FAILURE(close(mEffect));
ASSERT_NO_FATAL_FAILURE(destroy(mFactory, mEffect));
}
// An effect instance transfer to IDLE state after Command.Id.STOP in PROCESSING state.
TEST_P(AudioEffectTest, IdleStateAfterStop) {
std::shared_ptr<IEffect> effect;
ASSERT_NO_FATAL_FAILURE(create(mFactory, effect, mIdentity));
ASSERT_NO_FATAL_FAILURE(open(effect));
ASSERT_NO_FATAL_FAILURE(command(effect, CommandId::START));
ASSERT_NO_FATAL_FAILURE(expectState(effect, State::PROCESSING));
ASSERT_NO_FATAL_FAILURE(command(effect, CommandId::STOP));
ASSERT_NO_FATAL_FAILURE(expectState(effect, State::IDLE));
ASSERT_NO_FATAL_FAILURE(close(effect));
ASSERT_NO_FATAL_FAILURE(destroy(mFactory, effect));
ASSERT_NO_FATAL_FAILURE(create(mFactory, mEffect, mDescriptor));
ASSERT_NO_FATAL_FAILURE(open(mEffect));
ASSERT_NO_FATAL_FAILURE(command(mEffect, CommandId::START));
ASSERT_NO_FATAL_FAILURE(expectState(mEffect, State::PROCESSING));
ASSERT_NO_FATAL_FAILURE(command(mEffect, CommandId::STOP));
ASSERT_NO_FATAL_FAILURE(expectState(mEffect, State::IDLE));
ASSERT_NO_FATAL_FAILURE(close(mEffect));
ASSERT_NO_FATAL_FAILURE(destroy(mFactory, mEffect));
}
// An effect instance transfer to IDLE state after Command.Id.RESET in PROCESSING state.
TEST_P(AudioEffectTest, IdleStateAfterReset) {
std::shared_ptr<IEffect> effect;
ASSERT_NO_FATAL_FAILURE(create(mFactory, effect, mIdentity));
ASSERT_NO_FATAL_FAILURE(open(effect));
ASSERT_NO_FATAL_FAILURE(command(effect, CommandId::START));
ASSERT_NO_FATAL_FAILURE(expectState(effect, State::PROCESSING));
ASSERT_NO_FATAL_FAILURE(command(effect, CommandId::RESET));
ASSERT_NO_FATAL_FAILURE(expectState(effect, State::IDLE));
ASSERT_NO_FATAL_FAILURE(close(effect));
ASSERT_NO_FATAL_FAILURE(destroy(mFactory, effect));
ASSERT_NO_FATAL_FAILURE(create(mFactory, mEffect, mDescriptor));
ASSERT_NO_FATAL_FAILURE(open(mEffect));
ASSERT_NO_FATAL_FAILURE(command(mEffect, CommandId::START));
ASSERT_NO_FATAL_FAILURE(expectState(mEffect, State::PROCESSING));
ASSERT_NO_FATAL_FAILURE(command(mEffect, CommandId::RESET));
ASSERT_NO_FATAL_FAILURE(expectState(mEffect, State::IDLE));
ASSERT_NO_FATAL_FAILURE(close(mEffect));
ASSERT_NO_FATAL_FAILURE(destroy(mFactory, mEffect));
}
// An effect instance transfer to INIT after IEffect.ASSERT_NO_FATAL_FAILURE(close().
TEST_P(AudioEffectTest, InitStateAfterClose) {
std::shared_ptr<IEffect> effect;
ASSERT_NO_FATAL_FAILURE(create(mFactory, effect, mIdentity));
ASSERT_NO_FATAL_FAILURE(open(effect));
ASSERT_NO_FATAL_FAILURE(command(effect, CommandId::START));
ASSERT_NO_FATAL_FAILURE(command(effect, CommandId::STOP));
ASSERT_NO_FATAL_FAILURE(close(effect));
ASSERT_NO_FATAL_FAILURE(expectState(effect, State::INIT));
ASSERT_NO_FATAL_FAILURE(destroy(mFactory, effect));
ASSERT_NO_FATAL_FAILURE(create(mFactory, mEffect, mDescriptor));
ASSERT_NO_FATAL_FAILURE(open(mEffect));
ASSERT_NO_FATAL_FAILURE(command(mEffect, CommandId::START));
ASSERT_NO_FATAL_FAILURE(command(mEffect, CommandId::STOP));
ASSERT_NO_FATAL_FAILURE(close(mEffect));
ASSERT_NO_FATAL_FAILURE(expectState(mEffect, State::INIT));
ASSERT_NO_FATAL_FAILURE(destroy(mFactory, mEffect));
}
// An effect instance shouldn't accept any command before open.
TEST_P(AudioEffectTest, NoCommandAcceptedBeforeOpen) {
std::shared_ptr<IEffect> effect;
ASSERT_NO_FATAL_FAILURE(create(mFactory, effect, mIdentity));
ASSERT_NO_FATAL_FAILURE(command(effect, CommandId::START, EX_ILLEGAL_STATE));
ASSERT_NO_FATAL_FAILURE(command(effect, CommandId::STOP, EX_ILLEGAL_STATE));
ASSERT_NO_FATAL_FAILURE(command(effect, CommandId::RESET, EX_ILLEGAL_STATE));
ASSERT_NO_FATAL_FAILURE(open(effect));
ASSERT_NO_FATAL_FAILURE(close(effect));
ASSERT_NO_FATAL_FAILURE(destroy(mFactory, effect));
ASSERT_NO_FATAL_FAILURE(create(mFactory, mEffect, mDescriptor));
ASSERT_NO_FATAL_FAILURE(command(mEffect, CommandId::START, EX_ILLEGAL_STATE));
ASSERT_NO_FATAL_FAILURE(command(mEffect, CommandId::STOP, EX_ILLEGAL_STATE));
ASSERT_NO_FATAL_FAILURE(command(mEffect, CommandId::RESET, EX_ILLEGAL_STATE));
ASSERT_NO_FATAL_FAILURE(destroy(mFactory, mEffect));
}
// No-op when receive STOP command in IDLE state.
TEST_P(AudioEffectTest, StopCommandInIdleStateNoOp) {
std::shared_ptr<IEffect> effect;
ASSERT_NO_FATAL_FAILURE(create(mFactory, effect, mIdentity));
ASSERT_NO_FATAL_FAILURE(open(effect));
ASSERT_NO_FATAL_FAILURE(expectState(effect, State::IDLE));
ASSERT_NO_FATAL_FAILURE(command(effect, CommandId::STOP));
ASSERT_NO_FATAL_FAILURE(expectState(effect, State::IDLE));
ASSERT_NO_FATAL_FAILURE(close(effect));
ASSERT_NO_FATAL_FAILURE(destroy(mFactory, effect));
ASSERT_NO_FATAL_FAILURE(create(mFactory, mEffect, mDescriptor));
ASSERT_NO_FATAL_FAILURE(open(mEffect));
ASSERT_NO_FATAL_FAILURE(expectState(mEffect, State::IDLE));
ASSERT_NO_FATAL_FAILURE(command(mEffect, CommandId::STOP));
ASSERT_NO_FATAL_FAILURE(expectState(mEffect, State::IDLE));
ASSERT_NO_FATAL_FAILURE(close(mEffect));
ASSERT_NO_FATAL_FAILURE(destroy(mFactory, mEffect));
}
// No-op when receive RESET command in IDLE state.
TEST_P(AudioEffectTest, ResetCommandInIdleStateNoOp) {
std::shared_ptr<IEffect> effect;
ASSERT_NO_FATAL_FAILURE(create(mFactory, effect, mIdentity));
ASSERT_NO_FATAL_FAILURE(open(effect));
ASSERT_NO_FATAL_FAILURE(expectState(effect, State::IDLE));
ASSERT_NO_FATAL_FAILURE(command(effect, CommandId::RESET));
ASSERT_NO_FATAL_FAILURE(expectState(effect, State::IDLE));
ASSERT_NO_FATAL_FAILURE(close(effect));
ASSERT_NO_FATAL_FAILURE(destroy(mFactory, effect));
ASSERT_NO_FATAL_FAILURE(create(mFactory, mEffect, mDescriptor));
ASSERT_NO_FATAL_FAILURE(open(mEffect));
ASSERT_NO_FATAL_FAILURE(expectState(mEffect, State::IDLE));
ASSERT_NO_FATAL_FAILURE(command(mEffect, CommandId::RESET));
ASSERT_NO_FATAL_FAILURE(expectState(mEffect, State::IDLE));
ASSERT_NO_FATAL_FAILURE(close(mEffect));
ASSERT_NO_FATAL_FAILURE(destroy(mFactory, mEffect));
}
// Repeat START and STOP command.
TEST_P(AudioEffectTest, RepeatStartAndStop) {
std::shared_ptr<IEffect> effect;
ASSERT_NO_FATAL_FAILURE(create(mFactory, effect, mIdentity));
ASSERT_NO_FATAL_FAILURE(open(effect));
ASSERT_NO_FATAL_FAILURE(expectState(effect, State::IDLE));
ASSERT_NO_FATAL_FAILURE(command(effect, CommandId::START));
ASSERT_NO_FATAL_FAILURE(expectState(effect, State::PROCESSING));
ASSERT_NO_FATAL_FAILURE(command(effect, CommandId::STOP));
ASSERT_NO_FATAL_FAILURE(expectState(effect, State::IDLE));
ASSERT_NO_FATAL_FAILURE(create(mFactory, mEffect, mDescriptor));
ASSERT_NO_FATAL_FAILURE(open(mEffect));
ASSERT_NO_FATAL_FAILURE(expectState(mEffect, State::IDLE));
ASSERT_NO_FATAL_FAILURE(command(mEffect, CommandId::START));
ASSERT_NO_FATAL_FAILURE(expectState(mEffect, State::PROCESSING));
ASSERT_NO_FATAL_FAILURE(command(mEffect, CommandId::STOP));
ASSERT_NO_FATAL_FAILURE(expectState(mEffect, State::IDLE));
ASSERT_NO_FATAL_FAILURE(command(effect, CommandId::START));
ASSERT_NO_FATAL_FAILURE(expectState(effect, State::PROCESSING));
ASSERT_NO_FATAL_FAILURE(command(effect, CommandId::STOP));
ASSERT_NO_FATAL_FAILURE(expectState(effect, State::IDLE));
ASSERT_NO_FATAL_FAILURE(close(effect));
ASSERT_NO_FATAL_FAILURE(destroy(mFactory, effect));
ASSERT_NO_FATAL_FAILURE(command(mEffect, CommandId::START));
ASSERT_NO_FATAL_FAILURE(expectState(mEffect, State::PROCESSING));
ASSERT_NO_FATAL_FAILURE(command(mEffect, CommandId::STOP));
ASSERT_NO_FATAL_FAILURE(expectState(mEffect, State::IDLE));
ASSERT_NO_FATAL_FAILURE(close(mEffect));
ASSERT_NO_FATAL_FAILURE(destroy(mFactory, mEffect));
}
// Repeat START and RESET command.
TEST_P(AudioEffectTest, RepeatStartAndReset) {
std::shared_ptr<IEffect> effect;
ASSERT_NO_FATAL_FAILURE(create(mFactory, effect, mIdentity));
ASSERT_NO_FATAL_FAILURE(open(effect));
ASSERT_NO_FATAL_FAILURE(expectState(effect, State::IDLE));
ASSERT_NO_FATAL_FAILURE(command(effect, CommandId::START));
ASSERT_NO_FATAL_FAILURE(expectState(effect, State::PROCESSING));
ASSERT_NO_FATAL_FAILURE(command(effect, CommandId::RESET));
ASSERT_NO_FATAL_FAILURE(expectState(effect, State::IDLE));
ASSERT_NO_FATAL_FAILURE(create(mFactory, mEffect, mDescriptor));
ASSERT_NO_FATAL_FAILURE(open(mEffect));
ASSERT_NO_FATAL_FAILURE(expectState(mEffect, State::IDLE));
ASSERT_NO_FATAL_FAILURE(command(mEffect, CommandId::START));
ASSERT_NO_FATAL_FAILURE(expectState(mEffect, State::PROCESSING));
ASSERT_NO_FATAL_FAILURE(command(mEffect, CommandId::RESET));
ASSERT_NO_FATAL_FAILURE(expectState(mEffect, State::IDLE));
ASSERT_NO_FATAL_FAILURE(command(effect, CommandId::START));
ASSERT_NO_FATAL_FAILURE(expectState(effect, State::PROCESSING));
ASSERT_NO_FATAL_FAILURE(command(effect, CommandId::RESET));
ASSERT_NO_FATAL_FAILURE(expectState(effect, State::IDLE));
ASSERT_NO_FATAL_FAILURE(close(effect));
ASSERT_NO_FATAL_FAILURE(destroy(mFactory, effect));
ASSERT_NO_FATAL_FAILURE(command(mEffect, CommandId::START));
ASSERT_NO_FATAL_FAILURE(expectState(mEffect, State::PROCESSING));
ASSERT_NO_FATAL_FAILURE(command(mEffect, CommandId::RESET));
ASSERT_NO_FATAL_FAILURE(expectState(mEffect, State::IDLE));
ASSERT_NO_FATAL_FAILURE(close(mEffect));
ASSERT_NO_FATAL_FAILURE(destroy(mFactory, mEffect));
}
// Try to close an effect instance at PROCESSING state.
TEST_P(AudioEffectTest, CloseProcessingStateEffects) {
std::shared_ptr<IEffect> effect;
ASSERT_NO_FATAL_FAILURE(create(mFactory, effect, mIdentity));
ASSERT_NO_FATAL_FAILURE(open(effect));
ASSERT_NO_FATAL_FAILURE(expectState(effect, State::IDLE));
ASSERT_NO_FATAL_FAILURE(command(effect, CommandId::START));
ASSERT_NO_FATAL_FAILURE(expectState(effect, State::PROCESSING));
ASSERT_NO_FATAL_FAILURE(create(mFactory, mEffect, mDescriptor));
ASSERT_NO_FATAL_FAILURE(open(mEffect));
ASSERT_NO_FATAL_FAILURE(expectState(mEffect, State::IDLE));
ASSERT_NO_FATAL_FAILURE(command(mEffect, CommandId::START));
ASSERT_NO_FATAL_FAILURE(expectState(mEffect, State::PROCESSING));
ASSERT_NO_FATAL_FAILURE(close(effect, EX_ILLEGAL_STATE));
ASSERT_NO_FATAL_FAILURE(close(mEffect, EX_ILLEGAL_STATE));
ASSERT_NO_FATAL_FAILURE(command(effect, CommandId::STOP));
ASSERT_NO_FATAL_FAILURE(expectState(effect, State::IDLE));
ASSERT_NO_FATAL_FAILURE(close(effect));
ASSERT_NO_FATAL_FAILURE(destroy(mFactory, effect));
ASSERT_NO_FATAL_FAILURE(command(mEffect, CommandId::STOP));
ASSERT_NO_FATAL_FAILURE(expectState(mEffect, State::IDLE));
ASSERT_NO_FATAL_FAILURE(close(mEffect));
ASSERT_NO_FATAL_FAILURE(destroy(mFactory, mEffect));
}
// Expect EX_ILLEGAL_STATE if the effect instance is not in a proper state to be destroyed.
TEST_P(AudioEffectTest, DestroyOpenEffects) {
std::shared_ptr<IEffect> effect;
ASSERT_NO_FATAL_FAILURE(create(mFactory, effect, mIdentity));
ASSERT_NO_FATAL_FAILURE(open(effect));
ASSERT_NO_FATAL_FAILURE(expectState(effect, State::IDLE));
ASSERT_NO_FATAL_FAILURE(create(mFactory, mEffect, mDescriptor));
ASSERT_NO_FATAL_FAILURE(open(mEffect));
ASSERT_NO_FATAL_FAILURE(expectState(mEffect, State::IDLE));
ASSERT_NO_FATAL_FAILURE(destroy(mFactory, effect, EX_ILLEGAL_STATE));
ASSERT_NO_FATAL_FAILURE(destroy(mFactory, mEffect, EX_ILLEGAL_STATE));
// cleanup
ASSERT_NO_FATAL_FAILURE(close(mEffect));
ASSERT_NO_FATAL_FAILURE(destroy(mFactory, mEffect));
}
// Expect EX_ILLEGAL_STATE if the effect instance is not in a proper state to be destroyed.
TEST_P(AudioEffectTest, DestroyProcessingEffects) {
std::shared_ptr<IEffect> effect;
ASSERT_NO_FATAL_FAILURE(create(mFactory, effect, mIdentity));
ASSERT_NO_FATAL_FAILURE(open(effect));
ASSERT_NO_FATAL_FAILURE(expectState(effect, State::IDLE));
ASSERT_NO_FATAL_FAILURE(command(effect, CommandId::START));
ASSERT_NO_FATAL_FAILURE(expectState(effect, State::PROCESSING));
ASSERT_NO_FATAL_FAILURE(create(mFactory, mEffect, mDescriptor));
ASSERT_NO_FATAL_FAILURE(open(mEffect));
ASSERT_NO_FATAL_FAILURE(expectState(mEffect, State::IDLE));
ASSERT_NO_FATAL_FAILURE(command(mEffect, CommandId::START));
ASSERT_NO_FATAL_FAILURE(expectState(mEffect, State::PROCESSING));
ASSERT_NO_FATAL_FAILURE(destroy(mFactory, effect, EX_ILLEGAL_STATE));
ASSERT_NO_FATAL_FAILURE(destroy(mFactory, mEffect, EX_ILLEGAL_STATE));
// cleanup
ASSERT_NO_FATAL_FAILURE(command(mEffect, CommandId::STOP));
ASSERT_NO_FATAL_FAILURE(expectState(mEffect, State::IDLE));
ASSERT_NO_FATAL_FAILURE(close(mEffect));
ASSERT_NO_FATAL_FAILURE(destroy(mFactory, mEffect));
}
TEST_P(AudioEffectTest, NormalSequenceStates) {
std::shared_ptr<IEffect> effect;
ASSERT_NO_FATAL_FAILURE(create(mFactory, effect, mIdentity));
ASSERT_NO_FATAL_FAILURE(expectState(effect, State::INIT));
ASSERT_NO_FATAL_FAILURE(open(effect));
ASSERT_NO_FATAL_FAILURE(expectState(effect, State::IDLE));
ASSERT_NO_FATAL_FAILURE(command(effect, CommandId::START));
ASSERT_NO_FATAL_FAILURE(expectState(effect, State::PROCESSING));
ASSERT_NO_FATAL_FAILURE(command(effect, CommandId::STOP));
ASSERT_NO_FATAL_FAILURE(expectState(effect, State::IDLE));
ASSERT_NO_FATAL_FAILURE(command(effect, CommandId::START));
ASSERT_NO_FATAL_FAILURE(expectState(effect, State::PROCESSING));
ASSERT_NO_FATAL_FAILURE(command(effect, CommandId::RESET));
ASSERT_NO_FATAL_FAILURE(expectState(effect, State::IDLE));
ASSERT_NO_FATAL_FAILURE(close(effect));
ASSERT_NO_FATAL_FAILURE(destroy(mFactory, effect));
ASSERT_NO_FATAL_FAILURE(create(mFactory, mEffect, mDescriptor));
ASSERT_NO_FATAL_FAILURE(expectState(mEffect, State::INIT));
ASSERT_NO_FATAL_FAILURE(open(mEffect));
ASSERT_NO_FATAL_FAILURE(expectState(mEffect, State::IDLE));
ASSERT_NO_FATAL_FAILURE(command(mEffect, CommandId::START));
ASSERT_NO_FATAL_FAILURE(expectState(mEffect, State::PROCESSING));
ASSERT_NO_FATAL_FAILURE(command(mEffect, CommandId::STOP));
ASSERT_NO_FATAL_FAILURE(expectState(mEffect, State::IDLE));
ASSERT_NO_FATAL_FAILURE(command(mEffect, CommandId::START));
ASSERT_NO_FATAL_FAILURE(expectState(mEffect, State::PROCESSING));
ASSERT_NO_FATAL_FAILURE(command(mEffect, CommandId::RESET));
ASSERT_NO_FATAL_FAILURE(expectState(mEffect, State::IDLE));
ASSERT_NO_FATAL_FAILURE(close(mEffect));
ASSERT_NO_FATAL_FAILURE(destroy(mFactory, mEffect));
}
/// Parameter testing.
// Verify parameters pass in open can be successfully get.
TEST_P(AudioEffectTest, VerifyCommonParametersAfterOpen) {
std::shared_ptr<IEffect> effect;
ASSERT_NO_FATAL_FAILURE(create(mFactory, effect, mIdentity));
ASSERT_NO_FATAL_FAILURE(create(mFactory, mEffect, mDescriptor));
Parameter::Common common = EffectHelper::createParamCommon();
IEffect::OpenEffectReturn ret;
ASSERT_NO_FATAL_FAILURE(open(effect, common, std::nullopt /* specific */, &ret, EX_NONE));
ASSERT_NO_FATAL_FAILURE(open(mEffect, common, std::nullopt /* specific */, &ret, EX_NONE));
Parameter get = Parameter(), expect = Parameter();
expect.set<Parameter::common>(common);
Parameter::Id id;
id.set<Parameter::Id::commonTag>(Parameter::common);
EXPECT_IS_OK(effect->getParameter(id, &get));
EXPECT_IS_OK(mEffect->getParameter(id, &get));
EXPECT_EQ(expect, get) << expect.toString() << " vs " << get.toString();
ASSERT_NO_FATAL_FAILURE(close(effect));
ASSERT_NO_FATAL_FAILURE(destroy(mFactory, effect));
ASSERT_NO_FATAL_FAILURE(close(mEffect));
ASSERT_NO_FATAL_FAILURE(destroy(mFactory, mEffect));
}
// Verify parameters pass in set can be successfully get.
TEST_P(AudioEffectTest, SetAndGetCommonParameter) {
std::shared_ptr<IEffect> effect;
ASSERT_NO_FATAL_FAILURE(create(mFactory, effect, mIdentity));
ASSERT_NO_FATAL_FAILURE(open(effect));
ASSERT_NO_FATAL_FAILURE(create(mFactory, mEffect, mDescriptor));
ASSERT_NO_FATAL_FAILURE(open(mEffect));
Parameter::Common common = EffectHelper::createParamCommon(
0 /* session */, 1 /* ioHandle */, 44100 /* iSampleRate */, 44100 /* oSampleRate */);
Parameter get = Parameter(), set = Parameter();
set.set<Parameter::common>(common);
EXPECT_IS_OK(effect->setParameter(set));
EXPECT_IS_OK(mEffect->setParameter(set));
Parameter::Id id;
id.set<Parameter::Id::commonTag>(Parameter::common);
EXPECT_IS_OK(effect->getParameter(id, &get));
EXPECT_IS_OK(mEffect->getParameter(id, &get));
EXPECT_EQ(set, get) << set.toString() << " vs " << get.toString();
ASSERT_NO_FATAL_FAILURE(close(effect));
ASSERT_NO_FATAL_FAILURE(destroy(mFactory, effect));
ASSERT_NO_FATAL_FAILURE(close(mEffect));
ASSERT_NO_FATAL_FAILURE(destroy(mFactory, mEffect));
}
// Verify parameters set and get in PROCESSING state.
TEST_P(AudioEffectTest, SetAndGetParameterInProcessing) {
std::shared_ptr<IEffect> effect;
ASSERT_NO_FATAL_FAILURE(create(mFactory, effect, mIdentity));
ASSERT_NO_FATAL_FAILURE(open(effect));
ASSERT_NO_FATAL_FAILURE(command(effect, CommandId::START));
ASSERT_NO_FATAL_FAILURE(expectState(effect, State::PROCESSING));
ASSERT_NO_FATAL_FAILURE(create(mFactory, mEffect, mDescriptor));
ASSERT_NO_FATAL_FAILURE(open(mEffect));
ASSERT_NO_FATAL_FAILURE(command(mEffect, CommandId::START));
ASSERT_NO_FATAL_FAILURE(expectState(mEffect, State::PROCESSING));
Parameter::Common common = EffectHelper::createParamCommon(
0 /* session */, 1 /* ioHandle */, 44100 /* iSampleRate */, 44100 /* oSampleRate */);
Parameter get = Parameter(), set = Parameter();
set.set<Parameter::common>(common);
EXPECT_IS_OK(effect->setParameter(set));
EXPECT_IS_OK(mEffect->setParameter(set));
Parameter::Id id;
id.set<Parameter::Id::commonTag>(Parameter::common);
EXPECT_IS_OK(effect->getParameter(id, &get));
EXPECT_IS_OK(mEffect->getParameter(id, &get));
EXPECT_EQ(set, get) << set.toString() << " vs " << get.toString();
ASSERT_NO_FATAL_FAILURE(command(effect, CommandId::STOP));
ASSERT_NO_FATAL_FAILURE(close(effect));
ASSERT_NO_FATAL_FAILURE(destroy(mFactory, effect));
ASSERT_NO_FATAL_FAILURE(command(mEffect, CommandId::STOP));
ASSERT_NO_FATAL_FAILURE(close(mEffect));
ASSERT_NO_FATAL_FAILURE(destroy(mFactory, mEffect));
}
// Verify parameters set and get in IDLE state.
TEST_P(AudioEffectTest, SetAndGetParameterInIdle) {
std::shared_ptr<IEffect> effect;
ASSERT_NO_FATAL_FAILURE(create(mFactory, effect, mIdentity));
ASSERT_NO_FATAL_FAILURE(open(effect));
ASSERT_NO_FATAL_FAILURE(command(effect, CommandId::START));
ASSERT_NO_FATAL_FAILURE(expectState(effect, State::PROCESSING));
ASSERT_NO_FATAL_FAILURE(command(effect, CommandId::STOP));
ASSERT_NO_FATAL_FAILURE(expectState(effect, State::IDLE));
ASSERT_NO_FATAL_FAILURE(create(mFactory, mEffect, mDescriptor));
ASSERT_NO_FATAL_FAILURE(open(mEffect));
ASSERT_NO_FATAL_FAILURE(command(mEffect, CommandId::START));
ASSERT_NO_FATAL_FAILURE(expectState(mEffect, State::PROCESSING));
ASSERT_NO_FATAL_FAILURE(command(mEffect, CommandId::STOP));
ASSERT_NO_FATAL_FAILURE(expectState(mEffect, State::IDLE));
Parameter::Common common = EffectHelper::createParamCommon(
0 /* session */, 1 /* ioHandle */, 44100 /* iSampleRate */, 44100 /* oSampleRate */);
Parameter get = Parameter(), set = Parameter();
set.set<Parameter::common>(common);
EXPECT_IS_OK(effect->setParameter(set));
EXPECT_IS_OK(mEffect->setParameter(set));
Parameter::Id id;
id.set<Parameter::Id::commonTag>(Parameter::common);
EXPECT_IS_OK(effect->getParameter(id, &get));
EXPECT_IS_OK(mEffect->getParameter(id, &get));
EXPECT_EQ(set, get) << set.toString() << " vs " << get.toString();
ASSERT_NO_FATAL_FAILURE(close(effect));
ASSERT_NO_FATAL_FAILURE(destroy(mFactory, effect));
ASSERT_NO_FATAL_FAILURE(close(mEffect));
ASSERT_NO_FATAL_FAILURE(destroy(mFactory, mEffect));
}
// Verify Parameters kept after stop.
TEST_P(AudioEffectTest, SetAndGetParameterAfterStop) {
std::shared_ptr<IEffect> effect;
ASSERT_NO_FATAL_FAILURE(create(mFactory, effect, mIdentity));
ASSERT_NO_FATAL_FAILURE(open(effect));
ASSERT_NO_FATAL_FAILURE(command(effect, CommandId::START));
ASSERT_NO_FATAL_FAILURE(expectState(effect, State::PROCESSING));
ASSERT_NO_FATAL_FAILURE(create(mFactory, mEffect, mDescriptor));
ASSERT_NO_FATAL_FAILURE(open(mEffect));
ASSERT_NO_FATAL_FAILURE(command(mEffect, CommandId::START));
ASSERT_NO_FATAL_FAILURE(expectState(mEffect, State::PROCESSING));
Parameter::Common common = EffectHelper::createParamCommon(
0 /* session */, 1 /* ioHandle */, 44100 /* iSampleRate */, 44100 /* oSampleRate */);
Parameter get = Parameter(), set = Parameter();
set.set<Parameter::common>(common);
EXPECT_IS_OK(effect->setParameter(set));
EXPECT_IS_OK(mEffect->setParameter(set));
ASSERT_NO_FATAL_FAILURE(command(effect, CommandId::STOP));
ASSERT_NO_FATAL_FAILURE(expectState(effect, State::IDLE));
ASSERT_NO_FATAL_FAILURE(command(mEffect, CommandId::STOP));
ASSERT_NO_FATAL_FAILURE(expectState(mEffect, State::IDLE));
Parameter::Id id;
id.set<Parameter::Id::commonTag>(Parameter::common);
EXPECT_IS_OK(effect->getParameter(id, &get));
EXPECT_IS_OK(mEffect->getParameter(id, &get));
EXPECT_EQ(set, get) << set.toString() << " vs " << get.toString();
ASSERT_NO_FATAL_FAILURE(close(effect));
ASSERT_NO_FATAL_FAILURE(destroy(mFactory, effect));
ASSERT_NO_FATAL_FAILURE(close(mEffect));
ASSERT_NO_FATAL_FAILURE(destroy(mFactory, mEffect));
}
// Verify Parameters kept after reset.
TEST_P(AudioEffectTest, SetAndGetParameterAfterReset) {
std::shared_ptr<IEffect> effect;
ASSERT_NO_FATAL_FAILURE(create(mFactory, effect, mIdentity));
ASSERT_NO_FATAL_FAILURE(open(effect));
ASSERT_NO_FATAL_FAILURE(create(mFactory, mEffect, mDescriptor));
ASSERT_NO_FATAL_FAILURE(open(mEffect));
ASSERT_NO_FATAL_FAILURE(command(effect, CommandId::START));
ASSERT_NO_FATAL_FAILURE(expectState(effect, State::PROCESSING));
ASSERT_NO_FATAL_FAILURE(command(mEffect, CommandId::START));
ASSERT_NO_FATAL_FAILURE(expectState(mEffect, State::PROCESSING));
Parameter::Common common = EffectHelper::createParamCommon(
0 /* session */, 1 /* ioHandle */, 44100 /* iSampleRate */, 44100 /* oSampleRate */);
Parameter get = Parameter(), set = Parameter();
set.set<Parameter::common>(common);
EXPECT_IS_OK(effect->setParameter(set));
EXPECT_IS_OK(mEffect->setParameter(set));
ASSERT_NO_FATAL_FAILURE(command(effect, CommandId::RESET));
ASSERT_NO_FATAL_FAILURE(expectState(effect, State::IDLE));
ASSERT_NO_FATAL_FAILURE(command(mEffect, CommandId::RESET));
ASSERT_NO_FATAL_FAILURE(expectState(mEffect, State::IDLE));
Parameter::Id id;
id.set<Parameter::Id::commonTag>(Parameter::common);
EXPECT_IS_OK(effect->getParameter(id, &get));
EXPECT_IS_OK(mEffect->getParameter(id, &get));
EXPECT_EQ(set, get) << set.toString() << " vs " << get.toString();
ASSERT_NO_FATAL_FAILURE(close(effect));
ASSERT_NO_FATAL_FAILURE(destroy(mFactory, effect));
ASSERT_NO_FATAL_FAILURE(close(mEffect));
ASSERT_NO_FATAL_FAILURE(destroy(mFactory, mEffect));
}
/// Data processing test
// Send data to effects and expect it to be consumed by checking statusMQ.
TEST_P(AudioEffectTest, ConsumeDataInProcessingState) {
std::shared_ptr<IEffect> effect;
ASSERT_NO_FATAL_FAILURE(create(mFactory, effect, mIdentity));
ASSERT_NO_FATAL_FAILURE(create(mFactory, mEffect, mDescriptor));
Parameter::Common common = EffectHelper::createParamCommon(
0 /* session */, 1 /* ioHandle */, 44100 /* iSampleRate */, 44100 /* oSampleRate */,
kInputFrameCount /* iFrameCount */, kOutputFrameCount /* oFrameCount */);
IEffect::OpenEffectReturn ret;
ASSERT_NO_FATAL_FAILURE(open(effect, common, std::nullopt /* specific */, &ret, EX_NONE));
ASSERT_NO_FATAL_FAILURE(open(mEffect, common, std::nullopt /* specific */, &ret, EX_NONE));
auto statusMQ = std::make_unique<EffectHelper::StatusMQ>(ret.statusMQ);
ASSERT_TRUE(statusMQ->isValid());
auto inputMQ = std::make_unique<EffectHelper::DataMQ>(ret.inputDataMQ);
ASSERT_TRUE(inputMQ->isValid());
auto outputMQ = std::make_unique<EffectHelper::DataMQ>(ret.outputDataMQ);
ASSERT_TRUE(outputMQ->isValid());
ASSERT_NO_FATAL_FAILURE(command(effect, CommandId::START));
ASSERT_NO_FATAL_FAILURE(expectState(effect, State::PROCESSING));
ASSERT_NO_FATAL_FAILURE(command(mEffect, CommandId::START));
ASSERT_NO_FATAL_FAILURE(expectState(mEffect, State::PROCESSING));
std::vector<float> buffer;
EffectHelper::allocateInputData(common, inputMQ, buffer);
EffectHelper::writeToFmq(inputMQ, buffer);
EffectHelper::readFromFmq(statusMQ, 1, outputMQ, buffer.size(), buffer);
ASSERT_NO_FATAL_FAILURE(command(effect, CommandId::STOP));
ASSERT_NO_FATAL_FAILURE(expectState(effect, State::IDLE));
ASSERT_NO_FATAL_FAILURE(command(mEffect, CommandId::STOP));
ASSERT_NO_FATAL_FAILURE(expectState(mEffect, State::IDLE));
ASSERT_NO_FATAL_FAILURE(close(effect));
ASSERT_NO_FATAL_FAILURE(destroy(mFactory, effect));
ASSERT_NO_FATAL_FAILURE(close(mEffect));
ASSERT_NO_FATAL_FAILURE(destroy(mFactory, mEffect));
}
// Send data to effects and expect it to be consumed after effect restart.
TEST_P(AudioEffectTest, ConsumeDataAfterRestart) {
std::shared_ptr<IEffect> effect;
ASSERT_NO_FATAL_FAILURE(create(mFactory, effect, mIdentity));
ASSERT_NO_FATAL_FAILURE(create(mFactory, mEffect, mDescriptor));
Parameter::Common common = EffectHelper::createParamCommon(
0 /* session */, 1 /* ioHandle */, 44100 /* iSampleRate */, 44100 /* oSampleRate */,
kInputFrameCount /* iFrameCount */, kOutputFrameCount /* oFrameCount */);
IEffect::OpenEffectReturn ret;
ASSERT_NO_FATAL_FAILURE(open(effect, common, std::nullopt /* specific */, &ret, EX_NONE));
ASSERT_NO_FATAL_FAILURE(open(mEffect, common, std::nullopt /* specific */, &ret, EX_NONE));
auto statusMQ = std::make_unique<EffectHelper::StatusMQ>(ret.statusMQ);
ASSERT_TRUE(statusMQ->isValid());
auto inputMQ = std::make_unique<EffectHelper::DataMQ>(ret.inputDataMQ);
ASSERT_TRUE(inputMQ->isValid());
auto outputMQ = std::make_unique<EffectHelper::DataMQ>(ret.outputDataMQ);
ASSERT_TRUE(outputMQ->isValid());
ASSERT_NO_FATAL_FAILURE(command(effect, CommandId::START));
ASSERT_NO_FATAL_FAILURE(expectState(effect, State::PROCESSING));
ASSERT_NO_FATAL_FAILURE(command(effect, CommandId::STOP));
ASSERT_NO_FATAL_FAILURE(expectState(effect, State::IDLE));
ASSERT_NO_FATAL_FAILURE(command(effect, CommandId::START));
ASSERT_NO_FATAL_FAILURE(expectState(effect, State::PROCESSING));
ASSERT_NO_FATAL_FAILURE(command(mEffect, CommandId::START));
ASSERT_NO_FATAL_FAILURE(expectState(mEffect, State::PROCESSING));
ASSERT_NO_FATAL_FAILURE(command(mEffect, CommandId::STOP));
ASSERT_NO_FATAL_FAILURE(expectState(mEffect, State::IDLE));
ASSERT_NO_FATAL_FAILURE(command(mEffect, CommandId::START));
ASSERT_NO_FATAL_FAILURE(expectState(mEffect, State::PROCESSING));
std::vector<float> buffer;
EffectHelper::allocateInputData(common, inputMQ, buffer);
EffectHelper::writeToFmq(inputMQ, buffer);
EffectHelper::readFromFmq(statusMQ, 1, outputMQ, buffer.size(), buffer);
ASSERT_NO_FATAL_FAILURE(command(effect, CommandId::STOP));
ASSERT_NO_FATAL_FAILURE(expectState(effect, State::IDLE));
ASSERT_NO_FATAL_FAILURE(command(mEffect, CommandId::STOP));
ASSERT_NO_FATAL_FAILURE(expectState(mEffect, State::IDLE));
ASSERT_NO_FATAL_FAILURE(close(effect));
ASSERT_NO_FATAL_FAILURE(destroy(mFactory, effect));
ASSERT_NO_FATAL_FAILURE(close(mEffect));
ASSERT_NO_FATAL_FAILURE(destroy(mFactory, mEffect));
}
// Send data to IDLE effects and expect it to be consumed after effect start.
TEST_P(AudioEffectTest, SendDataAtIdleAndConsumeDataInProcessing) {
std::shared_ptr<IEffect> effect;
ASSERT_NO_FATAL_FAILURE(create(mFactory, effect, mIdentity));
ASSERT_NO_FATAL_FAILURE(create(mFactory, mEffect, mDescriptor));
Parameter::Common common = EffectHelper::createParamCommon(
0 /* session */, 1 /* ioHandle */, 44100 /* iSampleRate */, 44100 /* oSampleRate */,
kInputFrameCount /* iFrameCount */, kOutputFrameCount /* oFrameCount */);
IEffect::OpenEffectReturn ret;
ASSERT_NO_FATAL_FAILURE(open(effect, common, std::nullopt /* specific */, &ret, EX_NONE));
ASSERT_NO_FATAL_FAILURE(open(mEffect, common, std::nullopt /* specific */, &ret, EX_NONE));
auto statusMQ = std::make_unique<EffectHelper::StatusMQ>(ret.statusMQ);
ASSERT_TRUE(statusMQ->isValid());
auto inputMQ = std::make_unique<EffectHelper::DataMQ>(ret.inputDataMQ);
ASSERT_TRUE(inputMQ->isValid());
auto outputMQ = std::make_unique<EffectHelper::DataMQ>(ret.outputDataMQ);
ASSERT_TRUE(outputMQ->isValid());
std::vector<float> buffer;
EffectHelper::allocateInputData(common, inputMQ, buffer);
EffectHelper::writeToFmq(inputMQ, buffer);
EffectHelper::readFromFmq(statusMQ, 0, outputMQ, 0, buffer);
ASSERT_NO_FATAL_FAILURE(command(effect, CommandId::START));
ASSERT_NO_FATAL_FAILURE(expectState(effect, State::PROCESSING));
ASSERT_NO_FATAL_FAILURE(command(mEffect, CommandId::START));
ASSERT_NO_FATAL_FAILURE(expectState(mEffect, State::PROCESSING));
EffectHelper::readFromFmq(statusMQ, 1, outputMQ, buffer.size(), buffer);
ASSERT_NO_FATAL_FAILURE(command(effect, CommandId::STOP));
ASSERT_NO_FATAL_FAILURE(expectState(effect, State::IDLE));
ASSERT_NO_FATAL_FAILURE(command(mEffect, CommandId::STOP));
ASSERT_NO_FATAL_FAILURE(expectState(mEffect, State::IDLE));
ASSERT_NO_FATAL_FAILURE(close(effect));
ASSERT_NO_FATAL_FAILURE(destroy(mFactory, effect));
ASSERT_NO_FATAL_FAILURE(close(mEffect));
ASSERT_NO_FATAL_FAILURE(destroy(mFactory, mEffect));
}
// Send data multiple times.
TEST_P(AudioEffectTest, ProcessDataMultipleTimes) {
std::shared_ptr<IEffect> effect;
ASSERT_NO_FATAL_FAILURE(create(mFactory, effect, mIdentity));
ASSERT_NO_FATAL_FAILURE(create(mFactory, mEffect, mDescriptor));
Parameter::Common common = EffectHelper::createParamCommon(
0 /* session */, 1 /* ioHandle */, 44100 /* iSampleRate */, 44100 /* oSampleRate */,
kInputFrameCount /* iFrameCount */, kOutputFrameCount /* oFrameCount */);
IEffect::OpenEffectReturn ret;
ASSERT_NO_FATAL_FAILURE(open(effect, common, std::nullopt /* specific */, &ret, EX_NONE));
ASSERT_NO_FATAL_FAILURE(open(mEffect, common, std::nullopt /* specific */, &ret, EX_NONE));
auto statusMQ = std::make_unique<EffectHelper::StatusMQ>(ret.statusMQ);
ASSERT_TRUE(statusMQ->isValid());
auto inputMQ = std::make_unique<EffectHelper::DataMQ>(ret.inputDataMQ);
ASSERT_TRUE(inputMQ->isValid());
auto outputMQ = std::make_unique<EffectHelper::DataMQ>(ret.outputDataMQ);
ASSERT_TRUE(outputMQ->isValid());
std::vector<float> buffer;
EffectHelper::allocateInputData(common, inputMQ, buffer);
EffectHelper::writeToFmq(inputMQ, buffer);
EffectHelper::readFromFmq(statusMQ, 0, outputMQ, 0, buffer);
ASSERT_NO_FATAL_FAILURE(command(effect, CommandId::START));
ASSERT_NO_FATAL_FAILURE(expectState(effect, State::PROCESSING));
ASSERT_NO_FATAL_FAILURE(command(mEffect, CommandId::START));
ASSERT_NO_FATAL_FAILURE(expectState(mEffect, State::PROCESSING));
EffectHelper::readFromFmq(statusMQ, 1, outputMQ, buffer.size(), buffer);
// expect no status and data after consume
@ -634,77 +635,81 @@ TEST_P(AudioEffectTest, ProcessDataMultipleTimes) {
// expect no status and data after consume
EffectHelper::readFromFmq(statusMQ, 0, outputMQ, 0, buffer);
ASSERT_NO_FATAL_FAILURE(command(effect, CommandId::STOP));
ASSERT_NO_FATAL_FAILURE(expectState(effect, State::IDLE));
ASSERT_NO_FATAL_FAILURE(command(mEffect, CommandId::STOP));
ASSERT_NO_FATAL_FAILURE(expectState(mEffect, State::IDLE));
ASSERT_NO_FATAL_FAILURE(close(effect));
ASSERT_NO_FATAL_FAILURE(destroy(mFactory, effect));
ASSERT_NO_FATAL_FAILURE(close(mEffect));
ASSERT_NO_FATAL_FAILURE(destroy(mFactory, mEffect));
}
// Send data to IDLE state effects and expect it not be consumed.
TEST_P(AudioEffectTest, NotConsumeDataInIdleState) {
std::shared_ptr<IEffect> effect;
ASSERT_NO_FATAL_FAILURE(create(mFactory, effect, mIdentity));
ASSERT_NO_FATAL_FAILURE(create(mFactory, mEffect, mDescriptor));
Parameter::Common common = EffectHelper::createParamCommon(
0 /* session */, 1 /* ioHandle */, 44100 /* iSampleRate */, 44100 /* oSampleRate */,
kInputFrameCount /* iFrameCount */, kOutputFrameCount /* oFrameCount */);
IEffect::OpenEffectReturn ret;
ASSERT_NO_FATAL_FAILURE(open(effect, common, std::nullopt /* specific */, &ret, EX_NONE));
ASSERT_NO_FATAL_FAILURE(open(mEffect, common, std::nullopt /* specific */, &ret, EX_NONE));
auto statusMQ = std::make_unique<EffectHelper::StatusMQ>(ret.statusMQ);
ASSERT_TRUE(statusMQ->isValid());
auto inputMQ = std::make_unique<EffectHelper::DataMQ>(ret.inputDataMQ);
ASSERT_TRUE(inputMQ->isValid());
auto outputMQ = std::make_unique<EffectHelper::DataMQ>(ret.outputDataMQ);
ASSERT_TRUE(outputMQ->isValid());
ASSERT_NO_FATAL_FAILURE(command(effect, CommandId::START));
ASSERT_NO_FATAL_FAILURE(expectState(effect, State::PROCESSING));
ASSERT_NO_FATAL_FAILURE(command(effect, CommandId::STOP));
ASSERT_NO_FATAL_FAILURE(expectState(effect, State::IDLE));
ASSERT_NO_FATAL_FAILURE(command(mEffect, CommandId::START));
ASSERT_NO_FATAL_FAILURE(expectState(mEffect, State::PROCESSING));
ASSERT_NO_FATAL_FAILURE(command(mEffect, CommandId::STOP));
ASSERT_NO_FATAL_FAILURE(expectState(mEffect, State::IDLE));
std::vector<float> buffer;
EffectHelper::allocateInputData(common, inputMQ, buffer);
EffectHelper::writeToFmq(inputMQ, buffer);
EffectHelper::readFromFmq(statusMQ, 0, outputMQ, 0, buffer);
ASSERT_NO_FATAL_FAILURE(command(effect, CommandId::START));
ASSERT_NO_FATAL_FAILURE(expectState(effect, State::PROCESSING));
ASSERT_NO_FATAL_FAILURE(command(mEffect, CommandId::START));
ASSERT_NO_FATAL_FAILURE(expectState(mEffect, State::PROCESSING));
EffectHelper::readFromFmq(statusMQ, 1, outputMQ, buffer.size(), buffer);
ASSERT_NO_FATAL_FAILURE(command(effect, CommandId::STOP));
ASSERT_NO_FATAL_FAILURE(expectState(effect, State::IDLE));
ASSERT_NO_FATAL_FAILURE(command(mEffect, CommandId::STOP));
ASSERT_NO_FATAL_FAILURE(expectState(mEffect, State::IDLE));
ASSERT_NO_FATAL_FAILURE(close(effect));
ASSERT_NO_FATAL_FAILURE(destroy(mFactory, effect));
ASSERT_NO_FATAL_FAILURE(close(mEffect));
ASSERT_NO_FATAL_FAILURE(destroy(mFactory, mEffect));
}
// Send data to closed effects and expect it not be consumed.
TEST_P(AudioEffectTest, NotConsumeDataByClosedEffect) {
std::shared_ptr<IEffect> effect;
ASSERT_NO_FATAL_FAILURE(create(mFactory, effect, mIdentity));
ASSERT_NO_FATAL_FAILURE(create(mFactory, mEffect, mDescriptor));
Parameter::Common common = EffectHelper::createParamCommon(
0 /* session */, 1 /* ioHandle */, 44100 /* iSampleRate */, 44100 /* oSampleRate */,
kInputFrameCount /* iFrameCount */, kOutputFrameCount /* oFrameCount */);
IEffect::OpenEffectReturn ret;
ASSERT_NO_FATAL_FAILURE(open(effect, common, std::nullopt /* specific */, &ret, EX_NONE));
ASSERT_NO_FATAL_FAILURE(close(effect));
ASSERT_NO_FATAL_FAILURE(open(mEffect, common, std::nullopt /* specific */, &ret, EX_NONE));
ASSERT_NO_FATAL_FAILURE(close(mEffect));
auto statusMQ = std::make_unique<EffectHelper::StatusMQ>(ret.statusMQ);
ASSERT_TRUE(statusMQ->isValid());
auto inputMQ = std::make_unique<EffectHelper::DataMQ>(ret.inputDataMQ);
ASSERT_TRUE(inputMQ->isValid());
auto outputMQ = std::make_unique<EffectHelper::DataMQ>(ret.outputDataMQ);
ASSERT_TRUE(outputMQ->isValid());
std::vector<float> buffer;
EffectHelper::allocateInputData(common, inputMQ, buffer);
EffectHelper::writeToFmq(inputMQ, buffer);
EffectHelper::readFromFmq(statusMQ, 0, outputMQ, 0, buffer);
ASSERT_NO_FATAL_FAILURE(destroy(mFactory, effect));
ASSERT_NO_FATAL_FAILURE(destroy(mFactory, mEffect));
}
// Send data to multiple effects.
TEST_P(AudioEffectTest, ConsumeDataMultipleEffects) {
std::shared_ptr<IEffect> effect1, effect2;
ASSERT_NO_FATAL_FAILURE(create(mFactory, effect1, mIdentity));
ASSERT_NO_FATAL_FAILURE(create(mFactory, effect2, mIdentity));
ASSERT_NO_FATAL_FAILURE(create(mFactory, effect1, mDescriptor));
ASSERT_NO_FATAL_FAILURE(create(mFactory, effect2, mDescriptor));
Parameter::Common common1 = EffectHelper::createParamCommon(
0 /* session */, 1 /* ioHandle */, 44100 /* iSampleRate */, 44100 /* oSampleRate */,
@ -721,8 +726,11 @@ TEST_P(AudioEffectTest, ConsumeDataMultipleEffects) {
ASSERT_NO_FATAL_FAILURE(expectState(effect2, State::PROCESSING));
auto statusMQ1 = std::make_unique<EffectHelper::StatusMQ>(ret1.statusMQ);
ASSERT_TRUE(statusMQ1->isValid());
auto inputMQ1 = std::make_unique<EffectHelper::DataMQ>(ret1.inputDataMQ);
ASSERT_TRUE(inputMQ1->isValid());
auto outputMQ1 = std::make_unique<EffectHelper::DataMQ>(ret1.outputDataMQ);
ASSERT_TRUE(outputMQ1->isValid());
std::vector<float> buffer1, buffer2;
EffectHelper::allocateInputData(common1, inputMQ1, buffer1);
@ -730,8 +738,11 @@ TEST_P(AudioEffectTest, ConsumeDataMultipleEffects) {
EffectHelper::readFromFmq(statusMQ1, 1, outputMQ1, buffer1.size(), buffer1);
auto statusMQ2 = std::make_unique<EffectHelper::StatusMQ>(ret2.statusMQ);
ASSERT_TRUE(statusMQ2->isValid());
auto inputMQ2 = std::make_unique<EffectHelper::DataMQ>(ret2.inputDataMQ);
ASSERT_TRUE(inputMQ2->isValid());
auto outputMQ2 = std::make_unique<EffectHelper::DataMQ>(ret2.outputDataMQ);
ASSERT_TRUE(outputMQ2->isValid());
EffectHelper::allocateInputData(common2, inputMQ2, buffer2);
EffectHelper::writeToFmq(inputMQ2, buffer2);
EffectHelper::readFromFmq(statusMQ2, 1, outputMQ2, buffer2.size(), buffer2);
@ -752,9 +763,11 @@ INSTANTIATE_TEST_SUITE_P(
::testing::Combine(testing::ValuesIn(
EffectFactoryHelper::getAllEffectDescriptors(IFactory::descriptor))),
[](const testing::TestParamInfo<AudioEffectTest::ParamType>& info) {
auto instance = std::get<PARAM_INSTANCE_NAME>(info.param);
std::string name = "TYPE_" + instance.second.type.toString() + "_UUID_" +
instance.second.uuid.toString();
auto descriptor = std::get<PARAM_INSTANCE_NAME>(info.param).second;
std::string name = "Implementor_" + descriptor.common.implementor + "_name_" +
descriptor.common.name + "_TYPE_" +
descriptor.common.id.type.toString() + "_UUID_" +
descriptor.common.id.uuid.toString();
std::replace_if(
name.begin(), name.end(), [](const char c) { return !std::isalnum(c); }, '_');
return name;

View file

@ -37,8 +37,7 @@ using aidl::android::hardware::audio::effect::Parameter;
* VtsAudioEffectTargetTest.
*/
enum ParamName { PARAM_INSTANCE_NAME, PARAM_STRENGTH };
using BassBoostParamTestParam =
std::tuple<std::pair<std::shared_ptr<IFactory>, Descriptor::Identity>, int>;
using BassBoostParamTestParam = std::tuple<std::pair<std::shared_ptr<IFactory>, Descriptor>, int>;
/*
* Testing parameter range, assuming the parameter supported by effect is in this range.
@ -60,12 +59,12 @@ class BassBoostParamTest : public ::testing::TestWithParam<BassBoostParamTestPar
public EffectHelper {
public:
BassBoostParamTest() : mParamStrength(std::get<PARAM_STRENGTH>(GetParam())) {
std::tie(mFactory, mIdentity) = std::get<PARAM_INSTANCE_NAME>(GetParam());
std::tie(mFactory, mDescriptor) = std::get<PARAM_INSTANCE_NAME>(GetParam());
}
void SetUp() override {
ASSERT_NE(nullptr, mFactory);
ASSERT_NO_FATAL_FAILURE(create(mFactory, mEffect, mIdentity));
ASSERT_NO_FATAL_FAILURE(create(mFactory, mEffect, mDescriptor));
Parameter::Specific specific = getDefaultParamSpecific();
Parameter::Common common = EffectHelper::createParamCommon(
@ -91,7 +90,7 @@ class BassBoostParamTest : public ::testing::TestWithParam<BassBoostParamTestPar
static const long kInputFrameCount = 0x100, kOutputFrameCount = 0x100;
std::shared_ptr<IFactory> mFactory;
std::shared_ptr<IEffect> mEffect;
Descriptor::Identity mIdentity;
Descriptor mDescriptor;
int mParamStrength = BassBoost::MIN_PER_MILLE_STRENGTH;
void SetAndGetBassBoostParameters() {
@ -167,9 +166,11 @@ INSTANTIATE_TEST_SUITE_P(
IFactory::descriptor, kBassBoostTypeUUID)),
testing::ValuesIn(kStrengthValues)),
[](const testing::TestParamInfo<BassBoostParamTest::ParamType>& info) {
auto instance = std::get<PARAM_INSTANCE_NAME>(info.param);
auto descriptor = std::get<PARAM_INSTANCE_NAME>(info.param).second;
std::string strength = std::to_string(std::get<PARAM_STRENGTH>(info.param));
std::string name = instance.second.uuid.toString() + "_strength_" + strength;
std::string name = "Implementor_" + descriptor.common.implementor + "_name_" +
descriptor.common.name + "_UUID_" +
descriptor.common.id.uuid.toString() + "_strength_" + strength;
std::replace_if(
name.begin(), name.end(), [](const char c) { return !std::isalnum(c); }, '_');
return name;

View file

@ -57,8 +57,7 @@ using aidl::android::hardware::audio::effect::Parameter;
*/
enum ParamName { PARAM_INSTANCE_NAME, PARAM_BAND_LEVEL };
using EqualizerParamTestParam =
std::tuple<std::pair<std::shared_ptr<IFactory>, Descriptor::Identity>, int>;
using EqualizerParamTestParam = std::tuple<std::pair<std::shared_ptr<IFactory>, Descriptor>, int>;
/*
Testing parameter range, assuming the parameter supported by effect is in this range.
@ -71,12 +70,12 @@ class EqualizerTest : public ::testing::TestWithParam<EqualizerParamTestParam>,
public EffectHelper {
public:
EqualizerTest() : mBandLevel(std::get<PARAM_BAND_LEVEL>(GetParam())) {
std::tie(mFactory, mIdentity) = std::get<PARAM_INSTANCE_NAME>(GetParam());
std::tie(mFactory, mDescriptor) = std::get<PARAM_INSTANCE_NAME>(GetParam());
}
void SetUp() override {
ASSERT_NE(nullptr, mFactory);
ASSERT_NO_FATAL_FAILURE(create(mFactory, mEffect, mIdentity));
ASSERT_NO_FATAL_FAILURE(create(mFactory, mEffect, mDescriptor));
Parameter::Specific specific = getDefaultParamSpecific();
Parameter::Common common = EffectHelper::createParamCommon(
@ -115,7 +114,7 @@ class EqualizerTest : public ::testing::TestWithParam<EqualizerParamTestParam>,
static const long kInputFrameCount = 0x100, kOutputFrameCount = 0x100;
std::shared_ptr<IFactory> mFactory;
std::shared_ptr<IEffect> mEffect;
Descriptor::Identity mIdentity;
Descriptor mDescriptor;
std::pair<int, int> mPresetIndex;
std::pair<int, int> mBandIndex;
const int mBandLevel;
@ -327,9 +326,11 @@ INSTANTIATE_TEST_SUITE_P(
IFactory::descriptor, kEqualizerTypeUUID)),
testing::ValuesIn(kBandLevels)),
[](const testing::TestParamInfo<EqualizerTest::ParamType>& info) {
auto instance = std::get<PARAM_INSTANCE_NAME>(info.param);
auto descriptor = std::get<PARAM_INSTANCE_NAME>(info.param).second;
std::string bandLevel = std::to_string(std::get<PARAM_BAND_LEVEL>(info.param));
std::string name = instance.second.uuid.toString() + "_bandLevel_" + bandLevel;
std::string name = "Implementor_" + descriptor.common.implementor + "_name_" +
descriptor.common.name + "_UUID_" +
descriptor.common.id.uuid.toString() + "_bandLevel_" + bandLevel;
std::replace_if(
name.begin(), name.end(), [](const char c) { return !std::isalnum(c); }, '_');
return name;

View file

@ -38,7 +38,7 @@ using aidl::android::hardware::audio::effect::Parameter;
*/
enum ParamName { PARAM_INSTANCE_NAME, PARAM_GAIN_MB };
using LoudnessEnhancerParamTestParam =
std::tuple<std::pair<std::shared_ptr<IFactory>, Descriptor::Identity>, int>;
std::tuple<std::pair<std::shared_ptr<IFactory>, Descriptor>, int>;
// Every int 32 bit value is a valid gain, so testing the corner cases and one regular value.
// TODO : Update the test values once range/capability is updated by implementation.
@ -49,12 +49,12 @@ class LoudnessEnhancerParamTest : public ::testing::TestWithParam<LoudnessEnhanc
public EffectHelper {
public:
LoudnessEnhancerParamTest() : mParamGainMb(std::get<PARAM_GAIN_MB>(GetParam())) {
std::tie(mFactory, mIdentity) = std::get<PARAM_INSTANCE_NAME>(GetParam());
std::tie(mFactory, mDescriptor) = std::get<PARAM_INSTANCE_NAME>(GetParam());
}
void SetUp() override {
ASSERT_NE(nullptr, mFactory);
ASSERT_NO_FATAL_FAILURE(create(mFactory, mEffect, mIdentity));
ASSERT_NO_FATAL_FAILURE(create(mFactory, mEffect, mDescriptor));
Parameter::Specific specific = getDefaultParamSpecific();
Parameter::Common common = EffectHelper::createParamCommon(
@ -79,7 +79,7 @@ class LoudnessEnhancerParamTest : public ::testing::TestWithParam<LoudnessEnhanc
static const long kInputFrameCount = 0x100, kOutputFrameCount = 0x100;
std::shared_ptr<IFactory> mFactory;
std::shared_ptr<IEffect> mEffect;
Descriptor::Identity mIdentity;
Descriptor mDescriptor;
int mParamGainMb = 0;
void SetAndGetParameters() {
@ -130,9 +130,11 @@ INSTANTIATE_TEST_SUITE_P(
IFactory::descriptor, kLoudnessEnhancerTypeUUID)),
testing::ValuesIn(kGainMbValues)),
[](const testing::TestParamInfo<LoudnessEnhancerParamTest::ParamType>& info) {
auto instance = std::get<PARAM_INSTANCE_NAME>(info.param);
auto descriptor = std::get<PARAM_INSTANCE_NAME>(info.param).second;
std::string gainMb = std::to_string(std::get<PARAM_GAIN_MB>(info.param));
std::string name = instance.second.uuid.toString() + "_gainMb_" + gainMb;
std::string name = "Implementor_" + descriptor.common.implementor + "_name_" +
descriptor.common.name + "_UUID_" +
descriptor.common.id.uuid.toString() + "_gainMb_" + gainMb;
std::replace_if(
name.begin(), name.end(), [](const char c) { return !std::isalnum(c); }, '_');
return name;