1 # Copyright (C) 2006-2019 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 3 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, see <http://www.gnu.org/licenses/>.
16 # Miscellaneous CRIS simulator testcases in assembly code, testing
17 # dv-rv.c and dv-cris.c functions.
19 # Check whether dv-rv and dv-cris are present.
21 proc sim_has_rv_and_cris {} {
25 global global_as_options
26 global global_ld_options
27 global global_sim_options
29 # We need to assemble and link a trivial program and pass that, in
30 # order to test successful exit.
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.
36 if ![info exists global_as_options] {
37 set global_as_options ""
39 if ![info exists global_ld_options] {
40 set global_ld_options ""
42 if ![info exists global_sim_options] {
43 set global_sim_options ""
46 set comp_output [target_assemble $srcdir/$subdir/quit.s quit.o \
47 "-I$srcdir/$subdir $global_as_options"]
49 if ![string match "" $comp_output] {
50 verbose -log "$comp_output" 3
51 fail "rv sim test setup (assembling)"
55 set comp_output [target_link quit.o quit.x "$global_ld_options"]
57 if ![string match "" $comp_output] {
58 verbose -log "$comp_output" 3
59 fail "rv sim test setup (linking)"
65 "$global_sim_options --hw-device rv --hw-device cris --hw-info" \
67 set return_code [lindex $result 0]
68 set output [lindex $result 1]
70 if { "$return_code" == "pass" } {
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 ":".
82 proc slurp_rv { file } {
83 if [catch { set f [open $file r] } x] {
84 #perror "couldn't open `$file': $x"
89 # whitespace expression
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.
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] {
100 lappend rv_array $cmd
112 # The main test loop.
114 if [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
121 set saved_global_sim_options $global_sim_options
122 set saved_global_ld_options $global_ld_options
124 # See the logic in sim-defs.exp for more details.
125 set sim [board_info target sim]
126 if [string equal "" $sim] {
129 set rvdummy "$objdir/../$arch/rvdummy"
131 set rvdummy "[file dirname [board_info target sim]]/rvdummy"
134 # All machines we test and the corresponding assembler option.
135 # We'll only ever test v10 and higher here.
137 set combos {{"crisv10" "--march=v10 --no-mul-bug-abort"}
138 {"crisv32" "--march=v32"}}
140 # We need to pass different assembler flags for each machine.
141 # Specifying it here rather than adding a specifier to each and every
142 # test-file is preferrable.
144 foreach combo $combos {
145 set mach [lindex $combo 0]
146 set ASFLAGS_FOR_TARGET "[lindex $combo 1]"
148 # The .ms suffix is for "miscellaneous .s".
149 foreach src [lsort [glob -nocomplain $srcdir/$subdir/*.ms]] {
151 # If we're only testing specific files and this isn't one of them,
153 if ![runtest_file_p $runtests $src] {
157 # Whoever runs the test should be alerted that not all
158 # testcases have been checked; that's why we do the loop
159 # and don't just return at the top.
160 if !$has_rv_and_cris {
165 set sim_defaults "--hw-file $srcdir/$subdir/std.dev"
166 set ld_defaults "--section-start=.text=0"
168 # We parse options an extra time besides in run_sim_test,
169 # to determine if our defaults should be overridden.
171 set opt_array [slurp_options $src]
172 foreach i $opt_array {
173 set opt_name [lindex $i 0]
174 set opt_machs [lindex $i 1]
175 set opt_val [lindex $i 2]
177 # Allow concatenating to the default options by
179 if { $opt_name == "sim" && $opt_machs == "" } {
183 if { $opt_name == "ld" && $opt_machs == "" } {
189 set hostcmds [slurp_rv $src]
191 if { $hostcmds != "" } {
192 # I guess we could ask to have rvdummy executed on a
193 # remote host, but it looks like too much trouble for
194 # a feature rarely used.
195 if [is_remote host] {
200 set src_components [file split $src]
201 set rvfile "[lindex $src_components \
202 [expr [llength $src_components] - 1]].r"
204 if [catch { set f [open $rvfile w] } x] {
207 set contents [join $hostcmds "\n"]
209 # Make it possible to use files from the test
210 # source directory; expected with the @-command.
211 regsub -all "@srcdir@" $contents "$srcdir/$subdir" contents
213 verbose "rv: $contents" 2
218 spawn -noecho $rvdummy "$rvfile"
219 if { $spawn_id < 0 } {
220 error "Couldn't spawn $rvdummy"
223 set rvdummy_id $spawn_id
226 # Unfortunately this seems like the only way to pass
227 # additional sim, ld etc. options to run_sim_test.
228 set global_sim_options "$saved_global_sim_options $sim_defaults"
229 set global_ld_options "$saved_global_ld_options $ld_defaults"
230 run_sim_test $src $mach
231 set global_sim_options $saved_global_sim_options
232 set global_ld_options $saved_global_ld_options
234 # Stop the rvdummy, if it's still running. We need to
235 # wait on it anyway to avoid it turning into a zombie.
236 if { $rvdummy_id != -1 } {
240 # Gleaned from framework.exp, this seems an indicator
241 # to whether the test had expected outcome. If so, we
242 # want to remove the rv-file.
243 if { $exit_status == 0 } {