1 # Copyright
(C
) 1997-2017 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 # DejaGnu
's dg-test defines extra flags that are used to compile a test.
18 # Access them for directives that need to examine all options that are
19 # used for a test, including checks for non-cached effective targets.
20 # We don't know how far up the
call chain it is but we know we
'll hit
21 # it eventually, and that we're at least
3 calls down.
23 proc current_compiler_flags
{ } {
25 while { ![info exists flags1
] } {
26 set frames
[expr $frames
+ 1]
27 upvar $frames dg
-extra
-tool
-flags flags1
29 upvar $frames tool_flags flags2
30 return "$flags1 $flags2"
33 # DejaGnu
's dg-test defines a test name that includes torture options
34 # which is used in most pass/fail messages. Grab a copy of it.
36 proc testname-for-summary { } {
37 global testname_with_flags
39 # A variable called "name" is too generic, so identify dg-test by
40 # the existence of dg-extra-tool-flags.
41 if ![info exists testname_with_flags] {
43 while { ![info exists flags] } {
44 set frames [expr $frames + 1]
45 upvar $frames dg-extra-tool-flags flags
48 # We've got the stack level
for dg
-test
; get the
variable we want.
49 upvar $frames
name name
50 set testname_with_flags $
name
52 #
If there are flags
, add an extra space to improve readability of
54 if { [llength $testname_with_flags
] > 1 } {
55 set testname_with_flags
"$testname_with_flags "
58 return "$testname_with_flags"
61 #
If this target does not support weak symbols
, skip this test.
63 proc dg
-require
-weak
{ args } {
64 set weak_available
[ check_weak_available
]
65 if { $weak_available
== -1 } {
69 if { $weak_available
!= 1 } {
70 upvar dg
-do-what dg
-do-what
71 set dg
-do-what
[list
[lindex $
{dg
-do-what
} 0] "N" "P"]
75 #
If this target does not support overriding weak symbols
, skip this
78 proc dg
-require
-weak
-override
{ args } {
79 set weak_override_available
[ check_weak_override_available
]
80 if { $weak_override_available
== -1 } {
84 if { $weak_override_available
!= 1 } {
85 upvar dg
-do-what dg
-do-what
86 set dg
-do-what
[list
[lindex $
{dg
-do-what
} 0] "N" "P"]
90 #
If this target does not support the
"visibility" attribute, skip this
93 proc dg
-require
-visibility
{ args } {
94 set visibility_available
[ check_visibility_available
[lindex $
args 1 ] ]
95 if { $visibility_available
== -1 } {
99 if { $visibility_available
!= 1 } {
100 upvar dg
-do-what dg
-do-what
101 set dg
-do-what
[list
[lindex $
{dg
-do-what
} 0] "N" "P"]
105 #
If this target does not support the
"alias" attribute, skip this
108 proc dg
-require
-alias
{ args } {
109 set alias_available
[ check_alias_available
]
110 if { $alias_available
== -1 } {
114 if { $alias_available
< 2 } {
115 upvar dg
-do-what dg
-do-what
116 set dg
-do-what
[list
[lindex $
{dg
-do-what
} 0] "N" "P"]
120 #
If this target does not support the
"ifunc" attribute, skip this
123 proc dg
-require
-ifunc
{ args } {
124 if { ![ check_ifunc_available
] } {
125 upvar dg
-do-what dg
-do-what
126 set dg
-do-what
[list
[lindex $
{dg
-do-what
} 0] "N" "P"]
130 #
If this target
's linker does not support the --gc-sections flag,
133 proc dg-require-gc-sections { args } {
134 if { ![ check_gc_sections_available ] } {
135 upvar dg-do-what dg-do-what
136 set dg-do-what [list [lindex ${dg-do-what} 0] "N" "P"]
140 # If this target does not support profiling, skip this test.
142 proc dg-require-profiling { args } {
143 if { ![ check_profiling_available [lindex $args 1] ] } {
144 upvar dg-do-what dg-do-what
145 set dg-do-what [list [lindex ${dg-do-what} 0] "N" "P"]
149 # If this target does not support DLL attributes skip this test.
151 proc dg-require-dll { args } {
152 # As a special case, the mcore-*-elf supports these attributes.
153 # All Symbian OS targets also support these attributes.
154 if { [istarget mcore-*-elf]
155 || [istarget *-*-symbianelf] } {
158 # PE/COFF targets support dllimport/dllexport.
159 if { [gcc_target_object_format] == "pe" } {
163 upvar dg-do-what dg-do-what
164 set dg-do-what [list [lindex ${dg-do-what} 0] "N" "P"]
167 # If this host does not support an ASCII locale, skip this test.
169 proc dg-require-ascii-locale { args } {
170 if { ![ check_ascii_locale_available] } {
171 upvar dg-do-what dg-do-what
172 set dg-do-what [list [lindex ${dg-do-what} 0] "N" "P"]
176 proc dg-require-iconv { args } {
177 if { ![ check_iconv_available ${args} ] } {
178 upvar dg-do-what dg-do-what
179 set dg-do-what [list [lindex ${dg-do-what} 0] "N" "P"]
183 # If this target does not support named sections skip this test.
185 proc dg-require-named-sections { args } {
186 if { ![ check_named_sections_available ] } {
187 upvar dg-do-what dg-do-what
188 set dg-do-what [list [lindex ${dg-do-what} 0] "N" "P"]
192 # If the target does not match the required effective target, skip this test.
193 # Only apply this if the optional selector matches.
195 proc dg-require-effective-target { args } {
196 set args [lreplace $args 0 0]
197 # Verify the number of arguments. The last is optional.
198 if { [llength $args] < 1 || [llength $args] > 2 } {
199 error "syntax error, need a single effective-target keyword with optional selector"
202 # Don't bother
if we
're already skipping the test.
203 upvar dg-do-what dg-do-what
204 if { [lindex ${dg-do-what} 1] == "N" } {
208 # Evaluate selector if present.
209 if { [llength $args] == 2 } {
210 switch [dg-process-target-1 [lindex $args 1]] {
216 if { ![is-effective-target [lindex $args 0]] } {
217 set dg-do-what [list [lindex ${dg-do-what} 0] "N" "P"]
221 # If this target does not have fork, skip this test.
223 proc dg-require-fork { args } {
224 if { ![check_fork_available] } {
225 upvar dg-do-what dg-do-what
226 set dg-do-what [list [lindex ${dg-do-what} 0] "N" "P"]
230 # If this target does not have mkfifo, skip this test.
232 proc dg-require-mkfifo { args } {
233 if { ![check_mkfifo_available] } {
234 upvar dg-do-what dg-do-what
235 set dg-do-what [list [lindex ${dg-do-what} 0] "N" "P"]
239 # If this target does not use __cxa_atexit, skip this test.
241 proc dg-require-cxa-atexit { args } {
242 if { ![ check_cxa_atexit_available ] } {
243 upvar dg-do-what dg-do-what
244 set dg-do-what [list [lindex ${dg-do-what} 0] "N" "P"]
248 # If the host is remote rather than the same as the build system, skip
249 # this test. Some tests are incompatible with DejaGnu's handling of
250 # remote hosts
, which involves copying the source file to the host and
251 # compiling it with a relative path and
"-o a.out".
253 proc dg
-require
-host
-local
{ args } {
254 if [ is_remote host
] {
255 upvar dg
-do-what dg
-do-what
256 set dg
-do-what
[list
[lindex $
{dg
-do-what
} 0] "N" "P"]
260 proc dg
-require
-linker
-plugin
{ args } {
261 set linker_plugin_available
[ check_linker_plugin_available
]
262 if { $linker_plugin_available
== 0 } {
263 upvar dg
-do-what dg
-do-what
264 set dg
-do-what
[list
[lindex $
{dg
-do-what
} 0] "N" "P"]
268 #
If this target does not support the
"stack-check" option, skip this
271 proc dg
-require
-stack
-check
{ args } {
272 set stack_check_available
[ check_stack_check_available
[lindex $
args 1 ] ]
273 if { $stack_check_available
== -1 } {
277 if { $stack_check_available
!= 1 } {
278 upvar dg
-do-what dg
-do-what
279 set dg
-do-what
[list
[lindex $
{dg
-do-what
} 0] "N" "P"]
283 # Add
any target
-specific flags needed
for accessing the given list
284 # of features. This must come after all dg
-options.
286 proc dg
-add
-options
{ args } {
287 upvar dg
-extra
-tool
-flags extra
-tool
-flags
289 foreach
arg [lrange $
args 1 end
] {
290 if { [info procs add_options_for_$
arg] != "" } {
291 set extra
-tool
-flags \
292 [eval
[list add_options_for_$
arg $
{extra
-tool
-flags
}]]
294 error
"Unrecognized option type: $arg"
299 # Compare flags
for a test directive against flags that will be used to
300 #
compile the test
: multilib flags
, flags
for torture options
, and either
301 # the default flags
for this group of tests or flags specified with a
302 # previous dg
-options directive.
304 proc check
-flags
{ args } {
305 global compiler_flags
307 global TEST_ALWAYS_FLAGS
309 # The
args are within another list
; pull them out.
310 set args [lindex $
args 0]
312 # Start the list with a dummy tool
name so the list will match
"*"
313 #
if there are no flags.
314 set compiler_flags
" toolname "
315 append compiler_flags
[current_compiler_flags
]
316 #
If running a subset of the test suite
, $TOOL_OPTIONS may not exist.
317 catch
{append compiler_flags
" $TOOL_OPTIONS "}
318 #
If running a subset of the test suite
, $TEST_ALWAYS_FLAGS may not exist.
319 catch
{append compiler_flags
" $TEST_ALWAYS_FLAGS "}
320 set dest
[target_info
name]
321 if [board_info $dest
exists cflags
] {
322 append compiler_flags
"[board_info $dest cflags] "
324 if [board_info $dest
exists multilib_flags
] {
325 append compiler_flags
"[board_info $dest multilib_flags] "
328 # The next two arguments are optional.
If they were not specified
,
330 if { [llength $
args] == 2 } {
331 lappend $
args [list
"*"]
333 if { [llength $
args] == 3 } {
334 lappend $
args [list
""]
337 #
If the option strings are the defaults
, or the same as the
338 # defaults
, there is no need to
call check_conditional_xfail to
339 # compare them to the actual options.
340 if { [string compare
[lindex $
args 2] "*"] == 0
341 && [string compare
[lindex $
args 3] "" ] == 0 } {
344 # The target list might be an effective
-target keyword
, so replace
345 # the original list with
"*-*-*", since we already know it matches.
346 set result
[check_conditional_xfail
[lreplace $
args 1 1 "*-*-*"]]
349 #
Any value in this
variable was left over from an earlier test.
350 set compiler_flags
""
355 # Skip the test
(report it as UNSUPPORTED
) if the target list and
356 # included flags are matched and the excluded flags are not matched.
358 # The first
argument is the line number of the dg
-skip
-if directive
359 # within the test file. Remaining arguments are as
for xfail lists
:
360 # message
{ targets
} { include } { exclude
}
362 # This tests against multilib flags plus either the default flags
for this
363 # group of tests or flags specified with a previous dg
-options command.
365 proc dg
-skip
-if { args } {
366 # Verify the number of arguments. The last two are optional.
367 set args [lreplace $
args 0 0]
368 if { [llength $
args] < 2 ||
[llength $
args] > 4 } {
369 error
"dg-skip-if 2: need 2, 3, or 4 arguments"
372 # Don
't bother if we're already skipping the test.
373 upvar dg
-do-what dg
-do-what
374 if { [lindex $
{dg
-do-what
} 1] == "N" } {
378 set selector
[list target
[lindex $
args 1]]
379 if { [dg
-process
-target
-1 $selector
] == "S" } {
380 if [check
-flags $
args] {
381 upvar dg
-do-what dg
-do-what
382 set dg
-do-what
[list
[lindex $
{dg
-do-what
} 0] "N" "P"]
387 # Like check_conditional_xfail
, but callable from a dg test.
389 proc dg
-xfail
-if { args } {
390 # Verify the number of arguments. The last three are optional.
391 set args [lreplace $
args 0 0]
392 if { [llength $
args] < 2 ||
[llength $
args] > 4 } {
393 error
"dg-xfail-if: need 2, 3, or 4 arguments"
396 # Don
't change anything if we're already skipping the test.
397 upvar dg
-do-what dg
-do-what
398 if { [lindex $
{dg
-do-what
} 1] == "N" } {
402 set selector
[list target
[lindex $
args 1]]
403 if { [dg
-process
-target
-1 $selector
] == "S" } {
404 global compiler_conditional_xfail_data
406 # The target list might be an effective
-target keyword. Replace
407 # the original list with
"*-*-*", since we already know it matches.
408 set args [lreplace $
args 1 1 "*-*-*"]
410 # Supply default
values for unspecified optional arguments.
411 if { [llength $
args] == 2 } {
412 lappend $
args [list
"*"]
414 if { [llength $
args] == 3 } {
415 lappend $
args [list
""]
418 set compiler_conditional_xfail_data $
args
422 # Like dg
-xfail
-if but
for the
execute step.
424 proc dg
-xfail
-run
-if { args } {
425 # Verify the number of arguments. The last two are optional.
426 set args [lreplace $
args 0 0]
427 if { [llength $
args] < 2 ||
[llength $
args] > 4 } {
428 error
"dg-xfail-run-if: need 2, 3, or 4 arguments"
431 # Don
't bother if we're already skipping the test.
432 upvar dg
-do-what dg
-do-what
433 if { [lindex $
{dg
-do-what
} 1] == "N" } {
437 set selector
[list target
[lindex $
args 1]]
438 if { [dg
-process
-target
-1 $selector
] == "S" } {
439 if [check
-flags $
args] {
440 upvar dg
-do-what dg
-do-what
441 set dg
-do-what
[list
[lindex $
{dg
-do-what
} 0] "S" "F"]
446 # Record whether the
program is expected to
return a nonzero
status.
450 proc dg
-shouldfail
{ args } {
451 # Don
't bother if we're already skipping the test.
452 upvar dg
-do-what dg
-do-what
453 if { [lindex $
{dg
-do-what
} 1] == "N" } {
459 set args [lreplace $
args 0 0]
460 if { [llength $
args] > 1 } {
461 set selector
[list target
[lindex $
args 1]]
462 if { [dg
-process
-target
-1 $selector
] == "S" } {
463 # The target matches
, now check the flags.
464 if [check
-flags $
args] {
473 # Intercept the
call to the DejaGnu version of dg
-process
-target to
474 # support use of an effective
-target keyword in place of a list of
475 # target triplets to xfail or skip a test.
477 # The
argument to dg
-process
-target is the keyword
"target" or "xfail"
478 # followed by a selector
:
479 # target
-triplet
-1 ...
480 # effective
-target
-keyword
481 # selector
-expression
483 #
For a target list the result is
"S" if the target is selected, "N" otherwise.
484 #
For an xfail list the result is
"F" if the target is affected, "P" otherwise.
486 # In contexts that allow either
"target" or "xfail" the argument can be
487 # target selector1 xfail selector2
488 # which returns
"N" if selector1 is not selected, otherwise the result of
491 # A selector expression appears within curly braces and uses a single logical
492 # operator
: !, &&, or ||. An operand is another selector expression
, an
493 # effective
-target keyword
, or a list of target triplets within quotes or
496 if { [info procs saved
-dg
-process
-target
] == [list
] } {
497 rename dg
-process
-target saved
-dg
-process
-target
499 # Evaluate an operand within a selector expression.
500 proc selector_opd
{ op
} {
501 set selector
"target"
503 set answer
[ expr
{ [dg
-process
-target $selector
] == "S" } ]
504 verbose
"selector_opd: `$op' $answer" 2
508 # Evaluate a target triplet list within a selector expression.
509 # Unlike other operands
, this needs to be expanded from a list to
510 # the same string as
"target".
511 proc selector_list
{ op
} {
512 set selector
"target [join $op]"
513 set answer
[ expr
{ [dg
-process
-target $selector
] == "S" } ]
514 verbose
"selector_list: `$op' $answer" 2
518 # Evaluate a selector expression.
519 proc selector_expression
{ exp
} {
520 if { [llength $exp
] == 2 } {
521 if [string match
"!" [lindex $exp 0]] {
522 set op1
[lindex $exp
1]
523 set answer
[expr
{ ! [selector_opd $op1
] }]
525 # Assume it
's a list of target triplets.
526 set answer [selector_list $exp]
528 } elseif { [llength $exp] == 3 } {
529 set op1 [lindex $exp 0]
530 set opr [lindex $exp 1]
531 set op2 [lindex $exp 2]
532 if [string match "&&" $opr] {
533 set answer [expr { [selector_opd $op1] && [selector_opd $op2] }]
534 } elseif [string match "||" $opr] {
535 set answer [expr { [selector_opd $op1] || [selector_opd $op2] }]
537 # Assume it's a list of target triplets.
538 set answer
[selector_list $exp
]
541 # Assume it
's a list of target triplets.
542 set answer [selector_list $exp]
545 verbose "selector_expression: `$exp' $answer
" 2
549 # Evaluate
"target selector" or "xfail selector".
551 proc dg
-process
-target
-1 { args } {
552 verbose
"dg-process-target-1: `$args'" 2
554 # Extract the
'what' keyword from the
argument list.
555 set selector
[string trim
[lindex $
args 0]]
556 if [regexp
"^xfail " $selector] {
558 } elseif
[regexp
"^target " $selector] {
561 error
"syntax error in target selector \"$selector\""
564 # Extract the rest of the list
, which might be a keyword.
565 regsub
"^${what}" $selector "" rest
566 set rest
[string trim $rest
]
568 if [is
-effective
-target
-keyword $rest
] {
569 # The selector is an effective target keyword.
570 if [is
-effective
-target $rest
] {
571 return [expr
{ $what
== "xfail" ? "F" : "S" }]
573 return [expr
{ $what
== "xfail" ? "P" : "N" }]
577 if [string match
"{*}" $rest] {
578 if [selector_expression
[lindex $rest
0]] {
579 return [expr
{ $what
== "xfail" ? "F" : "S" }]
581 return [expr
{ $what
== "xfail" ? "P" : "N" }]
585 # The selector is not an effective
-target keyword
, so process
586 # the list of target triplets.
587 return [saved
-dg
-process
-target $selector
]
590 # Intercept calls to the DejaGnu function. In addition to
591 # processing
"target selector" or "xfail selector", handle
592 #
"target selector1 xfail selector2".
594 proc dg
-process
-target
{ args } {
595 verbose
"replacement dg-process-target: `$args'" 2
597 set selector
[string trim
[lindex $
args 0]]
599 #
If the
argument list contains both
'target' and
'xfail',
600 # process
'target' and
, if that succeeds
, process
'xfail'.
601 if [regexp
"^target .* xfail .*" $selector] {
602 set xfail_index
[string first
"xfail" $selector]
603 set xfail_selector
[string range $selector $xfail_index end
]
604 set target_selector
[string range $selector
0 [expr $xfail_index
-1]]
605 set target_selector
[string trim $target_selector
]
606 if { [dg
-process
-target
-1 $target_selector
] == "N" } {
609 return [dg
-process
-target
-1 $xfail_selector
]
612 return [dg
-process
-target
-1 $selector
]