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
22 if ![info exists OBJC_RUNTIME_OPTIONS] {
23 set OBJC_RUNTIME_OPTIONS ""
24 foreach type {-fgnu-runtime -fnext-runtime} {
27 set comp_output [objc_target_compile \
28 "$srcdir/$subdir/trivial.m" "trivial.exe" executable "additional_flags=$type"]
30 # If we get any error, then we failed
31 if ![string match "" $comp_output] then {
34 lappend OBJC_RUNTIME_OPTIONS $type
37 verbose -log "Using the following runtimes: $OBJC_RUNTIME_OPTIONS"
40 # The default option list can be overridden by
41 # TORTURE_OPTIONS="{ { list1 } ... { listN } }"
43 if [info exists TORTURE_OPTIONS] {
44 set OBJC_TORTURE_OPTIONS $TORTURE_OPTIONS
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 \
57 " -O3 -fomit-frame-pointer " \
58 " -O3 -fomit-frame-pointer -funroll-loops " \
59 " -O3 -fomit-frame-pointer -funroll-all-loops -finline-functions " \
64 if [info exists ADDITIONAL_TORTURE_OPTIONS] {
65 set OBJC_TORTURE_OPTIONS \
66 [concat $OBJC_TORTURE_OPTIONS $ADDITIONAL_TORTURE_OPTIONS]
70 # objc-torture-compile -- runs the Tege OBJC-torture test
72 # SRC is the full pathname of the testcase.
73 # OPTION is the specific compiler flag we're testing (eg: -O2).
75 proc objc-torture-compile { src option } {
80 set output "$tmpdir/[file tail [file rootname $src]].o"
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
87 if [string match "/*" $testcase] {
88 set testcase "[file tail [file dirname $src]]/[file tail $src]"
91 verbose "Testing $testcase, $option" 1
93 # Run the compiler and analyze the results.
95 lappend options "additional_flags=-w $option"
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
103 # objc-torture-execute -- utility to compile and execute a testcase
105 # SRC is the full pathname of the testcase.
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.
111 proc objc-torture-execute { src args } {
112 global tmpdir tool srcdir output compiler_conditional_xfail_data
114 if { [llength $args] > 0 } {
115 set additional_flags [lindex $args 0]
117 set additional_flags ""
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
123 catch "set done_p \[source [file rootname $src].x\]"
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
135 set option_list $torture_without_loops
138 set executable $tmpdir/[file tail [file rootname $src].x]
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
145 if [string match "/*" $testcase] {
146 set testcase "[file tail [file dirname $src]]/[file tail $src]"
151 foreach option $option_list {
153 set oldexec $execname
155 set execname "${executable}${count}"
158 # torture_{compile,execute}_xfail are set by the .x script
160 if [info exists torture_compile_xfail] {
161 setup_xfail $torture_compile_xfail
164 # torture_execute_before_{compile,execute} can be set by the .x script
166 if [info exists torture_eval_before_compile] {
167 set ignore_me [eval $torture_eval_before_compile]
170 remote_file build delete $execname
171 verbose "Testing $testcase, $option" 1
174 lappend options "additional_flags=-w $option"
175 if { $additional_flags != "" } {
176 lappend options "additional_flags=$additional_flags"
178 set comp_output [objc_target_compile "$src" "${execname}" executable $options]
180 if ![objc_check_compile "$testcase compilation" $option $execname $comp_output] {
181 unresolved "$testcase execution, $option"
182 remote_file build delete $execname
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"
195 if [info exists torture_execute_xfail] {
196 setup_xfail $torture_execute_xfail
199 if [info exists torture_eval_before_execute] {
200 set ignore_me [eval $torture_eval_before_execute]
204 # Sometimes we end up creating identical executables for two
205 # consecutive sets of different of compiler options.
207 # In such cases we know the result of this test will be identical
208 # to the result of the last test.
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.
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".
218 if { ![isnative] && [info exists oldexec] } {
219 if { [remote_file build cmp $oldexec $execname] == 0 } {
224 set result [objc_load "$execname" "" ""]
225 set status [lindex $result 0]
226 set output [lindex $result 1]
228 if { $oldstatus == "pass" } {
229 remote_file build delete $oldexec
231 $status "$testcase execution, $option"
232 set oldstatus $status
234 if [info exists status] {
235 if { $status == "pass" } {
236 remote_file build delete $execname
242 # search_for -- looks for a string match in a file
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 {
257 # objc-torture -- the objc-torture testcase source file processor
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.
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.
267 proc objc-torture { args } {
268 global srcdir subdir compiler_conditional_xfail_data
270 set src [lindex $args 0]
271 if { [llength $args] > 1 } {
272 set options [lindex $args 1]
277 # Prepend $srdir/$subdir if missing.
278 if ![string match "*/*" $src] {
279 set src "$srcdir/$subdir/$src"
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
286 catch "set done_p \[source [file rootname $src].x\]"
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
298 set option_list $torture_without_loops
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
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]
313 objc-torture-compile $src "$option $options"