Skip to content

Commit 873f7cf

Browse files
committed
Test memory commit result contract
1 parent 5636200 commit 873f7cf

1 file changed

Lines changed: 22 additions & 0 deletions

File tree

tests/FoundationsTests/MemoryRobustnessTests.cpp

Lines changed: 22 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -40,6 +40,28 @@ UTEST(MemoryRobustness, PushSizeOverflowDoesNotAdvanceArena)
4040
ASSERT_EQ(0llu, SystemGetMemoryArenaAllocationInfos(memoryArena).AllocatedBytes);
4141
}
4242

43+
UTEST(MemoryRobustness, CommitReportsInvalidRange)
44+
{
45+
// Arrange
46+
auto memoryArena = SystemAllocateMemoryArena(64);
47+
auto allocation = SystemPushArray<uint8_t>(memoryArena, 64, AllocationState_Reserved);
48+
49+
// Act
50+
auto validCommit = SystemCommitMemory(memoryArena, allocation, true);
51+
auto invalidCommit = SystemCommitMemory(memoryArena, allocation.Pointer + allocation.Length, 8);
52+
53+
// Assert
54+
ASSERT_TRUE(validCommit);
55+
ASSERT_FALSE(invalidCommit);
56+
57+
for (size_t i = 0; i < allocation.Length; i++)
58+
{
59+
ASSERT_EQ(0, allocation[i]);
60+
}
61+
62+
SystemFreeMemoryArena(memoryArena);
63+
}
64+
4365
UTEST(MemoryRobustness, ConcurrentArenaAllocationAccounting)
4466
{
4567
// Arrange

0 commit comments

Comments
 (0)