1 # Copyright
(C
) 1997, 1999, 2000, 2003, 2004, 2005, 2006
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
2 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 this
program; if not
, write to the Free Software
16 # Foundation
, Inc.
, 51 Franklin Street
, Fifth Floor
, Boston
, MA
02110-1301, USA.
19 load_lib file
-format.exp
20 load_lib target
-supports.exp
21 load_lib target
-supports
-dg.exp
28 load_lib target
-libpath.exp
30 # We
set LC_ALL and LANG to C so that we
get the same error messages as expected.
34 if ![info exists TORTURE_OPTIONS
] {
35 # It is theoretically beneficial to group all of the O2
/O3 options together
,
36 # as in many cases the compiler will generate identical executables
for
37 # all of them
--and the c
-torture testsuite will skip testing identical
38 # executables multiple times.
39 # Also note that
-finline
-functions is explicitly included in one of the
40 # items below
, even though
-O3 is also specified
, because some ports may
41 # choose to disable inlining functions by default
, even when optimizing.
42 set TORTURE_OPTIONS
[list \
46 { -O3
-fomit
-frame
-pointer
} \
47 { -O3
-fomit
-frame
-pointer
-funroll
-loops
} \
48 { -O3
-fomit
-frame
-pointer
-funroll
-all
-loops
-finline
-functions
} \
54 if ![info exists GCC_UNDER_TEST
] {
55 set GCC_UNDER_TEST
"[find_gcc]"
58 global orig_environment_saved
60 # This file may be sourced
, so don
't override environment settings
61 # that have been previously setup.
62 if { $orig_environment_saved == 0 } {
63 append ld_library_path [gcc-set-multilib-library-path $GCC_UNDER_TEST]
64 set_ld_library_path_env_vars
67 # Split TORTURE_OPTIONS into two choices: one for testcases with loops and
68 # one for testcases without loops.
70 set torture_with_loops $TORTURE_OPTIONS
71 set torture_without_loops ""
72 foreach option $TORTURE_OPTIONS {
73 if ![string match "*loop*" $option] {
74 lappend torture_without_loops $option
78 # Define gcc callbacks for dg.exp.
80 proc gcc-dg-test-1 { target_compile prog do_what extra_tool_flags } {
81 # Set up the compiler flags, based on what we're going to
do.
85 # Tests should be able to use
"dg-do repo". However, the dg test
86 # driver checks the
argument to dg
-do against a list of acceptable
87 # options
, and
"repo" is not among them. Therefore, we resort to
89 if [string match
"*-frepo*" $extra_tool_flags] then {
95 set compile_type
"preprocess"
96 set output_file
"[file rootname [file tail $prog]].i"
99 set compile_type
"assembly"
100 set output_file
"[file rootname [file tail $prog]].s"
103 set compile_type
"object"
104 set output_file
"[file rootname [file tail $prog]].o"
107 set compile_type
"precompiled_header"
108 set output_file
"[file tail $prog].gch"
111 set compile_type
"executable"
112 set output_file
"[file rootname [file tail $prog]].exe"
113 # The following line is needed
for targets like the i960 where
114 # the default output file is b.out. Sigh.
117 set compile_type
"object"
118 set output_file
"[file rootname [file tail $prog]].o"
121 set compile_type
"executable"
122 # FIXME
: "./" is to cope with "." not being in $PATH.
123 # Should this be handled elsewhere?
125 set output_file
"./[file rootname [file tail $prog]].exe"
126 # This is the only place where we care
if an executable was
127 # created or not.
If it was
, dg.exp will try to run it.
128 catch
{ remote_file build
delete $output_file
}
131 perror
"$do_what: not a valid dg-do keyword"
136 if { $extra_tool_flags
!= "" } {
137 lappend options
"additional_flags=$extra_tool_flags"
140 set comp_output
[$target_compile
"$prog" "$output_file" "$compile_type" $options]
142 if { $do_what
== "repo" } {
143 set object_file
"$output_file"
144 set output_file
"[file rootname [file tail $prog]].exe"
146 [ concat $comp_output \
147 [$target_compile
"$object_file" "$output_file" \
148 "executable" $options] ]
151 return [list $comp_output $output_file
]
154 proc gcc
-dg
-test
{ prog do_what extra_tool_flags
} {
155 return [gcc
-dg
-test
-1 gcc_target_compile $prog $do_what $extra_tool_flags
]
158 proc gcc
-dg
-prune
{ system text } {
159 global additional_prunes
161 set text [prune_gcc_output $
text]
163 foreach p $additional_prunes
{
164 if { [string length $p
] > 0 } {
165 # Following regexp matches a complete line containing $p.
166 regsub
-all
"(^|\n)\[^\n\]*$p\[^\n\]*" $text "" text
170 #
If we see
"region xxx is full" then the testcase is too big for ram.
171 # This is tricky to deal with in a large testsuite like c
-torture so
172 # deal with it here. Just mark the testcase as unsupported.
173 if [regexp
"(^|\n)\[^\n\]*: region \[^\n\]* is full" $text] {
174 # The format here is important. See dg.exp.
175 return "::unsupported::memory full"
184 # search_for
-- looks
for a string match in a file
186 proc search_for
{ file pattern
} {
187 set fd
[open $file r
]
188 while { [gets $fd cur_line
]>=0 } {
189 if [string match
"*$pattern*" $cur_line] then {
198 # Modified dg
-runtest that can cycle through a list of optimization options
200 proc gcc
-dg
-runtest
{ testcases default
-extra
-flags
} {
203 foreach test $testcases
{
204 #
If we
're only testing specific files and this isn't one of
206 if ![runtest_file_p $runtests $test
] {
210 # Look
for a loop within the source code
- if we don
't find one,
211 # don't pass
-funroll
[-all
]-loops.
212 global torture_with_loops torture_without_loops
213 if [expr
[search_for $test
"for*("]+[search_for $test "while*("]] {
214 set option_list $torture_with_loops
216 set option_list $torture_without_loops
219 set nshort
[file tail
[file dirname $test
]]/[file tail $test
]
221 foreach flags $option_list
{
222 verbose
"Testing $nshort, $flags" 1
223 dg
-test $test $flags $
{default
-extra
-flags
}
228 proc gcc
-dg
-debug
-runtest
{ target_compile trivial opt_opts testcases
} {
231 if ![info exists DEBUG_TORTURE_OPTIONS
] {
232 set DEBUG_TORTURE_OPTIONS
""
233 foreach type
{-gdwarf
-2 -gstabs
-gstabs
+ -gxcoff
-gxcoff
+ -gcoff
} {
234 set comp_output
[$target_compile \
235 "$srcdir/$subdir/$trivial" "trivial.S" assembly \
236 "additional_flags=$type"]
237 if { ! [string match
"*: target system does not support the * debug format*" \
239 foreach level
{1 "" 3} {
240 lappend DEBUG_TORTURE_OPTIONS
[list
"${type}${level}"]
241 foreach opt $opt_opts
{
242 lappend DEBUG_TORTURE_OPTIONS \
243 [list
"${type}${level}" "$opt" ]
250 verbose
-log "Using options $DEBUG_TORTURE_OPTIONS"
254 foreach test $testcases
{
255 #
If we
're only testing specific files and this isn't one of
257 if ![runtest_file_p $runtests $test
] {
261 set nshort
[file tail
[file dirname $test
]]/[file tail $test
]
263 foreach flags $DEBUG_TORTURE_OPTIONS
{
265 if { [string match
{*/debug
-[126].c
} "$nshort"] \
266 && [string match
"*1" [lindex "$flags" 0] ] } {
270 # High optimization can remove the
variable whose existence is tested.
271 # Dwarf debugging with commentary
(-dA
) preserves the symbol
name in the
272 # assembler output
, but stabs debugging does not.
273 # http
://gcc.gnu.org
/ml
/gcc
-regression
/2003-04/msg00095.html
274 if { [string match
{*/debug
-[12].c
} "$nshort"] \
275 && [string match
"*O*" "$flags"] \
276 && ( [string match
"*coff*" "$flags"] \
277 ||
[string match
"*stabs*" "$flags"] ) } {
282 verbose
-log "Testing $nshort, $flags" 1
283 dg
-test $test $flags
""
289 # Prune
any messages matching
ARGS[1] (a regexp
) from test output.
290 proc dg
-prune
-output
{ args } {
291 global additional_prunes
293 if { [llength $
args] != 2 } {
294 error
"[lindex $args 1]: need one argument"
298 lappend additional_prunes
[lindex $
args 1]
301 # Remove files matching the pattern from the build machine.
302 proc remove
-build
-file
{ pat
} {
303 verbose
"remove-build-file `$pat'" 2
304 set file_list
"[glob -nocomplain $pat]"
305 verbose
"remove-build-file `$file_list'" 2
306 foreach output_file $file_list
{
307 remote_file build
delete $output_file
311 # Remove compiler
-generated coverage files
for the current test.
312 proc cleanup
-coverage
-files
{ } {
313 # This assumes that we are two frames down from dg
-test or some other proc
314 # that stores the filename of the testcase in a local
variable "name".
315 # A cleaner solution would require a new DejaGnu release.
316 upvar
2 name testcase
317 remove
-build
-file
"[file rootname [file tail $testcase]].gc??"
319 # Clean up coverage files
for additional source files.
320 if [info exists additional_sources
] {
321 foreach srcfile $additional_sources
{
322 remove
-build
-file
"[file rootname [file tail $srcfile]].gc??"
327 # Remove compiler
-generated files from
-repo
for the current test.
328 proc cleanup
-repo
-files
{ } {
329 # This assumes that we are two frames down from dg
-test or some other proc
330 # that stores the filename of the testcase in a local
variable "name".
331 # A cleaner solution would require a new DejaGnu release.
332 upvar
2 name testcase
333 remove
-build
-file
"[file rootname [file tail $testcase]].o"
334 remove
-build
-file
"[file rootname [file tail $testcase]].rpo"
336 # Clean up files
for additional source files.
337 if [info exists additional_sources
] {
338 foreach srcfile $additional_sources
{
339 remove
-build
-file
"[file rootname [file tail $srcfile]].o"
340 remove
-build
-file
"[file rootname [file tail $srcfile]].rpo"
345 # Remove compiler
-generated RTL dump files
for the current test.
347 # SUFFIX is the filename suffix pattern.
348 proc cleanup
-rtl
-dump
{ suffix
} {
349 cleanup
-dump
"\[0-9\]\[0-9\]\[0-9\]r.$suffix"
352 # Remove a specific tree dump file
for the current test.
354 # SUFFIX is the tree dump file suffix pattern.
355 proc cleanup
-tree
-dump
{ suffix
} {
356 cleanup
-dump
"\[0-9\]\[0-9\]\[0-9\]t.$suffix"
359 # Remove a specific ipa dump file
for the current test.
361 # SUFFIX is the ipa dump file suffix pattern.
362 proc cleanup
-ipa
-dump
{ suffix
} {
363 cleanup
-dump
"\[0-9\]\[0-9\]\[0-9\]i.$suffix"
366 # Remove all dump files with the provided suffix.
367 proc cleanup
-dump
{ suffix
} {
368 # This assumes that we are three frames down from dg
-test or some other
369 # proc that stores the filename of the testcase in a local
variable
370 #
"name". A cleaner solution would require a new DejaGnu release.
371 upvar
3 name testcase
372 # The
name might
include a list of options
; extract the file
name.
373 set src
[file tail
[lindex $testcase
0]]
374 remove
-build
-file
"[file tail $src].$suffix"
376 # Clean up dump files
for additional source files.
377 if [info exists additional_sources
] {
378 foreach srcfile $additional_sources
{
379 remove
-build
-file
"[file tail $srcfile].$suffix"
384 # Remove files kept by
--save
-temps
for the current test.
386 # Currently this is only .i files
, but more can be added
if there are
387 # tests generating them.
388 proc cleanup
-saved
-temps
{ } {
389 global additional_sources
391 # This assumes that we are two frames down from dg
-test or some other proc
392 # that stores the filename of the testcase in a local
variable "name".
393 # A cleaner solution would require a new DejaGnu release.
394 upvar
2 name testcase
395 remove
-build
-file
"[file rootname [file tail $testcase]].ii"
396 remove
-build
-file
"[file rootname [file tail $testcase]].i"
398 # Clean up saved temp files
for additional source files.
399 if [info exists additional_sources
] {
400 foreach srcfile $additional_sources
{
401 remove
-build
-file
"[file rootname [file tail $srcfile]].ii"
402 remove
-build
-file
"[file rootname [file tail $srcfile]].i"
407 # We need to make sure that additional_
* are cleared out after
every
408 # test. It is not enough to clear them out
*before
* the next test run
409 # because gcc
-target
-compile gets run directly from some .exp files
410 #
(outside of
any test
).
(Those uses should eventually be eliminated.
)
412 # Because the DG framework doesn
't provide a hook that is run at the
413 # end of a test, we must replace dg-test with a wrapper.
415 if { [info procs saved-dg-test] == [list] } {
416 rename dg-test saved-dg-test
418 proc dg-test { args } {
419 global additional_files
420 global additional_sources
421 global additional_prunes
423 global compiler_conditional_xfail_data
425 if { [ catch { eval saved-dg-test $args } errmsg ] } {
426 set saved_info $errorInfo
427 set additional_files ""
428 set additional_sources ""
429 set additional_prunes ""
430 if [info exists compiler_conditional_xfail_data] {
431 unset compiler_conditional_xfail_data
433 error $errmsg $saved_info
435 set additional_files ""
436 set additional_sources ""
437 set additional_prunes ""
438 if [info exists compiler_conditional_xfail_data] {
439 unset compiler_conditional_xfail_data
444 set additional_prunes ""