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