jdk/test/sun/management/jmxremote/bootstrap/CustomLauncherTest.sh
changeset 21507 624a61211dd7
parent 21506 115e1128ce1a
parent 21474 4d9ae2ec8ba6
child 21508 3dd9732b1703
equal deleted inserted replaced
21506:115e1128ce1a 21507:624a61211dd7
     1 #!/bin/sh
       
     2 
       
     3 #
       
     4 # Copyright (c) 2006, Oracle and/or its affiliates. All rights reserved.
       
     5 # DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
       
     6 #
       
     7 # This code is free software; you can redistribute it and/or modify it
       
     8 # under the terms of the GNU General Public License version 2 only, as
       
     9 # published by the Free Software Foundation.
       
    10 #
       
    11 # This code is distributed in the hope that it will be useful, but WITHOUT
       
    12 # ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
       
    13 # FITNESS FOR A PARTICULAR PURPOSE.  See the GNU General Public License
       
    14 # version 2 for more details (a copy is included in the LICENSE file that
       
    15 # accompanied this code).
       
    16 #
       
    17 # You should have received a copy of the GNU General Public License version
       
    18 # 2 along with this work; if not, write to the Free Software Foundation,
       
    19 # Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
       
    20 #
       
    21 # Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
       
    22 # or visit www.oracle.com if you need additional information or have any
       
    23 # questions.
       
    24 #
       
    25 
       
    26 
       
    27 # @test
       
    28 # @bug 6434402
       
    29 # @summary Start an application using a custom launcher and check that
       
    30 #          a management tool can connect.
       
    31 #
       
    32 # @build TestManager TestApplication
       
    33 # @run shell CustomLauncherTest.sh
       
    34 
       
    35 #
       
    36 # Check we are run from jtreg
       
    37 #
       
    38 if [ -z "${TESTCLASSES}" ]; then
       
    39     echo "Test is designed to be run from jtreg only"
       
    40     exit 0
       
    41 fi
       
    42 
       
    43 #
       
    44 # For now this test passes silently on Windows - this means the test only
       
    45 # has to locate libjvm.so. Also $! is not reliable on some releases of MKS.
       
    46 #{
       
    47 OS=`uname -s`
       
    48 if [ "$OS" != "Linux" -a "$OS" != "SunOS" ]; then
       
    49     echo "Test not designed to run on this operating system, skipping..."
       
    50     exit 0
       
    51 fi
       
    52 
       
    53 #
       
    54 # Locate the custom launcher for this platform
       
    55 #
       
    56 PLATFORM=unknown
       
    57 ARCH=unknown
       
    58 if [ "$OS" = "SunOS" ]; then
       
    59     PLATFORM=solaris
       
    60     case "`uname -p`" in
       
    61 	i[3-9]86)
       
    62 	    ARCH=i586
       
    63 	    ;;
       
    64 	sparc)
       
    65 	    ARCH=sparc
       
    66 	    ;;
       
    67     esac
       
    68 else
       
    69     PLATFORM=linux
       
    70     case "`uname -m`" in
       
    71 	i[3-6]86)
       
    72 	    ARCH=i586
       
    73 	    ;;
       
    74 	x86_64)
       
    75 	    ARCH=amd64
       
    76 	    ;;
       
    77     esac
       
    78 fi
       
    79 
       
    80 
       
    81 #
       
    82 # On x86 the native libraries are in lib/i386 for
       
    83 # compatability reasons
       
    84 #
       
    85 if [ "$ARCH" = "i586" ]; then
       
    86     LIBARCH="i386"
       
    87 else
       
    88     LIBARCH=$ARCH
       
    89 fi
       
    90 
       
    91 
       
    92 #
       
    93 # Check that a custom launcher exists for this platform
       
    94 #
       
    95 LAUNCHER="${TESTSRC}/${PLATFORM}-${ARCH}/launcher"
       
    96 if [ ! -x "${LAUNCHER}" ]; then
       
    97     echo "${LAUNCHER} not found"
       
    98     exit 0
       
    99 fi
       
   100 
       
   101 # 
       
   102 # Locate the libjvm.so library 
       
   103 #
       
   104 JVMLIB="${TESTJAVA}/jre/lib/${LIBARCH}/client/libjvm.so"
       
   105 if [ ! -f "${JVMLIB}" ]; then
       
   106     JVMLIB="${TESTJAVA}/jre/lib/${LIBARCH}/server/libjvm.so"
       
   107     if [ ! -f "${JVMLIB}" ]; then
       
   108 	JVMLIB="${TESTJAVA}/lib/${LIBARCH}/client/libjvm.so"
       
   109 	if [ ! -f "${JVMLIB}" ]; then
       
   110 	    JVMLIB="${TESTJAVA}/lib/${LIBARCH}/serevr/libjvm.so"
       
   111 	    if [ ! -f "${JVMLIB}" ]; then
       
   112 		echo "Unable to locate libjvm.so in ${TESTJAVA}"
       
   113 		exit 1
       
   114 	    fi
       
   115 	fi
       
   116     fi
       
   117 fi
       
   118 
       
   119 #
       
   120 # Start the VM
       
   121 #
       
   122 outputfile=${TESTCLASSES}/Test.out
       
   123 rm -f ${outputfile}
       
   124 
       
   125 echo ''
       
   126 echo "Starting custom launcher..."
       
   127 echo " launcher: ${LAUNCHER}"
       
   128 echo "   libjvm: ${JVMLIB}"
       
   129 echo "classpath: ${TESTCLASSES}"
       
   130 
       
   131 
       
   132 ${LAUNCHER} ${JVMLIB} ${TESTCLASSES} TestApplication > ${outputfile} &
       
   133 pid=$!
       
   134 
       
   135 # Wait for managed VM to startup (although this looks like a potentially
       
   136 # infinate loop, the framework will eventually kill it)
       
   137 echo "Waiting for TestAppication to test..."
       
   138 attempts=0
       
   139 while true; do
       
   140     sleep 1
       
   141     port=`tail -1 ${outputfile}`
       
   142     if [ ! -z "$port" ]; then
       
   143 	# In case of errors wait time for output to be flushed
       
   144 	sleep 1
       
   145 	cat ${outputfile}
       
   146 	break
       
   147     fi
       
   148     attempts=`expr $attempts + 1`
       
   149     echo "Waiting $attempts second(s) ..."
       
   150 done
       
   151 
       
   152 # Start the manager - this should connect to VM
       
   153 ${TESTJAVA}/bin/java ${TESTVMOPTS} -classpath ${TESTCLASSES}:${TESTJAVA}/lib/tools.jar \
       
   154   TestManager $pid $port true
       
   155 if [ $? != 0 ]; then 
       
   156     echo "Test failed"
       
   157     exit 1
       
   158 fi
       
   159 exit 0