blob: 38ce59fc240e5e1a87a7b2ee1d6acc8287119c4c [file] [log] [blame]
J. Duke319a3b92007-12-01 00:00:00 +00001#!/bin/sh
2
3#
4# Copyright 2005-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 4527279
29# @summary Unit test for ProcessAttachingConnector
30#
31# @build ProcessAttachDebugger ProcessAttachDebuggee ShutdownDebuggee
32# @run shell ProcessAttachTest.sh
33
34if [ "${TESTJAVA}" = "" ]
35then
36 echo "TESTJAVA not set. Test cannot execute. Failed."
37 exit 1
38fi
39
40if [ "${TESTSRC}" = "" ]
41then
42 echo "TESTSRC not set. Test cannot execute. Failed."
43 exit 1
44fi
45
46if [ "${TESTCLASSES}" = "" ]
47then
48 echo "TESTCLASSES not set. Test cannot execute. Failed."
49 exit 1
50fi
51
52JAVA="${TESTJAVA}/bin/java"
53
54OS=`uname -s`
55
56case "$OS" in
57 Windows* | CYGWIN_NT*)
58 PS=";"
59 OS="Windows"
60 ;;
61 * )
62 PS=":"
63 ;;
64esac
65
66startDebuggee()
67{
68 OUTPUTFILE=${TESTCLASSES}/Debuggee.out
69 ${JAVA} "$@" > ${OUTPUTFILE} &
70 pid="$!"
71
72 # MKS creates an intermediate shell to launch ${JAVA} so
73 # ${pid} is not the actual pid. We have put in a small sleep
74 # to give the intermediate shell process time to launch the
75 # "java" process.
76 if [ "$OS" = "Windows" ]; then
77 sleep 2
78 realpid=`ps -o pid,ppid,comm|grep ${pid}|grep "java"|cut -c1-6`
79 pid=${realpid}
80 fi
81
82 echo "Waiting for Debuggee to initialize..."
83 attempts=0
84 while true; do
85 sleep 1
86 out=`tail -1 ${OUTPUTFILE}`
87 if [ ! -z "$out" ]; then
88 break
89 fi
90 attempts=`expr $attempts + 1`
91 echo "Waiting $attempts second(s) ..."
92 done
93
94 echo "Debuggee is process $pid"
95}
96
97stopDebuggee()
98{
99 $JAVA -classpath "${TESTCLASSES}" ShutdownDebuggee $1
100 if [ $? != 0 ] ; then
101 echo "Error: ShutdownDebuggee failed"
102 failures=`expr $failures + 1`
103 kill -9 $pid
104 fi
105}
106
107failures=0
108
109#########################################################
110echo "Test 1: Debuggee start with suspend=n"
111
112PORTFILE="${TESTCLASSES}"/shutdown1.port
113
114DEBUGGEEFLAGS=
115if [ -r $TESTCLASSES/@debuggeeVMOptions ] ; then
116 DEBUGGEEFLAGS=`cat $TESTCLASSES/@debuggeeVMOptions`
117elif [ -r $TESTCLASSES/../@debuggeeVMOptions ] ; then
118 DEBUGGEEFLAGS=`cat $TESTCLASSES/../@debuggeeVMOptions`
119fi
120
121startDebuggee \
122 $DEBUGGEEFLAGS \
123 -agentlib:jdwp=transport=dt_socket,server=y,suspend=n \
124 -classpath "${TESTCLASSES}" ProcessAttachDebuggee "${PORTFILE}"
125
126$JAVA -classpath ${TESTCLASSES}${PS}${TESTJAVA}/lib/tools.jar \
127 ProcessAttachDebugger $pid 2>&1
128if [ $? != 0 ]; then failures=`expr $failures + 1`; fi
129
130# Note that when the debugger disconnects, the debuggee picks another
131# port and outputs another 'Listening for transport ... ' msg.
132
133stopDebuggee "${PORTFILE}"
134
135#########################################################
136echo "\nTest 2: Debuggee start with suspend=y"
137
138PORTFILE="${TESTCLASSES}"/shutdown2.port
139startDebuggee \
140 $DEBUGGEEFLAGS \
141 -agentlib:jdwp=transport=dt_socket,server=y,suspend=y \
142 -classpath "${TESTCLASSES}" ProcessAttachDebuggee "${PORTFILE}"
143
144$JAVA -classpath ${TESTCLASSES}${PS}${TESTJAVA}/lib/tools.jar \
145 ProcessAttachDebugger $pid 2>&1
146
147# The debuggee is suspended and doesn't run until the debugger
148# disconnects. We have to give it time to write the port number
149# to ${PORTFILE}
150sleep 10
151
152if [ $? != 0 ]; then failures=`expr $failures + 1`; fi
153stopDebuggee "${PORTFILE}"
154
155###
156if [ $failures = 0 ];
157 then echo "All tests passed.";
158 else echo "$failures test(s) failed:"; cat ${OUTPUTFILE};
159fi
160exit $failures