From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: from mail-wm1-f41.google.com (mail-wm1-f41.google.com [209.85.128.41]) by sourceware.org (Postfix) with ESMTPS id 2DBA73858C52 for ; Wed, 18 May 2022 11:01:09 +0000 (GMT) DMARC-Filter: OpenDMARC Filter v1.4.1 sourceware.org 2DBA73858C52 Authentication-Results: sourceware.org; dmarc=none (p=none dis=none) header.from=palves.net Authentication-Results: sourceware.org; spf=pass smtp.mailfrom=gmail.com Received: by mail-wm1-f41.google.com with SMTP id o12-20020a1c4d0c000000b00393fbe2973dso2974826wmh.2 for ; Wed, 18 May 2022 04:01:09 -0700 (PDT) X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20210112; h=x-gm-message-state:message-id:date:mime-version:user-agent:subject :content-language:to:cc:references:from:in-reply-to :content-transfer-encoding; bh=mb4GG/K+JvcRLJNIt86qjKp1aiOb1NKn2YBsno8UmYI=; b=tL4Islb9WMS8GbYGcIVMmr+YQ6QLVxp53indca+t53FjRI6VC7pmU9PfV3VRifAgz2 Ujr6epoq8pFYdM2Rx6tg/6wjFz4wwA2LKE0fmgIGIr8A/mv53M70v2GK+ReYUvT6p8rc I8WE5vsG6fjgiVLFVyKYrk9N8R7tEUuPH598jOa1ruY7zg/0vQS461ff7cIw4qhYH/o1 LjZ582lfv+mdYYti5MH2+OTzu4Cd/otU9tVkjs9V7z6wKXjaWYd+lDE7tjXq87VMXU8K 7uvV46X0zSk0nXeppTWpOpsaBK8cxbCF6FC4eHpZqmGSm3aLywLd9hr41YWYOxkEYWKO kYpg== X-Gm-Message-State: AOAM5339CpQUhlHioppPtlvsAFSBqfsFh86GPcKCuNLxhRQRtfOVpeH5 qqLH3PSr4rOgf10WvBcjTQvNXiHOIZ8= X-Google-Smtp-Source: ABdhPJxgdXVH7f/VOYN2/oSUOmWuEP/PyD7mLxe9h8YvSgg6/x99W9Xz+G5V6YD5Bar/yW85LPC+TQ== X-Received: by 2002:a05:600c:600b:b0:395:b668:b3fa with SMTP id az11-20020a05600c600b00b00395b668b3famr33780275wmb.46.1652871668177; Wed, 18 May 2022 04:01:08 -0700 (PDT) Received: from ?IPV6:2001:8a0:f924:2600:209d:85e2:409e:8726? ([2001:8a0:f924:2600:209d:85e2:409e:8726]) by smtp.gmail.com with ESMTPSA id n13-20020a5d598d000000b0020c5253d8dasm1830707wri.38.2022.05.18.04.01.06 (version=TLS1_3 cipher=TLS_AES_128_GCM_SHA256 bits=128/128); Wed, 18 May 2022 04:01:06 -0700 (PDT) Message-ID: <8def622c-5396-d1e1-dfbb-a5732dd8183a@palves.net> Date: Wed, 18 May 2022 12:01:05 +0100 MIME-Version: 1.0 User-Agent: Mozilla/5.0 (X11; Linux x86_64; rv:91.0) Gecko/20100101 Thunderbird/91.9.0 Subject: [pushed] Support -prompt and -lbl in gdb_test (Re: [PATCH 5/5] Make gdb_test's question non-optional if specified) Content-Language: en-US To: Tom Tromey Cc: gdb-patches@sourceware.org References: <20220330192929.3161015-1-pedro@palves.net> <20220330192929.3161015-6-pedro@palves.net> <87o7zxeaa6.fsf@tromey.com> <87sfp7kc78.fsf@tromey.com> From: Pedro Alves In-Reply-To: <87sfp7kc78.fsf@tromey.com> Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 7bit X-Spam-Status: No, score=-10.0 required=5.0 tests=BAYES_00, FREEMAIL_FORGED_FROMDOMAIN, FREEMAIL_FROM, GIT_PATCH_0, HEADER_FROM_DIFFERENT_DOMAINS, KAM_DMARC_STATUS, RCVD_IN_DNSWL_NONE, RCVD_IN_MSPIKE_H2, SPF_HELO_NONE, SPF_PASS, TXREP, T_SCC_BODY_TEXT_LINE autolearn=ham autolearn_force=no version=3.4.6 X-Spam-Checker-Version: SpamAssassin 3.4.6 (2021-04-09) on server2.sourceware.org X-BeenThere: gdb-patches@sourceware.org X-Mailman-Version: 2.1.29 Precedence: list List-Id: Gdb-patches mailing list List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , X-List-Received-Date: Wed, 18 May 2022 11:01:11 -0000 On 2022-05-17 23:48, Tom Tromey wrote: > > Pedro> In the patch below I've added support for -prompt and -lbl, and > Pedro> one example using gdb_test -prompt, to show better what I mean. > > Seems pretty reasonable. > > Pedro> + set command [lindex $args 0] > Pedro> + set pattern [lindex $args 1] > Pedro> + set message [lindex $args 2] > Pedro> + set question [lindex $args 3] > Pedro> + set response [lindex $args 4] > > You can also write: > > lassign $args command pattern message question response Even better! I've now looked for an example where we could use "gdb_test -lbl", and found it. Here's what I pushed. >From c76d61da4a65eaadca861bf6c77d579a5cc3f422 Mon Sep 17 00:00:00 2001 From: Pedro Alves Date: Tue, 17 May 2022 11:16:01 +0100 Subject: [PATCH] Support -prompt and -lbl in gdb_test This teaches gdb_test to forward the -prompt and -lbl options to gdb_test_multiple. The option parsing is done with parse_args. As a cleanup, instead of using llength and lindex to get at the positional arguments, use lassign, and check whether the corresponding variable is empty. Convert gdb.base/ui-redirect.exp and gdb.xml/tdesc-reload.exp to use gdb_test -prompt/-lbl instead of gdb_test_multiple as examples. Change-Id: I243e1296d32c05a421ccef30b63d43a89eaeb4a0 --- gdb/testsuite/gdb.base/ui-redirect.exp | 10 ++--- gdb/testsuite/gdb.xml/tdesc-reload.exp | 6 +-- gdb/testsuite/lib/gdb.exp | 61 ++++++++++++++++---------- 3 files changed, 42 insertions(+), 35 deletions(-) diff --git a/gdb/testsuite/gdb.base/ui-redirect.exp b/gdb/testsuite/gdb.base/ui-redirect.exp index 13bc964f46c..4ed82ae63bf 100644 --- a/gdb/testsuite/gdb.base/ui-redirect.exp +++ b/gdb/testsuite/gdb.base/ui-redirect.exp @@ -117,12 +117,10 @@ with_test_prefix "debugging" { gdb_test "set logging enabled on" \ "Copying output to /dev/null.*Copying debug output to /dev/null\\." - set prompt "$gdb_prompt \\\[infrun\\\] fetch_inferior_event: exit\r\n$" - gdb_test_multiple "continue" "continue" -prompt $prompt { - -re "Continuing.*\\\[infrun\\\] .*\\\[infrun\\\] .*Breakpoint \[0-9\]+, foo.*$prompt$" { - pass $gdb_test_name - } - } + gdb_test \ + -prompt "$gdb_prompt \\\[infrun\\\] fetch_inferior_event: exit\r\n$" \ + "continue" \ + "Continuing.*\\\[infrun\\\] .*\\\[infrun\\\] .*Breakpoint \[0-9\]+, foo.*" gdb_test "set debug infrun 0" gdb_test "set logging enabled off" "Done logging to /dev/null\\." diff --git a/gdb/testsuite/gdb.xml/tdesc-reload.exp b/gdb/testsuite/gdb.xml/tdesc-reload.exp index 76dd70fb6d3..6e3fe2f5304 100644 --- a/gdb/testsuite/gdb.xml/tdesc-reload.exp +++ b/gdb/testsuite/gdb.xml/tdesc-reload.exp @@ -68,11 +68,7 @@ if ![runto_main] then { # Run info registers just to check this appears to run fine with the # new target description. -gdb_test_multiple "info all-registers" "Run info registers" -lbl { - -re -wrap "" { - pass $gdb_test_name - } -} +gdb_test -lbl "info all-registers" "" "Run info registers" # Write out the current target description. gdb_test_no_output "pipe maint print xml-tdesc | cat > $xml_file_3" \ diff --git a/gdb/testsuite/lib/gdb.exp b/gdb/testsuite/lib/gdb.exp index 0b1104bd299..97841ca19a1 100644 --- a/gdb/testsuite/lib/gdb.exp +++ b/gdb/testsuite/lib/gdb.exp @@ -1313,7 +1313,8 @@ proc gdb_test_multiline { name args } { } -# gdb_test COMMAND PATTERN MESSAGE QUESTION RESPONSE +# gdb_test [-prompt PROMPT_REGEXP] [-lbl] +# COMMAND [PATTERN] [MESSAGE] [QUESTION RESPONSE] # Send a command to gdb; test the result. # # COMMAND is the command to execute, send to GDB with send_gdb. If @@ -1331,61 +1332,73 @@ proc gdb_test_multiline { name args } { # doesn't print the question. # RESPONSE is the response to send when QUESTION appears. # +# -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. +# # Returns: # 1 if the test failed, # 0 if the test passes, # -1 if there was an internal error. -# +# proc gdb_test { args } { global gdb_prompt upvar timeout timeout + parse_args { + {prompt ""} + {lbl} + } + + lassign $args command pattern message question response + # Can't have a question without a response. - if { [llength $args] == 4 || [llength $args] > 5 } { + if { $question != "" && $response == "" || [llength $args] > 5 } { error "Unexpected arguments: $args" } - if [llength $args]>2 then { - set message [lindex $args 2] - } else { - set message [lindex $args 0] + if { $message == "" } { + set message $command } - set command [lindex $args 0] - set pattern [lindex $args 1] - set must_see_question 0 - if { [llength $args] == 5 } { - set must_see_question 1 - set saw_question 0 + if { $prompt == "" } { + set prompt "$gdb_prompt $" } + set saw_question 0 + set user_code {} lappend user_code { - -re "\[\r\n\]*(?:$pattern)\[\r\n\]+$gdb_prompt $" { + -re "\[\r\n\]*(?:$pattern)\[\r\n\]+$prompt" { if ![string match "" $message] then { - if {$must_see_question} { + if { $question != "" } { gdb_assert $saw_question "$message" } else { pass "$message" } - } - } + } + } } - if { [llength $args] == 5 } { - set question_string [lindex $args 3] - set response_string [lindex $args 4] + if { $question != "" } { lappend user_code { - -re "(${question_string})$" { + -re "$question$" { set saw_question 1 - send_gdb "$response_string\n" + send_gdb "$response\n" exp_continue } } - } + } set user_code [join $user_code] - return [gdb_test_multiple $command $message $user_code] + + set opts {} + lappend "-prompt $prompt" + if {$lbl} { + lappend opts "-lbl" + } + + return [gdb_test_multiple $command $message {*}$opts $user_code] } # Return 1 if version MAJOR.MINOR is at least AT_LEAST_MAJOR.AT_LEAST_MINOR. base-commit: 44b6e8016087c346dc21270d9097f6294ee1e4f6 -- 2.36.0