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