author | lana |
Thu, 02 Jun 2016 21:14:26 +0000 | |
changeset 38627 | 6dea0d12ee02 |
parent 37540 | e92d95400f31 |
child 39881 | c082c149d6eb |
permissions | -rw-r--r-- |
2 | 1 |
/* |
34011
b1ce08dd7f17
8139986: Store debug level in java.vm.debug and conditionally print in "java -version"
amurillo
parents:
33987
diff
changeset
|
2 |
* Copyright (c) 2007, 2015, Oracle and/or its affiliates. All rights reserved. |
2 | 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 |
* |
|
5506 | 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. |
|
2 | 22 |
*/ |
23 |
||
24 |
/** |
|
25 |
* @test |
|
34011
b1ce08dd7f17
8139986: Store debug level in java.vm.debug and conditionally print in "java -version"
amurillo
parents:
33987
diff
changeset
|
26 |
* @bug 6545058 6611182 8016209 8139986 |
12301 | 27 |
* @summary validate and test -version, -fullversion, and internal, as well as |
28 |
* sanity checks if a tool can be launched. |
|
2 | 29 |
* @compile VersionCheck.java |
30 |
* @run main VersionCheck |
|
31 |
*/ |
|
32 |
||
33 |
import java.io.File; |
|
12301 | 34 |
import java.io.FileFilter; |
2 | 35 |
import java.util.Map; |
36 |
import java.util.ArrayList; |
|
12301 | 37 |
import java.util.HashMap; |
2 | 38 |
import java.util.List; |
39 |
||
12301 | 40 |
public class VersionCheck extends TestHelper { |
2 | 41 |
|
12301 | 42 |
// tools that do not accept -J-option |
43 |
static final String[] BLACKLIST_JOPTION = { |
|
44 |
"controlpanel", |
|
15529
8112eb76bda3
8007135: tools/launcher/VersionCheck.java failing with new tool jabswitch
ksrini
parents:
14998
diff
changeset
|
45 |
"jabswitch", |
12301 | 46 |
"java-rmi", |
47 |
"java-rmi.cgi", |
|
48 |
"java", |
|
27565 | 49 |
"javacpl", |
34434
16dd60e78af4
8144660: VersionCheck.java fails when it tries to run jaccess*.exe -J-version on windows
ksrini
parents:
34392
diff
changeset
|
50 |
"jaccessinspector", |
16dd60e78af4
8144660: VersionCheck.java fails when it tries to run jaccess*.exe -J-version on windows
ksrini
parents:
34392
diff
changeset
|
51 |
"jaccessinspector-32", |
16dd60e78af4
8144660: VersionCheck.java fails when it tries to run jaccess*.exe -J-version on windows
ksrini
parents:
34392
diff
changeset
|
52 |
"jaccesswalker", |
16dd60e78af4
8144660: VersionCheck.java fails when it tries to run jaccess*.exe -J-version on windows
ksrini
parents:
34392
diff
changeset
|
53 |
"jaccesswalker-32", |
12301 | 54 |
"javaw", |
55 |
"javaws", |
|
56 |
"jcontrol", |
|
18152
804f7c54faa6
8016209: TEST_BUG: non-compliant jmc in the bin directory hangs testing
ksrini
parents:
16029
diff
changeset
|
57 |
"jmc", |
21327
9fc34e0b2a47
8026873: tools/launcher/VersionCheck.java fails in jprt because of jmc.ini
kizune
parents:
18152
diff
changeset
|
58 |
"jmc.ini", |
27565 | 59 |
"jp2launcher", |
12301 | 60 |
"jvisualvm", |
61 |
"packager", |
|
27565 | 62 |
"ssvagent", |
12301 | 63 |
"unpack200", |
64 |
"wsimport" |
|
65 |
}; |
|
2 | 66 |
|
12301 | 67 |
// tools that do not accept -version |
68 |
static final String[] BLACKLIST_VERSION = { |
|
2 | 69 |
"appletviewer", |
12301 | 70 |
"controlpanel", |
34434
16dd60e78af4
8144660: VersionCheck.java fails when it tries to run jaccess*.exe -J-version on windows
ksrini
parents:
34392
diff
changeset
|
71 |
"jaccessinspector", |
16dd60e78af4
8144660: VersionCheck.java fails when it tries to run jaccess*.exe -J-version on windows
ksrini
parents:
34392
diff
changeset
|
72 |
"jaccessinspector-32", |
16dd60e78af4
8144660: VersionCheck.java fails when it tries to run jaccess*.exe -J-version on windows
ksrini
parents:
34392
diff
changeset
|
73 |
"jaccesswalker", |
16dd60e78af4
8144660: VersionCheck.java fails when it tries to run jaccess*.exe -J-version on windows
ksrini
parents:
34392
diff
changeset
|
74 |
"jaccesswalker-32", |
2 | 75 |
"jar", |
76 |
"jarsigner", |
|
12301 | 77 |
"java-rmi", |
78 |
"java-rmi.cgi", |
|
2 | 79 |
"javadoc", |
27942
b43cb0ec4975
8066841: Need to exclude javacpl in tools/launcher/VersionCheck.java
ksrini
parents:
27565
diff
changeset
|
80 |
"javacpl", |
12301 | 81 |
"javaws", |
82 |
"jcmd", |
|
2 | 83 |
"jconsole", |
12301 | 84 |
"jcontrol", |
14998
b9a99aac309e
8005634: tools/launcher/VersionCheck.java fails version check on jdeps
chegar
parents:
12301
diff
changeset
|
85 |
"jdeps", |
27565 | 86 |
"jimage", |
2 | 87 |
"jinfo", |
36511 | 88 |
"jlink", |
2 | 89 |
"jmap", |
36511 | 90 |
"jmod", |
18152
804f7c54faa6
8016209: TEST_BUG: non-compliant jmc in the bin directory hangs testing
ksrini
parents:
16029
diff
changeset
|
91 |
"jmc", |
21327
9fc34e0b2a47
8026873: tools/launcher/VersionCheck.java fails in jprt because of jmc.ini
kizune
parents:
18152
diff
changeset
|
92 |
"jmc.ini", |
2 | 93 |
"jps", |
12301 | 94 |
"jrunscript", |
16029 | 95 |
"jjs", |
27565 | 96 |
"jp2launcher", |
12301 | 97 |
"jsadebugd", |
2 | 98 |
"jstack", |
99 |
"jstat", |
|
100 |
"jstatd", |
|
12301 | 101 |
"jvisualvm", |
2 | 102 |
"keytool", |
12301 | 103 |
"kinit", |
104 |
"klist", |
|
105 |
"ktab", |
|
2 | 106 |
"orbd", |
107 |
"pack200", |
|
12301 | 108 |
"packager", |
2 | 109 |
"policytool", |
110 |
"rmic", |
|
111 |
"rmid", |
|
112 |
"rmiregistry", |
|
12301 | 113 |
"schemagen", // returns error code 127 |
2 | 114 |
"serialver", |
115 |
"servertool", |
|
27565 | 116 |
"ssvagent", |
2 | 117 |
"tnameserv", |
12301 | 118 |
"unpack200", |
2 | 119 |
"wsgen", |
120 |
"wsimport", |
|
121 |
"xjc" |
|
122 |
}; |
|
123 |
||
124 |
// expected reference strings |
|
125 |
static String refVersion; |
|
126 |
static String refFullVersion; |
|
127 |
||
34011
b1ce08dd7f17
8139986: Store debug level in java.vm.debug and conditionally print in "java -version"
amurillo
parents:
33987
diff
changeset
|
128 |
static String getAllVersionLines(String... argv) { |
b1ce08dd7f17
8139986: Store debug level in java.vm.debug and conditionally print in "java -version"
amurillo
parents:
33987
diff
changeset
|
129 |
return getVersion0(true, argv); |
b1ce08dd7f17
8139986: Store debug level in java.vm.debug and conditionally print in "java -version"
amurillo
parents:
33987
diff
changeset
|
130 |
} |
b1ce08dd7f17
8139986: Store debug level in java.vm.debug and conditionally print in "java -version"
amurillo
parents:
33987
diff
changeset
|
131 |
|
2 | 132 |
static String getVersion(String... argv) { |
34011
b1ce08dd7f17
8139986: Store debug level in java.vm.debug and conditionally print in "java -version"
amurillo
parents:
33987
diff
changeset
|
133 |
return getVersion0(false, argv); |
b1ce08dd7f17
8139986: Store debug level in java.vm.debug and conditionally print in "java -version"
amurillo
parents:
33987
diff
changeset
|
134 |
} |
b1ce08dd7f17
8139986: Store debug level in java.vm.debug and conditionally print in "java -version"
amurillo
parents:
33987
diff
changeset
|
135 |
|
b1ce08dd7f17
8139986: Store debug level in java.vm.debug and conditionally print in "java -version"
amurillo
parents:
33987
diff
changeset
|
136 |
static String getVersion0(boolean allLines, String... argv) { |
12301 | 137 |
TestHelper.TestResult tr = doExec(argv); |
2 | 138 |
StringBuilder out = new StringBuilder(); |
139 |
// remove the HotSpot line |
|
12301 | 140 |
for (String x : tr.testOutput) { |
34011
b1ce08dd7f17
8139986: Store debug level in java.vm.debug and conditionally print in "java -version"
amurillo
parents:
33987
diff
changeset
|
141 |
if (allLines || !x.matches(".*Client.*VM.*|.*Server.*VM.*")) { |
2 | 142 |
out = out.append(x + "\n"); |
143 |
} |
|
144 |
} |
|
145 |
return out.toString(); |
|
146 |
} |
|
147 |
||
12301 | 148 |
/* |
149 |
* this tests if the tool can take a version string and returns |
|
150 |
* a 0 exit code, it is not possible to validate the contents |
|
151 |
* of the -version output as they are inconsistent. |
|
152 |
*/ |
|
153 |
static boolean testToolVersion() { |
|
154 |
TestHelper.testExitValue = 0; |
|
155 |
for (File f : new File(JAVA_BIN).listFiles(new ToolFilter(BLACKLIST_VERSION))) { |
|
156 |
String x = f.getAbsolutePath(); |
|
157 |
System.out.println("Testing (-version): " + x); |
|
37540
e92d95400f31
8154470: defines.h confused about PROGNAME and JAVA_ARGS
martin
parents:
36511
diff
changeset
|
158 |
TestResult tr = doExec(x, "-version"); |
12301 | 159 |
tr.checkPositive(); |
160 |
} |
|
161 |
return TestHelper.testExitValue == 0; |
|
162 |
} |
|
163 |
||
164 |
static boolean compareJVersionStrings() { |
|
2 | 165 |
int failcount = 0; |
12301 | 166 |
for (File f : new File(JAVA_BIN).listFiles(new ToolFilter(BLACKLIST_JOPTION))) { |
167 |
String x = f.getAbsolutePath(); |
|
168 |
System.out.println("Testing (-J-version): " + x); |
|
2 | 169 |
String testStr; |
170 |
||
171 |
testStr = getVersion(x, "-J-version"); |
|
172 |
if (refVersion.compareTo(testStr) != 0) { |
|
173 |
failcount++; |
|
174 |
System.out.println("Error: " + x + |
|
175 |
" fails -J-version comparison"); |
|
176 |
System.out.println("Expected:"); |
|
177 |
System.out.print(refVersion); |
|
178 |
System.out.println("Actual:"); |
|
179 |
System.out.print(testStr); |
|
180 |
} |
|
181 |
||
182 |
testStr = getVersion(x, "-J-fullversion"); |
|
183 |
if (refFullVersion.compareTo(testStr) != 0) { |
|
184 |
failcount++; |
|
185 |
System.out.println("Error: " + x + |
|
186 |
" fails -J-fullversion comparison"); |
|
187 |
System.out.println("Expected:"); |
|
188 |
System.out.print(refFullVersion); |
|
189 |
System.out.println("Actual:"); |
|
190 |
System.out.print(testStr); |
|
191 |
} |
|
192 |
} |
|
193 |
System.out.println("Version Test: " + failcount); |
|
194 |
return failcount == 0; |
|
195 |
} |
|
196 |
||
197 |
static boolean compareInternalStrings() { |
|
198 |
int failcount = 0; |
|
34392
ae4033cd28f4
8144533: VersionCheck.java failing after Verona changes in dev
ksrini
parents:
34011
diff
changeset
|
199 |
String bStr = refVersion.substring(refVersion.indexOf("build") + |
2 | 200 |
"build".length() + 1, |
201 |
refVersion.lastIndexOf(")")); |
|
202 |
||
203 |
String expectedFullVersion = "fullversion:" + bStr; |
|
204 |
||
12301 | 205 |
Map<String, String> envMap = new HashMap<>(); |
206 |
envMap.put(TestHelper.JLDEBUG_KEY, "true"); |
|
207 |
TestHelper.TestResult tr = doExec(envMap, javaCmd, "-version"); |
|
208 |
List<String> alist = new ArrayList<>(); |
|
209 |
alist.addAll(tr.testOutput); |
|
210 |
for (String x : tr.testOutput) { |
|
211 |
alist.add(x.trim()); |
|
212 |
} |
|
2 | 213 |
|
214 |
if (!alist.contains(expectedFullVersion)) { |
|
215 |
System.out.println("Error: could not find " + expectedFullVersion); |
|
216 |
failcount++; |
|
217 |
} |
|
218 |
System.out.println("Internal Strings Test: " + failcount); |
|
219 |
return failcount == 0; |
|
220 |
} |
|
221 |
||
34011
b1ce08dd7f17
8139986: Store debug level in java.vm.debug and conditionally print in "java -version"
amurillo
parents:
33987
diff
changeset
|
222 |
static boolean testDebugVersion() { |
b1ce08dd7f17
8139986: Store debug level in java.vm.debug and conditionally print in "java -version"
amurillo
parents:
33987
diff
changeset
|
223 |
String jdkType = System.getProperty("jdk.debug", "release"); |
b1ce08dd7f17
8139986: Store debug level in java.vm.debug and conditionally print in "java -version"
amurillo
parents:
33987
diff
changeset
|
224 |
String versionLines = getAllVersionLines(javaCmd, "-version"); |
b1ce08dd7f17
8139986: Store debug level in java.vm.debug and conditionally print in "java -version"
amurillo
parents:
33987
diff
changeset
|
225 |
if ("release".equals(jdkType)) { |
b1ce08dd7f17
8139986: Store debug level in java.vm.debug and conditionally print in "java -version"
amurillo
parents:
33987
diff
changeset
|
226 |
jdkType = ""; |
b1ce08dd7f17
8139986: Store debug level in java.vm.debug and conditionally print in "java -version"
amurillo
parents:
33987
diff
changeset
|
227 |
} else { |
b1ce08dd7f17
8139986: Store debug level in java.vm.debug and conditionally print in "java -version"
amurillo
parents:
33987
diff
changeset
|
228 |
jdkType = jdkType + " "; |
b1ce08dd7f17
8139986: Store debug level in java.vm.debug and conditionally print in "java -version"
amurillo
parents:
33987
diff
changeset
|
229 |
} |
b1ce08dd7f17
8139986: Store debug level in java.vm.debug and conditionally print in "java -version"
amurillo
parents:
33987
diff
changeset
|
230 |
String tofind = "(" + jdkType + "build"; |
b1ce08dd7f17
8139986: Store debug level in java.vm.debug and conditionally print in "java -version"
amurillo
parents:
33987
diff
changeset
|
231 |
int idx = versionLines.indexOf(tofind); |
b1ce08dd7f17
8139986: Store debug level in java.vm.debug and conditionally print in "java -version"
amurillo
parents:
33987
diff
changeset
|
232 |
if (idx < 0) { |
b1ce08dd7f17
8139986: Store debug level in java.vm.debug and conditionally print in "java -version"
amurillo
parents:
33987
diff
changeset
|
233 |
System.out.println("Did not find first instance of " + tofind); |
b1ce08dd7f17
8139986: Store debug level in java.vm.debug and conditionally print in "java -version"
amurillo
parents:
33987
diff
changeset
|
234 |
return false; |
b1ce08dd7f17
8139986: Store debug level in java.vm.debug and conditionally print in "java -version"
amurillo
parents:
33987
diff
changeset
|
235 |
} |
b1ce08dd7f17
8139986: Store debug level in java.vm.debug and conditionally print in "java -version"
amurillo
parents:
33987
diff
changeset
|
236 |
idx = versionLines.indexOf(tofind, idx + 1); |
b1ce08dd7f17
8139986: Store debug level in java.vm.debug and conditionally print in "java -version"
amurillo
parents:
33987
diff
changeset
|
237 |
if (idx < 0) { |
b1ce08dd7f17
8139986: Store debug level in java.vm.debug and conditionally print in "java -version"
amurillo
parents:
33987
diff
changeset
|
238 |
System.out.println("Did not find first instance of " + tofind); |
b1ce08dd7f17
8139986: Store debug level in java.vm.debug and conditionally print in "java -version"
amurillo
parents:
33987
diff
changeset
|
239 |
return false; |
b1ce08dd7f17
8139986: Store debug level in java.vm.debug and conditionally print in "java -version"
amurillo
parents:
33987
diff
changeset
|
240 |
} |
b1ce08dd7f17
8139986: Store debug level in java.vm.debug and conditionally print in "java -version"
amurillo
parents:
33987
diff
changeset
|
241 |
return true; |
b1ce08dd7f17
8139986: Store debug level in java.vm.debug and conditionally print in "java -version"
amurillo
parents:
33987
diff
changeset
|
242 |
} |
b1ce08dd7f17
8139986: Store debug level in java.vm.debug and conditionally print in "java -version"
amurillo
parents:
33987
diff
changeset
|
243 |
|
2 | 244 |
// Initialize |
245 |
static void init() { |
|
12301 | 246 |
refVersion = getVersion(javaCmd, "-version"); |
247 |
refFullVersion = getVersion(javaCmd, "-fullversion"); |
|
2 | 248 |
} |
249 |
||
250 |
public static void main(String[] args) { |
|
251 |
init(); |
|
12301 | 252 |
if (compareJVersionStrings() && |
253 |
compareInternalStrings() && |
|
34011
b1ce08dd7f17
8139986: Store debug level in java.vm.debug and conditionally print in "java -version"
amurillo
parents:
33987
diff
changeset
|
254 |
testToolVersion() && |
b1ce08dd7f17
8139986: Store debug level in java.vm.debug and conditionally print in "java -version"
amurillo
parents:
33987
diff
changeset
|
255 |
testDebugVersion()) { |
2 | 256 |
System.out.println("All Version string comparisons: PASS"); |
257 |
} else { |
|
258 |
throw new AssertionError("Some tests failed"); |
|
259 |
} |
|
260 |
} |
|
12301 | 261 |
|
262 |
static class ToolFilter implements FileFilter { |
|
34011
b1ce08dd7f17
8139986: Store debug level in java.vm.debug and conditionally print in "java -version"
amurillo
parents:
33987
diff
changeset
|
263 |
final Iterable<String> exclude; |
12301 | 264 |
protected ToolFilter(String... exclude) { |
265 |
List<String> tlist = new ArrayList<>(); |
|
266 |
this.exclude = tlist; |
|
267 |
for (String x : exclude) { |
|
268 |
String str = x + ((isWindows) ? EXE_FILE_EXT : ""); |
|
269 |
tlist.add(str.toLowerCase()); |
|
270 |
} |
|
271 |
} |
|
272 |
@Override |
|
273 |
public boolean accept(File pathname) { |
|
274 |
if (!pathname.isFile() || !pathname.canExecute()) { |
|
275 |
return false; |
|
276 |
} |
|
277 |
String name = pathname.getName().toLowerCase(); |
|
278 |
if (isWindows && !name.endsWith(EXE_FILE_EXT)) { |
|
279 |
return false; |
|
280 |
} |
|
281 |
for (String x : exclude) { |
|
282 |
if (name.endsWith(x)) { |
|
283 |
return false; |
|
284 |
} |
|
285 |
} |
|
286 |
return true; |
|
287 |
} |
|
288 |
} |
|
2 | 289 |
} |