Sham Rathod | 73aa2c3 | 2022-12-20 17:03:40 +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 | |
Sham Rathod | 73aa2c3 | 2022-12-20 17:03:40 +0530 | [diff] [blame] | 17 | #include <aidl/Vintf.h> |
Mikhail Naganov | 872d4a6 | 2023-03-09 18:19:01 -0800 | [diff] [blame] | 18 | #define LOG_TAG "VtsHalPresetReverbTargetTest" |
| 19 | #include <android-base/logging.h> |
Sham Rathod | 73aa2c3 | 2022-12-20 17:03:40 +0530 | [diff] [blame] | 20 | #include <android/binder_enums.h> |
Mikhail Naganov | 872d4a6 | 2023-03-09 18:19:01 -0800 | [diff] [blame] | 21 | |
Sham Rathod | 73aa2c3 | 2022-12-20 17:03:40 +0530 | [diff] [blame] | 22 | #include "EffectHelper.h" |
| 23 | |
| 24 | using namespace android; |
| 25 | |
Sham Rathod | 73aa2c3 | 2022-12-20 17:03:40 +0530 | [diff] [blame] | 26 | using aidl::android::hardware::audio::effect::Descriptor; |
Shunkai Yao | f8be1ac | 2023-03-06 18:41:27 +0000 | [diff] [blame] | 27 | using aidl::android::hardware::audio::effect::getEffectTypeUuidPresetReverb; |
Sham Rathod | 73aa2c3 | 2022-12-20 17:03:40 +0530 | [diff] [blame] | 28 | using aidl::android::hardware::audio::effect::IEffect; |
| 29 | using aidl::android::hardware::audio::effect::IFactory; |
Sham Rathod | 73aa2c3 | 2022-12-20 17:03:40 +0530 | [diff] [blame] | 30 | using aidl::android::hardware::audio::effect::Parameter; |
| 31 | using aidl::android::hardware::audio::effect::PresetReverb; |
| 32 | |
| 33 | /** |
| 34 | * Here we focus on specific parameter checking, general IEffect interfaces testing performed in |
| 35 | * VtsAudioEffectTargetTest. |
| 36 | */ |
| 37 | enum ParamName { PARAM_INSTANCE_NAME, PARAM_PRESETS }; |
| 38 | using PresetReverbParamTestParam = |
| 39 | std::tuple<std::pair<std::shared_ptr<IFactory>, Descriptor>, PresetReverb::Presets>; |
| 40 | |
| 41 | // Testing for enum values |
| 42 | const std::vector<PresetReverb::Presets> kPresetsValues{ |
| 43 | ndk::enum_range<PresetReverb::Presets>().begin(), |
| 44 | ndk::enum_range<PresetReverb::Presets>().end()}; |
| 45 | |
| 46 | class PresetReverbParamTest : public ::testing::TestWithParam<PresetReverbParamTestParam>, |
| 47 | public EffectHelper { |
| 48 | public: |
| 49 | PresetReverbParamTest() : mParamPresets(std::get<PARAM_PRESETS>(GetParam())) { |
| 50 | std::tie(mFactory, mDescriptor) = std::get<PARAM_INSTANCE_NAME>(GetParam()); |
| 51 | } |
| 52 | |
| 53 | void SetUp() override { |
| 54 | ASSERT_NE(nullptr, mFactory); |
| 55 | ASSERT_NO_FATAL_FAILURE(create(mFactory, mEffect, mDescriptor)); |
| 56 | |
| 57 | Parameter::Specific specific = getDefaultParamSpecific(); |
| 58 | Parameter::Common common = EffectHelper::createParamCommon( |
| 59 | 0 /* session */, 1 /* ioHandle */, 44100 /* iSampleRate */, 44100 /* oSampleRate */, |
| 60 | kInputFrameCount /* iFrameCount */, kOutputFrameCount /* oFrameCount */); |
| 61 | IEffect::OpenEffectReturn ret; |
| 62 | ASSERT_NO_FATAL_FAILURE(open(mEffect, common, specific, &ret, EX_NONE)); |
| 63 | ASSERT_NE(nullptr, mEffect); |
| 64 | } |
| 65 | |
| 66 | void TearDown() override { |
| 67 | ASSERT_NO_FATAL_FAILURE(close(mEffect)); |
| 68 | ASSERT_NO_FATAL_FAILURE(destroy(mFactory, mEffect)); |
| 69 | } |
| 70 | |
| 71 | static const long kInputFrameCount = 0x100, kOutputFrameCount = 0x100; |
| 72 | std::shared_ptr<IFactory> mFactory; |
| 73 | std::shared_ptr<IEffect> mEffect; |
| 74 | Descriptor mDescriptor; |
| 75 | PresetReverb::Presets mParamPresets = PresetReverb::Presets::NONE; |
| 76 | |
| 77 | void SetAndGetPresetReverbParameters() { |
| 78 | for (auto& it : mTags) { |
| 79 | auto& tag = it.first; |
| 80 | auto& pr = it.second; |
| 81 | |
| 82 | // validate parameter |
| 83 | Descriptor desc; |
| 84 | ASSERT_STATUS(EX_NONE, mEffect->getDescriptor(&desc)); |
Shunkai Yao | 0a0c45e | 2023-02-13 17:41:11 +0000 | [diff] [blame] | 85 | const bool valid = isParameterValid<PresetReverb, Range::presetReverb>(it.second, desc); |
Sham Rathod | 73aa2c3 | 2022-12-20 17:03:40 +0530 | [diff] [blame] | 86 | const binder_exception_t expected = valid ? EX_NONE : EX_ILLEGAL_ARGUMENT; |
| 87 | |
| 88 | // set parameter |
| 89 | Parameter expectParam; |
| 90 | Parameter::Specific specific; |
| 91 | specific.set<Parameter::Specific::presetReverb>(pr); |
| 92 | expectParam.set<Parameter::specific>(specific); |
| 93 | // All values are valid, set parameter should succeed |
| 94 | EXPECT_STATUS(expected, mEffect->setParameter(expectParam)) << expectParam.toString(); |
| 95 | |
| 96 | // get parameter |
| 97 | Parameter getParam; |
| 98 | Parameter::Id id; |
| 99 | PresetReverb::Id prId; |
| 100 | prId.set<PresetReverb::Id::commonTag>(tag); |
| 101 | id.set<Parameter::Id::presetReverbTag>(prId); |
| 102 | EXPECT_STATUS(expected, mEffect->getParameter(id, &getParam)); |
| 103 | |
| 104 | EXPECT_EQ(expectParam, getParam); |
| 105 | } |
| 106 | } |
| 107 | |
| 108 | void addPresetsParam(PresetReverb::Presets preset) { |
| 109 | PresetReverb pr; |
| 110 | pr.set<PresetReverb::preset>(preset); |
| 111 | mTags.push_back({PresetReverb::preset, pr}); |
| 112 | } |
| 113 | |
Sham Rathod | 73aa2c3 | 2022-12-20 17:03:40 +0530 | [diff] [blame] | 114 | Parameter::Specific getDefaultParamSpecific() { |
| 115 | PresetReverb pr = PresetReverb::make<PresetReverb::preset>(PresetReverb::Presets::NONE); |
| 116 | Parameter::Specific specific = |
| 117 | Parameter::Specific::make<Parameter::Specific::presetReverb>(pr); |
| 118 | return specific; |
| 119 | } |
| 120 | |
| 121 | private: |
| 122 | std::vector<std::pair<PresetReverb::Tag, PresetReverb>> mTags; |
| 123 | void CleanUp() { mTags.clear(); } |
| 124 | }; |
| 125 | |
| 126 | TEST_P(PresetReverbParamTest, SetAndGetPresets) { |
| 127 | EXPECT_NO_FATAL_FAILURE(addPresetsParam(mParamPresets)); |
| 128 | SetAndGetPresetReverbParameters(); |
| 129 | } |
| 130 | |
| 131 | INSTANTIATE_TEST_SUITE_P( |
| 132 | PresetReverbTest, PresetReverbParamTest, |
| 133 | ::testing::Combine(testing::ValuesIn(EffectFactoryHelper::getAllEffectDescriptors( |
Shunkai Yao | f8be1ac | 2023-03-06 18:41:27 +0000 | [diff] [blame] | 134 | IFactory::descriptor, getEffectTypeUuidPresetReverb())), |
Sham Rathod | 73aa2c3 | 2022-12-20 17:03:40 +0530 | [diff] [blame] | 135 | testing::ValuesIn(kPresetsValues)), |
| 136 | [](const testing::TestParamInfo<PresetReverbParamTest::ParamType>& info) { |
| 137 | auto descriptor = std::get<PARAM_INSTANCE_NAME>(info.param).second; |
| 138 | std::string preset = |
| 139 | std::to_string(static_cast<int>(std::get<PARAM_PRESETS>(info.param))); |
| 140 | std::string name = "Implementor_" + descriptor.common.implementor + "_name_" + |
| 141 | descriptor.common.name + "_UUID_" + |
| 142 | descriptor.common.id.uuid.toString() + "_preset" + preset; |
| 143 | std::replace_if( |
| 144 | name.begin(), name.end(), [](const char c) { return !std::isalnum(c); }, '_'); |
| 145 | return name; |
| 146 | }); |
| 147 | |
| 148 | GTEST_ALLOW_UNINSTANTIATED_PARAMETERIZED_TEST(PresetReverbParamTest); |
| 149 | |
| 150 | int main(int argc, char** argv) { |
| 151 | ::testing::InitGoogleTest(&argc, argv); |
| 152 | ABinderProcess_setThreadPoolMaxThreadCount(1); |
| 153 | ABinderProcess_startThreadPool(); |
| 154 | return RUN_ALL_TESTS(); |
| 155 | } |