1
0
Fork 0

drm_hwcomposer: Add PipelineBindable unit tests

Change-Id: Iada6f16cb3b72f38cbaad1b71b38c8ef201c4722
This commit is contained in:
Andrew Wolfers 2025-09-26 20:52:58 +00:00
parent 84892ec611
commit ec00b3dc25
5 changed files with 126 additions and 20 deletions

View file

@ -29,25 +29,6 @@
namespace android::drm_hwcomposer {
template <class O>
auto PipelineBindable<O>::BindPipeline(const DrmDisplayPipeline *pipeline,
bool return_object_if_bound)
-> std::shared_ptr<BindingOwner<O>> {
auto owner_object = owner_object_.lock();
if (owner_object) {
if (bound_pipeline_ == pipeline && return_object_if_bound) {
return owner_object;
}
return {};
}
owner_object = std::make_shared<BindingOwner<O>>(static_cast<O *>(this));
owner_object_ = owner_object;
bound_pipeline_ = pipeline;
return owner_object;
}
static auto TryCreatePipeline(DrmDevice &dev, DrmConnector &connector,
DrmEncoder &enc, DrmCrtc &crtc)
-> std::unique_ptr<DrmDisplayPipeline> {

View file

@ -42,9 +42,24 @@ class PipelineBindable {
return bound_pipeline_;
}
// Header implementation required for template instantiation.
auto BindPipeline(const DrmDisplayPipeline *pipeline,
bool return_object_if_bound = false)
-> std::shared_ptr<BindingOwner<O>>;
-> std::shared_ptr<BindingOwner<O>> {
auto owner_object = owner_object_.lock();
if (owner_object) {
if (bound_pipeline_ == pipeline && return_object_if_bound) {
return owner_object;
}
return {};
}
owner_object = std::make_shared<BindingOwner<O>>(static_cast<O *>(this));
owner_object_ = owner_object;
bound_pipeline_ = pipeline;
return owner_object;
}
private:
const DrmDisplayPipeline *bound_pipeline_;

View file

@ -0,0 +1,90 @@
/*
* Copyright (C) 2025 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 <memory>
#include <gtest/gtest.h>
#include "DrmDisplayPipeline.h"
namespace android::drm_hwcomposer {
class NoOpBindable : public PipelineBindable<NoOpBindable> {};
class DrmDisplayPipelineTest : public ::testing::Test {};
TEST_F(DrmDisplayPipelineTest, BindPipeline_Success) {
const auto pipeline = std::make_unique<DrmDisplayPipeline>();
NoOpBindable bindable;
const auto binding = bindable.BindPipeline(pipeline.get(),
/*return_object_if_bound=*/true);
ASSERT_NE(binding, nullptr);
EXPECT_EQ(binding->Get()->GetPipeline(), pipeline.get());
EXPECT_EQ(binding->Get(), &bindable);
}
TEST_F(DrmDisplayPipelineTest, BindPipeline_SamePipelineReturnsSameBinding) {
const auto pipeline = std::make_unique<DrmDisplayPipeline>();
NoOpBindable bindable;
const auto binding1 = bindable.BindPipeline(pipeline.get(),
/*return_object_if_bound=*/true);
ASSERT_NE(binding1, nullptr);
EXPECT_EQ(binding1->Get()->GetPipeline(), pipeline.get());
EXPECT_EQ(binding1->Get(), &bindable);
const auto binding2 = bindable.BindPipeline(pipeline.get(),
/*return_object_if_bound=*/true);
EXPECT_EQ(binding1, binding2);
}
TEST_F(DrmDisplayPipelineTest,
BindPipeline_DifferentPipelineReturnsNullBinding) {
const auto pipeline1 = std::make_unique<DrmDisplayPipeline>();
const auto pipeline2 = std::make_unique<DrmDisplayPipeline>();
NoOpBindable bindable;
const auto binding1 = bindable.BindPipeline(pipeline1.get(),
/*return_object_if_bound=*/true);
ASSERT_NE(binding1, nullptr);
EXPECT_EQ(binding1->Get()->GetPipeline(), pipeline1.get());
EXPECT_EQ(binding1->Get(), &bindable);
const auto binding2 = bindable.BindPipeline(pipeline2.get(),
/*return_object_if_bound=*/true);
EXPECT_EQ(binding2, nullptr);
}
TEST_F(DrmDisplayPipelineTest,
BindPipeline_ReleasedBindingDoesntPreventNewBinding) {
const auto pipeline1 = std::make_unique<DrmDisplayPipeline>();
const auto pipeline2 = std::make_unique<DrmDisplayPipeline>();
NoOpBindable bindable;
auto binding1 = bindable.BindPipeline(pipeline1.get(),
/*return_object_if_bound=*/true);
ASSERT_NE(binding1, nullptr);
EXPECT_EQ(binding1->Get()->GetPipeline(), pipeline1.get());
EXPECT_EQ(binding1->Get(), &bindable);
binding1.reset();
const auto binding2 = bindable.BindPipeline(pipeline2.get(),
/*return_object_if_bound=*/true);
ASSERT_NE(binding2, nullptr);
EXPECT_EQ(binding2->Get()->GetPipeline(), pipeline2.get());
EXPECT_EQ(binding2->Get(), &bindable);
}
} // namespace android::drm_hwcomposer