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.172 by jsr166, Fri Oct 9 01:26:36 2015 UTC vs.
Revision 1.180 by jsr166, Mon Nov 9 05:43:39 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 193 | Line 192 | public class JSR166TestCase extends Test
192  
193      // Instrumentation to debug very rare, but very annoying hung test runs.
194      static volatile TestCase currentTestCase;
195 <    static volatile int currentRun = 0;
195 >    // static volatile int currentRun = 0;
196      static {
197          Runnable checkForWedgedTest = new Runnable() { public void run() {
198 <            // avoid spurious reports with enormous runsPerTest
199 <            final int timeoutMinutes = Math.max(runsPerTest / 10, 1);
198 >            // Avoid spurious reports with enormous runsPerTest.
199 >            // A single test case run should never take more than 1 second.
200 >            // But let's cap it at the high end too ...
201 >            final int timeoutMinutes =
202 >                Math.min(15, Math.max(runsPerTest / 60, 1));
203              for (TestCase lastTestCase = currentTestCase;;) {
204                  try { MINUTES.sleep(timeoutMinutes); }
205                  catch (InterruptedException unexpected) { break; }
206                  if (lastTestCase == currentTestCase) {
207                      System.err.printf(
208 <                        "Looks like we're stuck running test: %s (%d/%d)%n",
209 <                        lastTestCase, currentRun, runsPerTest);
210 <                    System.err.println("availableProcessors=" +
211 <                        Runtime.getRuntime().availableProcessors());
212 <                    System.err.printf("cpu model = %s%n", cpuModel());
208 >                        "Looks like we're stuck running test: %s%n",
209 >                        lastTestCase);
210 > //                     System.err.printf(
211 > //                         "Looks like we're stuck running test: %s (%d/%d)%n",
212 > //                         lastTestCase, currentRun, runsPerTest);
213 > //                     System.err.println("availableProcessors=" +
214 > //                         Runtime.getRuntime().availableProcessors());
215 > //                     System.err.printf("cpu model = %s%n", cpuModel());
216                      dumpTestThreads();
217                      // one stack dump is probably enough; more would be spam
218                      break;
# Line 219 | Line 224 | public class JSR166TestCase extends Test
224          thread.start();
225      }
226  
227 <    public static String cpuModel() {
228 <        try {
229 <            Matcher matcher = Pattern.compile("model name\\s*: (.*)")
230 <                .matcher(new String(
231 <                     Files.readAllBytes(Paths.get("/proc/cpuinfo")), "UTF-8"));
232 <            matcher.find();
233 <            return matcher.group(1);
234 <        } catch (Exception ex) { return null; }
235 <    }
227 > //     public static String cpuModel() {
228 > //         try {
229 > //             Matcher matcher = Pattern.compile("model name\\s*: (.*)")
230 > //                 .matcher(new String(
231 > //                      Files.readAllBytes(Paths.get("/proc/cpuinfo")), "UTF-8"));
232 > //             matcher.find();
233 > //             return matcher.group(1);
234 > //         } catch (Exception ex) { return null; }
235 > //     }
236  
237      public void runBare() throws Throwable {
238          currentTestCase = this;
# Line 238 | Line 243 | public class JSR166TestCase extends Test
243  
244      protected void runTest() throws Throwable {
245          for (int i = 0; i < runsPerTest; i++) {
246 <            currentRun = i;
246 >            // currentRun = i;
247              if (profileTests)
248                  runTestProfiled();
249              else
# Line 267 | Line 272 | public class JSR166TestCase extends Test
272          main(suite(), args);
273      }
274  
275 +    static class PithyResultPrinter extends junit.textui.ResultPrinter {
276 +        PithyResultPrinter(java.io.PrintStream writer) { super(writer); }
277 +        long runTime;
278 +        public void startTest(Test test) {}
279 +        protected void printHeader(long runTime) {
280 +            this.runTime = runTime; // defer printing for later
281 +        }
282 +        protected void printFooter(TestResult result) {
283 +            if (result.wasSuccessful()) {
284 +                getWriter().println("OK (" + result.runCount() + " tests)"
285 +                    + "  Time: " + elapsedTimeAsString(runTime));
286 +            } else {
287 +                getWriter().println("Time: " + elapsedTimeAsString(runTime));
288 +                super.printFooter(result);
289 +            }
290 +        }
291 +    }
292 +
293 +    /**
294 +     * Returns a TestRunner that doesn't bother with unnecessary
295 +     * fluff, like printing a "." for each test case.
296 +     */
297 +    static junit.textui.TestRunner newPithyTestRunner() {
298 +        junit.textui.TestRunner runner = new junit.textui.TestRunner();
299 +        runner.setPrinter(new PithyResultPrinter(System.out));
300 +        return runner;
301 +    }
302 +
303      /**
304       * Runs all unit tests in the given test suite.
305       * Actual behavior influenced by jsr166.* system properties.
# Line 278 | Line 311 | public class JSR166TestCase extends Test
311              System.setSecurityManager(new SecurityManager());
312          }
313          for (int i = 0; i < suiteRuns; i++) {
314 <            TestResult result = junit.textui.TestRunner.run(suite);
314 >            TestResult result = newPithyTestRunner().doRun(suite);
315              if (!result.wasSuccessful())
316                  System.exit(1);
317              System.gc();
# Line 1222 | Line 1255 | public class JSR166TestCase extends Test
1255          } finally {
1256              if (t.getState() != Thread.State.TERMINATED) {
1257                  t.interrupt();
1258 <                threadFail("Test timed out");
1258 >                threadFail("timed out waiting for thread to terminate");
1259              }
1260          }
1261      }
# Line 1390 | Line 1423 | public class JSR166TestCase extends Test
1423  
1424      public void await(CountDownLatch latch) {
1425          try {
1426 <            assertTrue(latch.await(LONG_DELAY_MS, MILLISECONDS));
1426 >            if (!latch.await(LONG_DELAY_MS, MILLISECONDS))
1427 >                fail("timed out waiting for CountDownLatch for "
1428 >                     + (LONG_DELAY_MS/1000) + " sec");
1429          } catch (Throwable fail) {
1430              threadUnexpectedException(fail);
1431          }
# Line 1398 | Line 1433 | public class JSR166TestCase extends Test
1433  
1434      public void await(Semaphore semaphore) {
1435          try {
1436 <            assertTrue(semaphore.tryAcquire(LONG_DELAY_MS, MILLISECONDS));
1436 >            if (!semaphore.tryAcquire(LONG_DELAY_MS, MILLISECONDS))
1437 >                fail("timed out waiting for Semaphore for "
1438 >                     + (LONG_DELAY_MS/1000) + " sec");
1439          } catch (Throwable fail) {
1440              threadUnexpectedException(fail);
1441          }

Diff Legend

Removed lines
+ Added lines
< Changed lines
> Changed lines