22 */ |
22 */ |
23 |
23 |
24 /* |
24 /* |
25 * @test |
25 * @test |
26 * @bug 7029048 |
26 * @bug 7029048 |
27 * @summary Checks for LD_LIBRARY_PATH on *nixes |
27 * @summary Ensure that the launcher defends against user settings of the |
|
28 * LD_LIBRARY_PATH environment variable on Unixes |
28 * @compile -XDignore.symbol.file ExecutionEnvironment.java Test7029048.java |
29 * @compile -XDignore.symbol.file ExecutionEnvironment.java Test7029048.java |
29 * @run main Test7029048 |
30 * @run main Test7029048 |
30 */ |
31 */ |
31 |
32 |
32 /* |
|
33 * 7029048: test for LD_LIBRARY_PATH set to different paths which may or |
|
34 * may not contain a libjvm.so, but we test to ensure that the launcher |
|
35 * behaves correctly in all cases. |
|
36 */ |
|
37 import java.io.File; |
33 import java.io.File; |
38 import java.io.IOException; |
34 import java.io.IOException; |
39 import java.nio.file.Files; |
35 import java.nio.file.Files; |
40 import java.util.ArrayList; |
36 import java.util.ArrayList; |
41 import java.util.HashMap; |
37 import java.util.HashMap; |
64 |
60 |
65 private static final File dstClientDir = new File(dstLibDir, "client"); |
61 private static final File dstClientDir = new File(dstLibDir, "client"); |
66 private static final File dstClientLibjvm = new File(dstClientDir, LIBJVM); |
62 private static final File dstClientLibjvm = new File(dstClientDir, LIBJVM); |
67 |
63 |
68 private static final Map<String, String> env = new HashMap<>(); |
64 private static final Map<String, String> env = new HashMap<>(); |
69 |
|
70 |
65 |
71 static String getValue(String name, List<String> in) { |
66 static String getValue(String name, List<String> in) { |
72 for (String x : in) { |
67 for (String x : in) { |
73 String[] s = x.split("="); |
68 String[] s = x.split("="); |
74 if (name.equals(s[0].trim())) { |
69 if (name.equals(s[0].trim())) { |
97 /* |
92 /* |
98 * the envValue can never be null, since the test code should always |
93 * the envValue can never be null, since the test code should always |
99 * print a "null" string. |
94 * print a "null" string. |
100 */ |
95 */ |
101 if (envValue == null) { |
96 if (envValue == null) { |
102 System.out.println(tr); |
|
103 throw new RuntimeException("NPE, likely a program crash ??"); |
97 throw new RuntimeException("NPE, likely a program crash ??"); |
104 } |
98 } |
105 String values[] = envValue.split(File.pathSeparator); |
99 int len = (envValue.equals("null") |
106 if (values.length == nLLPComponents) { |
100 ? 0 : envValue.split(File.pathSeparator).length); |
107 System.out.println(caseID + " :OK"); |
101 if (len == nLLPComponents) { |
|
102 System.out.println(caseID + ": OK"); |
108 passes++; |
103 passes++; |
109 } else { |
104 } else { |
110 System.out.println("FAIL: test7029048, " + caseID); |
105 System.out.println("FAIL: test7029048, " + caseID); |
111 System.out.println(" expected " + nLLPComponents |
106 System.out.println(" expected " + nLLPComponents |
112 + " but got " + values.length); |
107 + " but got " + len); |
113 System.out.println(envValue); |
108 System.out.println(envValue); |
114 System.out.println(tr); |
|
115 errors++; |
109 errors++; |
116 } |
110 } |
117 } |
111 } |
118 |
112 |
119 /* |
113 /* |
120 * A crucial piece, specifies what we should expect, given the conditions. |
114 * Describe the cases that we test. Each case sets the environment |
121 * That is for a given enum type, the value indicates how many absolute |
115 * variable LD_LIBRARY_PATH to a different value. The value associated |
122 * environment variables that can be expected. This value is used to base |
116 * with a case is the number of path elements that we expect the launcher |
123 * the actual expected values by adding the set environment variable usually |
117 * to add to that variable. |
124 * it is 1, but it could be more if the test wishes to set more paths in |
|
125 * the future. |
|
126 */ |
118 */ |
127 private static enum LLP_VAR { |
119 private static enum TestCase { |
128 LLP_SET_NON_EXISTENT_PATH(0), // env set, but the path does not exist |
120 NO_DIR(0), // Directory does not exist |
129 LLP_SET_EMPTY_PATH(0), // env set, with a path but no libjvm.so |
121 NO_LIBJVM(0), // Directory exists, but no libjvm.so |
130 LLP_SET_WITH_JVM(3); // env set, with a libjvm.so |
122 LIBJVM(3); // Directory exists, with a libjvm.so |
131 private final int value; |
123 private final int value; |
132 LLP_VAR(int i) { |
124 TestCase(int i) { |
133 this.value = i; |
125 this.value = i; |
134 } |
126 } |
135 } |
127 } |
136 |
128 |
137 /* |
129 /* |
138 * test for 7029048 |
130 * test for 7029048 |
139 */ |
131 */ |
140 static void test7029048() throws IOException { |
132 static void test7029048() throws IOException { |
141 String desc = null; |
133 String desc = null; |
142 for (LLP_VAR v : LLP_VAR.values()) { |
134 for (TestCase v : TestCase.values()) { |
143 switch (v) { |
135 switch (v) { |
144 case LLP_SET_WITH_JVM: |
136 case LIBJVM: |
145 // copy the files into the directory structures |
137 // copy the files into the directory structures |
146 copyFile(srcLibjvmSo, dstServerLibjvm); |
138 copyFile(srcLibjvmSo, dstServerLibjvm); |
147 // does not matter if it is client or a server |
139 // does not matter if it is client or a server |
148 copyFile(srcLibjvmSo, dstClientLibjvm); |
140 copyFile(srcLibjvmSo, dstClientLibjvm); |
149 desc = "LD_LIBRARY_PATH should be set"; |
141 desc = "LD_LIBRARY_PATH should be set"; |
150 break; |
142 break; |
151 case LLP_SET_EMPTY_PATH: |
143 case NO_LIBJVM: |
152 if (!dstClientDir.exists()) { |
144 if (!dstClientDir.exists()) { |
153 Files.createDirectories(dstClientDir.toPath()); |
145 Files.createDirectories(dstClientDir.toPath()); |
154 } else { |
146 } else { |
155 Files.deleteIfExists(dstClientLibjvm.toPath()); |
147 Files.deleteIfExists(dstClientLibjvm.toPath()); |
156 } |
148 } |
159 Files.createDirectories(dstServerDir.toPath()); |
151 Files.createDirectories(dstServerDir.toPath()); |
160 } else { |
152 } else { |
161 Files.deleteIfExists(dstServerLibjvm.toPath()); |
153 Files.deleteIfExists(dstServerLibjvm.toPath()); |
162 } |
154 } |
163 |
155 |
164 desc = "LD_LIBRARY_PATH should not be set"; |
156 desc = "LD_LIBRARY_PATH should not be set (no libjvm.so)"; |
165 break; |
157 break; |
166 case LLP_SET_NON_EXISTENT_PATH: |
158 case NO_DIR: |
167 if (dstLibDir.exists()) { |
159 if (dstLibDir.exists()) { |
168 recursiveDelete(dstLibDir); |
160 recursiveDelete(dstLibDir); |
169 } |
161 } |
170 desc = "LD_LIBRARY_PATH should not be set"; |
162 desc = "LD_LIBRARY_PATH should not be set (no directory)"; |
171 break; |
163 break; |
172 default: |
164 default: |
173 throw new RuntimeException("unknown case"); |
165 throw new RuntimeException("unknown case"); |
174 } |
166 } |
175 |
167 |
176 /* |
168 /* |
177 * Case 1: set the server path |
169 * Case 1: set the server path |
178 */ |
170 */ |
179 env.clear(); |
171 env.clear(); |
180 env.put(LD_LIBRARY_PATH, dstServerDir.getAbsolutePath()); |
172 env.put(LD_LIBRARY_PATH, dstServerDir.getAbsolutePath()); |
181 run(env, v.value + 1, "Case 1: " + desc); |
173 run(env, |
|
174 v.value + 1, // Add one to account for our setting |
|
175 "Case 1: " + desc); |
182 |
176 |
183 /* |
177 /* |
184 * Case 2: repeat with client path |
178 * Case 2: repeat with client path |
185 */ |
179 */ |
186 env.clear(); |
180 env.clear(); |
187 env.put(LD_LIBRARY_PATH, dstClientDir.getAbsolutePath()); |
181 env.put(LD_LIBRARY_PATH, dstClientDir.getAbsolutePath()); |
188 run(env, v.value + 1, "Case 2: " + desc); |
182 run(env, |
|
183 v.value + 1, // Add one to account for our setting |
|
184 "Case 2: " + desc); |
189 |
185 |
190 if (isSolaris) { |
186 if (isSolaris) { |
191 /* |
187 /* |
192 * Case 3: set the appropriate LLP_XX flag, |
188 * Case 3: set the appropriate LLP_XX flag, |
193 * java64 LLP_64 is relevant, LLP_32 is ignored |
189 * java64 LLP_64 is relevant, LLP_32 is ignored |
194 */ |
190 */ |
195 env.clear(); |
191 env.clear(); |
196 env.put(LD_LIBRARY_PATH_64, dstServerDir.getAbsolutePath()); |
192 env.put(LD_LIBRARY_PATH_64, dstServerDir.getAbsolutePath()); |
197 run(env, v.value + 1, "Case 3: " + desc); |
193 run(env, |
|
194 v.value, // Do not add one, since we didn't set |
|
195 // LD_LIBRARY_PATH here |
|
196 "Case 3: " + desc); |
198 } |
197 } |
199 } |
198 } |
200 return; |
199 return; |
201 } |
200 } |
202 |
201 |