test/runtime/6819213/TestBootNativeLibraryPath.java

Mon, 06 Nov 2017 16:51:47 +0800

author
aoqi
date
Mon, 06 Nov 2017 16:51:47 +0800
changeset 7997
6cbff0651f1a
parent 6876
710a3c8b516e
permissions
-rw-r--r--

[Code Reorganization] remove trailing whitespace to pass jcheck test

aoqi@0 1 /*
aoqi@0 2 * Copyright (c) 2008, 2009, Oracle and/or its affiliates. All rights reserved.
aoqi@0 3 * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
aoqi@0 4 *
aoqi@0 5 * This code is free software; you can redistribute it and/or modify it
aoqi@0 6 * under the terms of the GNU General Public License version 2 only, as
aoqi@0 7 * published by the Free Software Foundation.
aoqi@0 8 *
aoqi@0 9 * This code is distributed in the hope that it will be useful, but WITHOUT
aoqi@0 10 * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
aoqi@0 11 * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
aoqi@0 12 * version 2 for more details (a copy is included in the LICENSE file that
aoqi@0 13 * accompanied this code).
aoqi@0 14 *
aoqi@0 15 * You should have received a copy of the GNU General Public License version
aoqi@0 16 * 2 along with this work; if not, write to the Free Software Foundation,
aoqi@0 17 * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
aoqi@0 18 *
aoqi@0 19 * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
aoqi@0 20 * or visit www.oracle.com if you need additional information or have any
aoqi@0 21 * questions.
aoqi@0 22 */
aoqi@0 23
aoqi@0 24 /*
aoqi@0 25 * @test TestBootNativeLibraryPath.java
aoqi@0 26 * @bug 6819213
aoqi@0 27 * @compile -XDignore.symbol.file TestBootNativeLibraryPath.java
aoqi@0 28 * @summary verify sun.boot.native.library.path is expandable on 32 bit systems
aoqi@0 29 * @run main TestBootNativeLibraryPath
aoqi@0 30 * @author ksrini
aoqi@0 31 */
aoqi@0 32
aoqi@0 33 import java.io.BufferedReader;
aoqi@0 34 import java.io.File;
aoqi@0 35 import java.io.FileOutputStream;
aoqi@0 36 import java.io.IOException;
aoqi@0 37 import java.io.InputStreamReader;
aoqi@0 38 import java.io.PrintStream;
aoqi@0 39 import java.util.ArrayList;
aoqi@0 40 import java.util.List;
aoqi@0 41 import java.util.Map;
aoqi@0 42 import java.util.logging.Level;
aoqi@0 43 import java.util.logging.Logger;
aoqi@0 44 import javax.tools.JavaCompiler;
aoqi@0 45 import javax.tools.ToolProvider;
aoqi@0 46
aoqi@0 47 public class TestBootNativeLibraryPath {
aoqi@0 48
aoqi@0 49 private static final String TESTFILE = "Test6";
aoqi@0 50
aoqi@0 51 static void createTestClass() throws IOException {
aoqi@0 52 FileOutputStream fos = new FileOutputStream(TESTFILE + ".java");
aoqi@0 53 PrintStream ps = new PrintStream(fos);
aoqi@0 54 ps.println("public class " + TESTFILE + "{");
aoqi@0 55 ps.println("public static void main(String[] args) {\n");
aoqi@0 56 ps.println("System.out.println(System.getProperty(\"sun.boot.library.path\"));\n");
aoqi@0 57 ps.println("}}\n");
aoqi@0 58 ps.close();
aoqi@0 59 fos.close();
aoqi@0 60
aoqi@0 61 JavaCompiler javac = ToolProvider.getSystemJavaCompiler();
aoqi@0 62 String javacOpts[] = {TESTFILE + ".java"};
aoqi@0 63 if (javac.run(null, null, null, javacOpts) != 0) {
aoqi@0 64 throw new RuntimeException("compilation of " + TESTFILE + ".java Failed");
aoqi@0 65 }
aoqi@0 66 }
aoqi@0 67
aoqi@0 68 static List<String> doExec(String... args) {
aoqi@0 69 String javaCmd = System.getProperty("java.home") + "/bin/java";
aoqi@0 70 if (!new File(javaCmd).exists()) {
aoqi@0 71 javaCmd = System.getProperty("java.home") + "/bin/java.exe";
aoqi@0 72 }
aoqi@0 73
aoqi@0 74 ArrayList<String> cmds = new ArrayList<String>();
aoqi@0 75 cmds.add(javaCmd);
aoqi@0 76 for (String x : args) {
aoqi@0 77 cmds.add(x);
aoqi@0 78 }
aoqi@0 79 System.out.println("cmds=" + cmds);
aoqi@0 80 ProcessBuilder pb = new ProcessBuilder(cmds);
aoqi@0 81
aoqi@0 82 Map<String, String> env = pb.environment();
aoqi@0 83 pb.directory(new File("."));
aoqi@0 84
aoqi@0 85 List<String> out = new ArrayList<String>();
aoqi@0 86 try {
aoqi@0 87 pb.redirectErrorStream(true);
aoqi@0 88 Process p = pb.start();
aoqi@0 89 BufferedReader rd = new BufferedReader(new InputStreamReader(p.getInputStream()),8192);
aoqi@0 90 String in = rd.readLine();
aoqi@0 91 while (in != null) {
aoqi@0 92 out.add(in);
aoqi@0 93 System.out.println(in);
aoqi@0 94 in = rd.readLine();
aoqi@0 95 }
aoqi@0 96 int retval = p.waitFor();
aoqi@0 97 p.destroy();
aoqi@0 98 if (retval != 0) {
aoqi@0 99 throw new RuntimeException("Error: test returned non-zero value");
aoqi@0 100 }
aoqi@0 101 return out;
aoqi@0 102 } catch (Exception ex) {
aoqi@0 103 ex.printStackTrace();
aoqi@0 104 throw new RuntimeException(ex.getMessage());
aoqi@0 105 }
aoqi@0 106 }
aoqi@0 107
aoqi@0 108 public static void main(String[] args) {
aoqi@0 109 try {
aoqi@0 110 if (!System.getProperty("sun.arch.data.model").equals("32")) {
aoqi@0 111 System.out.println("Warning: test skipped for 64-bit systems\n");
aoqi@0 112 return;
aoqi@0 113 }
aoqi@0 114 String osname = System.getProperty("os.name");
aoqi@0 115 if (osname.startsWith("Windows")) {
aoqi@0 116 osname = "Windows";
aoqi@0 117 }
aoqi@0 118
aoqi@0 119 createTestClass();
aoqi@0 120
aoqi@0 121 // Test a simple path
aoqi@0 122 String libpath = File.pathSeparator + "tmp" + File.pathSeparator + "foobar";
aoqi@0 123 List<String> processOut = null;
aoqi@0 124 String sunbootlibrarypath = "-Dsun.boot.library.path=" + libpath;
aoqi@0 125 processOut = doExec(sunbootlibrarypath, "-cp", ".", TESTFILE);
aoqi@0 126 if (processOut == null || !processOut.get(0).endsWith(libpath)) {
aoqi@0 127 throw new RuntimeException("Error: did not get expected error string");
aoqi@0 128 }
aoqi@0 129 } catch (IOException ex) {
aoqi@0 130 throw new RuntimeException("Unexpected error " + ex);
aoqi@0 131 }
aoqi@0 132 }
aoqi@0 133 }

mercurial