691N/A/*
1472N/A * Copyright (c) 2008, 2009, Oracle and/or its affiliates. All rights reserved.
691N/A * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
691N/A *
691N/A * This code is free software; you can redistribute it and/or modify it
691N/A * under the terms of the GNU General Public License version 2 only, as
691N/A * published by the Free Software Foundation.
691N/A *
691N/A * This code is distributed in the hope that it will be useful, but WITHOUT
691N/A * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
691N/A * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
691N/A * version 2 for more details (a copy is included in the LICENSE file that
691N/A * accompanied this code).
691N/A *
691N/A * You should have received a copy of the GNU General Public License version
691N/A * 2 along with this work; if not, write to the Free Software Foundation,
691N/A * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
691N/A *
1472N/A * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
1472N/A * or visit www.oracle.com if you need additional information or have any
1472N/A * questions.
691N/A */
691N/A
691N/A/*
691N/A * @test TestBootNativeLibraryPath.java
691N/A * @bug 6819213
691N/A * @compile -XDignore.symbol.file TestBootNativeLibraryPath.java
691N/A * @summary verify sun.boot.native.library.path is expandable on 32 bit systems
691N/A * @run main TestBootNativeLibraryPath
691N/A * @author ksrini
691N/A*/
691N/A
691N/Aimport java.io.BufferedReader;
691N/Aimport java.io.File;
691N/Aimport java.io.FileOutputStream;
691N/Aimport java.io.IOException;
691N/Aimport java.io.InputStreamReader;
691N/Aimport java.io.PrintStream;
691N/Aimport java.util.ArrayList;
691N/Aimport java.util.List;
691N/Aimport java.util.Map;
691N/Aimport java.util.logging.Level;
691N/Aimport java.util.logging.Logger;
691N/Aimport javax.tools.JavaCompiler;
691N/Aimport javax.tools.ToolProvider;
691N/A
691N/Apublic class TestBootNativeLibraryPath {
691N/A
691N/A private static final String TESTFILE = "Test6";
691N/A
691N/A static void createTestClass() throws IOException {
691N/A FileOutputStream fos = new FileOutputStream(TESTFILE + ".java");
691N/A PrintStream ps = new PrintStream(fos);
691N/A ps.println("public class " + TESTFILE + "{");
691N/A ps.println("public static void main(String[] args) {\n");
691N/A ps.println("System.out.println(System.getProperty(\"sun.boot.library.path\"));\n");
691N/A ps.println("}}\n");
691N/A ps.close();
691N/A fos.close();
691N/A
691N/A JavaCompiler javac = ToolProvider.getSystemJavaCompiler();
691N/A String javacOpts[] = {TESTFILE + ".java"};
691N/A if (javac.run(null, null, null, javacOpts) != 0) {
691N/A throw new RuntimeException("compilation of " + TESTFILE + ".java Failed");
691N/A }
691N/A }
691N/A
691N/A static List<String> doExec(String... args) {
691N/A String javaCmd = System.getProperty("java.home") + "/bin/java";
691N/A if (!new File(javaCmd).exists()) {
691N/A javaCmd = System.getProperty("java.home") + "/bin/java.exe";
691N/A }
691N/A
691N/A ArrayList<String> cmds = new ArrayList<String>();
691N/A cmds.add(javaCmd);
691N/A for (String x : args) {
691N/A cmds.add(x);
691N/A }
691N/A System.out.println("cmds=" + cmds);
691N/A ProcessBuilder pb = new ProcessBuilder(cmds);
691N/A
691N/A Map<String, String> env = pb.environment();
691N/A pb.directory(new File("."));
691N/A
691N/A List<String> out = new ArrayList<String>();
691N/A try {
691N/A pb.redirectErrorStream(true);
691N/A Process p = pb.start();
691N/A BufferedReader rd = new BufferedReader(new InputStreamReader(p.getInputStream()),8192);
691N/A String in = rd.readLine();
691N/A while (in != null) {
691N/A out.add(in);
691N/A System.out.println(in);
691N/A in = rd.readLine();
691N/A }
691N/A int retval = p.waitFor();
691N/A p.destroy();
691N/A if (retval != 0) {
691N/A throw new RuntimeException("Error: test returned non-zero value");
691N/A }
691N/A return out;
691N/A } catch (Exception ex) {
691N/A ex.printStackTrace();
691N/A throw new RuntimeException(ex.getMessage());
691N/A }
691N/A }
691N/A
691N/A public static void main(String[] args) {
691N/A try {
691N/A if (!System.getProperty("sun.arch.data.model").equals("32")) {
691N/A System.out.println("Warning: test skipped for 64-bit systems\n");
691N/A return;
691N/A }
691N/A String osname = System.getProperty("os.name");
691N/A if (osname.startsWith("Windows")) {
691N/A osname = "Windows";
691N/A }
691N/A
691N/A createTestClass();
691N/A
691N/A // Test a simple path
691N/A String libpath = File.pathSeparator + "tmp" + File.pathSeparator + "foobar";
691N/A List<String> processOut = null;
691N/A String sunbootlibrarypath = "-Dsun.boot.library.path=" + libpath;
691N/A processOut = doExec(sunbootlibrarypath, "-cp", ".", TESTFILE);
691N/A if (processOut == null || !processOut.get(0).endsWith(libpath)) {
691N/A throw new RuntimeException("Error: did not get expected error string");
691N/A }
691N/A } catch (IOException ex) {
691N/A throw new RuntimeException("Unexpected error " + ex);
691N/A }
691N/A }
691N/A}