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
27 load_lib timeout
-dg.exp
30 load_lib target
-libpath.exp
31 load_lib torture
-options.exp
32 load_lib fortran
-modules.exp
33 load_lib multiline.exp
35 # We
set LC_ALL and LANG to C so that we
get the same error messages as expected.
39 # Many hosts now default to a non
-ASCII C locale
, however
, so
40 # they can
set a
charset encoding here
if they need.
41 if { [ishost
"*-*-cygwin*"] } {
46 # Avoid sporadic data
-losses with expect
49 # Ensure GCC_COLORS is unset
, for the rare testcases that verify
50 # how output is colorized.
51 if [info exists ::env
(GCC_COLORS
) ] {
56 if ![info exists GCC_UNDER_TEST
] {
57 set GCC_UNDER_TEST
"[find_gcc]"
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 # Some torture-options cause intermediate code output, unusable for
68 # testing using e.g. scan-assembler. In this variable are the options
69 # how to force it, when needed.
70 global gcc_force_conventional_output
71 set gcc_force_conventional_output ""
73 set LTO_TORTURE_OPTIONS ""
74 if [info exists TORTURE_OPTIONS] {
75 set DG_TORTURE_OPTIONS $TORTURE_OPTIONS
77 # It is theoretically beneficial to group all of the O2/O3 options together,
78 # as in many cases the compiler will generate identical executables for
79 # all of them--and the c-torture testsuite will skip testing identical
80 # executables multiple times.
81 # Also note that -finline-functions is explicitly included in one of the
82 # items below, even though -O3 is also specified, because some ports may
83 # choose to disable inlining functions by default, even when optimizing.
84 set DG_TORTURE_OPTIONS [list \
88 { -O3 -fomit-frame-pointer -funroll-loops -fpeel-loops -ftracer -finline-functions } \
92 if [check_effective_target_lto] {
93 # When having plugin test both slim and fat LTO and plugin/nonplugin
95 if [check_linker_plugin_available] {
96 set LTO_TORTURE_OPTIONS [list \
97 { -O2 -flto -fno-use-linker-plugin -flto-partition=none } \
98 { -O2 -flto -fuse-linker-plugin -fno-fat-lto-objects }
101 set LTO_TORTURE_OPTIONS [list \
102 { -O2 -flto -flto-partition=none } \
106 set gcc_force_conventional_output "-ffat-lto-objects"
110 if [info exists ADDITIONAL_TORTURE_OPTIONS] {
111 set DG_TORTURE_OPTIONS \
112 [concat $DG_TORTURE_OPTIONS $ADDITIONAL_TORTURE_OPTIONS]
115 global orig_environment_saved
117 # Deduce generated files from tool flags, return finalcode string
118 proc schedule-cleanups { opts } {
119 global additional_sources
122 lappend testcases [lindex [testname-for-summary] 0]
123 verbose "Cleanup testcases: $testcases" 4
124 if { [info exists additional_sources] && $additional_sources != "" } {
125 lappend testcases $additional_sources
126 verbose "Cleanup testcases, additional: $additional_sources" 4
128 verbose "Cleanup all options: $opts" 4
130 # First some fixups to transform stuff to something manageable ..
131 # --dump= should translate to -d with joined operand.
132 if [regexp -- {(^|\s+)--dump=[^\s]+(\s+|$)} $opts] {
133 regsub -all -- {--dump=} $opts {-d} opts
135 # -da and -dx are treated as shorthand for -fdump-rtl-all here
136 if [regexp -- {(^|\s+)-d[ax](\s+|$)} $opts] {
137 verbose "Cleanup -d seen" 4
138 lappend opts "-fdump-rtl-all"
140 # .. and don't question why there is
--dump
=? and
-d?
142 #
Then handle options that generate non
-dump files
144 #
-fprofile
-generate
-> cleanup
-coverage
-files
()
145 #
-fstack
-usage
-> cleanup
-stack
-usage
()
146 if [regexp
-- {(^|\s
+)-fstack
-usage
(\s
+|$
)} $opts
] {
147 verbose
"Cleanup -fstack-usage seen" 4
148 # append finalcode
"cleanup-stack-usage\n"
150 global keep_saved_temps_suffixes
151 if [info exists keep_saved_temps_suffixes
] {
152 verbose
"dg-keep-saved-temps ${keep_saved_temps_suffixes}" 2
154 #
-save
-temps
-> cleanup
-saved
-temps
()
155 if [regexp
-- {(^|\s
+)-save
-temps
(\s
+|$
)} $opts
] {
156 verbose
"Cleanup -save-temps seen" 4
157 if [info exists keep_saved_temps_suffixes
] {
158 append finalcode
"cleanup-saved-temps ${keep_saved_temps_suffixes}\n"
160 append finalcode
"cleanup-saved-temps\n"
163 if [info exists keep_saved_temps_suffixes
] {
164 error
"dg-keep-saved-temps specified but testcase does not -save-temps"
168 # Finally see
if there are
any dumps in opts
, otherwise we are done
169 if [regexp
-- {(?
=(?
:^|
[ \t]+)?
)-fdump
-[^
\t]+(?
=(?
:$|
[ \t]+)?
)} $opts
] {
170 # Lang
, Ipa
, Rtl
, Tree
for simplicity
175 # stem.ext.
<passnum
><fam
>.
<passname
><pass
-instances
>
176 #
(tree
)passes can have multiple instances
, thus optional trailing
*
177 set ptn
"\[0-9\]\[0-9\]\[0-9\]$ptn.*"
178 # Handle ltrans files around
-flto
179 if [regexp
-- {(^|\s
+)-flto
(\s
+|$
)} $opts
] {
180 verbose
"Cleanup -flto seen" 4
181 set ltrans
"{ltrans\[0-9\]*.,}"
185 set ptn
"$ltrans$ptn"
186 verbose
"Cleanup final ptn: $ptn" 4
188 foreach src $testcases
{
189 set basename
[file tail $src
]
190 if { $ltrans
!= "" } {
191 # ??? should we use upvar
1 output_file instead of this
(dup ?
)
192 set stem
[file rootname $basename
]
193 set basename_ext
[file extension $basename
]
194 if {$basename_ext
!= ""} {
195 regsub
-- {^.
*\.
} $basename_ext
{} basename_ext
197 lappend tfiles
"$stem.{$basename_ext,exe}"
200 lappend tfiles $basename
203 if { [llength $tfiles
] > 1 } {
204 set tfiles
[join $tfiles
","]
205 set tfiles
"{$tfiles}"
207 verbose
"Cleanup final testcases: $tfiles" 4
208 # We have to quote the regex
209 regsub
-all
{([][$^?
+*()|
\\{}])} "$tfiles.$ptn" {\\\1} ptn
211 append final
{remove
-build
-file
}
212 append final
"\"$ptn\""
213 verbose
"Cleanup final: $final" 4
214 append finalcode
"$final\n"
219 #
Define gcc callbacks
for dg.exp.
221 proc gcc
-dg
-test
-1 { target_compile prog do_what extra_tool_flags
} {
222 #
Set up the compiler flags
, based
on what we
're going to do.
226 # Tests should be able to use "dg-do repo". However, the dg test
227 # driver checks the argument to dg-do against a list of acceptable
228 # options, and "repo" is not among them. Therefore, we resort to
229 # this ugly approach.
230 if [string match "*-frepo*" $extra_tool_flags] then {
236 set compile_type "preprocess"
237 set output_file "[file rootname [file tail $prog]].i"
240 set compile_type "assembly"
241 set output_file "[file rootname [file tail $prog]].s"
244 set compile_type "object"
245 set output_file "[file rootname [file tail $prog]].o"
248 set compile_type "precompiled_header"
249 set output_file "[file tail $prog].gch"
252 set compile_type "executable"
253 set output_file "[file rootname [file tail $prog]].exe"
254 # The following line is needed for targets like the i960 where
255 # the default output file is b.out. Sigh.
258 set compile_type "object"
259 set output_file "[file rootname [file tail $prog]].o"
262 set compile_type "executable"
263 # FIXME: "./" is to cope with "." not being in $PATH.
264 # Should this be handled elsewhere?
266 set output_file "./[file rootname [file tail $prog]].exe"
267 # This is the only place where we care if an executable was
268 # created or not. If it was, dg.exp will try to run it.
269 catch { remote_file build delete $output_file }
272 perror "$do_what: not a valid dg-do keyword"
277 # Let { dg-final { action } } force options as returned by an
278 # optional proc ${action}_required_options.
279 upvar 2 dg-final-code finalcode
280 foreach x [split $finalcode "\n"] {
281 set finalcmd [lindex $x 0]
282 if { [info procs ${finalcmd}_required_options] != "" } {
283 set req [${finalcmd}_required_options]
284 if { $req != "" && [lsearch -exact $extra_tool_flags $req] == -1 } {
285 lappend extra_tool_flags $req
290 append finalcode [schedule-cleanups "$options $extra_tool_flags"]
291 if { $extra_tool_flags != "" } {
292 lappend options "additional_flags=$extra_tool_flags"
295 verbose "$target_compile $prog $output_file $compile_type $options" 4
296 set comp_output [$target_compile "$prog" "$output_file" "$compile_type" $options]
298 # Look for an internal compiler error, which sometimes masks the fact
299 # that we didn't
get an expected error message. XFAIL an ICE via
300 # dg
-xfail
-if and use
{ dg
-prune
-output
".*internal compiler error.*" }
301 # to avoid a second failure
for excess errors.
302 if [string match
"*internal compiler error*" $comp_output] {
304 fail
"$name (internal compiler error)"
307 if { $do_what
== "repo" } {
308 set object_file
"$output_file"
309 set output_file
"[file rootname [file tail $prog]].exe"
311 [ concat $comp_output \
312 [$target_compile
"$object_file" "$output_file" \
313 "executable" $options] ]
316 return [list $comp_output $output_file
]
319 proc gcc
-dg
-test
{ prog do_what extra_tool_flags
} {
320 return [gcc
-dg
-test
-1 gcc_target_compile $prog $do_what $extra_tool_flags
]
323 # Global
: should
blank lines be allowed in the output?
324 # By default
, they should not be.
(PR other
/69006)
325 # However
, there are some ways
for them to validly occur.
326 set allow_blank_lines
0
328 # A command
for use by testcases to mark themselves as expecting
329 #
blank lines in the output.
331 proc dg
-allow
-blank-lines
-in
-output
{ args } {
332 global allow_blank_lines
333 set allow_blank_lines
1
336 proc gcc
-dg
-prune
{ system text } {
337 global additional_prunes
339 # Extra prune rules that will apply to tests defined in a .exp file.
340 # Always remember to clear it in .exp file after executed all tests.
341 global dg_runtest_extra_prunes
343 # Complain about
blank lines in the output
(PR other
/69006)
344 global allow_blank_lines
345 if { !$allow_blank_lines
} {
346 set num_blank_lines
[llength
[regexp
-all
-inline
"\n\n" $text]]
347 if { $num_blank_lines
} {
348 global testname_with_flags
349 fail
"$testname_with_flags $num_blank_lines blank line(s) in output"
351 set allow_blank_lines
0
354 set text [prune_gcc_output $
text]
356 foreach p
"$additional_prunes $dg_runtest_extra_prunes" {
357 if { [string length $p
] > 0 } {
358 # Following regexp matches a complete line containing $p.
359 regsub
-all
"(^|\n)\[^\n\]*$p\[^\n\]*" $text "" text
363 #
If we see
"region xxx is full" then the testcase is too big for ram.
364 # This is tricky to deal with in a large testsuite like c
-torture so
365 # deal with it here. Just mark the testcase as unsupported.
366 if [regexp
"(^|\n)\[^\n\]*: region \[^\n\]* is full" $text] {
367 # The format here is important. See dg.exp.
368 return "::unsupported::memory full"
371 if { [regexp
"(^|\n)\[^\n\]*: relocation truncated to fit" $text]
372 && [check_effective_target_tiny
] } {
373 return "::unsupported::memory full"
376 # Likewise
, if we see
".text exceeds local store range" or
378 if {[string match
"spu-*" $system] && \
379 [string match
"*exceeds local store*" $text]} {
380 # The format here is important. See dg.exp.
381 return "::unsupported::memory full"
387 # Replace $
{tool
}_load with a wrapper to provide
for an expected nonzero
388 # exit
status. Multiple languages
include this file so this handles them
390 if { [info procs $
{tool
}_load
] != [list
] \
391 && [info procs saved_$
{tool
}_load
] == [list
] } {
392 rename $
{tool
}_load saved_$
{tool
}_load
394 proc $
{tool
}_load
{ program args } {
397 global set_target_env_var
399 set saved_target_env_var
[list
]
400 if { [info exists set_target_env_var
] \
401 && [llength $set_target_env_var
] != 0 } {
402 if { [is_remote target
] } {
403 return [list
"unsupported" ""]
407 set result
[eval
[list saved_$
{tool
}_load $
program] $
args]
408 if { [info exists set_target_env_var
] \
409 && [llength $set_target_env_var
] != 0 } {
410 restore
-target
-env
-var
412 if { $shouldfail
!= 0 } {
413 switch [lindex $result
0] {
414 "pass" { set status "fail" }
415 "fail" { set status "pass" }
416 default
{ set status [lindex $result
0] }
418 set result
[list $
status [lindex $result
1]]
421 set result
[list
[lindex $result
0] [prune_file_path
[lindex $result
1]]]
426 proc dg
-set-target
-env
-var
{ args } {
427 global set_target_env_var
428 if { [llength $
args] != 3 } {
429 error
"dg-set-target-env-var: need two arguments"
432 lappend set_target_env_var
[list
[lindex $
args 1] [lindex $
args 2]]
435 proc
set-target
-env
-var
{ } {
436 global set_target_env_var
437 upvar
1 saved_target_env_var saved_target_env_var
438 foreach env_var $set_target_env_var
{
439 set var
[lindex $env_var
0]
440 set value
[lindex $env_var
1]
441 if [info exists ::env
($var
)] {
442 lappend saved_target_env_var
[list $var
1 $
::env
($var
)]
444 lappend saved_target_env_var
[list $var
0]
450 proc restore
-target
-env
-var
{ } {
451 upvar
1 saved_target_env_var saved_target_env_var
452 for { set env_vari
[llength $saved_target_env_var
] } {
453 [incr env_vari
-1] >= 0 } {} {
454 set env_var
[lindex $saved_target_env_var $env_vari
]
455 set var
[lindex $env_var
0]
456 if [lindex $env_var
1] {
457 setenv $var
[lindex $env_var
2]
464 proc dg
-set-compiler
-env
-var
{ args } {
465 global set_compiler_env_var
466 global saved_compiler_env_var
467 if { [llength $
args] != 3 } {
468 error
"dg-set-compiler-env-var: need two arguments"
471 set var
[lindex $
args 1]
472 set value
[lindex $
args 2]
473 if [info exists ::env
($var
)] {
474 lappend saved_compiler_env_var
[list $var
1 $
::env
($var
)]
476 lappend saved_compiler_env_var
[list $var
0]
479 lappend set_compiler_env_var
[list $var $value
]
482 proc restore
-compiler
-env
-var
{ } {
483 global saved_compiler_env_var
484 for { set env_vari
[llength $saved_compiler_env_var
] } {
485 [incr env_vari
-1] >= 0 } {} {
486 set env_var
[lindex $saved_compiler_env_var $env_vari
]
487 set var
[lindex $env_var
0]
488 if [lindex $env_var
1] {
489 setenv $var
[lindex $env_var
2]
499 # search_for
-- looks
for a string match in a file
501 proc search_for
{ file pattern
} {
502 set fd
[open $file r
]
503 while { [gets $fd cur_line
]>=0 } {
504 if [string match
"*$pattern*" $cur_line] then {
513 # Modified dg
-runtest that can cycle through a list of optimization options
515 proc gcc
-dg
-runtest
{ testcases flags default
-extra
-flags
} {
518 # Some callers
set torture options themselves
; don
't override those.
519 set existing_torture_options [torture-options-exist]
520 if { $existing_torture_options == 0 } {
521 global DG_TORTURE_OPTIONS LTO_TORTURE_OPTIONS
523 set-torture-options $DG_TORTURE_OPTIONS [list {}] $LTO_TORTURE_OPTIONS
527 foreach test $testcases {
528 global torture_with_loops torture_without_loops
529 # If we're only testing specific files and this isn
't one of
531 if ![runtest_file_p $runtests $test] {
535 # Look for a loop within the source code - if we don't find one
,
536 # don
't pass -funroll[-all]-loops.
537 if [expr [search_for $test "for*("]+[search_for $test "while*("]] {
538 set option_list $torture_with_loops
540 set option_list $torture_without_loops
543 set nshort [file tail [file dirname $test]]/[file tail $test]
545 foreach flags_t $option_list {
546 global torture_current_flags
547 set torture_current_flags "$flags_t"
548 verbose "Testing $nshort, $flags $flags_t" 1
549 dg-test $test "$flags $flags_t" ${default-extra-flags}
553 if { $existing_torture_options == 0 } {
558 proc gcc-dg-debug-runtest { target_compile trivial opt_opts testcases } {
561 if ![info exists DEBUG_TORTURE_OPTIONS] {
562 set DEBUG_TORTURE_OPTIONS ""
563 foreach type {-gdwarf-2 -gstabs -gstabs+ -gxcoff -gxcoff+ -gcoff} {
564 set comp_output [$target_compile \
565 "$srcdir/$subdir/$trivial" "trivial.S" assembly \
566 "additional_flags=$type"]
567 if { ! [string match "*: target system does not support the * debug format*" \
569 remove-build-file "trivial.S"
570 foreach level {1 "" 3} {
571 if { ($type == "-gdwarf-2") && ($level != "") } {
572 lappend DEBUG_TORTURE_OPTIONS [list "${type}" "-g${level}"]
573 foreach opt $opt_opts {
574 lappend DEBUG_TORTURE_OPTIONS \
575 [list "${type}" "-g${level}" "$opt" ]
578 lappend DEBUG_TORTURE_OPTIONS [list "${type}${level}"]
579 foreach opt $opt_opts {
580 lappend DEBUG_TORTURE_OPTIONS \
581 [list "${type}${level}" "$opt" ]
589 verbose -log "Using options $DEBUG_TORTURE_OPTIONS"
593 foreach test $testcases {
594 # If we're only testing specific files and this isn
't one of
596 if ![runtest_file_p $runtests $test] {
600 set nshort [file tail [file dirname $test]]/[file tail $test]
602 foreach flags $DEBUG_TORTURE_OPTIONS {
605 # These tests check for information which may be deliberately
607 if { ([string match {*/debug-[126].c} "$nshort"] \
608 || [string match {*/enum-1.c} "$nshort"] \
609 || [string match {*/enum-[12].C} "$nshort"]) \
610 && ([string match "*1" [lindex "$flags" 0] ]
611 || [lindex "$flags" 1] == "-g1") } {
615 # High optimization can remove the variable whose existence is tested.
616 # Dwarf debugging with commentary (-dA) preserves the symbol name in the
617 # assembler output, but stabs debugging does not.
618 # http://gcc.gnu.org/ml/gcc-regression/2003-04/msg00095.html
619 if { [string match {*/debug-[12].c} "$nshort"] \
620 && [string match "*O*" "$flags"] \
621 && ( [string match "*coff*" "$flags"] \
622 || [string match "*stabs*" "$flags"] ) } {
627 verbose -log "Testing $nshort, $flags" 1
628 dg-test $test $flags ""
634 # Prune any messages matching ARGS[1] (a regexp) from test output.
635 proc dg-prune-output { args } {
636 global additional_prunes
638 if { [llength $args] != 2 } {
639 error "[lindex $args 1]: need one argument"
643 lappend additional_prunes [lindex $args 1]
646 # Remove files matching the pattern from the build machine.
647 proc remove-build-file { pat } {
648 verbose "remove-build-file `$pat'" 2
649 set file_list
"[glob -nocomplain $pat]"
650 verbose
"remove-build-file `$file_list'" 2
651 foreach output_file $file_list
{
652 if [is_remote host
] {
653 # Ensure the host knows the file is gone by deleting there
655 remote_file host
delete $output_file
657 remote_file build
delete $output_file
661 # Remove runtime
-generated profile file
for the current test.
662 proc cleanup
-profile
-file
{ } {
663 remove
-build
-file
"mon.out"
664 remove
-build
-file
"gmon.out"
667 # Remove compiler
-generated coverage files
for the current test.
668 proc cleanup
-coverage
-files
{ } {
669 global additional_sources_used
670 set testcase
[testname
-for-summary
]
671 # The
name might
include a list of options
; extract the file
name.
672 set testcase
[lindex $testcase
0]
673 remove
-build
-file
"[file rootname [file tail $testcase]].gc??"
675 # Clean up coverage files
for additional source files.
676 if [info exists additional_sources_used
] {
677 foreach srcfile $additional_sources_used
{
678 remove
-build
-file
"[file rootname [file tail $srcfile]].gc??"
683 # Remove compiler
-generated files from
-repo
for the current test.
684 proc cleanup
-repo
-files
{ } {
685 global additional_sources_used
686 set testcase
[testname
-for-summary
]
687 # The
name might
include a list of options
; extract the file
name.
688 set testcase
[lindex $testcase
0]
689 remove
-build
-file
"[file rootname [file tail $testcase]].o"
690 remove
-build
-file
"[file rootname [file tail $testcase]].rpo"
692 # Clean up files
for additional source files.
693 if [info exists additional_sources_used
] {
694 foreach srcfile $additional_sources_used
{
695 remove
-build
-file
"[file rootname [file tail $srcfile]].o"
696 remove
-build
-file
"[file rootname [file tail $srcfile]].rpo"
701 # Remove a final insns dump file
for the current test.
702 proc cleanup
-final
-insns
-dump
{ } {
703 set testcase
[testname
-for-summary
]
704 # The
name might
include a list of options
; extract the file
name.
705 set testcase
[lindex $testcase
0]
706 remove
-build
-file
"[file rootname [file tail $testcase]].s.gkd"
708 # Clean up files
for additional source files.
709 if [info exists additional_sources_used
] {
710 foreach srcfile $additional_sources_used
{
711 remove
-build
-file
"[file rootname [file tail $srcfile]].s.gkd"
716 # Remove a stack usage file
for the current test.
717 proc cleanup
-stack
-usage
{ } {
718 set testcase
[testname
-for-summary
]
719 # The
name might
include a list of options
; extract the file
name.
720 set testcase
[lindex $testcase
0]
721 remove
-build
-file
"[file rootname [file tail $testcase]].su"
723 # Clean up files
for additional source files.
724 if [info exists additional_sources_used
] {
725 foreach srcfile $additional_sources_used
{
726 remove
-build
-file
"[file rootname [file tail $srcfile]].su"
731 # Remove an Ada spec file
for the current test.
732 proc cleanup
-ada
-spec
{ } {
733 global additional_sources_used
734 set testcase
[testname
-for-summary
]
735 remove
-build
-file
"[get_ada_spec_filename $testcase]"
737 # Clean up files
for additional source files.
738 if [info exists additional_sources_used
] {
739 foreach srcfile $additional_sources_used
{
740 remove
-build
-file
"[get_ada_spec_filename $srcfile]"
745 # Remove files kept by
--save
-temps
for the current test.
747 # Currently this is only .i
, .ii
, .s and .o files
, but more can be added
748 #
if there are tests generating them.
749 #
ARGS is a list of suffixes to NOT
delete.
750 proc cleanup
-saved
-temps
{ args } {
751 global additional_sources_used
754 # add the to
-be
-kept suffixes
755 foreach suffix
{".mii" ".ii" ".i" ".s" ".o" ".gkd" ".res" ".ltrans.out"} {
756 if {[lsearch $
args $suffix
] < 0} {
757 lappend suffixes $suffix
761 set testcase
[testname
-for-summary
]
762 # The
name might
include a list of options
; extract the file
name.
763 set testcase
[lindex $testcase
0]
764 foreach suffix $suffixes
{
765 remove
-build
-file
"[file rootname [file tail $testcase]]$suffix"
766 remove
-build
-file
"[file rootname [file tail $testcase]].exe$suffix"
767 remove
-build
-file
"[file rootname [file tail $testcase]].exe.ltrans\[0-9\]*$suffix"
768 #
-fcompare
-debug dumps
769 remove
-build
-file
"[file rootname [file tail $testcase]].gk$suffix"
772 # Clean up saved temp files
for additional source files.
773 if [info exists additional_sources_used
] {
774 foreach srcfile $additional_sources_used
{
775 foreach suffix $suffixes
{
776 remove
-build
-file
"[file rootname [file tail $srcfile]]$suffix"
777 remove
-build
-file
"[file rootname [file tail $srcfile]].exe$suffix"
778 remove
-build
-file
"[file rootname [file tail $srcfile]].exe.ltrans\[0-9\]*$suffix"
780 #
-fcompare
-debug dumps
781 remove
-build
-file
"[file rootname [file tail $srcfile]].gk$suffix"
788 # Files to be kept after cleanup of
--save
-temps
for the current test.
789 #
ARGS is a list of suffixes to NOT
delete.
790 proc dg
-keep
-saved
-temps
{ args } {
791 global keep_saved_temps_suffixes
792 set keep_saved_temps_suffixes
{}
794 # add the to
-be
-kept suffixes
795 foreach suffix
{".mii" ".ii" ".i" ".s" ".o" ".gkd" ".res" ".ltrans.out"} {
796 if {[lsearch $
args $suffix
] >= 0} {
797 lappend keep_saved_temps_suffixes $suffix
800 if { [llength keep_saved_temps_suffixes
] < 1 } {
801 error
"dg-keep-saved-temps ${args} did not match any known suffix"
805 # Scan Fortran modules
for a given regexp.
807 #
Argument 0 is the module
name
808 #
Argument 1 is the regexp to match
809 proc scan
-module
{ args } {
810 set modfilename
[string tolower
[lindex $
args 0]].mod
811 set fd
[open
[list | gzip
-dc $modfilename
] r
]
815 set testcase
[testname
-for-summary
]
816 if [regexp
-- [lindex $
args 1] $
text] {
817 pass
"$testcase scan-module [lindex $args 1]"
819 fail
"$testcase scan-module [lindex $args 1]"
823 # Scan Fortran modules
for absence of a given regexp.
825 #
Argument 0 is the module
name
826 #
Argument 1 is the regexp to match
827 proc scan
-module
-absence
{ args } {
828 set modfilename
[string tolower
[lindex $
args 0]].mod
829 set fd
[open
[list | gzip
-dc $modfilename
] r
]
833 set testcase
[testname
-for-summary
]
834 if [regexp
-- [lindex $
args 1] $
text] {
835 fail
"$testcase scan-module [lindex $args 1]"
837 pass
"$testcase scan-module [lindex $args 1]"
841 # Verify that the compiler output file
exists, invoked via dg
-final.
842 proc output
-exists { args } {
843 # Process an optional target or xfail list.
844 if { [llength $
args] >= 1 } {
845 switch [dg
-process
-target
[lindex $
args 0]] {
848 "F" { setup_xfail "*-*-*" }
853 set testcase
[testname
-for-summary
]
854 # Access
variable from gcc
-dg
-test
-1.
855 upvar
2 output_file output_file
857 if [file
exists $output_file
] {
858 pass
"$testcase output-exists $output_file"
860 fail
"$testcase output-exists $output_file"
864 # Verify that the compiler output file does not exist
, invoked via dg
-final.
865 proc output
-exists-not
{ args } {
866 # Process an optional target or xfail list.
867 if { [llength $
args] >= 1 } {
868 switch [dg
-process
-target
[lindex $
args 0]] {
871 "F" { setup_xfail "*-*-*" }
876 set testcase
[testname
-for-summary
]
877 # Access
variable from gcc
-dg
-test
-1.
878 upvar
2 output_file output_file
880 if [file
exists $output_file
] {
881 fail
"$testcase output-exists-not $output_file"
883 pass
"$testcase output-exists-not $output_file"
887 # We need to make sure that additional_
* are cleared out after
every
888 # test. It is not enough to clear them out
*before
* the next test run
889 # because gcc
-target
-compile gets run directly from some .exp files
890 #
(outside of
any test
).
(Those uses should eventually be eliminated.
)
892 # Because the DG framework doesn
't provide a hook that is run at the
893 # end of a test, we must replace dg-test with a wrapper.
895 if { [info procs saved-dg-test] == [list] } {
896 rename dg-test saved-dg-test
898 # Helper function for cleanups that should happen after the call
899 # to the real dg-test, whether or not it returns normally, or
900 # fails with an error.
901 proc cleanup-after-saved-dg-test { } {
902 global additional_files
903 global additional_sources
904 global additional_sources_used
905 global additional_prunes
906 global compiler_conditional_xfail_data
908 global testname_with_flags
909 global set_target_env_var
910 global set_compiler_env_var
911 global saved_compiler_env_var
912 global keep_saved_temps_suffixes
913 global multiline_expected_outputs
914 global freeform_regexps
915 global save_linenr_varnames
917 set additional_files ""
918 set additional_sources ""
919 set additional_sources_used ""
920 set additional_prunes ""
922 if [info exists set_target_env_var] {
923 unset set_target_env_var
925 if [info exists set_compiler_env_var] {
926 restore-compiler-env-var
927 unset set_compiler_env_var
928 unset saved_compiler_env_var
930 if [info exists keep_saved_temps_suffixes] {
931 unset keep_saved_temps_suffixes
934 if [info exists compiler_conditional_xfail_data] {
935 unset compiler_conditional_xfail_data
937 if [info exists testname_with_flags] {
938 unset testname_with_flags
940 set multiline_expected_outputs []
941 set freeform_regexps []
943 if { [info exists save_linenr_varnames] } {
944 foreach varname $save_linenr_varnames {
949 # Cleanup varname_used, or generate defined-but-not-used
951 set varname_used used_$varname
952 eval global $varname_used
953 eval set used [info exists $varname_used]
955 eval unset $varname_used
957 regsub {^saved_linenr_} $varname "" org_varname
958 warning "dg-line var $org_varname defined, but not used"
961 unset save_linenr_varnames
965 proc dg-test { args } {
968 if { [ catch { eval saved-dg-test $args } errmsg ] } {
969 set saved_info $errorInfo
970 cleanup-after-saved-dg-test
971 error $errmsg $saved_info
973 cleanup-after-saved-dg-test
977 if { [info procs saved-dg-warning] == [list] \
978 && [info exists gcc_warning_prefix] } {
979 rename dg-warning saved-dg-warning
981 proc dg-warning { args } {
982 # Make this variable available here and to the saved proc.
983 upvar dg-messages dg-messages
984 global gcc_warning_prefix
986 process-message saved-dg-warning "$gcc_warning_prefix" "$args"
990 if { [info procs saved-dg-error] == [list] \
991 && [info exists gcc_error_prefix] } {
992 rename dg-error saved-dg-error
994 proc dg-error { args } {
995 # Make this variable available here and to the saved proc.
996 upvar dg-messages dg-messages
997 global gcc_error_prefix
999 process-message saved-dg-error "$gcc_error_prefix" "$args"
1002 # Override dg-bogus at the same time. It doesn't handle a prefix
1003 # but its expression should
include a column number. Otherwise the
1004 # line number can match the column number
for other messages
, leading
1006 rename dg
-bogus saved
-dg
-bogus
1008 proc dg
-bogus
{ args } {
1009 upvar dg
-messages dg
-messages
1010 process
-message saved
-dg
-bogus
"" $args
1014 #
Set variable VARNAME to LINENR
1016 proc dg
-line
{ linenr varname
} {
1017 set org_varname $varname
1018 set varname
"saved_linenr_$varname"
1019 eval global $varname
1021 # Generate defined
-but
-previously
-defined error.
1022 eval
set var_defined
[info exists $varname
]
1023 if { $var_defined
} {
1024 eval
set deflinenr \$$varname
1025 error
"dg-line var $org_varname defined at line $linenr, but previously defined at line $deflinenr"
1029 eval
set $varname $linenr
1031 # Schedule cleanup of varname by cleanup
-after
-saved
-dg
-test
1032 global save_linenr_varnames
1033 if { [info exists save_linenr_varnames
] } {
1034 lappend save_linenr_varnames $varname
1036 set save_linenr_varnames
[list $varname
]
1040 # Modify the regular expression saved by a DejaGnu message directive to
1041 #
include a prefix and to force the expression to match a single line.
1042 # MSGPROC is the procedure to
call.
1043 # MSGPREFIX is the prefix to prepend.
1044 # DGARGS is the original
argument list.
1046 proc process
-message
{ msgproc msgprefix dgargs
} {
1047 upvar dg
-messages dg
-messages
1049 if { [llength $dgargs
] == 5 } {
1050 if { [regsub
"^\.\[+-\](\[0-9\]+)$" [lindex $dgargs 4] "\\1" num] } {
1051 # Handle relative line specification
, .
+1 or .
-1 etc.
1052 set num
[expr
[lindex $dgargs
0] [string index
[lindex $dgargs
4] 1] $num
]
1053 set dgargs
[lreplace $dgargs
4 4 $num
]
1054 } elseif
{ [regsub
"^(\[a-zA-Z\]\[a-zA-Z0-9_\]*)$" [lindex $dgargs 4] "\\1" varname] } {
1055 # Handle linenr
variable defined by dg
-line
1057 set org_varname $varname
1058 set varname
"saved_linenr_$varname"
1059 eval global $varname
1061 # Generate used
-but
-not
-defined error.
1062 eval
set var_defined
[info exists $varname
]
1063 if { ! $var_defined
} {
1064 set linenr
[expr
[lindex $dgargs
0]]
1065 error
"dg-line var $org_varname used at line $linenr, but not defined"
1069 # Note that varname has been used.
1070 set varname_used
"used_$varname"
1071 eval global $varname_used
1072 eval
set $varname_used
1
1074 #
Get line number from var and use it.
1075 eval
set num \$$varname
1076 set dgargs
[lreplace $dgargs
4 4 $num
]
1080 # Process the dg
- directive
, including adding the regular expression
1081 # to the new message entry in dg
-messages.
1082 set msgcnt
[llength $
{dg
-messages
}]
1083 eval $msgproc $dgargs
1085 #
If the target expression wasn
't satisfied there is no new message.
1086 if { [llength ${dg-messages}] == $msgcnt } {
1090 # Get the entry for the new message. Prepend the message prefix to
1091 # the regular expression and make it match a single line.
1092 set newentry [lindex ${dg-messages} end]
1093 set expmsg [lindex $newentry 2]
1095 # Handle column numbers from the specified expression (if there is
1096 # one) and set up the search expression that will be used by DejaGnu.
1097 if [regexp "^(\[0-9\]+):" $expmsg "" column] {
1098 # The expression in the directive included a column number.
1099 # Remove "COLUMN:" from the original expression and move it
1100 # to the proper place in the search expression.
1101 regsub "^\[0-9\]+:" $expmsg "" expmsg
1102 set expmsg "$column: $msgprefix\[^\n\]*$expmsg"
1103 } elseif [string match "" [lindex $newentry 0]] {
1104 # The specified line number is 0; don't expect a column number.
1105 set expmsg
"$msgprefix\[^\n\]*$expmsg"
1107 # There is no column number in the search expression
, but we
1108 # should expect one in the message itself.
1109 set expmsg
"\[0-9\]+: $msgprefix\[^\n\]*$expmsg"
1112 set newentry
[lreplace $newentry
2 2 $expmsg
]
1113 set dg
-messages
[lreplace $
{dg
-messages
} end end $newentry
]
1114 verbose
"process-message:\n${dg-messages}" 2
1117 # Look
for messages that don
't have standard prefixes.
1119 proc dg-message { args } {
1120 upvar dg-messages dg-messages
1121 process-message saved-dg-warning "" $args
1124 # Look for a location marker of the form
1126 # with no extra text (e.g. a line-span separator).
1128 proc dg-locus { args } {
1129 upvar dg-messages dg-messages
1131 # Process the dg- directive, including adding the regular expression
1132 # to the new message entry in dg-messages.
1133 set msgcnt [llength ${dg-messages}]
1134 eval saved-dg-warning $args
1136 # If the target expression wasn't satisfied there is no new message.
1137 if { [llength $
{dg
-messages
}] == $msgcnt
} {
1141 #
Get the entry
for the new message. Prepend the message prefix to
1142 # the regular expression and make it match a single line.
1143 set newentry
[lindex $
{dg
-messages
} end
]
1144 set expmsg
[lindex $newentry
2]
1146 set newentry
[lreplace $newentry
2 2 $expmsg
]
1147 set dg
-messages
[lreplace $
{dg
-messages
} end end $newentry
]
1148 verbose
"process-message:\n${dg-messages}" 2
1151 # Check the existence of a gdb in the path
, and
return true
if there
1154 #
Set env
(GDB_FOR_GCC_TESTING
) accordingly.
1156 proc gdb
-exists { args } {
1157 if ![info exists ::env
(GDB_FOR_GCC_TESTING
)] {
1159 if ![info exists ::env
(GDB_FOR_GCC_TESTING
)] {
1160 if [info exists GDB
] {
1161 setenv GDB_FOR_GCC_TESTING
"$GDB"
1163 setenv GDB_FOR_GCC_TESTING
"[transform gdb]"
1167 if { [which $
::env
(GDB_FOR_GCC_TESTING
)] != 0 } {
1173 set additional_prunes
""
1174 set dg_runtest_extra_prunes
""