1 # Copyright (C) 2006, 2007 Free Software Foundation, Inc.
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 2 of the License, or
6 # (at your option) any later version.
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.
13 # You should have received a copy of the GNU General Public License
14 # along with this program; if not, write to the Free Software
15 # Foundation, 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
17 # Miscellaneous CRIS simulator testcases in assembly code, testing
18 # dv-rv.c and dv-cris.c functions.
20 # Check whether dv-rv and dv-cris are present.
22 proc sim_has_rv_and_cris {} {
26 global global_as_options
27 global global_ld_options
28 global global_sim_options
30 # We need to assemble and link a trivial program and pass that, in
31 # order to test successful exit.
33 # A bit of duplication here for the assembling and linking part;
34 # what we want to do it to run the simulator without affecting the
35 # PASS/FAIL counters, and we can use e.g. run_sim_test for that.
37 if ![info exists global_as_options] {
38 set global_as_options ""
40 if ![info exists global_ld_options] {
41 set global_ld_options ""
43 if ![info exists global_sim_options] {
44 set global_sim_options ""
47 set comp_output [target_assemble $srcdir/$subdir/quit.s quit.o \
48 "-I$srcdir/$subdir $global_as_options"]
50 if ![string match "" $comp_output] {
51 verbose -log "$comp_output" 3
52 fail "rv sim test setup (assembling)"
56 set comp_output [target_link quit.o quit.x "$global_ld_options"]
58 if ![string match "" $comp_output] {
59 verbose -log "$comp_output" 3
60 fail "rv sim test setup (linking)"
66 "$global_sim_options --hw-device rv --hw-device cris --hw-info" \
68 set return_code [lindex $result 0]
69 set output [lindex $result 1]
71 if { "$return_code" == "pass" } {
78 # Similar to slurp_options, but lines are fixed format "^#r ..." (not
79 # "^#{ws}*r:{ws}+" to avoid intruding on slurp_options syntax). Only
80 # trailing whitespace of the "..." is trimmed. Beware that lines
81 # including parameters may not contain ":".
83 proc slurp_rv { file } {
84 if [catch { set f [open $file r] } x] {
85 #perror "couldn't open `$file': $x"
90 # whitespace expression
92 # whitespace is ignored at the end of a line.
93 set pat "^#r (.*)$ws\$"
94 # Allow arbitrary lines until the first option is seen.
96 while { [gets $f line] != -1 } {
97 set line [string trim $line]
98 # Whitespace here is space-tab.
99 if [regexp $pat $line xxx cmd] {
101 lappend rv_array $cmd
113 # The main test loop.
115 if [istarget cris*-*-*] {
116 global ASFLAGS_FOR_TARGET
117 set has_rv_and_cris [sim_has_rv_and_cris]
118 global global_as_options
119 global global_ld_options
120 global global_sim_options
122 set saved_global_sim_options $global_sim_options
123 set saved_global_ld_options $global_ld_options
124 set rvdummy "[file dirname [board_info target sim]]/rvdummy"
126 # All machines we test and the corresponding assembler option.
127 # We'll only ever test v10 and higher here.
129 set combos {{"crisv10" "--march=v10 --no-mul-bug-abort"}
130 {"crisv32" "--march=v32"}}
132 # We need to pass different assembler flags for each machine.
133 # Specifying it here rather than adding a specifier to each and every
134 # test-file is preferrable.
136 foreach combo $combos {
137 set mach [lindex $combo 0]
138 set ASFLAGS_FOR_TARGET "[lindex $combo 1]"
140 # The .ms suffix is for "miscellaneous .s".
141 foreach src [lsort [glob -nocomplain $srcdir/$subdir/*.ms]] {
143 # If we're only testing specific files and this isn't one of them,
145 if ![runtest_file_p $runtests $src] {
149 # Whoever runs the test should be alerted that not all
150 # testcases have been checked; that's why we do the loop
151 # and don't just return at the top.
152 if !$has_rv_and_cris {
157 set sim_defaults "--hw-file $srcdir/$subdir/std.dev"
158 set ld_defaults "--section-start=.text=0"
160 # We parse options an extra time besides in run_sim_test,
161 # to determine if our defaults should be overridden.
163 set opt_array [slurp_options $src]
164 foreach i $opt_array {
165 set opt_name [lindex $i 0]
166 set opt_machs [lindex $i 1]
167 set opt_val [lindex $i 2]
169 # Allow concatenating to the default options by
171 if { $opt_name == "sim" && $opt_machs == "" } {
175 if { $opt_name == "ld" && $opt_machs == "" } {
181 set hostcmds [slurp_rv $src]
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] {
192 set src_components [file split $src]
193 set rvfile "[lindex $src_components \
194 [expr [llength $src_components] - 1]].r"
196 if [catch { set f [open $rvfile w] } x] {
199 set contents [join $hostcmds "\n"]
201 # Make it possible to use files from the test
202 # source directory; expected with the @-command.
203 regsub -all "@srcdir@" $contents "$srcdir/$subdir" contents
205 verbose "rv: $contents" 2
210 spawn -noecho $rvdummy "$rvfile"
211 if { $spawn_id < 0 } {
212 error "Couldn't spawn $rvdummy"
215 set rvdummy_id $spawn_id
218 # Unfortunately this seems like the only way to pass
219 # additional sim, ld etc. options to run_sim_test.
220 set global_sim_options "$saved_global_sim_options $sim_defaults"
221 set global_ld_options "$saved_global_ld_options $ld_defaults"
222 run_sim_test $src $mach
223 set global_sim_options $saved_global_sim_options
224 set global_ld_options $saved_global_ld_options
226 # Stop the rvdummy, if it's still running. We need to
227 # wait on it anyway to avoid it turning into a zombie.
228 if { $rvdummy_id != -1 } {
232 # Gleaned from framework.exp, this seems an indicator
233 # to whether the test had expected outcome. If so, we
234 # want to remove the rv-file.
235 if { $exit_status == 0 } {