20 |
|
import java.lang.reflect.Constructor; |
21 |
|
import java.lang.reflect.Method; |
22 |
|
import java.lang.reflect.Modifier; |
23 |
+ |
import java.nio.file.Files; |
24 |
+ |
import java.nio.file.Paths; |
25 |
|
import java.security.CodeSource; |
26 |
|
import java.security.Permission; |
27 |
|
import java.security.PermissionCollection; |
54 |
|
import java.util.concurrent.ThreadPoolExecutor; |
55 |
|
import java.util.concurrent.TimeoutException; |
56 |
|
import java.util.concurrent.atomic.AtomicReference; |
57 |
+ |
import java.util.regex.Matcher; |
58 |
|
import java.util.regex.Pattern; |
59 |
|
|
60 |
|
import junit.framework.AssertionFailedError; |
193 |
|
|
194 |
|
// Instrumentation to debug very rare, but very annoying hung test runs. |
195 |
|
static volatile TestCase currentTestCase; |
196 |
< |
static volatile int currentRun = 0; |
196 |
> |
// static volatile int currentRun = 0; |
197 |
|
static { |
198 |
|
Runnable checkForWedgedTest = new Runnable() { public void run() { |
199 |
< |
// avoid spurious reports with enormous runsPerTest |
200 |
< |
final int timeoutMinutes = Math.max(runsPerTest / 10, 1); |
199 |
> |
// Avoid spurious reports with enormous runsPerTest. |
200 |
> |
// A single test case run should never take more than 1 second. |
201 |
> |
// But let's cap it at the high end too ... |
202 |
> |
final int timeoutMinutes = |
203 |
> |
Math.min(15, Math.max(runsPerTest / 60, 1)); |
204 |
|
for (TestCase lastTestCase = currentTestCase;;) { |
205 |
|
try { MINUTES.sleep(timeoutMinutes); } |
206 |
|
catch (InterruptedException unexpected) { break; } |
207 |
|
if (lastTestCase == currentTestCase) { |
208 |
|
System.err.printf( |
209 |
< |
"Looks like we're stuck running test: %s (%d/%d)%n", |
210 |
< |
lastTestCase, currentRun, runsPerTest); |
211 |
< |
System.err.println |
212 |
< |
("Looks like we're stuck running test: " |
213 |
< |
+ lastTestCase + " (" + currentRun + "/" + runsPerTest + ")"); |
209 |
> |
"Looks like we're stuck running test: %s%n", |
210 |
> |
lastTestCase); |
211 |
> |
// System.err.printf( |
212 |
> |
// "Looks like we're stuck running test: %s (%d/%d)%n", |
213 |
> |
// lastTestCase, currentRun, runsPerTest); |
214 |
|
System.err.println("availableProcessors=" + |
215 |
|
Runtime.getRuntime().availableProcessors()); |
216 |
+ |
System.err.printf("cpu model = %s%n", cpuModel()); |
217 |
|
dumpTestThreads(); |
218 |
|
// one stack dump is probably enough; more would be spam |
219 |
|
break; |
225 |
|
thread.start(); |
226 |
|
} |
227 |
|
|
228 |
+ |
public static String cpuModel() { |
229 |
+ |
try { |
230 |
+ |
Matcher matcher = Pattern.compile("model name\\s*: (.*)") |
231 |
+ |
.matcher(new String( |
232 |
+ |
Files.readAllBytes(Paths.get("/proc/cpuinfo")), "UTF-8")); |
233 |
+ |
matcher.find(); |
234 |
+ |
return matcher.group(1); |
235 |
+ |
} catch (Exception ex) { return null; } |
236 |
+ |
} |
237 |
+ |
|
238 |
|
public void runBare() throws Throwable { |
239 |
|
currentTestCase = this; |
240 |
|
if (methodFilter == null |
244 |
|
|
245 |
|
protected void runTest() throws Throwable { |
246 |
|
for (int i = 0; i < runsPerTest; i++) { |
247 |
< |
currentRun = i; |
247 |
> |
// currentRun = i; |
248 |
|
if (profileTests) |
249 |
|
runTestProfiled(); |
250 |
|
else |