Donate to e Foundation | Murena handsets with /e/OS | Own a part of Murena! Learn more

Commit 4a2d3b97 authored by Shunkai Yao's avatar Shunkai Yao Committed by Automerger Merge Worker
Browse files

Effect AIDL: Refactor effect capability with Range vts test cases am: 0a0c45ef

parents e2e4ad10 0a0c45ef
Loading
Loading
Loading
Loading
+0 −3
Original line number Diff line number Diff line
@@ -12,9 +12,6 @@
    {
      "name": "VtsHalDownmixTargetTest"
    },
    {
      "name": "VtsHalDynamicsProcessingTargetTest"
    },
    {
      "name": "VtsHalEnvironmentalReverbTargetTest"
    },
+57 −0
Original line number Diff line number Diff line
@@ -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);
    }
};
+16 −54
Original line number Diff line number Diff line
@@ -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(
        ::testing::Combine(
                testing::ValuesIn(kDescPair = EffectFactoryHelper::getAllEffectDescriptors(
                                          IFactory::descriptor, kAcousticEchoCancelerTypeUUID)),
                           testing::ValuesIn(AECParamTest::getEchoDelayTestValues()),
                           testing::ValuesIn(AECParamTest::getMobileModeValues())),
                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));
+16 −66
Original line number Diff line number Diff line
@@ -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,12 +160,20 @@ 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(
        ::testing::Combine(
                testing::ValuesIn(kDescPair = EffectFactoryHelper::getAllEffectDescriptors(
                                          IFactory::descriptor, kAutomaticGainControlTypeUUID)),
                           testing::ValuesIn(AGCParamTest::getDigitalGainValues()),
                           testing::ValuesIn(AGCParamTest::getSaturationMarginValues()),
                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;
+8 −46
Original line number Diff line number Diff line
@@ -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));
Loading