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.176 by jsr166, Mon Oct 12 07:16:39 2015 UTC vs.
Revision 1.184 by jsr166, Wed Feb 10 00:05:20 2016 UTC

# Line 6 | Line 6
6   * Pat Fisher, Mike Judd.
7   */
8  
9 + /*
10 + * @test
11 + * @summary JSR-166 tck tests
12 + * @modules java.management
13 + * @build *
14 + * @run junit/othervm/timeout=1000 -Djsr166.testImplementationDetails=true JSR166TestCase
15 + */
16 +
17   import static java.util.concurrent.TimeUnit.MILLISECONDS;
18   import static java.util.concurrent.TimeUnit.MINUTES;
19   import static java.util.concurrent.TimeUnit.NANOSECONDS;
# Line 112 | Line 120 | import junit.framework.TestSuite;
120   * methods as there are exceptions the method can throw. Sometimes
121   * there are multiple tests per JSR166 method when the different
122   * "normal" behaviors differ significantly. And sometimes testcases
123 < * cover multiple methods when they cannot be tested in
116 < * isolation.
123 > * cover multiple methods when they cannot be tested in isolation.
124   *
125   * <li>The documentation style for testcases is to provide as javadoc
126   * a simple sentence or two describing the property that the testcase
# Line 176 | Line 183 | public class JSR166TestCase extends Test
183      private static final int suiteRuns =
184          Integer.getInteger("jsr166.suiteRuns", 1);
185  
186 +    /**
187 +     * The scaling factor to apply to standard delays used in tests.
188 +     */
189 +    private static final int delayFactor =
190 +        Integer.getInteger("jsr166.delay.factor", 1);
191 +
192      public JSR166TestCase() { super(); }
193      public JSR166TestCase(String name) { super(name); }
194  
# Line 273 | Line 286 | public class JSR166TestCase extends Test
286          main(suite(), args);
287      }
288  
289 +    static class PithyResultPrinter extends junit.textui.ResultPrinter {
290 +        PithyResultPrinter(java.io.PrintStream writer) { super(writer); }
291 +        long runTime;
292 +        public void startTest(Test test) {}
293 +        protected void printHeader(long runTime) {
294 +            this.runTime = runTime; // defer printing for later
295 +        }
296 +        protected void printFooter(TestResult result) {
297 +            if (result.wasSuccessful()) {
298 +                getWriter().println("OK (" + result.runCount() + " tests)"
299 +                    + "  Time: " + elapsedTimeAsString(runTime));
300 +            } else {
301 +                getWriter().println("Time: " + elapsedTimeAsString(runTime));
302 +                super.printFooter(result);
303 +            }
304 +        }
305 +    }
306 +
307 +    /**
308 +     * Returns a TestRunner that doesn't bother with unnecessary
309 +     * fluff, like printing a "." for each test case.
310 +     */
311 +    static junit.textui.TestRunner newPithyTestRunner() {
312 +        junit.textui.TestRunner runner = new junit.textui.TestRunner();
313 +        runner.setPrinter(new PithyResultPrinter(System.out));
314 +        return runner;
315 +    }
316 +
317      /**
318       * Runs all unit tests in the given test suite.
319       * Actual behavior influenced by jsr166.* system properties.
# Line 284 | Line 325 | public class JSR166TestCase extends Test
325              System.setSecurityManager(new SecurityManager());
326          }
327          for (int i = 0; i < suiteRuns; i++) {
328 <            TestResult result = junit.textui.TestRunner.run(suite);
328 >            TestResult result = newPithyTestRunner().doRun(suite);
329              if (!result.wasSuccessful())
330                  System.exit(1);
331              System.gc();
# Line 521 | Line 562 | public class JSR166TestCase extends Test
562      public static long LONG_DELAY_MS;
563  
564      /**
565 <     * Returns the shortest timed delay. This could
566 <     * be reimplemented to use for example a Property.
565 >     * Returns the shortest timed delay. This can be scaled up for
566 >     * slow machines using the jsr166.delay.factor system property.
567       */
568      protected long getShortDelay() {
569 <        return 50;
569 >        return 50 * delayFactor;
570      }
571  
572      /**
# Line 1228 | Line 1269 | public class JSR166TestCase extends Test
1269          } finally {
1270              if (t.getState() != Thread.State.TERMINATED) {
1271                  t.interrupt();
1272 <                threadFail("Test timed out");
1272 >                threadFail("timed out waiting for thread to terminate");
1273              }
1274          }
1275      }

Diff Legend

Removed lines
+ Added lines
< Changed lines
> Changed lines