Shraddha Basantwani | f627d80 | 2022-11-08 14:45:07 +0530 | [diff] [blame] | 1 | /* |
| 2 | * Copyright (C) 2022 The Android Open Source Project |
| 3 | * |
| 4 | * Licensed under the Apache License, Version 2.0 (the "License"); |
| 5 | * you may not use this file except in compliance with the License. |
| 6 | * You may obtain a copy of the License at |
| 7 | * |
| 8 | * http://www.apache.org/licenses/LICENSE-2.0 |
| 9 | * |
| 10 | * Unless required by applicable law or agreed to in writing, software |
| 11 | * distributed under the License is distributed on an "AS IS" BASIS, |
| 12 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. |
| 13 | * See the License for the specific language governing permissions and |
| 14 | * limitations under the License. |
| 15 | */ |
| 16 | |
| 17 | #define LOG_TAG "VtsHalBassBoostTest" |
| 18 | |
| 19 | #include <Utils.h> |
| 20 | #include <aidl/Vintf.h> |
| 21 | #include <limits.h> |
| 22 | |
| 23 | #include "EffectHelper.h" |
| 24 | |
| 25 | using namespace android; |
| 26 | |
| 27 | using aidl::android::hardware::audio::effect::BassBoost; |
| 28 | using aidl::android::hardware::audio::effect::Capability; |
| 29 | using aidl::android::hardware::audio::effect::Descriptor; |
| 30 | using aidl::android::hardware::audio::effect::IEffect; |
| 31 | using aidl::android::hardware::audio::effect::IFactory; |
| 32 | using aidl::android::hardware::audio::effect::kBassBoostTypeUUID; |
| 33 | using aidl::android::hardware::audio::effect::Parameter; |
Shunkai Yao | 0a0c45e | 2023-02-13 17:41:11 +0000 | [diff] [blame] | 34 | using aidl::android::hardware::audio::effect::Range; |
Shraddha Basantwani | f627d80 | 2022-11-08 14:45:07 +0530 | [diff] [blame] | 35 | |
| 36 | /** |
| 37 | * Here we focus on specific parameter checking, general IEffect interfaces testing performed in |
| 38 | * VtsAudioEffectTargetTest. |
| 39 | */ |
| 40 | enum ParamName { PARAM_INSTANCE_NAME, PARAM_STRENGTH }; |
Shunkai Yao | cb0fc41 | 2022-12-15 20:34:32 +0000 | [diff] [blame] | 41 | using BassBoostParamTestParam = std::tuple<std::pair<std::shared_ptr<IFactory>, Descriptor>, int>; |
Shraddha Basantwani | f627d80 | 2022-11-08 14:45:07 +0530 | [diff] [blame] | 42 | |
| 43 | /* |
| 44 | * Testing parameter range, assuming the parameter supported by effect is in this range. |
| 45 | * Parameter should be within the valid range defined in the documentation, |
| 46 | * for any supported value test expects EX_NONE from IEffect.setParameter(), |
| 47 | * otherwise expect EX_ILLEGAL_ARGUMENT. |
| 48 | */ |
| 49 | |
Shraddha Basantwani | f627d80 | 2022-11-08 14:45:07 +0530 | [diff] [blame] | 50 | class BassBoostParamTest : public ::testing::TestWithParam<BassBoostParamTestParam>, |
| 51 | public EffectHelper { |
| 52 | public: |
| 53 | BassBoostParamTest() : mParamStrength(std::get<PARAM_STRENGTH>(GetParam())) { |
Shunkai Yao | cb0fc41 | 2022-12-15 20:34:32 +0000 | [diff] [blame] | 54 | std::tie(mFactory, mDescriptor) = std::get<PARAM_INSTANCE_NAME>(GetParam()); |
Shraddha Basantwani | f627d80 | 2022-11-08 14:45:07 +0530 | [diff] [blame] | 55 | } |
| 56 | |
| 57 | void SetUp() override { |
| 58 | ASSERT_NE(nullptr, mFactory); |
Shunkai Yao | cb0fc41 | 2022-12-15 20:34:32 +0000 | [diff] [blame] | 59 | ASSERT_NO_FATAL_FAILURE(create(mFactory, mEffect, mDescriptor)); |
Shraddha Basantwani | f627d80 | 2022-11-08 14:45:07 +0530 | [diff] [blame] | 60 | |
| 61 | Parameter::Specific specific = getDefaultParamSpecific(); |
| 62 | Parameter::Common common = EffectHelper::createParamCommon( |
| 63 | 0 /* session */, 1 /* ioHandle */, 44100 /* iSampleRate */, 44100 /* oSampleRate */, |
| 64 | kInputFrameCount /* iFrameCount */, kOutputFrameCount /* oFrameCount */); |
| 65 | IEffect::OpenEffectReturn ret; |
| 66 | ASSERT_NO_FATAL_FAILURE(open(mEffect, common, specific, &ret, EX_NONE)); |
| 67 | ASSERT_NE(nullptr, mEffect); |
| 68 | } |
| 69 | |
| 70 | void TearDown() override { |
| 71 | ASSERT_NO_FATAL_FAILURE(close(mEffect)); |
| 72 | ASSERT_NO_FATAL_FAILURE(destroy(mFactory, mEffect)); |
| 73 | } |
| 74 | |
| 75 | Parameter::Specific getDefaultParamSpecific() { |
Sham Rathod | 8411fd2 | 2022-12-27 10:27:03 +0530 | [diff] [blame] | 76 | BassBoost bb = BassBoost::make<BassBoost::strengthPm>(0); |
Shraddha Basantwani | f627d80 | 2022-11-08 14:45:07 +0530 | [diff] [blame] | 77 | Parameter::Specific specific = |
| 78 | Parameter::Specific::make<Parameter::Specific::bassBoost>(bb); |
| 79 | return specific; |
| 80 | } |
| 81 | |
| 82 | static const long kInputFrameCount = 0x100, kOutputFrameCount = 0x100; |
| 83 | std::shared_ptr<IFactory> mFactory; |
| 84 | std::shared_ptr<IEffect> mEffect; |
Shunkai Yao | cb0fc41 | 2022-12-15 20:34:32 +0000 | [diff] [blame] | 85 | Descriptor mDescriptor; |
Sham Rathod | 8411fd2 | 2022-12-27 10:27:03 +0530 | [diff] [blame] | 86 | int mParamStrength = 0; |
Shraddha Basantwani | f627d80 | 2022-11-08 14:45:07 +0530 | [diff] [blame] | 87 | |
| 88 | void SetAndGetBassBoostParameters() { |
| 89 | for (auto& it : mTags) { |
| 90 | auto& tag = it.first; |
| 91 | auto& bb = it.second; |
| 92 | |
| 93 | // validate parameter |
| 94 | Descriptor desc; |
| 95 | ASSERT_STATUS(EX_NONE, mEffect->getDescriptor(&desc)); |
Shunkai Yao | 0a0c45e | 2023-02-13 17:41:11 +0000 | [diff] [blame] | 96 | const bool valid = isParameterValid<BassBoost, Range::bassBoost>(it.second, desc); |
Shraddha Basantwani | f627d80 | 2022-11-08 14:45:07 +0530 | [diff] [blame] | 97 | const binder_exception_t expected = valid ? EX_NONE : EX_ILLEGAL_ARGUMENT; |
| 98 | |
| 99 | // set parameter |
| 100 | Parameter expectParam; |
| 101 | Parameter::Specific specific; |
| 102 | specific.set<Parameter::Specific::bassBoost>(bb); |
| 103 | expectParam.set<Parameter::specific>(specific); |
| 104 | EXPECT_STATUS(expected, mEffect->setParameter(expectParam)) << expectParam.toString(); |
| 105 | |
| 106 | // only get if parameter in range and set success |
| 107 | if (expected == EX_NONE) { |
| 108 | Parameter getParam; |
| 109 | Parameter::Id id; |
| 110 | BassBoost::Id bbId; |
| 111 | bbId.set<BassBoost::Id::commonTag>(tag); |
| 112 | id.set<Parameter::Id::bassBoostTag>(bbId); |
| 113 | // if set success, then get should match |
| 114 | EXPECT_STATUS(expected, mEffect->getParameter(id, &getParam)); |
| 115 | EXPECT_EQ(expectParam, getParam); |
| 116 | } |
| 117 | } |
| 118 | } |
| 119 | |
| 120 | void addStrengthParam(int strength) { |
| 121 | BassBoost bb; |
| 122 | bb.set<BassBoost::strengthPm>(strength); |
| 123 | mTags.push_back({BassBoost::strengthPm, bb}); |
| 124 | } |
| 125 | |
Shraddha Basantwani | f627d80 | 2022-11-08 14:45:07 +0530 | [diff] [blame] | 126 | private: |
| 127 | std::vector<std::pair<BassBoost::Tag, BassBoost>> mTags; |
| 128 | void CleanUp() { mTags.clear(); } |
| 129 | }; |
| 130 | |
| 131 | TEST_P(BassBoostParamTest, SetAndGetStrength) { |
| 132 | EXPECT_NO_FATAL_FAILURE(addStrengthParam(mParamStrength)); |
| 133 | SetAndGetBassBoostParameters(); |
| 134 | } |
| 135 | |
Shunkai Yao | 0a0c45e | 2023-02-13 17:41:11 +0000 | [diff] [blame] | 136 | std::vector<std::pair<std::shared_ptr<IFactory>, Descriptor>> kDescPair; |
Shraddha Basantwani | f627d80 | 2022-11-08 14:45:07 +0530 | [diff] [blame] | 137 | INSTANTIATE_TEST_SUITE_P( |
| 138 | BassBoostTest, BassBoostParamTest, |
Sham Rathod | 8411fd2 | 2022-12-27 10:27:03 +0530 | [diff] [blame] | 139 | ::testing::Combine( |
Shunkai Yao | 0a0c45e | 2023-02-13 17:41:11 +0000 | [diff] [blame] | 140 | testing::ValuesIn(kDescPair = EffectFactoryHelper::getAllEffectDescriptors( |
| 141 | IFactory::descriptor, kBassBoostTypeUUID)), |
| 142 | testing::ValuesIn(EffectHelper::getTestValueSet<BassBoost, int, Range::bassBoost, |
| 143 | BassBoost::strengthPm>( |
| 144 | kDescPair, EffectHelper::expandTestValueBasic<int>))), |
Shraddha Basantwani | f627d80 | 2022-11-08 14:45:07 +0530 | [diff] [blame] | 145 | [](const testing::TestParamInfo<BassBoostParamTest::ParamType>& info) { |
Shunkai Yao | cb0fc41 | 2022-12-15 20:34:32 +0000 | [diff] [blame] | 146 | auto descriptor = std::get<PARAM_INSTANCE_NAME>(info.param).second; |
Shraddha Basantwani | f627d80 | 2022-11-08 14:45:07 +0530 | [diff] [blame] | 147 | std::string strength = std::to_string(std::get<PARAM_STRENGTH>(info.param)); |
Shunkai Yao | cb0fc41 | 2022-12-15 20:34:32 +0000 | [diff] [blame] | 148 | std::string name = "Implementor_" + descriptor.common.implementor + "_name_" + |
| 149 | descriptor.common.name + "_UUID_" + |
| 150 | descriptor.common.id.uuid.toString() + "_strength_" + strength; |
Shraddha Basantwani | f627d80 | 2022-11-08 14:45:07 +0530 | [diff] [blame] | 151 | std::replace_if( |
| 152 | name.begin(), name.end(), [](const char c) { return !std::isalnum(c); }, '_'); |
| 153 | return name; |
| 154 | }); |
| 155 | |
| 156 | GTEST_ALLOW_UNINSTANTIATED_PARAMETERIZED_TEST(BassBoostParamTest); |
| 157 | |
| 158 | int main(int argc, char** argv) { |
| 159 | ::testing::InitGoogleTest(&argc, argv); |
| 160 | ABinderProcess_setThreadPoolMaxThreadCount(1); |
| 161 | ABinderProcess_startThreadPool(); |
| 162 | return RUN_ALL_TESTS(); |
| 163 | } |