• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
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 #include <aidl/Vintf.h>
18 #define LOG_TAG "VtsHalDownmixTargetTest"
19 #include <android-base/logging.h>
20 
21 #include "EffectHelper.h"
22 
23 using namespace android;
24 
25 using aidl::android::hardware::audio::effect::Descriptor;
26 using aidl::android::hardware::audio::effect::Downmix;
27 using aidl::android::hardware::audio::effect::getEffectTypeUuidDownmix;
28 using aidl::android::hardware::audio::effect::IEffect;
29 using aidl::android::hardware::audio::effect::IFactory;
30 using aidl::android::hardware::audio::effect::Parameter;
31 
32 /**
33  * Here we focus on specific parameter checking, general IEffect interfaces testing performed in
34  * VtsAudioEffectTargetTest.
35  */
36 enum ParamName { PARAM_INSTANCE_NAME, PARAM_TYPE };
37 using DownmixParamTestParam =
38         std::tuple<std::pair<std::shared_ptr<IFactory>, Descriptor>, Downmix::Type>;
39 
40 // Testing for enum values
41 const std::vector<Downmix::Type> kTypeValues = {Downmix::Type::STRIP, Downmix::Type::FOLD};
42 
43 class DownmixParamTest : public ::testing::TestWithParam<DownmixParamTestParam>,
44                          public EffectHelper {
45   public:
DownmixParamTest()46     DownmixParamTest() : mParamType(std::get<PARAM_TYPE>(GetParam())) {
47         std::tie(mFactory, mDescriptor) = std::get<PARAM_INSTANCE_NAME>(GetParam());
48     }
49 
SetUp()50     void SetUp() override {
51         ASSERT_NE(nullptr, mFactory);
52         ASSERT_NO_FATAL_FAILURE(create(mFactory, mEffect, mDescriptor));
53 
54         Parameter::Specific specific = getDefaultParamSpecific();
55         Parameter::Common common = EffectHelper::createParamCommon(
56                 0 /* session */, 1 /* ioHandle */, 44100 /* iSampleRate */, 44100 /* oSampleRate */,
57                 kInputFrameCount /* iFrameCount */, kOutputFrameCount /* oFrameCount */);
58         IEffect::OpenEffectReturn ret;
59         ASSERT_NO_FATAL_FAILURE(open(mEffect, common, specific, &ret, EX_NONE));
60         ASSERT_NE(nullptr, mEffect);
61     }
62 
TearDown()63     void TearDown() override {
64         ASSERT_NO_FATAL_FAILURE(close(mEffect));
65         ASSERT_NO_FATAL_FAILURE(destroy(mFactory, mEffect));
66     }
67 
68     static const long kInputFrameCount = 0x100, kOutputFrameCount = 0x100;
69     std::shared_ptr<IFactory> mFactory;
70     std::shared_ptr<IEffect> mEffect;
71     Descriptor mDescriptor;
72     Downmix::Type mParamType = Downmix::Type::STRIP;
73 
SetAndGetDownmixParameters()74     void SetAndGetDownmixParameters() {
75         for (auto& it : mTags) {
76             auto& tag = it.first;
77             auto& dm = it.second;
78 
79             // set parameter
80             Parameter expectParam;
81             Parameter::Specific specific;
82             specific.set<Parameter::Specific::downmix>(dm);
83             expectParam.set<Parameter::specific>(specific);
84             // All values are valid, set parameter should succeed
85             EXPECT_STATUS(EX_NONE, mEffect->setParameter(expectParam)) << expectParam.toString();
86 
87             // get parameter
88             Parameter getParam;
89             Parameter::Id id;
90             Downmix::Id dmId;
91             dmId.set<Downmix::Id::commonTag>(tag);
92             id.set<Parameter::Id::downmixTag>(dmId);
93             EXPECT_STATUS(EX_NONE, mEffect->getParameter(id, &getParam));
94 
95             EXPECT_EQ(expectParam, getParam);
96         }
97     }
98 
addTypeParam(Downmix::Type type)99     void addTypeParam(Downmix::Type type) {
100         Downmix dm;
101         dm.set<Downmix::type>(type);
102         mTags.push_back({Downmix::type, dm});
103     }
104 
getDefaultParamSpecific()105     Parameter::Specific getDefaultParamSpecific() {
106         Downmix dm = Downmix::make<Downmix::type>(Downmix::Type::STRIP);
107         Parameter::Specific specific = Parameter::Specific::make<Parameter::Specific::downmix>(dm);
108         return specific;
109     }
110 
111   private:
112     std::vector<std::pair<Downmix::Tag, Downmix>> mTags;
CleanUp()113     void CleanUp() { mTags.clear(); }
114 };
115 
TEST_P(DownmixParamTest,SetAndGetType)116 TEST_P(DownmixParamTest, SetAndGetType) {
117     EXPECT_NO_FATAL_FAILURE(addTypeParam(mParamType));
118     SetAndGetDownmixParameters();
119 }
120 
121 INSTANTIATE_TEST_SUITE_P(
122         DownmixTest, DownmixParamTest,
123         ::testing::Combine(testing::ValuesIn(EffectFactoryHelper::getAllEffectDescriptors(
124                                    IFactory::descriptor, getEffectTypeUuidDownmix())),
125                            testing::ValuesIn(kTypeValues)),
__anon96c69e9a0102(const testing::TestParamInfo<DownmixParamTest::ParamType>& info) 126         [](const testing::TestParamInfo<DownmixParamTest::ParamType>& info) {
127             auto descriptor = std::get<PARAM_INSTANCE_NAME>(info.param).second;
128             std::string type = std::to_string(static_cast<int>(std::get<PARAM_TYPE>(info.param)));
129             std::string name = getPrefix(descriptor) + "_type" + type;
130             std::replace_if(
131                     name.begin(), name.end(), [](const char c) { return !std::isalnum(c); }, '_');
132             return name;
133         });
134 
135 GTEST_ALLOW_UNINSTANTIATED_PARAMETERIZED_TEST(DownmixParamTest);
136 
main(int argc,char ** argv)137 int main(int argc, char** argv) {
138     ::testing::InitGoogleTest(&argc, argv);
139     ABinderProcess_setThreadPoolMaxThreadCount(1);
140     ABinderProcess_startThreadPool();
141     return RUN_ALL_TESTS();
142 }
143