hotspot/test/runtime/6819213/TestBootNativeLibraryPath.java
author xdono
Tue, 28 Jul 2009 12:12:40 -0700
changeset 3261 c7d5aae8d3f7
parent 2358 7c8346929fc6
child 5547 f4b087cbb361
permissions -rw-r--r--
6862919: Update copyright year Summary: Update copyright for files that have been modified in 2009, up to 07/09 Reviewed-by: tbell, ohair
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
2358
7c8346929fc6 6819213: revive sun.boot.library.path
phh
parents:
diff changeset
     1
/*
3261
c7d5aae8d3f7 6862919: Update copyright year
xdono
parents: 2358
diff changeset
     2
 * Copyright 2008-2009 Sun Microsystems, Inc.  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
 *
7c8346929fc6 6819213: revive sun.boot.library.path
phh
parents:
diff changeset
    19
 * Please contact Sun Microsystems, Inc., 4150 Network Circle, Santa Clara,
7c8346929fc6 6819213: revive sun.boot.library.path
phh
parents:
diff changeset
    20
 * CA 95054 USA or visit www.sun.com if you need additional information or
7c8346929fc6 6819213: revive sun.boot.library.path
phh
parents:
diff changeset
    21
 * have any questions.
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
7c8346929fc6 6819213: revive sun.boot.library.path
phh
parents:
diff changeset
    27
 * @compile -XDignore.symbol.file TestBootNativeLibraryPath.java
7c8346929fc6 6819213: revive sun.boot.library.path
phh
parents:
diff changeset
    28
 * @summary verify sun.boot.native.library.path is expandable on 32 bit systems
7c8346929fc6 6819213: revive sun.boot.library.path
phh
parents:
diff changeset
    29
 * @run main TestBootNativeLibraryPath
7c8346929fc6 6819213: revive sun.boot.library.path
phh
parents:
diff changeset
    30
 * @author ksrini
7c8346929fc6 6819213: revive sun.boot.library.path
phh
parents:
diff changeset
    31
*/
7c8346929fc6 6819213: revive sun.boot.library.path
phh
parents:
diff changeset
    32
7c8346929fc6 6819213: revive sun.boot.library.path
phh
parents:
diff changeset
    33
import java.io.BufferedReader;
7c8346929fc6 6819213: revive sun.boot.library.path
phh
parents:
diff changeset
    34
import java.io.File;
7c8346929fc6 6819213: revive sun.boot.library.path
phh
parents:
diff changeset
    35
import java.io.FileOutputStream;
7c8346929fc6 6819213: revive sun.boot.library.path
phh
parents:
diff changeset
    36
import java.io.IOException;
7c8346929fc6 6819213: revive sun.boot.library.path
phh
parents:
diff changeset
    37
import java.io.InputStreamReader;
7c8346929fc6 6819213: revive sun.boot.library.path
phh
parents:
diff changeset
    38
import java.io.PrintStream;
7c8346929fc6 6819213: revive sun.boot.library.path
phh
parents:
diff changeset
    39
import java.util.ArrayList;
7c8346929fc6 6819213: revive sun.boot.library.path
phh
parents:
diff changeset
    40
import java.util.List;
7c8346929fc6 6819213: revive sun.boot.library.path
phh
parents:
diff changeset
    41
import java.util.Map;
7c8346929fc6 6819213: revive sun.boot.library.path
phh
parents:
diff changeset
    42
import java.util.logging.Level;
7c8346929fc6 6819213: revive sun.boot.library.path
phh
parents:
diff changeset
    43
import java.util.logging.Logger;
7c8346929fc6 6819213: revive sun.boot.library.path
phh
parents:
diff changeset
    44
import javax.tools.JavaCompiler;
7c8346929fc6 6819213: revive sun.boot.library.path
phh
parents:
diff changeset
    45
import javax.tools.ToolProvider;
7c8346929fc6 6819213: revive sun.boot.library.path
phh
parents:
diff changeset
    46
7c8346929fc6 6819213: revive sun.boot.library.path
phh
parents:
diff changeset
    47
public class TestBootNativeLibraryPath {
7c8346929fc6 6819213: revive sun.boot.library.path
phh
parents:
diff changeset
    48
7c8346929fc6 6819213: revive sun.boot.library.path
phh
parents:
diff changeset
    49
    private static final String TESTFILE = "Test6";
7c8346929fc6 6819213: revive sun.boot.library.path
phh
parents:
diff changeset
    50
7c8346929fc6 6819213: revive sun.boot.library.path
phh
parents:
diff changeset
    51
    static void createTestClass() throws IOException {
7c8346929fc6 6819213: revive sun.boot.library.path
phh
parents:
diff changeset
    52
        FileOutputStream fos = new FileOutputStream(TESTFILE + ".java");
7c8346929fc6 6819213: revive sun.boot.library.path
phh
parents:
diff changeset
    53
        PrintStream ps = new PrintStream(fos);
7c8346929fc6 6819213: revive sun.boot.library.path
phh
parents:
diff changeset
    54
        ps.println("public class " + TESTFILE + "{");
7c8346929fc6 6819213: revive sun.boot.library.path
phh
parents:
diff changeset
    55
        ps.println("public static void main(String[] args) {\n");
7c8346929fc6 6819213: revive sun.boot.library.path
phh
parents:
diff changeset
    56
        ps.println("System.out.println(System.getProperty(\"sun.boot.library.path\"));\n");
7c8346929fc6 6819213: revive sun.boot.library.path
phh
parents:
diff changeset
    57
        ps.println("}}\n");
7c8346929fc6 6819213: revive sun.boot.library.path
phh
parents:
diff changeset
    58
        ps.close();
7c8346929fc6 6819213: revive sun.boot.library.path
phh
parents:
diff changeset
    59
        fos.close();
7c8346929fc6 6819213: revive sun.boot.library.path
phh
parents:
diff changeset
    60
7c8346929fc6 6819213: revive sun.boot.library.path
phh
parents:
diff changeset
    61
        JavaCompiler javac = ToolProvider.getSystemJavaCompiler();
7c8346929fc6 6819213: revive sun.boot.library.path
phh
parents:
diff changeset
    62
        String javacOpts[] = {TESTFILE + ".java"};
7c8346929fc6 6819213: revive sun.boot.library.path
phh
parents:
diff changeset
    63
        if (javac.run(null, null, null,  javacOpts) != 0) {
7c8346929fc6 6819213: revive sun.boot.library.path
phh
parents:
diff changeset
    64
            throw new RuntimeException("compilation of " + TESTFILE + ".java Failed");
7c8346929fc6 6819213: revive sun.boot.library.path
phh
parents:
diff changeset
    65
        }
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
    static List<String> doExec(String... args) {
7c8346929fc6 6819213: revive sun.boot.library.path
phh
parents:
diff changeset
    69
        String javaCmd = System.getProperty("java.home") + "/bin/java";
7c8346929fc6 6819213: revive sun.boot.library.path
phh
parents:
diff changeset
    70
        if (!new File(javaCmd).exists()) {
7c8346929fc6 6819213: revive sun.boot.library.path
phh
parents:
diff changeset
    71
            javaCmd = System.getProperty("java.home") + "/bin/java.exe";
7c8346929fc6 6819213: revive sun.boot.library.path
phh
parents:
diff changeset
    72
        }
7c8346929fc6 6819213: revive sun.boot.library.path
phh
parents:
diff changeset
    73
7c8346929fc6 6819213: revive sun.boot.library.path
phh
parents:
diff changeset
    74
        ArrayList<String> cmds = new ArrayList<String>();
7c8346929fc6 6819213: revive sun.boot.library.path
phh
parents:
diff changeset
    75
        cmds.add(javaCmd);
7c8346929fc6 6819213: revive sun.boot.library.path
phh
parents:
diff changeset
    76
        for (String x : args) {
7c8346929fc6 6819213: revive sun.boot.library.path
phh
parents:
diff changeset
    77
            cmds.add(x);
7c8346929fc6 6819213: revive sun.boot.library.path
phh
parents:
diff changeset
    78
        }
7c8346929fc6 6819213: revive sun.boot.library.path
phh
parents:
diff changeset
    79
        System.out.println("cmds=" + cmds);
7c8346929fc6 6819213: revive sun.boot.library.path
phh
parents:
diff changeset
    80
        ProcessBuilder pb = new ProcessBuilder(cmds);
7c8346929fc6 6819213: revive sun.boot.library.path
phh
parents:
diff changeset
    81
7c8346929fc6 6819213: revive sun.boot.library.path
phh
parents:
diff changeset
    82
        Map<String, String> env = pb.environment();
7c8346929fc6 6819213: revive sun.boot.library.path
phh
parents:
diff changeset
    83
        pb.directory(new File("."));
7c8346929fc6 6819213: revive sun.boot.library.path
phh
parents:
diff changeset
    84
7c8346929fc6 6819213: revive sun.boot.library.path
phh
parents:
diff changeset
    85
        List<String> out = new ArrayList<String>();
7c8346929fc6 6819213: revive sun.boot.library.path
phh
parents:
diff changeset
    86
        try {
7c8346929fc6 6819213: revive sun.boot.library.path
phh
parents:
diff changeset
    87
            pb.redirectErrorStream(true);
7c8346929fc6 6819213: revive sun.boot.library.path
phh
parents:
diff changeset
    88
            Process p = pb.start();
7c8346929fc6 6819213: revive sun.boot.library.path
phh
parents:
diff changeset
    89
            BufferedReader rd = new BufferedReader(new InputStreamReader(p.getInputStream()),8192);
7c8346929fc6 6819213: revive sun.boot.library.path
phh
parents:
diff changeset
    90
            String in = rd.readLine();
7c8346929fc6 6819213: revive sun.boot.library.path
phh
parents:
diff changeset
    91
            while (in != null) {
7c8346929fc6 6819213: revive sun.boot.library.path
phh
parents:
diff changeset
    92
                out.add(in);
7c8346929fc6 6819213: revive sun.boot.library.path
phh
parents:
diff changeset
    93
                System.out.println(in);
7c8346929fc6 6819213: revive sun.boot.library.path
phh
parents:
diff changeset
    94
                in = rd.readLine();
7c8346929fc6 6819213: revive sun.boot.library.path
phh
parents:
diff changeset
    95
            }
7c8346929fc6 6819213: revive sun.boot.library.path
phh
parents:
diff changeset
    96
            int retval = p.waitFor();
7c8346929fc6 6819213: revive sun.boot.library.path
phh
parents:
diff changeset
    97
            p.destroy();
7c8346929fc6 6819213: revive sun.boot.library.path
phh
parents:
diff changeset
    98
            if (retval != 0) {
7c8346929fc6 6819213: revive sun.boot.library.path
phh
parents:
diff changeset
    99
                throw new RuntimeException("Error: test returned non-zero value");
7c8346929fc6 6819213: revive sun.boot.library.path
phh
parents:
diff changeset
   100
            }
7c8346929fc6 6819213: revive sun.boot.library.path
phh
parents:
diff changeset
   101
            return out;
7c8346929fc6 6819213: revive sun.boot.library.path
phh
parents:
diff changeset
   102
        } catch (Exception ex) {
7c8346929fc6 6819213: revive sun.boot.library.path
phh
parents:
diff changeset
   103
            ex.printStackTrace();
7c8346929fc6 6819213: revive sun.boot.library.path
phh
parents:
diff changeset
   104
            throw new RuntimeException(ex.getMessage());
7c8346929fc6 6819213: revive sun.boot.library.path
phh
parents:
diff changeset
   105
        }
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
    public static void main(String[] args) {
7c8346929fc6 6819213: revive sun.boot.library.path
phh
parents:
diff changeset
   109
        try {
7c8346929fc6 6819213: revive sun.boot.library.path
phh
parents:
diff changeset
   110
            if (!System.getProperty("sun.arch.data.model").equals("32")) {
7c8346929fc6 6819213: revive sun.boot.library.path
phh
parents:
diff changeset
   111
                System.out.println("Warning: test skipped for 64-bit systems\n");
7c8346929fc6 6819213: revive sun.boot.library.path
phh
parents:
diff changeset
   112
                return;
7c8346929fc6 6819213: revive sun.boot.library.path
phh
parents:
diff changeset
   113
            }
7c8346929fc6 6819213: revive sun.boot.library.path
phh
parents:
diff changeset
   114
            String osname = System.getProperty("os.name");
7c8346929fc6 6819213: revive sun.boot.library.path
phh
parents:
diff changeset
   115
            if (osname.startsWith("Windows")) {
7c8346929fc6 6819213: revive sun.boot.library.path
phh
parents:
diff changeset
   116
                osname = "Windows";
7c8346929fc6 6819213: revive sun.boot.library.path
phh
parents:
diff changeset
   117
            }
7c8346929fc6 6819213: revive sun.boot.library.path
phh
parents:
diff changeset
   118
7c8346929fc6 6819213: revive sun.boot.library.path
phh
parents:
diff changeset
   119
            createTestClass();
7c8346929fc6 6819213: revive sun.boot.library.path
phh
parents:
diff changeset
   120
7c8346929fc6 6819213: revive sun.boot.library.path
phh
parents:
diff changeset
   121
            // Test a simple path
7c8346929fc6 6819213: revive sun.boot.library.path
phh
parents:
diff changeset
   122
            String libpath = File.pathSeparator + "tmp" + File.pathSeparator + "foobar";
7c8346929fc6 6819213: revive sun.boot.library.path
phh
parents:
diff changeset
   123
            List<String> processOut = null;
7c8346929fc6 6819213: revive sun.boot.library.path
phh
parents:
diff changeset
   124
            String sunbootlibrarypath = "-Dsun.boot.library.path=" + libpath;
7c8346929fc6 6819213: revive sun.boot.library.path
phh
parents:
diff changeset
   125
            processOut = doExec(sunbootlibrarypath, "-cp", ".", TESTFILE);
7c8346929fc6 6819213: revive sun.boot.library.path
phh
parents:
diff changeset
   126
            if (processOut == null || !processOut.get(0).endsWith(libpath)) {
7c8346929fc6 6819213: revive sun.boot.library.path
phh
parents:
diff changeset
   127
                throw new RuntimeException("Error: did not get expected error string");
7c8346929fc6 6819213: revive sun.boot.library.path
phh
parents:
diff changeset
   128
            }
7c8346929fc6 6819213: revive sun.boot.library.path
phh
parents:
diff changeset
   129
        } catch (IOException ex) {
7c8346929fc6 6819213: revive sun.boot.library.path
phh
parents:
diff changeset
   130
            throw new RuntimeException("Unexpected error " + ex);
7c8346929fc6 6819213: revive sun.boot.library.path
phh
parents:
diff changeset
   131
        }
7c8346929fc6 6819213: revive sun.boot.library.path
phh
parents:
diff changeset
   132
    }
7c8346929fc6 6819213: revive sun.boot.library.path
phh
parents:
diff changeset
   133
}