8 |
|
|
9 |
|
/* |
10 |
|
* @test |
11 |
< |
* @summary JSR-166 tck tests |
11 |
> |
* @summary JSR-166 tck tests (conformance testing mode) |
12 |
> |
* @build * |
13 |
|
* @modules java.management |
14 |
+ |
* @run junit/othervm/timeout=1000 JSR166TestCase |
15 |
+ |
*/ |
16 |
+ |
|
17 |
+ |
/* |
18 |
+ |
* @test |
19 |
+ |
* @summary JSR-166 tck tests (whitebox tests allowed) |
20 |
|
* @build * |
21 |
< |
* @run junit/othervm/timeout=1000 -Djsr166.testImplementationDetails=true JSR166TestCase |
22 |
< |
* @run junit/othervm/timeout=1000 -Djava.util.concurrent.ForkJoinPool.common.parallelism=0 -Djsr166.testImplementationDetails=true JSR166TestCase |
23 |
< |
* @run junit/othervm/timeout=1000 -Djava.util.concurrent.ForkJoinPool.common.parallelism=1 -Djava.util.secureRandomSeed=true JSR166TestCase |
21 |
> |
* @modules java.base/java.util.concurrent:open |
22 |
> |
* java.base/java.lang:open |
23 |
> |
* java.management |
24 |
> |
* @run junit/othervm/timeout=1000 |
25 |
> |
* -Djsr166.testImplementationDetails=true |
26 |
> |
* JSR166TestCase |
27 |
> |
* @run junit/othervm/timeout=1000 |
28 |
> |
* -Djsr166.testImplementationDetails=true |
29 |
> |
* -Djava.util.concurrent.ForkJoinPool.common.parallelism=0 |
30 |
> |
* JSR166TestCase |
31 |
> |
* @run junit/othervm/timeout=1000 |
32 |
> |
* -Djsr166.testImplementationDetails=true |
33 |
> |
* -Djava.util.concurrent.ForkJoinPool.common.parallelism=1 |
34 |
> |
* -Djava.util.secureRandomSeed=true |
35 |
> |
* JSR166TestCase |
36 |
> |
* @run junit/othervm/timeout=1000/policy=tck.policy |
37 |
> |
* -Djsr166.testImplementationDetails=true |
38 |
> |
* JSR166TestCase |
39 |
|
*/ |
40 |
|
|
41 |
|
import static java.util.concurrent.TimeUnit.MILLISECONDS; |
52 |
|
import java.lang.reflect.Constructor; |
53 |
|
import java.lang.reflect.Method; |
54 |
|
import java.lang.reflect.Modifier; |
33 |
– |
import java.nio.file.Files; |
34 |
– |
import java.nio.file.Paths; |
55 |
|
import java.security.CodeSource; |
56 |
|
import java.security.Permission; |
57 |
|
import java.security.PermissionCollection; |
61 |
|
import java.security.SecurityPermission; |
62 |
|
import java.util.ArrayList; |
63 |
|
import java.util.Arrays; |
64 |
+ |
import java.util.Collection; |
65 |
|
import java.util.Collections; |
66 |
|
import java.util.Date; |
67 |
|
import java.util.Enumeration; |
89 |
|
import java.util.concurrent.TimeoutException; |
90 |
|
import java.util.concurrent.atomic.AtomicBoolean; |
91 |
|
import java.util.concurrent.atomic.AtomicReference; |
71 |
– |
import java.util.regex.Matcher; |
92 |
|
import java.util.regex.Pattern; |
93 |
|
|
94 |
|
import junit.framework.AssertionFailedError; |
298 |
|
|
299 |
|
// public static String cpuModel() { |
300 |
|
// try { |
301 |
< |
// Matcher matcher = Pattern.compile("model name\\s*: (.*)") |
301 |
> |
// java.util.regex.Matcher matcher |
302 |
> |
// = Pattern.compile("model name\\s*: (.*)") |
303 |
|
// .matcher(new String( |
304 |
< |
// Files.readAllBytes(Paths.get("/proc/cpuinfo")), "UTF-8")); |
304 |
> |
// java.nio.file.Files.readAllBytes( |
305 |
> |
// java.nio.file.Paths.get("/proc/cpuinfo")), "UTF-8")); |
306 |
|
// matcher.find(); |
307 |
|
// return matcher.group(1); |
308 |
|
// } catch (Exception ex) { return null; } |
521 |
|
TreeMapTest.suite(), |
522 |
|
TreeSetTest.suite(), |
523 |
|
TreeSubMapTest.suite(), |
524 |
< |
TreeSubSetTest.suite()); |
524 |
> |
TreeSubSetTest.suite(), |
525 |
> |
VectorTest.suite()); |
526 |
|
|
527 |
|
// Java8+ test classes |
528 |
|
if (atLeastJava8()) { |
536 |
|
"DoubleAdderTest", |
537 |
|
"ForkJoinPool8Test", |
538 |
|
"ForkJoinTask8Test", |
539 |
+ |
"LinkedBlockingDeque8Test", |
540 |
+ |
"LinkedBlockingQueue8Test", |
541 |
|
"LongAccumulatorTest", |
542 |
|
"LongAdderTest", |
543 |
|
"SplittableRandomTest", |
560 |
|
"AtomicReference9Test", |
561 |
|
"AtomicReferenceArray9Test", |
562 |
|
"ExecutorCompletionService9Test", |
563 |
+ |
"ForkJoinPool9Test", |
564 |
|
}; |
565 |
|
addNamedTestClasses(suite, java9TestClassNames); |
566 |
|
} |
571 |
|
/** Returns list of junit-style test method names in given class. */ |
572 |
|
public static ArrayList<String> testMethodNames(Class<?> testClass) { |
573 |
|
Method[] methods = testClass.getDeclaredMethods(); |
574 |
< |
ArrayList<String> names = new ArrayList<String>(methods.length); |
574 |
> |
ArrayList<String> names = new ArrayList<>(methods.length); |
575 |
|
for (Method method : methods) { |
576 |
|
if (method.getName().startsWith("test") |
577 |
|
&& Modifier.isPublic(method.getModifiers()) |
677 |
|
* The first exception encountered if any threadAssertXXX method fails. |
678 |
|
*/ |
679 |
|
private final AtomicReference<Throwable> threadFailure |
680 |
< |
= new AtomicReference<Throwable>(null); |
680 |
> |
= new AtomicReference<>(null); |
681 |
|
|
682 |
|
/** |
683 |
|
* Records an exception so that it can be rethrown later in the test |
1239 |
|
} |
1240 |
|
public void refresh() {} |
1241 |
|
public String toString() { |
1242 |
< |
List<Permission> ps = new ArrayList<Permission>(); |
1242 |
> |
List<Permission> ps = new ArrayList<>(); |
1243 |
|
for (Enumeration<Permission> e = perms.elements(); e.hasMoreElements();) |
1244 |
|
ps.add(e.nextElement()); |
1245 |
|
return "AdjustablePolicy with permissions " + ps; |
1298 |
|
startTime = System.nanoTime(); |
1299 |
|
else if (millisElapsedSince(startTime) > timeoutMillis) { |
1300 |
|
threadAssertTrue(thread.isAlive()); |
1301 |
< |
return; |
1301 |
> |
fail("timed out waiting for thread to enter wait state"); |
1302 |
> |
} |
1303 |
> |
Thread.yield(); |
1304 |
> |
} |
1305 |
> |
} |
1306 |
> |
|
1307 |
> |
/** |
1308 |
> |
* Spin-waits up to the specified number of milliseconds for the given |
1309 |
> |
* thread to enter a wait state: BLOCKED, WAITING, or TIMED_WAITING, |
1310 |
> |
* and additionally satisfy the given condition. |
1311 |
> |
*/ |
1312 |
> |
void waitForThreadToEnterWaitState( |
1313 |
> |
Thread thread, long timeoutMillis, Callable<Boolean> waitingForGodot) { |
1314 |
> |
long startTime = 0L; |
1315 |
> |
for (;;) { |
1316 |
> |
Thread.State s = thread.getState(); |
1317 |
> |
if (s == Thread.State.BLOCKED || |
1318 |
> |
s == Thread.State.WAITING || |
1319 |
> |
s == Thread.State.TIMED_WAITING) { |
1320 |
> |
try { |
1321 |
> |
if (waitingForGodot.call()) |
1322 |
> |
return; |
1323 |
> |
} catch (Throwable fail) { threadUnexpectedException(fail); } |
1324 |
> |
} |
1325 |
> |
else if (s == Thread.State.TERMINATED) |
1326 |
> |
fail("Unexpected thread termination"); |
1327 |
> |
else if (startTime == 0L) |
1328 |
> |
startTime = System.nanoTime(); |
1329 |
> |
else if (millisElapsedSince(startTime) > timeoutMillis) { |
1330 |
> |
threadAssertTrue(thread.isAlive()); |
1331 |
> |
fail("timed out waiting for thread to enter wait state"); |
1332 |
|
} |
1333 |
|
Thread.yield(); |
1334 |
|
} |
1335 |
|
} |
1336 |
|
|
1337 |
|
/** |
1338 |
< |
* Waits up to LONG_DELAY_MS for the given thread to enter a wait |
1339 |
< |
* state: BLOCKED, WAITING, or TIMED_WAITING. |
1338 |
> |
* Spin-waits up to LONG_DELAY_MS milliseconds for the given thread to |
1339 |
> |
* enter a wait state: BLOCKED, WAITING, or TIMED_WAITING. |
1340 |
|
*/ |
1341 |
|
void waitForThreadToEnterWaitState(Thread thread) { |
1342 |
|
waitForThreadToEnterWaitState(thread, LONG_DELAY_MS); |
1343 |
|
} |
1344 |
|
|
1345 |
|
/** |
1346 |
+ |
* Spin-waits up to LONG_DELAY_MS milliseconds for the given thread to |
1347 |
+ |
* enter a wait state: BLOCKED, WAITING, or TIMED_WAITING, |
1348 |
+ |
* and additionally satisfy the given condition. |
1349 |
+ |
*/ |
1350 |
+ |
void waitForThreadToEnterWaitState( |
1351 |
+ |
Thread thread, Callable<Boolean> waitingForGodot) { |
1352 |
+ |
waitForThreadToEnterWaitState(thread, LONG_DELAY_MS, waitingForGodot); |
1353 |
+ |
} |
1354 |
+ |
|
1355 |
+ |
/** |
1356 |
|
* Returns the number of milliseconds since time given by |
1357 |
|
* startNanoTime, which must have been previously returned from a |
1358 |
|
* call to {@link System#nanoTime()}. |
1892 |
|
} |
1893 |
|
} |
1894 |
|
|
1895 |
+ |
void assertImmutable(final Object o) { |
1896 |
+ |
if (o instanceof Collection) { |
1897 |
+ |
assertThrows( |
1898 |
+ |
UnsupportedOperationException.class, |
1899 |
+ |
new Runnable() { public void run() { |
1900 |
+ |
((Collection) o).add(null);}}); |
1901 |
+ |
} |
1902 |
+ |
} |
1903 |
+ |
|
1904 |
|
@SuppressWarnings("unchecked") |
1905 |
|
<T> T serialClone(T o) { |
1906 |
|
try { |
1907 |
|
ObjectInputStream ois = new ObjectInputStream |
1908 |
|
(new ByteArrayInputStream(serialBytes(o))); |
1909 |
|
T clone = (T) ois.readObject(); |
1910 |
+ |
if (o == clone) assertImmutable(o); |
1911 |
|
assertSame(o.getClass(), clone.getClass()); |
1912 |
|
return clone; |
1913 |
|
} catch (Throwable fail) { |
1916 |
|
} |
1917 |
|
} |
1918 |
|
|
1919 |
+ |
/** |
1920 |
+ |
* A version of serialClone that leaves error handling (for |
1921 |
+ |
* e.g. NotSerializableException) up to the caller. |
1922 |
+ |
*/ |
1923 |
+ |
@SuppressWarnings("unchecked") |
1924 |
+ |
<T> T serialClonePossiblyFailing(T o) |
1925 |
+ |
throws ReflectiveOperationException, java.io.IOException { |
1926 |
+ |
ByteArrayOutputStream bos = new ByteArrayOutputStream(); |
1927 |
+ |
ObjectOutputStream oos = new ObjectOutputStream(bos); |
1928 |
+ |
oos.writeObject(o); |
1929 |
+ |
oos.flush(); |
1930 |
+ |
oos.close(); |
1931 |
+ |
ObjectInputStream ois = new ObjectInputStream |
1932 |
+ |
(new ByteArrayInputStream(bos.toByteArray())); |
1933 |
+ |
T clone = (T) ois.readObject(); |
1934 |
+ |
if (o == clone) assertImmutable(o); |
1935 |
+ |
assertSame(o.getClass(), clone.getClass()); |
1936 |
+ |
return clone; |
1937 |
+ |
} |
1938 |
+ |
|
1939 |
+ |
/** |
1940 |
+ |
* If o implements Cloneable and has a public clone method, |
1941 |
+ |
* returns a clone of o, else null. |
1942 |
+ |
*/ |
1943 |
+ |
@SuppressWarnings("unchecked") |
1944 |
+ |
<T> T cloneableClone(T o) { |
1945 |
+ |
if (!(o instanceof Cloneable)) return null; |
1946 |
+ |
final T clone; |
1947 |
+ |
try { |
1948 |
+ |
clone = (T) o.getClass().getMethod("clone").invoke(o); |
1949 |
+ |
} catch (NoSuchMethodException ok) { |
1950 |
+ |
return null; |
1951 |
+ |
} catch (ReflectiveOperationException unexpected) { |
1952 |
+ |
throw new Error(unexpected); |
1953 |
+ |
} |
1954 |
+ |
assertNotSame(o, clone); // not 100% guaranteed by spec |
1955 |
+ |
assertSame(o.getClass(), clone.getClass()); |
1956 |
+ |
return clone; |
1957 |
+ |
} |
1958 |
+ |
|
1959 |
|
public void assertThrows(Class<? extends Throwable> expectedExceptionClass, |
1960 |
|
Runnable... throwingActions) { |
1961 |
|
for (Runnable throwingAction : throwingActions) { |