OSDN Git Service

* gcc.c-torture/execute/ieee/rbug.x: XFAIL FreeBSD 5.x.
[pf3gnuchains/gcc-fork.git] / gcc / testsuite / lib / objc-torture.exp
1 # Copyright (C) 1992, 1993, 1994, 1995, 1996, 1997 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 2 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, write to the Free Software
15 # Foundation, 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
16
17 # Please email any bugs, comments, and/or additions to this file to:
18 # bug-dejagnu.prep.ai.mit.edu
19
20 # This file was written by Rob Savoye. (rob@cygnus.com)
21
22 # The default option list can be overridden by
23 # TORTURE_OPTIONS="{ { list1 } ... { listN } }"
24
25 if ![info exists TORTURE_OPTIONS] {
26     # FIXME: We should test -g at least once.
27     set TORTURE_OPTIONS [list { -O }]
28 }
29
30
31 # Split TORTURE_OPTIONS into two choices: one for testcases with loops and
32 # one for testcases without loops.
33
34 set torture_with_loops $TORTURE_OPTIONS
35 set torture_without_loops ""
36 foreach option $TORTURE_OPTIONS {
37     if ![string match "*loop*" $option] {
38         lappend torture_without_loops $option
39     }
40 }
41
42 #
43 # objc-torture-compile -- runs the Tege C-torture test
44 #
45 # SRC is the full pathname of the testcase.
46 # OPTION is the specific compiler flag we're testing (eg: -O2).
47 #
48 proc objc-torture-compile { src option } {
49     global output
50     global srcdir tmpdir
51     global host_triplet
52
53     set output "$tmpdir/[file tail [file rootname $src]].o"
54
55     regsub "^$srcdir/?" $src "" testcase
56     # If we couldn't rip $srcdir out of `src' then just do the best we can.
57     # The point is to reduce the unnecessary noise in the logs.  Don't strip
58     # out too much because different testcases with the same name can confuse
59     # `test-tool'.
60     if [string match "/*" $testcase] {
61         set testcase "[file tail [file dirname $src]]/[file tail $src]"
62     }
63
64     verbose "Testing $testcase, $option" 1
65
66     # Run the compiler and analyze the results.
67     set options ""
68     lappend options "additional_flags=-w $option"
69
70     set comp_output [objc_target_compile "$src" "$output" object $options];
71     
72     # Set a few common compiler messages.
73     set fatal_signal "*Obj-C*: Internal compiler error: program*got fatal signal"
74  
75     if [string match "$fatal_signal 6" $comp_output] then {
76         objc_fail $testcase "Got Signal 6, $option"
77         remote_file build delete $output
78         return
79     }
80
81     if [string match "$fatal_signal 11" $comp_output] then {
82         objc_fail $testcase "Got Signal 11, $option"
83         remote_file build delete $output
84         return
85     }
86
87     # We shouldn't get these because of -w, but just in case.
88     if [string match "*Obj-C*:*warning:*" $comp_output] then {
89         warning "$testcase: (with warnings) $option"
90         send_log "$comp_output\n"
91         unresolved "$testcase, $option"
92         remote_file build delete $output
93         return
94     }
95
96     set comp_output [prune_warnings $comp_output]
97
98     set unsupported_message [objc_check_unsupported_p $comp_output]
99     if { $unsupported_message != "" } {
100         unsupported "$testcase: $unsupported_message"
101         remote_file build delete $output
102         return
103     }
104
105     # remove any leftover LF/CR to make sure any output is legit
106     regsub -all -- "\[\r\n\]*" $comp_output "" comp_output
107     # If any message remains, we fail.
108     if ![string match "" $comp_output] then {
109         objc_fail $testcase $option
110         remote_file build delete $output
111         return
112     }
113
114     objc_pass $testcase $option
115     remote_file build delete $output
116 }
117
118 #
119 # objc-torture-execute -- utility to compile and execute a testcase
120 #
121 # SRC is the full pathname of the testcase.
122 #
123 # If the testcase has an associated .cexp file, we source that to run the
124 # test instead.  We use .cexp instead of .exp so that the testcase is still
125 # controlled by the main .exp driver (this is useful when one wants to only
126 # run the compile.exp tests for example - one need only pass compile.exp to
127 # dejagnu, and not compile.exp, foo1.exp, foo2.exp, etc.).
128 #
129 proc objc-torture-execute { src } {
130     global tmpdir tool srcdir output 
131
132     # Check for alternate driver.
133     if [file exists [file rootname $src].cexp] {
134         verbose "Using alternate driver [file rootname [file tail $src]].cexp" 2
135         set done_p 0
136         catch "set done_p \[source [file rootname $src].cexp\]"
137         if { $done_p } {
138             return
139         }
140     }
141    
142     # Look for a loop within the source code - if we don't find one,
143     # don't pass -funroll[-all]-loops.
144     global torture_with_loops torture_without_loops
145     if [expr [search_for $src "do *\[0-9\]"]+[search_for $src "end *do"]] then {
146         set option_list $torture_with_loops
147     } else {
148         set option_list $torture_without_loops
149     }
150
151     set executable $tmpdir/[file tail [file rootname $src].x]
152
153     regsub "^$srcdir/?" $src "" testcase
154     # If we couldn't rip $srcdir out of `src' then just do the best we can.
155     # The point is to reduce the unnecessary noise in the logs.  Don't strip
156     # out too much because different testcases with the same name can confuse
157     # `test-tool'.
158     if [string match "/*" $testcase] {
159         set testcase "[file tail [file dirname $src]]/[file tail $src]"
160     }
161
162     foreach option $option_list {
163         # torture_{compile,execute}_xfail are set by the .cexp script
164         # (if present)
165         if [info exists torture_compile_xfail] {
166             setup_xfail $torture_compile_xfail
167         }
168         remote_file build delete $executable
169         verbose "Testing $testcase, $option" 1
170
171         set options ""
172         lappend options "additional_flags=-w $option -I${srcdir}/../../libobjc"
173         set comp_output [objc_target_compile "$src" "$executable" executable $options];
174
175         # Set a few common compiler messages.
176         set fatal_signal "*Obj-C*: Internal compiler error: program*got fatal signal"
177         
178         if [string match "$fatal_signal 6" $comp_output] then {
179             objc_fail $testcase "Got Signal 6, $option"
180             remote_file build delete $executable
181             continue
182         }
183         
184         if [string match "$fatal_signal 11" $comp_output] then {
185             objc_fail $testcase "Got Signal 11, $option"
186             remote_file build delete $executable
187             continue
188         }
189         
190         # We shouldn't get these because of -w, but just in case.
191         if [string match "*Obj-C*:*warning:*" $comp_output] then {
192             warning "$testcase: (with warnings) $option"
193             send_log "$comp_output\n"
194             unresolved "$testcase, $option"
195             remote_file build delete $executable
196             continue
197         }
198         
199         set comp_output [prune_warnings $comp_output]
200         
201         set unsupported_message [objc_check_unsupported_p $comp_output]
202
203         if { $unsupported_message != "" } {
204             unsupported "$testcase: $unsupported_message"
205             continue
206         } elseif ![file exists $executable] {
207             if ![is3way] {
208                 fail "$testcase compilation, $option"
209                 untested "$testcase execution, $option"
210                 continue
211             } else {
212                 # FIXME: since we can't test for the existance of a remote
213                 # file without short of doing an remote file list, we assume
214                 # that since we got no output, it must have compiled.
215                 pass "$testcase compilation, $option"           
216             }
217         } else {
218             pass "$testcase compilation, $option"
219         }
220
221         # See if this source file uses "long long" types, if it does, and
222         # no_long_long is set, skip execution of the test.
223         if [target_info exists no_long_long] then {
224             if [expr [search_for $src "integer\*8"]] then {
225                 untested "$testcase execution, $option"
226                 continue
227             }
228         }
229
230         if [info exists torture_execute_xfail] {
231             setup_xfail $torture_execute_xfail
232         }
233         
234         set result [objc_load "$executable" "" ""]
235         set status [lindex $result 0];
236         set output [lindex $result 1];
237         if { $status == "pass" } {
238             remote_file build delete $executable
239         }
240         $status "$testcase execution, $option"
241     }
242 }
243
244 #
245 # search_for -- looks for a string match in a file
246 #
247 proc search_for { file pattern } {
248     set fd [open $file r]
249     while { [gets $fd cur_line]>=0 } {
250         set lower [string tolower $cur_line]
251         if [regexp "$pattern" $lower] then {
252             close $fd
253             return 1
254         }
255     }
256     close $fd
257     return 0
258 }
259
260 #
261 # objc-torture -- the objc-torture testcase source file processor
262 #
263 # This runs compilation only tests (no execute tests).
264 # SRC is the full pathname of the testcase, or just a file name in which case
265 # we prepend $srcdir/$subdir.
266 #
267 # If the testcase has an associated .cexp file, we source that to run the
268 # test instead.  We use .cexp instead of .exp so that the testcase is still
269 # controlled by the main .exp driver (this is useful when one wants to only
270 # run the compile.exp tests for example - one need only pass compile.exp to
271 # dejagnu, and not compile.exp, foo1.exp, foo2.exp, etc.).
272 #
273 proc objc-torture { args } {
274     global srcdir subdir
275
276     set src [lindex $args 0];
277     if { [llength $args] > 1 } {
278         set options [lindex $args 1];
279     } else {
280         set options ""
281     }
282
283     # Prepend $srdir/$subdir if missing.
284     if ![string match "*/*" $src] {
285         set src "$srcdir/$subdir/$src"
286     }
287
288     # Check for alternate driver.
289     if [file exists [file rootname $src].cexp] {
290         verbose "Using alternate driver [file rootname [file tail $src]].cexp" 2
291         set done_p 0
292         catch "set done_p \[source [file rootname $src].cexp\]"
293         if { $done_p } {
294             return
295         }
296     }
297    
298     # Look for a loop within the source code - if we don't find one,
299     # don't pass -funroll[-all]-loops.
300     global torture_with_loops torture_without_loops
301     if [expr [search_for $src "do *\[0-9\]"]+[search_for $src "end *do"]] then {
302         set option_list $torture_with_loops
303     } else {
304         set option_list $torture_without_loops
305     }
306
307     # loop through all the options
308     foreach option $option_list {
309         # torture_compile_xfail is set by the .cexp script (if present)
310         if [info exists torture_compile_xfail] {
311             setup_xfail $torture_compile_xfail
312         }
313
314         objc-torture-compile $src "$option $options"
315     }
316 }