1
0
Fork 0
mirror of https://github.com/eclipse-cdt/cdt synced 2025-09-10 12:03:16 +02:00

Adjust to the new dual POSIX/MSVC buildable MultiThread.cc. Also fix problems in the registers test

This commit is contained in:
John Cortell 2010-05-27 21:20:45 +00:00
parent 87aa0351e6
commit 4972e64775
3 changed files with 95 additions and 50 deletions

View file

@ -42,6 +42,7 @@ int main(int argc, char *argv[])
#ifdef __MINGW32__
{
uintptr_t rc = _beginthreadex(NULL, 0, PrintHello, (void*)t, 0, &threads[t]);
SLEEP(1); // debugger should for sure receive thread creation event after stepping over this sleep; not guaranteed to happen simply stepping over the thread creation call
if (rc == 0)
{
printf("ERROR; _beginthreadex() failed. errno = %d\n", errno);
@ -51,6 +52,7 @@ int main(int argc, char *argv[])
#else
{
int rc = pthread_create(&threads[t], NULL, PrintHello, (void *)t);
SLEEP(1); // debugger should for sure receive thread creation event after stepping over this sleep; not guaranteed to happen simply stepping over the thread creation call
if (rc)
{
printf("ERROR; return code from pthread_create() is %d\n", rc);
@ -59,4 +61,6 @@ int main(int argc, char *argv[])
}
#endif
}
return 0;
}

View file

@ -36,10 +36,13 @@ import org.eclipse.cdt.dsf.debug.service.IRegisters.IRegisterDMContext;
import org.eclipse.cdt.dsf.debug.service.IRegisters.IRegisterDMData;
import org.eclipse.cdt.dsf.debug.service.IRegisters.IRegisterGroupDMContext;
import org.eclipse.cdt.dsf.debug.service.IRegisters.IRegisterGroupDMData;
import org.eclipse.cdt.dsf.debug.service.IRunControl;
import org.eclipse.cdt.dsf.debug.service.IRunControl.IContainerDMContext;
import org.eclipse.cdt.dsf.debug.service.IRunControl.IExecutionDMContext;
import org.eclipse.cdt.dsf.debug.service.IRunControl.StepType;
import org.eclipse.cdt.dsf.debug.service.IStack.IFrameDMContext;
import org.eclipse.cdt.dsf.debug.service.command.ICommandControlService;
import org.eclipse.cdt.dsf.mi.service.IMIExecutionDMContext;
import org.eclipse.cdt.dsf.mi.service.IMIProcesses;
import org.eclipse.cdt.dsf.mi.service.MIProcesses;
import org.eclipse.cdt.dsf.mi.service.command.events.MIStoppedEvent;
@ -87,6 +90,7 @@ public class MIRegistersTest extends BaseTestCase {
private DsfServicesTracker fServicesTracker;
private IContainerDMContext fContainerDmc;
private IRegisters fRegService;
private IRunControl fRunControl;
@Before
public void init() throws Exception {
@ -102,6 +106,7 @@ public class MIRegistersTest extends BaseTestCase {
fRegService = fServicesTracker.getService(IRegisters.class);
fRunControl = fServicesTracker.getService(IRunControl.class);
}
@BeforeClass
@ -321,11 +326,51 @@ public class MIRegistersTest extends BaseTestCase {
@Test
public void compareRegisterForMultipleExecutionContexts() throws Throwable {
MIStoppedEvent stoppedEvent = SyncUtil.runToLine(SRC_NAME, "22");
IContainerDMContext containerDmc = DMContexts.getAncestorOfType(stoppedEvent.getDMContext(), IContainerDMContext.class);
// Run past the line that creates a thread and past the sleep that
// follows it. This is a bit tricky because the code that creates the
// 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
// Get the thread IDs
final IContainerDMContext containerDmc = DMContexts.getAncestorOfType(stoppedEvent.getDMContext(), IContainerDMContext.class);
final AsyncCompletionWaitor wait = new AsyncCompletionWaitor();
final DataRequestMonitor<IExecutionDMContext[]> drm =
new DataRequestMonitor<IExecutionDMContext[]>(fRegService.getExecutor(), null) {
@Override
protected void handleCompleted() {
if (isSuccess()) {
wait.setReturnInfo(getData());
}
wait.waitFinished(getStatus());
}
};
fRegService.getExecutor().submit(new Runnable() {
public void run() {
fRunControl.getExecutionContexts(containerDmc, drm);
}
});
wait.waitUntilDone(TestsPlugin.massageTimeout(5000));
Assert.assertTrue(wait.getMessage(), wait.isOK());
IExecutionDMContext[] ctxts = (IExecutionDMContext[])wait.getReturnInfo();
wait.waitReset();
Assert.assertNotNull(ctxts);
Assert.assertTrue(ctxts.length > 1);
int tid1 = ((IMIExecutionDMContext)ctxts[0]).getThreadId();
int tid2 = ((IMIExecutionDMContext)ctxts[1]).getThreadId();
// Get execution context to thread 2
IExecutionDMContext execDmc = SyncUtil.createExecutionContext(containerDmc, 2);
IExecutionDMContext execDmc = SyncUtil.createExecutionContext(containerDmc, tid2);
IFrameDMContext frameDmc2 = SyncUtil.getStackFrame(execDmc, 0);
String thread2RegVal0 = getModelDataForRegisterDataValue(frameDmc2, IFormattedValues.NATURAL_FORMAT, 0);
@ -336,7 +381,7 @@ public class MIRegistersTest extends BaseTestCase {
String thread2RegVal5 = getModelDataForRegisterDataValue(frameDmc2, IFormattedValues.NATURAL_FORMAT, 5);
// Get execution context to thread 1
execDmc = SyncUtil.createExecutionContext(containerDmc, 2);
execDmc = SyncUtil.createExecutionContext(containerDmc, tid1);
IFrameDMContext frameDmc1 = SyncUtil.getStackFrame(execDmc, 0);
getModelDataForRegisterDataValue(frameDmc1, IFormattedValues.NATURAL_FORMAT, 0);

View file

@ -83,6 +83,10 @@ public class MIRunControlTest extends BaseTestCase {
private IContainerDMContext fContainerDmc;
private IExecutionDMContext fThreadExecDmc;
// line numbers in MultiThread.cc
static final int LINE_MAIN_RETURN = 63;
static final int LINE_MAIN_PRINTF = 41;
/*
* Path to executable
*/
@ -197,7 +201,7 @@ public class MIRunControlTest extends BaseTestCase {
fRunCtrl.getExecutionContexts(containerDmc, rm);
}
});
wait.waitUntilDone(AsyncCompletionWaitor.WAIT_FOREVER);
wait.waitUntilDone(TestsPlugin.massageTimeout(5000));
Assert.assertTrue(wait.getMessage(), wait.isOK());
/*
@ -230,7 +234,7 @@ public class MIRunControlTest extends BaseTestCase {
* Testing for two execution DMC with id 1 & 2
*/
@Test
public void getExecutionContexts() throws InterruptedException{
public void getExecutionContexts() throws Throwable {
final AsyncCompletionWaitor wait = new AsyncCompletionWaitor();
/*
* Create a request monitor
@ -252,25 +256,18 @@ public class MIRunControlTest extends BaseTestCase {
getGDBLaunch().getSession(),
IStartedDMEvent.class);
try{
/*
* Run till line for 2 threads to be created
*/
SyncUtil.runToLine(fContainerDmc, SOURCE_NAME, "22", true);
}
catch(Throwable t){
Assert.fail("Exception in SyncUtil.SyncRunToLine: " + t.getMessage());
}
// Run past the line that creates a thread and past the sleep that
// follows it. This is a bit tricky because the code that creates the
// 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(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
// Make sure thread started event was received because it could arrive
// after the stopped event is received
IStartedDMEvent startedEvent = null;
try {
startedEvent = startedEventWaitor.waitForEvent(1000);
} catch (Exception e) {
Assert.fail("Timeout waiting for Thread create event");
return;
}
// Make sure thread started event was received
IStartedDMEvent startedEvent = startedEventWaitor.waitForEvent(TestsPlugin.massageTimeout(1000));
Assert.assertEquals("Thread created event is for wrong thread id", sProgramIsCygwin ? 3 : 2, ((IMIExecutionDMContext)startedEvent.getDMContext()).getThreadId());
@ -284,7 +281,7 @@ public class MIRunControlTest extends BaseTestCase {
fRunCtrl.getExecutionContexts(containerDmc, rmExecutionCtxts);
}
});
wait.waitUntilDone(AsyncCompletionWaitor.WAIT_FOREVER);
wait.waitUntilDone(TestsPlugin.massageTimeout(5000));
Assert.assertTrue(wait.getMessage(), wait.isOK());
wait.waitReset();
/*
@ -341,7 +338,7 @@ public class MIRunControlTest extends BaseTestCase {
fRunCtrl.getExecutionData(((MIRunControl)fRunCtrl).createMIExecutionContext(containerDmc, 1), rm);
}
});
wait.waitUntilDone(AsyncCompletionWaitor.WAIT_FOREVER);
wait.waitUntilDone(TestsPlugin.massageTimeout(5000));
Assert.assertTrue(wait.getMessage(), wait.isOK());
IRunControl.IExecutionDMData data = rm.getData();
@ -389,7 +386,7 @@ public class MIRunControlTest extends BaseTestCase {
fRunCtrl.getExecutionData(stoppedEvent.getDMContext(), rm);
}
});
wait.waitUntilDone(AsyncCompletionWaitor.WAIT_FOREVER);
wait.waitUntilDone(TestsPlugin.massageTimeout(5000));
Assert.assertTrue(wait.getMessage(), wait.isOK());
IRunControl.IExecutionDMData data = rm.getData();
@ -413,7 +410,7 @@ public class MIRunControlTest extends BaseTestCase {
/*
* Add a breakpoint
*/
SyncUtil.addBreakpoint(SOURCE_NAME + ":21", false);
SyncUtil.addBreakpoint(SOURCE_NAME + ":" + LINE_MAIN_PRINTF, false);
/*
* Resume till the breakpoint is hit
@ -435,7 +432,7 @@ public class MIRunControlTest extends BaseTestCase {
fRunCtrl.getExecutionData(stoppedEvent.getDMContext(), rm);
}
});
wait.waitUntilDone(AsyncCompletionWaitor.WAIT_FOREVER);
wait.waitUntilDone(TestsPlugin.massageTimeout(5000));
Assert.assertTrue(wait.getMessage(), wait.isOK());
IRunControl.IExecutionDMData data = rm.getData();
@ -481,7 +478,7 @@ public class MIRunControlTest extends BaseTestCase {
fRunCtrl.getExecutionData(fContainerDmc, rm);
}
});
wait.waitUntilDone(AsyncCompletionWaitor.WAIT_FOREVER);
wait.waitUntilDone(TestsPlugin.massageTimeout(5000));
Assert.assertTrue(wait.getMessage(), wait.isOK());
IRunControl.IExecutionDMData data = rm.getData();
@ -518,7 +515,7 @@ public class MIRunControlTest extends BaseTestCase {
fRunCtrl.getExecutionContexts(fContainerDmc, rm);
}
});
wait.waitUntilDone(AsyncCompletionWaitor.WAIT_FOREVER);
wait.waitUntilDone(TestsPlugin.massageTimeout(5000));
Assert.assertTrue(wait.getMessage(), !wait.isOK());
IStatus status = rm.getStatus();
@ -571,10 +568,10 @@ public class MIRunControlTest extends BaseTestCase {
fRunCtrl.resume(containerDmc, rm);
}
});
wait.waitUntilDone(AsyncCompletionWaitor.WAIT_FOREVER);
wait.waitUntilDone(TestsPlugin.massageTimeout(5000));
try {
eventWaitor.waitForEvent(ServiceEventWaitor.WAIT_FOREVER);
eventWaitor.waitForEvent(TestsPlugin.massageTimeout(5000));
} catch (Exception e) {
Assert.fail("Exception raised:: " + e.getMessage());
e.printStackTrace();
@ -591,7 +588,7 @@ public class MIRunControlTest extends BaseTestCase {
}
});
wait.waitUntilDone(AsyncCompletionWaitor.WAIT_FOREVER);
wait.waitUntilDone(TestsPlugin.massageTimeout(5000));
Assert.assertFalse("Target is suspended. It should have been running", (Boolean)wait.getReturnInfo());
wait.waitReset();
@ -619,9 +616,9 @@ public class MIRunControlTest extends BaseTestCase {
fRunCtrl.resume(fContainerDmc, rm);
}
});
wait.waitUntilDone(AsyncCompletionWaitor.WAIT_FOREVER);
wait.waitUntilDone(TestsPlugin.massageTimeout(5000));
try {
eventWaitor.waitForEvent(ServiceEventWaitor.WAIT_FOREVER);
eventWaitor.waitForEvent(TestsPlugin.massageTimeout(5000));
//TestsPlugin.debug("DsfMIRunningEvent received");
} catch (Exception e) {
Assert.fail("Exception raised:: " + e.getMessage());
@ -642,20 +639,24 @@ public class MIRunControlTest extends BaseTestCase {
}
});
wait.waitUntilDone(AsyncCompletionWaitor.WAIT_FOREVER);
wait.waitUntilDone(TestsPlugin.massageTimeout(5000));
Assert.assertFalse("Target is suspended. It should have been running", (Boolean)wait.getReturnInfo());
wait.waitReset();
}
@Test
public void runToLine() throws InterruptedException{
public void runToLine() throws Throwable {
final AsyncCompletionWaitor wait = new AsyncCompletionWaitor();
ServiceEventWaitor<ISuspendedDMEvent> suspendedEventWaitor = new ServiceEventWaitor<ISuspendedDMEvent>(
getGDBLaunch().getSession(),
ISuspendedDMEvent.class);
fRunCtrl.getExecutor().submit(new Runnable() {
public void run() {
fRunCtrl.runToLine(fThreadExecDmc, SOURCE_NAME, 27, true,
fRunCtrl.runToLine(fThreadExecDmc, SOURCE_NAME, LINE_MAIN_RETURN, true,
new RequestMonitor(fRunCtrl.getExecutor(), null) {
@Override
protected void handleCompleted() {
@ -664,19 +665,14 @@ public class MIRunControlTest extends BaseTestCase {
});
}
});
wait.waitUntilDone(AsyncCompletionWaitor.WAIT_FOREVER);
// The program takes five seconds to run. There's five iterations of a
// loop that has a one second sleep in it
wait.waitUntilDone(TestsPlugin.massageTimeout(10000));
Assert.assertTrue(wait.getMessage(), wait.isOK());
wait.waitReset();
try {
new ServiceEventWaitor<ISuspendedDMEvent>(
getGDBLaunch().getSession(),
ISuspendedDMEvent.class).waitForEvent(ServiceEventWaitor.WAIT_FOREVER);
} catch (Exception e) {
Assert.fail("Exception raised:: " + e.getMessage());
e.printStackTrace();
return;
}
suspendedEventWaitor.waitForEvent(TestsPlugin.massageTimeout(000));
final IContainerDMContext containerDmc = SyncUtil.getContainerContext();
@ -687,7 +683,7 @@ public class MIRunControlTest extends BaseTestCase {
}
});
wait.waitUntilDone(AsyncCompletionWaitor.WAIT_FOREVER);
wait.waitUntilDone(TestsPlugin.massageTimeout(5000));
Assert.assertTrue("Target is running. It should have been suspended", (Boolean)wait.getReturnInfo());
wait.waitReset();