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 # If this target does not support weak symbols, skip this test.
325 proc dg-require-weak { args } {
326 upvar dg-do-what dg-do-what
329 set weak_available [ check_weak_available ]
330 if { $weak_available == -1 } {
333 if { $weak_available != 1 } {
334 set dg-do-what [list [lindex ${dg-do-what} 0] "N" "P"]
339 # If this target does not support the "visibility" attribute, skip this
342 proc dg-require-visibility { args } {
343 upvar dg-do-what dg-do-what
346 set visibility_available [ check_visibility_available ]
347 if { $visibility_available == -1 } {
350 if { $visibility_available != 1 } {
351 set dg-do-what [list [lindex ${dg-do-what} 0] "N" "P"]
356 # If this target does not support the "alias" attribute, skip this
359 proc dg-require-alias { args } {
360 upvar dg-do-what dg-do-what
363 set alias_available [ check_alias_available ]
364 if { $alias_available == -1 } {
367 if { $alias_available < 2 } {
368 set dg-do-what [list [lindex ${dg-do-what} 0] "N" "P"]
373 # If this target's linker does not support the --gc-sections flag,
376 proc dg-require-gc-sections { args } {
377 if { ![ check_gc_sections_available ] } {
378 upvar dg-do-what dg-do-what
379 set dg-do-what [list [lindex ${dg-do-what} 0] "N" "P"]
384 # If this target does not support profiling, skip this test.
386 proc dg-require-profiling { args } {
387 if { ![ check_profiling_available ${args} ] } {
388 upvar dg-do-what dg-do-what
389 set dg-do-what [list [lindex ${dg-do-what} 0] "N" "P"]
394 # If this target does not support DLL attributes skip this test.
396 proc dg-require-dll { args } {
397 global target_triplet
398 # As a special case, the mcore-*-elf supports these attributes.
399 # All Symbian OS targets also support these attributes.
400 if { [string match "mcore-*-elf" $target_triplet]
401 || [string match "*-*-symbianelf" $target_triplet]} {
404 # PE/COFF targets support dllimport/dllexport.
405 if { [gcc_target_object_format] == "pe" } {
409 upvar dg-do-what dg-do-what
410 set dg-do-what [list [lindex ${dg-do-what} 0] "N" "P"]
413 proc dg-require-iconv { args } {
414 if { ![ check_iconv_available ${args} ] } {
415 upvar dg-do-what dg-do-what
416 set dg-do-what [list [lindex ${dg-do-what} 0] "N" "P"]
422 # If this target does not support named sections skip this test.
424 proc dg-require-named-sections { args } {
427 if { ![ check_named_sections_available ] } {
428 upvar dg-do-what dg-do-what
429 set dg-do-what [list [lindex ${dg-do-what} 0] "N" "P"]
433 # Prune any messages matching ARGS[1] (a regexp) from test output.
434 proc dg-prune-output { args } {
435 global additional_prunes
437 if { [llength $args] != 2 } {
438 error "[lindex $args 1]: need one argument"
442 lappend additional_prunes [lindex $args 1]
445 # Like check_conditional_xfail, but callable from a dg test.
447 proc dg-xfail-if { args } {
448 set args [lreplace $args 0 0]
449 set selector "target [join [lindex $args 1]]"
450 if { [dg-process-target $selector] == "S" } {
451 global compiler_conditional_xfail_data
452 set compiler_conditional_xfail_data $args
457 # We need to make sure that additional_* are cleared out after every
458 # test. It is not enough to clear them out *before* the next test run
459 # because gcc-target-compile gets run directly from some .exp files
460 # (outside of any test). (Those uses should eventually be eliminated.)
462 # Because the DG framework doesn't provide a hook that is run at the
463 # end of a test, we must replace dg-test with a wrapper.
465 if { [info procs saved-dg-test] == [list] } {
466 rename dg-test saved-dg-test
468 proc dg-test { args } {
469 global additional_files
470 global additional_sources
471 global additional_prunes
474 if { [ catch { eval saved-dg-test $args } errmsg ] } {
475 set saved_info $errorInfo
476 set additional_files ""
477 set additional_sources ""
478 set additional_prunes ""
479 error $errmsg $saved_info
481 set additional_files ""
482 set additional_sources ""
483 set additional_prunes ""
486 set additional_prunes ""