Remove old autovect-branch by moving to "dead" directory.
[official-gcc.git] / old-autovect-branch / gcc / testsuite / lib / gcc-dg.exp
blob6a228811dd4593520b594b42eea0322ed01d4504
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.
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 scantree.exp
23 load_lib scanipa.exp
24 load_lib prune.exp
25 load_lib libgloss.exp
26 load_lib target-libpath.exp
28 # We set LC_ALL and LANG to C so that we get the same error messages as expected.
29 setenv LC_ALL C
30 setenv LANG C
32 if ![info exists TORTURE_OPTIONS] {
33 # It is theoretically beneficial to group all of the O2/O3 options together,
34 # as in many cases the compiler will generate identical executables for
35 # all of them--and the c-torture testsuite will skip testing identical
36 # executables multiple times.
37 # Also note that -finline-functions is explicitly included in one of the
38 # items below, even though -O3 is also specified, because some ports may
39 # choose to disable inlining functions by default, even when optimizing.
40 set TORTURE_OPTIONS [list \
41 { -O0 } \
42 { -O1 } \
43 { -O2 } \
44 { -O3 -fomit-frame-pointer } \
45 { -O3 -fomit-frame-pointer -funroll-loops } \
46 { -O3 -fomit-frame-pointer -funroll-all-loops -finline-functions } \
47 { -O3 -g } \
48 { -Os } ]
51 global GCC_UNDER_TEST
52 if ![info exists GCC_UNDER_TEST] {
53 set GCC_UNDER_TEST "[find_gcc]"
56 global orig_environment_saved
58 # This file may be sourced, so don't override environment settings
59 # that have been previously setup.
60 if { $orig_environment_saved == 0 } {
61 append ld_library_path [gcc-set-multilib-library-path $GCC_UNDER_TEST]
62 set_ld_library_path_env_vars
65 # Split TORTURE_OPTIONS into two choices: one for testcases with loops and
66 # one for testcases without loops.
68 set torture_with_loops $TORTURE_OPTIONS
69 set torture_without_loops ""
70 foreach option $TORTURE_OPTIONS {
71 if ![string match "*loop*" $option] {
72 lappend torture_without_loops $option
76 # Define gcc callbacks for dg.exp.
78 proc gcc-dg-test-1 { target_compile prog do_what extra_tool_flags } {
79 # Set up the compiler flags, based on what we're going to do.
81 set options [list]
83 # Tests should be able to use "dg-do repo". However, the dg test
84 # driver checks the argument to dg-do against a list of acceptable
85 # options, and "repo" is not among them. Therefore, we resort to
86 # this ugly approach.
87 if [string match "*-frepo*" $extra_tool_flags] then {
88 set do_what "repo"
91 switch $do_what {
92 "preprocess" {
93 set compile_type "preprocess"
94 set output_file "[file rootname [file tail $prog]].i"
96 "compile" {
97 set compile_type "assembly"
98 set output_file "[file rootname [file tail $prog]].s"
100 "assemble" {
101 set compile_type "object"
102 set output_file "[file rootname [file tail $prog]].o"
104 "precompile" {
105 set compile_type "precompiled_header"
106 set output_file "[file tail $prog].gch"
108 "link" {
109 set compile_type "executable"
110 set output_file "[file rootname [file tail $prog]].exe"
111 # The following line is needed for targets like the i960 where
112 # the default output file is b.out. Sigh.
114 "repo" {
115 set compile_type "object"
116 set output_file "[file rootname [file tail $prog]].o"
118 "run" {
119 set compile_type "executable"
120 # FIXME: "./" is to cope with "." not being in $PATH.
121 # Should this be handled elsewhere?
122 # YES.
123 set output_file "./[file rootname [file tail $prog]].exe"
124 # This is the only place where we care if an executable was
125 # created or not. If it was, dg.exp will try to run it.
126 catch { remote_file build delete $output_file }
128 default {
129 perror "$do_what: not a valid dg-do keyword"
130 return ""
134 if { $extra_tool_flags != "" } {
135 lappend options "additional_flags=$extra_tool_flags"
138 set comp_output [$target_compile "$prog" "$output_file" "$compile_type" $options]
140 if { $do_what == "repo" } {
141 set object_file "$output_file"
142 set output_file "[file rootname [file tail $prog]].exe"
143 set comp_output \
144 [ concat $comp_output \
145 [$target_compile "$object_file" "$output_file" \
146 "executable" $options] ]
149 return [list $comp_output $output_file]
152 proc gcc-dg-test { prog do_what extra_tool_flags } {
153 return [gcc-dg-test-1 gcc_target_compile $prog $do_what $extra_tool_flags]
156 proc gcc-dg-prune { system text } {
157 global additional_prunes
159 set text [prune_gcc_output $text]
161 foreach p $additional_prunes {
162 if { [string length $p] > 0 } {
163 # Following regexp matches a complete line containing $p.
164 regsub -all "(^|\n)\[^\n\]*$p\[^\n\]*" $text "" text
168 # If we see "region xxx is full" then the testcase is too big for ram.
169 # This is tricky to deal with in a large testsuite like c-torture so
170 # deal with it here. Just mark the testcase as unsupported.
171 if [regexp "(^|\n)\[^\n\]*: region \[^\n\]* is full" $text] {
172 # The format here is important. See dg.exp.
173 return "::unsupported::memory full"
176 return $text
179 # Utility routines.
182 # search_for -- looks for a string match in a file
184 proc search_for { file pattern } {
185 set fd [open $file r]
186 while { [gets $fd cur_line]>=0 } {
187 if [string match "*$pattern*" $cur_line] then {
188 close $fd
189 return 1
192 close $fd
193 return 0
196 # Modified dg-runtest that can cycle through a list of optimization options
197 # as c-torture does.
198 proc gcc-dg-runtest { testcases default-extra-flags } {
199 global runtests
201 foreach test $testcases {
202 # If we're only testing specific files and this isn't one of
203 # them, skip it.
204 if ![runtest_file_p $runtests $test] {
205 continue
208 # Look for a loop within the source code - if we don't find one,
209 # don't pass -funroll[-all]-loops.
210 global torture_with_loops torture_without_loops
211 if [expr [search_for $test "for*("]+[search_for $test "while*("]] {
212 set option_list $torture_with_loops
213 } else {
214 set option_list $torture_without_loops
217 set nshort [file tail [file dirname $test]]/[file tail $test]
219 foreach flags $option_list {
220 verbose "Testing $nshort, $flags" 1
221 dg-test $test $flags ${default-extra-flags}
226 proc gcc-dg-debug-runtest { target_compile trivial opt_opts testcases } {
227 global srcdir subdir
229 if ![info exists DEBUG_TORTURE_OPTIONS] {
230 set DEBUG_TORTURE_OPTIONS ""
231 foreach type {-gdwarf-2 -gstabs -gstabs+ -gxcoff -gxcoff+ -gcoff} {
232 set comp_output [$target_compile \
233 "$srcdir/$subdir/$trivial" "trivial.S" assembly \
234 "additional_flags=$type"]
235 if { ! [string match "*: target system does not support the * debug format*" \
236 $comp_output] } {
237 foreach level {1 "" 3} {
238 lappend DEBUG_TORTURE_OPTIONS [list "${type}${level}"]
239 foreach opt $opt_opts {
240 lappend DEBUG_TORTURE_OPTIONS \
241 [list "${type}${level}" "$opt" ]
248 verbose -log "Using options $DEBUG_TORTURE_OPTIONS"
250 global runtests
252 foreach test $testcases {
253 # If we're only testing specific files and this isn't one of
254 # them, skip it.
255 if ![runtest_file_p $runtests $test] {
256 continue
259 set nshort [file tail [file dirname $test]]/[file tail $test]
261 foreach flags $DEBUG_TORTURE_OPTIONS {
262 set doit 1
263 if { [string match {*/debug-[126].c} "$nshort"] \
264 && [string match "*1" [lindex "$flags" 0] ] } {
265 set doit 0
268 # High optimization can remove the variable whose existence is tested.
269 # Dwarf debugging with commentary (-dA) preserves the symbol name in the
270 # assembler output, but stabs debugging does not.
271 # http://gcc.gnu.org/ml/gcc-regression/2003-04/msg00095.html
272 if { [string match {*/debug-[12].c} "$nshort"] \
273 && [string match "*O*" "$flags"] \
274 && ( [string match "*coff*" "$flags"] \
275 || [string match "*stabs*" "$flags"] ) } {
276 set doit 0
279 if { $doit } {
280 verbose -log "Testing $nshort, $flags" 1
281 dg-test $test $flags ""
287 # Prune any messages matching ARGS[1] (a regexp) from test output.
288 proc dg-prune-output { args } {
289 global additional_prunes
291 if { [llength $args] != 2 } {
292 error "[lindex $args 1]: need one argument"
293 return
296 lappend additional_prunes [lindex $args 1]
299 # Remove files matching the pattern from the build machine.
300 proc remove-build-file { pat } {
301 verbose "remove-build-file `$pat'" 2
302 set file_list "[glob -nocomplain $pat]"
303 verbose "remove-build-file `$file_list'" 2
304 foreach output_file $file_list {
305 remote_file build delete $output_file
309 # Remove compiler-generated coverage files for the current test.
310 proc cleanup-coverage-files { } {
311 # This assumes that we are two frames down from dg-test or some other proc
312 # that stores the filename of the testcase in a local variable "name".
313 # A cleaner solution would require a new DejaGnu release.
314 upvar 2 name testcase
315 remove-build-file "[file rootname [file tail $testcase]].gc??"
317 # Clean up coverage files for additional source files.
318 if [info exists additional_sources] {
319 foreach srcfile $additional_sources {
320 remove-build-file "[file rootname [file tail $srcfile]].gc??"
325 # Remove compiler-generated files from -repo for the current test.
326 proc cleanup-repo-files { } {
327 # This assumes that we are two frames down from dg-test or some other proc
328 # that stores the filename of the testcase in a local variable "name".
329 # A cleaner solution would require a new DejaGnu release.
330 upvar 2 name testcase
331 remove-build-file "[file rootname [file tail $testcase]].o"
332 remove-build-file "[file rootname [file tail $testcase]].rpo"
334 # Clean up files for additional source files.
335 if [info exists additional_sources] {
336 foreach srcfile $additional_sources {
337 remove-build-file "[file rootname [file tail $srcfile]].o"
338 remove-build-file "[file rootname [file tail $srcfile]].rpo"
343 # Remove compiler-generated RTL dump files for the current test.
345 # SUFFIX is the filename suffix pattern.
346 proc cleanup-rtl-dump { suffix } {
347 cleanup-dump "\[0-9\]\*.$suffix"
350 # Remove a specific tree dump file for the current test.
352 # SUFFIX is the tree dump file suffix pattern.
353 proc cleanup-tree-dump { suffix } {
354 cleanup-dump "t\[0-9\]\*.$suffix"
357 # Remove a specific ipa dump file for the current test.
359 # SUFFIX is the ipa dump file suffix pattern.
360 proc cleanup-ipa-dump { suffix } {
361 cleanup-dump "i\[0-9\]\*.$suffix"
364 # Remove all dump files with the provided suffix.
365 proc cleanup-dump { suffix } {
366 # This assumes that we are three frames down from dg-test or some other
367 # proc that stores the filename of the testcase in a local variable
368 # "name". A cleaner solution would require a new DejaGnu release.
369 upvar 3 name testcase
370 # The name might include a list of options; extract the file name.
371 set src [file tail [lindex $testcase 0]]
372 remove-build-file "[file tail $src].$suffix"
374 # Clean up dump files for additional source files.
375 if [info exists additional_sources] {
376 foreach srcfile $additional_sources {
377 remove-build-file "[file tail $srcfile].$suffix"
382 # Remove files kept by --save-temps for the current test.
384 # Currently this is only .i files, but more can be added if there are
385 # tests generating them.
386 proc cleanup-saved-temps { } {
387 global additional_sources
389 # This assumes that we are two frames down from dg-test or some other proc
390 # that stores the filename of the testcase in a local variable "name".
391 # A cleaner solution would require a new DejaGnu release.
392 upvar 2 name testcase
393 remove-build-file "[file rootname [file tail $testcase]].ii"
394 remove-build-file "[file rootname [file tail $testcase]].i"
396 # Clean up saved temp 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]].ii"
400 remove-build-file "[file rootname [file tail $srcfile]].i"
405 # We need to make sure that additional_* are cleared out after every
406 # test. It is not enough to clear them out *before* the next test run
407 # because gcc-target-compile gets run directly from some .exp files
408 # (outside of any test). (Those uses should eventually be eliminated.)
410 # Because the DG framework doesn't provide a hook that is run at the
411 # end of a test, we must replace dg-test with a wrapper.
413 if { [info procs saved-dg-test] == [list] } {
414 rename dg-test saved-dg-test
416 proc dg-test { args } {
417 global additional_files
418 global additional_sources
419 global additional_prunes
420 global errorInfo
421 global compiler_conditional_xfail_data
423 if { [ catch { eval saved-dg-test $args } errmsg ] } {
424 set saved_info $errorInfo
425 set additional_files ""
426 set additional_sources ""
427 set additional_prunes ""
428 if [info exists compiler_conditional_xfail_data] {
429 unset compiler_conditional_xfail_data
431 error $errmsg $saved_info
433 set additional_files ""
434 set additional_sources ""
435 set additional_prunes ""
436 if [info exists compiler_conditional_xfail_data] {
437 unset compiler_conditional_xfail_data
442 set additional_prunes ""