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 # We set LC_ALL and LANG to C so that we get the same error messages as expected.
29 if ![info exists TORTURE_OPTIONS] {
30 # It is theoretically beneficial to group all of the O2/O3 options together,
31 # as in many cases the compiler will generate identical executables for
32 # all of them--and the c-torture testsuite will skip testing identical
33 # executables multiple times.
34 # Also note that -finline-functions is explicitly included in one of the
35 # items below, even though -O3 is also specified, because some ports may
36 # choose to disable inlining functions by default, even when optimizing.
37 set TORTURE_OPTIONS [list \
41 { -O3 -fomit-frame-pointer } \
42 { -O3 -fomit-frame-pointer -funroll-loops } \
43 { -O3 -fomit-frame-pointer -funroll-all-loops -finline-functions } \
49 if ![info exists GCC_UNDER_TEST] {
50 set GCC_UNDER_TEST "[find_gcc]"
54 set libgcc_s_path "${rootme}"
55 set compiler [lindex $GCC_UNDER_TEST 0]
56 if { [is_remote host] == 0 && [which $compiler] != 0 } {
57 foreach i "[exec $compiler --print-multi-lib]" {
59 regexp -- "\[a-z0-9=/\.-\]*;" $i mldir
60 set mldir [string trimright $mldir "\;@"]
61 if { "$mldir" == "." } {
64 if { [llength [glob -nocomplain ${rootme}/${mldir}/libgcc_s*.so.*]] >= 1 } {
65 append libgcc_s_path ":${rootme}/${mldir}"
70 # On IRIX 6, we have to set variables akin to LD_LIBRARY_PATH, but
71 # called LD_LIBRARYN32_PATH (for the N32 ABI) and LD_LIBRARY64_PATH
72 # (for the 64-bit ABI). The right way to do this would be to modify
73 # unix.exp -- but that's not an option since it's part of DejaGNU
74 # proper, so we do it here. We really only need to do
75 # this on IRIX, but it shouldn't hurt to do it anywhere else.
76 # Doing this does cause trouble when testing cross-compilers.
77 if {![is_remote target]} {
78 if [info exists env(LD_LIBRARY_PATH)] {
79 setenv LD_LIBRARY_PATH "$libgcc_s_path:$env(LD_LIBRARY_PATH)"
81 setenv LD_LIBRARY_PATH $libgcc_s_path
83 if [info exists env(SHLIB_PATH)] {
84 setenv SHLIB_PATH "$libgcc_s_path:$env(SHLIB_PATH)"
86 setenv SHLIB_PATH $libgcc_s_path
88 if [info exists env(LD_LIBRARYN32_PATH)] {
89 setenv LD_LIBRARYN32_PATH "$libgcc_s_path:$env(LD_LIBRARYN32_PATH)"
91 setenv LD_LIBRARYN32_PATH $libgcc_s_path
93 if [info exists env(LD_LIBRARY64_PATH)] {
94 setenv LD_LIBRARY64_PATH "$libgcc_s_path:$env(LD_LIBRARY64_PATH)"
96 setenv LD_LIBRARY64_PATH $libgcc_s_path
98 if [info exists env(DYLD_LIBRARY_PATH)] {
99 setenv DYLD_LIBRARY_PATH "$libgcc_s_path:$env(DYLD_LIBRARY_PATH)"
101 setenv DYLD_LIBRARY_PATH $libgcc_s_path
105 # Split TORTURE_OPTIONS into two choices: one for testcases with loops and
106 # one for testcases without loops.
108 set torture_with_loops $TORTURE_OPTIONS
109 set torture_without_loops ""
110 foreach option $TORTURE_OPTIONS {
111 if ![string match "*loop*" $option] {
112 lappend torture_without_loops $option
116 # Define gcc callbacks for dg.exp.
118 proc gcc-dg-test-1 { target_compile prog do_what extra_tool_flags } {
119 # Set up the compiler flags, based on what we're going to do.
123 # Tests should be able to use "dg-do repo". However, the dg test
124 # driver checks the argument to dg-do against a list of acceptable
125 # options, and "repo" is not among them. Therefore, we resort to
126 # this ugly approach.
127 if [string match "*-frepo*" $extra_tool_flags] then {
133 set compile_type "preprocess"
134 set output_file "[file rootname [file tail $prog]].i"
137 set compile_type "assembly"
138 set output_file "[file rootname [file tail $prog]].s"
141 set compile_type "object"
142 set output_file "[file rootname [file tail $prog]].o"
145 set compile_type "precompiled_header"
146 set output_file "[file tail $prog].gch"
149 set compile_type "executable"
150 set output_file "[file rootname [file tail $prog]].exe"
151 # The following line is needed for targets like the i960 where
152 # the default output file is b.out. Sigh.
155 set compile_type "object"
156 set output_file "[file rootname [file tail $prog]].o"
159 set compile_type "executable"
160 # FIXME: "./" is to cope with "." not being in $PATH.
161 # Should this be handled elsewhere?
163 set output_file "./[file rootname [file tail $prog]].exe"
164 # This is the only place where we care if an executable was
165 # created or not. If it was, dg.exp will try to run it.
166 remote_file build delete $output_file;
169 perror "$do_what: not a valid dg-do keyword"
174 if { $extra_tool_flags != "" } {
175 lappend options "additional_flags=$extra_tool_flags"
178 set comp_output [$target_compile "$prog" "$output_file" "$compile_type" $options];
180 if { $do_what == "repo" } {
181 set object_file "$output_file"
182 set output_file "[file rootname [file tail $prog]].exe"
184 [ concat $comp_output \
185 [$target_compile "$object_file" "$output_file" \
186 "executable" $options] ]
189 return [list $comp_output $output_file]
192 proc gcc-dg-test { prog do_what extra_tool_flags } {
193 return [gcc-dg-test-1 gcc_target_compile $prog $do_what $extra_tool_flags]
196 proc gcc-dg-prune { system text } {
197 global additional_prunes
199 set text [prune_gcc_output $text]
201 foreach p $additional_prunes {
202 if { [string length $p] > 0 } {
203 # Following regexp matches a complete line containing $p.
204 regsub -all "(^|\n)\[^\n\]*$p\[^\n\]*" $text "" text
208 # If we see "region xxx is full" then the testcase is too big for ram.
209 # This is tricky to deal with in a large testsuite like c-torture so
210 # deal with it here. Just mark the testcase as unsupported.
211 if [regexp "(^|\n)\[^\n\]*: region \[^\n\]* is full" $text] {
212 # The format here is important. See dg.exp.
213 return "::unsupported::memory full"
222 # search_for -- looks for a string match in a file
224 proc search_for { file pattern } {
225 set fd [open $file r]
226 while { [gets $fd cur_line]>=0 } {
227 if [string match "*$pattern*" $cur_line] then {
236 # Modified dg-runtest that can cycle through a list of optimization options
238 proc gcc-dg-runtest { testcases default-extra-flags } {
241 foreach test $testcases {
242 # If we're only testing specific files and this isn't one of
244 if ![runtest_file_p $runtests $test] {
248 # Look for a loop within the source code - if we don't find one,
249 # don't pass -funroll[-all]-loops.
250 global torture_with_loops torture_without_loops
251 if [expr [search_for $test "for*("]+[search_for $test "while*("]] {
252 set option_list $torture_with_loops
254 set option_list $torture_without_loops
257 set nshort [file tail [file dirname $test]]/[file tail $test]
259 foreach flags $option_list {
260 verbose "Testing $nshort, $flags" 1
261 dg-test $test $flags ${default-extra-flags}
266 proc gcc-dg-debug-runtest { target_compile trivial opt_opts testcases } {
269 if ![info exists DEBUG_TORTURE_OPTIONS] {
270 set DEBUG_TORTURE_OPTIONS ""
271 foreach type {-gdwarf-2 -gstabs -gstabs+ -gxcoff -gxcoff+ -gcoff} {
272 set comp_output [$target_compile \
273 "$srcdir/$subdir/$trivial" "trivial.S" assembly \
274 "additional_flags=$type"]
275 if { ! [string match "*: target system does not support the * debug format*" \
277 foreach level {1 "" 3} {
278 lappend DEBUG_TORTURE_OPTIONS [list "${type}${level}"]
279 foreach opt $opt_opts {
280 lappend DEBUG_TORTURE_OPTIONS \
281 [list "${type}${level}" "$opt" ]
288 verbose -log "Using options $DEBUG_TORTURE_OPTIONS"
292 foreach test $testcases {
293 # If we're only testing specific files and this isn't one of
295 if ![runtest_file_p $runtests $test] {
299 set nshort [file tail [file dirname $test]]/[file tail $test]
301 foreach flags $DEBUG_TORTURE_OPTIONS {
303 if { [string match {*/debug-[126].c} "$nshort"] \
304 && [string match "*1" [lindex "$flags" 0] ] } {
308 # High optimization can remove the variable whose existence is tested.
309 # Dwarf debugging with commentary (-dA) preserves the symbol name in the
310 # assembler output, but stabs debugging does not.
311 # http://gcc.gnu.org/ml/gcc-regression/2003-04/msg00095.html
312 if { [string match {*/debug-[12].c} "$nshort"] \
313 && [string match "*O*" "$flags"] \
314 && ( [string match "*coff*" "$flags"] \
315 || [string match "*stabs*" "$flags"] ) } {
320 verbose -log "Testing $nshort, $flags" 1
321 dg-test $test $flags ""
327 # Skip a test and clear all xfail flags that might have been set for it
328 # by dg-xfail-if or for the xfail list in dg-do. A procedure that calls
329 # this must specify "upvar dg-do-what dg-do-what".
331 proc skip_test_and_clear_xfail { } {
332 global compiler_conditional_xfail_data
333 upvar dg-do-what dg-do-what
335 set dg-do-what [list [lindex ${dg-do-what} 0] "N" "P"]
336 if [info exists compiler_conditional_xfail_data] {
337 unset compiler_conditional_xfail_data
341 # If this target does not support weak symbols, skip this test.
343 proc dg-require-weak { args } {
344 set weak_available [ check_weak_available ]
345 if { $weak_available == -1 } {
349 if { $weak_available != 1 } {
350 upvar dg-do-what dg-do-what
351 skip_test_and_clear_xfail
355 # If this target does not support the "visibility" attribute, skip this
358 proc dg-require-visibility { args } {
359 set visibility_available [ check_visibility_available ]
360 if { $visibility_available == -1 } {
364 if { $visibility_available != 1 } {
365 upvar dg-do-what dg-do-what
366 skip_test_and_clear_xfail
370 # If this target does not support the "alias" attribute, skip this
373 proc dg-require-alias { args } {
374 set alias_available [ check_alias_available ]
375 if { $alias_available == -1 } {
379 if { $alias_available < 2 } {
380 upvar dg-do-what dg-do-what
381 skip_test_and_clear_xfail
385 # If this target's linker does not support the --gc-sections flag,
388 proc dg-require-gc-sections { args } {
389 if { ![ check_gc_sections_available ] } {
390 upvar dg-do-what dg-do-what
391 skip_test_and_clear_xfail
395 # If this target does not support profiling, skip this test.
397 proc dg-require-profiling { args } {
398 if { ![ check_profiling_available ${args} ] } {
399 upvar dg-do-what dg-do-what
400 skip_test_and_clear_xfail
404 # If this target does not support DLL attributes skip this test.
406 proc dg-require-dll { args } {
407 global target_triplet
408 # As a special case, the mcore-*-elf supports these attributes.
409 # All Symbian OS targets also support these attributes.
410 if { [string match "mcore-*-elf" $target_triplet]
411 || [string match "*-*-symbianelf" $target_triplet]} {
414 # PE/COFF targets support dllimport/dllexport.
415 if { [gcc_target_object_format] == "pe" } {
419 upvar dg-do-what dg-do-what
420 skip_test_and_clear_xfail
423 proc dg-require-iconv { args } {
424 if { ![ check_iconv_available ${args} ] } {
425 upvar dg-do-what dg-do-what
426 skip_test_and_clear_xfail
430 # If this target does not support named sections skip this test.
432 proc dg-require-named-sections { args } {
433 if { ![ check_named_sections_available ] } {
434 upvar dg-do-what dg-do-what
435 skip_test_and_clear_xfail
439 # If the target does not match the required effective target, skip this test.
441 proc dg-require-effective-target { args } {
442 set args [lreplace $args 0 0]
443 if { ![is-effective-target [lindex $args 0]] } {
444 upvar dg-do-what dg-do-what
445 skip_test_and_clear_xfail
449 # Skip the test (report it as UNSUPPORTED) if the target list and
450 # included flags are matched and the excluded flags are not matched.
452 # The first argument is the line number of the dg-skip-if directive
453 # within the test file. Remaining arguments are as for xfail lists:
454 # message { targets } { include } { exclude }
456 proc dg-skip-if { args } {
457 set args [lreplace $args 0 0]
458 if [check_conditional_xfail $args] {
459 upvar dg-do-what dg-do-what
460 skip_test_and_clear_xfail
464 # Prune any messages matching ARGS[1] (a regexp) from test output.
465 proc dg-prune-output { args } {
466 global additional_prunes
468 if { [llength $args] != 2 } {
469 error "[lindex $args 1]: need one argument"
473 lappend additional_prunes [lindex $args 1]
476 # Like check_conditional_xfail, but callable from a dg test.
478 proc dg-xfail-if { args } {
479 # Don't change anything if we're already skipping the test.
480 upvar dg-do-what dg-do-what
481 if { [lindex ${dg-do-what} 1] == "N" } {
485 set args [lreplace $args 0 0]
486 set selector "target [join [lindex $args 1]]"
487 if { [dg-process-target $selector] == "S" } {
488 global compiler_conditional_xfail_data
489 set compiler_conditional_xfail_data $args
493 # We need to make sure that additional_* are cleared out after every
494 # test. It is not enough to clear them out *before* the next test run
495 # because gcc-target-compile gets run directly from some .exp files
496 # (outside of any test). (Those uses should eventually be eliminated.)
498 # Because the DG framework doesn't provide a hook that is run at the
499 # end of a test, we must replace dg-test with a wrapper.
501 if { [info procs saved-dg-test] == [list] } {
502 rename dg-test saved-dg-test
504 proc dg-test { args } {
505 global additional_files
506 global additional_sources
507 global additional_prunes
510 if { [ catch { eval saved-dg-test $args } errmsg ] } {
511 set saved_info $errorInfo
512 set additional_files ""
513 set additional_sources ""
514 set additional_prunes ""
515 error $errmsg $saved_info
517 set additional_files ""
518 set additional_sources ""
519 set additional_prunes ""
522 set additional_prunes ""