Path: blob/master/test/hotspot/jtreg/runtime/6819213/TestBootNativeLibraryPath.java
40942 views
/*1* Copyright (c) 2008, 2018, 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* @summary verify sun.boot.native.library.path is expandable on 32 bit systems27* @author ksrini28* @modules java.compiler29* @library /test/lib30* @requires vm.bits == 3231* @compile -XDignore.symbol.file TestBootNativeLibraryPath.java32* @run main TestBootNativeLibraryPath33*/3435import java.io.BufferedReader;36import java.io.File;37import java.io.FileOutputStream;38import java.io.IOException;39import java.io.InputStreamReader;40import java.io.PrintStream;41import java.util.ArrayList;42import java.util.List;43import java.util.Map;44import java.util.logging.Level;45import java.util.logging.Logger;46import javax.tools.JavaCompiler;47import javax.tools.ToolProvider;4849public class TestBootNativeLibraryPath {5051private static final String TESTFILE = "Test6";5253static void createTestClass() throws IOException {54FileOutputStream fos = new FileOutputStream(TESTFILE + ".java");55PrintStream ps = new PrintStream(fos);56ps.println("public class " + TESTFILE + "{");57ps.println("public static void main(String[] args) {\n");58ps.println("System.out.println(System.getProperty(\"sun.boot.library.path\"));\n");59ps.println("}}\n");60ps.close();61fos.close();6263JavaCompiler javac = ToolProvider.getSystemJavaCompiler();64String javacOpts[] = {TESTFILE + ".java"};65if (javac.run(null, null, null, javacOpts) != 0) {66throw new RuntimeException("compilation of " + TESTFILE + ".java Failed");67}68}6970static List<String> doExec(String... args) {71String javaCmd = System.getProperty("java.home") + "/bin/java";72if (!new File(javaCmd).exists()) {73javaCmd = System.getProperty("java.home") + "/bin/java.exe";74}7576ArrayList<String> cmds = new ArrayList<String>();77cmds.add(javaCmd);78for (String x : args) {79cmds.add(x);80}81System.out.println("cmds=" + cmds);82ProcessBuilder pb = new ProcessBuilder(cmds);8384Map<String, String> env = pb.environment();85pb.directory(new File("."));8687List<String> out = new ArrayList<String>();88try {89pb.redirectErrorStream(true);90Process p = pb.start();91BufferedReader rd = new BufferedReader(new InputStreamReader(p.getInputStream()),8192);92String in = rd.readLine();93while (in != null) {94out.add(in);95System.out.println(in);96in = rd.readLine();97}98int retval = p.waitFor();99p.destroy();100if (retval != 0) {101throw new RuntimeException("Error: test returned non-zero value");102}103return out;104} catch (Exception ex) {105ex.printStackTrace();106throw new RuntimeException(ex.getMessage());107}108}109110public static void main(String[] args) {111try {112String osname = System.getProperty("os.name");113if (osname.startsWith("Windows")) {114osname = "Windows";115}116117createTestClass();118119// Test a simple path120String libpath = File.pathSeparator + "tmp" + File.pathSeparator + "foobar";121List<String> processOut = null;122String sunbootlibrarypath = "-Dsun.boot.library.path=" + libpath;123processOut = doExec(sunbootlibrarypath, "-cp", ".", TESTFILE);124if (processOut == null || !processOut.get(0).endsWith(libpath)) {125throw new RuntimeException("Error: did not get expected error string");126}127} catch (IOException ex) {128throw new RuntimeException("Unexpected error " + ex);129}130}131}132133134