This is the mail archive of the gdb-patches@sourceware.org mailing list for the GDB project.


Index Nav: [Date Index] [Subject Index] [Author Index] [Thread Index]
Message Nav: [Date Prev] [Date Next] [Thread Prev] [Thread Next]
Other format: [Raw text]

[patch] New testsuite utility: gdb_test_sequence


Hi.

signals.exp has started to give me the same kind of trouble that
ext-run.exp was: intermittent failures (due to .* embedded
in a regexp covering large amounts of output).

The test sets a 6 minute timeout which is more than enough time,
but can still fail.  I've also noticed it pass, but after waiting
a *long* time (feels like the 6 minutes).

Doing some research I found gdb.exp:gdb_expect_list, and a lot of
tests use it (I wonder if it's for similar reasons: avoiding .*
in the middle of a regexp for large output).

So I wrote a wrapper around gdb_expect_list, used it in signals.exp,
and now it passes consistently (and quickly, so I lowered the timeout).
I've also rewritten ext-run.exp to use it.
signals.exp has a separate case for hurd/mach which I can't test,
but this is a simple change.

If there are no objections I will check this in on Monday.
And then I'll go through the testsuite and convert all appropriate the callers
of gdb_expect_list to use gdb_test_sequence.
I'll also look into simplifying similar tests in gdb.base/maint.exp
(but some tests in there are more complicated, and I don't mind
leaving them alone :-)).


2010-11-19  Doug Evans  <dje@google.com>

	* lib/gdb.exp (gdb_test_sequence): New function.
	* gdb.base/signals.exp (test_handle_all_print): Call it.
	Reduce timeout increment from 6 minutes to 1 minute.
	* gdb.server/ext-run.exp: Call it.

Index: lib/gdb.exp
===================================================================
RCS file: /cvs/src/src/gdb/testsuite/lib/gdb.exp,v
retrieving revision 1.158
diff -u -p -r1.158 gdb.exp
--- lib/gdb.exp	12 Oct 2010 18:12:49 -0000	1.158
+++ lib/gdb.exp	19 Nov 2010 18:28:38 -0000
@@ -921,6 +921,32 @@ proc gdb_test_no_output { args } {
     }
 }
 
+# Send a command and then wait for a sequence of outputs.
+# This is useful when the sequence is long and contains ".*", a single
+# regexp to match the entire output can get a timeout much easier.
+#
+# COMMAND is the command to send.
+# TEST_NAME is passed to pass/fail.  COMMAND is used if TEST_NAME is "".
+# EXPECTED_OUTPUT_LIST is a list of regexps of expected output, which are
+# processed in order, and all must be present in the output.
+#
+# It is unnecessary to specify ".*" at the beginning or end of any regexp,
+# there is an implicit ".*" between each element of EXPECTED_OUTPUT_LIST.
+# There is also an implicit ".*" between the last regexp and the gdb prompt.
+#
+# Like gdb_test and gdb_test_multiple, the output is expected to end with the
+# gdb prompt, which must not be specified in EXPECTED_OUTPUT_LIST.
+
+proc gdb_test_sequence { command test_name expected_output_list } {
+    global gdb_prompt
+    if { $test_name == "" } {
+	set test_name $command
+    }
+    lappend expected_output_list ""; # implicit ".*" before gdb prompt
+    send_gdb "$command\n"
+    gdb_expect_list $test_name "$gdb_prompt $" $expected_output_list
+}
+
 
 # Test that a command gives an error.  For pass or fail, return
 # a 1 to indicate that more tests can proceed.  However a timeout
@@ -2375,6 +2401,7 @@ proc gdb_expect_list {test sentinel list
     while { ${index} < [llength ${list}] } {
 	set pattern [lindex ${list} ${index}]
         set index [expr ${index} + 1]
+	verbose -log "gdb_expect_list pattern: /$pattern/" 2
 	if { ${index} == [llength ${list}] } {
 	    if { ${ok} } {
 		gdb_expect {
Index: gdb.base/signals.exp
===================================================================
RCS file: /cvs/src/src/gdb/testsuite/gdb.base/signals.exp,v
retrieving revision 1.19
diff -u -p -r1.19 signals.exp
--- gdb.base/signals.exp	1 Jun 2010 21:29:21 -0000	1.19
+++ gdb.base/signals.exp	19 Nov 2010 18:28:38 -0000
@@ -56,14 +56,23 @@ proc test_handle_all_print {} {
     # Increase timeout and expect input buffer for large output from gdb.
     # Allow blank or TAB as whitespace characters.
     set oldtimeout $timeout
-    set timeout [expr "$timeout + 360"]
+    set timeout [expr "$timeout + 60"]
     verbose "Timeout is now $timeout seconds" 2
     if { ![istarget "*-*-linux*"]
          && ( [istarget "*-*-gnu*"]
               || [istarget "*-*-mach*"] ) } {
-	gdb_test "handle all print" "Signal\[ 	\]+Stop\[ 	\]+Print\[ 	\]+Pass to program\[ 	\]+Description\r\nSIGHUP\[ 	\]+Yes\[ 	\]+Yes\[ 	\]+Yes\[ 	\]+Hangup.*SIG63\[ 	\]+Yes\[ 	\]+Yes\[ 	\]+Yes\[ 	\]+Real-time event 63.*EXC_BREAKPOINT\[ 	\]+Yes\[ 	\]+Yes\[ 	\]+Yes\[ 	\]+Breakpoint"
+	gdb_test_sequence "handle all print" "" \
+	    {
+		"Signal\[ 	\]+Stop\[ 	\]+Print\[ 	\]+Pass to program\[ 	\]+Description\r\nSIGHUP\[ 	\]+Yes\[ 	\]+Yes\[ 	\]+Yes\[ 	\]+Hangup"
+		"SIG63\[ 	\]+Yes\[ 	\]+Yes\[ 	\]+Yes\[ 	\]+Real-time event 63"
+		"EXC_BREAKPOINT\[ 	\]+Yes\[ 	\]+Yes\[ 	\]+Yes\[ 	\]+Breakpoint"
+	    }
     } else {
-	gdb_test "handle all print" "Signal\[ 	\]+Stop\[ 	\]+Print\[ 	\]+Pass to program\[ 	\]+Description\r\nSIGHUP\[ 	\]+Yes\[ 	\]+Yes\[ 	\]+Yes\[ 	\]+Hangup.*SIG63\[ 	\]+Yes\[ 	\]+Yes\[ 	\]+Yes\[ 	\]+Real-time event 63.*"
+	gdb_test_sequence "handle all print" "" \
+	    {
+		"Signal\[ 	\]+Stop\[ 	\]+Print\[ 	\]+Pass to program\[ 	\]+Description\r\nSIGHUP\[ 	\]+Yes\[ 	\]+Yes\[ 	\]+Yes\[ 	\]+Hangup"
+		"SIG63\[ 	\]+Yes\[ 	\]+Yes\[ 	\]+Yes\[ 	\]+Real-time event 63"
+	    }
     }
     set timeout $oldtimeout
     verbose "Timeout restored to $timeout seconds" 2
Index: gdb.server/ext-run.exp
===================================================================
RCS file: /cvs/src/src/gdb/testsuite/gdb.server/ext-run.exp,v
retrieving revision 1.11
diff -u -p -r1.11 ext-run.exp
--- gdb.server/ext-run.exp	18 Nov 2010 20:25:12 -0000	1.11
+++ gdb.server/ext-run.exp	19 Nov 2010 18:28:38 -0000
@@ -53,21 +53,9 @@ if { [istarget *-*-linux*] } {
     # But only if xml support is compiled in.
     if { $do_xml_test } {
 	# This is done in a way to avoid the timeout that can occur from
-	# applying .* regexp to large output.  It is copied from
-	# gdb.base/maint.exp "maint check-symtabs".
-	send_gdb "info os processes\n"
-	gdb_expect {
-	    -re ".*pid +user +command.*1 +root +\[/a-z\]*init" {
-		gdb_expect {
-		    -re "$gdb_prompt $" {
-			pass "get process list"
-		    }
-		    timeout { fail "(timeout) get process list" }
-		}
-	    }
-	    -re ".*$gdb_prompt $" { fail "get process list" }
-	    timeout { fail "(timeout) get process list" }
-	}
+	# applying .* regexp to large output.
+	gdb_test_sequence "info os processes" "get process list" \
+	    { "pid +user +command" "1 +root +\[/a-z\]*init" }
     }
 }
 


Index Nav: [Date Index] [Subject Index] [Author Index] [Thread Index]
Message Nav: [Date Prev] [Date Next] [Thread Prev] [Thread Next]