1 # Copyright
(C
) 1997-2018 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 have sufficient stack size, skip this test.
185 proc dg-require-stack-size { args } {
186 if { ![is-effective-target stack_size] } {
190 set stack_size [dg-effective-target-value stack_size]
191 set required [expr [lindex $args 1]]
192 if { $stack_size < $required } {
193 upvar dg-do-what dg-do-what
194 set dg-do-what [list [lindex ${dg-do-what} 0] "N" "P"]
198 # If this target does not support named sections skip this test.
200 proc dg-require-named-sections { args } {
201 if { ![ check_named_sections_available ] } {
202 upvar dg-do-what dg-do-what
203 set dg-do-what [list [lindex ${dg-do-what} 0] "N" "P"]
207 # If the target does not match the required effective target, skip this test.
208 # Only apply this if the optional selector matches.
210 proc dg-require-effective-target { args } {
211 set args [lreplace $args 0 0]
212 # Verify the number of arguments. The last is optional.
213 if { [llength $args] < 1 || [llength $args] > 2 } {
214 error "syntax error, need a single effective-target keyword with optional selector"
217 # Don't bother
if we
're already skipping the test.
218 upvar dg-do-what dg-do-what
219 if { [lindex ${dg-do-what} 1] == "N" } {
223 # Evaluate selector if present.
224 if { [llength $args] == 2 } {
225 switch [dg-process-target-1 [lindex $args 1]] {
231 if { ![is-effective-target [lindex $args 0]] } {
232 set dg-do-what [list [lindex ${dg-do-what} 0] "N" "P"]
236 # If this target does not have fork, skip this test.
238 proc dg-require-fork { args } {
239 if { ![check_fork_available] } {
240 upvar dg-do-what dg-do-what
241 set dg-do-what [list [lindex ${dg-do-what} 0] "N" "P"]
245 # If this target does not have mkfifo, skip this test.
247 proc dg-require-mkfifo { args } {
248 if { ![check_mkfifo_available] } {
249 upvar dg-do-what dg-do-what
250 set dg-do-what [list [lindex ${dg-do-what} 0] "N" "P"]
254 # If this target does not use __cxa_atexit, skip this test.
256 proc dg-require-cxa-atexit { args } {
257 if { ![ check_cxa_atexit_available ] } {
258 upvar dg-do-what dg-do-what
259 set dg-do-what [list [lindex ${dg-do-what} 0] "N" "P"]
263 # If the host is remote rather than the same as the build system, skip
264 # this test. Some tests are incompatible with DejaGnu's handling of
265 # remote hosts
, which involves copying the source file to the host and
266 # compiling it with a relative path and
"-o a.out".
268 proc dg
-require
-host
-local
{ args } {
269 if [ is_remote host
] {
270 upvar dg
-do-what dg
-do-what
271 set dg
-do-what
[list
[lindex $
{dg
-do-what
} 0] "N" "P"]
275 proc dg
-require
-linker
-plugin
{ args } {
276 set linker_plugin_available
[ check_linker_plugin_available
]
277 if { $linker_plugin_available
== 0 } {
278 upvar dg
-do-what dg
-do-what
279 set dg
-do-what
[list
[lindex $
{dg
-do-what
} 0] "N" "P"]
283 #
If this target does not support the
"stack-check" option, skip this
286 proc dg
-require
-stack
-check
{ args } {
287 set stack_check_available
[ check_stack_check_available
[lindex $
args 1 ] ]
288 if { $stack_check_available
== -1 } {
292 if { $stack_check_available
!= 1 } {
293 upvar dg
-do-what dg
-do-what
294 set dg
-do-what
[list
[lindex $
{dg
-do-what
} 0] "N" "P"]
298 # Add
any target
-specific flags needed
for accessing the given list
299 # of features. This must come after all dg
-options.
301 proc dg
-add
-options
{ args } {
302 upvar dg
-extra
-tool
-flags extra
-tool
-flags
304 foreach
arg [lrange $
args 1 end
] {
305 if { [info procs add_options_for_$
arg] != "" } {
306 set extra
-tool
-flags \
307 [eval
[list add_options_for_$
arg $
{extra
-tool
-flags
}]]
309 error
"Unrecognized option type: $arg"
314 # Compare flags
for a test directive against flags that will be used to
315 #
compile the test
: multilib flags
, flags
for torture options
, and either
316 # the default flags
for this group of tests or flags specified with a
317 # previous dg
-options directive.
319 proc check
-flags
{ args } {
320 global compiler_flags
322 global TEST_ALWAYS_FLAGS
324 # The
args are within another list
; pull them out.
325 set args [lindex $
args 0]
327 # Start the list with a dummy tool
name so the list will match
"*"
328 #
if there are no flags.
329 set compiler_flags
" toolname "
330 append compiler_flags
[current_compiler_flags
]
331 #
If running a subset of the test suite
, $TOOL_OPTIONS may not exist.
332 catch
{append compiler_flags
" $TOOL_OPTIONS "}
333 #
If running a subset of the test suite
, $TEST_ALWAYS_FLAGS may not exist.
334 catch
{append compiler_flags
" $TEST_ALWAYS_FLAGS "}
335 set dest
[target_info
name]
336 if [board_info $dest
exists cflags
] {
337 append compiler_flags
"[board_info $dest cflags] "
339 if [board_info $dest
exists multilib_flags
] {
340 append compiler_flags
"[board_info $dest multilib_flags] "
343 # The next two arguments are optional.
If they were not specified
,
345 if { [llength $
args] == 2 } {
346 lappend $
args [list
"*"]
348 if { [llength $
args] == 3 } {
349 lappend $
args [list
""]
352 #
If the option strings are the defaults
, or the same as the
353 # defaults
, there is no need to
call check_conditional_xfail to
354 # compare them to the actual options.
355 if { [string compare
[lindex $
args 2] "*"] == 0
356 && [string compare
[lindex $
args 3] "" ] == 0 } {
359 # The target list might be an effective
-target keyword
, so replace
360 # the original list with
"*-*-*", since we already know it matches.
361 set result
[check_conditional_xfail
[lreplace $
args 1 1 "*-*-*"]]
364 #
Any value in this
variable was left over from an earlier test.
365 set compiler_flags
""
370 # Skip the test
(report it as UNSUPPORTED
) if the target list and
371 # included flags are matched and the excluded flags are not matched.
373 # The first
argument is the line number of the dg
-skip
-if directive
374 # within the test file. Remaining arguments are as
for xfail lists
:
375 # message
{ targets
} { include } { exclude
}
377 # This tests against multilib flags plus either the default flags
for this
378 # group of tests or flags specified with a previous dg
-options command.
380 proc dg
-skip
-if { args } {
381 # Verify the number of arguments. The last two are optional.
382 set args [lreplace $
args 0 0]
383 if { [llength $
args] < 2 ||
[llength $
args] > 4 } {
384 error
"dg-skip-if 2: need 2, 3, or 4 arguments"
387 # Don
't bother if we're already skipping the test.
388 upvar dg
-do-what dg
-do-what
389 if { [lindex $
{dg
-do-what
} 1] == "N" } {
393 set selector
[list target
[lindex $
args 1]]
394 if { [dg
-process
-target
-1 $selector
] == "S" } {
395 if [check
-flags $
args] {
396 upvar dg
-do-what dg
-do-what
397 set dg
-do-what
[list
[lindex $
{dg
-do-what
} 0] "N" "P"]
402 # Like check_conditional_xfail
, but callable from a dg test.
404 proc dg
-xfail
-if { args } {
405 # Verify the number of arguments. The last three are optional.
406 set args [lreplace $
args 0 0]
407 if { [llength $
args] < 2 ||
[llength $
args] > 4 } {
408 error
"dg-xfail-if: need 2, 3, or 4 arguments"
411 # Don
't change anything if we're already skipping the test.
412 upvar dg
-do-what dg
-do-what
413 if { [lindex $
{dg
-do-what
} 1] == "N" } {
417 set selector
[list target
[lindex $
args 1]]
418 if { [dg
-process
-target
-1 $selector
] == "S" } {
419 global compiler_conditional_xfail_data
421 # The target list might be an effective
-target keyword. Replace
422 # the original list with
"*-*-*", since we already know it matches.
423 set args [lreplace $
args 1 1 "*-*-*"]
425 # Supply default
values for unspecified optional arguments.
426 if { [llength $
args] == 2 } {
427 lappend $
args [list
"*"]
429 if { [llength $
args] == 3 } {
430 lappend $
args [list
""]
433 set compiler_conditional_xfail_data $
args
437 # Like dg
-xfail
-if but
for the
execute step.
439 proc dg
-xfail
-run
-if { args } {
440 # Verify the number of arguments. The last two are optional.
441 set args [lreplace $
args 0 0]
442 if { [llength $
args] < 2 ||
[llength $
args] > 4 } {
443 error
"dg-xfail-run-if: need 2, 3, or 4 arguments"
446 # Don
't bother if we're already skipping the test.
447 upvar dg
-do-what dg
-do-what
448 if { [lindex $
{dg
-do-what
} 1] == "N" } {
452 set selector
[list target
[lindex $
args 1]]
453 if { [dg
-process
-target
-1 $selector
] == "S" } {
454 if [check
-flags $
args] {
455 upvar dg
-do-what dg
-do-what
456 set dg
-do-what
[list
[lindex $
{dg
-do-what
} 0] "S" "F"]
461 # Record whether the
program is expected to
return a nonzero
status.
465 proc dg
-shouldfail
{ args } {
466 # Don
't bother if we're already skipping the test.
467 upvar dg
-do-what dg
-do-what
468 if { [lindex $
{dg
-do-what
} 1] == "N" } {
474 set args [lreplace $
args 0 0]
475 if { [llength $
args] > 1 } {
476 set selector
[list target
[lindex $
args 1]]
477 if { [dg
-process
-target
-1 $selector
] == "S" } {
478 # The target matches
, now check the flags.
479 if [check
-flags $
args] {
488 # Intercept the
call to the DejaGnu version of dg
-process
-target to
489 # support use of an effective
-target keyword in place of a list of
490 # target triplets to xfail or skip a test.
492 # The
argument to dg
-process
-target is the keyword
"target" or "xfail"
493 # followed by a selector
:
494 # target
-triplet
-1 ...
495 # effective
-target
-keyword
496 # selector
-expression
498 #
For a target list the result is
"S" if the target is selected, "N" otherwise.
499 #
For an xfail list the result is
"F" if the target is affected, "P" otherwise.
501 # In contexts that allow either
"target" or "xfail" the argument can be
502 # target selector1 xfail selector2
503 # which returns
"N" if selector1 is not selected, otherwise the result of
506 # A selector expression appears within curly braces and uses a single logical
507 # operator
: !, &&, or ||. An operand is another selector expression
, an
508 # effective
-target keyword
, or a list of target triplets within quotes or
511 if { [info procs saved
-dg
-process
-target
] == [list
] } {
512 rename dg
-process
-target saved
-dg
-process
-target
514 # Evaluate an operand within a selector expression.
515 proc selector_opd
{ op
} {
516 set selector
"target"
518 set answer
[ expr
{ [dg
-process
-target $selector
] == "S" } ]
519 verbose
"selector_opd: `$op' $answer" 2
523 # Evaluate a target triplet list within a selector expression.
524 # Unlike other operands
, this needs to be expanded from a list to
525 # the same string as
"target".
526 proc selector_list
{ op
} {
527 set selector
"target [join $op]"
528 set answer
[ expr
{ [dg
-process
-target $selector
] == "S" } ]
529 verbose
"selector_list: `$op' $answer" 2
533 # Evaluate a selector expression.
534 proc selector_expression
{ exp
} {
535 if { [llength $exp
] == 2 } {
536 if [string match
"!" [lindex $exp 0]] {
537 set op1
[lindex $exp
1]
538 set answer
[expr
{ ! [selector_opd $op1
] }]
540 # Assume it
's a list of target triplets.
541 set answer [selector_list $exp]
543 } elseif { [llength $exp] == 3 } {
544 set op1 [lindex $exp 0]
545 set opr [lindex $exp 1]
546 set op2 [lindex $exp 2]
547 if [string match "&&" $opr] {
548 set answer [expr { [selector_opd $op1] && [selector_opd $op2] }]
549 } elseif [string match "||" $opr] {
550 set answer [expr { [selector_opd $op1] || [selector_opd $op2] }]
552 # Assume it's a list of target triplets.
553 set answer
[selector_list $exp
]
556 # Assume it
's a list of target triplets.
557 set answer [selector_list $exp]
560 verbose "selector_expression: `$exp' $answer
" 2
564 # Evaluate
"target selector" or "xfail selector".
566 proc dg
-process
-target
-1 { args } {
567 verbose
"dg-process-target-1: `$args'" 2
569 # Extract the
'what' keyword from the
argument list.
570 set selector
[string trim
[lindex $
args 0]]
571 if [regexp
"^xfail " $selector] {
573 } elseif
[regexp
"^target " $selector] {
576 error
"syntax error in target selector \"$selector\""
579 # Extract the rest of the list
, which might be a keyword.
580 regsub
"^${what}" $selector "" rest
581 set rest
[string trim $rest
]
583 if [is
-effective
-target
-keyword $rest
] {
584 # The selector is an effective target keyword.
585 if [is
-effective
-target $rest
] {
586 return [expr
{ $what
== "xfail" ? "F" : "S" }]
588 return [expr
{ $what
== "xfail" ? "P" : "N" }]
592 if [string match
"{*}" $rest] {
593 if [selector_expression
[lindex $rest
0]] {
594 return [expr
{ $what
== "xfail" ? "F" : "S" }]
596 return [expr
{ $what
== "xfail" ? "P" : "N" }]
600 # The selector is not an effective
-target keyword
, so process
601 # the list of target triplets.
602 return [saved
-dg
-process
-target $selector
]
605 # Intercept calls to the DejaGnu function. In addition to
606 # processing
"target selector" or "xfail selector", handle
607 #
"target selector1 xfail selector2".
609 proc dg
-process
-target
{ args } {
610 verbose
"replacement dg-process-target: `$args'" 2
612 set selector
[string trim
[lindex $
args 0]]
614 #
If the
argument list contains both
'target' and
'xfail',
615 # process
'target' and
, if that succeeds
, process
'xfail'.
616 if [regexp
"^target .* xfail .*" $selector] {
617 set xfail_index
[string first
"xfail" $selector]
618 set xfail_selector
[string range $selector $xfail_index end
]
619 set target_selector
[string range $selector
0 [expr $xfail_index
-1]]
620 set target_selector
[string trim $target_selector
]
621 if { [dg
-process
-target
-1 $target_selector
] == "N" } {
624 return [dg
-process
-target
-1 $xfail_selector
]
627 return [dg
-process
-target
-1 $selector
]