Skip to content

Commit d66027e

Browse files
committed
Merge remote-tracking branch
'origin/GT-3447-dragonmacher-test-timeout-override' Fixes NationalSecurityAgency#1424
2 parents 38a533c + 8cb4ee8 commit d66027e

File tree

2 files changed

+47
-10
lines changed

2 files changed

+47
-10
lines changed

Ghidra/Framework/Docking/src/test.slow/java/docking/DockingErrorDisplayTest.java

Lines changed: 1 addition & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -15,7 +15,7 @@
1515
*/
1616
package docking;
1717

18-
import static org.junit.Assert.assertNotNull;
18+
import static org.junit.Assert.*;
1919

2020
import java.awt.Window;
2121
import java.util.Collections;
@@ -28,11 +28,6 @@
2828

2929
public class DockingErrorDisplayTest extends AbstractDockingTest {
3030

31-
public DockingErrorDisplayTest() {
32-
super();
33-
// TODO Auto-generated constructor stub
34-
}
35-
3631
private static final String TEST_TITLE = "Test Title";
3732

3833
@Test

Ghidra/Framework/Generic/src/main/java/generic/test/ConcurrentTestExceptionStatement.java

Lines changed: 46 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -29,6 +29,12 @@
2929

3030
public class ConcurrentTestExceptionStatement extends Statement {
3131

32+
// set this value to 'true' (ignoring case) to disable the test timeout feature
33+
public static final String DISABLE_TEST_TIMEOUT_PROPERTY =
34+
"ghidra.test.property.timeout.disable";
35+
public static final String TEST_TIMEOUT_MILLIS_PROPERTY =
36+
"ghidra.test.property.timeout.milliseconds";
37+
3238
/** The time period after which a test will be forcibly terminated */
3339
private static long TIMEOUT_MILLIS = 10 /*mins*/ * 60 /*secs*/ * 1000 /*millis*/;
3440
private static Thread lastTestThread = null;
@@ -40,14 +46,50 @@ public ConcurrentTestExceptionStatement(Statement originalStatement) {
4046
testStatement = originalStatement;
4147
ConcurrentTestExceptionHandler.clear();
4248

43-
// enable timeout monitor except when running from eclipse to permit extended debugging
44-
timoutMonitor =
45-
isRunningFromEclipse() ? null : GTimer.scheduleRunnable(TIMEOUT_MILLIS, () -> {
49+
// enable timeout monitor by default; disable to permit extended debugging when running
50+
// from eclipse or when set via a system property
51+
if (ignoreTimeout()) {
52+
timoutMonitor = null;
53+
}
54+
else {
55+
long testTimeout = getTestTimeout();
56+
timoutMonitor = GTimer.scheduleRunnable(testTimeout, () -> {
4657
// no-op; we will use the monitor directly
4758
});
59+
}
60+
}
61+
62+
private long getTestTimeout() {
63+
String timeoutString =
64+
System.getProperty(TEST_TIMEOUT_MILLIS_PROPERTY, Long.toString(TIMEOUT_MILLIS));
65+
try {
66+
long timeout = Long.parseLong(timeoutString);
67+
Msg.info(this, "Using test timeout override value " + timeout + "ms");
68+
return timeout;
69+
}
70+
catch (NumberFormatException e) {
71+
Msg.error(this,
72+
"Unable to parse " + TEST_TIMEOUT_MILLIS_PROPERTY + " Long value '" +
73+
timeoutString + "'");
74+
}
75+
return TIMEOUT_MILLIS;
76+
}
77+
78+
private boolean isTestTimeoutDisabled() {
79+
String disableProperty =
80+
System.getProperty(DISABLE_TEST_TIMEOUT_PROPERTY, Boolean.FALSE.toString());
81+
return Boolean.parseBoolean(disableProperty.trim());
82+
}
83+
84+
private boolean ignoreTimeout() {
85+
if (isTestTimeoutDisabled()) {
86+
Msg.info(this, "Test timeout feature disabled");
87+
return true;
88+
}
89+
return isRunningFromEclipse();
4890
}
4991

50-
private static boolean isRunningFromEclipse() {
92+
private boolean isRunningFromEclipse() {
5193
// TODO: this may need adjustment for other Eclipse platforms/versions
5294
return System.getProperty("java.class.path").endsWith(".cp");
5395
}

0 commit comments

Comments
 (0)