1 # Copyright
(C
) 1997-2018 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
24 load_lib scanltranstree.exp
26 load_lib scanwpaipa.exp
29 load_lib timeout
-dg.exp
32 load_lib target
-libpath.exp
33 load_lib torture
-options.exp
34 load_lib fortran
-modules.exp
35 load_lib multiline.exp
37 # We
set LC_ALL and LANG to C so that we
get the same error messages as expected.
41 # Many hosts now default to a non
-ASCII C locale
, however
, so
42 # they can
set a
charset encoding here
if they need.
43 if { [ishost
"*-*-cygwin*"] } {
48 # Avoid sporadic data
-losses with expect
51 # Ensure GCC_COLORS is unset
, for the rare testcases that verify
52 # how output is colorized.
53 if [info exists ::env
(GCC_COLORS
) ] {
58 if ![info exists GCC_UNDER_TEST
] {
59 set GCC_UNDER_TEST
"[find_gcc]"
62 # This file may be sourced
, so don
't override environment settings
63 # that have been previously setup.
64 if { $orig_environment_saved == 0 } {
65 append ld_library_path [gcc-set-multilib-library-path $GCC_UNDER_TEST]
66 set_ld_library_path_env_vars
69 # Some torture-options cause intermediate code output, unusable for
70 # testing using e.g. scan-assembler. In this variable are the options
71 # how to force it, when needed.
72 global gcc_force_conventional_output
73 set gcc_force_conventional_output ""
75 set LTO_TORTURE_OPTIONS ""
76 if [info exists TORTURE_OPTIONS] {
77 set DG_TORTURE_OPTIONS $TORTURE_OPTIONS
79 # It is theoretically beneficial to group all of the O2/O3 options together,
80 # as in many cases the compiler will generate identical executables for
81 # all of them--and the c-torture testsuite will skip testing identical
82 # executables multiple times.
83 # Also note that -finline-functions is explicitly included in one of the
84 # items below, even though -O3 is also specified, because some ports may
85 # choose to disable inlining functions by default, even when optimizing.
86 set DG_TORTURE_OPTIONS [list \
90 { -O3 -fomit-frame-pointer -funroll-loops -fpeel-loops -ftracer -finline-functions } \
94 if [check_effective_target_lto] {
95 # When having plugin test both slim and fat LTO and plugin/nonplugin
97 if [check_linker_plugin_available] {
98 set LTO_TORTURE_OPTIONS [list \
99 { -O2 -flto -fno-use-linker-plugin -flto-partition=none } \
100 { -O2 -flto -fuse-linker-plugin -fno-fat-lto-objects }
103 set LTO_TORTURE_OPTIONS [list \
104 { -O2 -flto -flto-partition=none } \
108 set gcc_force_conventional_output "-ffat-lto-objects"
112 if [info exists ADDITIONAL_TORTURE_OPTIONS] {
113 set DG_TORTURE_OPTIONS \
114 [concat $DG_TORTURE_OPTIONS $ADDITIONAL_TORTURE_OPTIONS]
117 global orig_environment_saved
119 # Deduce generated files from tool flags, return finalcode string
120 proc schedule-cleanups { opts } {
121 global additional_sources
124 lappend testcases [lindex [testname-for-summary] 0]
125 verbose "Cleanup testcases: $testcases" 4
126 if { [info exists additional_sources] && $additional_sources != "" } {
127 lappend testcases $additional_sources
128 verbose "Cleanup testcases, additional: $additional_sources" 4
130 verbose "Cleanup all options: $opts" 4
132 # First some fixups to transform stuff to something manageable ..
133 # --dump= should translate to -d with joined operand.
134 if [regexp -- {(^|\s+)--dump=[^\s]+(\s+|$)} $opts] {
135 regsub -all -- {--dump=} $opts {-d} opts
137 # -da and -dx are treated as shorthand for -fdump-rtl-all here
138 if [regexp -- {(^|\s+)-d[ax](\s+|$)} $opts] {
139 verbose "Cleanup -d seen" 4
140 lappend opts "-fdump-rtl-all"
142 # .. and don't question why there is
--dump
=? and
-d?
144 #
Then handle options that generate non
-dump files
146 #
-fprofile
-generate
-> cleanup
-coverage
-files
()
147 #
-fstack
-usage
-> cleanup
-stack
-usage
()
148 if [regexp
-- {(^|\s
+)-fstack
-usage
(\s
+|$
)} $opts
] {
149 verbose
"Cleanup -fstack-usage seen" 4
150 # append finalcode
"cleanup-stack-usage\n"
152 global keep_saved_temps_suffixes
153 if [info exists keep_saved_temps_suffixes
] {
154 verbose
"dg-keep-saved-temps ${keep_saved_temps_suffixes}" 2
156 #
-save
-temps
-> cleanup
-saved
-temps
()
157 if [regexp
-- {(^|\s
+)-save
-temps
(\s
+|$
)} $opts
] {
158 verbose
"Cleanup -save-temps seen" 4
159 if [info exists keep_saved_temps_suffixes
] {
160 append finalcode
"cleanup-saved-temps ${keep_saved_temps_suffixes}\n"
162 append finalcode
"cleanup-saved-temps\n"
165 if [info exists keep_saved_temps_suffixes
] {
166 error
"dg-keep-saved-temps specified but testcase does not -save-temps"
170 # Finally see
if there are
any dumps in opts
, otherwise we are done
171 if [regexp
-- {(?
=(?
:^|
[ \t]+)?
)-fdump
-[^
\t]+(?
=(?
:$|
[ \t]+)?
)} $opts
] {
172 # Lang
, Ipa
, Rtl
, Tree
for simplicity
177 # stem.ext.
<passnum
><fam
>.
<passname
><pass
-instances
>
178 #
(tree
)passes can have multiple instances
, thus optional trailing
*
179 set ptn
"\[0-9\]\[0-9\]\[0-9\]$ptn.*"
180 # Handle ltrans files around
-flto
181 if [regexp
-- {(^|\s
+)-flto
(\s
+|$
)} $opts
] {
182 verbose
"Cleanup -flto seen" 4
183 set ltrans
"{ltrans\[0-9\]*.,}"
187 set ptn
"$ltrans$ptn"
188 verbose
"Cleanup final ptn: $ptn" 4
190 foreach src $testcases
{
191 set basename
[file tail $src
]
192 if { $ltrans
!= "" } {
193 # ??? should we use upvar
1 output_file instead of this
(dup ?
)
194 set stem
[file rootname $basename
]
195 set basename_ext
[file extension $basename
]
196 if {$basename_ext
!= ""} {
197 regsub
-- {^.
*\.
} $basename_ext
{} basename_ext
199 lappend tfiles
"$stem.{$basename_ext,exe}"
202 lappend tfiles $basename
205 if { [llength $tfiles
] > 1 } {
206 set tfiles
[join $tfiles
","]
207 set tfiles
"{$tfiles}"
209 verbose
"Cleanup final testcases: $tfiles" 4
210 # We have to quote the regex
211 regsub
-all
{([][$^?
+*()|
\\{}])} "$tfiles.$ptn" {\\\1} ptn
213 append final
{remove
-build
-file
}
214 append final
"\"$ptn\""
215 verbose
"Cleanup final: $final" 4
216 append finalcode
"$final\n"
221 #
Define gcc callbacks
for dg.exp.
223 proc gcc
-dg
-test
-1 { target_compile prog do_what extra_tool_flags
} {
224 #
Set up the compiler flags
, based
on what we
're going to do.
228 # Tests should be able to use "dg-do repo". However, the dg test
229 # driver checks the argument to dg-do against a list of acceptable
230 # options, and "repo" is not among them. Therefore, we resort to
231 # this ugly approach.
232 if [string match "*-frepo*" $extra_tool_flags] then {
238 set compile_type "preprocess"
239 set output_file "[file rootname [file tail $prog]].i"
242 set compile_type "assembly"
243 set output_file "[file rootname [file tail $prog]].s"
246 set compile_type "object"
247 set output_file "[file rootname [file tail $prog]].o"
250 set compile_type "precompiled_header"
251 set output_file "[file tail $prog].gch"
254 set compile_type "executable"
255 set output_file "[file rootname [file tail $prog]].exe"
256 # The following line is needed for targets like the i960 where
257 # the default output file is b.out. Sigh.
260 set compile_type "object"
261 set output_file "[file rootname [file tail $prog]].o"
264 set compile_type "executable"
265 # FIXME: "./" is to cope with "." not being in $PATH.
266 # Should this be handled elsewhere?
268 set output_file "./[file rootname [file tail $prog]].exe"
269 # This is the only place where we care if an executable was
270 # created or not. If it was, dg.exp will try to run it.
271 catch { remote_file build delete $output_file }
274 perror "$do_what: not a valid dg-do keyword"
279 # Let { dg-final { action } } force options as returned by an
280 # optional proc ${action}_required_options.
281 upvar 2 dg-final-code finalcode
282 foreach x [split $finalcode "\n"] {
283 set finalcmd [lindex $x 0]
284 if { [info procs ${finalcmd}_required_options] != "" } {
285 set req [${finalcmd}_required_options]
286 if { $req != "" && [lsearch -exact $extra_tool_flags $req] == -1 } {
287 lappend extra_tool_flags $req
292 append finalcode [schedule-cleanups "$options $extra_tool_flags"]
293 if { $extra_tool_flags != "" } {
294 lappend options "additional_flags=$extra_tool_flags"
297 verbose "$target_compile $prog $output_file $compile_type $options" 4
298 set comp_output [$target_compile "$prog" "$output_file" "$compile_type" $options]
300 # Look for an internal compiler error, which sometimes masks the fact
301 # that we didn't
get an expected error message. XFAIL an ICE via
302 # dg
-xfail
-if and use
{ dg
-prune
-output
".*internal compiler error.*" }
303 # to avoid a second failure
for excess errors.
304 if [string match
"*internal compiler error*" $comp_output] {
306 fail
"$name (internal compiler error)"
309 if { $do_what
== "repo" } {
310 set object_file
"$output_file"
311 set output_file
"[file rootname [file tail $prog]].exe"
313 [ concat $comp_output \
314 [$target_compile
"$object_file" "$output_file" \
315 "executable" $options] ]
318 return [list $comp_output $output_file
]
321 proc gcc
-dg
-test
{ prog do_what extra_tool_flags
} {
322 return [gcc
-dg
-test
-1 gcc_target_compile $prog $do_what $extra_tool_flags
]
325 # Global
: should
blank lines be allowed in the output?
326 # By default
, they should not be.
(PR other
/69006)
327 # However
, there are some ways
for them to validly occur.
328 set allow_blank_lines
0
330 # A command
for use by testcases to mark themselves as expecting
331 #
blank lines in the output.
333 proc dg
-allow
-blank-lines
-in
-output
{ args } {
334 global allow_blank_lines
335 set allow_blank_lines
1
338 proc gcc
-dg
-prune
{ system text } {
339 global additional_prunes
341 # Extra prune rules that will apply to tests defined in a .exp file.
342 # Always remember to clear it in .exp file after executed all tests.
343 global dg_runtest_extra_prunes
345 # Complain about
blank lines in the output
(PR other
/69006)
346 global allow_blank_lines
347 if { !$allow_blank_lines
} {
348 set num_blank_lines
[llength
[regexp
-all
-inline
"\n\n" $text]]
349 if { $num_blank_lines
} {
350 global testname_with_flags
351 fail
"$testname_with_flags $num_blank_lines blank line(s) in output"
353 set allow_blank_lines
0
356 set text [prune_gcc_output $
text]
358 foreach p
"$additional_prunes $dg_runtest_extra_prunes" {
359 if { [string length $p
] > 0 } {
360 # Following regexp matches a complete line containing $p.
361 regsub
-all
"(^|\n)\[^\n\]*$p\[^\n\]*" $text "" text
365 #
If we see
"region xxx is full" then the testcase is too big for ram.
366 # This is tricky to deal with in a large testsuite like c
-torture so
367 # deal with it here. Just mark the testcase as unsupported.
368 if [regexp
"(^|\n)\[^\n\]*: region \[^\n\]* is full" $text] {
369 # The format here is important. See dg.exp.
370 return "::unsupported::memory full"
373 if { [regexp
"(^|\n)\[^\n\]*: relocation truncated to fit" $text]
374 && [check_effective_target_tiny
] } {
375 return "::unsupported::memory full"
378 # Likewise
, if we see
".text exceeds local store range" or
380 if {[string match
"spu-*" $system] && \
381 [string match
"*exceeds local store*" $text]} {
382 # The format here is important. See dg.exp.
383 return "::unsupported::memory full"
389 # Replace $
{tool
}_load with a wrapper to provide
for an expected nonzero
390 # exit
status. Multiple languages
include this file so this handles them
392 if { [info procs $
{tool
}_load
] != [list
] \
393 && [info procs saved_$
{tool
}_load
] == [list
] } {
394 rename $
{tool
}_load saved_$
{tool
}_load
396 proc $
{tool
}_load
{ program args } {
399 global set_target_env_var
401 set saved_target_env_var
[list
]
402 if { [info exists set_target_env_var
] \
403 && [llength $set_target_env_var
] != 0 } {
404 if { [is_remote target
] } {
405 return [list
"unsupported" ""]
409 set result
[eval
[list saved_$
{tool
}_load $
program] $
args]
410 if { [info exists set_target_env_var
] \
411 && [llength $set_target_env_var
] != 0 } {
412 restore
-target
-env
-var
414 if { $shouldfail
!= 0 } {
415 switch [lindex $result
0] {
416 "pass" { set status "fail" }
417 "fail" { set status "pass" }
418 default
{ set status [lindex $result
0] }
420 set result
[list $
status [lindex $result
1]]
423 set result
[list
[lindex $result
0] [prune_file_path
[lindex $result
1]]]
428 proc dg
-set-target
-env
-var
{ args } {
429 global set_target_env_var
430 if { [llength $
args] != 3 } {
431 error
"dg-set-target-env-var: need two arguments"
434 lappend set_target_env_var
[list
[lindex $
args 1] [lindex $
args 2]]
437 proc
set-target
-env
-var
{ } {
438 global set_target_env_var
439 upvar
1 saved_target_env_var saved_target_env_var
440 foreach env_var $set_target_env_var
{
441 set var
[lindex $env_var
0]
442 set value
[lindex $env_var
1]
443 if [info exists ::env
($var
)] {
444 lappend saved_target_env_var
[list $var
1 $
::env
($var
)]
446 lappend saved_target_env_var
[list $var
0]
452 proc restore
-target
-env
-var
{ } {
453 upvar
1 saved_target_env_var saved_target_env_var
454 for { set env_vari
[llength $saved_target_env_var
] } {
455 [incr env_vari
-1] >= 0 } {} {
456 set env_var
[lindex $saved_target_env_var $env_vari
]
457 set var
[lindex $env_var
0]
458 if [lindex $env_var
1] {
459 setenv $var
[lindex $env_var
2]
466 proc dg
-set-compiler
-env
-var
{ args } {
467 global set_compiler_env_var
468 global saved_compiler_env_var
469 if { [llength $
args] != 3 } {
470 error
"dg-set-compiler-env-var: need two arguments"
473 set var
[lindex $
args 1]
474 set value
[lindex $
args 2]
475 if [info exists ::env
($var
)] {
476 lappend saved_compiler_env_var
[list $var
1 $
::env
($var
)]
478 lappend saved_compiler_env_var
[list $var
0]
481 lappend set_compiler_env_var
[list $var $value
]
484 proc restore
-compiler
-env
-var
{ } {
485 global saved_compiler_env_var
486 for { set env_vari
[llength $saved_compiler_env_var
] } {
487 [incr env_vari
-1] >= 0 } {} {
488 set env_var
[lindex $saved_compiler_env_var $env_vari
]
489 set var
[lindex $env_var
0]
490 if [lindex $env_var
1] {
491 setenv $var
[lindex $env_var
2]
501 # search_for
-- looks
for a string match in a file
503 proc search_for
{ file pattern
} {
504 set fd
[open $file r
]
505 while { [gets $fd cur_line
]>=0 } {
506 if [string match
"*$pattern*" $cur_line] then {
515 # Modified dg
-runtest that can cycle through a list of optimization options
517 proc gcc
-dg
-runtest
{ testcases flags default
-extra
-flags
} {
520 # Some callers
set torture options themselves
; don
't override those.
521 set existing_torture_options [torture-options-exist]
522 if { $existing_torture_options == 0 } {
523 global DG_TORTURE_OPTIONS LTO_TORTURE_OPTIONS
525 set-torture-options $DG_TORTURE_OPTIONS [list {}] $LTO_TORTURE_OPTIONS
529 foreach test $testcases {
530 global torture_with_loops torture_without_loops
531 # If we're only testing specific files and this isn
't one of
533 if ![runtest_file_p $runtests $test] {
537 # Look for a loop within the source code - if we don't find one
,
538 # don
't pass -funroll[-all]-loops.
539 if [expr [search_for $test "for*("]+[search_for $test "while*("]] {
540 set option_list $torture_with_loops
542 set option_list $torture_without_loops
545 set nshort [file tail [file dirname $test]]/[file tail $test]
547 foreach flags_t $option_list {
548 global torture_current_flags
549 set torture_current_flags "$flags_t"
550 verbose "Testing $nshort, $flags $flags_t" 1
551 dg-test $test "$flags $flags_t" ${default-extra-flags}
555 if { $existing_torture_options == 0 } {
560 proc gcc-dg-debug-runtest { target_compile trivial opt_opts testcases } {
563 if ![info exists DEBUG_TORTURE_OPTIONS] {
564 set DEBUG_TORTURE_OPTIONS ""
565 foreach type {-gdwarf-2 -gstabs -gstabs+ -gxcoff -gxcoff+} {
566 set comp_output [$target_compile \
567 "$srcdir/$subdir/$trivial" "trivial.S" assembly \
568 "additional_flags=$type"]
569 if { ! [string match "*: target system does not support the * debug format*" \
571 remove-build-file "trivial.S"
572 foreach level {1 "" 3} {
573 if { ($type == "-gdwarf-2") && ($level != "") } {
574 lappend DEBUG_TORTURE_OPTIONS [list "${type}" "-g${level}"]
575 foreach opt $opt_opts {
576 lappend DEBUG_TORTURE_OPTIONS \
577 [list "${type}" "-g${level}" "$opt" ]
580 lappend DEBUG_TORTURE_OPTIONS [list "${type}${level}"]
581 foreach opt $opt_opts {
582 lappend DEBUG_TORTURE_OPTIONS \
583 [list "${type}${level}" "$opt" ]
591 verbose -log "Using options $DEBUG_TORTURE_OPTIONS"
595 foreach test $testcases {
596 # If we're only testing specific files and this isn
't one of
598 if ![runtest_file_p $runtests $test] {
602 set nshort [file tail [file dirname $test]]/[file tail $test]
604 foreach flags $DEBUG_TORTURE_OPTIONS {
607 # These tests check for information which may be deliberately
609 if { ([string match {*/debug-[126].c} "$nshort"] \
610 || [string match {*/enum-1.c} "$nshort"] \
611 || [string match {*/enum-[12].C} "$nshort"]) \
612 && ([string match "*1" [lindex "$flags" 0] ]
613 || [lindex "$flags" 1] == "-g1") } {
617 # High optimization can remove the variable whose existence is tested.
618 # Dwarf debugging with commentary (-dA) preserves the symbol name in the
619 # assembler output, but stabs debugging does not.
620 # http://gcc.gnu.org/ml/gcc-regression/2003-04/msg00095.html
621 if { [string match {*/debug-[12].c} "$nshort"] \
622 && [string match "*O*" "$flags"] \
623 && ( [string match "*coff*" "$flags"] \
624 || [string match "*stabs*" "$flags"] ) } {
629 verbose -log "Testing $nshort, $flags" 1
630 dg-test $test $flags ""
636 # Prune any messages matching ARGS[1] (a regexp) from test output.
637 proc dg-prune-output { args } {
638 global additional_prunes
640 if { [llength $args] != 2 } {
641 error "[lindex $args 1]: need one argument"
645 lappend additional_prunes [lindex $args 1]
648 # Remove files matching the pattern from the build machine.
649 proc remove-build-file { pat } {
650 verbose "remove-build-file `$pat'" 2
651 set file_list
"[glob -nocomplain $pat]"
652 verbose
"remove-build-file `$file_list'" 2
653 foreach output_file $file_list
{
654 if [is_remote host
] {
655 # Ensure the host knows the file is gone by deleting there
657 remote_file host
delete $output_file
659 remote_file build
delete $output_file
663 # Remove runtime
-generated profile file
for the current test.
664 proc cleanup
-profile
-file
{ } {
665 remove
-build
-file
"mon.out"
666 remove
-build
-file
"gmon.out"
669 # Remove compiler
-generated coverage files
for the current test.
670 proc cleanup
-coverage
-files
{ } {
671 global additional_sources_used
672 set testcase
[testname
-for-summary
]
673 # The
name might
include a list of options
; extract the file
name.
674 set testcase
[lindex $testcase
0]
675 remove
-build
-file
"[file rootname [file tail $testcase]].gc??"
677 # Clean up coverage files
for additional source files.
678 if [info exists additional_sources_used
] {
679 foreach srcfile $additional_sources_used
{
680 remove
-build
-file
"[file rootname [file tail $srcfile]].gc??"
685 # Remove compiler
-generated files from
-repo
for the current test.
686 proc cleanup
-repo
-files
{ } {
687 global additional_sources_used
688 set testcase
[testname
-for-summary
]
689 # The
name might
include a list of options
; extract the file
name.
690 set testcase
[lindex $testcase
0]
691 remove
-build
-file
"[file rootname [file tail $testcase]].o"
692 remove
-build
-file
"[file rootname [file tail $testcase]].rpo"
694 # Clean up files
for additional source files.
695 if [info exists additional_sources_used
] {
696 foreach srcfile $additional_sources_used
{
697 remove
-build
-file
"[file rootname [file tail $srcfile]].o"
698 remove
-build
-file
"[file rootname [file tail $srcfile]].rpo"
703 # Remove a final insns dump file
for the current test.
704 proc cleanup
-final
-insns
-dump
{ } {
705 set testcase
[testname
-for-summary
]
706 # The
name might
include a list of options
; extract the file
name.
707 set testcase
[lindex $testcase
0]
708 remove
-build
-file
"[file rootname [file tail $testcase]].s.gkd"
710 # Clean up files
for additional source files.
711 if [info exists additional_sources_used
] {
712 foreach srcfile $additional_sources_used
{
713 remove
-build
-file
"[file rootname [file tail $srcfile]].s.gkd"
718 # Remove a stack usage file
for the current test.
719 proc cleanup
-stack
-usage
{ } {
720 set testcase
[testname
-for-summary
]
721 # The
name might
include a list of options
; extract the file
name.
722 set testcase
[lindex $testcase
0]
723 remove
-build
-file
"[file rootname [file tail $testcase]].su"
725 # Clean up files
for additional source files.
726 if [info exists additional_sources_used
] {
727 foreach srcfile $additional_sources_used
{
728 remove
-build
-file
"[file rootname [file tail $srcfile]].su"
733 # Remove an Ada spec file
for the current test.
734 proc cleanup
-ada
-spec
{ } {
735 global additional_sources_used
736 set testcase
[testname
-for-summary
]
737 remove
-build
-file
"[get_ada_spec_filename $testcase]"
739 # Clean up files
for additional source files.
740 if [info exists additional_sources_used
] {
741 foreach srcfile $additional_sources_used
{
742 remove
-build
-file
"[get_ada_spec_filename $srcfile]"
747 # Remove files kept by
--save
-temps
for the current test.
749 # Currently this is only .i
, .ii
, .s and .o files
, but more can be added
750 #
if there are tests generating them.
751 #
ARGS is a list of suffixes to NOT
delete.
752 proc cleanup
-saved
-temps
{ args } {
753 global additional_sources_used
756 # add the to
-be
-kept suffixes
757 foreach suffix
{".mii" ".ii" ".i" ".s" ".o" ".gkd" ".res" ".ltrans.out"} {
758 if {[lsearch $
args $suffix
] < 0} {
759 lappend suffixes $suffix
763 set testcase
[testname
-for-summary
]
764 # The
name might
include a list of options
; extract the file
name.
765 set testcase
[lindex $testcase
0]
766 foreach suffix $suffixes
{
767 remove
-build
-file
"[file rootname [file tail $testcase]]$suffix"
768 remove
-build
-file
"[file rootname [file tail $testcase]].exe$suffix"
769 remove
-build
-file
"[file rootname [file tail $testcase]].exe.ltrans\[0-9\]*$suffix"
770 #
-fcompare
-debug dumps
771 remove
-build
-file
"[file rootname [file tail $testcase]].gk$suffix"
774 # Clean up saved temp files
for additional source files.
775 if [info exists additional_sources_used
] {
776 foreach srcfile $additional_sources_used
{
777 foreach suffix $suffixes
{
778 remove
-build
-file
"[file rootname [file tail $srcfile]]$suffix"
779 remove
-build
-file
"[file rootname [file tail $srcfile]].exe$suffix"
780 remove
-build
-file
"[file rootname [file tail $srcfile]].exe.ltrans\[0-9\]*$suffix"
782 #
-fcompare
-debug dumps
783 remove
-build
-file
"[file rootname [file tail $srcfile]].gk$suffix"
790 # Files to be kept after cleanup of
--save
-temps
for the current test.
791 #
ARGS is a list of suffixes to NOT
delete.
792 proc dg
-keep
-saved
-temps
{ args } {
793 global keep_saved_temps_suffixes
794 set keep_saved_temps_suffixes
{}
796 # add the to
-be
-kept suffixes
797 foreach suffix
{".mii" ".ii" ".i" ".s" ".o" ".gkd" ".res" ".ltrans.out"} {
798 if {[lsearch $
args $suffix
] >= 0} {
799 lappend keep_saved_temps_suffixes $suffix
802 if { [llength keep_saved_temps_suffixes
] < 1 } {
803 error
"dg-keep-saved-temps ${args} did not match any known suffix"
807 # Scan Fortran modules
for a given regexp.
809 #
Argument 0 is the module
name
810 #
Argument 1 is the regexp to match
811 proc scan
-module
{ args } {
812 set modfilename
[string tolower
[lindex $
args 0]].mod
813 set fd
[open
[list | gzip
-dc $modfilename
] r
]
817 set testcase
[testname
-for-summary
]
818 if [regexp
-- [lindex $
args 1] $
text] {
819 pass
"$testcase scan-module [lindex $args 1]"
821 fail
"$testcase scan-module [lindex $args 1]"
825 # Scan Fortran modules
for absence of a given regexp.
827 #
Argument 0 is the module
name
828 #
Argument 1 is the regexp to match
829 proc scan
-module
-absence
{ args } {
830 set modfilename
[string tolower
[lindex $
args 0]].mod
831 set fd
[open
[list | gzip
-dc $modfilename
] r
]
835 set testcase
[testname
-for-summary
]
836 if [regexp
-- [lindex $
args 1] $
text] {
837 fail
"$testcase scan-module [lindex $args 1]"
839 pass
"$testcase scan-module [lindex $args 1]"
843 # Verify that the compiler output file
exists, invoked via dg
-final.
844 proc output
-exists { args } {
845 # Process an optional target or xfail list.
846 if { [llength $
args] >= 1 } {
847 switch [dg
-process
-target
[lindex $
args 0]] {
850 "F" { setup_xfail "*-*-*" }
855 set testcase
[testname
-for-summary
]
856 # Access
variable from gcc
-dg
-test
-1.
857 upvar
2 output_file output_file
859 if [file
exists $output_file
] {
860 pass
"$testcase output-exists $output_file"
862 fail
"$testcase output-exists $output_file"
866 # Verify that the compiler output file does not exist
, invoked via dg
-final.
867 proc output
-exists-not
{ args } {
868 # Process an optional target or xfail list.
869 if { [llength $
args] >= 1 } {
870 switch [dg
-process
-target
[lindex $
args 0]] {
873 "F" { setup_xfail "*-*-*" }
878 set testcase
[testname
-for-summary
]
879 # Access
variable from gcc
-dg
-test
-1.
880 upvar
2 output_file output_file
882 if [file
exists $output_file
] {
883 fail
"$testcase output-exists-not $output_file"
885 pass
"$testcase output-exists-not $output_file"
889 # We need to make sure that additional_
* are cleared out after
every
890 # test. It is not enough to clear them out
*before
* the next test run
891 # because gcc
-target
-compile gets run directly from some .exp files
892 #
(outside of
any test
).
(Those uses should eventually be eliminated.
)
894 # Because the DG framework doesn
't provide a hook that is run at the
895 # end of a test, we must replace dg-test with a wrapper.
897 if { [info procs saved-dg-test] == [list] } {
898 rename dg-test saved-dg-test
900 # Helper function for cleanups that should happen after the call
901 # to the real dg-test, whether or not it returns normally, or
902 # fails with an error.
903 proc cleanup-after-saved-dg-test { } {
904 global additional_files
905 global additional_sources
906 global additional_sources_used
907 global additional_prunes
908 global compiler_conditional_xfail_data
910 global testname_with_flags
911 global set_target_env_var
912 global set_compiler_env_var
913 global saved_compiler_env_var
914 global keep_saved_temps_suffixes
915 global multiline_expected_outputs
916 global freeform_regexps
917 global save_linenr_varnames
919 set additional_files ""
920 set additional_sources ""
921 set additional_sources_used ""
922 set additional_prunes ""
924 if [info exists set_target_env_var] {
925 unset set_target_env_var
927 if [info exists set_compiler_env_var] {
928 restore-compiler-env-var
929 unset set_compiler_env_var
930 unset saved_compiler_env_var
932 if [info exists keep_saved_temps_suffixes] {
933 unset keep_saved_temps_suffixes
936 if [info exists compiler_conditional_xfail_data] {
937 unset compiler_conditional_xfail_data
939 if [info exists testname_with_flags] {
940 unset testname_with_flags
942 set multiline_expected_outputs []
943 set freeform_regexps []
945 if { [info exists save_linenr_varnames] } {
946 foreach varname $save_linenr_varnames {
951 # Cleanup varname_used, or generate defined-but-not-used
953 set varname_used used_$varname
954 eval global $varname_used
955 eval set used [info exists $varname_used]
957 eval unset $varname_used
959 regsub {^saved_linenr_} $varname "" org_varname
960 warning "dg-line var $org_varname defined, but not used"
963 unset save_linenr_varnames
967 proc dg-test { args } {
970 if { [ catch { eval saved-dg-test $args } errmsg ] } {
971 set saved_info $errorInfo
972 cleanup-after-saved-dg-test
973 error $errmsg $saved_info
975 cleanup-after-saved-dg-test
979 if { [info procs saved-dg-warning] == [list] \
980 && [info exists gcc_warning_prefix] } {
981 rename dg-warning saved-dg-warning
983 proc dg-warning { args } {
984 # Make this variable available here and to the saved proc.
985 upvar dg-messages dg-messages
986 global gcc_warning_prefix
988 process-message saved-dg-warning "$gcc_warning_prefix" "$args"
992 if { [info procs saved-dg-error] == [list] \
993 && [info exists gcc_error_prefix] } {
994 rename dg-error saved-dg-error
996 proc dg-error { args } {
997 # Make this variable available here and to the saved proc.
998 upvar dg-messages dg-messages
999 global gcc_error_prefix
1001 process-message saved-dg-error "$gcc_error_prefix" "$args"
1004 # Override dg-bogus at the same time. It doesn't handle a prefix
1005 # but its expression should
include a column number. Otherwise the
1006 # line number can match the column number
for other messages
, leading
1008 rename dg
-bogus saved
-dg
-bogus
1010 proc dg
-bogus
{ args } {
1011 upvar dg
-messages dg
-messages
1012 process
-message saved
-dg
-bogus
"" $args
1016 #
Set variable VARNAME to LINENR
1018 proc dg
-line
{ linenr varname
} {
1019 set org_varname $varname
1020 set varname
"saved_linenr_$varname"
1021 eval global $varname
1023 # Generate defined
-but
-previously
-defined error.
1024 eval
set var_defined
[info exists $varname
]
1025 if { $var_defined
} {
1026 eval
set deflinenr \$$varname
1027 error
"dg-line var $org_varname defined at line $linenr, but previously defined at line $deflinenr"
1031 eval
set $varname $linenr
1033 # Schedule cleanup of varname by cleanup
-after
-saved
-dg
-test
1034 global save_linenr_varnames
1035 if { [info exists save_linenr_varnames
] } {
1036 lappend save_linenr_varnames $varname
1038 set save_linenr_varnames
[list $varname
]
1042 # Modify the regular expression saved by a DejaGnu message directive to
1043 #
include a prefix and to force the expression to match a single line.
1044 # MSGPROC is the procedure to
call.
1045 # MSGPREFIX is the prefix to prepend.
1046 # DGARGS is the original
argument list.
1048 proc process
-message
{ msgproc msgprefix dgargs
} {
1049 upvar dg
-messages dg
-messages
1051 if { [llength $dgargs
] == 5 } {
1052 if { [regsub
"^\.\[+-\](\[0-9\]+)$" [lindex $dgargs 4] "\\1" num] } {
1053 # Handle relative line specification
, .
+1 or .
-1 etc.
1054 set num
[expr
[lindex $dgargs
0] [string index
[lindex $dgargs
4] 1] $num
]
1055 set dgargs
[lreplace $dgargs
4 4 $num
]
1056 } elseif
{ [regsub
"^(\[a-zA-Z\]\[a-zA-Z0-9_\]*)$" [lindex $dgargs 4] "\\1" varname] } {
1057 # Handle linenr
variable defined by dg
-line
1059 set org_varname $varname
1060 set varname
"saved_linenr_$varname"
1061 eval global $varname
1063 # Generate used
-but
-not
-defined error.
1064 eval
set var_defined
[info exists $varname
]
1065 if { ! $var_defined
} {
1066 set linenr
[expr
[lindex $dgargs
0]]
1067 error
"dg-line var $org_varname used at line $linenr, but not defined"
1071 # Note that varname has been used.
1072 set varname_used
"used_$varname"
1073 eval global $varname_used
1074 eval
set $varname_used
1
1076 #
Get line number from var and use it.
1077 eval
set num \$$varname
1078 set dgargs
[lreplace $dgargs
4 4 $num
]
1082 # Process the dg
- directive
, including adding the regular expression
1083 # to the new message entry in dg
-messages.
1084 set msgcnt
[llength $
{dg
-messages
}]
1085 eval $msgproc $dgargs
1087 #
If the target expression wasn
't satisfied there is no new message.
1088 if { [llength ${dg-messages}] == $msgcnt } {
1092 # Get the entry for the new message. Prepend the message prefix to
1093 # the regular expression and make it match a single line.
1094 set newentry [lindex ${dg-messages} end]
1095 set expmsg [lindex $newentry 2]
1098 # Handle column numbers from the specified expression (if there is
1099 # one) and set up the search expression that will be used by DejaGnu.
1100 if [regexp {^-:} $expmsg] {
1101 # The expected column is -, so shouldn't appear.
1102 set expmsg
[string range $expmsg
2 end
]
1103 } elseif
[regexp
{^
[0-9]+:} $expmsg column
] {
1104 # The expression in the directive included a column number.
1105 # Remove it from the original expression and
move it
1106 # to the proper place in the search expression.
1107 set expmsg
[string range $expmsg
[string length $column
] end
]
1108 set column
"$column "
1109 } elseif
[string match
"" [lindex $newentry 0]] {
1110 # The specified line number is
0; don
't expect a column number.
1112 # There is no column number in the search expression, but we
1113 # should expect one in the message itself.
1114 set column {[0-9]+: }
1116 set expmsg "$column$msgprefix\[^\n\]*$expmsg"
1117 set newentry [lreplace $newentry 2 2 $expmsg]
1119 set dg-messages [lreplace ${dg-messages} end end $newentry]
1120 verbose "process-message:\n${dg-messages}" 2
1123 # Look for messages that don't have standard prefixes.
1125 proc dg
-message
{ args } {
1126 upvar dg
-messages dg
-messages
1127 process
-message saved
-dg
-warning
"" $args
1130 # Look
for a location marker of the form
1132 # with no extra
text (e.g. a line
-span separator
).
1134 proc dg
-locus
{ args } {
1135 upvar dg
-messages dg
-messages
1137 # Process the dg
- directive
, including adding the regular expression
1138 # to the new message entry in dg
-messages.
1139 set msgcnt
[llength $
{dg
-messages
}]
1140 eval saved
-dg
-warning $
args
1142 #
If the target expression wasn
't satisfied there is no new message.
1143 if { [llength ${dg-messages}] == $msgcnt } {
1147 # Get the entry for the new message. Prepend the message prefix to
1148 # the regular expression and make it match a single line.
1149 set newentry [lindex ${dg-messages} end]
1150 set expmsg [lindex $newentry 2]
1152 set newentry [lreplace $newentry 2 2 $expmsg]
1153 set dg-messages [lreplace ${dg-messages} end end $newentry]
1154 verbose "process-message:\n${dg-messages}" 2
1157 # Check the existence of a gdb in the path, and return true if there
1160 # Set env(GDB_FOR_GCC_TESTING) accordingly.
1162 proc gdb-exists { args } {
1163 if ![info exists ::env(GDB_FOR_GCC_TESTING)] {
1165 if ![info exists ::env(GDB_FOR_GCC_TESTING)] {
1166 if [info exists GDB] {
1167 setenv GDB_FOR_GCC_TESTING "$GDB"
1169 setenv GDB_FOR_GCC_TESTING "[transform gdb]"
1173 if { [which $::env(GDB_FOR_GCC_TESTING)] != 0 } {
1179 set additional_prunes ""
1180 set dg_runtest_extra_prunes ""