author | ksrini |
Fri, 17 Jun 2011 15:17:01 -0700 | |
changeset 10053 | 43930b0d0564 |
parent 9244 | 84d85c90d5db |
child 11687 | f13cadbb0bb5 |
permissions | -rw-r--r-- |
4340 | 1 |
/* |
9244
84d85c90d5db
7029048: (launcher) fence the launcher against LD_LIBRARY_PATH
ksrini
parents:
5506
diff
changeset
|
2 |
* Copyright (c) 2009, 2011, 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 |
|
28 |
* @compile -XDignore.symbol.file ExecutionEnvironment.java TestHelper.java |
|
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 |
||
63 |
public class ExecutionEnvironment { |
|
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 JLDEBUG_KEY = "_JAVA_LAUNCHER_DEBUG"; |
|
74 |
static final String EXPECTED_MARKER = "TRACER_MARKER:About to EXEC"; |
|
75 |
||
76 |
static final String[] LD_PATH_STRINGS = { |
|
77 |
LD_LIBRARY_PATH + "=" + LD_LIBRARY_PATH_VALUE, |
|
78 |
LD_LIBRARY_PATH_32 + "=" + LD_LIBRARY_PATH_32_VALUE, |
|
79 |
LD_LIBRARY_PATH_64 + "=" + LD_LIBRARY_PATH_64_VALUE |
|
80 |
}; |
|
81 |
||
82 |
static final File testJarFile = new File("EcoFriendly.jar"); |
|
83 |
||
84 |
static int errors = 0; |
|
85 |
static int passes = 0; |
|
86 |
||
9244
84d85c90d5db
7029048: (launcher) fence the launcher against LD_LIBRARY_PATH
ksrini
parents:
5506
diff
changeset
|
87 |
static final String LIBJVM = TestHelper.isWindows ? "jvm.dll" : "libjvm.so"; |
84d85c90d5db
7029048: (launcher) fence the launcher against LD_LIBRARY_PATH
ksrini
parents:
5506
diff
changeset
|
88 |
|
84d85c90d5db
7029048: (launcher) fence the launcher against LD_LIBRARY_PATH
ksrini
parents:
5506
diff
changeset
|
89 |
static void createTestJar() { |
4340 | 90 |
try { |
91 |
List<String> codeList = new ArrayList<String>(); |
|
92 |
codeList.add("static void printValue(String name, boolean property) {\n"); |
|
93 |
codeList.add(" String value = (property) ? System.getProperty(name) : System.getenv(name);\n"); |
|
94 |
codeList.add(" System.out.println(name + \"=\" + value);\n"); |
|
95 |
codeList.add("}\n"); |
|
96 |
codeList.add("public static void main(String... args) {\n"); |
|
97 |
codeList.add(" System.out.println(\"Execute test:\");\n"); |
|
98 |
codeList.add(" printValue(\"os.name\", true);\n"); |
|
99 |
codeList.add(" printValue(\"os.arch\", true);\n"); |
|
100 |
codeList.add(" printValue(\"os.version\", true);\n"); |
|
101 |
codeList.add(" printValue(\"sun.arch.data.model\", true);\n"); |
|
102 |
codeList.add(" printValue(\"java.library.path\", true);\n"); |
|
103 |
codeList.add(" printValue(\"" + LD_LIBRARY_PATH + "\", false);\n"); |
|
104 |
codeList.add(" printValue(\"" + LD_LIBRARY_PATH_32 + "\", false);\n"); |
|
105 |
codeList.add(" printValue(\"" + LD_LIBRARY_PATH_64 + "\", false);\n"); |
|
106 |
codeList.add("}\n"); |
|
107 |
String[] clist = new String[codeList.size()]; |
|
108 |
TestHelper.createJar(testJarFile, codeList.toArray(clist)); |
|
109 |
} catch (FileNotFoundException fnfe) { |
|
110 |
throw new RuntimeException(fnfe); |
|
111 |
} |
|
112 |
} |
|
113 |
||
114 |
/* |
|
115 |
* tests if the launcher pollutes the LD_LIBRARY_PATH variables ie. there |
|
116 |
* should not be any new variables or pollution/mutations of any kind, the |
|
117 |
* environment should be pristine. |
|
118 |
*/ |
|
119 |
private static void ensureEcoFriendly() { |
|
120 |
TestHelper.TestResult tr = null; |
|
121 |
||
122 |
Map<String, String> env = new HashMap<String, String>(); |
|
123 |
for (String x : LD_PATH_STRINGS) { |
|
124 |
String pairs[] = x.split("="); |
|
125 |
env.put(pairs[0], pairs[1]); |
|
126 |
} |
|
127 |
||
128 |
tr = TestHelper.doExec(env, TestHelper.javaCmd, "-jar", |
|
129 |
testJarFile.getAbsolutePath()); |
|
130 |
||
131 |
if (!tr.isNotZeroOutput()) { |
|
9244
84d85c90d5db
7029048: (launcher) fence the launcher against LD_LIBRARY_PATH
ksrini
parents:
5506
diff
changeset
|
132 |
System.out.println(tr); |
4340 | 133 |
throw new RuntimeException("Error: No output at all. Did the test execute ?"); |
134 |
} |
|
135 |
||
136 |
for (String x : LD_PATH_STRINGS) { |
|
137 |
if (!tr.contains(x)) { |
|
138 |
System.out.println("FAIL: did not get <" + x + ">"); |
|
139 |
System.out.println(tr); |
|
140 |
errors++; |
|
141 |
} else { |
|
142 |
passes++; |
|
143 |
} |
|
144 |
} |
|
145 |
} |
|
146 |
||
147 |
/* |
|
148 |
* ensures that there are no execs as long as we are in the same |
|
149 |
* data model |
|
150 |
*/ |
|
151 |
static void ensureNoExec() { |
|
152 |
Map<String, String> env = new HashMap<String, String>(); |
|
153 |
env.put(JLDEBUG_KEY, "true"); |
|
154 |
TestHelper.TestResult tr = |
|
155 |
TestHelper.doExec(env, TestHelper.javaCmd, "-version"); |
|
156 |
if (tr.testOutput.contains(EXPECTED_MARKER)) { |
|
157 |
System.out.println("FAIL: EnsureNoExecs: found expected warning <" + |
|
158 |
EXPECTED_MARKER + |
|
159 |
"> the process execing ?"); |
|
160 |
errors++; |
|
161 |
} else { |
|
162 |
passes++; |
|
163 |
} |
|
164 |
return; |
|
165 |
} |
|
166 |
||
167 |
/* |
|
168 |
* This test ensures that LD_LIBRARY_PATH* values are interpreted by the VM |
|
169 |
* and the expected java.library.path behaviour. |
|
170 |
* For Generic platforms (All *nixes): |
|
171 |
* * All LD_LIBRARY_PATH variable should be on java.library.path |
|
172 |
* For Solaris 32-bit |
|
173 |
* * The LD_LIBRARY_PATH_32 should override LD_LIBRARY_PATH if specified |
|
174 |
* For Solaris 64-bit |
|
175 |
* * The LD_LIBRARY_PATH_64 should override LD_LIBRARY_PATH if specified |
|
176 |
*/ |
|
177 |
||
178 |
static void verifyJavaLibraryPath() { |
|
179 |
TestHelper.TestResult tr = null; |
|
180 |
||
181 |
Map<String, String> env = new HashMap<String, String>(); |
|
182 |
||
183 |
if (TestHelper.isLinux) { |
|
184 |
for (String x : LD_PATH_STRINGS) { |
|
185 |
String pairs[] = x.split("="); |
|
186 |
env.put(pairs[0], pairs[1]); |
|
187 |
} |
|
188 |
||
189 |
tr = TestHelper.doExec(env, TestHelper.javaCmd, "-jar", |
|
190 |
testJarFile.getAbsolutePath()); |
|
191 |
verifyJavaLibraryPathGeneric(tr); |
|
192 |
} else { |
|
193 |
// no override |
|
194 |
env.clear(); |
|
195 |
env.put(LD_LIBRARY_PATH, LD_LIBRARY_PATH_VALUE); |
|
196 |
tr = TestHelper.doExec(env, TestHelper.javaCmd, "-jar", |
|
197 |
testJarFile.getAbsolutePath()); |
|
198 |
verifyJavaLibraryPathGeneric(tr); |
|
199 |
||
200 |
env.clear(); |
|
201 |
for (String x : LD_PATH_STRINGS) { |
|
202 |
String pairs[] = x.split("="); |
|
203 |
env.put(pairs[0], pairs[1]); |
|
204 |
} |
|
205 |
||
206 |
// verify the override occurs, since we know the invocation always |
|
207 |
// uses by default is 32-bit, therefore we also set the test |
|
208 |
// expectation to be the same. |
|
209 |
tr = TestHelper.doExec(env, TestHelper.javaCmd, "-jar", |
|
210 |
testJarFile.getAbsolutePath()); |
|
211 |
verifyJavaLibraryPathOverride(tr, true); |
|
212 |
||
213 |
// try changing the model from 32 to 64 bit |
|
9244
84d85c90d5db
7029048: (launcher) fence the launcher against LD_LIBRARY_PATH
ksrini
parents:
5506
diff
changeset
|
214 |
if (TestHelper.dualModePresent() && TestHelper.is32Bit) { |
4340 | 215 |
// verify the override occurs |
216 |
env.clear(); |
|
217 |
for (String x : LD_PATH_STRINGS) { |
|
218 |
String pairs[] = x.split("="); |
|
219 |
env.put(pairs[0], pairs[1]); |
|
220 |
} |
|
221 |
tr = TestHelper.doExec(env, TestHelper.javaCmd, "-d64", "-jar", |
|
222 |
testJarFile.getAbsolutePath()); |
|
223 |
verifyJavaLibraryPathOverride(tr, false); |
|
224 |
||
225 |
// no override |
|
226 |
env.clear(); |
|
227 |
env.put(LD_LIBRARY_PATH, LD_LIBRARY_PATH_VALUE); |
|
228 |
tr = TestHelper.doExec(env, TestHelper.javaCmd, "-jar", |
|
229 |
testJarFile.getAbsolutePath()); |
|
230 |
verifyJavaLibraryPathGeneric(tr); |
|
231 |
} |
|
232 |
||
233 |
// try changing the model from 64 to 32 bit |
|
234 |
if (TestHelper.java64Cmd != null && TestHelper.is64Bit) { |
|
235 |
// verify the override occurs |
|
236 |
env.clear(); |
|
237 |
for (String x : LD_PATH_STRINGS) { |
|
238 |
String pairs[] = x.split("="); |
|
239 |
env.put(pairs[0], pairs[1]); |
|
240 |
} |
|
241 |
tr = TestHelper.doExec(env, TestHelper.java64Cmd, "-d32", "-jar", |
|
242 |
testJarFile.getAbsolutePath()); |
|
243 |
verifyJavaLibraryPathOverride(tr, true); |
|
244 |
||
245 |
// no override |
|
246 |
env.clear(); |
|
247 |
env.put(LD_LIBRARY_PATH, LD_LIBRARY_PATH_VALUE); |
|
248 |
tr = TestHelper.doExec(env, TestHelper.java64Cmd, "-d32", "-jar", |
|
249 |
testJarFile.getAbsolutePath()); |
|
250 |
verifyJavaLibraryPathGeneric(tr); |
|
251 |
} |
|
252 |
} |
|
253 |
} |
|
254 |
||
255 |
private static void verifyJavaLibraryPathGeneric(TestHelper.TestResult tr) { |
|
256 |
if (!tr.matches("java.library.path=.*" + LD_LIBRARY_PATH_VALUE + ".*")) { |
|
257 |
System.out.print("FAIL: verifyJavaLibraryPath: "); |
|
258 |
System.out.println(" java.library.path does not contain " + |
|
259 |
LD_LIBRARY_PATH_VALUE); |
|
260 |
System.out.println(tr); |
|
261 |
errors++; |
|
262 |
} else { |
|
263 |
passes++; |
|
264 |
} |
|
265 |
} |
|
266 |
||
267 |
private static void verifyJavaLibraryPathOverride(TestHelper.TestResult tr, |
|
268 |
boolean is32Bit) { |
|
269 |
// make sure the 32/64 bit value exists |
|
270 |
if (!tr.matches("java.library.path=.*" + |
|
271 |
(is32Bit ? LD_LIBRARY_PATH_32_VALUE : LD_LIBRARY_PATH_64_VALUE) + ".*")) { |
|
272 |
System.out.print("FAIL: verifyJavaLibraryPathOverride: "); |
|
273 |
System.out.println(" java.library.path does not contain " + |
|
274 |
(is32Bit ? LD_LIBRARY_PATH_32_VALUE : LD_LIBRARY_PATH_64_VALUE)); |
|
275 |
System.out.println(tr); |
|
276 |
errors++; |
|
277 |
} else { |
|
278 |
passes++; |
|
279 |
} |
|
280 |
// make sure the generic value is absent |
|
281 |
if (tr.matches("java.library.path=.*" + LD_LIBRARY_PATH_VALUE + ".*")) { |
|
282 |
System.out.print("FAIL: verifyJavaLibraryPathOverride: "); |
|
283 |
System.out.println(" java.library.path contains " + |
|
284 |
LD_LIBRARY_PATH_VALUE); |
|
285 |
System.out.println(tr); |
|
286 |
errors++; |
|
287 |
} else { |
|
288 |
passes++; |
|
289 |
} |
|
290 |
} |
|
291 |
||
292 |
/* |
|
293 |
* ensures we have indeed exec'ed the correct vm of choice, all VMs support |
|
294 |
* -server, however 32-bit VMs support -client and -server. |
|
295 |
*/ |
|
296 |
static void verifyVmSelection() { |
|
297 |
||
298 |
TestHelper.TestResult tr = null; |
|
299 |
||
300 |
if (TestHelper.is32Bit) { |
|
301 |
tr = TestHelper.doExec(TestHelper.javaCmd, "-client", "-version"); |
|
10053
43930b0d0564
7043125: TEST: tools/launcher/VersionCheck.java fails just against openjdk7 (b141 & b138-nightly) promoted
ksrini
parents:
9244
diff
changeset
|
302 |
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
|
303 |
System.out.println("FAIL: the expected vm -client did not launch"); |
4340 | 304 |
System.out.println(tr); |
305 |
errors++; |
|
306 |
} else { |
|
307 |
passes++; |
|
308 |
} |
|
309 |
} |
|
310 |
tr = TestHelper.doExec(TestHelper.javaCmd, "-server", "-version"); |
|
10053
43930b0d0564
7043125: TEST: tools/launcher/VersionCheck.java fails just against openjdk7 (b141 & b138-nightly) promoted
ksrini
parents:
9244
diff
changeset
|
311 |
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
|
312 |
System.out.println("FAIL: the expected vm -server did not launch"); |
4340 | 313 |
System.out.println(tr); |
314 |
errors++; |
|
315 |
} else { |
|
316 |
passes++; |
|
317 |
} |
|
318 |
} |
|
319 |
||
320 |
/* |
|
321 |
* checks to see there is no extra libjvm.so than needed |
|
322 |
*/ |
|
323 |
static void verifyNoSymLink() { |
|
324 |
if (TestHelper.is64Bit) { |
|
325 |
return; |
|
326 |
} |
|
327 |
||
328 |
File symLink = null; |
|
329 |
String libPathPrefix = TestHelper.isSDK ? "jre/lib" : "/lib"; |
|
330 |
symLink = new File(TestHelper.JAVAHOME, libPathPrefix + |
|
9244
84d85c90d5db
7029048: (launcher) fence the launcher against LD_LIBRARY_PATH
ksrini
parents:
5506
diff
changeset
|
331 |
TestHelper.getJreArch() + "/" + LIBJVM); |
4340 | 332 |
if (symLink.exists()) { |
333 |
System.out.println("FAIL: The symlink exists " + |
|
334 |
symLink.getAbsolutePath()); |
|
335 |
errors++; |
|
336 |
} else { |
|
337 |
passes++; |
|
338 |
} |
|
339 |
} |
|
340 |
||
341 |
public static void main(String... args) throws Exception { |
|
342 |
if (TestHelper.isWindows) { |
|
343 |
System.out.println("Warning: noop on windows"); |
|
344 |
return; |
|
345 |
} |
|
346 |
// create our test jar first |
|
347 |
createTestJar(); |
|
348 |
ensureNoExec(); |
|
349 |
verifyVmSelection(); |
|
350 |
ensureEcoFriendly(); |
|
351 |
verifyJavaLibraryPath(); |
|
352 |
verifyNoSymLink(); |
|
353 |
if (errors > 0) { |
|
354 |
throw new Exception("ExecutionEnvironment: FAIL: with " + |
|
355 |
errors + " errors and passes " + passes ); |
|
356 |
} else { |
|
357 |
System.out.println("ExecutionEnvironment: PASS " + passes); |
|
358 |
} |
|
359 |
} |
|
360 |
} |