OSDN Git Service

Updated copyright notices for most files.
[pf3gnuchains/pf3gnuchains3x.git] / sim / testsuite / sim / cris / c / c.exp
1 # Copyright (C) 2005, 2007, 2008 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 set CFLAGS_FOR_TARGET "-O2"
23 if [istarget cris-*-*] {
24     set mach "crisv10"
25 } {
26     set mach "crisv32"
27 }
28
29 # Using target_compile, since it is less noisy,
30 if { [target_compile $srcdir/$subdir/hello.c compilercheck.x \
31           "executable" "" ] == "" } {
32     set has_cc 1
33 } {
34     verbose -log "Can't execute C compiler"
35     set has_cc 0
36 }
37
38 # Like istarget, except take a list of targets as a string.
39 proc anytarget { targets } {
40     set targetlist [split $targets]
41     set argc [llength $targetlist]
42     for { set i 0 } { $i < $argc } { incr i } {
43         if [istarget [lindex $targetlist $i]] {
44             return 1
45         }
46     }
47     return 0
48 }
49
50 foreach src [lsort [glob -nocomplain $srcdir/$subdir/*.c]] {
51     if ![runtest_file_p $runtests $src] {
52         continue
53     }
54     set testname "[file tail $src]"
55
56     set opt_array [slurp_options $src]
57     if { $opt_array == -1 } {
58         unresolved $testname
59         return
60     }
61
62     # And again, to simplify specifying tests.
63     if ![runtest_file_p $runtests $src] {
64         continue
65     }
66
67     # Note absence of CC in results, but don't make a big fuss over it.
68     if { $has_cc == 0 } {
69         untested $testname
70         continue
71     }
72
73     # Clear default options
74     set opts(cc) ""
75     set opts(sim) ""
76     set opts(output) ""
77     set opts(progoptions) ""
78     set opts(timeout) ""
79     set opts(mach) ""
80     set opts(xerror) "no"
81     set opts(dest) "$testname.x"
82     set opts(simenv) ""
83     set opts(kfail) ""
84     set opts(xfail) ""
85     set opts(target) ""
86     set opts(notarget) ""
87
88     # Clear any machine specific options specified in a previous test case
89     if [info exists opts(sim,$mach)] {
90         unset opts(sim,$mach)
91     }
92
93     foreach i $opt_array {
94         set opt_name [lindex $i 0]
95         set opt_machs [lindex $i 1]
96         set opt_val [lindex $i 2]
97         if ![info exists opts($opt_name)] {
98             perror "unknown option $opt_name in file $src"
99             unresolved $testname
100             return
101         }
102
103         # Replace specific substitutions:
104         # @exedir@ is where the test-program is located.
105         regsub -all "@exedir@" $opt_val "[pwd]" opt_val
106         # @srcdir@ is where the source of the test-program is located.
107         regsub -all "@srcdir@" $opt_val "$srcdir/$subdir" opt_val
108
109         # Multiple of these options concatenate, they don't override.
110         if { $opt_name == "output" || $opt_name == "progoptions" } {
111             set opt_val "$opts($opt_name)$opt_val"
112         }
113
114         # Similar with "xfail", "kfail", "target" and "notarget", but
115         # arguments are space-separated.
116         if { $opt_name == "xfail" || $opt_name == "kfail" \
117                  || $opt_name == "target"  || $opt_name == "notarget" } {
118             if { $opts($opt_name) != "" } {
119                 set opt_val "$opts($opt_name) $opt_val"
120             }
121         }
122
123         foreach m $opt_machs {
124             set opts($opt_name,$m) $opt_val
125         }
126         if { "$opt_machs" == "" } {
127             set opts($opt_name) $opt_val
128         }
129     }
130
131     if { $opts(output) == "" } {
132         if { "$opts(xerror)" == "no" } {
133             set opts(output) "pass\n"
134         } else {
135             set opts(output) "fail\n"
136         }
137     }
138
139     if { $opts(target) != "" && ![anytarget $opts(target)] } {
140         continue
141     }
142
143     if { $opts(notarget) != "" && [anytarget $opts(notarget)] } {
144         continue
145     }
146
147     # If no machine specific options, default to the general version.
148     if ![info exists opts(sim,$mach)] {
149         set opts(sim,$mach) $opts(sim)
150     }
151
152     # Change \n sequences to newline chars.
153     regsub -all "\\\\n" $opts(output) "\n" opts(output)
154
155     verbose -log "Compiling $src with $opts(cc)"
156
157     set dest "$opts(dest)"
158     if { [sim_compile $src $dest "executable" "$opts(cc)" ] != "" } {
159         unresolved $testname
160         continue
161     }
162
163     verbose -log "Simulating $src with $opts(sim,$mach)"
164
165     # Time to setup xfailures and kfailures.
166     if { "$opts(xfail)" != "" } {
167         verbose -log "xfail: $opts(xfail)"
168         # Using eval to make $opts(xfail) appear as individual
169         # arguments.
170         eval setup_xfail $opts(xfail)
171     }
172     if { "$opts(kfail)" != "" } {
173         verbose -log "kfail: $opts(kfail)"
174         eval setup_kfail $opts(kfail)
175     }
176
177     set result [sim_run $dest "$opts(sim,$mach)" "$opts(progoptions)" \
178         "" "$opts(simenv)"]
179     set status [lindex $result 0]
180     set output [lindex $result 1]
181
182     if { "$status" == "pass" } {
183         if { "$opts(xerror)" == "no" } {
184             if [string match $opts(output) $output] {
185                 pass "$mach $testname"
186             } else {
187                 verbose -log "output:  $output" 3
188                 verbose -log "pattern: $opts(output)" 3
189                 fail "$mach $testname (execution)"
190             }
191         } else {
192             verbose -log "`pass' return code when expecting failure" 3
193             fail "$mach $testname (execution)"
194         }
195     } elseif { "$status" == "fail" } {
196         if { "$opts(xerror)" == "no" } {
197             fail "$mach $testname (execution)"
198         } else {
199             if [string match $opts(output) $output] {
200                 pass "$mach $testname"
201             } else {
202                 verbose -log "output:  $output" 3
203                 verbose -log "pattern: $opts(output)" 3
204                 fail "$mach $testname (execution)"
205             }
206         }
207     } else {
208         $status "$mach $testname"
209     }
210 }