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