1
0
Fork 0
mirror of https://github.com/eclipse-cdt/cdt synced 2025-08-03 06:15:37 +02:00

Bug 572581: fix terminating launches at end of test

this fixes cases where a single test failing does not clean up
properly causing subsequent tests to then fail.

Change-Id: I4bd9c08e5ce1a4cd2ccd5e710a446e6e96c4d353
This commit is contained in:
Jonah Graham 2021-04-09 10:19:52 -04:00
parent 6c2fc2d927
commit e701b76d87
24 changed files with 49 additions and 45 deletions

View file

@ -18,7 +18,6 @@ package org.eclipse.cdt.tests.dsf.gdb.framework;
import static org.junit.Assert.assertEquals;
import static org.junit.Assert.assertNotNull;
import static org.junit.Assert.assertTrue;
import static org.junit.Assert.fail;
import java.io.BufferedReader;
import java.io.FileReader;
@ -321,12 +320,12 @@ public class BaseTestCase {
* Make sure we are starting with a clean/known state. That means no
* existing launches.
*/
public void removeTeminatedLaunchesBeforeTest() throws CoreException {
public void teminateAndRemoveLaunches() throws Exception {
ILaunchManager launchManager = DebugPlugin.getDefault().getLaunchManager();
ILaunch[] launches = launchManager.getLaunches();
for (ILaunch launch : launches) {
if (!launch.isTerminated()) {
fail("Something has gone wrong, there is an unterminated launch from a previous test!");
assertLaunchTerminates((GdbLaunch) launch, true);
}
}
if (launches.length > 0) {
@ -354,7 +353,7 @@ public class BaseTestCase {
@Before
public void doBeforeTest() throws Exception {
removeTeminatedLaunchesBeforeTest();
teminateAndRemoveLaunches();
removeAllPlatformBreakpoints();
setLaunchAttributes();
doLaunch();
@ -602,11 +601,26 @@ public class BaseTestCase {
assertLaunchTerminates(launch);
}
protected void assertLaunchTerminates(GdbLaunch launch) throws InterruptedException {
/**
* Assert that the launch terminates, optionally requesting this method to terminate unterminated launch.
*/
protected void assertLaunchTerminates(boolean terminate) throws Exception {
GdbLaunch launch = fLaunch;
assertLaunchTerminates(launch, terminate);
}
protected void assertLaunchTerminates(GdbLaunch launch) throws Exception {
assertLaunchTerminates(launch, false);
}
protected void assertLaunchTerminates(GdbLaunch launch, boolean terminate) throws Exception {
if (launch != null) {
// Give a few seconds to allow the launch to terminate
int waitCount = 100;
while (!launch.isTerminated() && !launch.getDsfExecutor().isShutdown() && --waitCount > 0) {
if (terminate) {
launch.terminate();
}
Thread.sleep(TestsPlugin.massageTimeout(100));
}
assertTrue("Launch failed to terminate before timeout", launch.isTerminated());
@ -621,6 +635,7 @@ public class BaseTestCase {
fLaunch = null;
}
removeAllPlatformBreakpoints();
teminateAndRemoveLaunches();
}
/**

View file

@ -57,7 +57,7 @@ public class CommandLineArgsTest extends BaseParametrizedTestCase {
@Override
public void doBeforeTest() throws Exception {
assumeLocalSession();
removeTeminatedLaunchesBeforeTest();
teminateAndRemoveLaunches();
setLaunchAttributes();
// Can't run the launch right away because each test needs to first set
// ICDTLaunchConfigurationConstants.ATTR_PROGRAM_ARGUMENTS

View file

@ -61,7 +61,7 @@ public class CommandTimeoutTest extends BaseParametrizedTestCase {
@Override
public void doBeforeTest() throws Exception {
removeTeminatedLaunchesBeforeTest();
teminateAndRemoveLaunches();
setLaunchAttributes();
// Can't run the launch right away because each test needs to first set some
// parameters. The individual tests will be responsible for starting the launch.

View file

@ -92,12 +92,12 @@ public class GDBPatternMatchingExpressionsTest extends BaseParametrizedTestCase
@Override
public void doAfterTest() throws Exception {
super.doAfterTest();
fExpService = null;
if (fServicesTracker != null) {
fServicesTracker.dispose();
fServicesTracker = null;
}
super.doAfterTest();
}
//**************************************************************************************

View file

@ -69,11 +69,10 @@ public class GDBProcessesTest extends BaseParametrizedTestCase {
@Override
public void doAfterTest() throws Exception {
super.doAfterTest();
fProcService = null;
if (fServicesTracker != null)
fServicesTracker.dispose();
super.doAfterTest();
}
@Override

View file

@ -205,13 +205,13 @@ public class GDBRemoteTracepointsTest extends BaseParametrizedTestCase {
@Override
public void doAfterTest() throws Exception {
super.doAfterTest();
if (fSession != null)
fSession.getExecutor().submit(() -> fSession.removeServiceEventListener(GDBRemoteTracepointsTest.this))
.get();
fBreakpointService = null;
if (fServicesTracker != null)
fServicesTracker.dispose();
super.doAfterTest();
}
// *********************************************************************

View file

@ -92,7 +92,7 @@ public class LaunchConfigurationAndRestartTest extends BaseParametrizedTestCase
@Override
public void doBeforeTest() throws Exception {
assumeLocalSession();
removeTeminatedLaunchesBeforeTest();
teminateAndRemoveLaunches();
setLaunchAttributes();
// Can't run the launch right away because each test needs to first set some
// parameters. The individual tests will be responsible for starting the launch.
@ -142,10 +142,9 @@ public class LaunchConfigurationAndRestartTest extends BaseParametrizedTestCase
@Override
public void doAfterTest() throws Exception {
super.doAfterTest();
if (fServicesTracker != null)
fServicesTracker.dispose();
super.doAfterTest();
}
// *********************************************************************

View file

@ -220,7 +220,6 @@ public class MIBreakpointsTest extends BaseParametrizedTestCase {
@Override
public void doAfterTest() throws Exception {
super.doAfterTest();
// cleanup cannot assume sane state since it runs even test is failed or skipped
if (fSession != null) {
// Clear the references (not strictly necessary)
@ -233,6 +232,7 @@ public class MIBreakpointsTest extends BaseParametrizedTestCase {
fServicesTracker.dispose();
fServicesTracker = null;
clearEventCounters();
super.doAfterTest();
}
// ========================================================================
// Event Management Functions

View file

@ -196,7 +196,6 @@ public class MICatchpointsTest extends BaseParametrizedTestCase {
@Override
public void doAfterTest() throws Exception {
super.doAfterTest();
if (fSession != null) {
Runnable runnable = () -> fRunControl.getSession().removeServiceEventListener(MICatchpointsTest.this);
fSession.getExecutor().submit(runnable).get();
@ -208,6 +207,7 @@ public class MICatchpointsTest extends BaseParametrizedTestCase {
fServicesTracker.dispose();
fServicesTracker = null;
clearEventCounters();
super.doAfterTest();
}
// ========================================================================

View file

@ -120,14 +120,13 @@ public class MIDisassemblyTest extends BaseParametrizedTestCase {
@Override
public void doAfterTest() throws Exception {
super.doAfterTest();
fExpressionService = null;
fDisassembly = null;
if (fServicesTracker != null) {
fServicesTracker.dispose();
fServicesTracker = null;
}
super.doAfterTest();
}
// ========================================================================

View file

@ -112,7 +112,6 @@ public class MIExpressionsTest extends BaseParametrizedTestCase {
@Override
public void doAfterTest() throws Exception {
super.doAfterTest();
if (fSession != null) {
fSession.getExecutor().submit(() -> fSession.removeServiceEventListener(MIExpressionsTest.this)).get();
}
@ -120,6 +119,7 @@ public class MIExpressionsTest extends BaseParametrizedTestCase {
if (fServicesTracker != null) {
fServicesTracker.dispose();
}
super.doAfterTest();
}
@Override

View file

@ -138,7 +138,6 @@ public class MIMemoryTest extends BaseParametrizedTestCase {
@Override
public void doAfterTest() throws Exception {
super.doAfterTest();
// Clear the references (not strictly necessary)
if (fSession != null)
fSession.getExecutor().submit(() -> fSession.removeServiceEventListener(MIMemoryTest.this)).get();
@ -150,6 +149,7 @@ public class MIMemoryTest extends BaseParametrizedTestCase {
fServicesTracker.dispose();
fServicesTracker = null;
clearEventCounters();
super.doAfterTest();
}
// ========================================================================

View file

@ -104,7 +104,7 @@ public class MIModifiedServicesTest extends BaseParametrizedTestCase {
@Override
public void doBeforeTest() throws Exception {
removeTeminatedLaunchesBeforeTest();
teminateAndRemoveLaunches();
setLaunchAttributes();
// Can't run the launch right away because each test needs to first set some

View file

@ -133,11 +133,10 @@ public class MIRegistersTest extends BaseParametrizedTestCase {
@Override
public void doAfterTest() throws Exception {
super.doAfterTest();
if (fServicesTracker != null)
fServicesTracker.dispose();
fRegService = null;
super.doAfterTest();
}
/*

View file

@ -76,11 +76,10 @@ public class MIRunControlReverseTest extends BaseParametrizedTestCase {
@Override
public void doAfterTest() throws Exception {
super.doAfterTest();
if (fServicesTracker != null) {
fServicesTracker.dispose();
}
super.doAfterTest();
}
@Override

View file

@ -78,10 +78,9 @@ public class MIRunControlTargetAvailableTest extends BaseParametrizedTestCase {
@Override
public void doAfterTest() throws Exception {
super.doAfterTest();
if (fServicesTracker != null)
fServicesTracker.dispose();
super.doAfterTest();
}
@Override

View file

@ -128,10 +128,9 @@ public class MIRunControlTest extends BaseParametrizedTestCase {
@Override
public void doAfterTest() throws Exception {
super.doAfterTest();
if (fServicesTracker != null)
fServicesTracker.dispose();
super.doAfterTest();
}
@Override

View file

@ -87,14 +87,13 @@ public class OperationsWhileTargetIsRunningTest extends BaseParametrizedTestCase
@Override
public void doAfterTest() throws Exception {
super.doAfterTest();
if (fServicesTracker != null)
fServicesTracker.dispose();
// Restore the different preferences we might have changed
IEclipsePreferences node = InstanceScope.INSTANCE.getNode(GdbPlugin.PLUGIN_ID);
node.putBoolean(IGdbDebugPreferenceConstants.PREF_AUTO_TERMINATE_GDB, fgAutoTerminate);
super.doAfterTest();
}
@Override

View file

@ -74,7 +74,7 @@ public class PostMortemCoreTest extends BaseParametrizedTestCase {
@Override
public void doBeforeTest() throws Exception {
assumeLocalSession();
removeTeminatedLaunchesBeforeTest();
teminateAndRemoveLaunches();
setLaunchAttributes();
// Can't run the launch right away because each test needs to first set some
// parameters. The individual tests will be responsible for starting the launch.
@ -124,8 +124,6 @@ public class PostMortemCoreTest extends BaseParametrizedTestCase {
@Override
public void doAfterTest() throws Exception {
super.doAfterTest();
if (fSession != null) {
fSession.getExecutor().submit(() -> fSession.removeServiceEventListener(PostMortemCoreTest.this)).get();
}
@ -133,6 +131,8 @@ public class PostMortemCoreTest extends BaseParametrizedTestCase {
fExpService = null;
if (fServicesTracker != null)
fServicesTracker.dispose();
super.doAfterTest();
}
/**

View file

@ -215,7 +215,7 @@ public class SourceLookupTest extends BaseParametrizedTestCase {
@Override
public void doBeforeTest() throws Exception {
removeTeminatedLaunchesBeforeTest();
teminateAndRemoveLaunches();
IBreakpointManager manager = DebugPlugin.getDefault().getBreakpointManager();
manager.addBreakpointListener(fBreakpointListener);
setExeNames();
@ -229,11 +229,10 @@ public class SourceLookupTest extends BaseParametrizedTestCase {
*/
@Override
public void doAfterTest() throws Exception {
super.doAfterTest();
removeAllPlatformBreakpoints();
IBreakpointManager manager = DebugPlugin.getDefault().getBreakpointManager();
manager.removeBreakpointListener(fBreakpointListener);
super.doAfterTest();
}
protected void doLaunch(String programName) throws Exception {
@ -912,7 +911,7 @@ public class SourceLookupTest extends BaseParametrizedTestCase {
sourceFinderMappingAC_ActiveLaunchHelper(withBackend);
// Terminate the launch, but don't remove it
doAfterTest();
assertLaunchTerminates(true);
assertFinderFinds(EXEC_AC_NAME, new File(SOURCE_PATH, SOURCE_NAME).getAbsolutePath());
}

View file

@ -125,10 +125,9 @@ public class StepIntoSelectionTest extends BaseParametrizedTestCase {
@Override
public void doAfterTest() throws Exception {
super.doAfterTest();
if (fServicesTracker != null)
fServicesTracker.dispose();
super.doAfterTest();
}
@Override

View file

@ -93,7 +93,7 @@ public class TraceFileTest extends BaseParametrizedTestCase {
assumeRemoteSession();
resolveLineTagLocations(SOURCE_NAME, LINE_TAGS);
assumeGdbVersionAtLeast(ITestConstants.SUFFIX_GDB_7_4);
removeTeminatedLaunchesBeforeTest();
teminateAndRemoveLaunches();
// Suppress settings of the launch attributes and launching.
// Each test sets its own launch attributes
}
@ -125,7 +125,6 @@ public class TraceFileTest extends BaseParametrizedTestCase {
@Override
@After
public void doAfterTest() throws Exception {
super.doAfterTest();
fBreakpointService = null;
fTraceService = null;
fBreakpointsDmc = null;
@ -134,6 +133,7 @@ public class TraceFileTest extends BaseParametrizedTestCase {
fServicesTracker.dispose();
fServicesTracker = null;
}
super.doAfterTest();
}
/**

View file

@ -90,10 +90,9 @@ public class GDBMultiNonStopRunControlTest extends BaseParametrizedTestCase {
@Override
public void doAfterTest() throws Exception {
super.doAfterTest();
if (fServicesTracker != null)
fServicesTracker.dispose();
super.doAfterTest();
}
private abstract class AsyncRunnable<V> {

View file

@ -126,9 +126,9 @@ public class ThreadStackFrameSyncTest extends BaseParametrizedTestCase {
@Override
public void doAfterTest() throws Exception {
super.doAfterTest();
if (fServicesTracker != null)
fServicesTracker.dispose();
super.doAfterTest();
}
//////////////////////////////////////////////////////////////////////////////////////