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 # Compare flags for a test directive against flags that will be used to
185 # compile the test: multilib flags, flags for torture options, and either
186 # the default flags for this group of tests or flags specified with a
187 # previous dg-options directive.
189 proc check-flags { args } {
190 global compiler_flags
192 # These variables are from DejaGnu's dg-test.
193 upvar dg-extra-tool-flags extra_tool_flags
194 upvar tool_flags tool_flags
196 # The args are within another list; pull them out.
197 set args [lindex $args 0]
199 # Start the list with a dummy tool name so the list will match "*"
200 # if there are no flags.
201 set compiler_flags " toolname "
202 append compiler_flags $extra_tool_flags
203 append compiler_flags $tool_flags
204 # If running a subset of the test suite, $TOOL_OPTIONS may not exist.
205 catch {append compiler_flags " $TOOL_OPTIONS "}
206 set dest [target_info name]
207 if [board_info $dest exists multilib_flags] {
208 append compiler_flags "[board_info $dest multilib_flags] "
211 # The target list might be an effective-target keyword, so replace
212 # the original list with "*-*-*", since we already know it matches.
213 set result [check_conditional_xfail [lreplace $args 1 1 "*-*-*"]]
215 # Any value in this variable was left over from an earlier test.
216 set compiler_flags ""
221 # Skip the test (report it as UNSUPPORTED) if the target list and
222 # included flags are matched and the excluded flags are not matched.
224 # The first argument is the line number of the dg-skip-if directive
225 # within the test file. Remaining arguments are as for xfail lists:
226 # message { targets } { include } { exclude }
228 # This tests against multilib flags plus either the default flags for this
229 # group of tests or flags specified with a previous dg-options command.
231 proc dg-skip-if { args } {
232 # Don't bother if we're already skipping the test.
233 upvar dg-do-what dg-do-what
234 if { [lindex ${dg-do-what} 1] == "N" } {
238 set args [lreplace $args 0 0]
240 set selector [list target [lindex $args 1]]
241 if { [dg-process-target $selector] == "S" } {
242 # These are defined in DejaGnu's dg-test, needed by check-flags.
243 upvar dg-extra-tool-flags dg-extra-tool-flags
244 upvar tool_flags tool_flags
246 if [check-flags $args] {
247 upvar dg-do-what dg-do-what
248 set dg-do-what [list [lindex ${dg-do-what} 0] "N" "P"]
253 # Like check_conditional_xfail, but callable from a dg test.
255 proc dg-xfail-if { args } {
256 # Don't change anything if we're already skipping the test.
257 upvar dg-do-what dg-do-what
258 if { [lindex ${dg-do-what} 1] == "N" } {
262 set args [lreplace $args 0 0]
263 set selector [list target [lindex $args 1]]
264 if { [dg-process-target $selector] == "S" } {
265 global compiler_conditional_xfail_data
266 set compiler_conditional_xfail_data [lreplace $args 1 1 "*-*-*"]
270 # Like dg-xfail-if but for the execute step.
272 proc dg-xfail-run-if { args } {
273 # Don't bother if we're already skipping the test.
274 upvar dg-do-what dg-do-what
275 if { [lindex ${dg-do-what} 1] == "N" } {
279 set args [lreplace $args 0 0]
281 set selector [list target [lindex $args 1]]
282 if { [dg-process-target $selector] == "S" } {
283 # These are defined in DejaGnu's dg-test, needed by check-flags.
284 upvar dg-extra-tool-flags dg-extra-tool-flags
285 upvar tool_flags tool_flags
287 if [check-flags $args] {
288 upvar dg-do-what dg-do-what
289 set dg-do-what [list [lindex ${dg-do-what} 0] "S" "F"]
294 # Record whether the program is expected to return a nonzero status.
298 proc dg-shouldfail { args } {
299 # Don't bother if we're already skipping the test.
300 upvar dg-do-what dg-do-what
301 if { [lindex ${dg-do-what} 1] == "N" } {
307 set args [lreplace $args 0 0]
308 if { [llength $args] > 1 } {
309 set selector [list target [lindex $args 1]]
310 if { [dg-process-target $selector] == "S" } {
311 # The target matches, now check the flags. These variables
312 # are defined in DejaGnu's dg-test, needed by check-flags.
313 upvar dg-extra-tool-flags dg-extra-tool-flags
314 upvar tool_flags tool_flags
316 if [check-flags $args] {
325 # Intercept the call to the DejaGnu version of dg-process-target to
326 # support use of an effective-target keyword in place of a list of
327 # target triplets to xfail or skip a test.
329 # selector is one of:
330 # xfail target-triplet-1 ...
331 # xfail effective-target-keyword
332 # xfail selector-expression
333 # target target-triplet-1 ...
334 # target effective-target-keyword
335 # target selector-expression
337 # For a target list the result is "S" if the target is selected, "N" otherwise.
338 # For an xfail list the result is "F" if the target is affected, "P" otherwise.
340 # A selector expression appears within curly braces and uses a single logical
341 # operator: !, &&, or ||. An operand is another selector expression, an
342 # effective-target keyword, or a list of target triplets within quotes or
345 if { [info procs saved-dg-process-target] == [list] } {
346 rename dg-process-target saved-dg-process-target
348 # Evaluate an operand within a selector expression.
349 proc selector_opd { op } {
350 set selector "target"
352 set answer [ expr { [dg-process-target $selector] == "S" } ]
353 verbose "selector_opd: `$op' $answer" 2
357 # Evaluate a target triplet list within a selector expression.
358 # Unlike other operands, this needs to be expanded from a list to
359 # the same string as "target".
360 proc selector_list { op } {
361 set selector "target [join $op]"
362 set answer [ expr { [dg-process-target $selector] == "S" } ]
363 verbose "selector_list: `$op' $answer" 2
367 # Evaluate a selector expression.
368 proc selector_expression { exp } {
369 if { [llength $exp] == 2 } {
370 if [string match "!" [lindex $exp 0]] {
371 set op1 [lindex $exp 1]
372 set answer [expr { ! [selector_opd $op1] }]
374 # Assume it's a list of target triplets.
375 set answer [selector_list $exp]
377 } elseif { [llength $exp] == 3 } {
378 set op1 [lindex $exp 0]
379 set opr [lindex $exp 1]
380 set op2 [lindex $exp 2]
381 if [string match "&&" $opr] {
382 set answer [expr { [selector_opd $op1] && [selector_opd $op2] }]
383 } elseif [string match "||" $opr] {
384 set answer [expr { [selector_opd $op1] || [selector_opd $op2] }]
386 # Assume it's a list of target triplets.
387 set answer [selector_list $exp]
390 # Assume it's a list of target triplets.
391 set answer [selector_list $exp]
394 verbose "selector_expression: `$exp' $answer" 2
398 proc dg-process-target { args } {
399 verbose "replacement dg-process-target: `$args'" 2
401 # Extract the 'what' keyword from the argument list.
402 set selector [string trim [lindex $args 0]]
403 if [regexp "^xfail " $selector] {
405 } elseif [regexp "^target " $selector] {
408 error "syntax error in target selector \"$selector\""
411 # Extract the rest of the list, which might be a keyword.
412 regsub "^${what}" $selector "" rest
413 set rest [string trim $rest]
415 if [is-effective-target-keyword $rest] {
416 # The selector is an effective target keyword.
417 if [is-effective-target $rest] {
418 return [expr { $what == "xfail" ? "F" : "S" }]
420 return [expr { $what == "xfail" ? "P" : "N" }]
424 if [string match "{*}" $rest] {
425 if [selector_expression [lindex $rest 0]] {
426 return [expr { $what == "xfail" ? "F" : "S" }]
428 return [expr { $what == "xfail" ? "P" : "N" }]
432 # The selector is not an effective-target keyword, so process
433 # the list of target triplets.
434 return [saved-dg-process-target $selector]