blob: 78c2590a9584280c986ba37a9b6c029ca315914d [file] [log] [blame]
Venkatarama Avadhani820b5482022-05-18 15:19:04 +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
17#define LOG_TAG "Hdmi_hal_test"
18
19#include <aidl/Gtest.h>
20#include <aidl/Vintf.h>
21#include <aidl/android/hardware/tv/hdmi/BnHdmi.h>
22#include <aidl/android/hardware/tv/hdmi/BnHdmiCallback.h>
23#include <android-base/logging.h>
24#include <android/binder_manager.h>
25#include <android/binder_process.h>
26#include <gtest/gtest.h>
27#include <log/log.h>
28#include <sstream>
29#include <vector>
30
31using ::aidl::android::hardware::tv::hdmi::BnHdmiCallback;
32using ::aidl::android::hardware::tv::hdmi::HdmiPortInfo;
33using ::aidl::android::hardware::tv::hdmi::HdmiPortType;
34using ::aidl::android::hardware::tv::hdmi::IHdmi;
35using ::aidl::android::hardware::tv::hdmi::IHdmiCallback;
36using ::ndk::SpAIBinder;
37
38#define INCORRECT_VENDOR_ID 0x00
39#define TV_PHYSICAL_ADDRESS 0x0000
40
41// The main test class for TV HDMI HAL.
42class HdmiTest : public ::testing::TestWithParam<std::string> {
43 static void serviceDied(void* /* cookie */) { ALOGE("VtsHalTvCecAidlTargetTest died"); }
44
45 public:
46 void SetUp() override {
47 hdmi = IHdmi::fromBinder(SpAIBinder(AServiceManager_waitForService(GetParam().c_str())));
48 ASSERT_NE(hdmi, nullptr);
49 ALOGI("%s: getService() for hdmi is %s", __func__, hdmi->isRemote() ? "remote" : "local");
50
51 hdmiCallback = ::ndk::SharedRefBase::make<HdmiCallback>();
52 ASSERT_NE(hdmiCallback, nullptr);
53 hdmiDeathRecipient =
54 ndk::ScopedAIBinder_DeathRecipient(AIBinder_DeathRecipient_new(&serviceDied));
55 ASSERT_EQ(AIBinder_linkToDeath(hdmi->asBinder().get(), hdmiDeathRecipient.get(), 0),
56 STATUS_OK);
57 }
58
59 class HdmiCallback : public BnHdmiCallback {
60 public:
61 ::ndk::ScopedAStatus onHotplugEvent(bool connected __unused, int32_t portId __unused) {
62 return ::ndk::ScopedAStatus::ok();
63 };
64 };
65
66 std::shared_ptr<IHdmi> hdmi;
67 std::shared_ptr<IHdmiCallback> hdmiCallback;
68 ::ndk::ScopedAIBinder_DeathRecipient hdmiDeathRecipient;
69};
70
71GTEST_ALLOW_UNINSTANTIATED_PARAMETERIZED_TEST(HdmiTest);
72INSTANTIATE_TEST_SUITE_P(PerInstance, HdmiTest,
73 testing::ValuesIn(android::getAidlHalInstanceNames(IHdmi::descriptor)),
74 android::PrintInstanceNameToString);
75
76TEST_P(HdmiTest, SetCallback) {
77 ASSERT_TRUE(hdmi->setCallback(::ndk::SharedRefBase::make<HdmiCallback>()).isOk());
78}
79
80TEST_P(HdmiTest, GetPortInfo) {
81 std::vector<HdmiPortInfo> ports;
82 ASSERT_TRUE(hdmi->getPortInfo(&ports).isOk());
83
84 bool cecSupportedOnDevice = false;
85 for (size_t i = 0; i < ports.size(); ++i) {
86 EXPECT_TRUE((ports[i].type == HdmiPortType::OUTPUT) ||
87 (ports[i].type == HdmiPortType::INPUT));
88 if (ports[i].portId == 0) {
89 ALOGW("%s: Port id should start from 1", __func__);
90 }
91 cecSupportedOnDevice = cecSupportedOnDevice | ports[i].cecSupported;
92 }
93 EXPECT_NE(cecSupportedOnDevice, false) << "At least one port should support CEC";
94}
95
96TEST_P(HdmiTest, IsConnected) {
97 std::vector<HdmiPortInfo> ports;
98 ASSERT_TRUE(hdmi->getPortInfo(&ports).isOk());
99 for (size_t i = 0; i < ports.size(); ++i) {
100 bool connected;
101 ASSERT_TRUE(hdmi->isConnected(ports[i].portId, &connected).isOk());
102 }
103}