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