1 # Copyright (C) 2009 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 3 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 GCC; see the file COPYING3. If not see
15 # <http://www.gnu.org/licenses/>.
17 # Contributed by Diego Novillo <dnovillo@google.com>
19 # Prune messages from gcc that aren't useful.
21 proc lto_prune_vis_warns { text } {
23 # Many tests that use visibility will still pass on platforms that don't support it.
24 regsub -all "(^|\n)\[^\n\]*: warning: visibility attribute not supported in this configuration; ignored\[^\n\]*" $text "" text
26 # And any stray location lines.
27 regsub -all "(^|\n)\[^\n\]*: In function \[^\n\]*" $text "" text
28 regsub -all "(^|\n)In file included from :\[^\n\]*" $text "" text
33 # lto_init -- called at the start of each subdir of tests
35 proc lto_init { args } {
38 if {[info exists args] && $args == "no-mathlib"} {
42 set dest [target_info name]
43 if [board_info $dest exists mathlib] {
44 set saved_mathlib [board_info $dest mathlib]
46 set board_info($dest,mathlib) " "
49 # Each test is run with the compiler options from this list.
50 # The default option lists can be overridden by LTO_OPTIONS="[list
51 # {opts_1} {opts_2}... {opts_n}]" where opts_i are lists of options.
52 # You can put this in the environment before site.exp is written or
53 # add it to site.exp directly.
54 if ![info exists LTO_OPTIONS] {
55 set LTO_OPTIONS [list \
65 # lto_finish -- called at the end of each subdir of tests if mathlib is
73 set dest [target_info name]
74 if [info exists saved_mathlib] {
75 set board_info($dest,mathlib) $saved_mathlib
76 } elseif [board_info $dest exists mathlib] {
77 unset board_info($dest,mathlib)
81 # Subsets of tests can be selectively disabled by members of this list:
82 # - ATTRIBUTE: disable all tests using the __attribute__ extension,
83 # - COMPLEX: disable all tests using the complex types feature,
84 # - COMPLEX_INT: disable all tests using the complex integral types extension,
85 # - VA: disable all tests using the variable number of arguments feature,
86 # - VLA_IN_STRUCT: disable all tests using the variable-length arrays as
87 # structure members extension,
88 # - ZERO_ARRAY: disable all tests using the zero-sized arrays extension.
89 # The default skip lists can be overriden by
90 # LTO_SKIPS="[list {skip_1}...{skip_n}]"
91 # where skip_i are skip identifiers. You can put this in the environment
92 # before site.exp is written or add it to site.exp directly.
93 if ![info exists LTO_SKIPS] {
94 set LTO_SKIPS [list {}]
98 set lto_skip_list $LTO_SKIPS
103 # lto-obj -- compile to an object file
105 # SOURCE is the source file
106 # DEST is the object file
107 # OPTALL is the list of compiler options to use with all tests
108 # OPTFILE is the list of compiler options to use with this file
109 # OPTSTR is the options to print with test messages
110 # XFAILDATA is the xfail data to be passed to the compiler
111 proc lto-obj { source dest optall optfile optstr xfaildata } {
114 global compiler_conditional_xfail_data
117 # Add the skip specifiers.
118 foreach skip $lto_skip_list {
119 if { ![string match $skip ""] } {
120 lappend optall "-DSKIP_$skip"
124 # Set up the options for compiling this file.
126 lappend options "additional_flags=$optall $optfile"
128 set compiler_conditional_xfail_data $xfaildata
129 set comp_output [${tool}_target_compile "$source" "$dest" object $options]
130 ${tool}_check_compile "$testcase $dest assemble" $optstr $dest $comp_output
133 # lto-link-and-maybe-run -- link the object files and run the executable
134 # if compile_type is set to "run"
136 # TESTNAME is the mixture of object files to link
137 # OBJLIST is the list of object files to link
138 # DEST is the name of the executable
139 # OPTALL is a list of compiler and linker options to use for all tests
140 # OPTFILE is a list of compiler and linker options to use for this test
141 # OPTSTR is the list of options to list in messages
142 proc lto-link-and-maybe-run { testname objlist dest optall optfile optstr } {
147 # Check that all of the objects were built successfully.
148 foreach obj [split $objlist] {
149 if ![file_on_host exists $obj] then {
150 unresolved "$testcase $testname link $optstr"
151 unresolved "$testcase $testname execute $optstr"
156 # Set up the options for linking this test.
158 lappend options "additional_flags=$optall $optfile"
160 # Link the objects into an executable.
161 set comp_output [${tool}_target_compile "$objlist" $dest executable \
164 # Prune unimportant visibility warnings before checking output.
165 set comp_output [lto_prune_vis_warns $comp_output]
167 if ![${tool}_check_compile "$testcase $testname link" "" \
168 $dest $comp_output] then {
169 unresolved "$testcase $testname execute $optstr"
173 # Return if we only needed to link.
174 if { ![string compare "link" $compile_type] } {
178 # Run the self-checking executable.
179 if ![string match "*/*" $dest] then {
182 set result [${tool}_load $dest "" ""]
183 set status [lindex $result 0]
184 if { $status == "pass" } then {
185 file_on_host delete $dest
187 $status "$testcase $testname execute $optstr"
190 # lto-get-options-main -- get target requirements for a test and
191 # options for the primary source file and the test as a whole
193 # SRC is the full pathname of the primary source file.
194 proc lto-get-options-main { src } {
196 global dg-extra-ld-options
197 global dg-suppress-ld-options
199 set dg-extra-ld-options ""
200 set dg-suppress-ld-options ""
202 # dg-options sets a variable called dg-extra-tool-flags.
203 set dg-extra-tool-flags ""
205 # dg-options sets a variable called tool_flags.
208 # dg-require-* sets dg-do-what.
209 upvar dg-do-what dg-do-what
210 upvar dg-final-code dg-final-code
213 set tmp [dg-get-options $src]
214 verbose "getting options for $src: $tmp"
216 set cmd [lindex $op 0]
217 verbose "cmd is $cmd"
218 if { [string match "dg-skip-if" $cmd] \
219 || [string match "dg-require-*" $cmd] } {
220 set status [catch "$op" errmsg]
221 if { $status != 0 } {
222 perror "src: $errmsg for \"$op\"\n"
223 unresolved "$src: $errmsg for \"$op\""
226 } elseif { [string match "dg-lto-options" $cmd] } {
227 set op [lreplace $op 0 0 "dg-options"]
228 set status [catch "$op" errmsg]
229 if { $status != 0 } {
230 perror "src: $errmsg for \"$op\"\n"
231 unresolved "$src: $errmsg for \"$op\""
234 } elseif { ![string compare "dg-xfail-if" $cmd] \
235 || ![string compare "dg-options" $cmd] } {
236 warning "lto.exp does not support $cmd in primary source file"
237 } elseif { ![string compare "dg-lto-do" $cmd] } {
238 if { [llength $op] > 3 } {
239 set kw [lindex [lindex $op 3] 0]
240 if [string match "target" $kw] {
241 perror "$src: dg-lto-do does not support \"target\""
242 } elseif [string match "xfail" $kw] {
243 perror "$src: dg-lto-do does not support \"xfail\""
245 perror "$src: dg-lto-do takes a single argument"
248 set dgdo [lindex $op 2]
249 verbose "dg-lto-do command for \"$op\" is $dgdo"
250 if { ![string compare "assemble" $dgdo] } {
251 set compile_type "assemble"
252 } elseif { ![string compare "run" $dgdo] } {
253 set compile_type "run"
254 } elseif { ![string compare "link" $dgdo] } {
255 set compile_type "link"
257 warning "lto.exp does not support dg-lto-do $dgdo"
259 } elseif { ![string compare "dg-extra-ld-options" $cmd] } {
260 set dg-extra-ld-options [lindex $op 2]
261 verbose "dg-extra-ld-options for main is ${dg-extra-ld-options}"
262 } elseif { ![string compare "dg-suppress-ld-options" $cmd] } {
263 set dg-suppress-ld-options [lindex $op 2]
265 "dg-suppress-ld-options for main is ${dg-suppress-ld-options}"
266 } elseif { ![string compare "dg-final" $cmd] } {
267 if { [llength $op] > 3 } {
268 error "[lindex $op 0]: too many arguments"
270 append dg-final-code "[lindex $op 2]\n"
273 # Ignore unrecognized dg- commands, but warn about them.
274 warning "lto.exp does not support $cmd"
278 # Return flags to use for compiling the primary source file and for
280 verbose "dg-extra-tool-flags for main is ${dg-extra-tool-flags}"
281 return ${dg-extra-tool-flags}
285 # lto-get-options -- get special tool flags to use for a secondary
288 # SRC is the full pathname of the source file.
289 # The result is a list of options to use.
291 # This code is copied from proc dg-test in dg.exp from DejaGNU.
292 proc lto-get-options { src } {
293 # dg-options sets a variable called dg-extra-tool-flags.
294 set dg-extra-tool-flags ""
296 # dg-xfail-if sets compiler_conditional_xfail_data.
297 global compiler_conditional_xfail_data
298 set compiler_conditional_xfail_data ""
300 # dg-xfail-if needs access to dg-do-what.
301 upvar dg-do-what dg-do-what
303 set tmp [dg-get-options $src]
305 set cmd [lindex $op 0]
306 if { ![string compare "dg-options" $cmd] \
307 || ![string compare "dg-xfail-if" $cmd] } {
308 set status [catch "$op" errmsg]
309 if { $status != 0 } {
310 perror "src: $errmsg for \"$op\"\n"
311 unresolved "$src: $errmsg for \"$op\""
314 } elseif { [string match "dg-require-*" $cmd] } {
315 warning "lto.exp does not support $cmd in secondary source files"
317 # Ignore unrecognized dg- commands, but warn about them.
318 warning "lto.exp does not support $cmd in secondary source files"
322 return ${dg-extra-tool-flags}
325 # lto-execute -- compile multi-file tests
327 # SRC1 is the full pathname of the main file of the testcase.
328 # SID identifies a test suite in the names of temporary files.
329 proc lto-execute { src1 sid } {
331 global lto_option_list
336 global compiler_conditional_xfail_data
337 global dg-do-what-default
339 global dg-extra-ld-options
340 global dg-suppress-ld-options
344 # Get extra flags for this test from the primary source file, and
345 # process other dg-* options that this suite supports. Warn about
347 verbose "lto-execute: $src1" 1
348 set compile_type "run"
349 set dg-do-what [list ${dg-do-what-default} "" P]
350 set extra_flags(0) [lto-get-options-main $src1]
351 set compile_xfail(0) ""
353 # If the main file defines dg-options, those flags are used to
354 # overwrite the default lto_option_list taken from LTO_OPTIONS.
355 if { [string length $extra_flags(0)] > 0 } {
356 set lto_option_list $extra_flags(0)
357 set extra_flags(0) ""
359 set lto_option_list $LTO_OPTIONS
362 # Check whether this test is supported for this target.
363 if { [lindex ${dg-do-what} 1 ] == "N" } {
365 verbose "$src1 not supported on this target, skipping it" 3
369 # Set up the names of the other source files.
370 set dir [file dirname $src1]
371 set base [file rootname $src1]
372 set base [string range $base [string length $dir] end]
373 regsub "_0" $base "" base
374 regsub "/" $base "" base
379 set names [glob -nocomplain -types f -- "${dir}/${base}_${i}.*"]
380 if { [llength ${names}] > 1 } {
381 warning "lto-execute: more than one file matched ${dir}/${base}_${i}.*"
383 if { [llength ${names}] == 1 } {
384 lappend src_list [lindex ${names} 0]
392 # Use the dg-options mechanism to specify extra flags for each
393 # of the secondary files.
394 # The extra flags in each file are used to compile that file, and the
395 # extra flags in *_0.* are also used for linking.
396 verbose "\tsrc_list is: $src_list"
397 for {set i 1} {$i < $num_srcs} {incr i} {
398 set extra_flags($i) [lto-get-options [lindex $src_list $i]]
399 set compile_xfail($i) $compiler_conditional_xfail_data
402 # Define the names of the object files.
404 for {set i 0} {$i < $num_srcs} {incr i} {
405 lappend obj_list "${sid}_${base}_${i}.o"
408 # Get the base name of this test, for use in messages.
409 set testcase [lindex ${src_list} 0]
411 # Remove the $srcdir and $tmpdir prefixes from $src1. (It would
412 # be possible to use "regsub" here, if we were careful to escape
413 # all regular expression characters in $srcdir and $tmpdir, but
414 # that would be more complicated that this approach.)
415 if {[string first "$srcdir/" "${testcase}"] == 0} {
416 set testcase [string range "${testcase}" [string length "$srcdir/"] end]
418 if {[string first "$tmpdir/" "$testcase"] == 0} {
419 set testcase [string range "$testcase" [string length "$tmpdir/"] end]
420 set testcase "tmpdir-$testcase"
422 regsub "_0.*" $testcase "" testcase
424 # Set up the base name of executable files so they'll be unique.
425 regsub -all "\[./\]" $testcase "-" execbase
427 # If we couldn't rip $srcdir out of `src1' then just do the best we can.
428 # The point is to reduce the unnecessary noise in the logs. Don't strip
429 # out too much because different testcases with the same name can confuse
431 if [string match "/*" $testcase] then {
432 set testcase "[file tail [file dirname $src1]]/[file tail $src1]"
435 # Loop through all of the option lists used for this test.
437 foreach option $lto_option_list {
438 verbose "Testing $testcase, $option"
440 # There's a unique name for each executable we generate.
441 set execname "${execbase}-${count}1"
444 file_on_host delete $execname
446 # Compile pieces with the compiler under test.
448 foreach src $src_list obj $obj_list {
449 lto-obj $src $obj $option $extra_flags($i) $option \
454 # Link (using the compiler under test), run, and clean up tests.
455 if { ![string compare "run" $compile_type] \
456 || ![string compare "link" $compile_type] } {
458 # Filter out any link options we were asked to suppress.
460 foreach x [split $option] {
461 if {[lsearch ${dg-suppress-ld-options} $x] == -1} {
465 set filtered [join $reduced " "]
467 lto-link-and-maybe-run \
468 "[lindex $obj_list 0]-[lindex $obj_list end]" \
469 $obj_list $execname $filtered ${dg-extra-ld-options} \
474 # Are there any further tests to perform?
475 # Note that if the program has special run-time requirements, running
476 # of the program can be delayed until here. Ditto for other situations.
477 # It would be a bit cumbersome though.
479 if ![string match ${dg-final-code} ""] {
480 regsub -all "\\\\(\[{}\])" ${dg-final-code} "\\1" dg-final-code
481 # Note that the use of `args' here makes this a varargs proc.
482 proc dg-final-proc { args } ${dg-final-code}
483 verbose "Running dg-final tests." 3
484 verbose "dg-final-proc:\n[info body dg-final-proc]" 4
485 if [catch "dg-final-proc $src1" errmsg] {
486 perror "$name: error executing dg-final: $errmsg"
487 # ??? The call to unresolved here is necessary to clear
488 # `errcnt'. What we really need is a proc like perror that
489 # doesn't set errcnt. It should also set exit_status to 1.
490 unresolved "$name: error executing dg-final: $errmsg"
494 # Clean up object files.
495 set files [glob -nocomplain ${sid}_*.o]
496 if { $files != "" } {
497 foreach objfile $files {
498 if { ![info exists gluefile] || $objfile != $gluefile } {
499 eval "file_on_host delete $objfile"
504 if { ![string compare "run" $compile_type] \
505 || ![string compare "link" $compile_type] } {
506 file_on_host delete $execname
511 # Utility for scanning a symbol in the final executable, invoked via dg-final.
512 # Call pass if pattern is present, otherwise fail.
514 # Argument 0 is the regexp to match.
515 # Argument 1 handles expected failures and the like
516 proc scan-symbol { args } {
519 upvar 2 execname execname
521 if { [llength $args] >= 2 } {
522 switch [dg-process-target [lindex $args 1]] {
525 "F" { setup_xfail "*-*-*" }
530 # Find nm like we find g++ in g++.exp.
531 if ![info exists nm] {
532 set nm [findfile $base_dir/../../../binutils/nm \
533 $base_dir/../../../binutils/nm \
534 [findfile $base_dir/../../nm $base_dir/../../nm \
535 [findfile $base_dir/nm $base_dir/nm \
537 verbose -log "nm is $nm"
540 set output_file "[glob -nocomplain $execname]"
541 if { $output_file == "" } {
542 fail "scan-symbol $args: dump file does not exist"
546 set fd [open "| $nm $output_file" r]
550 if [regexp -- [lindex $args 0] $text] {
551 pass "scan-symbol $args"
553 fail "scan-symbol $args"