OSDN Git Service

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