author | adlertz |
Fri, 24 Jan 2014 13:06:52 +0100 | |
changeset 22804 | 401135897b65 |
parent 5547 | f4b087cbb361 |
child 29678 | dd2f3932c21e |
permissions | -rw-r--r-- |
2358 | 1 |
/* |
5547
f4b087cbb361
6941466: Oracle rebranding changes for Hotspot repositories
trims
parents:
3261
diff
changeset
|
2 |
* Copyright (c) 2008, 2009, Oracle and/or its affiliates. All rights reserved. |
2358 | 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 |
* |
|
5547
f4b087cbb361
6941466: Oracle rebranding changes for Hotspot repositories
trims
parents:
3261
diff
changeset
|
19 |
* Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA |
f4b087cbb361
6941466: Oracle rebranding changes for Hotspot repositories
trims
parents:
3261
diff
changeset
|
20 |
* or visit www.oracle.com if you need additional information or have any |
f4b087cbb361
6941466: Oracle rebranding changes for Hotspot repositories
trims
parents:
3261
diff
changeset
|
21 |
* questions. |
2358 | 22 |
*/ |
23 |
||
24 |
/* |
|
25 |
* @test TestBootNativeLibraryPath.java |
|
26 |
* @bug 6819213 |
|
27 |
* @compile -XDignore.symbol.file TestBootNativeLibraryPath.java |
|
28 |
* @summary verify sun.boot.native.library.path is expandable on 32 bit systems |
|
29 |
* @run main TestBootNativeLibraryPath |
|
30 |
* @author ksrini |
|
31 |
*/ |
|
32 |
||
33 |
import java.io.BufferedReader; |
|
34 |
import java.io.File; |
|
35 |
import java.io.FileOutputStream; |
|
36 |
import java.io.IOException; |
|
37 |
import java.io.InputStreamReader; |
|
38 |
import java.io.PrintStream; |
|
39 |
import java.util.ArrayList; |
|
40 |
import java.util.List; |
|
41 |
import java.util.Map; |
|
42 |
import java.util.logging.Level; |
|
43 |
import java.util.logging.Logger; |
|
44 |
import javax.tools.JavaCompiler; |
|
45 |
import javax.tools.ToolProvider; |
|
46 |
||
47 |
public class TestBootNativeLibraryPath { |
|
48 |
||
49 |
private static final String TESTFILE = "Test6"; |
|
50 |
||
51 |
static void createTestClass() throws IOException { |
|
52 |
FileOutputStream fos = new FileOutputStream(TESTFILE + ".java"); |
|
53 |
PrintStream ps = new PrintStream(fos); |
|
54 |
ps.println("public class " + TESTFILE + "{"); |
|
55 |
ps.println("public static void main(String[] args) {\n"); |
|
56 |
ps.println("System.out.println(System.getProperty(\"sun.boot.library.path\"));\n"); |
|
57 |
ps.println("}}\n"); |
|
58 |
ps.close(); |
|
59 |
fos.close(); |
|
60 |
||
61 |
JavaCompiler javac = ToolProvider.getSystemJavaCompiler(); |
|
62 |
String javacOpts[] = {TESTFILE + ".java"}; |
|
63 |
if (javac.run(null, null, null, javacOpts) != 0) { |
|
64 |
throw new RuntimeException("compilation of " + TESTFILE + ".java Failed"); |
|
65 |
} |
|
66 |
} |
|
67 |
||
68 |
static List<String> doExec(String... args) { |
|
69 |
String javaCmd = System.getProperty("java.home") + "/bin/java"; |
|
70 |
if (!new File(javaCmd).exists()) { |
|
71 |
javaCmd = System.getProperty("java.home") + "/bin/java.exe"; |
|
72 |
} |
|
73 |
||
74 |
ArrayList<String> cmds = new ArrayList<String>(); |
|
75 |
cmds.add(javaCmd); |
|
76 |
for (String x : args) { |
|
77 |
cmds.add(x); |
|
78 |
} |
|
79 |
System.out.println("cmds=" + cmds); |
|
80 |
ProcessBuilder pb = new ProcessBuilder(cmds); |
|
81 |
||
82 |
Map<String, String> env = pb.environment(); |
|
83 |
pb.directory(new File(".")); |
|
84 |
||
85 |
List<String> out = new ArrayList<String>(); |
|
86 |
try { |
|
87 |
pb.redirectErrorStream(true); |
|
88 |
Process p = pb.start(); |
|
89 |
BufferedReader rd = new BufferedReader(new InputStreamReader(p.getInputStream()),8192); |
|
90 |
String in = rd.readLine(); |
|
91 |
while (in != null) { |
|
92 |
out.add(in); |
|
93 |
System.out.println(in); |
|
94 |
in = rd.readLine(); |
|
95 |
} |
|
96 |
int retval = p.waitFor(); |
|
97 |
p.destroy(); |
|
98 |
if (retval != 0) { |
|
99 |
throw new RuntimeException("Error: test returned non-zero value"); |
|
100 |
} |
|
101 |
return out; |
|
102 |
} catch (Exception ex) { |
|
103 |
ex.printStackTrace(); |
|
104 |
throw new RuntimeException(ex.getMessage()); |
|
105 |
} |
|
106 |
} |
|
107 |
||
108 |
public static void main(String[] args) { |
|
109 |
try { |
|
110 |
if (!System.getProperty("sun.arch.data.model").equals("32")) { |
|
111 |
System.out.println("Warning: test skipped for 64-bit systems\n"); |
|
112 |
return; |
|
113 |
} |
|
114 |
String osname = System.getProperty("os.name"); |
|
115 |
if (osname.startsWith("Windows")) { |
|
116 |
osname = "Windows"; |
|
117 |
} |
|
118 |
||
119 |
createTestClass(); |
|
120 |
||
121 |
// Test a simple path |
|
122 |
String libpath = File.pathSeparator + "tmp" + File.pathSeparator + "foobar"; |
|
123 |
List<String> processOut = null; |
|
124 |
String sunbootlibrarypath = "-Dsun.boot.library.path=" + libpath; |
|
125 |
processOut = doExec(sunbootlibrarypath, "-cp", ".", TESTFILE); |
|
126 |
if (processOut == null || !processOut.get(0).endsWith(libpath)) { |
|
127 |
throw new RuntimeException("Error: did not get expected error string"); |
|
128 |
} |
|
129 |
} catch (IOException ex) { |
|
130 |
throw new RuntimeException("Unexpected error " + ex); |
|
131 |
} |
|
132 |
} |
|
133 |
} |