1 # Copyright (C) 1997, 1999, 2000, 2003, 2004, 2005 Free Software Foundation, Inc.
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 2 of the License, or
6 # (at your option) any later version.
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.
13 # You should have received a copy of the GNU General Public License
14 # along with this program; if not, write to the Free Software
15 # Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
18 load_lib file-format.exp
19 load_lib target-supports.exp
20 load_lib target-supports-dg.exp
25 load_lib target-libpath.exp
27 # We set LC_ALL and LANG to C so that we get the same error messages as expected.
31 if ![info exists TORTURE_OPTIONS] {
32 # It is theoretically beneficial to group all of the O2/O3 options together,
33 # as in many cases the compiler will generate identical executables for
34 # all of them--and the c-torture testsuite will skip testing identical
35 # executables multiple times.
36 # Also note that -finline-functions is explicitly included in one of the
37 # items below, even though -O3 is also specified, because some ports may
38 # choose to disable inlining functions by default, even when optimizing.
39 set TORTURE_OPTIONS [list \
43 { -O3 -fomit-frame-pointer } \
44 { -O3 -fomit-frame-pointer -funroll-loops } \
45 { -O3 -fomit-frame-pointer -funroll-all-loops -finline-functions } \
51 if ![info exists GCC_UNDER_TEST] {
52 set GCC_UNDER_TEST "[find_gcc]"
55 global orig_environment_saved
57 # This file may be sourced, so don't override environment settings
58 # that have been previously setup.
59 if { $orig_environment_saved == 0 } {
60 append ld_library_path [gcc-set-multilib-library-path $GCC_UNDER_TEST]
61 set_ld_library_path_env_vars
64 # Split TORTURE_OPTIONS into two choices: one for testcases with loops and
65 # one for testcases without loops.
67 set torture_with_loops $TORTURE_OPTIONS
68 set torture_without_loops ""
69 foreach option $TORTURE_OPTIONS {
70 if ![string match "*loop*" $option] {
71 lappend torture_without_loops $option
75 # Define gcc callbacks for dg.exp.
77 proc gcc-dg-test-1 { target_compile prog do_what extra_tool_flags } {
78 # Set up the compiler flags, based on what we're going to do.
82 # Tests should be able to use "dg-do repo". However, the dg test
83 # driver checks the argument to dg-do against a list of acceptable
84 # options, and "repo" is not among them. Therefore, we resort to
86 if [string match "*-frepo*" $extra_tool_flags] then {
92 set compile_type "preprocess"
93 set output_file "[file rootname [file tail $prog]].i"
96 set compile_type "assembly"
97 set output_file "[file rootname [file tail $prog]].s"
100 set compile_type "object"
101 set output_file "[file rootname [file tail $prog]].o"
104 set compile_type "precompiled_header"
105 set output_file "[file tail $prog].gch"
108 set compile_type "executable"
109 set output_file "[file rootname [file tail $prog]].exe"
110 # The following line is needed for targets like the i960 where
111 # the default output file is b.out. Sigh.
114 set compile_type "object"
115 set output_file "[file rootname [file tail $prog]].o"
118 set compile_type "executable"
119 # FIXME: "./" is to cope with "." not being in $PATH.
120 # Should this be handled elsewhere?
122 set output_file "./[file rootname [file tail $prog]].exe"
123 # This is the only place where we care if an executable was
124 # created or not. If it was, dg.exp will try to run it.
125 catch { remote_file build delete $output_file }
128 perror "$do_what: not a valid dg-do keyword"
133 if { $extra_tool_flags != "" } {
134 lappend options "additional_flags=$extra_tool_flags"
137 set comp_output [$target_compile "$prog" "$output_file" "$compile_type" $options]
139 if { $do_what == "repo" } {
140 set object_file "$output_file"
141 set output_file "[file rootname [file tail $prog]].exe"
143 [ concat $comp_output \
144 [$target_compile "$object_file" "$output_file" \
145 "executable" $options] ]
148 return [list $comp_output $output_file]
151 proc gcc-dg-test { prog do_what extra_tool_flags } {
152 return [gcc-dg-test-1 gcc_target_compile $prog $do_what $extra_tool_flags]
155 proc gcc-dg-prune { system text } {
156 global additional_prunes
158 set text [prune_gcc_output $text]
160 foreach p $additional_prunes {
161 if { [string length $p] > 0 } {
162 # Following regexp matches a complete line containing $p.
163 regsub -all "(^|\n)\[^\n\]*$p\[^\n\]*" $text "" text
167 # If we see "region xxx is full" then the testcase is too big for ram.
168 # This is tricky to deal with in a large testsuite like c-torture so
169 # deal with it here. Just mark the testcase as unsupported.
170 if [regexp "(^|\n)\[^\n\]*: region \[^\n\]* is full" $text] {
171 # The format here is important. See dg.exp.
172 return "::unsupported::memory full"
181 # search_for -- looks for a string match in a file
183 proc search_for { file pattern } {
184 set fd [open $file r]
185 while { [gets $fd cur_line]>=0 } {
186 if [string match "*$pattern*" $cur_line] then {
195 # Modified dg-runtest that can cycle through a list of optimization options
197 proc gcc-dg-runtest { testcases default-extra-flags } {
200 foreach test $testcases {
201 # If we're only testing specific files and this isn't one of
203 if ![runtest_file_p $runtests $test] {
207 # Look for a loop within the source code - if we don't find one,
208 # don't pass -funroll[-all]-loops.
209 global torture_with_loops torture_without_loops
210 if [expr [search_for $test "for*("]+[search_for $test "while*("]] {
211 set option_list $torture_with_loops
213 set option_list $torture_without_loops
216 set nshort [file tail [file dirname $test]]/[file tail $test]
218 foreach flags $option_list {
219 verbose "Testing $nshort, $flags" 1
220 dg-test $test $flags ${default-extra-flags}
225 proc gcc-dg-debug-runtest { target_compile trivial opt_opts testcases } {
228 if ![info exists DEBUG_TORTURE_OPTIONS] {
229 set DEBUG_TORTURE_OPTIONS ""
230 foreach type {-gdwarf-2 -gstabs -gstabs+ -gxcoff -gxcoff+ -gcoff} {
231 set comp_output [$target_compile \
232 "$srcdir/$subdir/$trivial" "trivial.S" assembly \
233 "additional_flags=$type"]
234 if { ! [string match "*: target system does not support the * debug format*" \
236 foreach level {1 "" 3} {
237 lappend DEBUG_TORTURE_OPTIONS [list "${type}${level}"]
238 foreach opt $opt_opts {
239 lappend DEBUG_TORTURE_OPTIONS \
240 [list "${type}${level}" "$opt" ]
247 verbose -log "Using options $DEBUG_TORTURE_OPTIONS"
251 foreach test $testcases {
252 # If we're only testing specific files and this isn't one of
254 if ![runtest_file_p $runtests $test] {
258 set nshort [file tail [file dirname $test]]/[file tail $test]
260 foreach flags $DEBUG_TORTURE_OPTIONS {
262 if { [string match {*/debug-[126].c} "$nshort"] \
263 && [string match "*1" [lindex "$flags" 0] ] } {
267 # High optimization can remove the variable whose existence is tested.
268 # Dwarf debugging with commentary (-dA) preserves the symbol name in the
269 # assembler output, but stabs debugging does not.
270 # http://gcc.gnu.org/ml/gcc-regression/2003-04/msg00095.html
271 if { [string match {*/debug-[12].c} "$nshort"] \
272 && [string match "*O*" "$flags"] \
273 && ( [string match "*coff*" "$flags"] \
274 || [string match "*stabs*" "$flags"] ) } {
279 verbose -log "Testing $nshort, $flags" 1
280 dg-test $test $flags ""
286 # Prune any messages matching ARGS[1] (a regexp) from test output.
287 proc dg-prune-output { args } {
288 global additional_prunes
290 if { [llength $args] != 2 } {
291 error "[lindex $args 1]: need one argument"
295 lappend additional_prunes [lindex $args 1]
298 # Remove files matching the pattern from the build machine.
299 proc remove-build-file { pat } {
300 verbose "remove-build-file `$pat'" 2
301 set file_list "[glob -nocomplain $pat]"
302 verbose "remove-build-file `$file_list'" 2
303 foreach output_file $file_list {
304 remote_file build delete $output_file
308 # Remove compiler-generated coverage files for the current test.
309 proc cleanup-coverage-files { } {
310 # This assumes that we are two frames down from dg-test or some other proc
311 # that stores the filename of the testcase in a local variable "name".
312 # A cleaner solution would require a new DejaGnu release.
313 upvar 2 name testcase
314 remove-build-file "[file rootname [file tail $testcase]].gc??"
316 # Clean up coverage files for additional source files.
317 if [info exists additional_sources] {
318 foreach srcfile $additional_sources {
319 remove-build-file "[file rootname [file tail $srcfile]].gc??"
324 # Remove compiler-generated files from -repo for the current test.
325 proc cleanup-repo-files { } {
326 # This assumes that we are two frames down from dg-test or some other proc
327 # that stores the filename of the testcase in a local variable "name".
328 # A cleaner solution would require a new DejaGnu release.
329 upvar 2 name testcase
330 remove-build-file "[file rootname [file tail $testcase]].o"
331 remove-build-file "[file rootname [file tail $testcase]].rpo"
333 # Clean up files for additional source files.
334 if [info exists additional_sources] {
335 foreach srcfile $additional_sources {
336 remove-build-file "[file rootname [file tail $srcfile]].o"
337 remove-build-file "[file rootname [file tail $srcfile]].rpo"
342 # Remove compiler-generated RTL dump files for the current test.
344 # SUFFIX is the filename suffix pattern.
345 proc cleanup-rtl-dump { suffix } {
346 # This assumes that we are two frames down from dg-test or some other proc
347 # that stores the filename of the testcase in a local variable "name".
348 # A cleaner solution would require a new DejaGnu release.
349 upvar 2 name testcase
350 remove-build-file "[file tail $testcase].??.$suffix"
352 # Clean up dump files for additional source files.
353 if [info exists additional_sources] {
354 foreach srcfile $additional_sources {
355 remove-build-file "[file tail $srcfile].??.$suffix"
360 # Remove a specific tree dump file for the current test.
362 # SUFFIX is the file suffix pattern.
363 proc cleanup-tree-dump { suffix } {
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 tail $testcase].t??.$suffix"
370 # Clean up dump files for additional source files.
371 if [info exists additional_sources] {
372 foreach srcfile $additional_sources {
373 remove-build-file "[file tail $srcfile].t??.$suffix"
378 # Remove a specific ipa dump file for the current test.
380 # SUFFIX is the file suffix pattern.
381 proc cleanup-ipa-dump { suffix } {
382 # This assumes that we are two frames down from dg-test or some other proc
383 # that stores the filename of the testcase in a local variable "name".
384 # A cleaner solution would require a new DejaGnu release.
385 upvar 2 name testcase
386 remove-build-file "[file tail $testcase].i??.$suffix"
388 # Clean up dump files for additional source files.
389 if [info exists additional_sources] {
390 foreach srcfile $additional_sources {
391 remove-build-file "[file tail $srcfile].i??.$suffix"
396 # Remove files kept by --save-temps for the current test.
398 # Currently this is only .i files, but more can be added if there are
399 # tests generating them.
400 proc cleanup-saved-temps { } {
401 global additional_sources
403 # This assumes that we are two frames down from dg-test or some other proc
404 # that stores the filename of the testcase in a local variable "name".
405 # A cleaner solution would require a new DejaGnu release.
406 upvar 2 name testcase
407 remove-build-file "[file rootname [file tail $testcase]].ii"
408 remove-build-file "[file rootname [file tail $testcase]].i"
410 # Clean up saved temp files for additional source files.
411 if [info exists additional_sources] {
412 foreach srcfile $additional_sources {
413 remove-build-file "[file rootname [file tail $srcfile]].ii"
414 remove-build-file "[file rootname [file tail $srcfile]].i"
419 # We need to make sure that additional_* are cleared out after every
420 # test. It is not enough to clear them out *before* the next test run
421 # because gcc-target-compile gets run directly from some .exp files
422 # (outside of any test). (Those uses should eventually be eliminated.)
424 # Because the DG framework doesn't provide a hook that is run at the
425 # end of a test, we must replace dg-test with a wrapper.
427 if { [info procs saved-dg-test] == [list] } {
428 rename dg-test saved-dg-test
430 proc dg-test { args } {
431 global additional_files
432 global additional_sources
433 global additional_prunes
435 global compiler_conditional_xfail_data
437 if { [ catch { eval saved-dg-test $args } errmsg ] } {
438 set saved_info $errorInfo
439 set additional_files ""
440 set additional_sources ""
441 set additional_prunes ""
442 if [info exists compiler_conditional_xfail_data] {
443 unset compiler_conditional_xfail_data
445 error $errmsg $saved_info
447 set additional_files ""
448 set additional_sources ""
449 set additional_prunes ""
450 if [info exists compiler_conditional_xfail_data] {
451 unset compiler_conditional_xfail_data
456 set additional_prunes ""