author | mikejwre |
Thu, 25 Mar 2010 15:05:15 -0700 | |
changeset 5074 | 9c9bfe8f3a47 |
parent 4658 | c1af7a34d1b5 |
child 5506 | 202f599c92aa |
permissions | -rw-r--r-- |
2 | 1 |
#!/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 |
||
34 |
if [ "${TESTJAVA}" = "" ] |
|
35 |
then |
|
36 |
echo "TESTJAVA not set. Test cannot execute. Failed." |
|
37 |
exit 1 |
|
38 |
fi |
|
39 |
||
40 |
if [ "${TESTSRC}" = "" ] |
|
41 |
then |
|
42 |
echo "TESTSRC not set. Test cannot execute. Failed." |
|
43 |
exit 1 |
|
44 |
fi |
|
45 |
||
46 |
if [ "${TESTCLASSES}" = "" ] |
|
47 |
then |
|
48 |
echo "TESTCLASSES not set. Test cannot execute. Failed." |
|
49 |
exit 1 |
|
50 |
fi |
|
51 |
||
52 |
JAVA="${TESTJAVA}/bin/java" |
|
53 |
||
54 |
OS=`uname -s` |
|
55 |
||
56 |
case "$OS" in |
|
4658
c1af7a34d1b5
6911117: These tests do not work with CYGWIN: com/sun/jdi
ohair
parents:
2
diff
changeset
|
57 |
Windows*) |
2 | 58 |
PS=";" |
59 |
OS="Windows" |
|
60 |
;; |
|
4658
c1af7a34d1b5
6911117: These tests do not work with CYGWIN: com/sun/jdi
ohair
parents:
2
diff
changeset
|
61 |
CYGWIN*) |
c1af7a34d1b5
6911117: These tests do not work with CYGWIN: com/sun/jdi
ohair
parents:
2
diff
changeset
|
62 |
PS=";" |
c1af7a34d1b5
6911117: These tests do not work with CYGWIN: com/sun/jdi
ohair
parents:
2
diff
changeset
|
63 |
OS="CYGWIN" |
c1af7a34d1b5
6911117: These tests do not work with CYGWIN: com/sun/jdi
ohair
parents:
2
diff
changeset
|
64 |
;; |
2 | 65 |
* ) |
66 |
PS=":" |
|
67 |
;; |
|
68 |
esac |
|
69 |
||
70 |
startDebuggee() |
|
71 |
{ |
|
72 |
OUTPUTFILE=${TESTCLASSES}/Debuggee.out |
|
73 |
${JAVA} "$@" > ${OUTPUTFILE} & |
|
4658
c1af7a34d1b5
6911117: These tests do not work with CYGWIN: com/sun/jdi
ohair
parents:
2
diff
changeset
|
74 |
startpid="$!" |
c1af7a34d1b5
6911117: These tests do not work with CYGWIN: com/sun/jdi
ohair
parents:
2
diff
changeset
|
75 |
pid="${startpid}" |
2 | 76 |
|
4658
c1af7a34d1b5
6911117: These tests do not work with CYGWIN: com/sun/jdi
ohair
parents:
2
diff
changeset
|
77 |
# CYGWIN startpid is not the native windows PID we want, get the WINPID |
c1af7a34d1b5
6911117: These tests do not work with CYGWIN: com/sun/jdi
ohair
parents:
2
diff
changeset
|
78 |
if [ "${OS}" = "CYGWIN" ]; then |
c1af7a34d1b5
6911117: These tests do not work with CYGWIN: com/sun/jdi
ohair
parents:
2
diff
changeset
|
79 |
sleep 2 |
c1af7a34d1b5
6911117: These tests do not work with CYGWIN: com/sun/jdi
ohair
parents:
2
diff
changeset
|
80 |
ps -l -p ${startpid} |
c1af7a34d1b5
6911117: These tests do not work with CYGWIN: com/sun/jdi
ohair
parents:
2
diff
changeset
|
81 |
pid=`ps -l -p ${startpid} | tail -1 | awk '{print $4;}'` |
c1af7a34d1b5
6911117: These tests do not work with CYGWIN: com/sun/jdi
ohair
parents:
2
diff
changeset
|
82 |
fi |
c1af7a34d1b5
6911117: These tests do not work with CYGWIN: com/sun/jdi
ohair
parents:
2
diff
changeset
|
83 |
|
2 | 84 |
# MKS creates an intermediate shell to launch ${JAVA} so |
4658
c1af7a34d1b5
6911117: These tests do not work with CYGWIN: com/sun/jdi
ohair
parents:
2
diff
changeset
|
85 |
# ${startpid} is not the actual pid. We have put in a small sleep |
2 | 86 |
# to give the intermediate shell process time to launch the |
87 |
# "java" process. |
|
88 |
if [ "$OS" = "Windows" ]; then |
|
89 |
sleep 2 |
|
4658
c1af7a34d1b5
6911117: These tests do not work with CYGWIN: com/sun/jdi
ohair
parents:
2
diff
changeset
|
90 |
pid=`ps -o pid,ppid,comm|grep ${startpid}|grep "java"|cut -c1-6` |
2 | 91 |
fi |
92 |
||
93 |
echo "Waiting for Debuggee to initialize..." |
|
94 |
attempts=0 |
|
95 |
while true; do |
|
96 |
sleep 1 |
|
97 |
out=`tail -1 ${OUTPUTFILE}` |
|
98 |
if [ ! -z "$out" ]; then |
|
99 |
break |
|
100 |
fi |
|
101 |
attempts=`expr $attempts + 1` |
|
102 |
echo "Waiting $attempts second(s) ..." |
|
103 |
done |
|
104 |
||
4658
c1af7a34d1b5
6911117: These tests do not work with CYGWIN: com/sun/jdi
ohair
parents:
2
diff
changeset
|
105 |
echo "Debuggee is process $pid (startpid=${startpid})" |
2 | 106 |
} |
107 |
||
108 |
stopDebuggee() |
|
109 |
{ |
|
110 |
$JAVA -classpath "${TESTCLASSES}" ShutdownDebuggee $1 |
|
111 |
if [ $? != 0 ] ; then |
|
112 |
echo "Error: ShutdownDebuggee failed" |
|
113 |
failures=`expr $failures + 1` |
|
4658
c1af7a34d1b5
6911117: These tests do not work with CYGWIN: com/sun/jdi
ohair
parents:
2
diff
changeset
|
114 |
kill -9 ${startpid} |
2 | 115 |
fi |
116 |
} |
|
117 |
||
118 |
failures=0 |
|
119 |
||
120 |
######################################################### |
|
121 |
echo "Test 1: Debuggee start with suspend=n" |
|
122 |
||
123 |
PORTFILE="${TESTCLASSES}"/shutdown1.port |
|
124 |
||
125 |
DEBUGGEEFLAGS= |
|
126 |
if [ -r $TESTCLASSES/@debuggeeVMOptions ] ; then |
|
127 |
DEBUGGEEFLAGS=`cat $TESTCLASSES/@debuggeeVMOptions` |
|
128 |
elif [ -r $TESTCLASSES/../@debuggeeVMOptions ] ; then |
|
129 |
DEBUGGEEFLAGS=`cat $TESTCLASSES/../@debuggeeVMOptions` |
|
130 |
fi |
|
131 |
||
132 |
startDebuggee \ |
|
133 |
$DEBUGGEEFLAGS \ |
|
134 |
-agentlib:jdwp=transport=dt_socket,server=y,suspend=n \ |
|
135 |
-classpath "${TESTCLASSES}" ProcessAttachDebuggee "${PORTFILE}" |
|
136 |
||
4658
c1af7a34d1b5
6911117: These tests do not work with CYGWIN: com/sun/jdi
ohair
parents:
2
diff
changeset
|
137 |
$JAVA -classpath "${TESTCLASSES}${PS}${TESTJAVA}/lib/tools.jar" \ |
2 | 138 |
ProcessAttachDebugger $pid 2>&1 |
139 |
if [ $? != 0 ]; then failures=`expr $failures + 1`; fi |
|
140 |
||
141 |
# Note that when the debugger disconnects, the debuggee picks another |
|
142 |
# port and outputs another 'Listening for transport ... ' msg. |
|
143 |
||
144 |
stopDebuggee "${PORTFILE}" |
|
145 |
||
146 |
######################################################### |
|
147 |
echo "\nTest 2: Debuggee start with suspend=y" |
|
148 |
||
149 |
PORTFILE="${TESTCLASSES}"/shutdown2.port |
|
150 |
startDebuggee \ |
|
151 |
$DEBUGGEEFLAGS \ |
|
152 |
-agentlib:jdwp=transport=dt_socket,server=y,suspend=y \ |
|
153 |
-classpath "${TESTCLASSES}" ProcessAttachDebuggee "${PORTFILE}" |
|
154 |
||
4658
c1af7a34d1b5
6911117: These tests do not work with CYGWIN: com/sun/jdi
ohair
parents:
2
diff
changeset
|
155 |
$JAVA -classpath "${TESTCLASSES}${PS}${TESTJAVA}/lib/tools.jar" \ |
2 | 156 |
ProcessAttachDebugger $pid 2>&1 |
157 |
||
158 |
# The debuggee is suspended and doesn't run until the debugger |
|
159 |
# disconnects. We have to give it time to write the port number |
|
160 |
# to ${PORTFILE} |
|
161 |
sleep 10 |
|
162 |
||
163 |
if [ $? != 0 ]; then failures=`expr $failures + 1`; fi |
|
164 |
stopDebuggee "${PORTFILE}" |
|
165 |
||
166 |
### |
|
167 |
if [ $failures = 0 ]; |
|
168 |
then echo "All tests passed."; |
|
169 |
else echo "$failures test(s) failed:"; cat ${OUTPUTFILE}; |
|
170 |
fi |
|
171 |
exit $failures |