mirror of
https://github.com/eclipse-cdt/cdt
synced 2025-04-22 14:12:10 +02:00
Add Inferior exit code test
Simple test to verify that the exit code of a process is properly set for the console to read. Change-Id: Ib7dca7a86732ad119dd57bb2681120d4a6222e5c
This commit is contained in:
parent
c28c12b353
commit
79e0972413
5 changed files with 77 additions and 5 deletions
|
@ -27,6 +27,8 @@ int main (int argc, char *argv[])
|
|||
envTest();
|
||||
reverseTest();
|
||||
stopAtOther();
|
||||
return 0;
|
||||
return 36;
|
||||
// Return special value to allow
|
||||
// testing exit code feature
|
||||
}
|
||||
|
||||
|
|
|
@ -1,5 +1,5 @@
|
|||
/*******************************************************************************
|
||||
* Copyright (c) 2004, 2011 QNX Software Systems and others.
|
||||
* Copyright (c) 2004, 2015 QNX Software Systems and others.
|
||||
* All rights reserved. This program and the accompanying materials
|
||||
* are made available under the terms of the Eclipse Public License v1.0
|
||||
* which accompanies this distribution, and is available at
|
||||
|
@ -43,7 +43,9 @@ public class TestLaunchDelegate extends GdbLaunchDelegate
|
|||
|
||||
@Override
|
||||
public boolean preLaunchCheck(ILaunchConfiguration config, String mode, IProgressMonitor monitor) throws CoreException {
|
||||
return true;
|
||||
// Don't override the base method to allow it to set the GdbProcessFactory
|
||||
// which LaunchConfigurationAndRestartTest.testExitCodeSet() depends on
|
||||
return super.preLaunchCheck(config, mode, monitor);
|
||||
}
|
||||
|
||||
@Override
|
||||
|
|
|
@ -12,6 +12,9 @@
|
|||
*******************************************************************************/
|
||||
package org.eclipse.cdt.tests.dsf.gdb.tests;
|
||||
|
||||
import static org.hamcrest.CoreMatchers.is;
|
||||
import static org.hamcrest.CoreMatchers.notNullValue;
|
||||
import static org.hamcrest.MatcherAssert.assertThat;
|
||||
import static org.junit.Assert.assertFalse;
|
||||
import static org.junit.Assert.assertTrue;
|
||||
import static org.junit.Assert.fail;
|
||||
|
@ -32,7 +35,10 @@ import org.eclipse.cdt.dsf.debug.service.IExpressions;
|
|||
import org.eclipse.cdt.dsf.debug.service.IExpressions.IExpressionDMContext;
|
||||
import org.eclipse.cdt.dsf.debug.service.IFormattedValues.FormattedValueDMData;
|
||||
import org.eclipse.cdt.dsf.debug.service.IRunControl.StepType;
|
||||
import org.eclipse.cdt.dsf.debug.service.command.ICommandControlService.ICommandControlShutdownDMEvent;
|
||||
import org.eclipse.cdt.dsf.gdb.IGDBLaunchConfigurationConstants;
|
||||
import org.eclipse.cdt.dsf.gdb.IGdbDebugConstants;
|
||||
import org.eclipse.cdt.dsf.gdb.launching.InferiorRuntimeProcess;
|
||||
import org.eclipse.cdt.dsf.gdb.service.command.IGDBControl;
|
||||
import org.eclipse.cdt.dsf.mi.service.MIExpressions;
|
||||
import org.eclipse.cdt.dsf.mi.service.command.events.MIStoppedEvent;
|
||||
|
@ -41,11 +47,13 @@ import org.eclipse.cdt.dsf.service.DsfServicesTracker;
|
|||
import org.eclipse.cdt.dsf.service.DsfSession;
|
||||
import org.eclipse.cdt.tests.dsf.gdb.framework.BackgroundRunner;
|
||||
import org.eclipse.cdt.tests.dsf.gdb.framework.BaseTestCase;
|
||||
import org.eclipse.cdt.tests.dsf.gdb.framework.ServiceEventWaitor;
|
||||
import org.eclipse.cdt.tests.dsf.gdb.framework.SyncUtil;
|
||||
import org.eclipse.cdt.tests.dsf.gdb.launching.TestsPlugin;
|
||||
import org.eclipse.core.resources.IFile;
|
||||
import org.eclipse.core.runtime.CoreException;
|
||||
import org.eclipse.debug.core.ILaunchManager;
|
||||
import org.eclipse.debug.core.model.IProcess;
|
||||
import org.junit.Ignore;
|
||||
import org.junit.Test;
|
||||
import org.junit.runner.RunWith;
|
||||
|
@ -56,6 +64,8 @@ public class LaunchConfigurationAndRestartTest extends BaseTestCase {
|
|||
|
||||
protected static final int FIRST_LINE_IN_MAIN = 27;
|
||||
protected static final int LAST_LINE_IN_MAIN = 30;
|
||||
// The exit code returned by the test program
|
||||
private static final int TEST_EXIT_CODE = 36;
|
||||
|
||||
protected DsfSession fSession;
|
||||
protected DsfServicesTracker fServicesTracker;
|
||||
|
@ -727,5 +737,46 @@ public class LaunchConfigurationAndRestartTest extends BaseTestCase {
|
|||
testNoStopAtMain();
|
||||
}
|
||||
|
||||
/**
|
||||
* Test that the exit code is available after the inferior as run to
|
||||
* completion so that the console can use it.
|
||||
*/
|
||||
@Test
|
||||
public void testExitCodeSet() throws Throwable {
|
||||
doLaunch();
|
||||
|
||||
ServiceEventWaitor<ICommandControlShutdownDMEvent> shutdownEventWaitor = new ServiceEventWaitor<ICommandControlShutdownDMEvent>(
|
||||
getGDBLaunch().getSession(),
|
||||
ICommandControlShutdownDMEvent.class);
|
||||
|
||||
// The target is currently stopped. We resume to get it running
|
||||
// and wait for a shutdown event to say execution has completed
|
||||
SyncUtil.resume();
|
||||
|
||||
shutdownEventWaitor.waitForEvent(TestsPlugin.massageTimeout(1000));
|
||||
|
||||
|
||||
IProcess[] launchProcesses = getGDBLaunch().getProcesses();;
|
||||
for (IProcess proc : launchProcesses) {
|
||||
if (proc instanceof InferiorRuntimeProcess) {
|
||||
assertThat(proc.getAttribute(IGdbDebugConstants.INFERIOR_EXITED_ATTR), is(notNullValue()));
|
||||
|
||||
// Wait for the process to terminate so we can obtain its exit code
|
||||
int count = 0;
|
||||
while (count++ < 100 && !proc.isTerminated()) {
|
||||
try {
|
||||
synchronized (proc) {
|
||||
proc.wait(10);
|
||||
}
|
||||
} catch (InterruptedException ie) {
|
||||
}
|
||||
}
|
||||
|
||||
int exitValue = proc.getExitValue();
|
||||
assertThat(exitValue, is(TEST_EXIT_CODE));
|
||||
return;
|
||||
}
|
||||
}
|
||||
assert false;
|
||||
}
|
||||
}
|
||||
|
|
|
@ -1,5 +1,5 @@
|
|||
/*******************************************************************************
|
||||
* Copyright (c) 2011, 2012 Ericsson and others.
|
||||
* Copyright (c) 2011, 2015 Ericsson and others.
|
||||
* All rights reserved. This program and the accompanying materials
|
||||
* are made available under the terms of the Eclipse Public License v1.0
|
||||
* which accompanies this distribution, and is available at
|
||||
|
@ -13,6 +13,8 @@ package org.eclipse.cdt.tests.dsf.gdb.tests.tests_6_6;
|
|||
import org.eclipse.cdt.tests.dsf.gdb.framework.BackgroundRunner;
|
||||
import org.eclipse.cdt.tests.dsf.gdb.tests.ITestConstants;
|
||||
import org.eclipse.cdt.tests.dsf.gdb.tests.LaunchConfigurationAndRestartTest;
|
||||
import org.junit.Ignore;
|
||||
import org.junit.Test;
|
||||
import org.junit.runner.RunWith;
|
||||
|
||||
@RunWith(BackgroundRunner.class)
|
||||
|
@ -21,4 +23,11 @@ public class LaunchConfigurationAndRestartTest_6_6 extends LaunchConfigurationAn
|
|||
protected void setGdbVersion() {
|
||||
setGdbProgramNamesLaunchAttributes(ITestConstants.SUFFIX_GDB_6_6);
|
||||
}
|
||||
|
||||
@Override
|
||||
@Ignore("Not supported before GDB 7.3")
|
||||
@Test
|
||||
public void testExitCodeSet() throws Throwable {
|
||||
super.testExitCodeSet();
|
||||
}
|
||||
}
|
||||
|
|
|
@ -1,5 +1,5 @@
|
|||
/*******************************************************************************
|
||||
* Copyright (c) 2011, 2012 Ericsson and others.
|
||||
* Copyright (c) 2011, 2015 Ericsson and others.
|
||||
* All rights reserved. This program and the accompanying materials
|
||||
* are made available under the terms of the Eclipse Public License v1.0
|
||||
* which accompanies this distribution, and is available at
|
||||
|
@ -13,6 +13,7 @@ package org.eclipse.cdt.tests.dsf.gdb.tests.tests_7_3;
|
|||
import org.eclipse.cdt.tests.dsf.gdb.framework.BackgroundRunner;
|
||||
import org.eclipse.cdt.tests.dsf.gdb.tests.ITestConstants;
|
||||
import org.eclipse.cdt.tests.dsf.gdb.tests.tests_7_2.LaunchConfigurationAndRestartTest_7_2;
|
||||
import org.junit.Test;
|
||||
import org.junit.runner.RunWith;
|
||||
|
||||
@RunWith(BackgroundRunner.class)
|
||||
|
@ -21,4 +22,11 @@ public class LaunchConfigurationAndRestartTest_7_3 extends LaunchConfigurationAn
|
|||
protected void setGdbVersion() {
|
||||
setGdbProgramNamesLaunchAttributes(ITestConstants.SUFFIX_GDB_7_3);
|
||||
}
|
||||
|
||||
// Enabled starting with GDB 7.3
|
||||
@Override
|
||||
@Test
|
||||
public void testExitCodeSet() throws Throwable {
|
||||
super.testExitCodeSet();
|
||||
}
|
||||
}
|
||||
|
|
Loading…
Add table
Reference in a new issue