From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: by sourceware.org (Postfix, from userid 1726) id 584773858284; Tue, 28 Feb 2023 11:09:25 +0000 (GMT) DKIM-Filter: OpenDKIM Filter v2.11.0 sourceware.org 584773858284 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=sourceware.org; s=default; t=1677582565; bh=RHFpKlAHcFmxEpEJbe0ZWUfMvssNBOUPl969/tnj0uU=; h=From:To:Subject:Date:From; b=YDvA++XTFd6UDtAYKCscI4IVsgQVoEwrRTy3uIfl4HiAi3NJlIKKCk8uyISu+u762 CQ9mAB1D7cdMVFrqSCFaQRPKN34iCTTqGyBE2tCVgnb0L4S35NcdXlgd3YpRGxmZX7 d03L3L8fGW1nUsuXL+skYcS8ltMwjt8FFyGz1EBo= Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: quoted-printable From: Andrew Burgess To: gdb-cvs@sourceware.org Subject: [binutils-gdb] gdb/testsuite introduce foreach_mi_ui_mode helper proc X-Act-Checkin: binutils-gdb X-Git-Author: Andrew Burgess X-Git-Refname: refs/heads/master X-Git-Oldrev: 1ccc4abbb3dda91c94c54d3aaaa417f0d7740a3f X-Git-Newrev: 292deeba7d6e0f1df99fff8c18000a1a3c481f3a Message-Id: <20230228110925.584773858284@sourceware.org> Date: Tue, 28 Feb 2023 11:09:25 +0000 (GMT) List-Id: https://sourceware.org/git/gitweb.cgi?p=3Dbinutils-gdb.git;h=3D292deeba7d6e= 0f1df99fff8c18000a1a3c481f3a commit 292deeba7d6e0f1df99fff8c18000a1a3c481f3a Author: Andrew Burgess Date: Fri Feb 17 15:19:12 2023 +0000 gdb/testsuite introduce foreach_mi_ui_mode helper proc =20 Introduce foreach_mi_ui_mode, a helper proc which can be used when tests are going to be repeated once with the MI in the main UI, and once with the MI on a separate UI. =20 The proc is used like this: =20 foreach_mi_ui_mode VAR { # BODY } =20 The BODY will be run twice, once with VAR set to 'main' and once with VAR set to 'separate', inside BODY we can then change the behaviour based on the current UI mode. =20 The point of this proc is that we sometimes shouldn't run the separate UI tests (when gdb_debug_enabled is true), and this proc hides all this logic. If the separate UI mode should not be used then BODY will be run just once with VAR set to 'main'. =20 I've updated two tests that can make use of this helper proc. I'm going to add another similar test in a later commit. =20 There should be no change to what is tested with this commit. =20 Approved-By: Pedro Alves Diff: --- gdb/testsuite/gdb.mi/mi-break.exp | 9 +------- gdb/testsuite/gdb.mi/mi-watch.exp | 9 +------- gdb/testsuite/lib/mi-support.exp | 44 +++++++++++++++++++++++++++++++++++= ++++ 3 files changed, 46 insertions(+), 16 deletions(-) diff --git a/gdb/testsuite/gdb.mi/mi-break.exp b/gdb/testsuite/gdb.mi/mi-br= eak.exp index 5b5d3aad2e4..3400e2e6f7c 100644 --- a/gdb/testsuite/gdb.mi/mi-break.exp +++ b/gdb/testsuite/gdb.mi/mi-break.exp @@ -419,13 +419,6 @@ proc test_break {mi_mode} { test_forced_conditions } =20 -if [gdb_debug_enabled] { - # gdb debug doesn't work for separate-mi-tty. - set modes {"main"} -} else { - set modes {"main" "separate"} -} - -foreach_with_prefix mi-mode $modes { +foreach_mi_ui_mode mi-mode { test_break ${mi-mode} } diff --git a/gdb/testsuite/gdb.mi/mi-watch.exp b/gdb/testsuite/gdb.mi/mi-wa= tch.exp index aaac7611015..12b9781e95a 100644 --- a/gdb/testsuite/gdb.mi/mi-watch.exp +++ b/gdb/testsuite/gdb.mi/mi-watch.exp @@ -175,16 +175,9 @@ proc test_watchpoint_all {mi_mode type} { test_watchpoint_triggering } =20 -if [gdb_debug_enabled] { - # gdb debug doesn't work for separate-mi-tty. - set modes {"main"} -} else { - set modes {"main" "separate"} -} - # Run the tests twice, once using software watchpoints, and another # with hardware watchpoints. -foreach_with_prefix mi-mode $modes { +foreach_mi_ui_mode mi-mode { foreach_with_prefix wp-type {"sw" "hw"} { test_watchpoint_all ${mi-mode} ${wp-type} } diff --git a/gdb/testsuite/lib/mi-support.exp b/gdb/testsuite/lib/mi-suppor= t.exp index cdebcc7d0f7..6454205e124 100644 --- a/gdb/testsuite/lib/mi-support.exp +++ b/gdb/testsuite/lib/mi-support.exp @@ -2795,3 +2795,47 @@ proc mi_get_valueof { fmt exp default {test ""} } { } return ${val} } + +# Some MI tests should be run in the normal way, on the main UI, while +# other tests should be run twice, once when the MI is on the main UI, +# and once with the MI on a secondary UI, this proc facilitates that. +# +# Use as: +# +# foreach_mi_ui_mode mode { +# # ... body ... +# } +# +# The BODY will then be run once with MODE set to 'main' and once with +# MODE set to 'separate'. +# +# However, there are times when we know using the 'separate' UI will +# not work. This proc handles figuring that out, if the 'separate' UI +# is known not to work then the 'separate' mode will be skipped and +# BODY will be run just once with MODE set to 'main'. + +proc foreach_mi_ui_mode { var_name body } { + upvar 1 $var_name var + + if [gdb_debug_enabled] { + # gdb debug doesn't work for separate-mi-tty. + set modes {"main"} + } else { + set modes {"main" "separate"} + } + + foreach var $modes { + with_test_prefix "$var_name=3D$var" { + set code [catch {uplevel 1 $body} result] + } + + if {$code =3D=3D 1} { + global errorInfo errorCode + return -code $code -errorinfo $errorInfo -errorcode $errorCode = $result + } elseif {$code =3D=3D 3} { + break + } elseif {$code =3D=3D 2} { + return -code $code $result + } + } +}