From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: from simark.ca by simark.ca with LMTP id 26dXE7pDSWOMJwwAWB0awg (envelope-from ) for ; Fri, 14 Oct 2022 07:10:50 -0400 Received: by simark.ca (Postfix, from userid 112) id 3FF461E112; Fri, 14 Oct 2022 07:10:50 -0400 (EDT) Authentication-Results: simark.ca; dkim=pass (1024-bit key; secure) header.d=sourceware.org header.i=@sourceware.org header.a=rsa-sha256 header.s=default header.b=djZVTGmB; dkim-atps=neutral X-Spam-Checker-Version: SpamAssassin 3.4.6 (2021-04-09) on simark.ca X-Spam-Level: X-Spam-Status: No, score=-3.0 required=5.0 tests=BAYES_00,DKIM_SIGNED, DKIM_VALID,DKIM_VALID_AU,MAILING_LIST_MULTI,URIBL_BLOCKED autolearn=ham autolearn_force=no version=3.4.6 Received: from sourceware.org (server2.sourceware.org [8.43.85.97]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits) key-exchange X25519 server-signature RSA-PSS (2048 bits) server-digest SHA256) (No client certificate requested) by simark.ca (Postfix) with ESMTPS id 51FE01E0D5 for ; Fri, 14 Oct 2022 07:10:49 -0400 (EDT) Received: from server2.sourceware.org (localhost [IPv6:::1]) by sourceware.org (Postfix) with ESMTP id ABD20386074A for ; Fri, 14 Oct 2022 11:10:48 +0000 (GMT) DKIM-Filter: OpenDKIM Filter v2.11.0 sourceware.org ABD20386074A DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=sourceware.org; s=default; t=1665745848; bh=aY+lSv0CsA9kGJMczTj+oGtFCbsN9HHzOGccwpnzhgY=; h=Date:To:Subject:List-Id:List-Unsubscribe:List-Archive:List-Post: List-Help:List-Subscribe:From:Reply-To:From; b=djZVTGmBsbH+Mj+2fdRf2zL1hcc5/ZCukBc28vhPjhueSNAI+pamPiVCqCJt5IAbR 7h9L0Z2IENvaQAhJXR2xeHxuHwHSu+cisjAMd//0qwP6giBI9R2IsZeCxniE54mZaN DcZZpVGeG14fKQfZc4dpMluT2aqm1+n498ksUmOc= Received: from smtp-out2.suse.de (smtp-out2.suse.de [195.135.220.29]) by sourceware.org (Postfix) with ESMTPS id 6302D3858C83 for ; Fri, 14 Oct 2022 11:10:16 +0000 (GMT) DMARC-Filter: OpenDMARC Filter v1.4.1 sourceware.org 6302D3858C83 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-out2.suse.de (Postfix) with ESMTPS id 8AF7C1F385 for ; Fri, 14 Oct 2022 11:10:15 +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 7969E13451 for ; Fri, 14 Oct 2022 11:10:15 +0000 (UTC) Received: from dovecot-director2.suse.de ([192.168.254.65]) by imap2.suse-dmz.suse.de with ESMTPSA id oC+fHJdDSWM9WgAAMHmgww (envelope-from ) for ; Fri, 14 Oct 2022 11:10:15 +0000 Date: Fri, 14 Oct 2022 13:10:14 +0200 To: gdb-patches@sourceware.org Subject: [committed][gdb/testsuite] Add cond_wrap proc Message-ID: <20221014111012.GA11100@delia.home> MIME-Version: 1.0 Content-Type: text/plain; charset=us-ascii Content-Disposition: inline User-Agent: Mutt/1.10.1 (2018-07-13) 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: , From: Tom de Vries via Gdb-patches Reply-To: Tom de Vries Errors-To: gdb-patches-bounces+public-inbox=simark.ca@sourceware.org Sender: "Gdb-patches" Hi, Add a new proc cond_wrap, that can be used to replace the repetitive: ... if { $cond } { wrap { } } else { } ... with the shorter: ... cond_wrap $cond wrap { } ... Tested on x86_64-linux. Committed to trunk. Thanks, - Tom [gdb/testsuite] Add cond_wrap proc --- 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 . + +# 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 } {