blob: c01a9a2d3681136015229fc7025c653f470a3917 [file] [log] [blame]
Sham Rathod40f55bd2022-11-14 14:24:49 +05301/*
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 Rathod40f55bd2022-11-14 14:24:49 +053017#include <aidl/Vintf.h>
Mikhail Naganov872d4a62023-03-09 18:19:01 -080018#define LOG_TAG "VtsHalDownmixTargetTest"
19#include <android-base/logging.h>
20
Sham Rathod40f55bd2022-11-14 14:24:49 +053021#include "EffectHelper.h"
22
23using namespace android;
24
Sham Rathod40f55bd2022-11-14 14:24:49 +053025using aidl::android::hardware::audio::effect::Descriptor;
26using aidl::android::hardware::audio::effect::Downmix;
Shunkai Yaof8be1ac2023-03-06 18:41:27 +000027using aidl::android::hardware::audio::effect::getEffectTypeUuidDownmix;
Sham Rathod40f55bd2022-11-14 14:24:49 +053028using aidl::android::hardware::audio::effect::IEffect;
29using aidl::android::hardware::audio::effect::IFactory;
Sham Rathod40f55bd2022-11-14 14:24:49 +053030using aidl::android::hardware::audio::effect::Parameter;
Jaideep Sharma74498412023-09-13 15:25:25 +053031using android::hardware::audio::common::testing::detail::TestExecutionTracer;
Sham Rathod40f55bd2022-11-14 14:24:49 +053032/**
33 * Here we focus on specific parameter checking, general IEffect interfaces testing performed in
34 * VtsAudioEffectTargetTest.
35 */
36enum ParamName { PARAM_INSTANCE_NAME, PARAM_TYPE };
37using DownmixParamTestParam =
38 std::tuple<std::pair<std::shared_ptr<IFactory>, Descriptor>, Downmix::Type>;
39
40// Testing for enum values
41const std::vector<Downmix::Type> kTypeValues = {Downmix::Type::STRIP, Downmix::Type::FOLD};
42
43class DownmixParamTest : public ::testing::TestWithParam<DownmixParamTestParam>,
44 public EffectHelper {
45 public:
46 DownmixParamTest() : mParamType(std::get<PARAM_TYPE>(GetParam())) {
47 std::tie(mFactory, mDescriptor) = std::get<PARAM_INSTANCE_NAME>(GetParam());
48 }
49
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
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
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
99 void addTypeParam(Downmix::Type type) {
100 Downmix dm;
101 dm.set<Downmix::type>(type);
102 mTags.push_back({Downmix::type, dm});
103 }
104
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;
113 void CleanUp() { mTags.clear(); }
114};
115
116TEST_P(DownmixParamTest, SetAndGetType) {
117 EXPECT_NO_FATAL_FAILURE(addTypeParam(mParamType));
118 SetAndGetDownmixParameters();
119}
120
121INSTANTIATE_TEST_SUITE_P(
122 DownmixTest, DownmixParamTest,
123 ::testing::Combine(testing::ValuesIn(EffectFactoryHelper::getAllEffectDescriptors(
Shunkai Yaof8be1ac2023-03-06 18:41:27 +0000124 IFactory::descriptor, getEffectTypeUuidDownmix())),
Sham Rathod40f55bd2022-11-14 14:24:49 +0530125 testing::ValuesIn(kTypeValues)),
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)));
Jaideep Sharmae4c7a962023-06-14 19:14:44 +0530129 std::string name = getPrefix(descriptor) + "_type" + type;
Sham Rathod40f55bd2022-11-14 14:24:49 +0530130 std::replace_if(
131 name.begin(), name.end(), [](const char c) { return !std::isalnum(c); }, '_');
132 return name;
133 });
134
135GTEST_ALLOW_UNINSTANTIATED_PARAMETERIZED_TEST(DownmixParamTest);
136
137int main(int argc, char** argv) {
138 ::testing::InitGoogleTest(&argc, argv);
Jaideep Sharma74498412023-09-13 15:25:25 +0530139 ::testing::UnitTest::GetInstance()->listeners().Append(new TestExecutionTracer());
Sham Rathod40f55bd2022-11-14 14:24:49 +0530140 ABinderProcess_setThreadPoolMaxThreadCount(1);
141 ABinderProcess_startThreadPool();
142 return RUN_ALL_TESTS();
143}