author | lkorinth |
Wed, 13 Nov 2019 11:37:29 +0100 | |
changeset 59053 | ba6c248cae19 |
parent 58144 | d003b3ef8b60 |
permissions | -rw-r--r-- |
34597
e5f2344c6fab
8141526: Allow to collect stdout/stderr from the FinalizationRunner even before the process returns
jbachorik
parents:
diff
changeset
|
1 |
/* |
53903
68bbd727dd5f
8219158: use 'test.root' property instead of traversing test-src path
iignatyev
parents:
51478
diff
changeset
|
2 |
* Copyright (c) 2013, 2019, Oracle and/or its affiliates. All rights reserved. |
34597
e5f2344c6fab
8141526: Allow to collect stdout/stderr from the FinalizationRunner even before the process returns
jbachorik
parents:
diff
changeset
|
3 |
* DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. |
e5f2344c6fab
8141526: Allow to collect stdout/stderr from the FinalizationRunner even before the process returns
jbachorik
parents:
diff
changeset
|
4 |
* |
e5f2344c6fab
8141526: Allow to collect stdout/stderr from the FinalizationRunner even before the process returns
jbachorik
parents:
diff
changeset
|
5 |
* This code is free software; you can redistribute it and/or modify it |
e5f2344c6fab
8141526: Allow to collect stdout/stderr from the FinalizationRunner even before the process returns
jbachorik
parents:
diff
changeset
|
6 |
* under the terms of the GNU General Public License version 2 only, as |
e5f2344c6fab
8141526: Allow to collect stdout/stderr from the FinalizationRunner even before the process returns
jbachorik
parents:
diff
changeset
|
7 |
* published by the Free Software Foundation. |
e5f2344c6fab
8141526: Allow to collect stdout/stderr from the FinalizationRunner even before the process returns
jbachorik
parents:
diff
changeset
|
8 |
* |
e5f2344c6fab
8141526: Allow to collect stdout/stderr from the FinalizationRunner even before the process returns
jbachorik
parents:
diff
changeset
|
9 |
* This code is distributed in the hope that it will be useful, but WITHOUT |
e5f2344c6fab
8141526: Allow to collect stdout/stderr from the FinalizationRunner even before the process returns
jbachorik
parents:
diff
changeset
|
10 |
* ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or |
e5f2344c6fab
8141526: Allow to collect stdout/stderr from the FinalizationRunner even before the process returns
jbachorik
parents:
diff
changeset
|
11 |
* FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License |
e5f2344c6fab
8141526: Allow to collect stdout/stderr from the FinalizationRunner even before the process returns
jbachorik
parents:
diff
changeset
|
12 |
* version 2 for more details (a copy is included in the LICENSE file that |
e5f2344c6fab
8141526: Allow to collect stdout/stderr from the FinalizationRunner even before the process returns
jbachorik
parents:
diff
changeset
|
13 |
* accompanied this code). |
e5f2344c6fab
8141526: Allow to collect stdout/stderr from the FinalizationRunner even before the process returns
jbachorik
parents:
diff
changeset
|
14 |
* |
e5f2344c6fab
8141526: Allow to collect stdout/stderr from the FinalizationRunner even before the process returns
jbachorik
parents:
diff
changeset
|
15 |
* You should have received a copy of the GNU General Public License version |
e5f2344c6fab
8141526: Allow to collect stdout/stderr from the FinalizationRunner even before the process returns
jbachorik
parents:
diff
changeset
|
16 |
* 2 along with this work; if not, write to the Free Software Foundation, |
e5f2344c6fab
8141526: Allow to collect stdout/stderr from the FinalizationRunner even before the process returns
jbachorik
parents:
diff
changeset
|
17 |
* Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA. |
e5f2344c6fab
8141526: Allow to collect stdout/stderr from the FinalizationRunner even before the process returns
jbachorik
parents:
diff
changeset
|
18 |
* |
e5f2344c6fab
8141526: Allow to collect stdout/stderr from the FinalizationRunner even before the process returns
jbachorik
parents:
diff
changeset
|
19 |
* Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA |
e5f2344c6fab
8141526: Allow to collect stdout/stderr from the FinalizationRunner even before the process returns
jbachorik
parents:
diff
changeset
|
20 |
* or visit www.oracle.com if you need additional information or have any |
e5f2344c6fab
8141526: Allow to collect stdout/stderr from the FinalizationRunner even before the process returns
jbachorik
parents:
diff
changeset
|
21 |
* questions. |
e5f2344c6fab
8141526: Allow to collect stdout/stderr from the FinalizationRunner even before the process returns
jbachorik
parents:
diff
changeset
|
22 |
*/ |
e5f2344c6fab
8141526: Allow to collect stdout/stderr from the FinalizationRunner even before the process returns
jbachorik
parents:
diff
changeset
|
23 |
|
e5f2344c6fab
8141526: Allow to collect stdout/stderr from the FinalizationRunner even before the process returns
jbachorik
parents:
diff
changeset
|
24 |
package jdk.test.lib; |
e5f2344c6fab
8141526: Allow to collect stdout/stderr from the FinalizationRunner even before the process returns
jbachorik
parents:
diff
changeset
|
25 |
|
e5f2344c6fab
8141526: Allow to collect stdout/stderr from the FinalizationRunner even before the process returns
jbachorik
parents:
diff
changeset
|
26 |
import java.io.File; |
e5f2344c6fab
8141526: Allow to collect stdout/stderr from the FinalizationRunner even before the process returns
jbachorik
parents:
diff
changeset
|
27 |
import java.io.IOException; |
58144
d003b3ef8b60
8230854: Cleanup SuppressWarnings in test lib and remove noisy traces in StreamPumper
clanger
parents:
55199
diff
changeset
|
28 |
import java.lang.annotation.Annotation; |
34597
e5f2344c6fab
8141526: Allow to collect stdout/stderr from the FinalizationRunner even before the process returns
jbachorik
parents:
diff
changeset
|
29 |
import java.net.InetAddress; |
49255
acdb8531cc8b
8199215: Re-examine getFreePort method in test infrastructure library
mli
parents:
46237
diff
changeset
|
30 |
import java.net.InetSocketAddress; |
34597
e5f2344c6fab
8141526: Allow to collect stdout/stderr from the FinalizationRunner even before the process returns
jbachorik
parents:
diff
changeset
|
31 |
import java.net.MalformedURLException; |
e5f2344c6fab
8141526: Allow to collect stdout/stderr from the FinalizationRunner even before the process returns
jbachorik
parents:
diff
changeset
|
32 |
import java.net.ServerSocket; |
e5f2344c6fab
8141526: Allow to collect stdout/stderr from the FinalizationRunner even before the process returns
jbachorik
parents:
diff
changeset
|
33 |
import java.net.URL; |
e5f2344c6fab
8141526: Allow to collect stdout/stderr from the FinalizationRunner even before the process returns
jbachorik
parents:
diff
changeset
|
34 |
import java.net.URLClassLoader; |
e5f2344c6fab
8141526: Allow to collect stdout/stderr from the FinalizationRunner even before the process returns
jbachorik
parents:
diff
changeset
|
35 |
import java.net.UnknownHostException; |
e5f2344c6fab
8141526: Allow to collect stdout/stderr from the FinalizationRunner even before the process returns
jbachorik
parents:
diff
changeset
|
36 |
import java.nio.file.Files; |
e5f2344c6fab
8141526: Allow to collect stdout/stderr from the FinalizationRunner even before the process returns
jbachorik
parents:
diff
changeset
|
37 |
import java.nio.file.Path; |
e5f2344c6fab
8141526: Allow to collect stdout/stderr from the FinalizationRunner even before the process returns
jbachorik
parents:
diff
changeset
|
38 |
import java.nio.file.Paths; |
50225
2942ae532175
8201331: Better test cleanup for jdk/jfr/api/consumer/TestRecordingFile.java
egahlin
parents:
49255
diff
changeset
|
39 |
import java.nio.file.attribute.FileAttribute; |
49255
acdb8531cc8b
8199215: Re-examine getFreePort method in test infrastructure library
mli
parents:
46237
diff
changeset
|
40 |
import java.nio.channels.SocketChannel; |
34597
e5f2344c6fab
8141526: Allow to collect stdout/stderr from the FinalizationRunner even before the process returns
jbachorik
parents:
diff
changeset
|
41 |
import java.util.ArrayList; |
e5f2344c6fab
8141526: Allow to collect stdout/stderr from the FinalizationRunner even before the process returns
jbachorik
parents:
diff
changeset
|
42 |
import java.util.Arrays; |
e5f2344c6fab
8141526: Allow to collect stdout/stderr from the FinalizationRunner even before the process returns
jbachorik
parents:
diff
changeset
|
43 |
import java.util.Collection; |
e5f2344c6fab
8141526: Allow to collect stdout/stderr from the FinalizationRunner even before the process returns
jbachorik
parents:
diff
changeset
|
44 |
import java.util.Collections; |
e5f2344c6fab
8141526: Allow to collect stdout/stderr from the FinalizationRunner even before the process returns
jbachorik
parents:
diff
changeset
|
45 |
import java.util.Iterator; |
40614
b5d80754b40e
8157957: ClassNotFoundException: jdk.test.lib.JDKToolFinder
ctornqvi
parents:
36793
diff
changeset
|
46 |
import java.util.Map; |
b5d80754b40e
8157957: ClassNotFoundException: jdk.test.lib.JDKToolFinder
ctornqvi
parents:
36793
diff
changeset
|
47 |
import java.util.HashMap; |
34597
e5f2344c6fab
8141526: Allow to collect stdout/stderr from the FinalizationRunner even before the process returns
jbachorik
parents:
diff
changeset
|
48 |
import java.util.List; |
40614
b5d80754b40e
8157957: ClassNotFoundException: jdk.test.lib.JDKToolFinder
ctornqvi
parents:
36793
diff
changeset
|
49 |
import java.util.Objects; |
34597
e5f2344c6fab
8141526: Allow to collect stdout/stderr from the FinalizationRunner even before the process returns
jbachorik
parents:
diff
changeset
|
50 |
import java.util.Random; |
e5f2344c6fab
8141526: Allow to collect stdout/stderr from the FinalizationRunner even before the process returns
jbachorik
parents:
diff
changeset
|
51 |
import java.util.function.BooleanSupplier; |
e5f2344c6fab
8141526: Allow to collect stdout/stderr from the FinalizationRunner even before the process returns
jbachorik
parents:
diff
changeset
|
52 |
import java.util.concurrent.TimeUnit; |
e5f2344c6fab
8141526: Allow to collect stdout/stderr from the FinalizationRunner even before the process returns
jbachorik
parents:
diff
changeset
|
53 |
import java.util.function.Consumer; |
e5f2344c6fab
8141526: Allow to collect stdout/stderr from the FinalizationRunner even before the process returns
jbachorik
parents:
diff
changeset
|
54 |
import java.util.function.Function; |
e5f2344c6fab
8141526: Allow to collect stdout/stderr from the FinalizationRunner even before the process returns
jbachorik
parents:
diff
changeset
|
55 |
import java.util.regex.Matcher; |
e5f2344c6fab
8141526: Allow to collect stdout/stderr from the FinalizationRunner even before the process returns
jbachorik
parents:
diff
changeset
|
56 |
import java.util.regex.Pattern; |
e5f2344c6fab
8141526: Allow to collect stdout/stderr from the FinalizationRunner even before the process returns
jbachorik
parents:
diff
changeset
|
57 |
|
e5f2344c6fab
8141526: Allow to collect stdout/stderr from the FinalizationRunner even before the process returns
jbachorik
parents:
diff
changeset
|
58 |
import static jdk.test.lib.Asserts.assertTrue; |
40614
b5d80754b40e
8157957: ClassNotFoundException: jdk.test.lib.JDKToolFinder
ctornqvi
parents:
36793
diff
changeset
|
59 |
import jdk.test.lib.process.ProcessTools; |
b5d80754b40e
8157957: ClassNotFoundException: jdk.test.lib.JDKToolFinder
ctornqvi
parents:
36793
diff
changeset
|
60 |
import jdk.test.lib.process.OutputAnalyzer; |
34597
e5f2344c6fab
8141526: Allow to collect stdout/stderr from the FinalizationRunner even before the process returns
jbachorik
parents:
diff
changeset
|
61 |
|
e5f2344c6fab
8141526: Allow to collect stdout/stderr from the FinalizationRunner even before the process returns
jbachorik
parents:
diff
changeset
|
62 |
/** |
e5f2344c6fab
8141526: Allow to collect stdout/stderr from the FinalizationRunner even before the process returns
jbachorik
parents:
diff
changeset
|
63 |
* Common library for various test helper functions. |
e5f2344c6fab
8141526: Allow to collect stdout/stderr from the FinalizationRunner even before the process returns
jbachorik
parents:
diff
changeset
|
64 |
*/ |
e5f2344c6fab
8141526: Allow to collect stdout/stderr from the FinalizationRunner even before the process returns
jbachorik
parents:
diff
changeset
|
65 |
public final class Utils { |
e5f2344c6fab
8141526: Allow to collect stdout/stderr from the FinalizationRunner even before the process returns
jbachorik
parents:
diff
changeset
|
66 |
|
e5f2344c6fab
8141526: Allow to collect stdout/stderr from the FinalizationRunner even before the process returns
jbachorik
parents:
diff
changeset
|
67 |
/** |
e5f2344c6fab
8141526: Allow to collect stdout/stderr from the FinalizationRunner even before the process returns
jbachorik
parents:
diff
changeset
|
68 |
* Returns the value of 'test.class.path' system property. |
e5f2344c6fab
8141526: Allow to collect stdout/stderr from the FinalizationRunner even before the process returns
jbachorik
parents:
diff
changeset
|
69 |
*/ |
e5f2344c6fab
8141526: Allow to collect stdout/stderr from the FinalizationRunner even before the process returns
jbachorik
parents:
diff
changeset
|
70 |
public static final String TEST_CLASS_PATH = System.getProperty("test.class.path", "."); |
e5f2344c6fab
8141526: Allow to collect stdout/stderr from the FinalizationRunner even before the process returns
jbachorik
parents:
diff
changeset
|
71 |
|
e5f2344c6fab
8141526: Allow to collect stdout/stderr from the FinalizationRunner even before the process returns
jbachorik
parents:
diff
changeset
|
72 |
/** |
e5f2344c6fab
8141526: Allow to collect stdout/stderr from the FinalizationRunner even before the process returns
jbachorik
parents:
diff
changeset
|
73 |
* Returns the sequence used by operating system to separate lines. |
e5f2344c6fab
8141526: Allow to collect stdout/stderr from the FinalizationRunner even before the process returns
jbachorik
parents:
diff
changeset
|
74 |
*/ |
e5f2344c6fab
8141526: Allow to collect stdout/stderr from the FinalizationRunner even before the process returns
jbachorik
parents:
diff
changeset
|
75 |
public static final String NEW_LINE = System.getProperty("line.separator"); |
e5f2344c6fab
8141526: Allow to collect stdout/stderr from the FinalizationRunner even before the process returns
jbachorik
parents:
diff
changeset
|
76 |
|
e5f2344c6fab
8141526: Allow to collect stdout/stderr from the FinalizationRunner even before the process returns
jbachorik
parents:
diff
changeset
|
77 |
/** |
e5f2344c6fab
8141526: Allow to collect stdout/stderr from the FinalizationRunner even before the process returns
jbachorik
parents:
diff
changeset
|
78 |
* Returns the value of 'test.vm.opts' system property. |
e5f2344c6fab
8141526: Allow to collect stdout/stderr from the FinalizationRunner even before the process returns
jbachorik
parents:
diff
changeset
|
79 |
*/ |
e5f2344c6fab
8141526: Allow to collect stdout/stderr from the FinalizationRunner even before the process returns
jbachorik
parents:
diff
changeset
|
80 |
public static final String VM_OPTIONS = System.getProperty("test.vm.opts", "").trim(); |
e5f2344c6fab
8141526: Allow to collect stdout/stderr from the FinalizationRunner even before the process returns
jbachorik
parents:
diff
changeset
|
81 |
|
e5f2344c6fab
8141526: Allow to collect stdout/stderr from the FinalizationRunner even before the process returns
jbachorik
parents:
diff
changeset
|
82 |
/** |
e5f2344c6fab
8141526: Allow to collect stdout/stderr from the FinalizationRunner even before the process returns
jbachorik
parents:
diff
changeset
|
83 |
* Returns the value of 'test.java.opts' system property. |
e5f2344c6fab
8141526: Allow to collect stdout/stderr from the FinalizationRunner even before the process returns
jbachorik
parents:
diff
changeset
|
84 |
*/ |
e5f2344c6fab
8141526: Allow to collect stdout/stderr from the FinalizationRunner even before the process returns
jbachorik
parents:
diff
changeset
|
85 |
public static final String JAVA_OPTIONS = System.getProperty("test.java.opts", "").trim(); |
e5f2344c6fab
8141526: Allow to collect stdout/stderr from the FinalizationRunner even before the process returns
jbachorik
parents:
diff
changeset
|
86 |
|
e5f2344c6fab
8141526: Allow to collect stdout/stderr from the FinalizationRunner even before the process returns
jbachorik
parents:
diff
changeset
|
87 |
/** |
e5f2344c6fab
8141526: Allow to collect stdout/stderr from the FinalizationRunner even before the process returns
jbachorik
parents:
diff
changeset
|
88 |
* Returns the value of 'test.src' system property. |
e5f2344c6fab
8141526: Allow to collect stdout/stderr from the FinalizationRunner even before the process returns
jbachorik
parents:
diff
changeset
|
89 |
*/ |
e5f2344c6fab
8141526: Allow to collect stdout/stderr from the FinalizationRunner even before the process returns
jbachorik
parents:
diff
changeset
|
90 |
public static final String TEST_SRC = System.getProperty("test.src", "").trim(); |
e5f2344c6fab
8141526: Allow to collect stdout/stderr from the FinalizationRunner even before the process returns
jbachorik
parents:
diff
changeset
|
91 |
|
53903
68bbd727dd5f
8219158: use 'test.root' property instead of traversing test-src path
iignatyev
parents:
51478
diff
changeset
|
92 |
/** |
68bbd727dd5f
8219158: use 'test.root' property instead of traversing test-src path
iignatyev
parents:
51478
diff
changeset
|
93 |
* Returns the value of 'test.root' system property. |
68bbd727dd5f
8219158: use 'test.root' property instead of traversing test-src path
iignatyev
parents:
51478
diff
changeset
|
94 |
*/ |
68bbd727dd5f
8219158: use 'test.root' property instead of traversing test-src path
iignatyev
parents:
51478
diff
changeset
|
95 |
public static final String TEST_ROOT = System.getProperty("test.root", "").trim(); |
68bbd727dd5f
8219158: use 'test.root' property instead of traversing test-src path
iignatyev
parents:
51478
diff
changeset
|
96 |
|
40846
5c77538cd897
8164608: [TESTBUG] compiler/profiling tests fail to compile
dpochepk
parents:
40614
diff
changeset
|
97 |
/* |
5c77538cd897
8164608: [TESTBUG] compiler/profiling tests fail to compile
dpochepk
parents:
40614
diff
changeset
|
98 |
* Returns the value of 'test.jdk' system property |
5c77538cd897
8164608: [TESTBUG] compiler/profiling tests fail to compile
dpochepk
parents:
40614
diff
changeset
|
99 |
*/ |
5c77538cd897
8164608: [TESTBUG] compiler/profiling tests fail to compile
dpochepk
parents:
40614
diff
changeset
|
100 |
public static final String TEST_JDK = System.getProperty("test.jdk"); |
5c77538cd897
8164608: [TESTBUG] compiler/profiling tests fail to compile
dpochepk
parents:
40614
diff
changeset
|
101 |
|
46213 | 102 |
/* |
103 |
* Returns the value of 'compile.jdk' system property |
|
104 |
*/ |
|
53903
68bbd727dd5f
8219158: use 'test.root' property instead of traversing test-src path
iignatyev
parents:
51478
diff
changeset
|
105 |
public static final String COMPILE_JDK = System.getProperty("compile.jdk", TEST_JDK); |
46213 | 106 |
|
40846
5c77538cd897
8164608: [TESTBUG] compiler/profiling tests fail to compile
dpochepk
parents:
40614
diff
changeset
|
107 |
/** |
5c77538cd897
8164608: [TESTBUG] compiler/profiling tests fail to compile
dpochepk
parents:
40614
diff
changeset
|
108 |
* Returns the value of 'test.classes' system property |
5c77538cd897
8164608: [TESTBUG] compiler/profiling tests fail to compile
dpochepk
parents:
40614
diff
changeset
|
109 |
*/ |
5c77538cd897
8164608: [TESTBUG] compiler/profiling tests fail to compile
dpochepk
parents:
40614
diff
changeset
|
110 |
public static final String TEST_CLASSES = System.getProperty("test.classes", "."); |
53903
68bbd727dd5f
8219158: use 'test.root' property instead of traversing test-src path
iignatyev
parents:
51478
diff
changeset
|
111 |
|
34597
e5f2344c6fab
8141526: Allow to collect stdout/stderr from the FinalizationRunner even before the process returns
jbachorik
parents:
diff
changeset
|
112 |
/** |
e5f2344c6fab
8141526: Allow to collect stdout/stderr from the FinalizationRunner even before the process returns
jbachorik
parents:
diff
changeset
|
113 |
* Defines property name for seed value. |
e5f2344c6fab
8141526: Allow to collect stdout/stderr from the FinalizationRunner even before the process returns
jbachorik
parents:
diff
changeset
|
114 |
*/ |
e5f2344c6fab
8141526: Allow to collect stdout/stderr from the FinalizationRunner even before the process returns
jbachorik
parents:
diff
changeset
|
115 |
public static final String SEED_PROPERTY_NAME = "jdk.test.lib.random.seed"; |
e5f2344c6fab
8141526: Allow to collect stdout/stderr from the FinalizationRunner even before the process returns
jbachorik
parents:
diff
changeset
|
116 |
|
e5f2344c6fab
8141526: Allow to collect stdout/stderr from the FinalizationRunner even before the process returns
jbachorik
parents:
diff
changeset
|
117 |
/* (non-javadoc) |
e5f2344c6fab
8141526: Allow to collect stdout/stderr from the FinalizationRunner even before the process returns
jbachorik
parents:
diff
changeset
|
118 |
* Random generator with (or without) predefined seed. Depends on |
e5f2344c6fab
8141526: Allow to collect stdout/stderr from the FinalizationRunner even before the process returns
jbachorik
parents:
diff
changeset
|
119 |
* "jdk.test.lib.random.seed" property value. |
e5f2344c6fab
8141526: Allow to collect stdout/stderr from the FinalizationRunner even before the process returns
jbachorik
parents:
diff
changeset
|
120 |
*/ |
e5f2344c6fab
8141526: Allow to collect stdout/stderr from the FinalizationRunner even before the process returns
jbachorik
parents:
diff
changeset
|
121 |
private static volatile Random RANDOM_GENERATOR; |
e5f2344c6fab
8141526: Allow to collect stdout/stderr from the FinalizationRunner even before the process returns
jbachorik
parents:
diff
changeset
|
122 |
|
e5f2344c6fab
8141526: Allow to collect stdout/stderr from the FinalizationRunner even before the process returns
jbachorik
parents:
diff
changeset
|
123 |
/** |
e5f2344c6fab
8141526: Allow to collect stdout/stderr from the FinalizationRunner even before the process returns
jbachorik
parents:
diff
changeset
|
124 |
* Contains the seed value used for {@link java.util.Random} creation. |
e5f2344c6fab
8141526: Allow to collect stdout/stderr from the FinalizationRunner even before the process returns
jbachorik
parents:
diff
changeset
|
125 |
*/ |
e5f2344c6fab
8141526: Allow to collect stdout/stderr from the FinalizationRunner even before the process returns
jbachorik
parents:
diff
changeset
|
126 |
public static final long SEED = Long.getLong(SEED_PROPERTY_NAME, new Random().nextLong()); |
e5f2344c6fab
8141526: Allow to collect stdout/stderr from the FinalizationRunner even before the process returns
jbachorik
parents:
diff
changeset
|
127 |
/** |
53903
68bbd727dd5f
8219158: use 'test.root' property instead of traversing test-src path
iignatyev
parents:
51478
diff
changeset
|
128 |
* Returns the value of 'test.timeout.factor' system property |
68bbd727dd5f
8219158: use 'test.root' property instead of traversing test-src path
iignatyev
parents:
51478
diff
changeset
|
129 |
* converted to {@code double}. |
68bbd727dd5f
8219158: use 'test.root' property instead of traversing test-src path
iignatyev
parents:
51478
diff
changeset
|
130 |
*/ |
34597
e5f2344c6fab
8141526: Allow to collect stdout/stderr from the FinalizationRunner even before the process returns
jbachorik
parents:
diff
changeset
|
131 |
public static final double TIMEOUT_FACTOR; |
e5f2344c6fab
8141526: Allow to collect stdout/stderr from the FinalizationRunner even before the process returns
jbachorik
parents:
diff
changeset
|
132 |
static { |
e5f2344c6fab
8141526: Allow to collect stdout/stderr from the FinalizationRunner even before the process returns
jbachorik
parents:
diff
changeset
|
133 |
String toFactor = System.getProperty("test.timeout.factor", "1.0"); |
e5f2344c6fab
8141526: Allow to collect stdout/stderr from the FinalizationRunner even before the process returns
jbachorik
parents:
diff
changeset
|
134 |
TIMEOUT_FACTOR = Double.parseDouble(toFactor); |
e5f2344c6fab
8141526: Allow to collect stdout/stderr from the FinalizationRunner even before the process returns
jbachorik
parents:
diff
changeset
|
135 |
} |
e5f2344c6fab
8141526: Allow to collect stdout/stderr from the FinalizationRunner even before the process returns
jbachorik
parents:
diff
changeset
|
136 |
|
e5f2344c6fab
8141526: Allow to collect stdout/stderr from the FinalizationRunner even before the process returns
jbachorik
parents:
diff
changeset
|
137 |
/** |
53903
68bbd727dd5f
8219158: use 'test.root' property instead of traversing test-src path
iignatyev
parents:
51478
diff
changeset
|
138 |
* Returns the value of JTREG default test timeout in milliseconds |
68bbd727dd5f
8219158: use 'test.root' property instead of traversing test-src path
iignatyev
parents:
51478
diff
changeset
|
139 |
* converted to {@code long}. |
68bbd727dd5f
8219158: use 'test.root' property instead of traversing test-src path
iignatyev
parents:
51478
diff
changeset
|
140 |
*/ |
34597
e5f2344c6fab
8141526: Allow to collect stdout/stderr from the FinalizationRunner even before the process returns
jbachorik
parents:
diff
changeset
|
141 |
public static final long DEFAULT_TEST_TIMEOUT = TimeUnit.SECONDS.toMillis(120); |
e5f2344c6fab
8141526: Allow to collect stdout/stderr from the FinalizationRunner even before the process returns
jbachorik
parents:
diff
changeset
|
142 |
|
e5f2344c6fab
8141526: Allow to collect stdout/stderr from the FinalizationRunner even before the process returns
jbachorik
parents:
diff
changeset
|
143 |
private Utils() { |
e5f2344c6fab
8141526: Allow to collect stdout/stderr from the FinalizationRunner even before the process returns
jbachorik
parents:
diff
changeset
|
144 |
// Private constructor to prevent class instantiation |
e5f2344c6fab
8141526: Allow to collect stdout/stderr from the FinalizationRunner even before the process returns
jbachorik
parents:
diff
changeset
|
145 |
} |
e5f2344c6fab
8141526: Allow to collect stdout/stderr from the FinalizationRunner even before the process returns
jbachorik
parents:
diff
changeset
|
146 |
|
e5f2344c6fab
8141526: Allow to collect stdout/stderr from the FinalizationRunner even before the process returns
jbachorik
parents:
diff
changeset
|
147 |
/** |
e5f2344c6fab
8141526: Allow to collect stdout/stderr from the FinalizationRunner even before the process returns
jbachorik
parents:
diff
changeset
|
148 |
* Returns the list of VM options. |
e5f2344c6fab
8141526: Allow to collect stdout/stderr from the FinalizationRunner even before the process returns
jbachorik
parents:
diff
changeset
|
149 |
* |
e5f2344c6fab
8141526: Allow to collect stdout/stderr from the FinalizationRunner even before the process returns
jbachorik
parents:
diff
changeset
|
150 |
* @return List of VM options |
e5f2344c6fab
8141526: Allow to collect stdout/stderr from the FinalizationRunner even before the process returns
jbachorik
parents:
diff
changeset
|
151 |
*/ |
e5f2344c6fab
8141526: Allow to collect stdout/stderr from the FinalizationRunner even before the process returns
jbachorik
parents:
diff
changeset
|
152 |
public static List<String> getVmOptions() { |
e5f2344c6fab
8141526: Allow to collect stdout/stderr from the FinalizationRunner even before the process returns
jbachorik
parents:
diff
changeset
|
153 |
return Arrays.asList(safeSplitString(VM_OPTIONS)); |
e5f2344c6fab
8141526: Allow to collect stdout/stderr from the FinalizationRunner even before the process returns
jbachorik
parents:
diff
changeset
|
154 |
} |
e5f2344c6fab
8141526: Allow to collect stdout/stderr from the FinalizationRunner even before the process returns
jbachorik
parents:
diff
changeset
|
155 |
|
e5f2344c6fab
8141526: Allow to collect stdout/stderr from the FinalizationRunner even before the process returns
jbachorik
parents:
diff
changeset
|
156 |
/** |
e5f2344c6fab
8141526: Allow to collect stdout/stderr from the FinalizationRunner even before the process returns
jbachorik
parents:
diff
changeset
|
157 |
* Returns the list of VM options with -J prefix. |
e5f2344c6fab
8141526: Allow to collect stdout/stderr from the FinalizationRunner even before the process returns
jbachorik
parents:
diff
changeset
|
158 |
* |
e5f2344c6fab
8141526: Allow to collect stdout/stderr from the FinalizationRunner even before the process returns
jbachorik
parents:
diff
changeset
|
159 |
* @return The list of VM options with -J prefix |
e5f2344c6fab
8141526: Allow to collect stdout/stderr from the FinalizationRunner even before the process returns
jbachorik
parents:
diff
changeset
|
160 |
*/ |
e5f2344c6fab
8141526: Allow to collect stdout/stderr from the FinalizationRunner even before the process returns
jbachorik
parents:
diff
changeset
|
161 |
public static List<String> getForwardVmOptions() { |
e5f2344c6fab
8141526: Allow to collect stdout/stderr from the FinalizationRunner even before the process returns
jbachorik
parents:
diff
changeset
|
162 |
String[] opts = safeSplitString(VM_OPTIONS); |
e5f2344c6fab
8141526: Allow to collect stdout/stderr from the FinalizationRunner even before the process returns
jbachorik
parents:
diff
changeset
|
163 |
for (int i = 0; i < opts.length; i++) { |
e5f2344c6fab
8141526: Allow to collect stdout/stderr from the FinalizationRunner even before the process returns
jbachorik
parents:
diff
changeset
|
164 |
opts[i] = "-J" + opts[i]; |
e5f2344c6fab
8141526: Allow to collect stdout/stderr from the FinalizationRunner even before the process returns
jbachorik
parents:
diff
changeset
|
165 |
} |
e5f2344c6fab
8141526: Allow to collect stdout/stderr from the FinalizationRunner even before the process returns
jbachorik
parents:
diff
changeset
|
166 |
return Arrays.asList(opts); |
e5f2344c6fab
8141526: Allow to collect stdout/stderr from the FinalizationRunner even before the process returns
jbachorik
parents:
diff
changeset
|
167 |
} |
e5f2344c6fab
8141526: Allow to collect stdout/stderr from the FinalizationRunner even before the process returns
jbachorik
parents:
diff
changeset
|
168 |
|
e5f2344c6fab
8141526: Allow to collect stdout/stderr from the FinalizationRunner even before the process returns
jbachorik
parents:
diff
changeset
|
169 |
/** |
e5f2344c6fab
8141526: Allow to collect stdout/stderr from the FinalizationRunner even before the process returns
jbachorik
parents:
diff
changeset
|
170 |
* Returns the default JTReg arguments for a jvm running a test. |
e5f2344c6fab
8141526: Allow to collect stdout/stderr from the FinalizationRunner even before the process returns
jbachorik
parents:
diff
changeset
|
171 |
* This is the combination of JTReg arguments test.vm.opts and test.java.opts. |
e5f2344c6fab
8141526: Allow to collect stdout/stderr from the FinalizationRunner even before the process returns
jbachorik
parents:
diff
changeset
|
172 |
* @return An array of options, or an empty array if no options. |
e5f2344c6fab
8141526: Allow to collect stdout/stderr from the FinalizationRunner even before the process returns
jbachorik
parents:
diff
changeset
|
173 |
*/ |
e5f2344c6fab
8141526: Allow to collect stdout/stderr from the FinalizationRunner even before the process returns
jbachorik
parents:
diff
changeset
|
174 |
public static String[] getTestJavaOpts() { |
e5f2344c6fab
8141526: Allow to collect stdout/stderr from the FinalizationRunner even before the process returns
jbachorik
parents:
diff
changeset
|
175 |
List<String> opts = new ArrayList<String>(); |
e5f2344c6fab
8141526: Allow to collect stdout/stderr from the FinalizationRunner even before the process returns
jbachorik
parents:
diff
changeset
|
176 |
Collections.addAll(opts, safeSplitString(VM_OPTIONS)); |
e5f2344c6fab
8141526: Allow to collect stdout/stderr from the FinalizationRunner even before the process returns
jbachorik
parents:
diff
changeset
|
177 |
Collections.addAll(opts, safeSplitString(JAVA_OPTIONS)); |
e5f2344c6fab
8141526: Allow to collect stdout/stderr from the FinalizationRunner even before the process returns
jbachorik
parents:
diff
changeset
|
178 |
return opts.toArray(new String[0]); |
e5f2344c6fab
8141526: Allow to collect stdout/stderr from the FinalizationRunner even before the process returns
jbachorik
parents:
diff
changeset
|
179 |
} |
e5f2344c6fab
8141526: Allow to collect stdout/stderr from the FinalizationRunner even before the process returns
jbachorik
parents:
diff
changeset
|
180 |
|
e5f2344c6fab
8141526: Allow to collect stdout/stderr from the FinalizationRunner even before the process returns
jbachorik
parents:
diff
changeset
|
181 |
/** |
e5f2344c6fab
8141526: Allow to collect stdout/stderr from the FinalizationRunner even before the process returns
jbachorik
parents:
diff
changeset
|
182 |
* Combines given arguments with default JTReg arguments for a jvm running a test. |
e5f2344c6fab
8141526: Allow to collect stdout/stderr from the FinalizationRunner even before the process returns
jbachorik
parents:
diff
changeset
|
183 |
* This is the combination of JTReg arguments test.vm.opts and test.java.opts |
e5f2344c6fab
8141526: Allow to collect stdout/stderr from the FinalizationRunner even before the process returns
jbachorik
parents:
diff
changeset
|
184 |
* @return The combination of JTReg test java options and user args. |
e5f2344c6fab
8141526: Allow to collect stdout/stderr from the FinalizationRunner even before the process returns
jbachorik
parents:
diff
changeset
|
185 |
*/ |
e5f2344c6fab
8141526: Allow to collect stdout/stderr from the FinalizationRunner even before the process returns
jbachorik
parents:
diff
changeset
|
186 |
public static String[] addTestJavaOpts(String... userArgs) { |
e5f2344c6fab
8141526: Allow to collect stdout/stderr from the FinalizationRunner even before the process returns
jbachorik
parents:
diff
changeset
|
187 |
List<String> opts = new ArrayList<String>(); |
e5f2344c6fab
8141526: Allow to collect stdout/stderr from the FinalizationRunner even before the process returns
jbachorik
parents:
diff
changeset
|
188 |
Collections.addAll(opts, getTestJavaOpts()); |
e5f2344c6fab
8141526: Allow to collect stdout/stderr from the FinalizationRunner even before the process returns
jbachorik
parents:
diff
changeset
|
189 |
Collections.addAll(opts, userArgs); |
e5f2344c6fab
8141526: Allow to collect stdout/stderr from the FinalizationRunner even before the process returns
jbachorik
parents:
diff
changeset
|
190 |
return opts.toArray(new String[0]); |
e5f2344c6fab
8141526: Allow to collect stdout/stderr from the FinalizationRunner even before the process returns
jbachorik
parents:
diff
changeset
|
191 |
} |
e5f2344c6fab
8141526: Allow to collect stdout/stderr from the FinalizationRunner even before the process returns
jbachorik
parents:
diff
changeset
|
192 |
|
e5f2344c6fab
8141526: Allow to collect stdout/stderr from the FinalizationRunner even before the process returns
jbachorik
parents:
diff
changeset
|
193 |
/** |
e5f2344c6fab
8141526: Allow to collect stdout/stderr from the FinalizationRunner even before the process returns
jbachorik
parents:
diff
changeset
|
194 |
* Removes any options specifying which GC to use, for example "-XX:+UseG1GC". |
e5f2344c6fab
8141526: Allow to collect stdout/stderr from the FinalizationRunner even before the process returns
jbachorik
parents:
diff
changeset
|
195 |
* Removes any options matching: -XX:(+/-)Use*GC |
e5f2344c6fab
8141526: Allow to collect stdout/stderr from the FinalizationRunner even before the process returns
jbachorik
parents:
diff
changeset
|
196 |
* Used when a test need to set its own GC version. Then any |
e5f2344c6fab
8141526: Allow to collect stdout/stderr from the FinalizationRunner even before the process returns
jbachorik
parents:
diff
changeset
|
197 |
* GC specified by the framework must first be removed. |
e5f2344c6fab
8141526: Allow to collect stdout/stderr from the FinalizationRunner even before the process returns
jbachorik
parents:
diff
changeset
|
198 |
* @return A copy of given opts with all GC options removed. |
e5f2344c6fab
8141526: Allow to collect stdout/stderr from the FinalizationRunner even before the process returns
jbachorik
parents:
diff
changeset
|
199 |
*/ |
e5f2344c6fab
8141526: Allow to collect stdout/stderr from the FinalizationRunner even before the process returns
jbachorik
parents:
diff
changeset
|
200 |
private static final Pattern useGcPattern = Pattern.compile( |
59053
ba6c248cae19
8232365: Implementation for JEP 363: Remove the Concurrent Mark Sweep (CMS) Garbage Collector
lkorinth
parents:
58144
diff
changeset
|
201 |
"(?:\\-XX\\:[\\+\\-]Use.+GC)"); |
34597
e5f2344c6fab
8141526: Allow to collect stdout/stderr from the FinalizationRunner even before the process returns
jbachorik
parents:
diff
changeset
|
202 |
public static List<String> removeGcOpts(List<String> opts) { |
e5f2344c6fab
8141526: Allow to collect stdout/stderr from the FinalizationRunner even before the process returns
jbachorik
parents:
diff
changeset
|
203 |
List<String> optsWithoutGC = new ArrayList<String>(); |
e5f2344c6fab
8141526: Allow to collect stdout/stderr from the FinalizationRunner even before the process returns
jbachorik
parents:
diff
changeset
|
204 |
for (String opt : opts) { |
e5f2344c6fab
8141526: Allow to collect stdout/stderr from the FinalizationRunner even before the process returns
jbachorik
parents:
diff
changeset
|
205 |
if (useGcPattern.matcher(opt).matches()) { |
e5f2344c6fab
8141526: Allow to collect stdout/stderr from the FinalizationRunner even before the process returns
jbachorik
parents:
diff
changeset
|
206 |
System.out.println("removeGcOpts: removed " + opt); |
e5f2344c6fab
8141526: Allow to collect stdout/stderr from the FinalizationRunner even before the process returns
jbachorik
parents:
diff
changeset
|
207 |
} else { |
e5f2344c6fab
8141526: Allow to collect stdout/stderr from the FinalizationRunner even before the process returns
jbachorik
parents:
diff
changeset
|
208 |
optsWithoutGC.add(opt); |
e5f2344c6fab
8141526: Allow to collect stdout/stderr from the FinalizationRunner even before the process returns
jbachorik
parents:
diff
changeset
|
209 |
} |
e5f2344c6fab
8141526: Allow to collect stdout/stderr from the FinalizationRunner even before the process returns
jbachorik
parents:
diff
changeset
|
210 |
} |
e5f2344c6fab
8141526: Allow to collect stdout/stderr from the FinalizationRunner even before the process returns
jbachorik
parents:
diff
changeset
|
211 |
return optsWithoutGC; |
e5f2344c6fab
8141526: Allow to collect stdout/stderr from the FinalizationRunner even before the process returns
jbachorik
parents:
diff
changeset
|
212 |
} |
e5f2344c6fab
8141526: Allow to collect stdout/stderr from the FinalizationRunner even before the process returns
jbachorik
parents:
diff
changeset
|
213 |
|
e5f2344c6fab
8141526: Allow to collect stdout/stderr from the FinalizationRunner even before the process returns
jbachorik
parents:
diff
changeset
|
214 |
/** |
e5f2344c6fab
8141526: Allow to collect stdout/stderr from the FinalizationRunner even before the process returns
jbachorik
parents:
diff
changeset
|
215 |
* Returns the default JTReg arguments for a jvm running a test without |
e5f2344c6fab
8141526: Allow to collect stdout/stderr from the FinalizationRunner even before the process returns
jbachorik
parents:
diff
changeset
|
216 |
* options that matches regular expressions in {@code filters}. |
e5f2344c6fab
8141526: Allow to collect stdout/stderr from the FinalizationRunner even before the process returns
jbachorik
parents:
diff
changeset
|
217 |
* This is the combination of JTReg arguments test.vm.opts and test.java.opts. |
e5f2344c6fab
8141526: Allow to collect stdout/stderr from the FinalizationRunner even before the process returns
jbachorik
parents:
diff
changeset
|
218 |
* @param filters Regular expressions used to filter out options. |
e5f2344c6fab
8141526: Allow to collect stdout/stderr from the FinalizationRunner even before the process returns
jbachorik
parents:
diff
changeset
|
219 |
* @return An array of options, or an empty array if no options. |
e5f2344c6fab
8141526: Allow to collect stdout/stderr from the FinalizationRunner even before the process returns
jbachorik
parents:
diff
changeset
|
220 |
*/ |
e5f2344c6fab
8141526: Allow to collect stdout/stderr from the FinalizationRunner even before the process returns
jbachorik
parents:
diff
changeset
|
221 |
public static String[] getFilteredTestJavaOpts(String... filters) { |
e5f2344c6fab
8141526: Allow to collect stdout/stderr from the FinalizationRunner even before the process returns
jbachorik
parents:
diff
changeset
|
222 |
String options[] = getTestJavaOpts(); |
e5f2344c6fab
8141526: Allow to collect stdout/stderr from the FinalizationRunner even before the process returns
jbachorik
parents:
diff
changeset
|
223 |
|
e5f2344c6fab
8141526: Allow to collect stdout/stderr from the FinalizationRunner even before the process returns
jbachorik
parents:
diff
changeset
|
224 |
if (filters.length == 0) { |
e5f2344c6fab
8141526: Allow to collect stdout/stderr from the FinalizationRunner even before the process returns
jbachorik
parents:
diff
changeset
|
225 |
return options; |
e5f2344c6fab
8141526: Allow to collect stdout/stderr from the FinalizationRunner even before the process returns
jbachorik
parents:
diff
changeset
|
226 |
} |
e5f2344c6fab
8141526: Allow to collect stdout/stderr from the FinalizationRunner even before the process returns
jbachorik
parents:
diff
changeset
|
227 |
|
e5f2344c6fab
8141526: Allow to collect stdout/stderr from the FinalizationRunner even before the process returns
jbachorik
parents:
diff
changeset
|
228 |
List<String> filteredOptions = new ArrayList<String>(options.length); |
e5f2344c6fab
8141526: Allow to collect stdout/stderr from the FinalizationRunner even before the process returns
jbachorik
parents:
diff
changeset
|
229 |
Pattern patterns[] = new Pattern[filters.length]; |
e5f2344c6fab
8141526: Allow to collect stdout/stderr from the FinalizationRunner even before the process returns
jbachorik
parents:
diff
changeset
|
230 |
for (int i = 0; i < filters.length; i++) { |
e5f2344c6fab
8141526: Allow to collect stdout/stderr from the FinalizationRunner even before the process returns
jbachorik
parents:
diff
changeset
|
231 |
patterns[i] = Pattern.compile(filters[i]); |
e5f2344c6fab
8141526: Allow to collect stdout/stderr from the FinalizationRunner even before the process returns
jbachorik
parents:
diff
changeset
|
232 |
} |
e5f2344c6fab
8141526: Allow to collect stdout/stderr from the FinalizationRunner even before the process returns
jbachorik
parents:
diff
changeset
|
233 |
|
e5f2344c6fab
8141526: Allow to collect stdout/stderr from the FinalizationRunner even before the process returns
jbachorik
parents:
diff
changeset
|
234 |
for (String option : options) { |
e5f2344c6fab
8141526: Allow to collect stdout/stderr from the FinalizationRunner even before the process returns
jbachorik
parents:
diff
changeset
|
235 |
boolean matched = false; |
e5f2344c6fab
8141526: Allow to collect stdout/stderr from the FinalizationRunner even before the process returns
jbachorik
parents:
diff
changeset
|
236 |
for (int i = 0; i < patterns.length && !matched; i++) { |
e5f2344c6fab
8141526: Allow to collect stdout/stderr from the FinalizationRunner even before the process returns
jbachorik
parents:
diff
changeset
|
237 |
Matcher matcher = patterns[i].matcher(option); |
e5f2344c6fab
8141526: Allow to collect stdout/stderr from the FinalizationRunner even before the process returns
jbachorik
parents:
diff
changeset
|
238 |
matched = matcher.find(); |
e5f2344c6fab
8141526: Allow to collect stdout/stderr from the FinalizationRunner even before the process returns
jbachorik
parents:
diff
changeset
|
239 |
} |
e5f2344c6fab
8141526: Allow to collect stdout/stderr from the FinalizationRunner even before the process returns
jbachorik
parents:
diff
changeset
|
240 |
if (!matched) { |
e5f2344c6fab
8141526: Allow to collect stdout/stderr from the FinalizationRunner even before the process returns
jbachorik
parents:
diff
changeset
|
241 |
filteredOptions.add(option); |
e5f2344c6fab
8141526: Allow to collect stdout/stderr from the FinalizationRunner even before the process returns
jbachorik
parents:
diff
changeset
|
242 |
} |
e5f2344c6fab
8141526: Allow to collect stdout/stderr from the FinalizationRunner even before the process returns
jbachorik
parents:
diff
changeset
|
243 |
} |
e5f2344c6fab
8141526: Allow to collect stdout/stderr from the FinalizationRunner even before the process returns
jbachorik
parents:
diff
changeset
|
244 |
|
e5f2344c6fab
8141526: Allow to collect stdout/stderr from the FinalizationRunner even before the process returns
jbachorik
parents:
diff
changeset
|
245 |
return filteredOptions.toArray(new String[filteredOptions.size()]); |
e5f2344c6fab
8141526: Allow to collect stdout/stderr from the FinalizationRunner even before the process returns
jbachorik
parents:
diff
changeset
|
246 |
} |
e5f2344c6fab
8141526: Allow to collect stdout/stderr from the FinalizationRunner even before the process returns
jbachorik
parents:
diff
changeset
|
247 |
|
e5f2344c6fab
8141526: Allow to collect stdout/stderr from the FinalizationRunner even before the process returns
jbachorik
parents:
diff
changeset
|
248 |
/** |
e5f2344c6fab
8141526: Allow to collect stdout/stderr from the FinalizationRunner even before the process returns
jbachorik
parents:
diff
changeset
|
249 |
* Splits a string by white space. |
e5f2344c6fab
8141526: Allow to collect stdout/stderr from the FinalizationRunner even before the process returns
jbachorik
parents:
diff
changeset
|
250 |
* Works like String.split(), but returns an empty array |
e5f2344c6fab
8141526: Allow to collect stdout/stderr from the FinalizationRunner even before the process returns
jbachorik
parents:
diff
changeset
|
251 |
* if the string is null or empty. |
e5f2344c6fab
8141526: Allow to collect stdout/stderr from the FinalizationRunner even before the process returns
jbachorik
parents:
diff
changeset
|
252 |
*/ |
e5f2344c6fab
8141526: Allow to collect stdout/stderr from the FinalizationRunner even before the process returns
jbachorik
parents:
diff
changeset
|
253 |
private static String[] safeSplitString(String s) { |
e5f2344c6fab
8141526: Allow to collect stdout/stderr from the FinalizationRunner even before the process returns
jbachorik
parents:
diff
changeset
|
254 |
if (s == null || s.trim().isEmpty()) { |
e5f2344c6fab
8141526: Allow to collect stdout/stderr from the FinalizationRunner even before the process returns
jbachorik
parents:
diff
changeset
|
255 |
return new String[] {}; |
e5f2344c6fab
8141526: Allow to collect stdout/stderr from the FinalizationRunner even before the process returns
jbachorik
parents:
diff
changeset
|
256 |
} |
e5f2344c6fab
8141526: Allow to collect stdout/stderr from the FinalizationRunner even before the process returns
jbachorik
parents:
diff
changeset
|
257 |
return s.trim().split("\\s+"); |
e5f2344c6fab
8141526: Allow to collect stdout/stderr from the FinalizationRunner even before the process returns
jbachorik
parents:
diff
changeset
|
258 |
} |
e5f2344c6fab
8141526: Allow to collect stdout/stderr from the FinalizationRunner even before the process returns
jbachorik
parents:
diff
changeset
|
259 |
|
e5f2344c6fab
8141526: Allow to collect stdout/stderr from the FinalizationRunner even before the process returns
jbachorik
parents:
diff
changeset
|
260 |
/** |
e5f2344c6fab
8141526: Allow to collect stdout/stderr from the FinalizationRunner even before the process returns
jbachorik
parents:
diff
changeset
|
261 |
* @return The full command line for the ProcessBuilder. |
e5f2344c6fab
8141526: Allow to collect stdout/stderr from the FinalizationRunner even before the process returns
jbachorik
parents:
diff
changeset
|
262 |
*/ |
e5f2344c6fab
8141526: Allow to collect stdout/stderr from the FinalizationRunner even before the process returns
jbachorik
parents:
diff
changeset
|
263 |
public static String getCommandLine(ProcessBuilder pb) { |
e5f2344c6fab
8141526: Allow to collect stdout/stderr from the FinalizationRunner even before the process returns
jbachorik
parents:
diff
changeset
|
264 |
StringBuilder cmd = new StringBuilder(); |
e5f2344c6fab
8141526: Allow to collect stdout/stderr from the FinalizationRunner even before the process returns
jbachorik
parents:
diff
changeset
|
265 |
for (String s : pb.command()) { |
e5f2344c6fab
8141526: Allow to collect stdout/stderr from the FinalizationRunner even before the process returns
jbachorik
parents:
diff
changeset
|
266 |
cmd.append(s).append(" "); |
e5f2344c6fab
8141526: Allow to collect stdout/stderr from the FinalizationRunner even before the process returns
jbachorik
parents:
diff
changeset
|
267 |
} |
e5f2344c6fab
8141526: Allow to collect stdout/stderr from the FinalizationRunner even before the process returns
jbachorik
parents:
diff
changeset
|
268 |
return cmd.toString(); |
e5f2344c6fab
8141526: Allow to collect stdout/stderr from the FinalizationRunner even before the process returns
jbachorik
parents:
diff
changeset
|
269 |
} |
e5f2344c6fab
8141526: Allow to collect stdout/stderr from the FinalizationRunner even before the process returns
jbachorik
parents:
diff
changeset
|
270 |
|
e5f2344c6fab
8141526: Allow to collect stdout/stderr from the FinalizationRunner even before the process returns
jbachorik
parents:
diff
changeset
|
271 |
/** |
49255
acdb8531cc8b
8199215: Re-examine getFreePort method in test infrastructure library
mli
parents:
46237
diff
changeset
|
272 |
* Returns the socket address of an endpoint that refuses connections. The |
acdb8531cc8b
8199215: Re-examine getFreePort method in test infrastructure library
mli
parents:
46237
diff
changeset
|
273 |
* endpoint is an InetSocketAddress where the address is the loopback address |
acdb8531cc8b
8199215: Re-examine getFreePort method in test infrastructure library
mli
parents:
46237
diff
changeset
|
274 |
* and the port is a system port (1-1023 range). |
acdb8531cc8b
8199215: Re-examine getFreePort method in test infrastructure library
mli
parents:
46237
diff
changeset
|
275 |
* This method is a better choice than getFreePort for tests that need |
acdb8531cc8b
8199215: Re-examine getFreePort method in test infrastructure library
mli
parents:
46237
diff
changeset
|
276 |
* an endpoint that refuses connections. |
acdb8531cc8b
8199215: Re-examine getFreePort method in test infrastructure library
mli
parents:
46237
diff
changeset
|
277 |
*/ |
acdb8531cc8b
8199215: Re-examine getFreePort method in test infrastructure library
mli
parents:
46237
diff
changeset
|
278 |
public static InetSocketAddress refusingEndpoint() { |
acdb8531cc8b
8199215: Re-examine getFreePort method in test infrastructure library
mli
parents:
46237
diff
changeset
|
279 |
InetAddress lb = InetAddress.getLoopbackAddress(); |
acdb8531cc8b
8199215: Re-examine getFreePort method in test infrastructure library
mli
parents:
46237
diff
changeset
|
280 |
int port = 1; |
acdb8531cc8b
8199215: Re-examine getFreePort method in test infrastructure library
mli
parents:
46237
diff
changeset
|
281 |
while (port < 1024) { |
acdb8531cc8b
8199215: Re-examine getFreePort method in test infrastructure library
mli
parents:
46237
diff
changeset
|
282 |
InetSocketAddress sa = new InetSocketAddress(lb, port); |
acdb8531cc8b
8199215: Re-examine getFreePort method in test infrastructure library
mli
parents:
46237
diff
changeset
|
283 |
try { |
acdb8531cc8b
8199215: Re-examine getFreePort method in test infrastructure library
mli
parents:
46237
diff
changeset
|
284 |
SocketChannel.open(sa).close(); |
acdb8531cc8b
8199215: Re-examine getFreePort method in test infrastructure library
mli
parents:
46237
diff
changeset
|
285 |
} catch (IOException ioe) { |
acdb8531cc8b
8199215: Re-examine getFreePort method in test infrastructure library
mli
parents:
46237
diff
changeset
|
286 |
return sa; |
acdb8531cc8b
8199215: Re-examine getFreePort method in test infrastructure library
mli
parents:
46237
diff
changeset
|
287 |
} |
acdb8531cc8b
8199215: Re-examine getFreePort method in test infrastructure library
mli
parents:
46237
diff
changeset
|
288 |
port++; |
acdb8531cc8b
8199215: Re-examine getFreePort method in test infrastructure library
mli
parents:
46237
diff
changeset
|
289 |
} |
acdb8531cc8b
8199215: Re-examine getFreePort method in test infrastructure library
mli
parents:
46237
diff
changeset
|
290 |
throw new RuntimeException("Unable to find system port that is refusing connections"); |
acdb8531cc8b
8199215: Re-examine getFreePort method in test infrastructure library
mli
parents:
46237
diff
changeset
|
291 |
} |
acdb8531cc8b
8199215: Re-examine getFreePort method in test infrastructure library
mli
parents:
46237
diff
changeset
|
292 |
|
acdb8531cc8b
8199215: Re-examine getFreePort method in test infrastructure library
mli
parents:
46237
diff
changeset
|
293 |
/** |
34597
e5f2344c6fab
8141526: Allow to collect stdout/stderr from the FinalizationRunner even before the process returns
jbachorik
parents:
diff
changeset
|
294 |
* Returns the free port on the local host. |
e5f2344c6fab
8141526: Allow to collect stdout/stderr from the FinalizationRunner even before the process returns
jbachorik
parents:
diff
changeset
|
295 |
* |
e5f2344c6fab
8141526: Allow to collect stdout/stderr from the FinalizationRunner even before the process returns
jbachorik
parents:
diff
changeset
|
296 |
* @return The port number |
e5f2344c6fab
8141526: Allow to collect stdout/stderr from the FinalizationRunner even before the process returns
jbachorik
parents:
diff
changeset
|
297 |
* @throws IOException if an I/O error occurs when opening the socket |
e5f2344c6fab
8141526: Allow to collect stdout/stderr from the FinalizationRunner even before the process returns
jbachorik
parents:
diff
changeset
|
298 |
*/ |
49255
acdb8531cc8b
8199215: Re-examine getFreePort method in test infrastructure library
mli
parents:
46237
diff
changeset
|
299 |
public static int getFreePort() throws IOException { |
acdb8531cc8b
8199215: Re-examine getFreePort method in test infrastructure library
mli
parents:
46237
diff
changeset
|
300 |
try (ServerSocket serverSocket = |
acdb8531cc8b
8199215: Re-examine getFreePort method in test infrastructure library
mli
parents:
46237
diff
changeset
|
301 |
new ServerSocket(0, 5, InetAddress.getLoopbackAddress());) { |
acdb8531cc8b
8199215: Re-examine getFreePort method in test infrastructure library
mli
parents:
46237
diff
changeset
|
302 |
return serverSocket.getLocalPort(); |
34597
e5f2344c6fab
8141526: Allow to collect stdout/stderr from the FinalizationRunner even before the process returns
jbachorik
parents:
diff
changeset
|
303 |
} |
e5f2344c6fab
8141526: Allow to collect stdout/stderr from the FinalizationRunner even before the process returns
jbachorik
parents:
diff
changeset
|
304 |
} |
e5f2344c6fab
8141526: Allow to collect stdout/stderr from the FinalizationRunner even before the process returns
jbachorik
parents:
diff
changeset
|
305 |
|
e5f2344c6fab
8141526: Allow to collect stdout/stderr from the FinalizationRunner even before the process returns
jbachorik
parents:
diff
changeset
|
306 |
/** |
e5f2344c6fab
8141526: Allow to collect stdout/stderr from the FinalizationRunner even before the process returns
jbachorik
parents:
diff
changeset
|
307 |
* Returns the name of the local host. |
e5f2344c6fab
8141526: Allow to collect stdout/stderr from the FinalizationRunner even before the process returns
jbachorik
parents:
diff
changeset
|
308 |
* |
e5f2344c6fab
8141526: Allow to collect stdout/stderr from the FinalizationRunner even before the process returns
jbachorik
parents:
diff
changeset
|
309 |
* @return The host name |
e5f2344c6fab
8141526: Allow to collect stdout/stderr from the FinalizationRunner even before the process returns
jbachorik
parents:
diff
changeset
|
310 |
* @throws UnknownHostException if IP address of a host could not be determined |
e5f2344c6fab
8141526: Allow to collect stdout/stderr from the FinalizationRunner even before the process returns
jbachorik
parents:
diff
changeset
|
311 |
*/ |
e5f2344c6fab
8141526: Allow to collect stdout/stderr from the FinalizationRunner even before the process returns
jbachorik
parents:
diff
changeset
|
312 |
public static String getHostname() throws UnknownHostException { |
e5f2344c6fab
8141526: Allow to collect stdout/stderr from the FinalizationRunner even before the process returns
jbachorik
parents:
diff
changeset
|
313 |
InetAddress inetAddress = InetAddress.getLocalHost(); |
e5f2344c6fab
8141526: Allow to collect stdout/stderr from the FinalizationRunner even before the process returns
jbachorik
parents:
diff
changeset
|
314 |
String hostName = inetAddress.getHostName(); |
e5f2344c6fab
8141526: Allow to collect stdout/stderr from the FinalizationRunner even before the process returns
jbachorik
parents:
diff
changeset
|
315 |
|
e5f2344c6fab
8141526: Allow to collect stdout/stderr from the FinalizationRunner even before the process returns
jbachorik
parents:
diff
changeset
|
316 |
assertTrue((hostName != null && !hostName.isEmpty()), |
e5f2344c6fab
8141526: Allow to collect stdout/stderr from the FinalizationRunner even before the process returns
jbachorik
parents:
diff
changeset
|
317 |
"Cannot get hostname"); |
e5f2344c6fab
8141526: Allow to collect stdout/stderr from the FinalizationRunner even before the process returns
jbachorik
parents:
diff
changeset
|
318 |
|
e5f2344c6fab
8141526: Allow to collect stdout/stderr from the FinalizationRunner even before the process returns
jbachorik
parents:
diff
changeset
|
319 |
return hostName; |
e5f2344c6fab
8141526: Allow to collect stdout/stderr from the FinalizationRunner even before the process returns
jbachorik
parents:
diff
changeset
|
320 |
} |
e5f2344c6fab
8141526: Allow to collect stdout/stderr from the FinalizationRunner even before the process returns
jbachorik
parents:
diff
changeset
|
321 |
|
e5f2344c6fab
8141526: Allow to collect stdout/stderr from the FinalizationRunner even before the process returns
jbachorik
parents:
diff
changeset
|
322 |
/** |
e5f2344c6fab
8141526: Allow to collect stdout/stderr from the FinalizationRunner even before the process returns
jbachorik
parents:
diff
changeset
|
323 |
* Uses "jcmd -l" to search for a jvm pid. This function will wait |
e5f2344c6fab
8141526: Allow to collect stdout/stderr from the FinalizationRunner even before the process returns
jbachorik
parents:
diff
changeset
|
324 |
* forever (until jtreg timeout) for the pid to be found. |
e5f2344c6fab
8141526: Allow to collect stdout/stderr from the FinalizationRunner even before the process returns
jbachorik
parents:
diff
changeset
|
325 |
* @param key Regular expression to search for |
e5f2344c6fab
8141526: Allow to collect stdout/stderr from the FinalizationRunner even before the process returns
jbachorik
parents:
diff
changeset
|
326 |
* @return The found pid. |
e5f2344c6fab
8141526: Allow to collect stdout/stderr from the FinalizationRunner even before the process returns
jbachorik
parents:
diff
changeset
|
327 |
*/ |
e5f2344c6fab
8141526: Allow to collect stdout/stderr from the FinalizationRunner even before the process returns
jbachorik
parents:
diff
changeset
|
328 |
public static int waitForJvmPid(String key) throws Throwable { |
e5f2344c6fab
8141526: Allow to collect stdout/stderr from the FinalizationRunner even before the process returns
jbachorik
parents:
diff
changeset
|
329 |
final long iterationSleepMillis = 250; |
e5f2344c6fab
8141526: Allow to collect stdout/stderr from the FinalizationRunner even before the process returns
jbachorik
parents:
diff
changeset
|
330 |
System.out.println("waitForJvmPid: Waiting for key '" + key + "'"); |
e5f2344c6fab
8141526: Allow to collect stdout/stderr from the FinalizationRunner even before the process returns
jbachorik
parents:
diff
changeset
|
331 |
System.out.flush(); |
e5f2344c6fab
8141526: Allow to collect stdout/stderr from the FinalizationRunner even before the process returns
jbachorik
parents:
diff
changeset
|
332 |
while (true) { |
e5f2344c6fab
8141526: Allow to collect stdout/stderr from the FinalizationRunner even before the process returns
jbachorik
parents:
diff
changeset
|
333 |
int pid = tryFindJvmPid(key); |
e5f2344c6fab
8141526: Allow to collect stdout/stderr from the FinalizationRunner even before the process returns
jbachorik
parents:
diff
changeset
|
334 |
if (pid >= 0) { |
e5f2344c6fab
8141526: Allow to collect stdout/stderr from the FinalizationRunner even before the process returns
jbachorik
parents:
diff
changeset
|
335 |
return pid; |
e5f2344c6fab
8141526: Allow to collect stdout/stderr from the FinalizationRunner even before the process returns
jbachorik
parents:
diff
changeset
|
336 |
} |
e5f2344c6fab
8141526: Allow to collect stdout/stderr from the FinalizationRunner even before the process returns
jbachorik
parents:
diff
changeset
|
337 |
Thread.sleep(iterationSleepMillis); |
e5f2344c6fab
8141526: Allow to collect stdout/stderr from the FinalizationRunner even before the process returns
jbachorik
parents:
diff
changeset
|
338 |
} |
e5f2344c6fab
8141526: Allow to collect stdout/stderr from the FinalizationRunner even before the process returns
jbachorik
parents:
diff
changeset
|
339 |
} |
e5f2344c6fab
8141526: Allow to collect stdout/stderr from the FinalizationRunner even before the process returns
jbachorik
parents:
diff
changeset
|
340 |
|
e5f2344c6fab
8141526: Allow to collect stdout/stderr from the FinalizationRunner even before the process returns
jbachorik
parents:
diff
changeset
|
341 |
/** |
e5f2344c6fab
8141526: Allow to collect stdout/stderr from the FinalizationRunner even before the process returns
jbachorik
parents:
diff
changeset
|
342 |
* Searches for a jvm pid in the output from "jcmd -l". |
e5f2344c6fab
8141526: Allow to collect stdout/stderr from the FinalizationRunner even before the process returns
jbachorik
parents:
diff
changeset
|
343 |
* |
e5f2344c6fab
8141526: Allow to collect stdout/stderr from the FinalizationRunner even before the process returns
jbachorik
parents:
diff
changeset
|
344 |
* Example output from jcmd is: |
e5f2344c6fab
8141526: Allow to collect stdout/stderr from the FinalizationRunner even before the process returns
jbachorik
parents:
diff
changeset
|
345 |
* 12498 sun.tools.jcmd.JCmd -l |
e5f2344c6fab
8141526: Allow to collect stdout/stderr from the FinalizationRunner even before the process returns
jbachorik
parents:
diff
changeset
|
346 |
* 12254 /tmp/jdk8/tl/jdk/JTwork/classes/com/sun/tools/attach/Application.jar |
e5f2344c6fab
8141526: Allow to collect stdout/stderr from the FinalizationRunner even before the process returns
jbachorik
parents:
diff
changeset
|
347 |
* |
e5f2344c6fab
8141526: Allow to collect stdout/stderr from the FinalizationRunner even before the process returns
jbachorik
parents:
diff
changeset
|
348 |
* @param key A regular expression to search for. |
e5f2344c6fab
8141526: Allow to collect stdout/stderr from the FinalizationRunner even before the process returns
jbachorik
parents:
diff
changeset
|
349 |
* @return The found pid, or -1 if not found. |
e5f2344c6fab
8141526: Allow to collect stdout/stderr from the FinalizationRunner even before the process returns
jbachorik
parents:
diff
changeset
|
350 |
* @throws Exception If multiple matching jvms are found. |
e5f2344c6fab
8141526: Allow to collect stdout/stderr from the FinalizationRunner even before the process returns
jbachorik
parents:
diff
changeset
|
351 |
*/ |
e5f2344c6fab
8141526: Allow to collect stdout/stderr from the FinalizationRunner even before the process returns
jbachorik
parents:
diff
changeset
|
352 |
public static int tryFindJvmPid(String key) throws Throwable { |
e5f2344c6fab
8141526: Allow to collect stdout/stderr from the FinalizationRunner even before the process returns
jbachorik
parents:
diff
changeset
|
353 |
OutputAnalyzer output = null; |
e5f2344c6fab
8141526: Allow to collect stdout/stderr from the FinalizationRunner even before the process returns
jbachorik
parents:
diff
changeset
|
354 |
try { |
e5f2344c6fab
8141526: Allow to collect stdout/stderr from the FinalizationRunner even before the process returns
jbachorik
parents:
diff
changeset
|
355 |
JDKToolLauncher jcmdLauncher = JDKToolLauncher.create("jcmd"); |
e5f2344c6fab
8141526: Allow to collect stdout/stderr from the FinalizationRunner even before the process returns
jbachorik
parents:
diff
changeset
|
356 |
jcmdLauncher.addToolArg("-l"); |
e5f2344c6fab
8141526: Allow to collect stdout/stderr from the FinalizationRunner even before the process returns
jbachorik
parents:
diff
changeset
|
357 |
output = ProcessTools.executeProcess(jcmdLauncher.getCommand()); |
e5f2344c6fab
8141526: Allow to collect stdout/stderr from the FinalizationRunner even before the process returns
jbachorik
parents:
diff
changeset
|
358 |
output.shouldHaveExitValue(0); |
e5f2344c6fab
8141526: Allow to collect stdout/stderr from the FinalizationRunner even before the process returns
jbachorik
parents:
diff
changeset
|
359 |
|
e5f2344c6fab
8141526: Allow to collect stdout/stderr from the FinalizationRunner even before the process returns
jbachorik
parents:
diff
changeset
|
360 |
// Search for a line starting with numbers (pid), follwed by the key. |
e5f2344c6fab
8141526: Allow to collect stdout/stderr from the FinalizationRunner even before the process returns
jbachorik
parents:
diff
changeset
|
361 |
Pattern pattern = Pattern.compile("([0-9]+)\\s.*(" + key + ").*\\r?\\n"); |
e5f2344c6fab
8141526: Allow to collect stdout/stderr from the FinalizationRunner even before the process returns
jbachorik
parents:
diff
changeset
|
362 |
Matcher matcher = pattern.matcher(output.getStdout()); |
e5f2344c6fab
8141526: Allow to collect stdout/stderr from the FinalizationRunner even before the process returns
jbachorik
parents:
diff
changeset
|
363 |
|
e5f2344c6fab
8141526: Allow to collect stdout/stderr from the FinalizationRunner even before the process returns
jbachorik
parents:
diff
changeset
|
364 |
int pid = -1; |
e5f2344c6fab
8141526: Allow to collect stdout/stderr from the FinalizationRunner even before the process returns
jbachorik
parents:
diff
changeset
|
365 |
if (matcher.find()) { |
e5f2344c6fab
8141526: Allow to collect stdout/stderr from the FinalizationRunner even before the process returns
jbachorik
parents:
diff
changeset
|
366 |
pid = Integer.parseInt(matcher.group(1)); |
e5f2344c6fab
8141526: Allow to collect stdout/stderr from the FinalizationRunner even before the process returns
jbachorik
parents:
diff
changeset
|
367 |
System.out.println("findJvmPid.pid: " + pid); |
e5f2344c6fab
8141526: Allow to collect stdout/stderr from the FinalizationRunner even before the process returns
jbachorik
parents:
diff
changeset
|
368 |
if (matcher.find()) { |
e5f2344c6fab
8141526: Allow to collect stdout/stderr from the FinalizationRunner even before the process returns
jbachorik
parents:
diff
changeset
|
369 |
throw new Exception("Found multiple JVM pids for key: " + key); |
e5f2344c6fab
8141526: Allow to collect stdout/stderr from the FinalizationRunner even before the process returns
jbachorik
parents:
diff
changeset
|
370 |
} |
e5f2344c6fab
8141526: Allow to collect stdout/stderr from the FinalizationRunner even before the process returns
jbachorik
parents:
diff
changeset
|
371 |
} |
e5f2344c6fab
8141526: Allow to collect stdout/stderr from the FinalizationRunner even before the process returns
jbachorik
parents:
diff
changeset
|
372 |
return pid; |
e5f2344c6fab
8141526: Allow to collect stdout/stderr from the FinalizationRunner even before the process returns
jbachorik
parents:
diff
changeset
|
373 |
} catch (Throwable t) { |
e5f2344c6fab
8141526: Allow to collect stdout/stderr from the FinalizationRunner even before the process returns
jbachorik
parents:
diff
changeset
|
374 |
System.out.println(String.format("Utils.findJvmPid(%s) failed: %s", key, t)); |
e5f2344c6fab
8141526: Allow to collect stdout/stderr from the FinalizationRunner even before the process returns
jbachorik
parents:
diff
changeset
|
375 |
throw t; |
e5f2344c6fab
8141526: Allow to collect stdout/stderr from the FinalizationRunner even before the process returns
jbachorik
parents:
diff
changeset
|
376 |
} |
e5f2344c6fab
8141526: Allow to collect stdout/stderr from the FinalizationRunner even before the process returns
jbachorik
parents:
diff
changeset
|
377 |
} |
e5f2344c6fab
8141526: Allow to collect stdout/stderr from the FinalizationRunner even before the process returns
jbachorik
parents:
diff
changeset
|
378 |
|
e5f2344c6fab
8141526: Allow to collect stdout/stderr from the FinalizationRunner even before the process returns
jbachorik
parents:
diff
changeset
|
379 |
/** |
e5f2344c6fab
8141526: Allow to collect stdout/stderr from the FinalizationRunner even before the process returns
jbachorik
parents:
diff
changeset
|
380 |
* Adjusts the provided timeout value for the TIMEOUT_FACTOR |
e5f2344c6fab
8141526: Allow to collect stdout/stderr from the FinalizationRunner even before the process returns
jbachorik
parents:
diff
changeset
|
381 |
* @param tOut the timeout value to be adjusted |
e5f2344c6fab
8141526: Allow to collect stdout/stderr from the FinalizationRunner even before the process returns
jbachorik
parents:
diff
changeset
|
382 |
* @return The timeout value adjusted for the value of "test.timeout.factor" |
e5f2344c6fab
8141526: Allow to collect stdout/stderr from the FinalizationRunner even before the process returns
jbachorik
parents:
diff
changeset
|
383 |
* system property |
e5f2344c6fab
8141526: Allow to collect stdout/stderr from the FinalizationRunner even before the process returns
jbachorik
parents:
diff
changeset
|
384 |
*/ |
e5f2344c6fab
8141526: Allow to collect stdout/stderr from the FinalizationRunner even before the process returns
jbachorik
parents:
diff
changeset
|
385 |
public static long adjustTimeout(long tOut) { |
e5f2344c6fab
8141526: Allow to collect stdout/stderr from the FinalizationRunner even before the process returns
jbachorik
parents:
diff
changeset
|
386 |
return Math.round(tOut * Utils.TIMEOUT_FACTOR); |
e5f2344c6fab
8141526: Allow to collect stdout/stderr from the FinalizationRunner even before the process returns
jbachorik
parents:
diff
changeset
|
387 |
} |
e5f2344c6fab
8141526: Allow to collect stdout/stderr from the FinalizationRunner even before the process returns
jbachorik
parents:
diff
changeset
|
388 |
|
e5f2344c6fab
8141526: Allow to collect stdout/stderr from the FinalizationRunner even before the process returns
jbachorik
parents:
diff
changeset
|
389 |
/** |
e5f2344c6fab
8141526: Allow to collect stdout/stderr from the FinalizationRunner even before the process returns
jbachorik
parents:
diff
changeset
|
390 |
* Return the contents of the named file as a single String, |
e5f2344c6fab
8141526: Allow to collect stdout/stderr from the FinalizationRunner even before the process returns
jbachorik
parents:
diff
changeset
|
391 |
* or null if not found. |
e5f2344c6fab
8141526: Allow to collect stdout/stderr from the FinalizationRunner even before the process returns
jbachorik
parents:
diff
changeset
|
392 |
* @param filename name of the file to read |
e5f2344c6fab
8141526: Allow to collect stdout/stderr from the FinalizationRunner even before the process returns
jbachorik
parents:
diff
changeset
|
393 |
* @return String contents of file, or null if file not found. |
e5f2344c6fab
8141526: Allow to collect stdout/stderr from the FinalizationRunner even before the process returns
jbachorik
parents:
diff
changeset
|
394 |
* @throws IOException |
e5f2344c6fab
8141526: Allow to collect stdout/stderr from the FinalizationRunner even before the process returns
jbachorik
parents:
diff
changeset
|
395 |
* if an I/O error occurs reading from the file or a malformed or |
e5f2344c6fab
8141526: Allow to collect stdout/stderr from the FinalizationRunner even before the process returns
jbachorik
parents:
diff
changeset
|
396 |
* unmappable byte sequence is read |
e5f2344c6fab
8141526: Allow to collect stdout/stderr from the FinalizationRunner even before the process returns
jbachorik
parents:
diff
changeset
|
397 |
*/ |
e5f2344c6fab
8141526: Allow to collect stdout/stderr from the FinalizationRunner even before the process returns
jbachorik
parents:
diff
changeset
|
398 |
public static String fileAsString(String filename) throws IOException { |
e5f2344c6fab
8141526: Allow to collect stdout/stderr from the FinalizationRunner even before the process returns
jbachorik
parents:
diff
changeset
|
399 |
Path filePath = Paths.get(filename); |
e5f2344c6fab
8141526: Allow to collect stdout/stderr from the FinalizationRunner even before the process returns
jbachorik
parents:
diff
changeset
|
400 |
if (!Files.exists(filePath)) return null; |
e5f2344c6fab
8141526: Allow to collect stdout/stderr from the FinalizationRunner even before the process returns
jbachorik
parents:
diff
changeset
|
401 |
return new String(Files.readAllBytes(filePath)); |
e5f2344c6fab
8141526: Allow to collect stdout/stderr from the FinalizationRunner even before the process returns
jbachorik
parents:
diff
changeset
|
402 |
} |
e5f2344c6fab
8141526: Allow to collect stdout/stderr from the FinalizationRunner even before the process returns
jbachorik
parents:
diff
changeset
|
403 |
|
e5f2344c6fab
8141526: Allow to collect stdout/stderr from the FinalizationRunner even before the process returns
jbachorik
parents:
diff
changeset
|
404 |
private static final char[] hexArray = new char[]{'0', '1', '2', '3', '4', '5', '6', '7', '8', '9', 'A', 'B', 'C', 'D', 'E', 'F'}; |
e5f2344c6fab
8141526: Allow to collect stdout/stderr from the FinalizationRunner even before the process returns
jbachorik
parents:
diff
changeset
|
405 |
|
e5f2344c6fab
8141526: Allow to collect stdout/stderr from the FinalizationRunner even before the process returns
jbachorik
parents:
diff
changeset
|
406 |
/** |
e5f2344c6fab
8141526: Allow to collect stdout/stderr from the FinalizationRunner even before the process returns
jbachorik
parents:
diff
changeset
|
407 |
* Returns hex view of byte array |
e5f2344c6fab
8141526: Allow to collect stdout/stderr from the FinalizationRunner even before the process returns
jbachorik
parents:
diff
changeset
|
408 |
* |
e5f2344c6fab
8141526: Allow to collect stdout/stderr from the FinalizationRunner even before the process returns
jbachorik
parents:
diff
changeset
|
409 |
* @param bytes byte array to process |
50367
b73f9723aa54
8199388: Test development for ChaCha20 and Poly1305 algorithms
jjiang
parents:
50225
diff
changeset
|
410 |
* @return space separated hexadecimal string representation of bytes |
34597
e5f2344c6fab
8141526: Allow to collect stdout/stderr from the FinalizationRunner even before the process returns
jbachorik
parents:
diff
changeset
|
411 |
*/ |
50367
b73f9723aa54
8199388: Test development for ChaCha20 and Poly1305 algorithms
jjiang
parents:
50225
diff
changeset
|
412 |
public static String toHexString(byte[] bytes) { |
b73f9723aa54
8199388: Test development for ChaCha20 and Poly1305 algorithms
jjiang
parents:
50225
diff
changeset
|
413 |
char[] hexView = new char[bytes.length * 3 - 1]; |
b73f9723aa54
8199388: Test development for ChaCha20 and Poly1305 algorithms
jjiang
parents:
50225
diff
changeset
|
414 |
for (int i = 0; i < bytes.length - 1; i++) { |
b73f9723aa54
8199388: Test development for ChaCha20 and Poly1305 algorithms
jjiang
parents:
50225
diff
changeset
|
415 |
hexView[i * 3] = hexArray[(bytes[i] >> 4) & 0x0F]; |
b73f9723aa54
8199388: Test development for ChaCha20 and Poly1305 algorithms
jjiang
parents:
50225
diff
changeset
|
416 |
hexView[i * 3 + 1] = hexArray[bytes[i] & 0x0F]; |
b73f9723aa54
8199388: Test development for ChaCha20 and Poly1305 algorithms
jjiang
parents:
50225
diff
changeset
|
417 |
hexView[i * 3 + 2] = ' '; |
b73f9723aa54
8199388: Test development for ChaCha20 and Poly1305 algorithms
jjiang
parents:
50225
diff
changeset
|
418 |
} |
b73f9723aa54
8199388: Test development for ChaCha20 and Poly1305 algorithms
jjiang
parents:
50225
diff
changeset
|
419 |
hexView[hexView.length - 2] = hexArray[(bytes[bytes.length - 1] >> 4) & 0x0F]; |
b73f9723aa54
8199388: Test development for ChaCha20 and Poly1305 algorithms
jjiang
parents:
50225
diff
changeset
|
420 |
hexView[hexView.length - 1] = hexArray[bytes[bytes.length - 1] & 0x0F]; |
b73f9723aa54
8199388: Test development for ChaCha20 and Poly1305 algorithms
jjiang
parents:
50225
diff
changeset
|
421 |
return new String(hexView); |
b73f9723aa54
8199388: Test development for ChaCha20 and Poly1305 algorithms
jjiang
parents:
50225
diff
changeset
|
422 |
} |
34597
e5f2344c6fab
8141526: Allow to collect stdout/stderr from the FinalizationRunner even before the process returns
jbachorik
parents:
diff
changeset
|
423 |
|
50367
b73f9723aa54
8199388: Test development for ChaCha20 and Poly1305 algorithms
jjiang
parents:
50225
diff
changeset
|
424 |
/** |
b73f9723aa54
8199388: Test development for ChaCha20 and Poly1305 algorithms
jjiang
parents:
50225
diff
changeset
|
425 |
* Returns byte array of hex view |
b73f9723aa54
8199388: Test development for ChaCha20 and Poly1305 algorithms
jjiang
parents:
50225
diff
changeset
|
426 |
* |
b73f9723aa54
8199388: Test development for ChaCha20 and Poly1305 algorithms
jjiang
parents:
50225
diff
changeset
|
427 |
* @param hex hexadecimal string representation |
b73f9723aa54
8199388: Test development for ChaCha20 and Poly1305 algorithms
jjiang
parents:
50225
diff
changeset
|
428 |
* @return byte array |
b73f9723aa54
8199388: Test development for ChaCha20 and Poly1305 algorithms
jjiang
parents:
50225
diff
changeset
|
429 |
*/ |
b73f9723aa54
8199388: Test development for ChaCha20 and Poly1305 algorithms
jjiang
parents:
50225
diff
changeset
|
430 |
public static byte[] toByteArray(String hex) { |
b73f9723aa54
8199388: Test development for ChaCha20 and Poly1305 algorithms
jjiang
parents:
50225
diff
changeset
|
431 |
int length = hex.length(); |
b73f9723aa54
8199388: Test development for ChaCha20 and Poly1305 algorithms
jjiang
parents:
50225
diff
changeset
|
432 |
byte[] bytes = new byte[length / 2]; |
b73f9723aa54
8199388: Test development for ChaCha20 and Poly1305 algorithms
jjiang
parents:
50225
diff
changeset
|
433 |
for (int i = 0; i < length; i += 2) { |
b73f9723aa54
8199388: Test development for ChaCha20 and Poly1305 algorithms
jjiang
parents:
50225
diff
changeset
|
434 |
bytes[i / 2] = (byte) ((Character.digit(hex.charAt(i), 16) << 4) |
b73f9723aa54
8199388: Test development for ChaCha20 and Poly1305 algorithms
jjiang
parents:
50225
diff
changeset
|
435 |
+ Character.digit(hex.charAt(i + 1), 16)); |
b73f9723aa54
8199388: Test development for ChaCha20 and Poly1305 algorithms
jjiang
parents:
50225
diff
changeset
|
436 |
} |
b73f9723aa54
8199388: Test development for ChaCha20 and Poly1305 algorithms
jjiang
parents:
50225
diff
changeset
|
437 |
return bytes; |
b73f9723aa54
8199388: Test development for ChaCha20 and Poly1305 algorithms
jjiang
parents:
50225
diff
changeset
|
438 |
} |
34597
e5f2344c6fab
8141526: Allow to collect stdout/stderr from the FinalizationRunner even before the process returns
jbachorik
parents:
diff
changeset
|
439 |
|
e5f2344c6fab
8141526: Allow to collect stdout/stderr from the FinalizationRunner even before the process returns
jbachorik
parents:
diff
changeset
|
440 |
/** |
e5f2344c6fab
8141526: Allow to collect stdout/stderr from the FinalizationRunner even before the process returns
jbachorik
parents:
diff
changeset
|
441 |
* Returns {@link java.util.Random} generator initialized with particular seed. |
e5f2344c6fab
8141526: Allow to collect stdout/stderr from the FinalizationRunner even before the process returns
jbachorik
parents:
diff
changeset
|
442 |
* The seed could be provided via system property {@link Utils#SEED_PROPERTY_NAME} |
e5f2344c6fab
8141526: Allow to collect stdout/stderr from the FinalizationRunner even before the process returns
jbachorik
parents:
diff
changeset
|
443 |
* In case no seed is provided, the method uses a random number. |
e5f2344c6fab
8141526: Allow to collect stdout/stderr from the FinalizationRunner even before the process returns
jbachorik
parents:
diff
changeset
|
444 |
* The used seed printed to stdout. |
e5f2344c6fab
8141526: Allow to collect stdout/stderr from the FinalizationRunner even before the process returns
jbachorik
parents:
diff
changeset
|
445 |
* @return {@link java.util.Random} generator with particular seed. |
e5f2344c6fab
8141526: Allow to collect stdout/stderr from the FinalizationRunner even before the process returns
jbachorik
parents:
diff
changeset
|
446 |
*/ |
e5f2344c6fab
8141526: Allow to collect stdout/stderr from the FinalizationRunner even before the process returns
jbachorik
parents:
diff
changeset
|
447 |
public static Random getRandomInstance() { |
e5f2344c6fab
8141526: Allow to collect stdout/stderr from the FinalizationRunner even before the process returns
jbachorik
parents:
diff
changeset
|
448 |
if (RANDOM_GENERATOR == null) { |
e5f2344c6fab
8141526: Allow to collect stdout/stderr from the FinalizationRunner even before the process returns
jbachorik
parents:
diff
changeset
|
449 |
synchronized (Utils.class) { |
e5f2344c6fab
8141526: Allow to collect stdout/stderr from the FinalizationRunner even before the process returns
jbachorik
parents:
diff
changeset
|
450 |
if (RANDOM_GENERATOR == null) { |
e5f2344c6fab
8141526: Allow to collect stdout/stderr from the FinalizationRunner even before the process returns
jbachorik
parents:
diff
changeset
|
451 |
RANDOM_GENERATOR = new Random(SEED); |
e5f2344c6fab
8141526: Allow to collect stdout/stderr from the FinalizationRunner even before the process returns
jbachorik
parents:
diff
changeset
|
452 |
System.out.printf("For random generator using seed: %d%n", SEED); |
e5f2344c6fab
8141526: Allow to collect stdout/stderr from the FinalizationRunner even before the process returns
jbachorik
parents:
diff
changeset
|
453 |
System.out.printf("To re-run test with same seed value please add \"-D%s=%d\" to command line.%n", SEED_PROPERTY_NAME, SEED); |
e5f2344c6fab
8141526: Allow to collect stdout/stderr from the FinalizationRunner even before the process returns
jbachorik
parents:
diff
changeset
|
454 |
} |
e5f2344c6fab
8141526: Allow to collect stdout/stderr from the FinalizationRunner even before the process returns
jbachorik
parents:
diff
changeset
|
455 |
} |
e5f2344c6fab
8141526: Allow to collect stdout/stderr from the FinalizationRunner even before the process returns
jbachorik
parents:
diff
changeset
|
456 |
} |
e5f2344c6fab
8141526: Allow to collect stdout/stderr from the FinalizationRunner even before the process returns
jbachorik
parents:
diff
changeset
|
457 |
return RANDOM_GENERATOR; |
e5f2344c6fab
8141526: Allow to collect stdout/stderr from the FinalizationRunner even before the process returns
jbachorik
parents:
diff
changeset
|
458 |
} |
e5f2344c6fab
8141526: Allow to collect stdout/stderr from the FinalizationRunner even before the process returns
jbachorik
parents:
diff
changeset
|
459 |
|
e5f2344c6fab
8141526: Allow to collect stdout/stderr from the FinalizationRunner even before the process returns
jbachorik
parents:
diff
changeset
|
460 |
/** |
e5f2344c6fab
8141526: Allow to collect stdout/stderr from the FinalizationRunner even before the process returns
jbachorik
parents:
diff
changeset
|
461 |
* Returns random element of non empty collection |
e5f2344c6fab
8141526: Allow to collect stdout/stderr from the FinalizationRunner even before the process returns
jbachorik
parents:
diff
changeset
|
462 |
* |
e5f2344c6fab
8141526: Allow to collect stdout/stderr from the FinalizationRunner even before the process returns
jbachorik
parents:
diff
changeset
|
463 |
* @param <T> a type of collection element |
e5f2344c6fab
8141526: Allow to collect stdout/stderr from the FinalizationRunner even before the process returns
jbachorik
parents:
diff
changeset
|
464 |
* @param collection collection of elements |
e5f2344c6fab
8141526: Allow to collect stdout/stderr from the FinalizationRunner even before the process returns
jbachorik
parents:
diff
changeset
|
465 |
* @return random element of collection |
e5f2344c6fab
8141526: Allow to collect stdout/stderr from the FinalizationRunner even before the process returns
jbachorik
parents:
diff
changeset
|
466 |
* @throws IllegalArgumentException if collection is empty |
e5f2344c6fab
8141526: Allow to collect stdout/stderr from the FinalizationRunner even before the process returns
jbachorik
parents:
diff
changeset
|
467 |
*/ |
e5f2344c6fab
8141526: Allow to collect stdout/stderr from the FinalizationRunner even before the process returns
jbachorik
parents:
diff
changeset
|
468 |
public static <T> T getRandomElement(Collection<T> collection) |
e5f2344c6fab
8141526: Allow to collect stdout/stderr from the FinalizationRunner even before the process returns
jbachorik
parents:
diff
changeset
|
469 |
throws IllegalArgumentException { |
e5f2344c6fab
8141526: Allow to collect stdout/stderr from the FinalizationRunner even before the process returns
jbachorik
parents:
diff
changeset
|
470 |
if (collection.isEmpty()) { |
e5f2344c6fab
8141526: Allow to collect stdout/stderr from the FinalizationRunner even before the process returns
jbachorik
parents:
diff
changeset
|
471 |
throw new IllegalArgumentException("Empty collection"); |
e5f2344c6fab
8141526: Allow to collect stdout/stderr from the FinalizationRunner even before the process returns
jbachorik
parents:
diff
changeset
|
472 |
} |
e5f2344c6fab
8141526: Allow to collect stdout/stderr from the FinalizationRunner even before the process returns
jbachorik
parents:
diff
changeset
|
473 |
Random random = getRandomInstance(); |
e5f2344c6fab
8141526: Allow to collect stdout/stderr from the FinalizationRunner even before the process returns
jbachorik
parents:
diff
changeset
|
474 |
int elementIndex = 1 + random.nextInt(collection.size() - 1); |
e5f2344c6fab
8141526: Allow to collect stdout/stderr from the FinalizationRunner even before the process returns
jbachorik
parents:
diff
changeset
|
475 |
Iterator<T> iterator = collection.iterator(); |
e5f2344c6fab
8141526: Allow to collect stdout/stderr from the FinalizationRunner even before the process returns
jbachorik
parents:
diff
changeset
|
476 |
while (--elementIndex != 0) { |
e5f2344c6fab
8141526: Allow to collect stdout/stderr from the FinalizationRunner even before the process returns
jbachorik
parents:
diff
changeset
|
477 |
iterator.next(); |
e5f2344c6fab
8141526: Allow to collect stdout/stderr from the FinalizationRunner even before the process returns
jbachorik
parents:
diff
changeset
|
478 |
} |
e5f2344c6fab
8141526: Allow to collect stdout/stderr from the FinalizationRunner even before the process returns
jbachorik
parents:
diff
changeset
|
479 |
return iterator.next(); |
e5f2344c6fab
8141526: Allow to collect stdout/stderr from the FinalizationRunner even before the process returns
jbachorik
parents:
diff
changeset
|
480 |
} |
e5f2344c6fab
8141526: Allow to collect stdout/stderr from the FinalizationRunner even before the process returns
jbachorik
parents:
diff
changeset
|
481 |
|
e5f2344c6fab
8141526: Allow to collect stdout/stderr from the FinalizationRunner even before the process returns
jbachorik
parents:
diff
changeset
|
482 |
/** |
40614
b5d80754b40e
8157957: ClassNotFoundException: jdk.test.lib.JDKToolFinder
ctornqvi
parents:
36793
diff
changeset
|
483 |
* Returns random element of non empty array |
b5d80754b40e
8157957: ClassNotFoundException: jdk.test.lib.JDKToolFinder
ctornqvi
parents:
36793
diff
changeset
|
484 |
* |
b5d80754b40e
8157957: ClassNotFoundException: jdk.test.lib.JDKToolFinder
ctornqvi
parents:
36793
diff
changeset
|
485 |
* @param <T> a type of array element |
b5d80754b40e
8157957: ClassNotFoundException: jdk.test.lib.JDKToolFinder
ctornqvi
parents:
36793
diff
changeset
|
486 |
* @param array array of elements |
b5d80754b40e
8157957: ClassNotFoundException: jdk.test.lib.JDKToolFinder
ctornqvi
parents:
36793
diff
changeset
|
487 |
* @return random element of array |
b5d80754b40e
8157957: ClassNotFoundException: jdk.test.lib.JDKToolFinder
ctornqvi
parents:
36793
diff
changeset
|
488 |
* @throws IllegalArgumentException if array is empty |
b5d80754b40e
8157957: ClassNotFoundException: jdk.test.lib.JDKToolFinder
ctornqvi
parents:
36793
diff
changeset
|
489 |
*/ |
b5d80754b40e
8157957: ClassNotFoundException: jdk.test.lib.JDKToolFinder
ctornqvi
parents:
36793
diff
changeset
|
490 |
public static <T> T getRandomElement(T[] array) |
b5d80754b40e
8157957: ClassNotFoundException: jdk.test.lib.JDKToolFinder
ctornqvi
parents:
36793
diff
changeset
|
491 |
throws IllegalArgumentException { |
b5d80754b40e
8157957: ClassNotFoundException: jdk.test.lib.JDKToolFinder
ctornqvi
parents:
36793
diff
changeset
|
492 |
if (array == null || array.length == 0) { |
b5d80754b40e
8157957: ClassNotFoundException: jdk.test.lib.JDKToolFinder
ctornqvi
parents:
36793
diff
changeset
|
493 |
throw new IllegalArgumentException("Empty or null array"); |
b5d80754b40e
8157957: ClassNotFoundException: jdk.test.lib.JDKToolFinder
ctornqvi
parents:
36793
diff
changeset
|
494 |
} |
b5d80754b40e
8157957: ClassNotFoundException: jdk.test.lib.JDKToolFinder
ctornqvi
parents:
36793
diff
changeset
|
495 |
Random random = getRandomInstance(); |
b5d80754b40e
8157957: ClassNotFoundException: jdk.test.lib.JDKToolFinder
ctornqvi
parents:
36793
diff
changeset
|
496 |
return array[random.nextInt(array.length)]; |
b5d80754b40e
8157957: ClassNotFoundException: jdk.test.lib.JDKToolFinder
ctornqvi
parents:
36793
diff
changeset
|
497 |
} |
b5d80754b40e
8157957: ClassNotFoundException: jdk.test.lib.JDKToolFinder
ctornqvi
parents:
36793
diff
changeset
|
498 |
|
b5d80754b40e
8157957: ClassNotFoundException: jdk.test.lib.JDKToolFinder
ctornqvi
parents:
36793
diff
changeset
|
499 |
/** |
34597
e5f2344c6fab
8141526: Allow to collect stdout/stderr from the FinalizationRunner even before the process returns
jbachorik
parents:
diff
changeset
|
500 |
* Wait for condition to be true |
e5f2344c6fab
8141526: Allow to collect stdout/stderr from the FinalizationRunner even before the process returns
jbachorik
parents:
diff
changeset
|
501 |
* |
e5f2344c6fab
8141526: Allow to collect stdout/stderr from the FinalizationRunner even before the process returns
jbachorik
parents:
diff
changeset
|
502 |
* @param condition, a condition to wait for |
e5f2344c6fab
8141526: Allow to collect stdout/stderr from the FinalizationRunner even before the process returns
jbachorik
parents:
diff
changeset
|
503 |
*/ |
e5f2344c6fab
8141526: Allow to collect stdout/stderr from the FinalizationRunner even before the process returns
jbachorik
parents:
diff
changeset
|
504 |
public static final void waitForCondition(BooleanSupplier condition) { |
e5f2344c6fab
8141526: Allow to collect stdout/stderr from the FinalizationRunner even before the process returns
jbachorik
parents:
diff
changeset
|
505 |
waitForCondition(condition, -1L, 100L); |
e5f2344c6fab
8141526: Allow to collect stdout/stderr from the FinalizationRunner even before the process returns
jbachorik
parents:
diff
changeset
|
506 |
} |
e5f2344c6fab
8141526: Allow to collect stdout/stderr from the FinalizationRunner even before the process returns
jbachorik
parents:
diff
changeset
|
507 |
|
e5f2344c6fab
8141526: Allow to collect stdout/stderr from the FinalizationRunner even before the process returns
jbachorik
parents:
diff
changeset
|
508 |
/** |
e5f2344c6fab
8141526: Allow to collect stdout/stderr from the FinalizationRunner even before the process returns
jbachorik
parents:
diff
changeset
|
509 |
* Wait until timeout for condition to be true |
e5f2344c6fab
8141526: Allow to collect stdout/stderr from the FinalizationRunner even before the process returns
jbachorik
parents:
diff
changeset
|
510 |
* |
e5f2344c6fab
8141526: Allow to collect stdout/stderr from the FinalizationRunner even before the process returns
jbachorik
parents:
diff
changeset
|
511 |
* @param condition, a condition to wait for |
e5f2344c6fab
8141526: Allow to collect stdout/stderr from the FinalizationRunner even before the process returns
jbachorik
parents:
diff
changeset
|
512 |
* @param timeout a time in milliseconds to wait for condition to be true |
e5f2344c6fab
8141526: Allow to collect stdout/stderr from the FinalizationRunner even before the process returns
jbachorik
parents:
diff
changeset
|
513 |
* specifying -1 will wait forever |
e5f2344c6fab
8141526: Allow to collect stdout/stderr from the FinalizationRunner even before the process returns
jbachorik
parents:
diff
changeset
|
514 |
* @return condition value, to determine if wait was successful |
e5f2344c6fab
8141526: Allow to collect stdout/stderr from the FinalizationRunner even before the process returns
jbachorik
parents:
diff
changeset
|
515 |
*/ |
e5f2344c6fab
8141526: Allow to collect stdout/stderr from the FinalizationRunner even before the process returns
jbachorik
parents:
diff
changeset
|
516 |
public static final boolean waitForCondition(BooleanSupplier condition, |
e5f2344c6fab
8141526: Allow to collect stdout/stderr from the FinalizationRunner even before the process returns
jbachorik
parents:
diff
changeset
|
517 |
long timeout) { |
e5f2344c6fab
8141526: Allow to collect stdout/stderr from the FinalizationRunner even before the process returns
jbachorik
parents:
diff
changeset
|
518 |
return waitForCondition(condition, timeout, 100L); |
e5f2344c6fab
8141526: Allow to collect stdout/stderr from the FinalizationRunner even before the process returns
jbachorik
parents:
diff
changeset
|
519 |
} |
e5f2344c6fab
8141526: Allow to collect stdout/stderr from the FinalizationRunner even before the process returns
jbachorik
parents:
diff
changeset
|
520 |
|
e5f2344c6fab
8141526: Allow to collect stdout/stderr from the FinalizationRunner even before the process returns
jbachorik
parents:
diff
changeset
|
521 |
/** |
e5f2344c6fab
8141526: Allow to collect stdout/stderr from the FinalizationRunner even before the process returns
jbachorik
parents:
diff
changeset
|
522 |
* Wait until timeout for condition to be true for specified time |
e5f2344c6fab
8141526: Allow to collect stdout/stderr from the FinalizationRunner even before the process returns
jbachorik
parents:
diff
changeset
|
523 |
* |
e5f2344c6fab
8141526: Allow to collect stdout/stderr from the FinalizationRunner even before the process returns
jbachorik
parents:
diff
changeset
|
524 |
* @param condition, a condition to wait for |
e5f2344c6fab
8141526: Allow to collect stdout/stderr from the FinalizationRunner even before the process returns
jbachorik
parents:
diff
changeset
|
525 |
* @param timeout a time in milliseconds to wait for condition to be true, |
e5f2344c6fab
8141526: Allow to collect stdout/stderr from the FinalizationRunner even before the process returns
jbachorik
parents:
diff
changeset
|
526 |
* specifying -1 will wait forever |
e5f2344c6fab
8141526: Allow to collect stdout/stderr from the FinalizationRunner even before the process returns
jbachorik
parents:
diff
changeset
|
527 |
* @param sleepTime a time to sleep value in milliseconds |
e5f2344c6fab
8141526: Allow to collect stdout/stderr from the FinalizationRunner even before the process returns
jbachorik
parents:
diff
changeset
|
528 |
* @return condition value, to determine if wait was successful |
e5f2344c6fab
8141526: Allow to collect stdout/stderr from the FinalizationRunner even before the process returns
jbachorik
parents:
diff
changeset
|
529 |
*/ |
e5f2344c6fab
8141526: Allow to collect stdout/stderr from the FinalizationRunner even before the process returns
jbachorik
parents:
diff
changeset
|
530 |
public static final boolean waitForCondition(BooleanSupplier condition, |
e5f2344c6fab
8141526: Allow to collect stdout/stderr from the FinalizationRunner even before the process returns
jbachorik
parents:
diff
changeset
|
531 |
long timeout, long sleepTime) { |
e5f2344c6fab
8141526: Allow to collect stdout/stderr from the FinalizationRunner even before the process returns
jbachorik
parents:
diff
changeset
|
532 |
long startTime = System.currentTimeMillis(); |
e5f2344c6fab
8141526: Allow to collect stdout/stderr from the FinalizationRunner even before the process returns
jbachorik
parents:
diff
changeset
|
533 |
while (!(condition.getAsBoolean() || (timeout != -1L |
e5f2344c6fab
8141526: Allow to collect stdout/stderr from the FinalizationRunner even before the process returns
jbachorik
parents:
diff
changeset
|
534 |
&& ((System.currentTimeMillis() - startTime) > timeout)))) { |
e5f2344c6fab
8141526: Allow to collect stdout/stderr from the FinalizationRunner even before the process returns
jbachorik
parents:
diff
changeset
|
535 |
try { |
e5f2344c6fab
8141526: Allow to collect stdout/stderr from the FinalizationRunner even before the process returns
jbachorik
parents:
diff
changeset
|
536 |
Thread.sleep(sleepTime); |
e5f2344c6fab
8141526: Allow to collect stdout/stderr from the FinalizationRunner even before the process returns
jbachorik
parents:
diff
changeset
|
537 |
} catch (InterruptedException e) { |
e5f2344c6fab
8141526: Allow to collect stdout/stderr from the FinalizationRunner even before the process returns
jbachorik
parents:
diff
changeset
|
538 |
Thread.currentThread().interrupt(); |
e5f2344c6fab
8141526: Allow to collect stdout/stderr from the FinalizationRunner even before the process returns
jbachorik
parents:
diff
changeset
|
539 |
throw new Error(e); |
e5f2344c6fab
8141526: Allow to collect stdout/stderr from the FinalizationRunner even before the process returns
jbachorik
parents:
diff
changeset
|
540 |
} |
e5f2344c6fab
8141526: Allow to collect stdout/stderr from the FinalizationRunner even before the process returns
jbachorik
parents:
diff
changeset
|
541 |
} |
e5f2344c6fab
8141526: Allow to collect stdout/stderr from the FinalizationRunner even before the process returns
jbachorik
parents:
diff
changeset
|
542 |
return condition.getAsBoolean(); |
e5f2344c6fab
8141526: Allow to collect stdout/stderr from the FinalizationRunner even before the process returns
jbachorik
parents:
diff
changeset
|
543 |
} |
e5f2344c6fab
8141526: Allow to collect stdout/stderr from the FinalizationRunner even before the process returns
jbachorik
parents:
diff
changeset
|
544 |
|
e5f2344c6fab
8141526: Allow to collect stdout/stderr from the FinalizationRunner even before the process returns
jbachorik
parents:
diff
changeset
|
545 |
/** |
e5f2344c6fab
8141526: Allow to collect stdout/stderr from the FinalizationRunner even before the process returns
jbachorik
parents:
diff
changeset
|
546 |
* Interface same as java.lang.Runnable but with |
e5f2344c6fab
8141526: Allow to collect stdout/stderr from the FinalizationRunner even before the process returns
jbachorik
parents:
diff
changeset
|
547 |
* method {@code run()} able to throw any Throwable. |
e5f2344c6fab
8141526: Allow to collect stdout/stderr from the FinalizationRunner even before the process returns
jbachorik
parents:
diff
changeset
|
548 |
*/ |
e5f2344c6fab
8141526: Allow to collect stdout/stderr from the FinalizationRunner even before the process returns
jbachorik
parents:
diff
changeset
|
549 |
public static interface ThrowingRunnable { |
e5f2344c6fab
8141526: Allow to collect stdout/stderr from the FinalizationRunner even before the process returns
jbachorik
parents:
diff
changeset
|
550 |
void run() throws Throwable; |
e5f2344c6fab
8141526: Allow to collect stdout/stderr from the FinalizationRunner even before the process returns
jbachorik
parents:
diff
changeset
|
551 |
} |
e5f2344c6fab
8141526: Allow to collect stdout/stderr from the FinalizationRunner even before the process returns
jbachorik
parents:
diff
changeset
|
552 |
|
e5f2344c6fab
8141526: Allow to collect stdout/stderr from the FinalizationRunner even before the process returns
jbachorik
parents:
diff
changeset
|
553 |
/** |
e5f2344c6fab
8141526: Allow to collect stdout/stderr from the FinalizationRunner even before the process returns
jbachorik
parents:
diff
changeset
|
554 |
* Filters out an exception that may be thrown by the given |
e5f2344c6fab
8141526: Allow to collect stdout/stderr from the FinalizationRunner even before the process returns
jbachorik
parents:
diff
changeset
|
555 |
* test according to the given filter. |
e5f2344c6fab
8141526: Allow to collect stdout/stderr from the FinalizationRunner even before the process returns
jbachorik
parents:
diff
changeset
|
556 |
* |
e5f2344c6fab
8141526: Allow to collect stdout/stderr from the FinalizationRunner even before the process returns
jbachorik
parents:
diff
changeset
|
557 |
* @param test - method that is invoked and checked for exception. |
e5f2344c6fab
8141526: Allow to collect stdout/stderr from the FinalizationRunner even before the process returns
jbachorik
parents:
diff
changeset
|
558 |
* @param filter - function that checks if the thrown exception matches |
e5f2344c6fab
8141526: Allow to collect stdout/stderr from the FinalizationRunner even before the process returns
jbachorik
parents:
diff
changeset
|
559 |
* criteria given in the filter's implementation. |
e5f2344c6fab
8141526: Allow to collect stdout/stderr from the FinalizationRunner even before the process returns
jbachorik
parents:
diff
changeset
|
560 |
* @return - exception that matches the filter if it has been thrown or |
e5f2344c6fab
8141526: Allow to collect stdout/stderr from the FinalizationRunner even before the process returns
jbachorik
parents:
diff
changeset
|
561 |
* {@code null} otherwise. |
e5f2344c6fab
8141526: Allow to collect stdout/stderr from the FinalizationRunner even before the process returns
jbachorik
parents:
diff
changeset
|
562 |
* @throws Throwable - if test has thrown an exception that does not |
e5f2344c6fab
8141526: Allow to collect stdout/stderr from the FinalizationRunner even before the process returns
jbachorik
parents:
diff
changeset
|
563 |
* match the filter. |
e5f2344c6fab
8141526: Allow to collect stdout/stderr from the FinalizationRunner even before the process returns
jbachorik
parents:
diff
changeset
|
564 |
*/ |
e5f2344c6fab
8141526: Allow to collect stdout/stderr from the FinalizationRunner even before the process returns
jbachorik
parents:
diff
changeset
|
565 |
public static Throwable filterException(ThrowingRunnable test, |
e5f2344c6fab
8141526: Allow to collect stdout/stderr from the FinalizationRunner even before the process returns
jbachorik
parents:
diff
changeset
|
566 |
Function<Throwable, Boolean> filter) throws Throwable { |
e5f2344c6fab
8141526: Allow to collect stdout/stderr from the FinalizationRunner even before the process returns
jbachorik
parents:
diff
changeset
|
567 |
try { |
e5f2344c6fab
8141526: Allow to collect stdout/stderr from the FinalizationRunner even before the process returns
jbachorik
parents:
diff
changeset
|
568 |
test.run(); |
e5f2344c6fab
8141526: Allow to collect stdout/stderr from the FinalizationRunner even before the process returns
jbachorik
parents:
diff
changeset
|
569 |
} catch (Throwable t) { |
e5f2344c6fab
8141526: Allow to collect stdout/stderr from the FinalizationRunner even before the process returns
jbachorik
parents:
diff
changeset
|
570 |
if (filter.apply(t)) { |
e5f2344c6fab
8141526: Allow to collect stdout/stderr from the FinalizationRunner even before the process returns
jbachorik
parents:
diff
changeset
|
571 |
return t; |
e5f2344c6fab
8141526: Allow to collect stdout/stderr from the FinalizationRunner even before the process returns
jbachorik
parents:
diff
changeset
|
572 |
} else { |
e5f2344c6fab
8141526: Allow to collect stdout/stderr from the FinalizationRunner even before the process returns
jbachorik
parents:
diff
changeset
|
573 |
throw t; |
e5f2344c6fab
8141526: Allow to collect stdout/stderr from the FinalizationRunner even before the process returns
jbachorik
parents:
diff
changeset
|
574 |
} |
e5f2344c6fab
8141526: Allow to collect stdout/stderr from the FinalizationRunner even before the process returns
jbachorik
parents:
diff
changeset
|
575 |
} |
e5f2344c6fab
8141526: Allow to collect stdout/stderr from the FinalizationRunner even before the process returns
jbachorik
parents:
diff
changeset
|
576 |
return null; |
e5f2344c6fab
8141526: Allow to collect stdout/stderr from the FinalizationRunner even before the process returns
jbachorik
parents:
diff
changeset
|
577 |
} |
e5f2344c6fab
8141526: Allow to collect stdout/stderr from the FinalizationRunner even before the process returns
jbachorik
parents:
diff
changeset
|
578 |
|
e5f2344c6fab
8141526: Allow to collect stdout/stderr from the FinalizationRunner even before the process returns
jbachorik
parents:
diff
changeset
|
579 |
/** |
e5f2344c6fab
8141526: Allow to collect stdout/stderr from the FinalizationRunner even before the process returns
jbachorik
parents:
diff
changeset
|
580 |
* Ensures a requested class is loaded |
e5f2344c6fab
8141526: Allow to collect stdout/stderr from the FinalizationRunner even before the process returns
jbachorik
parents:
diff
changeset
|
581 |
* @param aClass class to load |
e5f2344c6fab
8141526: Allow to collect stdout/stderr from the FinalizationRunner even before the process returns
jbachorik
parents:
diff
changeset
|
582 |
*/ |
e5f2344c6fab
8141526: Allow to collect stdout/stderr from the FinalizationRunner even before the process returns
jbachorik
parents:
diff
changeset
|
583 |
public static void ensureClassIsLoaded(Class<?> aClass) { |
e5f2344c6fab
8141526: Allow to collect stdout/stderr from the FinalizationRunner even before the process returns
jbachorik
parents:
diff
changeset
|
584 |
if (aClass == null) { |
e5f2344c6fab
8141526: Allow to collect stdout/stderr from the FinalizationRunner even before the process returns
jbachorik
parents:
diff
changeset
|
585 |
throw new Error("Requested null class"); |
e5f2344c6fab
8141526: Allow to collect stdout/stderr from the FinalizationRunner even before the process returns
jbachorik
parents:
diff
changeset
|
586 |
} |
e5f2344c6fab
8141526: Allow to collect stdout/stderr from the FinalizationRunner even before the process returns
jbachorik
parents:
diff
changeset
|
587 |
try { |
e5f2344c6fab
8141526: Allow to collect stdout/stderr from the FinalizationRunner even before the process returns
jbachorik
parents:
diff
changeset
|
588 |
Class.forName(aClass.getName(), /* initialize = */ true, |
e5f2344c6fab
8141526: Allow to collect stdout/stderr from the FinalizationRunner even before the process returns
jbachorik
parents:
diff
changeset
|
589 |
ClassLoader.getSystemClassLoader()); |
e5f2344c6fab
8141526: Allow to collect stdout/stderr from the FinalizationRunner even before the process returns
jbachorik
parents:
diff
changeset
|
590 |
} catch (ClassNotFoundException e) { |
e5f2344c6fab
8141526: Allow to collect stdout/stderr from the FinalizationRunner even before the process returns
jbachorik
parents:
diff
changeset
|
591 |
throw new Error("Class not found", e); |
e5f2344c6fab
8141526: Allow to collect stdout/stderr from the FinalizationRunner even before the process returns
jbachorik
parents:
diff
changeset
|
592 |
} |
e5f2344c6fab
8141526: Allow to collect stdout/stderr from the FinalizationRunner even before the process returns
jbachorik
parents:
diff
changeset
|
593 |
} |
e5f2344c6fab
8141526: Allow to collect stdout/stderr from the FinalizationRunner even before the process returns
jbachorik
parents:
diff
changeset
|
594 |
/** |
e5f2344c6fab
8141526: Allow to collect stdout/stderr from the FinalizationRunner even before the process returns
jbachorik
parents:
diff
changeset
|
595 |
* @param parent a class loader to be the parent for the returned one |
e5f2344c6fab
8141526: Allow to collect stdout/stderr from the FinalizationRunner even before the process returns
jbachorik
parents:
diff
changeset
|
596 |
* @return an UrlClassLoader with urls made of the 'test.class.path' jtreg |
e5f2344c6fab
8141526: Allow to collect stdout/stderr from the FinalizationRunner even before the process returns
jbachorik
parents:
diff
changeset
|
597 |
* property and with the given parent |
e5f2344c6fab
8141526: Allow to collect stdout/stderr from the FinalizationRunner even before the process returns
jbachorik
parents:
diff
changeset
|
598 |
*/ |
e5f2344c6fab
8141526: Allow to collect stdout/stderr from the FinalizationRunner even before the process returns
jbachorik
parents:
diff
changeset
|
599 |
public static URLClassLoader getTestClassPathURLClassLoader(ClassLoader parent) { |
e5f2344c6fab
8141526: Allow to collect stdout/stderr from the FinalizationRunner even before the process returns
jbachorik
parents:
diff
changeset
|
600 |
URL[] urls = Arrays.stream(TEST_CLASS_PATH.split(File.pathSeparator)) |
e5f2344c6fab
8141526: Allow to collect stdout/stderr from the FinalizationRunner even before the process returns
jbachorik
parents:
diff
changeset
|
601 |
.map(Paths::get) |
e5f2344c6fab
8141526: Allow to collect stdout/stderr from the FinalizationRunner even before the process returns
jbachorik
parents:
diff
changeset
|
602 |
.map(Path::toUri) |
e5f2344c6fab
8141526: Allow to collect stdout/stderr from the FinalizationRunner even before the process returns
jbachorik
parents:
diff
changeset
|
603 |
.map(x -> { |
e5f2344c6fab
8141526: Allow to collect stdout/stderr from the FinalizationRunner even before the process returns
jbachorik
parents:
diff
changeset
|
604 |
try { |
e5f2344c6fab
8141526: Allow to collect stdout/stderr from the FinalizationRunner even before the process returns
jbachorik
parents:
diff
changeset
|
605 |
return x.toURL(); |
e5f2344c6fab
8141526: Allow to collect stdout/stderr from the FinalizationRunner even before the process returns
jbachorik
parents:
diff
changeset
|
606 |
} catch (MalformedURLException ex) { |
e5f2344c6fab
8141526: Allow to collect stdout/stderr from the FinalizationRunner even before the process returns
jbachorik
parents:
diff
changeset
|
607 |
throw new Error("Test issue. JTREG property" |
e5f2344c6fab
8141526: Allow to collect stdout/stderr from the FinalizationRunner even before the process returns
jbachorik
parents:
diff
changeset
|
608 |
+ " 'test.class.path'" |
e5f2344c6fab
8141526: Allow to collect stdout/stderr from the FinalizationRunner even before the process returns
jbachorik
parents:
diff
changeset
|
609 |
+ " is not defined correctly", ex); |
e5f2344c6fab
8141526: Allow to collect stdout/stderr from the FinalizationRunner even before the process returns
jbachorik
parents:
diff
changeset
|
610 |
} |
e5f2344c6fab
8141526: Allow to collect stdout/stderr from the FinalizationRunner even before the process returns
jbachorik
parents:
diff
changeset
|
611 |
}).toArray(URL[]::new); |
e5f2344c6fab
8141526: Allow to collect stdout/stderr from the FinalizationRunner even before the process returns
jbachorik
parents:
diff
changeset
|
612 |
return new URLClassLoader(urls, parent); |
e5f2344c6fab
8141526: Allow to collect stdout/stderr from the FinalizationRunner even before the process returns
jbachorik
parents:
diff
changeset
|
613 |
} |
e5f2344c6fab
8141526: Allow to collect stdout/stderr from the FinalizationRunner even before the process returns
jbachorik
parents:
diff
changeset
|
614 |
|
e5f2344c6fab
8141526: Allow to collect stdout/stderr from the FinalizationRunner even before the process returns
jbachorik
parents:
diff
changeset
|
615 |
/** |
e5f2344c6fab
8141526: Allow to collect stdout/stderr from the FinalizationRunner even before the process returns
jbachorik
parents:
diff
changeset
|
616 |
* Runs runnable and checks that it throws expected exception. If exceptionException is null it means |
e5f2344c6fab
8141526: Allow to collect stdout/stderr from the FinalizationRunner even before the process returns
jbachorik
parents:
diff
changeset
|
617 |
* that we expect no exception to be thrown. |
e5f2344c6fab
8141526: Allow to collect stdout/stderr from the FinalizationRunner even before the process returns
jbachorik
parents:
diff
changeset
|
618 |
* @param runnable what we run |
e5f2344c6fab
8141526: Allow to collect stdout/stderr from the FinalizationRunner even before the process returns
jbachorik
parents:
diff
changeset
|
619 |
* @param expectedException expected exception |
e5f2344c6fab
8141526: Allow to collect stdout/stderr from the FinalizationRunner even before the process returns
jbachorik
parents:
diff
changeset
|
620 |
*/ |
51478
36c72eb60d5b
8209771: jdk.test.lib.Utils::runAndCheckException error
weijun
parents:
50367
diff
changeset
|
621 |
public static void runAndCheckException(ThrowingRunnable runnable, Class<? extends Throwable> expectedException) { |
34597
e5f2344c6fab
8141526: Allow to collect stdout/stderr from the FinalizationRunner even before the process returns
jbachorik
parents:
diff
changeset
|
622 |
runAndCheckException(runnable, t -> { |
e5f2344c6fab
8141526: Allow to collect stdout/stderr from the FinalizationRunner even before the process returns
jbachorik
parents:
diff
changeset
|
623 |
if (t == null) { |
e5f2344c6fab
8141526: Allow to collect stdout/stderr from the FinalizationRunner even before the process returns
jbachorik
parents:
diff
changeset
|
624 |
if (expectedException != null) { |
e5f2344c6fab
8141526: Allow to collect stdout/stderr from the FinalizationRunner even before the process returns
jbachorik
parents:
diff
changeset
|
625 |
throw new AssertionError("Didn't get expected exception " + expectedException.getSimpleName()); |
e5f2344c6fab
8141526: Allow to collect stdout/stderr from the FinalizationRunner even before the process returns
jbachorik
parents:
diff
changeset
|
626 |
} |
e5f2344c6fab
8141526: Allow to collect stdout/stderr from the FinalizationRunner even before the process returns
jbachorik
parents:
diff
changeset
|
627 |
} else { |
e5f2344c6fab
8141526: Allow to collect stdout/stderr from the FinalizationRunner even before the process returns
jbachorik
parents:
diff
changeset
|
628 |
String message = "Got unexpected exception " + t.getClass().getSimpleName(); |
e5f2344c6fab
8141526: Allow to collect stdout/stderr from the FinalizationRunner even before the process returns
jbachorik
parents:
diff
changeset
|
629 |
if (expectedException == null) { |
e5f2344c6fab
8141526: Allow to collect stdout/stderr from the FinalizationRunner even before the process returns
jbachorik
parents:
diff
changeset
|
630 |
throw new AssertionError(message, t); |
e5f2344c6fab
8141526: Allow to collect stdout/stderr from the FinalizationRunner even before the process returns
jbachorik
parents:
diff
changeset
|
631 |
} else if (!expectedException.isAssignableFrom(t.getClass())) { |
e5f2344c6fab
8141526: Allow to collect stdout/stderr from the FinalizationRunner even before the process returns
jbachorik
parents:
diff
changeset
|
632 |
message += " instead of " + expectedException.getSimpleName(); |
e5f2344c6fab
8141526: Allow to collect stdout/stderr from the FinalizationRunner even before the process returns
jbachorik
parents:
diff
changeset
|
633 |
throw new AssertionError(message, t); |
e5f2344c6fab
8141526: Allow to collect stdout/stderr from the FinalizationRunner even before the process returns
jbachorik
parents:
diff
changeset
|
634 |
} |
e5f2344c6fab
8141526: Allow to collect stdout/stderr from the FinalizationRunner even before the process returns
jbachorik
parents:
diff
changeset
|
635 |
} |
e5f2344c6fab
8141526: Allow to collect stdout/stderr from the FinalizationRunner even before the process returns
jbachorik
parents:
diff
changeset
|
636 |
}); |
e5f2344c6fab
8141526: Allow to collect stdout/stderr from the FinalizationRunner even before the process returns
jbachorik
parents:
diff
changeset
|
637 |
} |
e5f2344c6fab
8141526: Allow to collect stdout/stderr from the FinalizationRunner even before the process returns
jbachorik
parents:
diff
changeset
|
638 |
|
e5f2344c6fab
8141526: Allow to collect stdout/stderr from the FinalizationRunner even before the process returns
jbachorik
parents:
diff
changeset
|
639 |
/** |
e5f2344c6fab
8141526: Allow to collect stdout/stderr from the FinalizationRunner even before the process returns
jbachorik
parents:
diff
changeset
|
640 |
* Runs runnable and makes some checks to ensure that it throws expected exception. |
e5f2344c6fab
8141526: Allow to collect stdout/stderr from the FinalizationRunner even before the process returns
jbachorik
parents:
diff
changeset
|
641 |
* @param runnable what we run |
e5f2344c6fab
8141526: Allow to collect stdout/stderr from the FinalizationRunner even before the process returns
jbachorik
parents:
diff
changeset
|
642 |
* @param checkException a consumer which checks that we got expected exception and raises a new exception otherwise |
e5f2344c6fab
8141526: Allow to collect stdout/stderr from the FinalizationRunner even before the process returns
jbachorik
parents:
diff
changeset
|
643 |
*/ |
51478
36c72eb60d5b
8209771: jdk.test.lib.Utils::runAndCheckException error
weijun
parents:
50367
diff
changeset
|
644 |
public static void runAndCheckException(ThrowingRunnable runnable, Consumer<Throwable> checkException) { |
36c72eb60d5b
8209771: jdk.test.lib.Utils::runAndCheckException error
weijun
parents:
50367
diff
changeset
|
645 |
Throwable throwable = null; |
34597
e5f2344c6fab
8141526: Allow to collect stdout/stderr from the FinalizationRunner even before the process returns
jbachorik
parents:
diff
changeset
|
646 |
try { |
e5f2344c6fab
8141526: Allow to collect stdout/stderr from the FinalizationRunner even before the process returns
jbachorik
parents:
diff
changeset
|
647 |
runnable.run(); |
e5f2344c6fab
8141526: Allow to collect stdout/stderr from the FinalizationRunner even before the process returns
jbachorik
parents:
diff
changeset
|
648 |
} catch (Throwable t) { |
51478
36c72eb60d5b
8209771: jdk.test.lib.Utils::runAndCheckException error
weijun
parents:
50367
diff
changeset
|
649 |
throwable = t; |
34597
e5f2344c6fab
8141526: Allow to collect stdout/stderr from the FinalizationRunner even before the process returns
jbachorik
parents:
diff
changeset
|
650 |
} |
51478
36c72eb60d5b
8209771: jdk.test.lib.Utils::runAndCheckException error
weijun
parents:
50367
diff
changeset
|
651 |
checkException.accept(throwable); |
34597
e5f2344c6fab
8141526: Allow to collect stdout/stderr from the FinalizationRunner even before the process returns
jbachorik
parents:
diff
changeset
|
652 |
} |
e5f2344c6fab
8141526: Allow to collect stdout/stderr from the FinalizationRunner even before the process returns
jbachorik
parents:
diff
changeset
|
653 |
|
e5f2344c6fab
8141526: Allow to collect stdout/stderr from the FinalizationRunner even before the process returns
jbachorik
parents:
diff
changeset
|
654 |
/** |
e5f2344c6fab
8141526: Allow to collect stdout/stderr from the FinalizationRunner even before the process returns
jbachorik
parents:
diff
changeset
|
655 |
* Converts to VM type signature |
e5f2344c6fab
8141526: Allow to collect stdout/stderr from the FinalizationRunner even before the process returns
jbachorik
parents:
diff
changeset
|
656 |
* |
e5f2344c6fab
8141526: Allow to collect stdout/stderr from the FinalizationRunner even before the process returns
jbachorik
parents:
diff
changeset
|
657 |
* @param type Java type to convert |
e5f2344c6fab
8141526: Allow to collect stdout/stderr from the FinalizationRunner even before the process returns
jbachorik
parents:
diff
changeset
|
658 |
* @return string representation of VM type |
e5f2344c6fab
8141526: Allow to collect stdout/stderr from the FinalizationRunner even before the process returns
jbachorik
parents:
diff
changeset
|
659 |
*/ |
e5f2344c6fab
8141526: Allow to collect stdout/stderr from the FinalizationRunner even before the process returns
jbachorik
parents:
diff
changeset
|
660 |
public static String toJVMTypeSignature(Class<?> type) { |
e5f2344c6fab
8141526: Allow to collect stdout/stderr from the FinalizationRunner even before the process returns
jbachorik
parents:
diff
changeset
|
661 |
if (type.isPrimitive()) { |
e5f2344c6fab
8141526: Allow to collect stdout/stderr from the FinalizationRunner even before the process returns
jbachorik
parents:
diff
changeset
|
662 |
if (type == boolean.class) { |
e5f2344c6fab
8141526: Allow to collect stdout/stderr from the FinalizationRunner even before the process returns
jbachorik
parents:
diff
changeset
|
663 |
return "Z"; |
e5f2344c6fab
8141526: Allow to collect stdout/stderr from the FinalizationRunner even before the process returns
jbachorik
parents:
diff
changeset
|
664 |
} else if (type == byte.class) { |
e5f2344c6fab
8141526: Allow to collect stdout/stderr from the FinalizationRunner even before the process returns
jbachorik
parents:
diff
changeset
|
665 |
return "B"; |
e5f2344c6fab
8141526: Allow to collect stdout/stderr from the FinalizationRunner even before the process returns
jbachorik
parents:
diff
changeset
|
666 |
} else if (type == char.class) { |
e5f2344c6fab
8141526: Allow to collect stdout/stderr from the FinalizationRunner even before the process returns
jbachorik
parents:
diff
changeset
|
667 |
return "C"; |
e5f2344c6fab
8141526: Allow to collect stdout/stderr from the FinalizationRunner even before the process returns
jbachorik
parents:
diff
changeset
|
668 |
} else if (type == double.class) { |
e5f2344c6fab
8141526: Allow to collect stdout/stderr from the FinalizationRunner even before the process returns
jbachorik
parents:
diff
changeset
|
669 |
return "D"; |
e5f2344c6fab
8141526: Allow to collect stdout/stderr from the FinalizationRunner even before the process returns
jbachorik
parents:
diff
changeset
|
670 |
} else if (type == float.class) { |
e5f2344c6fab
8141526: Allow to collect stdout/stderr from the FinalizationRunner even before the process returns
jbachorik
parents:
diff
changeset
|
671 |
return "F"; |
e5f2344c6fab
8141526: Allow to collect stdout/stderr from the FinalizationRunner even before the process returns
jbachorik
parents:
diff
changeset
|
672 |
} else if (type == int.class) { |
e5f2344c6fab
8141526: Allow to collect stdout/stderr from the FinalizationRunner even before the process returns
jbachorik
parents:
diff
changeset
|
673 |
return "I"; |
e5f2344c6fab
8141526: Allow to collect stdout/stderr from the FinalizationRunner even before the process returns
jbachorik
parents:
diff
changeset
|
674 |
} else if (type == long.class) { |
e5f2344c6fab
8141526: Allow to collect stdout/stderr from the FinalizationRunner even before the process returns
jbachorik
parents:
diff
changeset
|
675 |
return "J"; |
e5f2344c6fab
8141526: Allow to collect stdout/stderr from the FinalizationRunner even before the process returns
jbachorik
parents:
diff
changeset
|
676 |
} else if (type == short.class) { |
e5f2344c6fab
8141526: Allow to collect stdout/stderr from the FinalizationRunner even before the process returns
jbachorik
parents:
diff
changeset
|
677 |
return "S"; |
e5f2344c6fab
8141526: Allow to collect stdout/stderr from the FinalizationRunner even before the process returns
jbachorik
parents:
diff
changeset
|
678 |
} else if (type == void.class) { |
e5f2344c6fab
8141526: Allow to collect stdout/stderr from the FinalizationRunner even before the process returns
jbachorik
parents:
diff
changeset
|
679 |
return "V"; |
e5f2344c6fab
8141526: Allow to collect stdout/stderr from the FinalizationRunner even before the process returns
jbachorik
parents:
diff
changeset
|
680 |
} else { |
e5f2344c6fab
8141526: Allow to collect stdout/stderr from the FinalizationRunner even before the process returns
jbachorik
parents:
diff
changeset
|
681 |
throw new Error("Unsupported type: " + type); |
e5f2344c6fab
8141526: Allow to collect stdout/stderr from the FinalizationRunner even before the process returns
jbachorik
parents:
diff
changeset
|
682 |
} |
e5f2344c6fab
8141526: Allow to collect stdout/stderr from the FinalizationRunner even before the process returns
jbachorik
parents:
diff
changeset
|
683 |
} |
e5f2344c6fab
8141526: Allow to collect stdout/stderr from the FinalizationRunner even before the process returns
jbachorik
parents:
diff
changeset
|
684 |
String result = type.getName().replaceAll("\\.", "/"); |
e5f2344c6fab
8141526: Allow to collect stdout/stderr from the FinalizationRunner even before the process returns
jbachorik
parents:
diff
changeset
|
685 |
if (!type.isArray()) { |
e5f2344c6fab
8141526: Allow to collect stdout/stderr from the FinalizationRunner even before the process returns
jbachorik
parents:
diff
changeset
|
686 |
return "L" + result + ";"; |
e5f2344c6fab
8141526: Allow to collect stdout/stderr from the FinalizationRunner even before the process returns
jbachorik
parents:
diff
changeset
|
687 |
} |
e5f2344c6fab
8141526: Allow to collect stdout/stderr from the FinalizationRunner even before the process returns
jbachorik
parents:
diff
changeset
|
688 |
return result; |
e5f2344c6fab
8141526: Allow to collect stdout/stderr from the FinalizationRunner even before the process returns
jbachorik
parents:
diff
changeset
|
689 |
} |
40614
b5d80754b40e
8157957: ClassNotFoundException: jdk.test.lib.JDKToolFinder
ctornqvi
parents:
36793
diff
changeset
|
690 |
|
b5d80754b40e
8157957: ClassNotFoundException: jdk.test.lib.JDKToolFinder
ctornqvi
parents:
36793
diff
changeset
|
691 |
public static Object[] getNullValues(Class<?>... types) { |
b5d80754b40e
8157957: ClassNotFoundException: jdk.test.lib.JDKToolFinder
ctornqvi
parents:
36793
diff
changeset
|
692 |
Object[] result = new Object[types.length]; |
b5d80754b40e
8157957: ClassNotFoundException: jdk.test.lib.JDKToolFinder
ctornqvi
parents:
36793
diff
changeset
|
693 |
int i = 0; |
b5d80754b40e
8157957: ClassNotFoundException: jdk.test.lib.JDKToolFinder
ctornqvi
parents:
36793
diff
changeset
|
694 |
for (Class<?> type : types) { |
b5d80754b40e
8157957: ClassNotFoundException: jdk.test.lib.JDKToolFinder
ctornqvi
parents:
36793
diff
changeset
|
695 |
result[i++] = NULL_VALUES.get(type); |
b5d80754b40e
8157957: ClassNotFoundException: jdk.test.lib.JDKToolFinder
ctornqvi
parents:
36793
diff
changeset
|
696 |
} |
b5d80754b40e
8157957: ClassNotFoundException: jdk.test.lib.JDKToolFinder
ctornqvi
parents:
36793
diff
changeset
|
697 |
return result; |
b5d80754b40e
8157957: ClassNotFoundException: jdk.test.lib.JDKToolFinder
ctornqvi
parents:
36793
diff
changeset
|
698 |
} |
b5d80754b40e
8157957: ClassNotFoundException: jdk.test.lib.JDKToolFinder
ctornqvi
parents:
36793
diff
changeset
|
699 |
private static Map<Class<?>, Object> NULL_VALUES = new HashMap<>(); |
b5d80754b40e
8157957: ClassNotFoundException: jdk.test.lib.JDKToolFinder
ctornqvi
parents:
36793
diff
changeset
|
700 |
static { |
b5d80754b40e
8157957: ClassNotFoundException: jdk.test.lib.JDKToolFinder
ctornqvi
parents:
36793
diff
changeset
|
701 |
NULL_VALUES.put(boolean.class, false); |
b5d80754b40e
8157957: ClassNotFoundException: jdk.test.lib.JDKToolFinder
ctornqvi
parents:
36793
diff
changeset
|
702 |
NULL_VALUES.put(byte.class, (byte) 0); |
b5d80754b40e
8157957: ClassNotFoundException: jdk.test.lib.JDKToolFinder
ctornqvi
parents:
36793
diff
changeset
|
703 |
NULL_VALUES.put(short.class, (short) 0); |
b5d80754b40e
8157957: ClassNotFoundException: jdk.test.lib.JDKToolFinder
ctornqvi
parents:
36793
diff
changeset
|
704 |
NULL_VALUES.put(char.class, '\0'); |
b5d80754b40e
8157957: ClassNotFoundException: jdk.test.lib.JDKToolFinder
ctornqvi
parents:
36793
diff
changeset
|
705 |
NULL_VALUES.put(int.class, 0); |
b5d80754b40e
8157957: ClassNotFoundException: jdk.test.lib.JDKToolFinder
ctornqvi
parents:
36793
diff
changeset
|
706 |
NULL_VALUES.put(long.class, 0L); |
b5d80754b40e
8157957: ClassNotFoundException: jdk.test.lib.JDKToolFinder
ctornqvi
parents:
36793
diff
changeset
|
707 |
NULL_VALUES.put(float.class, 0.0f); |
b5d80754b40e
8157957: ClassNotFoundException: jdk.test.lib.JDKToolFinder
ctornqvi
parents:
36793
diff
changeset
|
708 |
NULL_VALUES.put(double.class, 0.0d); |
b5d80754b40e
8157957: ClassNotFoundException: jdk.test.lib.JDKToolFinder
ctornqvi
parents:
36793
diff
changeset
|
709 |
} |
b5d80754b40e
8157957: ClassNotFoundException: jdk.test.lib.JDKToolFinder
ctornqvi
parents:
36793
diff
changeset
|
710 |
|
b5d80754b40e
8157957: ClassNotFoundException: jdk.test.lib.JDKToolFinder
ctornqvi
parents:
36793
diff
changeset
|
711 |
/** |
b5d80754b40e
8157957: ClassNotFoundException: jdk.test.lib.JDKToolFinder
ctornqvi
parents:
36793
diff
changeset
|
712 |
* Returns mandatory property value |
b5d80754b40e
8157957: ClassNotFoundException: jdk.test.lib.JDKToolFinder
ctornqvi
parents:
36793
diff
changeset
|
713 |
* @param propName is a name of property to request |
b5d80754b40e
8157957: ClassNotFoundException: jdk.test.lib.JDKToolFinder
ctornqvi
parents:
36793
diff
changeset
|
714 |
* @return a String with requested property value |
b5d80754b40e
8157957: ClassNotFoundException: jdk.test.lib.JDKToolFinder
ctornqvi
parents:
36793
diff
changeset
|
715 |
*/ |
b5d80754b40e
8157957: ClassNotFoundException: jdk.test.lib.JDKToolFinder
ctornqvi
parents:
36793
diff
changeset
|
716 |
public static String getMandatoryProperty(String propName) { |
b5d80754b40e
8157957: ClassNotFoundException: jdk.test.lib.JDKToolFinder
ctornqvi
parents:
36793
diff
changeset
|
717 |
Objects.requireNonNull(propName, "Requested null property"); |
b5d80754b40e
8157957: ClassNotFoundException: jdk.test.lib.JDKToolFinder
ctornqvi
parents:
36793
diff
changeset
|
718 |
String prop = System.getProperty(propName); |
b5d80754b40e
8157957: ClassNotFoundException: jdk.test.lib.JDKToolFinder
ctornqvi
parents:
36793
diff
changeset
|
719 |
Objects.requireNonNull(prop, |
b5d80754b40e
8157957: ClassNotFoundException: jdk.test.lib.JDKToolFinder
ctornqvi
parents:
36793
diff
changeset
|
720 |
String.format("A mandatory property '%s' isn't set", propName)); |
b5d80754b40e
8157957: ClassNotFoundException: jdk.test.lib.JDKToolFinder
ctornqvi
parents:
36793
diff
changeset
|
721 |
return prop; |
b5d80754b40e
8157957: ClassNotFoundException: jdk.test.lib.JDKToolFinder
ctornqvi
parents:
36793
diff
changeset
|
722 |
} |
45876
027bfd63b502
8177017: com/oracle/security/ucrypto/TestAES.java fails intermittently
mli
parents:
40849
diff
changeset
|
723 |
|
027bfd63b502
8177017: com/oracle/security/ucrypto/TestAES.java fails intermittently
mli
parents:
40849
diff
changeset
|
724 |
/* |
027bfd63b502
8177017: com/oracle/security/ucrypto/TestAES.java fails intermittently
mli
parents:
40849
diff
changeset
|
725 |
* Run uname with specified arguments. |
027bfd63b502
8177017: com/oracle/security/ucrypto/TestAES.java fails intermittently
mli
parents:
40849
diff
changeset
|
726 |
*/ |
027bfd63b502
8177017: com/oracle/security/ucrypto/TestAES.java fails intermittently
mli
parents:
40849
diff
changeset
|
727 |
public static OutputAnalyzer uname(String... args) throws Throwable { |
027bfd63b502
8177017: com/oracle/security/ucrypto/TestAES.java fails intermittently
mli
parents:
40849
diff
changeset
|
728 |
String[] cmds = new String[args.length + 1]; |
027bfd63b502
8177017: com/oracle/security/ucrypto/TestAES.java fails intermittently
mli
parents:
40849
diff
changeset
|
729 |
cmds[0] = "uname"; |
027bfd63b502
8177017: com/oracle/security/ucrypto/TestAES.java fails intermittently
mli
parents:
40849
diff
changeset
|
730 |
System.arraycopy(args, 0, cmds, 1, args.length); |
027bfd63b502
8177017: com/oracle/security/ucrypto/TestAES.java fails intermittently
mli
parents:
40849
diff
changeset
|
731 |
return ProcessTools.executeCommand(cmds); |
027bfd63b502
8177017: com/oracle/security/ucrypto/TestAES.java fails intermittently
mli
parents:
40849
diff
changeset
|
732 |
} |
027bfd63b502
8177017: com/oracle/security/ucrypto/TestAES.java fails intermittently
mli
parents:
40849
diff
changeset
|
733 |
|
027bfd63b502
8177017: com/oracle/security/ucrypto/TestAES.java fails intermittently
mli
parents:
40849
diff
changeset
|
734 |
/* |
027bfd63b502
8177017: com/oracle/security/ucrypto/TestAES.java fails intermittently
mli
parents:
40849
diff
changeset
|
735 |
* Returns the system distro. |
027bfd63b502
8177017: com/oracle/security/ucrypto/TestAES.java fails intermittently
mli
parents:
40849
diff
changeset
|
736 |
*/ |
027bfd63b502
8177017: com/oracle/security/ucrypto/TestAES.java fails intermittently
mli
parents:
40849
diff
changeset
|
737 |
public static String distro() { |
027bfd63b502
8177017: com/oracle/security/ucrypto/TestAES.java fails intermittently
mli
parents:
40849
diff
changeset
|
738 |
try { |
027bfd63b502
8177017: com/oracle/security/ucrypto/TestAES.java fails intermittently
mli
parents:
40849
diff
changeset
|
739 |
return uname("-v").asLines().get(0); |
027bfd63b502
8177017: com/oracle/security/ucrypto/TestAES.java fails intermittently
mli
parents:
40849
diff
changeset
|
740 |
} catch (Throwable t) { |
027bfd63b502
8177017: com/oracle/security/ucrypto/TestAES.java fails intermittently
mli
parents:
40849
diff
changeset
|
741 |
throw new RuntimeException("Failed to determine distro.", t); |
027bfd63b502
8177017: com/oracle/security/ucrypto/TestAES.java fails intermittently
mli
parents:
40849
diff
changeset
|
742 |
} |
027bfd63b502
8177017: com/oracle/security/ucrypto/TestAES.java fails intermittently
mli
parents:
40849
diff
changeset
|
743 |
} |
46237 | 744 |
|
46207 | 745 |
// This method is intended to be called from a jtreg test. |
746 |
// It will identify the name of the test by means of stack walking. |
|
747 |
// It can handle both jtreg tests and a testng tests wrapped inside jtreg tests. |
|
748 |
// For jtreg tests the name of the test will be searched by stack-walking |
|
749 |
// until the method main() is found; the class containing that method is the |
|
750 |
// main test class and will be returned as the name of the test. |
|
751 |
// Special handling is used for testng tests. |
|
58144
d003b3ef8b60
8230854: Cleanup SuppressWarnings in test lib and remove noisy traces in StreamPumper
clanger
parents:
55199
diff
changeset
|
752 |
@SuppressWarnings("unchecked") |
46207 | 753 |
public static String getTestName() { |
754 |
String result = null; |
|
755 |
// If we are using testng, then we should be able to load the "Test" annotation. |
|
58144
d003b3ef8b60
8230854: Cleanup SuppressWarnings in test lib and remove noisy traces in StreamPumper
clanger
parents:
55199
diff
changeset
|
756 |
Class<? extends Annotation> testClassAnnotation; |
46207 | 757 |
|
758 |
try { |
|
58144
d003b3ef8b60
8230854: Cleanup SuppressWarnings in test lib and remove noisy traces in StreamPumper
clanger
parents:
55199
diff
changeset
|
759 |
testClassAnnotation = (Class<? extends Annotation>)Class.forName("org.testng.annotations.Test"); |
46207 | 760 |
} catch (ClassNotFoundException e) { |
761 |
testClassAnnotation = null; |
|
762 |
} |
|
763 |
||
764 |
StackTraceElement[] elms = (new Throwable()).getStackTrace(); |
|
765 |
for (StackTraceElement n: elms) { |
|
766 |
String className = n.getClassName(); |
|
767 |
||
768 |
// If this is a "main" method, then use its class name, but only |
|
769 |
// if we are not using testng. |
|
770 |
if (testClassAnnotation == null && "main".equals(n.getMethodName())) { |
|
771 |
result = className; |
|
772 |
break; |
|
773 |
} |
|
774 |
||
775 |
// If this is a testng test, the test will have no "main" method. We can |
|
776 |
// detect a testng test class by looking for the org.testng.annotations.Test |
|
777 |
// annotation. If present, then use the name of this class. |
|
778 |
if (testClassAnnotation != null) { |
|
779 |
try { |
|
58144
d003b3ef8b60
8230854: Cleanup SuppressWarnings in test lib and remove noisy traces in StreamPumper
clanger
parents:
55199
diff
changeset
|
780 |
Class<?> c = Class.forName(className); |
46207 | 781 |
if (c.isAnnotationPresent(testClassAnnotation)) { |
782 |
result = className; |
|
783 |
break; |
|
784 |
} |
|
785 |
} catch (ClassNotFoundException e) { |
|
786 |
throw new RuntimeException("Unexpected exception: " + e, e); |
|
787 |
} |
|
788 |
} |
|
789 |
} |
|
790 |
||
791 |
if (result == null) { |
|
792 |
throw new RuntimeException("Couldn't find main test class in stack trace"); |
|
793 |
} |
|
794 |
||
795 |
return result; |
|
796 |
} |
|
797 |
||
50225
2942ae532175
8201331: Better test cleanup for jdk/jfr/api/consumer/TestRecordingFile.java
egahlin
parents:
49255
diff
changeset
|
798 |
/** |
2942ae532175
8201331: Better test cleanup for jdk/jfr/api/consumer/TestRecordingFile.java
egahlin
parents:
49255
diff
changeset
|
799 |
* Creates an empty file in "user.dir" if the property set. |
2942ae532175
8201331: Better test cleanup for jdk/jfr/api/consumer/TestRecordingFile.java
egahlin
parents:
49255
diff
changeset
|
800 |
* <p> |
2942ae532175
8201331: Better test cleanup for jdk/jfr/api/consumer/TestRecordingFile.java
egahlin
parents:
49255
diff
changeset
|
801 |
* This method is meant as a replacement for {@code Files#createTempFile(String, String, FileAttribute...)} |
2942ae532175
8201331: Better test cleanup for jdk/jfr/api/consumer/TestRecordingFile.java
egahlin
parents:
49255
diff
changeset
|
802 |
* that doesn't leave files behind in /tmp directory of the test machine |
2942ae532175
8201331: Better test cleanup for jdk/jfr/api/consumer/TestRecordingFile.java
egahlin
parents:
49255
diff
changeset
|
803 |
* <p> |
2942ae532175
8201331: Better test cleanup for jdk/jfr/api/consumer/TestRecordingFile.java
egahlin
parents:
49255
diff
changeset
|
804 |
* If the property "user.dir" is not set, "." will be used. |
2942ae532175
8201331: Better test cleanup for jdk/jfr/api/consumer/TestRecordingFile.java
egahlin
parents:
49255
diff
changeset
|
805 |
* |
2942ae532175
8201331: Better test cleanup for jdk/jfr/api/consumer/TestRecordingFile.java
egahlin
parents:
49255
diff
changeset
|
806 |
* @param prefix |
2942ae532175
8201331: Better test cleanup for jdk/jfr/api/consumer/TestRecordingFile.java
egahlin
parents:
49255
diff
changeset
|
807 |
* @param suffix |
2942ae532175
8201331: Better test cleanup for jdk/jfr/api/consumer/TestRecordingFile.java
egahlin
parents:
49255
diff
changeset
|
808 |
* @param attrs |
2942ae532175
8201331: Better test cleanup for jdk/jfr/api/consumer/TestRecordingFile.java
egahlin
parents:
49255
diff
changeset
|
809 |
* @return the path to the newly created file that did not exist before this |
2942ae532175
8201331: Better test cleanup for jdk/jfr/api/consumer/TestRecordingFile.java
egahlin
parents:
49255
diff
changeset
|
810 |
* method was invoked |
2942ae532175
8201331: Better test cleanup for jdk/jfr/api/consumer/TestRecordingFile.java
egahlin
parents:
49255
diff
changeset
|
811 |
* @throws IOException |
2942ae532175
8201331: Better test cleanup for jdk/jfr/api/consumer/TestRecordingFile.java
egahlin
parents:
49255
diff
changeset
|
812 |
* |
2942ae532175
8201331: Better test cleanup for jdk/jfr/api/consumer/TestRecordingFile.java
egahlin
parents:
49255
diff
changeset
|
813 |
* @see {@link Files#createTempFile(String, String, FileAttribute...)} |
2942ae532175
8201331: Better test cleanup for jdk/jfr/api/consumer/TestRecordingFile.java
egahlin
parents:
49255
diff
changeset
|
814 |
*/ |
2942ae532175
8201331: Better test cleanup for jdk/jfr/api/consumer/TestRecordingFile.java
egahlin
parents:
49255
diff
changeset
|
815 |
public static Path createTempFile(String prefix, String suffix, FileAttribute<?>... attrs) throws IOException { |
2942ae532175
8201331: Better test cleanup for jdk/jfr/api/consumer/TestRecordingFile.java
egahlin
parents:
49255
diff
changeset
|
816 |
Path dir = Paths.get(System.getProperty("user.dir", ".")); |
2942ae532175
8201331: Better test cleanup for jdk/jfr/api/consumer/TestRecordingFile.java
egahlin
parents:
49255
diff
changeset
|
817 |
return Files.createTempFile(dir, prefix, suffix); |
2942ae532175
8201331: Better test cleanup for jdk/jfr/api/consumer/TestRecordingFile.java
egahlin
parents:
49255
diff
changeset
|
818 |
} |
55199
3a09397c147e
8223396: [TESTBUG] several jfr tests do not clean up files created in /tmp
mseledtsov
parents:
53903
diff
changeset
|
819 |
|
3a09397c147e
8223396: [TESTBUG] several jfr tests do not clean up files created in /tmp
mseledtsov
parents:
53903
diff
changeset
|
820 |
/** |
3a09397c147e
8223396: [TESTBUG] several jfr tests do not clean up files created in /tmp
mseledtsov
parents:
53903
diff
changeset
|
821 |
* Creates an empty directory in "user.dir" or "." |
3a09397c147e
8223396: [TESTBUG] several jfr tests do not clean up files created in /tmp
mseledtsov
parents:
53903
diff
changeset
|
822 |
* <p> |
3a09397c147e
8223396: [TESTBUG] several jfr tests do not clean up files created in /tmp
mseledtsov
parents:
53903
diff
changeset
|
823 |
* This method is meant as a replacement for {@code Files#createTempDirectory(String, String, FileAttribute...)} |
3a09397c147e
8223396: [TESTBUG] several jfr tests do not clean up files created in /tmp
mseledtsov
parents:
53903
diff
changeset
|
824 |
* that doesn't leave files behind in /tmp directory of the test machine |
3a09397c147e
8223396: [TESTBUG] several jfr tests do not clean up files created in /tmp
mseledtsov
parents:
53903
diff
changeset
|
825 |
* <p> |
3a09397c147e
8223396: [TESTBUG] several jfr tests do not clean up files created in /tmp
mseledtsov
parents:
53903
diff
changeset
|
826 |
* If the property "user.dir" is not set, "." will be used. |
3a09397c147e
8223396: [TESTBUG] several jfr tests do not clean up files created in /tmp
mseledtsov
parents:
53903
diff
changeset
|
827 |
* |
3a09397c147e
8223396: [TESTBUG] several jfr tests do not clean up files created in /tmp
mseledtsov
parents:
53903
diff
changeset
|
828 |
* @param prefix |
3a09397c147e
8223396: [TESTBUG] several jfr tests do not clean up files created in /tmp
mseledtsov
parents:
53903
diff
changeset
|
829 |
* @param attrs |
3a09397c147e
8223396: [TESTBUG] several jfr tests do not clean up files created in /tmp
mseledtsov
parents:
53903
diff
changeset
|
830 |
* @return the path to the newly created directory |
3a09397c147e
8223396: [TESTBUG] several jfr tests do not clean up files created in /tmp
mseledtsov
parents:
53903
diff
changeset
|
831 |
* @throws IOException |
3a09397c147e
8223396: [TESTBUG] several jfr tests do not clean up files created in /tmp
mseledtsov
parents:
53903
diff
changeset
|
832 |
* |
3a09397c147e
8223396: [TESTBUG] several jfr tests do not clean up files created in /tmp
mseledtsov
parents:
53903
diff
changeset
|
833 |
* @see {@link Files#createTempDirectory(String, String, FileAttribute...)} |
3a09397c147e
8223396: [TESTBUG] several jfr tests do not clean up files created in /tmp
mseledtsov
parents:
53903
diff
changeset
|
834 |
*/ |
3a09397c147e
8223396: [TESTBUG] several jfr tests do not clean up files created in /tmp
mseledtsov
parents:
53903
diff
changeset
|
835 |
public static Path createTempDirectory(String prefix, FileAttribute<?>... attrs) throws IOException { |
3a09397c147e
8223396: [TESTBUG] several jfr tests do not clean up files created in /tmp
mseledtsov
parents:
53903
diff
changeset
|
836 |
Path dir = Paths.get(System.getProperty("user.dir", ".")); |
3a09397c147e
8223396: [TESTBUG] several jfr tests do not clean up files created in /tmp
mseledtsov
parents:
53903
diff
changeset
|
837 |
return Files.createTempDirectory(dir, prefix); |
3a09397c147e
8223396: [TESTBUG] several jfr tests do not clean up files created in /tmp
mseledtsov
parents:
53903
diff
changeset
|
838 |
} |
34597
e5f2344c6fab
8141526: Allow to collect stdout/stderr from the FinalizationRunner even before the process returns
jbachorik
parents:
diff
changeset
|
839 |
} |