public inbox for gdb-cvs@sourceware.org help / color / mirror / Atom feed
From: Tom de Vries <vries@sourceware.org> To: gdb-cvs@sourceware.org Subject: [binutils-gdb] [gdb/testsuite] Add cond_wrap proc Date: Fri, 14 Oct 2022 11:09:59 +0000 (GMT) [thread overview] Message-ID: <20221014111000.61CFA3858429@sourceware.org> (raw) https://sourceware.org/git/gitweb.cgi?p=binutils-gdb.git;h=1e4be05b752cc94019ed12d6d305e13e55530724 commit 1e4be05b752cc94019ed12d6d305e13e55530724 Author: Tom de Vries <tdevries@suse.de> Date: Fri Oct 14 13:09:50 2022 +0200 [gdb/testsuite] Add cond_wrap proc Add a new proc cond_wrap, that can be used to replace the repetitive: ... if { $cond } { wrap { <body> } } else { <body> } ... with the shorter: ... cond_wrap $cond wrap { <body> } ... Tested on x86_64-linux. Diff: --- gdb/testsuite/gdb.testsuite/cond-wrap.exp | 43 +++++++++++++++++++++++++++++++ gdb/testsuite/lib/gdb.exp | 20 ++++++++++++++ 2 files changed, 63 insertions(+) diff --git a/gdb/testsuite/gdb.testsuite/cond-wrap.exp b/gdb/testsuite/gdb.testsuite/cond-wrap.exp new file mode 100644 index 00000000000..7feb88bd102 --- /dev/null +++ b/gdb/testsuite/gdb.testsuite/cond-wrap.exp @@ -0,0 +1,43 @@ +# Copyright 2022 Free Software Foundation, Inc. +# This program is free software; you can redistribute it and/or modify +# it under the terms of the GNU General Public License as published by +# the Free Software Foundation; either version 3 of the License, or +# (at your option) any later version. +# +# This program is distributed in the hope that it will be useful, +# but WITHOUT ANY WARRANTY; without even the implied warranty of +# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the +# GNU General Public License for more details. +# +# You should have received a copy of the GNU General Public License +# along with this program. If not, see <http://www.gnu.org/licenses/>. + +# The purpose of this test-case is to test the cond_wrap proc. + +# Proc that temporarily sets global variable a to 6, and executes BODY. +# Note that normally a wrapper needs to guarantee that the restore is executed +# even if executing body throws an error, but we don't need to bother with this +# for this test-case. +proc wrap { body } { + global a + + # Save a. + set save_a $a + + set a 6 + uplevel 1 $body + + # Restore a. + set a $save_a +} + +# Set initial value of global variable a. +set a 5 + +# Verify values of global variable a for cond == 0 and cond == 1. +foreach_with_prefix cond {0 1} { + cond_wrap $cond wrap { + gdb_assert {[expr $a - $cond] == 5} "value in conditional wrap" + } + gdb_assert {$a == 5} "value after conditional wrap" +} diff --git a/gdb/testsuite/lib/gdb.exp b/gdb/testsuite/lib/gdb.exp index 61bc060b2f7..3049a7392a4 100644 --- a/gdb/testsuite/lib/gdb.exp +++ b/gdb/testsuite/lib/gdb.exp @@ -25,6 +25,26 @@ if {$tool == ""} { exit 2 } +# Execute BODY, if COND wrapped in proc WRAP. +# Instead of writing the verbose and repetitive: +# if { $cond } { +# wrap $body +# } else { +# $body +# } +# we can use instead: +# cond_wrap $cond wrap $body + +proc cond_wrap { cond wrap body } { + if { $cond } { + $wrap { + uplevel 1 $body + } + } else { + uplevel 1 $body + } +} + # Add VAR_ID=VAL to ENV_VAR, unless ENV_VAR already contains a VAR_ID setting. proc set_sanitizer_default { env_var var_id val } {
reply other threads:[~2022-10-14 11:09 UTC|newest] Thread overview: [no followups] expand[flat|nested] mbox.gz Atom feed
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=20221014111000.61CFA3858429@sourceware.org \ --to=vries@sourceware.org \ --cc=gdb-cvs@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: linkBe 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).