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 
  65 # However JPRT runs: .../solaris_x64_5.10-debug/bin/java
  66 # ..which is 32-bit, when it has built the 64-bit version to test,
  67 # but we have TESTVMOPTS including at least -d64
  68 
  69 if [ ${OS} -eq "SunOS" ]
  70 then
  71   printf  "SunOS test TESTVMOPTS = ${TESTVMOPTS}"
  72   printf ${TESTVMOPTS} | grep d64 > /dev/null
  73   if [ $? -eq 0 ]
  74   then
  75     printf "SunOS x64 test, using -d64\n"
  76     BIT_FLAG=-d64
  77   fi
  78 fi
  79 
  80 ARCH=`uname -p`
  81 case $ARCH in
  82   i386)
  83     if [ X${BIT_FLAG} != "X" ]
  84     then
  85       ARCH=amd64
  86       JAVA=${TESTJAVA}${FS}bin${FS}${ARCH}${FS}java
  87     fi
  88     ;;
  89   sparc)
  90     if [ X${BIT_FLAG} != "X" ]
  91     then
  92       ARCH=sparcv9
  93       JAVA=${TESTJAVA}${FS}bin${FS}${ARCH}${FS}java
  94     fi
  95     ;;
  96   * )
  97     printf "Not testing architecture $ARCH, skipping test.\n"
  98     exit 0
  99   ;; 
 100 esac
 101 
 102 LIBJSIG=${TESTJAVA}${FS}jre${FS}lib${FS}${ARCH}${FS}libjsig.so
 103 
 104 # If libjsig and binary do not match, skip test.
 105 
 106 A=`file ${LIBJSIG} | awk '{ print $3 }'`
 107 B=`file ${JAVA}    | awk '{ print $3 }'`
 108 
 109 if [ $A -ne $B ]
 110 then
 111   printf "Mismatching binary and library to preload, skipping test.\n"
 112   exit 0
 113 fi
 114 
 115 if [ ! -f ${LIBJSIG} ]
 116 then
 117   printf "Skipping test: libjsig missing for given architecture: ${LIBJSIG}\n"
 118   exit 0
 119 fi
 120 # Use java -version to test, java version info appears on stderr,
 121 # the libjsig message we are removing appears on stdout.
 122 
 123 # grep returns zero meaning found, non-zero means not found:
 124 
 125 LD_PRELOAD=${LIBJSIG} ${JAVA} ${TESTVMOPTS} -Xcheck:jni -version 2>&1  | grep "libjsig is activated"
 126 if [ $? -eq 0 ]; then
 127   printf "Failed: -Xcheck:jni prints message when libjsig.so is loaded.\n"
 128   exit 1
 129 fi
 130 
 131 
 132 LD_PRELOAD=${LIBJSIG} ${JAVA} ${TESTVMOPTS} -Xcheck:jni -verbose:jni -version 2>&1 | grep "libjsig is activated"
 133 if [ $? != 0 ]; then
 134   printf "Failed: -Xcheck:jni does not print message when libjsig.so is loaded and -verbose:jni is set.\n"
 135   exit 1
 136 fi
 137 
 138 printf "PASSED\n"
 139 exit 0
 140