From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: from mail-wr1-f51.google.com (mail-wr1-f51.google.com [209.85.221.51]) by sourceware.org (Postfix) with ESMTPS id 6B5BB3857352 for ; Wed, 22 Feb 2023 15:18:49 +0000 (GMT) DMARC-Filter: OpenDMARC Filter v1.4.2 sourceware.org 6B5BB3857352 Authentication-Results: sourceware.org; dmarc=none (p=none dis=none) header.from=palves.net Authentication-Results: sourceware.org; spf=pass smtp.mailfrom=gmail.com Received: by mail-wr1-f51.google.com with SMTP id p8so8232139wrt.12 for ; Wed, 22 Feb 2023 07:18:49 -0800 (PST) X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20210112; h=content-transfer-encoding:content-language:in-reply-to:mime-version :user-agent:date:message-id:from:references:to:subject :x-gm-message-state:from:to:cc:subject:date:message-id:reply-to; bh=0yge6d3s0wTqMtfQzo4gZzLVE+4PwB+AmgmEfLcTtwo=; b=Z6b+PXrqfcddgtKccE/hbCesniO5shZbdwmNQjuIU2XqKNCX4n6KJopJHUOW4SGfGP 7qdmi5w2L0t/vNhrcQq2Y2nws2qyPbLZbGJt4w/VucuMXa5IYSWaUXw2t5OaxbtEI1cp NcVksvI4PWt6O2TBNVqmSyPSYVpU2feIu5/Ui9TnNnawReyYXozOg6UkSwqxOEuk0mwp o3koQ7NUlyUo0iLYdQfN6v0ouqHqJptqXikaLhKij5MatZnPh02DvXIqlJskEkh2K2Ir cAuYWCM1AYbbzK4Rs9sfeD/e/ovtEvRl2rf1WGzHANUcKe9Ole04OoiLULGqs1jkVlkR 1taw== X-Gm-Message-State: AO0yUKUI54xjE/YZrlw7u/XWhTUeG1ModaRif21P9OsD10DIH2O91zu4 wrRelv8R3Qq6Z+JCMMWZVTCxw/GyqUdv2A== X-Google-Smtp-Source: AK7set+3cW1HXBL8KhWjfCpRxqEXaAx0RNa8IpqqTIMPifY++iyn4nX8qqf+gniM9dg435+Y84cAwA== X-Received: by 2002:adf:fb8d:0:b0:2c5:5391:8ab1 with SMTP id a13-20020adffb8d000000b002c553918ab1mr7744834wrr.53.1677079127651; Wed, 22 Feb 2023 07:18:47 -0800 (PST) Received: from ?IPv6:2001:8a0:f92b:9e00::1fe? ([2001:8a0:f92b:9e00::1fe]) by smtp.gmail.com with ESMTPSA id q15-20020a05600000cf00b002c559843748sm8776149wrx.10.2023.02.22.07.18.47 (version=TLS1_3 cipher=TLS_AES_128_GCM_SHA256 bits=128/128); Wed, 22 Feb 2023 07:18:47 -0800 (PST) Subject: Re: [PATCH 5/8] gdb/testsuite introduce foreach_mi_ui_mode helper proc To: Andrew Burgess , gdb-patches@sourceware.org References: <922925c1c55324deb567a51633fafc457afa381d.1676901929.git.aburgess@redhat.com> From: Pedro Alves Message-ID: <1e4b8581-9bf8-b421-bca9-b6a07df7ea70@palves.net> Date: Wed, 22 Feb 2023 15:18:45 +0000 User-Agent: Mozilla/5.0 (X11; Linux x86_64; rv:78.0) Gecko/20100101 Thunderbird/78.10.1 MIME-Version: 1.0 In-Reply-To: <922925c1c55324deb567a51633fafc457afa381d.1676901929.git.aburgess@redhat.com> Content-Type: text/plain; charset=utf-8 Content-Language: en-US Content-Transfer-Encoding: 7bit X-Spam-Status: No, score=-10.2 required=5.0 tests=BAYES_00,FREEMAIL_FORGED_FROMDOMAIN,FREEMAIL_FROM,GIT_PATCH_0,HEADER_FROM_DIFFERENT_DOMAINS,KAM_DMARC_STATUS,NICE_REPLY_A,RCVD_IN_DNSWL_NONE,RCVD_IN_MSPIKE_H2,SPF_HELO_NONE,SPF_PASS,TXREP autolearn=ham autolearn_force=no version=3.4.6 X-Spam-Checker-Version: SpamAssassin 3.4.6 (2021-04-09) on server2.sourceware.org List-Id: On 2023-02-20 2:13 p.m., Andrew Burgess via Gdb-patches wrote: > 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. > > The proc is used like this: > > foreach_mi_ui_mode VAR { > # BODY > } > > 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. > > 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'. > > 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. > > There should be no change to what is tested with this commit. > --- > 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-break.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 > } > > -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-watch.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 > } > > -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-support.exp > index 1a0dc584a4b..2ab751749e9 100644 > --- a/gdb/testsuite/lib/mi-support.exp > +++ b/gdb/testsuite/lib/mi-support.exp > @@ -2785,3 +2785,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 with then be run multiple times with MODE set to either > +# 'main' or 'separate'. "with then" -> "will then" ? "multiple times" gave me pause, like, it reads to me like this is saying that the body will be run multiple times with mode set to 'main', and then multiple times set to 'separate'. I think this would be improved by rephrasing it in way that it is clear the body will run at most once in each mode. Otherwise: Approved-By: Pedro Alves Thanks, Pedro Alves > +# > +# 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 > +# only 'main' will be run. > + > +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=$var" { > + set code [catch {uplevel 1 $body} result] > + } > + > + if {$code == 1} { > + global errorInfo errorCode > + return -code $code -errorinfo $errorInfo -errorcode $errorCode $result > + } elseif {$code == 3} { > + break > + } elseif {$code == 2} { > + return -code $code $result > + } > + } > +} >