MCPcopy Create free account
hub / github.com/WasmEdge/WasmEdge / TEST_F

Function TEST_F

test/meminstance/MemInstanceTest.cpp:175–196  ·  view source on GitHub ↗

Test: Forward overlap (dst > src, regions overlap). This is the case that was broken before the fix: std::copy iterates forward, so when dst > src, earlier writes overwrite source bytes that haven't been read yet. Memory layout: Address: 0 1 2 3 4 5 6 7 8 9 Before: A B C D E F G H . . copy(dst=3, src=0, len=5) Source region: [0..4] = A B C D E Dest region: [3..7] After (co

Source from the content-addressed store, hash-verified

173// After (correct): A B C A B C D E . .
174// After (buggy): A B C A B C A B . . (forward copy corruption)
175TEST_F(MemCopyOverlapTest, ForwardOverlap) {
176 // Initialize memory[0..7] = {0x41..0x48} ('A'..'H')
177 for (uint32_t I = 0; I < 8; ++I) {
178 storeByte(vm(), I, 0x41 + I);
179 }
180
181 // memory.copy(dst=3, src=0, len=5)
182 // Overlapping forward: dst > src, and dst < src + len
183 memoryCopy(vm(), 3, 0, 5);
184
185 // Verify: bytes at [3..7] should be the ORIGINAL [0..4] = A B C D E
186 std::vector<uint8_t> Expected = {0x41, 0x42, 0x43, 0x44, 0x45};
187 auto Actual = readMemory(vm(), 3, 5);
188 EXPECT_EQ(Actual, Expected)
189 << "Forward overlapping memory.copy produced incorrect results. "
190 "This indicates that std::copy was used instead of std::memmove.";
191
192 // Also verify that the non-overlapping prefix [0..2] is unchanged.
193 std::vector<uint8_t> Prefix = {0x41, 0x42, 0x43};
194 auto ActualPrefix = readMemory(vm(), 0, 3);
195 EXPECT_EQ(ActualPrefix, Prefix) << "Source prefix should be unchanged.";
196}
197
198// Test: Backward overlap (dst < src, regions overlap).
199// This case works correctly with forward std::copy, but we verify it anyway.

Callers

nothing calls this directly

Calls 4

storeByteFunction · 0.85
memoryCopyFunction · 0.85
readMemoryFunction · 0.85
loadByteFunction · 0.85

Tested by

no test coverage detected