1 # Copyright
(C
) 1992-1998, 1999, 2000 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
2 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 this
program; if not
, write to the Free Software
15 # Foundation
, 51 Franklin Street
, Fifth Floor
, Boston
, MA
02110-1301, USA.
17 # This file was written by Rob Savoye.
(rob@cygnus.com
)
19 load_lib file
-format.exp
21 # The default option list can be overridden by
22 # TORTURE_OPTIONS
="{ { list1 } ... { listN } }"
24 if ![info exists TORTURE_OPTIONS
] {
25 # It is theoretically beneficial to group all of the O2
/O3 options together
,
26 # as in many cases the compiler will generate identical executables
for
27 # all of them
--and the c
-torture testsuite will skip testing identical
28 # executables multiple times.
29 # Also note that
-finline
-functions is explicitly included in one of the
30 # items below
, even though
-O3 is also specified
, because some ports may
31 # choose to disable inlining functions by default
, even when optimizing.
32 set TORTURE_OPTIONS
[list \
36 { -O3
-fomit
-frame
-pointer
} \
37 { -O3
-fomit
-frame
-pointer
-funroll
-loops
} \
38 { -O3
-fomit
-frame
-pointer
-funroll
-all
-loops
-finline
-functions
} \
44 # Split TORTURE_OPTIONS into two choices
: one
for testcases with loops and
45 # one
for testcases without loops.
47 set torture_with_loops $TORTURE_OPTIONS
48 set torture_without_loops
""
49 foreach option $TORTURE_OPTIONS
{
50 if ![string match
"*loop*" $option] {
51 lappend torture_without_loops $option
56 # c
-torture
-compile -- runs the Tege C
-torture test
58 # SRC is the full pathname of the testcase.
59 # OPTION is the specific compiler flag we
're testing (eg: -O2).
61 proc c-torture-compile { src option } {
66 set output "$tmpdir/[file tail [file rootname $src]].o"
68 regsub "(?q)$srcdir/" $src "" testcase
69 # If we couldn't rip $srcdir out of `src
' then just do the best we can.
70 # The point is to reduce the unnecessary noise in the logs. Don't
strip
71 # out too much because different testcases with the same
name can confuse
73 if [string match "/*" $testcase] {
74 set testcase "[file tail [file dirname $src]]/[file tail $src]"
77 verbose "Testing $testcase, $option" 1
79 # Run the compiler and analyze the results.
81 lappend options "additional_flags=-w $option"
83 set comp_output [gcc_target_compile "$src" "$output" object $options]
84 gcc_check_compile $testcase $option $output $comp_output
85 remote_file build delete $output
89 # c-torture-execute -- utility to compile and execute a testcase
91 # SOURCES is a list of full pathnames to the test source files.
92 # The first filename in this list forms the "testcase".
94 # If the testcase has an associated .x file, we source that to run the
95 # test instead. We use .x so that we don't lengthen the existing filename
96 # to more than
14 chars.
98 proc c
-torture
-execute { sources
args } {
99 global tmpdir tool srcdir output compiler_conditional_xfail_data
101 # Use the first source filename given as the filename under test.
102 set src
[lindex $sources
0]
104 if { [llength $
args] > 0 } {
105 set additional_flags
[lindex $
args 0]
107 set additional_flags
""
109 # Check
for alternate driver.
110 if [file
exists [file rootname $src
].x
] {
111 verbose
"Using alternate driver [file rootname [file tail $src]].x" 2
113 catch
"set done_p \[source [file rootname $src].x\]"
119 # Look
for a loop within the source code
- if we don
't find one,
120 # don't pass
-funroll
[-all
]-loops.
121 global torture_with_loops torture_without_loops
122 if [expr
[search_for $src
"for*("]+[search_for $src "while*("]] then {
123 set option_list $torture_with_loops
125 set option_list $torture_without_loops
128 set executable $tmpdir
/[file tail
[file rootname $src
].x
]
130 regsub
"(?q)$srcdir/" $src "" testcase
131 #
If we couldn
't rip $srcdir out of `src' then just
do the best we can.
132 # The point is to reduce the unnecessary noise in the logs. Don
't strip
133 # out too much because different testcases with the same name can confuse
135 if [string match
"/*" $testcase] {
136 set testcase
"[file tail [file dirname $src]]/[file tail $src]"
141 foreach option $option_list
{
143 set oldexec $execname
145 set execname
"${executable}${count}"
148 # torture_
{compile,execute}_xfail are
set by the .x script
150 if [info exists torture_compile_xfail
] {
151 setup_xfail $torture_compile_xfail
154 # torture_execute_before_
{compile,execute} can be
set by the .x script
156 if [info exists torture_eval_before_compile
] {
157 set ignore_me
[eval $torture_eval_before_compile
]
160 remote_file build
delete $execname
161 verbose
"Testing $testcase, $option" 1
164 lappend options
"additional_flags=-w $option"
165 if { $additional_flags
!= "" } {
166 lappend options
"additional_flags=$additional_flags"
168 set comp_output
[gcc_target_compile
"$sources" "${execname}" executable $options]
170 if ![gcc_check_compile
"$testcase compilation" $option $execname $comp_output] {
171 unresolved
"$testcase execution, $option"
172 remote_file build
delete $execname
176 # See
if this source file uses
"long long" types, if it does, and
177 # no_long_long is
set, skip execution of the test.
178 if [target_info
exists no_long_long
] then {
179 if [expr
[search_for $src
"long long"]] then {
180 unsupported
"$testcase execution, $option"
185 if [info exists torture_execute_xfail
] {
186 setup_xfail $torture_execute_xfail
189 if [info exists torture_eval_before_execute
] {
190 set ignore_me
[eval $torture_eval_before_execute
]
194 # Sometimes we end up creating identical executables
for two
195 # consecutive sets of different of compiler options.
197 # In such cases we know the result of this test will be identical
198 # to the result of the last test.
200 # So in cases where the time to
load and run
/simulate the test
201 # is relatively high
, compare the two binaries and avoid rerunning
202 # tests
if the executables are identical.
204 #
Do not
do this
for native testing since the cost to
load/execute
205 # the test is fairly small and the comparison step actually slows
206 # the entire process down because it usually does not
"hit".
208 if { ![isnative
] && [info exists oldexec
] } {
209 if { [remote_file build cmp $oldexec $execname
] == 0 } {
214 set result
[gcc_load
"$execname" "" ""]
215 set status [lindex $result
0]
216 set output
[lindex $result
1]
218 if { $oldstatus
== "pass" } {
219 remote_file build
delete $oldexec
221 $
status "$testcase execution, $option"
222 set oldstatus $
status
224 if [info exists status] {
225 if { $
status == "pass" } {
226 remote_file build
delete $execname
232 # search_for
-- looks
for a string match in a file
234 proc search_for
{ file pattern
} {
235 set fd
[open $file r
]
236 while { [gets $fd cur_line
]>=0 } {
237 if [string match
"*$pattern*" $cur_line] then {
247 # c
-torture
-- the c
-torture testcase source file processor
249 # This runs compilation only tests
(no
execute tests
).
250 # SRC is the full pathname of the testcase
, or just a file
name in which case
251 # we prepend $srcdir
/$subdir.
253 #
If the testcase has an associated .x file
, we source that to run the
254 # test instead. We use .x so that we don
't lengthen the existing filename
255 # to more than 14 chars.
257 proc c-torture { args } {
258 global srcdir subdir compiler_conditional_xfail_data
260 set src [lindex $args 0]
261 if { [llength $args] > 1 } {
262 set options [lindex $args 1]
267 # Prepend $srdir/$subdir if missing.
268 if ![string match "*/*" $src] {
269 set src "$srcdir/$subdir/$src"
272 # Check for alternate driver.
273 if [file exists [file rootname $src].x] {
274 verbose "Using alternate driver [file rootname [file tail $src]].x" 2
276 catch "set done_p \[source [file rootname $src].x\]"
282 # Look for a loop within the source code - if we don't find one
,
283 # don
't pass -funroll[-all]-loops.
284 global torture_with_loops torture_without_loops
285 if [expr [search_for $src "for*("]+[search_for $src "while*("]] then {
286 set option_list $torture_with_loops
288 set option_list $torture_without_loops
291 # loop through all the options
292 foreach option $option_list {
293 # torture_compile_xfail is set by the .x script (if present)
294 if [info exists torture_compile_xfail] {
295 setup_xfail $torture_compile_xfail
298 # torture_execute_before_compile is set by the .x script (if present)
299 if [info exists torture_eval_before_compile] {
300 set ignore_me [eval $torture_eval_before_compile]
303 c-torture-compile $src "$option $options"