OSDN Git Service

gcc/testsuite:
[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 load_lib libgloss.exp
24
25 if ![info exists TORTURE_OPTIONS] {
26     # It is theoretically beneficial to group all of the O2/O3 options together,
27     # as in many cases the compiler will generate identical executables for
28     # all of them--and the c-torture testsuite will skip testing identical
29     # executables multiple times.
30     # Also note that -finline-functions is explicitly included in one of the
31     # items below, even though -O3 is also specified, because some ports may
32     # choose to disable inlining functions by default, even when optimizing.
33     set TORTURE_OPTIONS [list \
34         { -O0 } \
35         { -O1 } \
36         { -O2 } \
37         { -O3 -fomit-frame-pointer } \
38         { -O3 -fomit-frame-pointer -funroll-loops } \
39         { -O3 -fomit-frame-pointer -funroll-all-loops -finline-functions } \
40         { -O3 -g } \
41         { -Os } ]
42 }
43
44 global GCC_UNDER_TEST
45 if ![info exists GCC_UNDER_TEST] {
46     set GCC_UNDER_TEST "[find_gcc]"
47 }
48
49 global rootme
50 set libgcc_s_path "${rootme}"
51 set compiler [lindex $GCC_UNDER_TEST 0]
52 if { [is_remote host] == 0 && [which $compiler] != 0 } {
53     foreach i "[exec $compiler --print-multi-lib]" {
54         set mldir ""
55         regexp -- "\[a-z0-9=/\.-\]*;" $i mldir
56         set mldir [string trimright $mldir "\;@"]
57         if { "$mldir" == "." } {
58             continue
59         }
60         if { [llength [glob -nocomplain ${rootme}/${mldir}/libgcc_s*.so.*]] >= 1 } {
61             append libgcc_s_path ":${rootme}/${mldir}"
62         }
63     }
64 }
65
66 # On IRIX 6, we have to set variables akin to LD_LIBRARY_PATH, but
67 # called LD_LIBRARYN32_PATH (for the N32 ABI) and LD_LIBRARY64_PATH
68 # (for the 64-bit ABI).  The right way to do this would be to modify
69 # unix.exp -- but that's not an option since it's part of DejaGNU
70 # proper, so we do it here.  We really only need to do 
71 # this on IRIX, but it shouldn't hurt to do it anywhere else.
72 # Doing this does cause trouble when testing cross-compilers.
73 if {![is_remote target]} {
74     if [info exists env(LD_LIBRARY_PATH)] {
75         setenv  LD_LIBRARY_PATH    "$libgcc_s_path:$env(LD_LIBRARY_PATH)"
76     } else {
77         setenv  LD_LIBRARY_PATH     $libgcc_s_path
78     }
79     if [info exists env(SHLIB_PATH)] {
80         setenv  SHLIB_PATH          "$libgcc_s_path:$env(SHLIB_PATH)"
81     } else {
82         setenv  SHLIB_PATH          $libgcc_s_path
83     }
84     if [info exists env(LD_LIBRARYN32_PATH)] {
85         setenv  LD_LIBRARYN32_PATH  "$libgcc_s_path:$env(LD_LIBRARYN32_PATH)"
86     } else {
87         setenv  LD_LIBRARYN32_PATH  $libgcc_s_path
88     }
89     if [info exists env(LD_LIBRARY64_PATH)] {
90         setenv  LD_LIBRARY64_PATH  "$libgcc_s_path:$env(LD_LIBRARY64_PATH)"
91     } else {
92         setenv  LD_LIBRARY64_PATH   $libgcc_s_path
93     }
94     if [info exists env(DYLD_LIBRARY_PATH)] {
95         setenv  DYLD_LIBRARY_PATH  "$libgcc_s_path:$env(DYLD_LIBRARY_PATH)"
96     } else {
97         setenv  DYLD_LIBRARY_PATH   $libgcc_s_path
98     }
99 }
100
101 # Split TORTURE_OPTIONS into two choices: one for testcases with loops and
102 # one for testcases without loops.
103
104 set torture_with_loops $TORTURE_OPTIONS
105 set torture_without_loops ""
106 foreach option $TORTURE_OPTIONS {
107     if ![string match "*loop*" $option] {
108         lappend torture_without_loops $option
109     }
110 }
111
112 # Define gcc callbacks for dg.exp.
113
114 proc gcc-dg-test-1 { target_compile prog do_what extra_tool_flags } {
115     # Set up the compiler flags, based on what we're going to do.
116
117     set options [list]
118
119     # Tests should be able to use "dg-do repo".  However, the dg test
120     # driver checks the argument to dg-do against a list of acceptable
121     # options, and "repo" is not among them.  Therefore, we resort to
122     # this ugly approach.
123     if [string match "*-frepo*" $extra_tool_flags] then {
124         set do_what "repo"
125     }
126
127     switch $do_what {
128         "preprocess" {
129             set compile_type "preprocess"
130             set output_file "[file rootname [file tail $prog]].i"
131         }
132         "compile" {
133             set compile_type "assembly"
134             set output_file "[file rootname [file tail $prog]].s"
135         }
136         "assemble" {
137             set compile_type "object"
138             set output_file "[file rootname [file tail $prog]].o"
139         }
140         "precompile" {
141             set compile_type "precompiled_header"
142             set output_file "[file tail $prog].gch"
143         }
144         "link" {
145             set compile_type "executable"
146             set output_file "[file rootname [file tail $prog]].exe"
147             # The following line is needed for targets like the i960 where
148             # the default output file is b.out.  Sigh.
149         }
150         "repo" {
151             set compile_type "object"
152             set output_file "[file rootname [file tail $prog]].o"
153         }
154         "run" {
155             set compile_type "executable"
156             # FIXME: "./" is to cope with "." not being in $PATH.
157             # Should this be handled elsewhere?
158             # YES.
159             set output_file "./[file rootname [file tail $prog]].exe"
160             # This is the only place where we care if an executable was
161             # created or not.  If it was, dg.exp will try to run it.
162             remote_file build delete $output_file;
163         }
164         default {
165             perror "$do_what: not a valid dg-do keyword"
166             return ""
167         }
168     }
169
170     if { $extra_tool_flags != "" } {
171         lappend options "additional_flags=$extra_tool_flags"
172     }
173
174     set comp_output [$target_compile "$prog" "$output_file" "$compile_type" $options];
175
176     if { $do_what == "repo" } {
177         set object_file "$output_file"
178         set output_file "[file rootname [file tail $prog]].exe"
179         set comp_output \
180             [ concat $comp_output \
181                   [$target_compile "$object_file" "$output_file" \
182                        "executable" $options] ]
183     }
184
185     return [list $comp_output $output_file]
186 }
187
188 proc gcc-dg-test { prog do_what extra_tool_flags } {
189     return [gcc-dg-test-1 gcc_target_compile $prog $do_what $extra_tool_flags]
190 }
191
192 proc gcc-dg-prune { system text } {
193     global additional_prunes
194
195     set text [prune_gcc_output $text]
196
197     foreach p $additional_prunes {
198         if { [string length $p] > 0 } {
199             # Following regexp matches a complete line containing $p.
200             regsub -all "(^|\n)\[^\n\]*$p\[^\n\]*" $text "" text
201         }
202     }
203
204     # If we see "region xxx is full" then the testcase is too big for ram.
205     # This is tricky to deal with in a large testsuite like c-torture so
206     # deal with it here.  Just mark the testcase as unsupported.
207     if [regexp "(^|\n)\[^\n\]*: region \[^\n\]* is full" $text] {
208         # The format here is important.  See dg.exp.
209         return "::unsupported::memory full"
210     }
211
212     return $text
213 }
214
215 # Utility routines.
216
217 #
218 # search_for -- looks for a string match in a file
219 #
220 proc search_for { file pattern } {
221     set fd [open $file r]
222     while { [gets $fd cur_line]>=0 } {
223         if [string match "*$pattern*" $cur_line] then {
224             close $fd
225             return 1
226         }
227     }
228     close $fd
229     return 0
230 }
231
232 # Modified dg-runtest that can cycle through a list of optimization options
233 # as c-torture does.
234 proc gcc-dg-runtest { testcases default-extra-flags } {
235     global runtests
236
237     foreach test $testcases {
238         # If we're only testing specific files and this isn't one of
239         # them, skip it.
240         if ![runtest_file_p $runtests $test] {
241             continue
242         }
243
244         # Look for a loop within the source code - if we don't find one,
245         # don't pass -funroll[-all]-loops.
246         global torture_with_loops torture_without_loops
247         if [expr [search_for $test "for*("]+[search_for $test "while*("]] {
248             set option_list $torture_with_loops
249         } else {
250             set option_list $torture_without_loops
251         }
252
253         set nshort [file tail [file dirname $test]]/[file tail $test]
254
255         foreach flags $option_list {
256             verbose "Testing $nshort, $flags" 1
257             dg-test $test $flags ${default-extra-flags}
258         }
259     }
260 }
261
262 proc gcc-dg-debug-runtest { target_compile trivial opt_opts testcases } {
263     global srcdir subdir
264
265     if ![info exists DEBUG_TORTURE_OPTIONS] {
266         set DEBUG_TORTURE_OPTIONS ""
267         foreach type {-gdwarf-2 -gstabs -gstabs+ -gxcoff -gxcoff+ -gcoff} {
268             set comp_output [$target_compile \
269                     "$srcdir/$subdir/$trivial" "trivial.S" assembly \
270                     "additional_flags=$type"]
271             if { ! [string match "*: target system does not support the * debug format*" \
272                     $comp_output] } {
273                 foreach level {1 "" 3} {
274                     lappend DEBUG_TORTURE_OPTIONS [list "${type}${level}"]
275                     foreach opt $opt_opts {
276                         lappend DEBUG_TORTURE_OPTIONS \
277                                 [list "${type}${level}" "$opt" ]
278                     }
279                 }
280             }
281         }
282     }
283
284     verbose -log "Using options $DEBUG_TORTURE_OPTIONS"
285
286     global runtests
287
288     foreach test $testcases {
289         # If we're only testing specific files and this isn't one of
290         # them, skip it.
291         if ![runtest_file_p $runtests $test] {
292             continue
293         }
294
295         set nshort [file tail [file dirname $test]]/[file tail $test]
296
297         foreach flags $DEBUG_TORTURE_OPTIONS {
298             set doit 1
299             if { [string match {*/debug-[126].c} "$nshort"] \
300                     && [string match "*1" [lindex "$flags" 0] ] } {
301                 set doit 0
302             }
303
304     # High optimization can remove the variable whose existence is tested.
305     # Dwarf debugging with commentary (-dA) preserves the symbol name in the
306     # assembler output, but stabs debugging does not.
307     # http://gcc.gnu.org/ml/gcc-regression/2003-04/msg00095.html
308             if { [string match {*/debug-[12].c} "$nshort"] \
309                     && [string match "*O*" "$flags"] \
310                     && ( [string match "*coff*" "$flags"] \
311                          || [string match "*stabs*" "$flags"] ) } {
312                 set doit 0
313             }
314
315             if { $doit } {
316                 verbose -log "Testing $nshort, $flags" 1
317                 dg-test $test $flags ""
318             }
319         }
320     }
321 }
322
323 # If this target does not support weak symbols, skip this test.
324
325 proc dg-require-weak { args } {
326     upvar dg-do-what dg-do-what
327     upvar name name
328
329     set weak_available [ check_weak_available ]
330     if { $weak_available == -1 } {
331         unresolved "$name"
332     }
333     if { $weak_available != 1 } {
334         set dg-do-what [list [lindex ${dg-do-what} 0] "N" "P"]
335         return
336     }
337 }
338
339 # If this target does not support the "visibility" attribute, skip this
340 # test.
341
342 proc dg-require-visibility { args } {
343     upvar dg-do-what dg-do-what
344     upvar name name
345
346     set visibility_available [ check_visibility_available ]
347     if { $visibility_available == -1 } {
348         unresolved "$name"
349     }
350     if { $visibility_available != 1 } {
351         set dg-do-what [list [lindex ${dg-do-what} 0] "N" "P"]
352         return
353     }
354 }
355
356 # If this target does not support the "alias" attribute, skip this
357 # test.
358
359 proc dg-require-alias { args } {
360     upvar dg-do-what dg-do-what
361     upvar name name
362
363     set alias_available [ check_alias_available ]
364     if { $alias_available == -1 } {
365         unresolved "$name"
366     }
367     if { $alias_available < 2 } {
368         set dg-do-what [list [lindex ${dg-do-what} 0] "N" "P"]
369         return
370     }
371 }
372
373 # If this target's linker does not support the --gc-sections flag,
374 # skip this test.
375
376 proc dg-require-gc-sections { args } {
377     if { ![ check_gc_sections_available ] } {
378         upvar dg-do-what dg-do-what
379         set dg-do-what [list [lindex ${dg-do-what} 0] "N" "P"]
380         return
381     }
382 }
383
384 # If this target does not support profiling, skip this test.
385
386 proc dg-require-profiling { args } {
387     if { ![ check_profiling_available ${args} ] } {
388         upvar dg-do-what dg-do-what
389         set dg-do-what [list [lindex ${dg-do-what} 0] "N" "P"]
390         return
391     }
392 }
393
394 # If this target does not support DLL attributes skip this test.
395
396 proc dg-require-dll { args } {
397     global target_triplet
398     # As a special case, the mcore-*-elf supports these attributes.
399     # All Symbian OS targets also support these attributes.
400     if { [string match "mcore-*-elf" $target_triplet]
401          || [string match "*-*-symbianelf" $target_triplet]} {
402         return
403     }
404     # PE/COFF targets support dllimport/dllexport.
405     if { [gcc_target_object_format] == "pe" } {
406         return
407     }
408
409     upvar dg-do-what dg-do-what
410     set dg-do-what [list [lindex ${dg-do-what} 0] "N" "P"]
411 }
412
413 proc dg-require-iconv { args } {
414     if { ![ check_iconv_available ${args} ] } {
415         upvar dg-do-what dg-do-what
416         set dg-do-what [list [lindex ${dg-do-what} 0] "N" "P"]
417         return
418     }
419     return
420 }
421
422 # If this target does not support named sections skip this test.
423
424 proc dg-require-named-sections { args } {
425    upvar name name
426
427    if { ![ check_named_sections_available ] } {
428        upvar dg-do-what dg-do-what
429        set dg-do-what [list [lindex ${dg-do-what} 0] "N" "P"]
430    }
431 }
432
433 # Prune any messages matching ARGS[1] (a regexp) from test output.
434 proc dg-prune-output { args } {
435     global additional_prunes
436
437     if { [llength $args] != 2 } {
438         error "[lindex $args 1]: need one argument"
439         return
440     }
441
442     lappend additional_prunes [lindex $args 1]
443 }
444
445 # Like check_conditional_xfail, but callable from a dg test.
446
447 proc dg-xfail-if { args } {
448     set args [lreplace $args 0 0]
449     set selector "target [join [lindex $args 1]]"
450     if { [dg-process-target $selector] == "S" } {
451         global compiler_conditional_xfail_data
452         set compiler_conditional_xfail_data $args
453     }
454 }
455
456
457 # We need to make sure that additional_* are cleared out after every
458 # test.  It is not enough to clear them out *before* the next test run
459 # because gcc-target-compile gets run directly from some .exp files
460 # (outside of any test).  (Those uses should eventually be eliminated.)
461
462 # Because the DG framework doesn't provide a hook that is run at the
463 # end of a test, we must replace dg-test with a wrapper.
464
465 if { [info procs saved-dg-test] == [list] } {
466     rename dg-test saved-dg-test
467
468     proc dg-test { args } {
469         global additional_files
470         global additional_sources
471         global additional_prunes
472         global errorInfo
473
474         if { [ catch { eval saved-dg-test $args } errmsg ] } {
475             set saved_info $errorInfo
476             set additional_files ""
477             set additional_sources ""
478             set additional_prunes ""
479             error $errmsg $saved_info
480         }
481         set additional_files ""
482         set additional_sources ""
483         set additional_prunes ""
484     }
485 }
486 set additional_prunes ""