Book a Demo!
CoCalc Logo Icon
StoreFeaturesDocsShareSupportNewsAboutPoliciesSign UpSign In
PojavLauncherTeam
GitHub Repository: PojavLauncherTeam/mobile
Path: blob/master/test/jdk/tools/launcher/Test7029048.java
41144 views
1
/*
2
* Copyright (c) 2011, 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 7029048 8217340 8217216
27
* @summary Ensure that the launcher defends against user settings of the
28
* LD_LIBRARY_PATH environment variable on Unixes
29
* @requires os.family != "windows" & os.family != "mac" & !vm.musl & os.family != "aix"
30
* @library /test/lib
31
* @compile -XDignore.symbol.file ExecutionEnvironment.java Test7029048.java
32
* @run main/othervm -DexpandedLdLibraryPath=false Test7029048
33
*/
34
35
/**
36
* @test
37
* @bug 7029048 8217340 8217216
38
* @summary Ensure that the launcher defends against user settings of the
39
* LD_LIBRARY_PATH environment variable on Unixes
40
* @requires os.family == "aix" | vm.musl
41
* @library /test/lib
42
* @compile -XDignore.symbol.file ExecutionEnvironment.java Test7029048.java
43
* @run main/othervm -DexpandedLdLibraryPath=true Test7029048
44
*/
45
46
import java.io.File;
47
import java.io.IOException;
48
import java.nio.file.Files;
49
import java.util.ArrayList;
50
import java.util.HashMap;
51
import java.util.List;
52
import java.util.Map;
53
54
public class Test7029048 extends TestHelper {
55
56
private static final String LIBJVM = ExecutionEnvironment.LIBJVM;
57
private static final String LD_LIBRARY_PATH =
58
ExecutionEnvironment.LD_LIBRARY_PATH;
59
private static final String LD_LIBRARY_PATH_64 =
60
ExecutionEnvironment.LD_LIBRARY_PATH_64;
61
62
private static final File libDir =
63
new File(System.getProperty("sun.boot.library.path"));
64
private static final File srcServerDir = new File(libDir, "server");
65
private static final File srcLibjvmSo = new File(srcServerDir, LIBJVM);
66
67
private static final File dstLibDir = new File("lib");
68
private static final File dstServerDir = new File(dstLibDir, "server");
69
private static final File dstServerLibjvm = new File(dstServerDir, LIBJVM);
70
71
private static final File dstClientDir = new File(dstLibDir, "client");
72
private static final File dstClientLibjvm = new File(dstClientDir, LIBJVM);
73
74
static final boolean IS_EXPANDED_LD_LIBRARY_PATH =
75
Boolean.getBoolean("expandedLdLibraryPath");
76
77
static String getValue(String name, List<String> in) {
78
for (String x : in) {
79
String[] s = x.split("=");
80
if (name.equals(s[0].trim())) {
81
return s[1].trim();
82
}
83
}
84
return null;
85
}
86
87
static boolean run(int nLLPComponents, File variantDir, String caseID) {
88
89
Map<String, String> env = new HashMap<>();
90
env.put(LD_LIBRARY_PATH, variantDir.getAbsolutePath());
91
env.put(ExecutionEnvironment.JLDEBUG_KEY, "true");
92
List<String> cmdsList = new ArrayList<>();
93
cmdsList.add(javaCmd);
94
cmdsList.add("-server");
95
cmdsList.add("-jar");
96
cmdsList.add(ExecutionEnvironment.testJarFile.getAbsolutePath());
97
String[] cmds = new String[cmdsList.size()];
98
TestResult tr = doExec(env, cmdsList.toArray(cmds));
99
System.out.println(tr);
100
int len = getLLPComponents(tr);
101
if (len == nLLPComponents) {
102
System.out.printf("Test7029048 OK %s%n", caseID);
103
return true;
104
} else {
105
System.out.printf("Test7029048 FAIL %s: expected %d but got %d%n",
106
caseID, nLLPComponents, len);
107
return false;
108
}
109
}
110
111
static int getLLPComponents(TestResult tr) {
112
String envValue = getValue(LD_LIBRARY_PATH, tr.testOutput);
113
/*
114
* the envValue can never be null, since the test code should always
115
* print a "null" string.
116
*/
117
if (envValue == null) {
118
throw new RuntimeException("NPE, likely a program crash ??");
119
}
120
121
if (envValue.equals("null")) {
122
return 0;
123
}
124
125
return envValue.split(File.pathSeparator).length;
126
}
127
128
/*
129
* Describe the cases that we test. Each case sets the environment
130
* variable LD_LIBRARY_PATH to a different value. The value associated
131
* with a case is the number of path elements that we expect the launcher
132
* to add to that variable.
133
*/
134
private static enum TestCase {
135
NO_DIR(0), // Directory does not exist
136
NO_LIBJVM(0), // Directory exists, but no libjvm.so
137
LIBJVM(3); // Directory exists, with a libjvm.so
138
private final int value;
139
TestCase(int i) {
140
this.value = i;
141
}
142
}
143
144
/*
145
* test for 7029048
146
*/
147
static boolean runTest() throws IOException {
148
String desc = null;
149
boolean pass = true;
150
for (TestCase v : TestCase.values()) {
151
switch (v) {
152
case LIBJVM:
153
// copy the files into the directory structures
154
copyFile(srcLibjvmSo, dstServerLibjvm);
155
// does not matter if it is client or a server
156
copyFile(srcLibjvmSo, dstClientLibjvm);
157
desc = "LD_LIBRARY_PATH should be set";
158
break;
159
case NO_LIBJVM:
160
if (!dstClientDir.exists()) {
161
Files.createDirectories(dstClientDir.toPath());
162
} else {
163
Files.deleteIfExists(dstClientLibjvm.toPath());
164
}
165
166
if (!dstServerDir.exists()) {
167
Files.createDirectories(dstServerDir.toPath());
168
} else {
169
Files.deleteIfExists(dstServerLibjvm.toPath());
170
}
171
172
desc = "LD_LIBRARY_PATH should not be set (no libjvm.so)";
173
if (IS_EXPANDED_LD_LIBRARY_PATH) {
174
printSkipMessage(desc);
175
continue;
176
}
177
break;
178
case NO_DIR:
179
if (dstLibDir.exists()) {
180
recursiveDelete(dstLibDir);
181
}
182
desc = "LD_LIBRARY_PATH should not be set (no directory)";
183
if (IS_EXPANDED_LD_LIBRARY_PATH) {
184
printSkipMessage(desc);
185
continue;
186
}
187
break;
188
default:
189
throw new RuntimeException("unknown case");
190
}
191
192
// Add one to account for our setting
193
int nLLPComponents = v.value + 1;
194
195
/*
196
* Case 1: set the server path
197
*/
198
boolean pass1 = run(nLLPComponents, dstServerDir, "Case 1: " + desc);
199
200
/*
201
* Case 2: repeat with client path
202
*/
203
boolean pass2 = run(nLLPComponents, dstClientDir, "Case 2: " + desc);
204
205
pass &= pass1 && pass2;
206
}
207
return pass;
208
}
209
210
private static void printSkipMessage(String description) {
211
System.out.printf("Skipping test case '%s' because the Aix and musl launchers" +
212
" add the paths in any case.%n", description);
213
}
214
215
public static void main(String... args) throws Exception {
216
if (!TestHelper.haveServerVM) {
217
System.out.println("Note: test relies on server vm, not found, exiting");
218
return;
219
}
220
// create our test jar first
221
ExecutionEnvironment.createTestJar();
222
223
if (!runTest()) {
224
throw new Exception("Test7029048 fails");
225
}
226
}
227
}
228
229