OSDN Git Service

gcc:
[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     global additional_prunes
134
135     set text [prune_gcc_output $text]
136
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
141         }
142     }
143
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"
150     }
151
152     return $text
153 }
154
155 # Utility routines.
156
157 #
158 # search_for -- looks for a string match in a file
159 #
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 {
164             close $fd
165             return 1
166         }
167     }
168     close $fd
169     return 0
170 }
171
172 # Modified dg-runtest that can cycle through a list of optimization options
173 # as c-torture does.
174 proc gcc-dg-runtest { testcases default-extra-flags } {
175     global runtests
176
177     foreach test $testcases {
178         # If we're only testing specific files and this isn't one of 
179         # them, skip it.
180         if ![runtest_file_p $runtests $test] {
181             continue
182         }
183
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
189         } else {
190             set option_list $torture_without_loops
191         }
192
193         set nshort [file tail [file dirname $test]]/[file tail $test]
194
195         foreach flags $option_list {
196             verbose "Testing $nshort, $flags" 1
197             dg-test $test $flags ${default-extra-flags}
198         }
199     }
200 }
201
202 proc gcc-dg-debug-runtest { target_compile trivial opt_opts testcases } {
203     global srcdir subdir
204
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*" \
212                     $comp_output] } {
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" ]
218                     }
219                 }
220             }
221         }
222     }
223
224     verbose -log "Using options $DEBUG_TORTURE_OPTIONS"
225
226     global runtests
227
228     foreach test $testcases {
229         # If we're only testing specific files and this isn't one of 
230         # them, skip it.
231         if ![runtest_file_p $runtests $test] {
232             continue
233         }
234
235         set nshort [file tail [file dirname $test]]/[file tail $test]
236
237         foreach flags $DEBUG_TORTURE_OPTIONS {
238             set doit 1
239             if { [string match {*/debug-[126].c} "$nshort"] \
240                     && [string match "*1" [lindex "$flags" 0] ] } { 
241                 set doit 0
242             }
243
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"] ) } {
252                 set doit 0
253             }
254
255             if { $doit } {
256                 verbose -log "Testing $nshort, $flags" 1
257                 dg-test $test $flags ""
258             }
259         }
260     }
261 }
262
263 # If this target does not support weak symbols, skip this test.
264
265 proc dg-require-weak { args } {
266     upvar dg-do-what dg-do-what
267     upvar name name
268
269     set weak_available [ check_weak_available ]
270     if { $weak_available == -1 } {
271         unresolved "$name"
272     }
273     if { $weak_available != 1 } {
274         set dg-do-what [list [lindex ${dg-do-what} 0] "N" "P"]
275         return
276     }
277 }
278
279 # If this target does not support the "visibility" attribute, skip this
280 # test.
281
282 proc dg-require-visibility { args } {
283     upvar dg-do-what dg-do-what
284     upvar name name
285
286     set visibility_available [ check_visibility_available ]
287     if { $visibility_available == -1 } {
288         unresolved "$name"
289     }
290     if { $visibility_available != 1 } {
291         set dg-do-what [list [lindex ${dg-do-what} 0] "N" "P"]
292         return
293     }
294 }
295
296 # If this target does not support the "alias" attribute, skip this
297 # test.
298
299 proc dg-require-alias { args } {
300     upvar dg-do-what dg-do-what
301     upvar name name
302
303     set alias_available [ check_alias_available ]
304     if { $alias_available == -1 } {
305         unresolved "$name"
306     }
307     if { $alias_available < 2 } {
308         set dg-do-what [list [lindex ${dg-do-what} 0] "N" "P"]
309         return
310     }
311 }
312
313 # If this target's linker does not support the --gc-sections flag,
314 # skip this test.
315
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"]
320         return
321     }
322 }
323
324 # If this target does not support DLL attributes skip this test.
325
326 proc dg-require-dll { args } { 
327     global target_triplet
328     # As a special case, the mcore-*-elf supports dllimport/dllexport.
329     if { [string match "mcore-*-elf" $target_triplet] } {
330         return
331     }
332     # PE/COFF targets support dllimport/dllexport.
333     if { [gcc_target_object_format] == "pe" } {
334         return
335     }
336
337     upvar dg-do-what dg-do-what
338     set dg-do-what [list [lindex ${dg-do-what} 0] "N" "P"]
339 }
340
341 # Prune any messages matching ARGS[1] (a regexp) from test output.
342 proc dg-prune-output { args } {
343     global additional_prunes
344
345     if { [llength $args] != 2 } {
346         error "[lindex $args 1]: need one argument"
347         return
348     }
349
350     lappend additional_prunes [lindex $args 1]
351 }
352
353 # Like check_conditional_xfail, but callable from a dg test.
354
355 proc dg-xfail-if { args } {
356     set args [lreplace $args 0 0]
357     set selector "target [join [lindex $args 1]]"
358     if { [dg-process-target $selector] == "S" } {
359         global compiler_conditional_xfail_data
360         set compiler_conditional_xfail_data $args
361     }
362 }
363
364
365 # We need to make sure that additional_* are cleared out after every
366 # test.  It is not enough to clear them out *before* the next test run
367 # because gcc-target-compile gets run directly from some .exp files
368 # (outside of any test).  (Those uses should eventually be eliminated.)
369
370 # Because the DG framework doesn't provide a hook that is run at the
371 # end of a test, we must replace dg-test with a wrapper.
372
373 if { [info procs saved-dg-test] == [list] } {
374     rename dg-test saved-dg-test
375
376     proc dg-test { args } {
377         global additional_files
378         global additional_sources
379         global additional_prunes
380         global errorInfo
381
382         if { [ catch { eval saved-dg-test $args } errmsg ] } {
383             set saved_info $errorInfo
384             set additional_files ""
385             set additional_sources ""
386             set additional_prunes ""
387             error $errmsg $saved_info
388         }
389         set additional_files ""
390         set additional_sources ""
391         set additional_prunes ""
392     }
393 }
394 set additional_prunes ""