OSDN Git Service

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