Automatic Copyright Year update after running gdb/copyright.py
[deliverable/binutils-gdb.git] / sim / testsuite / cris / hw / rv-n-cris / rvc.exp
CommitLineData
88b9d363 1# Copyright (C) 2006-2022 Free Software Foundation, Inc.
26d01138
HPN
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
4744ac1b 5# the Free Software Foundation; either version 3 of the License, or
26d01138
HPN
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
4744ac1b 14# along with this program. If not, see <http://www.gnu.org/licenses/>.
26d01138
HPN
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
37a9c3a5 70 if { $return_code == 0 } {
26d01138
HPN
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
d4a587a4
MF
123
124 # See the logic in sim-defs.exp for more details.
125 set sim [board_info target sim]
126 if [string equal "" $sim] {
127 global objdir
23cb7bac 128 set rvdummy "$objdir/cris/rvdummy"
d4a587a4
MF
129 } else {
130 set rvdummy "[file dirname [board_info target sim]]/rvdummy"
131 }
26d01138
HPN
132
133 # All machines we test and the corresponding assembler option.
134 # We'll only ever test v10 and higher here.
135
136 set combos {{"crisv10" "--march=v10 --no-mul-bug-abort"}
137 {"crisv32" "--march=v32"}}
138
139 # We need to pass different assembler flags for each machine.
140 # Specifying it here rather than adding a specifier to each and every
141 # test-file is preferrable.
142
143 foreach combo $combos {
144 set mach [lindex $combo 0]
145 set ASFLAGS_FOR_TARGET "[lindex $combo 1]"
146
147 # The .ms suffix is for "miscellaneous .s".
148 foreach src [lsort [glob -nocomplain $srcdir/$subdir/*.ms]] {
149
150 # If we're only testing specific files and this isn't one of them,
151 # skip it.
152 if ![runtest_file_p $runtests $src] {
153 continue
154 }
155
156 # Whoever runs the test should be alerted that not all
157 # testcases have been checked; that's why we do the loop
158 # and don't just return at the top.
159 if !$has_rv_and_cris {
160 untested $src
161 continue
162 }
163
164 set sim_defaults "--hw-file $srcdir/$subdir/std.dev"
165 set ld_defaults "--section-start=.text=0"
166
167 # We parse options an extra time besides in run_sim_test,
168 # to determine if our defaults should be overridden.
169
170 set opt_array [slurp_options $src]
171 foreach i $opt_array {
172 set opt_name [lindex $i 0]
173 set opt_machs [lindex $i 1]
174 set opt_val [lindex $i 2]
175
176 # Allow concatenating to the default options by
177 # specifying a mach.
178 if { $opt_name == "sim" && $opt_machs == "" } {
179 set sim_defaults ""
180 }
181
182 if { $opt_name == "ld" && $opt_machs == "" } {
183 set ld_defaults ""
184 }
185 }
186
187 set rvdummy_id -1
188 set hostcmds [slurp_rv $src]
189
190 if { $hostcmds != "" } {
191 # I guess we could ask to have rvdummy executed on a
192 # remote host, but it looks like too much trouble for
193 # a feature rarely used.
194 if [is_remote host] {
195 untested $src
196 continue
197 }
198
199 set src_components [file split $src]
200 set rvfile "[lindex $src_components \
201 [expr [llength $src_components] - 1]].r"
202
203 if [catch { set f [open $rvfile w] } x] {
204 error "$x"
205 } {
206 set contents [join $hostcmds "\n"]
207
208 # Make it possible to use files from the test
209 # source directory; expected with the @-command.
210 regsub -all "@srcdir@" $contents "$srcdir/$subdir" contents
211
212 verbose "rv: $contents" 2
213 puts $f $contents
214 close $f
215 }
216
217 spawn -noecho $rvdummy "$rvfile"
218 if { $spawn_id < 0 } {
219 error "Couldn't spawn $rvdummy"
220 continue
221 }
222 set rvdummy_id $spawn_id
223 }
224
225 # Unfortunately this seems like the only way to pass
226 # additional sim, ld etc. options to run_sim_test.
227 set global_sim_options "$saved_global_sim_options $sim_defaults"
228 set global_ld_options "$saved_global_ld_options $ld_defaults"
229 run_sim_test $src $mach
230 set global_sim_options $saved_global_sim_options
231 set global_ld_options $saved_global_ld_options
232
233 # Stop the rvdummy, if it's still running. We need to
234 # wait on it anyway to avoid it turning into a zombie.
235 if { $rvdummy_id != -1 } {
236 close -i $rvdummy_id
237 wait -i $rvdummy_id
238
239 # Gleaned from framework.exp, this seems an indicator
240 # to whether the test had expected outcome. If so, we
241 # want to remove the rv-file.
242 if { $exit_status == 0 } {
243 file delete $rvfile
244 }
245 }
246 }
247 }
248}
This page took 0.933266 seconds and 4 git commands to generate.