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