1 # Copyright
(C
) 1992-1998, 1999, 2000, 2007 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
21 if ![info exists OBJC_RUNTIME_OPTIONS
] {
22 set OBJC_RUNTIME_OPTIONS
""
23 foreach type
{-fgnu
-runtime
-fnext
-runtime
} {
26 set comp_output
[objc_target_compile \
27 "$srcdir/$subdir/trivial.m" "trivial.exe" executable "additional_flags=$type"]
29 #
If we
get any error
, then we failed
30 if ![string match
"" $comp_output] then {
33 lappend OBJC_RUNTIME_OPTIONS $type
36 verbose
-log "Using the following runtimes: $OBJC_RUNTIME_OPTIONS"
39 # The default option list can be overridden by
40 # TORTURE_OPTIONS
="{ { list1 } ... { listN } }"
42 if [info exists TORTURE_OPTIONS
] {
43 set OBJC_TORTURE_OPTIONS $TORTURE_OPTIONS
45 # It is theoretically beneficial to group all of the O2
/O3 options together
,
46 # as in many cases the compiler will generate identical executables
for
47 # all of them
--and the objc
-torture testsuite will skip testing identical
48 # executables multiple times.
49 # Also note that
-finline
-functions is explicitly included in one of the
50 # items below
, even though
-O3 is also specified
, because some ports may
51 # choose to disable inlining functions by default
, even when optimizing.
52 set OBJC_TORTURE_OPTIONS
[list \
56 " -O3 -fomit-frame-pointer " \
57 " -O3 -fomit-frame-pointer -funroll-loops " \
58 " -O3 -fomit-frame-pointer -funroll-all-loops -finline-functions " \
64 # objc
-torture
-compile -- runs the Tege OBJC
-torture test
66 # SRC is the full pathname of the testcase.
67 # OPTION is the specific compiler flag we
're testing (eg: -O2).
69 proc objc-torture-compile { src option } {
74 set output "$tmpdir/[file tail [file rootname $src]].o"
76 regsub "(?q)$srcdir/" $src "" testcase
77 # If we couldn't rip $srcdir out of `src
' then just do the best we can.
78 # The point is to reduce the unnecessary noise in the logs. Don't
strip
79 # out too much because different testcases with the same
name can confuse
81 if [string match "/*" $testcase] {
82 set testcase "[file tail [file dirname $src]]/[file tail $src]"
85 verbose "Testing $testcase, $option" 1
87 # Run the compiler and analyze the results.
89 lappend options "additional_flags=-w $option"
91 set comp_output [objc_target_compile "$src" "$output" object $options]
92 objc_check_compile $testcase $option $output $comp_output
93 remote_file build delete $output
97 # objc-torture-execute -- utility to compile and execute a testcase
99 # SRC is the full pathname of the testcase.
101 # If the testcase has an associated .x file, we source that to run the
102 # test instead. We use .x so that we don't lengthen the existing filename
103 # to more than
14 chars.
105 proc objc
-torture
-execute { src
args } {
106 global tmpdir tool srcdir output compiler_conditional_xfail_data
108 if { [llength $
args] > 0 } {
109 set additional_flags
[lindex $
args 0]
111 set additional_flags
""
113 # Check
for alternate driver.
114 if [file
exists [file rootname $src
].x
] {
115 verbose
"Using alternate driver [file rootname [file tail $src]].x" 2
117 catch
"set done_p \[source [file rootname $src].x\]"
123 # Look
for a loop within the source code
- if we don
't find one,
124 # don't pass
-funroll
[-all
]-loops.
125 global torture_with_loops torture_without_loops
126 if [expr
[search_for $src
"for*("]+[search_for $src "while*("]] then {
127 set option_list $torture_with_loops
129 set option_list $torture_without_loops
132 set executable $tmpdir
/[file tail
[file rootname $src
].x
]
134 regsub
"(?q)$srcdir/" $src "" testcase
135 #
If we couldn
't rip $srcdir out of `src' then just
do the best we can.
136 # The point is to reduce the unnecessary noise in the logs. Don
't strip
137 # out too much because different testcases with the same name can confuse
139 if [string match
"/*" $testcase] {
140 set testcase
"[file tail [file dirname $src]]/[file tail $src]"
145 foreach option $option_list
{
147 set oldexec $execname
149 set execname
"${executable}${count}"
152 # torture_
{compile,execute}_xfail are
set by the .x script
154 if [info exists torture_compile_xfail
] {
155 setup_xfail $torture_compile_xfail
158 # torture_execute_before_
{compile,execute} can be
set by the .x script
160 if [info exists torture_eval_before_compile
] {
161 set ignore_me
[eval $torture_eval_before_compile
]
164 remote_file build
delete $execname
165 verbose
"Testing $testcase, $option" 1
168 lappend options
"additional_flags=-w $option"
169 if { $additional_flags
!= "" } {
170 lappend options
"additional_flags=$additional_flags"
172 set comp_output
[objc_target_compile
"$src" "${execname}" executable $options]
174 if ![objc_check_compile
"$testcase compilation" $option $execname $comp_output] {
175 unresolved
"$testcase execution, $option"
176 remote_file build
delete $execname
180 # See
if this source file uses
"long long" types, if it does, and
181 # no_long_long is
set, skip execution of the test.
182 if [target_info
exists no_long_long
] then {
183 if [expr
[search_for $src
"long long"]] then {
184 unsupported
"$testcase execution, $option"
189 if [info exists torture_execute_xfail
] {
190 setup_xfail $torture_execute_xfail
193 if [info exists torture_eval_before_execute
] {
194 set ignore_me
[eval $torture_eval_before_execute
]
198 # Sometimes we end up creating identical executables
for two
199 # consecutive sets of different of compiler options.
201 # In such cases we know the result of this test will be identical
202 # to the result of the last test.
204 # So in cases where the time to
load and run
/simulate the test
205 # is relatively high
, compare the two binaries and avoid rerunning
206 # tests
if the executables are identical.
208 #
Do not
do this
for native testing since the cost to
load/execute
209 # the test is fairly small and the comparison step actually slows
210 # the entire process down because it usually does not
"hit".
212 if { ![isnative
] && [info exists oldexec
] } {
213 if { [remote_file build cmp $oldexec $execname
] == 0 } {
218 set result
[objc_load
"$execname" "" ""]
219 set status [lindex $result
0]
220 set output
[lindex $result
1]
222 if { $oldstatus
== "pass" } {
223 remote_file build
delete $oldexec
225 $
status "$testcase execution, $option"
226 set oldstatus $
status
228 if [info exists status] {
229 if { $
status == "pass" } {
230 remote_file build
delete $execname
236 # search_for
-- looks
for a string match in a file
238 proc search_for
{ file pattern
} {
239 set fd
[open $file r
]
240 while { [gets $fd cur_line
]>=0 } {
241 if [string match
"*$pattern*" $cur_line] then {
251 # objc
-torture
-- the objc
-torture testcase source file processor
253 # This runs compilation only tests
(no
execute tests
).
254 # SRC is the full pathname of the testcase
, or just a file
name in which case
255 # we prepend $srcdir
/$subdir.
257 #
If the testcase has an associated .x file
, we source that to run the
258 # test instead. We use .x so that we don
't lengthen the existing filename
259 # to more than 14 chars.
261 proc objc-torture { args } {
262 global srcdir subdir compiler_conditional_xfail_data
264 set src [lindex $args 0]
265 if { [llength $args] > 1 } {
266 set options [lindex $args 1]
271 # Prepend $srdir/$subdir if missing.
272 if ![string match "*/*" $src] {
273 set src "$srcdir/$subdir/$src"
276 # Check for alternate driver.
277 if [file exists [file rootname $src].x] {
278 verbose "Using alternate driver [file rootname [file tail $src]].x" 2
280 catch "set done_p \[source [file rootname $src].x\]"
286 # Look for a loop within the source code - if we don't find one
,
287 # don
't pass -funroll[-all]-loops.
288 global torture_with_loops torture_without_loops
289 if [expr [search_for $src "for*("]+[search_for $src "while*("]] then {
290 set option_list $torture_with_loops
292 set option_list $torture_without_loops
295 # loop through all the options
296 foreach option $option_list {
297 # torture_compile_xfail is set by the .x script (if present)
298 if [info exists torture_compile_xfail] {
299 setup_xfail $torture_compile_xfail
302 # torture_execute_before_compile is set by the .x script (if present)
303 if [info exists torture_eval_before_compile] {
304 set ignore_me [eval $torture_eval_before_compile]
307 objc-torture-compile $src "$option $options"