2015-09-24 Vladimir Makarov <vmakarov@redhat.com>
[official-gcc.git] / gcc / testsuite / lib / objc-torture.exp
blob87d301785aa1b40ff1be0ff4f01693a793d122c9
1 # Copyright (C) 1992-2015 Free Software Foundation, Inc.
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 3 of the License, or
6 # (at your option) any later version.
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.
13 # You should have received a copy of the GNU General Public License
14 # along with GCC; see the file COPYING3. If not see
15 # <http://www.gnu.org/licenses/>.
17 # This file was written by Rob Savoye. (rob@cygnus.com)
19 load_lib file-format.exp
20 load_lib target-supports.exp
22 # Make sure that the runtime list is re-evaluated for each multilib.
23 proc objc-set-runtime-options { dowhat args } {
24 global OBJC_RUNTIME_OPTIONS
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.
32 if [istarget *-*-darwin*] {
33 lappend rtlist "-fnext-runtime"
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
41 lappend rtlist $other
45 set OBJC_RUNTIME_OPTIONS ""
47 foreach type $rtlist {
48 global srcdir subdir target_triplet tmpdir
50 set options "additional_flags=$type"
51 if [info exists args] {
52 lappend options $args
54 verbose "options $options"
55 if [info exists dowhat] {
56 switch $dowhat {
57 "compile" {
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"
62 set comp_output [objc_target_compile \
63 "$srcdir/$subdir/trivial.m" "$output_file" "$compile_type" $options]
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;
71 "execute" {
72 set test_obj "trivial.exe"
73 set comp_output [objc_target_compile \
74 "$srcdir/$subdir/trivial.m" $test_obj "executable" $options]
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;
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;
90 default {
91 perror "$dowhat: not a valid objc-torture action"
92 return ""
95 } else {
96 set test_obj "trivial.exe"
97 set comp_output [objc_target_compile \
98 "$srcdir/$subdir/trivial.m" $test_obj executable $options]
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;
106 lappend OBJC_RUNTIME_OPTIONS $type
109 verbose -log "Using the following runtimes: $OBJC_RUNTIME_OPTIONS"
112 # The default option list can be overridden by
113 # TORTURE_OPTIONS="{ { list1 } ... { listN } }"
115 if [info exists TORTURE_OPTIONS] {
116 set OBJC_TORTURE_OPTIONS $TORTURE_OPTIONS
117 } else {
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.
125 set OBJC_TORTURE_OPTIONS [list \
126 " -O0 " \
127 " -O1 " \
128 " -O2 " \
129 " -O3 -fomit-frame-pointer -funroll-loops -fpeel-loops -ftracer -finline-functions " \
130 " -O3 -g " \
131 " -Os " ]
134 if [info exists ADDITIONAL_TORTURE_OPTIONS] {
135 set OBJC_TORTURE_OPTIONS \
136 [concat $OBJC_TORTURE_OPTIONS $ADDITIONAL_TORTURE_OPTIONS]
140 # objc-torture-compile -- runs the Tege OBJC-torture test
142 # SRC is the full pathname of the testcase.
143 # OPTION is the specific compiler flag we're testing (eg: -O2).
145 proc objc-torture-compile { src option } {
146 global output
147 global srcdir tmpdir
148 global host_triplet
150 set output "$tmpdir/[file tail [file rootname $src]].o"
152 regsub "(?q)$srcdir/" $src "" testcase
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]"
161 verbose "Testing $testcase, $option" 1
163 # Run the compiler and analyze the results.
164 set options ""
165 lappend options "additional_flags=-w $option"
167 set comp_output [objc_target_compile "$src" "$output" object $options]
168 objc_check_compile $testcase $option $output $comp_output
169 remote_file build delete $output
173 # objc-torture-execute -- utility to compile and execute a testcase
175 # SRC is the full pathname of the testcase.
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.
181 proc objc-torture-execute { src args } {
182 global tmpdir tool srcdir output compiler_conditional_xfail_data
184 if { [llength $args] > 0 } {
185 set additional_flags [lindex $args 0]
186 } else {
187 set additional_flags ""
189 # Check for alternate driver.
190 if [file exists [file rootname $src].x] {
191 verbose "Using alternate driver [file rootname [file tail $src]].x" 2
192 set done_p 0
193 catch "set done_p \[source [file rootname $src].x\]"
194 if { $done_p } {
195 return
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
202 if [expr [search_for $src "for*("]+[search_for $src "while*("]] then {
203 set option_list $torture_with_loops
204 } else {
205 set option_list $torture_without_loops
208 set executable $tmpdir/[file tail [file rootname $src].x]
210 regsub "(?q)$srcdir/" $src "" testcase
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]"
219 set count 0
220 set oldstatus "foo"
221 foreach option $option_list {
222 if { $count > 0 } {
223 if [info exists oldexec] {
224 remote_file build delete $oldexec
226 set oldexec $execname
228 set execname "${executable}${count}"
229 incr count
231 # torture_{compile,execute}_xfail are set by the .x script
232 # (if present)
233 if [info exists torture_compile_xfail] {
234 setup_xfail $torture_compile_xfail
237 # torture_execute_before_{compile,execute} can be set by the .x script
238 # (if present)
239 if [info exists torture_eval_before_compile] {
240 set ignore_me [eval $torture_eval_before_compile]
243 remote_file build delete $execname
244 verbose "Testing $testcase, $option" 1
246 set options ""
247 lappend options "additional_flags=-w $option"
248 if { $additional_flags != "" } {
249 lappend options "additional_flags=$additional_flags"
251 set comp_output [objc_target_compile "$src" "${execname}" executable $options]
253 if ![objc_check_compile "$testcase compilation" $option $execname $comp_output] {
254 unresolved "$testcase execution, $option"
255 remote_file build delete $execname
256 continue
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 {
262 if [expr [search_for $src "long long"]] then {
263 unsupported "$testcase execution, $option"
264 remote_file build delete $execname
265 continue
269 if [info exists torture_execute_xfail] {
270 setup_xfail $torture_execute_xfail
273 if [info exists torture_eval_before_execute] {
274 set ignore_me [eval $torture_eval_before_execute]
278 # Sometimes we end up creating identical executables for two
279 # consecutive sets of different of compiler options.
281 # In such cases we know the result of this test will be identical
282 # to the result of the last test.
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.
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".
291 set skip 0
292 if { ![isnative] && [info exists oldexec] } {
293 if { [remote_file build cmp $oldexec $execname] == 0 } {
294 set skip 1
295 set status $oldstatus
298 if { $skip == 0 } {
299 set result [objc_load "$execname" "" ""]
300 set status [lindex $result 0]
301 set output [lindex $result 1]
303 $status "$testcase execution, $option"
304 set oldstatus $status
305 # for each option
307 # tidy up
308 if [info exists execname] {
309 remote_file build delete $execname
311 if [info exists oldexec] {
312 remote_file build delete $oldexec
317 # search_for -- looks for a string match in a file
319 proc search_for { file pattern } {
320 set fd [open $file r]
321 while { [gets $fd cur_line]>=0 } {
322 if [string match "*$pattern*" $cur_line] then {
323 close $fd
324 return 1
327 close $fd
328 return 0
332 # objc-torture -- the objc-torture testcase source file processor
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.
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.
342 proc objc-torture { args } {
343 global srcdir subdir compiler_conditional_xfail_data
345 set src [lindex $args 0]
346 if { [llength $args] > 1 } {
347 set options [lindex $args 1]
348 } else {
349 set options ""
352 # Prepend $srdir/$subdir if missing.
353 if ![string match "*/*" $src] {
354 set src "$srcdir/$subdir/$src"
357 # Check for alternate driver.
358 if [file exists [file rootname $src].x] {
359 verbose "Using alternate driver [file rootname [file tail $src]].x" 2
360 set done_p 0
361 catch "set done_p \[source [file rootname $src].x\]"
362 if { $done_p } {
363 return
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
370 if [expr [search_for $src "for*("]+[search_for $src "while*("]] then {
371 set option_list $torture_with_loops
372 } else {
373 set option_list $torture_without_loops
376 # loop through all the options
377 foreach option $option_list {
378 # torture_compile_xfail is set by the .x script (if present)
379 if [info exists torture_compile_xfail] {
380 setup_xfail $torture_compile_xfail
383 # torture_execute_before_compile is set by the .x script (if present)
384 if [info exists torture_eval_before_compile] {
385 set ignore_me [eval $torture_eval_before_compile]
388 objc-torture-compile $src "$option $options"