]> git.ipfire.org Git - thirdparty/gcc.git/blob - gcc/testsuite/lib/gcc-dg.exp
gcc-dg.exp (cleanup-final-insns-dump): New procedure.
[thirdparty/gcc.git] / gcc / testsuite / lib / gcc-dg.exp
1 # Copyright (C) 1997-2015 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
33 # We set LC_ALL and LANG to C so that we get the same error messages as expected.
34 setenv LC_ALL C
35 setenv LANG C
36
37 # Many hosts now default to a non-ASCII C locale, however, so
38 # they can set a charset encoding here if they need.
39 if { [ishost "*-*-cygwin*"] } {
40 setenv LC_ALL C.ASCII
41 setenv LANG C.ASCII
42 }
43
44 global GCC_UNDER_TEST
45 if ![info exists GCC_UNDER_TEST] {
46 set GCC_UNDER_TEST "[find_gcc]"
47 }
48
49 if [info exists TORTURE_OPTIONS] {
50 set DG_TORTURE_OPTIONS $TORTURE_OPTIONS
51 } else {
52 # It is theoretically beneficial to group all of the O2/O3 options together,
53 # as in many cases the compiler will generate identical executables for
54 # all of them--and the c-torture testsuite will skip testing identical
55 # executables multiple times.
56 # Also note that -finline-functions is explicitly included in one of the
57 # items below, even though -O3 is also specified, because some ports may
58 # choose to disable inlining functions by default, even when optimizing.
59 set DG_TORTURE_OPTIONS [list \
60 { -O0 } \
61 { -O1 } \
62 { -O2 } \
63 { -O3 -fomit-frame-pointer } \
64 { -O3 -fomit-frame-pointer -funroll-loops } \
65 { -O3 -fomit-frame-pointer -funroll-all-loops -finline-functions } \
66 { -O3 -g } \
67 { -Os } ]
68 }
69
70 if [info exists ADDITIONAL_TORTURE_OPTIONS] {
71 set DG_TORTURE_OPTIONS \
72 [concat $DG_TORTURE_OPTIONS $ADDITIONAL_TORTURE_OPTIONS]
73 }
74
75 global orig_environment_saved
76
77 # This file may be sourced, so don't override environment settings
78 # that have been previously setup.
79 if { $orig_environment_saved == 0 } {
80 append ld_library_path [gcc-set-multilib-library-path $GCC_UNDER_TEST]
81 set_ld_library_path_env_vars
82 }
83
84 # Some torture-options cause intermediate code output, unusable for
85 # testing using e.g. scan-assembler. In this variable are the options
86 # how to force it, when needed.
87 global gcc_force_conventional_output
88 set gcc_force_conventional_output ""
89
90 set LTO_TORTURE_OPTIONS ""
91 if [check_effective_target_lto] {
92 # When having plugin test both slim and fat LTO and plugin/nonplugin
93 # path.
94 if [check_linker_plugin_available] {
95 set LTO_TORTURE_OPTIONS [list \
96 { -O2 -flto -fno-use-linker-plugin -flto-partition=none } \
97 { -O2 -flto -fuse-linker-plugin -fno-fat-lto-objects }
98 ]
99 set gcc_force_conventional_output "-ffat-lto-objects"
100 } else {
101 set LTO_TORTURE_OPTIONS [list \
102 { -O2 -flto -flto-partition=none } \
103 { -O2 -flto }
104 ]
105 }
106 }
107
108 # Define gcc callbacks for dg.exp.
109
110 proc gcc-dg-test-1 { target_compile prog do_what extra_tool_flags } {
111 # Set up the compiler flags, based on what we're going to do.
112
113 set options [list]
114
115 # Tests should be able to use "dg-do repo". However, the dg test
116 # driver checks the argument to dg-do against a list of acceptable
117 # options, and "repo" is not among them. Therefore, we resort to
118 # this ugly approach.
119 if [string match "*-frepo*" $extra_tool_flags] then {
120 set do_what "repo"
121 }
122
123 switch $do_what {
124 "preprocess" {
125 set compile_type "preprocess"
126 set output_file "[file rootname [file tail $prog]].i"
127 }
128 "compile" {
129 set compile_type "assembly"
130 set output_file "[file rootname [file tail $prog]].s"
131 }
132 "assemble" {
133 set compile_type "object"
134 set output_file "[file rootname [file tail $prog]].o"
135 }
136 "precompile" {
137 set compile_type "precompiled_header"
138 set output_file "[file tail $prog].gch"
139 }
140 "link" {
141 set compile_type "executable"
142 set output_file "[file rootname [file tail $prog]].exe"
143 # The following line is needed for targets like the i960 where
144 # the default output file is b.out. Sigh.
145 }
146 "repo" {
147 set compile_type "object"
148 set output_file "[file rootname [file tail $prog]].o"
149 }
150 "run" {
151 set compile_type "executable"
152 # FIXME: "./" is to cope with "." not being in $PATH.
153 # Should this be handled elsewhere?
154 # YES.
155 set output_file "./[file rootname [file tail $prog]].exe"
156 # This is the only place where we care if an executable was
157 # created or not. If it was, dg.exp will try to run it.
158 catch { remote_file build delete $output_file }
159 }
160 default {
161 perror "$do_what: not a valid dg-do keyword"
162 return ""
163 }
164 }
165
166 # Let { dg-final { action } } force options as returned by an
167 # optional proc ${action}_required_options.
168 upvar 2 dg-final-code finalcode
169 foreach x [split $finalcode "\n"] {
170 set finalcmd [lindex $x 0]
171 if { [info procs ${finalcmd}_required_options] != "" } {
172 set req [${finalcmd}_required_options]
173 if { $req != "" } {
174 lappend extra_tool_flags $req
175 }
176 }
177 }
178
179 if { $extra_tool_flags != "" } {
180 lappend options "additional_flags=$extra_tool_flags"
181 }
182
183 verbose "$target_compile $prog $output_file $compile_type $options" 4
184 set comp_output [$target_compile "$prog" "$output_file" "$compile_type" $options]
185
186 # Look for an internal compiler error, which sometimes masks the fact
187 # that we didn't get an expected error message. XFAIL an ICE via
188 # dg-xfail-if and use { dg-prune-output ".*internal compiler error.*" }
189 # to avoid a second failure for excess errors.
190 if [string match "*internal compiler error*" $comp_output] {
191 upvar 2 name name
192 fail "$name (internal compiler error)"
193 }
194
195 if { $do_what == "repo" } {
196 set object_file "$output_file"
197 set output_file "[file rootname [file tail $prog]].exe"
198 set comp_output \
199 [ concat $comp_output \
200 [$target_compile "$object_file" "$output_file" \
201 "executable" $options] ]
202 }
203
204 return [list $comp_output $output_file]
205 }
206
207 proc gcc-dg-test { prog do_what extra_tool_flags } {
208 return [gcc-dg-test-1 gcc_target_compile $prog $do_what $extra_tool_flags]
209 }
210
211 proc gcc-dg-prune { system text } {
212 global additional_prunes
213
214 # Extra prune rules that will apply to tests defined in a .exp file.
215 # Always remember to clear it in .exp file after executed all tests.
216 global dg_runtest_extra_prunes
217
218 set text [prune_gcc_output $text]
219
220 foreach p "$additional_prunes $dg_runtest_extra_prunes" {
221 if { [string length $p] > 0 } {
222 # Following regexp matches a complete line containing $p.
223 regsub -all "(^|\n)\[^\n\]*$p\[^\n\]*" $text "" text
224 }
225 }
226
227 # If we see "region xxx is full" then the testcase is too big for ram.
228 # This is tricky to deal with in a large testsuite like c-torture so
229 # deal with it here. Just mark the testcase as unsupported.
230 if [regexp "(^|\n)\[^\n\]*: region \[^\n\]* is full" $text] {
231 # The format here is important. See dg.exp.
232 return "::unsupported::memory full"
233 }
234
235 if { [regexp "(^|\n)\[^\n\]*: relocation truncated to fit" $text]
236 && [check_effective_target_tiny] } {
237 return "::unsupported::memory full"
238 }
239
240 # Likewise, if we see ".text exceeds local store range" or
241 # similar.
242 if {[string match "spu-*" $system] && \
243 [string match "*exceeds local store*" $text]} {
244 # The format here is important. See dg.exp.
245 return "::unsupported::memory full"
246 }
247
248 return $text
249 }
250
251 # Replace ${tool}_load with a wrapper to provide for an expected nonzero
252 # exit status. Multiple languages include this file so this handles them
253 # all, not just gcc.
254 if { [info procs ${tool}_load] != [list] \
255 && [info procs saved_${tool}_load] == [list] } {
256 rename ${tool}_load saved_${tool}_load
257
258 proc ${tool}_load { program args } {
259 global tool
260 global shouldfail
261 global set_target_env_var
262
263 set saved_target_env_var [list]
264 if { [info exists set_target_env_var] \
265 && [llength $set_target_env_var] != 0 } {
266 if { [is_remote target] } {
267 return [list "unsupported" ""]
268 }
269 set-target-env-var
270 }
271 set result [eval [list saved_${tool}_load $program] $args]
272 if { [info exists set_target_env_var] \
273 && [llength $set_target_env_var] != 0 } {
274 restore-target-env-var
275 }
276 if { $shouldfail != 0 } {
277 switch [lindex $result 0] {
278 "pass" { set status "fail" }
279 "fail" { set status "pass" }
280 }
281 set result [list $status [lindex $result 1]]
282 }
283
284 set result [list [lindex $result 0] [prune_file_path [lindex $result 1]]]
285 return $result
286 }
287 }
288
289 proc dg-set-target-env-var { args } {
290 global set_target_env_var
291 if { [llength $args] != 3 } {
292 error "dg-set-target-env-var: need two arguments"
293 return
294 }
295 lappend set_target_env_var [list [lindex $args 1] [lindex $args 2]]
296 }
297
298 proc set-target-env-var { } {
299 global set_target_env_var
300 upvar 1 saved_target_env_var saved_target_env_var
301 foreach env_var $set_target_env_var {
302 set var [lindex $env_var 0]
303 set value [lindex $env_var 1]
304 if [info exists ::env($var)] {
305 lappend saved_target_env_var [list $var 1 $::env($var)]
306 } else {
307 lappend saved_target_env_var [list $var 0]
308 }
309 setenv $var $value
310 }
311 }
312
313 proc restore-target-env-var { } {
314 upvar 1 saved_target_env_var saved_target_env_var
315 for { set env_vari [llength $saved_target_env_var] } {
316 [incr env_vari -1] >= 0 } {} {
317 set env_var [lindex $saved_target_env_var $env_vari]
318 set var [lindex $env_var 0]
319 if [lindex $env_var 1] {
320 setenv $var [lindex $env_var 2]
321 } else {
322 unsetenv $var
323 }
324 }
325 }
326
327 # Utility routines.
328
329 #
330 # search_for -- looks for a string match in a file
331 #
332 proc search_for { file pattern } {
333 set fd [open $file r]
334 while { [gets $fd cur_line]>=0 } {
335 if [string match "*$pattern*" $cur_line] then {
336 close $fd
337 return 1
338 }
339 }
340 close $fd
341 return 0
342 }
343
344 # Modified dg-runtest that can cycle through a list of optimization options
345 # as c-torture does.
346 proc gcc-dg-runtest { testcases flags default-extra-flags } {
347 global runtests
348
349 # Some callers set torture options themselves; don't override those.
350 set existing_torture_options [torture-options-exist]
351 if { $existing_torture_options == 0 } {
352 global DG_TORTURE_OPTIONS LTO_TORTURE_OPTIONS
353 torture-init
354 set-torture-options $DG_TORTURE_OPTIONS [list {}] $LTO_TORTURE_OPTIONS
355 }
356 dump-torture-options
357
358 foreach test $testcases {
359 global torture_with_loops torture_without_loops
360 # If we're only testing specific files and this isn't one of
361 # them, skip it.
362 if ![runtest_file_p $runtests $test] {
363 continue
364 }
365
366 # Look for a loop within the source code - if we don't find one,
367 # don't pass -funroll[-all]-loops.
368 if [expr [search_for $test "for*("]+[search_for $test "while*("]] {
369 set option_list $torture_with_loops
370 } else {
371 set option_list $torture_without_loops
372 }
373
374 set nshort [file tail [file dirname $test]]/[file tail $test]
375
376 foreach flags_t $option_list {
377 verbose "Testing $nshort, $flags $flags_t" 1
378 dg-test $test "$flags $flags_t" ${default-extra-flags}
379 }
380 }
381
382 if { $existing_torture_options == 0 } {
383 torture-finish
384 }
385 }
386
387 proc gcc-dg-debug-runtest { target_compile trivial opt_opts testcases } {
388 global srcdir subdir
389
390 if ![info exists DEBUG_TORTURE_OPTIONS] {
391 set DEBUG_TORTURE_OPTIONS ""
392 foreach type {-gdwarf-2 -gstabs -gstabs+ -gxcoff -gxcoff+ -gcoff} {
393 set comp_output [$target_compile \
394 "$srcdir/$subdir/$trivial" "trivial.S" assembly \
395 "additional_flags=$type"]
396 if { ! [string match "*: target system does not support the * debug format*" \
397 $comp_output] } {
398 remove-build-file "trivial.S"
399 foreach level {1 "" 3} {
400 if { ($type == "-gdwarf-2") && ($level != "") } {
401 lappend DEBUG_TORTURE_OPTIONS [list "${type}" "-g${level}"]
402 foreach opt $opt_opts {
403 lappend DEBUG_TORTURE_OPTIONS \
404 [list "${type}" "-g${level}" "$opt" ]
405 }
406 } else {
407 lappend DEBUG_TORTURE_OPTIONS [list "${type}${level}"]
408 foreach opt $opt_opts {
409 lappend DEBUG_TORTURE_OPTIONS \
410 [list "${type}${level}" "$opt" ]
411 }
412 }
413 }
414 }
415 }
416 }
417
418 verbose -log "Using options $DEBUG_TORTURE_OPTIONS"
419
420 global runtests
421
422 foreach test $testcases {
423 # If we're only testing specific files and this isn't one of
424 # them, skip it.
425 if ![runtest_file_p $runtests $test] {
426 continue
427 }
428
429 set nshort [file tail [file dirname $test]]/[file tail $test]
430
431 foreach flags $DEBUG_TORTURE_OPTIONS {
432 set doit 1
433
434 # These tests check for information which may be deliberately
435 # suppressed at -g1.
436 if { ([string match {*/debug-[126].c} "$nshort"] \
437 || [string match {*/enum-1.c} "$nshort"] \
438 || [string match {*/enum-[12].C} "$nshort"]) \
439 && ([string match "*1" [lindex "$flags" 0] ]
440 || [lindex "$flags" 1] == "-g1") } {
441 set doit 0
442 }
443
444 # High optimization can remove the variable whose existence is tested.
445 # Dwarf debugging with commentary (-dA) preserves the symbol name in the
446 # assembler output, but stabs debugging does not.
447 # http://gcc.gnu.org/ml/gcc-regression/2003-04/msg00095.html
448 if { [string match {*/debug-[12].c} "$nshort"] \
449 && [string match "*O*" "$flags"] \
450 && ( [string match "*coff*" "$flags"] \
451 || [string match "*stabs*" "$flags"] ) } {
452 set doit 0
453 }
454
455 if { $doit } {
456 verbose -log "Testing $nshort, $flags" 1
457 dg-test $test $flags ""
458 }
459 }
460 }
461 }
462
463 # Prune any messages matching ARGS[1] (a regexp) from test output.
464 proc dg-prune-output { args } {
465 global additional_prunes
466
467 if { [llength $args] != 2 } {
468 error "[lindex $args 1]: need one argument"
469 return
470 }
471
472 lappend additional_prunes [lindex $args 1]
473 }
474
475 # Remove files matching the pattern from the build machine.
476 proc remove-build-file { pat } {
477 verbose "remove-build-file `$pat'" 2
478 set file_list "[glob -nocomplain $pat]"
479 verbose "remove-build-file `$file_list'" 2
480 foreach output_file $file_list {
481 if [is_remote host] {
482 # Ensure the host knows the file is gone by deleting there
483 # first.
484 remote_file host delete $output_file
485 }
486 remote_file build delete $output_file
487 }
488 }
489
490 # Remove runtime-generated profile file for the current test.
491 proc cleanup-profile-file { } {
492 remove-build-file "mon.out"
493 remove-build-file "gmon.out"
494 }
495
496 # Remove compiler-generated coverage files for the current test.
497 proc cleanup-coverage-files { } {
498 global additional_sources_used
499 set testcase [testname-for-summary]
500 # The name might include a list of options; extract the file name.
501 set testcase [lindex $testcase 0]
502 remove-build-file "[file rootname [file tail $testcase]].gc??"
503
504 # Clean up coverage files for additional source files.
505 if [info exists additional_sources_used] {
506 foreach srcfile $additional_sources_used {
507 remove-build-file "[file rootname [file tail $srcfile]].gc??"
508 }
509 }
510 }
511
512 # Remove compiler-generated files from -repo for the current test.
513 proc cleanup-repo-files { } {
514 global additional_sources_used
515 set testcase [testname-for-summary]
516 # The name might include a list of options; extract the file name.
517 set testcase [lindex $testcase 0]
518 remove-build-file "[file rootname [file tail $testcase]].o"
519 remove-build-file "[file rootname [file tail $testcase]].rpo"
520
521 # Clean up files for additional source files.
522 if [info exists additional_sources_used] {
523 foreach srcfile $additional_sources_used {
524 remove-build-file "[file rootname [file tail $srcfile]].o"
525 remove-build-file "[file rootname [file tail $srcfile]].rpo"
526 }
527 }
528 }
529
530 # Remove compiler-generated RTL dump files for the current test.
531 #
532 # SUFFIX is the filename suffix pattern.
533 proc cleanup-rtl-dump { suffix } {
534 cleanup-dump "\[0-9\]\[0-9\]\[0-9\]r.$suffix"
535 }
536
537 # Remove a specific tree dump file for the current test.
538 #
539 # SUFFIX is the tree dump file suffix pattern.
540 proc cleanup-tree-dump { suffix } {
541 cleanup-dump "\[0-9\]\[0-9\]\[0-9\]t.$suffix"
542 }
543
544 # Remove a specific ipa dump file for the current test.
545 #
546 # SUFFIX is the ipa dump file suffix pattern.
547 proc cleanup-ipa-dump { suffix } {
548 cleanup-dump "\[0-9\]\[0-9\]\[0-9\]i.$suffix"
549 }
550
551 # Remove a final insns dump file for the current test.
552 proc cleanup-final-insns-dump { } {
553 set testcase [testname-for-summary]
554 # The name might include a list of options; extract the file name.
555 set testcase [lindex $testcase 0]
556 remove-build-file "[file rootname [file tail $testcase]].s.gkd"
557
558 # Clean up files for additional source files.
559 if [info exists additional_sources_used] {
560 foreach srcfile $additional_sources_used {
561 remove-build-file "[file rootname [file tail $srcfile]].s.gkd"
562 }
563 }
564 }
565
566 # Remove a stack usage file for the current test.
567 proc cleanup-stack-usage { } {
568 set testcase [testname-for-summary]
569 # The name might include a list of options; extract the file name.
570 set testcase [lindex $testcase 0]
571 remove-build-file "[file rootname [file tail $testcase]].su"
572
573 # Clean up files for additional source files.
574 if [info exists additional_sources_used] {
575 foreach srcfile $additional_sources_used {
576 remove-build-file "[file rootname [file tail $srcfile]].su"
577 }
578 }
579 }
580
581 # Remove an Ada spec file for the current test.
582 proc cleanup-ada-spec { } {
583 global additional_sources_used
584 set testcase [testname-for-summary]
585 remove-build-file "[get_ada_spec_filename $testcase]"
586
587 # Clean up files for additional source files.
588 if [info exists additional_sources_used] {
589 foreach srcfile $additional_sources_used {
590 remove-build-file "[get_ada_spec_filename $srcfile]"
591 }
592 }
593 }
594
595 # Remove all dump files with the provided suffix.
596 proc cleanup-dump { suffix } {
597 global additional_sources_used
598 set testcase [testname-for-summary]
599 # The name might include a list of options; extract the file name.
600 set src [file tail [lindex $testcase 0]]
601 remove-build-file "[file tail $src].$suffix"
602 remove-build-file "[file rootname [file tail $src]].exe.$suffix"
603 remove-build-file "[file rootname [file tail $src]].exe.ltrans\[0-9\]*.$suffix"
604 # -fcompare-debug dumps
605 remove-build-file "[file tail $src].gk.$suffix"
606
607 # Clean up dump files for additional source files.
608 if [info exists additional_sources_used] {
609 foreach srcfile $additional_sources_used {
610 remove-build-file "[file tail $srcfile].$suffix"
611 remove-build-file "[file rootname [file tail $srcfile]].exe.$suffix"
612 remove-build-file "[file rootname [file tail $srcfile]].exe.ltrans\[0-9\]*.$suffix"
613 # -fcompare-debug dumps
614 remove-build-file "[file tail $srcfile].gk.$suffix"
615 }
616 }
617 }
618
619 # Remove files kept by --save-temps for the current test.
620 #
621 # Currently this is only .i, .ii, .s and .o files, but more can be added
622 # if there are tests generating them.
623 # ARGS is a list of suffixes to NOT delete.
624 proc cleanup-saved-temps { args } {
625 global additional_sources_used
626 set suffixes {}
627
628 # add the to-be-kept suffixes
629 foreach suffix {".mii" ".ii" ".i" ".s" ".o" ".gkd" ".res" ".ltrans.out"} {
630 if {[lsearch $args $suffix] < 0} {
631 lappend suffixes $suffix
632 }
633 }
634
635 set testcase [testname-for-summary]
636 # The name might include a list of options; extract the file name.
637 set testcase [lindex $testcase 0]
638 foreach suffix $suffixes {
639 remove-build-file "[file rootname [file tail $testcase]]$suffix"
640 remove-build-file "[file rootname [file tail $testcase]].exe$suffix"
641 remove-build-file "[file rootname [file tail $testcase]].exe.ltrans\[0-9\]*$suffix"
642 # -fcompare-debug dumps
643 remove-build-file "[file rootname [file tail $testcase]].gk$suffix"
644 }
645
646 # Clean up saved temp files for additional source files.
647 if [info exists additional_sources_used] {
648 foreach srcfile $additional_sources_used {
649 foreach suffix $suffixes {
650 remove-build-file "[file rootname [file tail $srcfile]]$suffix"
651 remove-build-file "[file rootname [file tail $srcfile]].exe$suffix"
652 remove-build-file "[file rootname [file tail $srcfile]].exe.ltrans\[0-9\]*$suffix"
653
654 # -fcompare-debug dumps
655 remove-build-file "[file rootname [file tail $srcfile]].gk$suffix"
656 }
657 }
658 }
659 }
660
661 # Scan Fortran modules for a given regexp.
662 #
663 # Argument 0 is the module name
664 # Argument 1 is the regexp to match
665 proc scan-module { args } {
666 set modfilename [string tolower [lindex $args 0]].mod
667 set fd [open [list | gzip -dc $modfilename] r]
668 set text [read $fd]
669 close $fd
670
671 set testcase [testname-for-summary]
672 if [regexp -- [lindex $args 1] $text] {
673 pass "$testcase scan-module [lindex $args 1]"
674 } else {
675 fail "$testcase scan-module [lindex $args 1]"
676 }
677 }
678
679 # Scan Fortran modules for absence of a given regexp.
680 #
681 # Argument 0 is the module name
682 # Argument 1 is the regexp to match
683 proc scan-module-absence { args } {
684 set modfilename [string tolower [lindex $args 0]].mod
685 set fd [open [list | gzip -dc $modfilename] r]
686 set text [read $fd]
687 close $fd
688
689 set testcase [testname-for-summary]
690 if [regexp -- [lindex $args 1] $text] {
691 fail "$testcase scan-module [lindex $args 1]"
692 } else {
693 pass "$testcase scan-module [lindex $args 1]"
694 }
695 }
696
697 # Verify that the compiler output file exists, invoked via dg-final.
698 proc output-exists { args } {
699 # Process an optional target or xfail list.
700 if { [llength $args] >= 1 } {
701 switch [dg-process-target [lindex $args 0]] {
702 "S" { }
703 "N" { return }
704 "F" { setup_xfail "*-*-*" }
705 "P" { }
706 }
707 }
708
709 set testcase [testname-for-summary]
710 # Access variable from gcc-dg-test-1.
711 upvar 2 output_file output_file
712
713 if [file exists $output_file] {
714 pass "$testcase output-exists $output_file"
715 } else {
716 fail "$testcase output-exists $output_file"
717 }
718 }
719
720 # Verify that the compiler output file does not exist, invoked via dg-final.
721 proc output-exists-not { args } {
722 # Process an optional target or xfail list.
723 if { [llength $args] >= 1 } {
724 switch [dg-process-target [lindex $args 0]] {
725 "S" { }
726 "N" { return }
727 "F" { setup_xfail "*-*-*" }
728 "P" { }
729 }
730 }
731
732 set testcase [testname-for-summary]
733 # Access variable from gcc-dg-test-1.
734 upvar 2 output_file output_file
735
736 if [file exists $output_file] {
737 fail "$testcase output-exists-not $output_file"
738 } else {
739 pass "$testcase output-exists-not $output_file"
740 }
741 }
742
743 # We need to make sure that additional_* are cleared out after every
744 # test. It is not enough to clear them out *before* the next test run
745 # because gcc-target-compile gets run directly from some .exp files
746 # (outside of any test). (Those uses should eventually be eliminated.)
747
748 # Because the DG framework doesn't provide a hook that is run at the
749 # end of a test, we must replace dg-test with a wrapper.
750
751 if { [info procs saved-dg-test] == [list] } {
752 rename dg-test saved-dg-test
753
754 proc dg-test { args } {
755 global additional_files
756 global additional_sources
757 global additional_prunes
758 global errorInfo
759 global compiler_conditional_xfail_data
760 global shouldfail
761 global testname_with_flags
762 global set_target_env_var
763
764 if { [ catch { eval saved-dg-test $args } errmsg ] } {
765 set saved_info $errorInfo
766 set additional_files ""
767 set additional_sources ""
768 set additional_sources_used ""
769 set additional_prunes ""
770 set shouldfail 0
771 if [info exists compiler_conditional_xfail_data] {
772 unset compiler_conditional_xfail_data
773 }
774 if [info exists testname_with_flags] {
775 unset testname_with_flags
776 }
777 unset_timeout_vars
778 error $errmsg $saved_info
779 }
780 set additional_files ""
781 set additional_sources ""
782 set additional_sources_used ""
783 set additional_prunes ""
784 set shouldfail 0
785 if [info exists set_target_env_var] {
786 unset set_target_env_var
787 }
788 unset_timeout_vars
789 if [info exists compiler_conditional_xfail_data] {
790 unset compiler_conditional_xfail_data
791 }
792 if [info exists testname_with_flags] {
793 unset testname_with_flags
794 }
795 }
796 }
797
798 if { [info procs saved-dg-warning] == [list] \
799 && [info exists gcc_warning_prefix] } {
800 rename dg-warning saved-dg-warning
801
802 proc dg-warning { args } {
803 # Make this variable available here and to the saved proc.
804 upvar dg-messages dg-messages
805 global gcc_warning_prefix
806
807 process-message saved-dg-warning "$gcc_warning_prefix" "$args"
808 }
809 }
810
811 if { [info procs saved-dg-error] == [list] \
812 && [info exists gcc_error_prefix] } {
813 rename dg-error saved-dg-error
814
815 proc dg-error { args } {
816 # Make this variable available here and to the saved proc.
817 upvar dg-messages dg-messages
818 global gcc_error_prefix
819
820 process-message saved-dg-error "$gcc_error_prefix" "$args"
821 }
822
823 # Override dg-bogus at the same time. It doesn't handle a prefix
824 # but its expression should include a column number. Otherwise the
825 # line number can match the column number for other messages, leading
826 # to insanity.
827 rename dg-bogus saved-dg-bogus
828
829 proc dg-bogus { args } {
830 upvar dg-messages dg-messages
831 process-message saved-dg-bogus "" $args
832 }
833 }
834
835 # Modify the regular expression saved by a DejaGnu message directive to
836 # include a prefix and to force the expression to match a single line.
837 # MSGPROC is the procedure to call.
838 # MSGPREFIX is the prefix to prepend.
839 # DGARGS is the original argument list.
840
841 proc process-message { msgproc msgprefix dgargs } {
842 upvar dg-messages dg-messages
843
844 # Process the dg- directive, including adding the regular expression
845 # to the new message entry in dg-messages.
846 set msgcnt [llength ${dg-messages}]
847 eval $msgproc $dgargs
848
849 # If the target expression wasn't satisfied there is no new message.
850 if { [llength ${dg-messages}] == $msgcnt } {
851 return;
852 }
853
854 # Get the entry for the new message. Prepend the message prefix to
855 # the regular expression and make it match a single line.
856 set newentry [lindex ${dg-messages} end]
857 set expmsg [lindex $newentry 2]
858
859 # Handle column numbers from the specified expression (if there is
860 # one) and set up the search expression that will be used by DejaGnu.
861 if [regexp "^(\[0-9\]+):" $expmsg "" column] {
862 # The expression in the directive included a column number.
863 # Remove "COLUMN:" from the original expression and move it
864 # to the proper place in the search expression.
865 regsub "^\[0-9\]+:" $expmsg "" expmsg
866 set expmsg "$column: $msgprefix\[^\n\]*$expmsg"
867 } elseif [string match "" [lindex $newentry 0]] {
868 # The specified line number is 0; don't expect a column number.
869 set expmsg "$msgprefix\[^\n\]*$expmsg"
870 } else {
871 # There is no column number in the search expression, but we
872 # should expect one in the message itself.
873 set expmsg "\[0-9\]+: $msgprefix\[^\n\]*$expmsg"
874 }
875
876 set newentry [lreplace $newentry 2 2 $expmsg]
877 set dg-messages [lreplace ${dg-messages} end end $newentry]
878 verbose "process-message:\n${dg-messages}" 2
879 }
880
881 # Look for messages that don't have standard prefixes.
882
883 proc dg-message { args } {
884 upvar dg-messages dg-messages
885 process-message saved-dg-warning "" $args
886 }
887
888 # Check the existence of a gdb in the path, and return true if there
889 # is one.
890 #
891 # Set env(GDB_FOR_GCC_TESTING) accordingly.
892
893 proc gdb-exists { args } {
894 if ![info exists ::env(GDB_FOR_GCC_TESTING)] {
895 global GDB
896 if ![info exists ::env(GDB_FOR_GCC_TESTING)] {
897 if [info exists GDB] {
898 setenv GDB_FOR_GCC_TESTING "$GDB"
899 } else {
900 setenv GDB_FOR_GCC_TESTING "[transform gdb]"
901 }
902 }
903 }
904 if { [which $::env(GDB_FOR_GCC_TESTING)] != 0 } {
905 return 1;
906 }
907 return 0;
908 }
909
910 set additional_prunes ""
911 set dg_runtest_extra_prunes ""