]> git.ipfire.org Git - thirdparty/binutils-gdb.git/commitdiff
sim: testsuite: allow tests to declare expected exit status
authorMike Frysinger <vapier@gentoo.org>
Tue, 5 Jan 2021 06:26:21 +0000 (01:26 -0500)
committerMike Frysinger <vapier@gentoo.org>
Fri, 15 Jan 2021 06:33:35 +0000 (01:33 -0500)
Some tests want to verify they can control the exit status, and
allowing any non-zero value would allow tests to silently fail:
if it crashed & exited 1, or forced all non-zero to 1, then we
wouldn't be able to differentiate with a test exiting with a
status like 47.

Extend the test harness to allow tests to declare their expected
exit status that would be defined as a "pass".  This requires a
small tweak to the sim_run API to return the status directly, but
that shouldn't be a big deal as it's only used by sim code.

sim/testsuite/ChangeLog
sim/testsuite/lib/sim-defs.exp
sim/testsuite/sim/cris/ChangeLog
sim/testsuite/sim/cris/c/c.exp
sim/testsuite/sim/cris/hw/rv-n-cris/rvc.exp

index a32672a46beacf45a8e83b0c3c62ecfd2eeda9e6..1245ab46086c7ef27d60c9bbb6e118a558803961 100644 (file)
@@ -1,3 +1,9 @@
+2021-01-15  Mike Frysinger  <vapier@gentoo.org>
+
+       * lib/sim-defs.exp (sim_run): Delete status and return return_code.
+       (run_sim_test): Define status option.  Change sim_run return to
+       return_code.  Define status.  Log return_code.
+
 2021-01-11  Mike Frysinger  <vapier@gentoo.org>
 
        * common/alu-tst.c: Include stdlib.h.
index b8ce230f13c375f2ee6085080d6522f24d65575d..43a07050f50830d9adc1d737350bbca81ac8f02e 100644 (file)
@@ -62,7 +62,7 @@ proc sim_compile { source dest type options } {
 #      timeout=val     - set the timeout to val for this run
 #
 # The result is a list of two elements.
-# The first is one of pass/fail/etc.
+# The first is the program's exit status (0/1/etc...).
 # The second is the program's output.
 #
 # This is different than the sim_load routine provided by
@@ -156,15 +156,7 @@ proc sim_run { prog sim_opts prog_opts redir options } {
        remote_file host delete $prog
     }
 
-    # ??? Not sure the test for pass/fail is right.
-    # We just care that the simulator ran correctly, not whether the simulated
-    # program return 0 or non-zero from `main'.
-    set status fail
-    if { $return_code == 0 } {
-       set status pass
-    }
-
-    return [list $status $output]
+    return [list $return_code $output]
 }
 
 # Run testcase NAME.
@@ -183,6 +175,7 @@ proc sim_run { prog sim_opts prog_opts redir options } {
 # cc[(mach-list)]: <compiler options>
 # sim[(mach-list)]: <simulator options>
 # progopts: <arguments to the program being simulated>
+# status: program exit status to treat as "pass"
 # output: program output pattern to match with string-match
 # xerror: program is expected to return with a "failure" exit code
 # xfail: <PRMS-opt> <target-triplets-where-test-fails>
@@ -223,6 +216,7 @@ proc run_sim_test { name requested_machs } {
     set opts(cc) ""
     set opts(progopts) ""
     set opts(sim) ""
+    set opts(status) "0"
     set opts(output) ""
     set opts(mach) ""
     set opts(timeout) ""
@@ -385,15 +379,21 @@ proc run_sim_test { name requested_machs } {
        }
 
        set result [sim_run ${name}.x "$opts(sim,$mach) $global_sim_options" "$opts(progopts)" "" "$options"]
-       set status [lindex $result 0]
+       set return_code [lindex $result 0]
        set output [lindex $result 1]
 
+       set status fail
+       if { $return_code == $opts(status) } {
+           set status pass
+       }
+
        if { "$status" == "pass" } {
            if { "$opts(xerror)" == "no" } {
                if [string match $opts(output) $output] {
                    pass "$mach $testname"
                    file delete ${name}.o ${name}.x
                } else {
+                   verbose -log "status:  $return_code" 3
                    verbose -log "output:  $output" 3
                    verbose -log "pattern: $opts(output)" 3
                    fail "$mach $testname (execution)"
@@ -410,6 +410,7 @@ proc run_sim_test { name requested_machs } {
                    pass "$mach $testname"
                    file delete ${name}.o ${name}.x
                } else {
+                   verbose -log "status:  $return_code" 3
                    verbose -log "output:  $output" 3
                    verbose -log "pattern: $opts(output)" 3
                    fail "$mach $testname (execution)"
index 9cfffd1d869c62eb452b06b837c15d72b7d1fd30..16c7c27ad4f8e2fc27b7c7b6bf9d6a32f80ff9f9 100644 (file)
@@ -1,3 +1,10 @@
+2021-01-15  Mike Frysinger  <vapier@gentoo.org>
+
+       * c/c.exp: Change sim_run return to return_code.  Set status to
+       pass/fail based on return_code.
+       * hw/rv-n-cris/rvc.exp (sim_has_rv_and_cris): Compare return_code
+       to 0.
+
 2021-01-09  Mike Frysinger  <vapier@gentoo.org>
 
        * readlink4.c (main): Change rindex to strrchr.
index 034c4bfd8f74c3989432272b8c29a87c1775930b..08ea18812ec5bd655556d0db2877eb5ebefe5d39 100644 (file)
@@ -214,9 +214,14 @@ foreach src [lsort [glob -nocomplain $srcdir/$subdir/*.c]] {
 
     set result [sim_run $dest "$opts(sim,$mach)" "$opts(progoptions)" \
        "" "$opts(simenv)"]
-    set status [lindex $result 0]
+    set return_code [lindex $result 0]
     set output [lindex $result 1]
 
+    set status fail
+    if { $return_code == 0 } {
+       set status pass
+    }
+
     if { "$status" == "pass" } {
        if { "$opts(xerror)" == "no" } {
            if [string match $opts(output) $output] {
index 98fc717ed7619c335e09ee19d0fd56adec183092..0f9ecec32a26e83e54401329d730645bfbe6b2a0 100644 (file)
@@ -67,7 +67,7 @@ proc sim_has_rv_and_cris {} {
     set return_code [lindex $result 0]
     set output [lindex $result 1]
 
-    if { "$return_code" == "pass" } {
+    if { $return_code == 0 } {
        return 1
     }