1 # Copyright (C) 1992-1998, 1999, 2000, 2007, 2008
2 # Free Software Foundation, Inc.
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.
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.
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/>.
18 # This file was written by Rob Savoye. (rob@cygnus.com)
20 load_lib file-format.exp
21 load_lib target-supports.exp
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" ]
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" ) } {
39 set OBJC_RUNTIME_OPTIONS ""
41 foreach type $rtlist {
42 global srcdir subdir target_triplet tmpdir
44 set options "additional_flags=$type"
45 if [info exists args] {
48 verbose "options $options"
49 if [info exists dowhat] {
52 set compile_type "assembly"
53 set output_file "trivial.s"
54 set comp_output [objc_target_compile \
55 "$srcdir/$subdir/trivial.m" "$output_file" "$compile_type" $options]
57 remote_file build delete $output_file
58 # If we get any error, then we failed.
59 if ![string match "" $comp_output] then {
64 set test_obj "trivial.exe"
65 set comp_output [objc_target_compile \
66 "$srcdir/$subdir/trivial.m" $test_obj "executable" $options]
68 # If we get any error, then we failed.
69 if ![string match "" $comp_output] then {
70 remote_file build delete $test_obj
73 set result [objc_load "$tmpdir/$test_obj" "" ""]
74 set status [lindex $result 0]
75 set output [lindex $result 1]
76 remote_file build delete $test_obj
77 if { $status != "pass" } {
78 verbose -log "trivial execute failed with $status $output"
83 perror "$dowhat: not a valid objc-torture action"
88 set test_obj "trivial.exe"
89 set comp_output [objc_target_compile \
90 "$srcdir/$subdir/trivial.m" $test_obj executable $options]
92 # If we get any error, then we failed.
93 remote_file build delete $test_obj
94 if ![string match "" $comp_output] then {
98 lappend OBJC_RUNTIME_OPTIONS $type
101 verbose -log "Using the following runtimes: $OBJC_RUNTIME_OPTIONS"
104 # The default option list can be overridden by
105 # TORTURE_OPTIONS="{ { list1 } ... { listN } }"
107 if [info exists TORTURE_OPTIONS] {
108 set OBJC_TORTURE_OPTIONS $TORTURE_OPTIONS
110 # It is theoretically beneficial to group all of the O2/O3 options together,
111 # as in many cases the compiler will generate identical executables for
112 # all of them--and the objc-torture testsuite will skip testing identical
113 # executables multiple times.
114 # Also note that -finline-functions is explicitly included in one of the
115 # items below, even though -O3 is also specified, because some ports may
116 # choose to disable inlining functions by default, even when optimizing.
117 set OBJC_TORTURE_OPTIONS [list \
121 " -O3 -fomit-frame-pointer " \
122 " -O3 -fomit-frame-pointer -funroll-loops " \
123 " -O3 -fomit-frame-pointer -funroll-all-loops -finline-functions " \
128 if [info exists ADDITIONAL_TORTURE_OPTIONS] {
129 set OBJC_TORTURE_OPTIONS \
130 [concat $OBJC_TORTURE_OPTIONS $ADDITIONAL_TORTURE_OPTIONS]
134 # objc-torture-compile -- runs the Tege OBJC-torture test
136 # SRC is the full pathname of the testcase.
137 # OPTION is the specific compiler flag we're testing (eg: -O2).
139 proc objc-torture-compile { src option } {
144 set output "$tmpdir/[file tail [file rootname $src]].o"
146 regsub "(?q)$srcdir/" $src "" testcase
147 # If we couldn't rip $srcdir out of `src' then just do the best we can.
148 # The point is to reduce the unnecessary noise in the logs. Don't strip
149 # out too much because different testcases with the same name can confuse
151 if [string match "/*" $testcase] {
152 set testcase "[file tail [file dirname $src]]/[file tail $src]"
155 verbose "Testing $testcase, $option" 1
157 # Run the compiler and analyze the results.
159 lappend options "additional_flags=-w $option"
161 set comp_output [objc_target_compile "$src" "$output" object $options]
162 objc_check_compile $testcase $option $output $comp_output
163 remote_file build delete $output
167 # objc-torture-execute -- utility to compile and execute a testcase
169 # SRC is the full pathname of the testcase.
171 # If the testcase has an associated .x file, we source that to run the
172 # test instead. We use .x so that we don't lengthen the existing filename
173 # to more than 14 chars.
175 proc objc-torture-execute { src args } {
176 global tmpdir tool srcdir output compiler_conditional_xfail_data
178 if { [llength $args] > 0 } {
179 set additional_flags [lindex $args 0]
181 set additional_flags ""
183 # Check for alternate driver.
184 if [file exists [file rootname $src].x] {
185 verbose "Using alternate driver [file rootname [file tail $src]].x" 2
187 catch "set done_p \[source [file rootname $src].x\]"
193 # Look for a loop within the source code - if we don't find one,
194 # don't pass -funroll[-all]-loops.
195 global torture_with_loops torture_without_loops
196 if [expr [search_for $src "for*("]+[search_for $src "while*("]] then {
197 set option_list $torture_with_loops
199 set option_list $torture_without_loops
202 set executable $tmpdir/[file tail [file rootname $src].x]
204 regsub "(?q)$srcdir/" $src "" testcase
205 # If we couldn't rip $srcdir out of `src' then just do the best we can.
206 # The point is to reduce the unnecessary noise in the logs. Don't strip
207 # out too much because different testcases with the same name can confuse
209 if [string match "/*" $testcase] {
210 set testcase "[file tail [file dirname $src]]/[file tail $src]"
215 foreach option $option_list {
217 if [info exists oldexec] {
218 remote_file build delete $oldexec
220 set oldexec $execname
222 set execname "${executable}${count}"
225 # torture_{compile,execute}_xfail are set by the .x script
227 if [info exists torture_compile_xfail] {
228 setup_xfail $torture_compile_xfail
231 # torture_execute_before_{compile,execute} can be set by the .x script
233 if [info exists torture_eval_before_compile] {
234 set ignore_me [eval $torture_eval_before_compile]
237 remote_file build delete $execname
238 verbose "Testing $testcase, $option" 1
241 lappend options "additional_flags=-w $option"
242 if { $additional_flags != "" } {
243 lappend options "additional_flags=$additional_flags"
245 set comp_output [objc_target_compile "$src" "${execname}" executable $options]
247 if ![objc_check_compile "$testcase compilation" $option $execname $comp_output] {
248 unresolved "$testcase execution, $option"
249 remote_file build delete $execname
253 # See if this source file uses "long long" types, if it does, and
254 # no_long_long is set, skip execution of the test.
255 if [target_info exists no_long_long] then {
256 if [expr [search_for $src "long long"]] then {
257 unsupported "$testcase execution, $option"
258 remote_file build delete $execname
263 if [info exists torture_execute_xfail] {
264 setup_xfail $torture_execute_xfail
267 if [info exists torture_eval_before_execute] {
268 set ignore_me [eval $torture_eval_before_execute]
272 # Sometimes we end up creating identical executables for two
273 # consecutive sets of different of compiler options.
275 # In such cases we know the result of this test will be identical
276 # to the result of the last test.
278 # So in cases where the time to load and run/simulate the test
279 # is relatively high, compare the two binaries and avoid rerunning
280 # tests if the executables are identical.
282 # Do not do this for native testing since the cost to load/execute
283 # the test is fairly small and the comparison step actually slows
284 # the entire process down because it usually does not "hit".
286 if { ![isnative] && [info exists oldexec] } {
287 if { [remote_file build cmp $oldexec $execname] == 0 } {
289 set status $oldstatus
293 set result [objc_load "$execname" "" ""]
294 set status [lindex $result 0]
295 set output [lindex $result 1]
297 $status "$testcase execution, $option"
298 set oldstatus $status
302 if [info exists execname] {
303 remote_file build delete $execname
305 if [info exists oldexec] {
306 remote_file build delete $oldexec
311 # search_for -- looks for a string match in a file
313 proc search_for { file pattern } {
314 set fd [open $file r]
315 while { [gets $fd cur_line]>=0 } {
316 if [string match "*$pattern*" $cur_line] then {
326 # objc-torture -- the objc-torture testcase source file processor
328 # This runs compilation only tests (no execute tests).
329 # SRC is the full pathname of the testcase, or just a file name in which case
330 # we prepend $srcdir/$subdir.
332 # If the testcase has an associated .x file, we source that to run the
333 # test instead. We use .x so that we don't lengthen the existing filename
334 # to more than 14 chars.
336 proc objc-torture { args } {
337 global srcdir subdir compiler_conditional_xfail_data
339 set src [lindex $args 0]
340 if { [llength $args] > 1 } {
341 set options [lindex $args 1]
346 # Prepend $srdir/$subdir if missing.
347 if ![string match "*/*" $src] {
348 set src "$srcdir/$subdir/$src"
351 # Check for alternate driver.
352 if [file exists [file rootname $src].x] {
353 verbose "Using alternate driver [file rootname [file tail $src]].x" 2
355 catch "set done_p \[source [file rootname $src].x\]"
361 # Look for a loop within the source code - if we don't find one,
362 # don't pass -funroll[-all]-loops.
363 global torture_with_loops torture_without_loops
364 if [expr [search_for $src "for*("]+[search_for $src "while*("]] then {
365 set option_list $torture_with_loops
367 set option_list $torture_without_loops
370 # loop through all the options
371 foreach option $option_list {
372 # torture_compile_xfail is set by the .x script (if present)
373 if [info exists torture_compile_xfail] {
374 setup_xfail $torture_compile_xfail
377 # torture_execute_before_compile is set by the .x script (if present)
378 if [info exists torture_eval_before_compile] {
379 set ignore_me [eval $torture_eval_before_compile]
382 objc-torture-compile $src "$option $options"