]> git.ipfire.org Git - thirdparty/binutils-gdb.git/blob - sim/testsuite/cris/c/c.exp
sim: testsuite: push $arch out to targets
[thirdparty/binutils-gdb.git] / sim / testsuite / cris / c / c.exp
1 # Copyright (C) 2005-2021 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 testing syscall sequences.
17
18 if ![istarget cris*-*-*] {
19 return
20 }
21
22 # Used to locate the `run` program.
23 global arch
24 set arch "cris"
25
26 set CFLAGS_FOR_TARGET "-O2"
27 if [istarget cris-*-*] {
28 set mach "crisv10"
29 } {
30 set mach "crisv32"
31 }
32
33 if [istarget cris*-*-elf] {
34 append CFLAGS_FOR_TARGET " -sim"
35 }
36
37 # Using target_compile, since it is less noisy,
38 if { [target_compile $srcdir/$subdir/hello.c compilercheck.x \
39 "executable" "" ] == "" } {
40 set has_cc 1
41
42 # Now check if we can link a program dynamically, and where
43 # libc.so is located. If it is, we provide a sym link to the
44 # directory (which must end in /lib) in [pwd], so /lib/ld.so.1 is
45 # found (which must reside along libc.so). We don't bother
46 # replacing the board ldflags like below as we don't care about
47 # detrimental effects on the executable from the specs and
48 # -static in the board ldflags, we just add -Bdynamic.
49 if [regexp "(.*/lib)/libc.so" \
50 [target_compile $srcdir/$subdir/hello.c compilercheck.x \
51 "executable" \
52 "ldflags=-print-file-name=libc.so -Wl,-Bdynamic"] \
53 xxx libcsodir] {
54 file delete lib
55 verbose -log "Creating link to $libcsodir in [pwd]"
56 file link lib $libcsodir
57 }
58 } {
59 verbose -log "Can't execute C compiler"
60 set has_cc 0
61 }
62
63 # Like istarget, except take a list of targets as a string.
64 proc anytarget { targets } {
65 set targetlist [split $targets]
66 set argc [llength $targetlist]
67 for { set i 0 } { $i < $argc } { incr i } {
68 if [istarget [lindex $targetlist $i]] {
69 return 1
70 }
71 }
72 return 0
73 }
74
75 foreach src [lsort [glob -nocomplain $srcdir/$subdir/*.c]] {
76 set orig_ldflags ""
77
78 if ![runtest_file_p $runtests $src] {
79 continue
80 }
81 set testname "[file tail $src]"
82
83 set opt_array [slurp_options $src]
84 if { $opt_array == -1 } {
85 unresolved $testname
86 return
87 }
88
89 # And again, to simplify specifying tests.
90 if ![runtest_file_p $runtests $src] {
91 continue
92 }
93
94 # Note absence of CC in results, but don't make a big fuss over it.
95 if { $has_cc == 0 } {
96 untested $testname
97 continue
98 }
99
100 # Clear default options
101 set opts(cc) ""
102 set opts(sim) ""
103 set opts(output) ""
104 set opts(progoptions) ""
105 set opts(timeout) ""
106 set opts(mach) ""
107 set opts(xerror) "no"
108 set opts(dest) "$testname.x"
109 set opts(simenv) ""
110 set opts(kfail) ""
111 set opts(xfail) ""
112 set opts(target) ""
113 set opts(notarget) ""
114 set opts(dynamic) ""
115
116 # Clear any machine specific options specified in a previous test case
117 if [info exists opts(sim,$mach)] {
118 unset opts(sim,$mach)
119 }
120
121 foreach i $opt_array {
122 set opt_name [lindex $i 0]
123 set opt_machs [lindex $i 1]
124 set opt_val [lindex $i 2]
125 if ![info exists opts($opt_name)] {
126 perror "unknown option $opt_name in file $src"
127 unresolved $testname
128 return
129 }
130
131 # Replace specific substitutions:
132 # @exedir@ is where the test-program is located.
133 regsub -all "@exedir@" $opt_val "[pwd]" opt_val
134 # @srcdir@ is where the source of the test-program is located.
135 regsub -all "@srcdir@" $opt_val "$srcdir/$subdir" opt_val
136
137 # Multiple of these options concatenate, they don't override.
138 if { $opt_name == "output" || $opt_name == "progoptions" } {
139 set opt_val "$opts($opt_name)$opt_val"
140 }
141
142 # Similar with "xfail", "kfail", "target" and "notarget", but
143 # arguments are space-separated.
144 if { $opt_name == "xfail" || $opt_name == "kfail" \
145 || $opt_name == "target" || $opt_name == "notarget" } {
146 if { $opts($opt_name) != "" } {
147 set opt_val "$opts($opt_name) $opt_val"
148 }
149 }
150
151 if { $opt_name == "dynamic" \
152 && [info exists board_info([target_info name],ldflags)] } {
153 # Weed out -static from ldflags, but keep the original in
154 # $orig_ldflags.
155 set orig_ldflags $board_info([target_info name],ldflags)
156 set ldflags " $orig_ldflags "
157 regsub -all " -static " $ldflags " " ldflags
158 set board_info([target_info name],ldflags) $ldflags
159 }
160
161 foreach m $opt_machs {
162 set opts($opt_name,$m) $opt_val
163 }
164 if { "$opt_machs" == "" } {
165 set opts($opt_name) $opt_val
166 }
167 }
168
169 if { $opts(output) == "" } {
170 if { "$opts(xerror)" == "no" } {
171 set opts(output) "pass\n"
172 } else {
173 set opts(output) "fail\n"
174 }
175 }
176
177 if { $opts(target) != "" && ![anytarget $opts(target)] } {
178 continue
179 }
180
181 if { $opts(notarget) != "" && [anytarget $opts(notarget)] } {
182 continue
183 }
184
185 # If no machine specific options, default to the general version.
186 if ![info exists opts(sim,$mach)] {
187 set opts(sim,$mach) $opts(sim)
188 }
189
190 # Change \n sequences to newline chars.
191 regsub -all "\\\\n" $opts(output) "\n" opts(output)
192
193 verbose -log "Compiling $src with $opts(cc)"
194
195 set dest "$opts(dest)"
196 if { [sim_compile $src $dest "executable" "$opts(cc)" ] != "" } {
197 unresolved $testname
198 continue
199 }
200
201 if { $orig_ldflags != "" } {
202 set board_info([target_info name],ldflags) $orig_ldflags
203 }
204
205 verbose -log "Simulating $src with $opts(sim,$mach)"
206
207 # Time to setup xfailures and kfailures.
208 if { "$opts(xfail)" != "" } {
209 verbose -log "xfail: $opts(xfail)"
210 # Using eval to make $opts(xfail) appear as individual
211 # arguments.
212 eval setup_xfail $opts(xfail)
213 }
214 if { "$opts(kfail)" != "" } {
215 verbose -log "kfail: $opts(kfail)"
216 eval setup_kfail $opts(kfail)
217 }
218
219 set result [sim_run $dest "$opts(sim,$mach)" "$opts(progoptions)" \
220 "" "$opts(simenv)"]
221 set return_code [lindex $result 0]
222 set output [lindex $result 1]
223
224 set status fail
225 if { $return_code == 0 } {
226 set status pass
227 }
228
229 if { "$status" == "pass" } {
230 if { "$opts(xerror)" == "no" } {
231 if [string match $opts(output) $output] {
232 pass "$mach $testname"
233 } else {
234 verbose -log "output: $output" 3
235 verbose -log "pattern: $opts(output)" 3
236 fail "$mach $testname (execution)"
237 }
238 } else {
239 verbose -log "`pass' return code when expecting failure" 3
240 fail "$mach $testname (execution)"
241 }
242 } elseif { "$status" == "fail" } {
243 if { "$opts(xerror)" == "no" } {
244 fail "$mach $testname (execution)"
245 } else {
246 if [string match $opts(output) $output] {
247 pass "$mach $testname"
248 } else {
249 verbose -log "output: $output" 3
250 verbose -log "pattern: $opts(output)" 3
251 fail "$mach $testname (execution)"
252 }
253 }
254 } else {
255 $status "$mach $testname"
256 }
257 }