1 # Copyright (C) 1997, 1999, 2000, 2003, 2004, 2005, 2006, 2007
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
28 load_lib target-libpath.exp
30 # We set LC_ALL and LANG to C so that we get the same error messages as expected.
34 if ![info exists TORTURE_OPTIONS] {
35 # It is theoretically beneficial to group all of the O2/O3 options together,
36 # as in many cases the compiler will generate identical executables for
37 # all of them--and the c-torture testsuite will skip testing identical
38 # executables multiple times.
39 # Also note that -finline-functions is explicitly included in one of the
40 # items below, even though -O3 is also specified, because some ports may
41 # choose to disable inlining functions by default, even when optimizing.
42 set TORTURE_OPTIONS [list \
46 { -O3 -fomit-frame-pointer } \
47 { -O3 -fomit-frame-pointer -funroll-loops } \
48 { -O3 -fomit-frame-pointer -funroll-all-loops -finline-functions } \
54 if ![info exists GCC_UNDER_TEST] {
55 set GCC_UNDER_TEST "[find_gcc]"
58 global orig_environment_saved
60 # This file may be sourced, so don't override environment settings
61 # that have been previously setup.
62 if { $orig_environment_saved == 0 } {
63 append ld_library_path [gcc-set-multilib-library-path $GCC_UNDER_TEST]
64 set_ld_library_path_env_vars
67 # Split TORTURE_OPTIONS into two choices: one for testcases with loops and
68 # one for testcases without loops.
70 set torture_with_loops $TORTURE_OPTIONS
71 set torture_without_loops ""
72 foreach option $TORTURE_OPTIONS {
73 if ![string match "*loop*" $option] {
74 lappend torture_without_loops $option
78 # Define gcc callbacks for dg.exp.
80 proc gcc-dg-test-1 { target_compile prog do_what extra_tool_flags } {
81 # Set up the compiler flags, based on what we're going to do.
85 # Tests should be able to use "dg-do repo". However, the dg test
86 # driver checks the argument to dg-do against a list of acceptable
87 # options, and "repo" is not among them. Therefore, we resort to
89 if [string match "*-frepo*" $extra_tool_flags] then {
95 set compile_type "preprocess"
96 set output_file "[file rootname [file tail $prog]].i"
99 set compile_type "assembly"
100 set output_file "[file rootname [file tail $prog]].s"
103 set compile_type "object"
104 set output_file "[file rootname [file tail $prog]].o"
107 set compile_type "precompiled_header"
108 set output_file "[file tail $prog].gch"
111 set compile_type "executable"
112 set output_file "[file rootname [file tail $prog]].exe"
113 # The following line is needed for targets like the i960 where
114 # the default output file is b.out. Sigh.
117 set compile_type "object"
118 set output_file "[file rootname [file tail $prog]].o"
121 set compile_type "executable"
122 # FIXME: "./" is to cope with "." not being in $PATH.
123 # Should this be handled elsewhere?
125 set output_file "./[file rootname [file tail $prog]].exe"
126 # This is the only place where we care if an executable was
127 # created or not. If it was, dg.exp will try to run it.
128 catch { remote_file build delete $output_file }
131 perror "$do_what: not a valid dg-do keyword"
136 if { $extra_tool_flags != "" } {
137 lappend options "additional_flags=$extra_tool_flags"
140 set comp_output [$target_compile "$prog" "$output_file" "$compile_type" $options]
142 # Look for an internal compiler error, which sometimes masks the fact
143 # that we didn't get an expected error message. XFAIL an ICE via
144 # dg-xfail-if and use { dg-prune-output ".*internal compiler error.*" }
145 # to avoid a second failure for excess errors.
146 if [string match "*internal compiler error*" $comp_output] {
148 fail "$name (internal compiler error)"
151 if { $do_what == "repo" } {
152 set object_file "$output_file"
153 set output_file "[file rootname [file tail $prog]].exe"
155 [ concat $comp_output \
156 [$target_compile "$object_file" "$output_file" \
157 "executable" $options] ]
160 return [list $comp_output $output_file]
163 proc gcc-dg-test { prog do_what extra_tool_flags } {
164 return [gcc-dg-test-1 gcc_target_compile $prog $do_what $extra_tool_flags]
167 proc gcc-dg-prune { system text } {
168 global additional_prunes
170 set text [prune_gcc_output $text]
172 foreach p $additional_prunes {
173 if { [string length $p] > 0 } {
174 # Following regexp matches a complete line containing $p.
175 regsub -all "(^|\n)\[^\n\]*$p\[^\n\]*" $text "" text
179 # If we see "region xxx is full" then the testcase is too big for ram.
180 # This is tricky to deal with in a large testsuite like c-torture so
181 # deal with it here. Just mark the testcase as unsupported.
182 if [regexp "(^|\n)\[^\n\]*: region \[^\n\]* is full" $text] {
183 # The format here is important. See dg.exp.
184 return "::unsupported::memory full"
187 # Likewise, if we see ".text exceeds local store range" or
189 if {[string match "spu-*" $system] && \
190 [string match "*exceeds local store range*" $text]} {
191 # The format here is important. See dg.exp.
192 return "::unsupported::memory full"
198 # Replace ${tool}_load with a wrapper to provide for an expected nonzero
199 # exit status. Multiple languages include this file so this handles them
201 if { [info procs ${tool}_load] != [list] \
202 && [info procs saved_${tool}_load] == [list] } {
203 rename ${tool}_load saved_${tool}_load
205 proc ${tool}_load { program args } {
208 set result [eval [list saved_${tool}_load $program] $args]
209 if { $shouldfail != 0 } {
210 switch [lindex $result 0] {
211 "pass" { set status "fail" }
212 "fail" { set status "pass" }
214 set result [list $status [lindex $result 1]]
223 # search_for -- looks for a string match in a file
225 proc search_for { file pattern } {
226 set fd [open $file r]
227 while { [gets $fd cur_line]>=0 } {
228 if [string match "*$pattern*" $cur_line] then {
237 # Modified dg-runtest that can cycle through a list of optimization options
239 proc gcc-dg-runtest { testcases default-extra-flags } {
242 foreach test $testcases {
243 # If we're only testing specific files and this isn't one of
245 if ![runtest_file_p $runtests $test] {
249 # Look for a loop within the source code - if we don't find one,
250 # don't pass -funroll[-all]-loops.
251 global torture_with_loops torture_without_loops
252 if [expr [search_for $test "for*("]+[search_for $test "while*("]] {
253 set option_list $torture_with_loops
255 set option_list $torture_without_loops
258 set nshort [file tail [file dirname $test]]/[file tail $test]
260 foreach flags $option_list {
261 verbose "Testing $nshort, $flags" 1
262 dg-test $test $flags ${default-extra-flags}
267 proc gcc-dg-debug-runtest { target_compile trivial opt_opts testcases } {
270 if ![info exists DEBUG_TORTURE_OPTIONS] {
271 set DEBUG_TORTURE_OPTIONS ""
272 foreach type {-gdwarf-2 -gstabs -gstabs+ -gxcoff -gxcoff+ -gcoff} {
273 set comp_output [$target_compile \
274 "$srcdir/$subdir/$trivial" "trivial.S" assembly \
275 "additional_flags=$type"]
276 if { ! [string match "*: target system does not support the * debug format*" \
278 remove-build-file "trivial.S"
279 foreach level {1 "" 3} {
280 lappend DEBUG_TORTURE_OPTIONS [list "${type}${level}"]
281 foreach opt $opt_opts {
282 lappend DEBUG_TORTURE_OPTIONS \
283 [list "${type}${level}" "$opt" ]
290 verbose -log "Using options $DEBUG_TORTURE_OPTIONS"
294 foreach test $testcases {
295 # If we're only testing specific files and this isn't one of
297 if ![runtest_file_p $runtests $test] {
301 set nshort [file tail [file dirname $test]]/[file tail $test]
303 foreach flags $DEBUG_TORTURE_OPTIONS {
306 # These tests check for information which may be deliberately
308 if { ([string match {*/debug-[126].c} "$nshort"] \
309 || [string match {*/enum-1.c} "$nshort"] \
310 || [string match {*/enum-[12].C} "$nshort"]) \
311 && [string match "*1" [lindex "$flags" 0] ] } {
315 # High optimization can remove the variable whose existence is tested.
316 # Dwarf debugging with commentary (-dA) preserves the symbol name in the
317 # assembler output, but stabs debugging does not.
318 # http://gcc.gnu.org/ml/gcc-regression/2003-04/msg00095.html
319 if { [string match {*/debug-[12].c} "$nshort"] \
320 && [string match "*O*" "$flags"] \
321 && ( [string match "*coff*" "$flags"] \
322 || [string match "*stabs*" "$flags"] ) } {
327 verbose -log "Testing $nshort, $flags" 1
328 dg-test $test $flags ""
334 # Prune any messages matching ARGS[1] (a regexp) from test output.
335 proc dg-prune-output { args } {
336 global additional_prunes
338 if { [llength $args] != 2 } {
339 error "[lindex $args 1]: need one argument"
343 lappend additional_prunes [lindex $args 1]
346 # Remove files matching the pattern from the build machine.
347 proc remove-build-file { pat } {
348 verbose "remove-build-file `$pat'" 2
349 set file_list "[glob -nocomplain $pat]"
350 verbose "remove-build-file `$file_list'" 2
351 foreach output_file $file_list {
352 remote_file build delete $output_file
356 # Remove runtime-generated profile file for the current test.
357 proc cleanup-profile-file { } {
358 remove-build-file "mon.out"
359 remove-build-file "gmon.out"
362 # Remove compiler-generated coverage files for the current test.
363 proc cleanup-coverage-files { } {
364 # This assumes that we are two frames down from dg-test or some other proc
365 # that stores the filename of the testcase in a local variable "name".
366 # A cleaner solution would require a new DejaGnu release.
367 upvar 2 name testcase
368 remove-build-file "[file rootname [file tail $testcase]].gc??"
370 # Clean up coverage files for additional source files.
371 if [info exists additional_sources] {
372 foreach srcfile $additional_sources {
373 remove-build-file "[file rootname [file tail $srcfile]].gc??"
378 # Remove compiler-generated files from -repo for the current test.
379 proc cleanup-repo-files { } {
380 # This assumes that we are two frames down from dg-test or some other proc
381 # that stores the filename of the testcase in a local variable "name".
382 # A cleaner solution would require a new DejaGnu release.
383 upvar 2 name testcase
384 remove-build-file "[file rootname [file tail $testcase]].o"
385 remove-build-file "[file rootname [file tail $testcase]].rpo"
387 # Clean up 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]].o"
391 remove-build-file "[file rootname [file tail $srcfile]].rpo"
396 # Remove compiler-generated RTL dump files for the current test.
398 # SUFFIX is the filename suffix pattern.
399 proc cleanup-rtl-dump { suffix } {
400 cleanup-dump "\[0-9\]\[0-9\]\[0-9\]r.$suffix"
403 # Remove a specific tree dump file for the current test.
405 # SUFFIX is the tree dump file suffix pattern.
406 proc cleanup-tree-dump { suffix } {
407 cleanup-dump "\[0-9\]\[0-9\]\[0-9\]t.$suffix"
410 # Remove a specific ipa dump file for the current test.
412 # SUFFIX is the ipa dump file suffix pattern.
413 proc cleanup-ipa-dump { suffix } {
414 cleanup-dump "\[0-9\]\[0-9\]\[0-9\]i.$suffix"
417 # Remove all dump files with the provided suffix.
418 proc cleanup-dump { suffix } {
419 # This assumes that we are three frames down from dg-test or some other
420 # proc that stores the filename of the testcase in a local variable
421 # "name". A cleaner solution would require a new DejaGnu release.
422 upvar 3 name testcase
423 # The name might include a list of options; extract the file name.
424 set src [file tail [lindex $testcase 0]]
425 remove-build-file "[file tail $src].$suffix"
427 # Clean up dump files for additional source files.
428 if [info exists additional_sources] {
429 foreach srcfile $additional_sources {
430 remove-build-file "[file tail $srcfile].$suffix"
435 # Remove files kept by --save-temps for the current test.
437 # Currently this is only .i, .ii and .s files, but more can be added
438 # if there are tests generating them.
439 proc cleanup-saved-temps { } {
440 global additional_sources
442 # This assumes that we are two frames down from dg-test or some other proc
443 # that stores the filename of the testcase in a local variable "name".
444 # A cleaner solution would require a new DejaGnu release.
445 upvar 2 name testcase
446 remove-build-file "[file rootname [file tail $testcase]].ii"
447 remove-build-file "[file rootname [file tail $testcase]].i"
449 # Clean up saved temp files for additional source files.
450 if [info exists additional_sources] {
451 foreach srcfile $additional_sources {
452 remove-build-file "[file rootname [file tail $srcfile]].ii"
453 remove-build-file "[file rootname [file tail $srcfile]].i"
458 # Remove files for specified Fortran modules.
459 proc cleanup-modules { modlist } {
460 foreach modname $modlist {
461 remove-build-file [string tolower $modname].mod
465 # Scan Fortran modules for a given regexp.
467 # Argument 0 is the module name
468 # Argument 1 is the regexp to match
469 proc scan-module { args } {
470 set modfilename [string tolower [lindex $args 0]].mod
471 set fd [open $modfilename r]
475 upvar 2 name testcase
476 if [regexp -- [lindex $args 1] $text] {
477 pass "$testcase scan-module [lindex $args 1]"
479 fail "$testcase scan-module [lindex $args 1]"
483 # Verify that the compiler output file exists, invoked via dg-final.
484 proc output-exists { args } {
485 # Process an optional target or xfail list.
486 if { [llength $args] >= 1 } {
487 switch [dg-process-target [lindex $args 0]] {
490 "F" { setup_xfail "*-*-*" }
495 # Access variables from gcc-dg-test-1.
496 upvar 2 name testcase
497 upvar 2 output_file output_file
499 if [file exists $output_file] {
500 pass "$testcase output-exists $output_file"
502 fail "$testcase output-exists $output_file"
506 # Verify that the compiler output file does not exist, invoked via dg-final.
507 proc output-exists-not { args } {
508 # Process an optional target or xfail list.
509 if { [llength $args] >= 1 } {
510 switch [dg-process-target [lindex $args 0]] {
513 "F" { setup_xfail "*-*-*" }
518 # Access variables from gcc-dg-test-1.
519 upvar 2 name testcase
520 upvar 2 output_file output_file
522 if [file exists $output_file] {
523 fail "$testcase output-exists-not $output_file"
525 pass "$testcase output-exists-not $output_file"
529 # We need to make sure that additional_* are cleared out after every
530 # test. It is not enough to clear them out *before* the next test run
531 # because gcc-target-compile gets run directly from some .exp files
532 # (outside of any test). (Those uses should eventually be eliminated.)
534 # Because the DG framework doesn't provide a hook that is run at the
535 # end of a test, we must replace dg-test with a wrapper.
537 if { [info procs saved-dg-test] == [list] } {
538 rename dg-test saved-dg-test
540 proc dg-test { args } {
541 global additional_files
542 global additional_sources
543 global additional_prunes
545 global compiler_conditional_xfail_data
548 if { [ catch { eval saved-dg-test $args } errmsg ] } {
549 set saved_info $errorInfo
550 set additional_files ""
551 set additional_sources ""
552 set additional_prunes ""
554 if [info exists compiler_conditional_xfail_data] {
555 unset compiler_conditional_xfail_data
557 error $errmsg $saved_info
559 set additional_files ""
560 set additional_sources ""
561 set additional_prunes ""
563 if [info exists compiler_conditional_xfail_data] {
564 unset compiler_conditional_xfail_data
569 if { [info procs saved-dg-warning] == [list] \
570 && [info exists gcc_warning_prefix] } {
571 rename dg-warning saved-dg-warning
573 proc dg-warning { args } {
574 # Make this variable available here and to the saved proc.
575 upvar dg-messages dg-messages
576 global gcc_warning_prefix
578 process-message saved-dg-warning "$gcc_warning_prefix" "$args"
582 if { [info procs saved-dg-error] == [list] \
583 && [info exists gcc_error_prefix] } {
584 rename dg-error saved-dg-error
586 proc dg-error { args } {
587 # Make this variable available here and to the saved proc.
588 upvar dg-messages dg-messages
589 global gcc_error_prefix
591 process-message saved-dg-error "$gcc_error_prefix" "$args"
595 # Modify the regular expression saved by a DejaGnu message directive to
596 # include a prefix and to force the expression to match a single line.
597 # MSGPROC is the procedure to call.
598 # MSGPREFIX is the prefix to prepend.
599 # DGARGS is the original argument list.
601 proc process-message { msgproc msgprefix dgargs } {
602 upvar dg-messages dg-messages
604 # Process the dg- directive, including adding the regular expression
605 # to the new message entry in dg-messages.
606 set msgcnt [llength ${dg-messages}]
607 catch { eval $msgproc $dgargs }
609 # If the target expression wasn't satisfied there is no new message.
610 if { [llength ${dg-messages}] == $msgcnt } {
614 # Prepend the message prefix to the regular expression and make
615 # it match a single line.
616 set newentry [lindex ${dg-messages} end]
617 set expmsg [lindex $newentry 2]
618 set expmsg "$msgprefix\[^\n]*$expmsg"
619 set newentry [lreplace $newentry 2 2 $expmsg]
620 set dg-messages [lreplace ${dg-messages} end end $newentry]
621 verbose "process-message:\n${dg-messages}" 2
624 # Look for messages that don't have standard prefixes.
626 proc dg-message { args } {
627 upvar dg-messages dg-messages
628 process-message saved-dg-warning "" $args
631 set additional_prunes ""