public inbox for gdb-patches@sourceware.org
 help / color / mirror / Atom feed
From: Pedro Alves <pedro@palves.net>
To: gdb-patches@sourceware.org
Subject: [PATCH 1/2] Add -nopass option to gdb_test/gdb_test_multiple
Date: Thu, 19 May 2022 13:34:44 +0100	[thread overview]
Message-ID: <20220519123445.2756177-2-pedro@palves.net> (raw)
In-Reply-To: <20220519123445.2756177-1-pedro@palves.net>

The previous patch to add -prompt/-lbl gdb_test to gdb_test introduced
a regression: Before, you could specify an explicit empty message to
indicate you didn't want to PASS, like so:

  gdb_test COMMAND PATTERN ""

After said patch, gdb_test no longer distinguishes
no-message-specified vs empty-message, so tests that previously would
be silent on PASS, now started emitting PASS messages based on
COMMAND.  This in turn introduced a number of PATH/DUPLICATE
violations in the testsuite.

I think that not issuing a PASS should be restricted to only a few
cases -- namely in shared routines exported by gdb.exp, which happen
to use gdb_test internally.  In tests that iterate an unknown number
of tests exercising some racy scenario.  In the latter case, if we
emit PASSes for each iteration, we run into the situation where
different testsuite runs emit a different number of PASSes.

Thus, this patch preserves the current behavior, and, instead, adds a
new "-nopass" option to gdb_test and gdb_test_no_output.  Compared to
the old way of supressing PASS with an empty message, this has the
advantage that you can specify a FAIL message that is distinct from
the command string, and, it's also more explicit.

Change-Id: I5375f23f073493e0672190a0ec2e847938a580b2
---
 gdb/testsuite/lib/gdb.exp | 60 +++++++++++++++++++++------------------
 1 file changed, 32 insertions(+), 28 deletions(-)

diff --git a/gdb/testsuite/lib/gdb.exp b/gdb/testsuite/lib/gdb.exp
index 97841ca19a1..d6627d3b23e 100644
--- a/gdb/testsuite/lib/gdb.exp
+++ b/gdb/testsuite/lib/gdb.exp
@@ -834,6 +834,13 @@ proc gdb_internal_error_resync {} {
     return 0
 }
 
+# Fill in the default prompt if PROMPT_REGEXP is empty.
+proc fill_in_default_prompt {prompt_regexp} {
+    if { "$prompt_regexp" == "" } {
+	return "$::gdb_prompt $"
+    }
+    return $prompt_regexp
+}
 
 # gdb_test_multiple COMMAND MESSAGE [ -prompt PROMPT_REGEXP] [ -lbl ]
 #                   EXPECT_ARGUMENTS
@@ -960,9 +967,7 @@ proc gdb_test_multiple { command message args } {
 	error "Too few arguments to gdb_test_multiple"
     }
 
-    if { "$prompt_regexp" == "" } {
-	set prompt_regexp "$gdb_prompt $"
-    }
+    set prompt_regexp [fill_in_default_prompt $prompt_regexp]
 
     if { $message == "" } {
 	set message $command
@@ -1335,6 +1340,7 @@ proc gdb_test_multiline { name args } {
 # -prompt PROMPT_REGEXP specifies a regexp matching the expected prompt
 #   after the command output.  If empty, defaults to "$gdb_prompt $".
 # -lbl specifies that line-by-line matching will be used.
+# -nopass specifies that a PASS should not be issued.
 #
 # Returns:
 #    1 if the test failed,
@@ -1348,6 +1354,7 @@ proc gdb_test { args } {
     parse_args {
 	{prompt ""}
 	{lbl}
+	{nopass}
     }
 
     lassign $args command pattern message question response
@@ -1361,21 +1368,17 @@ proc gdb_test { args } {
 	set message $command
     }
 
-    if { $prompt == "" } {
-	set prompt "$gdb_prompt $"
-    }
+    set prompt [fill_in_default_prompt $prompt]
 
     set saw_question 0
 
     set user_code {}
     lappend user_code {
 	-re "\[\r\n\]*(?:$pattern)\[\r\n\]+$prompt" {
-	    if ![string match "" $message] then {
-		if { $question != "" } {
-		    gdb_assert $saw_question "$message"
-		} else {
-		    pass "$message"
-		}
+	    if { $question != "" & !$saw_question} {
+		fail $message
+	    } elseif {!$nopass} {
+		pass $message
 	    }
 	}
     }
@@ -1439,30 +1442,31 @@ if { [tcl_version_at_least 8 5] == 0 } {
     }
 }
 
-# gdb_test_no_output COMMAND MESSAGE
+# gdb_test_no_output [-prompt PROMPT_REGEXP] [-nopass] COMMAND [MESSAGE]
 # Send a command to GDB and verify that this command generated no output.
 #
-# See gdb_test_multiple for a description of the COMMAND and MESSAGE
-# parameters.  If MESSAGE is ommitted, then COMMAND will be used as
-# the message.  (If MESSAGE is the empty string, then sometimes we do not
-# call pass or fail at all; I don't understand this at all.)
+# See gdb_test for a description of the -prompt, -nopass, COMMAND, and
+# MESSAGE parameters.
 
 proc gdb_test_no_output { args } {
     global gdb_prompt
-    set command [lindex $args 0]
-    if [llength $args]>1 then {
-	set message [lindex $args 1]
-    } else {
-	set message $command
+
+    parse_args {
+	{prompt_re ""}
+	{nopass}
     }
 
+    lassign $args command message
+
+    set prompt_re [fill_in_default_prompt $prompt_re]
+
     set command_regex [string_to_regexp $command]
-    gdb_test_multiple $command $message {
-        -re "^$command_regex\r\n$gdb_prompt $" {
-	    if ![string match "" $message] then {
-		pass "$message"
-            }
-        }
+    gdb_test_multiple $command $message -prompt $prompt_re {
+	-re "^$command_regex\r\n$prompt_re" {
+	    if {!$nopass} {
+		pass $gdb_test_name
+	    }
+	}
     }
 }
 
-- 
2.36.0


  reply	other threads:[~2022-05-19 12:34 UTC|newest]

Thread overview: 7+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2022-05-19 12:34 [PATCH 0/2] gdb: Fix DUPLICATE and PATH regressions throughout Pedro Alves
2022-05-19 12:34 ` Pedro Alves [this message]
2022-05-19 12:34 ` [PATCH 2/2] " Pedro Alves
2022-05-20 10:10 ` [PATCH, TEST REQUEST][gdb/testsuite] Fix ERROR in gdb.ctf/funcreturn.exp Tom de Vries
2022-06-04  9:19   ` [committed][gdb/testsuite] " Tom de Vries
2022-05-24 15:18 ` [PATCH 0/2] gdb: Fix DUPLICATE and PATH regressions throughout Simon Marchi
2022-05-25 12:47   ` Pedro Alves

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=20220519123445.2756177-2-pedro@palves.net \
    --to=pedro@palves.net \
    --cc=gdb-patches@sourceware.org \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
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).