From 1cb794eb3d1db10a0bcb0c82d86c7970ecd171c3 Mon Sep 17 00:00:00 2001 From: ramindani Date: Wed, 13 Oct 2021 20:45:23 +0000 Subject: [PATCH] Populates the displays required for the tests. Create composer callback for tests. Test: atest VtsHalGraphicsComposer3_TargetTest, test are not run yet but BUG: 202401906 Change-Id: I87396cdae7d083a2d2529617648fdd784e9097db --- .../composer3/vts/functional/Android.bp | 6 +- .../VtsHalGraphicsComposer3_TargetTest.cpp | 56 +++++++- .../vts/functional/composer-vts/Android.bp | 44 ++++++ .../composer-vts/GraphicsComposerCallback.cpp | 136 ++++++++++++++++++ .../include/GraphicsComposerCallback.h | 75 ++++++++++ 5 files changed, 310 insertions(+), 7 deletions(-) create mode 100644 graphics/composer/aidl/android/hardware/graphics/composer3/vts/functional/composer-vts/Android.bp create mode 100644 graphics/composer/aidl/android/hardware/graphics/composer3/vts/functional/composer-vts/GraphicsComposerCallback.cpp create mode 100644 graphics/composer/aidl/android/hardware/graphics/composer3/vts/functional/composer-vts/include/GraphicsComposerCallback.h diff --git a/graphics/composer/aidl/android/hardware/graphics/composer3/vts/functional/Android.bp b/graphics/composer/aidl/android/hardware/graphics/composer3/vts/functional/Android.bp index 8a36b1d82f..420b32c2f9 100644 --- a/graphics/composer/aidl/android/hardware/graphics/composer3/vts/functional/Android.bp +++ b/graphics/composer/aidl/android/hardware/graphics/composer3/vts/functional/Android.bp @@ -29,7 +29,10 @@ cc_test { "VtsHalTargetTestDefaults", "use_libaidlvintf_gtest_helper_static", ], - srcs: ["VtsHalGraphicsComposer3_TargetTest.cpp"], + srcs: [ + "VtsHalGraphicsComposer3_TargetTest.cpp", + "composer-vts/GraphicsComposerCallback.cpp", + ], // TODO(b/64437680): Assume these libs are always available on the device. shared_libs: [ @@ -42,6 +45,7 @@ cc_test { "android.hardware.graphics.common@1.2", "android.hardware.common-V2-ndk", "android.hardware.common.fmq-V1-ndk", + "android.hardware.graphics.composer@3-vts", ], test_suites: [ diff --git a/graphics/composer/aidl/android/hardware/graphics/composer3/vts/functional/VtsHalGraphicsComposer3_TargetTest.cpp b/graphics/composer/aidl/android/hardware/graphics/composer3/vts/functional/VtsHalGraphicsComposer3_TargetTest.cpp index 40dfe06eda..2dc80fcd4b 100644 --- a/graphics/composer/aidl/android/hardware/graphics/composer3/vts/functional/VtsHalGraphicsComposer3_TargetTest.cpp +++ b/graphics/composer/aidl/android/hardware/graphics/composer3/vts/functional/VtsHalGraphicsComposer3_TargetTest.cpp @@ -6,22 +6,28 @@ #include #include #include +#include #include #include +#include #pragma push_macro("LOG_TAG") #undef LOG_TAG #define LOG_TAG "VtsHalGraphicsComposer3_TargetTest" +typedef int32_t Config; + namespace aidl::android::hardware::graphics::composer3::vts { namespace { +using namespace std::chrono_literals; + class VtsDisplay { public: - VtsDisplay(uint64_t displayId, int32_t displayWidth, int32_t displayHeight) + VtsDisplay(int64_t displayId, int32_t displayWidth, int32_t displayHeight) : mDisplayId(displayId), mDisplayWidth(displayWidth), mDisplayHeight(displayHeight) {} - uint64_t get() const { return mDisplayId; } + int64_t get() const { return mDisplayId; } void setDimensions(int32_t displayWidth, int32_t displayHeight) { mDisplayWidth = displayWidth; @@ -29,7 +35,7 @@ class VtsDisplay { } private: - const uint64_t mDisplayId; + const int64_t mDisplayId; int32_t mDisplayWidth; int32_t mDisplayHeight; }; @@ -44,6 +50,12 @@ class GraphicsComposerAidlTest : public ::testing::TestWithParam { ASSERT_NE(mComposer, nullptr); ASSERT_NO_FATAL_FAILURE(mComposer->createClient(&mComposerClient)); mInvalidDisplayId = GetInvalidDisplayId(); + + mComposerCallback = ::ndk::SharedRefBase::make(); + EXPECT_TRUE(mComposerClient->registerCallback(mComposerCallback).isOk()); + + // assume the first displays are built-in and are never removed + mDisplays = waitForDisplays(); } // returns an invalid display id (one that has not been registered to a @@ -62,11 +74,43 @@ class GraphicsComposerAidlTest : public ::testing::TestWithParam { return 0; } + std::vector waitForDisplays() { + while (true) { + // Sleep for a small period of time to allow all built-in displays + // to post hotplug events + std::this_thread::sleep_for(5ms); + std::vector displays = mComposerCallback->getDisplays(); + if (displays.empty()) { + continue; + } + + std::vector vtsDisplays; + vtsDisplays.reserve(displays.size()); + for (int64_t display : displays) { + Config activeConfig; + EXPECT_TRUE(mComposerClient->getActiveConfig(display, &activeConfig).isOk()); + int32_t displayWidth; + EXPECT_TRUE(mComposerClient + ->getDisplayAttribute(display, activeConfig, + DisplayAttribute::WIDTH, &displayWidth) + .isOk()); + int32_t displayHeight; + EXPECT_TRUE(mComposerClient + ->getDisplayAttribute(display, activeConfig, + DisplayAttribute::HEIGHT, &displayHeight) + .isOk()); + vtsDisplays.emplace_back(VtsDisplay{display, displayWidth, displayHeight}); + } + + return vtsDisplays; + } + } + std::shared_ptr mComposer; std::shared_ptr mComposerClient; - uint64_t mInvalidDisplayId; - std::vector - mDisplays; // TODO(b/202401906) populate all the displays available for test. + int64_t mInvalidDisplayId; + std::vector mDisplays; + std::shared_ptr mComposerCallback; }; TEST_P(GraphicsComposerAidlTest, getDisplayCapabilitiesBadDisplay) { diff --git a/graphics/composer/aidl/android/hardware/graphics/composer3/vts/functional/composer-vts/Android.bp b/graphics/composer/aidl/android/hardware/graphics/composer3/vts/functional/composer-vts/Android.bp new file mode 100644 index 0000000000..bb5f3f18b5 --- /dev/null +++ b/graphics/composer/aidl/android/hardware/graphics/composer3/vts/functional/composer-vts/Android.bp @@ -0,0 +1,44 @@ +/** + * Copyright (c) 2021, The Android Open Source Project + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +package { + // See: http://go/android-license-faq + // A large-scale-change added 'default_applicable_licenses' to import + // all of the 'license_kinds' from "hardware_interfaces_license" + // to get the below license kinds: + // SPDX-license-identifier-Apache-2.0 + default_applicable_licenses: ["hardware_interfaces_license"], +} + +cc_library_static { + name: "android.hardware.graphics.composer@3-vts", + defaults: ["hidl_defaults"], + srcs: [ + "GraphicsComposerCallback.cpp", + ], + static_libs: [ + "android.hardware.graphics.composer3-V1-ndk", + "android.hardware.graphics.common-V3-ndk", + "libgtest", + "libbase", + ], + cflags: [ + "-O0", + "-g", + "-DLOG_TAG=\"ComposerVts\"", + ], + export_include_dirs: ["include"], +} diff --git a/graphics/composer/aidl/android/hardware/graphics/composer3/vts/functional/composer-vts/GraphicsComposerCallback.cpp b/graphics/composer/aidl/android/hardware/graphics/composer3/vts/functional/composer-vts/GraphicsComposerCallback.cpp new file mode 100644 index 0000000000..daf9924fb7 --- /dev/null +++ b/graphics/composer/aidl/android/hardware/graphics/composer3/vts/functional/composer-vts/GraphicsComposerCallback.cpp @@ -0,0 +1,136 @@ +/** + * Copyright (c) 2021, The Android Open Source Project + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +#include "include/GraphicsComposerCallback.h" +#include + +#pragma push_macro("LOG_TAG") +#undef LOG_TAG +#define LOG_TAG "GraphicsComposerCallback" + +namespace aidl::android::hardware::graphics::composer3::vts { + +void GraphicsComposerCallback::setVsyncAllowed(bool allowed) { + std::scoped_lock lock(mMutex); + mVsyncAllowed = allowed; +} + +std::vector GraphicsComposerCallback::getDisplays() const { + std::scoped_lock lock(mMutex); + return std::vector(mDisplays.begin(), mDisplays.end()); +} + +int32_t GraphicsComposerCallback::getInvalidHotplugCount() const { + std::scoped_lock lock(mMutex); + return mInvalidHotplugCount; +} + +int32_t GraphicsComposerCallback::getInvalidRefreshCount() const { + std::scoped_lock lock(mMutex); + return mInvalidRefreshCount; +} + +int32_t GraphicsComposerCallback::getInvalidVsyncCount() const { + std::scoped_lock lock(mMutex); + return mInvalidVsyncCount; +} + +int32_t GraphicsComposerCallback::getInvalidVsyncPeriodChangeCount() const { + std::scoped_lock lock(mMutex); + return mInvalidVsyncPeriodChangeCount; +} + +int32_t GraphicsComposerCallback::getInvalidSeamlessPossibleCount() const { + std::scoped_lock lock(mMutex); + return mInvalidSeamlessPossibleCount; +} + +std::optional +GraphicsComposerCallback::takeLastVsyncPeriodChangeTimeline() { + std::scoped_lock lock(mMutex); + + std::optional ret; + ret.swap(mTimeline); + + return ret; +} + +::ndk::ScopedAStatus GraphicsComposerCallback::onHotplug(int64_t in_display, bool in_connected) { + std::scoped_lock lock(mMutex); + if (in_connected) { + if (!mDisplays.insert(in_display).second) { + mInvalidHotplugCount++; + } + } else { + if (!mDisplays.erase(in_display)) { + mInvalidHotplugCount++; + } + } + return ::ndk::ScopedAStatus::ok(); +} + +::ndk::ScopedAStatus GraphicsComposerCallback::onRefresh(int64_t display) { + std::scoped_lock lock(mMutex); + + if (mDisplays.count(display) == 0) { + mInvalidRefreshCount++; + } + + return ::ndk::ScopedAStatus::ok(); +} + +::ndk::ScopedAStatus GraphicsComposerCallback::onVsync(int64_t in_display, int64_t in_timestamp, + int32_t in_vsyncPeriodNanos) { + std::scoped_lock lock(mMutex); + if (!mVsyncAllowed || mDisplays.count(in_display) == 0) { + mInvalidVsyncCount++; + } + + ALOGV("%ld, %d", static_cast(in_timestamp), in_vsyncPeriodNanos); + + return ::ndk::ScopedAStatus::ok(); +} + +::ndk::ScopedAStatus GraphicsComposerCallback::onVsyncPeriodTimingChanged( + int64_t in_display, + const ::aidl::android::hardware::graphics::composer3::VsyncPeriodChangeTimeline& + in_updatedTimeline) { + std::scoped_lock lock(mMutex); + if (mDisplays.count(in_display) == 0) { + mInvalidVsyncPeriodChangeCount++; + } + mTimeline = in_updatedTimeline; + + return ::ndk::ScopedAStatus::ok(); +} + +::ndk::ScopedAStatus GraphicsComposerCallback::onSeamlessPossible(int64_t in_display) { + std::scoped_lock lock(mMutex); + if (mDisplays.count(in_display)) { + mInvalidSeamlessPossibleCount++; + } + return ::ndk::ScopedAStatus::ok(); +} + +::ndk::SpAIBinder GraphicsComposerCallback::asBinder() { + return nullptr; +} + +bool GraphicsComposerCallback::isRemote() { + return true; +} + +} // namespace aidl::android::hardware::graphics::composer3::vts diff --git a/graphics/composer/aidl/android/hardware/graphics/composer3/vts/functional/composer-vts/include/GraphicsComposerCallback.h b/graphics/composer/aidl/android/hardware/graphics/composer3/vts/functional/composer-vts/include/GraphicsComposerCallback.h new file mode 100644 index 0000000000..9afc72f2de --- /dev/null +++ b/graphics/composer/aidl/android/hardware/graphics/composer3/vts/functional/composer-vts/include/GraphicsComposerCallback.h @@ -0,0 +1,75 @@ +/** + * Copyright (c) 2021, The Android Open Source Project + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ +#pragma once + +#include + +#include +#include +#include + +namespace aidl::android::hardware::graphics::composer3::vts { + +// IComposerCallback to be installed with IComposerClient::registerCallback. +class GraphicsComposerCallback : public IComposerCallback { + public: + void setVsyncAllowed(bool allowed); + + std::vector getDisplays() const; + + int32_t getInvalidHotplugCount() const; + + int32_t getInvalidRefreshCount() const; + + int32_t getInvalidVsyncCount() const; + + int32_t getInvalidVsyncPeriodChangeCount() const; + + int32_t getInvalidSeamlessPossibleCount() const; + + std::optional takeLastVsyncPeriodChangeTimeline(); + + private: + virtual ::ndk::ScopedAStatus onHotplug(int64_t in_display, bool in_connected) override; + virtual ::ndk::ScopedAStatus onRefresh(int64_t in_display) override; + virtual ::ndk::ScopedAStatus onSeamlessPossible(int64_t in_display) override; + virtual ::ndk::ScopedAStatus onVsync(int64_t in_display, int64_t in_timestamp, + int32_t in_vsyncPeriodNanos) override; + virtual ::ndk::ScopedAStatus onVsyncPeriodTimingChanged( + int64_t in_display, + const ::aidl::android::hardware::graphics::composer3::VsyncPeriodChangeTimeline& + in_updatedTimeline) override; + + ::ndk::SpAIBinder asBinder() override; + bool isRemote() override; + + mutable std::mutex mMutex; + // the set of all currently connected displays + std::unordered_set mDisplays GUARDED_BY(mMutex); + // true only when vsync is enabled + bool mVsyncAllowed GUARDED_BY(mMutex) = true; + + std::optional mTimeline GUARDED_BY(mMutex); + + // track invalid callbacks + int32_t mInvalidHotplugCount GUARDED_BY(mMutex) = 0; + int32_t mInvalidRefreshCount GUARDED_BY(mMutex) = 0; + int32_t mInvalidVsyncCount GUARDED_BY(mMutex) = 0; + int32_t mInvalidVsyncPeriodChangeCount GUARDED_BY(mMutex) = 0; + int32_t mInvalidSeamlessPossibleCount GUARDED_BY(mMutex) = 0; +}; + +} // namespace aidl::android::hardware::graphics::composer3::vts \ No newline at end of file