author | ksrini |
Sat, 28 Jan 2012 10:46:46 -0800 | |
changeset 11687 | f13cadbb0bb5 |
parent 10053 | 43930b0d0564 |
child 12047 | 320a714614e9 |
permissions | -rw-r--r-- |
4340 | 1 |
/* |
11687
f13cadbb0bb5
7127906: (launcher) convert the launcher regression tests to java
ksrini
parents:
10053
diff
changeset
|
2 |
* Copyright (c) 2009, 2012, Oracle and/or its affiliates. All rights reserved. |
4340 | 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. |
|
4340 | 22 |
*/ |
23 |
||
24 |
/* |
|
25 |
* @test |
|
26 |
* @bug 4780570 4731671 6354700 6367077 6670965 4882974 |
|
27 |
* @summary Checks for LD_LIBRARY_PATH and execution on *nixes |
|
11687
f13cadbb0bb5
7127906: (launcher) convert the launcher regression tests to java
ksrini
parents:
10053
diff
changeset
|
28 |
* @compile -XDignore.symbol.file ExecutionEnvironment.java |
4340 | 29 |
* @run main ExecutionEnvironment |
30 |
*/ |
|
31 |
||
32 |
/* |
|
9244
84d85c90d5db
7029048: (launcher) fence the launcher against LD_LIBRARY_PATH
ksrini
parents:
5506
diff
changeset
|
33 |
* This tests for various things as follows: |
4340 | 34 |
* Ensures that: |
35 |
* 1. uneccessary execs do not occur |
|
36 |
* 2. the environment is pristine, users environment variable wrt. |
|
37 |
* LD_LIBRARY_PATH if set are not modified in any way. |
|
38 |
* 3. the correct vm is chosen with -server and -client options |
|
39 |
* 4. the VM on Solaris correctly interprets the LD_LIBRARY_PATH32 |
|
40 |
* and LD_LIBRARY_PATH64 variables if set by the user, ie. |
|
41 |
* i. on 32 bit systems: |
|
42 |
* a. if LD_LIBRARY_PATH32 is set it will override LD_LIBRARY_PATH |
|
43 |
* b. LD_LIBRARY_PATH64 is ignored if set |
|
44 |
* ii. on 64 bit systems: |
|
45 |
* a. if LD_LIBRARY_PATH64 is set it will override LD_LIBRARY_PATH |
|
46 |
* b. LD_LIBRARY_PATH32 is ignored if set |
|
47 |
* 5. no extra symlink exists on Solaris ie. |
|
48 |
* jre/lib/$arch/libjvm.so -> client/libjvm.so |
|
49 |
* TODO: |
|
50 |
* a. perhaps we need to add a test to audit all environment variables are |
|
51 |
* in pristine condition after the launch, there may be a few that the |
|
52 |
* launcher may add as implementation details. |
|
53 |
* b. add a pldd for solaris to ensure only one libjvm.so is linked |
|
54 |
*/ |
|
55 |
import java.io.File; |
|
56 |
import java.io.FileNotFoundException; |
|
57 |
import java.util.ArrayList; |
|
58 |
import java.util.HashMap; |
|
59 |
import java.util.List; |
|
60 |
import java.util.Map; |
|
61 |
||
62 |
||
11687
f13cadbb0bb5
7127906: (launcher) convert the launcher regression tests to java
ksrini
parents:
10053
diff
changeset
|
63 |
public class ExecutionEnvironment extends TestHelper { |
4340 | 64 |
static final String LD_LIBRARY_PATH = "LD_LIBRARY_PATH"; |
65 |
static final String LD_LIBRARY_PATH_32 = LD_LIBRARY_PATH + "_32"; |
|
66 |
static final String LD_LIBRARY_PATH_64 = LD_LIBRARY_PATH + "_64"; |
|
67 |
||
68 |
// Note: these paths need not exist on the filesytem |
|
69 |
static final String LD_LIBRARY_PATH_VALUE = "/Bridge/On/The/River/Kwai"; |
|
70 |
static final String LD_LIBRARY_PATH_32_VALUE = "/Lawrence/Of/Arabia"; |
|
71 |
static final String LD_LIBRARY_PATH_64_VALUE = "/A/Passage/To/India"; |
|
72 |
||
73 |
static final String[] LD_PATH_STRINGS = { |
|
74 |
LD_LIBRARY_PATH + "=" + LD_LIBRARY_PATH_VALUE, |
|
75 |
LD_LIBRARY_PATH_32 + "=" + LD_LIBRARY_PATH_32_VALUE, |
|
76 |
LD_LIBRARY_PATH_64 + "=" + LD_LIBRARY_PATH_64_VALUE |
|
77 |
}; |
|
78 |
||
79 |
static final File testJarFile = new File("EcoFriendly.jar"); |
|
80 |
||
81 |
static int errors = 0; |
|
82 |
static int passes = 0; |
|
83 |
||
11687
f13cadbb0bb5
7127906: (launcher) convert the launcher regression tests to java
ksrini
parents:
10053
diff
changeset
|
84 |
static final String LIBJVM = isWindows ? "jvm.dll" : "libjvm.so"; |
9244
84d85c90d5db
7029048: (launcher) fence the launcher against LD_LIBRARY_PATH
ksrini
parents:
5506
diff
changeset
|
85 |
|
84d85c90d5db
7029048: (launcher) fence the launcher against LD_LIBRARY_PATH
ksrini
parents:
5506
diff
changeset
|
86 |
static void createTestJar() { |
4340 | 87 |
try { |
11687
f13cadbb0bb5
7127906: (launcher) convert the launcher regression tests to java
ksrini
parents:
10053
diff
changeset
|
88 |
List<String> codeList = new ArrayList<>(); |
4340 | 89 |
codeList.add("static void printValue(String name, boolean property) {\n"); |
90 |
codeList.add(" String value = (property) ? System.getProperty(name) : System.getenv(name);\n"); |
|
91 |
codeList.add(" System.out.println(name + \"=\" + value);\n"); |
|
92 |
codeList.add("}\n"); |
|
93 |
codeList.add("public static void main(String... args) {\n"); |
|
94 |
codeList.add(" System.out.println(\"Execute test:\");\n"); |
|
95 |
codeList.add(" printValue(\"os.name\", true);\n"); |
|
96 |
codeList.add(" printValue(\"os.arch\", true);\n"); |
|
97 |
codeList.add(" printValue(\"os.version\", true);\n"); |
|
98 |
codeList.add(" printValue(\"sun.arch.data.model\", true);\n"); |
|
99 |
codeList.add(" printValue(\"java.library.path\", true);\n"); |
|
100 |
codeList.add(" printValue(\"" + LD_LIBRARY_PATH + "\", false);\n"); |
|
101 |
codeList.add(" printValue(\"" + LD_LIBRARY_PATH_32 + "\", false);\n"); |
|
102 |
codeList.add(" printValue(\"" + LD_LIBRARY_PATH_64 + "\", false);\n"); |
|
103 |
codeList.add("}\n"); |
|
104 |
String[] clist = new String[codeList.size()]; |
|
11687
f13cadbb0bb5
7127906: (launcher) convert the launcher regression tests to java
ksrini
parents:
10053
diff
changeset
|
105 |
createJar(testJarFile, codeList.toArray(clist)); |
4340 | 106 |
} catch (FileNotFoundException fnfe) { |
107 |
throw new RuntimeException(fnfe); |
|
108 |
} |
|
109 |
} |
|
110 |
||
111 |
/* |
|
112 |
* tests if the launcher pollutes the LD_LIBRARY_PATH variables ie. there |
|
113 |
* should not be any new variables or pollution/mutations of any kind, the |
|
114 |
* environment should be pristine. |
|
115 |
*/ |
|
116 |
private static void ensureEcoFriendly() { |
|
11687
f13cadbb0bb5
7127906: (launcher) convert the launcher regression tests to java
ksrini
parents:
10053
diff
changeset
|
117 |
TestResult tr = null; |
4340 | 118 |
|
11687
f13cadbb0bb5
7127906: (launcher) convert the launcher regression tests to java
ksrini
parents:
10053
diff
changeset
|
119 |
Map<String, String> env = new HashMap<>(); |
4340 | 120 |
for (String x : LD_PATH_STRINGS) { |
121 |
String pairs[] = x.split("="); |
|
122 |
env.put(pairs[0], pairs[1]); |
|
123 |
} |
|
124 |
||
11687
f13cadbb0bb5
7127906: (launcher) convert the launcher regression tests to java
ksrini
parents:
10053
diff
changeset
|
125 |
tr = doExec(env, javaCmd, "-jar", testJarFile.getAbsolutePath()); |
4340 | 126 |
|
127 |
if (!tr.isNotZeroOutput()) { |
|
9244
84d85c90d5db
7029048: (launcher) fence the launcher against LD_LIBRARY_PATH
ksrini
parents:
5506
diff
changeset
|
128 |
System.out.println(tr); |
4340 | 129 |
throw new RuntimeException("Error: No output at all. Did the test execute ?"); |
130 |
} |
|
131 |
||
132 |
for (String x : LD_PATH_STRINGS) { |
|
133 |
if (!tr.contains(x)) { |
|
134 |
System.out.println("FAIL: did not get <" + x + ">"); |
|
135 |
System.out.println(tr); |
|
136 |
errors++; |
|
137 |
} else { |
|
138 |
passes++; |
|
139 |
} |
|
140 |
} |
|
141 |
} |
|
142 |
||
143 |
/* |
|
144 |
* ensures that there are no execs as long as we are in the same |
|
145 |
* data model |
|
146 |
*/ |
|
147 |
static void ensureNoExec() { |
|
11687
f13cadbb0bb5
7127906: (launcher) convert the launcher regression tests to java
ksrini
parents:
10053
diff
changeset
|
148 |
Map<String, String> env = new HashMap<>(); |
4340 | 149 |
env.put(JLDEBUG_KEY, "true"); |
11687
f13cadbb0bb5
7127906: (launcher) convert the launcher regression tests to java
ksrini
parents:
10053
diff
changeset
|
150 |
TestResult tr = doExec(env, javaCmd, "-version"); |
4340 | 151 |
if (tr.testOutput.contains(EXPECTED_MARKER)) { |
152 |
System.out.println("FAIL: EnsureNoExecs: found expected warning <" + |
|
153 |
EXPECTED_MARKER + |
|
154 |
"> the process execing ?"); |
|
155 |
errors++; |
|
156 |
} else { |
|
157 |
passes++; |
|
158 |
} |
|
159 |
return; |
|
160 |
} |
|
161 |
||
162 |
/* |
|
163 |
* This test ensures that LD_LIBRARY_PATH* values are interpreted by the VM |
|
164 |
* and the expected java.library.path behaviour. |
|
165 |
* For Generic platforms (All *nixes): |
|
166 |
* * All LD_LIBRARY_PATH variable should be on java.library.path |
|
167 |
* For Solaris 32-bit |
|
168 |
* * The LD_LIBRARY_PATH_32 should override LD_LIBRARY_PATH if specified |
|
169 |
* For Solaris 64-bit |
|
170 |
* * The LD_LIBRARY_PATH_64 should override LD_LIBRARY_PATH if specified |
|
171 |
*/ |
|
172 |
||
173 |
static void verifyJavaLibraryPath() { |
|
11687
f13cadbb0bb5
7127906: (launcher) convert the launcher regression tests to java
ksrini
parents:
10053
diff
changeset
|
174 |
TestResult tr = null; |
4340 | 175 |
|
11687
f13cadbb0bb5
7127906: (launcher) convert the launcher regression tests to java
ksrini
parents:
10053
diff
changeset
|
176 |
Map<String, String> env = new HashMap<>(); |
4340 | 177 |
|
11687
f13cadbb0bb5
7127906: (launcher) convert the launcher regression tests to java
ksrini
parents:
10053
diff
changeset
|
178 |
if (isLinux) { |
4340 | 179 |
for (String x : LD_PATH_STRINGS) { |
180 |
String pairs[] = x.split("="); |
|
181 |
env.put(pairs[0], pairs[1]); |
|
182 |
} |
|
183 |
||
11687
f13cadbb0bb5
7127906: (launcher) convert the launcher regression tests to java
ksrini
parents:
10053
diff
changeset
|
184 |
tr = doExec(env, javaCmd, "-jar", testJarFile.getAbsolutePath()); |
4340 | 185 |
verifyJavaLibraryPathGeneric(tr); |
186 |
} else { |
|
187 |
// no override |
|
188 |
env.clear(); |
|
189 |
env.put(LD_LIBRARY_PATH, LD_LIBRARY_PATH_VALUE); |
|
11687
f13cadbb0bb5
7127906: (launcher) convert the launcher regression tests to java
ksrini
parents:
10053
diff
changeset
|
190 |
tr = doExec(env, javaCmd, "-jar", testJarFile.getAbsolutePath()); |
4340 | 191 |
verifyJavaLibraryPathGeneric(tr); |
192 |
||
193 |
env.clear(); |
|
194 |
for (String x : LD_PATH_STRINGS) { |
|
195 |
String pairs[] = x.split("="); |
|
196 |
env.put(pairs[0], pairs[1]); |
|
197 |
} |
|
198 |
||
199 |
// verify the override occurs, since we know the invocation always |
|
200 |
// uses by default is 32-bit, therefore we also set the test |
|
201 |
// expectation to be the same. |
|
11687
f13cadbb0bb5
7127906: (launcher) convert the launcher regression tests to java
ksrini
parents:
10053
diff
changeset
|
202 |
tr = doExec(env, javaCmd, "-jar", testJarFile.getAbsolutePath()); |
4340 | 203 |
verifyJavaLibraryPathOverride(tr, true); |
204 |
||
205 |
// try changing the model from 32 to 64 bit |
|
11687
f13cadbb0bb5
7127906: (launcher) convert the launcher regression tests to java
ksrini
parents:
10053
diff
changeset
|
206 |
if (dualModePresent() && is32Bit) { |
4340 | 207 |
// verify the override occurs |
208 |
env.clear(); |
|
209 |
for (String x : LD_PATH_STRINGS) { |
|
210 |
String pairs[] = x.split("="); |
|
211 |
env.put(pairs[0], pairs[1]); |
|
212 |
} |
|
11687
f13cadbb0bb5
7127906: (launcher) convert the launcher regression tests to java
ksrini
parents:
10053
diff
changeset
|
213 |
tr = doExec(env, javaCmd, "-d64", "-jar", |
4340 | 214 |
testJarFile.getAbsolutePath()); |
215 |
verifyJavaLibraryPathOverride(tr, false); |
|
216 |
||
217 |
// no override |
|
218 |
env.clear(); |
|
219 |
env.put(LD_LIBRARY_PATH, LD_LIBRARY_PATH_VALUE); |
|
11687
f13cadbb0bb5
7127906: (launcher) convert the launcher regression tests to java
ksrini
parents:
10053
diff
changeset
|
220 |
tr = doExec(env, javaCmd, "-jar", |
4340 | 221 |
testJarFile.getAbsolutePath()); |
222 |
verifyJavaLibraryPathGeneric(tr); |
|
223 |
} |
|
224 |
||
225 |
// try changing the model from 64 to 32 bit |
|
11687
f13cadbb0bb5
7127906: (launcher) convert the launcher regression tests to java
ksrini
parents:
10053
diff
changeset
|
226 |
if (java64Cmd != null && is64Bit) { |
4340 | 227 |
// verify the override occurs |
228 |
env.clear(); |
|
229 |
for (String x : LD_PATH_STRINGS) { |
|
230 |
String pairs[] = x.split("="); |
|
231 |
env.put(pairs[0], pairs[1]); |
|
232 |
} |
|
11687
f13cadbb0bb5
7127906: (launcher) convert the launcher regression tests to java
ksrini
parents:
10053
diff
changeset
|
233 |
tr = doExec(env, java64Cmd, "-d32", "-jar", |
4340 | 234 |
testJarFile.getAbsolutePath()); |
235 |
verifyJavaLibraryPathOverride(tr, true); |
|
236 |
||
237 |
// no override |
|
238 |
env.clear(); |
|
239 |
env.put(LD_LIBRARY_PATH, LD_LIBRARY_PATH_VALUE); |
|
11687
f13cadbb0bb5
7127906: (launcher) convert the launcher regression tests to java
ksrini
parents:
10053
diff
changeset
|
240 |
tr = doExec(env, java64Cmd, "-d32", "-jar", |
4340 | 241 |
testJarFile.getAbsolutePath()); |
242 |
verifyJavaLibraryPathGeneric(tr); |
|
243 |
} |
|
244 |
} |
|
245 |
} |
|
246 |
||
11687
f13cadbb0bb5
7127906: (launcher) convert the launcher regression tests to java
ksrini
parents:
10053
diff
changeset
|
247 |
private static void verifyJavaLibraryPathGeneric(TestResult tr) { |
4340 | 248 |
if (!tr.matches("java.library.path=.*" + LD_LIBRARY_PATH_VALUE + ".*")) { |
249 |
System.out.print("FAIL: verifyJavaLibraryPath: "); |
|
250 |
System.out.println(" java.library.path does not contain " + |
|
251 |
LD_LIBRARY_PATH_VALUE); |
|
252 |
System.out.println(tr); |
|
253 |
errors++; |
|
254 |
} else { |
|
255 |
passes++; |
|
256 |
} |
|
257 |
} |
|
258 |
||
11687
f13cadbb0bb5
7127906: (launcher) convert the launcher regression tests to java
ksrini
parents:
10053
diff
changeset
|
259 |
private static void verifyJavaLibraryPathOverride(TestResult tr, |
4340 | 260 |
boolean is32Bit) { |
261 |
// make sure the 32/64 bit value exists |
|
262 |
if (!tr.matches("java.library.path=.*" + |
|
263 |
(is32Bit ? LD_LIBRARY_PATH_32_VALUE : LD_LIBRARY_PATH_64_VALUE) + ".*")) { |
|
264 |
System.out.print("FAIL: verifyJavaLibraryPathOverride: "); |
|
265 |
System.out.println(" java.library.path does not contain " + |
|
266 |
(is32Bit ? LD_LIBRARY_PATH_32_VALUE : LD_LIBRARY_PATH_64_VALUE)); |
|
267 |
System.out.println(tr); |
|
268 |
errors++; |
|
269 |
} else { |
|
270 |
passes++; |
|
271 |
} |
|
272 |
// make sure the generic value is absent |
|
273 |
if (tr.matches("java.library.path=.*" + LD_LIBRARY_PATH_VALUE + ".*")) { |
|
274 |
System.out.print("FAIL: verifyJavaLibraryPathOverride: "); |
|
275 |
System.out.println(" java.library.path contains " + |
|
276 |
LD_LIBRARY_PATH_VALUE); |
|
277 |
System.out.println(tr); |
|
278 |
errors++; |
|
279 |
} else { |
|
280 |
passes++; |
|
281 |
} |
|
282 |
} |
|
283 |
||
284 |
/* |
|
285 |
* ensures we have indeed exec'ed the correct vm of choice, all VMs support |
|
286 |
* -server, however 32-bit VMs support -client and -server. |
|
287 |
*/ |
|
288 |
static void verifyVmSelection() { |
|
289 |
||
11687
f13cadbb0bb5
7127906: (launcher) convert the launcher regression tests to java
ksrini
parents:
10053
diff
changeset
|
290 |
TestResult tr = null; |
4340 | 291 |
|
11687
f13cadbb0bb5
7127906: (launcher) convert the launcher regression tests to java
ksrini
parents:
10053
diff
changeset
|
292 |
if (is32Bit) { |
f13cadbb0bb5
7127906: (launcher) convert the launcher regression tests to java
ksrini
parents:
10053
diff
changeset
|
293 |
tr = doExec(javaCmd, "-client", "-version"); |
10053
43930b0d0564
7043125: TEST: tools/launcher/VersionCheck.java fails just against openjdk7 (b141 & b138-nightly) promoted
ksrini
parents:
9244
diff
changeset
|
294 |
if (!tr.matches(".*Client VM.*")) { |
43930b0d0564
7043125: TEST: tools/launcher/VersionCheck.java fails just against openjdk7 (b141 & b138-nightly) promoted
ksrini
parents:
9244
diff
changeset
|
295 |
System.out.println("FAIL: the expected vm -client did not launch"); |
4340 | 296 |
System.out.println(tr); |
297 |
errors++; |
|
298 |
} else { |
|
299 |
passes++; |
|
300 |
} |
|
301 |
} |
|
11687
f13cadbb0bb5
7127906: (launcher) convert the launcher regression tests to java
ksrini
parents:
10053
diff
changeset
|
302 |
tr = doExec(javaCmd, "-server", "-version"); |
10053
43930b0d0564
7043125: TEST: tools/launcher/VersionCheck.java fails just against openjdk7 (b141 & b138-nightly) promoted
ksrini
parents:
9244
diff
changeset
|
303 |
if (!tr.matches(".*Server VM.*")) { |
43930b0d0564
7043125: TEST: tools/launcher/VersionCheck.java fails just against openjdk7 (b141 & b138-nightly) promoted
ksrini
parents:
9244
diff
changeset
|
304 |
System.out.println("FAIL: the expected vm -server did not launch"); |
4340 | 305 |
System.out.println(tr); |
306 |
errors++; |
|
307 |
} else { |
|
308 |
passes++; |
|
309 |
} |
|
310 |
} |
|
311 |
||
312 |
/* |
|
313 |
* checks to see there is no extra libjvm.so than needed |
|
314 |
*/ |
|
315 |
static void verifyNoSymLink() { |
|
11687
f13cadbb0bb5
7127906: (launcher) convert the launcher regression tests to java
ksrini
parents:
10053
diff
changeset
|
316 |
if (is64Bit) { |
4340 | 317 |
return; |
318 |
} |
|
319 |
||
320 |
File symLink = null; |
|
11687
f13cadbb0bb5
7127906: (launcher) convert the launcher regression tests to java
ksrini
parents:
10053
diff
changeset
|
321 |
String libPathPrefix = isSDK ? "jre/lib" : "/lib"; |
f13cadbb0bb5
7127906: (launcher) convert the launcher regression tests to java
ksrini
parents:
10053
diff
changeset
|
322 |
symLink = new File(JAVAHOME, libPathPrefix + |
f13cadbb0bb5
7127906: (launcher) convert the launcher regression tests to java
ksrini
parents:
10053
diff
changeset
|
323 |
getJreArch() + "/" + LIBJVM); |
4340 | 324 |
if (symLink.exists()) { |
325 |
System.out.println("FAIL: The symlink exists " + |
|
326 |
symLink.getAbsolutePath()); |
|
327 |
errors++; |
|
328 |
} else { |
|
329 |
passes++; |
|
330 |
} |
|
331 |
} |
|
332 |
||
333 |
public static void main(String... args) throws Exception { |
|
11687
f13cadbb0bb5
7127906: (launcher) convert the launcher regression tests to java
ksrini
parents:
10053
diff
changeset
|
334 |
if (isWindows) { |
4340 | 335 |
System.out.println("Warning: noop on windows"); |
336 |
return; |
|
337 |
} |
|
338 |
// create our test jar first |
|
339 |
createTestJar(); |
|
340 |
ensureNoExec(); |
|
341 |
verifyVmSelection(); |
|
342 |
ensureEcoFriendly(); |
|
343 |
verifyJavaLibraryPath(); |
|
344 |
verifyNoSymLink(); |
|
345 |
if (errors > 0) { |
|
346 |
throw new Exception("ExecutionEnvironment: FAIL: with " + |
|
347 |
errors + " errors and passes " + passes ); |
|
348 |
} else { |
|
349 |
System.out.println("ExecutionEnvironment: PASS " + passes); |
|
350 |
} |
|
351 |
} |
|
352 |
} |