--- jsr166/src/test/tck/JSR166TestCase.java 2015/10/08 21:50:26 1.169 +++ jsr166/src/test/tck/JSR166TestCase.java 2015/10/09 19:09:59 1.174 @@ -20,6 +20,8 @@ import java.lang.management.ThreadMXBean import java.lang.reflect.Constructor; import java.lang.reflect.Method; import java.lang.reflect.Modifier; +import java.nio.file.Files; +import java.nio.file.Paths; import java.security.CodeSource; import java.security.Permission; import java.security.PermissionCollection; @@ -52,6 +54,7 @@ import java.util.concurrent.ThreadFactor import java.util.concurrent.ThreadPoolExecutor; import java.util.concurrent.TimeoutException; import java.util.concurrent.atomic.AtomicReference; +import java.util.regex.Matcher; import java.util.regex.Pattern; import junit.framework.AssertionFailedError; @@ -188,20 +191,29 @@ public class JSR166TestCase extends Test return (regex == null) ? null : Pattern.compile(regex); } + // Instrumentation to debug very rare, but very annoying hung test runs. static volatile TestCase currentTestCase; + // static volatile int currentRun = 0; static { Runnable checkForWedgedTest = new Runnable() { public void run() { - // avoid spurious reports with enormous runsPerTest - final int timeoutMinutes = Math.max(runsPerTest / 10, 1); + // Avoid spurious reports with enormous runsPerTest. + // A single test case run should never take more than 1 second. + // But let's cap it at the high end too ... + final int timeoutMinutes = + Math.min(15, Math.max(runsPerTest / 60, 1)); for (TestCase lastTestCase = currentTestCase;;) { try { MINUTES.sleep(timeoutMinutes); } catch (InterruptedException unexpected) { break; } if (lastTestCase == currentTestCase) { - System.err.println - ("Looks like we're stuck running test: " - + lastTestCase); + System.err.printf( + "Looks like we're stuck running test: %s%n", + lastTestCase); +// System.err.printf( +// "Looks like we're stuck running test: %s (%d/%d)%n", +// lastTestCase, currentRun, runsPerTest); System.err.println("availableProcessors=" + Runtime.getRuntime().availableProcessors()); + System.err.printf("cpu model = %s%n", cpuModel()); dumpTestThreads(); // one stack dump is probably enough; more would be spam break; @@ -213,6 +225,16 @@ public class JSR166TestCase extends Test thread.start(); } + public static String cpuModel() { + try { + Matcher matcher = Pattern.compile("model name\\s*: (.*)") + .matcher(new String( + Files.readAllBytes(Paths.get("/proc/cpuinfo")), "UTF-8")); + matcher.find(); + return matcher.group(1); + } catch (Exception ex) { return null; } + } + public void runBare() throws Throwable { currentTestCase = this; if (methodFilter == null @@ -222,6 +244,7 @@ public class JSR166TestCase extends Test protected void runTest() throws Throwable { for (int i = 0; i < runsPerTest; i++) { + // currentRun = i; if (profileTests) runTestProfiled(); else