[Test] (MG_IntegrationTest): assert which persistent-map arm the scenario landed in through a peek at IsBackendPersistentMapped, not by inferring it from the push byte counter - "the push was never wired" and "the store was adopted" are different defects with different owners and the counter reads the same for both

This commit is contained in:
2026-09-11 14:40:30 -04:00
parent f265f0a8e1
commit 7ad0ff3c33
4 changed files with 289 additions and 42 deletions
@@ -0,0 +1,91 @@
// MobileGL - MobileGL/MG_IntegrationTest/Harness/PersistentMapPeek.cpp
// Copyright (c) 2026 MobileGL-Dev
// Licensed under the GNU Lesser General Public License v3.0:
// https://www.gnu.org/licenses/gpl-3.0.txt
// https://www.gnu.org/licenses/lgpl-3.0.txt
// SPDX-License-Identifier: LGPL-3.0-only
// End of Source File Header
#include "PersistentMapPeek.h"
#if !defined(__ANDROID__)
#include <MG_State/GLState/BufferState/BufferObject.h>
#include <MG_State/GLState/Core.h>
#define MGITEST_PERSISTENT_MAP_PEEK_LIVE 1
#endif
// MGITEST_PERSISTENT_MAP_TRACKER is defined by MG_IntegrationTest/CMakeLists.txt, and only when
// BOTH halves are true: the build compiled MG_Remote (so the symbol can link) AND some source
// under MG_Remote/Client names IsLivePersistentMap (so package b1 landed it). __has_include is
// NOT enough on its own - the header exists in the source tree of every build, including the pull
// build that never compiles MG_Remote, so keying on it would turn a healthy pull build into a
// link error.
#if defined(MGITEST_PERSISTENT_MAP_PEEK_LIVE) && defined(MGITEST_PERSISTENT_MAP_TRACKER)
#include <MG_Remote/Client/PersistentMapTracker.h>
#define MGITEST_PERSISTENT_MAP_TRACKER_LIVE 1
#endif
namespace MGITest {
bool PersistentMapPeekAvailable() {
#if defined(MGITEST_PERSISTENT_MAP_PEEK_LIVE)
return true;
#else
return false;
#endif
}
bool PersistentMapTrackerAvailable() {
#if defined(MGITEST_PERSISTENT_MAP_TRACKER_LIVE)
return true;
#else
return false;
#endif
}
#if defined(MGITEST_PERSISTENT_MAP_PEEK_LIVE)
namespace {
// The frontend object behind a GL buffer name, or null. GetBufferObject mints on demand
// for a name that was generated and never bound, which is harmless here: a scenario only
// ever asks about a buffer it has already defined and mapped, and a null store answers
// "not adopted", which is the same answer an un-mapped buffer would give.
MobileGL::MG_State::GLState::BufferObject* FrontendBuffer(unsigned int bufferName) {
if (bufferName == 0) return nullptr;
auto& context = MobileGL::MG_State::pGLContext;
if (!context) return nullptr;
const auto& buffer = context->GetBufferObject(static_cast<MobileGL::Uint>(bufferName));
return buffer.get();
}
} // namespace
#endif
bool PeekBufferIsAdoptedPersistentMap(unsigned int bufferName, bool* outAdopted) {
#if defined(MGITEST_PERSISTENT_MAP_PEEK_LIVE)
if (outAdopted == nullptr) return false;
MobileGL::MG_State::GLState::BufferObject* buffer = FrontendBuffer(bufferName);
if (buffer == nullptr) return false;
*outAdopted = static_cast<bool>(buffer->IsBackendPersistentMapped());
return true;
#else
(void)bufferName;
(void)outAdopted;
return false;
#endif
}
bool PeekBufferIsLivePersistentMap(unsigned int bufferName, bool* outLive) {
#if defined(MGITEST_PERSISTENT_MAP_TRACKER_LIVE)
if (outLive == nullptr) return false;
MobileGL::MG_State::GLState::BufferObject* buffer = FrontendBuffer(bufferName);
if (buffer == nullptr) return false;
*outLive = static_cast<bool>(
MobileGL::MG_Remote::Client::PersistentMapTracker::IsLivePersistentMap(*buffer));
return true;
#else
(void)bufferName;
(void)outLive;
return false;
#endif
}
} // namespace MGITest
@@ -0,0 +1,61 @@
// MobileGL - MobileGL/MG_IntegrationTest/Harness/PersistentMapPeek.h
// Copyright (c) 2026 MobileGL-Dev
// Licensed under the GNU Lesser General Public License v3.0:
// https://www.gnu.org/licenses/gpl-3.0.txt
// https://www.gnu.org/licenses/lgpl-3.0.txt
// SPDX-License-Identifier: LGPL-3.0-only
// End of Source File Header
//
// WHICH ARM A PERSISTENT|WRITE|COHERENT MAP LANDED IN, read from a scenario.
//
// It exists for exit gate E3's first assertion, and package b1 (b1-v1.md 4.1) names the
// spelling: `IsBackendPersistentMapped()` must be FALSE, i.e. the store was NOT adopted and the
// CPU shadow is still the source of truth, i.e. the emulated arm. The question has no answer in
// the GL API at all - both arms map, both arms take the application's writes, both arms draw the
// same pixels - so a scenario with no peek is a scenario that silently tests whichever arm the
// driver and the build happened to choose. `MOBILEGL_DISABLE_LARGE_BUFFER_ADOPTION` does not
// separate them either: it is read only inside TryAdoptLargeStorage, and a scenario-sized buffer
// never reaches the 16 MiB threshold that calls it.
//
// A separate translation unit for BackendCapsPeek.h's reason, verbatim: the scenario sources
// include the GL headers with prototypes and MobileGL's umbrella header is not meant to meet them
// in one file.
//
// Every entry point returns FALSE, touching nothing, where the state is out of reach - on Android
// this module links the shipping libMobileGL.so built -fvisibility=hidden, so no internal symbol
// resolves, and the tracker half additionally needs a build that compiled MG_Remote/Client. A
// caller that gets false must SKIP rather than pass: "could not look" is not "it was emulated".
#pragma once
namespace MGITest {
// True when the peek can answer at all in this build. A scenario asks this first so that its
// skip message can name WHY it could not look.
bool PersistentMapPeekAvailable();
// BufferObject::IsBackendPersistentMapped() for the buffer with this GL name.
//
// returns false -> could not look (no peek in this build, no current context, or no such
// buffer). *outAdopted is untouched.
// returns true -> *outAdopted is true on the ADOPTED arm (the resource owner minted
// host-visible coherent storage and the shadow was released) and false on
// the EMULATED arm (the owner declined; the shadow is the truth and the
// client has to push blocks). R-6 pins the split arm at emulated.
bool PeekBufferIsAdoptedPersistentMap(unsigned int bufferName, bool* outAdopted);
// True when this build compiled package b1's client-side persistent-map tracker, so the
// membership predicate below means something. CMake answers it, by probing MG_Remote/Client
// for the symbol: a build that never compiled MG_Remote cannot link the call, so the decision
// has to be made before the compiler sees it rather than by __has_include.
bool PersistentMapTrackerAvailable();
// MG_Remote::Client::PersistentMapTracker::IsLivePersistentMap() for this buffer - b1-v1.md
// 4.1 item 2. The membership set is meant to be exactly the early-out chain of
// SyncPersistentMappedRange; asking it here is what makes a drift between the two fail in a
// named test rather than silently stop the push.
//
// Same contract as above: false means "could not look".
bool PeekBufferIsLivePersistentMap(unsigned int bufferName, bool* outLive);
} // namespace MGITest