29
29
30
30
public class ConcurrentTestExceptionStatement extends Statement {
31
31
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
+
32
38
/** The time period after which a test will be forcibly terminated */
33
39
private static long TIMEOUT_MILLIS = 10 /*mins*/ * 60 /*secs*/ * 1000 /*millis*/ ;
34
40
private static Thread lastTestThread = null ;
@@ -40,14 +46,50 @@ public ConcurrentTestExceptionStatement(Statement originalStatement) {
40
46
testStatement = originalStatement ;
41
47
ConcurrentTestExceptionHandler .clear ();
42
48
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 , () -> {
46
57
// no-op; we will use the monitor directly
47
58
});
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 ();
48
90
}
49
91
50
- private static boolean isRunningFromEclipse () {
92
+ private boolean isRunningFromEclipse () {
51
93
// TODO: this may need adjustment for other Eclipse platforms/versions
52
94
return System .getProperty ("java.class.path" ).endsWith (".cp" );
53
95
}
0 commit comments