[PATCH 1/6] gdb/testsuite: Better detection of auto-response at y/n prompts

Andrew Burgess andrew.burgess@embecosm.com
Tue Jan 1 22:45:00 GMT 2019


I noticed that when running this test:

  make check-gdb RUNTESTFLAGS="--target_board=native-gdbserver gdb.mi/mi-break.exp"

I would occasionally see some UNRESOLVED test results like this:

  (gdb)
  PASS: gdb.mi/mi-break.exp: mi-mode=separate: breakpoint at main
  Expecting: ^(kill[
  ]+)?(.*[
  ]+[(]gdb[)]
  [ ]*)
  kill
  &"kill\n"
  ~"Kill the program being debugged? (y or n) [answered Y; input not from terminal]\n"
  =thread-group-exited,id="i1"
  ERROR: Got interactive prompt.
  UNRESOLVED: gdb.mi/mi-break.exp: mi-mode=separate:

The problem appears to be that the expect buffer fills up to include
the '(y or n)' prompt without including the following lines.

The pattern supplied by the outer test script is looking for the
following lines.  As the following lines are not present then expect
matches on the interactive prompt case rather than the case for the
user supplied pattern.

The problem with this is that we are not really at an interactive
prompt, GDB is providing an answer for us and then moving on.  When I
examine a successful run of the test the output from GDB is identical,
the only difference is where expect happens to buffer the output from
GDB.

This patch introduces a second check inside the 'y or n' prompt case,
which gives expect a chance to refill its buffers and catches the
'answered Y; input ...' text.

This second check is on a short 1 second timeout, I'm currently
assuming that the auto-answer text will either already be in expect,
or is waiting to be read in.  If after 1 second the auto-answer text
is not seen then we assume that GDB really is waiting at an
interactive prompt.

With this patch in place I can now leave the following loop running
indefinitely, where before it would fail usually after ~10
iterations.

  while make check-gdb RUNTESTFLAGS="--target_board=native-gdbserver gdb.mi/mi-break.exp"; \
  do /bin/true; \
  done

gdb/testsuite/ChangeLog:

	* lib/mi-support.exp (mi_gdb_test): When detecting a 'y or n'
	interactive prompt, look for the auto-answer before declaring a
	fail.
---
 gdb/testsuite/ChangeLog          |  6 ++++++
 gdb/testsuite/lib/mi-support.exp | 21 ++++++++++++++++++---
 2 files changed, 24 insertions(+), 3 deletions(-)

diff --git a/gdb/testsuite/lib/mi-support.exp b/gdb/testsuite/lib/mi-support.exp
index d193592a843..48ea45d62c7 100644
--- a/gdb/testsuite/lib/mi-support.exp
+++ b/gdb/testsuite/lib/mi-support.exp
@@ -834,9 +834,24 @@ proc mi_gdb_test { args } {
 	     fail "$message"
 	}
 	 -re "\\(y or n\\) " {
-	    send_gdb "n\n"
-	    perror "Got interactive prompt."
-	     fail "$message"
+	    # If the expect buffer just happens to fill up to the 'y
+	    # or n' prompt then we can end up in this case, even
+	    # though GDB will automatically provide a response for us.
+	    # We give expect another chance here to look for the auto
+	    # answer text before declaring a fail.
+	    set auto_response_seen 0
+	    gdb_expect 1 {
+		-re ".answered Y; input not from terminal." {
+		    set auto_response_seen 1
+		}
+	    }
+	    if { ! $auto_response_seen } {
+		send_gdb "n\n"
+		perror "Got interactive prompt."
+		fail "$message"
+	    } else {
+		exp_continue
+	    }
 	}
 	 eof {
 	     perror "Process no longer exists"
-- 
2.14.5



More information about the Gdb-patches mailing list