diff options
author | Tom de Vries <tdevries@suse.de> | 2022-10-14 13:09:50 +0200 |
---|---|---|
committer | Tom de Vries <tdevries@suse.de> | 2022-10-14 13:09:50 +0200 |
commit | 1e4be05b752cc94019ed12d6d305e13e55530724 (patch) | |
tree | 194f86c0fb404c22f78b92c184bba71ced0d948f | |
parent | 2ff50ff02d99b27b6b2069c931f759d86afdbbe2 (diff) | |
download | gdb-1e4be05b752cc94019ed12d6d305e13e55530724.zip gdb-1e4be05b752cc94019ed12d6d305e13e55530724.tar.gz gdb-1e4be05b752cc94019ed12d6d305e13e55530724.tar.bz2 |
[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.
-rw-r--r-- | gdb/testsuite/gdb.testsuite/cond-wrap.exp | 43 | ||||
-rw-r--r-- | gdb/testsuite/lib/gdb.exp | 20 |
2 files changed, 63 insertions, 0 deletions
diff --git a/gdb/testsuite/gdb.testsuite/cond-wrap.exp b/gdb/testsuite/gdb.testsuite/cond-wrap.exp new file mode 100644 index 0000000..7feb88b --- /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 61bc060..3049a73 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 } { |