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; |
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 |
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 |
|
|
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. |
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(); |
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 |
|
/** |