1 # Copyright (C) 1997, 1999, 2000, 2003 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., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
18 load_lib file-format.exp
19 load_lib target-supports.exp
24 if ![info exists TORTURE_OPTIONS] {
25 # It is theoretically beneficial to group all of the O2/O3 options together,
26 # as in many cases the compiler will generate identical executables for
27 # all of them--and the c-torture testsuite will skip testing identical
28 # executables multiple times.
29 # Also note that -finline-functions is explicitly included in one of the
30 # items below, even though -O3 is also specified, because some ports may
31 # choose to disable inlining functions by default, even when optimizing.
32 set TORTURE_OPTIONS [list \
36 { -O3 -fomit-frame-pointer } \
37 { -O3 -fomit-frame-pointer -funroll-loops } \
38 { -O3 -fomit-frame-pointer -funroll-all-loops -finline-functions } \
44 # Split TORTURE_OPTIONS into two choices: one for testcases with loops and
45 # one for testcases without loops.
47 set torture_with_loops $TORTURE_OPTIONS
48 set torture_without_loops ""
49 foreach option $TORTURE_OPTIONS {
50 if ![string match "*loop*" $option] {
51 lappend torture_without_loops $option
55 # Define gcc callbacks for dg.exp.
57 proc gcc-dg-test-1 { target_compile prog do_what extra_tool_flags } {
58 # Set up the compiler flags, based on what we're going to do.
62 # Tests should be able to use "dg-do repo". However, the dg test
63 # driver checks the argument to dg-do against a list of acceptable
64 # options, and "repo" is not among them. Therefore, we resort to
66 if [string match "*-frepo*" $extra_tool_flags] then {
72 set compile_type "preprocess"
73 set output_file "[file rootname [file tail $prog]].i"
76 set compile_type "assembly"
77 set output_file "[file rootname [file tail $prog]].s"
80 set compile_type "object"
81 set output_file "[file rootname [file tail $prog]].o"
84 set compile_type "precompiled_header"
85 set output_file "[file tail $prog].gch"
88 set compile_type "executable"
89 set output_file "[file rootname [file tail $prog]].exe"
90 # The following line is needed for targets like the i960 where
91 # the default output file is b.out. Sigh.
94 set compile_type "object"
95 set output_file "[file rootname [file tail $prog]].o"
98 set compile_type "executable"
99 # FIXME: "./" is to cope with "." not being in $PATH.
100 # Should this be handled elsewhere?
102 set output_file "./[file rootname [file tail $prog]].exe"
103 # This is the only place where we care if an executable was
104 # created or not. If it was, dg.exp will try to run it.
105 remote_file build delete $output_file;
108 perror "$do_what: not a valid dg-do keyword"
113 if { $extra_tool_flags != "" } {
114 lappend options "additional_flags=$extra_tool_flags"
117 set comp_output [$target_compile "$prog" "$output_file" "$compile_type" $options];
119 if { $do_what == "repo" } {
120 set object_file "$output_file"
121 set output_file "[file rootname [file tail $prog]].exe"
123 [$target_compile "$object_file" "$output_file" "executable" $options]
126 return [list $comp_output $output_file]
129 proc gcc-dg-test { prog do_what extra_tool_flags } {
130 return [gcc-dg-test-1 gcc_target_compile $prog $do_what $extra_tool_flags]
133 proc gcc-dg-prune { system text } {
134 global additional_prunes
136 set text [prune_gcc_output $text]
138 foreach p $additional_prunes {
139 if { [string length $p] > 0 } {
140 # Following regexp matches a complete line containing $p.
141 regsub -all "(^|\n)\[^\n\]*$p\[^\n\]*" $text "" text
145 # If we see "region xxx is full" then the testcase is too big for ram.
146 # This is tricky to deal with in a large testsuite like c-torture so
147 # deal with it here. Just mark the testcase as unsupported.
148 if [regexp "(^|\n)\[^\n\]*: region \[^\n\]* is full" $text] {
149 # The format here is important. See dg.exp.
150 return "::unsupported::memory full"
159 # search_for -- looks for a string match in a file
161 proc search_for { file pattern } {
162 set fd [open $file r]
163 while { [gets $fd cur_line]>=0 } {
164 if [string match "*$pattern*" $cur_line] then {
173 # Modified dg-runtest that can cycle through a list of optimization options
175 proc gcc-dg-runtest { testcases default-extra-flags } {
178 foreach test $testcases {
179 # If we're only testing specific files and this isn't one of
181 if ![runtest_file_p $runtests $test] {
185 # Look for a loop within the source code - if we don't find one,
186 # don't pass -funroll[-all]-loops.
187 global torture_with_loops torture_without_loops
188 if [expr [search_for $test "for*("]+[search_for $test "while*("]] {
189 set option_list $torture_with_loops
191 set option_list $torture_without_loops
194 set nshort [file tail [file dirname $test]]/[file tail $test]
196 foreach flags $option_list {
197 verbose "Testing $nshort, $flags" 1
198 dg-test $test $flags ${default-extra-flags}
203 proc gcc-dg-debug-runtest { target_compile trivial opt_opts testcases } {
206 if ![info exists DEBUG_TORTURE_OPTIONS] {
207 set DEBUG_TORTURE_OPTIONS ""
208 foreach type {-gdwarf-2 -gstabs -gstabs+ -gxcoff -gxcoff+ -gcoff} {
209 set comp_output [$target_compile \
210 "$srcdir/$subdir/$trivial" "trivial.S" assembly \
211 "additional_flags=$type"]
212 if { ! [string match "*: target system does not support the * debug format*" \
214 foreach level {1 "" 3} {
215 lappend DEBUG_TORTURE_OPTIONS [list "${type}${level}"]
216 foreach opt $opt_opts {
217 lappend DEBUG_TORTURE_OPTIONS \
218 [list "${type}${level}" "$opt" ]
225 verbose -log "Using options $DEBUG_TORTURE_OPTIONS"
229 foreach test $testcases {
230 # If we're only testing specific files and this isn't one of
232 if ![runtest_file_p $runtests $test] {
236 set nshort [file tail [file dirname $test]]/[file tail $test]
238 foreach flags $DEBUG_TORTURE_OPTIONS {
240 if { [string match {*/debug-[126].c} "$nshort"] \
241 && [string match "*1" [lindex "$flags" 0] ] } {
245 # High optimization can remove the variable whose existence is tested.
246 # Dwarf debugging with commentary (-dA) preserves the symbol name in the
247 # assembler output, but stabs debugging does not.
248 # http://gcc.gnu.org/ml/gcc-regression/2003-04/msg00095.html
249 if { [string match {*/debug-[12].c} "$nshort"] \
250 && [string match "*O*" "$flags"] \
251 && ( [string match "*coff*" "$flags"] \
252 || [string match "*stabs*" "$flags"] ) } {
257 verbose -log "Testing $nshort, $flags" 1
258 dg-test $test $flags ""
264 # If this target does not support weak symbols, skip this test.
266 proc dg-require-weak { args } {
267 upvar dg-do-what dg-do-what
270 set weak_available [ check_weak_available ]
271 if { $weak_available == -1 } {
274 if { $weak_available != 1 } {
275 set dg-do-what [list [lindex ${dg-do-what} 0] "N" "P"]
280 # If this target does not support the "visibility" attribute, skip this
283 proc dg-require-visibility { args } {
284 upvar dg-do-what dg-do-what
287 set visibility_available [ check_visibility_available ]
288 if { $visibility_available == -1 } {
291 if { $visibility_available != 1 } {
292 set dg-do-what [list [lindex ${dg-do-what} 0] "N" "P"]
297 # If this target does not support the "alias" attribute, skip this
300 proc dg-require-alias { args } {
301 upvar dg-do-what dg-do-what
304 set alias_available [ check_alias_available ]
305 if { $alias_available == -1 } {
308 if { $alias_available < 2 } {
309 set dg-do-what [list [lindex ${dg-do-what} 0] "N" "P"]
314 # If this target's linker does not support the --gc-sections flag,
317 proc dg-require-gc-sections { args } {
318 if { ![ check_gc_sections_available ] } {
319 upvar dg-do-what dg-do-what
320 set dg-do-what [list [lindex ${dg-do-what} 0] "N" "P"]
325 # If this target does not support profiling, skip this test.
327 proc dg-require-profiling { args } {
328 if { ![ check_profiling_available ${args} ] } {
329 upvar dg-do-what dg-do-what
330 set dg-do-what [list [lindex ${dg-do-what} 0] "N" "P"]
335 # If this target does not support DLL attributes skip this test.
337 proc dg-require-dll { args } {
338 global target_triplet
339 # As a special case, the mcore-*-elf supports dllimport/dllexport.
340 if { [string match "mcore-*-elf" $target_triplet] } {
343 # PE/COFF targets support dllimport/dllexport.
344 if { [gcc_target_object_format] == "pe" } {
348 upvar dg-do-what dg-do-what
349 set dg-do-what [list [lindex ${dg-do-what} 0] "N" "P"]
352 proc dg-require-iconv { args } {
353 if { ![ check_iconv_available ${args} ] } {
354 upvar dg-do-what dg-do-what
355 set dg-do-what [list [lindex ${dg-do-what} 0] "N" "P"]
361 # If this target does not support named sections skip this test.
363 proc dg-require-named-sections { args } {
366 if { ![ check_named_sections_available ] } {
367 upvar dg-do-what dg-do-what
368 set dg-do-what [list [lindex ${dg-do-what} 0] "N" "P"]
372 # Prune any messages matching ARGS[1] (a regexp) from test output.
373 proc dg-prune-output { args } {
374 global additional_prunes
376 if { [llength $args] != 2 } {
377 error "[lindex $args 1]: need one argument"
381 lappend additional_prunes [lindex $args 1]
384 # Like check_conditional_xfail, but callable from a dg test.
386 proc dg-xfail-if { args } {
387 set args [lreplace $args 0 0]
388 set selector "target [join [lindex $args 1]]"
389 if { [dg-process-target $selector] == "S" } {
390 global compiler_conditional_xfail_data
391 set compiler_conditional_xfail_data $args
396 # We need to make sure that additional_* are cleared out after every
397 # test. It is not enough to clear them out *before* the next test run
398 # because gcc-target-compile gets run directly from some .exp files
399 # (outside of any test). (Those uses should eventually be eliminated.)
401 # Because the DG framework doesn't provide a hook that is run at the
402 # end of a test, we must replace dg-test with a wrapper.
404 if { [info procs saved-dg-test] == [list] } {
405 rename dg-test saved-dg-test
407 proc dg-test { args } {
408 global additional_files
409 global additional_sources
410 global additional_prunes
413 if { [ catch { eval saved-dg-test $args } errmsg ] } {
414 set saved_info $errorInfo
415 set additional_files ""
416 set additional_sources ""
417 set additional_prunes ""
418 error $errmsg $saved_info
420 set additional_files ""
421 set additional_sources ""
422 set additional_prunes ""
425 set additional_prunes ""