0N/A#!/bin/sh
0N/A
0N/A#
2362N/A# Copyright (c) 2006, 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# @test
0N/A# @bug 6434402
0N/A# @summary Start an application using a custom launcher and check that
0N/A# a management tool can connect.
0N/A#
0N/A# @build TestManager TestApplication
0N/A# @run shell CustomLauncherTest.sh
0N/A
0N/A#
0N/A# Check we are run from jtreg
0N/A#
0N/Aif [ -z "${TESTCLASSES}" ]; then
0N/A echo "Test is designed to be run from jtreg only"
0N/A exit 0
0N/Afi
0N/A
0N/A#
0N/A# For now this test passes silently on Windows - this means the test only
0N/A# has to locate libjvm.so. Also $! is not reliable on some releases of MKS.
0N/A#{
0N/AOS=`uname -s`
0N/Aif [ "$OS" != "Linux" -a "$OS" != "SunOS" ]; then
0N/A echo "Test not designed to run on this operating system, skipping..."
0N/A exit 0
0N/Afi
0N/A
0N/A#
0N/A# Locate the custom launcher for this platform
0N/A#
0N/APLATFORM=unknown
0N/AARCH=unknown
0N/Aif [ "$OS" = "SunOS" ]; then
0N/A PLATFORM=solaris
0N/A case "`uname -p`" in
0N/A i[3-9]86)
0N/A ARCH=i586
0N/A ;;
0N/A sparc)
0N/A ARCH=sparc
0N/A ;;
0N/A esac
0N/Aelse
0N/A PLATFORM=linux
0N/A case "`uname -m`" in
0N/A i[3-6]86)
0N/A ARCH=i586
0N/A ;;
0N/A x86_64)
0N/A ARCH=amd64
0N/A ;;
0N/A esac
0N/Afi
0N/A
0N/A
0N/A#
0N/A# On x86 the native libraries are in lib/i386 for
0N/A# compatability reasons
0N/A#
0N/Aif [ "$ARCH" = "i586" ]; then
0N/A LIBARCH="i386"
0N/Aelse
0N/A LIBARCH=$ARCH
0N/Afi
0N/A
0N/A
0N/A#
0N/A# Check that a custom launcher exists for this platform
0N/A#
0N/ALAUNCHER="${TESTSRC}/${PLATFORM}-${ARCH}/launcher"
0N/Aif [ ! -x "${LAUNCHER}" ]; then
0N/A echo "${LAUNCHER} not found"
0N/A exit 0
0N/Afi
0N/A
0N/A#
0N/A# Locate the libjvm.so library
0N/A#
0N/AJVMLIB="${TESTJAVA}/jre/lib/${LIBARCH}/client/libjvm.so"
0N/Aif [ ! -f "${JVMLIB}" ]; then
0N/A JVMLIB="${TESTJAVA}/jre/lib/${LIBARCH}/server/libjvm.so"
0N/A if [ ! -f "${JVMLIB}" ]; then
0N/A JVMLIB="${TESTJAVA}/lib/${LIBARCH}/client/libjvm.so"
0N/A if [ ! -f "${JVMLIB}" ]; then
0N/A JVMLIB="${TESTJAVA}/lib/${LIBARCH}/serevr/libjvm.so"
0N/A if [ ! -f "${JVMLIB}" ]; then
0N/A echo "Unable to locate libjvm.so in ${TESTJAVA}"
0N/A exit 1
0N/A fi
0N/A fi
0N/A fi
0N/Afi
0N/A
0N/A#
0N/A# Start the VM
0N/A#
0N/Aoutputfile=${TESTCLASSES}/Test.out
0N/Arm -f ${outputfile}
0N/A
0N/Aecho ''
0N/Aecho "Starting custom launcher..."
0N/Aecho " launcher: ${LAUNCHER}"
0N/Aecho " libjvm: ${JVMLIB}"
0N/Aecho "classpath: ${TESTCLASSES}"
0N/A
0N/A
0N/A${LAUNCHER} ${JVMLIB} ${TESTCLASSES} TestApplication > ${outputfile} &
0N/Apid=$!
0N/A
0N/A# Wait for managed VM to startup (although this looks like a potentially
0N/A# infinate loop, the framework will eventually kill it)
0N/Aecho "Waiting for TestAppication to test..."
0N/Aattempts=0
0N/Awhile true; do
0N/A sleep 1
0N/A port=`tail -1 ${outputfile}`
0N/A if [ ! -z "$port" ]; then
0N/A # In case of errors wait time for output to be flushed
0N/A sleep 1
0N/A cat ${outputfile}
0N/A break
0N/A fi
0N/A attempts=`expr $attempts + 1`
0N/A echo "Waiting $attempts second(s) ..."
0N/Adone
0N/A
0N/A# Start the manager - this should connect to VM
0N/A${TESTJAVA}/bin/java -classpath ${TESTCLASSES}:${TESTJAVA}/lib/tools.jar \
0N/A TestManager $pid $port true
0N/Aif [ $? != 0 ]; then
0N/A echo "Test failed"
0N/A exit 1
0N/Afi
0N/Aexit 0