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