1# Copyright (C) 2006, 2007 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# Check whether dv-rv and dv-cris are present. 20 21proc sim_has_rv_and_cris {} { 22 global srcdir 23 global subdir 24 global SIMFLAGS 25 global global_as_options 26 global global_ld_options 27 global global_sim_options 28 29 # We need to assemble and link a trivial program and pass that, in 30 # order to test successful exit. 31 32 # A bit of duplication here for the assembling and linking part; 33 # what we want to do it to run the simulator without affecting the 34 # PASS/FAIL counters, and we can use e.g. run_sim_test for that. 35 36 if ![info exists global_as_options] { 37 set global_as_options "" 38 } 39 if ![info exists global_ld_options] { 40 set global_ld_options "" 41 } 42 if ![info exists global_sim_options] { 43 set global_sim_options "" 44 } 45 46 set comp_output [target_assemble $srcdir/$subdir/quit.s quit.o \ 47 "-I$srcdir/$subdir $global_as_options"] 48 49 if ![string match "" $comp_output] { 50 verbose -log "$comp_output" 3 51 fail "rv sim test setup (assembling)" 52 return 0 53 } 54 55 set comp_output [target_link quit.o quit.x "$global_ld_options"] 56 57 if ![string match "" $comp_output] { 58 verbose -log "$comp_output" 3 59 fail "rv sim test setup (linking)" 60 return 0 61 } 62 63 set result \ 64 [sim_run quit.x \ 65 "$global_sim_options --hw-device rv --hw-device cris --hw-info" \ 66 "" "" ""] 67 set return_code [lindex $result 0] 68 set output [lindex $result 1] 69 70 if { "$return_code" == "pass" } { 71 return 1 72 } 73 74 return 0 75} 76 77# Similar to slurp_options, but lines are fixed format "^#r ..." (not 78# "^#{ws}*r:{ws}+" to avoid intruding on slurp_options syntax). Only 79# trailing whitespace of the "..." is trimmed. Beware that lines 80# including parameters may not contain ":". 81 82proc slurp_rv { file } { 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 lappend rv_array $cmd 101 set seen_opt 1 102 } else { 103 if { $seen_opt } { 104 break 105 } 106 } 107 } 108 close $f 109 return $rv_array 110} 111 112# The main test loop. 113 114if [istarget cris*-*-*] { 115 global ASFLAGS_FOR_TARGET 116 set has_rv_and_cris [sim_has_rv_and_cris] 117 global global_as_options 118 global global_ld_options 119 global global_sim_options 120 121 set saved_global_sim_options $global_sim_options 122 set saved_global_ld_options $global_ld_options 123 set rvdummy "[file dirname [board_info target sim]]/rvdummy" 124 125 # All machines we test and the corresponding assembler option. 126 # We'll only ever test v10 and higher here. 127 128 set combos {{"crisv10" "--march=v10 --no-mul-bug-abort"} 129 {"crisv32" "--march=v32"}} 130 131 # We need to pass different assembler flags for each machine. 132 # Specifying it here rather than adding a specifier to each and every 133 # test-file is preferrable. 134 135 foreach combo $combos { 136 set mach [lindex $combo 0] 137 set ASFLAGS_FOR_TARGET "[lindex $combo 1]" 138 139 # The .ms suffix is for "miscellaneous .s". 140 foreach src [lsort [glob -nocomplain $srcdir/$subdir/*.ms]] { 141 142 # If we're only testing specific files and this isn't one of them, 143 # skip it. 144 if ![runtest_file_p $runtests $src] { 145 continue 146 } 147 148 # Whoever runs the test should be alerted that not all 149 # testcases have been checked; that's why we do the loop 150 # and don't just return at the top. 151 if !$has_rv_and_cris { 152 untested $src 153 continue 154 } 155 156 set sim_defaults "--hw-file $srcdir/$subdir/std.dev" 157 set ld_defaults "--section-start=.text=0" 158 159 # We parse options an extra time besides in run_sim_test, 160 # to determine if our defaults should be overridden. 161 162 set opt_array [slurp_options $src] 163 foreach i $opt_array { 164 set opt_name [lindex $i 0] 165 set opt_machs [lindex $i 1] 166 set opt_val [lindex $i 2] 167 168 # Allow concatenating to the default options by 169 # specifying a mach. 170 if { $opt_name == "sim" && $opt_machs == "" } { 171 set sim_defaults "" 172 } 173 174 if { $opt_name == "ld" && $opt_machs == "" } { 175 set ld_defaults "" 176 } 177 } 178 179 set rvdummy_id -1 180 set hostcmds [slurp_rv $src] 181 182 if { $hostcmds != "" } { 183 # I guess we could ask to have rvdummy executed on a 184 # remote host, but it looks like too much trouble for 185 # a feature rarely used. 186 if [is_remote host] { 187 untested $src 188 continue 189 } 190 191 set src_components [file split $src] 192 set rvfile "[lindex $src_components \ 193 [expr [llength $src_components] - 1]].r" 194 195 if [catch { set f [open $rvfile w] } x] { 196 error "$x" 197 } { 198 set contents [join $hostcmds "\n"] 199 200 # Make it possible to use files from the test 201 # source directory; expected with the @-command. 202 regsub -all "@srcdir@" $contents "$srcdir/$subdir" contents 203 204 verbose "rv: $contents" 2 205 puts $f $contents 206 close $f 207 } 208 209 spawn -noecho $rvdummy "$rvfile" 210 if { $spawn_id < 0 } { 211 error "Couldn't spawn $rvdummy" 212 continue 213 } 214 set rvdummy_id $spawn_id 215 } 216 217 # Unfortunately this seems like the only way to pass 218 # additional sim, ld etc. options to run_sim_test. 219 set global_sim_options "$saved_global_sim_options $sim_defaults" 220 set global_ld_options "$saved_global_ld_options $ld_defaults" 221 run_sim_test $src $mach 222 set global_sim_options $saved_global_sim_options 223 set global_ld_options $saved_global_ld_options 224 225 # Stop the rvdummy, if it's still running. We need to 226 # wait on it anyway to avoid it turning into a zombie. 227 if { $rvdummy_id != -1 } { 228 close -i $rvdummy_id 229 wait -i $rvdummy_id 230 231 # Gleaned from framework.exp, this seems an indicator 232 # to whether the test had expected outcome. If so, we 233 # want to remove the rv-file. 234 if { $exit_status == 0 } { 235 file delete $rvfile 236 } 237 } 238 } 239 } 240} 241