Add invalid config const to the AIDL interface.

Test: atest VtsHalGraphicsComposer3_TargetTest but tests don't just work yet. as we don't have service implementation.
BUG: 202053621
Change-Id: I96fc1f6bcb4ce4907342b3a73994f80b9347ea9f
This commit is contained in:
Ram Indani
2021-11-03 16:39:08 +00:00
committed by ramindani
7 changed files with 318 additions and 7 deletions

View File

@@ -85,4 +85,5 @@ interface IComposerClient {
const int EX_UNSUPPORTED = 8;
const int EX_SEAMLESS_NOT_ALLOWED = 9;
const int EX_SEAMLESS_NOT_POSSIBLE = 10;
const int INVALID_CONFIGURATION = 2147483647;
}

View File

@@ -89,6 +89,12 @@ interface IComposerClient {
*/
const int EX_SEAMLESS_NOT_POSSIBLE = 10;
/**
* Integer.MAX_VALUE is reserved for the invalid configuration.
* This should not be returned as a valid configuration.
*/
const int INVALID_CONFIGURATION = 0x7fffffff;
/**
* Creates a new layer on the given display.
*
@@ -282,6 +288,7 @@ interface IComposerClient {
/**
* Returns handles for all of the valid display configurations on this
* display.
* This should never return INVALID_CONFIGURATION as a valid value.
*
* @param display is the display to query.
*

View File

@@ -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: [

View File

@@ -6,22 +6,28 @@
#include <android/binder_manager.h>
#include <android/binder_process.h>
#include <binder/ProcessState.h>
#include <composer-vts/include/GraphicsComposerCallback.h>
#include <gtest/gtest.h>
#include <string>
#include <thread>
#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<std::string> {
ASSERT_NE(mComposer, nullptr);
ASSERT_NO_FATAL_FAILURE(mComposer->createClient(&mComposerClient));
mInvalidDisplayId = GetInvalidDisplayId();
mComposerCallback = ::ndk::SharedRefBase::make<GraphicsComposerCallback>();
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<std::string> {
return 0;
}
std::vector<VtsDisplay> 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<int64_t> displays = mComposerCallback->getDisplays();
if (displays.empty()) {
continue;
}
std::vector<VtsDisplay> 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<IComposer> mComposer;
std::shared_ptr<IComposerClient> mComposerClient;
uint64_t mInvalidDisplayId;
std::vector<VtsDisplay>
mDisplays; // TODO(b/202401906) populate all the displays available for test.
int64_t mInvalidDisplayId;
std::vector<VtsDisplay> mDisplays;
std::shared_ptr<GraphicsComposerCallback> mComposerCallback;
};
TEST_P(GraphicsComposerAidlTest, getDisplayCapabilitiesBadDisplay) {

View File

@@ -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"],
}

View File

@@ -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 <log/log_main.h>
#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<int64_t> GraphicsComposerCallback::getDisplays() const {
std::scoped_lock lock(mMutex);
return std::vector<int64_t>(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<VsyncPeriodChangeTimeline>
GraphicsComposerCallback::takeLastVsyncPeriodChangeTimeline() {
std::scoped_lock lock(mMutex);
std::optional<VsyncPeriodChangeTimeline> 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<long>(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

View File

@@ -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 <aidl/android/hardware/graphics/composer3/IComposerCallback.h>
#include <android-base/thread_annotations.h>
#include <mutex>
#include <unordered_set>
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<int64_t> getDisplays() const;
int32_t getInvalidHotplugCount() const;
int32_t getInvalidRefreshCount() const;
int32_t getInvalidVsyncCount() const;
int32_t getInvalidVsyncPeriodChangeCount() const;
int32_t getInvalidSeamlessPossibleCount() const;
std::optional<VsyncPeriodChangeTimeline> 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<int64_t> mDisplays GUARDED_BY(mMutex);
// true only when vsync is enabled
bool mVsyncAllowed GUARDED_BY(mMutex) = true;
std::optional<VsyncPeriodChangeTimeline> 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