Book a Demo!
CoCalc Logo Icon
StoreFeaturesDocsShareSupportNewsAboutPoliciesSign UpSign In
PojavLauncherTeam
GitHub Repository: PojavLauncherTeam/mobile
Path: blob/master/test/hotspot/jtreg/runtime/6819213/TestBootNativeLibraryPath.java
40942 views
1
/*
2
* Copyright (c) 2008, 2018, 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 TestBootNativeLibraryPath.java
26
* @bug 6819213
27
* @summary verify sun.boot.native.library.path is expandable on 32 bit systems
28
* @author ksrini
29
* @modules java.compiler
30
* @library /test/lib
31
* @requires vm.bits == 32
32
* @compile -XDignore.symbol.file TestBootNativeLibraryPath.java
33
* @run main TestBootNativeLibraryPath
34
*/
35
36
import java.io.BufferedReader;
37
import java.io.File;
38
import java.io.FileOutputStream;
39
import java.io.IOException;
40
import java.io.InputStreamReader;
41
import java.io.PrintStream;
42
import java.util.ArrayList;
43
import java.util.List;
44
import java.util.Map;
45
import java.util.logging.Level;
46
import java.util.logging.Logger;
47
import javax.tools.JavaCompiler;
48
import javax.tools.ToolProvider;
49
50
public class TestBootNativeLibraryPath {
51
52
private static final String TESTFILE = "Test6";
53
54
static void createTestClass() throws IOException {
55
FileOutputStream fos = new FileOutputStream(TESTFILE + ".java");
56
PrintStream ps = new PrintStream(fos);
57
ps.println("public class " + TESTFILE + "{");
58
ps.println("public static void main(String[] args) {\n");
59
ps.println("System.out.println(System.getProperty(\"sun.boot.library.path\"));\n");
60
ps.println("}}\n");
61
ps.close();
62
fos.close();
63
64
JavaCompiler javac = ToolProvider.getSystemJavaCompiler();
65
String javacOpts[] = {TESTFILE + ".java"};
66
if (javac.run(null, null, null, javacOpts) != 0) {
67
throw new RuntimeException("compilation of " + TESTFILE + ".java Failed");
68
}
69
}
70
71
static List<String> doExec(String... args) {
72
String javaCmd = System.getProperty("java.home") + "/bin/java";
73
if (!new File(javaCmd).exists()) {
74
javaCmd = System.getProperty("java.home") + "/bin/java.exe";
75
}
76
77
ArrayList<String> cmds = new ArrayList<String>();
78
cmds.add(javaCmd);
79
for (String x : args) {
80
cmds.add(x);
81
}
82
System.out.println("cmds=" + cmds);
83
ProcessBuilder pb = new ProcessBuilder(cmds);
84
85
Map<String, String> env = pb.environment();
86
pb.directory(new File("."));
87
88
List<String> out = new ArrayList<String>();
89
try {
90
pb.redirectErrorStream(true);
91
Process p = pb.start();
92
BufferedReader rd = new BufferedReader(new InputStreamReader(p.getInputStream()),8192);
93
String in = rd.readLine();
94
while (in != null) {
95
out.add(in);
96
System.out.println(in);
97
in = rd.readLine();
98
}
99
int retval = p.waitFor();
100
p.destroy();
101
if (retval != 0) {
102
throw new RuntimeException("Error: test returned non-zero value");
103
}
104
return out;
105
} catch (Exception ex) {
106
ex.printStackTrace();
107
throw new RuntimeException(ex.getMessage());
108
}
109
}
110
111
public static void main(String[] args) {
112
try {
113
String osname = System.getProperty("os.name");
114
if (osname.startsWith("Windows")) {
115
osname = "Windows";
116
}
117
118
createTestClass();
119
120
// Test a simple path
121
String libpath = File.pathSeparator + "tmp" + File.pathSeparator + "foobar";
122
List<String> processOut = null;
123
String sunbootlibrarypath = "-Dsun.boot.library.path=" + libpath;
124
processOut = doExec(sunbootlibrarypath, "-cp", ".", TESTFILE);
125
if (processOut == null || !processOut.get(0).endsWith(libpath)) {
126
throw new RuntimeException("Error: did not get expected error string");
127
}
128
} catch (IOException ex) {
129
throw new RuntimeException("Unexpected error " + ex);
130
}
131
}
132
}
133
134