]> git.ipfire.org Git - thirdparty/gcc.git/blob - gcc/testsuite/lib/gcc-dg.exp
PR testsuite/69181: ensure expected multiline outputs is cleared per-test
[thirdparty/gcc.git] / gcc / testsuite / lib / gcc-dg.exp
1 # Copyright (C) 1997-2016 Free Software Foundation, Inc.
2
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.
7 #
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.
12 #
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/>.
16
17 load_lib dg.exp
18 load_lib file-format.exp
19 load_lib target-supports.exp
20 load_lib target-supports-dg.exp
21 load_lib scanasm.exp
22 load_lib scanrtl.exp
23 load_lib scantree.exp
24 load_lib scanipa.exp
25 load_lib timeout.exp
26 load_lib timeout-dg.exp
27 load_lib prune.exp
28 load_lib libgloss.exp
29 load_lib target-libpath.exp
30 load_lib torture-options.exp
31 load_lib fortran-modules.exp
32 load_lib multiline.exp
33
34 # We set LC_ALL and LANG to C so that we get the same error messages as expected.
35 setenv LC_ALL C
36 setenv LANG C
37
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*"] } {
41 setenv LC_ALL C.ASCII
42 setenv LANG C.ASCII
43 }
44
45 global GCC_UNDER_TEST
46 if ![info exists GCC_UNDER_TEST] {
47 set GCC_UNDER_TEST "[find_gcc]"
48 }
49
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
55 }
56
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 ""
62
63 set LTO_TORTURE_OPTIONS ""
64 if [info exists TORTURE_OPTIONS] {
65 set DG_TORTURE_OPTIONS $TORTURE_OPTIONS
66 } else {
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 \
75 { -O0 } \
76 { -O1 } \
77 { -O2 } \
78 { -O3 -fomit-frame-pointer -funroll-loops -fpeel-loops -ftracer -finline-functions } \
79 { -O3 -g } \
80 { -Os } ]
81
82 if [check_effective_target_lto] {
83 # When having plugin test both slim and fat LTO and plugin/nonplugin
84 # path.
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 }
89 ]
90 set gcc_force_conventional_output "-ffat-lto-objects"
91 } else {
92 set LTO_TORTURE_OPTIONS [list \
93 { -O2 -flto -flto-partition=none } \
94 { -O2 -flto }
95 ]
96 }
97 }
98 }
99
100 if [info exists ADDITIONAL_TORTURE_OPTIONS] {
101 set DG_TORTURE_OPTIONS \
102 [concat $DG_TORTURE_OPTIONS $ADDITIONAL_TORTURE_OPTIONS]
103 }
104
105 global orig_environment_saved
106
107 # Deduce generated files from tool flags, return finalcode string
108 proc schedule-cleanups { opts } {
109 global additional_sources
110 set finalcode ""
111 set testcases {}
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
117 }
118 verbose "Cleanup all options: $opts" 4
119
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
124 }
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"
129 }
130 # .. and don't question why there is --dump=? and -d?
131
132 # Then handle options that generate non-dump files
133 # TODO
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"
139 }
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
143 }
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"
149 } else {
150 append finalcode "cleanup-saved-temps\n"
151 }
152 } else {
153 if [info exists keep_saved_temps_suffixes ] {
154 error "dg-keep-saved-temps specified but testcase does not -save-temps"
155 return
156 }
157 }
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
161 set ptn "{i,r,t}"
162 } else {
163 return $finalcode
164 }
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\]*.,}"
172 } else {
173 set ltrans ""
174 }
175 set ptn "$ltrans$ptn"
176 verbose "Cleanup final ptn: $ptn" 4
177 set tfiles {}
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
186 }
187 lappend tfiles "$stem.{$basename_ext,exe}"
188 unset basename_ext
189 } else {
190 lappend tfiles $basename
191 }
192 }
193 if { [llength $tfiles] > 1 } {
194 set tfiles [join $tfiles ","]
195 set tfiles "{$tfiles}"
196 }
197 verbose "Cleanup final testcases: $tfiles" 4
198 # We have to quote the regex
199 regsub -all {([][$^?+*()|\\{}])} "$tfiles.$ptn" {\\\1} ptn
200 set final ""
201 append final {remove-build-file }
202 append final "\"$ptn\""
203 verbose "Cleanup final: $final" 4
204 append finalcode "$final\n"
205
206 return $finalcode
207 }
208
209 # Define gcc callbacks for dg.exp.
210
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.
213
214 set options [list]
215
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 {
221 set do_what "repo"
222 }
223
224 switch $do_what {
225 "preprocess" {
226 set compile_type "preprocess"
227 set output_file "[file rootname [file tail $prog]].i"
228 }
229 "compile" {
230 set compile_type "assembly"
231 set output_file "[file rootname [file tail $prog]].s"
232 }
233 "assemble" {
234 set compile_type "object"
235 set output_file "[file rootname [file tail $prog]].o"
236 }
237 "precompile" {
238 set compile_type "precompiled_header"
239 set output_file "[file tail $prog].gch"
240 }
241 "link" {
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.
246 }
247 "repo" {
248 set compile_type "object"
249 set output_file "[file rootname [file tail $prog]].o"
250 }
251 "run" {
252 set compile_type "executable"
253 # FIXME: "./" is to cope with "." not being in $PATH.
254 # Should this be handled elsewhere?
255 # YES.
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 }
260 }
261 default {
262 perror "$do_what: not a valid dg-do keyword"
263 return ""
264 }
265 }
266
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
276 }
277 }
278 }
279
280 append finalcode [schedule-cleanups "$options $extra_tool_flags"]
281 if { $extra_tool_flags != "" } {
282 lappend options "additional_flags=$extra_tool_flags"
283 }
284
285 verbose "$target_compile $prog $output_file $compile_type $options" 4
286 set comp_output [$target_compile "$prog" "$output_file" "$compile_type" $options]
287
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] {
293 upvar 2 name name
294 fail "$name (internal compiler error)"
295 }
296
297 if { $do_what == "repo" } {
298 set object_file "$output_file"
299 set output_file "[file rootname [file tail $prog]].exe"
300 set comp_output \
301 [ concat $comp_output \
302 [$target_compile "$object_file" "$output_file" \
303 "executable" $options] ]
304 }
305
306 return [list $comp_output $output_file]
307 }
308
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]
311 }
312
313 proc gcc-dg-prune { system text } {
314 global additional_prunes
315
316 # Extra prune rules that will apply to tests defined in a .exp file.
317 # Always remember to clear it in .exp file after executed all tests.
318 global dg_runtest_extra_prunes
319
320 set text [prune_gcc_output $text]
321
322 foreach p "$additional_prunes $dg_runtest_extra_prunes" {
323 if { [string length $p] > 0 } {
324 # Following regexp matches a complete line containing $p.
325 regsub -all "(^|\n)\[^\n\]*$p\[^\n\]*" $text "" text
326 }
327 }
328
329 # If we see "region xxx is full" then the testcase is too big for ram.
330 # This is tricky to deal with in a large testsuite like c-torture so
331 # deal with it here. Just mark the testcase as unsupported.
332 if [regexp "(^|\n)\[^\n\]*: region \[^\n\]* is full" $text] {
333 # The format here is important. See dg.exp.
334 return "::unsupported::memory full"
335 }
336
337 if { [regexp "(^|\n)\[^\n\]*: relocation truncated to fit" $text]
338 && [check_effective_target_tiny] } {
339 return "::unsupported::memory full"
340 }
341
342 # Likewise, if we see ".text exceeds local store range" or
343 # similar.
344 if {[string match "spu-*" $system] && \
345 [string match "*exceeds local store*" $text]} {
346 # The format here is important. See dg.exp.
347 return "::unsupported::memory full"
348 }
349
350 return $text
351 }
352
353 # Replace ${tool}_load with a wrapper to provide for an expected nonzero
354 # exit status. Multiple languages include this file so this handles them
355 # all, not just gcc.
356 if { [info procs ${tool}_load] != [list] \
357 && [info procs saved_${tool}_load] == [list] } {
358 rename ${tool}_load saved_${tool}_load
359
360 proc ${tool}_load { program args } {
361 global tool
362 global shouldfail
363 global set_target_env_var
364
365 set saved_target_env_var [list]
366 if { [info exists set_target_env_var] \
367 && [llength $set_target_env_var] != 0 } {
368 if { [is_remote target] } {
369 return [list "unsupported" ""]
370 }
371 set-target-env-var
372 }
373 set result [eval [list saved_${tool}_load $program] $args]
374 if { [info exists set_target_env_var] \
375 && [llength $set_target_env_var] != 0 } {
376 restore-target-env-var
377 }
378 if { $shouldfail != 0 } {
379 switch [lindex $result 0] {
380 "pass" { set status "fail" }
381 "fail" { set status "pass" }
382 }
383 set result [list $status [lindex $result 1]]
384 }
385
386 set result [list [lindex $result 0] [prune_file_path [lindex $result 1]]]
387 return $result
388 }
389 }
390
391 proc dg-set-target-env-var { args } {
392 global set_target_env_var
393 if { [llength $args] != 3 } {
394 error "dg-set-target-env-var: need two arguments"
395 return
396 }
397 lappend set_target_env_var [list [lindex $args 1] [lindex $args 2]]
398 }
399
400 proc set-target-env-var { } {
401 global set_target_env_var
402 upvar 1 saved_target_env_var saved_target_env_var
403 foreach env_var $set_target_env_var {
404 set var [lindex $env_var 0]
405 set value [lindex $env_var 1]
406 if [info exists ::env($var)] {
407 lappend saved_target_env_var [list $var 1 $::env($var)]
408 } else {
409 lappend saved_target_env_var [list $var 0]
410 }
411 setenv $var $value
412 }
413 }
414
415 proc restore-target-env-var { } {
416 upvar 1 saved_target_env_var saved_target_env_var
417 for { set env_vari [llength $saved_target_env_var] } {
418 [incr env_vari -1] >= 0 } {} {
419 set env_var [lindex $saved_target_env_var $env_vari]
420 set var [lindex $env_var 0]
421 if [lindex $env_var 1] {
422 setenv $var [lindex $env_var 2]
423 } else {
424 unsetenv $var
425 }
426 }
427 }
428
429 # Utility routines.
430
431 #
432 # search_for -- looks for a string match in a file
433 #
434 proc search_for { file pattern } {
435 set fd [open $file r]
436 while { [gets $fd cur_line]>=0 } {
437 if [string match "*$pattern*" $cur_line] then {
438 close $fd
439 return 1
440 }
441 }
442 close $fd
443 return 0
444 }
445
446 # Modified dg-runtest that can cycle through a list of optimization options
447 # as c-torture does.
448 proc gcc-dg-runtest { testcases flags default-extra-flags } {
449 global runtests
450
451 # Some callers set torture options themselves; don't override those.
452 set existing_torture_options [torture-options-exist]
453 if { $existing_torture_options == 0 } {
454 global DG_TORTURE_OPTIONS LTO_TORTURE_OPTIONS
455 torture-init
456 set-torture-options $DG_TORTURE_OPTIONS [list {}] $LTO_TORTURE_OPTIONS
457 }
458 dump-torture-options
459
460 foreach test $testcases {
461 global torture_with_loops torture_without_loops
462 # If we're only testing specific files and this isn't one of
463 # them, skip it.
464 if ![runtest_file_p $runtests $test] {
465 continue
466 }
467
468 # Look for a loop within the source code - if we don't find one,
469 # don't pass -funroll[-all]-loops.
470 if [expr [search_for $test "for*("]+[search_for $test "while*("]] {
471 set option_list $torture_with_loops
472 } else {
473 set option_list $torture_without_loops
474 }
475
476 set nshort [file tail [file dirname $test]]/[file tail $test]
477
478 foreach flags_t $option_list {
479 verbose "Testing $nshort, $flags $flags_t" 1
480 dg-test $test "$flags $flags_t" ${default-extra-flags}
481 }
482 }
483
484 if { $existing_torture_options == 0 } {
485 torture-finish
486 }
487 }
488
489 proc gcc-dg-debug-runtest { target_compile trivial opt_opts testcases } {
490 global srcdir subdir
491
492 if ![info exists DEBUG_TORTURE_OPTIONS] {
493 set DEBUG_TORTURE_OPTIONS ""
494 foreach type {-gdwarf-2 -gstabs -gstabs+ -gxcoff -gxcoff+ -gcoff} {
495 set comp_output [$target_compile \
496 "$srcdir/$subdir/$trivial" "trivial.S" assembly \
497 "additional_flags=$type"]
498 if { ! [string match "*: target system does not support the * debug format*" \
499 $comp_output] } {
500 remove-build-file "trivial.S"
501 foreach level {1 "" 3} {
502 if { ($type == "-gdwarf-2") && ($level != "") } {
503 lappend DEBUG_TORTURE_OPTIONS [list "${type}" "-g${level}"]
504 foreach opt $opt_opts {
505 lappend DEBUG_TORTURE_OPTIONS \
506 [list "${type}" "-g${level}" "$opt" ]
507 }
508 } else {
509 lappend DEBUG_TORTURE_OPTIONS [list "${type}${level}"]
510 foreach opt $opt_opts {
511 lappend DEBUG_TORTURE_OPTIONS \
512 [list "${type}${level}" "$opt" ]
513 }
514 }
515 }
516 }
517 }
518 }
519
520 verbose -log "Using options $DEBUG_TORTURE_OPTIONS"
521
522 global runtests
523
524 foreach test $testcases {
525 # If we're only testing specific files and this isn't one of
526 # them, skip it.
527 if ![runtest_file_p $runtests $test] {
528 continue
529 }
530
531 set nshort [file tail [file dirname $test]]/[file tail $test]
532
533 foreach flags $DEBUG_TORTURE_OPTIONS {
534 set doit 1
535
536 # These tests check for information which may be deliberately
537 # suppressed at -g1.
538 if { ([string match {*/debug-[126].c} "$nshort"] \
539 || [string match {*/enum-1.c} "$nshort"] \
540 || [string match {*/enum-[12].C} "$nshort"]) \
541 && ([string match "*1" [lindex "$flags" 0] ]
542 || [lindex "$flags" 1] == "-g1") } {
543 set doit 0
544 }
545
546 # High optimization can remove the variable whose existence is tested.
547 # Dwarf debugging with commentary (-dA) preserves the symbol name in the
548 # assembler output, but stabs debugging does not.
549 # http://gcc.gnu.org/ml/gcc-regression/2003-04/msg00095.html
550 if { [string match {*/debug-[12].c} "$nshort"] \
551 && [string match "*O*" "$flags"] \
552 && ( [string match "*coff*" "$flags"] \
553 || [string match "*stabs*" "$flags"] ) } {
554 set doit 0
555 }
556
557 if { $doit } {
558 verbose -log "Testing $nshort, $flags" 1
559 dg-test $test $flags ""
560 }
561 }
562 }
563 }
564
565 # Prune any messages matching ARGS[1] (a regexp) from test output.
566 proc dg-prune-output { args } {
567 global additional_prunes
568
569 if { [llength $args] != 2 } {
570 error "[lindex $args 1]: need one argument"
571 return
572 }
573
574 lappend additional_prunes [lindex $args 1]
575 }
576
577 # Remove files matching the pattern from the build machine.
578 proc remove-build-file { pat } {
579 verbose "remove-build-file `$pat'" 2
580 set file_list "[glob -nocomplain $pat]"
581 verbose "remove-build-file `$file_list'" 2
582 foreach output_file $file_list {
583 if [is_remote host] {
584 # Ensure the host knows the file is gone by deleting there
585 # first.
586 remote_file host delete $output_file
587 }
588 remote_file build delete $output_file
589 }
590 }
591
592 # Remove runtime-generated profile file for the current test.
593 proc cleanup-profile-file { } {
594 remove-build-file "mon.out"
595 remove-build-file "gmon.out"
596 }
597
598 # Remove compiler-generated coverage files for the current test.
599 proc cleanup-coverage-files { } {
600 global additional_sources_used
601 set testcase [testname-for-summary]
602 # The name might include a list of options; extract the file name.
603 set testcase [lindex $testcase 0]
604 remove-build-file "[file rootname [file tail $testcase]].gc??"
605
606 # Clean up coverage files for additional source files.
607 if [info exists additional_sources_used] {
608 foreach srcfile $additional_sources_used {
609 remove-build-file "[file rootname [file tail $srcfile]].gc??"
610 }
611 }
612 }
613
614 # Remove compiler-generated files from -repo for the current test.
615 proc cleanup-repo-files { } {
616 global additional_sources_used
617 set testcase [testname-for-summary]
618 # The name might include a list of options; extract the file name.
619 set testcase [lindex $testcase 0]
620 remove-build-file "[file rootname [file tail $testcase]].o"
621 remove-build-file "[file rootname [file tail $testcase]].rpo"
622
623 # Clean up files for additional source files.
624 if [info exists additional_sources_used] {
625 foreach srcfile $additional_sources_used {
626 remove-build-file "[file rootname [file tail $srcfile]].o"
627 remove-build-file "[file rootname [file tail $srcfile]].rpo"
628 }
629 }
630 }
631
632 # Remove a final insns dump file for the current test.
633 proc cleanup-final-insns-dump { } {
634 set testcase [testname-for-summary]
635 # The name might include a list of options; extract the file name.
636 set testcase [lindex $testcase 0]
637 remove-build-file "[file rootname [file tail $testcase]].s.gkd"
638
639 # Clean up files for additional source files.
640 if [info exists additional_sources_used] {
641 foreach srcfile $additional_sources_used {
642 remove-build-file "[file rootname [file tail $srcfile]].s.gkd"
643 }
644 }
645 }
646
647 # Remove a stack usage file for the current test.
648 proc cleanup-stack-usage { } {
649 set testcase [testname-for-summary]
650 # The name might include a list of options; extract the file name.
651 set testcase [lindex $testcase 0]
652 remove-build-file "[file rootname [file tail $testcase]].su"
653
654 # Clean up files for additional source files.
655 if [info exists additional_sources_used] {
656 foreach srcfile $additional_sources_used {
657 remove-build-file "[file rootname [file tail $srcfile]].su"
658 }
659 }
660 }
661
662 # Remove an Ada spec file for the current test.
663 proc cleanup-ada-spec { } {
664 global additional_sources_used
665 set testcase [testname-for-summary]
666 remove-build-file "[get_ada_spec_filename $testcase]"
667
668 # Clean up files for additional source files.
669 if [info exists additional_sources_used] {
670 foreach srcfile $additional_sources_used {
671 remove-build-file "[get_ada_spec_filename $srcfile]"
672 }
673 }
674 }
675
676 # Remove files kept by --save-temps for the current test.
677 #
678 # Currently this is only .i, .ii, .s and .o files, but more can be added
679 # if there are tests generating them.
680 # ARGS is a list of suffixes to NOT delete.
681 proc cleanup-saved-temps { args } {
682 global additional_sources_used
683 set suffixes {}
684
685 # add the to-be-kept suffixes
686 foreach suffix {".mii" ".ii" ".i" ".s" ".o" ".gkd" ".res" ".ltrans.out"} {
687 if {[lsearch $args $suffix] < 0} {
688 lappend suffixes $suffix
689 }
690 }
691
692 set testcase [testname-for-summary]
693 # The name might include a list of options; extract the file name.
694 set testcase [lindex $testcase 0]
695 foreach suffix $suffixes {
696 remove-build-file "[file rootname [file tail $testcase]]$suffix"
697 remove-build-file "[file rootname [file tail $testcase]].exe$suffix"
698 remove-build-file "[file rootname [file tail $testcase]].exe.ltrans\[0-9\]*$suffix"
699 # -fcompare-debug dumps
700 remove-build-file "[file rootname [file tail $testcase]].gk$suffix"
701 }
702
703 # Clean up saved temp files for additional source files.
704 if [info exists additional_sources_used] {
705 foreach srcfile $additional_sources_used {
706 foreach suffix $suffixes {
707 remove-build-file "[file rootname [file tail $srcfile]]$suffix"
708 remove-build-file "[file rootname [file tail $srcfile]].exe$suffix"
709 remove-build-file "[file rootname [file tail $srcfile]].exe.ltrans\[0-9\]*$suffix"
710
711 # -fcompare-debug dumps
712 remove-build-file "[file rootname [file tail $srcfile]].gk$suffix"
713 }
714 }
715 }
716 }
717
718
719 # Files to be kept after cleanup of --save-temps for the current test.
720 # ARGS is a list of suffixes to NOT delete.
721 proc dg-keep-saved-temps { args } {
722 global keep_saved_temps_suffixes
723 set keep_saved_temps_suffixes {}
724
725 # add the to-be-kept suffixes
726 foreach suffix {".mii" ".ii" ".i" ".s" ".o" ".gkd" ".res" ".ltrans.out"} {
727 if {[lsearch $args $suffix] >= 0} {
728 lappend keep_saved_temps_suffixes $suffix
729 }
730 }
731 if { [llength keep_saved_temps_suffixes] < 1 } {
732 error "dg-keep-saved-temps ${args} did not match any known suffix"
733 }
734 }
735
736 # Scan Fortran modules for a given regexp.
737 #
738 # Argument 0 is the module name
739 # Argument 1 is the regexp to match
740 proc scan-module { args } {
741 set modfilename [string tolower [lindex $args 0]].mod
742 set fd [open [list | gzip -dc $modfilename] r]
743 set text [read $fd]
744 close $fd
745
746 set testcase [testname-for-summary]
747 if [regexp -- [lindex $args 1] $text] {
748 pass "$testcase scan-module [lindex $args 1]"
749 } else {
750 fail "$testcase scan-module [lindex $args 1]"
751 }
752 }
753
754 # Scan Fortran modules for absence of a given regexp.
755 #
756 # Argument 0 is the module name
757 # Argument 1 is the regexp to match
758 proc scan-module-absence { args } {
759 set modfilename [string tolower [lindex $args 0]].mod
760 set fd [open [list | gzip -dc $modfilename] r]
761 set text [read $fd]
762 close $fd
763
764 set testcase [testname-for-summary]
765 if [regexp -- [lindex $args 1] $text] {
766 fail "$testcase scan-module [lindex $args 1]"
767 } else {
768 pass "$testcase scan-module [lindex $args 1]"
769 }
770 }
771
772 # Verify that the compiler output file exists, invoked via dg-final.
773 proc output-exists { args } {
774 # Process an optional target or xfail list.
775 if { [llength $args] >= 1 } {
776 switch [dg-process-target [lindex $args 0]] {
777 "S" { }
778 "N" { return }
779 "F" { setup_xfail "*-*-*" }
780 "P" { }
781 }
782 }
783
784 set testcase [testname-for-summary]
785 # Access variable from gcc-dg-test-1.
786 upvar 2 output_file output_file
787
788 if [file exists $output_file] {
789 pass "$testcase output-exists $output_file"
790 } else {
791 fail "$testcase output-exists $output_file"
792 }
793 }
794
795 # Verify that the compiler output file does not exist, invoked via dg-final.
796 proc output-exists-not { args } {
797 # Process an optional target or xfail list.
798 if { [llength $args] >= 1 } {
799 switch [dg-process-target [lindex $args 0]] {
800 "S" { }
801 "N" { return }
802 "F" { setup_xfail "*-*-*" }
803 "P" { }
804 }
805 }
806
807 set testcase [testname-for-summary]
808 # Access variable from gcc-dg-test-1.
809 upvar 2 output_file output_file
810
811 if [file exists $output_file] {
812 fail "$testcase output-exists-not $output_file"
813 } else {
814 pass "$testcase output-exists-not $output_file"
815 }
816 }
817
818 # We need to make sure that additional_* are cleared out after every
819 # test. It is not enough to clear them out *before* the next test run
820 # because gcc-target-compile gets run directly from some .exp files
821 # (outside of any test). (Those uses should eventually be eliminated.)
822
823 # Because the DG framework doesn't provide a hook that is run at the
824 # end of a test, we must replace dg-test with a wrapper.
825
826 if { [info procs saved-dg-test] == [list] } {
827 rename dg-test saved-dg-test
828
829 # Helper function for cleanups that should happen after the call
830 # to the real dg-test, whether or not it returns normally, or
831 # fails with an error.
832 proc cleanup-after-saved-dg-test { } {
833 global additional_files
834 global additional_sources
835 global additional_sources_used
836 global additional_prunes
837 global compiler_conditional_xfail_data
838 global shouldfail
839 global testname_with_flags
840 global set_target_env_var
841 global keep_saved_temps_suffixes
842 global multiline_expected_outputs
843
844 set additional_files ""
845 set additional_sources ""
846 set additional_sources_used ""
847 set additional_prunes ""
848 set shouldfail 0
849 if [info exists set_target_env_var] {
850 unset set_target_env_var
851 }
852 if [info exists keep_saved_temps_suffixes] {
853 unset keep_saved_temps_suffixes
854 }
855 unset_timeout_vars
856 if [info exists compiler_conditional_xfail_data] {
857 unset compiler_conditional_xfail_data
858 }
859 if [info exists testname_with_flags] {
860 unset testname_with_flags
861 }
862 set multiline_expected_outputs []
863 }
864
865 proc dg-test { args } {
866 global errorInfo
867
868 if { [ catch { eval saved-dg-test $args } errmsg ] } {
869 set saved_info $errorInfo
870 cleanup-after-saved-dg-test
871 error $errmsg $saved_info
872 }
873 cleanup-after-saved-dg-test
874 }
875 }
876
877 if { [info procs saved-dg-warning] == [list] \
878 && [info exists gcc_warning_prefix] } {
879 rename dg-warning saved-dg-warning
880
881 proc dg-warning { args } {
882 # Make this variable available here and to the saved proc.
883 upvar dg-messages dg-messages
884 global gcc_warning_prefix
885
886 process-message saved-dg-warning "$gcc_warning_prefix" "$args"
887 }
888 }
889
890 if { [info procs saved-dg-error] == [list] \
891 && [info exists gcc_error_prefix] } {
892 rename dg-error saved-dg-error
893
894 proc dg-error { args } {
895 # Make this variable available here and to the saved proc.
896 upvar dg-messages dg-messages
897 global gcc_error_prefix
898
899 process-message saved-dg-error "$gcc_error_prefix" "$args"
900 }
901
902 # Override dg-bogus at the same time. It doesn't handle a prefix
903 # but its expression should include a column number. Otherwise the
904 # line number can match the column number for other messages, leading
905 # to insanity.
906 rename dg-bogus saved-dg-bogus
907
908 proc dg-bogus { args } {
909 upvar dg-messages dg-messages
910 process-message saved-dg-bogus "" $args
911 }
912 }
913
914 # Modify the regular expression saved by a DejaGnu message directive to
915 # include a prefix and to force the expression to match a single line.
916 # MSGPROC is the procedure to call.
917 # MSGPREFIX is the prefix to prepend.
918 # DGARGS is the original argument list.
919
920 proc process-message { msgproc msgprefix dgargs } {
921 upvar dg-messages dg-messages
922
923 # Process the dg- directive, including adding the regular expression
924 # to the new message entry in dg-messages.
925 set msgcnt [llength ${dg-messages}]
926 eval $msgproc $dgargs
927
928 # If the target expression wasn't satisfied there is no new message.
929 if { [llength ${dg-messages}] == $msgcnt } {
930 return;
931 }
932
933 # Get the entry for the new message. Prepend the message prefix to
934 # the regular expression and make it match a single line.
935 set newentry [lindex ${dg-messages} end]
936 set expmsg [lindex $newentry 2]
937
938 # Handle column numbers from the specified expression (if there is
939 # one) and set up the search expression that will be used by DejaGnu.
940 if [regexp "^(\[0-9\]+):" $expmsg "" column] {
941 # The expression in the directive included a column number.
942 # Remove "COLUMN:" from the original expression and move it
943 # to the proper place in the search expression.
944 regsub "^\[0-9\]+:" $expmsg "" expmsg
945 set expmsg "$column: $msgprefix\[^\n\]*$expmsg"
946 } elseif [string match "" [lindex $newentry 0]] {
947 # The specified line number is 0; don't expect a column number.
948 set expmsg "$msgprefix\[^\n\]*$expmsg"
949 } else {
950 # There is no column number in the search expression, but we
951 # should expect one in the message itself.
952 set expmsg "\[0-9\]+: $msgprefix\[^\n\]*$expmsg"
953 }
954
955 set newentry [lreplace $newentry 2 2 $expmsg]
956 set dg-messages [lreplace ${dg-messages} end end $newentry]
957 verbose "process-message:\n${dg-messages}" 2
958 }
959
960 # Look for messages that don't have standard prefixes.
961
962 proc dg-message { args } {
963 upvar dg-messages dg-messages
964 process-message saved-dg-warning "" $args
965 }
966
967 # Check the existence of a gdb in the path, and return true if there
968 # is one.
969 #
970 # Set env(GDB_FOR_GCC_TESTING) accordingly.
971
972 proc gdb-exists { args } {
973 if ![info exists ::env(GDB_FOR_GCC_TESTING)] {
974 global GDB
975 if ![info exists ::env(GDB_FOR_GCC_TESTING)] {
976 if [info exists GDB] {
977 setenv GDB_FOR_GCC_TESTING "$GDB"
978 } else {
979 setenv GDB_FOR_GCC_TESTING "[transform gdb]"
980 }
981 }
982 }
983 if { [which $::env(GDB_FOR_GCC_TESTING)] != 0 } {
984 return 1;
985 }
986 return 0;
987 }
988
989 set additional_prunes ""
990 set dg_runtest_extra_prunes ""