From 161b57f9edec45801dccc330cbacc7e59a54f445 Mon Sep 17 00:00:00 2001 From: Jonah Graham Date: Sun, 9 Oct 2022 14:50:14 -0400 Subject: [PATCH] Tests for dprintf GDB functionality Bug 400628 was originally completed without any new tests. To make it easier to test that Bug 580873 works, this commit adds in some missing tests. --- .../data/launch/src/BreakpointTestApp.cc | 2 +- .../dsf/gdb/tests/MIBreakpointsTest.java | 28 ++++++++++++++++++- 2 files changed, 28 insertions(+), 2 deletions(-) diff --git a/dsf-gdb/org.eclipse.cdt.tests.dsf.gdb/data/launch/src/BreakpointTestApp.cc b/dsf-gdb/org.eclipse.cdt.tests.dsf.gdb/data/launch/src/BreakpointTestApp.cc index 020ef90523a..c74cd664715 100644 --- a/dsf-gdb/org.eclipse.cdt.tests.dsf.gdb/data/launch/src/BreakpointTestApp.cc +++ b/dsf-gdb/org.eclipse.cdt.tests.dsf.gdb/data/launch/src/BreakpointTestApp.cc @@ -25,7 +25,7 @@ void zeroBlocks(int abc) void setBlocks() { for (int i = 0; i < ARRAY_SIZE; i++) { // LINE_NUMBER_3 - charBlock[i] = (char) i; + charBlock[i] = (char) i; // LINE_LOOP_1 integerBlock[i] = i; } } diff --git a/dsf-gdb/org.eclipse.cdt.tests.dsf.gdb/src/org/eclipse/cdt/tests/dsf/gdb/tests/MIBreakpointsTest.java b/dsf-gdb/org.eclipse.cdt.tests.dsf.gdb/src/org/eclipse/cdt/tests/dsf/gdb/tests/MIBreakpointsTest.java index 0d56e0a923e..972529a6947 100644 --- a/dsf-gdb/org.eclipse.cdt.tests.dsf.gdb/src/org/eclipse/cdt/tests/dsf/gdb/tests/MIBreakpointsTest.java +++ b/dsf-gdb/org.eclipse.cdt.tests.dsf.gdb/src/org/eclipse/cdt/tests/dsf/gdb/tests/MIBreakpointsTest.java @@ -68,6 +68,8 @@ import org.eclipse.cdt.tests.dsf.gdb.launching.TestsPlugin; import org.eclipse.debug.core.DebugPlugin; import org.eclipse.debug.core.IBreakpointManager; import org.eclipse.debug.core.model.IBreakpoint; +import org.eclipse.debug.core.model.IProcess; +import org.eclipse.debug.core.model.IStreamMonitor; import org.junit.Assert; import org.junit.Assume; import org.junit.Ignore; @@ -141,7 +143,7 @@ public class MIBreakpointsTest extends BaseParametrizedTestCase { // Target application 'special' locations private static final String[] LINE_TAGS = new String[] { "LINE_NUMBER_1", "LINE_NUMBER_2", "LINE_NUMBER_3", - "LINE_NUMBER_4", "LINE_NUMBER_5", "LINE_NUMBER_6", }; + "LINE_NUMBER_4", "LINE_NUMBER_5", "LINE_NUMBER_6", "LINE_LOOP_1" }; private int LINE_NUMBER_1; private int LINE_NUMBER_2; @@ -149,6 +151,7 @@ public class MIBreakpointsTest extends BaseParametrizedTestCase { private int LINE_NUMBER_4; private int LINE_NUMBER_5; private int LINE_NUMBER_6; + private int LINE_LOOP_1; protected final String FUNCTION = "zeroBlocks"; protected final String SIGNED_FUNCTION = "zeroBlocks(int)"; @@ -216,6 +219,7 @@ public class MIBreakpointsTest extends BaseParametrizedTestCase { LINE_NUMBER_4 = getLineForTag("LINE_NUMBER_4"); LINE_NUMBER_5 = getLineForTag("LINE_NUMBER_5"); LINE_NUMBER_6 = getLineForTag("LINE_NUMBER_6"); + LINE_LOOP_1 = getLineForTag("LINE_LOOP_1"); } @Override @@ -3312,4 +3316,26 @@ public class MIBreakpointsTest extends BaseParametrizedTestCase { assertTrue("BreakpointService problem: breakpoint mismatch (not pending)", breakpoint1.isPending()); clearEventCounters(); } + + @Test + public void insertDprintfBreakpoint() throws Throwable { + Map printfBreakpoint = new HashMap<>(); + printfBreakpoint.put(MIBreakpoints.BREAKPOINT_TYPE, MIBreakpoints.DYNAMICPRINTF); + printfBreakpoint.put(MIBreakpoints.FILE_NAME, SOURCE_NAME); + printfBreakpoint.put(MIBreakpoints.LINE_NUMBER, LINE_LOOP_1); + printfBreakpoint.put(MIBreakpoints.PRINTF_STRING, "\"format %d\\n\", i"); + + IBreakpointDMContext printfRef = insertBreakpoint(fBreakpointsDmc, printfBreakpoint); + waitForBreakpointEvent(1); + insertBreakpoint(fBreakpointsDmc, Map.of(BREAKPOINT_TYPE_TAG, BREAKPOINT_TAG, FILE_NAME_TAG, SOURCE_NAME, + LINE_NUMBER_TAG, LINE_NUMBER_5)); + SyncUtil.resumeUntilStopped(5000); + IProcess[] processes = getGDBLaunch().getProcesses(); + IStreamMonitor outputStreamMonitor = processes[1].getStreamsProxy().getOutputStreamMonitor(); + String[] contents = outputStreamMonitor.getContents().split("\n"); + for (int i = 0; i < 256; i++) { + assertEquals("format " + i, contents[i].trim()); + } + + } }