OSDN Git Service

* lib/gcc-dg.exp: Load scanipa.exp.
[pf3gnuchains/gcc-fork.git] / gcc / testsuite / lib / gcc-dg.exp
1 #   Copyright (C) 1997, 1999, 2000, 2003, 2004, 2005 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., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
16
17 load_lib dg.exp
18 load_lib file-format.exp
19 load_lib target-supports.exp
20 load_lib target-supports-dg.exp
21 load_lib scanasm.exp
22 load_lib scantree.exp
23 load_lib scanipa.exp
24 load_lib prune.exp
25 load_lib libgloss.exp
26 load_lib target-libpath.exp
27
28 # We set LC_ALL and LANG to C so that we get the same error messages as expected.
29 setenv LC_ALL C
30 setenv LANG C
31
32 if ![info exists TORTURE_OPTIONS] {
33     # It is theoretically beneficial to group all of the O2/O3 options together,
34     # as in many cases the compiler will generate identical executables for
35     # all of them--and the c-torture testsuite will skip testing identical
36     # executables multiple times.
37     # Also note that -finline-functions is explicitly included in one of the
38     # items below, even though -O3 is also specified, because some ports may
39     # choose to disable inlining functions by default, even when optimizing.
40     set TORTURE_OPTIONS [list \
41         { -O0 } \
42         { -O1 } \
43         { -O2 } \
44         { -O3 -fomit-frame-pointer } \
45         { -O3 -fomit-frame-pointer -funroll-loops } \
46         { -O3 -fomit-frame-pointer -funroll-all-loops -finline-functions } \
47         { -O3 -g } \
48         { -Os } ]
49 }
50
51 global GCC_UNDER_TEST
52 if ![info exists GCC_UNDER_TEST] {
53     set GCC_UNDER_TEST "[find_gcc]"
54 }
55
56 global orig_environment_saved
57
58 # This file may be sourced, so don't override environment settings
59 # that have been previously setup.
60 if { $orig_environment_saved == 0 } {
61     append ld_library_path [gcc-set-multilib-library-path $GCC_UNDER_TEST]
62     set_ld_library_path_env_vars
63 }
64
65 # Split TORTURE_OPTIONS into two choices: one for testcases with loops and
66 # one for testcases without loops.
67
68 set torture_with_loops $TORTURE_OPTIONS
69 set torture_without_loops ""
70 foreach option $TORTURE_OPTIONS {
71     if ![string match "*loop*" $option] {
72         lappend torture_without_loops $option
73     }
74 }
75
76 # Define gcc callbacks for dg.exp.
77
78 proc gcc-dg-test-1 { target_compile prog do_what extra_tool_flags } {
79     # Set up the compiler flags, based on what we're going to do.
80
81     set options [list]
82
83     # Tests should be able to use "dg-do repo".  However, the dg test
84     # driver checks the argument to dg-do against a list of acceptable
85     # options, and "repo" is not among them.  Therefore, we resort to
86     # this ugly approach.
87     if [string match "*-frepo*" $extra_tool_flags] then {
88         set do_what "repo"
89     }
90
91     switch $do_what {
92         "preprocess" {
93             set compile_type "preprocess"
94             set output_file "[file rootname [file tail $prog]].i"
95         }
96         "compile" {
97             set compile_type "assembly"
98             set output_file "[file rootname [file tail $prog]].s"
99         }
100         "assemble" {
101             set compile_type "object"
102             set output_file "[file rootname [file tail $prog]].o"
103         }
104         "precompile" {
105             set compile_type "precompiled_header"
106             set output_file "[file tail $prog].gch"
107         }
108         "link" {
109             set compile_type "executable"
110             set output_file "[file rootname [file tail $prog]].exe"
111             # The following line is needed for targets like the i960 where
112             # the default output file is b.out.  Sigh.
113         }
114         "repo" {
115             set compile_type "object"
116             set output_file "[file rootname [file tail $prog]].o"
117         }
118         "run" {
119             set compile_type "executable"
120             # FIXME: "./" is to cope with "." not being in $PATH.
121             # Should this be handled elsewhere?
122             # YES.
123             set output_file "./[file rootname [file tail $prog]].exe"
124             # This is the only place where we care if an executable was
125             # created or not.  If it was, dg.exp will try to run it.
126             catch { remote_file build delete $output_file }
127         }
128         default {
129             perror "$do_what: not a valid dg-do keyword"
130             return ""
131         }
132     }
133
134     if { $extra_tool_flags != "" } {
135         lappend options "additional_flags=$extra_tool_flags"
136     }
137
138     set comp_output [$target_compile "$prog" "$output_file" "$compile_type" $options]
139
140     if { $do_what == "repo" } {
141         set object_file "$output_file"
142         set output_file "[file rootname [file tail $prog]].exe"
143         set comp_output \
144             [ concat $comp_output \
145                   [$target_compile "$object_file" "$output_file" \
146                        "executable" $options] ]
147     }
148
149     return [list $comp_output $output_file]
150 }
151
152 proc gcc-dg-test { prog do_what extra_tool_flags } {
153     return [gcc-dg-test-1 gcc_target_compile $prog $do_what $extra_tool_flags]
154 }
155
156 proc gcc-dg-prune { system text } {
157     global additional_prunes
158
159     set text [prune_gcc_output $text]
160
161     foreach p $additional_prunes {
162         if { [string length $p] > 0 } {
163             # Following regexp matches a complete line containing $p.
164             regsub -all "(^|\n)\[^\n\]*$p\[^\n\]*" $text "" text
165         }
166     }
167
168     # If we see "region xxx is full" then the testcase is too big for ram.
169     # This is tricky to deal with in a large testsuite like c-torture so
170     # deal with it here.  Just mark the testcase as unsupported.
171     if [regexp "(^|\n)\[^\n\]*: region \[^\n\]* is full" $text] {
172         # The format here is important.  See dg.exp.
173         return "::unsupported::memory full"
174     }
175
176     return $text
177 }
178
179 # Utility routines.
180
181 #
182 # search_for -- looks for a string match in a file
183 #
184 proc search_for { file pattern } {
185     set fd [open $file r]
186     while { [gets $fd cur_line]>=0 } {
187         if [string match "*$pattern*" $cur_line] then {
188             close $fd
189             return 1
190         }
191     }
192     close $fd
193     return 0
194 }
195
196 # Modified dg-runtest that can cycle through a list of optimization options
197 # as c-torture does.
198 proc gcc-dg-runtest { testcases default-extra-flags } {
199     global runtests
200
201     foreach test $testcases {
202         # If we're only testing specific files and this isn't one of
203         # them, skip it.
204         if ![runtest_file_p $runtests $test] {
205             continue
206         }
207
208         # Look for a loop within the source code - if we don't find one,
209         # don't pass -funroll[-all]-loops.
210         global torture_with_loops torture_without_loops
211         if [expr [search_for $test "for*("]+[search_for $test "while*("]] {
212             set option_list $torture_with_loops
213         } else {
214             set option_list $torture_without_loops
215         }
216
217         set nshort [file tail [file dirname $test]]/[file tail $test]
218
219         foreach flags $option_list {
220             verbose "Testing $nshort, $flags" 1
221             dg-test $test $flags ${default-extra-flags}
222         }
223     }
224 }
225
226 proc gcc-dg-debug-runtest { target_compile trivial opt_opts testcases } {
227     global srcdir subdir
228
229     if ![info exists DEBUG_TORTURE_OPTIONS] {
230         set DEBUG_TORTURE_OPTIONS ""
231         foreach type {-gdwarf-2 -gstabs -gstabs+ -gxcoff -gxcoff+ -gcoff} {
232             set comp_output [$target_compile \
233                     "$srcdir/$subdir/$trivial" "trivial.S" assembly \
234                     "additional_flags=$type"]
235             if { ! [string match "*: target system does not support the * debug format*" \
236                     $comp_output] } {
237                 foreach level {1 "" 3} {
238                     lappend DEBUG_TORTURE_OPTIONS [list "${type}${level}"]
239                     foreach opt $opt_opts {
240                         lappend DEBUG_TORTURE_OPTIONS \
241                                 [list "${type}${level}" "$opt" ]
242                     }
243                 }
244             }
245         }
246     }
247
248     verbose -log "Using options $DEBUG_TORTURE_OPTIONS"
249
250     global runtests
251
252     foreach test $testcases {
253         # If we're only testing specific files and this isn't one of
254         # them, skip it.
255         if ![runtest_file_p $runtests $test] {
256             continue
257         }
258
259         set nshort [file tail [file dirname $test]]/[file tail $test]
260
261         foreach flags $DEBUG_TORTURE_OPTIONS {
262             set doit 1
263             if { [string match {*/debug-[126].c} "$nshort"] \
264                     && [string match "*1" [lindex "$flags" 0] ] } {
265                 set doit 0
266             }
267
268     # High optimization can remove the variable whose existence is tested.
269     # Dwarf debugging with commentary (-dA) preserves the symbol name in the
270     # assembler output, but stabs debugging does not.
271     # http://gcc.gnu.org/ml/gcc-regression/2003-04/msg00095.html
272             if { [string match {*/debug-[12].c} "$nshort"] \
273                     && [string match "*O*" "$flags"] \
274                     && ( [string match "*coff*" "$flags"] \
275                          || [string match "*stabs*" "$flags"] ) } {
276                 set doit 0
277             }
278
279             if { $doit } {
280                 verbose -log "Testing $nshort, $flags" 1
281                 dg-test $test $flags ""
282             }
283         }
284     }
285 }
286
287 # Prune any messages matching ARGS[1] (a regexp) from test output.
288 proc dg-prune-output { args } {
289     global additional_prunes
290
291     if { [llength $args] != 2 } {
292         error "[lindex $args 1]: need one argument"
293         return
294     }
295
296     lappend additional_prunes [lindex $args 1]
297 }
298
299 # Remove files matching the pattern from the build machine.
300 proc remove-build-file { pat } {
301     verbose "remove-build-file `$pat'" 2
302     set file_list "[glob -nocomplain $pat]"
303     verbose "remove-build-file `$file_list'" 2
304     foreach output_file $file_list {
305         remote_file build delete $output_file
306     }
307 }
308
309 # Remove compiler-generated coverage files for the current test.
310 proc cleanup-coverage-files { } {
311     # This assumes that we are two frames down from dg-test or some other proc
312     # that stores the filename of the testcase in a local variable "name".
313     # A cleaner solution would require a new DejaGnu release.
314     upvar 2 name testcase
315     remove-build-file "[file rootname [file tail $testcase]].gc??"
316
317     # Clean up coverage files for additional source files.
318     if [info exists additional_sources] {
319         foreach srcfile $additional_sources {
320             remove-build-file "[file rootname [file tail $srcfile]].gc??"
321         }
322     }
323 }
324
325 # Remove compiler-generated files from -repo for the current test.
326 proc cleanup-repo-files { } {
327     # This assumes that we are two frames down from dg-test or some other proc
328     # that stores the filename of the testcase in a local variable "name".
329     # A cleaner solution would require a new DejaGnu release.
330     upvar 2 name testcase
331     remove-build-file "[file rootname [file tail $testcase]].o"
332     remove-build-file "[file rootname [file tail $testcase]].rpo"
333
334     # Clean up files for additional source files.
335     if [info exists additional_sources] {
336         foreach srcfile $additional_sources {
337             remove-build-file "[file rootname [file tail $srcfile]].o"
338             remove-build-file "[file rootname [file tail $srcfile]].rpo"
339         }
340     }
341 }
342
343 # Remove compiler-generated RTL dump files for the current test.
344 #
345 # SUFFIX is the filename suffix pattern.
346 proc cleanup-rtl-dump { suffix } {
347   cleanup-dump "\[0-9\]\[0-9\].$suffix"
348 }
349
350 # Remove a specific tree dump file for the current test.
351 #
352 # SUFFIX is the tree dump file suffix pattern.
353 proc cleanup-tree-dump { suffix } {
354   cleanup-dump "t\[0-9\]\[0-9\].$suffix"
355 }
356
357 # Remove a specific ipa dump file for the current test.
358 #
359 # SUFFIX is the ipa dump file suffix pattern.
360 proc cleanup-ipa-dump { suffix } {
361   cleanup-dump "i\[0-9\]\[0-9\].$suffix"
362 }
363
364 # Remove all dump files with the provided suffix.
365 proc cleanup-dump { suffix } {
366     # This assumes that we are three frames down from dg-test or some other
367     # proc that stores the filename of the testcase in a local variable
368     # "name".  A cleaner solution would require a new DejaGnu release.
369     upvar 3 name testcase
370     remove-build-file "[file tail $testcase].$suffix"
371
372     # Clean up dump files for additional source files.
373     if [info exists additional_sources] {
374         foreach srcfile $additional_sources {
375             remove-build-file "[file tail $srcfile].$suffix"
376         }
377     }
378 }
379
380 # Remove files kept by --save-temps for the current test.
381 #
382 # Currently this is only .i files, but more can be added if there are
383 # tests generating them.
384 proc cleanup-saved-temps { } {
385     global additional_sources
386
387     # This assumes that we are two frames down from dg-test or some other proc
388     # that stores the filename of the testcase in a local variable "name".
389     # A cleaner solution would require a new DejaGnu release.
390     upvar 2 name testcase
391     remove-build-file "[file rootname [file tail $testcase]].ii"
392     remove-build-file "[file rootname [file tail $testcase]].i"
393
394     # Clean up saved temp files for additional source files.
395     if [info exists additional_sources] {
396         foreach srcfile $additional_sources {
397             remove-build-file "[file rootname [file tail $srcfile]].ii"
398             remove-build-file "[file rootname [file tail $srcfile]].i"
399         }
400     }
401 }
402
403 # We need to make sure that additional_* are cleared out after every
404 # test.  It is not enough to clear them out *before* the next test run
405 # because gcc-target-compile gets run directly from some .exp files
406 # (outside of any test).  (Those uses should eventually be eliminated.)
407
408 # Because the DG framework doesn't provide a hook that is run at the
409 # end of a test, we must replace dg-test with a wrapper.
410
411 if { [info procs saved-dg-test] == [list] } {
412     rename dg-test saved-dg-test
413
414     proc dg-test { args } {
415         global additional_files
416         global additional_sources
417         global additional_prunes
418         global errorInfo
419         global compiler_conditional_xfail_data
420
421         if { [ catch { eval saved-dg-test $args } errmsg ] } {
422             set saved_info $errorInfo
423             set additional_files ""
424             set additional_sources ""
425             set additional_prunes ""
426             if [info exists compiler_conditional_xfail_data] {
427                 unset compiler_conditional_xfail_data
428             }
429             error $errmsg $saved_info
430         }
431         set additional_files ""
432         set additional_sources ""
433         set additional_prunes ""
434         if [info exists compiler_conditional_xfail_data] {
435             unset compiler_conditional_xfail_data
436         }
437     }
438 }
439
440 set additional_prunes ""