blob: a7ced06fc3eba1f5a92f6e9a057c879763008e80 [file] [log] [blame]
J. Duke319a3b92007-12-01 00:00:00 +00001#!/bin/sh
2
3#
4# Copyright 2006 Sun Microsystems, Inc. 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 Sun Microsystems, Inc., 4150 Network Circle, Santa Clara,
22# CA 95054 USA or visit www.sun.com if you need additional information or
23# have any 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#
38if [ -z "${TESTCLASSES}" ]; then
39 echo "Test is designed to be run from jtreg only"
40 exit 0
41fi
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#{
47OS=`uname -s`
48if [ "$OS" != "Linux" -a "$OS" != "SunOS" ]; then
49 echo "Test not designed to run on this operating system, skipping..."
50 exit 0
51fi
52
53#
54# Locate the custom launcher for this platform
55#
56PLATFORM=unknown
57ARCH=unknown
58if [ "$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
68else
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
78fi
79
80
81#
82# On x86 the native libraries are in lib/i386 for
83# compatability reasons
84#
85if [ "$ARCH" = "i586" ]; then
86 LIBARCH="i386"
87else
88 LIBARCH=$ARCH
89fi
90
91
92#
93# Check that a custom launcher exists for this platform
94#
95LAUNCHER="${TESTSRC}/${PLATFORM}-${ARCH}/launcher"
96if [ ! -x "${LAUNCHER}" ]; then
97 echo "${LAUNCHER} not found"
98 exit 0
99fi
100
101#
102# Locate the libjvm.so library
103#
104JVMLIB="${TESTJAVA}/jre/lib/${LIBARCH}/client/libjvm.so"
105if [ ! -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
117fi
118
119#
120# Start the VM
121#
122outputfile=${TESTCLASSES}/Test.out
123rm -f ${outputfile}
124
125echo ''
126echo "Starting custom launcher..."
127echo " launcher: ${LAUNCHER}"
128echo " libjvm: ${JVMLIB}"
129echo "classpath: ${TESTCLASSES}"
130
131
132${LAUNCHER} ${JVMLIB} ${TESTCLASSES} TestApplication > ${outputfile} &
133pid=$!
134
135# Wait for managed VM to startup (although this looks like a potentially
136# infinate loop, the framework will eventually kill it)
137echo "Waiting for TestAppication to test..."
138attempts=0
139while 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) ..."
150done
151
152# Start the manager - this should connect to VM
153${TESTJAVA}/bin/java -classpath ${TESTCLASSES}:${TESTJAVA}/lib/tools.jar \
154 TestManager $pid $port true
155if [ $? != 0 ]; then
156 echo "Test failed"
157 exit 1
158fi
159exit 0