1 # Copyright (C) 1997, 1999, 2000, 2003, 2004, 2005, 2006, 2007, 2008, 2009
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/>.
19 load_lib file-format.exp
20 load_lib target-supports.exp
21 load_lib target-supports-dg.exp
27 load_lib timeout-dg.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.
37 if [info exists TORTURE_OPTIONS] {
38 set DG_TORTURE_OPTIONS $TORTURE_OPTIONS
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 \
51 { -O3 -fomit-frame-pointer } \
52 { -O3 -fomit-frame-pointer -funroll-loops } \
53 { -O3 -fomit-frame-pointer -funroll-all-loops -finline-functions } \
58 if [info exists ADDITIONAL_TORTURE_OPTIONS] {
59 set DG_TORTURE_OPTIONS \
60 [concat $DG_TORTURE_OPTIONS $ADDITIONAL_TORTURE_OPTIONS]
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.
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
88 if [string match "*-frepo*" $extra_tool_flags] then {
94 set compile_type "preprocess"
95 set output_file "[file rootname [file tail $prog]].i"
98 set compile_type "assembly"
99 set output_file "[file rootname [file tail $prog]].s"
102 set compile_type "object"
103 set output_file "[file rootname [file tail $prog]].o"
106 set compile_type "precompiled_header"
107 set output_file "[file tail $prog].gch"
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.
116 set compile_type "object"
117 set output_file "[file rootname [file tail $prog]].o"
120 set compile_type "executable"
121 # FIXME: "./" is to cope with "." not being in $PATH.
122 # Should this be handled elsewhere?
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 }
130 perror "$do_what: not a valid dg-do keyword"
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] {
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"
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
188 if {[string match "spu-*" $system] && \
189 [string match "*exceeds local store*" $text]} {
190 # The format here is important. See dg.exp.
191 return "::unsupported::memory full"
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
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 } {
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]]
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 {
236 # Modified dg-runtest that can cycle through a list of optimization options
238 proc gcc-dg-runtest { testcases default-extra-flags } {
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
246 set-torture-options $DG_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
254 if ![runtest_file_p $runtests $test] {
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
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 } {
279 proc gcc-dg-debug-runtest { target_compile trivial opt_opts testcases } {
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*" \
290 remove-build-file "trivial.S"
291 foreach level {1 "" 3} {
292 if { ($type == "-gdwarf-2") && ($level != "") } {
293 lappend DEBUG_TORTURE_OPTIONS [list "${type}" "-g${level}"]
294 foreach opt $opt_opts {
295 lappend DEBUG_TORTURE_OPTIONS \
296 [list "${type}" "-g${level}" "$opt" ]
299 lappend DEBUG_TORTURE_OPTIONS [list "${type}${level}"]
300 foreach opt $opt_opts {
301 lappend DEBUG_TORTURE_OPTIONS \
302 [list "${type}${level}" "$opt" ]
310 verbose -log "Using options $DEBUG_TORTURE_OPTIONS"
314 foreach test $testcases {
315 # If we're only testing specific files and this isn't one of
317 if ![runtest_file_p $runtests $test] {
321 set nshort [file tail [file dirname $test]]/[file tail $test]
323 foreach flags $DEBUG_TORTURE_OPTIONS {
326 # These tests check for information which may be deliberately
328 if { ([string match {*/debug-[126].c} "$nshort"] \
329 || [string match {*/enum-1.c} "$nshort"] \
330 || [string match {*/enum-[12].C} "$nshort"]) \
331 && ([string match "*1" [lindex "$flags" 0] ]
332 || [lindex "$flags" 1] == "-g1") } {
336 # High optimization can remove the variable whose existence is tested.
337 # Dwarf debugging with commentary (-dA) preserves the symbol name in the
338 # assembler output, but stabs debugging does not.
339 # http://gcc.gnu.org/ml/gcc-regression/2003-04/msg00095.html
340 if { [string match {*/debug-[12].c} "$nshort"] \
341 && [string match "*O*" "$flags"] \
342 && ( [string match "*coff*" "$flags"] \
343 || [string match "*stabs*" "$flags"] ) } {
348 verbose -log "Testing $nshort, $flags" 1
349 dg-test $test $flags ""
355 # Prune any messages matching ARGS[1] (a regexp) from test output.
356 proc dg-prune-output { args } {
357 global additional_prunes
359 if { [llength $args] != 2 } {
360 error "[lindex $args 1]: need one argument"
364 lappend additional_prunes [lindex $args 1]
367 # Remove files matching the pattern from the build machine.
368 proc remove-build-file { pat } {
369 verbose "remove-build-file `$pat'" 2
370 set file_list "[glob -nocomplain $pat]"
371 verbose "remove-build-file `$file_list'" 2
372 foreach output_file $file_list {
373 if [is_remote host] {
374 # Ensure the host knows the file is gone by deleting there
376 remote_file host delete $output_file
378 remote_file build delete $output_file
382 # Remove runtime-generated profile file for the current test.
383 proc cleanup-profile-file { } {
384 remove-build-file "mon.out"
385 remove-build-file "gmon.out"
388 # Remove compiler-generated coverage files for the current test.
389 proc cleanup-coverage-files { } {
390 # This assumes that we are two frames down from dg-test or some other proc
391 # that stores the filename of the testcase in a local variable "name".
392 # A cleaner solution would require a new DejaGnu release.
393 upvar 2 name testcase
394 remove-build-file "[file rootname [file tail $testcase]].gc??"
396 # Clean up coverage files for additional source files.
397 if [info exists additional_sources] {
398 foreach srcfile $additional_sources {
399 remove-build-file "[file rootname [file tail $srcfile]].gc??"
404 # Remove compiler-generated files from -repo for the current test.
405 proc cleanup-repo-files { } {
406 # This assumes that we are two frames down from dg-test or some other proc
407 # that stores the filename of the testcase in a local variable "name".
408 # A cleaner solution would require a new DejaGnu release.
409 upvar 2 name testcase
410 remove-build-file "[file rootname [file tail $testcase]].o"
411 remove-build-file "[file rootname [file tail $testcase]].rpo"
413 # Clean up files for additional source files.
414 if [info exists additional_sources] {
415 foreach srcfile $additional_sources {
416 remove-build-file "[file rootname [file tail $srcfile]].o"
417 remove-build-file "[file rootname [file tail $srcfile]].rpo"
422 # Remove compiler-generated RTL dump files for the current test.
424 # SUFFIX is the filename suffix pattern.
425 proc cleanup-rtl-dump { suffix } {
426 cleanup-dump "\[0-9\]\[0-9\]\[0-9\]r.$suffix"
429 # Remove a specific tree dump file for the current test.
431 # SUFFIX is the tree dump file suffix pattern.
432 proc cleanup-tree-dump { suffix } {
433 cleanup-dump "\[0-9\]\[0-9\]\[0-9\]t.$suffix"
436 # Remove a specific ipa dump file for the current test.
438 # SUFFIX is the ipa dump file suffix pattern.
439 proc cleanup-ipa-dump { suffix } {
440 cleanup-dump "\[0-9\]\[0-9\]\[0-9\]i.$suffix"
443 # Remove all dump files with the provided suffix.
444 proc cleanup-dump { suffix } {
445 # This assumes that we are three frames down from dg-test or some other
446 # proc that stores the filename of the testcase in a local variable
447 # "name". A cleaner solution would require a new DejaGnu release.
448 upvar 3 name testcase
449 # The name might include a list of options; extract the file name.
450 set src [file tail [lindex $testcase 0]]
451 remove-build-file "[file tail $src].$suffix"
453 # Clean up dump files for additional source files.
454 if [info exists additional_sources] {
455 foreach srcfile $additional_sources {
456 remove-build-file "[file tail $srcfile].$suffix"
461 # Remove files kept by --save-temps for the current test.
463 # Currently this is only .i, .ii, .s and .o files, but more can be added
464 # if there are tests generating them.
465 # ARGS is a list of suffixes to NOT delete.
466 proc cleanup-saved-temps { args } {
467 global additional_sources
470 # add the to-be-kept suffixes
471 foreach suffix {".ii" ".i" ".s" ".o"} {
472 if {[lsearch $args $suffix] < 0} {
473 lappend suffixes $suffix
477 # This assumes that we are two frames down from dg-test or some other proc
478 # that stores the filename of the testcase in a local variable "name".
479 # A cleaner solution would require a new DejaGnu release.
480 upvar 2 name testcase
481 foreach suffix $suffixes {
482 remove-build-file "[file rootname [file tail $testcase]]$suffix"
485 # Clean up saved temp files for additional source files.
486 if [info exists additional_sources] {
487 foreach srcfile $additional_sources {
488 foreach suffix $suffixes {
489 remove-build-file "[file rootname [file tail $srcfile]]$suffix"
495 # Remove files for specified Fortran modules.
496 proc cleanup-modules { modlist } {
497 foreach modname $modlist {
498 remove-build-file [string tolower $modname].mod
502 # Scan Fortran modules for a given regexp.
504 # Argument 0 is the module name
505 # Argument 1 is the regexp to match
506 proc scan-module { args } {
507 set modfilename [string tolower [lindex $args 0]].mod
508 set fd [open $modfilename r]
512 upvar 2 name testcase
513 if [regexp -- [lindex $args 1] $text] {
514 pass "$testcase scan-module [lindex $args 1]"
516 fail "$testcase scan-module [lindex $args 1]"
520 # Verify that the compiler output file exists, invoked via dg-final.
521 proc output-exists { args } {
522 # Process an optional target or xfail list.
523 if { [llength $args] >= 1 } {
524 switch [dg-process-target [lindex $args 0]] {
527 "F" { setup_xfail "*-*-*" }
532 # Access variables from gcc-dg-test-1.
533 upvar 2 name testcase
534 upvar 2 output_file output_file
536 if [file exists $output_file] {
537 pass "$testcase output-exists $output_file"
539 fail "$testcase output-exists $output_file"
543 # Verify that the compiler output file does not exist, invoked via dg-final.
544 proc output-exists-not { args } {
545 # Process an optional target or xfail list.
546 if { [llength $args] >= 1 } {
547 switch [dg-process-target [lindex $args 0]] {
550 "F" { setup_xfail "*-*-*" }
555 # Access variables from gcc-dg-test-1.
556 upvar 2 name testcase
557 upvar 2 output_file output_file
559 if [file exists $output_file] {
560 fail "$testcase output-exists-not $output_file"
562 pass "$testcase output-exists-not $output_file"
566 # We need to make sure that additional_* are cleared out after every
567 # test. It is not enough to clear them out *before* the next test run
568 # because gcc-target-compile gets run directly from some .exp files
569 # (outside of any test). (Those uses should eventually be eliminated.)
571 # Because the DG framework doesn't provide a hook that is run at the
572 # end of a test, we must replace dg-test with a wrapper.
574 if { [info procs saved-dg-test] == [list] } {
575 rename dg-test saved-dg-test
577 proc dg-test { args } {
578 global additional_files
579 global additional_sources
580 global additional_prunes
582 global compiler_conditional_xfail_data
585 if { [ catch { eval saved-dg-test $args } errmsg ] } {
586 set saved_info $errorInfo
587 set additional_files ""
588 set additional_sources ""
589 set additional_prunes ""
591 if [info exists compiler_conditional_xfail_data] {
592 unset compiler_conditional_xfail_data
595 error $errmsg $saved_info
597 set additional_files ""
598 set additional_sources ""
599 set additional_prunes ""
602 if [info exists compiler_conditional_xfail_data] {
603 unset compiler_conditional_xfail_data
608 if { [info procs saved-dg-warning] == [list] \
609 && [info exists gcc_warning_prefix] } {
610 rename dg-warning saved-dg-warning
612 proc dg-warning { args } {
613 # Make this variable available here and to the saved proc.
614 upvar dg-messages dg-messages
615 global gcc_warning_prefix
617 process-message saved-dg-warning "$gcc_warning_prefix" "$args"
621 if { [info procs saved-dg-error] == [list] \
622 && [info exists gcc_error_prefix] } {
623 rename dg-error saved-dg-error
625 proc dg-error { args } {
626 # Make this variable available here and to the saved proc.
627 upvar dg-messages dg-messages
628 global gcc_error_prefix
630 process-message saved-dg-error "$gcc_error_prefix" "$args"
633 # Override dg-bogus at the same time. It doesn't handle a prefix
634 # but its expression should include a column number. Otherwise the
635 # line number can match the column number for other messages, leading
637 rename dg-bogus saved-dg-bogus
639 proc dg-bogus { args } {
640 upvar dg-messages dg-messages
641 process-message saved-dg-bogus "" $args
645 # Modify the regular expression saved by a DejaGnu message directive to
646 # include a prefix and to force the expression to match a single line.
647 # MSGPROC is the procedure to call.
648 # MSGPREFIX is the prefix to prepend.
649 # DGARGS is the original argument list.
651 proc process-message { msgproc msgprefix dgargs } {
652 upvar dg-messages dg-messages
654 # Process the dg- directive, including adding the regular expression
655 # to the new message entry in dg-messages.
656 set msgcnt [llength ${dg-messages}]
657 catch { eval $msgproc $dgargs }
659 # If the target expression wasn't satisfied there is no new message.
660 if { [llength ${dg-messages}] == $msgcnt } {
664 # Get the entry for the new message. Prepend the message prefix to
665 # the regular expression and make it match a single line.
666 set newentry [lindex ${dg-messages} end]
667 set expmsg [lindex $newentry 2]
669 # Handle column numbers from the specified expression (if there is
670 # one) and set up the search expression that will be used by DejaGnu.
671 if [regexp "^(\[0-9\]+):" $expmsg "" column] {
672 # The expression in the directive included a column number.
673 # Remove "COLUMN:" from the original expression and move it
674 # to the proper place in the search expression.
675 regsub "^\[0-9\]+:" $expmsg "" expmsg
676 set expmsg "$column: $msgprefix\[^\n\]*$expmsg"
677 } elseif [string match "" [lindex $newentry 0]] {
678 # The specified line number is 0; don't expect a column number.
679 set expmsg "$msgprefix\[^\n\]*$expmsg"
681 # There is no column number in the search expression, but we
682 # should expect one in the message itself.
683 set expmsg "\[0-9\]+: $msgprefix\[^\n\]*$expmsg"
686 set newentry [lreplace $newentry 2 2 $expmsg]
687 set dg-messages [lreplace ${dg-messages} end end $newentry]
688 verbose "process-message:\n${dg-messages}" 2
691 # Look for messages that don't have standard prefixes.
693 proc dg-message { args } {
694 upvar dg-messages dg-messages
695 process-message saved-dg-warning "" $args
698 set additional_prunes ""