From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: by sourceware.org (Postfix, from userid 1551) id 00CD03858010; Tue, 17 May 2022 10:15:25 +0000 (GMT) DKIM-Filter: OpenDKIM Filter v2.11.0 sourceware.org 00CD03858010 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: quoted-printable From: Pedro Alves To: gdb-cvs@sourceware.org Subject: [binutils-gdb] Make gdb_test's question non-optional if specified X-Act-Checkin: binutils-gdb X-Git-Author: Pedro Alves X-Git-Refname: refs/heads/master X-Git-Oldrev: d7440bee9ffa6767e704f226ec28b9aa2fb748d6 X-Git-Newrev: ed01945057cfdf048bc025f15b410492e12283f6 Message-Id: <20220517101525.00CD03858010@sourceware.org> Date: Tue, 17 May 2022 10:15:25 +0000 (GMT) X-BeenThere: gdb-cvs@sourceware.org X-Mailman-Version: 2.1.29 Precedence: list List-Id: Gdb-cvs mailing list List-Unsubscribe: , List-Archive: List-Help: List-Subscribe: , X-List-Received-Date: Tue, 17 May 2022 10:15:25 -0000 https://sourceware.org/git/gitweb.cgi?p=3Dbinutils-gdb.git;h=3Ded01945057cf= df048bc025f15b410492e12283f6 commit ed01945057cfdf048bc025f15b410492e12283f6 Author: Pedro Alves Date: Wed Mar 30 14:31:56 2022 +0100 Make gdb_test's question non-optional if specified =20 gdb_test supports handling scenarios where GDB asks a question before finishing handling some command. The full prototype of gdb_test is: =20 # gdb_test COMMAND PATTERN MESSAGE QUESTION RESPONSE =20 However, QUESTION is a question that GDB _may_ ask, not one that GDB _must_ ask: =20 # QUESTION is a question GDB may ask in response to COMMAND, like # "are you sure?" # RESPONSE is the response to send if QUESTION appears. =20 If GDB doesn't raise the question, the test still passes. =20 I think that this is a misfeature. If GDB regresses and stops asking a question, the testsuite won't notice. So I think that if a QUESTION is specified, gdb_test should ensure it comes out of GDB. =20 Running the testsuite exposed a number of tests that pass QUESTION/RESPONSE to GDB, but no question comes out. The previous commits fixed them all, so this commit changes gdb_test's behavior. =20 A related issue is that gdb_test doesn't enforce that if you specify QUESTION, that you also specify RESPONSE. I.e., you should pass 1, 2, 3, or 5 arguments to gdb_test, but never 4, or more than 5. Making gdb_test detect bogus arguments actually regressed some testcases, also all fixed in previous commits. =20 Change-Id: I47c39c9034e6a6841129312037a5ca4c5811f0db Diff: --- gdb/testsuite/lib/gdb.exp | 25 +++++++++++++++++++++---- 1 file changed, 21 insertions(+), 4 deletions(-) diff --git a/gdb/testsuite/lib/gdb.exp b/gdb/testsuite/lib/gdb.exp index 47cb2b23676..0b1104bd299 100644 --- a/gdb/testsuite/lib/gdb.exp +++ b/gdb/testsuite/lib/gdb.exp @@ -1326,9 +1326,10 @@ proc gdb_test_multiline { name args } { # omitted, then the pass/fail messages use the command string as the # message. (If this is the empty string, then sometimes we don't # call pass or fail at all; I don't understand this at all.) -# QUESTION is a question GDB may ask in response to COMMAND, like -# "are you sure?" -# RESPONSE is the response to send if QUESTION appears. +# QUESTION is a question GDB should ask in response to COMMAND, like +# "are you sure?" If this is specified, the test fails if GDB +# doesn't print the question. +# RESPONSE is the response to send when QUESTION appears. # # Returns: # 1 if the test failed, @@ -1339,6 +1340,11 @@ proc gdb_test { args } { global gdb_prompt upvar timeout timeout =20 + # Can't have a question without a response. + if { [llength $args] =3D=3D 4 || [llength $args] > 5 } { + error "Unexpected arguments: $args" + } + if [llength $args]>2 then { set message [lindex $args 2] } else { @@ -1347,11 +1353,21 @@ proc gdb_test { args } { set command [lindex $args 0] set pattern [lindex $args 1] =20 + set must_see_question 0 + if { [llength $args] =3D=3D 5 } { + set must_see_question 1 + set saw_question 0 + } + set user_code {} lappend user_code { -re "\[\r\n\]*(?:$pattern)\[\r\n\]+$gdb_prompt $" { if ![string match "" $message] then { - pass "$message" + if {$must_see_question} { + gdb_assert $saw_question "$message" + } else { + pass "$message" + } } } } @@ -1361,6 +1377,7 @@ proc gdb_test { args } { set response_string [lindex $args 4] lappend user_code { -re "(${question_string})$" { + set saw_question 1 send_gdb "$response_string\n" exp_continue }