Ghidra is a software reverse engineering (SRE) framework
GT-3447 - Tests - timeout override property
dragonmacher8cb4ee8f60a3
diff --git a/Ghidra/Framework/Docking/src/test.slow/java/docking/DockingErrorDisplayTest.java b/Ghidra/Framework/Docking/src/test.slow/java/docking/DockingErrorDisplayTest.javaindex b51ed95466..6ced1b0bf9 100644--- a/Ghidra/Framework/Docking/src/test.slow/java/docking/DockingErrorDisplayTest.java+++ b/Ghidra/Framework/Docking/src/test.slow/java/docking/DockingErrorDisplayTest.java@@ -15,7 +15,7 @@*/package docking;-import static org.junit.Assert.assertNotNull;+import static org.junit.Assert.*;import java.awt.Window;import java.util.Collections;@@ -28,11 +28,6 @@ import ghidra.util.exception.MultipleCauses;public class DockingErrorDisplayTest extends AbstractDockingTest {- public DockingErrorDisplayTest() {- super();- // TODO Auto-generated constructor stub- }-private static final String TEST_TITLE = "Test Title";@Testdiff --git a/Ghidra/Framework/Generic/src/main/java/generic/test/ConcurrentTestExceptionStatement.java b/Ghidra/Framework/Generic/src/main/java/generic/test/ConcurrentTestExceptionStatement.javaindex 881b7b1476..7879d2bed0 100644--- a/Ghidra/Framework/Generic/src/main/java/generic/test/ConcurrentTestExceptionStatement.java+++ b/Ghidra/Framework/Generic/src/main/java/generic/test/ConcurrentTestExceptionStatement.java@@ -29,6 +29,12 @@ import util.CollectionUtils;public class ConcurrentTestExceptionStatement extends Statement {+ // set this value to 'true' (ignoring case) to disable the test timeout feature+ public static final String DISABLE_TEST_TIMEOUT_PROPERTY =+ "ghidra.test.property.timeout.disable";+ public static final String TEST_TIMEOUT_MILLIS_PROPERTY =+ "ghidra.test.property.timeout.milliseconds";+/** The time period after which a test will be forcibly terminated */private static long TIMEOUT_MILLIS = 10 /*mins*/ * 60 /*secs*/ * 1000 /*millis*/;private static Thread lastTestThread = null;@@ -40,14 +46,50 @@ public class ConcurrentTestExceptionStatement extends Statement {testStatement = originalStatement;ConcurrentTestExceptionHandler.clear();- // enable timeout monitor except when running from eclipse to permit extended debugging- timoutMonitor =- isRunningFromEclipse() ? null : GTimer.scheduleRunnable(TIMEOUT_MILLIS, () -> {+ // enable timeout monitor by default; disable to permit extended debugging when running+ // from eclipse or when set via a system property+ if (ignoreTimeout()) {+ timoutMonitor = null;+ }+ else {+ long testTimeout = getTestTimeout();+ timoutMonitor = GTimer.scheduleRunnable(testTimeout, () -> {// no-op; we will use the monitor directly});+ }+ }++ private long getTestTimeout() {+ String timeoutString =+ System.getProperty(TEST_TIMEOUT_MILLIS_PROPERTY, Long.toString(TIMEOUT_MILLIS));+ try {+ long timeout = Long.parseLong(timeoutString);+ Msg.info(this, "Using test timeout override value " + timeout + "ms");+ return timeout;+ }+ catch (NumberFormatException e) {+ Msg.error(this,+ "Unable to parse " + TEST_TIMEOUT_MILLIS_PROPERTY + " Long value '" ++ timeoutString + "'");+ }+ return TIMEOUT_MILLIS;+ }++ private boolean isTestTimeoutDisabled() {+ String disableProperty =+ System.getProperty(DISABLE_TEST_TIMEOUT_PROPERTY, Boolean.FALSE.toString());+ return Boolean.parseBoolean(disableProperty.trim());+ }++ private boolean ignoreTimeout() {+ if (isTestTimeoutDisabled()) {+ Msg.info(this, "Test timeout feature disabled");+ return true;+ }+ return isRunningFromEclipse();}- private static boolean isRunningFromEclipse() {+ private boolean isRunningFromEclipse() {// TODO: this may need adjustment for other Eclipse platforms/versionsreturn System.getProperty("java.class.path").endsWith(".cp");}