test/runtime/6819213/TestBootNativeLibraryPath.java

changeset 0
f90c822e73f8
child 6876
710a3c8b516e
     1.1 --- /dev/null	Thu Jan 01 00:00:00 1970 +0000
     1.2 +++ b/test/runtime/6819213/TestBootNativeLibraryPath.java	Wed Apr 27 01:25:04 2016 +0800
     1.3 @@ -0,0 +1,133 @@
     1.4 +/*
     1.5 + * Copyright (c) 2008, 2009, Oracle and/or its affiliates. All rights reserved.
     1.6 + * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
     1.7 + *
     1.8 + * This code is free software; you can redistribute it and/or modify it
     1.9 + * under the terms of the GNU General Public License version 2 only, as
    1.10 + * published by the Free Software Foundation.
    1.11 + *
    1.12 + * This code is distributed in the hope that it will be useful, but WITHOUT
    1.13 + * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
    1.14 + * FITNESS FOR A PARTICULAR PURPOSE.  See the GNU General Public License
    1.15 + * version 2 for more details (a copy is included in the LICENSE file that
    1.16 + * accompanied this code).
    1.17 + *
    1.18 + * You should have received a copy of the GNU General Public License version
    1.19 + * 2 along with this work; if not, write to the Free Software Foundation,
    1.20 + * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
    1.21 + *
    1.22 + * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
    1.23 + * or visit www.oracle.com if you need additional information or have any
    1.24 + * questions.
    1.25 + */
    1.26 +
    1.27 +/*
    1.28 + * @test TestBootNativeLibraryPath.java
    1.29 + * @bug 6819213
    1.30 + * @compile -XDignore.symbol.file TestBootNativeLibraryPath.java
    1.31 + * @summary verify sun.boot.native.library.path is expandable on 32 bit systems
    1.32 + * @run main TestBootNativeLibraryPath
    1.33 + * @author ksrini
    1.34 +*/
    1.35 +
    1.36 +import java.io.BufferedReader;
    1.37 +import java.io.File;
    1.38 +import java.io.FileOutputStream;
    1.39 +import java.io.IOException;
    1.40 +import java.io.InputStreamReader;
    1.41 +import java.io.PrintStream;
    1.42 +import java.util.ArrayList;
    1.43 +import java.util.List;
    1.44 +import java.util.Map;
    1.45 +import java.util.logging.Level;
    1.46 +import java.util.logging.Logger;
    1.47 +import javax.tools.JavaCompiler;
    1.48 +import javax.tools.ToolProvider;
    1.49 +
    1.50 +public class TestBootNativeLibraryPath {
    1.51 +
    1.52 +    private static final String TESTFILE = "Test6";
    1.53 +
    1.54 +    static void createTestClass() throws IOException {
    1.55 +        FileOutputStream fos = new FileOutputStream(TESTFILE + ".java");
    1.56 +        PrintStream ps = new PrintStream(fos);
    1.57 +        ps.println("public class " + TESTFILE + "{");
    1.58 +        ps.println("public static void main(String[] args) {\n");
    1.59 +        ps.println("System.out.println(System.getProperty(\"sun.boot.library.path\"));\n");
    1.60 +        ps.println("}}\n");
    1.61 +        ps.close();
    1.62 +        fos.close();
    1.63 +
    1.64 +        JavaCompiler javac = ToolProvider.getSystemJavaCompiler();
    1.65 +        String javacOpts[] = {TESTFILE + ".java"};
    1.66 +        if (javac.run(null, null, null,  javacOpts) != 0) {
    1.67 +            throw new RuntimeException("compilation of " + TESTFILE + ".java Failed");
    1.68 +        }
    1.69 +    }
    1.70 +
    1.71 +    static List<String> doExec(String... args) {
    1.72 +        String javaCmd = System.getProperty("java.home") + "/bin/java";
    1.73 +        if (!new File(javaCmd).exists()) {
    1.74 +            javaCmd = System.getProperty("java.home") + "/bin/java.exe";
    1.75 +        }
    1.76 +
    1.77 +        ArrayList<String> cmds = new ArrayList<String>();
    1.78 +        cmds.add(javaCmd);
    1.79 +        for (String x : args) {
    1.80 +            cmds.add(x);
    1.81 +        }
    1.82 +        System.out.println("cmds=" + cmds);
    1.83 +        ProcessBuilder pb = new ProcessBuilder(cmds);
    1.84 +
    1.85 +        Map<String, String> env = pb.environment();
    1.86 +        pb.directory(new File("."));
    1.87 +
    1.88 +        List<String> out = new ArrayList<String>();
    1.89 +        try {
    1.90 +            pb.redirectErrorStream(true);
    1.91 +            Process p = pb.start();
    1.92 +            BufferedReader rd = new BufferedReader(new InputStreamReader(p.getInputStream()),8192);
    1.93 +            String in = rd.readLine();
    1.94 +            while (in != null) {
    1.95 +                out.add(in);
    1.96 +                System.out.println(in);
    1.97 +                in = rd.readLine();
    1.98 +            }
    1.99 +            int retval = p.waitFor();
   1.100 +            p.destroy();
   1.101 +            if (retval != 0) {
   1.102 +                throw new RuntimeException("Error: test returned non-zero value");
   1.103 +            }
   1.104 +            return out;
   1.105 +        } catch (Exception ex) {
   1.106 +            ex.printStackTrace();
   1.107 +            throw new RuntimeException(ex.getMessage());
   1.108 +        }
   1.109 +    }
   1.110 +
   1.111 +    public static void main(String[] args) {
   1.112 +        try {
   1.113 +            if (!System.getProperty("sun.arch.data.model").equals("32")) {
   1.114 +                System.out.println("Warning: test skipped for 64-bit systems\n");
   1.115 +                return;
   1.116 +            }
   1.117 +            String osname = System.getProperty("os.name");
   1.118 +            if (osname.startsWith("Windows")) {
   1.119 +                osname = "Windows";
   1.120 +            }
   1.121 +
   1.122 +            createTestClass();
   1.123 +
   1.124 +            // Test a simple path
   1.125 +            String libpath = File.pathSeparator + "tmp" + File.pathSeparator + "foobar";
   1.126 +            List<String> processOut = null;
   1.127 +            String sunbootlibrarypath = "-Dsun.boot.library.path=" + libpath;
   1.128 +            processOut = doExec(sunbootlibrarypath, "-cp", ".", TESTFILE);
   1.129 +            if (processOut == null || !processOut.get(0).endsWith(libpath)) {
   1.130 +                throw new RuntimeException("Error: did not get expected error string");
   1.131 +            }
   1.132 +        } catch (IOException ex) {
   1.133 +            throw new RuntimeException("Unexpected error " + ex);
   1.134 +        }
   1.135 +    }
   1.136 +}

mercurial