1 # Copyright (C) 1997, 1999, 2000, 2003, 2004, 2005 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 # If this target does not support weak symbols, skip this test.
303 proc dg-require-weak { args } {
304 set weak_available [ check_weak_available ]
305 if { $weak_available == -1 } {
309 if { $weak_available != 1 } {
310 upvar dg-do-what dg-do-what
311 set dg-do-what [list [lindex ${dg-do-what} 0] "N" "P"]
315 # If this target does not support the "visibility" attribute, skip this
318 proc dg-require-visibility { args } {
319 set visibility_available [ check_visibility_available ]
320 if { $visibility_available == -1 } {
324 if { $visibility_available != 1 } {
325 upvar dg-do-what dg-do-what
326 set dg-do-what [list [lindex ${dg-do-what} 0] "N" "P"]
330 # If this target does not support the "alias" attribute, skip this
333 proc dg-require-alias { args } {
334 set alias_available [ check_alias_available ]
335 if { $alias_available == -1 } {
339 if { $alias_available < 2 } {
340 upvar dg-do-what dg-do-what
341 set dg-do-what [list [lindex ${dg-do-what} 0] "N" "P"]
345 # If this target's linker does not support the --gc-sections flag,
348 proc dg-require-gc-sections { args } {
349 if { ![ check_gc_sections_available ] } {
350 upvar dg-do-what dg-do-what
351 set dg-do-what [list [lindex ${dg-do-what} 0] "N" "P"]
355 # If this target does not support profiling, skip this test.
357 proc dg-require-profiling { args } {
358 if { ![ check_profiling_available ${args} ] } {
359 upvar dg-do-what dg-do-what
360 set dg-do-what [list [lindex ${dg-do-what} 0] "N" "P"]
364 # If this target does not support DLL attributes skip this test.
366 proc dg-require-dll { args } {
367 global target_triplet
368 # As a special case, the mcore-*-elf supports these attributes.
369 # All Symbian OS targets also support these attributes.
370 if { [string match "mcore-*-elf" $target_triplet]
371 || [string match "*-*-symbianelf" $target_triplet]} {
374 # PE/COFF targets support dllimport/dllexport.
375 if { [gcc_target_object_format] == "pe" } {
379 upvar dg-do-what dg-do-what
380 set dg-do-what [list [lindex ${dg-do-what} 0] "N" "P"]
383 proc dg-require-iconv { args } {
384 if { ![ check_iconv_available ${args} ] } {
385 upvar dg-do-what dg-do-what
386 set dg-do-what [list [lindex ${dg-do-what} 0] "N" "P"]
390 # If this target does not support named sections skip this test.
392 proc dg-require-named-sections { args } {
393 if { ![ check_named_sections_available ] } {
394 upvar dg-do-what dg-do-what
395 set dg-do-what [list [lindex ${dg-do-what} 0] "N" "P"]
399 # If the target does not match the required effective target, skip this test.
401 proc dg-require-effective-target { args } {
402 set args [lreplace $args 0 0]
403 if { ![is-effective-target [lindex $args 0]] } {
404 upvar dg-do-what dg-do-what
405 set dg-do-what [list [lindex ${dg-do-what} 0] "N" "P"]
409 # Skip the test (report it as UNSUPPORTED) if the target list and
410 # included flags are matched and the excluded flags are not matched.
412 # The first argument is the line number of the dg-skip-if directive
413 # within the test file. Remaining arguments are as for xfail lists:
414 # message { targets } { include } { exclude }
416 # This tests against multilib flags plus either the default flags for this
417 # group of tests or flags specified with a previous dg-options command.
419 proc dg-skip-if { args } {
420 set args [lreplace $args 0 0]
422 set selector "target [join [lindex $args 1]]"
423 if { [dg-process-target $selector] == "S" } {
424 # The target list matched; now check the flags. The DejaGnu proc
425 # check_conditional_xfail will look at the options in compiler_flags,
426 # so set that up for this test based on flags we know about. Start
427 # the list with a dummy tool name so the list will match "*" if
428 # there are no flags.
430 global compiler_flags
431 upvar dg-extra-tool-flags extra_tool_flags
433 set compiler_flags " toolname "
434 append compiler_flags $extra_tool_flags
435 set dest [target_info name]
436 if [board_info $dest exists multilib_flags] {
437 append compiler_flags "[board_info $dest multilib_flags] "
440 # The target list might be an effective-target keyword, so replace
441 # the original list with "*-*-*".
442 if [check_conditional_xfail [lreplace $args 1 1 "*-*-*"]] {
443 upvar dg-do-what dg-do-what
444 set dg-do-what [list [lindex ${dg-do-what} 0] "N" "P"]
447 # Any value in this variable was left over from an earlier test.
448 set compiler_flags ""
452 # Prune any messages matching ARGS[1] (a regexp) from test output.
453 proc dg-prune-output { args } {
454 global additional_prunes
456 if { [llength $args] != 2 } {
457 error "[lindex $args 1]: need one argument"
461 lappend additional_prunes [lindex $args 1]
464 # Like check_conditional_xfail, but callable from a dg test.
466 proc dg-xfail-if { args } {
467 # Don't change anything if we're already skipping the test.
468 upvar dg-do-what dg-do-what
469 if { [lindex ${dg-do-what} 1] == "N" } {
473 set args [lreplace $args 0 0]
474 set selector "target [join [lindex $args 1]]"
475 if { [dg-process-target $selector] == "S" } {
476 global compiler_conditional_xfail_data
477 set compiler_conditional_xfail_data [lreplace $args 1 1 "*-*-*"]
481 # We need to make sure that additional_* are cleared out after every
482 # test. It is not enough to clear them out *before* the next test run
483 # because gcc-target-compile gets run directly from some .exp files
484 # (outside of any test). (Those uses should eventually be eliminated.)
486 # Because the DG framework doesn't provide a hook that is run at the
487 # end of a test, we must replace dg-test with a wrapper.
489 if { [info procs saved-dg-test] == [list] } {
490 rename dg-test saved-dg-test
492 proc dg-test { args } {
493 global additional_files
494 global additional_sources
495 global additional_prunes
497 global compiler_conditional_xfail_data
499 if { [ catch { eval saved-dg-test $args } errmsg ] } {
500 set saved_info $errorInfo
501 set additional_files ""
502 set additional_sources ""
503 set additional_prunes ""
504 if [info exists compiler_conditional_xfail_data] {
505 unset compiler_conditional_xfail_data
507 error $errmsg $saved_info
509 set additional_files ""
510 set additional_sources ""
511 set additional_prunes ""
512 if [info exists compiler_conditional_xfail_data] {
513 unset compiler_conditional_xfail_data
518 # Intercept the call to the DejaGnu version of dg-process-target to
519 # support use of an effective-target keyword in place of a list of
520 # target triplets to xfail or skip a test.
522 # selector is one of:
523 # xfail target-triplet-1 ...
524 # xfail effective-target-keyword
525 # target target-triplet-1 ...
526 # target effective-target-keyword
528 # For a target list the result is "S" if the target is selected, "N" otherwise.
529 # For an xfail list the result is "F" if the target is affected, "P" otherwise.
531 if { [info procs saved-dg-process-target] == [list] } {
532 rename dg-process-target saved-dg-process-target
534 proc dg-process-target { args } {
535 verbose "replacement dg-process-target" 2
537 # Extract the 'what' keyword from the argument list.
538 set selector [string trim [lindex $args 0]]
539 if [regexp "^xfail " $selector] {
541 } elseif [regexp "^target " $selector] {
544 error "syntax error in target selector \"$selector\""
547 # Extract the rest of the list, which might be a keyword.
548 regsub "^${what}" $selector "" rest
549 set rest [string trim $rest]
551 if [is-effective-target-keyword $rest] {
552 # The selector is an effective target keyword.
553 if [is-effective-target $rest] {
554 return [expr { $what == "xfail" ? "F" : "S" }]
556 return [expr { $what == "xfail" ? "P" : "N" }]
560 # The selector is not an effective-target keyword, so process
561 # the list of target triplets.
562 return [saved-dg-process-target $selector]
566 set additional_prunes ""