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