SF: Deduplicate mock scheduler setup in tests
Extract TestableSurfaceFlinger::setupMockScheduler, and add an option to
customize the PhysicalDisplayId of the injected RefreshRateSelector (and
its display modes), so that tests can later inject a DisplayDevice with
a matching ID. Remove the DisplayModesVariant with two display modes, as
the few tests that used it are unrelated to scheduling and will later be
decoupled entirely.
Bug: 259436835
Bug: 241285191
Test: libsurfaceflinger_unittest
Change-Id: Ie58b6947201a1911342e7bcd5ea64dd8702aaa57
Merged-In: Ie58b6947201a1911342e7bcd5ea64dd8702aaa57
(cherry picked from commit fb281c53240c3e2420a20cf0ea071198e963ed3d)
diff --git a/services/surfaceflinger/tests/unittests/DisplayTransactionTest.cpp b/services/surfaceflinger/tests/unittests/DisplayTransactionTest.cpp
index e0b508a..52dc695 100644
--- a/services/surfaceflinger/tests/unittests/DisplayTransactionTest.cpp
+++ b/services/surfaceflinger/tests/unittests/DisplayTransactionTest.cpp
@@ -29,9 +29,7 @@
using android::hardware::graphics::composer::hal::HWDisplayId;
-using FakeDisplayDeviceInjector = TestableSurfaceFlinger::FakeDisplayDeviceInjector;
-
-DisplayTransactionTest::DisplayTransactionTest() {
+DisplayTransactionTest::DisplayTransactionTest(bool withMockScheduler) {
const ::testing::TestInfo* const test_info =
::testing::UnitTest::GetInstance()->current_test_info();
ALOGD("**** Setting up for %s.%s\n", test_info->test_case_name(), test_info->name());
@@ -48,7 +46,10 @@
return nullptr;
});
- injectMockScheduler();
+ if (withMockScheduler) {
+ injectMockScheduler(PhysicalDisplayId::fromPort(0));
+ }
+
mFlinger.setupRenderEngine(std::unique_ptr<renderengine::RenderEngine>(mRenderEngine));
injectMockComposer(0);
@@ -61,7 +62,9 @@
mFlinger.resetScheduler(nullptr);
}
-void DisplayTransactionTest::injectMockScheduler() {
+void DisplayTransactionTest::injectMockScheduler(PhysicalDisplayId displayId) {
+ LOG_ALWAYS_FATAL_IF(mFlinger.scheduler());
+
EXPECT_CALL(*mEventThread, registerDisplayEventConnection(_));
EXPECT_CALL(*mEventThread, createEventConnection(_, _))
.WillOnce(Return(sp<EventThreadConnection>::make(mEventThread,
@@ -78,6 +81,7 @@
std::unique_ptr<scheduler::VSyncTracker>(mVSyncTracker),
std::unique_ptr<EventThread>(mEventThread),
std::unique_ptr<EventThread>(mSFEventThread),
+ TestableSurfaceFlinger::DefaultDisplayMode{displayId},
TestableSurfaceFlinger::SchedulerCallbackImpl::kMock);
}