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.174 by jsr166, Fri Oct 9 19:09:59 2015 UTC vs.
Revision 1.181 by jsr166, Mon Nov 9 06:06:54 2015 UTC

# Line 112 | Line 112 | import junit.framework.TestSuite;
112   * methods as there are exceptions the method can throw. Sometimes
113   * there are multiple tests per JSR166 method when the different
114   * "normal" behaviors differ significantly. And sometimes testcases
115 < * cover multiple methods when they cannot be tested in
116 < * isolation.
115 > * cover multiple methods when they cannot be tested in isolation.
116   *
117   * <li>The documentation style for testcases is to provide as javadoc
118   * a simple sentence or two describing the property that the testcase
# Line 176 | Line 175 | public class JSR166TestCase extends Test
175      private static final int suiteRuns =
176          Integer.getInteger("jsr166.suiteRuns", 1);
177  
178 +    /**
179 +     * The scaling factor to apply to standard delays used in tests.
180 +     */
181 +    private static final int delayFactor =
182 +        Integer.getInteger("jsr166.delay.factor", 1);
183 +
184      public JSR166TestCase() { super(); }
185      public JSR166TestCase(String name) { super(name); }
186  
# Line 211 | Line 216 | public class JSR166TestCase extends Test
216   //                     System.err.printf(
217   //                         "Looks like we're stuck running test: %s (%d/%d)%n",
218   //                         lastTestCase, currentRun, runsPerTest);
219 <                    System.err.println("availableProcessors=" +
220 <                        Runtime.getRuntime().availableProcessors());
221 <                    System.err.printf("cpu model = %s%n", cpuModel());
219 > //                     System.err.println("availableProcessors=" +
220 > //                         Runtime.getRuntime().availableProcessors());
221 > //                     System.err.printf("cpu model = %s%n", cpuModel());
222                      dumpTestThreads();
223                      // one stack dump is probably enough; more would be spam
224                      break;
# Line 225 | Line 230 | public class JSR166TestCase extends Test
230          thread.start();
231      }
232  
233 <    public static String cpuModel() {
234 <        try {
235 <            Matcher matcher = Pattern.compile("model name\\s*: (.*)")
236 <                .matcher(new String(
237 <                     Files.readAllBytes(Paths.get("/proc/cpuinfo")), "UTF-8"));
238 <            matcher.find();
239 <            return matcher.group(1);
240 <        } catch (Exception ex) { return null; }
241 <    }
233 > //     public static String cpuModel() {
234 > //         try {
235 > //             Matcher matcher = Pattern.compile("model name\\s*: (.*)")
236 > //                 .matcher(new String(
237 > //                      Files.readAllBytes(Paths.get("/proc/cpuinfo")), "UTF-8"));
238 > //             matcher.find();
239 > //             return matcher.group(1);
240 > //         } catch (Exception ex) { return null; }
241 > //     }
242  
243      public void runBare() throws Throwable {
244          currentTestCase = this;
# Line 273 | Line 278 | public class JSR166TestCase extends Test
278          main(suite(), args);
279      }
280  
281 +    static class PithyResultPrinter extends junit.textui.ResultPrinter {
282 +        PithyResultPrinter(java.io.PrintStream writer) { super(writer); }
283 +        long runTime;
284 +        public void startTest(Test test) {}
285 +        protected void printHeader(long runTime) {
286 +            this.runTime = runTime; // defer printing for later
287 +        }
288 +        protected void printFooter(TestResult result) {
289 +            if (result.wasSuccessful()) {
290 +                getWriter().println("OK (" + result.runCount() + " tests)"
291 +                    + "  Time: " + elapsedTimeAsString(runTime));
292 +            } else {
293 +                getWriter().println("Time: " + elapsedTimeAsString(runTime));
294 +                super.printFooter(result);
295 +            }
296 +        }
297 +    }
298 +
299 +    /**
300 +     * Returns a TestRunner that doesn't bother with unnecessary
301 +     * fluff, like printing a "." for each test case.
302 +     */
303 +    static junit.textui.TestRunner newPithyTestRunner() {
304 +        junit.textui.TestRunner runner = new junit.textui.TestRunner();
305 +        runner.setPrinter(new PithyResultPrinter(System.out));
306 +        return runner;
307 +    }
308 +
309      /**
310       * Runs all unit tests in the given test suite.
311       * Actual behavior influenced by jsr166.* system properties.
# Line 284 | Line 317 | public class JSR166TestCase extends Test
317              System.setSecurityManager(new SecurityManager());
318          }
319          for (int i = 0; i < suiteRuns; i++) {
320 <            TestResult result = junit.textui.TestRunner.run(suite);
320 >            TestResult result = newPithyTestRunner().doRun(suite);
321              if (!result.wasSuccessful())
322                  System.exit(1);
323              System.gc();
# Line 521 | Line 554 | public class JSR166TestCase extends Test
554      public static long LONG_DELAY_MS;
555  
556      /**
557 <     * Returns the shortest timed delay. This could
558 <     * be reimplemented to use for example a Property.
557 >     * Returns the shortest timed delay. This can be scaled up for
558 >     * slow machines using the jsr166.delay.factor system property.
559       */
560      protected long getShortDelay() {
561 <        return 50;
561 >        return 50 * delayFactor;
562      }
563  
564      /**
# Line 1228 | Line 1261 | public class JSR166TestCase extends Test
1261          } finally {
1262              if (t.getState() != Thread.State.TERMINATED) {
1263                  t.interrupt();
1264 <                threadFail("Test timed out");
1264 >                threadFail("timed out waiting for thread to terminate");
1265              }
1266          }
1267      }
# Line 1396 | Line 1429 | public class JSR166TestCase extends Test
1429  
1430      public void await(CountDownLatch latch) {
1431          try {
1432 <            assertTrue(latch.await(LONG_DELAY_MS, MILLISECONDS));
1432 >            if (!latch.await(LONG_DELAY_MS, MILLISECONDS))
1433 >                fail("timed out waiting for CountDownLatch for "
1434 >                     + (LONG_DELAY_MS/1000) + " sec");
1435          } catch (Throwable fail) {
1436              threadUnexpectedException(fail);
1437          }
# Line 1404 | Line 1439 | public class JSR166TestCase extends Test
1439  
1440      public void await(Semaphore semaphore) {
1441          try {
1442 <            assertTrue(semaphore.tryAcquire(LONG_DELAY_MS, MILLISECONDS));
1442 >            if (!semaphore.tryAcquire(LONG_DELAY_MS, MILLISECONDS))
1443 >                fail("timed out waiting for Semaphore for "
1444 >                     + (LONG_DELAY_MS/1000) + " sec");
1445          } catch (Throwable fail) {
1446              threadUnexpectedException(fail);
1447          }

Diff Legend

Removed lines
+ Added lines
< Changed lines
> Changed lines