AArch64: Add MTE ptrace requests
[binutils-gdb.git] / sim / testsuite / lib / sim-defs.exp
index c8093a25566ffd67ca6c008e86091c0fbffeffe8..0157f9bb2834576b0866a5601261bbea653d2b7d 100644 (file)
@@ -1,4 +1,5 @@
 # Simulator dejagnu utilities.
+# TODO: Switch to using dg-xxx helpers rather than parsing the files directly.
 
 # Communicate simulator path from sim_init to sim_version.
 # For some reason [board_info target sim] doesn't work in sim_version.
@@ -12,6 +13,16 @@ proc sim_init { args } {
     global sim_path
     set sim_path [board_info target sim]
     # Need to return an empty string (copied from GAS).
+
+    # As gross as it is, we unset the linker script specified by the target
+    # board.  The simulator board file mips-sim.exp, sets ldscript to the
+    # MIPS libgloss linker scripts which include libgcc (and possibly other
+    # libraries), which the linker (used to link these tests rather than the
+    # compiler) can't necessarily find.  Similarly iq2000-sim.exp and
+    # m68hc11-sim.exp.  So, we make it a common rule to clear the slate for
+    # all simulators.
+    unset_currtarget_info ldscript
+
     return ""
 }
 
@@ -51,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
@@ -95,7 +106,7 @@ proc sim_run { prog sim_opts prog_opts redir options } {
        # These global variables come from generated site.exp.
        global objdir
        global arch
-       set sim "$objdir/../$arch/run"
+       set sim "$objdir/$arch/run"
     }
 
     if [is_remote host] {
@@ -145,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.
@@ -172,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>
@@ -212,12 +216,14 @@ 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) ""
     set opts(xerror) "no"
     set opts(xfail) ""
     set opts(kfail) ""
+    set seen_output 0
 
     if ![info exists global_as_options] {
         set global_as_options ""
@@ -260,6 +266,7 @@ proc run_sim_test { name requested_machs } {
        # Multiple "output" specifications concatenate, they don't override.
        if { $opt_name == "output" } {
            set opt_val "$opts(output)$opt_val"
+           set seen_output 1
        }
        # Similar with "xfail" and "kfail", but arguments are space-separated.
        if { $opt_name == "xfail" || $opt_name == "kfail" } {
@@ -276,7 +283,7 @@ proc run_sim_test { name requested_machs } {
 
     set testname $name
     set sourcefile $file
-    if { $opts(output) == "" } {
+    if { $seen_output == 0 } {
        if { "$opts(xerror)" == "no" } {
            set opts(output) "pass\n"
        } else {
@@ -372,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)"
@@ -397,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)"
@@ -411,6 +425,7 @@ proc run_sim_test { name requested_machs } {
 # Subroutine of run_sim_test to process options in FILE.
 
 proc slurp_options { file } {
+    global subdir srcdir
     if [catch { set f [open $file r] } x] {
        #perror "couldn't open `$file': $x"
        perror "$x"
@@ -430,6 +445,10 @@ proc slurp_options { file } {
        # Whitespace here is space-tab.
        if [regexp $pat $line xxx opt_name opt_machs opt_val] {
            # match!
+           set opt_val [string map [list \
+               {$srcdir} "$srcdir" \
+               {$subdir} "$subdir" \
+           ] "$opt_val"]
            lappend opt_array [list $opt_name $opt_machs $opt_val]
            set seen_opt 1
        } else {