From 00c0f29f8ed44bdf7ad68f6a3d36c84ae8fd58d9 Mon Sep 17 00:00:00 2001 From: Xaver Hugl Date: Thu, 29 Dec 2022 00:05:08 +0100 Subject: [PATCH] autotests/drm: add test that verifies extending output lifetimes works --- autotests/drm/drmTest.cpp | 28 ++++++++++++++++++++++++++++ 1 file changed, 28 insertions(+) diff --git a/autotests/drm/drmTest.cpp b/autotests/drm/drmTest.cpp index dcdd5d07fa..a8a58bb3e3 100644 --- a/autotests/drm/drmTest.cpp +++ b/autotests/drm/drmTest.cpp @@ -38,6 +38,7 @@ private Q_SLOTS: void testZeroModesHandling(); void testModeGeneration_data(); void testModeGeneration(); + void testConnectorLifetime(); }; static void verifyCleanup(MockGpu *mockGpu) @@ -279,5 +280,32 @@ void DrmTest::testModeGeneration() verifyCleanup(mockGpu.get()); } +void DrmTest::testConnectorLifetime() +{ + // don't crash if output lifetime is extended beyond the connector + const auto mockGpu = std::make_unique(1, 5); + + const auto conn = std::make_shared(mockGpu.get()); + mockGpu->connectors.push_back(conn); + + const auto session = Session::create(Session::Type::Noop); + const auto backend = std::make_unique(session.get()); + const auto renderBackend = backend->createQPainterBackend(); + auto gpu = std::make_unique(backend.get(), "test", 1, 0); + + QVERIFY(gpu->updateOutputs()); + QCOMPARE(gpu->drmOutputs().size(), 1); + + DrmOutput *const output = gpu->drmOutputs().front(); + + output->ref(); + mockGpu->connectors.clear(); + QVERIFY(gpu->updateOutputs()); + output->unref(); + + gpu.reset(); + verifyCleanup(mockGpu.get()); +} + QTEST_GUILESS_MAIN(DrmTest) #include "drmTest.moc"