Merged revisions 143552,143554,143557,143560,143562,143564-143567,143570-143573,14357...
[official-gcc.git] / gcc / testsuite / lib / gcc-dg.exp
blob1944e83febc4511a8e23c9a0c5808c718b20be14
1 # Copyright (C) 1997, 1999, 2000, 2003, 2004, 2005, 2006, 2007, 2008
2 # Free Software Foundation, Inc.
4 # This program is free software; you can redistribute it and/or modify
5 # it under the terms of the GNU General Public License as published by
6 # the Free Software Foundation; either version 3 of the License, or
7 # (at your option) any later version.
9 # This program is distributed in the hope that it will be useful,
10 # but WITHOUT ANY WARRANTY; without even the implied warranty of
11 # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
12 # GNU General Public License for more details.
14 # You should have received a copy of the GNU General Public License
15 # along with GCC; see the file COPYING3. If not see
16 # <http://www.gnu.org/licenses/>.
18 load_lib dg.exp
19 load_lib file-format.exp
20 load_lib target-supports.exp
21 load_lib target-supports-dg.exp
22 load_lib scanasm.exp
23 load_lib scanrtl.exp
24 load_lib scantree.exp
25 load_lib scanipa.exp
26 load_lib timeout.exp
27 load_lib timeout-dg.exp
28 load_lib prune.exp
29 load_lib libgloss.exp
30 load_lib target-libpath.exp
31 load_lib torture-options.exp
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
37 if [info exists TORTURE_OPTIONS] {
38 set DG_TORTURE_OPTIONS $TORTURE_OPTIONS
39 } else {
40 # It is theoretically beneficial to group all of the O2/O3 options together,
41 # as in many cases the compiler will generate identical executables for
42 # all of them--and the c-torture testsuite will skip testing identical
43 # executables multiple times.
44 # Also note that -finline-functions is explicitly included in one of the
45 # items below, even though -O3 is also specified, because some ports may
46 # choose to disable inlining functions by default, even when optimizing.
47 set DG_TORTURE_OPTIONS [list \
48 { -O0 } \
49 { -O1 } \
50 { -O2 } \
51 { -O3 -fomit-frame-pointer } \
52 { -O3 -fomit-frame-pointer -funroll-loops } \
53 { -O3 -fomit-frame-pointer -funroll-all-loops -finline-functions } \
54 { -O3 -g } \
55 { -Os } ]
58 if [info exists ADDITIONAL_TORTURE_OPTIONS] {
59 set DG_TORTURE_OPTIONS \
60 [concat $DG_TORTURE_OPTIONS $ADDITIONAL_TORTURE_OPTIONS]
63 global GCC_UNDER_TEST
64 if ![info exists GCC_UNDER_TEST] {
65 set GCC_UNDER_TEST "[find_gcc]"
68 global orig_environment_saved
70 # This file may be sourced, so don't override environment settings
71 # that have been previously setup.
72 if { $orig_environment_saved == 0 } {
73 append ld_library_path [gcc-set-multilib-library-path $GCC_UNDER_TEST]
74 set_ld_library_path_env_vars
77 # Define gcc callbacks for dg.exp.
79 proc gcc-dg-test-1 { target_compile prog do_what extra_tool_flags } {
80 # Set up the compiler flags, based on what we're going to do.
82 set options [list]
84 # Tests should be able to use "dg-do repo". However, the dg test
85 # driver checks the argument to dg-do against a list of acceptable
86 # options, and "repo" is not among them. Therefore, we resort to
87 # this ugly approach.
88 if [string match "*-frepo*" $extra_tool_flags] then {
89 set do_what "repo"
92 switch $do_what {
93 "preprocess" {
94 set compile_type "preprocess"
95 set output_file "[file rootname [file tail $prog]].i"
97 "compile" {
98 set compile_type "assembly"
99 set output_file "[file rootname [file tail $prog]].s"
101 "assemble" {
102 set compile_type "object"
103 set output_file "[file rootname [file tail $prog]].o"
105 "precompile" {
106 set compile_type "precompiled_header"
107 set output_file "[file tail $prog].gch"
109 "link" {
110 set compile_type "executable"
111 set output_file "[file rootname [file tail $prog]].exe"
112 # The following line is needed for targets like the i960 where
113 # the default output file is b.out. Sigh.
115 "repo" {
116 set compile_type "object"
117 set output_file "[file rootname [file tail $prog]].o"
119 "run" {
120 set compile_type "executable"
121 # FIXME: "./" is to cope with "." not being in $PATH.
122 # Should this be handled elsewhere?
123 # YES.
124 set output_file "./[file rootname [file tail $prog]].exe"
125 # This is the only place where we care if an executable was
126 # created or not. If it was, dg.exp will try to run it.
127 catch { remote_file build delete $output_file }
129 default {
130 perror "$do_what: not a valid dg-do keyword"
131 return ""
135 if { $extra_tool_flags != "" } {
136 lappend options "additional_flags=$extra_tool_flags"
139 set comp_output [$target_compile "$prog" "$output_file" "$compile_type" $options]
141 # Look for an internal compiler error, which sometimes masks the fact
142 # that we didn't get an expected error message. XFAIL an ICE via
143 # dg-xfail-if and use { dg-prune-output ".*internal compiler error.*" }
144 # to avoid a second failure for excess errors.
145 if [string match "*internal compiler error*" $comp_output] {
146 upvar 2 name name
147 fail "$name (internal compiler error)"
150 if { $do_what == "repo" } {
151 set object_file "$output_file"
152 set output_file "[file rootname [file tail $prog]].exe"
153 set comp_output \
154 [ concat $comp_output \
155 [$target_compile "$object_file" "$output_file" \
156 "executable" $options] ]
159 return [list $comp_output $output_file]
162 proc gcc-dg-test { prog do_what extra_tool_flags } {
163 return [gcc-dg-test-1 gcc_target_compile $prog $do_what $extra_tool_flags]
166 proc gcc-dg-prune { system text } {
167 global additional_prunes
169 set text [prune_gcc_output $text]
171 foreach p $additional_prunes {
172 if { [string length $p] > 0 } {
173 # Following regexp matches a complete line containing $p.
174 regsub -all "(^|\n)\[^\n\]*$p\[^\n\]*" $text "" text
178 # If we see "region xxx is full" then the testcase is too big for ram.
179 # This is tricky to deal with in a large testsuite like c-torture so
180 # deal with it here. Just mark the testcase as unsupported.
181 if [regexp "(^|\n)\[^\n\]*: region \[^\n\]* is full" $text] {
182 # The format here is important. See dg.exp.
183 return "::unsupported::memory full"
186 # Likewise, if we see ".text exceeds local store range" or
187 # similar.
188 if {[string match "spu-*" $system] && \
189 [string match "*exceeds local store range*" $text]} {
190 # The format here is important. See dg.exp.
191 return "::unsupported::memory full"
194 return $text
197 # Replace ${tool}_load with a wrapper to provide for an expected nonzero
198 # exit status. Multiple languages include this file so this handles them
199 # all, not just gcc.
200 if { [info procs ${tool}_load] != [list] \
201 && [info procs saved_${tool}_load] == [list] } {
202 rename ${tool}_load saved_${tool}_load
204 proc ${tool}_load { program args } {
205 global tool
206 global shouldfail
207 set result [eval [list saved_${tool}_load $program] $args]
208 if { $shouldfail != 0 } {
209 switch [lindex $result 0] {
210 "pass" { set status "fail" }
211 "fail" { set status "pass" }
213 set result [list $status [lindex $result 1]]
215 return $result
219 # Utility routines.
222 # search_for -- looks for a string match in a file
224 proc search_for { file pattern } {
225 set fd [open $file r]
226 while { [gets $fd cur_line]>=0 } {
227 if [string match "*$pattern*" $cur_line] then {
228 close $fd
229 return 1
232 close $fd
233 return 0
236 # Modified dg-runtest that can cycle through a list of optimization options
237 # as c-torture does.
238 proc gcc-dg-runtest { testcases default-extra-flags } {
239 global runtests
241 # Some callers set torture options themselves; don't override those.
242 set existing_torture_options [torture-options-exist]
243 if { $existing_torture_options == 0 } {
244 global DG_TORTURE_OPTIONS
245 torture-init
246 set-torture-options $DG_TORTURE_OPTIONS
248 dump-torture-options
250 foreach test $testcases {
251 global torture_with_loops torture_without_loops
252 # If we're only testing specific files and this isn't one of
253 # them, skip it.
254 if ![runtest_file_p $runtests $test] {
255 continue
258 # Look for a loop within the source code - if we don't find one,
259 # don't pass -funroll[-all]-loops.
260 if [expr [search_for $test "for*("]+[search_for $test "while*("]] {
261 set option_list $torture_with_loops
262 } else {
263 set option_list $torture_without_loops
266 set nshort [file tail [file dirname $test]]/[file tail $test]
268 foreach flags $option_list {
269 verbose "Testing $nshort, $flags" 1
270 dg-test $test $flags ${default-extra-flags}
274 if { $existing_torture_options == 0 } {
275 torture-finish
279 proc gcc-dg-debug-runtest { target_compile trivial opt_opts testcases } {
280 global srcdir subdir
282 if ![info exists DEBUG_TORTURE_OPTIONS] {
283 set DEBUG_TORTURE_OPTIONS ""
284 foreach type {-gdwarf-2 -gstabs -gstabs+ -gxcoff -gxcoff+ -gcoff} {
285 set comp_output [$target_compile \
286 "$srcdir/$subdir/$trivial" "trivial.S" assembly \
287 "additional_flags=$type"]
288 if { ! [string match "*: target system does not support the * debug format*" \
289 $comp_output] } {
290 remove-build-file "trivial.S"
291 foreach level {1 "" 3} {
292 lappend DEBUG_TORTURE_OPTIONS [list "${type}${level}"]
293 foreach opt $opt_opts {
294 lappend DEBUG_TORTURE_OPTIONS \
295 [list "${type}${level}" "$opt" ]
302 verbose -log "Using options $DEBUG_TORTURE_OPTIONS"
304 global runtests
306 foreach test $testcases {
307 # If we're only testing specific files and this isn't one of
308 # them, skip it.
309 if ![runtest_file_p $runtests $test] {
310 continue
313 set nshort [file tail [file dirname $test]]/[file tail $test]
315 foreach flags $DEBUG_TORTURE_OPTIONS {
316 set doit 1
318 # These tests check for information which may be deliberately
319 # suppressed at -g1.
320 if { ([string match {*/debug-[126].c} "$nshort"] \
321 || [string match {*/enum-1.c} "$nshort"] \
322 || [string match {*/enum-[12].C} "$nshort"]) \
323 && [string match "*1" [lindex "$flags" 0] ] } {
324 set doit 0
327 # High optimization can remove the variable whose existence is tested.
328 # Dwarf debugging with commentary (-dA) preserves the symbol name in the
329 # assembler output, but stabs debugging does not.
330 # http://gcc.gnu.org/ml/gcc-regression/2003-04/msg00095.html
331 if { [string match {*/debug-[12].c} "$nshort"] \
332 && [string match "*O*" "$flags"] \
333 && ( [string match "*coff*" "$flags"] \
334 || [string match "*stabs*" "$flags"] ) } {
335 set doit 0
338 if { $doit } {
339 verbose -log "Testing $nshort, $flags" 1
340 dg-test $test $flags ""
346 # Prune any messages matching ARGS[1] (a regexp) from test output.
347 proc dg-prune-output { args } {
348 global additional_prunes
350 if { [llength $args] != 2 } {
351 error "[lindex $args 1]: need one argument"
352 return
355 lappend additional_prunes [lindex $args 1]
358 # Remove files matching the pattern from the build machine.
359 proc remove-build-file { pat } {
360 verbose "remove-build-file `$pat'" 2
361 set file_list "[glob -nocomplain $pat]"
362 verbose "remove-build-file `$file_list'" 2
363 foreach output_file $file_list {
364 if [is_remote host] {
365 # Ensure the host knows the file is gone by deleting there
366 # first.
367 remote_file host delete $output_file
369 remote_file build delete $output_file
373 # Remove runtime-generated profile file for the current test.
374 proc cleanup-profile-file { } {
375 remove-build-file "mon.out"
376 remove-build-file "gmon.out"
379 # Remove compiler-generated coverage files for the current test.
380 proc cleanup-coverage-files { } {
381 # This assumes that we are two frames down from dg-test or some other proc
382 # that stores the filename of the testcase in a local variable "name".
383 # A cleaner solution would require a new DejaGnu release.
384 upvar 2 name testcase
385 remove-build-file "[file rootname [file tail $testcase]].gc??"
387 # Clean up coverage files for additional source files.
388 if [info exists additional_sources] {
389 foreach srcfile $additional_sources {
390 remove-build-file "[file rootname [file tail $srcfile]].gc??"
395 # Remove compiler-generated files from -repo for the current test.
396 proc cleanup-repo-files { } {
397 # This assumes that we are two frames down from dg-test or some other proc
398 # that stores the filename of the testcase in a local variable "name".
399 # A cleaner solution would require a new DejaGnu release.
400 upvar 2 name testcase
401 remove-build-file "[file rootname [file tail $testcase]].o"
402 remove-build-file "[file rootname [file tail $testcase]].rpo"
404 # Clean up files for additional source files.
405 if [info exists additional_sources] {
406 foreach srcfile $additional_sources {
407 remove-build-file "[file rootname [file tail $srcfile]].o"
408 remove-build-file "[file rootname [file tail $srcfile]].rpo"
413 # Remove compiler-generated RTL dump files for the current test.
415 # SUFFIX is the filename suffix pattern.
416 proc cleanup-rtl-dump { suffix } {
417 cleanup-dump "\[0-9\]\[0-9\]\[0-9\]r.$suffix"
420 # Remove a specific tree dump file for the current test.
422 # SUFFIX is the tree dump file suffix pattern.
423 proc cleanup-tree-dump { suffix } {
424 cleanup-dump "\[0-9\]\[0-9\]\[0-9\]t.$suffix"
427 # Remove a specific ipa dump file for the current test.
429 # SUFFIX is the ipa dump file suffix pattern.
430 proc cleanup-ipa-dump { suffix } {
431 cleanup-dump "\[0-9\]\[0-9\]\[0-9\]i.$suffix"
434 # Remove all dump files with the provided suffix.
435 proc cleanup-dump { suffix } {
436 # This assumes that we are three frames down from dg-test or some other
437 # proc that stores the filename of the testcase in a local variable
438 # "name". A cleaner solution would require a new DejaGnu release.
439 upvar 3 name testcase
440 # The name might include a list of options; extract the file name.
441 set src [file tail [lindex $testcase 0]]
442 remove-build-file "[file tail $src].$suffix"
444 # Clean up dump files for additional source files.
445 if [info exists additional_sources] {
446 foreach srcfile $additional_sources {
447 remove-build-file "[file tail $srcfile].$suffix"
452 # Remove files kept by --save-temps for the current test.
454 # Currently this is only .i, .ii and .s files, but more can be added
455 # if there are tests generating them.
456 # ARGS is a list of suffixes to NOT delete.
457 proc cleanup-saved-temps { args } {
458 global additional_sources
459 set suffixes {}
461 # add the to-be-kept suffixes
462 foreach suffix {".ii" ".i" ".s"} {
463 if {[lsearch $args $suffix] < 0} {
464 lappend suffixes $suffix
468 # This assumes that we are two frames down from dg-test or some other proc
469 # that stores the filename of the testcase in a local variable "name".
470 # A cleaner solution would require a new DejaGnu release.
471 upvar 2 name testcase
472 foreach suffix $suffixes {
473 remove-build-file "[file rootname [file tail $testcase]]$suffix"
476 # Clean up saved temp files for additional source files.
477 if [info exists additional_sources] {
478 foreach srcfile $additional_sources {
479 foreach suffix $suffixes {
480 remove-build-file "[file rootname [file tail $srcfile]]$suffix"
486 # Remove files for specified Fortran modules.
487 proc cleanup-modules { modlist } {
488 foreach modname $modlist {
489 remove-build-file [string tolower $modname].mod
493 # Scan Fortran modules for a given regexp.
495 # Argument 0 is the module name
496 # Argument 1 is the regexp to match
497 proc scan-module { args } {
498 set modfilename [string tolower [lindex $args 0]].mod
499 set fd [open $modfilename r]
500 set text [read $fd]
501 close $fd
503 upvar 2 name testcase
504 if [regexp -- [lindex $args 1] $text] {
505 pass "$testcase scan-module [lindex $args 1]"
506 } else {
507 fail "$testcase scan-module [lindex $args 1]"
511 # Verify that the compiler output file exists, invoked via dg-final.
512 proc output-exists { args } {
513 # Process an optional target or xfail list.
514 if { [llength $args] >= 1 } {
515 switch [dg-process-target [lindex $args 0]] {
516 "S" { }
517 "N" { return }
518 "F" { setup_xfail "*-*-*" }
519 "P" { }
523 # Access variables from gcc-dg-test-1.
524 upvar 2 name testcase
525 upvar 2 output_file output_file
527 if [file exists $output_file] {
528 pass "$testcase output-exists $output_file"
529 } else {
530 fail "$testcase output-exists $output_file"
534 # Verify that the compiler output file does not exist, invoked via dg-final.
535 proc output-exists-not { args } {
536 # Process an optional target or xfail list.
537 if { [llength $args] >= 1 } {
538 switch [dg-process-target [lindex $args 0]] {
539 "S" { }
540 "N" { return }
541 "F" { setup_xfail "*-*-*" }
542 "P" { }
546 # Access variables from gcc-dg-test-1.
547 upvar 2 name testcase
548 upvar 2 output_file output_file
550 if [file exists $output_file] {
551 fail "$testcase output-exists-not $output_file"
552 } else {
553 pass "$testcase output-exists-not $output_file"
557 # We need to make sure that additional_* are cleared out after every
558 # test. It is not enough to clear them out *before* the next test run
559 # because gcc-target-compile gets run directly from some .exp files
560 # (outside of any test). (Those uses should eventually be eliminated.)
562 # Because the DG framework doesn't provide a hook that is run at the
563 # end of a test, we must replace dg-test with a wrapper.
565 if { [info procs saved-dg-test] == [list] } {
566 rename dg-test saved-dg-test
568 proc dg-test { args } {
569 global additional_files
570 global additional_sources
571 global additional_prunes
572 global errorInfo
573 global compiler_conditional_xfail_data
574 global shouldfail
576 if { [ catch { eval saved-dg-test $args } errmsg ] } {
577 set saved_info $errorInfo
578 set additional_files ""
579 set additional_sources ""
580 set additional_prunes ""
581 set shouldfail 0
582 if [info exists compiler_conditional_xfail_data] {
583 unset compiler_conditional_xfail_data
585 unset_timeout_vars
586 error $errmsg $saved_info
588 set additional_files ""
589 set additional_sources ""
590 set additional_prunes ""
591 set shouldfail 0
592 unset_timeout_vars
593 if [info exists compiler_conditional_xfail_data] {
594 unset compiler_conditional_xfail_data
599 if { [info procs saved-dg-warning] == [list] \
600 && [info exists gcc_warning_prefix] } {
601 rename dg-warning saved-dg-warning
603 proc dg-warning { args } {
604 # Make this variable available here and to the saved proc.
605 upvar dg-messages dg-messages
606 global gcc_warning_prefix
608 process-message saved-dg-warning "$gcc_warning_prefix" "$args"
612 if { [info procs saved-dg-error] == [list] \
613 && [info exists gcc_error_prefix] } {
614 rename dg-error saved-dg-error
616 proc dg-error { args } {
617 # Make this variable available here and to the saved proc.
618 upvar dg-messages dg-messages
619 global gcc_error_prefix
621 process-message saved-dg-error "$gcc_error_prefix" "$args"
625 # Modify the regular expression saved by a DejaGnu message directive to
626 # include a prefix and to force the expression to match a single line.
627 # MSGPROC is the procedure to call.
628 # MSGPREFIX is the prefix to prepend.
629 # DGARGS is the original argument list.
631 proc process-message { msgproc msgprefix dgargs } {
632 upvar dg-messages dg-messages
634 # Process the dg- directive, including adding the regular expression
635 # to the new message entry in dg-messages.
636 set msgcnt [llength ${dg-messages}]
637 catch { eval $msgproc $dgargs }
639 # If the target expression wasn't satisfied there is no new message.
640 if { [llength ${dg-messages}] == $msgcnt } {
641 return;
644 # Prepend the message prefix to the regular expression and make
645 # it match a single line.
646 set newentry [lindex ${dg-messages} end]
647 set expmsg [lindex $newentry 2]
649 # If we have a column...
650 if [regexp "^(\[0-9\]+):" $expmsg "" column] {
651 # Remove "COLUMN:"
652 regsub "^\[0-9\]+:" $expmsg "" expmsg
654 # Include the column in the search expression.
655 set expmsg "$column: $msgprefix\[^\n]*$expmsg"
656 } else {
657 set expmsg "$msgprefix\[^\n]*$expmsg"
660 set newentry [lreplace $newentry 2 2 $expmsg]
661 set dg-messages [lreplace ${dg-messages} end end $newentry]
662 verbose "process-message:\n${dg-messages}" 2
665 # Look for messages that don't have standard prefixes.
667 proc dg-message { args } {
668 upvar dg-messages dg-messages
669 process-message saved-dg-warning "" $args
672 set additional_prunes ""