1 # 
   2 #  Copyright (c) 2011, 2012, 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 Xchecksig.sh
  26 # @bug 7051189
  27 # @summary Need to suppress info message if -xcheck:jni used with libjsig.so
  28 # @run shell Xchecksig.sh
  29 #
  30 
  31 if [ "${TESTSRC}" = "" ]
  32   then TESTSRC=.
  33 fi
  34 
  35 if [ "${TESTJAVA}" = "" ]
  36 then
  37   PARENT=`dirname \`which java\``
  38   TESTJAVA=`dirname ${PARENT}`
  39   printf "TESTJAVA not set, selecting " ${TESTJAVA}
  40   printf "  If this is incorrect, try setting the variable manually.\n"
  41 fi
  42 
  43 
  44 OS=`uname -s`
  45 case "$OS" in
  46   SunOS | Linux )
  47     FS="/"
  48     ;;
  49   Windows_* )
  50     printf "Not testing libjsig.so on Windows. PASSED.\n "
  51     exit 0
  52     ;;
  53   * )
  54     printf "Not testing libjsig.so on unrecognised system. PASSED.\n "
  55     exit 0
  56     ;;
  57 esac
  58 
  59 
  60 JAVA=${TESTJAVA}${FS}bin${FS}java
  61 
  62 # LD_PRELOAD arch needs to match the binary we run, so run the java
  63 # 64-bit binary directly if we are testing 64-bit (bin/ARCH/java).
  64 # Check if TESTVMOPS contains -d64, but cannot use 
  65 # java ${TESTVMOPS} to run "java -d64"  with LD_PRELOAD.
  66 
  67 if [ ${OS} -eq "SunOS" ]
  68 then
  69   printf  "SunOS test TESTVMOPTS = ${TESTVMOPTS}"
  70   printf ${TESTVMOPTS} | grep d64 > /dev/null
  71   if [ $? -eq 0 ]
  72   then
  73     printf "SunOS 64-bit test\n"
  74     BIT_FLAG=-d64
  75   fi
  76 fi
  77 
  78 ARCH=`uname -p`
  79 case $ARCH in
  80   i386)
  81     if [ X${BIT_FLAG} != "X" ]
  82     then
  83       ARCH=amd64
  84       JAVA=${TESTJAVA}${FS}bin${FS}${ARCH}${FS}java
  85     fi
  86     ;;
  87   sparc)
  88     if [ X${BIT_FLAG} != "X" ]
  89     then
  90       ARCH=sparcv9
  91       JAVA=${TESTJAVA}${FS}bin${FS}${ARCH}${FS}java
  92     fi
  93     ;;
  94   * )
  95     printf "Not testing architecture $ARCH, skipping test.\n"
  96     exit 0
  97   ;; 
  98 esac
  99 
 100 LIBJSIG=${TESTJAVA}${FS}jre${FS}lib${FS}${ARCH}${FS}libjsig.so
 101 
 102 # If libjsig and binary do not match, skip test.
 103 
 104 A=`file ${LIBJSIG} | awk '{ print $3 }'`
 105 B=`file ${JAVA}    | awk '{ print $3 }'`
 106 
 107 if [ $A -ne $B ]
 108 then
 109   printf "Mismatching binary and library to preload, skipping test.\n"
 110   exit 0
 111 fi
 112 
 113 if [ ! -f ${LIBJSIG} ]
 114 then
 115   printf "Skipping test: libjsig missing for given architecture: ${LIBJSIG}\n"
 116   exit 0
 117 fi
 118 # Use java -version to test, java version info appears on stderr,
 119 # the libjsig message we are removing appears on stdout.
 120 
 121 # grep returns zero meaning found, non-zero means not found:
 122 
 123 LD_PRELOAD=${LIBJSIG} ${JAVA} ${TESTVMOPTS} -Xcheck:jni -version 2>&1  | grep "libjsig is activated"
 124 if [ $? -eq 0 ]; then
 125   printf "Failed: -Xcheck:jni prints message when libjsig.so is loaded.\n"
 126   exit 1
 127 fi
 128 
 129 
 130 LD_PRELOAD=${LIBJSIG} ${JAVA} ${TESTVMOPTS} -Xcheck:jni -verbose:jni -version 2>&1 | grep "libjsig is activated"
 131 if [ $? != 0 ]; then
 132   printf "Failed: -Xcheck:jni does not print message when libjsig.so is loaded and -verbose:jni is set.\n"
 133   exit 1
 134 fi
 135 
 136 printf "PASSED\n"
 137 exit 0
 138