public inbox for gdb-patches@sourceware.org
 help / color / mirror / Atom feed
* [pushed 1/2] [gdb/testsuite] Make Term::wait_for "" match only a prompt
@ 2023-06-21 13:31 Tom de Vries
  2023-06-21 13:32 ` [pushed 2/2] [gdb/testsuite] Reimplement Term::command_no_prompt_prefix Tom de Vries
  0 siblings, 1 reply; 2+ messages in thread
From: Tom de Vries @ 2023-06-21 13:31 UTC (permalink / raw)
  To: gdb-patches

The semantics of Term::wait_for is:
...
    # Accept some output from gdb and update the screen.  WAIT_FOR is
    # a regexp matching the line to wait for.  Return 0 on timeout, 1
    # on success.
    proc wait_for {wait_for} {
...

Note that besides the regexp, also a subsequent gdb prompt is matched.

I recently used wait_for "" in a few test-cases, thinking that this would
match just a prompt, but in fact that's not the case.

Fix this in wait_for, and add a corresponding test in gdb.tui/tuiterm-2.exp.

Tested on x86_64-linux.
---
 gdb/testsuite/gdb.tui/tuiterm-2.exp | 13 +++++++++++++
 gdb/testsuite/lib/tuiterm.exp       |  4 ++++
 2 files changed, 17 insertions(+)

diff --git a/gdb/testsuite/gdb.tui/tuiterm-2.exp b/gdb/testsuite/gdb.tui/tuiterm-2.exp
index e7a0f03e4ba..8e838d31073 100644
--- a/gdb/testsuite/gdb.tui/tuiterm-2.exp
+++ b/gdb/testsuite/gdb.tui/tuiterm-2.exp
@@ -93,6 +93,19 @@ with_override Term::accept_gdb_output test_accept_gdb_output {
 		}
 		gdb_assert { ![Term::command "foo"] }
 	    }
+
+	    with_test_prefix Term::wait_for {
+		Term::_setup 4 20
+		set send_cnt 0
+		set expect_send {}
+		set action_cnt 0
+		set actions {
+		    {
+			Term::_insert "(gdb) "
+		    }
+		}
+		gdb_assert { [Term::wait_for ""] }
+	    }
 	}
     }
 }
diff --git a/gdb/testsuite/lib/tuiterm.exp b/gdb/testsuite/lib/tuiterm.exp
index dc928ae5aff..41fa554aa09 100644
--- a/gdb/testsuite/lib/tuiterm.exp
+++ b/gdb/testsuite/lib/tuiterm.exp
@@ -789,6 +789,10 @@ namespace eval Term {
 	set fn "wait_for"
 
 	set prompt_wait_for "(^|\\|)$gdb_prompt \$"
+	if { $wait_for == "" } {
+	    set wait_for $prompt_wait_for
+	}
+
 	debug_tui_matching "$fn: regexp: '$wait_for'"
 
 	while 1 {

base-commit: 340640f710e690b37c885166949595cde5f827b2
-- 
2.35.3


^ permalink raw reply	[flat|nested] 2+ messages in thread

* [pushed 2/2] [gdb/testsuite] Reimplement Term::command_no_prompt_prefix
  2023-06-21 13:31 [pushed 1/2] [gdb/testsuite] Make Term::wait_for "" match only a prompt Tom de Vries
@ 2023-06-21 13:32 ` Tom de Vries
  0 siblings, 0 replies; 2+ messages in thread
From: Tom de Vries @ 2023-06-21 13:32 UTC (permalink / raw)
  To: gdb-patches

Say we run test-case gdb.tui/basic.exp.  It calls Term::enter_tui, which does:
...
	command_no_prompt_prefix "tui enable"
...

The proc command_no_prompt_prefix is documented as:
...
    # As proc command, but don't wait for an initial prompt.  This is used for
    # initial terminal commands, where there's no prompt yet.
...

Indeed, before the "tui enable" command, the tuiterm is empty, so there is no
prompt and just before switching to TUI we have in the tuiterm:
...
tui enable
...

The reason that there is no prompt, is that:
- in order for tuiterm to show something, its input processing procs need to
  be called, and
- the initial gdb prompt, and subsequent prompts generated by gdb_test-style
  procs, are all consumed by those procs instead.

This is in principle not a problem, but the absence of a prompt makes a
tuiterm session look less like a session on an actual xterm.

Add a new proc gen_prompt, that:
- generates a prompt using echo
- consumes the response before the prompt using gdb_expect
- consumes the prompt using Term::wait_for "".

This allows us to reimplement Term::command_no_prompt_prefix using
Term::command, and just before switching to TUI we have in the tuiterm:
...
(gdb) tui enable
...

Tested on x86_64-linux.
---
 gdb/testsuite/lib/tuiterm.exp | 20 +++++++++++++++++---
 1 file changed, 17 insertions(+), 3 deletions(-)

diff --git a/gdb/testsuite/lib/tuiterm.exp b/gdb/testsuite/lib/tuiterm.exp
index 41fa554aa09..598c1f8cbdf 100644
--- a/gdb/testsuite/lib/tuiterm.exp
+++ b/gdb/testsuite/lib/tuiterm.exp
@@ -875,6 +875,21 @@ namespace eval Term {
 	}
     }
 
+    # Generate prompt on TUIterm.
+    proc gen_prompt {} {
+	# Generate a prompt.
+	send_gdb "echo\n"
+
+	# Drain the output before the prompt.
+	gdb_expect {
+	    -re "echo\r\n" {
+	    }
+	}
+
+	# Interpret prompt using TUIterm.
+	wait_for ""
+    }
+
     # Setup ready for starting the tui, but don't actually start it.
     # Returns 1 on success, 0 if TUI tests should be skipped.
     proc prepare_for_tui {} {
@@ -920,9 +935,8 @@ namespace eval Term {
     # As proc command, but don't wait for an initial prompt.  This is used for
     # initial terminal commands, where there's no prompt yet.
     proc command_no_prompt_prefix {cmd} {
-	send_gdb "$cmd\n"
-	set str [string_to_regexp $cmd]
-	wait_for "^$str"
+	gen_prompt
+	command $cmd
     }
 
     # Apply the attribute list in ATTRS to attributes array UPVAR_NAME.
-- 
2.35.3


^ permalink raw reply	[flat|nested] 2+ messages in thread

end of thread, other threads:[~2023-06-21 13:31 UTC | newest]

Thread overview: 2+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2023-06-21 13:31 [pushed 1/2] [gdb/testsuite] Make Term::wait_for "" match only a prompt Tom de Vries
2023-06-21 13:32 ` [pushed 2/2] [gdb/testsuite] Reimplement Term::command_no_prompt_prefix Tom de Vries

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for read-only IMAP folder(s) and NNTP newsgroup(s).