26 |
|
import java.util.concurrent.atomic.AtomicReference; |
27 |
|
import static java.util.concurrent.TimeUnit.MILLISECONDS; |
28 |
|
import static java.util.concurrent.TimeUnit.NANOSECONDS; |
29 |
+ |
import java.util.regex.Pattern; |
30 |
|
import java.security.CodeSource; |
31 |
|
import java.security.Permission; |
32 |
|
import java.security.PermissionCollection; |
135 |
|
private static final int runsPerTest = |
136 |
|
Integer.getInteger("jsr166.runsPerTest", 1); |
137 |
|
|
138 |
+ |
/** |
139 |
+ |
* A filter for tests to run, matching strings of the form |
140 |
+ |
* methodName(className), e.g. "testInvokeAll5(ForkJoinPoolTest)" |
141 |
+ |
* Usefully combined with jsr166.runsPerTest. |
142 |
+ |
*/ |
143 |
+ |
private static final Pattern methodFilter = methodFilter(); |
144 |
+ |
|
145 |
+ |
private static Pattern methodFilter() { |
146 |
+ |
String regex = System.getProperty("jsr166.methodFilter"); |
147 |
+ |
return (regex == null) ? null : Pattern.compile(regex); |
148 |
+ |
} |
149 |
+ |
|
150 |
|
protected void runTest() throws Throwable { |
151 |
< |
for (int i = 0; i < runsPerTest; i++) { |
152 |
< |
if (profileTests) |
153 |
< |
runTestProfiled(); |
154 |
< |
else |
155 |
< |
super.runTest(); |
151 |
> |
if (methodFilter == null |
152 |
> |
|| methodFilter.matcher(toString()).find()) { |
153 |
> |
for (int i = 0; i < runsPerTest; i++) { |
154 |
> |
if (profileTests) |
155 |
> |
runTestProfiled(); |
156 |
> |
else |
157 |
> |
super.runTest(); |
158 |
> |
} |
159 |
|
} |
160 |
|
} |
161 |
|
|
162 |
|
protected void runTestProfiled() throws Throwable { |
163 |
+ |
// Warmup run, notably to trigger all needed classloading. |
164 |
+ |
super.runTest(); |
165 |
|
long t0 = System.nanoTime(); |
166 |
|
try { |
167 |
|
super.runTest(); |
168 |
|
} finally { |
169 |
< |
long elapsedMillis = |
152 |
< |
(System.nanoTime() - t0) / (1000L * 1000L); |
169 |
> |
long elapsedMillis = millisElapsedSince(t0); |
170 |
|
if (elapsedMillis >= profileThreshold) |
171 |
|
System.out.printf("%n%s: %d%n", toString(), elapsedMillis); |
172 |
|
} |
222 |
|
} |
223 |
|
|
224 |
|
public static final double JAVA_CLASS_VERSION; |
225 |
+ |
public static final String JAVA_SPECIFICATION_VERSION; |
226 |
|
static { |
227 |
|
try { |
228 |
|
JAVA_CLASS_VERSION = java.security.AccessController.doPrivileged( |
229 |
|
new java.security.PrivilegedAction<Double>() { |
230 |
|
public Double run() { |
231 |
|
return Double.valueOf(System.getProperty("java.class.version"));}}); |
232 |
+ |
JAVA_SPECIFICATION_VERSION = java.security.AccessController.doPrivileged( |
233 |
+ |
new java.security.PrivilegedAction<String>() { |
234 |
+ |
public String run() { |
235 |
+ |
return System.getProperty("java.specification.version");}}); |
236 |
|
} catch (Throwable t) { |
237 |
|
throw new Error(t); |
238 |
|
} |
241 |
|
public static boolean atLeastJava6() { return JAVA_CLASS_VERSION >= 50.0; } |
242 |
|
public static boolean atLeastJava7() { return JAVA_CLASS_VERSION >= 51.0; } |
243 |
|
public static boolean atLeastJava8() { return JAVA_CLASS_VERSION >= 52.0; } |
244 |
+ |
public static boolean atLeastJava9() { |
245 |
+ |
// As of 2014-05, java9 still uses 52.0 class file version |
246 |
+ |
return JAVA_SPECIFICATION_VERSION.startsWith("1.9"); |
247 |
+ |
} |
248 |
|
|
249 |
|
/** |
250 |
|
* Collects all JSR166 unit tests as one suite. |
320 |
|
// Java8+ test classes |
321 |
|
if (atLeastJava8()) { |
322 |
|
String[] java8TestClassNames = { |
323 |
+ |
"Atomic8Test", |
324 |
|
"CompletableFutureTest", |
325 |
|
"ConcurrentHashMap8Test", |
326 |
|
"CountedCompleterTest", |
327 |
|
"DoubleAccumulatorTest", |
328 |
|
"DoubleAdderTest", |
329 |
|
"ForkJoinPool8Test", |
330 |
+ |
"ForkJoinTask8Test", |
331 |
|
"LongAccumulatorTest", |
332 |
|
"LongAdderTest", |
333 |
+ |
"SplittableRandomTest", |
334 |
|
"StampedLockTest", |
335 |
+ |
"ThreadLocalRandom8Test", |
336 |
|
}; |
337 |
|
addNamedTestClasses(suite, java8TestClassNames); |
338 |
|
} |
339 |
|
|
340 |
+ |
// Java9+ test classes |
341 |
+ |
if (atLeastJava9()) { |
342 |
+ |
String[] java9TestClassNames = { |
343 |
+ |
"ThreadPoolExecutor9Test", |
344 |
+ |
}; |
345 |
+ |
addNamedTestClasses(suite, java9TestClassNames); |
346 |
+ |
} |
347 |
+ |
|
348 |
|
return suite; |
349 |
|
} |
350 |
|
|
351 |
+ |
// Delays for timing-dependent tests, in milliseconds. |
352 |
|
|
353 |
|
public static long SHORT_DELAY_MS; |
354 |
|
public static long SMALL_DELAY_MS; |
355 |
|
public static long MEDIUM_DELAY_MS; |
356 |
|
public static long LONG_DELAY_MS; |
357 |
|
|
319 |
– |
|
358 |
|
/** |
359 |
|
* Returns the shortest timed delay. This could |
360 |
|
* be reimplemented to use for example a Property. |
747 |
|
public static final Integer m6 = new Integer(-6); |
748 |
|
public static final Integer m10 = new Integer(-10); |
749 |
|
|
712 |
– |
|
750 |
|
/** |
751 |
|
* Runs Runnable r with a security policy that permits precisely |
752 |
|
* the specified permissions. If there is no current security |