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 /testlibrary
  29  * @modules java.base/sun.misc
  30  *          java.management
  31  * @run main XCheckJSig
  32  */
  33 
  34 import java.io.File;
  35 import java.util.Map;
  36 import com.oracle.java.testlibrary.*;
  37 
  38 public class XCheckJSig {
  39     public static void main(String args[]) throws Throwable {
  40 
  41         System.out.println("Regression test for bugs 7051189 and 8023393");
  42         if (!Platform.isSolaris() && !Platform.isLinux() && !Platform.isOSX()) {
  43             System.out.println("Test only applicable on Solaris, Linux, and Mac OSX, skipping");
  44             return;
  45         }
  46 
  47         String jdk_path = System.getProperty("test.jdk");
  48         String os_arch = Platform.getOsArch();
  49         String libjsig;
  50         String env_var;
  51         if (Platform.isOSX()) {
  52             env_var = "DYLD_INSERT_LIBRARIES";
  53             libjsig = jdk_path + "/jre/lib/libjsig.dylib"; // jdk location
  54             if (!(new File(libjsig).exists())) {
  55                 libjsig = jdk_path + "/lib/libjsig.dylib"; // jre location
  56             }
  57         } else {
  58             env_var = "LD_PRELOAD";
  59             libjsig = jdk_path + "/jre/lib/" + os_arch + "/libjsig.so"; // jdk location
  60             if (!(new File(libjsig).exists())) {
  61                 libjsig = jdk_path + "/lib/" + os_arch + "/libjsig.so"; // jre location
  62             }
  63         }
  64         // If this test fails, these might be useful to know.
  65         System.out.println("libjsig: " + libjsig);
  66         System.out.println("osArch: " + os_arch);
  67 
  68         // Make sure the libjsig file exists.
  69         if (!(new File(libjsig).exists())) {
  70             System.out.println("File " + libjsig + " not found, skipping");
  71             return;
  72         }
  73 
  74         ProcessBuilder pb = ProcessTools.createJavaProcessBuilder("-Xcheck:jni", "-version");
  75         Map<String, String> env = pb.environment();
  76         env.put(env_var, libjsig);
  77         OutputAnalyzer output = new OutputAnalyzer(pb.start());
  78         output.shouldNotContain("libjsig is activated");
  79         output.shouldHaveExitValue(0);
  80 
  81         pb = ProcessTools.createJavaProcessBuilder("-Xcheck:jni", "-verbose:jni", "-version");
  82         env = pb.environment();
  83         env.put(env_var, libjsig);
  84         output = new OutputAnalyzer(pb.start());
  85         output.shouldContain("libjsig is activated");
  86         output.shouldHaveExitValue(0);
  87     }
  88 }