8027705: com/sun/jdi/JdbMethodExitTest.sh fails when a background thread is generating events.
authorsla
Fri, 01 Nov 2013 15:10:10 +0100
changeset 21602 85bdffaf5e5d
parent 21601 ed0ad544e76f
child 21603 e88919c55dac
8027705: com/sun/jdi/JdbMethodExitTest.sh fails when a background thread is generating events. Reviewed-by: dcubed
jdk/test/com/sun/jdi/JdbMethodExitTest.sh
jdk/test/com/sun/jdi/ShellScaffold.sh
--- a/jdk/test/com/sun/jdi/JdbMethodExitTest.sh	Fri Nov 01 10:08:10 2013 +0100
+++ b/jdk/test/com/sun/jdi/JdbMethodExitTest.sh	Fri Nov 01 15:10:10 2013 +0100
@@ -156,7 +156,7 @@
         // a resume.
 
         $classname xx = new $classname();
-        
+        System.out.println("threadid="+Thread.currentThread().getId());
         bkpt();
 
         // test all possible return types
@@ -197,6 +197,8 @@
 
     # test all possible return types
     runToBkpt @1
+    debuggeeMatchRegexp "s/threadid=\(.*\)/\1/g"
+    threadid=$?
     cmd untrace
 
     cmd trace methods
@@ -226,7 +228,7 @@
 
     # trace exit of methods with all the return values
     # (but just check a couple of them)
-    cmd trace go exits
+    cmd trace go method exits $threadid
     cmd cont
     jdbFailIfNotPresent "instance of JdbMethodExitTest"
     jdbFailIfNotPresent "return value = 8"
@@ -235,7 +237,7 @@
     cmd step up
 
 
-    cmd trace methods
+    cmd trace methods $threadid
     cmd cont
     jdbFailIfNotPresent "Method entered:"
     cmd cont
@@ -243,7 +245,9 @@
     cmd step up
 
 
-    cmd trace go methods
+    cmd trace go methods $threadid
+    cmd cont
+    cmd cont
     cmd cont
     jdbFailIfNotPresent "Method entered: \"thread=main\", JdbMethodExitTest.traceMethods1"
     jdbFailIfNotPresent 'Method exited: .* JdbMethodExitTest.traceMethods1'
@@ -251,14 +255,14 @@
     cmd step up
     
 
-    cmd trace method exits
+    cmd trace method exits $threadid
     cmd cont
     jdbFailIfNotPresent "Method exited: return value = \"traceExits\""
     cmd untrace
     cmd step up
 
 
-    cmd trace go method exits
+    cmd trace go method exits $threadid
     cmd cont
     jdbFailIfNotPresent 'Method exited: .* JdbMethodExitTest.traceExits1'
     cmd untrace
@@ -266,7 +270,7 @@
 
 
     cmd step            # step into traceExit()
-    cmd trace method exit
+    cmd trace method exit $threadid
     cmd cont
     jdbFailIfNotPresent "Method exited: return value = \"traceExit\""
     cmd untrace
@@ -275,7 +279,7 @@
 
     cmd step
     cmd step           # skip over setting return value in caller :-(
-    cmd trace go method exit
+    cmd trace go method exit $threadid
     cmd cont
     jdbFailIfNotPresent 'Method exited: .*JdbMethodExitTest.traceExit1'
     cmd quit
--- a/jdk/test/com/sun/jdi/ShellScaffold.sh	Fri Nov 01 10:08:10 2013 +0100
+++ b/jdk/test/com/sun/jdi/ShellScaffold.sh	Fri Nov 01 15:10:10 2013 +0100
@@ -1004,6 +1004,50 @@
     return $stat
 }
 
+# $1 is the filename, $2 is the regexp to match and return,
+# $3 is the number of lines to search (from the end)
+matchRegexp()
+{
+    if [ -z "$3" ] ; then
+        theCmd=cat
+    else
+        theCmd="tail -$3"
+    fi
+
+    case "$2" in 
+    *\>*)
+        # Target string contains a '>' so we better not ignore it
+        res=`$theCmd $1 | sed -e "$2"`
+        ;;
+    *)
+        # Target string does not contain a '>'.
+        # NOTE:  if $1 does not end with a new line, piping it to sed
+        # doesn't include the chars on the last line.  Detect this
+        # case, and add a new line.
+        theFile="$1"
+        if [ `tail -1 "$theFile" | wc -l | sed -e 's@ @@g'` = 0 ] ; then
+            # The target file doesn't end with a new line so we have
+            # add one to a copy of the target file so the sed command
+            # below can filter that last line.
+            cp "$theFile" "$theFile.tmp"
+            theFile="$theFile.tmp"
+            echo >> "$theFile"
+        fi
+
+        # See bug 6220903. Sometimes the jdb prompt chars ('> ') can
+        # get interleaved in the target file which can keep us from
+        # matching the target string.
+        res=`$theCmd "$theFile" | sed -e 's@> @@g' -e 's@>@@g' \
+            | sed -e "$2"`
+        if [ "$theFile" != "$1" ]; then
+            # remove the copy of the target file
+            rm -f "$theFile"
+        fi
+        unset theFile
+    esac
+    return $res
+}
+
 # $1 is the filename, $2 is the string to look for,
 # $3 is the number of lines to search (from the end)
 failIfPresent()
@@ -1058,6 +1102,14 @@
     failIfPresent $debuggeeOutFile "$1" $2
 }
 
+# match and return the output from the regexp $1 in the debuggee output
+# $2 is the number of lines to search (from the end)
+debuggeeMatchRegexp()
+{
+    matchRegexp $debuggeeOutFile "$1" $2
+}
+
+
 # This should really be named 'done' instead of pass.
 pass()
 {