Book a Demo!
CoCalc Logo Icon
StoreFeaturesDocsShareSupportNewsAboutPoliciesSign UpSign In
PojavLauncherTeam
GitHub Repository: PojavLauncherTeam/mobile
Path: blob/master/test/jdk/tools/launcher/ExecutionEnvironment.java
41144 views
1
/*
2
* Copyright (c) 2009, 2020, Oracle and/or its affiliates. All rights reserved.
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
*
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.
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
* @requires os.family != "windows" & !vm.musl & os.family != "aix"
29
* @library /test/lib
30
* @modules jdk.compiler
31
* jdk.zipfs
32
* @compile -XDignore.symbol.file ExecutionEnvironment.java
33
* @run main/othervm -DexpandedLdLibraryPath=false ExecutionEnvironment
34
*/
35
36
/*
37
* @test
38
* @bug 4780570 4731671 6354700 6367077 6670965 4882974
39
* @summary Checks for LD_LIBRARY_PATH and execution on *nixes
40
* @requires os.family == "aix" | vm.musl
41
* @library /test/lib
42
* @modules jdk.compiler
43
* jdk.zipfs
44
* @compile -XDignore.symbol.file ExecutionEnvironment.java
45
* @run main/othervm -DexpandedLdLibraryPath=true ExecutionEnvironment
46
*/
47
48
/*
49
* This tests for various things as follows:
50
* Ensures that:
51
* 1. uneccessary execs do not occur
52
* 2. the environment is pristine, users environment variable wrt.
53
* LD_LIBRARY_PATH if set are not modified in any way.
54
* 3. the correct vm is chosen with -server and -client options
55
* 4. the VM on Solaris correctly interprets the LD_LIBRARY_PATH32
56
* and LD_LIBRARY_PATH64 variables if set by the user, ie.
57
* i. on 32 bit systems:
58
* a. if LD_LIBRARY_PATH32 is set it will override LD_LIBRARY_PATH
59
* b. LD_LIBRARY_PATH64 is ignored if set
60
* ii. on 64 bit systems:
61
* a. if LD_LIBRARY_PATH64 is set it will override LD_LIBRARY_PATH
62
* b. LD_LIBRARY_PATH32 is ignored if set
63
* 5. no extra symlink exists on Solaris ie.
64
* lib/$arch/libjvm.so -> client/libjvm.so
65
* TODO:
66
* a. perhaps we need to add a test to audit all environment variables are
67
* in pristine condition after the launch, there may be a few that the
68
* launcher may add as implementation details.
69
* b. add a pldd for solaris to ensure only one libjvm.so is linked
70
*/
71
72
import jdk.test.lib.Platform;
73
74
import java.io.File;
75
import java.io.FileNotFoundException;
76
import java.util.ArrayList;
77
import java.util.HashMap;
78
import java.util.List;
79
import java.util.Map;
80
81
public class ExecutionEnvironment extends TestHelper {
82
static final String LD_LIBRARY_PATH = Platform.sharedLibraryPathVariableName();
83
static final String LD_LIBRARY_PATH_32 = LD_LIBRARY_PATH + "_32";
84
static final String LD_LIBRARY_PATH_64 = LD_LIBRARY_PATH + "_64";
85
86
// Note: these paths need not exist on the filesytem
87
static final String LD_LIBRARY_PATH_VALUE = "/Bridge/On/The/River/Kwai";
88
static final String LD_LIBRARY_PATH_32_VALUE = "/Lawrence/Of/Arabia";
89
static final String LD_LIBRARY_PATH_64_VALUE = "/A/Passage/To/India";
90
91
static final String[] LD_PATH_STRINGS = {
92
LD_LIBRARY_PATH + "=" + LD_LIBRARY_PATH_VALUE,
93
LD_LIBRARY_PATH_32 + "=" + LD_LIBRARY_PATH_32_VALUE,
94
LD_LIBRARY_PATH_64 + "=" + LD_LIBRARY_PATH_64_VALUE
95
};
96
97
static final File testJarFile = new File("EcoFriendly.jar");
98
99
static final boolean IS_EXPANDED_LD_LIBRARY_PATH =
100
Boolean.getBoolean("expandedLdLibraryPath");
101
102
public ExecutionEnvironment() {
103
createTestJar();
104
}
105
106
static void createTestJar() {
107
try {
108
List<String> codeList = new ArrayList<>();
109
codeList.add("static void printValue(String name, boolean property) {\n");
110
codeList.add(" String value = (property) ? System.getProperty(name) : System.getenv(name);\n");
111
codeList.add(" System.out.println(name + \"=\" + value);\n");
112
codeList.add("}\n");
113
codeList.add("public static void main(String... args) {\n");
114
codeList.add(" System.out.println(\"Execute test:\");\n");
115
codeList.add(" printValue(\"os.name\", true);\n");
116
codeList.add(" printValue(\"os.arch\", true);\n");
117
codeList.add(" printValue(\"os.version\", true);\n");
118
codeList.add(" printValue(\"sun.arch.data.model\", true);\n");
119
codeList.add(" printValue(\"java.library.path\", true);\n");
120
codeList.add(" printValue(\"" + LD_LIBRARY_PATH + "\", false);\n");
121
codeList.add(" printValue(\"" + LD_LIBRARY_PATH_32 + "\", false);\n");
122
codeList.add(" printValue(\"" + LD_LIBRARY_PATH_64 + "\", false);\n");
123
codeList.add("}\n");
124
String[] clist = new String[codeList.size()];
125
createJar(testJarFile, codeList.toArray(clist));
126
} catch (FileNotFoundException fnfe) {
127
throw new RuntimeException(fnfe);
128
}
129
}
130
private void flagError(TestResult tr, String message) {
131
System.err.println(tr);
132
throw new RuntimeException(message);
133
}
134
/*
135
* tests if the launcher pollutes the LD_LIBRARY_PATH variables ie. there
136
* should not be any new variables or pollution/mutations of any kind, the
137
* environment should be pristine.
138
*/
139
@Test
140
void testEcoFriendly() {
141
Map<String, String> env = new HashMap<>();
142
for (String x : LD_PATH_STRINGS) {
143
String pairs[] = x.split("=");
144
env.put(pairs[0], pairs[1]);
145
}
146
147
TestResult tr =
148
doExec(env, javaCmd, "-jar", testJarFile.getAbsolutePath());
149
150
if (!tr.isNotZeroOutput()) {
151
flagError(tr, "Error: No output at all. Did the test execute ?");
152
}
153
154
for (String x : LD_PATH_STRINGS) {
155
if (!tr.contains(x)) {
156
if (IS_EXPANDED_LD_LIBRARY_PATH && x.startsWith(LD_LIBRARY_PATH)) {
157
// AIX does not support the '-rpath' linker options so the
158
// launchers have to prepend the jdk library path to 'LIBPATH'.
159
// The musl library loader requires LD_LIBRARY_PATH to be set in
160
// order to correctly resolve the dependency libjava.so has on libjvm.so.
161
String libPath = LD_LIBRARY_PATH + "=" +
162
System.getenv(LD_LIBRARY_PATH) +
163
System.getProperty("path.separator") + LD_LIBRARY_PATH_VALUE;
164
if (!tr.matches(libPath)) {
165
flagError(tr, "FAIL: did not get <" + libPath + ">");
166
}
167
}
168
else {
169
flagError(tr, "FAIL: did not get <" + x + ">");
170
}
171
}
172
}
173
}
174
175
/*
176
* ensures that there are no execs as long as we are in the same
177
* data model
178
*/
179
@Test
180
void testNoExec() {
181
Map<String, String> env = new HashMap<>();
182
env.put(JLDEBUG_KEY, "true");
183
TestResult tr = doExec(env, javaCmd, "-version");
184
if (tr.testOutput.contains(EXPECTED_MARKER)) {
185
flagError(tr, "testNoExec: found warning <" + EXPECTED_MARKER +
186
"> the process execing ?");
187
}
188
}
189
190
/*
191
* This test ensures that LD_LIBRARY_PATH* values are interpreted by the VM
192
* and the expected java.library.path behaviour.
193
* For Generic platforms (All *nixes):
194
* * All LD_LIBRARY_PATH variable should be on java.library.path
195
*/
196
@Test
197
void testJavaLibraryPath() {
198
TestResult tr;
199
200
Map<String, String> env = new HashMap<>();
201
202
for (String x : LD_PATH_STRINGS) {
203
String pairs[] = x.split("=");
204
env.put(pairs[0], pairs[1]);
205
}
206
207
tr = doExec(env, javaCmd, "-jar", testJarFile.getAbsolutePath());
208
verifyJavaLibraryPathGeneric(tr);
209
}
210
211
private void verifyJavaLibraryPathGeneric(TestResult tr) {
212
if (!tr.matches("java.library.path=.*" + LD_LIBRARY_PATH_VALUE + ".*")) {
213
flagError(tr, "testJavaLibraryPath: java.library.path does not contain " +
214
LD_LIBRARY_PATH_VALUE);
215
}
216
}
217
218
private void verifyJavaLibraryPathOverride(TestResult tr,
219
boolean is32Bit) {
220
// make sure the 32/64 bit value exists
221
if (!tr.matches("java.library.path=.*" +
222
(is32Bit ? LD_LIBRARY_PATH_32_VALUE : LD_LIBRARY_PATH_64_VALUE) + ".*")) {
223
flagError(tr, "verifyJavaLibraryPathOverride: " +
224
" java.library.path does not contain " +
225
(is32Bit ? LD_LIBRARY_PATH_32_VALUE : LD_LIBRARY_PATH_64_VALUE));
226
227
}
228
// make sure the generic value is absent
229
if (!tr.notMatches("java.library.path=.*" + LD_LIBRARY_PATH_VALUE + ".*")) {
230
flagError(tr, "verifyJavaLibraryPathOverride: " +
231
" java.library.path contains " + LD_LIBRARY_PATH_VALUE);
232
}
233
}
234
235
/*
236
* ensures we have indeed exec'ed the correct vm of choice if it exists
237
*/
238
@Test
239
void testVmSelection() {
240
boolean haveSomeVM = false;
241
if (haveClientVM) {
242
tryVmOption("-client", ".*Client VM.*");
243
haveSomeVM = true;
244
}
245
if (haveServerVM) {
246
tryVmOption("-server", ".*Server VM.*");
247
haveSomeVM = true;
248
}
249
if (!haveSomeVM) {
250
String msg = "Don't have a known VM";
251
System.err.println(msg);
252
throw new RuntimeException(msg);
253
}
254
}
255
256
private void tryVmOption(String opt, String expected) {
257
TestResult tr = doExec(javaCmd, opt, "-version");
258
if (!tr.matches(expected)) {
259
flagError(tr, "the expected vm " + opt + " did not launch");
260
}
261
}
262
263
/*
264
* checks to see there is no extra libjvm.so than needed
265
*/
266
@Test
267
void testNoSymLink() {
268
if (is64Bit) {
269
return;
270
}
271
272
File symLink = null;
273
String libPathPrefix = "/lib";
274
symLink = new File(JAVAHOME, libPathPrefix +
275
getJreArch() + "/" + LIBJVM);
276
if (symLink.exists()) {
277
throw new RuntimeException("symlink exists " + symLink.getAbsolutePath());
278
}
279
}
280
public static void main(String... args) throws Exception {
281
ExecutionEnvironment ee = new ExecutionEnvironment();
282
ee.run(args);
283
}
284
}
285
286