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.211 by jsr166, Mon Nov 14 23:52:22 2016 UTC vs.
Revision 1.219 by jsr166, Sat Feb 18 16:37:49 2017 UTC

# Line 8 | Line 8
8  
9   /*
10   * @test
11 < * @summary JSR-166 tck tests
11 > * @summary JSR-166 tck tests (conformance testing mode)
12 > * @build *
13   * @modules java.management
14 + * @run junit/othervm/timeout=1000 JSR166TestCase
15 + */
16 +
17 + /*
18 + * @test
19 + * @summary JSR-166 tck tests (whitebox tests allowed)
20   * @build *
21 < * @run junit/othervm/timeout=1000 -Djsr166.testImplementationDetails=true JSR166TestCase
22 < * @run junit/othervm/timeout=1000 -Djava.util.concurrent.ForkJoinPool.common.parallelism=0 -Djsr166.testImplementationDetails=true JSR166TestCase
23 < * @run junit/othervm/timeout=1000 -Djava.util.concurrent.ForkJoinPool.common.parallelism=1 -Djava.util.secureRandomSeed=true JSR166TestCase
21 > * @modules java.base/java.util.concurrent:open
22 > *          java.base/java.lang:open
23 > *          java.management
24 > * @run junit/othervm/timeout=1000
25 > *      -Djsr166.testImplementationDetails=true
26 > *      JSR166TestCase
27 > * @run junit/othervm/timeout=1000
28 > *      -Djsr166.testImplementationDetails=true
29 > *      -Djava.util.concurrent.ForkJoinPool.common.parallelism=0
30 > *      JSR166TestCase
31 > * @run junit/othervm/timeout=1000
32 > *      -Djsr166.testImplementationDetails=true
33 > *      -Djava.util.concurrent.ForkJoinPool.common.parallelism=1
34 > *      -Djava.util.secureRandomSeed=true
35 > *      JSR166TestCase
36 > * @run junit/othervm/timeout=1000/policy=tck.policy
37 > *      -Djsr166.testImplementationDetails=true
38 > *      JSR166TestCase
39   */
40  
41   import static java.util.concurrent.TimeUnit.MILLISECONDS;
# Line 515 | Line 537 | public class JSR166TestCase extends Test
537                  "DoubleAdderTest",
538                  "ForkJoinPool8Test",
539                  "ForkJoinTask8Test",
540 +                "LinkedBlockingDeque8Test",
541 +                "LinkedBlockingQueue8Test",
542                  "LongAccumulatorTest",
543                  "LongAdderTest",
544                  "SplittableRandomTest",
# Line 537 | Line 561 | public class JSR166TestCase extends Test
561                  "AtomicReference9Test",
562                  "AtomicReferenceArray9Test",
563                  "ExecutorCompletionService9Test",
564 +                "ForkJoinPool9Test",
565              };
566              addNamedTestClasses(suite, java9TestClassNames);
567          }
# Line 547 | Line 572 | public class JSR166TestCase extends Test
572      /** Returns list of junit-style test method names in given class. */
573      public static ArrayList<String> testMethodNames(Class<?> testClass) {
574          Method[] methods = testClass.getDeclaredMethods();
575 <        ArrayList<String> names = new ArrayList<String>(methods.length);
575 >        ArrayList<String> names = new ArrayList<>(methods.length);
576          for (Method method : methods) {
577              if (method.getName().startsWith("test")
578                  && Modifier.isPublic(method.getModifiers())
# Line 653 | Line 678 | public class JSR166TestCase extends Test
678       * The first exception encountered if any threadAssertXXX method fails.
679       */
680      private final AtomicReference<Throwable> threadFailure
681 <        = new AtomicReference<Throwable>(null);
681 >        = new AtomicReference<>(null);
682  
683      /**
684       * Records an exception so that it can be rethrown later in the test
# Line 1215 | Line 1240 | public class JSR166TestCase extends Test
1240          }
1241          public void refresh() {}
1242          public String toString() {
1243 <            List<Permission> ps = new ArrayList<Permission>();
1243 >            List<Permission> ps = new ArrayList<>();
1244              for (Enumeration<Permission> e = perms.elements(); e.hasMoreElements();)
1245                  ps.add(e.nextElement());
1246              return "AdjustablePolicy with permissions " + ps;
# Line 1274 | Line 1299 | public class JSR166TestCase extends Test
1299                  startTime = System.nanoTime();
1300              else if (millisElapsedSince(startTime) > timeoutMillis) {
1301                  threadAssertTrue(thread.isAlive());
1302 <                return;
1302 >                fail("timed out waiting for thread to enter wait state");
1303 >            }
1304 >            Thread.yield();
1305 >        }
1306 >    }
1307 >
1308 >    /**
1309 >     * Spin-waits up to the specified number of milliseconds for the given
1310 >     * thread to enter a wait state: BLOCKED, WAITING, or TIMED_WAITING,
1311 >     * and additionally satisfy the given condition.
1312 >     */
1313 >    void waitForThreadToEnterWaitState(
1314 >        Thread thread, long timeoutMillis, Callable<Boolean> waitingForGodot) {
1315 >        long startTime = 0L;
1316 >        for (;;) {
1317 >            Thread.State s = thread.getState();
1318 >            if (s == Thread.State.BLOCKED ||
1319 >                s == Thread.State.WAITING ||
1320 >                s == Thread.State.TIMED_WAITING) {
1321 >                try {
1322 >                    if (waitingForGodot.call())
1323 >                        return;
1324 >                } catch (Throwable fail) { threadUnexpectedException(fail); }
1325 >            }
1326 >            else if (s == Thread.State.TERMINATED)
1327 >                fail("Unexpected thread termination");
1328 >            else if (startTime == 0L)
1329 >                startTime = System.nanoTime();
1330 >            else if (millisElapsedSince(startTime) > timeoutMillis) {
1331 >                threadAssertTrue(thread.isAlive());
1332 >                fail("timed out waiting for thread to enter wait state");
1333              }
1334              Thread.yield();
1335          }
1336      }
1337  
1338      /**
1339 <     * Waits up to LONG_DELAY_MS for the given thread to enter a wait
1340 <     * state: BLOCKED, WAITING, or TIMED_WAITING.
1339 >     * Spin-waits up to LONG_DELAY_MS milliseconds for the given thread to
1340 >     * enter a wait state: BLOCKED, WAITING, or TIMED_WAITING.
1341       */
1342      void waitForThreadToEnterWaitState(Thread thread) {
1343          waitForThreadToEnterWaitState(thread, LONG_DELAY_MS);
1344      }
1345  
1346      /**
1347 +     * Spin-waits up to LONG_DELAY_MS milliseconds for the given thread to
1348 +     * enter a wait state: BLOCKED, WAITING, or TIMED_WAITING,
1349 +     * and additionally satisfy the given condition.
1350 +     */
1351 +    void waitForThreadToEnterWaitState(
1352 +        Thread thread, Callable<Boolean> waitingForGodot) {
1353 +        waitForThreadToEnterWaitState(thread, LONG_DELAY_MS, waitingForGodot);
1354 +    }
1355 +
1356 +    /**
1357       * Returns the number of milliseconds since time given by
1358       * startNanoTime, which must have been previously returned from a
1359       * call to {@link System#nanoTime()}.

Diff Legend

Removed lines
+ Added lines
< Changed lines
> Changed lines