From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: from smtp-out1.suse.de (smtp-out1.suse.de [195.135.220.28]) by sourceware.org (Postfix) with ESMTPS id 34C123858D28 for ; Mon, 11 Oct 2021 10:28:31 +0000 (GMT) DMARC-Filter: OpenDMARC Filter v1.4.1 sourceware.org 34C123858D28 Received: from imap2.suse-dmz.suse.de (imap2.suse-dmz.suse.de [192.168.254.74]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits) key-exchange X25519 server-signature ECDSA (P-521) server-digest SHA512) (No client certificate requested) by smtp-out1.suse.de (Postfix) with ESMTPS id 4F05622009; Mon, 11 Oct 2021 10:28:30 +0000 (UTC) Received: from imap2.suse-dmz.suse.de (imap2.suse-dmz.suse.de [192.168.254.74]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits) key-exchange X25519 server-signature ECDSA (P-521) server-digest SHA512) (No client certificate requested) by imap2.suse-dmz.suse.de (Postfix) with ESMTPS id 3911713C4C; Mon, 11 Oct 2021 10:28:30 +0000 (UTC) Received: from dovecot-director2.suse.de ([192.168.254.65]) by imap2.suse-dmz.suse.de with ESMTPSA id pXGzDM4RZGElOQAAMHmgww (envelope-from ); Mon, 11 Oct 2021 10:28:30 +0000 Subject: Re: [PATCH][gdb/testsuite] Add proc require in lib/gdb.exp From: Tom de Vries To: Tom Tromey , Tom de Vries via Gdb-patches References: <20210929135520.GA16103@delia> <87pmsq0y4m.fsf@tromey.com> <8735pfz6ax.fsf@tromey.com> <5de83135-c797-d211-467a-de12d174ae67@suse.de> Message-ID: <43b4486d-d5a9-a057-de9c-6de55aa81e36@suse.de> Date: Mon, 11 Oct 2021 12:28:29 +0200 User-Agent: Mozilla/5.0 (X11; Linux x86_64; rv:78.0) Gecko/20100101 Thunderbird/78.12.0 MIME-Version: 1.0 In-Reply-To: <5de83135-c797-d211-467a-de12d174ae67@suse.de> Content-Type: multipart/mixed; boundary="------------AEC396A6A57B1B8719A718F7" Content-Language: en-US X-Spam-Status: No, score=-12.5 required=5.0 tests=BAYES_00, DKIM_SIGNED, DKIM_VALID, DKIM_VALID_AU, DKIM_VALID_EF, GIT_PATCH_0, KAM_SHORT, NICE_REPLY_A, SPF_HELO_NONE, SPF_PASS, TXREP autolearn=ham autolearn_force=no version=3.4.4 X-Spam-Checker-Version: SpamAssassin 3.4.4 (2020-01-24) 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: Mon, 11 Oct 2021 10:28:33 -0000 This is a multi-part message in MIME format. --------------AEC396A6A57B1B8719A718F7 Content-Type: text/plain; charset=utf-8 Content-Transfer-Encoding: 7bit On 10/6/21 9:40 AM, Tom de Vries wrote: > [ was: Re: [committed][gdb/testsuite] Disable vgdb tests if xml not > supported ] > > On 10/5/21 8:15 PM, Tom Tromey wrote: >> Tom> Or perhaps you mean more generically (which wouldn't require us to write >> Tom> a proc for each type of require): >> Tom> ... >> Tom> proc require { fn val } { >> Tom> if { [$fn] != $val } { >> Tom> untested "$fn != $val" >> Tom> return -code return 0 >> Tom> } >> Tom> } >> Tom> ... >> Tom> and: >> Tom> ... >> Tom> require gdb_skip_xml_test 0 >> Tom> ... >> Tom> ? >> >> Either seems fine but this one does read nicely to me. >> Or maybe even just requiring 'fn' to return 0 would be good enough. > > I've also thought about that, but decided against it: > - it does not take into account a proc support_foo that returns 1, which > in the current form can be required using "require support_foo 1" > - it does not support the cases where we require no support for a > feature, say "require gdb_skip_xml_test 1" > > Also, I considered making the test freeform, as in gdb_assert, but > decided against it because: > - it does not enforce uniform usage > - makes it harder to do the fn+value to message matching I've added in > this version. > I ended up using require to transform: ... if { [ensure_gdb_index $binfile] == -1 } { return -1 } ... into: ... require {ensure_gdb_index $binfile} != -1 ... and consequently had to change proc require a bit. Committed as attached. Thanks, - Tom --------------AEC396A6A57B1B8719A718F7 Content-Type: text/x-patch; charset=UTF-8; name="0001-gdb-testsuite-Add-proc-require-in-lib-gdb.exp.patch" Content-Transfer-Encoding: 7bit Content-Disposition: inline; filename="0001-gdb-testsuite-Add-proc-require-in-lib-gdb.exp.patch" [gdb/testsuite] Add proc require in lib/gdb.exp Add a new proc require in lib/gdb.exp, and use it to shorten: ... if { [gdb_skip_xml_test] } { # Valgrind gdbserver requires gdb with xml support. untested "missing xml support" return 0 } ... into: ... require gdb_skip_xml_test 0 ... Tested on x86_64-linux, both with and without a trigger patch that forces gdb_skip_xml_test to return 1. --- gdb/testsuite/gdb.base/valgrind-bt.exp | 7 ++----- gdb/testsuite/gdb.base/valgrind-disp-step.exp | 7 ++----- gdb/testsuite/gdb.base/valgrind-infcall-2.exp | 7 ++----- gdb/testsuite/gdb.base/valgrind-infcall.exp | 7 ++----- gdb/testsuite/lib/gdb.exp | 30 +++++++++++++++++++++++++++ 5 files changed, 38 insertions(+), 20 deletions(-) diff --git a/gdb/testsuite/gdb.base/valgrind-bt.exp b/gdb/testsuite/gdb.base/valgrind-bt.exp index 440c6e403e9..546701498b2 100644 --- a/gdb/testsuite/gdb.base/valgrind-bt.exp +++ b/gdb/testsuite/gdb.base/valgrind-bt.exp @@ -13,11 +13,8 @@ # You should have received a copy of the GNU General Public License # along with this program. If not, see . -if { [gdb_skip_xml_test] } { - # Valgrind gdbserver requires gdb with xml support. - untested "missing xml support" - return 0 -} +# Valgrind gdbserver requires gdb with xml support. +require gdb_skip_xml_test 0 load_lib valgrind.exp diff --git a/gdb/testsuite/gdb.base/valgrind-disp-step.exp b/gdb/testsuite/gdb.base/valgrind-disp-step.exp index 88ac848ae2d..c1ed5a3e69b 100644 --- a/gdb/testsuite/gdb.base/valgrind-disp-step.exp +++ b/gdb/testsuite/gdb.base/valgrind-disp-step.exp @@ -18,11 +18,8 @@ # really tests is that GDB falls back to in-line stepping # automatically instead of getting stuck or crashing. -if { [gdb_skip_xml_test] } { - # Valgrind gdbserver requires gdb with xml support. - untested "missing xml support" - return 0 -} +# Valgrind gdbserver requires gdb with xml support. +require gdb_skip_xml_test 0 load_lib valgrind.exp diff --git a/gdb/testsuite/gdb.base/valgrind-infcall-2.exp b/gdb/testsuite/gdb.base/valgrind-infcall-2.exp index a368717c1e8..064cf719712 100644 --- a/gdb/testsuite/gdb.base/valgrind-infcall-2.exp +++ b/gdb/testsuite/gdb.base/valgrind-infcall-2.exp @@ -29,11 +29,8 @@ # terminate called after throwing an instance of 'gdb_exception_error' # Aborted (core dumped) -if { [gdb_skip_xml_test] } { - # Valgrind gdbserver requires gdb with xml support. - untested "missing xml support" - return 0 -} +# Valgrind gdbserver requires gdb with xml support. +require gdb_skip_xml_test 0 load_lib valgrind.exp diff --git a/gdb/testsuite/gdb.base/valgrind-infcall.exp b/gdb/testsuite/gdb.base/valgrind-infcall.exp index 9f49a320f52..68bc1b8e4e7 100644 --- a/gdb/testsuite/gdb.base/valgrind-infcall.exp +++ b/gdb/testsuite/gdb.base/valgrind-infcall.exp @@ -13,11 +13,8 @@ # You should have received a copy of the GNU General Public License # along with this program. If not, see . -if { [gdb_skip_xml_test] } { - # Valgrind gdbserver requires gdb with xml support. - untested "missing xml support" - return 0 -} +# Valgrind gdbserver requires gdb with xml support. +require gdb_skip_xml_test 0 load_lib valgrind.exp diff --git a/gdb/testsuite/lib/gdb.exp b/gdb/testsuite/lib/gdb.exp index 5642db4334d..6a5cdc06485 100644 --- a/gdb/testsuite/lib/gdb.exp +++ b/gdb/testsuite/lib/gdb.exp @@ -8215,5 +8215,35 @@ gdb_caching_proc have_avx { return $status } +# Called as either: +# - require EXPR VAL +# - require EXPR OP VAL +# In the first case, OP is ==. +# +# Require EXPR OP VAL, where EXPR is evaluated in caller context. If not, +# return in the caller's context. + +proc require { fn arg1 {arg2 ""} } { + if { $arg2 == "" } { + set op == + set val $arg1 + } else { + set op $arg1 + set val $arg2 + } + set res [uplevel 1 $fn] + if { [expr $res $op $val] } { + return + } + + switch "$fn $op $val" { + "gdb_skip_xml_test == 0" { set msg "missing xml support" } + default { set msg "$fn != $val" } + } + + untested $msg + return -code return 0 +} + # Always load compatibility stuff. load_lib future.exp --------------AEC396A6A57B1B8719A718F7--