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
23 if ![info exists TORTURE_OPTIONS
] {
24 # It is theoretically beneficial to group all of the O2
/O3 options together
,
25 # as in many cases the compiler will generate identical executables
for
26 # all of them
--and the c
-torture testsuite will skip testing identical
27 # executables multiple times.
28 # Also note that
-finline
-functions is explicitly included in one of the
29 # items below
, even though
-O3 is also specified
, because some ports may
30 # choose to disable inlining functions by default
, even when optimizing.
31 set TORTURE_OPTIONS
[list \
35 { -O3
-fomit
-frame
-pointer
} \
36 { -O3
-fomit
-frame
-pointer
-funroll
-loops
} \
37 { -O3
-fomit
-frame
-pointer
-funroll
-all
-loops
-finline
-functions
} \
43 # Split TORTURE_OPTIONS into two choices
: one
for testcases with loops and
44 # one
for testcases without loops.
46 set torture_with_loops $TORTURE_OPTIONS
47 set torture_without_loops
""
48 foreach option $TORTURE_OPTIONS
{
49 if ![string match
"*loop*" $option] {
50 lappend torture_without_loops $option
54 #
Define gcc callbacks
for dg.exp.
56 proc gcc
-dg
-test
-1 { target_compile prog do_what extra_tool_flags
} {
57 #
Set up the compiler flags
, based
on what we
're going to do.
61 # Tests should be able to use "dg-do repo". However, the dg test
62 # driver checks the argument to dg-do against a list of acceptable
63 # options, and "repo" is not among them. Therefore, we resort to
65 if [string match "*-frepo*" $extra_tool_flags] then {
71 set compile_type "preprocess"
72 set output_file "[file rootname [file tail $prog]].i"
75 set compile_type "assembly"
76 set output_file "[file rootname [file tail $prog]].s"
79 set compile_type "object"
80 set output_file "[file rootname [file tail $prog]].o"
83 set compile_type "precompiled_header"
84 set output_file "[file tail $prog].gch"
87 set compile_type "executable"
88 set output_file "[file rootname [file tail $prog]].exe"
89 # The following line is needed for targets like the i960 where
90 # the default output file is b.out. Sigh.
93 set compile_type "object"
94 set output_file "[file rootname [file tail $prog]].o"
97 set compile_type "executable"
98 # FIXME: "./" is to cope with "." not being in $PATH.
99 # Should this be handled elsewhere?
101 set output_file "./[file rootname [file tail $prog]].exe"
102 # This is the only place where we care if an executable was
103 # created or not. If it was, dg.exp will try to run it.
104 remote_file build delete $output_file;
107 perror "$do_what: not a valid dg-do keyword"
112 if { $extra_tool_flags != "" } {
113 lappend options "additional_flags=$extra_tool_flags"
116 set comp_output [$target_compile "$prog" "$output_file" "$compile_type" $options];
118 if { $do_what == "repo" } {
119 set object_file "$output_file"
120 set output_file "[file rootname [file tail $prog]].exe"
122 [$target_compile "$object_file" "$output_file" "executable" $options]
125 return [list $comp_output $output_file]
128 proc gcc-dg-test { prog do_what extra_tool_flags } {
129 return [gcc-dg-test-1 gcc_target_compile $prog $do_what $extra_tool_flags]
132 proc gcc-dg-prune { system text } {
133 global additional_prunes
135 set text [prune_gcc_output $text]
137 foreach p $additional_prunes {
138 if { [string length $p] > 0 } {
139 # Following regexp matches a complete line containing $p.
140 regsub -all "(^|\n)\[^\n\]*$p\[^\n\]*" $text "" text
144 # If we see "region xxx is full" then the testcase is too big for ram.
145 # This is tricky to deal with in a large testsuite like c-torture so
146 # deal with it here. Just mark the testcase as unsupported.
147 if [regexp "(^|\n)\[^\n\]*: region \[^\n\]* is full" $text] {
148 # The format here is important. See dg.exp.
149 return "::unsupported::memory full"
158 # search_for -- looks for a string match in a file
160 proc search_for { file pattern } {
161 set fd [open $file r]
162 while { [gets $fd cur_line]>=0 } {
163 if [string match "*$pattern*" $cur_line] then {
172 # Modified dg-runtest that can cycle through a list of optimization options
174 proc gcc-dg-runtest { testcases default-extra-flags } {
177 foreach test $testcases {
178 # If we're only testing specific files and this isn
't one of
180 if ![runtest_file_p $runtests $test] {
184 # Look for a loop within the source code - if we don't find one
,
185 # don
't pass -funroll[-all]-loops.
186 global torture_with_loops torture_without_loops
187 if [expr [search_for $test "for*("]+[search_for $test "while*("]] {
188 set option_list $torture_with_loops
190 set option_list $torture_without_loops
193 set nshort [file tail [file dirname $test]]/[file tail $test]
195 foreach flags $option_list {
196 verbose "Testing $nshort, $flags" 1
197 dg-test $test $flags ${default-extra-flags}
202 proc gcc-dg-debug-runtest { target_compile trivial opt_opts testcases } {
205 if ![info exists DEBUG_TORTURE_OPTIONS] {
206 set DEBUG_TORTURE_OPTIONS ""
207 foreach type {-gdwarf-2 -gstabs -gstabs+ -gxcoff -gxcoff+ -gcoff} {
208 set comp_output [$target_compile \
209 "$srcdir/$subdir/$trivial" "trivial.S" assembly \
210 "additional_flags=$type"]
211 if { ! [string match "*: target system does not support the * debug format*" \
213 foreach level {1 "" 3} {
214 lappend DEBUG_TORTURE_OPTIONS [list "${type}${level}"]
215 foreach opt $opt_opts {
216 lappend DEBUG_TORTURE_OPTIONS \
217 [list "${type}${level}" "$opt" ]
224 verbose -log "Using options $DEBUG_TORTURE_OPTIONS"
228 foreach test $testcases {
229 # If we're only testing specific files and this isn
't one of
231 if ![runtest_file_p $runtests $test] {
235 set nshort [file tail [file dirname $test]]/[file tail $test]
237 foreach flags $DEBUG_TORTURE_OPTIONS {
239 if { [string match {*/debug-[126].c} "$nshort"] \
240 && [string match "*1" [lindex "$flags" 0] ] } {
244 # High optimization can remove the variable whose existence is tested.
245 # Dwarf debugging with commentary (-dA) preserves the symbol name in the
246 # assembler output, but stabs debugging does not.
247 # http://gcc.gnu.org/ml/gcc-regression/2003-04/msg00095.html
248 if { [string match {*/debug-[12].c} "$nshort"] \
249 && [string match "*O*" "$flags"] \
250 && ( [string match "*coff*" "$flags"] \
251 || [string match "*stabs*" "$flags"] ) } {
256 verbose -log "Testing $nshort, $flags" 1
257 dg-test $test $flags ""
263 # If this target does not support weak symbols, skip this test.
265 proc dg-require-weak { args } {
266 upvar dg-do-what dg-do-what
269 set weak_available [ check_weak_available ]
270 if { $weak_available == -1 } {
273 if { $weak_available != 1 } {
274 set dg-do-what [list [lindex ${dg-do-what} 0] "N" "P"]
279 # If this target does not support the "visibility" attribute, skip this
282 proc dg-require-visibility { args } {
283 upvar dg-do-what dg-do-what
286 set visibility_available [ check_visibility_available ]
287 if { $visibility_available == -1 } {
290 if { $visibility_available != 1 } {
291 set dg-do-what [list [lindex ${dg-do-what} 0] "N" "P"]
296 # If this target does not support the "alias" attribute, skip this
299 proc dg-require-alias { args } {
300 upvar dg-do-what dg-do-what
303 set alias_available [ check_alias_available ]
304 if { $alias_available == -1 } {
307 if { $alias_available < 2 } {
308 set dg-do-what [list [lindex ${dg-do-what} 0] "N" "P"]
313 # If this target's linker does not support the
--gc
-sections flag
,
316 proc dg
-require
-gc
-sections
{ args } {
317 if { ![ check_gc_sections_available
] } {
318 upvar dg
-do-what dg
-do-what
319 set dg
-do-what
[list
[lindex $
{dg
-do-what
} 0] "N" "P"]
324 #
If this target does not support profiling
, skip this test.
326 proc dg
-require
-profiling
{ args } {
327 if { ![ check_profiling_available
] } {
328 upvar dg
-do-what dg
-do-what
329 set dg
-do-what
[list
[lindex $
{dg
-do-what
} 0] "N" "P"]
334 #
If this target does not support DLL attributes skip this test.
336 proc dg
-require
-dll
{ args } {
337 global target_triplet
338 # As a special case
, the mcore
-*-elf supports dllimport
/dllexport.
339 if { [string match
"mcore-*-elf" $target_triplet] } {
342 # PE
/COFF targets support dllimport
/dllexport.
343 if { [gcc_target_object_format
] == "pe" } {
347 upvar dg
-do-what dg
-do-what
348 set dg
-do-what
[list
[lindex $
{dg
-do-what
} 0] "N" "P"]
351 # Prune
any messages matching
ARGS[1] (a regexp
) from test output.
352 proc dg
-prune
-output
{ args } {
353 global additional_prunes
355 if { [llength $
args] != 2 } {
356 error
"[lindex $args 1]: need one argument"
360 lappend additional_prunes
[lindex $
args 1]
363 # Like check_conditional_xfail
, but callable from a dg test.
365 proc dg
-xfail
-if { args } {
366 set args [lreplace $
args 0 0]
367 set selector
"target [join [lindex $args 1]]"
368 if { [dg
-process
-target $selector
] == "S" } {
369 global compiler_conditional_xfail_data
370 set compiler_conditional_xfail_data $
args
375 # We need to make sure that additional_
* are cleared out after
every
376 # test. It is not enough to clear them out
*before
* the next test run
377 # because gcc
-target
-compile gets run directly from some .exp files
378 #
(outside of
any test
).
(Those uses should eventually be eliminated.
)
380 # Because the DG framework doesn
't provide a hook that is run at the
381 # end of a test, we must replace dg-test with a wrapper.
383 if { [info procs saved-dg-test] == [list] } {
384 rename dg-test saved-dg-test
386 proc dg-test { args } {
387 global additional_files
388 global additional_sources
389 global additional_prunes
392 if { [ catch { eval saved-dg-test $args } errmsg ] } {
393 set saved_info $errorInfo
394 set additional_files ""
395 set additional_sources ""
396 set additional_prunes ""
397 error $errmsg $saved_info
399 set additional_files ""
400 set additional_sources ""
401 set additional_prunes ""
404 set additional_prunes ""