]>
Commit | Line | Data |
---|---|---|
e2882c85 | 1 | # Copyright (C) 2006-2018 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 | ||
21 | proc 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 | ||
82 | proc 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 | ||
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 | |
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 | |
128 | global arch | |
129 | set rvdummy "$objdir/../$arch/rvdummy" | |
130 | } else { | |
131 | set rvdummy "[file dirname [board_info target sim]]/rvdummy" | |
132 | } | |
26d01138 HPN |
133 | |
134 | # All machines we test and the corresponding assembler option. | |
135 | # We'll only ever test v10 and higher here. | |
136 | ||
137 | set combos {{"crisv10" "--march=v10 --no-mul-bug-abort"} | |
138 | {"crisv32" "--march=v32"}} | |
139 | ||
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. | |
143 | ||
144 | foreach combo $combos { | |
145 | set mach [lindex $combo 0] | |
146 | set ASFLAGS_FOR_TARGET "[lindex $combo 1]" | |
147 | ||
148 | # The .ms suffix is for "miscellaneous .s". | |
149 | foreach src [lsort [glob -nocomplain $srcdir/$subdir/*.ms]] { | |
150 | ||
151 | # If we're only testing specific files and this isn't one of them, | |
152 | # skip it. | |
153 | if ![runtest_file_p $runtests $src] { | |
154 | continue | |
155 | } | |
156 | ||
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 { | |
161 | untested $src | |
162 | continue | |
163 | } | |
164 | ||
165 | set sim_defaults "--hw-file $srcdir/$subdir/std.dev" | |
166 | set ld_defaults "--section-start=.text=0" | |
167 | ||
168 | # We parse options an extra time besides in run_sim_test, | |
169 | # to determine if our defaults should be overridden. | |
170 | ||
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] | |
176 | ||
177 | # Allow concatenating to the default options by | |
178 | # specifying a mach. | |
179 | if { $opt_name == "sim" && $opt_machs == "" } { | |
180 | set sim_defaults "" | |
181 | } | |
182 | ||
183 | if { $opt_name == "ld" && $opt_machs == "" } { | |
184 | set ld_defaults "" | |
185 | } | |
186 | } | |
187 | ||
188 | set rvdummy_id -1 | |
189 | set hostcmds [slurp_rv $src] | |
190 | ||
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] { | |
196 | untested $src | |
197 | continue | |
198 | } | |
199 | ||
200 | set src_components [file split $src] | |
201 | set rvfile "[lindex $src_components \ | |
202 | [expr [llength $src_components] - 1]].r" | |
203 | ||
204 | if [catch { set f [open $rvfile w] } x] { | |
205 | error "$x" | |
206 | } { | |
207 | set contents [join $hostcmds "\n"] | |
208 | ||
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 | |
212 | ||
213 | verbose "rv: $contents" 2 | |
214 | puts $f $contents | |
215 | close $f | |
216 | } | |
217 | ||
218 | spawn -noecho $rvdummy "$rvfile" | |
219 | if { $spawn_id < 0 } { | |
220 | error "Couldn't spawn $rvdummy" | |
221 | continue | |
222 | } | |
223 | set rvdummy_id $spawn_id | |
224 | } | |
225 | ||
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 | |
233 | ||
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 } { | |
237 | close -i $rvdummy_id | |
238 | wait -i $rvdummy_id | |
239 | ||
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 } { | |
244 | file delete $rvfile | |
245 | } | |
246 | } | |
247 | } | |
248 | } | |
249 | } |