Effect AIDL: Refactor effect capability with Range vts test cases am: 0a0c45efa4 am: 4a2d3b97b8

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

Change-Id: Id254031dfba3e3c2a78b1d640addecf1eb86cb0d
Signed-off-by: Automerger Merge Worker <android-build-automerger-merge-worker@system.gserviceaccount.com>
This commit is contained in:
Shunkai Yao 2023-02-15 01:27:20 +00:00 committed by Automerger Merge Worker
commit ddcee8613c
16 changed files with 249 additions and 1068 deletions

View file

@ -12,9 +12,6 @@
{
"name": "VtsHalDownmixTargetTest"
},
{
"name": "VtsHalDynamicsProcessingTargetTest"
},
{
"name": "VtsHalEnvironmentalReverbTargetTest"
},

View file

@ -19,6 +19,7 @@
#include <algorithm>
#include <memory>
#include <string>
#include <type_traits>
#include <unordered_map>
#include <vector>
@ -27,6 +28,7 @@
#include <aidl/android/media/audio/common/AudioChannelLayout.h>
#include <android/binder_auto_utils.h>
#include <fmq/AidlMessageQueue.h>
#include <system/audio_effects/aidl_effects_utils.h>
#include "AudioHalBinderServiceUtil.h"
#include "EffectFactoryHelper.h"
@ -37,6 +39,7 @@ using aidl::android::hardware::audio::effect::CommandId;
using aidl::android::hardware::audio::effect::Descriptor;
using aidl::android::hardware::audio::effect::IEffect;
using aidl::android::hardware::audio::effect::Parameter;
using aidl::android::hardware::audio::effect::Range;
using aidl::android::hardware::audio::effect::State;
using aidl::android::hardware::common::fmq::SynchronizedReadWrite;
using aidl::android::media::audio::common::AudioChannelLayout;
@ -205,4 +208,58 @@ class EffectHelper {
std::unique_ptr<DataMQ> inputMQ;
std::unique_ptr<DataMQ> outputMQ;
};
template <typename T, Range::Tag tag>
static bool isParameterValid(const T& target, const Descriptor& desc) {
if (desc.capability.range.getTag() != tag) {
return true;
}
const auto& ranges = desc.capability.range.get<tag>();
return inRange(target, ranges);
}
/**
* Add to test value set: (min+max)/2, minimum/maximum numeric limits, and min-1/max+1 if
* result still in numeric limits after -1/+1.
* Only use this when the type of test value is basic type (std::is_arithmetic return true).
*/
template <typename S, typename = std::enable_if_t<std::is_arithmetic_v<S>>>
static std::set<S> expandTestValueBasic(std::set<S>& s) {
const auto min = *s.begin(), max = *s.rbegin();
const auto minLimit = std::numeric_limits<S>::min(),
maxLimit = std::numeric_limits<S>::max();
if (s.size()) {
s.insert(min + (max - min) / 2);
if (min != minLimit) {
s.insert(min - 1);
}
if (max != maxLimit) {
s.insert(max + 1);
}
}
s.insert(minLimit);
s.insert(maxLimit);
return s;
}
template <typename T, typename S, Range::Tag R, typename T::Tag tag, typename Functor>
static std::set<S> getTestValueSet(
std::vector<std::pair<std::shared_ptr<IFactory>, Descriptor>> kFactoryDescList,
Functor functor) {
std::set<S> result;
for (const auto& [_, desc] : kFactoryDescList) {
if (desc.capability.range.getTag() == R) {
const auto& ranges = desc.capability.range.get<R>();
for (const auto& range : ranges) {
if (range.min.getTag() == tag) {
result.insert(range.min.template get<tag>());
}
if (range.max.getTag() == tag) {
result.insert(range.max.template get<tag>());
}
}
}
}
return functor(result);
}
};

View file

@ -23,16 +23,17 @@
#define LOG_TAG "VtsHalAECParamTest"
#include "EffectHelper.h"
#include "effect-impl/EffectTypes.h"
using namespace android;
using aidl::android::hardware::audio::effect::AcousticEchoCanceler;
using aidl::android::hardware::audio::effect::Capability;
using aidl::android::hardware::audio::effect::Descriptor;
using aidl::android::hardware::audio::effect::IEffect;
using aidl::android::hardware::audio::effect::IFactory;
using aidl::android::hardware::audio::effect::kAcousticEchoCancelerTypeUUID;
using aidl::android::hardware::audio::effect::Parameter;
using aidl::android::hardware::audio::effect::Range;
enum ParamName { PARAM_INSTANCE_NAME, PARAM_ECHO_DELAY, PARAM_MOBILE_MODE };
using AECParamTestParam = std::tuple<std::pair<std::shared_ptr<IFactory>, Descriptor>,
@ -87,7 +88,8 @@ class AECParamTest : public ::testing::TestWithParam<AECParamTestParam>, public
// validate parameter
Descriptor desc;
ASSERT_STATUS(EX_NONE, mEffect->getDescriptor(&desc));
const bool valid = isTagInRange(tag, aec, desc);
const bool valid =
isParameterValid<AcousticEchoCanceler, Range::acousticEchoCanceler>(aec, desc);
const binder_exception_t expected = valid ? EX_NONE : EX_ILLEGAL_ARGUMENT;
// set parameter
@ -124,54 +126,6 @@ class AECParamTest : public ::testing::TestWithParam<AECParamTestParam>, public
mTags.push_back({AcousticEchoCanceler::mobileMode, aec});
}
bool isTagInRange(const AcousticEchoCanceler::Tag& tag, const AcousticEchoCanceler& aec,
const Descriptor& desc) const {
const AcousticEchoCanceler::Capability& aecCap =
desc.capability.get<Capability::acousticEchoCanceler>();
switch (tag) {
case AcousticEchoCanceler::echoDelayUs: {
return isEchoDelayInRange(aecCap, aec.get<AcousticEchoCanceler::echoDelayUs>());
}
case AcousticEchoCanceler::mobileMode: {
bool mode = aec.get<AcousticEchoCanceler::mobileMode>();
return isMobileModeValid(aecCap, mode);
}
default:
return false;
}
}
bool isEchoDelayInRange(const AcousticEchoCanceler::Capability& cap, int delay) const {
return (delay >= 0 && delay <= cap.maxEchoDelayUs);
}
bool isMobileModeValid(const AcousticEchoCanceler::Capability& cap, bool mode) const {
if (cap.supportMobileMode) {
return true;
} else {
return mode == false;
}
}
static std::unordered_set<int> getEchoDelayTestValues() {
auto descList = EffectFactoryHelper::getAllEffectDescriptors(IFactory::descriptor,
kAcousticEchoCancelerTypeUUID);
const auto max = std::max_element(
descList.begin(), descList.end(),
[](const std::pair<std::shared_ptr<IFactory>, Descriptor>& a,
const std::pair<std::shared_ptr<IFactory>, Descriptor>& b) {
return a.second.capability.get<Capability::acousticEchoCanceler>()
.maxEchoDelayUs <
b.second.capability.get<Capability::acousticEchoCanceler>()
.maxEchoDelayUs;
});
if (max == descList.end()) {
return {0};
}
int maxDelay =
max->second.capability.get<Capability::acousticEchoCanceler>().maxEchoDelayUs;
return {-1, 0, maxDelay - 1, maxDelay, maxDelay + 1};
}
static std::unordered_set<bool> getMobileModeValues() { return {true, false}; }
private:
@ -189,12 +143,20 @@ TEST_P(AECParamTest, SetAndGetMobileMode) {
SetAndGetParameters();
}
std::vector<std::pair<std::shared_ptr<IFactory>, Descriptor>> kDescPair;
INSTANTIATE_TEST_SUITE_P(
AECParamTest, AECParamTest,
::testing::Combine(testing::ValuesIn(EffectFactoryHelper::getAllEffectDescriptors(
IFactory::descriptor, kAcousticEchoCancelerTypeUUID)),
testing::ValuesIn(AECParamTest::getEchoDelayTestValues()),
testing::ValuesIn(AECParamTest::getMobileModeValues())),
::testing::Combine(
testing::ValuesIn(kDescPair = EffectFactoryHelper::getAllEffectDescriptors(
IFactory::descriptor, kAcousticEchoCancelerTypeUUID)),
testing::ValuesIn(EffectHelper::getTestValueSet<AcousticEchoCanceler, int,
Range::acousticEchoCanceler,
AcousticEchoCanceler::echoDelayUs>(
kDescPair, EffectHelper::expandTestValueBasic<int>)),
testing::ValuesIn(EffectHelper::getTestValueSet<AcousticEchoCanceler, bool,
Range::acousticEchoCanceler,
AcousticEchoCanceler::mobileMode>(
kDescPair, EffectHelper::expandTestValueBasic<bool>))),
[](const testing::TestParamInfo<AECParamTest::ParamType>& info) {
auto descriptor = std::get<PARAM_INSTANCE_NAME>(info.param).second;
std::string echoDelay = std::to_string(std::get<PARAM_ECHO_DELAY>(info.param));

View file

@ -26,7 +26,6 @@
using namespace android;
using aidl::android::hardware::audio::effect::AutomaticGainControl;
using aidl::android::hardware::audio::effect::Capability;
using aidl::android::hardware::audio::effect::Descriptor;
using aidl::android::hardware::audio::effect::IEffect;
using aidl::android::hardware::audio::effect::IFactory;
@ -94,7 +93,8 @@ class AGCParamTest : public ::testing::TestWithParam<AGCParamTestParam>, public
// validate parameter
Descriptor desc;
ASSERT_STATUS(EX_NONE, mEffect->getDescriptor(&desc));
const bool valid = isTagInRange(tag, AGC, desc);
const bool valid =
isParameterValid<AutomaticGainControl, Range::automaticGainControl>(AGC, desc);
const binder_exception_t expected = valid ? EX_NONE : EX_ILLEGAL_ARGUMENT;
// set parameter
@ -135,65 +135,7 @@ class AGCParamTest : public ::testing::TestWithParam<AGCParamTestParam>, public
mTags.push_back({AutomaticGainControl::levelEstimator, AGC});
}
bool isTagInRange(const AutomaticGainControl::Tag& tag, const AutomaticGainControl& AGC,
const Descriptor& desc) const {
const AutomaticGainControl::Capability& AGCCap =
desc.capability.get<Capability::automaticGainControl>();
switch (tag) {
case AutomaticGainControl::fixedDigitalGainMb: {
auto gain = AGC.get<AutomaticGainControl::fixedDigitalGainMb>();
return gain >= 0 && gain <= AGCCap.maxFixedDigitalGainMb;
}
case AutomaticGainControl::levelEstimator: {
return true;
}
case AutomaticGainControl::saturationMarginMb: {
auto margin = AGC.get<AutomaticGainControl::saturationMarginMb>();
return margin >= 0 && margin <= AGCCap.maxSaturationMarginMb;
}
default:
return false;
}
}
static std::unordered_set<int> getDigitalGainValues() {
auto descList = EffectFactoryHelper::getAllEffectDescriptors(IFactory::descriptor,
kAutomaticGainControlTypeUUID);
const auto max = std::max_element(
descList.begin(), descList.end(),
[](const std::pair<std::shared_ptr<IFactory>, Descriptor>& a,
const std::pair<std::shared_ptr<IFactory>, Descriptor>& b) {
return a.second.capability.get<Capability::automaticGainControl>()
.maxFixedDigitalGainMb <
b.second.capability.get<Capability::automaticGainControl>()
.maxFixedDigitalGainMb;
});
if (max == descList.end()) {
return {0};
}
int maxGain = max->second.capability.get<Capability::automaticGainControl>()
.maxFixedDigitalGainMb;
return {-1, 0, maxGain - 1, maxGain, maxGain + 1};
}
static std::unordered_set<int> getSaturationMarginValues() {
auto descList = EffectFactoryHelper::getAllEffectDescriptors(IFactory::descriptor,
kAutomaticGainControlTypeUUID);
const auto max = std::max_element(
descList.begin(), descList.end(),
[](const std::pair<std::shared_ptr<IFactory>, Descriptor>& a,
const std::pair<std::shared_ptr<IFactory>, Descriptor>& b) {
return a.second.capability.get<Capability::automaticGainControl>()
.maxSaturationMarginMb <
b.second.capability.get<Capability::automaticGainControl>()
.maxSaturationMarginMb;
});
if (max == descList.end()) {
return {0};
}
int maxMargin = max->second.capability.get<Capability::automaticGainControl>()
.maxSaturationMarginMb;
return {-1, 0, maxMargin - 1, maxMargin, maxMargin + 1};
}
static std::unordered_set<AutomaticGainControl::LevelEstimator> getLevelEstimatorValues() {
static std::set<AutomaticGainControl::LevelEstimator> getLevelEstimatorValues() {
return {ndk::enum_range<AutomaticGainControl::LevelEstimator>().begin(),
ndk::enum_range<AutomaticGainControl::LevelEstimator>().end()};
}
@ -218,13 +160,21 @@ TEST_P(AGCParamTest, SetAndGetLevelEstimator) {
SetAndGetParameters();
}
std::vector<std::pair<std::shared_ptr<IFactory>, Descriptor>> kDescPair;
INSTANTIATE_TEST_SUITE_P(
AGCParamTest, AGCParamTest,
::testing::Combine(testing::ValuesIn(EffectFactoryHelper::getAllEffectDescriptors(
IFactory::descriptor, kAutomaticGainControlTypeUUID)),
testing::ValuesIn(AGCParamTest::getDigitalGainValues()),
testing::ValuesIn(AGCParamTest::getSaturationMarginValues()),
testing::ValuesIn(AGCParamTest::getLevelEstimatorValues())),
::testing::Combine(
testing::ValuesIn(kDescPair = EffectFactoryHelper::getAllEffectDescriptors(
IFactory::descriptor, kAutomaticGainControlTypeUUID)),
testing::ValuesIn(EffectHelper::getTestValueSet<
AutomaticGainControl, int, Range::automaticGainControl,
AutomaticGainControl::fixedDigitalGainMb>(
kDescPair, EffectHelper::expandTestValueBasic<int>)),
testing::ValuesIn(EffectHelper::getTestValueSet<
AutomaticGainControl, int, Range::automaticGainControl,
AutomaticGainControl::saturationMarginMb>(
kDescPair, EffectHelper::expandTestValueBasic<int>)),
testing::ValuesIn(AGCParamTest::getLevelEstimatorValues())),
[](const testing::TestParamInfo<AGCParamTest::ParamType>& info) {
auto descriptor = std::get<PARAM_INSTANCE_NAME>(info.param).second;
std::string gain = std::to_string(std::get<PARAM_DIGITAL_GAIN>(info.param));

View file

@ -31,6 +31,7 @@ using aidl::android::hardware::audio::effect::IEffect;
using aidl::android::hardware::audio::effect::IFactory;
using aidl::android::hardware::audio::effect::kBassBoostTypeUUID;
using aidl::android::hardware::audio::effect::Parameter;
using aidl::android::hardware::audio::effect::Range;
/**
* Here we focus on specific parameter checking, general IEffect interfaces testing performed in
@ -92,7 +93,7 @@ class BassBoostParamTest : public ::testing::TestWithParam<BassBoostParamTestPar
// validate parameter
Descriptor desc;
ASSERT_STATUS(EX_NONE, mEffect->getDescriptor(&desc));
const bool valid = isTagInRange(it.first, it.second, desc);
const bool valid = isParameterValid<BassBoost, Range::bassBoost>(it.second, desc);
const binder_exception_t expected = valid ? EX_NONE : EX_ILLEGAL_ARGUMENT;
// set parameter
@ -122,46 +123,6 @@ class BassBoostParamTest : public ::testing::TestWithParam<BassBoostParamTestPar
mTags.push_back({BassBoost::strengthPm, bb});
}
bool isTagInRange(const BassBoost::Tag& tag, const BassBoost& bb,
const Descriptor& desc) const {
const BassBoost::Capability& bbCap = desc.capability.get<Capability::bassBoost>();
switch (tag) {
case BassBoost::strengthPm: {
int strength = bb.get<BassBoost::strengthPm>();
return isStrengthInRange(bbCap, strength);
}
default:
return false;
}
return false;
}
bool isStrengthInRange(const BassBoost::Capability& cap, int strength) const {
return cap.strengthSupported && strength >= 0 && strength <= cap.maxStrengthPm;
}
static std::vector<int> getStrengthTestValues(
std::vector<std::pair<std::shared_ptr<IFactory>, Descriptor>> kFactoryDescList) {
const auto max = std::max_element(
kFactoryDescList.begin(), kFactoryDescList.end(),
[](const std::pair<std::shared_ptr<IFactory>, Descriptor>& a,
const std::pair<std::shared_ptr<IFactory>, Descriptor>& b) {
return a.second.capability.get<Capability::bassBoost>().maxStrengthPm <
b.second.capability.get<Capability::bassBoost>().maxStrengthPm;
});
if (max == kFactoryDescList.end()) {
return {0};
}
int maxStrength = max->second.capability.get<Capability::bassBoost>().maxStrengthPm;
return {std::numeric_limits<int>::min(),
-1,
0,
maxStrength >> 1,
maxStrength,
maxStrength + 1,
std::numeric_limits<int>::max()};
}
private:
std::vector<std::pair<BassBoost::Tag, BassBoost>> mTags;
void CleanUp() { mTags.clear(); }
@ -172,14 +133,15 @@ TEST_P(BassBoostParamTest, SetAndGetStrength) {
SetAndGetBassBoostParameters();
}
std::vector<std::pair<std::shared_ptr<IFactory>, Descriptor>> kDescPair;
INSTANTIATE_TEST_SUITE_P(
BassBoostTest, BassBoostParamTest,
::testing::Combine(
testing::ValuesIn(EffectFactoryHelper::getAllEffectDescriptors(IFactory::descriptor,
kBassBoostTypeUUID)),
testing::ValuesIn(BassBoostParamTest::getStrengthTestValues(
EffectFactoryHelper::getAllEffectDescriptors(IFactory::descriptor,
kBassBoostTypeUUID)))),
testing::ValuesIn(kDescPair = EffectFactoryHelper::getAllEffectDescriptors(
IFactory::descriptor, kBassBoostTypeUUID)),
testing::ValuesIn(EffectHelper::getTestValueSet<BassBoost, int, Range::bassBoost,
BassBoost::strengthPm>(
kDescPair, EffectHelper::expandTestValueBasic<int>))),
[](const testing::TestParamInfo<BassBoostParamTest::ParamType>& info) {
auto descriptor = std::get<PARAM_INSTANCE_NAME>(info.param).second;
std::string strength = std::to_string(std::get<PARAM_STRENGTH>(info.param));

View file

@ -22,7 +22,6 @@
using namespace android;
using aidl::android::hardware::audio::effect::Capability;
using aidl::android::hardware::audio::effect::Descriptor;
using aidl::android::hardware::audio::effect::Downmix;
using aidl::android::hardware::audio::effect::IEffect;

View file

@ -28,7 +28,6 @@
using namespace android;
using aidl::android::hardware::audio::effect::Capability;
using aidl::android::hardware::audio::effect::Descriptor;
using aidl::android::hardware::audio::effect::DynamicsProcessing;
using aidl::android::hardware::audio::effect::IEffect;
@ -82,31 +81,8 @@ class DynamicsProcessingTestHelper : public EffectHelper {
}
// utils functions for parameter checking
bool isParamValid(const DynamicsProcessing::Tag& tag, const DynamicsProcessing& dp,
const Descriptor& desc);
bool isParamEqual(const DynamicsProcessing::Tag& tag, const DynamicsProcessing& dpRef,
const DynamicsProcessing& dpTest);
bool isEnablementValid(const DynamicsProcessing::StageEnablement& enablement);
bool isEngineConfigValid(const DynamicsProcessing::EngineArchitecture& cfg);
bool isCutoffFrequencyValid(float freq, const DynamicsProcessing::Capability& cap);
bool isChannelConfigValid(const std::vector<DynamicsProcessing::ChannelConfig>& cfgs,
bool stageInUse);
bool isPreEqBandConfigValid(const DynamicsProcessing::Capability& cap,
const std::vector<DynamicsProcessing::EqBandConfig>& cfgs,
bool stageInUse, int bandCount);
bool isPostEqBandConfigValid(const DynamicsProcessing::Capability& cap,
const std::vector<DynamicsProcessing::EqBandConfig>& cfgs,
bool stageInUse, int bandCount);
bool isMbcBandConfigValid(const DynamicsProcessing::Capability& cap,
const std::vector<DynamicsProcessing::MbcBandConfig>& cfgs,
bool stageInUse, int bandCount);
bool isLimiterConfigValid(const std::vector<DynamicsProcessing::LimiterConfig>& cfgs,
bool stageInUse);
bool isInputGainValid(const std::vector<DynamicsProcessing::InputGain>& cfgs);
bool isEngineConfigEqual(const DynamicsProcessing::EngineArchitecture& refCfg,
const DynamicsProcessing::EngineArchitecture& testCfg);
@ -201,56 +177,6 @@ const std::set<std::vector<DynamicsProcessing::InputGain>>
{{.channel = -1, .gainDb = 10.f}, {.channel = 0, .gainDb = -10.f}}};
bool DynamicsProcessingTestHelper::isParamValid(const DynamicsProcessing::Tag& tag,
const DynamicsProcessing& dp,
const Descriptor& desc) {
const DynamicsProcessing::Capability& dpCap =
desc.capability.get<Capability::dynamicsProcessing>();
switch (tag) {
case DynamicsProcessing::engineArchitecture: {
return isEngineConfigValid(dp.get<DynamicsProcessing::engineArchitecture>());
}
case DynamicsProcessing::preEq: {
return isChannelConfigValid(dp.get<DynamicsProcessing::preEq>(),
mEngineConfigApplied.preEqStage.inUse);
}
case DynamicsProcessing::postEq: {
return isChannelConfigValid(dp.get<DynamicsProcessing::postEq>(),
mEngineConfigApplied.postEqStage.inUse);
}
case DynamicsProcessing::mbc: {
return isChannelConfigValid(dp.get<DynamicsProcessing::mbc>(),
mEngineConfigApplied.mbcStage.inUse);
}
case DynamicsProcessing::preEqBand: {
return isPreEqBandConfigValid(dpCap, dp.get<DynamicsProcessing::preEqBand>(),
mEngineConfigApplied.preEqStage.inUse,
mEngineConfigApplied.preEqStage.bandCount);
}
case DynamicsProcessing::postEqBand: {
return isPostEqBandConfigValid(dpCap, dp.get<DynamicsProcessing::postEqBand>(),
mEngineConfigApplied.postEqStage.inUse,
mEngineConfigApplied.postEqStage.bandCount);
}
case DynamicsProcessing::mbcBand: {
return isMbcBandConfigValid(dpCap, dp.get<DynamicsProcessing::mbcBand>(),
mEngineConfigApplied.mbcStage.inUse,
mEngineConfigApplied.mbcStage.bandCount);
}
case DynamicsProcessing::limiter: {
return isLimiterConfigValid(dp.get<DynamicsProcessing::limiter>(),
mEngineConfigApplied.limiterInUse);
}
case DynamicsProcessing::inputGain: {
return isInputGainValid(dp.get<DynamicsProcessing::inputGain>());
}
case DynamicsProcessing::vendorExtension: {
return true;
}
}
return true;
}
bool DynamicsProcessingTestHelper::isParamEqual(const DynamicsProcessing::Tag& tag,
const DynamicsProcessing& dpRef,
const DynamicsProcessing& dpTest) {
@ -304,117 +230,6 @@ bool DynamicsProcessingTestHelper::isParamEqual(const DynamicsProcessing::Tag& t
}
}
bool DynamicsProcessingTestHelper::isEnablementValid(
const DynamicsProcessing::StageEnablement& enablement) {
return !enablement.inUse || (enablement.inUse && enablement.bandCount > 0);
}
bool DynamicsProcessingTestHelper::isEngineConfigValid(
const DynamicsProcessing::EngineArchitecture& cfg) {
return cfg.preferredProcessingDurationMs >= 0 && isEnablementValid(cfg.preEqStage) &&
isEnablementValid(cfg.postEqStage) && isEnablementValid(cfg.mbcStage);
}
bool DynamicsProcessingTestHelper::isChannelConfigValid(
const std::vector<DynamicsProcessing::ChannelConfig>& cfgs, bool stageInUse) {
std::unordered_set<int> channelSet;
if (!stageInUse) return false;
for (auto cfg : cfgs) {
if (cfg.channel < 0 || cfg.channel >= mChannelCount || 0 != channelSet.count(cfg.channel)) {
return false;
}
channelSet.insert(cfg.channel);
}
return true;
}
bool DynamicsProcessingTestHelper::isCutoffFrequencyValid(
float freq, const DynamicsProcessing::Capability& cap) {
return freq >= cap.minCutOffFreq && freq <= cap.maxCutOffFreq;
}
bool DynamicsProcessingTestHelper::isPreEqBandConfigValid(
const DynamicsProcessing::Capability& cap,
const std::vector<DynamicsProcessing::EqBandConfig>& cfgs, bool stageInUse, int bandCount) {
std::set<std::pair<int /* channelID */, int /* bandID */>> bandSet;
if (!stageInUse) return false;
for (auto cfg : cfgs) {
if (0 == mPreEqChannelEnable.count(cfg.channel) || cfg.channel < 0 ||
cfg.channel >= mChannelCount || cfg.band < 0 || cfg.band >= bandCount ||
!isCutoffFrequencyValid(cfg.cutoffFrequencyHz, cap) ||
0 != bandSet.count({cfg.channel, cfg.band})) {
return false;
}
bandSet.insert({cfg.channel, cfg.band});
}
return true;
}
bool DynamicsProcessingTestHelper::isPostEqBandConfigValid(
const DynamicsProcessing::Capability& cap,
const std::vector<DynamicsProcessing::EqBandConfig>& cfgs, bool stageInUse, int bandCount) {
std::set<std::pair<int /* channelID */, int /* bandID */>> bandSet;
// not able to set/get parameter when stage not in use.
if (!stageInUse) return false;
for (auto cfg : cfgs) {
if (0 == mPostEqChannelEnable.count(cfg.channel) || cfg.channel < 0 ||
cfg.channel >= mChannelCount || cfg.band < 0 || cfg.band >= bandCount ||
!isCutoffFrequencyValid(cfg.cutoffFrequencyHz, cap) ||
0 != bandSet.count({cfg.channel, cfg.band})) {
return false;
}
bandSet.insert({cfg.channel, cfg.band});
}
return true;
}
bool DynamicsProcessingTestHelper::isMbcBandConfigValid(
const DynamicsProcessing::Capability& cap,
const std::vector<DynamicsProcessing::MbcBandConfig>& cfgs, bool stageInUse,
int bandCount) {
std::set<std::pair<int /* channelID */, int /* bandID */>> bandSet;
if (!stageInUse) return false;
for (auto cfg : cfgs) {
if (0 == mMbcChannelEnable.count(cfg.channel) || cfg.channel < 0 ||
cfg.channel >= mChannelCount || cfg.band < 0 || cfg.band >= bandCount ||
(cfg.attackTimeMs < 0) || cfg.releaseTimeMs < 0 || cfg.ratio < 0 ||
cfg.thresholdDb > 0 || cfg.kneeWidthDb < 0 || cfg.noiseGateThresholdDb > 0 ||
cfg.expanderRatio < 0 || !isCutoffFrequencyValid(cfg.cutoffFrequencyHz, cap) ||
0 != bandSet.count({cfg.channel, cfg.band})) {
return false;
}
bandSet.insert({cfg.channel, cfg.band});
}
return true;
}
bool DynamicsProcessingTestHelper::isLimiterConfigValid(
const std::vector<DynamicsProcessing::LimiterConfig>& cfgs, bool stageInUse) {
std::set<int> channelSet;
if (!stageInUse) return false;
for (auto cfg : cfgs) {
if (0 == mLimiterChannelEnable.count(cfg.channel) || cfg.channel < 0 ||
cfg.channel >= mChannelCount || cfg.attackTimeMs < 0 || cfg.releaseTimeMs < 0 ||
cfg.ratio < 0 || cfg.thresholdDb > 0 || 0 != channelSet.count(cfg.channel)) {
return false;
}
channelSet.insert(cfg.channel);
}
return true;
}
bool DynamicsProcessingTestHelper::isInputGainValid(
const std::vector<DynamicsProcessing::InputGain>& cfgs) {
std::set<int> channelSet;
for (auto cfg : cfgs) {
if (cfg.channel < 0 || cfg.channel >= mChannelCount || 0 != channelSet.count(cfg.channel)) {
return false;
}
channelSet.insert(cfg.channel);
}
return true;
}
bool DynamicsProcessingTestHelper::isEngineConfigEqual(
const DynamicsProcessing::EngineArchitecture& ref,
const DynamicsProcessing::EngineArchitecture& test) {
@ -455,7 +270,8 @@ void DynamicsProcessingTestHelper::SetAndGetDynamicsProcessingParameters() {
// validate parameter
Descriptor desc;
ASSERT_STATUS(EX_NONE, mEffect->getDescriptor(&desc));
const bool valid = isParamValid(tag, dp, desc);
const bool valid =
isParameterValid<DynamicsProcessing, Range::dynamicsProcessing>(dp, desc);
const binder_exception_t expected = valid ? EX_NONE : EX_ILLEGAL_ARGUMENT;
// set parameter
@ -463,7 +279,10 @@ void DynamicsProcessingTestHelper::SetAndGetDynamicsProcessingParameters() {
Parameter::Specific specific;
specific.set<Parameter::Specific::dynamicsProcessing>(dp);
expectParam.set<Parameter::specific>(specific);
ASSERT_STATUS(expected, mEffect->setParameter(expectParam)) << expectParam.toString();
ASSERT_STATUS(expected, mEffect->setParameter(expectParam))
<< "\n"
<< expectParam.toString() << "\n"
<< desc.toString();
// only get if parameter in range and set success
if (expected == EX_NONE) {

View file

@ -23,7 +23,6 @@
using namespace android;
using aidl::android::hardware::audio::effect::Capability;
using aidl::android::hardware::audio::effect::Descriptor;
using aidl::android::hardware::audio::effect::EnvironmentalReverb;
using aidl::android::hardware::audio::effect::IEffect;
@ -93,7 +92,8 @@ class EnvironmentalReverbHelper : public EffectHelper {
// validate parameter
Descriptor desc;
ASSERT_STATUS(EX_NONE, mEffect->getDescriptor(&desc));
const bool valid = isTagInRange(it.first, it.second, desc);
const bool valid = isParameterValid<EnvironmentalReverb, Range::environmentalReverb>(
it.second, desc);
const binder_exception_t expected = valid ? EX_NONE : EX_ILLEGAL_ARGUMENT;
// set
@ -171,239 +171,6 @@ class EnvironmentalReverbHelper : public EffectHelper {
mTags.push_back({EnvironmentalReverb::bypass, er});
}
bool isTagInRange(const EnvironmentalReverb::Tag& tag, const EnvironmentalReverb er,
const Descriptor& desc) const {
const EnvironmentalReverb::Capability& erCap =
desc.capability.get<Capability::environmentalReverb>();
switch (tag) {
case EnvironmentalReverb::roomLevelMb: {
int roomLevel = er.get<EnvironmentalReverb::roomLevelMb>();
return isRoomLevelInRange(erCap, roomLevel);
}
case EnvironmentalReverb::roomHfLevelMb: {
int roomHfLevel = er.get<EnvironmentalReverb::roomHfLevelMb>();
return isRoomHfLevelInRange(erCap, roomHfLevel);
}
case EnvironmentalReverb::decayTimeMs: {
int decayTime = er.get<EnvironmentalReverb::decayTimeMs>();
return isDecayTimeInRange(erCap, decayTime);
}
case EnvironmentalReverb::decayHfRatioPm: {
int decayHfRatio = er.get<EnvironmentalReverb::decayHfRatioPm>();
return isDecayHfRatioInRange(erCap, decayHfRatio);
}
case EnvironmentalReverb::levelMb: {
int level = er.get<EnvironmentalReverb::levelMb>();
return isLevelInRange(erCap, level);
}
case EnvironmentalReverb::delayMs: {
int delay = er.get<EnvironmentalReverb::delayMs>();
return isDelayInRange(erCap, delay);
}
case EnvironmentalReverb::diffusionPm: {
int diffusion = er.get<EnvironmentalReverb::diffusionPm>();
return isDiffusionInRange(erCap, diffusion);
}
case EnvironmentalReverb::densityPm: {
int density = er.get<EnvironmentalReverb::densityPm>();
return isDensityInRange(erCap, density);
}
case EnvironmentalReverb::bypass: {
return true;
}
default:
return false;
}
return false;
}
bool isRoomLevelInRange(const EnvironmentalReverb::Capability& cap, int roomLevel) const {
return roomLevel >= cap.minRoomLevelMb && roomLevel <= cap.maxRoomLevelMb;
}
bool isRoomHfLevelInRange(const EnvironmentalReverb::Capability& cap, int roomHfLevel) const {
return roomHfLevel >= cap.minRoomHfLevelMb && roomHfLevel <= cap.maxRoomHfLevelMb;
}
bool isDecayTimeInRange(const EnvironmentalReverb::Capability& cap, int decayTime) const {
return decayTime >= 0 && decayTime <= cap.maxDecayTimeMs;
}
bool isDecayHfRatioInRange(const EnvironmentalReverb::Capability& cap, int decayHfRatio) const {
return decayHfRatio >= cap.minDecayHfRatioPm && decayHfRatio <= cap.maxDecayHfRatioPm;
}
bool isLevelInRange(const EnvironmentalReverb::Capability& cap, int level) const {
return level >= cap.minLevelMb && level <= cap.maxLevelMb;
}
bool isDelayInRange(const EnvironmentalReverb::Capability& cap, int delay) const {
return delay >= 0 && delay <= cap.maxDelayMs;
}
bool isDiffusionInRange(const EnvironmentalReverb::Capability& cap, int diffusion) const {
return diffusion >= 0 && diffusion <= cap.maxDiffusionPm;
}
bool isDensityInRange(const EnvironmentalReverb::Capability& cap, int density) const {
return density >= 0 && density <= cap.maxDensityPm;
}
static std::unordered_set<int> getRoomLevelValues() {
auto descList = EffectFactoryHelper::getAllEffectDescriptors(IFactory::descriptor,
kEnvReverbTypeUUID);
int minRoomLevelMb = std::numeric_limits<int>::max();
int maxRoomLevelMb = std::numeric_limits<int>::min();
for (const auto& it : descList) {
maxRoomLevelMb = std::max(
it.second.capability.get<Capability::environmentalReverb>().maxRoomLevelMb,
maxRoomLevelMb);
minRoomLevelMb = std::min(
it.second.capability.get<Capability::environmentalReverb>().minRoomLevelMb,
minRoomLevelMb);
}
return {std::numeric_limits<int>::min(), minRoomLevelMb - 1, minRoomLevelMb,
(minRoomLevelMb + maxRoomLevelMb) >> 1, maxRoomLevelMb, maxRoomLevelMb + 1,
std::numeric_limits<int>::max()};
}
static std::unordered_set<int> getRoomHfLevelValues() {
auto descList = EffectFactoryHelper::getAllEffectDescriptors(IFactory::descriptor,
kEnvReverbTypeUUID);
int minRoomHfLevelMb = std::numeric_limits<int>::max();
int maxRoomHfLevelMb = std::numeric_limits<int>::min();
for (const auto& it : descList) {
maxRoomHfLevelMb = std::max(
it.second.capability.get<Capability::environmentalReverb>().maxRoomHfLevelMb,
maxRoomHfLevelMb);
minRoomHfLevelMb = std::min(
it.second.capability.get<Capability::environmentalReverb>().minRoomHfLevelMb,
minRoomHfLevelMb);
}
return {std::numeric_limits<int>::min(),
minRoomHfLevelMb - 1,
minRoomHfLevelMb,
(minRoomHfLevelMb + maxRoomHfLevelMb) >> 1,
maxRoomHfLevelMb,
maxRoomHfLevelMb + 1,
std::numeric_limits<int>::max()};
}
static std::unordered_set<int> getDecayTimeValues() {
auto descList = EffectFactoryHelper::getAllEffectDescriptors(IFactory::descriptor,
kEnvReverbTypeUUID);
const auto max = std::max_element(
descList.begin(), descList.end(),
[](const std::pair<std::shared_ptr<IFactory>, Descriptor>& a,
const std::pair<std::shared_ptr<IFactory>, Descriptor>& b) {
return a.second.capability.get<Capability::environmentalReverb>()
.maxDecayTimeMs <
b.second.capability.get<Capability::environmentalReverb>()
.maxDecayTimeMs;
});
if (max == descList.end()) {
return {0};
}
int maxDecayTimeMs =
max->second.capability.get<Capability::environmentalReverb>().maxDecayTimeMs;
return {-1, 0, maxDecayTimeMs >> 1, maxDecayTimeMs - 1, maxDecayTimeMs, maxDecayTimeMs + 1};
}
static std::unordered_set<int> getDecayHfRatioValues() {
auto descList = EffectFactoryHelper::getAllEffectDescriptors(IFactory::descriptor,
kEnvReverbTypeUUID);
int minDecayHfRatioPm = std::numeric_limits<int>::max();
int maxDecayHfRatioPm = std::numeric_limits<int>::min();
for (const auto& it : descList) {
maxDecayHfRatioPm = std::max(
it.second.capability.get<Capability::environmentalReverb>().maxDecayHfRatioPm,
maxDecayHfRatioPm);
minDecayHfRatioPm = std::min(
it.second.capability.get<Capability::environmentalReverb>().minDecayHfRatioPm,
minDecayHfRatioPm);
}
return {std::numeric_limits<int>::min(),
minDecayHfRatioPm - 1,
minDecayHfRatioPm,
(minDecayHfRatioPm + maxDecayHfRatioPm) >> 1,
maxDecayHfRatioPm,
maxDecayHfRatioPm + 1,
std::numeric_limits<int>::max()};
}
static std::unordered_set<int> getLevelValues() {
auto descList = EffectFactoryHelper::getAllEffectDescriptors(IFactory::descriptor,
kEnvReverbTypeUUID);
int minLevelMb = std::numeric_limits<int>::max();
int maxLevelMb = std::numeric_limits<int>::min();
for (const auto& it : descList) {
maxLevelMb =
std::max(it.second.capability.get<Capability::environmentalReverb>().maxLevelMb,
maxLevelMb);
minLevelMb =
std::min(it.second.capability.get<Capability::environmentalReverb>().minLevelMb,
minLevelMb);
}
return {std::numeric_limits<int>::min(), minLevelMb - 1, minLevelMb,
(minLevelMb + maxLevelMb) >> 1, maxLevelMb, maxLevelMb + 1,
std::numeric_limits<int>::max()};
}
static std::unordered_set<int> getDelayValues() {
auto descList = EffectFactoryHelper::getAllEffectDescriptors(IFactory::descriptor,
kEnvReverbTypeUUID);
const auto max = std::max_element(
descList.begin(), descList.end(),
[](const std::pair<std::shared_ptr<IFactory>, Descriptor>& a,
const std::pair<std::shared_ptr<IFactory>, Descriptor>& b) {
return a.second.capability.get<Capability::environmentalReverb>().maxDelayMs <
b.second.capability.get<Capability::environmentalReverb>().maxDelayMs;
});
if (max == descList.end()) {
return {0};
}
int maxDelayMs = max->second.capability.get<Capability::environmentalReverb>().maxDelayMs;
return {-1, 0, maxDelayMs >> 1, maxDelayMs - 1, maxDelayMs, maxDelayMs + 1};
}
static std::unordered_set<int> getDiffusionValues() {
auto descList = EffectFactoryHelper::getAllEffectDescriptors(IFactory::descriptor,
kEnvReverbTypeUUID);
const auto max = std::max_element(
descList.begin(), descList.end(),
[](const std::pair<std::shared_ptr<IFactory>, Descriptor>& a,
const std::pair<std::shared_ptr<IFactory>, Descriptor>& b) {
return a.second.capability.get<Capability::environmentalReverb>()
.maxDiffusionPm <
b.second.capability.get<Capability::environmentalReverb>()
.maxDiffusionPm;
});
if (max == descList.end()) {
return {0};
}
int maxDiffusionPm =
max->second.capability.get<Capability::environmentalReverb>().maxDiffusionPm;
return {-1, 0, maxDiffusionPm >> 1, maxDiffusionPm - 1, maxDiffusionPm, maxDiffusionPm + 1};
}
static std::unordered_set<int> getDensityValues() {
auto descList = EffectFactoryHelper::getAllEffectDescriptors(IFactory::descriptor,
kEnvReverbTypeUUID);
const auto max = std::max_element(
descList.begin(), descList.end(),
[](const std::pair<std::shared_ptr<IFactory>, Descriptor>& a,
const std::pair<std::shared_ptr<IFactory>, Descriptor>& b) {
return a.second.capability.get<Capability::environmentalReverb>().maxDensityPm <
b.second.capability.get<Capability::environmentalReverb>().maxDensityPm;
});
if (max == descList.end()) {
return {0};
}
int maxDensityPm =
max->second.capability.get<Capability::environmentalReverb>().maxDensityPm;
return {-1, 0, maxDensityPm >> 1, maxDensityPm - 1, maxDensityPm, maxDensityPm + 1};
}
private:
std::vector<std::pair<EnvironmentalReverb::Tag, EnvironmentalReverb>> mTags;
void CleanUp() { mTags.clear(); }
@ -428,11 +195,17 @@ TEST_P(EnvironmentalReverbRoomLevelTest, SetAndGetRoomLevel) {
SetAndGetReverbParameters();
}
std::vector<std::pair<std::shared_ptr<IFactory>, Descriptor>> kDescPair;
INSTANTIATE_TEST_SUITE_P(
EnvironmentalReverbTest, EnvironmentalReverbRoomLevelTest,
::testing::Combine(testing::ValuesIn(EffectFactoryHelper::getAllEffectDescriptors(
IFactory::descriptor, kEnvReverbTypeUUID)),
testing::ValuesIn(EnvironmentalReverbHelper::getRoomLevelValues())),
::testing::Combine(
testing::ValuesIn(kDescPair = EffectFactoryHelper::getAllEffectDescriptors(
IFactory::descriptor, kEnvReverbTypeUUID)),
testing::ValuesIn(EffectHelper::getTestValueSet<EnvironmentalReverb, int,
Range::environmentalReverb,
EnvironmentalReverb::roomLevelMb>(
kDescPair, EffectHelper::expandTestValueBasic<int>))),
[](const testing::TestParamInfo<EnvironmentalReverbRoomLevelTest::ParamType>& info) {
auto descriptor = std::get<0>(info.param).second;
std::string roomLevel = std::to_string(std::get<1>(info.param));
@ -467,9 +240,13 @@ TEST_P(EnvironmentalReverbRoomHfLevelTest, SetAndGetRoomHfLevel) {
INSTANTIATE_TEST_SUITE_P(
EnvironmentalReverbTest, EnvironmentalReverbRoomHfLevelTest,
::testing::Combine(testing::ValuesIn(EffectFactoryHelper::getAllEffectDescriptors(
IFactory::descriptor, kEnvReverbTypeUUID)),
testing::ValuesIn(EnvironmentalReverbHelper::getRoomHfLevelValues())),
::testing::Combine(
testing::ValuesIn(EffectFactoryHelper::getAllEffectDescriptors(IFactory::descriptor,
kEnvReverbTypeUUID)),
testing::ValuesIn(EffectHelper::getTestValueSet<EnvironmentalReverb, int,
Range::environmentalReverb,
EnvironmentalReverb::roomHfLevelMb>(
kDescPair, EffectHelper::expandTestValueBasic<int>))),
[](const testing::TestParamInfo<EnvironmentalReverbRoomHfLevelTest::ParamType>& info) {
auto descriptor = std::get<0>(info.param).second;
std::string roomHfLevel = std::to_string(std::get<1>(info.param));
@ -504,9 +281,13 @@ TEST_P(EnvironmentalReverbDecayTimeTest, SetAndGetDecayTime) {
INSTANTIATE_TEST_SUITE_P(
EnvironmentalReverbTest, EnvironmentalReverbDecayTimeTest,
::testing::Combine(testing::ValuesIn(EffectFactoryHelper::getAllEffectDescriptors(
IFactory::descriptor, kEnvReverbTypeUUID)),
testing::ValuesIn(EnvironmentalReverbHelper::getDecayTimeValues())),
::testing::Combine(
testing::ValuesIn(EffectFactoryHelper::getAllEffectDescriptors(IFactory::descriptor,
kEnvReverbTypeUUID)),
testing::ValuesIn(EffectHelper::getTestValueSet<EnvironmentalReverb, int,
Range::environmentalReverb,
EnvironmentalReverb::decayTimeMs>(
kDescPair, EffectHelper::expandTestValueBasic<int>))),
[](const testing::TestParamInfo<EnvironmentalReverbDecayTimeTest::ParamType>& info) {
auto descriptor = std::get<0>(info.param).second;
std::string decayTime = std::to_string(std::get<1>(info.param));
@ -543,7 +324,10 @@ INSTANTIATE_TEST_SUITE_P(
EnvironmentalReverbTest, EnvironmentalReverbDecayHfRatioTest,
::testing::Combine(testing::ValuesIn(EffectFactoryHelper::getAllEffectDescriptors(
IFactory::descriptor, kEnvReverbTypeUUID)),
testing::ValuesIn(EnvironmentalReverbHelper::getDecayHfRatioValues())),
testing::ValuesIn(EffectHelper::getTestValueSet<
EnvironmentalReverb, int, Range::environmentalReverb,
EnvironmentalReverb::decayHfRatioPm>(
kDescPair, EffectHelper::expandTestValueBasic<int>))),
[](const testing::TestParamInfo<EnvironmentalReverbDecayHfRatioTest::ParamType>& info) {
auto descriptor = std::get<0>(info.param).second;
std::string decayHfRatio = std::to_string(std::get<1>(info.param));
@ -579,9 +363,13 @@ TEST_P(EnvironmentalReverbLevelTest, SetAndGetLevel) {
INSTANTIATE_TEST_SUITE_P(
EnvironmentalReverbTest, EnvironmentalReverbLevelTest,
::testing::Combine(testing::ValuesIn(EffectFactoryHelper::getAllEffectDescriptors(
IFactory::descriptor, kEnvReverbTypeUUID)),
testing::ValuesIn(EnvironmentalReverbHelper::getLevelValues())),
::testing::Combine(
testing::ValuesIn(EffectFactoryHelper::getAllEffectDescriptors(IFactory::descriptor,
kEnvReverbTypeUUID)),
testing::ValuesIn(EffectHelper::getTestValueSet<EnvironmentalReverb, int,
Range::environmentalReverb,
EnvironmentalReverb::levelMb>(
kDescPair, EffectHelper::expandTestValueBasic<int>))),
[](const testing::TestParamInfo<EnvironmentalReverbDecayHfRatioTest::ParamType>& info) {
auto descriptor = std::get<0>(info.param).second;
std::string level = std::to_string(std::get<1>(info.param));
@ -616,9 +404,13 @@ TEST_P(EnvironmentalReverbDelayTest, SetAndGetDelay) {
INSTANTIATE_TEST_SUITE_P(
EnvironmentalReverbTest, EnvironmentalReverbDelayTest,
::testing::Combine(testing::ValuesIn(EffectFactoryHelper::getAllEffectDescriptors(
IFactory::descriptor, kEnvReverbTypeUUID)),
testing::ValuesIn(EnvironmentalReverbHelper::getDelayValues())),
::testing::Combine(
testing::ValuesIn(EffectFactoryHelper::getAllEffectDescriptors(IFactory::descriptor,
kEnvReverbTypeUUID)),
testing::ValuesIn(EffectHelper::getTestValueSet<EnvironmentalReverb, int,
Range::environmentalReverb,
EnvironmentalReverb::delayMs>(
kDescPair, EffectHelper::expandTestValueBasic<int>))),
[](const testing::TestParamInfo<EnvironmentalReverbDelayTest::ParamType>& info) {
auto descriptor = std::get<0>(info.param).second;
std::string delay = std::to_string(std::get<1>(info.param));
@ -653,9 +445,13 @@ TEST_P(EnvironmentalReverbDiffusionTest, SetAndGetDiffusion) {
INSTANTIATE_TEST_SUITE_P(
EnvironmentalReverbTest, EnvironmentalReverbDiffusionTest,
::testing::Combine(testing::ValuesIn(EffectFactoryHelper::getAllEffectDescriptors(
IFactory::descriptor, kEnvReverbTypeUUID)),
testing::ValuesIn(EnvironmentalReverbHelper::getDiffusionValues())),
::testing::Combine(
testing::ValuesIn(EffectFactoryHelper::getAllEffectDescriptors(IFactory::descriptor,
kEnvReverbTypeUUID)),
testing::ValuesIn(EffectHelper::getTestValueSet<EnvironmentalReverb, int,
Range::environmentalReverb,
EnvironmentalReverb::diffusionPm>(
kDescPair, EffectHelper::expandTestValueBasic<int>))),
[](const testing::TestParamInfo<EnvironmentalReverbDiffusionTest::ParamType>& info) {
auto descriptor = std::get<0>(info.param).second;
std::string diffusion = std::to_string(std::get<1>(info.param));
@ -690,9 +486,13 @@ TEST_P(EnvironmentalReverbDensityTest, SetAndGetDensity) {
INSTANTIATE_TEST_SUITE_P(
EnvironmentalReverbTest, EnvironmentalReverbDensityTest,
::testing::Combine(testing::ValuesIn(EffectFactoryHelper::getAllEffectDescriptors(
IFactory::descriptor, kEnvReverbTypeUUID)),
testing::ValuesIn(EnvironmentalReverbHelper::getDensityValues())),
::testing::Combine(
testing::ValuesIn(EffectFactoryHelper::getAllEffectDescriptors(IFactory::descriptor,
kEnvReverbTypeUUID)),
testing::ValuesIn(EffectHelper::getTestValueSet<EnvironmentalReverb, int,
Range::environmentalReverb,
EnvironmentalReverb::densityPm>(
kDescPair, EffectHelper::expandTestValueBasic<int>))),
[](const testing::TestParamInfo<EnvironmentalReverbDensityTest::ParamType>& info) {
auto descriptor = std::get<0>(info.param).second;
std::string density = std::to_string(std::get<1>(info.param));

View file

@ -18,6 +18,7 @@
#include <limits>
#include <map>
#include <memory>
#include <optional>
#include <string>
#include <vector>
@ -43,7 +44,6 @@
using namespace android;
using aidl::android::hardware::audio::effect::Capability;
using aidl::android::hardware::audio::effect::Descriptor;
using aidl::android::hardware::audio::effect::Equalizer;
using aidl::android::hardware::audio::effect::IEffect;
@ -56,8 +56,9 @@ using aidl::android::hardware::audio::effect::Parameter;
* testing performed in VtsAudioEfectTargetTest.
*/
enum ParamName { PARAM_INSTANCE_NAME, PARAM_BAND_LEVEL };
using EqualizerParamTestParam = std::tuple<std::pair<std::shared_ptr<IFactory>, Descriptor>, int>;
enum ParamName { PARAM_INSTANCE_NAME, PARAM_PRESET, PARAM_BAND_LEVEL };
using EqualizerParamTestParam = std::tuple<std::pair<std::shared_ptr<IFactory>, Descriptor>, int,
std::vector<Equalizer::BandLevel>>;
/*
Testing parameter range, assuming the parameter supported by effect is in this range.
@ -69,7 +70,9 @@ const std::vector<int> kBandLevels = {0, -10, 10}; // needs update with impleme
class EqualizerTest : public ::testing::TestWithParam<EqualizerParamTestParam>,
public EffectHelper {
public:
EqualizerTest() : mBandLevel(std::get<PARAM_BAND_LEVEL>(GetParam())) {
EqualizerTest()
: mPresetIndex(std::get<PARAM_PRESET>(GetParam())),
mBandLevel(std::get<PARAM_BAND_LEVEL>(GetParam())) {
std::tie(mFactory, mDescriptor) = std::get<PARAM_INSTANCE_NAME>(GetParam());
}
@ -77,48 +80,24 @@ class EqualizerTest : public ::testing::TestWithParam<EqualizerParamTestParam>,
ASSERT_NE(nullptr, mFactory);
ASSERT_NO_FATAL_FAILURE(create(mFactory, mEffect, mDescriptor));
Parameter::Specific specific = getDefaultParamSpecific();
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(mEffect, common, specific, &ret, EX_NONE));
ASSERT_NO_FATAL_FAILURE(open(mEffect, common, std::nullopt, &ret, EX_NONE));
ASSERT_NE(nullptr, mEffect);
ASSERT_NO_FATAL_FAILURE(setTagRange());
}
void TearDown() override {
ASSERT_NO_FATAL_FAILURE(close(mEffect));
ASSERT_NO_FATAL_FAILURE(destroy(mFactory, mEffect));
}
std::pair<int, int> setPresetIndexRange(const Equalizer::Capability& cap) const {
const auto [min, max] =
std::minmax_element(cap.presets.begin(), cap.presets.end(),
[](const auto& a, const auto& b) { return a.index < b.index; });
return {min->index, max->index};
}
std::pair<int, int> setBandIndexRange(const Equalizer::Capability& cap) const {
const auto [min, max] =
std::minmax_element(cap.bandFrequencies.begin(), cap.bandFrequencies.end(),
[](const auto& a, const auto& b) { return a.index < b.index; });
return {min->index, max->index};
}
void setTagRange() {
Descriptor desc;
ASSERT_STATUS(EX_NONE, mEffect->getDescriptor(&desc));
Equalizer::Capability& eqCap = desc.capability.get<Capability::equalizer>();
mPresetIndex = setPresetIndexRange(eqCap);
mBandIndex = setBandIndexRange(eqCap);
}
static const long kInputFrameCount = 0x100, kOutputFrameCount = 0x100;
std::shared_ptr<IFactory> mFactory;
std::shared_ptr<IEffect> mEffect;
Descriptor mDescriptor;
std::pair<int, int> mPresetIndex;
std::pair<int, int> mBandIndex;
const int mBandLevel;
Descriptor mDesc;
int mPresetIndex;
std::vector<Equalizer::BandLevel> mBandLevel;
void SetAndGetEqualizerParameters() {
ASSERT_NE(nullptr, mEffect);
@ -127,25 +106,22 @@ class EqualizerTest : public ::testing::TestWithParam<EqualizerParamTestParam>,
auto& eq = it.second;
// validate parameter
const bool valid = isTagInRange(it.first, it.second);
const bool valid = isParameterValid<Equalizer, Range::equalizer>(eq, mDescriptor);
const binder_exception_t expected = valid ? EX_NONE : EX_ILLEGAL_ARGUMENT;
// set
Parameter expectParam;
Parameter::Specific specific;
specific.set<Parameter::Specific::equalizer>(eq);
expectParam.set<Parameter::specific>(specific);
Parameter::Specific specific =
Parameter::Specific::make<Parameter::Specific::equalizer>(eq);
Parameter expectParam = Parameter::make<Parameter::specific>(specific);
EXPECT_STATUS(expected, mEffect->setParameter(expectParam))
<< expectParam.toString() << "\n"
<< mDesc.toString();
<< mDescriptor.toString();
// only get if parameter in range and set success
if (expected == EX_NONE) {
Parameter getParam;
Parameter::Id id;
Equalizer::Id eqId;
eqId.set<Equalizer::Id::commonTag>(tag);
id.set<Parameter::Id::equalizerTag>(eqId);
Equalizer::Id eqId = Equalizer::Id::make<Equalizer::Id::commonTag>(tag);
Parameter::Id id = Parameter::Id::make<Parameter::Id::equalizerTag>(eqId);
// if set success, then get should match
EXPECT_STATUS(expected, mEffect->getParameter(id, &getParam));
EXPECT_TRUE(isEqParameterExpected(expectParam, getParam))
@ -197,140 +173,51 @@ class EqualizerTest : public ::testing::TestWithParam<EqualizerParamTestParam>,
}
void addPresetParam(int preset) {
Equalizer eq;
eq.set<Equalizer::preset>(preset);
mTags.push_back({Equalizer::preset, eq});
mTags.push_back({Equalizer::preset, Equalizer::make<Equalizer::preset>(preset)});
}
void addBandLevelsParam(std::vector<Equalizer::BandLevel>& bandLevels) {
Equalizer eq;
eq.set<Equalizer::bandLevels>(bandLevels);
mTags.push_back({Equalizer::bandLevels, eq});
}
bool isTagInRange(const Equalizer::Tag& tag, const Equalizer& eq) const {
switch (tag) {
case Equalizer::preset: {
int index = eq.get<Equalizer::preset>();
return index >= mPresetIndex.first && index <= mPresetIndex.second;
}
case Equalizer::bandLevels: {
auto& bandLevel = eq.get<Equalizer::bandLevels>();
return isBandInRange(bandLevel);
}
default:
return false;
}
return false;
}
bool isBandInRange(const std::vector<Equalizer::BandLevel>& bandLevel) const {
for (auto& it : bandLevel) {
if (it.index < mBandIndex.first || it.index > mBandIndex.second) return false;
}
return true;
}
Parameter::Specific getDefaultParamSpecific() {
Equalizer eq = Equalizer::make<Equalizer::preset>(0);
Parameter::Specific specific =
Parameter::Specific::make<Parameter::Specific::equalizer>(eq);
return specific;
mTags.push_back(
{Equalizer::bandLevels, Equalizer::make<Equalizer::bandLevels>(bandLevels)});
}
private:
std::vector<std::pair<Equalizer::Tag, Equalizer>> mTags;
bool validCapabilityTag(Capability& cap) { return cap.getTag() == Capability::equalizer; }
void CleanUp() { mTags.clear(); }
};
TEST_P(EqualizerTest, SetAndGetPresetOutOfLowerBound) {
addPresetParam(mPresetIndex.second - 1);
ASSERT_NO_FATAL_FAILURE(SetAndGetEqualizerParameters());
}
TEST_P(EqualizerTest, SetAndGetPresetOutOfUpperBound) {
addPresetParam(mPresetIndex.second + 1);
EXPECT_NO_FATAL_FAILURE(SetAndGetEqualizerParameters());
}
TEST_P(EqualizerTest, SetAndGetPresetAtLowerBound) {
addPresetParam(mPresetIndex.first);
EXPECT_NO_FATAL_FAILURE(SetAndGetEqualizerParameters());
}
TEST_P(EqualizerTest, SetAndGetPresetAtHigherBound) {
addPresetParam(mPresetIndex.second);
EXPECT_NO_FATAL_FAILURE(SetAndGetEqualizerParameters());
}
TEST_P(EqualizerTest, SetAndGetPresetInBound) {
addPresetParam((mPresetIndex.first + mPresetIndex.second) >> 1);
EXPECT_NO_FATAL_FAILURE(SetAndGetEqualizerParameters());
}
TEST_P(EqualizerTest, SetAndGetBandOutOfLowerBound) {
std::vector<Equalizer::BandLevel> bandLevels{{mBandIndex.first - 1, mBandLevel}};
addBandLevelsParam(bandLevels);
EXPECT_NO_FATAL_FAILURE(SetAndGetEqualizerParameters());
}
TEST_P(EqualizerTest, SetAndGetBandOutOfUpperBound) {
std::vector<Equalizer::BandLevel> bandLevels{{mBandIndex.second + 1, mBandLevel}};
addBandLevelsParam(bandLevels);
EXPECT_NO_FATAL_FAILURE(SetAndGetEqualizerParameters());
}
TEST_P(EqualizerTest, SetAndGetBandAtLowerBound) {
std::vector<Equalizer::BandLevel> bandLevels{{mBandIndex.first, mBandLevel}};
addBandLevelsParam(bandLevels);
EXPECT_NO_FATAL_FAILURE(SetAndGetEqualizerParameters());
}
TEST_P(EqualizerTest, SetAndGetBandAtHigherBound) {
std::vector<Equalizer::BandLevel> bandLevels{{mBandIndex.second, mBandLevel}};
addBandLevelsParam(bandLevels);
EXPECT_NO_FATAL_FAILURE(SetAndGetEqualizerParameters());
}
TEST_P(EqualizerTest, SetAndGetBandInBound) {
std::vector<Equalizer::BandLevel> bandLevels{
{(mBandIndex.first + mBandIndex.second) >> 1, mBandLevel}};
addBandLevelsParam(bandLevels);
EXPECT_NO_FATAL_FAILURE(SetAndGetEqualizerParameters());
}
TEST_P(EqualizerTest, SetAndGetMultiBands) {
addPresetParam(mPresetIndex.first);
std::vector<Equalizer::BandLevel> bandLevels{
{mBandIndex.first, mBandLevel},
{mBandIndex.second, mBandLevel},
{(mBandIndex.first + mBandIndex.second) >> 1, mBandLevel}};
addBandLevelsParam(bandLevels);
EXPECT_NO_FATAL_FAILURE(SetAndGetEqualizerParameters());
}
TEST_P(EqualizerTest, SetAndGetMultipleParams) {
std::vector<Equalizer::BandLevel> bandLevels{
{(mBandIndex.first + mBandIndex.second) >> 1, mBandLevel}};
addBandLevelsParam(bandLevels);
addPresetParam((mPresetIndex.first + mPresetIndex.second) >> 1);
TEST_P(EqualizerTest, SetAndGetParams) {
addBandLevelsParam(mBandLevel);
addPresetParam(mPresetIndex);
EXPECT_NO_FATAL_FAILURE(SetAndGetEqualizerParameters());
}
std::vector<std::pair<std::shared_ptr<IFactory>, Descriptor>> kDescPair;
INSTANTIATE_TEST_SUITE_P(
EqualizerTest, EqualizerTest,
::testing::Combine(testing::ValuesIn(EffectFactoryHelper::getAllEffectDescriptors(
IFactory::descriptor, kEqualizerTypeUUID)),
testing::ValuesIn(kBandLevels)),
::testing::Combine(
testing::ValuesIn(kDescPair = EffectFactoryHelper::getAllEffectDescriptors(
IFactory::descriptor, kEqualizerTypeUUID)),
testing::ValuesIn(EffectHelper::getTestValueSet<Equalizer, int, Range::equalizer,
Equalizer::preset>(
kDescPair, EffectHelper::expandTestValueBasic<int>)),
testing::ValuesIn(
EffectHelper::getTestValueSet<Equalizer, std::vector<Equalizer::BandLevel>,
Range::equalizer, Equalizer::bandLevels>(
kDescPair,
[](std::set<std::vector<Equalizer::BandLevel>>& bandLevels) {
return bandLevels;
}))),
[](const testing::TestParamInfo<EqualizerTest::ParamType>& info) {
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 bandLevel =
::android::internal::ToString(std::get<PARAM_BAND_LEVEL>(info.param));
std::string name = "Implementor_" + descriptor.common.implementor + "_name_" +
descriptor.common.name + "_UUID_" +
descriptor.common.id.uuid.toString() + "_bandLevel_" + bandLevel;
descriptor.common.id.uuid.toString() + "_preset_" +
std::to_string(std::get<PARAM_PRESET>(info.param)) + "_bandLevel_" +
bandLevel;
std::replace_if(
name.begin(), name.end(), [](const char c) { return !std::isalnum(c); }, '_');
return name;

View file

@ -27,7 +27,6 @@
using namespace android;
using aidl::android::hardware::audio::effect::Capability;
using aidl::android::hardware::audio::effect::Descriptor;
using aidl::android::hardware::audio::effect::HapticGenerator;
using aidl::android::hardware::audio::effect::IEffect;

View file

@ -24,7 +24,6 @@
using namespace android;
using aidl::android::hardware::audio::effect::Capability;
using aidl::android::hardware::audio::effect::Descriptor;
using aidl::android::hardware::audio::effect::IEffect;
using aidl::android::hardware::audio::effect::IFactory;

View file

@ -26,7 +26,6 @@
using namespace android;
using aidl::android::hardware::audio::effect::Capability;
using aidl::android::hardware::audio::effect::Descriptor;
using aidl::android::hardware::audio::effect::IEffect;
using aidl::android::hardware::audio::effect::IFactory;

View file

@ -23,7 +23,6 @@
using namespace android;
using aidl::android::hardware::audio::effect::Capability;
using aidl::android::hardware::audio::effect::Descriptor;
using aidl::android::hardware::audio::effect::IEffect;
using aidl::android::hardware::audio::effect::IFactory;
@ -84,7 +83,7 @@ class PresetReverbParamTest : public ::testing::TestWithParam<PresetReverbParamT
// validate parameter
Descriptor desc;
ASSERT_STATUS(EX_NONE, mEffect->getDescriptor(&desc));
const bool valid = isTagInRange(it.first, it.second, desc);
const bool valid = isParameterValid<PresetReverb, Range::presetReverb>(it.second, desc);
const binder_exception_t expected = valid ? EX_NONE : EX_ILLEGAL_ARGUMENT;
// set parameter
@ -113,27 +112,6 @@ class PresetReverbParamTest : public ::testing::TestWithParam<PresetReverbParamT
mTags.push_back({PresetReverb::preset, pr});
}
bool isTagInRange(const PresetReverb::Tag& tag, const PresetReverb& pr,
const Descriptor& desc) const {
const PresetReverb::Capability& prCap = desc.capability.get<Capability::presetReverb>();
switch (tag) {
case PresetReverb::preset: {
PresetReverb::Presets preset = pr.get<PresetReverb::preset>();
return isPresetInRange(prCap, preset);
}
default:
return false;
}
return false;
}
bool isPresetInRange(const PresetReverb::Capability& cap, PresetReverb::Presets preset) const {
for (auto i : cap.supportedPresets) {
if (preset == i) return true;
}
return false;
}
Parameter::Specific getDefaultParamSpecific() {
PresetReverb pr = PresetReverb::make<PresetReverb::preset>(PresetReverb::Presets::NONE);
Parameter::Specific specific =

View file

@ -22,7 +22,6 @@
using namespace android;
using aidl::android::hardware::audio::effect::Capability;
using aidl::android::hardware::audio::effect::Descriptor;
using aidl::android::hardware::audio::effect::IEffect;
using aidl::android::hardware::audio::effect::IFactory;
@ -90,7 +89,7 @@ class VirtualizerParamTest : public ::testing::TestWithParam<VirtualizerParamTes
// validate parameter
Descriptor desc;
ASSERT_STATUS(EX_NONE, mEffect->getDescriptor(&desc));
const bool valid = isTagInRange(it.first, it.second, desc);
const bool valid = isParameterValid<Virtualizer, Range::virtualizer>(it.second, desc);
const binder_exception_t expected = valid ? EX_NONE : EX_ILLEGAL_ARGUMENT;
// set parameter
@ -120,46 +119,6 @@ class VirtualizerParamTest : public ::testing::TestWithParam<VirtualizerParamTes
mTags.push_back({Virtualizer::strengthPm, vr});
}
bool isTagInRange(const Virtualizer::Tag& tag, const Virtualizer& vr,
const Descriptor& desc) const {
const Virtualizer::Capability& vrCap = desc.capability.get<Capability::virtualizer>();
switch (tag) {
case Virtualizer::strengthPm: {
int strength = vr.get<Virtualizer::strengthPm>();
return isStrengthInRange(vrCap, strength);
}
default:
return false;
}
return false;
}
bool isStrengthInRange(const Virtualizer::Capability& cap, int strength) const {
return cap.strengthSupported && strength >= 0 && strength <= cap.maxStrengthPm;
}
static std::vector<int> getStrengthTestValues(
std::vector<std::pair<std::shared_ptr<IFactory>, Descriptor>> kFactoryDescList) {
const auto max = std::max_element(
kFactoryDescList.begin(), kFactoryDescList.end(),
[](const std::pair<std::shared_ptr<IFactory>, Descriptor>& a,
const std::pair<std::shared_ptr<IFactory>, Descriptor>& b) {
return a.second.capability.get<Capability::virtualizer>().maxStrengthPm <
b.second.capability.get<Capability::virtualizer>().maxStrengthPm;
});
if (max == kFactoryDescList.end()) {
return {0};
}
int maxStrength = max->second.capability.get<Capability::virtualizer>().maxStrengthPm;
return {std::numeric_limits<int>::min(),
-1,
0,
maxStrength >> 1,
maxStrength,
maxStrength + 1,
std::numeric_limits<int>::max()};
}
private:
std::vector<std::pair<Virtualizer::Tag, Virtualizer>> mTags;
void CleanUp() { mTags.clear(); }
@ -170,13 +129,15 @@ TEST_P(VirtualizerParamTest, SetAndGetStrength) {
SetAndGetVirtualizerParameters();
}
std::vector<std::pair<std::shared_ptr<IFactory>, Descriptor>> kDescPair;
INSTANTIATE_TEST_SUITE_P(
VirtualizerTest, VirtualizerParamTest,
::testing::Combine(testing::ValuesIn(EffectFactoryHelper::getAllEffectDescriptors(
IFactory::descriptor, kVirtualizerTypeUUID)),
testing::ValuesIn(VirtualizerParamTest::getStrengthTestValues(
EffectFactoryHelper::getAllEffectDescriptors(
IFactory::descriptor, kVirtualizerTypeUUID)))),
::testing::Combine(
testing::ValuesIn(kDescPair = EffectFactoryHelper::getAllEffectDescriptors(
IFactory::descriptor, kVirtualizerTypeUUID)),
testing::ValuesIn(EffectHelper::getTestValueSet<
Virtualizer, int, Range::virtualizer, Virtualizer::strengthPm>(
kDescPair, EffectHelper::expandTestValueBasic<int>))),
[](const testing::TestParamInfo<VirtualizerParamTest::ParamType>& info) {
auto descriptor = std::get<PARAM_INSTANCE_NAME>(info.param).second;
std::string strength = std::to_string(std::get<PARAM_STRENGTH>(info.param));

View file

@ -26,7 +26,6 @@
using namespace android;
using aidl::android::hardware::audio::effect::Capability;
using aidl::android::hardware::audio::effect::Descriptor;
using aidl::android::hardware::audio::effect::IEffect;
using aidl::android::hardware::audio::effect::IFactory;
@ -64,12 +63,11 @@ class VisualizerParamTest : public ::testing::TestWithParam<VisualizerParamTestP
ASSERT_NE(nullptr, mFactory);
ASSERT_NO_FATAL_FAILURE(create(mFactory, mEffect, mDescriptor));
Parameter::Specific specific = getDefaultParamSpecific();
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(mEffect, common, specific, &ret, EX_NONE));
ASSERT_NO_FATAL_FAILURE(open(mEffect, common, std::nullopt, &ret, EX_NONE));
ASSERT_NE(nullptr, mEffect);
}
@ -77,13 +75,6 @@ class VisualizerParamTest : public ::testing::TestWithParam<VisualizerParamTestP
ASSERT_NO_FATAL_FAILURE(close(mEffect));
ASSERT_NO_FATAL_FAILURE(destroy(mFactory, mEffect));
}
Parameter::Specific getDefaultParamSpecific() {
Visualizer vs = Visualizer::make<Visualizer::captureSamples>(
mDescriptor.capability.get<Capability::visualizer>().captureSampleRange.max);
Parameter::Specific specific =
Parameter::Specific::make<Parameter::Specific::visualizer>(vs);
return specific;
}
static const long kInputFrameCount = 0x100, kOutputFrameCount = 0x100;
std::shared_ptr<IFactory> mFactory;
@ -94,7 +85,7 @@ class VisualizerParamTest : public ::testing::TestWithParam<VisualizerParamTestP
Visualizer::MeasurementMode mMeasurementMode = Visualizer::MeasurementMode::NONE;
int mLatency = 0;
void SetAndGetCommonParameters() {
void SetAndGetParameters() {
for (auto& it : mCommonTags) {
auto& tag = it.first;
auto& vs = it.second;
@ -102,7 +93,7 @@ class VisualizerParamTest : public ::testing::TestWithParam<VisualizerParamTestP
// validate parameter
Descriptor desc;
ASSERT_STATUS(EX_NONE, mEffect->getDescriptor(&desc));
const bool valid = isTagInRange(tag, vs, desc);
const bool valid = isParameterValid<Visualizer, Range::visualizer>(vs, desc);
const binder_exception_t expected = valid ? EX_NONE : EX_ILLEGAL_ARGUMENT;
// set parameter
@ -119,170 +110,39 @@ class VisualizerParamTest : public ::testing::TestWithParam<VisualizerParamTestP
Visualizer::Id vsId;
vsId.set<Visualizer::Id::commonTag>(tag);
id.set<Parameter::Id::visualizerTag>(vsId);
EXPECT_STATUS(EX_NONE, mEffect->getParameter(id, &getParam));
EXPECT_STATUS(EX_NONE, mEffect->getParameter(id, &getParam))
<< " with: " << id.toString();
EXPECT_EQ(expectParam, getParam) << "\nexpect:" << expectParam.toString()
<< "\ngetParam:" << getParam.toString();
}
}
}
void SetAndGetSetOnlyParameters() {
for (auto& it : mSetOnlyParamTags) {
auto& tag = it.first;
auto& vs = it.second;
// validate parameter
Descriptor desc;
ASSERT_STATUS(EX_NONE, mEffect->getDescriptor(&desc));
const bool valid = isSetOnlyParamTagInRange(vs, desc);
const binder_exception_t expected = valid ? EX_NONE : EX_ILLEGAL_ARGUMENT;
// set parameter
Parameter expectParam;
Parameter::Specific specific;
specific.set<Parameter::Specific::visualizer>(vs);
expectParam.set<Parameter::specific>(specific);
ASSERT_STATUS(expected, mEffect->setParameter(expectParam));
// parameter defined in this setOnlyParameter union must be settable via
// setParameter(), but must not be gettable
Parameter getParam;
Parameter::Id id;
Visualizer::Id vsId;
vsId.set<Visualizer::Id::setOnlyParamTag>(tag);
id.set<Parameter::Id::visualizerTag>(vsId);
EXPECT_STATUS(EX_ILLEGAL_ARGUMENT, mEffect->getParameter(id, &getParam));
}
}
void GetandSetGetOnlyParameters() {
for (auto& tag : mGetOnlyParamTags) {
// get parameter
Parameter getParam;
Parameter::Id id;
Visualizer::Id vsId;
vsId.set<Visualizer::Id::getOnlyParamTag>(tag);
id.set<Parameter::Id::visualizerTag>(vsId);
ASSERT_STATUS(EX_NONE, mEffect->getParameter(id, &getParam));
// parameter defined in this getOnlyParameter union must be gettable via
// getParameter(), but must not be settable
// set parameter
ASSERT_STATUS(EX_ILLEGAL_ARGUMENT, mEffect->setParameter(getParam));
}
}
void addCaptureSizeParam(int captureSize) {
Visualizer vs;
vs.set<Visualizer::captureSamples>(captureSize);
mCommonTags.push_back({Visualizer::captureSamples, vs});
mCommonTags.push_back({Visualizer::captureSamples,
Visualizer::make<Visualizer::captureSamples>(captureSize)});
}
void addScalingModeParam(Visualizer::ScalingMode scalingMode) {
Visualizer vs;
vs.set<Visualizer::scalingMode>(scalingMode);
mCommonTags.push_back({Visualizer::scalingMode, vs});
mCommonTags.push_back(
{Visualizer::scalingMode, Visualizer::make<Visualizer::scalingMode>(scalingMode)});
}
void addMeasurementModeParam(Visualizer::MeasurementMode measurementMode) {
Visualizer vs;
vs.set<Visualizer::measurementMode>(measurementMode);
mCommonTags.push_back({Visualizer::measurementMode, vs});
mCommonTags.push_back({Visualizer::measurementMode,
Visualizer::make<Visualizer::measurementMode>(measurementMode)});
}
void addLatencyParam(int latency) {
Visualizer vs;
Visualizer::SetOnlyParameters setOnlyParam;
setOnlyParam.set<Visualizer::SetOnlyParameters::latencyMs>(latency);
vs.set<Visualizer::setOnlyParameters>(setOnlyParam);
mSetOnlyParamTags.push_back({Visualizer::SetOnlyParameters::latencyMs, vs});
mCommonTags.push_back(
{Visualizer::latencyMs, Visualizer::make<Visualizer::latencyMs>(latency)});
}
void addMeasurementTag() {
mGetOnlyParamTags.push_back(Visualizer::GetOnlyParameters::measurement);
}
void addCaptureBytesTag() {
mGetOnlyParamTags.push_back(Visualizer::GetOnlyParameters::captureSampleBuffer);
}
bool isTagInRange(const Visualizer::Tag& tag, const Visualizer& vs,
const Descriptor& desc) const {
const Visualizer::Capability& vsCap = desc.capability.get<Capability::visualizer>();
switch (tag) {
case Visualizer::captureSamples: {
int captureSize = vs.get<Visualizer::captureSamples>();
return captureSize >= vsCap.captureSampleRange.min &&
captureSize <= vsCap.captureSampleRange.max;
}
case Visualizer::scalingMode:
case Visualizer::measurementMode:
return true;
case Visualizer::setOnlyParameters: {
auto setOnly = vs.get<Visualizer::setOnlyParameters>();
if (setOnly.getTag() != Visualizer::SetOnlyParameters::latencyMs) {
return false;
}
auto latencyMs = setOnly.get<Visualizer::SetOnlyParameters::latencyMs>();
return latencyMs >= 0 && latencyMs <= vsCap.maxLatencyMs;
}
default:
return false;
}
}
bool isSetOnlyParamTagInRange(const Visualizer& vs, const Descriptor& desc) const {
const Visualizer::Capability& vsCap = desc.capability.get<Capability::visualizer>();
if (vs.getTag() != Visualizer::setOnlyParameters) return false;
Visualizer::SetOnlyParameters setOnlyParam = vs.get<Visualizer::setOnlyParameters>();
if (setOnlyParam.getTag() != Visualizer::SetOnlyParameters::latencyMs) return false;
int latency = setOnlyParam.get<Visualizer::SetOnlyParameters::latencyMs>();
return isLatencyInRange(vsCap, latency);
}
bool isLatencyInRange(const Visualizer::Capability& cap, int latency) const {
return (latency >= 0 && latency <= cap.maxLatencyMs);
}
static std::unordered_set<int> getCaptureSizeValues() {
auto descList = EffectFactoryHelper::getAllEffectDescriptors(IFactory::descriptor,
kVisualizerTypeUUID);
int minCaptureSize = std::numeric_limits<int>::max();
int maxCaptureSize = std::numeric_limits<int>::min();
for (const auto& it : descList) {
maxCaptureSize = std::max(
it.second.capability.get<Capability::visualizer>().captureSampleRange.max,
maxCaptureSize);
minCaptureSize = std::min(
it.second.capability.get<Capability ::visualizer>().captureSampleRange.min,
minCaptureSize);
}
return {std::numeric_limits<int>::min(), minCaptureSize - 1, minCaptureSize,
(minCaptureSize + maxCaptureSize) >> 1, maxCaptureSize, maxCaptureSize + 1,
std::numeric_limits<int>::max()};
}
static std::unordered_set<int> getLatencyValues() {
auto descList = EffectFactoryHelper::getAllEffectDescriptors(IFactory::descriptor,
kVisualizerTypeUUID);
const auto max = std::max_element(
descList.begin(), descList.end(),
[](const std::pair<std::shared_ptr<IFactory>, Descriptor>& a,
const std::pair<std::shared_ptr<IFactory>, Descriptor>& b) {
return a.second.capability.get<Capability::visualizer>().maxLatencyMs <
b.second.capability.get<Capability::visualizer>().maxLatencyMs;
});
if (max == descList.end()) {
return {0};
}
int maxDelay = max->second.capability.get<Capability::visualizer>().maxLatencyMs;
return {-1, 0, maxDelay >> 1, maxDelay - 1, maxDelay, maxDelay + 1};
}
static std::unordered_set<Visualizer::MeasurementMode> getMeasurementModeValues() {
return {ndk::enum_range<Visualizer::MeasurementMode>().begin(),
ndk::enum_range<Visualizer::MeasurementMode>().end()};
}
static std::unordered_set<Visualizer::ScalingMode> getScalingModeValues() {
return {ndk::enum_range<Visualizer::ScalingMode>().begin(),
ndk::enum_range<Visualizer::ScalingMode>().end()};
@ -290,53 +150,43 @@ class VisualizerParamTest : public ::testing::TestWithParam<VisualizerParamTestP
private:
std::vector<std::pair<Visualizer::Tag, Visualizer>> mCommonTags;
std::vector<std::pair<Visualizer::SetOnlyParameters::Tag, Visualizer>> mSetOnlyParamTags;
std::vector<Visualizer::GetOnlyParameters::Tag> mGetOnlyParamTags;
void CleanUp() {
mCommonTags.clear();
mSetOnlyParamTags.clear();
mGetOnlyParamTags.clear();
}
void CleanUp() { mCommonTags.clear(); }
};
TEST_P(VisualizerParamTest, SetAndGetCaptureSize) {
EXPECT_NO_FATAL_FAILURE(addCaptureSizeParam(mCaptureSize));
SetAndGetCommonParameters();
SetAndGetParameters();
}
TEST_P(VisualizerParamTest, SetAndGetScalingMode) {
EXPECT_NO_FATAL_FAILURE(addScalingModeParam(mScalingMode));
SetAndGetCommonParameters();
SetAndGetParameters();
}
TEST_P(VisualizerParamTest, SetAndGetMeasurementMode) {
EXPECT_NO_FATAL_FAILURE(addMeasurementModeParam(mMeasurementMode));
SetAndGetCommonParameters();
SetAndGetParameters();
}
TEST_P(VisualizerParamTest, SetAndGetLatency) {
EXPECT_NO_FATAL_FAILURE(addLatencyParam(mLatency));
SetAndGetSetOnlyParameters();
}
TEST_P(VisualizerParamTest, GetAndSetMeasurement) {
EXPECT_NO_FATAL_FAILURE(addMeasurementTag());
GetandSetGetOnlyParameters();
}
TEST_P(VisualizerParamTest, GetAndSetCaptureBytes) {
EXPECT_NO_FATAL_FAILURE(addCaptureBytesTag());
GetandSetGetOnlyParameters();
SetAndGetParameters();
}
std::vector<std::pair<std::shared_ptr<IFactory>, Descriptor>> kDescPair;
INSTANTIATE_TEST_SUITE_P(
VisualizerParamTest, VisualizerParamTest,
::testing::Combine(testing::ValuesIn(EffectFactoryHelper::getAllEffectDescriptors(
IFactory::descriptor, kVisualizerTypeUUID)),
testing::ValuesIn(VisualizerParamTest::getCaptureSizeValues()),
testing::ValuesIn(VisualizerParamTest::getScalingModeValues()),
testing::ValuesIn(VisualizerParamTest::getMeasurementModeValues()),
testing::ValuesIn(VisualizerParamTest::getLatencyValues())),
::testing::Combine(
testing::ValuesIn(kDescPair = EffectFactoryHelper::getAllEffectDescriptors(
IFactory::descriptor, kVisualizerTypeUUID)),
testing::ValuesIn(EffectHelper::getTestValueSet<Visualizer, int, Range::visualizer,
Visualizer::captureSamples>(
kDescPair, EffectHelper::expandTestValueBasic<int>)),
testing::ValuesIn(VisualizerParamTest::getScalingModeValues()),
testing::ValuesIn(VisualizerParamTest::getMeasurementModeValues()),
testing::ValuesIn(EffectHelper::getTestValueSet<Visualizer, int, Range::visualizer,
Visualizer::latencyMs>(
kDescPair, EffectHelper::expandTestValueBasic<int>))),
[](const testing::TestParamInfo<VisualizerParamTest::ParamType>& info) {
auto descriptor = std::get<PARAM_INSTANCE_NAME>(info.param).second;
std::string captureSize = std::to_string(std::get<PARAM_CAPTURE_SIZE>(info.param));

View file

@ -22,7 +22,6 @@
using namespace android;
using aidl::android::hardware::audio::effect::Capability;
using aidl::android::hardware::audio::effect::Descriptor;
using aidl::android::hardware::audio::effect::IEffect;
using aidl::android::hardware::audio::effect::IFactory;
@ -84,9 +83,7 @@ class VolumeParamTest : public ::testing::TestWithParam<VolumeParamTestParam>, p
// validate parameter
Descriptor desc;
ASSERT_STATUS(EX_NONE, mEffect->getDescriptor(&desc));
// only set and get parameter if capability is valid
ASSERT_TRUE(isCapabilityValid(desc));
const bool valid = isTagInRange(it.first, it.second, desc);
const bool valid = isParameterValid<Volume, Range::volume>(it.second, desc);
const binder_exception_t expected = valid ? EX_NONE : EX_ILLEGAL_ARGUMENT;
// set parameter
@ -123,42 +120,6 @@ class VolumeParamTest : public ::testing::TestWithParam<VolumeParamTestParam>, p
mTags.push_back({Volume::mute, vol});
}
bool isCapabilityValid(const Descriptor& desc) {
const Volume::Capability& volCap = desc.capability.get<Capability::volume>();
return (volCap.minLevelDb <= volCap.maxLevelDb);
}
bool isTagInRange(const Volume::Tag& tag, const Volume& vol, const Descriptor& desc) const {
const Volume::Capability& volCap = desc.capability.get<Capability::volume>();
switch (tag) {
case Volume::levelDb: {
int level = vol.get<Volume::levelDb>();
return isLevelInRange(volCap, level);
}
case Volume::mute:
return true;
default:
return false;
}
}
static std::vector<int> getLevelTestValues(
std::vector<std::pair<std::shared_ptr<IFactory>, Descriptor>> kFactoryDescList) {
int minLevelDb = std::numeric_limits<int>::max();
int maxLevelDb = std::numeric_limits<int>::min();
for (const auto& it : kFactoryDescList) {
maxLevelDb =
std::max(it.second.capability.get<Capability::volume>().maxLevelDb, maxLevelDb);
minLevelDb = std::min(it.second.capability.get<Capability ::volume>().minLevelDb,
minLevelDb);
}
return {minLevelDb - 1, minLevelDb, -100, maxLevelDb, maxLevelDb + 1};
}
bool isLevelInRange(const Volume::Capability& volCap, int level) const {
return level >= volCap.minLevelDb && level <= volCap.maxLevelDb;
}
private:
std::vector<std::pair<Volume::Tag, Volume>> mTags;
void CleanUp() { mTags.clear(); }
@ -174,14 +135,15 @@ TEST_P(VolumeParamTest, SetAndGetMute) {
SetAndGetParameters();
}
std::vector<std::pair<std::shared_ptr<IFactory>, Descriptor>> kDescPair;
INSTANTIATE_TEST_SUITE_P(
VolumeTest, VolumeParamTest,
::testing::Combine(
testing::ValuesIn(EffectFactoryHelper::getAllEffectDescriptors(IFactory::descriptor,
kVolumeTypeUUID)),
testing::ValuesIn(VolumeParamTest::getLevelTestValues(
EffectFactoryHelper::getAllEffectDescriptors(IFactory::descriptor,
kVolumeTypeUUID))),
testing::ValuesIn(kDescPair = EffectFactoryHelper::getAllEffectDescriptors(
IFactory::descriptor, kVolumeTypeUUID)),
testing::ValuesIn(
EffectHelper::getTestValueSet<Volume, int, Range::volume, Volume::levelDb>(
kDescPair, EffectHelper::expandTestValueBasic<int>)),
testing::Bool() /* mute */),
[](const testing::TestParamInfo<VolumeParamTest::ParamType>& info) {
auto descriptor = std::get<PARAM_INSTANCE_NAME>(info.param).second;