From 39d3edc175e36de08f13b8dd8105cf9871e6db2d Mon Sep 17 00:00:00 2001 From: Marc Khouzam Date: Fri, 2 Mar 2012 14:49:51 -0500 Subject: [PATCH] Bug 371198: Fixes for intermittent test failures. --- .../cdt/tests/dsf/gdb/tests/MIRegistersTest.java | 14 ++++++++++---- .../cdt/tests/dsf/gdb/tests/MIRunControlTest.java | 12 +++++++++--- 2 files changed, 19 insertions(+), 7 deletions(-) diff --git a/dsf-gdb/org.eclipse.cdt.tests.dsf.gdb/src/org/eclipse/cdt/tests/dsf/gdb/tests/MIRegistersTest.java b/dsf-gdb/org.eclipse.cdt.tests.dsf.gdb/src/org/eclipse/cdt/tests/dsf/gdb/tests/MIRegistersTest.java index 6c5949ca61b..5fbeaf37bbe 100644 --- a/dsf-gdb/org.eclipse.cdt.tests.dsf.gdb/src/org/eclipse/cdt/tests/dsf/gdb/tests/MIRegistersTest.java +++ b/dsf-gdb/org.eclipse.cdt.tests.dsf.gdb/src/org/eclipse/cdt/tests/dsf/gdb/tests/MIRegistersTest.java @@ -347,10 +347,16 @@ public class MIRegistersTest extends BaseTestCase { // thread is conditional depending on environment. Run to the printf // before it (which is common), then do step operations over the // non-common code (but same number of lines) - SyncUtil.runToLine(SRC_NAME, Integer.toString(MIRunControlTest.LINE_MAIN_PRINTF)); - SyncUtil.step(StepType.STEP_OVER); // over the printf - SyncUtil.step(StepType.STEP_OVER); // over the create-thread call - MIStoppedEvent stoppedEvent = SyncUtil.step(StepType.STEP_OVER, TestsPlugin.massageTimeout(2000)); // over the one second sleep + SyncUtil.runToLine(SRC_NAME, Integer.toString(MIRunControlTest.LINE_MAIN_PRINTF)); + + // Because the program is about to go multi-threaded, we have to select the thread + // we want to keep stepping. If we don't, we will ask GDB to step the entire process + // which is not what we want. We can fetch the thread from the stopped event + // but we should do that before the second thread is created, to be sure the stopped + // event is for the main thread. + MIStoppedEvent stoppedEvent = SyncUtil.step(StepType.STEP_OVER); // over the printf + SyncUtil.step(stoppedEvent.getDMContext(), StepType.STEP_OVER); // over the create-thread call + stoppedEvent = SyncUtil.step(stoppedEvent.getDMContext(), StepType.STEP_OVER, TestsPlugin.massageTimeout(2000)); // over the one second sleep // Get the thread IDs final IContainerDMContext containerDmc = DMContexts.getAncestorOfType(stoppedEvent.getDMContext(), IContainerDMContext.class); diff --git a/dsf-gdb/org.eclipse.cdt.tests.dsf.gdb/src/org/eclipse/cdt/tests/dsf/gdb/tests/MIRunControlTest.java b/dsf-gdb/org.eclipse.cdt.tests.dsf.gdb/src/org/eclipse/cdt/tests/dsf/gdb/tests/MIRunControlTest.java index 582794cfd06..1616e126efa 100644 --- a/dsf-gdb/org.eclipse.cdt.tests.dsf.gdb/src/org/eclipse/cdt/tests/dsf/gdb/tests/MIRunControlTest.java +++ b/dsf-gdb/org.eclipse.cdt.tests.dsf.gdb/src/org/eclipse/cdt/tests/dsf/gdb/tests/MIRunControlTest.java @@ -272,9 +272,15 @@ public class MIRunControlTest extends BaseTestCase { // before it (which is common), then do step operations over the // non-common code (but same number of lines) SyncUtil.runToLine(fContainerDmc, SOURCE_NAME, Integer.toString(LINE_MAIN_PRINTF), true); - SyncUtil.step(StepType.STEP_OVER); // over the printf - SyncUtil.step(StepType.STEP_OVER); // over the create-thread call - SyncUtil.step(StepType.STEP_OVER, TestsPlugin.massageTimeout(2000)); // over the one second sleep + + // Because the program is about to go multi-threaded, we have to select the thread + // we want to keep stepping. If we don't, we will ask GDB to step the entire process + // which is not what we want. We can fetch the thread from the stopped event + // but we should do that before the second thread is created, to be sure the stopped + // event is for the main thread. + MIStoppedEvent stoppedEvent = SyncUtil.step(StepType.STEP_OVER); // over the printf + SyncUtil.step(stoppedEvent.getDMContext(), StepType.STEP_OVER); // over the create-thread call + SyncUtil.step(stoppedEvent.getDMContext(), StepType.STEP_OVER, TestsPlugin.massageTimeout(2000)); // over the one second sleep // Make sure thread started event was received IStartedDMEvent startedEvent = startedEventWaitor.waitForEvent(TestsPlugin.massageTimeout(1000));