diff --git a/dsf-gdb/org.eclipse.cdt.tests.dsf.gdb/data/launch/src/LaunchConfigurationAndRestartTestApp.cc b/dsf-gdb/org.eclipse.cdt.tests.dsf.gdb/data/launch/src/LaunchConfigurationAndRestartTestApp.cc index 7fd0a799ec6..f697b269e74 100644 --- a/dsf-gdb/org.eclipse.cdt.tests.dsf.gdb/data/launch/src/LaunchConfigurationAndRestartTestApp.cc +++ b/dsf-gdb/org.eclipse.cdt.tests.dsf.gdb/data/launch/src/LaunchConfigurationAndRestartTestApp.cc @@ -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 } diff --git a/dsf-gdb/org.eclipse.cdt.tests.dsf.gdb/src/org/eclipse/cdt/tests/dsf/gdb/launching/TestLaunchDelegate.java b/dsf-gdb/org.eclipse.cdt.tests.dsf.gdb/src/org/eclipse/cdt/tests/dsf/gdb/launching/TestLaunchDelegate.java index 9e282f2f380..fcc984254d9 100644 --- a/dsf-gdb/org.eclipse.cdt.tests.dsf.gdb/src/org/eclipse/cdt/tests/dsf/gdb/launching/TestLaunchDelegate.java +++ b/dsf-gdb/org.eclipse.cdt.tests.dsf.gdb/src/org/eclipse/cdt/tests/dsf/gdb/launching/TestLaunchDelegate.java @@ -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 diff --git a/dsf-gdb/org.eclipse.cdt.tests.dsf.gdb/src/org/eclipse/cdt/tests/dsf/gdb/tests/LaunchConfigurationAndRestartTest.java b/dsf-gdb/org.eclipse.cdt.tests.dsf.gdb/src/org/eclipse/cdt/tests/dsf/gdb/tests/LaunchConfigurationAndRestartTest.java index 7ca322b44e2..b2fffb68a5c 100644 --- a/dsf-gdb/org.eclipse.cdt.tests.dsf.gdb/src/org/eclipse/cdt/tests/dsf/gdb/tests/LaunchConfigurationAndRestartTest.java +++ b/dsf-gdb/org.eclipse.cdt.tests.dsf.gdb/src/org/eclipse/cdt/tests/dsf/gdb/tests/LaunchConfigurationAndRestartTest.java @@ -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 shutdownEventWaitor = new ServiceEventWaitor( + 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; + } } diff --git a/dsf-gdb/org.eclipse.cdt.tests.dsf.gdb/src/org/eclipse/cdt/tests/dsf/gdb/tests/tests_6_6/LaunchConfigurationAndRestartTest_6_6.java b/dsf-gdb/org.eclipse.cdt.tests.dsf.gdb/src/org/eclipse/cdt/tests/dsf/gdb/tests/tests_6_6/LaunchConfigurationAndRestartTest_6_6.java index 678bd2cf6e0..1926199ef3a 100644 --- a/dsf-gdb/org.eclipse.cdt.tests.dsf.gdb/src/org/eclipse/cdt/tests/dsf/gdb/tests/tests_6_6/LaunchConfigurationAndRestartTest_6_6.java +++ b/dsf-gdb/org.eclipse.cdt.tests.dsf.gdb/src/org/eclipse/cdt/tests/dsf/gdb/tests/tests_6_6/LaunchConfigurationAndRestartTest_6_6.java @@ -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(); + } } diff --git a/dsf-gdb/org.eclipse.cdt.tests.dsf.gdb/src/org/eclipse/cdt/tests/dsf/gdb/tests/tests_7_3/LaunchConfigurationAndRestartTest_7_3.java b/dsf-gdb/org.eclipse.cdt.tests.dsf.gdb/src/org/eclipse/cdt/tests/dsf/gdb/tests/tests_7_3/LaunchConfigurationAndRestartTest_7_3.java index 794b0c3e4a3..2c0b26e0f1c 100644 --- a/dsf-gdb/org.eclipse.cdt.tests.dsf.gdb/src/org/eclipse/cdt/tests/dsf/gdb/tests/tests_7_3/LaunchConfigurationAndRestartTest_7_3.java +++ b/dsf-gdb/org.eclipse.cdt.tests.dsf.gdb/src/org/eclipse/cdt/tests/dsf/gdb/tests/tests_7_3/LaunchConfigurationAndRestartTest_7_3.java @@ -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(); + } }