OSDN Git Service

* config/i386.i386.c (ix86_return_in_memory): Reformat. Return true
[pf3gnuchains/gcc-fork.git] / gcc / testsuite / lib / objc-torture.exp
1 # Copyright (C) 1992-1998, 1999, 2000 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@gnu.org.
19
20 # This file was written by Rob Savoye. (rob@cygnus.com)
21
22 load_lib file-format.exp
23
24 # The default option list can be overridden by
25 # TORTURE_OPTIONS="{ { list1 } ... { listN } }"
26
27 if ![info exists TORTURE_OPTIONS] {
28     # It is theoretically beneficial to group all of the O2/O3 options together,
29     # as in many cases the compiler will generate identical executables for
30     # all of them--and the objc-torture testsuite will skip testing identical
31     # executables multiple times.
32     # Also note that -finline-functions is explicitly included in one of the
33     # items below, even though -O3 is also specified, because some ports may
34     # choose to disable inlining functions by default, even when optimizing.
35     set TORTURE_OPTIONS [list \
36         { -O0 } \
37         { -O1 } \
38         { -O2 } \
39         { -O3 -fomit-frame-pointer } \
40         { -O3 -fomit-frame-pointer -funroll-loops } \
41         { -O3 -fomit-frame-pointer -funroll-all-loops -finline-functions } \
42         { -O3 -g } \
43         { -Os } ]
44 }
45
46
47 # Split TORTURE_OPTIONS into two choices: one for testcases with loops and
48 # one for testcases without loops.
49
50 set torture_with_loops $TORTURE_OPTIONS
51 set torture_without_loops ""
52 foreach option $TORTURE_OPTIONS {
53     if ![string match "*loop*" $option] {
54         lappend torture_without_loops $option
55     }
56 }
57
58 #
59 # objc-torture-compile -- runs the Tege OBJC-torture test
60 #
61 # SRC is the full pathname of the testcase.
62 # OPTION is the specific compiler flag we're testing (eg: -O2).
63 #
64 proc objc-torture-compile { src option } {
65     global output
66     global srcdir tmpdir
67     global host_triplet
68
69     set output "$tmpdir/[file tail [file rootname $src]].o"
70
71     regsub "^$srcdir/?" $src "" testcase
72     # If we couldn't rip $srcdir out of `src' then just do the best we can.
73     # The point is to reduce the unnecessary noise in the logs.  Don't strip
74     # out too much because different testcases with the same name can confuse
75     # `test-tool'.
76     if [string match "/*" $testcase] {
77         set testcase "[file tail [file dirname $src]]/[file tail $src]"
78     }
79
80     verbose "Testing $testcase, $option" 1
81
82     # Run the compiler and analyze the results.
83     set options ""
84     lappend options "additional_flags=-w $option"
85
86     set comp_output [objc_target_compile "$src" "$output" object $options];
87     objc_check_compile $testcase $option $output $comp_output
88     remote_file build delete $output
89 }
90
91 #
92 # objc-torture-execute -- utility to compile and execute a testcase
93 #
94 # SRC is the full pathname of the testcase.
95 #
96 # If the testcase has an associated .x file, we source that to run the
97 # test instead.  We use .x so that we don't lengthen the existing filename
98 # to more than 14 chars.
99 #
100 proc objc-torture-execute { src args } {
101     global tmpdir tool srcdir output compiler_conditional_xfail_data
102
103     if { [llength $args] > 0 } {
104         set additional_flags [lindex $args 0];
105     } else {
106         set additional_flags "";
107     }
108     # Check for alternate driver.
109     if [file exists [file rootname $src].x] {
110         verbose "Using alternate driver [file rootname [file tail $src]].x" 2
111         set done_p 0
112         catch "set done_p \[source [file rootname $src].x\]"
113         if { $done_p } {
114             return
115         }
116     }
117
118     # Look for a loop within the source code - if we don't find one,
119     # don't pass -funroll[-all]-loops.
120     global torture_with_loops torture_without_loops
121     if [expr [search_for $src "for*("]+[search_for $src "while*("]] then {
122         set option_list $torture_with_loops
123     } else {
124         set option_list $torture_without_loops
125     }
126
127     set executable $tmpdir/[file tail [file rootname $src].x]
128
129     regsub "^$srcdir/?" $src "" testcase
130     # If we couldn't rip $srcdir out of `src' then just do the best we can.
131     # The point is to reduce the unnecessary noise in the logs.  Don't strip
132     # out too much because different testcases with the same name can confuse
133     # `test-tool'.
134     if [string match "/*" $testcase] {
135         set testcase "[file tail [file dirname $src]]/[file tail $src]"
136     }
137
138     set count 0;
139     set oldstatus "foo";
140     foreach option $option_list {
141         if { $count > 0 } {
142             set oldexec $execname;
143         }
144         set execname "${executable}${count}";
145         incr count;
146
147         # torture_{compile,execute}_xfail are set by the .x script
148         # (if present)
149         if [info exists torture_compile_xfail] {
150             setup_xfail $torture_compile_xfail
151         }
152
153         # torture_execute_before_{compile,execute} can be set by the .x script
154         # (if present)
155         if [info exists torture_eval_before_compile] {
156             set ignore_me [eval $torture_eval_before_compile]
157         }
158
159         remote_file build delete $execname;
160         verbose "Testing $testcase, $option" 1
161
162         set options ""
163         lappend options "additional_flags=-w $option"
164         if { $additional_flags != "" } {
165             lappend options "additional_flags=$additional_flags";
166         }
167         set comp_output [objc_target_compile "$src" "${execname}" executable $options];
168
169         if ![objc_check_compile "$testcase compilation" $option $execname $comp_output] {
170             unresolved "$testcase execution, $option"
171             remote_file build delete $execname
172             continue
173         }
174
175         # See if this source file uses "long long" types, if it does, and
176         # no_long_long is set, skip execution of the test.
177         if [target_info exists no_long_long] then {
178             if [expr [search_for $src "long long"]] then {
179                 unsupported "$testcase execution, $option"
180                 continue
181             }
182         }
183
184         if [info exists torture_execute_xfail] {
185             setup_xfail $torture_execute_xfail
186         }
187
188         if [info exists torture_eval_before_execute] {
189             set ignore_me [eval $torture_eval_before_execute]
190         }
191
192
193         # Sometimes we end up creating identical executables for two
194         # consecutive sets of different of compiler options.
195         #
196         # In such cases we know the result of this test will be identical
197         # to the result of the last test.
198         #
199         # So in cases where the time to load and run/simulate the test
200         # is relatively high, compare the two binaries and avoid rerunning
201         # tests if the executables are identical.
202         #
203         # Do not do this for native testing since the cost to load/execute
204         # the test is fairly small and the comparison step actually slows
205         # the entire process down because it usually does not "hit".
206         set skip 0;
207         if { ![isnative] && [info exists oldexec] } {
208             if { [remote_file build cmp $oldexec $execname] == 0 } {
209                 set skip 1;
210             }
211         }
212         if { $skip == 0 } {
213             set result [objc_load "$execname" "" ""]
214             set status [lindex $result 0];
215             set output [lindex $result 1];
216         }
217         if { $oldstatus == "pass" } {
218             remote_file build delete $oldexec;
219         }
220         $status "$testcase execution, $option"
221         set oldstatus $status;
222     }
223     if [info exists status] {
224         if { $status == "pass" } {
225             remote_file build delete $execname;
226         }
227     }
228 }
229
230 #
231 # search_for -- looks for a string match in a file
232 #
233 proc search_for { file pattern } {
234     set fd [open $file r]
235     while { [gets $fd cur_line]>=0 } {
236         if [string match "*$pattern*" $cur_line] then {
237             close $fd
238             return 1
239         }
240     }
241     close $fd
242     return 0
243 }
244
245 #
246 # objc-torture -- the objc-torture testcase source file processor
247 #
248 # This runs compilation only tests (no execute tests).
249 # SRC is the full pathname of the testcase, or just a file name in which case
250 # we prepend $srcdir/$subdir.
251 #
252 # If the testcase has an associated .x file, we source that to run the
253 # test instead.  We use .x so that we don't lengthen the existing filename
254 # to more than 14 chars.
255 #
256 proc objc-torture { args } {
257     global srcdir subdir compiler_conditional_xfail_data
258
259     set src [lindex $args 0];
260     if { [llength $args] > 1 } {
261         set options [lindex $args 1];
262     } else {
263         set options ""
264     }
265
266     # Prepend $srdir/$subdir if missing.
267     if ![string match "*/*" $src] {
268         set src "$srcdir/$subdir/$src"
269     }
270
271     # Check for alternate driver.
272     if [file exists [file rootname $src].x] {
273         verbose "Using alternate driver [file rootname [file tail $src]].x" 2
274         set done_p 0
275         catch "set done_p \[source [file rootname $src].x\]"
276         if { $done_p } {
277             return
278         }
279     }
280
281     # Look for a loop within the source code - if we don't find one,
282     # don't pass -funroll[-all]-loops.
283     global torture_with_loops torture_without_loops
284     if [expr [search_for $src "for*("]+[search_for $src "while*("]] then {
285         set option_list $torture_with_loops
286     } else {
287         set option_list $torture_without_loops
288     }
289
290     # loop through all the options
291     foreach option $option_list {
292         # torture_compile_xfail is set by the .x script (if present)
293         if [info exists torture_compile_xfail] {
294             setup_xfail $torture_compile_xfail
295         }
296
297         # torture_execute_before_compile is set by the .x script (if present)
298         if [info exists torture_eval_before_compile] {
299             set ignore_me [eval $torture_eval_before_compile]
300         }
301
302         objc-torture-compile $src "$option $options"
303     }
304 }