1 # Copyright
(C
) 1992-2013 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
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" ) } {
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] {
54 verbose "options $options"
55 if [info exists dowhat] {
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 {
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
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"
91 perror "$dowhat: not a valid objc-torture action"
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 {
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
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 \
129 " -O3 -fomit-frame-pointer " \
130 " -O3 -fomit-frame-pointer -funroll-loops " \
131 " -O3 -fomit-frame-pointer -funroll-all-loops -finline-functions " \
136 if [info exists ADDITIONAL_TORTURE_OPTIONS] {
137 set OBJC_TORTURE_OPTIONS \
138 [concat $OBJC_TORTURE_OPTIONS $ADDITIONAL_TORTURE_OPTIONS]
142 # objc-torture-compile -- runs the Tege OBJC-torture test
144 # SRC is the full pathname of the testcase.
145 # OPTION is the specific compiler flag we're testing
(eg
: -O2
).
147 proc objc
-torture
-compile { src option
} {
152 set output
"$tmpdir/[file tail [file rootname $src]].o"
154 regsub
"(?q)$srcdir/" $src "" testcase
155 #
If we couldn
't rip $srcdir out of `src' then just
do the best we can.
156 # The point is to reduce the unnecessary noise in the logs. Don
't strip
157 # out too much because different testcases with the same name can confuse
159 if [string match
"/*" $testcase] {
160 set testcase
"[file tail [file dirname $src]]/[file tail $src]"
163 verbose
"Testing $testcase, $option" 1
165 # Run the compiler and analyze the results.
167 lappend options
"additional_flags=-w $option"
169 set comp_output
[objc_target_compile
"$src" "$output" object $options]
170 objc_check_compile $testcase $option $output $comp_output
171 remote_file build
delete $output
175 # objc
-torture
-execute -- utility to
compile and
execute a testcase
177 # SRC is the full pathname of the testcase.
179 #
If the testcase has an associated .x file
, we source that to run the
180 # test instead. We use .x so that we don
't lengthen the existing filename
181 # to more than 14 chars.
183 proc objc-torture-execute { src args } {
184 global tmpdir tool srcdir output compiler_conditional_xfail_data
186 if { [llength $args] > 0 } {
187 set additional_flags [lindex $args 0]
189 set additional_flags ""
191 # Check for alternate driver.
192 if [file exists [file rootname $src].x] {
193 verbose "Using alternate driver [file rootname [file tail $src]].x" 2
195 catch "set done_p \[source [file rootname $src].x\]"
201 # Look for a loop within the source code - if we don't find one
,
202 # don
't pass -funroll[-all]-loops.
203 global torture_with_loops torture_without_loops
204 if [expr [search_for $src "for*("]+[search_for $src "while*("]] then {
205 set option_list $torture_with_loops
207 set option_list $torture_without_loops
210 set executable $tmpdir/[file tail [file rootname $src].x]
212 regsub "(?q)$srcdir/" $src "" testcase
213 # If we couldn't rip $srcdir out of `src
' then just do the best we can.
214 # The point is to reduce the unnecessary noise in the logs. Don't
strip
215 # out too much because different testcases with the same
name can confuse
217 if [string match "/*" $testcase] {
218 set testcase "[file tail [file dirname $src]]/[file tail $src]"
223 foreach option $option_list {
225 if [info exists oldexec] {
226 remote_file build delete $oldexec
228 set oldexec $execname
230 set execname "${executable}${count}"
233 # torture_{compile,execute}_xfail are set by the .x script
235 if [info exists torture_compile_xfail] {
236 setup_xfail $torture_compile_xfail
239 # torture_execute_before_{compile,execute} can be set by the .x script
241 if [info exists torture_eval_before_compile] {
242 set ignore_me [eval $torture_eval_before_compile]
245 remote_file build delete $execname
246 verbose "Testing $testcase, $option" 1
249 lappend options "additional_flags=-w $option"
250 if { $additional_flags != "" } {
251 lappend options "additional_flags=$additional_flags"
253 set comp_output [objc_target_compile "$src" "${execname}" executable $options]
255 if ![objc_check_compile "$testcase compilation" $option $execname $comp_output] {
256 unresolved "$testcase execution, $option"
257 remote_file build delete $execname
261 # See if this source file uses "long long" types, if it does, and
262 # no_long_long is set, skip execution of the test.
263 if [target_info exists no_long_long] then {
264 if [expr [search_for $src "long long"]] then {
265 unsupported "$testcase execution, $option"
266 remote_file build delete $execname
271 if [info exists torture_execute_xfail] {
272 setup_xfail $torture_execute_xfail
275 if [info exists torture_eval_before_execute] {
276 set ignore_me [eval $torture_eval_before_execute]
280 # Sometimes we end up creating identical executables for two
281 # consecutive sets of different of compiler options.
283 # In such cases we know the result of this test will be identical
284 # to the result of the last test.
286 # So in cases where the time to load and run/simulate the test
287 # is relatively high, compare the two binaries and avoid rerunning
288 # tests if the executables are identical.
290 # Do not do this for native testing since the cost to load/execute
291 # the test is fairly small and the comparison step actually slows
292 # the entire process down because it usually does not "hit".
294 if { ![isnative] && [info exists oldexec] } {
295 if { [remote_file build cmp $oldexec $execname] == 0 } {
297 set status $oldstatus
301 set result [objc_load "$execname" "" ""]
302 set status [lindex $result 0]
303 set output [lindex $result 1]
305 $status "$testcase execution, $option"
306 set oldstatus $status
310 if [info exists execname] {
311 remote_file build delete $execname
313 if [info exists oldexec] {
314 remote_file build delete $oldexec
319 # search_for -- looks for a string match in a file
321 proc search_for { file pattern } {
322 set fd [open $file r]
323 while { [gets $fd cur_line]>=0 } {
324 if [string match "*$pattern*" $cur_line] then {
334 # objc-torture -- the objc-torture testcase source file processor
336 # This runs compilation only tests (no execute tests).
337 # SRC is the full pathname of the testcase, or just a file name in which case
338 # we prepend $srcdir/$subdir.
340 # If the testcase has an associated .x file, we source that to run the
341 # test instead. We use .x so that we don't lengthen the existing filename
342 # to more than
14 chars.
344 proc objc
-torture
{ args } {
345 global srcdir subdir compiler_conditional_xfail_data
347 set src
[lindex $
args 0]
348 if { [llength $
args] > 1 } {
349 set options
[lindex $
args 1]
354 # Prepend $srdir
/$subdir
if missing.
355 if ![string match
"*/*" $src] {
356 set src
"$srcdir/$subdir/$src"
359 # Check
for alternate driver.
360 if [file
exists [file rootname $src
].x
] {
361 verbose
"Using alternate driver [file rootname [file tail $src]].x" 2
363 catch
"set done_p \[source [file rootname $src].x\]"
369 # Look
for a loop within the source code
- if we don
't find one,
370 # don't pass
-funroll
[-all
]-loops.
371 global torture_with_loops torture_without_loops
372 if [expr
[search_for $src
"for*("]+[search_for $src "while*("]] then {
373 set option_list $torture_with_loops
375 set option_list $torture_without_loops
378 # loop through all the options
379 foreach option $option_list
{
380 # torture_compile_xfail is
set by the .x script
(if present
)
381 if [info exists torture_compile_xfail
] {
382 setup_xfail $torture_compile_xfail
385 # torture_execute_before_compile is
set by the .x script
(if present
)
386 if [info exists torture_eval_before_compile
] {
387 set ignore_me
[eval $torture_eval_before_compile
]
390 objc
-torture
-compile $src
"$option $options"