1 # Copyright (C) 1997, 1999, 2000, 2003 Free Software Foundation, Inc.
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.
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.
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.
18 load_lib file-format.exp
19 load_lib target-supports.exp
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 \
37 { -O3 -fomit-frame-pointer } \
38 { -O3 -fomit-frame-pointer -funroll-loops } \
39 { -O3 -fomit-frame-pointer -funroll-all-loops -finline-functions } \
45 if ![info exists GCC_UNDER_TEST] {
46 set GCC_UNDER_TEST "[find_gcc]"
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]" {
55 regexp -- "\[a-z0-9=/\.-\]*;" $i mldir
56 set mldir [string trimright $mldir "\;@"]
57 if { "$mldir" == "." } {
60 if { [llength [glob -nocomplain ${rootme}/${mldir}/libgcc_s*.so.*]] >= 1 } {
61 append libgcc_s_path ":${rootme}/${mldir}"
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)"
77 setenv LD_LIBRARY_PATH $libgcc_s_path
79 if [info exists env(SHLIB_PATH)] {
80 setenv SHLIB_PATH "$libgcc_s_path:$env(SHLIB_PATH)"
82 setenv SHLIB_PATH $libgcc_s_path
84 if [info exists env(LD_LIBRARYN32_PATH)] {
85 setenv LD_LIBRARYN32_PATH "$libgcc_s_path:$env(LD_LIBRARYN32_PATH)"
87 setenv LD_LIBRARYN32_PATH $libgcc_s_path
89 if [info exists env(LD_LIBRARY64_PATH)] {
90 setenv LD_LIBRARY64_PATH "$libgcc_s_path:$env(LD_LIBRARY64_PATH)"
92 setenv LD_LIBRARY64_PATH $libgcc_s_path
94 if [info exists env(DYLD_LIBRARY_PATH)] {
95 setenv DYLD_LIBRARY_PATH "$libgcc_s_path:$env(DYLD_LIBRARY_PATH)"
97 setenv DYLD_LIBRARY_PATH $libgcc_s_path
101 # Split TORTURE_OPTIONS into two choices: one for testcases with loops and
102 # one for testcases without loops.
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
112 # Define gcc callbacks for dg.exp.
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.
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 {
129 set compile_type "preprocess"
130 set output_file "[file rootname [file tail $prog]].i"
133 set compile_type "assembly"
134 set output_file "[file rootname [file tail $prog]].s"
137 set compile_type "object"
138 set output_file "[file rootname [file tail $prog]].o"
141 set compile_type "precompiled_header"
142 set output_file "[file tail $prog].gch"
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.
151 set compile_type "object"
152 set output_file "[file rootname [file tail $prog]].o"
155 set compile_type "executable"
156 # FIXME: "./" is to cope with "." not being in $PATH.
157 # Should this be handled elsewhere?
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;
165 perror "$do_what: not a valid dg-do keyword"
170 if { $extra_tool_flags != "" } {
171 lappend options "additional_flags=$extra_tool_flags"
174 set comp_output [$target_compile "$prog" "$output_file" "$compile_type" $options];
176 if { $do_what == "repo" } {
177 set object_file "$output_file"
178 set output_file "[file rootname [file tail $prog]].exe"
180 [ concat $comp_output \
181 [$target_compile "$object_file" "$output_file" \
182 "executable" $options] ]
185 return [list $comp_output $output_file]
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]
192 proc gcc-dg-prune { system text } {
193 global additional_prunes
195 set text [prune_gcc_output $text]
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
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"
218 # search_for -- looks for a string match in a file
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 {
232 # Modified dg-runtest that can cycle through a list of optimization options
234 proc gcc-dg-runtest { testcases default-extra-flags } {
237 foreach test $testcases {
238 # If we're only testing specific files and this isn't one of
240 if ![runtest_file_p $runtests $test] {
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
250 set option_list $torture_without_loops
253 set nshort [file tail [file dirname $test]]/[file tail $test]
255 foreach flags $option_list {
256 verbose "Testing $nshort, $flags" 1
257 dg-test $test $flags ${default-extra-flags}
262 proc gcc-dg-debug-runtest { target_compile trivial opt_opts testcases } {
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*" \
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" ]
284 verbose -log "Using options $DEBUG_TORTURE_OPTIONS"
288 foreach test $testcases {
289 # If we're only testing specific files and this isn't one of
291 if ![runtest_file_p $runtests $test] {
295 set nshort [file tail [file dirname $test]]/[file tail $test]
297 foreach flags $DEBUG_TORTURE_OPTIONS {
299 if { [string match {*/debug-[126].c} "$nshort"] \
300 && [string match "*1" [lindex "$flags" 0] ] } {
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"] ) } {
316 verbose -log "Testing $nshort, $flags" 1
317 dg-test $test $flags ""
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".
327 proc skip_test_and_clear_xfail { } {
328 global compiler_conditional_xfail_data
329 upvar dg-do-what dg-do-what
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
337 # If this target does not support weak symbols, skip this test.
339 proc dg-require-weak { args } {
340 set weak_available [ check_weak_available ]
341 if { $weak_available == -1 } {
345 if { $weak_available != 1 } {
346 upvar dg-do-what dg-do-what
347 skip_test_and_clear_xfail
351 # If this target does not support the "visibility" attribute, skip this
354 proc dg-require-visibility { args } {
355 set visibility_available [ check_visibility_available ]
356 if { $visibility_available == -1 } {
360 if { $visibility_available != 1 } {
361 upvar dg-do-what dg-do-what
362 skip_test_and_clear_xfail
366 # If this target does not support the "alias" attribute, skip this
369 proc dg-require-alias { args } {
370 set alias_available [ check_alias_available ]
371 if { $alias_available == -1 } {
375 if { $alias_available < 2 } {
376 upvar dg-do-what dg-do-what
377 skip_test_and_clear_xfail
381 # If this target's linker does not support the --gc-sections flag,
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
391 # If this target does not support profiling, skip this test.
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
400 # If this target does not support DLL attributes skip this test.
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]} {
410 # PE/COFF targets support dllimport/dllexport.
411 if { [gcc_target_object_format] == "pe" } {
415 upvar dg-do-what dg-do-what
416 skip_test_and_clear_xfail
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
426 # If this target does not support named sections skip this test.
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
435 # If the target does not match the required effective target, skip this test.
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
445 # Prune any messages matching ARGS[1] (a regexp) from test output.
446 proc dg-prune-output { args } {
447 global additional_prunes
449 if { [llength $args] != 2 } {
450 error "[lindex $args 1]: need one argument"
454 lappend additional_prunes [lindex $args 1]
457 # Like check_conditional_xfail, but callable from a dg test.
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" } {
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
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.
479 proc dg-target-list { what cond } {
481 "target" { set result [list $what] }
482 "xfail" { set result [list $what] }
483 "" { set result [list] }
484 default { error "`$what' not allowed here" }
487 lappend result "*-*-*"
489 lappend result "empty-empty-empty"
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.)
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.
502 if { [info procs saved-dg-test] == [list] } {
503 rename dg-test saved-dg-test
505 proc dg-test { args } {
506 global additional_files
507 global additional_sources
508 global additional_prunes
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
518 set additional_files ""
519 set additional_sources ""
520 set additional_prunes ""
523 set additional_prunes ""