From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: from smtp1.axis.com (smtp1.axis.com [195.60.68.17]) by sourceware.org (Postfix) with ESMTPS id 4205B3858D3C for ; Mon, 14 Feb 2022 23:03:58 +0000 (GMT) DMARC-Filter: OpenDMARC Filter v1.4.1 sourceware.org 4205B3858D3C From: Hans-Peter Nilsson To: Subject: [PATCH 06/12] sim/testsuite: Support "requires: simoption <--name-of-option>" MIME-Version: 1.0 Content-Type: text/plain; charset="iso-8859-1" Content-Transfer-Encoding: 8BIT Message-ID: <20220214230356.BA97820439@pchp3.se.axis.com> Date: Tue, 15 Feb 2022 00:03:56 +0100 X-Spam-Status: No, score=-10.7 required=5.0 tests=BAYES_00, DKIM_SIGNED, DKIM_VALID, DKIM_VALID_AU, DKIM_VALID_EF, GIT_PATCH_0, RCVD_IN_MSPIKE_H2, SPF_HELO_PASS, SPF_PASS, TXREP, T_SCC_BODY_TEXT_LINE autolearn=ham autolearn_force=no version=3.4.4 X-Spam-Checker-Version: SpamAssassin 3.4.4 (2020-01-24) on server2.sourceware.org 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: , X-List-Received-Date: Mon, 14 Feb 2022 23:04:00 -0000 Simulator features can be present or not, typically depending on different-valued configure options, like --enable-sim-hardware[=off|=on]. To avoid failures in test-suite-runs when testing such configurations, a new predicate is needed, as neither "target", "progos" nor "mach" fits cleanly. The immediate need was to check for presence of a simulator option, but rather than a specialized "requires-simoption:" predicate I thought I'd handle the general (parametrized) need, so here's a generic predicate machinery and a (first) predicate to use together with it; checking whether a particular option is supported, by looking at "run --help" output. This was inspired by the check_effective_target_ machinery in the gcc test-suite. Multiple "requires: " form a list of predicates (with parameters), to be used as a conjunction. sim/testsuite: * lib/sim-defs.exp (sim_check_requires_simoption): New function. (run_sim_test): Support "requires: ". --- sim/testsuite/lib/sim-defs.exp | 60 ++++++++++++++++++++++++++++++++++ 1 file changed, 60 insertions(+) diff --git a/sim/testsuite/lib/sim-defs.exp b/sim/testsuite/lib/sim-defs.exp index 3586fa550765..d2750e08b046 100644 --- a/sim/testsuite/lib/sim-defs.exp +++ b/sim/testsuite/lib/sim-defs.exp @@ -261,6 +261,41 @@ proc sim_run { prog sim_opts prog_opts redir options } { return [list $return_code $output] } +# Support function for "#requires: simoption ": +# Looks in "run --help" output for , returns 1 iff is mentioned +# there and looks like an option name, otherwise 0. + +proc sim_check_requires_simoption { optname } { + global sim_path + set testrun "$sim_path --help" + verbose -log "Checking for simoption `$optname'" 3 + remote_spawn host $testrun + set result [remote_wait host 240] + + set return_code [lindex $result 0] + if { $return_code != 0 } { + perror "Can't execute `$testrun' to check for `$optname'" + return 0 + } + + set output [lindex $result 1] + # Remove \r as for regular runs. + regsub -all -- "\r" $output "" output + + # The option output format for --help for each line where an + # option name is mentioned, is assumed to be two space followed + # by the option name followed by a space or left square bracket, + # like in (optname=--foo): " --foo " or " --foo[this|that]". + # Beware not to match " --foo-bar" nor " --foobar". + if [string match "*\n $optname\[\[ \]*" $output] { + verbose -log "Found `$optname'" 3 + return 1 + } + verbose -log "Did not find `$optname'" 3 + + return 0 +} + # Run testcase NAME. # NAME is either a fully specified file name, or just the file name in which # case $srcdir/$subdir will be prepended. @@ -326,6 +361,7 @@ proc run_sim_test { name requested_machs } { set opts(cc) "" set opts(progopts) "" set opts(progos) "" + set opts(requires) {} set opts(sim) "" set opts(status) "0" set opts(output) "" @@ -375,6 +411,14 @@ proc run_sim_test { name requested_machs } { set opt_val "$opts($opt_name) $opt_val" } + # Similar for "requires", except we append a pair to a list, and + # that doesn't match the processing in the rest of the loop, so we + # "continue" early. + if { $opt_name == "requires" } { + lappend opts($opt_name) [split $opt_val " "] + continue + } + foreach m $opt_machs { set opts($opt_name,$m) $opt_val } @@ -449,6 +493,22 @@ proc run_sim_test { name requested_machs } { set opts(cc,$mach) $opts(cc) } + foreach req $opts(requires) { + set what [lindex $req 0] + set what_opt [lindex $req 1] + verbose -log "requires: <$what> <$what_opt>" + if { [info procs sim_check_requires_${what}] != [list] } { + if ![sim_check_requires_${what} $what_opt] { + untested $subdir/$name + return + } + } { + perror "unknown requirement `requires: $what' in file $file" + unresolved $subdir/$name + return + } + } + if [string match "*.c" $sourcefile] { # If we don't have a compiler available, skip tests :(. if { $global_cc_works == 0 } { -- 2.30.2