Skip to main content
aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorMarc Khouzam2017-02-10 15:04:25 +0000
committerGerrit Code Review @ Eclipse.org2017-02-14 16:01:23 +0000
commit78c9a0bb5e8180e0ca483312c7f09639f0abd9b4 (patch)
tree01ec176d97bf024787c27cc5c9cad14057cbb40d /dsf-gdb/org.eclipse.cdt.tests.dsf.gdb
parentf187157456505f27e6bd1a51b69bf0bc52383080 (diff)
downloadorg.eclipse.cdt-78c9a0bb5e8180e0ca483312c7f09639f0abd9b4.tar.gz
org.eclipse.cdt-78c9a0bb5e8180e0ca483312c7f09639f0abd9b4.tar.xz
org.eclipse.cdt-78c9a0bb5e8180e0ca483312c7f09639f0abd9b4.zip
Validate GDB version in debug tests
Diffstat (limited to 'dsf-gdb/org.eclipse.cdt.tests.dsf.gdb')
-rw-r--r--dsf-gdb/org.eclipse.cdt.tests.dsf.gdb/src/org/eclipse/cdt/tests/dsf/gdb/framework/BaseParametrizedTestCase.java39
-rw-r--r--dsf-gdb/org.eclipse.cdt.tests.dsf.gdb/src/org/eclipse/cdt/tests/dsf/gdb/framework/BaseTestCase.java18
2 files changed, 54 insertions, 3 deletions
diff --git a/dsf-gdb/org.eclipse.cdt.tests.dsf.gdb/src/org/eclipse/cdt/tests/dsf/gdb/framework/BaseParametrizedTestCase.java b/dsf-gdb/org.eclipse.cdt.tests.dsf.gdb/src/org/eclipse/cdt/tests/dsf/gdb/framework/BaseParametrizedTestCase.java
index 5909edb2bf6..a66bba46567 100644
--- a/dsf-gdb/org.eclipse.cdt.tests.dsf.gdb/src/org/eclipse/cdt/tests/dsf/gdb/framework/BaseParametrizedTestCase.java
+++ b/dsf-gdb/org.eclipse.cdt.tests.dsf.gdb/src/org/eclipse/cdt/tests/dsf/gdb/framework/BaseParametrizedTestCase.java
@@ -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());
+ }
+ }
}
diff --git a/dsf-gdb/org.eclipse.cdt.tests.dsf.gdb/src/org/eclipse/cdt/tests/dsf/gdb/framework/BaseTestCase.java b/dsf-gdb/org.eclipse.cdt.tests.dsf.gdb/src/org/eclipse/cdt/tests/dsf/gdb/framework/BaseTestCase.java
index 4bf45f6ac2a..47c45b92880 100644
--- a/dsf-gdb/org.eclipse.cdt.tests.dsf.gdb/src/org/eclipse/cdt/tests/dsf/gdb/framework/BaseTestCase.java
+++ b/dsf-gdb/org.eclipse.cdt.tests.dsf.gdb/src/org/eclipse/cdt/tests/dsf/gdb/framework/BaseTestCase.java
@@ -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;

Back to the top