0N/A#
3261N/A# Copyright (c) 2004, 2010, Oracle and/or its affiliates. All rights reserved.
0N/A# DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
0N/A#
0N/A# This code is free software; you can redistribute it and/or modify it
0N/A# under the terms of the GNU General Public License version 2 only, as
0N/A# published by the Free Software Foundation.
0N/A#
0N/A# This code is distributed in the hope that it will be useful, but WITHOUT
0N/A# ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
0N/A# FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
0N/A# version 2 for more details (a copy is included in the LICENSE file that
0N/A# accompanied this code).
0N/A#
0N/A# You should have received a copy of the GNU General Public License version
0N/A# 2 along with this work; if not, write to the Free Software Foundation,
0N/A# Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
0N/A#
2362N/A# Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
2362N/A# or visit www.oracle.com if you need additional information or have any
2362N/A# questions.
0N/A#
0N/A
0N/A#
0N/A
0N/Asetup() {
0N/A # Verify directory context variables are set
0N/A if [ "${TESTJAVA}" = "" ] ; then
0N/A echo "TESTJAVA not set. Test cannot execute. Failed."
0N/A exit 1
0N/A fi
0N/A
0N/A if [ "${TESTCLASSES}" = "" ] ; then
0N/A TESTCLASSES="."
0N/A fi
0N/A
0N/A if [ "${TESTSRC}" = "" ] ; then
0N/A TESTSRC="."
0N/A fi
0N/A
0N/A OS=`uname -s`
0N/A case ${OS} in
2078N/A Windows_* | CYGWIN*)
0N/A PS=";"
0N/A FS="\\"
0N/A ;;
0N/A *)
0N/A PS=":"
0N/A FS="/"
0N/A ;;
0N/A esac
0N/A}
0N/A
0N/Averify_os() {
0N/A OS=`uname -s`
0N/A case ${OS} in
2078N/A Windows_95 | Windows_98 | Windows_ME | CYGWIN* )
0N/A echo "Test bypassed: jvmstat feature not supported on ${OS}"
0N/A exit 0
0N/A ;;
0N/A Windows_*)
0N/A # verify that the tmp directory supports persistent ACLs, which
0N/A # are required for jvmstat to enable its shared memory feature.
0N/A # NOTE: FAT type files systems do not support ACLs, but NTFS files
0N/A # systems do.
0N/A #
0N/A echo "temp directory is in: `windir -t`"
0N/A TMPDRIVE=`windir -t | cut -d: -f1`
0N/A if [ "${TMPDRIVE}" = "" ] ; then
0N/A echo "Could not get temp directory drive letter"
0N/A exit 1
0N/A fi
0N/A
0N/A echo "temp file system characteristics:"
0N/A sysinf drives -a | grep "^${TMPDRIVE}"
0N/A sysinf drives -a | grep "^${TMPDRIVE}" | grep PERSISTENT_ACLS > /dev/null
0N/A case $? in
0N/A 0)
0N/A ;;
0N/A 1)
0N/A echo "Test bypassed: jvmstat feature disabled because the temp"
0N/A echo "directory doesn't support persistent ACLs"
0N/A exit 0
0N/A ;;
0N/A 2)
0N/A echo "Could not get temp directory file system features"
0N/A exit 1
0N/A ;;
0N/A *)
0N/A echo "Unexpected return code from grep - $?"
0N/A exit 1
0N/A ;;
0N/A esac
0N/A ;;
0N/A esac
0N/A}
0N/A
0N/A# function to kill the process with the given process id
0N/Akill_proc() {
0N/A kill_pid=$1
0N/A
0N/A if [ "${kill_pid}" = "" ]
0N/A then
0N/A echo "kill_proc(): null pid: ignored"
0N/A return
0N/A fi
0N/A
0N/A if [ ${kill_pid} -le 0 ]
0N/A then
0N/A echo "kill_proc(): invalid pid: ${kill_pid}: ignored"
0N/A return
0N/A fi
0N/A
0N/A OS=`uname -s`
0N/A case $OS in
0N/A Windows_*)
0N/A case ${SHELL_VERSION} in
0N/A [1234567].* | 8.[12345].*)
0N/A # when starting processes in the background, mks creates an
0N/A # intervening between the parent process and the background
0N/A # process. The pid acquired for background process as acquired
0N/A # by the $! shell variable is actually the pid of the invervening
0N/A # shell and not that of the background process. Sending a specific
0N/A # signal to the intervening shell will only effects the intervening
0N/A # shell and not the background process, thus leaving the background
0N/A # process running. The following code assumes that the pid passed
0N/A # into this function as ${kill_pid}, was acquired by $!. Therefore,
0N/A # in order to kill the background process, we must first find the
0N/A # children of ${kill_pid} (should be only one child) and kill them.
0N/A
0N/A ps -o pid,ppid | grep "${kill_pid}$"
0N/A children=`mks_children ${kill_pid}`
0N/A echo "killing children of ${kill_pid}: ${children}"
0N/A for child in ${children} ; do
0N/A kill_proc_common ${child}
0N/A done
0N/A ;;
0N/A *)
0N/A # in mks 8.6 and later, the pid returned in $! is now the pid
0N/A # of the background process and not that of the intervening shell.
0N/A kill_proc_common ${kill_pid}
0N/A ;;
0N/A esac
0N/A ;;
0N/A *)
0N/A kill_proc_common ${kill_pid}
0N/A ;;
0N/A esac
0N/A}
0N/A
0N/Amks_children() {
0N/A ppid=$1
0N/A ps -o pid,ppid | grep "${ppid}$" | awk '
0N/ABEGIN { pids="" }
0N/A { pids = pids $1 " " }
0N/AEND { print pids }'
0N/A}
0N/A
0N/Akill_proc_common() {
0N/A kpid=$1
0N/A
0N/A # verify that the process exists and we can signal it
0N/A kill -0 ${kpid} 2>/dev/null
0N/A if [ $? -ne 0 ]
0N/A then
0N/A echo "Could not signal >${kpid}<"
0N/A echo "user id = `id`"
0N/A echo "process information :"
0N/A ps -l -p ${kpid}
0N/A return
0N/A fi
0N/A
0N/A kill -TERM ${kpid} # hit it easy first
0N/A if [ $? -eq 0 ]
0N/A then
0N/A sleep 2
0N/A kill -0 ${kpid} 2>/dev/null
0N/A # check if it's still hanging around
0N/A if [ $? -eq 0 ]
0N/A then
0N/A # it's still lingering, now it it hard
0N/A kill -KILL ${kpid} 2>/dev/null
0N/A if [ $? -ne 0 ]
0N/A then
0N/A echo "Could not kill ${kpid}!"
0N/A fi
0N/A fi
0N/A else
0N/A echo "Error sending term signal to ${kpid}!"
0N/A fi
0N/A}
2500N/A
2500N/A# check to see if a port is free
2500N/AcheckPort() # port
2500N/A{
2500N/A inuse=`netstat -a | egrep "\.$1"`
2500N/A if [ "${inuse}" = "" ] ; then
2500N/A echo "free"
2500N/A else
2500N/A echo "inuse"
2500N/A fi
2500N/A}
2500N/A
2500N/A# Get a free port, where port+1 is also free, return 0 when giving up
2500N/AfreePort()
2500N/A{
2500N/A start=3000
2500N/A while [ ${start} -lt 3030 ] ; do
2500N/A port1=`expr ${start} '+' $$ '%' 1000`
2500N/A port2=`expr ${port1} '+' 1`
2500N/A if [ "`checkPort ${port1}`" = "inuse" \
2500N/A -o "`checkPort ${port2}`" = "inuse" ] ; then
2500N/A start=`expr ${start} '+' 1`
2500N/A else
2500N/A break
2500N/A fi
2500N/A done
2500N/A if [ "`checkPort ${port1}`" = "inuse" \
2500N/A -o "`checkPort ${port2}`" = "inuse" ] ; then
2500N/A port1="0"
2500N/A fi
2500N/A echo "${port1}"
2500N/A}
2500N/A
2500N/A