1 # Copyright (C) 1997, 1999, 2000, 2003, 2004 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
24 load_lib target-libpath.exp
26 # We set LC_ALL and LANG to C so that we get the same error messages as expected.
30 if ![info exists TORTURE_OPTIONS] {
31 # It is theoretically beneficial to group all of the O2/O3 options together,
32 # as in many cases the compiler will generate identical executables for
33 # all of them--and the c-torture testsuite will skip testing identical
34 # executables multiple times.
35 # Also note that -finline-functions is explicitly included in one of the
36 # items below, even though -O3 is also specified, because some ports may
37 # choose to disable inlining functions by default, even when optimizing.
38 set TORTURE_OPTIONS [list \
42 { -O3 -fomit-frame-pointer } \
43 { -O3 -fomit-frame-pointer -funroll-loops } \
44 { -O3 -fomit-frame-pointer -funroll-all-loops -finline-functions } \
50 if ![info exists GCC_UNDER_TEST] {
51 set GCC_UNDER_TEST "[find_gcc]"
55 global ld_library_path
56 global orig_environment_saved
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 set ld_library_path "${rootme}"
62 set compiler [lindex $GCC_UNDER_TEST 0]
63 if { [is_remote host] == 0 && [which $compiler] != 0 } {
64 foreach i "[exec $compiler --print-multi-lib]" {
66 regexp -- "\[a-z0-9=/\.-\]*;" $i mldir
67 set mldir [string trimright $mldir "\;@"]
68 if { "$mldir" == "." } {
71 if { [llength [glob -nocomplain ${rootme}/${mldir}/libgcc_s*.so.*]] >= 1 } {
72 append ld_library_path ":${rootme}/${mldir}"
76 set_ld_library_path_env_vars
79 # Split TORTURE_OPTIONS into two choices: one for testcases with loops and
80 # one for testcases without loops.
82 set torture_with_loops $TORTURE_OPTIONS
83 set torture_without_loops ""
84 foreach option $TORTURE_OPTIONS {
85 if ![string match "*loop*" $option] {
86 lappend torture_without_loops $option
90 # Define gcc callbacks for dg.exp.
92 proc gcc-dg-test-1 { target_compile prog do_what extra_tool_flags } {
93 # Set up the compiler flags, based on what we're going to do.
97 # Tests should be able to use "dg-do repo". However, the dg test
98 # driver checks the argument to dg-do against a list of acceptable
99 # options, and "repo" is not among them. Therefore, we resort to
100 # this ugly approach.
101 if [string match "*-frepo*" $extra_tool_flags] then {
107 set compile_type "preprocess"
108 set output_file "[file rootname [file tail $prog]].i"
111 set compile_type "assembly"
112 set output_file "[file rootname [file tail $prog]].s"
115 set compile_type "object"
116 set output_file "[file rootname [file tail $prog]].o"
119 set compile_type "precompiled_header"
120 set output_file "[file tail $prog].gch"
123 set compile_type "executable"
124 set output_file "[file rootname [file tail $prog]].exe"
125 # The following line is needed for targets like the i960 where
126 # the default output file is b.out. Sigh.
129 set compile_type "object"
130 set output_file "[file rootname [file tail $prog]].o"
133 set compile_type "executable"
134 # FIXME: "./" is to cope with "." not being in $PATH.
135 # Should this be handled elsewhere?
137 set output_file "./[file rootname [file tail $prog]].exe"
138 # This is the only place where we care if an executable was
139 # created or not. If it was, dg.exp will try to run it.
140 remote_file build delete $output_file;
143 perror "$do_what: not a valid dg-do keyword"
148 if { $extra_tool_flags != "" } {
149 lappend options "additional_flags=$extra_tool_flags"
152 set comp_output [$target_compile "$prog" "$output_file" "$compile_type" $options];
154 if { $do_what == "repo" } {
155 set object_file "$output_file"
156 set output_file "[file rootname [file tail $prog]].exe"
158 [ concat $comp_output \
159 [$target_compile "$object_file" "$output_file" \
160 "executable" $options] ]
163 return [list $comp_output $output_file]
166 proc gcc-dg-test { prog do_what extra_tool_flags } {
167 return [gcc-dg-test-1 gcc_target_compile $prog $do_what $extra_tool_flags]
170 proc gcc-dg-prune { system text } {
171 global additional_prunes
173 set text [prune_gcc_output $text]
175 foreach p $additional_prunes {
176 if { [string length $p] > 0 } {
177 # Following regexp matches a complete line containing $p.
178 regsub -all "(^|\n)\[^\n\]*$p\[^\n\]*" $text "" text
182 # If we see "region xxx is full" then the testcase is too big for ram.
183 # This is tricky to deal with in a large testsuite like c-torture so
184 # deal with it here. Just mark the testcase as unsupported.
185 if [regexp "(^|\n)\[^\n\]*: region \[^\n\]* is full" $text] {
186 # The format here is important. See dg.exp.
187 return "::unsupported::memory full"
196 # search_for -- looks for a string match in a file
198 proc search_for { file pattern } {
199 set fd [open $file r]
200 while { [gets $fd cur_line]>=0 } {
201 if [string match "*$pattern*" $cur_line] then {
210 # Modified dg-runtest that can cycle through a list of optimization options
212 proc gcc-dg-runtest { testcases default-extra-flags } {
215 foreach test $testcases {
216 # If we're only testing specific files and this isn't one of
218 if ![runtest_file_p $runtests $test] {
222 # Look for a loop within the source code - if we don't find one,
223 # don't pass -funroll[-all]-loops.
224 global torture_with_loops torture_without_loops
225 if [expr [search_for $test "for*("]+[search_for $test "while*("]] {
226 set option_list $torture_with_loops
228 set option_list $torture_without_loops
231 set nshort [file tail [file dirname $test]]/[file tail $test]
233 foreach flags $option_list {
234 verbose "Testing $nshort, $flags" 1
235 dg-test $test $flags ${default-extra-flags}
240 proc gcc-dg-debug-runtest { target_compile trivial opt_opts testcases } {
243 if ![info exists DEBUG_TORTURE_OPTIONS] {
244 set DEBUG_TORTURE_OPTIONS ""
245 foreach type {-gdwarf-2 -gstabs -gstabs+ -gxcoff -gxcoff+ -gcoff} {
246 set comp_output [$target_compile \
247 "$srcdir/$subdir/$trivial" "trivial.S" assembly \
248 "additional_flags=$type"]
249 if { ! [string match "*: target system does not support the * debug format*" \
251 foreach level {1 "" 3} {
252 lappend DEBUG_TORTURE_OPTIONS [list "${type}${level}"]
253 foreach opt $opt_opts {
254 lappend DEBUG_TORTURE_OPTIONS \
255 [list "${type}${level}" "$opt" ]
262 verbose -log "Using options $DEBUG_TORTURE_OPTIONS"
266 foreach test $testcases {
267 # If we're only testing specific files and this isn't one of
269 if ![runtest_file_p $runtests $test] {
273 set nshort [file tail [file dirname $test]]/[file tail $test]
275 foreach flags $DEBUG_TORTURE_OPTIONS {
277 if { [string match {*/debug-[126].c} "$nshort"] \
278 && [string match "*1" [lindex "$flags" 0] ] } {
282 # High optimization can remove the variable whose existence is tested.
283 # Dwarf debugging with commentary (-dA) preserves the symbol name in the
284 # assembler output, but stabs debugging does not.
285 # http://gcc.gnu.org/ml/gcc-regression/2003-04/msg00095.html
286 if { [string match {*/debug-[12].c} "$nshort"] \
287 && [string match "*O*" "$flags"] \
288 && ( [string match "*coff*" "$flags"] \
289 || [string match "*stabs*" "$flags"] ) } {
294 verbose -log "Testing $nshort, $flags" 1
295 dg-test $test $flags ""
301 # Skip a test and clear all xfail flags that might have been set for it
302 # by dg-xfail-if or for the xfail list in dg-do. A procedure that calls
303 # this must specify "upvar dg-do-what dg-do-what".
305 proc skip_test_and_clear_xfail { } {
306 global compiler_conditional_xfail_data
307 upvar dg-do-what dg-do-what
309 set dg-do-what [list [lindex ${dg-do-what} 0] "N" "P"]
310 if [info exists compiler_conditional_xfail_data] {
311 unset compiler_conditional_xfail_data
315 # If this target does not support weak symbols, skip this test.
317 proc dg-require-weak { args } {
318 set weak_available [ check_weak_available ]
319 if { $weak_available == -1 } {
323 if { $weak_available != 1 } {
324 upvar dg-do-what dg-do-what
325 skip_test_and_clear_xfail
329 # If this target does not support the "visibility" attribute, skip this
332 proc dg-require-visibility { args } {
333 set visibility_available [ check_visibility_available ]
334 if { $visibility_available == -1 } {
338 if { $visibility_available != 1 } {
339 upvar dg-do-what dg-do-what
340 skip_test_and_clear_xfail
344 # If this target does not support the "alias" attribute, skip this
347 proc dg-require-alias { args } {
348 set alias_available [ check_alias_available ]
349 if { $alias_available == -1 } {
353 if { $alias_available < 2 } {
354 upvar dg-do-what dg-do-what
355 skip_test_and_clear_xfail
359 # If this target's linker does not support the --gc-sections flag,
362 proc dg-require-gc-sections { args } {
363 if { ![ check_gc_sections_available ] } {
364 upvar dg-do-what dg-do-what
365 skip_test_and_clear_xfail
369 # If this target does not support profiling, skip this test.
371 proc dg-require-profiling { args } {
372 if { ![ check_profiling_available ${args} ] } {
373 upvar dg-do-what dg-do-what
374 skip_test_and_clear_xfail
378 # If this target does not support DLL attributes skip this test.
380 proc dg-require-dll { args } {
381 global target_triplet
382 # As a special case, the mcore-*-elf supports these attributes.
383 # All Symbian OS targets also support these attributes.
384 if { [string match "mcore-*-elf" $target_triplet]
385 || [string match "*-*-symbianelf" $target_triplet]} {
388 # PE/COFF targets support dllimport/dllexport.
389 if { [gcc_target_object_format] == "pe" } {
393 upvar dg-do-what dg-do-what
394 skip_test_and_clear_xfail
397 proc dg-require-iconv { args } {
398 if { ![ check_iconv_available ${args} ] } {
399 upvar dg-do-what dg-do-what
400 skip_test_and_clear_xfail
404 # If this target does not support named sections skip this test.
406 proc dg-require-named-sections { args } {
407 if { ![ check_named_sections_available ] } {
408 upvar dg-do-what dg-do-what
409 skip_test_and_clear_xfail
413 # If the target does not match the required effective target, skip this test.
415 proc dg-require-effective-target { args } {
416 set args [lreplace $args 0 0]
417 if { ![is-effective-target [lindex $args 0]] } {
418 upvar dg-do-what dg-do-what
419 skip_test_and_clear_xfail
423 # Skip the test (report it as UNSUPPORTED) if the target list and
424 # included flags are matched and the excluded flags are not matched.
426 # The first argument is the line number of the dg-skip-if directive
427 # within the test file. Remaining arguments are as for xfail lists:
428 # message { targets } { include } { exclude }
430 proc dg-skip-if { args } {
431 set args [lreplace $args 0 0]
432 if [check_conditional_xfail $args] {
433 upvar dg-do-what dg-do-what
434 skip_test_and_clear_xfail
438 # Prune any messages matching ARGS[1] (a regexp) from test output.
439 proc dg-prune-output { args } {
440 global additional_prunes
442 if { [llength $args] != 2 } {
443 error "[lindex $args 1]: need one argument"
447 lappend additional_prunes [lindex $args 1]
450 # Like check_conditional_xfail, but callable from a dg test.
452 proc dg-xfail-if { args } {
453 # Don't change anything if we're already skipping the test.
454 upvar dg-do-what dg-do-what
455 if { [lindex ${dg-do-what} 1] == "N" } {
459 set args [lreplace $args 0 0]
460 set selector "target [join [lindex $args 1]]"
461 if { [dg-process-target $selector] == "S" } {
462 global compiler_conditional_xfail_data
463 set compiler_conditional_xfail_data $args
467 # We need to make sure that additional_* are cleared out after every
468 # test. It is not enough to clear them out *before* the next test run
469 # because gcc-target-compile gets run directly from some .exp files
470 # (outside of any test). (Those uses should eventually be eliminated.)
472 # Because the DG framework doesn't provide a hook that is run at the
473 # end of a test, we must replace dg-test with a wrapper.
475 if { [info procs saved-dg-test] == [list] } {
476 rename dg-test saved-dg-test
478 proc dg-test { args } {
479 global additional_files
480 global additional_sources
481 global additional_prunes
484 if { [ catch { eval saved-dg-test $args } errmsg ] } {
485 set saved_info $errorInfo
486 set additional_files ""
487 set additional_sources ""
488 set additional_prunes ""
489 error $errmsg $saved_info
491 set additional_files ""
492 set additional_sources ""
493 set additional_prunes ""
496 set additional_prunes ""