From patchwork Tue Oct 1 17:28:50 2019 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Andrew Burgess X-Patchwork-Id: 34765 Received: (qmail 10799 invoked by alias); 1 Oct 2019 17:29:01 -0000 Mailing-List: contact gdb-patches-help@sourceware.org; run by ezmlm Precedence: bulk List-Id: List-Unsubscribe: List-Subscribe: List-Archive: List-Post: List-Help: , Sender: gdb-patches-owner@sourceware.org Delivered-To: mailing list gdb-patches@sourceware.org Received: (qmail 10771 invoked by uid 89); 1 Oct 2019 17:28:59 -0000 Authentication-Results: sourceware.org; auth=none X-Spam-SWARE-Status: No, score=-24.1 required=5.0 tests=AWL, BAYES_00, GIT_PATCH_0, GIT_PATCH_1, GIT_PATCH_2, GIT_PATCH_3, RCVD_IN_DNSWL_NONE, SPF_PASS autolearn=ham version=3.3.1 spammy=H*MI:andrew, Within, Clean X-HELO: mail-wr1-f48.google.com Received: from mail-wr1-f48.google.com (HELO mail-wr1-f48.google.com) (209.85.221.48) by sourceware.org (qpsmtpd/0.93/v0.84-503-g423c35a) with ESMTP; Tue, 01 Oct 2019 17:28:56 +0000 Received: by mail-wr1-f48.google.com with SMTP id o18so16492384wrv.13 for ; Tue, 01 Oct 2019 10:28:55 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=embecosm.com; s=google; h=from:to:cc:subject:date:message-id; bh=gGSUVRoxNOnnKel0c7MomCcAQ71TQ/im380FtW0p+Qs=; b=I1DahuIwn9KwamKRGDEdoIu4P7LUILYLCBRmdh8LtUkMlsEu63h27ZoLARn+0Fkgiq Uy+6VWXnAoPA4KlHVeYa2iHP1k7YAXo8XVPOG+BZA6qAWEcMC8SUxM7qZOhOjRl8UY/Y YnDYH0smCe9QqyfuEaLeUG7Cvyn9cd8UXbOOn8fHOPz4bUj7XnXlAhEbAwjhkxo3zF5i WW9pG4sO6Dsc99i5GOO4fzNpQXEakM2izRRy+MJ6f4FeKDWPczPLWn8x31iUS1ro0sZI T/9BXpIgqyeC19huoRS+pGof5WoBD6ihkQFEjY0+/b2Dykm0/1YZJgHFUfv1bUBe+sAM wcHw== Return-Path: Received: from localhost (host86-128-12-122.range86-128.btcentralplus.com. [86.128.12.122]) by smtp.gmail.com with ESMTPSA id d9sm20746480wrf.62.2019.10.01.10.28.52 (version=TLS1_2 cipher=ECDHE-RSA-CHACHA20-POLY1305 bits=256/256); Tue, 01 Oct 2019 10:28:53 -0700 (PDT) From: Andrew Burgess To: gdb-patches Cc: Andrew Burgess Subject: [PATCH] gdb/testsuite: Add gdb_test_multiple_name variable Date: Tue, 1 Oct 2019 18:28:50 +0100 Message-Id: <20191001172850.29867-1-andrew.burgess@embecosm.com> X-IsSubscribed: yes This commit adds a new feature to gdb_test_multiple, an automatically created variable gdb_test_multiple_name. The idea is to make it easier to write tests using gdb_test_multiple, and avoid places where the string passed to pass/fail within an action element is different to the message passed to the top level gdb_test_multiple. As an example, previously you might write this: gdb_test_multiple "print foo" "test foo" { -re "expected output 1" { pass "test foo" } -re "expected output 2" { fail "test foo" } } This is OK, but it's easy for the pass/fail strings to come out of sync, or contain a typo. A better version would look like this: set testname "test foo" gdb_test_multiple "print foo" $testname { -re "expected output 1" { pass $testname } -re "expected output 2" { fail $testname } } This is better, but its a bit of a drag having to create a new variable each time. After this patch you can now write this: gdb_test_multiple "print foo" "test foo" { -re "expected output 1" { pass $gdb_test_multiple_name } -re "expected output 2" { fail $gdb_test_multiple_name } } The $gdb_test_multiple_name is setup by gdb_test_multiple, and cleaned up once the test has completed. Nested calls to gdb_test_multiple are supported, though $gdb_test_multiple_name will only ever contain the inner most test message (which is probably what you want). My only regret is that '$gdb_test_multiple_name' is so long, but I wanted something that was unlikely to clash with any existing variable name, or anything that a user is likely to want to use. I've tested this on x86-64/GNU Linux and see no test regressions, and I've converted one test script over to make use of this new technique both as an example, and to ensure that the new facility doesn't get broken. I have no plans to convert all tests over to this technique, but I hope others will find this useful for writing tests in the future. gdb/testsuite/ChangeLog: * lib/gdb.exp (gdb_test_multiple): Add gdb_test_multiple_name mechanism. * gdb.base/annota1.exp: Update to use gdb_test_multiple_name. --- gdb/testsuite/ChangeLog | 6 ++++ gdb/testsuite/gdb.base/annota1.exp | 58 ++++++++++++++++++-------------------- gdb/testsuite/lib/gdb.exp | 38 +++++++++++++++++++++++-- 3 files changed, 70 insertions(+), 32 deletions(-) diff --git a/gdb/testsuite/gdb.base/annota1.exp b/gdb/testsuite/gdb.base/annota1.exp index 3d379f0fd49..96b0fce5cf7 100644 --- a/gdb/testsuite/gdb.base/annota1.exp +++ b/gdb/testsuite/gdb.base/annota1.exp @@ -97,11 +97,11 @@ gdb_expect { # gdb_test_multiple "info break" "breakpoint info" { -re "\r\n\032\032post-prompt\r\n\r\n\032\032breakpoints-headers\r\n\r\n\032\032field 0\r\nNum \r\n\032\032field 1\r\nType \r\n\032\032field 2\r\nDisp \r\n\032\032field 3\r\nEnb \r\n\032\032field 4\r\nAddress +\r\n\032\032field 5\r\nWhat\r\n\r\n\032\032breakpoints-table\r\n\r\n\032\032record\r\n\r\n\032\032field 0\r\n1 \r\n\032\032field 1\r\nbreakpoint \r\n\032\032field 2\r\nkeep \r\n\032\032field 3\r\ny \r\n\032\032field 4\r\n$hex +\r\n\032\032field 5\r\nin main at ${escapedsrcfile}:$main_line\r\n\r\n\032\032breakpoints-table-end\r\n$gdb_prompt$" { - pass "breakpoint info" + pass $gdb_test_multiple_name } -re "\r\n\032\032post-prompt\r\n\r\n\032\032breakpoints-headers\r\n\r\n\032\032field 0\r\nNum \r\n\032\032field 1\r\nType \r\n\032\032field 2\r\nDisp \r\n\032\032field 3\r\nEnb \r\n\032\032field 4\r\nAddress +\r\n\032\032field 5\r\nWhat\r\n\r\n\032\032breakpoints-table\r\n\r\n\032\032record\r\n\r\n\032\032field 0\r\n1 \r\n\032\032field 1\r\nbreakpoint \r\n\032\032field 2\r\nkeep \r\n\032\032field 3\r\ny \r\n\032\032field 4\r\n$hex +\r\n\032\032field 5\r\nin main at .*${srcfile}:$main_line\r\n\r\n\032\032breakpoints-table-end\r\n$gdb_prompt$" { setup_xfail "*-*-*" 1270 - fail "breakpoint info" + fail $gdb_test_multiple_name } } @@ -147,7 +147,7 @@ gdb_test_multiple "run" "run until main breakpoint" { "\032\032source.*$srcfile:$main_line:.*:beg:$hex\r\n\r\n" \ "\032\032frame-end\r\n\r\n" \ "\032\032stopped.*$gdb_prompt$" } ] { - pass "run until main breakpoint" + pass $gdb_test_multiple_name } } #exp_internal 0 @@ -160,7 +160,7 @@ gdb_test_multiple "run" "run until main breakpoint" { # gdb_test_multiple "next" "go after array init line" { -re "source .*annota1.c.*$gdb_prompt$" { - pass "go after array init line" + pass $gdb_test_multiple_name } } @@ -179,7 +179,7 @@ gdb_test_multiple "next" "go after array init line" { # gdb_test_multiple "print my_array" "print array" { -re "\r\n\032\032post-prompt\r\n\r\n\032\032value-history-begin 1 -\r\n.*= \r\n\032\032value-history-value\r\n.\r\n\032\032array-section-begin 0 -\r\n1\r\n\032\032elt\r\n, 2\r\n\032\032elt\r\n, 3\r\n\032\032elt\r\n\r\n\032\032array-section-end\r\n.\r\n\r\n\032\032value-history-end\r\n$gdb_prompt$" { - pass "print array" + pass $gdb_test_multiple_name } } @@ -193,7 +193,7 @@ gdb_test_multiple "print my_array" "print array" { #exp_internal 1 gdb_test_multiple "print non_existent_value" "print non_existent_value" { -re "\r\n\032\032post-prompt\r\n\r\n\032\032error-begin\r\nNo symbol \"non_existent_value\" in current context.\r\n\r\n\032\032error\r\n$gdb_prompt$" { - pass "print non_existent_value" + pass $gdb_test_multiple_name } } @@ -204,7 +204,7 @@ gdb_test_multiple "print non_existent_value" "print non_existent_value" { # gdb_test_multiple "break handle_USR1" "break handle_USR1" { -re "\r\n\032\032post-prompt\r\nBreakpoint.*at $hex: file.*$srcfile, line.*\r\n\032\032breakpoints-invalid\r\n.*$gdb_prompt$" { - pass "break handle_USR1" + pass $gdb_test_multiple_name } } @@ -213,10 +213,10 @@ gdb_test_multiple "break handle_USR1" "break handle_USR1" { # gdb_test_multiple "break printf" "break printf" { -re "\r\n\032\032post-prompt\r\nBreakpoint.*at $hex.*\032\032breakpoints-invalid\r\n.*$gdb_prompt$" { - pass "break printf" + pass $gdb_test_multiple_name } -re "\r\n\032\032post-prompt\r\nwarning: Breakpoint address adjusted from $hex to $hex.\r\n\r\n\032\032breakpoints-invalid\r\nBreakpoint.*at $hex.*$gdb_prompt$" { - pass "break printf" + pass $gdb_test_multiple_name } } @@ -229,9 +229,9 @@ set pat_end "\r\n\032\032breakpoint 3\r\n\r\nBreakpoint 3, \r\n\032\032frame-beg gdb_test_multiple "continue" "continue to printf" { -re "${pat_begin}($pat_adjust)?$pat_end" { - pass "continue to printf" + pass $gdb_test_multiple_name } - -re ".*$gdb_prompt$" { fail "continue to printf" } + -re ".*$gdb_prompt$" { fail $gdb_test_multiple_name } } # @@ -246,11 +246,11 @@ set pat_end "\r\n\032\032frame-source-file-end\r\n:\r\n\032\032frame-source-line gdb_test_multiple "backtrace" "backtrace from shlibrary" { -re "$pat_begin$escapedsrcfile$pat_end" { - pass "backtrace from shlibrary" + pass $gdb_test_multiple_name } -re "$pat_begin.*$srcfile$pat_end" { setup_xfail "*-*-*" 1270 - fail "backtrace from shlibrary" + fail $gdb_test_multiple_name } } @@ -269,11 +269,11 @@ if [target_info exists gdb,nosignals] { } else { gdb_test_multiple "signal SIGUSR1" "send SIGUSR1" { -re "\r\n\032\032post-prompt\r\nContinuing with signal SIGUSR1.\r\n\r\n\032\032starting\(\(\r\n\r\n\032\032frames-invalid\)|\(\r\n\r\n\032\032breakpoints-invalid\)\)+\r\n\r\n\032\032breakpoint 2\r\n\r\nBreakpoint 2, \r\n\032\032frame-begin 0 $hex\r\n\r\n\032\032frame-function-name\r\nhandle_USR1\r\n\032\032frame-args\r\n \\(\r\n\032\032arg-begin\r\nsig\r\n\032\032arg-name-end\r\n=\r\n\032\032arg-value -\r\n$decimal\r\n\032\032arg-end\r\n\\)\r\n\032\032frame-source-begin\r\n at \r\n\032\032frame-source-file\r\n${escapedsrcfile}\r\n\032\032frame-source-file-end\r\n:\r\n\032\032frame-source-line\r\n.*\r\n\032\032frame-source-end\r\n\r\n\r\n\032\032source.*annota1.c:.*:.*:beg:$hex\r\n$decimal\[^\r\n\]+\r\n\r\n\032\032frame-end\r\n\r\n\032\032stopped\r\n$gdb_prompt$" { - pass "send SIGUSR1" + pass $gdb_test_multiple_name } -re "\r\n\032\032post-prompt\r\nContinuing with signal SIGUSR1.\r\n\r\n\032\032starting\(\(\r\n\r\n\032\032frames-invalid\)|\(\r\n\r\n\032\032breakpoints-invalid\)\)+\r\n\r\n\032\032breakpoint 2\r\n\r\nBreakpoint 2, \r\n\032\032frame-begin 0 $hex\r\n\r\n\032\032frame-function-name\r\nhandle_USR1\r\n\032\032frame-args\r\n \\(\r\n\032\032arg-begin\r\nsig\r\n\032\032arg-name-end\r\n=\r\n\032\032arg-value -\r\n$decimal\r\n\032\032arg-end\r\n\\)\r\n\032\032frame-source-begin\r\n at \r\n\032\032frame-source-file\r\n.*${srcfile}\r\n\032\032frame-source-file-end\r\n:\r\n\032\032frame-source-line\r\n.*\r\n\032\032frame-source-end\r\n\r\n\r\n\032\032source.*annota1.c:.*:.*:beg:$hex\r\n$decimal\[^\r\n\]+\r\n\r\n\032\032frame-end\r\n\r\n\032\032stopped\r\n$gdb_prompt$" { setup_xfail "*-*-*" 1270 - fail "send SIGUSR1" + fail $gdb_test_multiple_name } } @@ -283,7 +283,7 @@ if [target_info exists gdb,nosignals] { # gdb_test_multiple "backtrace" "backtrace @ signal handler" { -re "frame-begin 0 $hex\r\n#0.*frame-end.*frame-begin 1 $hex\r\n#1.*(\032\032signal-handler-caller\r\n.signal handler called.\r\n\r\n)+\032\032frame-end\r\n\r\n\032\032frame-begin 2 $hex\r\n#2.*(frame-begin 3 $hex\r\n#3.*)*frame-end.*$gdb_prompt$" { - pass "backtrace @ signal handler" + pass $gdb_test_multiple_name } } } @@ -293,19 +293,19 @@ if [target_info exists gdb,nosignals] { # gdb_test_multiple "delete 1" "delete bp 1" { -re "\r\n\032\032post-prompt\r\n${breakpoints_invalid}$gdb_prompt$" { - pass "delete bp 1" + pass $gdb_test_multiple_name } } gdb_test_multiple "delete 2" "delete bp 2" { -re "\r\n\032\032post-prompt\r\n${breakpoints_invalid}$gdb_prompt$" { - pass "delete bp 2" + pass $gdb_test_multiple_name } } gdb_test_multiple "delete 3" "delete bp 3" { -re "\r\n\032\032post-prompt\r\n${breakpoints_invalid}$gdb_prompt$" { - pass "delete bp 3" + pass $gdb_test_multiple_name } } @@ -313,14 +313,13 @@ gdb_test_multiple "delete 3" "delete bp 3" { # break in main, after value is initialized. This is in preparation # to test the annotate output for the display command. # -set test "break in main" -gdb_test_multiple "break ${srcfile}:${main_line}" $test { +gdb_test_multiple "break ${srcfile}:${main_line}" "break in main" { -re "post-prompt.*Breakpoint 4 at $hex: file ${escapedsrcfile}, line $main_line.*\032\032breakpoints-invalid.*$gdb_prompt$" { - pass $test + pass $gdb_test_multiple_name } -re "post-prompt.*Breakpoint 4 at $hex: file .*${srcfile}, line $main_line.*\032\032breakpoints-invalid.*$gdb_prompt$" { setup_xfail "*-*-*" 1270 - fail $test + fail $gdb_test_multiple_name } } @@ -405,12 +404,11 @@ gdb_test_multiple "next" "breakpoint ignore count" { # Get the inferior's PID for later. -set test "get inferior pid" set pid -1 -gdb_test_multiple "info inferior 1" "$test" { +gdb_test_multiple "info inferior 1" "get inferior pid" { -re "process (\[0-9\]*).*$gdb_prompt$" { set pid $expect_out(1,string) - pass "$test" + pass $gdb_test_multiple_name } } @@ -429,7 +427,7 @@ if [target_info exists gdb,nosignals] { } else { gdb_test_multiple "signal SIGTRAP" "signal sent" { -re ".*\032\032post-prompt\r\nContinuing with signal SIGTRAP.\r\n\r\n\032\032starting\(\r\n\r\n\032\032frames-invalid\)+\r\n\r\n\032\032signalled\r\n\r\nProgram terminated with signal \r\n\032\032signal-name\r\nSIGTRAP\r\n\032\032signal-name-end\r\n, \r\n\032\032signal-string\r\nTrace.breakpoint trap\r\n\032\032signal-string-end\r\n.\r\nThe program no longer exists.\r\n\r\n\032\032thread-exited,id=\"${decimal}\",group-id=\"i${decimal}\"\r\n\r\n\032\032stopped\r\n$gdb_prompt$" { - pass "signal sent" + pass $gdb_test_multiple_name } } } @@ -482,13 +480,13 @@ proc thread_test {} { gdb_test_multiple "continue" "new thread" { -re "\032\032new-thread.*\r\n$gdb_prompt$" { - pass "new thread" + pass $gdb_test_multiple_name } } gdb_test_multiple "continue" "thread exit" { -re "\032\032thread-exited,id=\"${decimal}\",group-id=\"i${decimal}\".*\r\n$gdb_prompt$" { - pass "thread exit" + pass $gdb_test_multiple_name } } } @@ -497,7 +495,7 @@ proc thread_test {} { proc thread_switch {} { gdb_test_multiple "thread 1" "thread switch" { -re ".*\032\032thread-changed" { - pass "thread switch" + pass $gdb_test_multiple_name } } } diff --git a/gdb/testsuite/lib/gdb.exp b/gdb/testsuite/lib/gdb.exp index 3a1f053cf8a..a472650cc75 100644 --- a/gdb/testsuite/lib/gdb.exp +++ b/gdb/testsuite/lib/gdb.exp @@ -719,10 +719,24 @@ proc gdb_internal_error_resync {} { # # gdb_test_multiple "print foo" "test foo" { # -re "expected output 1" { -# pass "print foo" +# pass "test foo" # } # -re "expected output 2" { -# fail "print foo" +# fail "test foo" +# } +# } +# +# Within action elements you can also make use of the variable +# gdb_test_multiple_name, this variable is setup automatically by +# gdb_test_multiple, and contains the value of MESSAGE. You can then +# write this, which is equivalent to the above: +# +# gdb_test_multiple "print foo" "test foo" { +# -re "expected output 1" { +# pass $gdb_test_multiple_name +# } +# -re "expected output 2" { +# fail $gdb_test_multiple_name # } # } # @@ -1038,8 +1052,28 @@ proc gdb_test_multiple { command message user_code { prompt_regexp "" } } { } } + # Create gdb_test_multiple_name in the parent scope. If this + # variable already exists, which is might if we have nested calls + # to gdb_test_multiple, then preserve the old value, otherwise, + # create a new variable in the parent scope. + upvar gdb_test_multiple_name gdb_test_multiple_name + if { [info exists gdb_test_multiple_name] } { + set gdb_test_multiple_name_old "$gdb_test_multiple_name" + } + set gdb_test_multiple_name "$message" + set result 0 set code [catch {gdb_expect $code} string] + + # Clean up the gdb_test_multiple_name variable. If we had a + # previous value then restore it, otherwise, delete the variable + # from the parent scope. + if { [info exists gdb_test_multiple_name_old] } { + set gdb_test_multiple_name "$gdb_test_multiple_name_old" + } else { + unset gdb_test_multiple_name + } + if {$code == 1} { global errorInfo errorCode return -code error -errorinfo $errorInfo -errorcode $errorCode $string