1 # Copyright
(C
) 1997, 1999, 2000, 2003, 2004, 2005, 2007, 2008, 2009, 2010
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 # DejaGnu
's dg-test defines extra flags that are used to compile a test.
19 # Access them for directives that need to examine all options that are
20 # used for a test, including checks for non-cached effective targets.
21 # We don't know how far up the
call chain it is but we know we
'll hit
22 # it eventually, and that we're at least
3 calls down.
24 proc current_compiler_flags
{ } {
26 while { ![info exists flags1
] } {
27 set frames
[expr $frames
+ 1]
28 upvar $frames dg
-extra
-tool
-flags flags1
30 upvar $frames tool_flags flags2
31 return "$flags1 $flags2"
34 #
If this target does not support weak symbols
, skip this test.
36 proc dg
-require
-weak
{ args } {
37 set weak_available
[ check_weak_available
]
38 if { $weak_available
== -1 } {
42 if { $weak_available
!= 1 } {
43 upvar dg
-do-what dg
-do-what
44 set dg
-do-what
[list
[lindex $
{dg
-do-what
} 0] "N" "P"]
48 #
If this target does not support overriding weak symbols
, skip this
51 proc dg
-require
-weak
-override
{ args } {
52 set weak_override_available
[ check_weak_override_available
]
53 if { $weak_override_available
== -1 } {
57 if { $weak_override_available
!= 1 } {
58 upvar dg
-do-what dg
-do-what
59 set dg
-do-what
[list
[lindex $
{dg
-do-what
} 0] "N" "P"]
63 #
If this target does not support the
"visibility" attribute, skip this
66 proc dg
-require
-visibility
{ args } {
67 set visibility_available
[ check_visibility_available
[lindex $
args 1 ] ]
68 if { $visibility_available
== -1 } {
72 if { $visibility_available
!= 1 } {
73 upvar dg
-do-what dg
-do-what
74 set dg
-do-what
[list
[lindex $
{dg
-do-what
} 0] "N" "P"]
78 #
If this target does not support the
"alias" attribute, skip this
81 proc dg
-require
-alias
{ args } {
82 set alias_available
[ check_alias_available
]
83 if { $alias_available
== -1 } {
87 if { $alias_available
< 2 } {
88 upvar dg
-do-what dg
-do-what
89 set dg
-do-what
[list
[lindex $
{dg
-do-what
} 0] "N" "P"]
93 #
If this target
's linker does not support the --gc-sections flag,
96 proc dg-require-gc-sections { args } {
97 if { ![ check_gc_sections_available ] } {
98 upvar dg-do-what dg-do-what
99 set dg-do-what [list [lindex ${dg-do-what} 0] "N" "P"]
103 # If this target does not support profiling, skip this test.
105 proc dg-require-profiling { args } {
106 if { ![ check_profiling_available ${args} ] } {
107 upvar dg-do-what dg-do-what
108 set dg-do-what [list [lindex ${dg-do-what} 0] "N" "P"]
112 # If this target does not support DLL attributes skip this test.
114 proc dg-require-dll { args } {
115 global target_triplet
116 # As a special case, the mcore-*-elf supports these attributes.
117 # All Symbian OS targets also support these attributes.
118 if { [string match "mcore-*-elf" $target_triplet]
119 || [string match "*-*-symbianelf" $target_triplet]} {
122 # PE/COFF targets support dllimport/dllexport.
123 if { [gcc_target_object_format] == "pe" } {
127 upvar dg-do-what dg-do-what
128 set dg-do-what [list [lindex ${dg-do-what} 0] "N" "P"]
131 proc dg-require-iconv { args } {
132 if { ![ check_iconv_available ${args} ] } {
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 support named sections skip this test.
140 proc dg-require-named-sections { args } {
141 if { ![ check_named_sections_available ] } {
142 upvar dg-do-what dg-do-what
143 set dg-do-what [list [lindex ${dg-do-what} 0] "N" "P"]
147 # If the target does not match the required effective target, skip this test.
148 # Only apply this if the optional selector matches.
150 proc dg-require-effective-target { args } {
151 set args [lreplace $args 0 0]
152 # Verify the number of arguments. The last is optional.
153 if { [llength $args] < 1 || [llength $args] > 2 } {
154 error "syntax error, need a single effective-target keyword with optional selector"
157 # Evaluate selector if present.
158 if { [llength $args] == 2 } {
159 switch [dg-process-target [lindex $args 1]] {
165 if { ![is-effective-target [lindex $args 0]] } {
166 upvar dg-do-what dg-do-what
167 set dg-do-what [list [lindex ${dg-do-what} 0] "N" "P"]
171 # If this target does not have fork, skip this test.
173 proc dg-require-fork { args } {
174 if { ![check_fork_available] } {
175 upvar dg-do-what dg-do-what
176 set dg-do-what [list [lindex ${dg-do-what} 0] "N" "P"]
180 # If this target does not have mkfifo, skip this test.
182 proc dg-require-mkfifo { args } {
183 if { ![check_mkfifo_available] } {
184 upvar dg-do-what dg-do-what
185 set dg-do-what [list [lindex ${dg-do-what} 0] "N" "P"]
189 # If this target does not use __cxa_atexit, skip this test.
191 proc dg-require-cxa-atexit { args } {
192 if { ![ check_cxa_atexit_available ] } {
193 upvar dg-do-what dg-do-what
194 set dg-do-what [list [lindex ${dg-do-what} 0] "N" "P"]
198 # If the host is remote rather than the same as the build system, skip
199 # this test. Some tests are incompatible with DejaGnu's handling of
200 # remote hosts
, which involves copying the source file to the host and
201 # compiling it with a relative path and
"-o a.out".
203 proc dg
-require
-host
-local
{ args } {
204 if [ is_remote host
] {
205 upvar dg
-do-what dg
-do-what
206 set dg
-do-what
[list
[lindex $
{dg
-do-what
} 0] "N" "P"]
210 proc dg
-require
-linker
-plugin
{ args } {
211 set linker_plugin_available
[ check_linker_plugin_available
]
212 if { $linker_plugin_available
== 0 } {
213 upvar dg
-do-what dg
-do-what
214 set dg
-do-what
[list
[lindex $
{dg
-do-what
} 0] "N" "P"]
218 # Add
any target
-specific flags needed
for accessing the given list
219 # of features. This must come after all dg
-options.
221 proc dg
-add
-options
{ args } {
222 upvar dg
-extra
-tool
-flags extra
-tool
-flags
224 foreach
arg [lrange $
args 1 end
] {
225 if { [info procs add_options_for_$
arg] != "" } {
226 set extra
-tool
-flags \
227 [eval
[list add_options_for_$
arg $
{extra
-tool
-flags
}]]
229 error
"Unrecognized option type: $arg"
234 # Compare flags
for a test directive against flags that will be used to
235 #
compile the test
: multilib flags
, flags
for torture options
, and either
236 # the default flags
for this group of tests or flags specified with a
237 # previous dg
-options directive.
239 proc check
-flags
{ args } {
240 global compiler_flags
243 # The
args are within another list
; pull them out.
244 set args [lindex $
args 0]
246 # Start the list with a dummy tool
name so the list will match
"*"
247 #
if there are no flags.
248 set compiler_flags
" toolname "
249 append compiler_flags
[current_compiler_flags
]
250 #
If running a subset of the test suite
, $TOOL_OPTIONS may not exist.
251 catch
{append compiler_flags
" $TOOL_OPTIONS "}
252 set dest
[target_info
name]
253 if [board_info $dest
exists multilib_flags
] {
254 append compiler_flags
"[board_info $dest multilib_flags] "
257 # The next two arguments are optional.
If they were not specified
,
259 if { [llength $
args] == 2 } {
260 lappend $
args [list
"*"]
262 if { [llength $
args] == 3 } {
263 lappend $
args [list
""]
266 #
If the option strings are the defaults
, or the same as the
267 # defaults
, there is no need to
call check_conditional_xfail to
268 # compare them to the actual options.
269 if { [string compare
[lindex $
args 2] "*"] == 0
270 && [string compare
[lindex $
args 3] "" ] == 0 } {
273 # The target list might be an effective
-target keyword
, so replace
274 # the original list with
"*-*-*", since we already know it matches.
275 set result
[check_conditional_xfail
[lreplace $
args 1 1 "*-*-*"]]
278 #
Any value in this
variable was left over from an earlier test.
279 set compiler_flags
""
284 # Skip the test
(report it as UNSUPPORTED
) if the target list and
285 # included flags are matched and the excluded flags are not matched.
287 # The first
argument is the line number of the dg
-skip
-if directive
288 # within the test file. Remaining arguments are as
for xfail lists
:
289 # message
{ targets
} { include } { exclude
}
291 # This tests against multilib flags plus either the default flags
for this
292 # group of tests or flags specified with a previous dg
-options command.
294 proc dg
-skip
-if { args } {
295 # Verify the number of arguments. The last two are optional.
296 set args [lreplace $
args 0 0]
297 if { [llength $
args] < 2 ||
[llength $
args] > 4 } {
298 error
"dg-skip-if 2: need 2, 3, or 4 arguments"
301 # Don
't bother if we're already skipping the test.
302 upvar dg
-do-what dg
-do-what
303 if { [lindex $
{dg
-do-what
} 1] == "N" } {
307 set selector
[list target
[lindex $
args 1]]
308 if { [dg
-process
-target $selector
] == "S" } {
309 if [check
-flags $
args] {
310 upvar dg
-do-what dg
-do-what
311 set dg
-do-what
[list
[lindex $
{dg
-do-what
} 0] "N" "P"]
316 # Like check_conditional_xfail
, but callable from a dg test.
318 proc dg
-xfail
-if { args } {
319 # Verify the number of arguments. The last three are optional.
320 set args [lreplace $
args 0 0]
321 if { [llength $
args] < 2 ||
[llength $
args] > 4 } {
322 error
"dg-xfail-if: need 2, 3, or 4 arguments"
325 # Don
't change anything if we're already skipping the test.
326 upvar dg
-do-what dg
-do-what
327 if { [lindex $
{dg
-do-what
} 1] == "N" } {
331 set selector
[list target
[lindex $
args 1]]
332 if { [dg
-process
-target $selector
] == "S" } {
333 global compiler_conditional_xfail_data
335 # The target list might be an effective
-target keyword. Replace
336 # the original list with
"*-*-*", since we already know it matches.
337 set args [lreplace $
args 1 1 "*-*-*"]
339 # Supply default
values for unspecified optional arguments.
340 if { [llength $
args] == 2 } {
341 lappend $
args [list
"*"]
343 if { [llength $
args] == 3 } {
344 lappend $
args [list
""]
347 set compiler_conditional_xfail_data $
args
351 # Like dg
-xfail
-if but
for the
execute step.
353 proc dg
-xfail
-run
-if { args } {
354 # Verify the number of arguments. The last two are optional.
355 set args [lreplace $
args 0 0]
356 if { [llength $
args] < 2 ||
[llength $
args] > 4 } {
357 error
"dg-xfail-run-if: need 2, 3, or 4 arguments"
360 # Don
't bother if we're already skipping the test.
361 upvar dg
-do-what dg
-do-what
362 if { [lindex $
{dg
-do-what
} 1] == "N" } {
366 set selector
[list target
[lindex $
args 1]]
367 if { [dg
-process
-target $selector
] == "S" } {
368 if [check
-flags $
args] {
369 upvar dg
-do-what dg
-do-what
370 set dg
-do-what
[list
[lindex $
{dg
-do-what
} 0] "S" "F"]
375 # Record whether the
program is expected to
return a nonzero
status.
379 proc dg
-shouldfail
{ args } {
380 # Don
't bother if we're already skipping the test.
381 upvar dg
-do-what dg
-do-what
382 if { [lindex $
{dg
-do-what
} 1] == "N" } {
388 set args [lreplace $
args 0 0]
389 if { [llength $
args] > 1 } {
390 set selector
[list target
[lindex $
args 1]]
391 if { [dg
-process
-target $selector
] == "S" } {
392 # The target matches
, now check the flags.
393 if [check
-flags $
args] {
402 # Intercept the
call to the DejaGnu version of dg
-process
-target to
403 # support use of an effective
-target keyword in place of a list of
404 # target triplets to xfail or skip a test.
406 # selector is one of
:
407 # xfail target
-triplet
-1 ...
408 # xfail effective
-target
-keyword
409 # xfail selector
-expression
410 # target target
-triplet
-1 ...
411 # target effective
-target
-keyword
412 # target selector
-expression
414 #
For a target list the result is
"S" if the target is selected, "N" otherwise.
415 #
For an xfail list the result is
"F" if the target is affected, "P" otherwise.
417 # A selector expression appears within curly braces and uses a single logical
418 # operator
: !, &&, or ||. An operand is another selector expression
, an
419 # effective
-target keyword
, or a list of target triplets within quotes or
422 if { [info procs saved
-dg
-process
-target
] == [list
] } {
423 rename dg
-process
-target saved
-dg
-process
-target
425 # Evaluate an operand within a selector expression.
426 proc selector_opd
{ op
} {
427 set selector
"target"
429 set answer
[ expr
{ [dg
-process
-target $selector
] == "S" } ]
430 verbose
"selector_opd: `$op' $answer" 2
434 # Evaluate a target triplet list within a selector expression.
435 # Unlike other operands
, this needs to be expanded from a list to
436 # the same string as
"target".
437 proc selector_list
{ op
} {
438 set selector
"target [join $op]"
439 set answer
[ expr
{ [dg
-process
-target $selector
] == "S" } ]
440 verbose
"selector_list: `$op' $answer" 2
444 # Evaluate a selector expression.
445 proc selector_expression
{ exp
} {
446 if { [llength $exp
] == 2 } {
447 if [string match
"!" [lindex $exp 0]] {
448 set op1
[lindex $exp
1]
449 set answer
[expr
{ ! [selector_opd $op1
] }]
451 # Assume it
's a list of target triplets.
452 set answer [selector_list $exp]
454 } elseif { [llength $exp] == 3 } {
455 set op1 [lindex $exp 0]
456 set opr [lindex $exp 1]
457 set op2 [lindex $exp 2]
458 if [string match "&&" $opr] {
459 set answer [expr { [selector_opd $op1] && [selector_opd $op2] }]
460 } elseif [string match "||" $opr] {
461 set answer [expr { [selector_opd $op1] || [selector_opd $op2] }]
463 # Assume it's a list of target triplets.
464 set answer
[selector_list $exp
]
467 # Assume it
's a list of target triplets.
468 set answer [selector_list $exp]
471 verbose "selector_expression: `$exp' $answer
" 2
475 proc dg
-process
-target
{ args } {
476 verbose
"replacement dg-process-target: `$args'" 2
478 # Extract the
'what' keyword from the
argument list.
479 set selector
[string trim
[lindex $
args 0]]
480 if [regexp
"^xfail " $selector] {
482 } elseif
[regexp
"^target " $selector] {
485 error
"syntax error in target selector \"$selector\""
488 # Extract the rest of the list
, which might be a keyword.
489 regsub
"^${what}" $selector "" rest
490 set rest
[string trim $rest
]
492 if [is
-effective
-target
-keyword $rest
] {
493 # The selector is an effective target keyword.
494 if [is
-effective
-target $rest
] {
495 return [expr
{ $what
== "xfail" ? "F" : "S" }]
497 return [expr
{ $what
== "xfail" ? "P" : "N" }]
501 if [string match
"{*}" $rest] {
502 if [selector_expression
[lindex $rest
0]] {
503 return [expr
{ $what
== "xfail" ? "F" : "S" }]
505 return [expr
{ $what
== "xfail" ? "P" : "N" }]
509 # The selector is not an effective
-target keyword
, so process
510 # the list of target triplets.
511 return [saved
-dg
-process
-target $selector
]