[Test] (MG_Test/Buffer): keep the mapping backend alive through adoption checks

This commit is contained in:
BZLZHH committed 2026-11-29 11:56:37 +08:00
1 parent bc7e703e23
commit 13d9317aab
1 file changed
+20 -18
+20 -18
View File
@@ -57,24 +57,26 @@ namespace {
return ops;
}();
// The window in which the case is a MONOLITH with that backend registered: the adopted buffer
// is created, mapped and destroyed inside one, so its records are applied synchronously.
struct ScopedMintingMonolith {
ScopedMintingMonolith()
: m_transport(MG_Config::Transport), m_push(MG_Config::Features.PipePush),
m_ops(MG_Pipe::MGPipeGetResourceOps()) {
MG_Config::Transport = MG_Config::TransportMode::Monolith;
MG_Config::Features.PipePush |= MG_Pipe::kMGPipeSubsystemResources;
struct ScopedMintingOps {
ScopedMintingOps() : m_ops(MG_Pipe::MGPipeGetResourceOps()) {
MG_Pipe::MGPipeSetResourceOps(&g_mintingResourceOps);
}
~ScopedMintingMonolith() {
MG_Pipe::MGPipeSetResourceOps(m_ops);
~ScopedMintingOps() { MG_Pipe::MGPipeSetResourceOps(m_ops); }
const MG_Pipe::MGPipeResourceOps* m_ops;
};
// Buffer creation, mapping and destruction use synchronous monolith records.
struct ScopedMonolithResources {
ScopedMonolithResources() : m_transport(MG_Config::Transport), m_push(MG_Config::Features.PipePush) {
MG_Config::Transport = MG_Config::TransportMode::Monolith;
MG_Config::Features.PipePush |= MG_Pipe::kMGPipeSubsystemResources;
}
~ScopedMonolithResources() {
MG_Config::Features.PipePush = m_push;
MG_Config::Transport = m_transport;
}
MG_Config::TransportMode m_transport;
Uint64 m_push;
const MG_Pipe::MGPipeResourceOps* m_ops;
};
// Everything in this package is gated on `Transport != Monolith`, so every case has to
@@ -339,11 +341,6 @@ TEST_F(SplitBufferSet, TheAdoptedArmIsNotAMemberAndItIsTheChainRowThatSaysSo) {
Vector<Uint8> minted(kSize, static_cast<Uint8>(0));
g_mintedPersistentBase = minted.data();
SharedPtr<BufferObject> adopted;
{
ScopedMintingMonolith minting;
adopted = MakeBuffer(27u, kSize);
}
auto declined = MakeBuffer(28u, kSize);
// The declined twin first, with no backend ops at all: same flags, same size, same call.
@@ -353,8 +350,13 @@ TEST_F(SplitBufferSet, TheAdoptedArmIsNotAMemberAndItIsTheChainRowThatSaysSo) {
<< "the emulated arm IS a member - if this fails the two halves are not comparable and the "
"assertion below proves nothing";
// Replacing the backend ops revokes resident mappings. Keep the minting ops
// installed until the adopted buffer has been tested and destroyed.
const ScopedMintingOps minting;
SharedPtr<BufferObject> adopted;
{
ScopedMintingMonolith minting;
const ScopedMonolithResources monolith;
adopted = MakeBuffer(27u, kSize);
adopted->AcquireMemoryRange(Range1D{0, kSize},
BufferMappingAccessBit::Write | BufferMappingAccessBit::Persistent);
}
@@ -396,7 +398,7 @@ TEST_F(SplitBufferSet, TheAdoptedArmIsNotAMemberAndItIsTheChainRowThatSaysSo) {
// definition (PipeResource.h:121-127). It is dropped here with the mapping still adopted,
// which is also the shape ~BufferObject has to survive.
{
ScopedMintingMonolith minting;
const ScopedMonolithResources monolith;
adopted.reset();
}
g_mintedPersistentBase = nullptr;