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