summaryrefslogtreecommitdiff
path: root/sim
diff options
context:
space:
mode:
authorHans-Peter Nilsson <hp@axis.com>2022-02-14 23:50:48 +0100
committerHans-Peter Nilsson <hp@bitrange.com>2022-02-14 23:50:48 +0100
commit81064d7abc3c86cb93b12836eeaaf5a3fbce349e (patch)
tree794710802cf21bacedf2c94cb692a3d6752dde3d /sim
parent46f238477f5e83cba9dc79d1e14c0f6acbeda37b (diff)
sim/testsuite: Support "requires: simoption <--name-of-option>"
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: <requirement> <parameter>" 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: <requirement> <parameter>".
Diffstat (limited to 'sim')
-rw-r--r--sim/testsuite/lib/sim-defs.exp60
1 files changed, 60 insertions, 0 deletions
diff --git a/sim/testsuite/lib/sim-defs.exp b/sim/testsuite/lib/sim-defs.exp
index 3586fa5507..d2750e08b0 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 <xx>":
+# Looks in "run --help" output for <xx>, returns 1 iff <xx> 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 } {