--- jsr166/src/test/tck/JSR166TestCase.java 2013/01/21 19:43:52 1.95 +++ jsr166/src/test/tck/JSR166TestCase.java 2013/02/03 06:20:32 1.98 @@ -11,6 +11,9 @@ import java.io.ByteArrayInputStream; import java.io.ByteArrayOutputStream; import java.io.ObjectInputStream; import java.io.ObjectOutputStream; +import java.lang.management.ManagementFactory; +import java.lang.management.ThreadInfo; +import java.lang.reflect.Method; import java.util.ArrayList; import java.util.Arrays; import java.util.Date; @@ -179,11 +182,42 @@ public class JSR166TestCase extends Test return suite; } + public static void addNamedTestClasses(TestSuite suite, + String... testClassNames) { + for (String testClassName : testClassNames) { + try { + Class testClass = Class.forName(testClassName); + Method m = testClass.getDeclaredMethod("suite", + new Class[0]); + suite.addTest(newTestSuite((Test)m.invoke(null))); + } catch (Exception e) { + throw new Error("Missing test class", e); + } + } + } + + public static final double JAVA_CLASS_VERSION; + static { + try { + JAVA_CLASS_VERSION = java.security.AccessController.doPrivileged( + new java.security.PrivilegedAction() { + public Double run() { + return Double.valueOf(System.getProperty("java.class.version"));}}); + } catch (Throwable t) { + throw new Error(t); + } + } + + public static boolean atLeastJava6() { return JAVA_CLASS_VERSION >= 50.0; } + public static boolean atLeastJava7() { return JAVA_CLASS_VERSION >= 51.0; } + public static boolean atLeastJava8() { return JAVA_CLASS_VERSION >= 52.0; } + /** * Collects all JSR166 unit tests as one suite. */ public static Test suite() { - return newTestSuite( + // Java7+ test classes + TestSuite suite = newTestSuite( ForkJoinPoolTest.suite(), ForkJoinTaskTest.suite(), RecursiveActionTest.suite(), @@ -248,6 +282,16 @@ public class JSR166TestCase extends Test TreeSetTest.suite(), TreeSubMapTest.suite(), TreeSubSetTest.suite()); + + // Java8+ test classes + if (atLeastJava8()) { + String[] java8TestClassNames = { + "StampedLockTest", + }; + addNamedTestClasses(suite, java8TestClassNames); + } + + return suite; } @@ -514,11 +558,11 @@ public class JSR166TestCase extends Test /** * A debugging tool to print all stack traces, as jstack does. */ - void printAllStackTraces() { - System.err.println( - Arrays.toString( - java.lang.management.ManagementFactory.getThreadMXBean() - .dumpAllThreads(true, true))); + static void printAllStackTraces() { + for (ThreadInfo info : + ManagementFactory.getThreadMXBean() + .dumpAllThreads(true, true)) + System.err.print(info); } /**