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.250 by jsr166, Sat Nov 24 21:48:19 2018 UTC vs.
Revision 1.265 by jsr166, Sat Sep 7 15:03:44 2019 UTC

# Line 284 | Line 284 | public class JSR166TestCase extends Test
284      static volatile TestCase currentTestCase;
285      // static volatile int currentRun = 0;
286      static {
287 <        Runnable checkForWedgedTest = new Runnable() { public void run() {
287 >        Runnable wedgedTestDetector = new Runnable() { public void run() {
288              // Avoid spurious reports with enormous runsPerTest.
289              // A single test case run should never take more than 1 second.
290              // But let's cap it at the high end too ...
291 <            final int timeoutMinutes =
292 <                Math.min(15, Math.max(runsPerTest / 60, 1));
291 >            final int timeoutMinutesMin = Math.max(runsPerTest / 60, 1)
292 >                * Math.max((int) delayFactor, 1);
293 >            final int timeoutMinutes = Math.min(15, timeoutMinutesMin);
294              for (TestCase lastTestCase = currentTestCase;;) {
295                  try { MINUTES.sleep(timeoutMinutes); }
296                  catch (InterruptedException unexpected) { break; }
# Line 309 | Line 310 | public class JSR166TestCase extends Test
310                  }
311                  lastTestCase = currentTestCase;
312              }}};
313 <        Thread thread = new Thread(checkForWedgedTest, "checkForWedgedTest");
313 >        Thread thread = new Thread(wedgedTestDetector, "WedgedTestDetector");
314          thread.setDaemon(true);
315          thread.start();
316      }
# Line 460 | Line 461 | public class JSR166TestCase extends Test
461      public static boolean atLeastJava9()  { return JAVA_CLASS_VERSION >= 53.0; }
462      public static boolean atLeastJava10() { return JAVA_CLASS_VERSION >= 54.0; }
463      public static boolean atLeastJava11() { return JAVA_CLASS_VERSION >= 55.0; }
464 +    public static boolean atLeastJava12() { return JAVA_CLASS_VERSION >= 56.0; }
465 +    public static boolean atLeastJava13() { return JAVA_CLASS_VERSION >= 57.0; }
466 +    public static boolean atLeastJava14() { return JAVA_CLASS_VERSION >= 58.0; }
467 +    public static boolean atLeastJava15() { return JAVA_CLASS_VERSION >= 59.0; }
468 +    public static boolean atLeastJava16() { return JAVA_CLASS_VERSION >= 60.0; }
469 +    public static boolean atLeastJava17() { return JAVA_CLASS_VERSION >= 61.0; }
470  
471      /**
472       * Collects all JSR166 unit tests as one suite.
# Line 511 | Line 518 | public class JSR166TestCase extends Test
518              ExecutorsTest.suite(),
519              ExecutorCompletionServiceTest.suite(),
520              FutureTaskTest.suite(),
521 +            HashtableTest.suite(),
522              LinkedBlockingDequeTest.suite(),
523              LinkedBlockingQueueTest.suite(),
524              LinkedListTest.suite(),
# Line 550 | Line 558 | public class JSR166TestCase extends Test
558                  "HashMapTest",
559                  "LinkedBlockingDeque8Test",
560                  "LinkedBlockingQueue8Test",
561 +                "LinkedHashMapTest",
562                  "LongAccumulatorTest",
563                  "LongAdderTest",
564                  "SplittableRandomTest",
# Line 648 | Line 657 | public class JSR166TestCase extends Test
657      public static long MEDIUM_DELAY_MS;
658      public static long LONG_DELAY_MS;
659  
660 +    /**
661 +     * A delay significantly longer than LONG_DELAY_MS.
662 +     * Use this in a thread that is waited for via awaitTermination(Thread).
663 +     */
664 +    public static long LONGER_DELAY_MS;
665 +
666      private static final long RANDOM_TIMEOUT;
667      private static final long RANDOM_EXPIRED_TIMEOUT;
668      private static final TimeUnit RANDOM_TIMEUNIT;
# Line 676 | Line 691 | public class JSR166TestCase extends Test
691      static TimeUnit randomTimeUnit() { return RANDOM_TIMEUNIT; }
692  
693      /**
694 +     * Returns a random boolean; a "coin flip".
695 +     */
696 +    static boolean randomBoolean() {
697 +        return ThreadLocalRandom.current().nextBoolean();
698 +    }
699 +
700 +    /**
701 +     * Returns a random element from given choices.
702 +     */
703 +    <T> T chooseRandomly(T... choices) {
704 +        return choices[ThreadLocalRandom.current().nextInt(choices.length)];
705 +    }
706 +
707 +    /**
708       * Returns the shortest timed delay. This can be scaled up for
709       * slow machines using the jsr166.delay.factor system property,
710       * or via jtreg's -timeoutFactor: flag.
# Line 693 | Line 722 | public class JSR166TestCase extends Test
722          SMALL_DELAY_MS  = SHORT_DELAY_MS * 5;
723          MEDIUM_DELAY_MS = SHORT_DELAY_MS * 10;
724          LONG_DELAY_MS   = SHORT_DELAY_MS * 200;
725 +        LONGER_DELAY_MS = 2 * LONG_DELAY_MS;
726      }
727  
728      private static final long TIMEOUT_DELAY_MS
# Line 731 | Line 761 | public class JSR166TestCase extends Test
761       */
762      public void threadRecordFailure(Throwable t) {
763          System.err.println(t);
764 <        dumpTestThreads();
765 <        threadFailure.compareAndSet(null, t);
764 >        if (threadFailure.compareAndSet(null, t))
765 >            dumpTestThreads();
766      }
767  
768      public void setUp() {
# Line 1076 | Line 1106 | public class JSR166TestCase extends Test
1106                  continue;
1107              if ("Reference Handler".equals(name)
1108                  && (lockName = info.getLockName()) != null
1109 <                && lockName.startsWith("java.lang.ref.Reference$Lock"))
1109 >                && lockName.startsWith("java.lang.ref"))
1110                  continue;
1111 <            if ("Finalizer".equals(name)
1111 >            if (("Finalizer".equals(name) || "Common-Cleaner".equals(name))
1112                  && (lockName = info.getLockName()) != null
1113 <                && lockName.startsWith("java.lang.ref.ReferenceQueue$Lock"))
1113 >                && lockName.startsWith("java.lang.ref"))
1114                  continue;
1115 <            if ("checkForWedgedTest".equals(name))
1115 >            if ("WedgedTestDetector".equals(name))
1116                  continue;
1117              System.err.print(info);
1118          }
# Line 1358 | Line 1388 | public class JSR166TestCase extends Test
1388      }
1389  
1390      /**
1391 +     * Spin-waits up to LONG_DELAY_MS milliseconds for the current thread to
1392 +     * be interrupted.  Clears the interrupt status before returning.
1393 +     */
1394 +    void awaitInterrupted() {
1395 +        for (long startTime = 0L; !Thread.interrupted(); ) {
1396 +            if (startTime == 0L)
1397 +                startTime = System.nanoTime();
1398 +            else if (millisElapsedSince(startTime) > LONG_DELAY_MS)
1399 +                fail("timed out waiting for thread interrupt");
1400 +            Thread.yield();
1401 +        }
1402 +    }
1403 +
1404 +    /**
1405       * Returns the number of milliseconds since time given by
1406       * startNanoTime, which must have been previously returned from a
1407       * call to {@link System#nanoTime()}.
# Line 1366 | Line 1410 | public class JSR166TestCase extends Test
1410          return NANOSECONDS.toMillis(System.nanoTime() - startNanoTime);
1411      }
1412  
1369 //     void assertTerminatesPromptly(long timeoutMillis, Runnable r) {
1370 //         long startTime = System.nanoTime();
1371 //         try {
1372 //             r.run();
1373 //         } catch (Throwable fail) { threadUnexpectedException(fail); }
1374 //         if (millisElapsedSince(startTime) > timeoutMillis/2)
1375 //             throw new AssertionError("did not return promptly");
1376 //     }
1377
1378 //     void assertTerminatesPromptly(Runnable r) {
1379 //         assertTerminatesPromptly(LONG_DELAY_MS/2, r);
1380 //     }
1381
1413      /**
1414       * Checks that timed f.get() returns the expected value, and does not
1415       * wait for the timeout to elapse before returning.
# Line 1413 | Line 1444 | public class JSR166TestCase extends Test
1444       * to terminate (using {@link Thread#join(long)}), else interrupts
1445       * the thread (in the hope that it may terminate later) and fails.
1446       */
1447 <    void awaitTermination(Thread t, long timeoutMillis) {
1447 >    void awaitTermination(Thread thread, long timeoutMillis) {
1448          try {
1449 <            t.join(timeoutMillis);
1449 >            thread.join(timeoutMillis);
1450          } catch (InterruptedException fail) {
1451              threadUnexpectedException(fail);
1452 <        } finally {
1453 <            if (t.getState() != Thread.State.TERMINATED) {
1454 <                t.interrupt();
1455 <                threadFail("timed out waiting for thread to terminate");
1452 >        }
1453 >        if (thread.getState() != Thread.State.TERMINATED) {
1454 >            String detail = String.format(
1455 >                    "timed out waiting for thread to terminate, thread=%s, state=%s" ,
1456 >                    thread, thread.getState());
1457 >            try {
1458 >                threadFail(detail);
1459 >            } finally {
1460 >                // Interrupt thread __after__ having reported its stack trace
1461 >                thread.interrupt();
1462              }
1463          }
1464      }
# Line 1743 | Line 1780 | public class JSR166TestCase extends Test
1780          }
1781      }
1782  
1783 <    void assertImmutable(final Object o) {
1783 >    void assertImmutable(Object o) {
1784          if (o instanceof Collection) {
1785              assertThrows(
1786                  UnsupportedOperationException.class,
1787 <                new Runnable() { public void run() {
1751 <                        ((Collection) o).add(null);}});
1787 >                () -> ((Collection) o).add(null));
1788          }
1789      }
1790  
# Line 1808 | Line 1844 | public class JSR166TestCase extends Test
1844      }
1845  
1846      public void assertThrows(Class<? extends Throwable> expectedExceptionClass,
1847 <                             Runnable... throwingActions) {
1848 <        for (Runnable throwingAction : throwingActions) {
1847 >                             Action... throwingActions) {
1848 >        for (Action throwingAction : throwingActions) {
1849              boolean threw = false;
1850              try { throwingAction.run(); }
1851              catch (Throwable t) {

Diff Legend

Removed lines
+ Added lines
< Changed lines
> Changed lines