1 # Copyright
(C
) 1997-2017 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
/>.
18 load_lib file
-format.exp
19 load_lib target
-supports.exp
20 load_lib target
-supports
-dg.exp
26 load_lib timeout
-dg.exp
29 load_lib target
-libpath.exp
30 load_lib torture
-options.exp
31 load_lib fortran
-modules.exp
32 load_lib multiline.exp
34 # We
set LC_ALL and LANG to C so that we
get the same error messages as expected.
38 # Many hosts now default to a non
-ASCII C locale
, however
, so
39 # they can
set a
charset encoding here
if they need.
40 if { [ishost
"*-*-cygwin*"] } {
46 if ![info exists GCC_UNDER_TEST
] {
47 set GCC_UNDER_TEST
"[find_gcc]"
50 # This file may be sourced
, so don
't override environment settings
51 # that have been previously setup.
52 if { $orig_environment_saved == 0 } {
53 append ld_library_path [gcc-set-multilib-library-path $GCC_UNDER_TEST]
54 set_ld_library_path_env_vars
57 # Some torture-options cause intermediate code output, unusable for
58 # testing using e.g. scan-assembler. In this variable are the options
59 # how to force it, when needed.
60 global gcc_force_conventional_output
61 set gcc_force_conventional_output ""
63 set LTO_TORTURE_OPTIONS ""
64 if [info exists TORTURE_OPTIONS] {
65 set DG_TORTURE_OPTIONS $TORTURE_OPTIONS
67 # It is theoretically beneficial to group all of the O2/O3 options together,
68 # as in many cases the compiler will generate identical executables for
69 # all of them--and the c-torture testsuite will skip testing identical
70 # executables multiple times.
71 # Also note that -finline-functions is explicitly included in one of the
72 # items below, even though -O3 is also specified, because some ports may
73 # choose to disable inlining functions by default, even when optimizing.
74 set DG_TORTURE_OPTIONS [list \
78 { -O3 -fomit-frame-pointer -funroll-loops -fpeel-loops -ftracer -finline-functions } \
82 if [check_effective_target_lto] {
83 # When having plugin test both slim and fat LTO and plugin/nonplugin
85 if [check_linker_plugin_available] {
86 set LTO_TORTURE_OPTIONS [list \
87 { -O2 -flto -fno-use-linker-plugin -flto-partition=none } \
88 { -O2 -flto -fuse-linker-plugin -fno-fat-lto-objects }
91 set LTO_TORTURE_OPTIONS [list \
92 { -O2 -flto -flto-partition=none } \
96 set gcc_force_conventional_output "-ffat-lto-objects"
100 if [info exists ADDITIONAL_TORTURE_OPTIONS] {
101 set DG_TORTURE_OPTIONS \
102 [concat $DG_TORTURE_OPTIONS $ADDITIONAL_TORTURE_OPTIONS]
105 global orig_environment_saved
107 # Deduce generated files from tool flags, return finalcode string
108 proc schedule-cleanups { opts } {
109 global additional_sources
112 lappend testcases [lindex [testname-for-summary] 0]
113 verbose "Cleanup testcases: $testcases" 4
114 if { [info exists additional_sources] && $additional_sources != "" } {
115 lappend testcases $additional_sources
116 verbose "Cleanup testcases, additional: $additional_sources" 4
118 verbose "Cleanup all options: $opts" 4
120 # First some fixups to transform stuff to something manageable ..
121 # --dump= should translate to -d with joined operand.
122 if [regexp -- {(^|\s+)--dump=[^\s]+(\s+|$)} $opts] {
123 regsub -all -- {--dump=} $opts {-d} opts
125 # -da and -dx are treated as shorthand for -fdump-rtl-all here
126 if [regexp -- {(^|\s+)-d[ax](\s+|$)} $opts] {
127 verbose "Cleanup -d seen" 4
128 lappend opts "-fdump-rtl-all"
130 # .. and don't question why there is
--dump
=? and
-d?
132 #
Then handle options that generate non
-dump files
134 #
-fprofile
-generate
-> cleanup
-coverage
-files
()
135 #
-fstack
-usage
-> cleanup
-stack
-usage
()
136 if [regexp
-- {(^|\s
+)-fstack
-usage
(\s
+|$
)} $opts
] {
137 verbose
"Cleanup -fstack-usage seen" 4
138 # append finalcode
"cleanup-stack-usage\n"
140 global keep_saved_temps_suffixes
141 if [info exists keep_saved_temps_suffixes
] {
142 verbose
"dg-keep-saved-temps ${keep_saved_temps_suffixes}" 2
144 #
-save
-temps
-> cleanup
-saved
-temps
()
145 if [regexp
-- {(^|\s
+)-save
-temps
(\s
+|$
)} $opts
] {
146 verbose
"Cleanup -save-temps seen" 4
147 if [info exists keep_saved_temps_suffixes
] {
148 append finalcode
"cleanup-saved-temps ${keep_saved_temps_suffixes}\n"
150 append finalcode
"cleanup-saved-temps\n"
153 if [info exists keep_saved_temps_suffixes
] {
154 error
"dg-keep-saved-temps specified but testcase does not -save-temps"
158 # Finally see
if there are
any dumps in opts
, otherwise we are done
159 if [regexp
-- {(?
=(?
:^|
[ \t]+)?
)-fdump
-[^
\t]+(?
=(?
:$|
[ \t]+)?
)} $opts
] {
160 # Ipa
, Rtl
, Tree
for simplicity
165 # stem.ext.
<passnum
><fam
>.
<passname
><pass
-instances
>
166 #
(tree
)passes can have multiple instances
, thus optional trailing
*
167 set ptn
"\[0-9\]\[0-9\]\[0-9\]$ptn.*"
168 # Handle ltrans files around
-flto
169 if [regexp
-- {(^|\s
+)-flto
(\s
+|$
)} $opts
] {
170 verbose
"Cleanup -flto seen" 4
171 set ltrans
"{ltrans\[0-9\]*.,}"
175 set ptn
"$ltrans$ptn"
176 verbose
"Cleanup final ptn: $ptn" 4
178 foreach src $testcases
{
179 set basename
[file tail $src
]
180 if { $ltrans
!= "" } {
181 # ??? should we use upvar
1 output_file instead of this
(dup ?
)
182 set stem
[file rootname $basename
]
183 set basename_ext
[file extension $basename
]
184 if {$basename_ext
!= ""} {
185 regsub
-- {^.
*\.
} $basename_ext
{} basename_ext
187 lappend tfiles
"$stem.{$basename_ext,exe}"
190 lappend tfiles $basename
193 if { [llength $tfiles
] > 1 } {
194 set tfiles
[join $tfiles
","]
195 set tfiles
"{$tfiles}"
197 verbose
"Cleanup final testcases: $tfiles" 4
198 # We have to quote the regex
199 regsub
-all
{([][$^?
+*()|
\\{}])} "$tfiles.$ptn" {\\\1} ptn
201 append final
{remove
-build
-file
}
202 append final
"\"$ptn\""
203 verbose
"Cleanup final: $final" 4
204 append finalcode
"$final\n"
209 #
Define gcc callbacks
for dg.exp.
211 proc gcc
-dg
-test
-1 { target_compile prog do_what extra_tool_flags
} {
212 #
Set up the compiler flags
, based
on what we
're going to do.
216 # Tests should be able to use "dg-do repo". However, the dg test
217 # driver checks the argument to dg-do against a list of acceptable
218 # options, and "repo" is not among them. Therefore, we resort to
219 # this ugly approach.
220 if [string match "*-frepo*" $extra_tool_flags] then {
226 set compile_type "preprocess"
227 set output_file "[file rootname [file tail $prog]].i"
230 set compile_type "assembly"
231 set output_file "[file rootname [file tail $prog]].s"
234 set compile_type "object"
235 set output_file "[file rootname [file tail $prog]].o"
238 set compile_type "precompiled_header"
239 set output_file "[file tail $prog].gch"
242 set compile_type "executable"
243 set output_file "[file rootname [file tail $prog]].exe"
244 # The following line is needed for targets like the i960 where
245 # the default output file is b.out. Sigh.
248 set compile_type "object"
249 set output_file "[file rootname [file tail $prog]].o"
252 set compile_type "executable"
253 # FIXME: "./" is to cope with "." not being in $PATH.
254 # Should this be handled elsewhere?
256 set output_file "./[file rootname [file tail $prog]].exe"
257 # This is the only place where we care if an executable was
258 # created or not. If it was, dg.exp will try to run it.
259 catch { remote_file build delete $output_file }
262 perror "$do_what: not a valid dg-do keyword"
267 # Let { dg-final { action } } force options as returned by an
268 # optional proc ${action}_required_options.
269 upvar 2 dg-final-code finalcode
270 foreach x [split $finalcode "\n"] {
271 set finalcmd [lindex $x 0]
272 if { [info procs ${finalcmd}_required_options] != "" } {
273 set req [${finalcmd}_required_options]
274 if { $req != "" && [lsearch -exact $extra_tool_flags $req] == -1 } {
275 lappend extra_tool_flags $req
280 append finalcode [schedule-cleanups "$options $extra_tool_flags"]
281 if { $extra_tool_flags != "" } {
282 lappend options "additional_flags=$extra_tool_flags"
285 verbose "$target_compile $prog $output_file $compile_type $options" 4
286 set comp_output [$target_compile "$prog" "$output_file" "$compile_type" $options]
288 # Look for an internal compiler error, which sometimes masks the fact
289 # that we didn't
get an expected error message. XFAIL an ICE via
290 # dg
-xfail
-if and use
{ dg
-prune
-output
".*internal compiler error.*" }
291 # to avoid a second failure
for excess errors.
292 if [string match
"*internal compiler error*" $comp_output] {
294 fail
"$name (internal compiler error)"
297 if { $do_what
== "repo" } {
298 set object_file
"$output_file"
299 set output_file
"[file rootname [file tail $prog]].exe"
301 [ concat $comp_output \
302 [$target_compile
"$object_file" "$output_file" \
303 "executable" $options] ]
306 return [list $comp_output $output_file
]
309 proc gcc
-dg
-test
{ prog do_what extra_tool_flags
} {
310 return [gcc
-dg
-test
-1 gcc_target_compile $prog $do_what $extra_tool_flags
]
313 # Global
: should
blank lines be allowed in the output?
314 # By default
, they should not be.
(PR other
/69006)
315 # However
, there are some ways
for them to validly occur.
316 set allow_blank_lines
0
318 # A command
for use by testcases to mark themselves as expecting
319 #
blank lines in the output.
321 proc dg
-allow
-blank-lines
-in
-output
{ args } {
322 global allow_blank_lines
323 set allow_blank_lines
1
326 proc gcc
-dg
-prune
{ system text } {
327 global additional_prunes
329 # Extra prune rules that will apply to tests defined in a .exp file.
330 # Always remember to clear it in .exp file after executed all tests.
331 global dg_runtest_extra_prunes
333 # Complain about
blank lines in the output
(PR other
/69006)
334 global allow_blank_lines
335 if { !$allow_blank_lines
} {
336 set num_blank_lines
[llength
[regexp
-all
-inline
"\n\n" $text]]
337 if { $num_blank_lines
} {
338 global testname_with_flags
339 fail
"$testname_with_flags $num_blank_lines blank line(s) in output"
341 set allow_blank_lines
0
344 set text [prune_gcc_output $
text]
346 foreach p
"$additional_prunes $dg_runtest_extra_prunes" {
347 if { [string length $p
] > 0 } {
348 # Following regexp matches a complete line containing $p.
349 regsub
-all
"(^|\n)\[^\n\]*$p\[^\n\]*" $text "" text
353 #
If we see
"region xxx is full" then the testcase is too big for ram.
354 # This is tricky to deal with in a large testsuite like c
-torture so
355 # deal with it here. Just mark the testcase as unsupported.
356 if [regexp
"(^|\n)\[^\n\]*: region \[^\n\]* is full" $text] {
357 # The format here is important. See dg.exp.
358 return "::unsupported::memory full"
361 if { [regexp
"(^|\n)\[^\n\]*: relocation truncated to fit" $text]
362 && [check_effective_target_tiny
] } {
363 return "::unsupported::memory full"
366 # Likewise
, if we see
".text exceeds local store range" or
368 if {[string match
"spu-*" $system] && \
369 [string match
"*exceeds local store*" $text]} {
370 # The format here is important. See dg.exp.
371 return "::unsupported::memory full"
377 # Replace $
{tool
}_load with a wrapper to provide
for an expected nonzero
378 # exit
status. Multiple languages
include this file so this handles them
380 if { [info procs $
{tool
}_load
] != [list
] \
381 && [info procs saved_$
{tool
}_load
] == [list
] } {
382 rename $
{tool
}_load saved_$
{tool
}_load
384 proc $
{tool
}_load
{ program args } {
387 global set_target_env_var
389 set saved_target_env_var
[list
]
390 if { [info exists set_target_env_var
] \
391 && [llength $set_target_env_var
] != 0 } {
392 if { [is_remote target
] } {
393 return [list
"unsupported" ""]
397 set result
[eval
[list saved_$
{tool
}_load $
program] $
args]
398 if { [info exists set_target_env_var
] \
399 && [llength $set_target_env_var
] != 0 } {
400 restore
-target
-env
-var
402 if { $shouldfail
!= 0 } {
403 switch [lindex $result
0] {
404 "pass" { set status "fail" }
405 "fail" { set status "pass" }
406 default
{ set status [lindex $result
0] }
408 set result
[list $
status [lindex $result
1]]
411 set result
[list
[lindex $result
0] [prune_file_path
[lindex $result
1]]]
416 proc dg
-set-target
-env
-var
{ args } {
417 global set_target_env_var
418 if { [llength $
args] != 3 } {
419 error
"dg-set-target-env-var: need two arguments"
422 lappend set_target_env_var
[list
[lindex $
args 1] [lindex $
args 2]]
425 proc
set-target
-env
-var
{ } {
426 global set_target_env_var
427 upvar
1 saved_target_env_var saved_target_env_var
428 foreach env_var $set_target_env_var
{
429 set var
[lindex $env_var
0]
430 set value
[lindex $env_var
1]
431 if [info exists ::env
($var
)] {
432 lappend saved_target_env_var
[list $var
1 $
::env
($var
)]
434 lappend saved_target_env_var
[list $var
0]
440 proc restore
-target
-env
-var
{ } {
441 upvar
1 saved_target_env_var saved_target_env_var
442 for { set env_vari
[llength $saved_target_env_var
] } {
443 [incr env_vari
-1] >= 0 } {} {
444 set env_var
[lindex $saved_target_env_var $env_vari
]
445 set var
[lindex $env_var
0]
446 if [lindex $env_var
1] {
447 setenv $var
[lindex $env_var
2]
454 proc dg
-set-compiler
-env
-var
{ args } {
455 global set_compiler_env_var
456 global saved_compiler_env_var
457 if { [llength $
args] != 3 } {
458 error
"dg-set-compiler-env-var: need two arguments"
461 set var
[lindex $
args 1]
462 set value
[lindex $
args 2]
463 if [info exists ::env
($var
)] {
464 lappend saved_compiler_env_var
[list $var
1 $
::env
($var
)]
466 lappend saved_compiler_env_var
[list $var
0]
469 lappend set_compiler_env_var
[list $var $value
]
472 proc restore
-compiler
-env
-var
{ } {
473 global saved_compiler_env_var
474 for { set env_vari
[llength $saved_compiler_env_var
] } {
475 [incr env_vari
-1] >= 0 } {} {
476 set env_var
[lindex $saved_compiler_env_var $env_vari
]
477 set var
[lindex $env_var
0]
478 if [lindex $env_var
1] {
479 setenv $var
[lindex $env_var
2]
489 # search_for
-- looks
for a string match in a file
491 proc search_for
{ file pattern
} {
492 set fd
[open $file r
]
493 while { [gets $fd cur_line
]>=0 } {
494 if [string match
"*$pattern*" $cur_line] then {
503 # Modified dg
-runtest that can cycle through a list of optimization options
505 proc gcc
-dg
-runtest
{ testcases flags default
-extra
-flags
} {
508 # Some callers
set torture options themselves
; don
't override those.
509 set existing_torture_options [torture-options-exist]
510 if { $existing_torture_options == 0 } {
511 global DG_TORTURE_OPTIONS LTO_TORTURE_OPTIONS
513 set-torture-options $DG_TORTURE_OPTIONS [list {}] $LTO_TORTURE_OPTIONS
517 foreach test $testcases {
518 global torture_with_loops torture_without_loops
519 # If we're only testing specific files and this isn
't one of
521 if ![runtest_file_p $runtests $test] {
525 # Look for a loop within the source code - if we don't find one
,
526 # don
't pass -funroll[-all]-loops.
527 if [expr [search_for $test "for*("]+[search_for $test "while*("]] {
528 set option_list $torture_with_loops
530 set option_list $torture_without_loops
533 set nshort [file tail [file dirname $test]]/[file tail $test]
535 foreach flags_t $option_list {
536 global torture_current_flags
537 set torture_current_flags "$flags_t"
538 verbose "Testing $nshort, $flags $flags_t" 1
539 dg-test $test "$flags $flags_t" ${default-extra-flags}
543 if { $existing_torture_options == 0 } {
548 proc gcc-dg-debug-runtest { target_compile trivial opt_opts testcases } {
551 if ![info exists DEBUG_TORTURE_OPTIONS] {
552 set DEBUG_TORTURE_OPTIONS ""
553 foreach type {-gdwarf-2 -gstabs -gstabs+ -gxcoff -gxcoff+ -gcoff} {
554 set comp_output [$target_compile \
555 "$srcdir/$subdir/$trivial" "trivial.S" assembly \
556 "additional_flags=$type"]
557 if { ! [string match "*: target system does not support the * debug format*" \
559 remove-build-file "trivial.S"
560 foreach level {1 "" 3} {
561 if { ($type == "-gdwarf-2") && ($level != "") } {
562 lappend DEBUG_TORTURE_OPTIONS [list "${type}" "-g${level}"]
563 foreach opt $opt_opts {
564 lappend DEBUG_TORTURE_OPTIONS \
565 [list "${type}" "-g${level}" "$opt" ]
568 lappend DEBUG_TORTURE_OPTIONS [list "${type}${level}"]
569 foreach opt $opt_opts {
570 lappend DEBUG_TORTURE_OPTIONS \
571 [list "${type}${level}" "$opt" ]
579 verbose -log "Using options $DEBUG_TORTURE_OPTIONS"
583 foreach test $testcases {
584 # If we're only testing specific files and this isn
't one of
586 if ![runtest_file_p $runtests $test] {
590 set nshort [file tail [file dirname $test]]/[file tail $test]
592 foreach flags $DEBUG_TORTURE_OPTIONS {
595 # These tests check for information which may be deliberately
597 if { ([string match {*/debug-[126].c} "$nshort"] \
598 || [string match {*/enum-1.c} "$nshort"] \
599 || [string match {*/enum-[12].C} "$nshort"]) \
600 && ([string match "*1" [lindex "$flags" 0] ]
601 || [lindex "$flags" 1] == "-g1") } {
605 # High optimization can remove the variable whose existence is tested.
606 # Dwarf debugging with commentary (-dA) preserves the symbol name in the
607 # assembler output, but stabs debugging does not.
608 # http://gcc.gnu.org/ml/gcc-regression/2003-04/msg00095.html
609 if { [string match {*/debug-[12].c} "$nshort"] \
610 && [string match "*O*" "$flags"] \
611 && ( [string match "*coff*" "$flags"] \
612 || [string match "*stabs*" "$flags"] ) } {
617 verbose -log "Testing $nshort, $flags" 1
618 dg-test $test $flags ""
624 # Prune any messages matching ARGS[1] (a regexp) from test output.
625 proc dg-prune-output { args } {
626 global additional_prunes
628 if { [llength $args] != 2 } {
629 error "[lindex $args 1]: need one argument"
633 lappend additional_prunes [lindex $args 1]
636 # Remove files matching the pattern from the build machine.
637 proc remove-build-file { pat } {
638 verbose "remove-build-file `$pat'" 2
639 set file_list
"[glob -nocomplain $pat]"
640 verbose
"remove-build-file `$file_list'" 2
641 foreach output_file $file_list
{
642 if [is_remote host
] {
643 # Ensure the host knows the file is gone by deleting there
645 remote_file host
delete $output_file
647 remote_file build
delete $output_file
651 # Remove runtime
-generated profile file
for the current test.
652 proc cleanup
-profile
-file
{ } {
653 remove
-build
-file
"mon.out"
654 remove
-build
-file
"gmon.out"
657 # Remove compiler
-generated coverage files
for the current test.
658 proc cleanup
-coverage
-files
{ } {
659 global additional_sources_used
660 set testcase
[testname
-for-summary
]
661 # The
name might
include a list of options
; extract the file
name.
662 set testcase
[lindex $testcase
0]
663 remove
-build
-file
"[file rootname [file tail $testcase]].gc??"
665 # Clean up coverage files
for additional source files.
666 if [info exists additional_sources_used
] {
667 foreach srcfile $additional_sources_used
{
668 remove
-build
-file
"[file rootname [file tail $srcfile]].gc??"
673 # Remove compiler
-generated files from
-repo
for the current test.
674 proc cleanup
-repo
-files
{ } {
675 global additional_sources_used
676 set testcase
[testname
-for-summary
]
677 # The
name might
include a list of options
; extract the file
name.
678 set testcase
[lindex $testcase
0]
679 remove
-build
-file
"[file rootname [file tail $testcase]].o"
680 remove
-build
-file
"[file rootname [file tail $testcase]].rpo"
682 # Clean up files
for additional source files.
683 if [info exists additional_sources_used
] {
684 foreach srcfile $additional_sources_used
{
685 remove
-build
-file
"[file rootname [file tail $srcfile]].o"
686 remove
-build
-file
"[file rootname [file tail $srcfile]].rpo"
691 # Remove a final insns dump file
for the current test.
692 proc cleanup
-final
-insns
-dump
{ } {
693 set testcase
[testname
-for-summary
]
694 # The
name might
include a list of options
; extract the file
name.
695 set testcase
[lindex $testcase
0]
696 remove
-build
-file
"[file rootname [file tail $testcase]].s.gkd"
698 # Clean up files
for additional source files.
699 if [info exists additional_sources_used
] {
700 foreach srcfile $additional_sources_used
{
701 remove
-build
-file
"[file rootname [file tail $srcfile]].s.gkd"
706 # Remove a stack usage file
for the current test.
707 proc cleanup
-stack
-usage
{ } {
708 set testcase
[testname
-for-summary
]
709 # The
name might
include a list of options
; extract the file
name.
710 set testcase
[lindex $testcase
0]
711 remove
-build
-file
"[file rootname [file tail $testcase]].su"
713 # Clean up files
for additional source files.
714 if [info exists additional_sources_used
] {
715 foreach srcfile $additional_sources_used
{
716 remove
-build
-file
"[file rootname [file tail $srcfile]].su"
721 # Remove an Ada spec file
for the current test.
722 proc cleanup
-ada
-spec
{ } {
723 global additional_sources_used
724 set testcase
[testname
-for-summary
]
725 remove
-build
-file
"[get_ada_spec_filename $testcase]"
727 # Clean up files
for additional source files.
728 if [info exists additional_sources_used
] {
729 foreach srcfile $additional_sources_used
{
730 remove
-build
-file
"[get_ada_spec_filename $srcfile]"
735 # Remove files kept by
--save
-temps
for the current test.
737 # Currently this is only .i
, .ii
, .s and .o files
, but more can be added
738 #
if there are tests generating them.
739 #
ARGS is a list of suffixes to NOT
delete.
740 proc cleanup
-saved
-temps
{ args } {
741 global additional_sources_used
744 # add the to
-be
-kept suffixes
745 foreach suffix
{".mii" ".ii" ".i" ".s" ".o" ".gkd" ".res" ".ltrans.out"} {
746 if {[lsearch $
args $suffix
] < 0} {
747 lappend suffixes $suffix
751 set testcase
[testname
-for-summary
]
752 # The
name might
include a list of options
; extract the file
name.
753 set testcase
[lindex $testcase
0]
754 foreach suffix $suffixes
{
755 remove
-build
-file
"[file rootname [file tail $testcase]]$suffix"
756 remove
-build
-file
"[file rootname [file tail $testcase]].exe$suffix"
757 remove
-build
-file
"[file rootname [file tail $testcase]].exe.ltrans\[0-9\]*$suffix"
758 #
-fcompare
-debug dumps
759 remove
-build
-file
"[file rootname [file tail $testcase]].gk$suffix"
762 # Clean up saved temp files
for additional source files.
763 if [info exists additional_sources_used
] {
764 foreach srcfile $additional_sources_used
{
765 foreach suffix $suffixes
{
766 remove
-build
-file
"[file rootname [file tail $srcfile]]$suffix"
767 remove
-build
-file
"[file rootname [file tail $srcfile]].exe$suffix"
768 remove
-build
-file
"[file rootname [file tail $srcfile]].exe.ltrans\[0-9\]*$suffix"
770 #
-fcompare
-debug dumps
771 remove
-build
-file
"[file rootname [file tail $srcfile]].gk$suffix"
778 # Files to be kept after cleanup of
--save
-temps
for the current test.
779 #
ARGS is a list of suffixes to NOT
delete.
780 proc dg
-keep
-saved
-temps
{ args } {
781 global keep_saved_temps_suffixes
782 set keep_saved_temps_suffixes
{}
784 # add the to
-be
-kept suffixes
785 foreach suffix
{".mii" ".ii" ".i" ".s" ".o" ".gkd" ".res" ".ltrans.out"} {
786 if {[lsearch $
args $suffix
] >= 0} {
787 lappend keep_saved_temps_suffixes $suffix
790 if { [llength keep_saved_temps_suffixes
] < 1 } {
791 error
"dg-keep-saved-temps ${args} did not match any known suffix"
795 # Scan Fortran modules
for a given regexp.
797 #
Argument 0 is the module
name
798 #
Argument 1 is the regexp to match
799 proc scan
-module
{ args } {
800 set modfilename
[string tolower
[lindex $
args 0]].mod
801 set fd
[open
[list | gzip
-dc $modfilename
] r
]
805 set testcase
[testname
-for-summary
]
806 if [regexp
-- [lindex $
args 1] $
text] {
807 pass
"$testcase scan-module [lindex $args 1]"
809 fail
"$testcase scan-module [lindex $args 1]"
813 # Scan Fortran modules
for absence of a given regexp.
815 #
Argument 0 is the module
name
816 #
Argument 1 is the regexp to match
817 proc scan
-module
-absence
{ args } {
818 set modfilename
[string tolower
[lindex $
args 0]].mod
819 set fd
[open
[list | gzip
-dc $modfilename
] r
]
823 set testcase
[testname
-for-summary
]
824 if [regexp
-- [lindex $
args 1] $
text] {
825 fail
"$testcase scan-module [lindex $args 1]"
827 pass
"$testcase scan-module [lindex $args 1]"
831 # Verify that the compiler output file
exists, invoked via dg
-final.
832 proc output
-exists { args } {
833 # Process an optional target or xfail list.
834 if { [llength $
args] >= 1 } {
835 switch [dg
-process
-target
[lindex $
args 0]] {
838 "F" { setup_xfail "*-*-*" }
843 set testcase
[testname
-for-summary
]
844 # Access
variable from gcc
-dg
-test
-1.
845 upvar
2 output_file output_file
847 if [file
exists $output_file
] {
848 pass
"$testcase output-exists $output_file"
850 fail
"$testcase output-exists $output_file"
854 # Verify that the compiler output file does not exist
, invoked via dg
-final.
855 proc output
-exists-not
{ args } {
856 # Process an optional target or xfail list.
857 if { [llength $
args] >= 1 } {
858 switch [dg
-process
-target
[lindex $
args 0]] {
861 "F" { setup_xfail "*-*-*" }
866 set testcase
[testname
-for-summary
]
867 # Access
variable from gcc
-dg
-test
-1.
868 upvar
2 output_file output_file
870 if [file
exists $output_file
] {
871 fail
"$testcase output-exists-not $output_file"
873 pass
"$testcase output-exists-not $output_file"
877 # We need to make sure that additional_
* are cleared out after
every
878 # test. It is not enough to clear them out
*before
* the next test run
879 # because gcc
-target
-compile gets run directly from some .exp files
880 #
(outside of
any test
).
(Those uses should eventually be eliminated.
)
882 # Because the DG framework doesn
't provide a hook that is run at the
883 # end of a test, we must replace dg-test with a wrapper.
885 if { [info procs saved-dg-test] == [list] } {
886 rename dg-test saved-dg-test
888 # Helper function for cleanups that should happen after the call
889 # to the real dg-test, whether or not it returns normally, or
890 # fails with an error.
891 proc cleanup-after-saved-dg-test { } {
892 global additional_files
893 global additional_sources
894 global additional_sources_used
895 global additional_prunes
896 global compiler_conditional_xfail_data
898 global testname_with_flags
899 global set_target_env_var
900 global set_compiler_env_var
901 global saved_compiler_env_var
902 global keep_saved_temps_suffixes
903 global multiline_expected_outputs
904 global freeform_regexps
906 set additional_files ""
907 set additional_sources ""
908 set additional_sources_used ""
909 set additional_prunes ""
911 if [info exists set_target_env_var] {
912 unset set_target_env_var
914 if [info exists set_compiler_env_var] {
915 restore-compiler-env-var
916 unset set_compiler_env_var
917 unset saved_compiler_env_var
919 if [info exists keep_saved_temps_suffixes] {
920 unset keep_saved_temps_suffixes
923 if [info exists compiler_conditional_xfail_data] {
924 unset compiler_conditional_xfail_data
926 if [info exists testname_with_flags] {
927 unset testname_with_flags
929 set multiline_expected_outputs []
930 set freeform_regexps []
933 proc dg-test { args } {
936 if { [ catch { eval saved-dg-test $args } errmsg ] } {
937 set saved_info $errorInfo
938 cleanup-after-saved-dg-test
939 error $errmsg $saved_info
941 cleanup-after-saved-dg-test
945 if { [info procs saved-dg-warning] == [list] \
946 && [info exists gcc_warning_prefix] } {
947 rename dg-warning saved-dg-warning
949 proc dg-warning { args } {
950 # Make this variable available here and to the saved proc.
951 upvar dg-messages dg-messages
952 global gcc_warning_prefix
954 process-message saved-dg-warning "$gcc_warning_prefix" "$args"
958 if { [info procs saved-dg-error] == [list] \
959 && [info exists gcc_error_prefix] } {
960 rename dg-error saved-dg-error
962 proc dg-error { args } {
963 # Make this variable available here and to the saved proc.
964 upvar dg-messages dg-messages
965 global gcc_error_prefix
967 process-message saved-dg-error "$gcc_error_prefix" "$args"
970 # Override dg-bogus at the same time. It doesn't handle a prefix
971 # but its expression should
include a column number. Otherwise the
972 # line number can match the column number
for other messages
, leading
974 rename dg
-bogus saved
-dg
-bogus
976 proc dg
-bogus
{ args } {
977 upvar dg
-messages dg
-messages
978 process
-message saved
-dg
-bogus
"" $args
982 # Modify the regular expression saved by a DejaGnu message directive to
983 #
include a prefix and to force the expression to match a single line.
984 # MSGPROC is the procedure to
call.
985 # MSGPREFIX is the prefix to prepend.
986 # DGARGS is the original
argument list.
988 proc process
-message
{ msgproc msgprefix dgargs
} {
989 upvar dg
-messages dg
-messages
991 # Handle relative line specification
, .
+1 or .
-1 etc.
992 if { [llength $dgargs
] == 5
993 && [regsub
"^\.\[+-\](\[0-9\]+)$" [lindex $dgargs 4] "\\1" num] } {
994 set num
[expr
[lindex $dgargs
0] [string index
[lindex $dgargs
4] 1] $num
]
995 set dgargs
[lreplace $dgargs
4 4 $num
]
998 # Process the dg
- directive
, including adding the regular expression
999 # to the new message entry in dg
-messages.
1000 set msgcnt
[llength $
{dg
-messages
}]
1001 eval $msgproc $dgargs
1003 #
If the target expression wasn
't satisfied there is no new message.
1004 if { [llength ${dg-messages}] == $msgcnt } {
1008 # Get the entry for the new message. Prepend the message prefix to
1009 # the regular expression and make it match a single line.
1010 set newentry [lindex ${dg-messages} end]
1011 set expmsg [lindex $newentry 2]
1013 # Handle column numbers from the specified expression (if there is
1014 # one) and set up the search expression that will be used by DejaGnu.
1015 if [regexp "^(\[0-9\]+):" $expmsg "" column] {
1016 # The expression in the directive included a column number.
1017 # Remove "COLUMN:" from the original expression and move it
1018 # to the proper place in the search expression.
1019 regsub "^\[0-9\]+:" $expmsg "" expmsg
1020 set expmsg "$column: $msgprefix\[^\n\]*$expmsg"
1021 } elseif [string match "" [lindex $newentry 0]] {
1022 # The specified line number is 0; don't expect a column number.
1023 set expmsg
"$msgprefix\[^\n\]*$expmsg"
1025 # There is no column number in the search expression
, but we
1026 # should expect one in the message itself.
1027 set expmsg
"\[0-9\]+: $msgprefix\[^\n\]*$expmsg"
1030 set newentry
[lreplace $newentry
2 2 $expmsg
]
1031 set dg
-messages
[lreplace $
{dg
-messages
} end end $newentry
]
1032 verbose
"process-message:\n${dg-messages}" 2
1035 # Look
for messages that don
't have standard prefixes.
1037 proc dg-message { args } {
1038 upvar dg-messages dg-messages
1039 process-message saved-dg-warning "" $args
1042 # Look for a location marker of the form
1044 # with no extra text (e.g. a line-span separator).
1046 proc dg-locus { args } {
1047 upvar dg-messages dg-messages
1049 # Process the dg- directive, including adding the regular expression
1050 # to the new message entry in dg-messages.
1051 set msgcnt [llength ${dg-messages}]
1052 eval saved-dg-warning $args
1054 # If the target expression wasn't satisfied there is no new message.
1055 if { [llength $
{dg
-messages
}] == $msgcnt
} {
1059 #
Get the entry
for the new message. Prepend the message prefix to
1060 # the regular expression and make it match a single line.
1061 set newentry
[lindex $
{dg
-messages
} end
]
1062 set expmsg
[lindex $newentry
2]
1064 set newentry
[lreplace $newentry
2 2 $expmsg
]
1065 set dg
-messages
[lreplace $
{dg
-messages
} end end $newentry
]
1066 verbose
"process-message:\n${dg-messages}" 2
1069 # Check the existence of a gdb in the path
, and
return true
if there
1072 #
Set env
(GDB_FOR_GCC_TESTING
) accordingly.
1074 proc gdb
-exists { args } {
1075 if ![info exists ::env
(GDB_FOR_GCC_TESTING
)] {
1077 if ![info exists ::env
(GDB_FOR_GCC_TESTING
)] {
1078 if [info exists GDB
] {
1079 setenv GDB_FOR_GCC_TESTING
"$GDB"
1081 setenv GDB_FOR_GCC_TESTING
"[transform gdb]"
1085 if { [which $
::env
(GDB_FOR_GCC_TESTING
)] != 0 } {
1091 set additional_prunes
""
1092 set dg_runtest_extra_prunes
""