1 # Copyright (C) 2005-2024 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 testing syscall sequences.
20 global global_cc_works
23 set CFLAGS_FOR_TARGET "-O2"
24 if [istarget cris-*-*] {
30 # Make sure we're using the right runtime for simulator runs. If the
31 # cris-sim dejagnu baseboard is used, -sim3 will be duplicated, but
32 # that's ok. For e.g. cris*-linux-gnu, neither -sim not -sim3 are
33 # supported options and likely not other targets too.
34 set saved_CFLAGS_FOR_TARGET $CFLAGS_FOR_TARGET
35 if { $global_cc_os == "newlib" } {
36 append CFLAGS_FOR_TARGET " -sim3"
39 # Using target_compile, since it is less noisy,
40 if { $global_cc_works == 1 } {
41 # Now check if we can link a program dynamically, and where
42 # libc.so is located. If it is, we provide a sym link to the
43 # directory (which must end in /lib) in [pwd], so /lib/ld.so.1 is
44 # found (which must reside along libc.so). We don't bother
45 # replacing the board ldflags like below as we don't care about
46 # detrimental effects on the executable from the specs and
47 # -static in the board ldflags, we just add -Bdynamic.
49 if [regexp "(.*/lib)/libc.so" \
50 [target_compile $srcdir/lib/compilercheck.c $objdir/compilercheck.x \
52 "ldflags=-print-file-name=libc.so -Wl,-Bdynamic"] \
55 verbose -log "Creating link to $libcsodir in [pwd]"
56 file link lib $libcsodir
58 file delete $objdir/compilercheck.x
61 # Like istarget, except take a list of targets as a string.
62 proc anytarget { targets } {
63 set targetlist [split $targets]
64 set argc [llength $targetlist]
65 for { set i 0 } { $i < $argc } { incr i } {
66 if [istarget [lindex $targetlist $i]] {
74 foreach src [lsort [glob -nocomplain $srcdir/$subdir/*.c]] {
77 if ![runtest_file_p $runtests $src] {
80 set testname "[file tail $src]"
82 set opt_array [slurp_options $src]
83 if { $opt_array == -1 } {
88 # And again, to simplify specifying tests.
89 if ![runtest_file_p $runtests $src] {
93 # Note absence of CC in results, but don't make a big fuss over it.
94 if { $global_cc_works == 0 } {
99 if ![file exists $sim_path] {
104 # Clear default options
108 set opts(progoptions) ""
112 set opts(xerror) "no"
116 set opts(notarget) ""
118 # Clear any machine specific options specified in a previous test case
119 if [info exists opts(sim,$mach)] {
120 unset opts(sim,$mach)
123 foreach i $opt_array {
124 set opt_name [lindex $i 0]
125 set opt_machs [lindex $i 1]
126 set opt_val [lindex $i 2]
127 if ![info exists opts($opt_name)] {
128 perror "unknown option $opt_name in file $src"
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"
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"
147 foreach m $opt_machs {
148 set opts($opt_name,$m) $opt_val
150 if { "$opt_machs" == "" } {
151 set opts($opt_name) $opt_val
155 if { $opts(output) == "" } {
156 if { "$opts(xerror)" == "no" } {
157 set opts(output) "pass\n"
159 set opts(output) "fail\n"
163 if { $opts(target) != "" && ![anytarget $opts(target)] } {
167 if { $opts(notarget) != "" && [anytarget $opts(notarget)] } {
171 if { $opts(progos) != "" && $opts(progos) != $global_cc_os } {
176 # If no machine specific options, default to the general version.
177 if ![info exists opts(sim,$mach)] {
178 set opts(sim,$mach) $opts(sim)
181 # Change \n sequences to newline chars.
182 regsub -all "\\\\n" $opts(output) "\n" opts(output)
184 verbose -log "Compiling $src with $opts(cc)"
186 if { [target_compile $src "$objdir/$testname.x" "executable" "$opts(cc)" ] != "" } {
187 fail "$mach $testname (compilation)"
191 if { $orig_ldflags != "" } {
192 set board_info([target_info name],ldflags) $orig_ldflags
195 verbose -log "Simulating $src with $opts(sim,$mach)"
197 # Time to setup xfailures and kfailures.
198 if { "$opts(xfail)" != "" } {
199 verbose -log "xfail: $opts(xfail)"
200 # Using eval to make $opts(xfail) appear as individual
202 eval setup_xfail $opts(xfail)
204 if { "$opts(kfail)" != "" } {
205 verbose -log "kfail: $opts(kfail)"
206 eval setup_kfail $opts(kfail)
209 set result [sim_run "$objdir/$testname.x" "$opts(sim,$mach)" "$opts(progoptions)" \
211 set return_code [lindex $result 0]
212 set output [lindex $result 1]
215 if { $return_code == 0 } {
219 if { "$status" == "pass" } {
220 if { "$opts(xerror)" == "no" } {
221 if [string match $opts(output) $output] {
222 pass "$mach $testname"
224 verbose -log "output: $output" 3
225 verbose -log "pattern: $opts(output)" 3
226 fail "$mach $testname (execution)"
229 verbose -log "`pass' return code when expecting failure" 3
230 fail "$mach $testname (execution)"
232 } elseif { "$status" == "fail" } {
233 if { "$opts(xerror)" == "no" } {
234 fail "$mach $testname (execution)"
236 if [string match $opts(output) $output] {
237 pass "$mach $testname"
239 verbose -log "output: $output" 3
240 verbose -log "pattern: $opts(output)" 3
241 fail "$mach $testname (execution)"
245 $status "$mach $testname"
249 set CFLAGS_FOR_TARGET $saved_CFLAGS_FOR_TARGET