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