author | jlaskey |
Tue, 19 Feb 2013 09:47:02 -0400 | |
changeset 16248 | e4bcc4b4f897 |
parent 15529 | 8112eb76bda3 |
child 16029 | 4e88242da117 |
child 21374 | 9e22d8dc2035 |
permissions | -rw-r--r-- |
2 | 1 |
/* |
15529
8112eb76bda3
8007135: tools/launcher/VersionCheck.java failing with new tool jabswitch
ksrini
parents:
14998
diff
changeset
|
2 |
* Copyright (c) 2007, 2013, 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 |
|
26 |
* @bug 6545058 6611182 |
|
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", |
|
49 |
"javaw", |
|
50 |
"javaws", |
|
51 |
"jcontrol", |
|
52 |
"jvisualvm", |
|
53 |
"packager", |
|
54 |
"unpack200", |
|
55 |
"wsimport" |
|
56 |
}; |
|
2 | 57 |
|
12301 | 58 |
// tools that do not accept -version |
59 |
static final String[] BLACKLIST_VERSION = { |
|
2 | 60 |
"appletviewer", |
12301 | 61 |
"controlpanel", |
2 | 62 |
"extcheck", |
63 |
"jar", |
|
64 |
"jarsigner", |
|
12301 | 65 |
"java-rmi", |
66 |
"java-rmi.cgi", |
|
2 | 67 |
"javadoc", |
12301 | 68 |
"javaws", |
69 |
"jcmd", |
|
2 | 70 |
"jconsole", |
12301 | 71 |
"jcontrol", |
14998
b9a99aac309e
8005634: tools/launcher/VersionCheck.java fails version check on jdeps
chegar
parents:
12301
diff
changeset
|
72 |
"jdeps", |
2 | 73 |
"jinfo", |
74 |
"jmap", |
|
75 |
"jps", |
|
12301 | 76 |
"jrunscript", |
77 |
"jsadebugd", |
|
2 | 78 |
"jstack", |
79 |
"jstat", |
|
80 |
"jstatd", |
|
12301 | 81 |
"jvisualvm", |
2 | 82 |
"keytool", |
12301 | 83 |
"kinit", |
84 |
"klist", |
|
85 |
"ktab", |
|
2 | 86 |
"native2ascii", |
87 |
"orbd", |
|
88 |
"pack200", |
|
12301 | 89 |
"packager", |
2 | 90 |
"policytool", |
91 |
"rmic", |
|
92 |
"rmid", |
|
93 |
"rmiregistry", |
|
12301 | 94 |
"schemagen", // returns error code 127 |
2 | 95 |
"serialver", |
96 |
"servertool", |
|
97 |
"tnameserv", |
|
12301 | 98 |
"unpack200", |
2 | 99 |
"wsgen", |
100 |
"wsimport", |
|
101 |
"xjc" |
|
102 |
}; |
|
103 |
||
104 |
// expected reference strings |
|
105 |
static String refVersion; |
|
106 |
static String refFullVersion; |
|
107 |
||
108 |
static String getVersion(String... argv) { |
|
12301 | 109 |
TestHelper.TestResult tr = doExec(argv); |
2 | 110 |
StringBuilder out = new StringBuilder(); |
111 |
// remove the HotSpot line |
|
12301 | 112 |
for (String x : tr.testOutput) { |
10053
43930b0d0564
7043125: TEST: tools/launcher/VersionCheck.java fails just against openjdk7 (b141 & b138-nightly) promoted
ksrini
parents:
5506
diff
changeset
|
113 |
if (!x.matches(".*Client.*VM.*|.*Server.*VM.*")) { |
2 | 114 |
out = out.append(x + "\n"); |
115 |
} |
|
116 |
} |
|
117 |
return out.toString(); |
|
118 |
} |
|
119 |
||
12301 | 120 |
/* |
121 |
* this tests if the tool can take a version string and returns |
|
122 |
* a 0 exit code, it is not possible to validate the contents |
|
123 |
* of the -version output as they are inconsistent. |
|
124 |
*/ |
|
125 |
static boolean testToolVersion() { |
|
126 |
TestResult tr = null; |
|
127 |
TestHelper.testExitValue = 0; |
|
128 |
for (File f : new File(JAVA_BIN).listFiles(new ToolFilter(BLACKLIST_VERSION))) { |
|
129 |
String x = f.getAbsolutePath(); |
|
130 |
System.out.println("Testing (-version): " + x); |
|
131 |
tr = doExec(x, "-version"); |
|
132 |
tr.checkPositive(); |
|
133 |
} |
|
134 |
return TestHelper.testExitValue == 0; |
|
135 |
} |
|
136 |
||
137 |
static boolean compareJVersionStrings() { |
|
2 | 138 |
int failcount = 0; |
12301 | 139 |
for (File f : new File(JAVA_BIN).listFiles(new ToolFilter(BLACKLIST_JOPTION))) { |
140 |
String x = f.getAbsolutePath(); |
|
141 |
System.out.println("Testing (-J-version): " + x); |
|
2 | 142 |
String testStr; |
143 |
||
144 |
testStr = getVersion(x, "-J-version"); |
|
145 |
if (refVersion.compareTo(testStr) != 0) { |
|
146 |
failcount++; |
|
147 |
System.out.println("Error: " + x + |
|
148 |
" fails -J-version comparison"); |
|
149 |
System.out.println("Expected:"); |
|
150 |
System.out.print(refVersion); |
|
151 |
System.out.println("Actual:"); |
|
152 |
System.out.print(testStr); |
|
153 |
} |
|
154 |
||
155 |
testStr = getVersion(x, "-J-fullversion"); |
|
156 |
if (refFullVersion.compareTo(testStr) != 0) { |
|
157 |
failcount++; |
|
158 |
System.out.println("Error: " + x + |
|
159 |
" fails -J-fullversion comparison"); |
|
160 |
System.out.println("Expected:"); |
|
161 |
System.out.print(refFullVersion); |
|
162 |
System.out.println("Actual:"); |
|
163 |
System.out.print(testStr); |
|
164 |
} |
|
165 |
} |
|
166 |
System.out.println("Version Test: " + failcount); |
|
167 |
return failcount == 0; |
|
168 |
} |
|
169 |
||
170 |
static boolean compareInternalStrings() { |
|
171 |
int failcount = 0; |
|
172 |
String bStr = refVersion.substring(refVersion.lastIndexOf("build") + |
|
173 |
"build".length() + 1, |
|
174 |
refVersion.lastIndexOf(")")); |
|
175 |
||
176 |
String[] vStr = bStr.split("\\.|-|_"); |
|
177 |
String jdkMajor = vStr[0]; |
|
178 |
String jdkMinor = vStr[1]; |
|
179 |
String jdkMicro = vStr[2]; |
|
180 |
String jdkBuild = vStr[vStr.length - 1]; |
|
181 |
||
182 |
String expectedDotVersion = "dotversion:" + jdkMajor + "." + jdkMinor; |
|
183 |
String expectedFullVersion = "fullversion:" + bStr; |
|
184 |
||
12301 | 185 |
Map<String, String> envMap = new HashMap<>(); |
186 |
envMap.put(TestHelper.JLDEBUG_KEY, "true"); |
|
187 |
TestHelper.TestResult tr = doExec(envMap, javaCmd, "-version"); |
|
188 |
List<String> alist = new ArrayList<>(); |
|
189 |
alist.addAll(tr.testOutput); |
|
190 |
for (String x : tr.testOutput) { |
|
191 |
alist.add(x.trim()); |
|
192 |
} |
|
2 | 193 |
if (!alist.contains(expectedDotVersion)) { |
194 |
System.out.println("Error: could not find " + expectedDotVersion); |
|
195 |
failcount++; |
|
196 |
} |
|
197 |
||
198 |
if (!alist.contains(expectedFullVersion)) { |
|
199 |
System.out.println("Error: could not find " + expectedFullVersion); |
|
200 |
failcount++; |
|
201 |
} |
|
202 |
System.out.println("Internal Strings Test: " + failcount); |
|
203 |
return failcount == 0; |
|
204 |
} |
|
205 |
||
206 |
// Initialize |
|
207 |
static void init() { |
|
12301 | 208 |
refVersion = getVersion(javaCmd, "-version"); |
209 |
refFullVersion = getVersion(javaCmd, "-fullversion"); |
|
2 | 210 |
} |
211 |
||
212 |
public static void main(String[] args) { |
|
213 |
init(); |
|
12301 | 214 |
if (compareJVersionStrings() && |
215 |
compareInternalStrings() && |
|
216 |
testToolVersion()) { |
|
2 | 217 |
System.out.println("All Version string comparisons: PASS"); |
218 |
} else { |
|
219 |
throw new AssertionError("Some tests failed"); |
|
220 |
} |
|
221 |
} |
|
12301 | 222 |
|
223 |
static class ToolFilter implements FileFilter { |
|
224 |
final Iterable<String> exclude ; |
|
225 |
protected ToolFilter(String... exclude) { |
|
226 |
List<String> tlist = new ArrayList<>(); |
|
227 |
this.exclude = tlist; |
|
228 |
for (String x : exclude) { |
|
229 |
String str = x + ((isWindows) ? EXE_FILE_EXT : ""); |
|
230 |
tlist.add(str.toLowerCase()); |
|
231 |
} |
|
232 |
} |
|
233 |
@Override |
|
234 |
public boolean accept(File pathname) { |
|
235 |
if (!pathname.isFile() || !pathname.canExecute()) { |
|
236 |
return false; |
|
237 |
} |
|
238 |
String name = pathname.getName().toLowerCase(); |
|
239 |
if (isWindows && !name.endsWith(EXE_FILE_EXT)) { |
|
240 |
return false; |
|
241 |
} |
|
242 |
for (String x : exclude) { |
|
243 |
if (name.endsWith(x)) { |
|
244 |
return false; |
|
245 |
} |
|
246 |
} |
|
247 |
return true; |
|
248 |
} |
|
249 |
} |
|
2 | 250 |
} |