1 /* 2 * Copyright (c) 2013, 2015, Oracle and/or its affiliates. All rights reserved. 3 * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. 4 * 5 * This code is free software; you can redistribute it and/or modify it 6 * under the terms of the GNU General Public License version 2 only, as 7 * published by the Free Software Foundation. 8 * 9 * This code is distributed in the hope that it will be useful, but WITHOUT 10 * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or 11 * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License 12 * version 2 for more details (a copy is included in the LICENSE file that 13 * accompanied this code). 14 * 15 * You should have received a copy of the GNU General Public License version 16 * 2 along with this work; if not, write to the Free Software Foundation, 17 * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA. 18 * 19 * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA 20 * or visit www.oracle.com if you need additional information or have any 21 * questions. 22 */ 23 24 /* 25 * @test 26 * @bug 7051189 8023393 27 * @summary Need to suppress info message if -Xcheck:jni is used with libjsig.so 28 * @library /test/lib 29 * @modules java.base/jdk.internal.misc 30 * java.management 31 * @run main XCheckJSig 32 */ 33 34 import java.io.File; 35 import java.util.Map; 36 import jdk.test.lib.process.ProcessTools; 37 import jdk.test.lib.process.OutputAnalyzer; 38 import jdk.test.lib.Platform; 39 40 public class XCheckJSig { 41 public static void main(String args[]) throws Throwable { 42 43 System.out.println("Regression test for bugs 7051189 and 8023393"); 44 if (!Platform.isSolaris() && !Platform.isLinux() && !Platform.isOSX()) { 45 System.out.println("Test only applicable on Solaris, Linux, and Mac OSX, skipping"); 46 return; 47 } 48 49 String jdk_path = System.getProperty("test.jdk"); 50 String os_arch = Platform.getOsArch(); 51 String libjsig; 52 String env_var; 53 if (Platform.isOSX()) { 54 env_var = "DYLD_INSERT_LIBRARIES"; 55 libjsig = jdk_path + "/jre/lib/libjsig.dylib"; // jdk location 56 if (!(new File(libjsig).exists())) { 57 libjsig = jdk_path + "/lib/libjsig.dylib"; // jre location 58 } 59 } else { 60 env_var = "LD_PRELOAD"; 61 libjsig = jdk_path + "/jre/lib/" + os_arch + "/libjsig.so"; // jdk location 62 if (!(new File(libjsig).exists())) { 63 libjsig = jdk_path + "/lib/" + os_arch + "/libjsig.so"; // jre location 64 } 65 } 66 // If this test fails, these might be useful to know. 67 System.out.println("libjsig: " + libjsig); 68 System.out.println("osArch: " + os_arch); 69 70 // Make sure the libjsig file exists. 71 if (!(new File(libjsig).exists())) { 72 System.out.println("File " + libjsig + " not found, skipping"); 73 return; 74 } 75 76 ProcessBuilder pb = ProcessTools.createJavaProcessBuilder("-Xcheck:jni", "-version"); 77 Map<String, String> env = pb.environment(); 78 env.put(env_var, libjsig); 79 OutputAnalyzer output = new OutputAnalyzer(pb.start()); 80 output.shouldNotContain("libjsig is activated"); 81 output.shouldHaveExitValue(0); 82 83 pb = ProcessTools.createJavaProcessBuilder("-Xcheck:jni", "-verbose:jni", "-version"); 84 env = pb.environment(); 85 env.put(env_var, libjsig); 86 output = new OutputAnalyzer(pb.start()); 87 output.shouldContain("libjsig is activated"); 88 output.shouldHaveExitValue(0); 89 } 90 }