author | mr |
Wed, 16 Jan 2019 16:27:21 -0800 | |
changeset 53372 | 4003935e6e5f |
parent 49538 | 707553fcca04 |
permissions | -rw-r--r-- |
12301 | 1 |
/* |
48335
f1e1a4fc1cc7
8193503: javah launcher was not removed by JDK-8191054
alanb
parents:
47216
diff
changeset
|
2 |
* Copyright (c) 2012, 2017, Oracle and/or its affiliates. All rights reserved. |
12301 | 3 |
* DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. |
4 |
* |
|
5 |
* This code is free software; you can redistribute it and/or modify it |
|
6 |
* under the terms of the GNU General Public License version 2 only, as |
|
7 |
* published by the Free Software Foundation. |
|
8 |
* |
|
9 |
* This code is distributed in the hope that it will be useful, but WITHOUT |
|
10 |
* ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or |
|
11 |
* FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License |
|
12 |
* version 2 for more details (a copy is included in the LICENSE file that |
|
13 |
* accompanied this code). |
|
14 |
* |
|
15 |
* You should have received a copy of the GNU General Public License version |
|
16 |
* 2 along with this work; if not, write to the Free Software Foundation, |
|
17 |
* Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA. |
|
18 |
* |
|
19 |
* Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA |
|
20 |
* or visit www.oracle.com if you need additional information or have any |
|
21 |
* questions. |
|
22 |
*/ |
|
23 |
||
24 |
/* |
|
25 |
* @test |
|
16091
4eb1062acb5b
8002091: tools/launcher/ToolsOpts.java test started to fail since 7u11 b01 on Windows
ksrini
parents:
13411
diff
changeset
|
26 |
* @bug 8002091 |
48335
f1e1a4fc1cc7
8193503: javah launcher was not removed by JDK-8191054
alanb
parents:
47216
diff
changeset
|
27 |
* @summary Test options patterns for javac,javap and javadoc using |
12301 | 28 |
* javac as a test launcher. Create a dummy javac and intercept options to check |
29 |
* reception of options as passed through the launcher without having to launch |
|
30 |
* javac. Only -J and -cp ./* options should be consumed by the launcher. |
|
45944
882cea808912
8179292: a number of launcher tests fail when run with --limit-modules due to CNFE: javax.tools.ToolProvider
anazarov
parents:
43734
diff
changeset
|
31 |
* @modules jdk.compiler |
882cea808912
8179292: a number of launcher tests fail when run with --limit-modules due to CNFE: javax.tools.ToolProvider
anazarov
parents:
43734
diff
changeset
|
32 |
* jdk.zipfs |
12301 | 33 |
* @run main ToolsOpts |
34 |
* @author ssides |
|
35 |
*/ |
|
36 |
||
37 |
import java.io.File; |
|
38 |
import java.io.IOException; |
|
39 |
import java.util.ArrayList; |
|
40 |
import java.util.List; |
|
41 |
||
42 |
public class ToolsOpts extends TestHelper { |
|
43 |
static String[][] optionPatterns = { |
|
44 |
{"-J-Xmx128m"}, |
|
45 |
{"-J-version"}, |
|
46 |
{"-J-XshowSettings:vm"}, |
|
47 |
{"-J-Xdiag"}, |
|
48 |
{"-J-showversion"}, |
|
49 |
{"-J-version", "-option"}, |
|
50 |
{"-option"}, |
|
51 |
{"-option:sub"}, |
|
52 |
{"-option:sub-"}, |
|
53 |
{"-option:sub1,sub2"}, // -option:list |
|
54 |
{"-option:{sub1,sub2,sub3}"}, // -option:{list} |
|
55 |
{"-option:{{sub1,sub2,sub3}}"},// -option:{{list}} |
|
56 |
{"-option/c:/export/date/tmp"}, |
|
57 |
{"-option=value"}, |
|
58 |
{"-Dpk1.pk2.pk3"}, // dot in option |
|
59 |
{"-Dpk1.pk2=value"}, // dot in option followed by =value |
|
60 |
{"@<filename>"}, |
|
61 |
{"-option", "http://site.com", "http://site.org"}, |
|
62 |
{"-option", "name", "p1:p2.."}, |
|
63 |
{"-All these non-options show launchers pass options as is to tool."}, |
|
64 |
{"-option"}, |
|
65 |
{"-option:sub"}, |
|
66 |
{"-option:sub-"}, |
|
67 |
{"-option", "<path>"}, |
|
68 |
{"-option", "<file>"}, |
|
69 |
{"-option", "<dir>"}, |
|
70 |
{"-option", "http://a/b/c/g;x?y#s"}, |
|
71 |
{"-option", "<html code>"}, |
|
72 |
{"-option", "name1:name2"}, |
|
73 |
{"-option", "3"}, |
|
74 |
{"option1", "-J-version", "option2"}, |
|
75 |
{"option1", "-J-version", "-J-XshowSettings:vm", "option2"},}; |
|
76 |
||
77 |
static void init() throws IOException { |
|
78 |
||
79 |
// A tool which simulates com.sun.tools.javac.Main argument processing, |
|
80 |
// intercepts options passed via the javac launcher. |
|
81 |
final String mainJava = "Main" + JAVA_FILE_EXT; |
|
82 |
List<String> contents = new ArrayList<>(); |
|
83 |
contents.add("package com.sun.tools.javac;"); |
|
84 |
contents.add("public class Main {"); |
|
85 |
contents.add(" public static void main(String... args) {\n"); |
|
86 |
contents.add(" for (String x : args) {\n"); |
|
87 |
contents.add(" if(x.compareTo(\" \")!=0)\n"); |
|
88 |
contents.add(" System.out.println(x);\n"); |
|
89 |
contents.add(" }\n"); |
|
90 |
contents.add(" }\n"); |
|
91 |
contents.add("}\n"); |
|
43734
64b58fc82d90
8173777: Merge javac -Xmodule into javac--patch-module
jlahoda
parents:
40261
diff
changeset
|
92 |
String mainJavaPath = "patch-src/com/sun/tools/javac/" + mainJava; |
64b58fc82d90
8173777: Merge javac -Xmodule into javac--patch-module
jlahoda
parents:
40261
diff
changeset
|
93 |
File mainJavaFile = new File(mainJavaPath.replace('/', File.separatorChar)); |
64b58fc82d90
8173777: Merge javac -Xmodule into javac--patch-module
jlahoda
parents:
40261
diff
changeset
|
94 |
mainJavaFile.getParentFile().mkdirs(); |
64b58fc82d90
8173777: Merge javac -Xmodule into javac--patch-module
jlahoda
parents:
40261
diff
changeset
|
95 |
createFile(mainJavaFile, contents); |
12301 | 96 |
|
36511 | 97 |
// compile Main.java into directory to override classes in jdk.compiler |
98 |
new File("jdk.compiler").mkdir(); |
|
43734
64b58fc82d90
8173777: Merge javac -Xmodule into javac--patch-module
jlahoda
parents:
40261
diff
changeset
|
99 |
compile("--patch-module", "jdk.compiler=patch-src", |
64b58fc82d90
8173777: Merge javac -Xmodule into javac--patch-module
jlahoda
parents:
40261
diff
changeset
|
100 |
"-d", "jdk.compiler", |
64b58fc82d90
8173777: Merge javac -Xmodule into javac--patch-module
jlahoda
parents:
40261
diff
changeset
|
101 |
mainJavaFile.toString()); |
36511 | 102 |
} |
12301 | 103 |
|
104 |
static void pass(String msg) { |
|
105 |
System.out.println("pass: " + msg); |
|
106 |
} |
|
107 |
||
108 |
static void errout(String msg) { |
|
109 |
System.err.println(msg); |
|
110 |
} |
|
111 |
||
112 |
// Return position of -J option or -1 is does not contain a -J option. |
|
113 |
static int indexOfJoption(String[] opts) { |
|
114 |
for (int i = 0; i < opts.length; i++) { |
|
115 |
if (opts[i].startsWith("-J")) { |
|
116 |
return i; |
|
117 |
} |
|
118 |
} |
|
119 |
return -1; |
|
120 |
} |
|
121 |
||
122 |
/* |
|
123 |
* Check that J options a) are not passed to tool, and b) do the right thing, |
|
124 |
* that is, they should be passed to java launcher and work as expected. |
|
125 |
*/ |
|
126 |
static void checkJoptionOutput(TestResult tr, String[] opts) throws IOException { |
|
127 |
// Check -J-version options are not passed but do what they should. |
|
128 |
String jopts = ""; |
|
129 |
for (String pat : opts) { |
|
130 |
jopts = jopts.concat(pat + " "); |
|
131 |
if (tr.contains("-J")) { |
|
132 |
throw new RuntimeException( |
|
133 |
"failed: output should not contain option " + pat); |
|
134 |
} |
|
135 |
if (pat.compareTo("-J-version") == 0 || |
|
136 |
pat.compareTo("-J-showversion") == 0) { |
|
12303
498f8b38423b
7158090: (launcher) newly added ToolsOpts.java fails on openjdk builds
ksrini
parents:
12301
diff
changeset
|
137 |
if (!tr.contains("java version") && |
498f8b38423b
7158090: (launcher) newly added ToolsOpts.java fails on openjdk builds
ksrini
parents:
12301
diff
changeset
|
138 |
!tr.contains("openjdk version")) { |
12301 | 139 |
throw new RuntimeException("failed: " + pat + |
12303
498f8b38423b
7158090: (launcher) newly added ToolsOpts.java fails on openjdk builds
ksrini
parents:
12301
diff
changeset
|
140 |
" should display a version string."); |
12301 | 141 |
} |
142 |
} else if (pat.compareTo("-J-XshowSettings:VM") == 0) { |
|
143 |
if (!tr.contains("VM settings")) { |
|
144 |
throw new RuntimeException("failed: " + pat + |
|
145 |
" should have display VM settings."); |
|
146 |
} |
|
147 |
} |
|
148 |
} |
|
149 |
pass("Joption check: " + jopts); |
|
150 |
} |
|
151 |
||
152 |
/* |
|
153 |
* Feed each option pattern in optionPatterns array to javac launcher with |
|
154 |
* checking program preempting javac. Check that option received by 'dummy' |
|
155 |
* javac is the one passed on the command line. |
|
156 |
*/ |
|
157 |
static void runTestOptions() throws IOException { |
|
158 |
init(); |
|
37540
e92d95400f31
8154470: defines.h confused about PROGNAME and JAVA_ARGS
martin
parents:
36511
diff
changeset
|
159 |
TestResult tr; |
12301 | 160 |
int jpos = -1; |
40261
86a49ba76f52
8136930: Simplify use of module-system options by custom launchers
mchung
parents:
37779
diff
changeset
|
161 |
String xPatch = "-J--patch-module=jdk.compiler=jdk.compiler"; |
12301 | 162 |
for (String arg[] : optionPatterns) { |
163 |
jpos = indexOfJoption(arg); |
|
164 |
//Build a cmd string for output in results reporting. |
|
37779
7c84df693837
8154956: Module system implementation refresh (4/2016)
alanb
parents:
37540
diff
changeset
|
165 |
String cmdString = javacCmd + " " + xPatch; |
12301 | 166 |
for (String opt : arg) { |
167 |
cmdString = cmdString.concat(" " + opt); |
|
168 |
} |
|
169 |
switch (arg.length) { |
|
170 |
case 1: |
|
37779
7c84df693837
8154956: Module system implementation refresh (4/2016)
alanb
parents:
37540
diff
changeset
|
171 |
tr = doExec(javacCmd, xPatch, arg[0]); |
12301 | 172 |
break; |
173 |
case 2: |
|
37779
7c84df693837
8154956: Module system implementation refresh (4/2016)
alanb
parents:
37540
diff
changeset
|
174 |
tr = doExec(javacCmd, xPatch, arg[0], arg[1]); |
12301 | 175 |
break; |
176 |
case 3: |
|
37779
7c84df693837
8154956: Module system implementation refresh (4/2016)
alanb
parents:
37540
diff
changeset
|
177 |
tr = doExec(javacCmd, xPatch, arg[0], arg[1], arg[2]); |
12301 | 178 |
break; |
179 |
case 4: |
|
37779
7c84df693837
8154956: Module system implementation refresh (4/2016)
alanb
parents:
37540
diff
changeset
|
180 |
tr = doExec(javacCmd, xPatch, arg[0], arg[1], arg[2], arg[3]); |
12301 | 181 |
break; |
182 |
default: |
|
183 |
tr = null; |
|
184 |
break; |
|
185 |
} |
|
186 |
||
187 |
//-Joptions should not be passed to tool |
|
188 |
if (jpos > -1) { |
|
189 |
checkJoptionOutput(tr, arg); |
|
190 |
if (tr.contains(arg[jpos])) { |
|
191 |
throw new RuntimeException( |
|
192 |
"failed! Should not have passed -J option to tool.\n" |
|
193 |
+ "CMD: " + cmdString); |
|
194 |
} |
|
195 |
} else { |
|
49538
707553fcca04
8196750: [Testbug] tools/launcher tests need to tolerate unrelated warnings
anazarov
parents:
48335
diff
changeset
|
196 |
// check that each non -J option was passed to tool. It looks for each arg in the output. |
707553fcca04
8196750: [Testbug] tools/launcher tests need to tolerate unrelated warnings
anazarov
parents:
48335
diff
changeset
|
197 |
// Irrelevant lines in the output are skipped. Arguments order is checked as well. |
707553fcca04
8196750: [Testbug] tools/launcher tests need to tolerate unrelated warnings
anazarov
parents:
48335
diff
changeset
|
198 |
int j = 0; |
707553fcca04
8196750: [Testbug] tools/launcher tests need to tolerate unrelated warnings
anazarov
parents:
48335
diff
changeset
|
199 |
List<String> output = tr.testOutput; |
12301 | 200 |
for (int i = 0; i < arg.length; i++) { |
49538
707553fcca04
8196750: [Testbug] tools/launcher tests need to tolerate unrelated warnings
anazarov
parents:
48335
diff
changeset
|
201 |
boolean found = false; |
707553fcca04
8196750: [Testbug] tools/launcher tests need to tolerate unrelated warnings
anazarov
parents:
48335
diff
changeset
|
202 |
for (; j < output.size(); j++) { |
707553fcca04
8196750: [Testbug] tools/launcher tests need to tolerate unrelated warnings
anazarov
parents:
48335
diff
changeset
|
203 |
if (output.get(j).equals(arg[i])) { |
707553fcca04
8196750: [Testbug] tools/launcher tests need to tolerate unrelated warnings
anazarov
parents:
48335
diff
changeset
|
204 |
pass("check " + output.get(j) + " == " + arg[i]); |
707553fcca04
8196750: [Testbug] tools/launcher tests need to tolerate unrelated warnings
anazarov
parents:
48335
diff
changeset
|
205 |
found = true; |
707553fcca04
8196750: [Testbug] tools/launcher tests need to tolerate unrelated warnings
anazarov
parents:
48335
diff
changeset
|
206 |
break; |
707553fcca04
8196750: [Testbug] tools/launcher tests need to tolerate unrelated warnings
anazarov
parents:
48335
diff
changeset
|
207 |
} |
707553fcca04
8196750: [Testbug] tools/launcher tests need to tolerate unrelated warnings
anazarov
parents:
48335
diff
changeset
|
208 |
} |
707553fcca04
8196750: [Testbug] tools/launcher tests need to tolerate unrelated warnings
anazarov
parents:
48335
diff
changeset
|
209 |
if (!found) { |
12301 | 210 |
throw new RuntimeException( |
49538
707553fcca04
8196750: [Testbug] tools/launcher tests need to tolerate unrelated warnings
anazarov
parents:
48335
diff
changeset
|
211 |
"failed! Should have passed non -J option [" + arg[i] + "] to tool.\n" |
707553fcca04
8196750: [Testbug] tools/launcher tests need to tolerate unrelated warnings
anazarov
parents:
48335
diff
changeset
|
212 |
+ "CMD: " + cmdString); |
12301 | 213 |
} |
214 |
} |
|
215 |
} |
|
216 |
pass(cmdString); |
|
217 |
} |
|
218 |
} |
|
219 |
||
220 |
public static void main(String... args) throws IOException { |
|
221 |
runTestOptions(); |
|
222 |
} |
|
223 |
} |