OSDN Git Service

2010-03-24 Iain Sandoe <iain.sandoe@sandoe-acoustics.co.uk>
[pf3gnuchains/gcc-fork.git] / gcc / testsuite / lib / objc-torture.exp
1 # Copyright (C) 1992-1998, 1999, 2000, 2007, 2008
2 # Free Software Foundation, Inc.
3
4 # This program is free software; you can redistribute it and/or modify
5 # it under the terms of the GNU General Public License as published by
6 # the Free Software Foundation; either version 3 of the License, or
7 # (at your option) any later version.
8 #
9 # This program is distributed in the hope that it will be useful,
10 # but WITHOUT ANY WARRANTY; without even the implied warranty of
11 # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
12 # GNU General Public License for more details.
13 #
14 # You should have received a copy of the GNU General Public License
15 # along with GCC; see the file COPYING3.  If not see
16 # <http://www.gnu.org/licenses/>.
17
18 # This file was written by Rob Savoye. (rob@cygnus.com)
19
20 load_lib file-format.exp
21 load_lib target-supports.exp
22
23 # Make sure that the runtime list is re-evaluated for each multilib.
24 proc objc-set-runtime-options { dowhat args } {
25     global OBJC_RUNTIME_OPTIONS
26     if ![info exists OBJC_RUNTIME_OPTIONS] {
27         set rtlist [list "-fgnu-runtime" "-fnext-runtime" ]
28     } else {
29         set rtlist [list "-fgnu-runtime" "-fnext-runtime" ]
30         foreach other $OBJC_RUNTIME_OPTIONS {
31             # Don't do tests twice...
32             if { ( $other == "-fnext-runtime"  || $other == "-fgnu-runtime" ) } {
33                 continue
34             }
35             lappend rtlist $other
36         }
37     }
38
39     set OBJC_RUNTIME_OPTIONS ""
40
41     foreach type $rtlist {
42         global srcdir subdir target_triplet tmpdir
43
44         set options "additional_flags=$type"
45         if [info exists args] {
46             lappend options $args
47         }
48         verbose "options $options"
49         set test_obj "trivial.exe"
50         set comp_output [objc_target_compile \
51         "$srcdir/$subdir/trivial.m" $test_obj executable $options]
52
53         # If we get any error, then we failed.
54         if ![string match "" $comp_output] then {
55             remote_file build delete $test_obj
56             continue;
57         }
58         if [info exists dowhat] {
59             if { $dowhat == "execute" } {
60                 set result [objc_load "$tmpdir/$test_obj" "" ""]
61                 set status [lindex $result 0]
62                 set output [lindex $result 1]
63                 if { $status != "pass" } {
64                     remote_file build delete $test_obj
65                     verbose -log "trivial execute failed with $status $output"
66                     continue;
67                 }
68             }
69         }
70         remote_file build delete $test_obj
71         lappend OBJC_RUNTIME_OPTIONS $type
72     }
73
74     verbose -log "Using the following runtimes: $OBJC_RUNTIME_OPTIONS"
75 }
76
77 # The default option list can be overridden by
78 # TORTURE_OPTIONS="{ { list1 } ... { listN } }"
79
80 if [info exists TORTURE_OPTIONS] {
81     set OBJC_TORTURE_OPTIONS $TORTURE_OPTIONS
82 } else {
83     # It is theoretically beneficial to group all of the O2/O3 options together,
84     # as in many cases the compiler will generate identical executables for
85     # all of them--and the objc-torture testsuite will skip testing identical
86     # executables multiple times.
87     # Also note that -finline-functions is explicitly included in one of the
88     # items below, even though -O3 is also specified, because some ports may
89     # choose to disable inlining functions by default, even when optimizing.
90     set OBJC_TORTURE_OPTIONS [list \
91         " -O0 " \
92         " -O1 " \
93         " -O2 " \
94         " -O3 -fomit-frame-pointer " \
95         " -O3 -fomit-frame-pointer -funroll-loops " \
96         " -O3 -fomit-frame-pointer -funroll-all-loops -finline-functions " \
97         " -O3 -g " \
98         " -Os " ]
99 }
100
101 if [info exists ADDITIONAL_TORTURE_OPTIONS] {
102     set OBJC_TORTURE_OPTIONS \
103         [concat $OBJC_TORTURE_OPTIONS $ADDITIONAL_TORTURE_OPTIONS]
104 }
105
106 #
107 # objc-torture-compile -- runs the Tege OBJC-torture test
108 #
109 # SRC is the full pathname of the testcase.
110 # OPTION is the specific compiler flag we're testing (eg: -O2).
111 #
112 proc objc-torture-compile { src option } {
113     global output
114     global srcdir tmpdir
115     global host_triplet
116
117     set output "$tmpdir/[file tail [file rootname $src]].o"
118
119     regsub "(?q)$srcdir/" $src "" testcase
120     # If we couldn't rip $srcdir out of `src' then just do the best we can.
121     # The point is to reduce the unnecessary noise in the logs.  Don't strip
122     # out too much because different testcases with the same name can confuse
123     # `test-tool'.
124     if [string match "/*" $testcase] {
125         set testcase "[file tail [file dirname $src]]/[file tail $src]"
126     }
127
128     verbose "Testing $testcase, $option" 1
129
130     # Run the compiler and analyze the results.
131     set options ""
132     lappend options "additional_flags=-w $option"
133
134     set comp_output [objc_target_compile "$src" "$output" object $options]
135     objc_check_compile $testcase $option $output $comp_output
136     remote_file build delete $output
137 }
138
139 #
140 # objc-torture-execute -- utility to compile and execute a testcase
141 #
142 # SRC is the full pathname of the testcase.
143 #
144 # If the testcase has an associated .x file, we source that to run the
145 # test instead.  We use .x so that we don't lengthen the existing filename
146 # to more than 14 chars.
147 #
148 proc objc-torture-execute { src args } {
149     global tmpdir tool srcdir output compiler_conditional_xfail_data
150
151     if { [llength $args] > 0 } {
152         set additional_flags [lindex $args 0]
153     } else {
154         set additional_flags ""
155     }
156     # Check for alternate driver.
157     if [file exists [file rootname $src].x] {
158         verbose "Using alternate driver [file rootname [file tail $src]].x" 2
159         set done_p 0
160         catch "set done_p \[source [file rootname $src].x\]"
161         if { $done_p } {
162             return
163         }
164     }
165
166     # Look for a loop within the source code - if we don't find one,
167     # don't pass -funroll[-all]-loops.
168     global torture_with_loops torture_without_loops
169     if [expr [search_for $src "for*("]+[search_for $src "while*("]] then {
170         set option_list $torture_with_loops
171     } else {
172         set option_list $torture_without_loops
173     }
174
175     set executable $tmpdir/[file tail [file rootname $src].x]
176
177     regsub "(?q)$srcdir/" $src "" testcase
178     # If we couldn't rip $srcdir out of `src' then just do the best we can.
179     # The point is to reduce the unnecessary noise in the logs.  Don't strip
180     # out too much because different testcases with the same name can confuse
181     # `test-tool'.
182     if [string match "/*" $testcase] {
183         set testcase "[file tail [file dirname $src]]/[file tail $src]"
184     }
185
186     set count 0
187     set oldstatus "foo"
188     foreach option $option_list {
189         if { $count > 0 } {
190             if [info exists oldexec] {
191                 remote_file build delete $oldexec
192             }
193             set oldexec $execname
194         }
195         set execname "${executable}${count}"
196         incr count
197
198         # torture_{compile,execute}_xfail are set by the .x script
199         # (if present)
200         if [info exists torture_compile_xfail] {
201             setup_xfail $torture_compile_xfail
202         }
203
204         # torture_execute_before_{compile,execute} can be set by the .x script
205         # (if present)
206         if [info exists torture_eval_before_compile] {
207           set ignore_me [eval $torture_eval_before_compile]
208         }
209
210         remote_file build delete $execname
211         verbose "Testing $testcase, $option" 1
212
213         set options ""
214         lappend options "additional_flags=-w $option"
215         if { $additional_flags != "" } {
216             lappend options "additional_flags=$additional_flags"
217         }
218         set comp_output [objc_target_compile "$src" "${execname}" executable $options]
219
220         if ![objc_check_compile "$testcase compilation" $option $execname $comp_output] {
221             unresolved "$testcase execution, $option"
222             remote_file build delete $execname
223             continue
224         }
225
226         # See if this source file uses "long long" types, if it does, and
227         # no_long_long is set, skip execution of the test.
228         if [target_info exists no_long_long] then {
229             if [expr [search_for $src "long long"]] then {
230                 unsupported "$testcase execution, $option"
231                 remote_file build delete $execname
232                 continue
233             }
234         }
235
236         if [info exists torture_execute_xfail] {
237             setup_xfail $torture_execute_xfail
238         }
239
240         if [info exists torture_eval_before_execute] {
241             set ignore_me [eval $torture_eval_before_execute]
242         }
243
244
245         # Sometimes we end up creating identical executables for two
246         # consecutive sets of different of compiler options.
247         #
248         # In such cases we know the result of this test will be identical
249         # to the result of the last test.
250         #
251         # So in cases where the time to load and run/simulate the test
252         # is relatively high, compare the two binaries and avoid rerunning
253         # tests if the executables are identical.
254         #
255         # Do not do this for native testing since the cost to load/execute
256         # the test is fairly small and the comparison step actually slows
257         # the entire process down because it usually does not "hit".
258         set skip 0
259         if { ![isnative] && [info exists oldexec] } {
260             if { [remote_file build cmp $oldexec $execname] == 0 } {
261                 set skip 1
262                 set status $oldstatus
263             }
264         }
265         if { $skip == 0 } {
266             set result [objc_load "$execname" "" ""]
267             set status [lindex $result 0]
268             set output [lindex $result 1]
269         }
270         $status "$testcase execution, $option"
271         set oldstatus $status
272     # for each option
273     } 
274     # tidy up
275     if [info exists execname] {
276         remote_file build delete $execname
277     }
278     if [info exists oldexec] {
279         remote_file build delete $oldexec
280     }
281 }
282
283 #
284 # search_for -- looks for a string match in a file
285 #
286 proc search_for { file pattern } {
287     set fd [open $file r]
288     while { [gets $fd cur_line]>=0 } {
289         if [string match "*$pattern*" $cur_line] then {
290             close $fd
291             return 1
292         }
293     }
294     close $fd
295     return 0
296 }
297
298 #
299 # objc-torture -- the objc-torture testcase source file processor
300 #
301 # This runs compilation only tests (no execute tests).
302 # SRC is the full pathname of the testcase, or just a file name in which case
303 # we prepend $srcdir/$subdir.
304 #
305 # If the testcase has an associated .x file, we source that to run the
306 # test instead.  We use .x so that we don't lengthen the existing filename
307 # to more than 14 chars.
308 #
309 proc objc-torture { args } {
310     global srcdir subdir compiler_conditional_xfail_data
311
312     set src [lindex $args 0]
313     if { [llength $args] > 1 } {
314         set options [lindex $args 1]
315     } else {
316         set options ""
317     }
318
319     # Prepend $srdir/$subdir if missing.
320     if ![string match "*/*" $src] {
321         set src "$srcdir/$subdir/$src"
322     }
323
324     # Check for alternate driver.
325     if [file exists [file rootname $src].x] {
326         verbose "Using alternate driver [file rootname [file tail $src]].x" 2
327         set done_p 0
328         catch "set done_p \[source [file rootname $src].x\]"
329         if { $done_p } {
330             return
331         }
332     }
333
334     # Look for a loop within the source code - if we don't find one,
335     # don't pass -funroll[-all]-loops.
336     global torture_with_loops torture_without_loops
337     if [expr [search_for $src "for*("]+[search_for $src "while*("]] then {
338             set option_list $torture_with_loops
339     } else {
340             set option_list $torture_without_loops
341     }
342
343     # loop through all the options
344     foreach option $option_list {
345         # torture_compile_xfail is set by the .x script (if present)
346         if [info exists torture_compile_xfail] {
347             setup_xfail $torture_compile_xfail
348         }
349
350         # torture_execute_before_compile is set by the .x script (if present)
351         if [info exists torture_eval_before_compile] {
352             set ignore_me [eval $torture_eval_before_compile]
353         }
354
355         objc-torture-compile $src "$option $options"
356     }
357 }