jdk/test/sun/management/jmxremote/bootstrap/LocalManagementTest.sh
author duke
Sat, 01 Dec 2007 00:00:00 +0000
changeset 2 90ce3da70b43
child 5506 202f599c92aa
permissions -rw-r--r--
Initial load
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
     1
#!/bin/sh
90ce3da70b43 Initial load
duke
parents:
diff changeset
     2
90ce3da70b43 Initial load
duke
parents:
diff changeset
     3
#
90ce3da70b43 Initial load
duke
parents:
diff changeset
     4
# Copyright 2004-2006 Sun Microsystems, Inc.  All Rights Reserved.
90ce3da70b43 Initial load
duke
parents:
diff changeset
     5
# DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
90ce3da70b43 Initial load
duke
parents:
diff changeset
     6
#
90ce3da70b43 Initial load
duke
parents:
diff changeset
     7
# This code is free software; you can redistribute it and/or modify it
90ce3da70b43 Initial load
duke
parents:
diff changeset
     8
# under the terms of the GNU General Public License version 2 only, as
90ce3da70b43 Initial load
duke
parents:
diff changeset
     9
# published by the Free Software Foundation.
90ce3da70b43 Initial load
duke
parents:
diff changeset
    10
#
90ce3da70b43 Initial load
duke
parents:
diff changeset
    11
# This code is distributed in the hope that it will be useful, but WITHOUT
90ce3da70b43 Initial load
duke
parents:
diff changeset
    12
# ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
90ce3da70b43 Initial load
duke
parents:
diff changeset
    13
# FITNESS FOR A PARTICULAR PURPOSE.  See the GNU General Public License
90ce3da70b43 Initial load
duke
parents:
diff changeset
    14
# version 2 for more details (a copy is included in the LICENSE file that
90ce3da70b43 Initial load
duke
parents:
diff changeset
    15
# accompanied this code).
90ce3da70b43 Initial load
duke
parents:
diff changeset
    16
#
90ce3da70b43 Initial load
duke
parents:
diff changeset
    17
# You should have received a copy of the GNU General Public License version
90ce3da70b43 Initial load
duke
parents:
diff changeset
    18
# 2 along with this work; if not, write to the Free Software Foundation,
90ce3da70b43 Initial load
duke
parents:
diff changeset
    19
# Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
90ce3da70b43 Initial load
duke
parents:
diff changeset
    20
#
90ce3da70b43 Initial load
duke
parents:
diff changeset
    21
# Please contact Sun Microsystems, Inc., 4150 Network Circle, Santa Clara,
90ce3da70b43 Initial load
duke
parents:
diff changeset
    22
# CA 95054 USA or visit www.sun.com if you need additional information or
90ce3da70b43 Initial load
duke
parents:
diff changeset
    23
# have any questions.
90ce3da70b43 Initial load
duke
parents:
diff changeset
    24
#
90ce3da70b43 Initial load
duke
parents:
diff changeset
    25
90ce3da70b43 Initial load
duke
parents:
diff changeset
    26
90ce3da70b43 Initial load
duke
parents:
diff changeset
    27
# @test
90ce3da70b43 Initial load
duke
parents:
diff changeset
    28
# @bug 5016507 6173612 6319776 6342019 6484550
90ce3da70b43 Initial load
duke
parents:
diff changeset
    29
# @summary Start a managed VM and test that a management tool can connect
90ce3da70b43 Initial load
duke
parents:
diff changeset
    30
#          without connection or username/password details.
90ce3da70b43 Initial load
duke
parents:
diff changeset
    31
#          TestManager will attempt a connection to the address obtained from 
90ce3da70b43 Initial load
duke
parents:
diff changeset
    32
#          both agent properties and jvmstat buffer.
90ce3da70b43 Initial load
duke
parents:
diff changeset
    33
#
90ce3da70b43 Initial load
duke
parents:
diff changeset
    34
# @build TestManager TestApplication
90ce3da70b43 Initial load
duke
parents:
diff changeset
    35
# @run shell/timeout=300 LocalManagementTest.sh
90ce3da70b43 Initial load
duke
parents:
diff changeset
    36
90ce3da70b43 Initial load
duke
parents:
diff changeset
    37
90ce3da70b43 Initial load
duke
parents:
diff changeset
    38
doTest()
90ce3da70b43 Initial load
duke
parents:
diff changeset
    39
{
90ce3da70b43 Initial load
duke
parents:
diff changeset
    40
    echo ''
90ce3da70b43 Initial load
duke
parents:
diff changeset
    41
90ce3da70b43 Initial load
duke
parents:
diff changeset
    42
    outputfile=${TESTCLASSES}/Test.out
90ce3da70b43 Initial load
duke
parents:
diff changeset
    43
    rm -f ${outputfile}
90ce3da70b43 Initial load
duke
parents:
diff changeset
    44
90ce3da70b43 Initial load
duke
parents:
diff changeset
    45
    # Start VM with given options
90ce3da70b43 Initial load
duke
parents:
diff changeset
    46
    echo "+ $JAVA $1 Test"
90ce3da70b43 Initial load
duke
parents:
diff changeset
    47
    $JAVA $1 TestApplication > ${outputfile}&
90ce3da70b43 Initial load
duke
parents:
diff changeset
    48
    pid=$!
90ce3da70b43 Initial load
duke
parents:
diff changeset
    49
 
90ce3da70b43 Initial load
duke
parents:
diff changeset
    50
    # Wait for managed VM to startup
90ce3da70b43 Initial load
duke
parents:
diff changeset
    51
    echo "Waiting for VM to startup..."
90ce3da70b43 Initial load
duke
parents:
diff changeset
    52
    attempts=0
90ce3da70b43 Initial load
duke
parents:
diff changeset
    53
    while true; do
90ce3da70b43 Initial load
duke
parents:
diff changeset
    54
        sleep 1
90ce3da70b43 Initial load
duke
parents:
diff changeset
    55
  	port=`tail -1 ${outputfile}`
90ce3da70b43 Initial load
duke
parents:
diff changeset
    56
  	if [ ! -z "$port" ]; then
90ce3da70b43 Initial load
duke
parents:
diff changeset
    57
     	    # In case of errors wait time for output to be flushed
90ce3da70b43 Initial load
duke
parents:
diff changeset
    58
     	    sleep 1
90ce3da70b43 Initial load
duke
parents:
diff changeset
    59
     	    cat ${outputfile}
90ce3da70b43 Initial load
duke
parents:
diff changeset
    60
     	    break
90ce3da70b43 Initial load
duke
parents:
diff changeset
    61
	fi
90ce3da70b43 Initial load
duke
parents:
diff changeset
    62
      attempts=`expr $attempts + 1`
90ce3da70b43 Initial load
duke
parents:
diff changeset
    63
      echo "Waiting $attempts second(s) ..."
90ce3da70b43 Initial load
duke
parents:
diff changeset
    64
    done
90ce3da70b43 Initial load
duke
parents:
diff changeset
    65
90ce3da70b43 Initial load
duke
parents:
diff changeset
    66
    # Start the manager - this should connect to VM
90ce3da70b43 Initial load
duke
parents:
diff changeset
    67
    sh -xc "$JAVA -classpath ${TESTCLASSES}:${TESTJAVA}/lib/tools.jar \
90ce3da70b43 Initial load
duke
parents:
diff changeset
    68
        TestManager $pid $port"  2>&1
90ce3da70b43 Initial load
duke
parents:
diff changeset
    69
    if [ $? != 0 ]; then failures=`expr $failures + 1`; fi
90ce3da70b43 Initial load
duke
parents:
diff changeset
    70
}
90ce3da70b43 Initial load
duke
parents:
diff changeset
    71
90ce3da70b43 Initial load
duke
parents:
diff changeset
    72
90ce3da70b43 Initial load
duke
parents:
diff changeset
    73
# Check we are run from jtreg
90ce3da70b43 Initial load
duke
parents:
diff changeset
    74
if [ -z "${TESTCLASSES}" ]; then
90ce3da70b43 Initial load
duke
parents:
diff changeset
    75
    echo "Test is designed to be run from jtreg only"
90ce3da70b43 Initial load
duke
parents:
diff changeset
    76
    exit 0
90ce3da70b43 Initial load
duke
parents:
diff changeset
    77
fi
90ce3da70b43 Initial load
duke
parents:
diff changeset
    78
90ce3da70b43 Initial load
duke
parents:
diff changeset
    79
# For now this test passes silently on Windows - there are 2 reasons
90ce3da70b43 Initial load
duke
parents:
diff changeset
    80
# to skip it :-
90ce3da70b43 Initial load
duke
parents:
diff changeset
    81
#
90ce3da70b43 Initial load
duke
parents:
diff changeset
    82
# 1. No jstat instrumentation buffers if FAT32 so need
90ce3da70b43 Initial load
duke
parents:
diff changeset
    83
#    -XX:+PerfBypassFileSystemCheck 
90ce3da70b43 Initial load
duke
parents:
diff changeset
    84
# 2. $! is used to get the pid of the created process but it's not
90ce3da70b43 Initial load
duke
parents:
diff changeset
    85
#    reliable on older versions of MKS. Also negative pids are returned
90ce3da70b43 Initial load
duke
parents:
diff changeset
    86
#    on Windows 98.
90ce3da70b43 Initial load
duke
parents:
diff changeset
    87
90ce3da70b43 Initial load
duke
parents:
diff changeset
    88
os=`uname -s`
90ce3da70b43 Initial load
duke
parents:
diff changeset
    89
if [ "$os" != "Linux" -a "$os" != "SunOS" ]; then
90ce3da70b43 Initial load
duke
parents:
diff changeset
    90
    echo "Test not designed to run on this operating system, skipping..."
90ce3da70b43 Initial load
duke
parents:
diff changeset
    91
    exit 0
90ce3da70b43 Initial load
duke
parents:
diff changeset
    92
fi
90ce3da70b43 Initial load
duke
parents:
diff changeset
    93
90ce3da70b43 Initial load
duke
parents:
diff changeset
    94
JAVA=${TESTJAVA}/bin/java
90ce3da70b43 Initial load
duke
parents:
diff changeset
    95
CLASSPATH=${TESTCLASSES}
90ce3da70b43 Initial load
duke
parents:
diff changeset
    96
export CLASSPATH
90ce3da70b43 Initial load
duke
parents:
diff changeset
    97
90ce3da70b43 Initial load
duke
parents:
diff changeset
    98
failures=0
90ce3da70b43 Initial load
duke
parents:
diff changeset
    99
90ce3da70b43 Initial load
duke
parents:
diff changeset
   100
# Test 1 
90ce3da70b43 Initial load
duke
parents:
diff changeset
   101
doTest "-Dcom.sun.management.jmxremote" 
90ce3da70b43 Initial load
duke
parents:
diff changeset
   102
90ce3da70b43 Initial load
duke
parents:
diff changeset
   103
# Test 2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   104
AGENT="${TESTJAVA}/jre/lib/management-agent.jar"
90ce3da70b43 Initial load
duke
parents:
diff changeset
   105
if [ ! -f ${AGENT} ]; then
90ce3da70b43 Initial load
duke
parents:
diff changeset
   106
  AGENT="${TESTJAVA}/lib/management-agent.jar"
90ce3da70b43 Initial load
duke
parents:
diff changeset
   107
fi
90ce3da70b43 Initial load
duke
parents:
diff changeset
   108
doTest "-javaagent:${AGENT}" 
90ce3da70b43 Initial load
duke
parents:
diff changeset
   109
90ce3da70b43 Initial load
duke
parents:
diff changeset
   110
# Test 3 - no args (blank) - manager should attach and start agent
90ce3da70b43 Initial load
duke
parents:
diff changeset
   111
doTest " " 
90ce3da70b43 Initial load
duke
parents:
diff changeset
   112
90ce3da70b43 Initial load
duke
parents:
diff changeset
   113
# Test 4 - sanity check arguments to management-agent.jar
90ce3da70b43 Initial load
duke
parents:
diff changeset
   114
echo ' '
90ce3da70b43 Initial load
duke
parents:
diff changeset
   115
sh -xc "${JAVA} -javaagent:${AGENT}=com.sun.management.jmxremote.port=7775,\
90ce3da70b43 Initial load
duke
parents:
diff changeset
   116
com.sun.management.jmxremote.authenticate=false,com.sun.management.jmxremote.ssl=false \
90ce3da70b43 Initial load
duke
parents:
diff changeset
   117
  TestApplication -exit" 2>&1
90ce3da70b43 Initial load
duke
parents:
diff changeset
   118
if [ $? != 0 ]; then failures=`expr $failures + 1`; fi
90ce3da70b43 Initial load
duke
parents:
diff changeset
   119
90ce3da70b43 Initial load
duke
parents:
diff changeset
   120
# Test 5 - use DNS-only name service
90ce3da70b43 Initial load
duke
parents:
diff changeset
   121
doTest "-Dsun.net.spi.namservice.provider.1=\"dns,sun\"" 
90ce3da70b43 Initial load
duke
parents:
diff changeset
   122
90ce3da70b43 Initial load
duke
parents:
diff changeset
   123
#
90ce3da70b43 Initial load
duke
parents:
diff changeset
   124
# Results
90ce3da70b43 Initial load
duke
parents:
diff changeset
   125
#
90ce3da70b43 Initial load
duke
parents:
diff changeset
   126
echo ''
90ce3da70b43 Initial load
duke
parents:
diff changeset
   127
if [ $failures -gt 0 ];
90ce3da70b43 Initial load
duke
parents:
diff changeset
   128
  then echo "$failures test(s) failed";
90ce3da70b43 Initial load
duke
parents:
diff changeset
   129
  else echo "All test(s) passed"; fi
90ce3da70b43 Initial load
duke
parents:
diff changeset
   130
exit $failures
90ce3da70b43 Initial load
duke
parents:
diff changeset
   131