Subject: [PATCH 13/21] wip: add dormant tiled test modeset seam

From: Justin Youens <[email-masked]>
Date: Sat, 15 Aug 2026 10:23:59 -0500

---
 src/backend/drm/TiledDRMIntegration.cpp   |  73 +++++-
 src/backend/drm/TiledDRMIntegration.hpp   |  11 +
 src/backend/drm/TiledRuntimeAuthority.cpp | 282 +++++++++++++++++++++-
 src/backend/drm/TiledRuntimeAuthority.hpp | 107 +++++++-
 tests/TiledDRMIntegration.cpp             | 199 +++++++++++++--
 5 files changed, 645 insertions(+), 27 deletions(-)

diff --git a/src/backend/drm/TiledDRMIntegration.cpp b/src/backend/drm/TiledDRMIntegration.cpp
index 2acc2e8b71412bf3491930477524d78f51b1460d..9c9b0cfc5d621d50647557cb02c82182f626cbec 100644
--- a/src/backend/drm/TiledDRMIntegration.cpp
+++ b/src/backend/drm/TiledDRMIntegration.cpp
@@ -277,6 +277,18 @@ SBeginConnectorScanResult CTiledDRMIntegrationRegistry::beginConnectorScan(const
             std::terminate();
     };
 
+    Hyprutils::Memory::CUniquePointer<CGroupedRuntimeAuthority> groupedRuntime;
+    try {
+        groupedRuntime = Hyprutils::Memory::makeUnique<CGroupedRuntimeAuthority>(m_impl->eventThread);
+    } catch (...) {
+        discardState();
+        return shadowDisabled();
+    }
+    if (!groupedRuntime || !groupedRuntime->configureProductionTestModeset(device, backend, backend->drmFD())) {
+        discardState();
+        return shadowDisabled();
+    }
+
     bool inserted = false;
     try {
         const auto [ITERATOR, INSERTED] = m_impl->entries.emplace(KEY,
@@ -285,7 +297,7 @@ SBeginConnectorScanResult CTiledDRMIntegrationRegistry::beginConnectorScan(const
                                                                       .device         = device,
                                                                       .session        = session,
                                                                       .outputBridge   = CSharedPointer<COutputBridgeState>{new COutputBridgeState{m_impl->eventThread}},
-                                                                      .groupedRuntime = Hyprutils::Memory::makeUnique<CGroupedRuntimeAuthority>(m_impl->eventThread),
+                                                                      .groupedRuntime = std::move(groupedRuntime),
                                                                   });
         inserted                        = INSERTED;
         if (!INSERTED) {
@@ -927,6 +939,46 @@ bool CTiledDRMIntegrationRegistry::withCurrentOutputBridge(const CWeakPointer<CD
     return withCurrentOutputBridgeKey(backend.impl_, expected, callback);
 }
 
+SGroupedTestModesetResult CTiledDRMIntegrationRegistry::executeCurrentGroupedTestModesetKey(const void* key, const POutputBridgeObservation& expected,
+                                                                                            const PScanGroupDefinition&        group,
+                                                                                            const CSharedPointer<SOutputMode>& outputMode) noexcept {
+    const auto THREAD = m_impl->registeredThread(key);
+    if (!THREAD || *THREAD != std::this_thread::get_id())
+        return {.status = eGroupedTestModesetStatus::WRONG_THREAD};
+    if (!expected || !group || !outputMode)
+        return {.status = eGroupedTestModesetStatus::INVALID_CURRENT};
+    const auto ENTRY = m_impl->entries.find(key);
+    if (ENTRY == m_impl->entries.end() || ENTRY->second.detachBegun || !ENTRY->second.outputBridge || !ENTRY->second.groupedRuntime || !ENTRY->second.allocationShadow)
+        return {.status = eGroupedTestModesetStatus::INVALID_CURRENT};
+    if (m_impl->mutationBusy(ENTRY->second))
+        return {.status = eGroupedTestModesetStatus::BUSY};
+
+    const auto                SHADOW = ENTRY->second.allocationShadow;
+    SGroupedTestModesetResult result{.status = eGroupedTestModesetStatus::INVALID_CURRENT};
+    bool                      bridgeCurrent = false;
+    bool                      invoked       = false;
+    try {
+        const auto ALLOCATION_CURRENT = withCurrentAllocationKey(key, SHADOW, [&](const CPlan&, const SCurrentState& current) {
+            const auto CURRENT_ENTRY = m_impl->entries.find(key);
+            if (CURRENT_ENTRY == m_impl->entries.end() || !CURRENT_ENTRY->second.outputBridge || !CURRENT_ENTRY->second.groupedRuntime)
+                return;
+            bridgeCurrent = CURRENT_ENTRY->second.outputBridge->withCurrentOwner(current, [&](const POutputBridgeObservation& observation) {
+                if (observation.impl_ != expected.impl_)
+                    return;
+                invoked = true;
+                result  = CURRENT_ENTRY->second.groupedRuntime->executeCurrentTestModeset(observation, group, outputMode);
+            });
+        });
+        return ALLOCATION_CURRENT && bridgeCurrent && invoked ? result : SGroupedTestModesetResult{.status = eGroupedTestModesetStatus::INVALID_CURRENT};
+    } catch (...) { return {.status = eGroupedTestModesetStatus::ALLOCATION_FAILED}; }
+}
+
+SGroupedTestModesetResult CTiledDRMIntegrationRegistry::executeCurrentGroupedTestModeset(const CWeakPointer<CDRMBackend>& backend, const POutputBridgeObservation& expected,
+                                                                                         const PScanGroupDefinition&        group,
+                                                                                         const CSharedPointer<SOutputMode>& outputMode) noexcept {
+    return executeCurrentGroupedTestModesetKey(backend.impl_, expected, group, outputMode);
+}
+
 SGroupedPageFlipResult CTiledDRMIntegrationRegistry::routeGroupedPageFlipKey(const void* key, uintptr_t transactionId, uint32_t crtcId, uint32_t sequence,
                                                                              uint64_t timestampNs) noexcept {
     const auto THREAD = m_impl->registeredThread(key);
@@ -955,6 +1007,20 @@ bool CTiledDRMIntegrationRegistry::withCurrentTestOutputBridge(const PBackendLif
     return withCurrentOutputBridgeKey(lifetime.impl_, expected, callback);
 }
 
+bool CTiledDRMIntegrationRegistry::configureInjectedTestModeset(const PBackendLifetime& lifetime, int drmFD, const CSharedPointer<ITiledAtomicRequestOperations>& operations,
+                                                                const CSharedPointer<IGroupedTestFramebufferSource>& framebufferSource) noexcept {
+    if (!m_impl->onEventThread() || !lifetime || lifetime->binding() != eBackendBinding::TEST_TOKEN)
+        return false;
+    const auto ENTRY = m_impl->entries.find(lifetime.impl_);
+    return ENTRY != m_impl->entries.end() && !ENTRY->second.detachBegun && !m_impl->mutationBusy(ENTRY->second) && ENTRY->second.lifetime == lifetime &&
+        ENTRY->second.groupedRuntime && ENTRY->second.groupedRuntime->configureInjectedTestModeset(ENTRY->second.device, drmFD, operations, framebufferSource);
+}
+
+SGroupedTestModesetResult CTiledDRMIntegrationRegistry::executeCurrentTestModeset(const PBackendLifetime& lifetime, const POutputBridgeObservation& expected,
+                                                                                  const PScanGroupDefinition& group, const CSharedPointer<SOutputMode>& outputMode) noexcept {
+    return executeCurrentGroupedTestModesetKey(lifetime.impl_, expected, group, outputMode);
+}
+
 eSessionResult CTiledDRMIntegrationRegistry::rotateSessionKey(const void* key) noexcept {
     const auto THREAD = m_impl->registeredThread(key);
     if (!THREAD)
@@ -1020,9 +1086,10 @@ eDetachResult CTiledDRMIntegrationRegistry::beginDetachKey(const void* key, eDet
         return eDetachResult::ALREADY_BEGUN;
     if (m_impl->mutationBusy(ENTRY->second))
         return eDetachResult::BUSY;
+    if (!ENTRY->second.groupedRuntime || !ENTRY->second.groupedRuntime->prepareTestModesetDetach())
+        return eDetachResult::BUSY;
 
-    if (ENTRY->second.groupedRuntime)
-        static_cast<void>(ENTRY->second.groupedRuntime->quiesceAll(eTiledQuiesceReason::BACKEND_TEARDOWN));
+    static_cast<void>(ENTRY->second.groupedRuntime->quiesceAll(eTiledQuiesceReason::BACKEND_TEARDOWN));
     setLastScan(key, false);
     m_impl->invalidateOutputBridge(ENTRY->second);
 
diff --git a/src/backend/drm/TiledDRMIntegration.hpp b/src/backend/drm/TiledDRMIntegration.hpp
index 3120cba4f91002ae93e2de59486facffff9a5b9d..531bc5f3834ed033a84d4409350aa4484568dcc2 100644
--- a/src/backend/drm/TiledDRMIntegration.hpp
+++ b/src/backend/drm/TiledDRMIntegration.hpp
@@ -30,8 +30,11 @@ namespace Aquamarine::NDRM::NTiledDRMIntegration { // NOLINT(readability-identif
     using NTiledCrtcAllocator::CPlan;
     using NTiledCrtcAllocator::SCurrentState;
     using NTiledOutputBridge::POutputBridgeObservation;
+    using NTiledRuntimeAuthority::IGroupedTestFramebufferSource;
     using NTiledRuntimeAuthority::SGroupedPageFlipResult;
+    using NTiledRuntimeAuthority::SGroupedTestModesetResult;
     using NTiledScan::PCommittedScan;
+    using NTiledScan::PScanGroupDefinition;
     using NTiledScan::PPreparedScan;
     using NTiledScan::PScanAttemptTicket;
     using NTiledScan::SConnectorView;
@@ -220,6 +223,8 @@ namespace Aquamarine::NDRM::NTiledDRMIntegration { // NOLINT(readability-identif
                                                                             const std::function<void(const CPlan&, const SCurrentState&)>& callback) noexcept;
         [[nodiscard]] bool                      withCurrentOutputBridge(const CWeakPointer<CDRMBackend>& backend, const PAllocationShadow& expected,
                                                                         const std::function<void(const POutputBridgeObservation&)>& callback) noexcept;
+        [[nodiscard]] SGroupedTestModesetResult executeCurrentGroupedTestModeset(const CWeakPointer<CDRMBackend>& backend, const POutputBridgeObservation& expected,
+                                                                                 const PScanGroupDefinition& group, const CSharedPointer<SOutputMode>& outputMode) noexcept;
         [[nodiscard]] SGroupedPageFlipResult    routeGroupedPageFlip(const CWeakPointer<CDRMBackend>& backend, uintptr_t transactionId, uint32_t crtcId, uint32_t sequence,
                                                                      uint64_t timestampNs) noexcept;
 
@@ -250,6 +255,8 @@ namespace Aquamarine::NDRM::NTiledDRMIntegration { // NOLINT(readability-identif
                                                                          const std::function<void(const CPlan&, const SCurrentState&)>& callback) noexcept;
         [[nodiscard]] bool                      withCurrentOutputBridgeKey(const void* key, const PAllocationShadow& expected,
                                                                            const std::function<void(const POutputBridgeObservation&)>& callback) noexcept;
+        [[nodiscard]] SGroupedTestModesetResult executeCurrentGroupedTestModesetKey(const void* key, const POutputBridgeObservation& expected, const PScanGroupDefinition& group,
+                                                                                    const CSharedPointer<SOutputMode>& outputMode) noexcept;
         [[nodiscard]] SGroupedPageFlipResult routeGroupedPageFlipKey(const void* key, uintptr_t transactionId, uint32_t crtcId, uint32_t sequence, uint64_t timestampNs) noexcept;
         void                                 abortConnectorScan(CConnectorScan& scan) noexcept;
 
@@ -268,6 +275,10 @@ namespace Aquamarine::NDRM::NTiledDRMIntegration { // NOLINT(readability-identif
                                                                                 const std::function<void(const CPlan&, const SCurrentState&)>& callback) noexcept;
         [[nodiscard]] bool                      withCurrentTestOutputBridge(const PBackendLifetime& lifetime, const PAllocationShadow& expected,
                                                                             const std::function<void(const POutputBridgeObservation&)>& callback) noexcept;
+        [[nodiscard]] bool configureInjectedTestModeset(const PBackendLifetime& lifetime, int drmFD, const CSharedPointer<NTiledAtomic::ITiledAtomicRequestOperations>& operations,
+                                                        const CSharedPointer<IGroupedTestFramebufferSource>& framebufferSource) noexcept;
+        [[nodiscard]] SGroupedTestModesetResult executeCurrentTestModeset(const PBackendLifetime& lifetime, const POutputBridgeObservation& expected,
+                                                                          const PScanGroupDefinition& group, const CSharedPointer<SOutputMode>& outputMode) noexcept;
         [[nodiscard]] bool                      exhaustTestResourceEpoch(const PBackendLifetime& lifetime) noexcept;
 
         class CImpl;
diff --git a/src/backend/drm/TiledRuntimeAuthority.cpp b/src/backend/drm/TiledRuntimeAuthority.cpp
index 7cda6afdfc829eab82d46fe33001f70b1466a19b..25f14746ab04837e81831a1de021d9d797bf8d99 100644
--- a/src/backend/drm/TiledRuntimeAuthority.cpp
+++ b/src/backend/drm/TiledRuntimeAuthority.cpp
@@ -1,15 +1,20 @@
 #include "TiledRuntimeAuthority.hpp"
 
+#include "PlaneFormats.hpp"
+
 #include <algorithm>
 #include <exception>
 #include <ranges>
 #include <utility>
 
+#include <drm_fourcc.h>
 #include <hyprutils/utils/ScopeGuard.hpp>
 
 using namespace Aquamarine;
 using namespace Aquamarine::NDRM;
 using namespace Aquamarine::NDRM::NTiledAtomic;
+using namespace Aquamarine::NDRM::NTiledCrtcAllocator;
+using namespace Aquamarine::NDRM::NTiledIncarnations;
 using namespace Aquamarine::NDRM::NTiledOutputBridge;
 using namespace Aquamarine::NDRM::NTiledRuntimeAuthority;
 
@@ -18,6 +23,85 @@ namespace {
     bool sameOwner(const Hyprutils::Memory::CSharedPointer<T>& lhs, const Hyprutils::Memory::CSharedPointer<U>& rhs) noexcept {
         return lhs.impl_ != nullptr && lhs.impl_ == rhs.impl_;
     }
+
+    [[nodiscard]] bool supportsExactFormat(std::span<const SDRMFormat> formats, uint32_t drmFormat, uint64_t modifier) {
+        const auto FORMAT = std::ranges::find(formats, drmFormat, &SDRMFormat::drmFormat);
+        return FORMAT != formats.end() && std::ranges::contains(FORMAT->modifiers, modifier);
+    }
+
+    class CLibdrmGroupedTestFramebufferSource final : public IGroupedTestFramebufferSource {
+      public:
+        PGroupedTestFramebuffer acquire(const SGroupedTestFramebufferRequest& request) noexcept override {
+            try {
+                const auto BACKEND  = request.backend.lock();
+                const auto LIFETIME = request.device ? request.device->backend().lock() : PBackendLifetime{};
+                if (!BACKEND || !LIFETIME || LIFETIME->binding() != eBackendBinding::PRODUCTION_BACKEND || !request.device->valid() || request.drmFD < 0 ||
+                    BACKEND->drmFD() != request.drmFD || LIFETIME->drmBackend().impl_ != request.backend.impl_ || request.size.width == 0 || request.size.height == 0 ||
+                    request.commonFormats.empty())
+                    return {};
+
+                std::vector<uint32_t> candidateFormats;
+                candidateFormats.reserve(request.commonFormats.size());
+                if (std::ranges::find(request.commonFormats, DRM_FORMAT_XRGB8888, &SDRMFormat::drmFormat) != request.commonFormats.end())
+                    candidateFormats.push_back(DRM_FORMAT_XRGB8888);
+                for (const auto& FORMAT : request.commonFormats) {
+                    if (FORMAT.drmFormat != DRM_FORMAT_INVALID && !std::ranges::contains(candidateFormats, FORMAT.drmFormat))
+                        candidateFormats.push_back(FORMAT.drmFormat);
+                }
+
+                for (const auto& ALLOCATOR : BACKEND->getAllocators()) {
+                    if (!ALLOCATOR || ALLOCATOR->drmFD() != request.drmFD)
+                        continue;
+                    for (const auto FORMAT : candidateFormats) {
+                        auto swapchain = CSwapchain::create(ALLOCATOR, BACKEND);
+                        if (!swapchain ||
+                            !swapchain->reconfigure({
+                                .length   = 1,
+                                .size     = {static_cast<double>(request.size.width), static_cast<double>(request.size.height)},
+                                .format   = FORMAT,
+                                .scanout  = true,
+                                .cursor   = false,
+                                .multigpu = false,
+                            }))
+                            continue;
+
+                        auto buffer = swapchain->next(nullptr);
+                        if (!buffer)
+                            continue;
+                        const auto ATTRS = buffer->dmabuf();
+                        if (!ATTRS.success || ATTRS.size.x != static_cast<double>(request.size.width) || ATTRS.size.y != static_cast<double>(request.size.height) ||
+                            !supportsExactFormat(request.commonFormats, ATTRS.format, ATTRS.modifier))
+                            continue;
+
+                        auto framebuffer = CDRMFB::create(buffer, BACKEND);
+                        if (!framebuffer || framebuffer->id == 0 || framebuffer->dead || framebuffer->backend.impl_ != request.backend.impl_ ||
+                            framebuffer->buffer.impl_ != buffer.impl_)
+                            continue;
+
+                        CSharedPointer<SGroupedTestFramebuffer> result{new SGroupedTestFramebuffer{
+                            .device      = request.device,
+                            .backend     = request.backend,
+                            .drmFD       = request.drmFD,
+                            .allocator   = ALLOCATOR,
+                            .swapchain   = std::move(swapchain),
+                            .buffer      = std::move(buffer),
+                            .framebuffer = framebuffer,
+                            .atomic      = {.id = framebuffer->id, .size = request.size, .format = ATTRS.format, .modifier = ATTRS.modifier},
+                        }};
+                        return result;
+                    }
+                }
+                return {};
+            } catch (...) { return {}; }
+        }
+    };
+
+    [[nodiscard]] CSharedPointer<IGroupedTestFramebufferSource> createLibdrmGroupedTestFramebufferSource() noexcept {
+        try {
+            CSharedPointer<CLibdrmGroupedTestFramebufferSource> source{new CLibdrmGroupedTestFramebufferSource{}};
+            return source;
+        } catch (...) { return {}; }
+    }
 }
 
 CGroupedFrameOwner::CGroupedFrameOwner(PResolvedTiledAtomicRoute route, CSharedPointer<CDRMFB> framebuffer, CSharedPointer<IBuffer> buffer) noexcept :
@@ -53,6 +137,10 @@ SGroupedReconcileResult::operator bool() const noexcept {
     return result == eGroupedReconcileResult::RECONCILED || result == eGroupedReconcileResult::RECONCILED_WITH_QUIESCE;
 }
 
+SGroupedTestModesetResult::operator bool() const noexcept {
+    return status == eGroupedTestModesetStatus::SUCCEEDED;
+}
+
 CGroupedRuntimeAuthority::CGroupedRuntimeAuthority(std::thread::id eventThread) : m_eventThread(eventThread) {}
 
 CGroupedRuntimeAuthority::~CGroupedRuntimeAuthority() noexcept {
@@ -93,6 +181,188 @@ const CGroupedRuntimeAuthority::SRuntimeRecord* CGroupedRuntimeAuthority::record
     return RECORD == m_runtimes.end() ? nullptr : &RECORD->second;
 }
 
+bool CGroupedRuntimeAuthority::configureProductionTestModeset(const PDeviceIncarnation& device, const CWeakPointer<CDRMBackend>& backend, int drmFD) noexcept {
+    if (!onEventThread() || m_mutationActive || m_terminal || m_testDevice || !device || !device->valid() || drmFD < 0)
+        return false;
+    const auto LIFETIME = device->backend().lock();
+    const auto BACKEND  = backend.lock();
+    if (!LIFETIME || LIFETIME->binding() != eBackendBinding::PRODUCTION_BACKEND || !BACKEND || LIFETIME->drmBackend().impl_ != backend.impl_ || BACKEND->drmFD() != drmFD)
+        return false;
+
+    auto operations = createLibdrmTiledAtomicOperations();
+    auto source     = createLibdrmGroupedTestFramebufferSource();
+    auto cleanup    = CTiledModeBlobCleanupRegistry::create(drmFD);
+    if (!operations || !source || !cleanup)
+        return false;
+
+    m_testDevice            = device;
+    m_testBackend           = backend;
+    m_testDrmFD             = drmFD;
+    m_testOperations        = std::move(operations);
+    m_testFramebufferSource = std::move(source);
+    m_testCleanupRegistry   = std::move(cleanup);
+    return true;
+}
+
+bool CGroupedRuntimeAuthority::configureInjectedTestModeset(const PDeviceIncarnation& device, int drmFD, const CSharedPointer<ITiledAtomicRequestOperations>& operations,
+                                                            const CSharedPointer<IGroupedTestFramebufferSource>& framebufferSource) noexcept {
+    if (!onEventThread() || m_mutationActive || m_terminal || m_testDevice || !device || !device->valid() || drmFD < 0 || !operations || !framebufferSource)
+        return false;
+    const auto LIFETIME = device->backend().lock();
+    if (!LIFETIME || LIFETIME->binding() != eBackendBinding::TEST_TOKEN || LIFETIME->drmBackend().impl_ != nullptr)
+        return false;
+    auto cleanup = CTiledModeBlobCleanupRegistry::create(drmFD);
+    if (!cleanup)
+        return false;
+
+    m_testDevice            = device;
+    m_testDrmFD             = drmFD;
+    m_testOperations        = operations;
+    m_testFramebufferSource = framebufferSource;
+    m_testCleanupRegistry   = std::move(cleanup);
+    return true;
+}
+
+bool CGroupedRuntimeAuthority::validTestFramebuffer(const PGroupedTestFramebuffer& framebuffer, const SPlaneFramebufferSize& size,
+                                                    std::span<const SDRMFormat> commonFormats) const noexcept {
+    if (!framebuffer || !sameOwner(framebuffer->device, m_testDevice) || framebuffer->drmFD != m_testDrmFD || framebuffer->atomic.id == 0 ||
+        framebuffer->atomic.format == DRM_FORMAT_INVALID || framebuffer->atomic.size != size ||
+        !supportsExactFormat(commonFormats, framebuffer->atomic.format, framebuffer->atomic.modifier))
+        return false;
+
+    const auto LIFETIME = m_testDevice ? m_testDevice->backend().lock() : PBackendLifetime{};
+    if (!LIFETIME)
+        return false;
+    if (LIFETIME->binding() == eBackendBinding::TEST_TOKEN)
+        return framebuffer->backend.impl_ == nullptr && !framebuffer->allocator && !framebuffer->swapchain && !framebuffer->buffer && !framebuffer->framebuffer;
+
+    const auto BACKEND = m_testBackend.lock();
+    if (LIFETIME->binding() != eBackendBinding::PRODUCTION_BACKEND || !BACKEND || BACKEND->drmFD() != m_testDrmFD || framebuffer->backend.impl_ != m_testBackend.impl_ ||
+        !framebuffer->allocator || framebuffer->allocator->drmFD() != m_testDrmFD || !framebuffer->swapchain ||
+        !sameOwner(framebuffer->swapchain->getAllocator(), framebuffer->allocator) || !framebuffer->buffer || !framebuffer->swapchain->contains(framebuffer->buffer) ||
+        !framebuffer->framebuffer || framebuffer->framebuffer->id != framebuffer->atomic.id || framebuffer->framebuffer->dead ||
+        framebuffer->framebuffer->backend.impl_ != m_testBackend.impl_ || framebuffer->framebuffer->buffer.impl_ != framebuffer->buffer.impl_)
+        return false;
+
+    const auto ATTRS = framebuffer->buffer->dmabuf();
+    return ATTRS.success && ATTRS.size.x == static_cast<double>(size.width) && ATTRS.size.y == static_cast<double>(size.height) && ATTRS.format == framebuffer->atomic.format &&
+        ATTRS.modifier == framebuffer->atomic.modifier;
+}
+
+SGroupedTestModesetResult CGroupedRuntimeAuthority::executeCurrentTestModeset(const POutputBridgeObservation& current, const PScanGroupDefinition& group,
+                                                                              const CSharedPointer<SOutputMode>& outputMode) noexcept {
+    if (!onEventThread())
+        return {.status = eGroupedTestModesetStatus::WRONG_THREAD};
+    if (m_mutationActive)
+        return {.status = eGroupedTestModesetStatus::BUSY};
+    if (m_terminal)
+        return {.status = eGroupedTestModesetStatus::TERMINAL};
+    if (!m_testDevice || m_testDrmFD < 0 || !m_testOperations || !m_testFramebufferSource || !m_testCleanupRegistry || m_testCleanupRegistry->drmFD() != m_testDrmFD)
+        return {.status = eGroupedTestModesetStatus::NOT_CONFIGURED};
+
+    m_mutationActive = true;
+    Hyprutils::Utils::CScopeGuard mutationGuard([&] { m_mutationActive = false; });
+    try {
+        const auto& SNAPSHOT = current ? current->capturedSnapshot() : CSharedPointer<const CSnapshot>{};
+        const auto* GROUP    = current ? current->findGroup(group) : nullptr;
+        if (!SNAPSHOT || !sameOwner(SNAPSHOT->device(), m_testDevice) || !GROUP || !sameOwner(GROUP->scanDefinition(), group) || !GROUP->definitionIdentity())
+            return {.status = eGroupedTestModesetStatus::INVALID_CURRENT};
+        if (GROUP->projection() != eGroupProjection::MULTI_STREAM_ALLOCATED)
+            return {.status = eGroupedTestModesetStatus::NOT_ALLOCATED};
+
+        const auto& MODE_SET  = GROUP->modeSet();
+        const auto  ALLOCATED = GROUP->allocation();
+        const auto* LOGICAL   = MODE_SET ? MODE_SET->logicalModeFor(outputMode) : nullptr;
+        const auto* MAPPING   = MODE_SET ? MODE_SET->physicalMappingFor(outputMode) : nullptr;
+        if (!MODE_SET || !ALLOCATED || ALLOCATED->get().status() != eGroupStatus::ALLOCATED || !LOGICAL || !MAPPING || !outputMode || outputMode->modeInfo.has_value() ||
+            outputMode->pixelSize.x != static_cast<double>(LOGICAL->width) || outputMode->pixelSize.y != static_cast<double>(LOGICAL->height) ||
+            outputMode->refreshRate != LOGICAL->refreshRate || outputMode->preferred != LOGICAL->preferred)
+            return {.status = eGroupedTestModesetStatus::INVALID_MODE};
+
+        const auto& TOPOLOGY = group->group();
+        if (TOPOLOGY.kind != NTiling::eTileGroupKind::MULTI_STREAM || TOPOLOGY.members.empty() || ALLOCATED->get().bindings().size() != TOPOLOGY.members.size())
+            return {.status = eGroupedTestModesetStatus::INVALID_CURRENT};
+
+        std::vector<SPlaneFormatSet> planeFormats;
+        planeFormats.reserve(TOPOLOGY.members.size());
+        size_t primaryMember = TOPOLOGY.members.size();
+        for (size_t index = 0; index < TOPOLOGY.members.size(); ++index) {
+            const auto& MEMBER = TOPOLOGY.members.at(index);
+            const auto  BINDING =
+                std::ranges::find(ALLOCATED->get().bindings(), MEMBER.connectorId, [](const auto& candidate) { return candidate.connector() ? candidate.connector()->id : 0; });
+            if (BINDING == ALLOCATED->get().bindings().end() || !BINDING->tiled() || !BINDING->primaryPlane() || !sameOwner(BINDING->definition(), GROUP->allocationDefinition()) ||
+                BINDING->tileX() != MEMBER.tileHLoc || BINDING->tileY() != MEMBER.tileVLoc)
+                return {.status = eGroupedTestModesetStatus::INVALID_CURRENT};
+            planeFormats.push_back({.formats = BINDING->primaryPlane()->formats});
+            if (MEMBER.connectorId == TOPOLOGY.primaryConnector)
+                primaryMember = index;
+        }
+        const auto COMMON_FORMATS = intersectPlaneFormats(planeFormats, primaryMember);
+        if (COMMON_FORMATS.empty())
+            return {.status = eGroupedTestModesetStatus::NO_COMMON_FORMAT};
+
+        const SPlaneFramebufferSize SIZE{.width = LOGICAL->width, .height = LOGICAL->height};
+        if (!validTestFramebuffer(m_testFramebuffer, SIZE, COMMON_FORMATS)) {
+            m_testFramebuffer.reset();
+            m_testFramebuffer = m_testFramebufferSource->acquire({
+                .device        = m_testDevice,
+                .backend       = m_testBackend,
+                .drmFD         = m_testDrmFD,
+                .size          = SIZE,
+                .commonFormats = COMMON_FORMATS,
+            });
+        }
+        if (!validTestFramebuffer(m_testFramebuffer, SIZE, COMMON_FORMATS)) {
+            m_testFramebuffer.reset();
+            return {.status = eGroupedTestModesetStatus::FRAMEBUFFER_UNAVAILABLE};
+        }
+
+        SGroupedTestModesetResult result;
+        result.cleanup = m_testCleanupRegistry->retryPending();
+        if (!result.cleanup.complete()) {
+            result.status = eGroupedTestModesetStatus::CLEANUP_PENDING;
+            return result;
+        }
+
+        const auto RESOLVED = resolveCapturedTiledAtomic({
+            .generationOwner    = current,
+            .groupDefinition    = group,
+            .definitionIdentity = GROUP->definitionIdentity(),
+            .outputMode         = outputMode,
+            .framebuffer        = m_testFramebuffer->atomic,
+        });
+        result.routeError   = RESOLVED.error;
+        if (!RESOLVED) {
+            result.status = eGroupedTestModesetStatus::ROUTE_INVALID;
+            return result;
+        }
+
+        const auto EXECUTION   = executeTiledTestModeset(RESOLVED.route, m_testDrmFD, m_testOperations, m_testCleanupRegistry);
+        result.executionStatus = EXECUTION.status;
+        result.submission      = EXECUTION.submission;
+        result.cleanup         = EXECUTION.cleanup;
+        if ((EXECUTION.retainedCleanup && !sameOwner(EXECUTION.retainedCleanup, m_testCleanupRegistry)) || m_testCleanupRegistry->pendingCount() != result.cleanup.retained) {
+            result.status = eGroupedTestModesetStatus::ALLOCATION_FAILED;
+            return result;
+        }
+        if (!result.cleanup.complete()) {
+            result.status = eGroupedTestModesetStatus::CLEANUP_PENDING;
+            return result;
+        }
+        result.status = EXECUTION ? eGroupedTestModesetStatus::SUCCEEDED : eGroupedTestModesetStatus::EXECUTION_FAILED;
+        return result;
+    } catch (...) { return {.status = eGroupedTestModesetStatus::ALLOCATION_FAILED}; }
+}
+
+bool CGroupedRuntimeAuthority::prepareTestModesetDetach() noexcept {
+    if (!onEventThread() || m_mutationActive)
+        return false;
+    m_mutationActive = true;
+    Hyprutils::Utils::CScopeGuard mutationGuard([&] { m_mutationActive = false; });
+    m_testFramebuffer.reset();
+    return !m_testCleanupRegistry || m_testCleanupRegistry->retryPending().complete();
+}
+
 bool CGroupedRuntimeAuthority::applyReservationEffects(const CGroupedRuntime::SEffects& effects) noexcept {
     const bool NEEDS_RESERVATION = effects.rollbackReservation || effects.quiesceReservation || effects.retireReservation;
     if (NEEDS_RESERVATION && !effects.reservation)
@@ -426,6 +696,8 @@ bool CGroupedRuntimeAuthority::terminalShutdown(eTiledRegistryShutdownProof regi
     const bool NO_CALLBACKS = registryProof == eTiledRegistryShutdownProof::BACKEND_NO_CALLBACKS && runtimeProof == eTiledRetirementProof::BACKEND_TEARDOWN_NO_CALLBACKS;
     if (!DEVICE_GONE && !NO_CALLBACKS)
         return false;
+    if (!prepareTestModesetDetach())
+        return false;
 
     m_mutationActive = true;
     Hyprutils::Utils::CScopeGuard mutationGuard([&] { m_mutationActive = false; });
@@ -445,7 +717,13 @@ bool CGroupedRuntimeAuthority::terminalShutdown(eTiledRegistryShutdownProof regi
         }
         if (!m_reservations.shutdown(registryProof))
             return false;
-        m_terminal = true;
+        m_testCleanupRegistry.reset();
+        m_testFramebufferSource.reset();
+        m_testOperations.reset();
+        m_testBackend.reset();
+        m_testDevice.reset();
+        m_testDrmFD = -1;
+        m_terminal  = true;
         return readyForDestruction();
     } catch (...) { return false; }
 }
@@ -455,7 +733,7 @@ bool CGroupedRuntimeAuthority::busy() const noexcept {
 }
 
 bool CGroupedRuntimeAuthority::readyForDestruction() const noexcept {
-    return m_reservations.readyForDestruction() &&
+    return !m_testFramebuffer && (!m_testCleanupRegistry || m_testCleanupRegistry->pendingCount() == 0) && m_reservations.readyForDestruction() &&
         std::ranges::all_of(m_runtimes, [](const auto& entry) { return entry.second.runtime && entry.second.runtime->readyForDestruction(); });
 }
 
diff --git a/src/backend/drm/TiledRuntimeAuthority.hpp b/src/backend/drm/TiledRuntimeAuthority.hpp
index 73415d501a3057f5db158f5732cfafa1ccf8321e..ec8945eea276f8faae6d03448a1e8015435e321f 100644
--- a/src/backend/drm/TiledRuntimeAuthority.hpp
+++ b/src/backend/drm/TiledRuntimeAuthority.hpp
@@ -2,11 +2,15 @@
 
 #include "TiledAtomic.hpp"
 
+#include <aquamarine/allocator/Allocator.hpp>
+#include <aquamarine/allocator/Swapchain.hpp>
 #include <aquamarine/backend/DRM.hpp>
 
 #include <cstddef>
 #include <cstdint>
 #include <map>
+#include <optional>
+#include <span>
 #include <thread>
 #include <vector>
 
@@ -23,12 +27,22 @@ namespace Aquamarine::NDRM::NTiledRuntimeAuthorityTest {
     class CFixtureAuthority;
 }
 
+namespace Aquamarine::NDRM::NTiledDRMIntegration {
+    class CTiledDRMIntegrationRegistry;
+}
+
 namespace Aquamarine::NDRM::NTiledRuntimeAuthority { // NOLINT(readability-identifier-naming): established Aquamarine DRM namespace
     using Hyprutils::Memory::CSharedPointer;
+    using Hyprutils::Memory::CWeakPointer;
     using Hyprutils::Memory::CUniquePointer;
+    using NTiledAtomic::ITiledAtomicRequestOperations;
+    using NTiledAtomic::STiledAtomicFramebuffer;
+    using NTiledAtomic::STiledModeBlobCleanupOutcome;
     using NTiledAtomic::PResolvedTiledAtomicRoute;
+    using NTiledIncarnations::PDeviceIncarnation;
     using NTiledOutputBridge::POutputBridgeObservation;
     using NTiledOutputBridge::POutputDefinitionIdentity;
+    using NTiledScan::PScanGroupDefinition;
 
     // One retained frame owner for the grouped runtime. The route preserves the
     // exact bridge/allocation/incarnation chain; future production activation
@@ -150,9 +164,70 @@ namespace Aquamarine::NDRM::NTiledRuntimeAuthority { // NOLINT(readability-ident
         bool                        reservationRetired = false;
     };
 
-    // Event-thread-only per-backend authority. No method publishes outputs or
-    // performs an ioctl; production runtime creation remains impossible until a
-    // later activation path supplies an exact current resolved route.
+    enum class eGroupedTestModesetStatus : uint8_t {
+        SUCCEEDED = 0,
+        WRONG_THREAD,
+        BUSY,
+        TERMINAL,
+        NOT_CONFIGURED,
+        INVALID_CURRENT,
+        NOT_ALLOCATED,
+        INVALID_MODE,
+        NO_COMMON_FORMAT,
+        FRAMEBUFFER_UNAVAILABLE,
+        ROUTE_INVALID,
+        EXECUTION_FAILED,
+        CLEANUP_PENDING,
+        ALLOCATION_FAILED,
+    };
+
+    // Diagnostic result only. It records what happened while the exact bridge
+    // owner gate was held and carries no reusable currentness authority.
+    struct AQ_TILED_RUNTIME_AUTHORITY_PRIVATE SGroupedTestModesetResult {
+        eGroupedTestModesetStatus                            status     = eGroupedTestModesetStatus::INVALID_CURRENT;
+        NTiledAtomic::eTiledAtomicError                      routeError = NTiledAtomic::eTiledAtomicError::INVALID_INPUT;
+        std::optional<NTiledAtomic::eTiledTestModesetStatus> executionStatus;
+        std::optional<SAtomicSubmitResult>                   submission;
+        STiledModeBlobCleanupOutcome                         cleanup;
+
+        explicit                                             operator bool() const noexcept;
+    };
+
+    struct AQ_TILED_RUNTIME_AUTHORITY_PRIVATE SGroupedTestFramebuffer {
+        PDeviceIncarnation         device;
+        CWeakPointer<CDRMBackend>  backend;
+        int                        drmFD = -1;
+        CSharedPointer<IAllocator> allocator;
+        CSharedPointer<CSwapchain> swapchain;
+        CSharedPointer<IBuffer>    buffer;
+        CSharedPointer<CDRMFB>     framebuffer;
+        STiledAtomicFramebuffer    atomic;
+    };
+
+    using PGroupedTestFramebuffer = CSharedPointer<const SGroupedTestFramebuffer>;
+
+    struct AQ_TILED_RUNTIME_AUTHORITY_PRIVATE SGroupedTestFramebufferRequest {
+        PDeviceIncarnation          device;
+        CWeakPointer<CDRMBackend>   backend;
+        int                         drmFD = -1;
+        SPlaneFramebufferSize       size;
+        std::span<const SDRMFormat> commonFormats;
+    };
+
+    // The production implementation performs real allocation/import. Tests
+    // inject a TEST_TOKEN-only source and can never satisfy the production
+    // provenance checks for allocator/swapchain/buffer/CDRMFB ownership.
+    class AQ_TILED_RUNTIME_AUTHORITY_PRIVATE IGroupedTestFramebufferSource {
+      public:
+        virtual ~IGroupedTestFramebufferSource() = default;
+
+        [[nodiscard]] virtual PGroupedTestFramebuffer acquire(const SGroupedTestFramebufferRequest& request) noexcept = 0;
+    };
+
+    // Event-thread-only per-backend authority. No method publishes outputs.
+    // Its synchronous TEST_ONLY path remains dormant until the integration
+    // registry supplies an exact-current bridge owner; there is intentionally
+    // no production callsite in this milestone.
     class AQ_TILED_RUNTIME_AUTHORITY_PRIVATE CGroupedRuntimeAuthority final {
       public:
         explicit CGroupedRuntimeAuthority(std::thread::id eventThread = std::this_thread::get_id());
@@ -194,14 +269,30 @@ namespace Aquamarine::NDRM::NTiledRuntimeAuthority { // NOLINT(readability-ident
         [[nodiscard]] SGroupedRetirementResult retireUnguarded(SRuntimeRecord& record, eTiledRetirementProof proof);
         [[nodiscard]] SRuntimeRecord*          recordFor(const POutputDefinitionIdentity& identity) noexcept;
         [[nodiscard]] const SRuntimeRecord*    recordFor(const POutputDefinitionIdentity& identity) const noexcept;
+        [[nodiscard]] bool                     configureProductionTestModeset(const PDeviceIncarnation& device, const CWeakPointer<CDRMBackend>& backend, int drmFD) noexcept;
+        [[nodiscard]] bool configureInjectedTestModeset(const PDeviceIncarnation& device, int drmFD, const CSharedPointer<ITiledAtomicRequestOperations>& operations,
+                                                        const CSharedPointer<IGroupedTestFramebufferSource>& framebufferSource) noexcept;
+        [[nodiscard]] SGroupedTestModesetResult       executeCurrentTestModeset(const POutputBridgeObservation& current, const PScanGroupDefinition& group,
+                                                                                const CSharedPointer<SOutputMode>& outputMode) noexcept;
+        [[nodiscard]] bool                            prepareTestModesetDetach() noexcept;
+        [[nodiscard]] bool                            validTestFramebuffer(const PGroupedTestFramebuffer& framebuffer, const SPlaneFramebufferSize& size,
+                                                                           std::span<const SDRMFormat> commonFormats) const noexcept;
 
-        std::thread::id                        m_eventThread;
-        CTiledFlipReservationRegistry          m_reservations;
-        TRuntimeMap                            m_runtimes;
-        bool                                   m_mutationActive = false;
-        bool                                   m_terminal       = false;
+        std::thread::id                               m_eventThread;
+        CTiledFlipReservationRegistry                 m_reservations;
+        TRuntimeMap                                   m_runtimes;
+        PDeviceIncarnation                            m_testDevice;
+        CWeakPointer<CDRMBackend>                     m_testBackend;
+        int                                           m_testDrmFD = -1;
+        CSharedPointer<ITiledAtomicRequestOperations> m_testOperations;
+        CSharedPointer<IGroupedTestFramebufferSource> m_testFramebufferSource;
+        NTiledAtomic::PModeBlobCleanupRegistry        m_testCleanupRegistry;
+        PGroupedTestFramebuffer                       m_testFramebuffer;
+        bool                                          m_mutationActive = false;
+        bool                                          m_terminal       = false;
 
         friend class ::Aquamarine::NDRM::NTiledRuntimeAuthorityTest::CFixtureAuthority;
+        friend class ::Aquamarine::NDRM::NTiledDRMIntegration::CTiledDRMIntegrationRegistry;
     };
 }
 
diff --git a/tests/TiledDRMIntegration.cpp b/tests/TiledDRMIntegration.cpp
index 84c7bef3c17e7934d9c4f9d998453979a7f90e86..27383607b6e90f21aa0d741d67fe7f3d2ccc4530 100644
--- a/tests/TiledDRMIntegration.cpp
+++ b/tests/TiledDRMIntegration.cpp
@@ -3,6 +3,7 @@
 
 #include <algorithm>
 #include <atomic>
+#include <cerrno>
 #include <cstdint>
 #include <string_view>
 #include <thread>
@@ -14,7 +15,9 @@
 using namespace Aquamarine::NDRM::NTiledDRMIntegration;
 using namespace Aquamarine::NDRM::NTiledIncarnations;
 using namespace Aquamarine::NDRM::NTiledCrtcAllocator;
+using namespace Aquamarine::NDRM::NTiledAtomic;
 using namespace Aquamarine::NDRM::NTiledOutputBridge;
+using namespace Aquamarine::NDRM::NTiledRuntimeAuthority;
 using namespace Aquamarine::NDRM::NTiledScan;
 using namespace Hyprutils::Memory;
 
@@ -77,6 +80,16 @@ namespace Aquamarine::NDRM::NTiledDRMIntegrationTest {
             return registry.withCurrentTestOutputBridge(lifetime, expected, callback);
         }
 
+        static bool configureTestModeset(CTiledDRMIntegrationRegistry& registry, const PBackendLifetime& lifetime, int drmFD,
+                                         const CSharedPointer<ITiledAtomicRequestOperations>& operations, const CSharedPointer<IGroupedTestFramebufferSource>& framebufferSource) {
+            return registry.configureInjectedTestModeset(lifetime, drmFD, operations, framebufferSource);
+        }
+
+        static SGroupedTestModesetResult executeTestModeset(CTiledDRMIntegrationRegistry& registry, const PBackendLifetime& lifetime, const POutputBridgeObservation& expected,
+                                                            const PScanGroupDefinition& group, const CSharedPointer<Aquamarine::SOutputMode>& outputMode) {
+            return registry.executeCurrentTestModeset(lifetime, expected, group, outputMode);
+        }
+
         static bool exhaustResourceEpoch(CTiledDRMIntegrationRegistry& registry, const PBackendLifetime& lifetime) {
             return registry.exhaustTestResourceEpoch(lifetime);
         }
@@ -114,6 +127,85 @@ namespace {
         return static_cast<int>(result);
     }
 
+    int value(eGroupedTestModesetStatus result) {
+        return static_cast<int>(result);
+    }
+
+    struct STestAtomicOperations final : ITiledAtomicRequestOperations {
+        drmModeAtomicReqPtr allocateRequest() noexcept override {
+            ++allocations;
+            // NOLINTNEXTLINE(cppcoreguidelines-pro-type-reinterpret-cast): opaque fake request identity for the injected boundary
+            return reinterpret_cast<drmModeAtomicReqPtr>(this);
+        }
+
+        void freeRequest(drmModeAtomicReqPtr request) noexcept override {
+            // NOLINTNEXTLINE(cppcoreguidelines-pro-type-reinterpret-cast): matches allocateRequest's opaque identity
+            if (request == reinterpret_cast<drmModeAtomicReqPtr>(this))
+                ++frees;
+        }
+
+        int addProperty(drmModeAtomicReqPtr, uint32_t, uint32_t, uint64_t) noexcept override {
+            ++properties;
+            return 0;
+        }
+
+        int submit(int fd, drmModeAtomicReqPtr, uint32_t flags, void* userData) noexcept override {
+            ++submits;
+            submittedFD       = fd;
+            submittedFlags    = flags;
+            submittedUserData = userData;
+            return 0;
+        }
+
+        int createModeBlob(int, const drmModeModeInfo&, uint32_t* blobId) noexcept override {
+            if (!blobId)
+                return -EINVAL;
+            *blobId = nextBlob++;
+            return 0;
+        }
+
+        int destroyModeBlob(int, uint32_t) noexcept override {
+            ++destructionAttempts;
+            if (destroyFailuresRemaining == 0)
+                return 0;
+            --destroyFailuresRemaining;
+            return -EBUSY;
+        }
+
+        size_t   allocations              = 0;
+        size_t   frees                    = 0;
+        size_t   properties               = 0;
+        size_t   submits                  = 0;
+        size_t   destructionAttempts      = 0;
+        size_t   destroyFailuresRemaining = 0;
+        uint32_t nextBlob                 = 900;
+        int      submittedFD              = -1;
+        uint32_t submittedFlags           = 0;
+        void*    submittedUserData        = nullptr;
+    };
+
+    struct STestFramebufferSource final : IGroupedTestFramebufferSource {
+        explicit STestFramebufferSource(PGroupedTestFramebuffer framebuffer_) : framebuffer(std::move(framebuffer_)) {}
+
+        PGroupedTestFramebuffer acquire(const SGroupedTestFramebufferRequest& request) noexcept override {
+            ++acquisitions;
+            sawExactDevice = framebuffer && request.device.impl_ == framebuffer->device.impl_;
+            sawExactFD     = framebuffer && request.drmFD == framebuffer->drmFD;
+            sawExactSize   = framebuffer && request.size == framebuffer->atomic.size;
+            sawCommonPair  = framebuffer && std::ranges::any_of(request.commonFormats, [&](const auto& format) {
+                                return format.drmFormat == framebuffer->atomic.format && std::ranges::contains(format.modifiers, framebuffer->atomic.modifier);
+                             });
+            return sawExactDevice && sawExactFD && sawExactSize && sawCommonPair ? framebuffer : PGroupedTestFramebuffer{};
+        }
+
+        PGroupedTestFramebuffer framebuffer;
+        size_t                  acquisitions   = 0;
+        bool                    sawExactDevice = false;
+        bool                    sawExactFD     = false;
+        bool                    sawExactSize   = false;
+        bool                    sawCommonPair  = false;
+    };
+
     SConnectorView connector(uint32_t id) {
         return {.connectorId = id};
     }
@@ -164,18 +256,48 @@ namespace {
     }
 
     SAllocationCapture allocationCapture() {
-        auto left   = makeShared<Aquamarine::SDRMConnector>();
-        auto right  = makeShared<Aquamarine::SDRMConnector>();
-        auto crtc0  = makeShared<Aquamarine::SDRMCRTC>();
-        auto crtc1  = makeShared<Aquamarine::SDRMCRTC>();
-        auto plane0 = makeShared<Aquamarine::SDRMPlane>();
-        auto plane1 = makeShared<Aquamarine::SDRMPlane>();
-        left->id    = 101;
-        right->id   = 202;
-        crtc0->id   = 10;
-        crtc1->id   = 11;
-        plane0->id  = 100;
-        plane1->id  = 101;
+        auto left                       = makeShared<Aquamarine::SDRMConnector>();
+        auto right                      = makeShared<Aquamarine::SDRMConnector>();
+        auto crtc0                      = makeShared<Aquamarine::SDRMCRTC>();
+        auto crtc1                      = makeShared<Aquamarine::SDRMCRTC>();
+        auto plane0                     = makeShared<Aquamarine::SDRMPlane>();
+        auto plane1                     = makeShared<Aquamarine::SDRMPlane>();
+        left->id                        = 101;
+        right->id                       = 202;
+        crtc0->id                       = 10;
+        crtc1->id                       = 11;
+        plane0->id                      = 100;
+        plane1->id                      = 102;
+        left->props.values.crtc_id      = 1000;
+        left->props.values.link_status  = 1001;
+        right->props.values.crtc_id     = 1010;
+        right->props.values.link_status = 1011;
+        crtc0->props.values.mode_id     = 2000;
+        crtc0->props.values.active      = 2001;
+        crtc1->props.values.mode_id     = 2010;
+        crtc1->props.values.active      = 2011;
+        plane0->formats                 = {{.drmFormat = DRM_FORMAT_XRGB8888, .modifiers = {DRM_FORMAT_MOD_LINEAR}}};
+        plane1->formats                 = plane0->formats;
+        plane0->props.values.src_x      = 3002;
+        plane0->props.values.src_y      = 3003;
+        plane0->props.values.src_w      = 3004;
+        plane0->props.values.src_h      = 3005;
+        plane0->props.values.crtc_x     = 3006;
+        plane0->props.values.crtc_y     = 3007;
+        plane0->props.values.crtc_w     = 3008;
+        plane0->props.values.crtc_h     = 3009;
+        plane0->props.values.fb_id      = 3000;
+        plane0->props.values.crtc_id    = 3001;
+        plane1->props.values.src_x      = 3022;
+        plane1->props.values.src_y      = 3023;
+        plane1->props.values.src_w      = 3024;
+        plane1->props.values.src_h      = 3025;
+        plane1->props.values.crtc_x     = 3026;
+        plane1->props.values.crtc_y     = 3027;
+        plane1->props.values.crtc_w     = 3028;
+        plane1->props.values.crtc_h     = 3029;
+        plane1->props.values.fb_id      = 3020;
+        plane1->props.values.crtc_id    = 3021;
         return {
             .resourceCRTCOrder = {10, 11},
             .connectors =
@@ -186,7 +308,7 @@ namespace {
             .crtcs =
                 {
                     {.crtc = crtc0, .preferredPrimaryPlaneID = 100, .kernelActive = true},
-                    // Plane 101 remains a candidate even though legacy's greedy
+                    // Plane 102 remains a candidate even though legacy's greedy
                     // CRTC cache did not select it as this CRTC's preference.
                     {.crtc = crtc1, .kernelActive = true},
                 },
@@ -340,7 +462,7 @@ int main() {
         EXPECT(SHADOW && SHADOW->plan()->status() == ePlanStatus::READY, true);
         EXPECT(SHADOW ? SHADOW->plan()->groups().size() : 0U, 1U);
         EXPECT(SHADOW && SHADOW->plan()->groups().front().status() == eGroupStatus::ALLOCATED, true);
-        EXPECT(SHADOW ? SHADOW->plan()->groups().front().bindings().at(1).primaryPlane()->id : 0U, 101U);
+        EXPECT(SHADOW ? SHADOW->plan()->groups().front().bindings().at(1).primaryPlane()->id : 0U, 102U);
         const auto  BRIDGE          = CFixtureAuthority::outputBridge(registry, LIFETIME);
         const auto* ALLOCATED_GROUP = multiStreamGroup(BRIDGE);
         EXPECT(!!BRIDGE, true);
@@ -349,6 +471,37 @@ int main() {
         EXPECT(ALLOCATED_GROUP && ALLOCATED_GROUP->modeSet(), true);
         const auto DEFINITION_IDENTITY = ALLOCATED_GROUP ? ALLOCATED_GROUP->definitionIdentity() : POutputDefinitionIdentity{};
         const auto OUTPUT_MODE = ALLOCATED_GROUP && ALLOCATED_GROUP->modeSet() ? ALLOCATED_GROUP->modeSet()->modes().front().outputMode : CSharedPointer<Aquamarine::SOutputMode>{};
+        auto       testFramebuffer = makeShared<SGroupedTestFramebuffer>();
+        testFramebuffer->device    = BRIDGE ? BRIDGE->capturedSnapshot()->device() : PDeviceIncarnation{};
+        testFramebuffer->drmFD     = 73;
+        testFramebuffer->atomic    = {
+            .id       = 700,
+            .size     = {.width = 5120, .height = 1440},
+            .format   = DRM_FORMAT_XRGB8888,
+            .modifier = DRM_FORMAT_MOD_LINEAR,
+        };
+        PGroupedTestFramebuffer                       retainedTestFramebuffer    = testFramebuffer;
+        auto                                          framebufferSource          = makeShared<STestFramebufferSource>(retainedTestFramebuffer);
+        auto                                          atomicOperations           = makeShared<STestAtomicOperations>();
+        CSharedPointer<IGroupedTestFramebufferSource> framebufferSourceInterface = framebufferSource;
+        CSharedPointer<ITiledAtomicRequestOperations> atomicOperationsInterface  = atomicOperations;
+        EXPECT(CFixtureAuthority::configureTestModeset(registry, LIFETIME, 73, atomicOperationsInterface, framebufferSourceInterface), true);
+
+        const auto TEST_MODESET =
+            CFixtureAuthority::executeTestModeset(registry, LIFETIME, BRIDGE, ALLOCATED_GROUP ? ALLOCATED_GROUP->scanDefinition() : PScanGroupDefinition{}, OUTPUT_MODE);
+        EXPECT(value(TEST_MODESET.status), value(eGroupedTestModesetStatus::SUCCEEDED));
+        EXPECT(TEST_MODESET.routeError == eTiledAtomicError::NONE, true);
+        EXPECT(TEST_MODESET.executionStatus.value_or(eTiledTestModesetStatus::INVALID_INPUT) == eTiledTestModesetStatus::SUCCEEDED, true);
+        EXPECT(TEST_MODESET.submission.has_value(), true);
+        EXPECT(TEST_MODESET.cleanup.complete(), true);
+        EXPECT(framebufferSource->acquisitions, 1U);
+        EXPECT(framebufferSource->sawExactDevice && framebufferSource->sawExactFD && framebufferSource->sawExactSize && framebufferSource->sawCommonPair, true);
+        EXPECT(atomicOperations->submits, 1U);
+        EXPECT(atomicOperations->submittedFD, 73);
+        EXPECT(atomicOperations->submittedFlags, TILED_ATOMIC_TEST_MODESET_FLAGS);
+        EXPECT(atomicOperations->submittedUserData == nullptr, true);
+        EXPECT(atomicOperations->allocations, 1U);
+        EXPECT(atomicOperations->frees, 1U);
         POutputBridgeObservation gatedBridge;
         EXPECT(CFixtureAuthority::withCurrentOutputBridge(registry, LIFETIME, SHADOW, [&](const auto& current) { gatedBridge = current; }), true);
         EXPECT(gatedBridge == BRIDGE, true);
@@ -392,6 +545,10 @@ int main() {
         EXPECT(FALLBACK_GROUP && FALLBACK_GROUP->projection() == eGroupProjection::MULTI_STREAM_FALLBACK, true);
         EXPECT(FALLBACK_GROUP && FALLBACK_GROUP->definitionIdentity() == DEFINITION_IDENTITY, true);
         EXPECT(FALLBACK_GROUP && FALLBACK_GROUP->modeSet() && FALLBACK_GROUP->modeSet()->modes().front().outputMode == OUTPUT_MODE, true);
+        const auto STALE_TEST_MODESET =
+            CFixtureAuthority::executeTestModeset(registry, LIFETIME, BRIDGE, ALLOCATED_GROUP ? ALLOCATED_GROUP->scanDefinition() : PScanGroupDefinition{}, OUTPUT_MODE);
+        EXPECT(value(STALE_TEST_MODESET.status), value(eGroupedTestModesetStatus::INVALID_CURRENT));
+        EXPECT(atomicOperations->submits, 1U);
         EXPECT(CFixtureAuthority::withCurrent(registry, LIFETIME, SHADOW, [&](const CPlan&, const SCurrentState&) { ++callbacks; }), false);
         EXPECT(CFixtureAuthority::withCurrentOutputBridge(registry, LIFETIME, SHADOW, [&](const auto&) { ++callbacks; }), false);
         EXPECT(callbacks, 1U);
@@ -465,6 +622,20 @@ int main() {
         EXPECT(callbacks, 1U);
 
         EXPECT(value(CFixtureAuthority::capture(registry, LIFETIME, allocationCapture())), value(eAllocationCaptureResult::INSTALLED));
+        const auto  FINAL_BRIDGE = CFixtureAuthority::outputBridge(registry, LIFETIME);
+        const auto* FINAL_GROUP  = multiStreamGroup(FINAL_BRIDGE);
+        const auto  FINAL_MODE   = FINAL_GROUP && FINAL_GROUP->modeSet() ? FINAL_GROUP->modeSet()->modes().front().outputMode : CSharedPointer<Aquamarine::SOutputMode>{};
+        EXPECT(!!FINAL_BRIDGE, true);
+        atomicOperations->destroyFailuresRemaining = 1;
+        const auto RETAINED_CLEANUP =
+            CFixtureAuthority::executeTestModeset(registry, LIFETIME, FINAL_BRIDGE, FINAL_GROUP ? FINAL_GROUP->scanDefinition() : PScanGroupDefinition{}, FINAL_MODE);
+        EXPECT(value(RETAINED_CLEANUP.status), value(eGroupedTestModesetStatus::CLEANUP_PENDING));
+        EXPECT(RETAINED_CLEANUP.cleanup.retained, 1U);
+        EXPECT(atomicOperations->submits, 2U);
+        // The fd-scoped cleanup debt survives every scan/session replacement.
+        // Detach retries it and cannot advance while destruction still fails.
+        atomicOperations->destroyFailuresRemaining = 1;
+        EXPECT(value(CFixtureAuthority::beginDetach(registry, LIFETIME, eDetachReason::BACKEND_SHUTDOWN)), value(eDetachResult::BUSY));
         EXPECT(!!CFixtureAuthority::outputBridge(registry, LIFETIME), true);
         EXPECT(value(CFixtureAuthority::beginDetach(registry, LIFETIME, eDetachReason::BACKEND_SHUTDOWN)), value(eDetachResult::BEGUN));
         EXPECT(!!CFixtureAuthority::outputBridge(registry, LIFETIME), false);