OSDN Git Service

fortran/
[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 scantree.exp
22 load_lib prune.exp
23
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 \
33         { -O0 } \
34         { -O1 } \
35         { -O2 } \
36         { -O3 -fomit-frame-pointer } \
37         { -O3 -fomit-frame-pointer -funroll-loops } \
38         { -O3 -fomit-frame-pointer -funroll-all-loops -finline-functions } \
39         { -O3 -g } \
40         { -Os } ]
41 }
42
43
44 # Split TORTURE_OPTIONS into two choices: one for testcases with loops and
45 # one for testcases without loops.
46
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
52     }
53 }
54
55 # Define gcc callbacks for dg.exp.
56
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.
59
60     set options [list]
61
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
65     # this ugly approach.
66     if [string match "*-frepo*" $extra_tool_flags] then {
67         set do_what "repo"
68     }
69
70     switch $do_what {
71         "preprocess" {
72             set compile_type "preprocess"
73             set output_file "[file rootname [file tail $prog]].i"
74         }
75         "compile" {
76             set compile_type "assembly"
77             set output_file "[file rootname [file tail $prog]].s"
78         }
79         "assemble" {
80             set compile_type "object"
81             set output_file "[file rootname [file tail $prog]].o"
82         }
83         "precompile" {
84             set compile_type "precompiled_header"
85             set output_file "[file tail $prog].gch"
86         }
87         "link" {
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.
92         }
93         "repo" {
94             set compile_type "object"
95             set output_file "[file rootname [file tail $prog]].o"
96         }
97         "run" {
98             set compile_type "executable"
99             # FIXME: "./" is to cope with "." not being in $PATH.
100             # Should this be handled elsewhere?
101             # YES.
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;
106         }
107         default {
108             perror "$do_what: not a valid dg-do keyword"
109             return ""
110         }
111     }
112
113     if { $extra_tool_flags != "" } {
114         lappend options "additional_flags=$extra_tool_flags"
115     }
116
117     set comp_output [$target_compile "$prog" "$output_file" "$compile_type" $options];
118
119     if { $do_what == "repo" } {
120         set object_file "$output_file"
121         set output_file "[file rootname [file tail $prog]].exe"
122         concat comp_output \
123                [$target_compile "$object_file" "$output_file" "executable" $options]
124     }
125
126     return [list $comp_output $output_file]
127 }
128
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]
131 }
132
133 proc gcc-dg-prune { system text } {
134     global additional_prunes
135
136     set text [prune_gcc_output $text]
137
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
142         }
143     }
144
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"
151     }
152
153     return $text
154 }
155
156 # Utility routines.
157
158 #
159 # search_for -- looks for a string match in a file
160 #
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 {
165             close $fd
166             return 1
167         }
168     }
169     close $fd
170     return 0
171 }
172
173 # Modified dg-runtest that can cycle through a list of optimization options
174 # as c-torture does.
175 proc gcc-dg-runtest { testcases default-extra-flags } {
176     global runtests
177
178     foreach test $testcases {
179         # If we're only testing specific files and this isn't one of
180         # them, skip it.
181         if ![runtest_file_p $runtests $test] {
182             continue
183         }
184
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
190         } else {
191             set option_list $torture_without_loops
192         }
193
194         set nshort [file tail [file dirname $test]]/[file tail $test]
195
196         foreach flags $option_list {
197             verbose "Testing $nshort, $flags" 1
198             dg-test $test $flags ${default-extra-flags}
199         }
200     }
201 }
202
203 proc gcc-dg-debug-runtest { target_compile trivial opt_opts testcases } {
204     global srcdir subdir
205
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*" \
213                     $comp_output] } {
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" ]
219                     }
220                 }
221             }
222         }
223     }
224
225     verbose -log "Using options $DEBUG_TORTURE_OPTIONS"
226
227     global runtests
228
229     foreach test $testcases {
230         # If we're only testing specific files and this isn't one of
231         # them, skip it.
232         if ![runtest_file_p $runtests $test] {
233             continue
234         }
235
236         set nshort [file tail [file dirname $test]]/[file tail $test]
237
238         foreach flags $DEBUG_TORTURE_OPTIONS {
239             set doit 1
240             if { [string match {*/debug-[126].c} "$nshort"] \
241                     && [string match "*1" [lindex "$flags" 0] ] } {
242                 set doit 0
243             }
244
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"] ) } {
253                 set doit 0
254             }
255
256             if { $doit } {
257                 verbose -log "Testing $nshort, $flags" 1
258                 dg-test $test $flags ""
259             }
260         }
261     }
262 }
263
264 # If this target does not support weak symbols, skip this test.
265
266 proc dg-require-weak { args } {
267     upvar dg-do-what dg-do-what
268     upvar name name
269
270     set weak_available [ check_weak_available ]
271     if { $weak_available == -1 } {
272         unresolved "$name"
273     }
274     if { $weak_available != 1 } {
275         set dg-do-what [list [lindex ${dg-do-what} 0] "N" "P"]
276         return
277     }
278 }
279
280 # If this target does not support the "visibility" attribute, skip this
281 # test.
282
283 proc dg-require-visibility { args } {
284     upvar dg-do-what dg-do-what
285     upvar name name
286
287     set visibility_available [ check_visibility_available ]
288     if { $visibility_available == -1 } {
289         unresolved "$name"
290     }
291     if { $visibility_available != 1 } {
292         set dg-do-what [list [lindex ${dg-do-what} 0] "N" "P"]
293         return
294     }
295 }
296
297 # If this target does not support the "alias" attribute, skip this
298 # test.
299
300 proc dg-require-alias { args } {
301     upvar dg-do-what dg-do-what
302     upvar name name
303
304     set alias_available [ check_alias_available ]
305     if { $alias_available == -1 } {
306         unresolved "$name"
307     }
308     if { $alias_available < 2 } {
309         set dg-do-what [list [lindex ${dg-do-what} 0] "N" "P"]
310         return
311     }
312 }
313
314 # If this target's linker does not support the --gc-sections flag,
315 # skip this test.
316
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"]
321         return
322     }
323 }
324
325 # If this target does not support profiling, skip this test.
326
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"]
331         return
332     }
333 }
334
335 # If this target does not support DLL attributes skip this test.
336
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] } {
341         return
342     }
343     # PE/COFF targets support dllimport/dllexport.
344     if { [gcc_target_object_format] == "pe" } {
345         return
346     }
347
348     upvar dg-do-what dg-do-what
349     set dg-do-what [list [lindex ${dg-do-what} 0] "N" "P"]
350 }
351
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"]
356         return
357     }
358     return
359 }
360
361 # If this target does not support named sections skip this test.
362
363 proc dg-require-named-sections { args } {
364    upvar name name
365
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"]
369    }
370 }
371
372 # Prune any messages matching ARGS[1] (a regexp) from test output.
373 proc dg-prune-output { args } {
374     global additional_prunes
375
376     if { [llength $args] != 2 } {
377         error "[lindex $args 1]: need one argument"
378         return
379     }
380
381     lappend additional_prunes [lindex $args 1]
382 }
383
384 # Like check_conditional_xfail, but callable from a dg test.
385
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
392     }
393 }
394
395
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.)
400
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.
403
404 if { [info procs saved-dg-test] == [list] } {
405     rename dg-test saved-dg-test
406
407     proc dg-test { args } {
408         global additional_files
409         global additional_sources
410         global additional_prunes
411         global errorInfo
412
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
419         }
420         set additional_files ""
421         set additional_sources ""
422         set additional_prunes ""
423     }
424 }
425 set additional_prunes ""