| 1 |
# Copyright (C) 2006-2024 Free Software Foundation, Inc. |
| 2 |
# |
| 3 |
# This program is free software; you can redistribute it and/or modify |
| 4 |
# it under the terms of the GNU General Public License as published by |
| 5 |
# the Free Software Foundation; either version 3 of the License, or |
| 6 |
# (at your option) any later version. |
| 7 |
# |
| 8 |
# This program is distributed in the hope that it will be useful, |
| 9 |
# but WITHOUT ANY WARRANTY; without even the implied warranty of |
| 10 |
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the |
| 11 |
# GNU General Public License for more details. |
| 12 |
# |
| 13 |
# You should have received a copy of the GNU General Public License |
| 14 |
# along with this program. If not, see <http://www.gnu.org/licenses/>. |
| 15 |
|
| 16 |
# Miscellaneous CRIS simulator testcases in assembly code, testing |
| 17 |
# dv-rv.c and dv-cris.c functions. |
| 18 |
|
| 19 |
sim_init |
| 20 |
|
| 21 |
# Check whether dv-rv and dv-cris are present. |
| 22 |
|
| 23 |
proc sim_has_rv_and_cris {} { |
| 24 |
global srcdir |
| 25 |
global subdir |
| 26 |
global objdir |
| 27 |
global sim_path |
| 28 |
global SIMFLAGS_FOR_TARGET |
| 29 |
|
| 30 |
if ![file exists $sim_path] { |
| 31 |
return 0 |
| 32 |
} |
| 33 |
|
| 34 |
# We need to assemble and link a trivial program and pass that, in |
| 35 |
# order to test successful exit. |
| 36 |
|
| 37 |
# A bit of duplication here for the assembling and linking part; |
| 38 |
# what we want to do it to run the simulator without affecting the |
| 39 |
# PASS/FAIL counters, and we can use e.g. run_sim_test for that. |
| 40 |
|
| 41 |
if ![info exists SIMFLAGS_FOR_TARGET] { |
| 42 |
set SIMFLAGS_FOR_TARGET "" |
| 43 |
} |
| 44 |
|
| 45 |
set comp_output [target_assemble $srcdir/$subdir/quit.s $objdir/quit.o \ |
| 46 |
"-I$srcdir/$subdir"] |
| 47 |
|
| 48 |
if ![string match "" $comp_output] { |
| 49 |
verbose -log "$comp_output" 3 |
| 50 |
fail "rv sim test setup (assembling)" |
| 51 |
return 0 |
| 52 |
} |
| 53 |
|
| 54 |
set comp_output [target_link $objdir/quit.o $objdir/quit.x ""] |
| 55 |
|
| 56 |
if ![string match "" $comp_output] { |
| 57 |
verbose -log "$comp_output" 3 |
| 58 |
fail "rv sim test setup (linking)" |
| 59 |
return 0 |
| 60 |
} |
| 61 |
|
| 62 |
set result \ |
| 63 |
[sim_run $objdir/quit.x \ |
| 64 |
"$SIMFLAGS_FOR_TARGET --hw-device rv --hw-device cris --hw-info" \ |
| 65 |
"" "" ""] |
| 66 |
set return_code [lindex $result 0] |
| 67 |
set output [lindex $result 1] |
| 68 |
|
| 69 |
if { $return_code == 0 } { |
| 70 |
return 1 |
| 71 |
} |
| 72 |
|
| 73 |
return 0 |
| 74 |
} |
| 75 |
|
| 76 |
# Similar to slurp_options, but lines are fixed format "^#r ..." (not |
| 77 |
# "^#{ws}*r:{ws}+" to avoid intruding on slurp_options syntax). Only |
| 78 |
# trailing whitespace of the "..." is trimmed. Beware that lines |
| 79 |
# including parameters may not contain ":". |
| 80 |
|
| 81 |
proc slurp_rv { file } { |
| 82 |
global subdir srcdir |
| 83 |
if [catch { set f [open $file r] } x] { |
| 84 |
#perror "couldn't open `$file': $x" |
| 85 |
perror "$x" |
| 86 |
return -1 |
| 87 |
} |
| 88 |
set rv_array {} |
| 89 |
# whitespace expression |
| 90 |
set ws {[ ]*} |
| 91 |
# whitespace is ignored at the end of a line. |
| 92 |
set pat "^#r (.*)$ws\$" |
| 93 |
# Allow arbitrary lines until the first option is seen. |
| 94 |
set seen_opt 0 |
| 95 |
while { [gets $f line] != -1 } { |
| 96 |
set line [string trim $line] |
| 97 |
# Whitespace here is space-tab. |
| 98 |
if [regexp $pat $line xxx cmd] { |
| 99 |
# match! |
| 100 |
set cmd [string map [list \ |
| 101 |
{$pwd} [pwd] \ |
| 102 |
{$srcdir} "$srcdir" \ |
| 103 |
{$subdir} "$subdir" \ |
| 104 |
] "$cmd"] |
| 105 |
lappend rv_array $cmd |
| 106 |
set seen_opt 1 |
| 107 |
} else { |
| 108 |
if { $seen_opt } { |
| 109 |
break |
| 110 |
} |
| 111 |
} |
| 112 |
} |
| 113 |
close $f |
| 114 |
return $rv_array |
| 115 |
} |
| 116 |
|
| 117 |
# The main test loop. |
| 118 |
|
| 119 |
if [istarget *] { |
| 120 |
global ASFLAGS_FOR_TARGET |
| 121 |
global LDFLAGS_FOR_TARGET |
| 122 |
global SIMFLAGS_FOR_TARGET |
| 123 |
set has_rv_and_cris [sim_has_rv_and_cris] |
| 124 |
|
| 125 |
global builddir |
| 126 |
set rvdummy "$builddir/cris/rvdummy" |
| 127 |
|
| 128 |
# All machines we test and the corresponding assembler option. |
| 129 |
# We'll only ever test v10 and higher here. |
| 130 |
|
| 131 |
set combos {{"crisv10" "--march=v10 --no-mul-bug-abort"} |
| 132 |
{"crisv32" "--march=v32"}} |
| 133 |
|
| 134 |
# We need to pass different assembler flags for each machine. |
| 135 |
# Specifying it here rather than adding a specifier to each and every |
| 136 |
# test-file is preferrable. |
| 137 |
|
| 138 |
foreach combo $combos { |
| 139 |
set mach [lindex $combo 0] |
| 140 |
set ASFLAGS_FOR_TARGET "[lindex $combo 1]" |
| 141 |
|
| 142 |
# The .ms suffix is for "miscellaneous .s". |
| 143 |
foreach src [lsort [glob -nocomplain $srcdir/$subdir/*.ms]] { |
| 144 |
|
| 145 |
# If we're only testing specific files and this isn't one of them, |
| 146 |
# skip it. |
| 147 |
if ![runtest_file_p $runtests $src] { |
| 148 |
continue |
| 149 |
} |
| 150 |
|
| 151 |
# Whoever runs the test should be alerted that not all |
| 152 |
# testcases have been checked; that's why we do the loop |
| 153 |
# and don't just return at the top. |
| 154 |
if !$has_rv_and_cris { |
| 155 |
untested $src |
| 156 |
continue |
| 157 |
} |
| 158 |
|
| 159 |
# Unfortunately this seems like the only way to pass |
| 160 |
# additional sim, ld etc. options to run_sim_test. |
| 161 |
set SIMFLAGS_FOR_TARGET "--hw-file $srcdir/$subdir/std.dev" |
| 162 |
set LDFLAGS_FOR_TARGET "--section-start=.text=0" |
| 163 |
|
| 164 |
# We parse options an extra time besides in run_sim_test, |
| 165 |
# to determine if our defaults should be overridden. |
| 166 |
|
| 167 |
set opt_array [slurp_options $src] |
| 168 |
foreach i $opt_array { |
| 169 |
set opt_name [lindex $i 0] |
| 170 |
set opt_machs [lindex $i 1] |
| 171 |
set opt_val [lindex $i 2] |
| 172 |
|
| 173 |
# Allow concatenating to the default options by |
| 174 |
# specifying a mach. |
| 175 |
if { $opt_name == "sim" && $opt_machs == "" } { |
| 176 |
set SIMFLAGS_FOR_TARGET "" |
| 177 |
} |
| 178 |
} |
| 179 |
|
| 180 |
set rvdummy_id -1 |
| 181 |
set hostcmds [slurp_rv $src] |
| 182 |
|
| 183 |
if { $hostcmds != "" } { |
| 184 |
# I guess we could ask to have rvdummy executed on a |
| 185 |
# remote host, but it looks like too much trouble for |
| 186 |
# a feature rarely used. |
| 187 |
if [is_remote host] { |
| 188 |
untested $src |
| 189 |
continue |
| 190 |
} |
| 191 |
|
| 192 |
set src_components [file split $src] |
| 193 |
set rvfile "[lindex $src_components \ |
| 194 |
[expr [llength $src_components] - 1]].r" |
| 195 |
|
| 196 |
if [catch { set f [open $rvfile w] } x] { |
| 197 |
error "$x" |
| 198 |
} { |
| 199 |
set contents [join $hostcmds "\n"] |
| 200 |
verbose "rv: $contents" 2 |
| 201 |
puts $f $contents |
| 202 |
close $f |
| 203 |
} |
| 204 |
|
| 205 |
spawn -noecho $rvdummy "$rvfile" |
| 206 |
if { $spawn_id < 0 } { |
| 207 |
error "Couldn't spawn $rvdummy" |
| 208 |
continue |
| 209 |
} |
| 210 |
set rvdummy_id $spawn_id |
| 211 |
} |
| 212 |
|
| 213 |
run_sim_test $src $mach |
| 214 |
|
| 215 |
# Stop the rvdummy, if it's still running. We need to |
| 216 |
# wait on it anyway to avoid it turning into a zombie. |
| 217 |
if { $rvdummy_id != -1 } { |
| 218 |
close -i $rvdummy_id |
| 219 |
wait -i $rvdummy_id |
| 220 |
|
| 221 |
# Gleaned from framework.exp, this seems an indicator |
| 222 |
# to whether the test had expected outcome. If so, we |
| 223 |
# want to remove the rv-file. |
| 224 |
if { $exit_status == 0 } { |
| 225 |
file delete $rvfile |
| 226 |
} |
| 227 |
} |
| 228 |
} |
| 229 |
} |
| 230 |
} |