1 # Copyright
(C
) 1997, 1999, 2000, 2003, 2004, 2005 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
, Inc.
, 59 Temple Place
- Suite
330, Boston
, MA
02111-1307, USA.
18 load_lib file
-format.exp
19 load_lib target
-supports.exp
20 load_lib target
-supports
-dg.exp
25 load_lib target
-libpath.exp
27 # We
set LC_ALL and LANG to C so that we
get the same error messages as expected.
31 if ![info exists TORTURE_OPTIONS
] {
32 # It is theoretically beneficial to group all of the O2
/O3 options together
,
33 # as in many cases the compiler will generate identical executables
for
34 # all of them
--and the c
-torture testsuite will skip testing identical
35 # executables multiple times.
36 # Also note that
-finline
-functions is explicitly included in one of the
37 # items below
, even though
-O3 is also specified
, because some ports may
38 # choose to disable inlining functions by default
, even when optimizing.
39 set TORTURE_OPTIONS
[list \
43 { -O3
-fomit
-frame
-pointer
} \
44 { -O3
-fomit
-frame
-pointer
-funroll
-loops
} \
45 { -O3
-fomit
-frame
-pointer
-funroll
-all
-loops
-finline
-functions
} \
51 if ![info exists GCC_UNDER_TEST
] {
52 set GCC_UNDER_TEST
"[find_gcc]"
56 global ld_library_path
57 global orig_environment_saved
59 # This file may be sourced
, so don
't override environment settings
60 # that have been previously setup.
61 if { $orig_environment_saved == 0 } {
62 set ld_library_path "${rootme}"
63 set compiler [lindex $GCC_UNDER_TEST 0]
64 if { [is_remote host] == 0 && [which $compiler] != 0 } {
65 foreach i "[exec $compiler --print-multi-lib]" {
67 regexp -- "\[a-z0-9=/\.-\]*;" $i mldir
68 set mldir [string trimright $mldir "\;@"]
69 if { "$mldir" == "." } {
72 if { [llength [glob -nocomplain ${rootme}/${mldir}/libgcc_s*.so.*]] >= 1 } {
73 append ld_library_path ":${rootme}/${mldir}"
77 set_ld_library_path_env_vars
80 # Split TORTURE_OPTIONS into two choices: one for testcases with loops and
81 # one for testcases without loops.
83 set torture_with_loops $TORTURE_OPTIONS
84 set torture_without_loops ""
85 foreach option $TORTURE_OPTIONS {
86 if ![string match "*loop*" $option] {
87 lappend torture_without_loops $option
91 # Define gcc callbacks for dg.exp.
93 proc gcc-dg-test-1 { target_compile prog do_what extra_tool_flags } {
94 # Set up the compiler flags, based on what we're going to
do.
98 # Tests should be able to use
"dg-do repo". However, the dg test
99 # driver checks the
argument to dg
-do against a list of acceptable
100 # options
, and
"repo" is not among them. Therefore, we resort to
101 # this ugly approach.
102 if [string match
"*-frepo*" $extra_tool_flags] then {
108 set compile_type
"preprocess"
109 set output_file
"[file rootname [file tail $prog]].i"
112 set compile_type
"assembly"
113 set output_file
"[file rootname [file tail $prog]].s"
116 set compile_type
"object"
117 set output_file
"[file rootname [file tail $prog]].o"
120 set compile_type
"precompiled_header"
121 set output_file
"[file tail $prog].gch"
124 set compile_type
"executable"
125 set output_file
"[file rootname [file tail $prog]].exe"
126 # The following line is needed
for targets like the i960 where
127 # the default output file is b.out. Sigh.
130 set compile_type
"object"
131 set output_file
"[file rootname [file tail $prog]].o"
134 set compile_type
"executable"
135 # FIXME
: "./" is to cope with "." not being in $PATH.
136 # Should this be handled elsewhere?
138 set output_file
"./[file rootname [file tail $prog]].exe"
139 # This is the only place where we care
if an executable was
140 # created or not.
If it was
, dg.exp will try to run it.
141 remote_file build
delete $output_file
;
144 perror
"$do_what: not a valid dg-do keyword"
149 if { $extra_tool_flags
!= "" } {
150 lappend options
"additional_flags=$extra_tool_flags"
153 set comp_output
[$target_compile
"$prog" "$output_file" "$compile_type" $options];
155 if { $do_what
== "repo" } {
156 set object_file
"$output_file"
157 set output_file
"[file rootname [file tail $prog]].exe"
159 [ concat $comp_output \
160 [$target_compile
"$object_file" "$output_file" \
161 "executable" $options] ]
164 return [list $comp_output $output_file
]
167 proc gcc
-dg
-test
{ prog do_what extra_tool_flags
} {
168 return [gcc
-dg
-test
-1 gcc_target_compile $prog $do_what $extra_tool_flags
]
171 proc gcc
-dg
-prune
{ system text } {
172 global additional_prunes
174 set text [prune_gcc_output $
text]
176 foreach p $additional_prunes
{
177 if { [string length $p
] > 0 } {
178 # Following regexp matches a complete line containing $p.
179 regsub
-all
"(^|\n)\[^\n\]*$p\[^\n\]*" $text "" text
183 #
If we see
"region xxx is full" then the testcase is too big for ram.
184 # This is tricky to deal with in a large testsuite like c
-torture so
185 # deal with it here. Just mark the testcase as unsupported.
186 if [regexp
"(^|\n)\[^\n\]*: region \[^\n\]* is full" $text] {
187 # The format here is important. See dg.exp.
188 return "::unsupported::memory full"
197 # search_for
-- looks
for a string match in a file
199 proc search_for
{ file pattern
} {
200 set fd
[open $file r
]
201 while { [gets $fd cur_line
]>=0 } {
202 if [string match
"*$pattern*" $cur_line] then {
211 # Modified dg
-runtest that can cycle through a list of optimization options
213 proc gcc
-dg
-runtest
{ testcases default
-extra
-flags
} {
216 foreach test $testcases
{
217 #
If we
're only testing specific files and this isn't one of
219 if ![runtest_file_p $runtests $test
] {
223 # Look
for a loop within the source code
- if we don
't find one,
224 # don't pass
-funroll
[-all
]-loops.
225 global torture_with_loops torture_without_loops
226 if [expr
[search_for $test
"for*("]+[search_for $test "while*("]] {
227 set option_list $torture_with_loops
229 set option_list $torture_without_loops
232 set nshort
[file tail
[file dirname $test
]]/[file tail $test
]
234 foreach flags $option_list
{
235 verbose
"Testing $nshort, $flags" 1
236 dg
-test $test $flags $
{default
-extra
-flags
}
241 proc gcc
-dg
-debug
-runtest
{ target_compile trivial opt_opts testcases
} {
244 if ![info exists DEBUG_TORTURE_OPTIONS
] {
245 set DEBUG_TORTURE_OPTIONS
""
246 foreach type
{-gdwarf
-2 -gstabs
-gstabs
+ -gxcoff
-gxcoff
+ -gcoff
} {
247 set comp_output
[$target_compile \
248 "$srcdir/$subdir/$trivial" "trivial.S" assembly \
249 "additional_flags=$type"]
250 if { ! [string match
"*: target system does not support the * debug format*" \
252 foreach level
{1 "" 3} {
253 lappend DEBUG_TORTURE_OPTIONS
[list
"${type}${level}"]
254 foreach opt $opt_opts
{
255 lappend DEBUG_TORTURE_OPTIONS \
256 [list
"${type}${level}" "$opt" ]
263 verbose
-log "Using options $DEBUG_TORTURE_OPTIONS"
267 foreach test $testcases
{
268 #
If we
're only testing specific files and this isn't one of
270 if ![runtest_file_p $runtests $test
] {
274 set nshort
[file tail
[file dirname $test
]]/[file tail $test
]
276 foreach flags $DEBUG_TORTURE_OPTIONS
{
278 if { [string match
{*/debug
-[126].c
} "$nshort"] \
279 && [string match
"*1" [lindex "$flags" 0] ] } {
283 # High optimization can remove the
variable whose existence is tested.
284 # Dwarf debugging with commentary
(-dA
) preserves the symbol
name in the
285 # assembler output
, but stabs debugging does not.
286 # http
://gcc.gnu.org
/ml
/gcc
-regression
/2003-04/msg00095.html
287 if { [string match
{*/debug
-[12].c
} "$nshort"] \
288 && [string match
"*O*" "$flags"] \
289 && ( [string match
"*coff*" "$flags"] \
290 ||
[string match
"*stabs*" "$flags"] ) } {
295 verbose
-log "Testing $nshort, $flags" 1
296 dg
-test $test $flags
""
302 # Prune
any messages matching
ARGS[1] (a regexp
) from test output.
303 proc dg
-prune
-output
{ args } {
304 global additional_prunes
306 if { [llength $
args] != 2 } {
307 error
"[lindex $args 1]: need one argument"
311 lappend additional_prunes
[lindex $
args 1]
314 # We need to make sure that additional_
* are cleared out after
every
315 # test. It is not enough to clear them out
*before
* the next test run
316 # because gcc
-target
-compile gets run directly from some .exp files
317 #
(outside of
any test
).
(Those uses should eventually be eliminated.
)
319 # Because the DG framework doesn
't provide a hook that is run at the
320 # end of a test, we must replace dg-test with a wrapper.
322 if { [info procs saved-dg-test] == [list] } {
323 rename dg-test saved-dg-test
325 proc dg-test { args } {
326 global additional_files
327 global additional_sources
328 global additional_prunes
330 global compiler_conditional_xfail_data
332 if { [ catch { eval saved-dg-test $args } errmsg ] } {
333 set saved_info $errorInfo
334 set additional_files ""
335 set additional_sources ""
336 set additional_prunes ""
337 if [info exists compiler_conditional_xfail_data] {
338 unset compiler_conditional_xfail_data
340 error $errmsg $saved_info
342 set additional_files ""
343 set additional_sources ""
344 set additional_prunes ""
345 if [info exists compiler_conditional_xfail_data] {
346 unset compiler_conditional_xfail_data
351 set additional_prunes ""