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.184 by jsr166, Wed Feb 10 00:05:20 2016 UTC vs.
Revision 1.196 by jsr166, Fri Jun 17 19:00:48 2016 UTC

# Line 12 | Line 12
12   * @modules java.management
13   * @build *
14   * @run junit/othervm/timeout=1000 -Djsr166.testImplementationDetails=true JSR166TestCase
15 + * @run junit/othervm/timeout=1000 -Djava.util.concurrent.ForkJoinPool.common.parallelism=0 -Djsr166.testImplementationDetails=true JSR166TestCase
16   */
17  
18   import static java.util.concurrent.TimeUnit.MILLISECONDS;
# Line 58 | Line 59 | import java.util.concurrent.RecursiveAct
59   import java.util.concurrent.RecursiveTask;
60   import java.util.concurrent.RejectedExecutionHandler;
61   import java.util.concurrent.Semaphore;
62 + import java.util.concurrent.SynchronousQueue;
63   import java.util.concurrent.ThreadFactory;
64   import java.util.concurrent.ThreadPoolExecutor;
65   import java.util.concurrent.TimeoutException;
66 + import java.util.concurrent.atomic.AtomicBoolean;
67   import java.util.concurrent.atomic.AtomicReference;
68   import java.util.regex.Matcher;
69   import java.util.regex.Pattern;
# Line 184 | Line 187 | public class JSR166TestCase extends Test
187          Integer.getInteger("jsr166.suiteRuns", 1);
188  
189      /**
190 <     * The scaling factor to apply to standard delays used in tests.
190 >     * Returns the value of the system property, or NaN if not defined.
191       */
192 <    private static final int delayFactor =
193 <        Integer.getInteger("jsr166.delay.factor", 1);
192 >    private static float systemPropertyValue(String name) {
193 >        String floatString = System.getProperty(name);
194 >        if (floatString == null)
195 >            return Float.NaN;
196 >        try {
197 >            return Float.parseFloat(floatString);
198 >        } catch (NumberFormatException ex) {
199 >            throw new IllegalArgumentException(
200 >                String.format("Bad float value in system property %s=%s",
201 >                              name, floatString));
202 >        }
203 >    }
204 >
205 >    /**
206 >     * The scaling factor to apply to standard delays used in tests.
207 >     * May be initialized from any of:
208 >     * - the "jsr166.delay.factor" system property
209 >     * - the "test.timeout.factor" system property (as used by jtreg)
210 >     *   See: http://openjdk.java.net/jtreg/tag-spec.html
211 >     * - hard-coded fuzz factor when using a known slowpoke VM
212 >     */
213 >    private static final float delayFactor = delayFactor();
214 >
215 >    private static float delayFactor() {
216 >        float x;
217 >        if (!Float.isNaN(x = systemPropertyValue("jsr166.delay.factor")))
218 >            return x;
219 >        if (!Float.isNaN(x = systemPropertyValue("test.timeout.factor")))
220 >            return x;
221 >        String prop = System.getProperty("java.vm.version");
222 >        if (prop != null && prop.matches(".*debug.*"))
223 >            return 4.0f; // How much slower is fastdebug than product?!
224 >        return 1.0f;
225 >    }
226  
227      public JSR166TestCase() { super(); }
228      public JSR166TestCase(String name) { super(name); }
# Line 478 | Line 513 | public class JSR166TestCase extends Test
513                  "StampedLockTest",
514                  "SubmissionPublisherTest",
515                  "ThreadLocalRandom8Test",
516 +                "TimeUnit8Test",
517              };
518              addNamedTestClasses(suite, java8TestClassNames);
519          }
# Line 485 | Line 521 | public class JSR166TestCase extends Test
521          // Java9+ test classes
522          if (atLeastJava9()) {
523              String[] java9TestClassNames = {
524 <                // Currently empty, but expecting varhandle tests
524 >                "AtomicBoolean9Test",
525 >                "AtomicInteger9Test",
526 >                "AtomicIntegerArray9Test",
527 >                "AtomicLong9Test",
528 >                "AtomicLongArray9Test",
529 >                "AtomicReference9Test",
530 >                "AtomicReferenceArray9Test",
531 >                "ExecutorCompletionService9Test",
532              };
533              addNamedTestClasses(suite, java9TestClassNames);
534          }
# Line 563 | Line 606 | public class JSR166TestCase extends Test
606  
607      /**
608       * Returns the shortest timed delay. This can be scaled up for
609 <     * slow machines using the jsr166.delay.factor system property.
609 >     * slow machines using the jsr166.delay.factor system property,
610 >     * or via jtreg's -timeoutFactor: flag.
611 >     * http://openjdk.java.net/jtreg/command-help.html
612       */
613      protected long getShortDelay() {
614 <        return 50 * delayFactor;
614 >        return (long) (50 * delayFactor);
615      }
616  
617      /**
# Line 879 | Line 924 | public class JSR166TestCase extends Test
924          }};
925      }
926  
927 +    PoolCleaner cleaner(ExecutorService pool, AtomicBoolean flag) {
928 +        return new PoolCleanerWithReleaser(pool, releaser(flag));
929 +    }
930 +
931 +    Runnable releaser(final AtomicBoolean flag) {
932 +        return new Runnable() { public void run() { flag.set(true); }};
933 +    }
934 +
935      /**
936       * Waits out termination of a thread pool or fails doing so.
937       */
# Line 933 | Line 986 | public class JSR166TestCase extends Test
986       * Uninteresting threads are filtered out.
987       */
988      static void dumpTestThreads() {
989 +        SecurityManager sm = System.getSecurityManager();
990 +        if (sm != null) {
991 +            try {
992 +                System.setSecurityManager(null);
993 +            } catch (SecurityException giveUp) {
994 +                return;
995 +            }
996 +        }
997 +
998          ThreadMXBean threadMXBean = ManagementFactory.getThreadMXBean();
999          System.err.println("------ stacktrace dump start ------");
1000          for (ThreadInfo info : threadMXBean.dumpAllThreads(true, true)) {
# Line 950 | Line 1012 | public class JSR166TestCase extends Test
1012              System.err.print(info);
1013          }
1014          System.err.println("------ stacktrace dump end ------");
1015 +
1016 +        if (sm != null) System.setSecurityManager(sm);
1017      }
1018  
1019      /**
# Line 1435 | Line 1499 | public class JSR166TestCase extends Test
1499          return new LatchAwaiter(latch);
1500      }
1501  
1502 <    public void await(CountDownLatch latch) {
1502 >    public void await(CountDownLatch latch, long timeoutMillis) {
1503          try {
1504 <            if (!latch.await(LONG_DELAY_MS, MILLISECONDS))
1504 >            if (!latch.await(timeoutMillis, MILLISECONDS))
1505                  fail("timed out waiting for CountDownLatch for "
1506 <                     + (LONG_DELAY_MS/1000) + " sec");
1506 >                     + (timeoutMillis/1000) + " sec");
1507          } catch (Throwable fail) {
1508              threadUnexpectedException(fail);
1509          }
1510      }
1511  
1512 +    public void await(CountDownLatch latch) {
1513 +        await(latch, LONG_DELAY_MS);
1514 +    }
1515 +
1516      public void await(Semaphore semaphore) {
1517          try {
1518              if (!semaphore.tryAcquire(LONG_DELAY_MS, MILLISECONDS))
# Line 1785 | Line 1853 | public class JSR166TestCase extends Test
1853          } catch (NoSuchElementException success) {}
1854          assertFalse(it.hasNext());
1855      }
1856 +
1857 +    public <T> Callable<T> callableThrowing(final Exception ex) {
1858 +        return new Callable<T>() { public T call() throws Exception { throw ex; }};
1859 +    }
1860 +
1861 +    public Runnable runnableThrowing(final RuntimeException ex) {
1862 +        return new Runnable() { public void run() { throw ex; }};
1863 +    }
1864 +
1865 +    /** A reusable thread pool to be shared by tests. */
1866 +    static final ExecutorService cachedThreadPool =
1867 +        new ThreadPoolExecutor(0, Integer.MAX_VALUE,
1868 +                               1000L, MILLISECONDS,
1869 +                               new SynchronousQueue<Runnable>());
1870 +
1871   }

Diff Legend

Removed lines
+ Added lines
< Changed lines
> Changed lines