mirror of
https://github.com/eclipse-cdt/cdt
synced 2025-07-31 21:05:37 +02:00
Validate GDB version in debug tests
Change-Id: Ic8f0b7494a19d20630536dd992ed035f52f0f3e7
This commit is contained in:
parent
f187157456
commit
78c9a0bb5e
2 changed files with 54 additions and 3 deletions
|
@ -10,6 +10,9 @@
|
|||
*******************************************************************************/
|
||||
package org.eclipse.cdt.tests.dsf.gdb.framework;
|
||||
|
||||
import static org.junit.Assert.assertTrue;
|
||||
import static org.junit.Assert.fail;
|
||||
|
||||
import java.util.Arrays;
|
||||
import java.util.Collection;
|
||||
import java.util.Collections;
|
||||
|
@ -17,8 +20,10 @@ import java.util.List;
|
|||
|
||||
import org.eclipse.cdt.debug.core.ICDTLaunchConfigurationConstants;
|
||||
import org.eclipse.cdt.dsf.gdb.IGDBLaunchConfigurationConstants;
|
||||
import org.eclipse.cdt.dsf.gdb.launching.GdbLaunch;
|
||||
import org.eclipse.cdt.dsf.gdb.launching.LaunchUtils;
|
||||
import org.eclipse.cdt.tests.dsf.gdb.tests.ITestConstants;
|
||||
import org.eclipse.core.runtime.CoreException;
|
||||
import org.junit.Assume;
|
||||
import org.junit.runner.RunWith;
|
||||
import org.junit.runners.Parameterized;
|
||||
|
@ -78,7 +83,7 @@ public abstract class BaseParametrizedTestCase extends BaseTestCase {
|
|||
gdbVersionPostfix = parameter;
|
||||
}
|
||||
if (gdbVersionPostfix.isEmpty())
|
||||
gdbVersionPostfix = "default";
|
||||
gdbVersionPostfix = DEFAULT_VERSION_STRING;
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -129,7 +134,7 @@ public abstract class BaseParametrizedTestCase extends BaseTestCase {
|
|||
// fail assumption
|
||||
Assume.assumeFalse("GDB cannot be run " + gdbPath, true);
|
||||
}
|
||||
if (checkVersion == null || checkVersion.isEmpty() || checkVersion.equals("default"))
|
||||
if (checkVersion == null || checkVersion.isEmpty() || checkVersion.equals(DEFAULT_VERSION_STRING))
|
||||
return; // no version restrictions
|
||||
if (checkVersion.equals(gdbVersion))
|
||||
return;
|
||||
|
@ -155,4 +160,34 @@ public abstract class BaseParametrizedTestCase extends BaseTestCase {
|
|||
setLaunchAttribute(ICDTLaunchConfigurationConstants.ATTR_DEBUGGER_START_MODE,
|
||||
IGDBLaunchConfigurationConstants.DEBUGGER_MODE_REMOTE);
|
||||
}
|
||||
|
||||
@Override
|
||||
protected void validateGdbVersion(GdbLaunch launch) {
|
||||
try {
|
||||
String expected = getGdbVersionParameter();
|
||||
if (expected.equals(DEFAULT_VERSION_STRING)) {
|
||||
// If the user has requested the default GDB, we accept whatever version runs.
|
||||
return;
|
||||
}
|
||||
|
||||
String actual = launch.getGDBVersion();
|
||||
|
||||
String[] expectedParts = expected.split("\\."); //$NON-NLS-1$
|
||||
String[] actualParts = actual.split("\\."); //$NON-NLS-1$
|
||||
|
||||
String comparableActualString = actual;
|
||||
if (expectedParts.length == 2 // If the expected version does not care about the maintenance number
|
||||
&& actualParts.length == 3) { // and the actual version has a maintenance number
|
||||
// We should ignore the maintenance number.
|
||||
// For example, if we expect 7.12, then the actual
|
||||
// version we should accept can be 7.12 or 7.12.1 or 7.12.2, etc.
|
||||
comparableActualString = actual.substring(0, actual.lastIndexOf('.'));
|
||||
}
|
||||
|
||||
assertTrue("Unexpected GDB version. Expected " + expected + " actual " + actual,
|
||||
LaunchUtils.compareVersions(expected, comparableActualString) == 0);
|
||||
} catch (CoreException e) {
|
||||
fail(e.getMessage());
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
|
@ -80,6 +80,12 @@ import org.junit.rules.Timeout;
|
|||
*/
|
||||
@SuppressWarnings("restriction")
|
||||
public class BaseTestCase {
|
||||
/**
|
||||
* When used, the tests will use a GDB called 'gdb'. This uses
|
||||
* whatever GDB is installed on the machine where the tests are run.
|
||||
*/
|
||||
public final static String DEFAULT_VERSION_STRING = "default";
|
||||
|
||||
/*
|
||||
* Path to executable
|
||||
*/
|
||||
|
@ -168,6 +174,14 @@ public class BaseTestCase {
|
|||
.equals(IGDBLaunchConfigurationConstants.DEBUGGER_MODE_REMOTE);
|
||||
}
|
||||
|
||||
/**
|
||||
* Validate that the gdb version launched is the one that was targeted.
|
||||
* Will fail the test if the versions don't match.
|
||||
*
|
||||
* @param launch The launch in which we can find the gdb version
|
||||
*/
|
||||
protected void validateGdbVersion(GdbLaunch launch) {};
|
||||
|
||||
/**
|
||||
* We listen for the target to stop at the main breakpoint. This listener is
|
||||
* installed when the session is created and we uninstall ourselves when we
|
||||
|
@ -441,6 +455,8 @@ public class BaseTestCase {
|
|||
fLaunchConfiguration = lcWorkingCopy.doSave();
|
||||
fLaunch = doLaunchInner();
|
||||
|
||||
validateGdbVersion(fLaunch);
|
||||
|
||||
// If we started a gdbserver add it to the launch to make sure it is killed at the end
|
||||
if (gdbserverProc != null) {
|
||||
DebugPlugin.newProcess(fLaunch, gdbserverProc, "gdbserver");
|
||||
|
@ -623,7 +639,7 @@ public class BaseTestCase {
|
|||
boolean isWindows = runningOnWindows();
|
||||
String gdbPath = System.getProperty("cdt.tests.dsf.gdb.path");
|
||||
String fileExtension = isWindows ? ".exe" : "";
|
||||
String versionPostfix = (!version.equals("default")) ? "." + version : "";
|
||||
String versionPostfix = (!version.equals(DEFAULT_VERSION_STRING)) ? "." + version : "";
|
||||
String debugName = main + versionPostfix + fileExtension;
|
||||
if (gdbPath != null) {
|
||||
debugName = gdbPath + "/" + debugName;
|
||||
|
|
Loading…
Add table
Reference in a new issue