OSDN Git Service

* lib/gcc-dg.exp (dg-require-alias): Fix typo.
[pf3gnuchains/gcc-fork.git] / gcc / testsuite / lib / gcc-dg.exp
1 #   Copyright (C) 1997, 1999, 2000, 2003 Free Software Foundation, Inc.
2
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.
7
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.
12
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.  
16
17 load_lib dg.exp
18 load_lib file-format.exp
19 load_lib target-supports.exp
20 load_lib scanasm.exp
21 load_lib prune.exp
22
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 \
32         { -O0 } \
33         { -O1 } \
34         { -O2 } \
35         { -O3 -fomit-frame-pointer } \
36         { -O3 -fomit-frame-pointer -funroll-loops } \
37         { -O3 -fomit-frame-pointer -funroll-all-loops -finline-functions } \
38         { -O3 -g } \
39         { -Os } ]
40 }
41
42
43 # Split TORTURE_OPTIONS into two choices: one for testcases with loops and
44 # one for testcases without loops.
45
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
51     }
52 }
53
54 # Define gcc callbacks for dg.exp.
55
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.
58
59     set options [list]
60
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
64     # this ugly approach.
65     if [string match "*-frepo*" $extra_tool_flags] then {
66         set do_what "repo"
67     }
68
69     switch $do_what {
70         "preprocess" {
71             set compile_type "preprocess"
72             set output_file "[file rootname [file tail $prog]].i"
73         }
74         "compile" {
75             set compile_type "assembly"
76             set output_file "[file rootname [file tail $prog]].s"
77         }
78         "assemble" {
79             set compile_type "object"
80             set output_file "[file rootname [file tail $prog]].o"
81         }
82         "precompile" {
83             set compile_type "precompiled_header"
84             set output_file "[file tail $prog].gch"
85         }
86         "link" {
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.
91         }
92         "repo" {
93             set compile_type "object"
94             set output_file "[file rootname [file tail $prog]].o"
95         }
96         "run" {
97             set compile_type "executable"
98             # FIXME: "./" is to cope with "." not being in $PATH.
99             # Should this be handled elsewhere?
100             # YES.
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;
105         }
106         default {
107             perror "$do_what: not a valid dg-do keyword"
108             return ""
109         }
110     }
111
112     if { $extra_tool_flags != "" } {
113         lappend options "additional_flags=$extra_tool_flags"
114     }
115
116     set comp_output [$target_compile "$prog" "$output_file" "$compile_type" $options];
117
118     if { $do_what == "repo" } {
119         set object_file "$output_file"
120         set output_file "[file rootname [file tail $prog]].exe"
121         concat comp_output \
122                [$target_compile "$object_file" "$output_file" "executable" $options]
123     }
124
125     return [list $comp_output $output_file]
126 }
127
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]
130 }
131
132 proc gcc-dg-prune { system text } {
133     set text [prune_gcc_output $text]
134
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"
141     }
142
143     return $text
144 }
145
146 # Utility routines.
147
148 #
149 # search_for -- looks for a string match in a file
150 #
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 {
155             close $fd
156             return 1
157         }
158     }
159     close $fd
160     return 0
161 }
162
163 # Modified dg-runtest that can cycle through a list of optimization options
164 # as c-torture does.
165 proc gcc-dg-runtest { testcases default-extra-flags } {
166     global runtests
167
168     foreach test $testcases {
169         # If we're only testing specific files and this isn't one of 
170         # them, skip it.
171         if ![runtest_file_p $runtests $test] {
172             continue
173         }
174
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
180         } else {
181             set option_list $torture_without_loops
182         }
183
184         set nshort [file tail [file dirname $test]]/[file tail $test]
185
186         foreach flags $option_list {
187             verbose "Testing $nshort, $flags" 1
188             dg-test $test $flags ${default-extra-flags}
189         }
190     }
191 }
192
193 proc gcc-dg-debug-runtest { target_compile trivial opt_opts testcases } {
194     global srcdir subdir
195
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*" \
203                     $comp_output] } {
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" ]
209                     }
210                 }
211             }
212         }
213     }
214
215     verbose -log "Using options $DEBUG_TORTURE_OPTIONS"
216
217     global runtests
218
219     foreach test $testcases {
220         # If we're only testing specific files and this isn't one of 
221         # them, skip it.
222         if ![runtest_file_p $runtests $test] {
223             continue
224         }
225
226         set nshort [file tail [file dirname $test]]/[file tail $test]
227
228         foreach flags $DEBUG_TORTURE_OPTIONS {
229             set doit 1
230             if { [string match {*/debug-[126].c} "$nshort"] \
231                     && [string match "*1" [lindex "$flags" 0] ] } { 
232                 set doit 0
233             }
234
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"] ) } {
243                 set doit 0
244             }
245
246             if { $doit } {
247                 verbose -log "Testing $nshort, $flags" 1
248                 dg-test $test $flags ""
249             }
250         }
251     }
252 }
253
254 # If this target does not support weak symbols, skip this test.
255
256 proc dg-require-weak { args } {
257     upvar dg-do-what dg-do-what
258     upvar name name
259
260     set weak_available [ check_weak_available ]
261     if { $weak_available == -1 } {
262         unresolved "$name"
263     }
264     if { $weak_available != 1 } {
265         set dg-do-what [list [lindex $dg_do_what 0] "N" "P"]
266         return
267     }
268 }
269
270 # If this target does not support the "alias" attribute, skip this
271 # test.
272
273 proc dg-require-alias { args } {
274     upvar dg-do-what dg-do-what
275     upvar name name
276
277     set alias_available [ check_alias_available ]
278     if { $alias_available == -1 } {
279         unresolved "$name"
280     }
281     if { $alias_available < 2 } {
282         set dg-do-what [list [lindex $dg-do-what 0] "N" "P"]
283         return
284     }
285 }
286
287 # If this target's linker does not support the --gc-sections flag,
288 # skip this test.
289
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"]
294         return
295     }
296 }