jdk/test/com/sun/jdi/ProcessAttachTest.sh
author ohair
Wed, 06 Apr 2011 22:06:11 -0700
changeset 9035 1255eb81cc2f
parent 5506 202f599c92aa
child 21832 85be6fd8b7be
permissions -rw-r--r--
7033660: Update copyright year to 2011 on any files changed in 2011 Reviewed-by: dholmes
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
     1
#!/bin/sh
90ce3da70b43 Initial load
duke
parents:
diff changeset
     2
90ce3da70b43 Initial load
duke
parents:
diff changeset
     3
#
9035
1255eb81cc2f 7033660: Update copyright year to 2011 on any files changed in 2011
ohair
parents: 5506
diff changeset
     4
# Copyright (c) 2005, 2010, Oracle and/or its affiliates. All rights reserved.
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
     5
# DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
90ce3da70b43 Initial load
duke
parents:
diff changeset
     6
#
90ce3da70b43 Initial load
duke
parents:
diff changeset
     7
# This code is free software; you can redistribute it and/or modify it
90ce3da70b43 Initial load
duke
parents:
diff changeset
     8
# under the terms of the GNU General Public License version 2 only, as
90ce3da70b43 Initial load
duke
parents:
diff changeset
     9
# published by the Free Software Foundation.
90ce3da70b43 Initial load
duke
parents:
diff changeset
    10
#
90ce3da70b43 Initial load
duke
parents:
diff changeset
    11
# This code is distributed in the hope that it will be useful, but WITHOUT
90ce3da70b43 Initial load
duke
parents:
diff changeset
    12
# ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
90ce3da70b43 Initial load
duke
parents:
diff changeset
    13
# FITNESS FOR A PARTICULAR PURPOSE.  See the GNU General Public License
90ce3da70b43 Initial load
duke
parents:
diff changeset
    14
# version 2 for more details (a copy is included in the LICENSE file that
90ce3da70b43 Initial load
duke
parents:
diff changeset
    15
# accompanied this code).
90ce3da70b43 Initial load
duke
parents:
diff changeset
    16
#
90ce3da70b43 Initial load
duke
parents:
diff changeset
    17
# You should have received a copy of the GNU General Public License version
90ce3da70b43 Initial load
duke
parents:
diff changeset
    18
# 2 along with this work; if not, write to the Free Software Foundation,
90ce3da70b43 Initial load
duke
parents:
diff changeset
    19
# Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
90ce3da70b43 Initial load
duke
parents:
diff changeset
    20
#
5506
202f599c92aa 6943119: Rebrand source copyright notices
ohair
parents: 4658
diff changeset
    21
# Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
202f599c92aa 6943119: Rebrand source copyright notices
ohair
parents: 4658
diff changeset
    22
# or visit www.oracle.com if you need additional information or have any
202f599c92aa 6943119: Rebrand source copyright notices
ohair
parents: 4658
diff changeset
    23
# questions.
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
    24
#
90ce3da70b43 Initial load
duke
parents:
diff changeset
    25
90ce3da70b43 Initial load
duke
parents:
diff changeset
    26
90ce3da70b43 Initial load
duke
parents:
diff changeset
    27
# @test
90ce3da70b43 Initial load
duke
parents:
diff changeset
    28
# @bug 4527279
90ce3da70b43 Initial load
duke
parents:
diff changeset
    29
# @summary Unit test for ProcessAttachingConnector
90ce3da70b43 Initial load
duke
parents:
diff changeset
    30
#
90ce3da70b43 Initial load
duke
parents:
diff changeset
    31
# @build ProcessAttachDebugger ProcessAttachDebuggee ShutdownDebuggee
90ce3da70b43 Initial load
duke
parents:
diff changeset
    32
# @run shell ProcessAttachTest.sh
90ce3da70b43 Initial load
duke
parents:
diff changeset
    33
90ce3da70b43 Initial load
duke
parents:
diff changeset
    34
if [ "${TESTJAVA}" = "" ]
90ce3da70b43 Initial load
duke
parents:
diff changeset
    35
then
90ce3da70b43 Initial load
duke
parents:
diff changeset
    36
  echo "TESTJAVA not set.  Test cannot execute.  Failed."
90ce3da70b43 Initial load
duke
parents:
diff changeset
    37
  exit 1
90ce3da70b43 Initial load
duke
parents:
diff changeset
    38
fi
90ce3da70b43 Initial load
duke
parents:
diff changeset
    39
                                                                                                     
90ce3da70b43 Initial load
duke
parents:
diff changeset
    40
if [ "${TESTSRC}" = "" ]
90ce3da70b43 Initial load
duke
parents:
diff changeset
    41
then
90ce3da70b43 Initial load
duke
parents:
diff changeset
    42
  echo "TESTSRC not set.  Test cannot execute.  Failed."
90ce3da70b43 Initial load
duke
parents:
diff changeset
    43
  exit 1
90ce3da70b43 Initial load
duke
parents:
diff changeset
    44
fi
90ce3da70b43 Initial load
duke
parents:
diff changeset
    45
                                                                                                     
90ce3da70b43 Initial load
duke
parents:
diff changeset
    46
if [ "${TESTCLASSES}" = "" ]
90ce3da70b43 Initial load
duke
parents:
diff changeset
    47
then
90ce3da70b43 Initial load
duke
parents:
diff changeset
    48
  echo "TESTCLASSES not set.  Test cannot execute.  Failed."
90ce3da70b43 Initial load
duke
parents:
diff changeset
    49
  exit 1
90ce3da70b43 Initial load
duke
parents:
diff changeset
    50
fi
90ce3da70b43 Initial load
duke
parents:
diff changeset
    51
                                                                                                     
90ce3da70b43 Initial load
duke
parents:
diff changeset
    52
JAVA="${TESTJAVA}/bin/java"
90ce3da70b43 Initial load
duke
parents:
diff changeset
    53
90ce3da70b43 Initial load
duke
parents:
diff changeset
    54
OS=`uname -s`
90ce3da70b43 Initial load
duke
parents:
diff changeset
    55
90ce3da70b43 Initial load
duke
parents:
diff changeset
    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
90ce3da70b43 Initial load
duke
parents:
diff changeset
    58
    PS=";"
90ce3da70b43 Initial load
duke
parents:
diff changeset
    59
    OS="Windows"
90ce3da70b43 Initial load
duke
parents:
diff changeset
    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
90ce3da70b43 Initial load
duke
parents:
diff changeset
    65
  * )
90ce3da70b43 Initial load
duke
parents:
diff changeset
    66
    PS=":"
90ce3da70b43 Initial load
duke
parents:
diff changeset
    67
    ;;
90ce3da70b43 Initial load
duke
parents:
diff changeset
    68
esac
90ce3da70b43 Initial load
duke
parents:
diff changeset
    69
90ce3da70b43 Initial load
duke
parents:
diff changeset
    70
startDebuggee()
90ce3da70b43 Initial load
duke
parents:
diff changeset
    71
{
90ce3da70b43 Initial load
duke
parents:
diff changeset
    72
  OUTPUTFILE=${TESTCLASSES}/Debuggee.out
90ce3da70b43 Initial load
duke
parents:
diff changeset
    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
90ce3da70b43 Initial load
duke
parents:
diff changeset
    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
90ce3da70b43 Initial load
duke
parents:
diff changeset
    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
90ce3da70b43 Initial load
duke
parents:
diff changeset
    86
  # to give the intermediate shell process time to launch the
90ce3da70b43 Initial load
duke
parents:
diff changeset
    87
  # "java" process.
90ce3da70b43 Initial load
duke
parents:
diff changeset
    88
  if [ "$OS" = "Windows" ]; then
90ce3da70b43 Initial load
duke
parents:
diff changeset
    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
90ce3da70b43 Initial load
duke
parents:
diff changeset
    91
  fi
90ce3da70b43 Initial load
duke
parents:
diff changeset
    92
                                                                                                     
90ce3da70b43 Initial load
duke
parents:
diff changeset
    93
  echo "Waiting for Debuggee to initialize..."
90ce3da70b43 Initial load
duke
parents:
diff changeset
    94
  attempts=0
90ce3da70b43 Initial load
duke
parents:
diff changeset
    95
  while true; do
90ce3da70b43 Initial load
duke
parents:
diff changeset
    96
    sleep 1
90ce3da70b43 Initial load
duke
parents:
diff changeset
    97
    out=`tail -1 ${OUTPUTFILE}`
90ce3da70b43 Initial load
duke
parents:
diff changeset
    98
    if [ ! -z "$out" ]; then
90ce3da70b43 Initial load
duke
parents:
diff changeset
    99
      break
90ce3da70b43 Initial load
duke
parents:
diff changeset
   100
    fi
90ce3da70b43 Initial load
duke
parents:
diff changeset
   101
    attempts=`expr $attempts + 1`
90ce3da70b43 Initial load
duke
parents:
diff changeset
   102
    echo "Waiting $attempts second(s) ..."
90ce3da70b43 Initial load
duke
parents:
diff changeset
   103
  done
90ce3da70b43 Initial load
duke
parents:
diff changeset
   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
90ce3da70b43 Initial load
duke
parents:
diff changeset
   106
}
90ce3da70b43 Initial load
duke
parents:
diff changeset
   107
90ce3da70b43 Initial load
duke
parents:
diff changeset
   108
stopDebuggee()
90ce3da70b43 Initial load
duke
parents:
diff changeset
   109
{
90ce3da70b43 Initial load
duke
parents:
diff changeset
   110
  $JAVA -classpath "${TESTCLASSES}" ShutdownDebuggee $1
90ce3da70b43 Initial load
duke
parents:
diff changeset
   111
  if [ $? != 0 ] ; then
90ce3da70b43 Initial load
duke
parents:
diff changeset
   112
    echo "Error: ShutdownDebuggee failed"
90ce3da70b43 Initial load
duke
parents:
diff changeset
   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
90ce3da70b43 Initial load
duke
parents:
diff changeset
   115
  fi
90ce3da70b43 Initial load
duke
parents:
diff changeset
   116
}
90ce3da70b43 Initial load
duke
parents:
diff changeset
   117
90ce3da70b43 Initial load
duke
parents:
diff changeset
   118
failures=0
90ce3da70b43 Initial load
duke
parents:
diff changeset
   119
90ce3da70b43 Initial load
duke
parents:
diff changeset
   120
#########################################################
90ce3da70b43 Initial load
duke
parents:
diff changeset
   121
echo "Test 1: Debuggee start with suspend=n"
90ce3da70b43 Initial load
duke
parents:
diff changeset
   122
90ce3da70b43 Initial load
duke
parents:
diff changeset
   123
PORTFILE="${TESTCLASSES}"/shutdown1.port
90ce3da70b43 Initial load
duke
parents:
diff changeset
   124
90ce3da70b43 Initial load
duke
parents:
diff changeset
   125
DEBUGGEEFLAGS=
90ce3da70b43 Initial load
duke
parents:
diff changeset
   126
if [ -r $TESTCLASSES/@debuggeeVMOptions ] ; then
90ce3da70b43 Initial load
duke
parents:
diff changeset
   127
   DEBUGGEEFLAGS=`cat $TESTCLASSES/@debuggeeVMOptions`
90ce3da70b43 Initial load
duke
parents:
diff changeset
   128
elif [ -r $TESTCLASSES/../@debuggeeVMOptions ] ; then
90ce3da70b43 Initial load
duke
parents:
diff changeset
   129
   DEBUGGEEFLAGS=`cat $TESTCLASSES/../@debuggeeVMOptions`
90ce3da70b43 Initial load
duke
parents:
diff changeset
   130
fi
90ce3da70b43 Initial load
duke
parents:
diff changeset
   131
90ce3da70b43 Initial load
duke
parents:
diff changeset
   132
startDebuggee \
90ce3da70b43 Initial load
duke
parents:
diff changeset
   133
  $DEBUGGEEFLAGS \
90ce3da70b43 Initial load
duke
parents:
diff changeset
   134
  -agentlib:jdwp=transport=dt_socket,server=y,suspend=n \
90ce3da70b43 Initial load
duke
parents:
diff changeset
   135
  -classpath "${TESTCLASSES}" ProcessAttachDebuggee "${PORTFILE}"
90ce3da70b43 Initial load
duke
parents:
diff changeset
   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
90ce3da70b43 Initial load
duke
parents:
diff changeset
   138
  ProcessAttachDebugger $pid 2>&1
90ce3da70b43 Initial load
duke
parents:
diff changeset
   139
if [ $? != 0 ]; then failures=`expr $failures + 1`; fi
90ce3da70b43 Initial load
duke
parents:
diff changeset
   140
90ce3da70b43 Initial load
duke
parents:
diff changeset
   141
# Note that when the debugger disconnects, the debuggee picks another
90ce3da70b43 Initial load
duke
parents:
diff changeset
   142
# port and outputs another 'Listening for transport ... ' msg.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   143
90ce3da70b43 Initial load
duke
parents:
diff changeset
   144
stopDebuggee "${PORTFILE}"
90ce3da70b43 Initial load
duke
parents:
diff changeset
   145
90ce3da70b43 Initial load
duke
parents:
diff changeset
   146
#########################################################
90ce3da70b43 Initial load
duke
parents:
diff changeset
   147
echo "\nTest 2: Debuggee start with suspend=y"
90ce3da70b43 Initial load
duke
parents:
diff changeset
   148
90ce3da70b43 Initial load
duke
parents:
diff changeset
   149
PORTFILE="${TESTCLASSES}"/shutdown2.port
90ce3da70b43 Initial load
duke
parents:
diff changeset
   150
startDebuggee \
90ce3da70b43 Initial load
duke
parents:
diff changeset
   151
  $DEBUGGEEFLAGS \
90ce3da70b43 Initial load
duke
parents:
diff changeset
   152
  -agentlib:jdwp=transport=dt_socket,server=y,suspend=y \
90ce3da70b43 Initial load
duke
parents:
diff changeset
   153
  -classpath "${TESTCLASSES}" ProcessAttachDebuggee "${PORTFILE}"
90ce3da70b43 Initial load
duke
parents:
diff changeset
   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
90ce3da70b43 Initial load
duke
parents:
diff changeset
   156
  ProcessAttachDebugger $pid 2>&1
90ce3da70b43 Initial load
duke
parents:
diff changeset
   157
90ce3da70b43 Initial load
duke
parents:
diff changeset
   158
# The debuggee is suspended and doesn't run until the debugger
90ce3da70b43 Initial load
duke
parents:
diff changeset
   159
# disconnects.  We have to give it time to write the port number
90ce3da70b43 Initial load
duke
parents:
diff changeset
   160
# to ${PORTFILE}
90ce3da70b43 Initial load
duke
parents:
diff changeset
   161
sleep 10
90ce3da70b43 Initial load
duke
parents:
diff changeset
   162
90ce3da70b43 Initial load
duke
parents:
diff changeset
   163
if [ $? != 0 ]; then failures=`expr $failures + 1`; fi
90ce3da70b43 Initial load
duke
parents:
diff changeset
   164
stopDebuggee "${PORTFILE}"
90ce3da70b43 Initial load
duke
parents:
diff changeset
   165
90ce3da70b43 Initial load
duke
parents:
diff changeset
   166
### 
90ce3da70b43 Initial load
duke
parents:
diff changeset
   167
if [ $failures = 0 ];
90ce3da70b43 Initial load
duke
parents:
diff changeset
   168
  then echo "All tests passed.";
90ce3da70b43 Initial load
duke
parents:
diff changeset
   169
  else echo "$failures test(s) failed:"; cat ${OUTPUTFILE};
90ce3da70b43 Initial load
duke
parents:
diff changeset
   170
fi
90ce3da70b43 Initial load
duke
parents:
diff changeset
   171
exit $failures