blob: f70948c3be628417cc2423d48581caf9ec0aabb5 [file] [log] [blame]
Shunkai Yao67b1be62022-07-13 05:01:42 +00001/*
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 <string>
18
19#define LOG_TAG "VtsHalAudioEffect"
20
21#include <aidl/Gtest.h>
22#include <aidl/Vintf.h>
23#include <android-base/logging.h>
24#include <android-base/properties.h>
25#include <android/binder_interface_utils.h>
26#include <android/binder_manager.h>
27#include <android/binder_process.h>
28
29#include <aidl/android/hardware/audio/effect/IFactory.h>
30
31#include "AudioHalBinderServiceUtil.h"
32
33using namespace android;
34
35using ndk::ScopedAStatus;
36
37using aidl::android::hardware::audio::effect::Descriptor;
38using aidl::android::hardware::audio::effect::IFactory;
39using aidl::android::media::audio::common::AudioUuid;
40
41namespace ndk {
42std::ostream& operator<<(std::ostream& str, const ScopedAStatus& status) {
43 str << status.getDescription();
44 return str;
45}
46} // namespace ndk
47
48class EffectFactory : public testing::TestWithParam<std::string> {
49 public:
50 void SetUp() override { ASSERT_NO_FATAL_FAILURE(ConnectToService()); }
51
52 void TearDown() override {}
53
54 void ConnectToService() {
55 serviceName = GetParam();
56 factory = IFactory::fromBinder(binderUtil.connectToService(serviceName));
57 ASSERT_NE(factory, nullptr);
58 }
59
60 void RestartService() {
61 ASSERT_NE(factory, nullptr);
62 factory = IFactory::fromBinder(binderUtil.restartService());
63 ASSERT_NE(factory, nullptr);
64 }
65
66 std::shared_ptr<IFactory> factory;
67 std::string serviceName;
68 AudioHalBinderServiceUtil binderUtil;
69 // TODO: these UUID can get from config file
70 // ec7178ec-e5e1-4432-a3f4-4657e6795210
71 const AudioUuid nullUuid = {static_cast<int32_t>(0xec7178ec),
72 0xe5e1,
73 0x4432,
74 0xa3f4,
75 {0x46, 0x57, 0xe6, 0x79, 0x52, 0x10}};
76 const AudioUuid zeroUuid = {
77 static_cast<int32_t>(0x0), 0x0, 0x0, 0x0, {0x0, 0x0, 0x0, 0x0, 0x0, 0x0}};
78};
79
80TEST_P(EffectFactory, SetupAndTearDown) {
81 // Intentionally empty test body.
82}
83
84TEST_P(EffectFactory, CanBeRestarted) {
85 ASSERT_NO_FATAL_FAILURE(RestartService());
86}
87
88TEST_P(EffectFactory, QueriedDescriptorList) {
89 std::vector<Descriptor::Identity> descriptors;
90 ScopedAStatus status = factory->queryEffects(std::nullopt, std::nullopt, &descriptors);
91 EXPECT_EQ(EX_NONE, status.getExceptionCode());
92 EXPECT_NE(static_cast<int>(descriptors.size()), 0);
93}
94
95TEST_P(EffectFactory, DescriptorUUIDNotNull) {
96 std::vector<Descriptor::Identity> descriptors;
97 ScopedAStatus status = factory->queryEffects(std::nullopt, std::nullopt, &descriptors);
98 EXPECT_EQ(EX_NONE, status.getExceptionCode());
99 // TODO: Factory eventually need to return the full list of MUST supported AOSP effects.
100 for (auto& desc : descriptors) {
101 EXPECT_NE(desc.type, zeroUuid);
102 EXPECT_NE(desc.uuid, zeroUuid);
103 }
104}
105
106TEST_P(EffectFactory, QueriedDescriptorNotExistType) {
107 std::vector<Descriptor::Identity> descriptors;
108 ScopedAStatus status = factory->queryEffects(nullUuid, std::nullopt, &descriptors);
109 EXPECT_EQ(EX_NONE, status.getExceptionCode());
110 EXPECT_EQ(static_cast<int>(descriptors.size()), 0);
111}
112
113TEST_P(EffectFactory, QueriedDescriptorNotExistInstance) {
114 std::vector<Descriptor::Identity> descriptors;
115 ScopedAStatus status = factory->queryEffects(std::nullopt, nullUuid, &descriptors);
116 EXPECT_EQ(EX_NONE, status.getExceptionCode());
117 EXPECT_EQ(static_cast<int>(descriptors.size()), 0);
118}
119
120INSTANTIATE_TEST_SUITE_P(EffectFactoryTest, EffectFactory,
121 testing::ValuesIn(android::getAidlHalInstanceNames(IFactory::descriptor)),
122 android::PrintInstanceNameToString);
123GTEST_ALLOW_UNINSTANTIATED_PARAMETERIZED_TEST(EffectFactory);
124
125int main(int argc, char** argv) {
126 ::testing::InitGoogleTest(&argc, argv);
127 ABinderProcess_setThreadPoolMaxThreadCount(1);
128 ABinderProcess_startThreadPool();
129 return RUN_ALL_TESTS();
130}