summaryrefslogtreecommitdiff
path: root/services/surfaceflinger/tests/unittests/HWComposerTest.cpp
diff options
context:
space:
mode:
Diffstat (limited to 'services/surfaceflinger/tests/unittests/HWComposerTest.cpp')
-rw-r--r--services/surfaceflinger/tests/unittests/HWComposerTest.cpp64
1 files changed, 28 insertions, 36 deletions
diff --git a/services/surfaceflinger/tests/unittests/HWComposerTest.cpp b/services/surfaceflinger/tests/unittests/HWComposerTest.cpp
index 655baf8a77..91b304cca8 100644
--- a/services/surfaceflinger/tests/unittests/HWComposerTest.cpp
+++ b/services/surfaceflinger/tests/unittests/HWComposerTest.cpp
@@ -23,21 +23,12 @@
#include <vector>
-// StrictMock<T> derives from T and is not marked final, so the destructor of T is expected to be
-// virtual in case StrictMock<T> is used as a polymorphic base class. That is not the case here.
-#pragma clang diagnostic push
-#pragma clang diagnostic ignored "-Wnon-virtual-dtor"
#include <gmock/gmock.h>
-#pragma clang diagnostic pop
-
#include <gui/LayerMetadata.h>
#include <log/log.h>
-#include "DisplayHardware/DisplayMode.h"
#include "DisplayHardware/HWComposer.h"
-#include "DisplayHardware/Hal.h"
#include "mock/DisplayHardware/MockComposer.h"
-#include "mock/DisplayHardware/MockHWC2.h"
// TODO(b/129481165): remove the #pragma below and fix conversion issues
#pragma clang diagnostic pop // ignored "-Wconversion"
@@ -45,10 +36,7 @@
namespace android {
namespace {
-namespace V2_1 = hardware::graphics::composer::V2_1;
-namespace V2_4 = hardware::graphics::composer::V2_4;
-
-using Hwc2::Config;
+namespace hal = android::hardware::graphics::composer::hal;
using ::testing::_;
using ::testing::DoAll;
@@ -57,27 +45,36 @@ using ::testing::Return;
using ::testing::SetArgPointee;
using ::testing::StrictMock;
-struct MockHWC2ComposerCallback final : StrictMock<HWC2::ComposerCallback> {
- MOCK_METHOD2(onComposerHalHotplug, void(hal::HWDisplayId, hal::Connection));
- MOCK_METHOD1(onComposerHalRefresh, void(hal::HWDisplayId));
- MOCK_METHOD3(onComposerHalVsync,
- void(hal::HWDisplayId, int64_t timestamp, std::optional<hal::VsyncPeriodNanos>));
- MOCK_METHOD2(onComposerHalVsyncPeriodTimingChanged,
- void(hal::HWDisplayId, const hal::VsyncPeriodChangeTimeline&));
- MOCK_METHOD1(onComposerHalSeamlessPossible, void(hal::HWDisplayId));
+struct MockHWC2ComposerCallback : public HWC2::ComposerCallback {
+ ~MockHWC2ComposerCallback() = default;
+
+ MOCK_METHOD3(onHotplugReceived,
+ void(int32_t sequenceId, hal::HWDisplayId display, hal::Connection connection));
+ MOCK_METHOD2(onRefreshReceived, void(int32_t sequenceId, hal::HWDisplayId display));
+ MOCK_METHOD4(onVsyncReceived,
+ void(int32_t sequenceId, hal::HWDisplayId display, int64_t timestamp,
+ std::optional<hal::VsyncPeriodNanos> vsyncPeriod));
+ MOCK_METHOD3(onVsyncPeriodTimingChangedReceived,
+ void(int32_t sequenceId, hal::HWDisplayId display,
+ const hal::VsyncPeriodChangeTimeline& updatedTimeline));
+ MOCK_METHOD2(onSeamlessPossible, void(int32_t sequenceId, hal::HWDisplayId display));
};
-struct HWComposerSetCallbackTest : testing::Test {
+struct HWComposerTest : public testing::Test {
Hwc2::mock::Composer* mHal = new StrictMock<Hwc2::mock::Composer>();
- MockHWC2ComposerCallback mCallback;
};
-TEST_F(HWComposerSetCallbackTest, loadsLayerMetadataSupport) {
+struct HWComposerSetConfigurationTest : public HWComposerTest {
+ StrictMock<MockHWC2ComposerCallback> mCallback;
+};
+
+TEST_F(HWComposerSetConfigurationTest, loadsLayerMetadataSupport) {
const std::string kMetadata1Name = "com.example.metadata.1";
constexpr bool kMetadata1Mandatory = false;
const std::string kMetadata2Name = "com.example.metadata.2";
constexpr bool kMetadata2Mandatory = true;
+ EXPECT_CALL(*mHal, getMaxVirtualDisplayCount()).WillOnce(Return(0));
EXPECT_CALL(*mHal, getCapabilities()).WillOnce(Return(std::vector<hal::Capability>{}));
EXPECT_CALL(*mHal, getLayerGenericMetadataKeys(_))
.WillOnce(DoAll(SetArgPointee<0>(std::vector<hal::LayerGenericMetadataKey>{
@@ -89,7 +86,7 @@ TEST_F(HWComposerSetCallbackTest, loadsLayerMetadataSupport) {
EXPECT_CALL(*mHal, isVsyncPeriodSwitchSupported()).WillOnce(Return(false));
impl::HWComposer hwc{std::unique_ptr<Hwc2::Composer>(mHal)};
- hwc.setCallback(&mCallback);
+ hwc.setConfiguration(&mCallback, 123);
const auto& supported = hwc.getSupportedLayerGenericMetadata();
EXPECT_EQ(2u, supported.size());
@@ -99,7 +96,8 @@ TEST_F(HWComposerSetCallbackTest, loadsLayerMetadataSupport) {
EXPECT_EQ(kMetadata2Mandatory, supported.find(kMetadata2Name)->second);
}
-TEST_F(HWComposerSetCallbackTest, handlesUnsupportedCallToGetLayerGenericMetadataKeys) {
+TEST_F(HWComposerSetConfigurationTest, handlesUnsupportedCallToGetLayerGenericMetadataKeys) {
+ EXPECT_CALL(*mHal, getMaxVirtualDisplayCount()).WillOnce(Return(0));
EXPECT_CALL(*mHal, getCapabilities()).WillOnce(Return(std::vector<hal::Capability>{}));
EXPECT_CALL(*mHal, getLayerGenericMetadataKeys(_))
.WillOnce(Return(hardware::graphics::composer::V2_4::Error::UNSUPPORTED));
@@ -107,7 +105,7 @@ TEST_F(HWComposerSetCallbackTest, handlesUnsupportedCallToGetLayerGenericMetadat
EXPECT_CALL(*mHal, isVsyncPeriodSwitchSupported()).WillOnce(Return(false));
impl::HWComposer hwc{std::unique_ptr<Hwc2::Composer>(mHal)};
- hwc.setCallback(&mCallback);
+ hwc.setConfiguration(&mCallback, 123);
const auto& supported = hwc.getSupportedLayerGenericMetadata();
EXPECT_EQ(0u, supported.size());
@@ -118,19 +116,13 @@ struct HWComposerLayerTest : public testing::Test {
static constexpr hal::HWLayerId kLayerId = static_cast<hal::HWLayerId>(1002);
HWComposerLayerTest(const std::unordered_set<hal::Capability>& capabilities)
- : mCapabilies(capabilities) {
- EXPECT_CALL(mDisplay, getId()).WillRepeatedly(Return(kDisplayId));
- }
+ : mCapabilies(capabilities) {}
- ~HWComposerLayerTest() override {
- EXPECT_CALL(mDisplay, onLayerDestroyed(kLayerId));
- EXPECT_CALL(*mHal, destroyLayer(kDisplayId, kLayerId));
- }
+ ~HWComposerLayerTest() override { EXPECT_CALL(*mHal, destroyLayer(kDisplayId, kLayerId)); }
std::unique_ptr<Hwc2::mock::Composer> mHal{new StrictMock<Hwc2::mock::Composer>()};
const std::unordered_set<hal::Capability> mCapabilies;
- StrictMock<HWC2::mock::Display> mDisplay;
- HWC2::impl::Layer mLayer{*mHal, mCapabilies, mDisplay, kLayerId};
+ HWC2::impl::Layer mLayer{*mHal, mCapabilies, kDisplayId, kLayerId};
};
struct HWComposerLayerGenericMetadataTest : public HWComposerLayerTest {