author | iignatyev |
Sun, 05 Mar 2017 22:25:52 -0800 | |
changeset 44238 | a81138486a91 |
parent 43414 | bd9a5a9dc9bc |
permissions | -rw-r--r-- |
26915
ba674d5d0f77
8025606: [TESTBUG] Move ctw-tests to /testlibrary_tests
vlivanov
parents:
diff
changeset
|
1 |
/* |
40631
ed82623d7831
8157957: ClassNotFoundException: jdk.test.lib.JDKToolFinder
ctornqvi
parents:
30604
diff
changeset
|
2 |
* Copyright (c) 2013, 2016, Oracle and/or its affiliates. All rights reserved. |
26915
ba674d5d0f77
8025606: [TESTBUG] Move ctw-tests to /testlibrary_tests
vlivanov
parents:
diff
changeset
|
3 |
* DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. |
ba674d5d0f77
8025606: [TESTBUG] Move ctw-tests to /testlibrary_tests
vlivanov
parents:
diff
changeset
|
4 |
* |
ba674d5d0f77
8025606: [TESTBUG] Move ctw-tests to /testlibrary_tests
vlivanov
parents:
diff
changeset
|
5 |
* This code is free software; you can redistribute it and/or modify it |
ba674d5d0f77
8025606: [TESTBUG] Move ctw-tests to /testlibrary_tests
vlivanov
parents:
diff
changeset
|
6 |
* under the terms of the GNU General Public License version 2 only, as |
ba674d5d0f77
8025606: [TESTBUG] Move ctw-tests to /testlibrary_tests
vlivanov
parents:
diff
changeset
|
7 |
* published by the Free Software Foundation. |
ba674d5d0f77
8025606: [TESTBUG] Move ctw-tests to /testlibrary_tests
vlivanov
parents:
diff
changeset
|
8 |
* |
ba674d5d0f77
8025606: [TESTBUG] Move ctw-tests to /testlibrary_tests
vlivanov
parents:
diff
changeset
|
9 |
* This code is distributed in the hope that it will be useful, but WITHOUT |
ba674d5d0f77
8025606: [TESTBUG] Move ctw-tests to /testlibrary_tests
vlivanov
parents:
diff
changeset
|
10 |
* ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or |
ba674d5d0f77
8025606: [TESTBUG] Move ctw-tests to /testlibrary_tests
vlivanov
parents:
diff
changeset
|
11 |
* FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License |
ba674d5d0f77
8025606: [TESTBUG] Move ctw-tests to /testlibrary_tests
vlivanov
parents:
diff
changeset
|
12 |
* version 2 for more details (a copy is included in the LICENSE file that |
ba674d5d0f77
8025606: [TESTBUG] Move ctw-tests to /testlibrary_tests
vlivanov
parents:
diff
changeset
|
13 |
* accompanied this code). |
ba674d5d0f77
8025606: [TESTBUG] Move ctw-tests to /testlibrary_tests
vlivanov
parents:
diff
changeset
|
14 |
* |
ba674d5d0f77
8025606: [TESTBUG] Move ctw-tests to /testlibrary_tests
vlivanov
parents:
diff
changeset
|
15 |
* You should have received a copy of the GNU General Public License version |
ba674d5d0f77
8025606: [TESTBUG] Move ctw-tests to /testlibrary_tests
vlivanov
parents:
diff
changeset
|
16 |
* 2 along with this work; if not, write to the Free Software Foundation, |
ba674d5d0f77
8025606: [TESTBUG] Move ctw-tests to /testlibrary_tests
vlivanov
parents:
diff
changeset
|
17 |
* Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA. |
ba674d5d0f77
8025606: [TESTBUG] Move ctw-tests to /testlibrary_tests
vlivanov
parents:
diff
changeset
|
18 |
* |
ba674d5d0f77
8025606: [TESTBUG] Move ctw-tests to /testlibrary_tests
vlivanov
parents:
diff
changeset
|
19 |
* Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA |
ba674d5d0f77
8025606: [TESTBUG] Move ctw-tests to /testlibrary_tests
vlivanov
parents:
diff
changeset
|
20 |
* or visit www.oracle.com if you need additional information or have any |
ba674d5d0f77
8025606: [TESTBUG] Move ctw-tests to /testlibrary_tests
vlivanov
parents:
diff
changeset
|
21 |
* questions. |
ba674d5d0f77
8025606: [TESTBUG] Move ctw-tests to /testlibrary_tests
vlivanov
parents:
diff
changeset
|
22 |
*/ |
ba674d5d0f77
8025606: [TESTBUG] Move ctw-tests to /testlibrary_tests
vlivanov
parents:
diff
changeset
|
23 |
|
43414 | 24 |
import java.util.Arrays; |
26915
ba674d5d0f77
8025606: [TESTBUG] Move ctw-tests to /testlibrary_tests
vlivanov
parents:
diff
changeset
|
25 |
import java.util.List; |
ba674d5d0f77
8025606: [TESTBUG] Move ctw-tests to /testlibrary_tests
vlivanov
parents:
diff
changeset
|
26 |
import java.util.Collections; |
ba674d5d0f77
8025606: [TESTBUG] Move ctw-tests to /testlibrary_tests
vlivanov
parents:
diff
changeset
|
27 |
import java.util.ArrayList; |
ba674d5d0f77
8025606: [TESTBUG] Move ctw-tests to /testlibrary_tests
vlivanov
parents:
diff
changeset
|
28 |
|
ba674d5d0f77
8025606: [TESTBUG] Move ctw-tests to /testlibrary_tests
vlivanov
parents:
diff
changeset
|
29 |
import java.io.File; |
ba674d5d0f77
8025606: [TESTBUG] Move ctw-tests to /testlibrary_tests
vlivanov
parents:
diff
changeset
|
30 |
import java.io.Writer; |
ba674d5d0f77
8025606: [TESTBUG] Move ctw-tests to /testlibrary_tests
vlivanov
parents:
diff
changeset
|
31 |
import java.io.FileWriter; |
ba674d5d0f77
8025606: [TESTBUG] Move ctw-tests to /testlibrary_tests
vlivanov
parents:
diff
changeset
|
32 |
import java.io.IOException; |
ba674d5d0f77
8025606: [TESTBUG] Move ctw-tests to /testlibrary_tests
vlivanov
parents:
diff
changeset
|
33 |
import java.io.BufferedReader; |
ba674d5d0f77
8025606: [TESTBUG] Move ctw-tests to /testlibrary_tests
vlivanov
parents:
diff
changeset
|
34 |
|
ba674d5d0f77
8025606: [TESTBUG] Move ctw-tests to /testlibrary_tests
vlivanov
parents:
diff
changeset
|
35 |
import java.nio.file.Files; |
ba674d5d0f77
8025606: [TESTBUG] Move ctw-tests to /testlibrary_tests
vlivanov
parents:
diff
changeset
|
36 |
import java.nio.file.Paths; |
ba674d5d0f77
8025606: [TESTBUG] Move ctw-tests to /testlibrary_tests
vlivanov
parents:
diff
changeset
|
37 |
import java.nio.file.StandardCopyOption; |
ba674d5d0f77
8025606: [TESTBUG] Move ctw-tests to /testlibrary_tests
vlivanov
parents:
diff
changeset
|
38 |
import java.nio.charset.Charset; |
ba674d5d0f77
8025606: [TESTBUG] Move ctw-tests to /testlibrary_tests
vlivanov
parents:
diff
changeset
|
39 |
|
44238
a81138486a91
8172457: JarDirTest.java fails after recent change
iignatyev
parents:
43414
diff
changeset
|
40 |
import jdk.test.lib.Platform; |
30604
b8d532cb6420
8067013: Rename the com.oracle.java.testlibary package
ykantser
parents:
26915
diff
changeset
|
41 |
import jdk.test.lib.JDKToolFinder; |
40631
ed82623d7831
8157957: ClassNotFoundException: jdk.test.lib.JDKToolFinder
ctornqvi
parents:
30604
diff
changeset
|
42 |
import jdk.test.lib.process.OutputAnalyzer; |
43414 | 43 |
import jdk.test.lib.process.ProcessTools; |
26915
ba674d5d0f77
8025606: [TESTBUG] Move ctw-tests to /testlibrary_tests
vlivanov
parents:
diff
changeset
|
44 |
|
ba674d5d0f77
8025606: [TESTBUG] Move ctw-tests to /testlibrary_tests
vlivanov
parents:
diff
changeset
|
45 |
public abstract class CtwTest { |
43414 | 46 |
private static final String LOG_FILE = "ctw.log"; |
47 |
private static final String[] CTW_COMMAND = { |
|
48 |
"-Xbootclasspath/a:.", |
|
49 |
"-XX:+UnlockDiagnosticVMOptions", |
|
50 |
"-XX:+WhiteBoxAPI", |
|
51 |
"-Dsun.hotspot.tools.ctw.logfile=" + LOG_FILE, |
|
52 |
"--add-exports", "java.base/jdk.internal.jimage=ALL-UNNAMED", |
|
53 |
"--add-exports", "java.base/jdk.internal.misc=ALL-UNNAMED", |
|
54 |
"--add-exports", "java.base/jdk.internal.reflect=ALL-UNNAMED", |
|
55 |
sun.hotspot.tools.ctw.CompileTheWorld.class.getName(), |
|
56 |
}; |
|
26915
ba674d5d0f77
8025606: [TESTBUG] Move ctw-tests to /testlibrary_tests
vlivanov
parents:
diff
changeset
|
57 |
protected final String[] shouldContain; |
ba674d5d0f77
8025606: [TESTBUG] Move ctw-tests to /testlibrary_tests
vlivanov
parents:
diff
changeset
|
58 |
protected CtwTest(String[] shouldContain) { |
ba674d5d0f77
8025606: [TESTBUG] Move ctw-tests to /testlibrary_tests
vlivanov
parents:
diff
changeset
|
59 |
this.shouldContain = shouldContain; |
ba674d5d0f77
8025606: [TESTBUG] Move ctw-tests to /testlibrary_tests
vlivanov
parents:
diff
changeset
|
60 |
} |
ba674d5d0f77
8025606: [TESTBUG] Move ctw-tests to /testlibrary_tests
vlivanov
parents:
diff
changeset
|
61 |
|
ba674d5d0f77
8025606: [TESTBUG] Move ctw-tests to /testlibrary_tests
vlivanov
parents:
diff
changeset
|
62 |
public void run(String[] args) throws Exception { |
ba674d5d0f77
8025606: [TESTBUG] Move ctw-tests to /testlibrary_tests
vlivanov
parents:
diff
changeset
|
63 |
if (args.length == 0) { |
ba674d5d0f77
8025606: [TESTBUG] Move ctw-tests to /testlibrary_tests
vlivanov
parents:
diff
changeset
|
64 |
throw new Error("args is empty"); |
ba674d5d0f77
8025606: [TESTBUG] Move ctw-tests to /testlibrary_tests
vlivanov
parents:
diff
changeset
|
65 |
} |
ba674d5d0f77
8025606: [TESTBUG] Move ctw-tests to /testlibrary_tests
vlivanov
parents:
diff
changeset
|
66 |
switch (args[0]) { |
ba674d5d0f77
8025606: [TESTBUG] Move ctw-tests to /testlibrary_tests
vlivanov
parents:
diff
changeset
|
67 |
case "prepare": |
ba674d5d0f77
8025606: [TESTBUG] Move ctw-tests to /testlibrary_tests
vlivanov
parents:
diff
changeset
|
68 |
prepare(); |
ba674d5d0f77
8025606: [TESTBUG] Move ctw-tests to /testlibrary_tests
vlivanov
parents:
diff
changeset
|
69 |
break; |
ba674d5d0f77
8025606: [TESTBUG] Move ctw-tests to /testlibrary_tests
vlivanov
parents:
diff
changeset
|
70 |
case "check": |
43414 | 71 |
check(); |
72 |
break; |
|
73 |
case "compile": |
|
74 |
compile(args); |
|
26915
ba674d5d0f77
8025606: [TESTBUG] Move ctw-tests to /testlibrary_tests
vlivanov
parents:
diff
changeset
|
75 |
break; |
ba674d5d0f77
8025606: [TESTBUG] Move ctw-tests to /testlibrary_tests
vlivanov
parents:
diff
changeset
|
76 |
default: |
ba674d5d0f77
8025606: [TESTBUG] Move ctw-tests to /testlibrary_tests
vlivanov
parents:
diff
changeset
|
77 |
throw new Error("unregonized action -- " + args[0]); |
ba674d5d0f77
8025606: [TESTBUG] Move ctw-tests to /testlibrary_tests
vlivanov
parents:
diff
changeset
|
78 |
} |
ba674d5d0f77
8025606: [TESTBUG] Move ctw-tests to /testlibrary_tests
vlivanov
parents:
diff
changeset
|
79 |
} |
ba674d5d0f77
8025606: [TESTBUG] Move ctw-tests to /testlibrary_tests
vlivanov
parents:
diff
changeset
|
80 |
|
ba674d5d0f77
8025606: [TESTBUG] Move ctw-tests to /testlibrary_tests
vlivanov
parents:
diff
changeset
|
81 |
protected void prepare() throws Exception { } |
ba674d5d0f77
8025606: [TESTBUG] Move ctw-tests to /testlibrary_tests
vlivanov
parents:
diff
changeset
|
82 |
|
43414 | 83 |
protected void check() throws Exception { |
84 |
try (BufferedReader r = Files.newBufferedReader(Paths.get(LOG_FILE), |
|
26915
ba674d5d0f77
8025606: [TESTBUG] Move ctw-tests to /testlibrary_tests
vlivanov
parents:
diff
changeset
|
85 |
Charset.defaultCharset())) { |
ba674d5d0f77
8025606: [TESTBUG] Move ctw-tests to /testlibrary_tests
vlivanov
parents:
diff
changeset
|
86 |
OutputAnalyzer output = readOutput(r); |
43414 | 87 |
for (String test : shouldContain) { |
26915
ba674d5d0f77
8025606: [TESTBUG] Move ctw-tests to /testlibrary_tests
vlivanov
parents:
diff
changeset
|
88 |
output.shouldContain(test); |
ba674d5d0f77
8025606: [TESTBUG] Move ctw-tests to /testlibrary_tests
vlivanov
parents:
diff
changeset
|
89 |
} |
ba674d5d0f77
8025606: [TESTBUG] Move ctw-tests to /testlibrary_tests
vlivanov
parents:
diff
changeset
|
90 |
} |
ba674d5d0f77
8025606: [TESTBUG] Move ctw-tests to /testlibrary_tests
vlivanov
parents:
diff
changeset
|
91 |
} |
ba674d5d0f77
8025606: [TESTBUG] Move ctw-tests to /testlibrary_tests
vlivanov
parents:
diff
changeset
|
92 |
|
43414 | 93 |
protected void compile(String[] args) throws Exception { |
94 |
// concat CTW_COMMAND and args w/o 0th element |
|
95 |
String[] cmd = Arrays.copyOf(CTW_COMMAND, CTW_COMMAND.length + args.length - 1); |
|
96 |
System.arraycopy(args, 1, cmd, CTW_COMMAND.length, args.length - 1); |
|
44238
a81138486a91
8172457: JarDirTest.java fails after recent change
iignatyev
parents:
43414
diff
changeset
|
97 |
if (Platform.isWindows()) { |
a81138486a91
8172457: JarDirTest.java fails after recent change
iignatyev
parents:
43414
diff
changeset
|
98 |
// '*' has to be escaped on windows |
a81138486a91
8172457: JarDirTest.java fails after recent change
iignatyev
parents:
43414
diff
changeset
|
99 |
for (int i = 0; i < cmd.length; ++i) { |
a81138486a91
8172457: JarDirTest.java fails after recent change
iignatyev
parents:
43414
diff
changeset
|
100 |
cmd[i] = cmd[i].replace("*", "\"*\""); |
a81138486a91
8172457: JarDirTest.java fails after recent change
iignatyev
parents:
43414
diff
changeset
|
101 |
} |
a81138486a91
8172457: JarDirTest.java fails after recent change
iignatyev
parents:
43414
diff
changeset
|
102 |
} |
43414 | 103 |
ProcessBuilder pb = ProcessTools.createJavaProcessBuilder(true, cmd); |
104 |
OutputAnalyzer output = new OutputAnalyzer(pb.start()); |
|
105 |
dump(output, "compile"); |
|
106 |
output.shouldHaveExitValue(0); |
|
107 |
} |
|
108 |
||
26915
ba674d5d0f77
8025606: [TESTBUG] Move ctw-tests to /testlibrary_tests
vlivanov
parents:
diff
changeset
|
109 |
private static OutputAnalyzer readOutput(BufferedReader reader) |
ba674d5d0f77
8025606: [TESTBUG] Move ctw-tests to /testlibrary_tests
vlivanov
parents:
diff
changeset
|
110 |
throws IOException { |
ba674d5d0f77
8025606: [TESTBUG] Move ctw-tests to /testlibrary_tests
vlivanov
parents:
diff
changeset
|
111 |
StringBuilder builder = new StringBuilder(); |
ba674d5d0f77
8025606: [TESTBUG] Move ctw-tests to /testlibrary_tests
vlivanov
parents:
diff
changeset
|
112 |
String eol = String.format("%n"); |
ba674d5d0f77
8025606: [TESTBUG] Move ctw-tests to /testlibrary_tests
vlivanov
parents:
diff
changeset
|
113 |
String line; |
ba674d5d0f77
8025606: [TESTBUG] Move ctw-tests to /testlibrary_tests
vlivanov
parents:
diff
changeset
|
114 |
|
ba674d5d0f77
8025606: [TESTBUG] Move ctw-tests to /testlibrary_tests
vlivanov
parents:
diff
changeset
|
115 |
while ((line = reader.readLine()) != null) { |
ba674d5d0f77
8025606: [TESTBUG] Move ctw-tests to /testlibrary_tests
vlivanov
parents:
diff
changeset
|
116 |
builder.append(line); |
ba674d5d0f77
8025606: [TESTBUG] Move ctw-tests to /testlibrary_tests
vlivanov
parents:
diff
changeset
|
117 |
builder.append(eol); |
ba674d5d0f77
8025606: [TESTBUG] Move ctw-tests to /testlibrary_tests
vlivanov
parents:
diff
changeset
|
118 |
} |
ba674d5d0f77
8025606: [TESTBUG] Move ctw-tests to /testlibrary_tests
vlivanov
parents:
diff
changeset
|
119 |
return new OutputAnalyzer(builder.toString(), ""); |
ba674d5d0f77
8025606: [TESTBUG] Move ctw-tests to /testlibrary_tests
vlivanov
parents:
diff
changeset
|
120 |
} |
ba674d5d0f77
8025606: [TESTBUG] Move ctw-tests to /testlibrary_tests
vlivanov
parents:
diff
changeset
|
121 |
|
ba674d5d0f77
8025606: [TESTBUG] Move ctw-tests to /testlibrary_tests
vlivanov
parents:
diff
changeset
|
122 |
protected void dump(OutputAnalyzer output, String name) { |
ba674d5d0f77
8025606: [TESTBUG] Move ctw-tests to /testlibrary_tests
vlivanov
parents:
diff
changeset
|
123 |
try (Writer w = new FileWriter(name + ".out")) { |
ba674d5d0f77
8025606: [TESTBUG] Move ctw-tests to /testlibrary_tests
vlivanov
parents:
diff
changeset
|
124 |
String s = output.getStdout(); |
ba674d5d0f77
8025606: [TESTBUG] Move ctw-tests to /testlibrary_tests
vlivanov
parents:
diff
changeset
|
125 |
w.write(s, s.length(), 0); |
ba674d5d0f77
8025606: [TESTBUG] Move ctw-tests to /testlibrary_tests
vlivanov
parents:
diff
changeset
|
126 |
} catch (IOException io) { |
ba674d5d0f77
8025606: [TESTBUG] Move ctw-tests to /testlibrary_tests
vlivanov
parents:
diff
changeset
|
127 |
io.printStackTrace(); |
ba674d5d0f77
8025606: [TESTBUG] Move ctw-tests to /testlibrary_tests
vlivanov
parents:
diff
changeset
|
128 |
} |
ba674d5d0f77
8025606: [TESTBUG] Move ctw-tests to /testlibrary_tests
vlivanov
parents:
diff
changeset
|
129 |
try (Writer w = new FileWriter(name + ".err")) { |
ba674d5d0f77
8025606: [TESTBUG] Move ctw-tests to /testlibrary_tests
vlivanov
parents:
diff
changeset
|
130 |
String s = output.getStderr(); |
ba674d5d0f77
8025606: [TESTBUG] Move ctw-tests to /testlibrary_tests
vlivanov
parents:
diff
changeset
|
131 |
w.write(s, s.length(), 0); |
ba674d5d0f77
8025606: [TESTBUG] Move ctw-tests to /testlibrary_tests
vlivanov
parents:
diff
changeset
|
132 |
} catch (IOException io) { |
ba674d5d0f77
8025606: [TESTBUG] Move ctw-tests to /testlibrary_tests
vlivanov
parents:
diff
changeset
|
133 |
io.printStackTrace(); |
ba674d5d0f77
8025606: [TESTBUG] Move ctw-tests to /testlibrary_tests
vlivanov
parents:
diff
changeset
|
134 |
} |
ba674d5d0f77
8025606: [TESTBUG] Move ctw-tests to /testlibrary_tests
vlivanov
parents:
diff
changeset
|
135 |
} |
ba674d5d0f77
8025606: [TESTBUG] Move ctw-tests to /testlibrary_tests
vlivanov
parents:
diff
changeset
|
136 |
|
ba674d5d0f77
8025606: [TESTBUG] Move ctw-tests to /testlibrary_tests
vlivanov
parents:
diff
changeset
|
137 |
protected ProcessBuilder createJarProcessBuilder(String... command) |
ba674d5d0f77
8025606: [TESTBUG] Move ctw-tests to /testlibrary_tests
vlivanov
parents:
diff
changeset
|
138 |
throws Exception { |
ba674d5d0f77
8025606: [TESTBUG] Move ctw-tests to /testlibrary_tests
vlivanov
parents:
diff
changeset
|
139 |
String javapath = JDKToolFinder.getJDKTool("jar"); |
ba674d5d0f77
8025606: [TESTBUG] Move ctw-tests to /testlibrary_tests
vlivanov
parents:
diff
changeset
|
140 |
|
ba674d5d0f77
8025606: [TESTBUG] Move ctw-tests to /testlibrary_tests
vlivanov
parents:
diff
changeset
|
141 |
ArrayList<String> args = new ArrayList<>(); |
ba674d5d0f77
8025606: [TESTBUG] Move ctw-tests to /testlibrary_tests
vlivanov
parents:
diff
changeset
|
142 |
args.add(javapath); |
ba674d5d0f77
8025606: [TESTBUG] Move ctw-tests to /testlibrary_tests
vlivanov
parents:
diff
changeset
|
143 |
Collections.addAll(args, command); |
ba674d5d0f77
8025606: [TESTBUG] Move ctw-tests to /testlibrary_tests
vlivanov
parents:
diff
changeset
|
144 |
|
ba674d5d0f77
8025606: [TESTBUG] Move ctw-tests to /testlibrary_tests
vlivanov
parents:
diff
changeset
|
145 |
return new ProcessBuilder(args.toArray(new String[args.size()])); |
ba674d5d0f77
8025606: [TESTBUG] Move ctw-tests to /testlibrary_tests
vlivanov
parents:
diff
changeset
|
146 |
} |
ba674d5d0f77
8025606: [TESTBUG] Move ctw-tests to /testlibrary_tests
vlivanov
parents:
diff
changeset
|
147 |
} |