From 80ff1f872fd049f0ba4792ce99175da483ccc2c6 Mon Sep 17 00:00:00 2001 From: Simon Marchi Date: Fri, 23 Jan 2015 14:27:47 -0500 Subject: [PATCH] debug tests: Factor out test in GDBConsoleSynchronizingTest Factor out the code for testSettingVariableWithSet and testSettingVariableWithPrint. testSettingVariableWithSetWithMemory is not exactly the same, so I didn't factor it out. Change-Id: Ib4e79eda4851ec2291fcf32054694b76e40c65ca Signed-off-by: Simon Marchi --- .../GDBConsoleSynchronizingTest_7_6.java | 111 ++++++------------ 1 file changed, 38 insertions(+), 73 deletions(-) diff --git a/dsf-gdb/org.eclipse.cdt.tests.dsf.gdb/src/org/eclipse/cdt/tests/dsf/gdb/tests/tests_7_6/GDBConsoleSynchronizingTest_7_6.java b/dsf-gdb/org.eclipse.cdt.tests.dsf.gdb/src/org/eclipse/cdt/tests/dsf/gdb/tests/tests_7_6/GDBConsoleSynchronizingTest_7_6.java index 8da25465a89..e57b0bd5996 100644 --- a/dsf-gdb/org.eclipse.cdt.tests.dsf.gdb/src/org/eclipse/cdt/tests/dsf/gdb/tests/tests_7_6/GDBConsoleSynchronizingTest_7_6.java +++ b/dsf-gdb/org.eclipse.cdt.tests.dsf.gdb/src/org/eclipse/cdt/tests/dsf/gdb/tests/tests_7_6/GDBConsoleSynchronizingTest_7_6.java @@ -188,19 +188,13 @@ public class GDBConsoleSynchronizingTest_7_6 extends BaseTestCase { assertEquals(newValue, exprValue); } - /** - * This test verifies that setting a variable from the console - * using the set command will properly trigger a DSF event to - * indicate the change, when the address is not in the memory cache. - */ - @Test - public void testSettingVariableWithSet() throws Throwable { - MIStoppedEvent stoppedEvent = SyncUtil.runToLocation("testMemoryChanges"); - - final IFrameDMContext frameDmc = SyncUtil.getStackFrame(stoppedEvent.getDMContext(), 0); - final IExpressionDMContext exprDmc = SyncUtil.createExpression(frameDmc, "i"); + private void testSettingVariableWithCommon(String commandPrefix) throws Throwable { + MIStoppedEvent stoppedEvent = SyncUtil.runToLocation("testMemoryChanges"); - // Read the memory that will change first, or else there will be no event for it + final IFrameDMContext frameDmc = SyncUtil.getStackFrame(stoppedEvent.getDMContext(), 0); + final IExpressionDMContext exprDmc = SyncUtil.createExpression(frameDmc, "i"); + + // Read the memory that will change first, or else there will be no event for it Query query = new Query() { @Override protected void execute(final DataRequestMonitor rm) { @@ -211,30 +205,40 @@ public class GDBConsoleSynchronizingTest_7_6 extends BaseTestCase { fSession.getExecutor().execute(query); IExpressionDMAddress data = query.get(); - fEventsReceived.clear(); + fEventsReceived.clear(); - final String newValue = NEW_VAR_VALUE; - queueConsoleCommand("set variable i=" + newValue); - - IMemoryChangedEvent memoryEvent = waitForEvent(IMemoryChangedEvent.class); - assertEquals(1, memoryEvent.getAddresses().length); - assertEquals(data.getAddress(), memoryEvent.getAddresses()[0]); + final String newValue = NEW_VAR_VALUE; + queueConsoleCommand(commandPrefix + " = " + newValue); - // Now verify the memory service knows the new memory value - IMemoryDMContext memoryDmc = DMContexts.getAncestorOfType(frameDmc, IMemoryDMContext.class); - MemoryByte[] memory = readMemory(memoryDmc, data.getAddress(), NEW_VAR_SIZE); - assertEquals(NEW_VAR_SIZE, memory.length); - for (int i=0; i query = new Query() { - @Override - protected void execute(final DataRequestMonitor rm) { - fExprService.getExpressionAddressData(exprDmc, rm); - } - }; - - fSession.getExecutor().execute(query); - IExpressionDMAddress data = query.get(); - - fEventsReceived.clear(); - - final String newValue = NEW_VAR_VALUE; - queueConsoleCommand("print i=" + newValue); - - IMemoryChangedEvent memoryEvent = waitForEvent(IMemoryChangedEvent.class); - assertEquals(1, memoryEvent.getAddresses().length); - assertEquals(data.getAddress(), memoryEvent.getAddresses()[0]); - - // Now verify the memory service knows the new memory value - IMemoryDMContext memoryDmc = DMContexts.getAncestorOfType(frameDmc, IMemoryDMContext.class); - MemoryByte[] memory = readMemory(memoryDmc, data.getAddress(), NEW_VAR_SIZE); - assertEquals(NEW_VAR_SIZE, memory.length); - for (int i=0; i