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 "EArc_hal_test"
18
19 #include <aidl/Gtest.h>
20 #include <aidl/Vintf.h>
21 #include <aidl/android/hardware/tv/hdmi/earc/BnEArcCallback.h>
22 #include <aidl/android/hardware/tv/hdmi/earc/IEArc.h>
23 #include <aidl/android/hardware/tv/hdmi/earc/IEArcStatus.h>
24 #include <android-base/logging.h>
25 #include <android/binder_manager.h>
26 #include <android/binder_process.h>
27 #include <gtest/gtest.h>
28 #include <log/log.h>
29 #include <sstream>
30 #include <vector>
31
32 using ::aidl::android::hardware::tv::hdmi::earc::BnEArcCallback;
33 using ::aidl::android::hardware::tv::hdmi::earc::IEArc;
34 using ::aidl::android::hardware::tv::hdmi::earc::IEArcCallback;
35 using ::aidl::android::hardware::tv::hdmi::earc::IEArcStatus;
36 using ::ndk::SpAIBinder;
37
38 // The main test class for TV EARC HAL.
39 class EArcTest : public ::testing::TestWithParam<std::string> {
serviceDied(void *)40 static void serviceDied(void* /* cookie */) { ALOGE("VtsHalTvCecAidlTargetTest died"); }
41
42 public:
SetUp()43 void SetUp() override {
44 eArc = IEArc::fromBinder(SpAIBinder(AServiceManager_waitForService(GetParam().c_str())));
45 ASSERT_NE(eArc, nullptr);
46 ALOGI("%s: getService() for eArc is %s", __func__, eArc->isRemote() ? "remote" : "local");
47
48 eArcCallback = ::ndk::SharedRefBase::make<EArcCallback>();
49 ASSERT_NE(eArcCallback, nullptr);
50 eArcDeathRecipient =
51 ndk::ScopedAIBinder_DeathRecipient(AIBinder_DeathRecipient_new(&serviceDied));
52 ASSERT_EQ(AIBinder_linkToDeath(eArc->asBinder().get(), eArcDeathRecipient.get(), 0),
53 STATUS_OK);
54 }
55
56 class EArcCallback : public BnEArcCallback {
57 public:
onStateChange(IEArcStatus connected __unused,int32_t portId __unused)58 ::ndk::ScopedAStatus onStateChange(IEArcStatus connected __unused,
59 int32_t portId __unused) {
60 return ::ndk::ScopedAStatus::ok();
61 };
onCapabilitiesReported(const std::vector<uint8_t> & capabilities __unused,int32_t portId __unused)62 ::ndk::ScopedAStatus onCapabilitiesReported(
63 const std::vector<uint8_t>& capabilities __unused, int32_t portId __unused) {
64 return ::ndk::ScopedAStatus::ok();
65 };
66 };
67
68 std::shared_ptr<IEArc> eArc;
69 std::shared_ptr<IEArcCallback> eArcCallback;
70 ::ndk::ScopedAIBinder_DeathRecipient eArcDeathRecipient;
71 };
72
73 GTEST_ALLOW_UNINSTANTIATED_PARAMETERIZED_TEST(EArcTest);
74 INSTANTIATE_TEST_SUITE_P(PerInstance, EArcTest,
75 testing::ValuesIn(android::getAidlHalInstanceNames(IEArc::descriptor)),
76 android::PrintInstanceNameToString);
77
TEST_P(EArcTest,setGetEArcEnabled)78 TEST_P(EArcTest, setGetEArcEnabled) {
79 bool initial_state;
80 bool changed_state;
81 ASSERT_TRUE(eArc->isEArcEnabled(&initial_state).isOk());
82 ASSERT_TRUE(eArc->setEArcEnabled(!initial_state).isOk());
83 ASSERT_TRUE(eArc->isEArcEnabled(&changed_state).isOk());
84 ASSERT_TRUE(initial_state != changed_state);
85 ASSERT_TRUE(eArc->setEArcEnabled(initial_state).isOk());
86 }
87
TEST_P(EArcTest,SetCallback)88 TEST_P(EArcTest, SetCallback) {
89 ASSERT_TRUE(eArc->setCallback(eArcCallback).isOk());
90 }
91
TEST_P(EArcTest,GetState)92 TEST_P(EArcTest, GetState) {
93 IEArcStatus connectionStatus;
94 ASSERT_TRUE(eArc->getState(1, &connectionStatus).isOk());
95 }
96
TEST_P(EArcTest,GetLastReportedAudioCapabilities)97 TEST_P(EArcTest, GetLastReportedAudioCapabilities) {
98 std::vector<uint8_t> capabilities;
99 ASSERT_TRUE(eArc->getLastReportedAudioCapabilities(1, &capabilities).isOk());
100 }
101