1 # Copyright (C) 1997, 1999, 2000, 2003, 2004, 2005, 2007
2 # Free Software Foundation, Inc.
4 # This program is free software; you can redistribute it and/or modify
5 # it under the terms of the GNU General Public License as published by
6 # the Free Software Foundation; either version 3 of the License, or
7 # (at your option) any later version.
9 # This program is distributed in the hope that it will be useful,
10 # but WITHOUT ANY WARRANTY; without even the implied warranty of
11 # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
12 # GNU General Public License for more details.
14 # You should have received a copy of the GNU General Public License
15 # along with GCC; see the file COPYING3. If not see
16 # <http://www.gnu.org/licenses/>.
18 # If this target does not support weak symbols, skip this test.
20 proc dg-require-weak { args } {
21 set weak_available [ check_weak_available ]
22 if { $weak_available == -1 } {
26 if { $weak_available != 1 } {
27 upvar dg-do-what dg-do-what
28 set dg-do-what [list [lindex ${dg-do-what} 0] "N" "P"]
32 # If this target does not support the "visibility" attribute, skip this
35 proc dg-require-visibility { args } {
36 set visibility_available [ check_visibility_available [lindex $args 1 ] ]
37 if { $visibility_available == -1 } {
41 if { $visibility_available != 1 } {
42 upvar dg-do-what dg-do-what
43 set dg-do-what [list [lindex ${dg-do-what} 0] "N" "P"]
47 # If this target does not support the "alias" attribute, skip this
50 proc dg-require-alias { args } {
51 set alias_available [ check_alias_available ]
52 if { $alias_available == -1 } {
56 if { $alias_available < 2 } {
57 upvar dg-do-what dg-do-what
58 set dg-do-what [list [lindex ${dg-do-what} 0] "N" "P"]
62 # If this target's linker does not support the --gc-sections flag,
65 proc dg-require-gc-sections { args } {
66 if { ![ check_gc_sections_available ] } {
67 upvar dg-do-what dg-do-what
68 set dg-do-what [list [lindex ${dg-do-what} 0] "N" "P"]
72 # If this target does not support profiling, skip this test.
74 proc dg-require-profiling { args } {
75 if { ![ check_profiling_available ${args} ] } {
76 upvar dg-do-what dg-do-what
77 set dg-do-what [list [lindex ${dg-do-what} 0] "N" "P"]
81 # If this target does not support DLL attributes skip this test.
83 proc dg-require-dll { args } {
85 # As a special case, the mcore-*-elf supports these attributes.
86 # All Symbian OS targets also support these attributes.
87 if { [string match "mcore-*-elf" $target_triplet]
88 || [string match "*-*-symbianelf" $target_triplet]} {
91 # PE/COFF targets support dllimport/dllexport.
92 if { [gcc_target_object_format] == "pe" } {
96 upvar dg-do-what dg-do-what
97 set dg-do-what [list [lindex ${dg-do-what} 0] "N" "P"]
100 proc dg-require-iconv { args } {
101 if { ![ check_iconv_available ${args} ] } {
102 upvar dg-do-what dg-do-what
103 set dg-do-what [list [lindex ${dg-do-what} 0] "N" "P"]
107 # If this target does not support named sections skip this test.
109 proc dg-require-named-sections { args } {
110 if { ![ check_named_sections_available ] } {
111 upvar dg-do-what dg-do-what
112 set dg-do-what [list [lindex ${dg-do-what} 0] "N" "P"]
116 # If the target does not match the required effective target, skip this test.
118 proc dg-require-effective-target { args } {
119 set args [lreplace $args 0 0]
120 if { [llength $args] != 1 } {
121 error "syntax error, need a single effective-target keyword"
123 if { ![is-effective-target [lindex $args 0]] } {
124 upvar dg-do-what dg-do-what
125 set dg-do-what [list [lindex ${dg-do-what} 0] "N" "P"]
129 # If this target does not have fork, skip this test.
131 proc dg-require-fork { args } {
132 if { ![check_fork_available] } {
133 upvar dg-do-what dg-do-what
134 set dg-do-what [list [lindex ${dg-do-what} 0] "N" "P"]
138 # If this target does not have mkfifo, skip this test.
140 proc dg-require-mkfifo { args } {
141 if { ![check_mkfifo_available] } {
142 upvar dg-do-what dg-do-what
143 set dg-do-what [list [lindex ${dg-do-what} 0] "N" "P"]
147 # If this target does not use __cxa_atexit, skip this test.
149 proc dg-require-cxa-atexit { args } {
150 if { ![ check_cxa_atexit_available ] } {
151 upvar dg-do-what dg-do-what
152 set dg-do-what [list [lindex ${dg-do-what} 0] "N" "P"]
156 # If the host is remote rather than the same as the build system, skip
157 # this test. Some tests are incompatible with DejaGnu's handling of
158 # remote hosts, which involves copying the source file to the host and
159 # compiling it with a relative path and "-o a.out".
161 proc dg-require-host-local { args } {
162 if [ is_remote host ] {
163 upvar dg-do-what dg-do-what
164 set dg-do-what [list [lindex ${dg-do-what} 0] "N" "P"]
168 # Add any target-specific flags needed for accessing the given list
169 # of features. This must come after all dg-options.
171 proc dg-add-options { args } {
172 upvar dg-extra-tool-flags extra-tool-flags
174 foreach arg [lrange $args 1 end] {
175 if { [info procs add_options_for_$arg] != "" } {
176 set extra-tool-flags \
177 [eval [list add_options_for_$arg ${extra-tool-flags}]]
179 error "Unrecognized option type: $arg"
184 # Check the flags with which the test will be run against options in
185 # a test directive that will skip or xfail that test. The DejaGnu proc
186 # check_conditional_xfail will look at the options in compiler_flags, so
187 # set that up for this test based on flags we know about.
189 proc check_test_flags { args } {
190 global compiler_flags
191 upvar 2 dg-extra-tool-flags extra_tool_flags
193 # Pull the args out of the enclosing list.
194 set args [lindex $args 0]
196 # Start the list with a dummy tool name so the list will match "*"
197 # if there are no flags.
198 set compiler_flags " toolname "
199 append compiler_flags $extra_tool_flags
200 set dest [target_info name]
201 if [board_info $dest exists multilib_flags] {
202 append compiler_flags "[board_info $dest multilib_flags] "
205 set answer [check_conditional_xfail $args]
207 # Any value in this variable originally was left over from an earlier test.
208 set compiler_flags ""
210 verbose "check_test_flags: $args $answer" 2
214 # Compare flags for a test directive against flags that will be used to
215 # compile the test: multilib flags, flags for torture options, and either
216 # the default flags for this group of tests or flags specified with a
217 # previous dg-options directive.
219 proc check-flags { args } {
220 global compiler_flags
222 # These variables are from DejaGnu's dg-test.
223 upvar dg-extra-tool-flags extra_tool_flags
224 upvar tool_flags tool_flags
226 # The args are within another list; pull them out.
227 set args [lindex $args 0]
229 # Start the list with a dummy tool name so the list will match "*"
230 # if there are no flags.
231 set compiler_flags " toolname "
232 append compiler_flags $extra_tool_flags
233 append compiler_flags $tool_flags
234 # If running a subset of the test suite, $TOOL_OPTIONS may not exist.
235 catch {append compiler_flags " $TOOL_OPTIONS "}
236 set dest [target_info name]
237 if [board_info $dest exists multilib_flags] {
238 append compiler_flags "[board_info $dest multilib_flags] "
241 # The target list might be an effective-target keyword, so replace
242 # the original list with "*-*-*", since we already know it matches.
243 set result [check_conditional_xfail [lreplace $args 1 1 "*-*-*"]]
245 # Any value in this variable was left over from an earlier test.
246 set compiler_flags ""
251 # Skip the test (report it as UNSUPPORTED) if the target list and
252 # included flags are matched and the excluded flags are not matched.
254 # The first argument is the line number of the dg-skip-if directive
255 # within the test file. Remaining arguments are as for xfail lists:
256 # message { targets } { include } { exclude }
258 # This tests against multilib flags plus either the default flags for this
259 # group of tests or flags specified with a previous dg-options command.
261 proc dg-skip-if { args } {
262 # Don't bother if we're already skipping the test.
263 upvar dg-do-what dg-do-what
264 if { [lindex ${dg-do-what} 1] == "N" } {
268 set args [lreplace $args 0 0]
270 set selector [list target [lindex $args 1]]
271 if { [dg-process-target $selector] == "S" } {
272 # These are defined in DejaGnu's dg-test, needed by check-flags.
273 upvar dg-extra-tool-flags dg-extra-tool-flags
274 upvar tool_flags tool_flags
276 if [check-flags $args] {
277 upvar dg-do-what dg-do-what
278 set dg-do-what [list [lindex ${dg-do-what} 0] "N" "P"]
283 # Like check_conditional_xfail, but callable from a dg test.
285 proc dg-xfail-if { args } {
286 # Don't change anything if we're already skipping the test.
287 upvar dg-do-what dg-do-what
288 if { [lindex ${dg-do-what} 1] == "N" } {
292 set args [lreplace $args 0 0]
293 set selector [list target [lindex $args 1]]
294 if { [dg-process-target $selector] == "S" } {
295 global compiler_conditional_xfail_data
296 set compiler_conditional_xfail_data [lreplace $args 1 1 "*-*-*"]
300 # Like dg-xfail-if but for the execute step.
302 proc dg-xfail-run-if { args } {
303 # Don't bother if we're already skipping the test.
304 upvar dg-do-what dg-do-what
305 if { [lindex ${dg-do-what} 1] == "N" } {
309 set args [lreplace $args 0 0]
311 set selector [list target [lindex $args 1]]
312 if { [dg-process-target $selector] == "S" } {
313 # These are defined in DejaGnu's dg-test, needed by check-flags.
314 upvar dg-extra-tool-flags dg-extra-tool-flags
315 upvar tool_flags tool_flags
317 if [check-flags $args] {
318 upvar dg-do-what dg-do-what
319 set dg-do-what [list [lindex ${dg-do-what} 0] "S" "F"]
324 # Record whether the program is expected to return a nonzero status.
328 proc dg-shouldfail { args } {
329 # Don't bother if we're already skipping the test.
330 upvar dg-do-what dg-do-what
331 if { [lindex ${dg-do-what} 1] == "N" } {
337 set args [lreplace $args 0 0]
338 if { [llength $args] > 1 } {
339 set selector [list target [lindex $args 1]]
340 if { [dg-process-target $selector] == "S" } {
341 # The target matches, now check the flags. These variables
342 # are defined in DejaGnu's dg-test, needed by check-flags.
343 upvar dg-extra-tool-flags dg-extra-tool-flags
344 upvar tool_flags tool_flags
346 if [check-flags $args] {
355 # Intercept the call to the DejaGnu version of dg-process-target to
356 # support use of an effective-target keyword in place of a list of
357 # target triplets to xfail or skip a test.
359 # selector is one of:
360 # xfail target-triplet-1 ...
361 # xfail effective-target-keyword
362 # xfail selector-expression
363 # target target-triplet-1 ...
364 # target effective-target-keyword
365 # target selector-expression
367 # For a target list the result is "S" if the target is selected, "N" otherwise.
368 # For an xfail list the result is "F" if the target is affected, "P" otherwise.
370 # A selector expression appears within curly braces and uses a single logical
371 # operator: !, &&, or ||. An operand is another selector expression, an
372 # effective-target keyword, or a list of target triplets within quotes or
375 if { [info procs saved-dg-process-target] == [list] } {
376 rename dg-process-target saved-dg-process-target
378 # Evaluate an operand within a selector expression.
379 proc selector_opd { op } {
380 set selector "target"
382 set answer [ expr { [dg-process-target $selector] == "S" } ]
383 verbose "selector_opd: `$op' $answer" 2
387 # Evaluate a target triplet list within a selector expression.
388 # Unlike other operands, this needs to be expanded from a list to
389 # the same string as "target".
390 proc selector_list { op } {
391 set selector "target [join $op]"
392 set answer [ expr { [dg-process-target $selector] == "S" } ]
393 verbose "selector_list: `$op' $answer" 2
397 # Evaluate a selector expression.
398 proc selector_expression { exp } {
399 if { [llength $exp] == 2 } {
400 if [string match "!" [lindex $exp 0]] {
401 set op1 [lindex $exp 1]
402 set answer [expr { ! [selector_opd $op1] }]
404 # Assume it's a list of target triplets.
405 set answer [selector_list $exp]
407 } elseif { [llength $exp] == 3 } {
408 set op1 [lindex $exp 0]
409 set opr [lindex $exp 1]
410 set op2 [lindex $exp 2]
411 if [string match "&&" $opr] {
412 set answer [expr { [selector_opd $op1] && [selector_opd $op2] }]
413 } elseif [string match "||" $opr] {
414 set answer [expr { [selector_opd $op1] || [selector_opd $op2] }]
416 # Assume it's a list of target triplets.
417 set answer [selector_list $exp]
420 # Assume it's a list of target triplets.
421 set answer [selector_list $exp]
424 verbose "selector_expression: `$exp' $answer" 2
428 proc dg-process-target { args } {
429 verbose "replacement dg-process-target: `$args'" 2
431 # Extract the 'what' keyword from the argument list.
432 set selector [string trim [lindex $args 0]]
433 if [regexp "^xfail " $selector] {
435 } elseif [regexp "^target " $selector] {
438 error "syntax error in target selector \"$selector\""
441 # Extract the rest of the list, which might be a keyword.
442 regsub "^${what}" $selector "" rest
443 set rest [string trim $rest]
445 if [is-effective-target-keyword $rest] {
446 # The selector is an effective target keyword.
447 if [is-effective-target $rest] {
448 return [expr { $what == "xfail" ? "F" : "S" }]
450 return [expr { $what == "xfail" ? "P" : "N" }]
454 if [string match "{*}" $rest] {
455 if [selector_expression [lindex $rest 0]] {
456 return [expr { $what == "xfail" ? "F" : "S" }]
458 return [expr { $what == "xfail" ? "P" : "N" }]
462 # The selector is not an effective-target keyword, so process
463 # the list of target triplets.
464 return [saved-dg-process-target $selector]