ViewVC Help
View File | Revision Log | Show Annotations | Download File | Root Listing
root/jsr166/jsr166/src/test/tck/JSR166TestCase.java
(Generate patch)

Comparing jsr166/src/test/tck/JSR166TestCase.java (file contents):
Revision 1.92 by jsr166, Sun Nov 18 18:03:11 2012 UTC vs.
Revision 1.97 by jsr166, Fri Feb 1 19:07:36 2013 UTC

# Line 11 | Line 11 | import java.io.ByteArrayInputStream;
11   import java.io.ByteArrayOutputStream;
12   import java.io.ObjectInputStream;
13   import java.io.ObjectOutputStream;
14 + import java.lang.management.ManagementFactory;
15 + import java.lang.management.ThreadInfo;
16 + import java.lang.reflect.Method;
17 + import java.util.ArrayList;
18   import java.util.Arrays;
19   import java.util.Date;
20 + import java.util.Enumeration;
21 + import java.util.List;
22   import java.util.NoSuchElementException;
23   import java.util.PropertyPermission;
24   import java.util.concurrent.*;
# Line 142 | Line 148 | public class JSR166TestCase extends Test
148      }
149  
150      /**
151 <     * Runs all JSR166 unit tests using junit.textui.TestRunner
151 >     * Runs all JSR166 unit tests using junit.textui.TestRunner.
152 >     * Optional command line arg provides the number of iterations to
153 >     * repeat running the tests.
154       */
155      public static void main(String[] args) {
156          if (useSecurityManager) {
# Line 174 | Line 182 | public class JSR166TestCase extends Test
182          return suite;
183      }
184  
185 +    static void addTestReflectively(TestSuite suite, String testClassName) {
186 +        try {
187 +            Class klazz = Class.forName(testClassName);
188 +            Method m = klazz.getDeclaredMethod("suite", new Class<?>[0]);
189 +            suite.addTest(newTestSuite((Test)m.invoke(null)));
190 +        } catch (Exception e) {
191 +            throw new Error(e);
192 +        }
193 +    }
194 +
195 +    public static final double JAVA_CLASS_VERSION;
196 +    static {
197 +        try {
198 +            JAVA_CLASS_VERSION = java.security.AccessController.doPrivileged(
199 +                new java.security.PrivilegedAction<Double>() {
200 +                public Double run() {
201 +                    return Double.valueOf(System.getProperty("java.class.version"));}});
202 +        } catch (Throwable t) {
203 +            throw new Error(t);
204 +        }
205 +    }
206 +
207 +    public static boolean isAtLeastJdk6() { return JAVA_CLASS_VERSION >= 50.0; }
208 +    public static boolean isAtLeastJdk7() { return JAVA_CLASS_VERSION >= 51.0; }
209 +    public static boolean isAtLeastJdk8() { return JAVA_CLASS_VERSION >= 52.0; }
210 +
211      /**
212       * Collects all JSR166 unit tests as one suite.
213       */
214      public static Test suite() {
215 <        return newTestSuite(
215 >        TestSuite suite = newTestSuite(
216              ForkJoinPoolTest.suite(),
217              ForkJoinTaskTest.suite(),
218              RecursiveActionTest.suite(),
# Line 243 | Line 277 | public class JSR166TestCase extends Test
277              TreeSetTest.suite(),
278              TreeSubMapTest.suite(),
279              TreeSubSetTest.suite());
280 +        if (isAtLeastJdk8()) {
281 +            addTestReflectively(suite, "StampedLockTest");
282 +        }
283 +        return suite;
284      }
285  
286  
# Line 507 | Line 545 | public class JSR166TestCase extends Test
545      }
546  
547      /**
548 +     * A debugging tool to print all stack traces, as jstack does.
549 +     */
550 +    static void printAllStackTraces() {
551 +        for (ThreadInfo info :
552 +                 ManagementFactory.getThreadMXBean()
553 +                 .dumpAllThreads(true, true))
554 +            System.err.print(info);
555 +    }
556 +
557 +    /**
558       * Checks that thread does not terminate within the default
559       * millisecond delay of {@code timeoutMillis()}.
560       */
# Line 623 | Line 671 | public class JSR166TestCase extends Test
671          SecurityManager sm = System.getSecurityManager();
672          if (sm == null) {
673              r.run();
674 +        }
675 +        runWithSecurityManagerWithPermissions(r, permissions);
676 +    }
677 +
678 +    /**
679 +     * Runs Runnable r with a security policy that permits precisely
680 +     * the specified permissions.  If there is no current security
681 +     * manager, a temporary one is set for the duration of the
682 +     * Runnable.  We require that any security manager permit
683 +     * getPolicy/setPolicy.
684 +     */
685 +    public void runWithSecurityManagerWithPermissions(Runnable r,
686 +                                                      Permission... permissions) {
687 +        SecurityManager sm = System.getSecurityManager();
688 +        if (sm == null) {
689              Policy savedPolicy = Policy.getPolicy();
690              try {
691                  Policy.setPolicy(permissivePolicy());
692                  System.setSecurityManager(new SecurityManager());
693 <                runWithPermissions(r, permissions);
693 >                runWithSecurityManagerWithPermissions(r, permissions);
694              } finally {
695                  System.setSecurityManager(null);
696                  Policy.setPolicy(savedPolicy);
# Line 675 | Line 738 | public class JSR166TestCase extends Test
738              return perms.implies(p);
739          }
740          public void refresh() {}
741 +        public String toString() {
742 +            List<Permission> ps = new ArrayList<Permission>();
743 +            for (Enumeration<Permission> e = perms.elements(); e.hasMoreElements();)
744 +                ps.add(e.nextElement());
745 +            return "AdjustablePolicy with permissions " + ps;
746 +        }
747      }
748  
749      /**

Diff Legend

Removed lines
+ Added lines
< Changed lines
> Changed lines