OSDN Git Service

* lib/gcc-dg.exp (dg-target-list): New.
[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 # Skip a test and clear all xfail flags that might have been set for it
324 # by dg-xfail-if or for the xfail list in dg-do.  A procedure that calls
325 # this must specify "upvar dg-do-what dg-do-what".
326
327 proc skip_test_and_clear_xfail { } {
328     global compiler_conditional_xfail_data
329     upvar dg-do-what dg-do-what
330
331     set dg-do-what [list [lindex ${dg-do-what} 0] "N" "P"]
332     if [info exists compiler_conditional_xfail_data] {
333         unset compiler_conditional_xfail_data
334     }
335 }
336
337 # If this target does not support weak symbols, skip this test.
338
339 proc dg-require-weak { args } {
340     set weak_available [ check_weak_available ]
341     if { $weak_available == -1 } {
342         upvar name name
343         unresolved "$name"
344     }
345     if { $weak_available != 1 } {
346         upvar dg-do-what dg-do-what
347         skip_test_and_clear_xfail
348     }
349 }
350
351 # If this target does not support the "visibility" attribute, skip this
352 # test.
353
354 proc dg-require-visibility { args } {
355     set visibility_available [ check_visibility_available ]
356     if { $visibility_available == -1 } {
357         upvar name name
358         unresolved "$name"
359     }
360     if { $visibility_available != 1 } {
361         upvar dg-do-what dg-do-what
362         skip_test_and_clear_xfail
363     }
364 }
365
366 # If this target does not support the "alias" attribute, skip this
367 # test.
368
369 proc dg-require-alias { args } {
370     set alias_available [ check_alias_available ]
371     if { $alias_available == -1 } {
372         upvar name name
373         unresolved "$name"
374     }
375     if { $alias_available < 2 } {
376         upvar dg-do-what dg-do-what
377         skip_test_and_clear_xfail
378     }
379 }
380
381 # If this target's linker does not support the --gc-sections flag,
382 # skip this test.
383
384 proc dg-require-gc-sections { args } {
385     if { ![ check_gc_sections_available ] } {
386         upvar dg-do-what dg-do-what
387         skip_test_and_clear_xfail
388     }
389 }
390
391 # If this target does not support profiling, skip this test.
392
393 proc dg-require-profiling { args } {
394     if { ![ check_profiling_available ${args} ] } {
395         upvar dg-do-what dg-do-what
396         skip_test_and_clear_xfail
397     }
398 }
399
400 # If this target does not support DLL attributes skip this test.
401
402 proc dg-require-dll { args } {
403     global target_triplet
404     # As a special case, the mcore-*-elf supports these attributes.
405     # All Symbian OS targets also support these attributes.
406     if { [string match "mcore-*-elf" $target_triplet]
407          || [string match "*-*-symbianelf" $target_triplet]} {
408         return
409     }
410     # PE/COFF targets support dllimport/dllexport.
411     if { [gcc_target_object_format] == "pe" } {
412         return
413     }
414
415     upvar dg-do-what dg-do-what
416     skip_test_and_clear_xfail
417 }
418
419 proc dg-require-iconv { args } {
420     if { ![ check_iconv_available ${args} ] } {
421         upvar dg-do-what dg-do-what
422         skip_test_and_clear_xfail
423     }
424 }
425
426 # If this target does not support named sections skip this test.
427
428 proc dg-require-named-sections { args } {
429     if { ![ check_named_sections_available ] } {
430         upvar dg-do-what dg-do-what
431         skip_test_and_clear_xfail
432     }
433 }
434
435 # If the target does not match the required effective target, skip this test.
436
437 proc dg-require-effective-target { args } {
438     set args [lreplace $args 0 0]
439     if { ![is-effective-target [lindex $args 0]] } {
440         upvar dg-do-what dg-do-what
441         skip_test_and_clear_xfail
442     }
443 }
444
445 # Prune any messages matching ARGS[1] (a regexp) from test output.
446 proc dg-prune-output { args } {
447     global additional_prunes
448
449     if { [llength $args] != 2 } {
450         error "[lindex $args 1]: need one argument"
451         return
452     }
453
454     lappend additional_prunes [lindex $args 1]
455 }
456
457 # Like check_conditional_xfail, but callable from a dg test.
458
459 proc dg-xfail-if { args } {
460     # Don't change anything if we're already skipping the test.
461     upvar dg-do-what dg-do-what
462     if { [lindex ${dg-do-what} 1] == "N" } {
463       return
464     }
465
466     set args [lreplace $args 0 0]
467     set selector "target [join [lindex $args 1]]"
468     if { [dg-process-target $selector] == "S" } {
469         global compiler_conditional_xfail_data
470         set compiler_conditional_xfail_data $args
471     }
472 }
473
474 # Given an optional keyword "target" or "xfail" and the result of a
475 # condition which has been evaluated by the framework, return a list
476 # containing the keyword and "*-*-*" if the condition is true or
477 # "empty-empty-empty" if the condition is false.
478
479 proc dg-target-list { what cond } {
480     switch $what {
481         "target" { set result [list $what] }
482         "xfail"  { set result [list $what] }
483         ""       { set result [list] }
484         default  { error "`$what' not allowed here" }
485     }
486     if { $cond } {
487         lappend result "*-*-*"
488     } else {
489         lappend result "empty-empty-empty"
490     }
491     return $result
492 }
493
494 # We need to make sure that additional_* are cleared out after every
495 # test.  It is not enough to clear them out *before* the next test run
496 # because gcc-target-compile gets run directly from some .exp files
497 # (outside of any test).  (Those uses should eventually be eliminated.)
498
499 # Because the DG framework doesn't provide a hook that is run at the
500 # end of a test, we must replace dg-test with a wrapper.
501
502 if { [info procs saved-dg-test] == [list] } {
503     rename dg-test saved-dg-test
504
505     proc dg-test { args } {
506         global additional_files
507         global additional_sources
508         global additional_prunes
509         global errorInfo
510
511         if { [ catch { eval saved-dg-test $args } errmsg ] } {
512             set saved_info $errorInfo
513             set additional_files ""
514             set additional_sources ""
515             set additional_prunes ""
516             error $errmsg $saved_info
517         }
518         set additional_files ""
519         set additional_sources ""
520         set additional_prunes ""
521     }
522 }
523 set additional_prunes ""