1
0
Fork 0
mirror of https://github.com/eclipse-cdt/cdt synced 2025-06-06 17:26:01 +02:00

debug tests: Factor out duplicated code in MIMemoryTest.memoryCachedRead

Change-Id: I8ee7883e96e99d2daebe7a3748d4e5e6b3a165fe
Signed-off-by: Simon Marchi <simon.marchi@polymtl.ca>
This commit is contained in:
Simon Marchi 2015-01-24 00:50:07 -05:00 committed by Marc Khouzam
parent 9ae9ed49f6
commit 59854a48cd

View file

@ -11,6 +11,7 @@
*******************************************************************************/ *******************************************************************************/
package org.eclipse.cdt.tests.dsf.gdb.tests; package org.eclipse.cdt.tests.dsf.gdb.tests;
import static org.junit.Assert.assertEquals;
import static org.junit.Assert.assertTrue; import static org.junit.Assert.assertTrue;
import java.util.concurrent.ExecutionException; import java.util.concurrent.ExecutionException;
@ -1298,6 +1299,18 @@ public class MIMemoryTest extends BaseTestCase {
} }
} }
private void memoryCacheReadHelper(int offset, int count, int word_size)
throws InterruptedException, ExecutionException {
MemoryByte[] buffer = SyncUtil.readMemory(fMemoryDmc, fBaseAddress,
offset, word_size, count);
// Verify that all bytes are correctly set
for (int i = 0; i < count; i++) {
assertEquals("Wrong value read at offset " + i,
(byte) (offset + i), buffer[i].getValue());
}
}
// ------------------------------------------------------------------------ // ------------------------------------------------------------------------
// memoryCacheRead // memoryCacheRead
// Get a bunch of blocks to exercise the memory cache // Get a bunch of blocks to exercise the memory cache
@ -1312,120 +1325,41 @@ public class MIMemoryTest extends BaseTestCase {
IFrameDMContext frameDmc = SyncUtil.getStackFrame(stoppedEvent.getDMContext(), 0); IFrameDMContext frameDmc = SyncUtil.getStackFrame(stoppedEvent.getDMContext(), 0);
// Setup call parameters // Setup call parameters
long offset = 0;
int word_size = 1; int word_size = 1;
int count = BLOCK_SIZE;
fBaseAddress = evaluateExpression(frameDmc, "&charBlock"); fBaseAddress = evaluateExpression(frameDmc, "&charBlock");
// Get the 'reference' memory block // Get the 'reference' memory block
MemoryByte[] buffer = SyncUtil.readMemory(fMemoryDmc, fBaseAddress, offset, word_size, count); memoryCacheReadHelper(0, BLOCK_SIZE, word_size);
// Verify that all bytes are set to 'i'
for (int i = 0; i < count; i++) {
assertTrue("Wrong value read at offset " + i + ": expected '" + i + "', received '" + buffer[i].getValue() + "'",
(buffer[i].getValue() == (byte) i));
}
// Clear the cache // Clear the cache
SyncUtil.step(StepType.STEP_OVER); SyncUtil.step(StepType.STEP_OVER);
// Get a first block // Get a first block
fWait.waitReset(); memoryCacheReadHelper(0, 64, word_size);
offset = 0;
count = 64;
buffer = SyncUtil.readMemory(fMemoryDmc, fBaseAddress, offset, word_size, count);
// Verify that all bytes are correctly set
for (int i = 0; i < count; i++) {
assertTrue("Wrong value read at offset " + i + ": expected '" + offset + i + "', received '" + buffer[i].getValue() + "'",
(buffer[i].getValue() == (byte) (offset + i)));
}
// Get a second block // Get a second block
fWait.waitReset(); memoryCacheReadHelper(128, 64, word_size);
offset = 128;
count = 64;
buffer = SyncUtil.readMemory(fMemoryDmc, fBaseAddress, offset, word_size, count);
// Verify that all bytes are correctly set
for (int i = 0; i < count; i++) {
assertTrue("Wrong value read at offset " + i + ": expected '" + offset + i + "', received '" + buffer[i].getValue() + "'",
(buffer[i].getValue() == (byte) (offset + i)));
}
// Get a third block between the first 2 // Get a third block between the first 2
fWait.waitReset(); memoryCacheReadHelper(80, 32, word_size);
offset = 80;
count = 32;
buffer = SyncUtil.readMemory(fMemoryDmc, fBaseAddress, offset, word_size, count);
// Verify that all bytes are correctly set
for (int i = 0; i < count; i++) {
assertTrue("Wrong value read at offset " + i + ": expected '" + offset + i + "', received '" + buffer[i].getValue() + "'",
(buffer[i].getValue() == (byte) (offset + i)));
}
// Get a block that is contiguous to the end of an existing block // Get a block that is contiguous to the end of an existing block
fWait.waitReset(); memoryCacheReadHelper(192, 32, word_size);
offset = 192;
count = 32;
buffer = SyncUtil.readMemory(fMemoryDmc, fBaseAddress, offset, word_size, count);
// Verify that all bytes are correctly set
for (int i = 0; i < count; i++) {
assertTrue("Wrong value read at offset " + i + ": expected '" + offset + i + "', received '" + buffer[i].getValue() + "'",
(buffer[i].getValue() == (byte) (offset + i)));
}
// Get a block that ends beyond an existing block // Get a block that ends beyond an existing block
fWait.waitReset(); memoryCacheReadHelper(192, 64, word_size);
offset = 192;
count = 64;
buffer = SyncUtil.readMemory(fMemoryDmc, fBaseAddress, offset, word_size, count);
// Verify that all bytes are correctly set
for (int i = 0; i < count; i++) {
assertTrue("Wrong value read at offset " + i + ": expected '" + offset + i + "', received '" + buffer[i].getValue() + "'",
(buffer[i].getValue() == (byte) (offset + i)));
}
// Get a block that will require 2 reads (for the gaps between blocks 1-2 and 2-3) // Get a block that will require 2 reads (for the gaps between blocks 1-2 and 2-3)
fWait.waitReset(); memoryCacheReadHelper(32, 128, word_size);
offset = 32;
count = 128;
buffer = SyncUtil.readMemory(fMemoryDmc, fBaseAddress, offset, word_size, count);
// Verify that all bytes are correctly set
for (int i = 0; i < count; i++) {
assertTrue("Wrong value read at offset " + i + ": expected '" + offset + i + "', received '" + buffer[i].getValue() + "'",
(buffer[i].getValue() == (byte) (offset + i)));
}
// Get a block that involves multiple cached blocks // Get a block that involves multiple cached blocks
fWait.waitReset(); memoryCacheReadHelper(48, 192, word_size);
offset = 48;
count = 192;
buffer = SyncUtil.readMemory(fMemoryDmc, fBaseAddress, offset, word_size, count);
// Verify that all bytes are set to 'i'
for (int i = 0; i < count; i++) {
assertTrue("Wrong value read at offset " + i + ": expected '" + offset + i + "', received '" + buffer[i].getValue() + "'",
(buffer[i].getValue() == (byte) (offset + i)));
}
// Get the whole block // Get the whole block
fWait.waitReset(); memoryCacheReadHelper(0, BLOCK_SIZE, word_size);
offset = 0;
count = BLOCK_SIZE;
buffer = SyncUtil.readMemory(fMemoryDmc, fBaseAddress, offset, word_size, count);
// Verify that all bytes are correctly set
for (int i = 0; i < count; i++) {
assertTrue("Wrong value read at offset " + i + ": expected '" + offset + i + "', received '" + buffer[i].getValue() + "'",
(buffer[i].getValue() == (byte) (offset + i)));
}
// Ensure no MemoryChangedEvent event was received // Ensure no MemoryChangedEvent event was received
assertTrue("MemoryChangedEvent problem: expected " + 0 + ", received " + getEventCount(), getEventCount() == 0); assertEquals("MemoryChangedEvent problem: expected 0 events received.",
0, getEventCount());
} }
} }