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 set text [prune_gcc_output $text]
135 # If we see "region xxx is full" then the testcase is too big for ram.
136 # This is tricky to deal with in a large testsuite like c-torture so
137 # deal with it here. Just mark the testcase as unsupported.
138 if [regexp "(^|\n)\[^\n\]*: region \[^\n\]* is full" $text] {
139 # The format here is important. See dg.exp.
140 return "::unsupported::memory full"
149 # search_for -- looks for a string match in a file
151 proc search_for { file pattern } {
152 set fd [open $file r]
153 while { [gets $fd cur_line]>=0 } {
154 if [string match "*$pattern*" $cur_line] then {
163 # Modified dg-runtest that can cycle through a list of optimization options
165 proc gcc-dg-runtest { testcases default-extra-flags } {
168 foreach test $testcases {
169 # If we're only testing specific files and this isn't one of
171 if ![runtest_file_p $runtests $test] {
175 # Look for a loop within the source code - if we don't find one,
176 # don't pass -funroll[-all]-loops.
177 global torture_with_loops torture_without_loops
178 if [expr [search_for $test "for*("]+[search_for $test "while*("]] {
179 set option_list $torture_with_loops
181 set option_list $torture_without_loops
184 set nshort [file tail [file dirname $test]]/[file tail $test]
186 foreach flags $option_list {
187 verbose "Testing $nshort, $flags" 1
188 dg-test $test $flags ${default-extra-flags}
193 proc gcc-dg-debug-runtest { target_compile trivial opt_opts testcases } {
196 if ![info exists DEBUG_TORTURE_OPTIONS] {
197 set DEBUG_TORTURE_OPTIONS ""
198 foreach type {-gdwarf-2 -gstabs -gstabs+ -gxcoff -gxcoff+ -gcoff} {
199 set comp_output [$target_compile \
200 "$srcdir/$subdir/$trivial" "trivial.S" assembly \
201 "additional_flags=$type"]
202 if { ! [string match "*: unknown or unsupported -g option*" \
204 foreach level {1 "" 3} {
205 lappend DEBUG_TORTURE_OPTIONS [list "${type}${level}"]
206 foreach opt $opt_opts {
207 lappend DEBUG_TORTURE_OPTIONS \
208 [list "${type}${level}" "$opt" ]
215 verbose -log "Using options $DEBUG_TORTURE_OPTIONS"
219 foreach test $testcases {
220 # If we're only testing specific files and this isn't one of
222 if ![runtest_file_p $runtests $test] {
226 set nshort [file tail [file dirname $test]]/[file tail $test]
228 foreach flags $DEBUG_TORTURE_OPTIONS {
230 if { [string match {*/debug-[126].c} "$nshort"] \
231 && [string match "*1" [lindex "$flags" 0] ] } {
235 # High optimization can remove the variable whose existence is tested.
236 # Dwarf debugging with commentary (-dA) preserves the symbol name in the
237 # assembler output, but stabs debugging does not.
238 # http://gcc.gnu.org/ml/gcc-regression/2003-04/msg00095.html
239 if { [string match {*/debug-[12].c} "$nshort"] \
240 && [string match "*O3*" "$flags"] \
241 && ( [string match "*coff*" "$flags"] \
242 || [string match "*stabs*" "$flags"] ) } {
247 verbose -log "Testing $nshort, $flags" 1
248 dg-test $test $flags ""
254 # If this target does not support weak symbols, skip this test.
256 proc dg-require-weak { args } {
257 upvar dg-do-what dg-do-what
260 set weak_available [ check_weak_available ]
261 if { $weak_available == -1 } {
264 if { $weak_available != 1 } {
265 set dg-do-what [list [lindex $dg_do_what 0] "N" "P"]
270 # If this target does not support the "alias" attribute, skip this
273 proc dg-require-alias { args } {
274 upvar dg-do-what dg-do-what
277 set alias_available [ check_alias_available ]
278 if { $alias_available == -1 } {
281 if { $alias_available < 2 } {
282 set dg-do-what [list [lindex $dg-do-what 0] "N" "P"]
287 # If this target's linker does not support the --gc-sections flag,
290 proc dg-require-gc-sections { args } {
291 if { ![ check_gc_sections_available ] } {
292 upvar dg-do-what dg-do-what
293 set dg-do-what [list [lindex $dg-do-what 0] "N" "P"]