| 1 |
# Copyright (C) 1997-2025 Free Software Foundation, Inc. |
| 2 |
|
| 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. |
| 7 |
# |
| 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. |
| 12 |
# |
| 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/>. |
| 16 |
|
| 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. |
| 22 |
|
| 23 |
proc current_compiler_flags { } { |
| 24 |
set frames 2 |
| 25 |
while { ![info exists flags1] } { |
| 26 |
set frames [expr $frames + 1] |
| 27 |
upvar $frames dg-extra-tool-flags flags1 |
| 28 |
} |
| 29 |
upvar $frames tool_flags flags2 |
| 30 |
return "$flags1 $flags2" |
| 31 |
} |
| 32 |
|
| 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. |
| 35 |
|
| 36 |
proc testname-for-summary { } { |
| 37 |
global testname_with_flags |
| 38 |
|
| 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] { |
| 42 |
set frames 2 |
| 43 |
while { ![info exists flags] } { |
| 44 |
set frames [expr $frames + 1] |
| 45 |
upvar $frames dg-extra-tool-flags flags |
| 46 |
} |
| 47 |
|
| 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 |
| 51 |
|
| 52 |
# If there are flags, add an extra space to improve readability of |
| 53 |
# the test summary. |
| 54 |
if { [llength $testname_with_flags] > 1 } { |
| 55 |
set testname_with_flags "$testname_with_flags " |
| 56 |
} |
| 57 |
} |
| 58 |
return "$testname_with_flags" |
| 59 |
} |
| 60 |
|
| 61 |
# Find the 'dg-do-what' variable living inside DejaGnu's 'dg-test' procedure, |
| 62 |
# as a local variable. We start looking at the second-outer frame: this way, |
| 63 |
# the caller of 'find-dg-do-what' may maintain a local 'dg-do-what' variable |
| 64 |
# without interfering with this search. |
| 65 |
|
| 66 |
proc find-dg-do-what { } { |
| 67 |
set level [info level] |
| 68 |
set lookup_level 2 |
| 69 |
while { $lookup_level <= $level } { |
| 70 |
upvar $lookup_level dg-do-what dg-do-what |
| 71 |
if { [info exists dg-do-what] } { |
| 72 |
verbose "find-dg-do-what: found 'dg-do-what' at level $lookup_level: ${dg-do-what}" 2 |
| 73 |
return ${dg-do-what} |
| 74 |
} |
| 75 |
incr lookup_level |
| 76 |
} |
| 77 |
# We've not be called (indirectly) from 'dg-test'. |
| 78 |
verbose "find-dg-do-what: have not found 'dg-do-what'" 2 |
| 79 |
return [list] |
| 80 |
} |
| 81 |
|
| 82 |
# If this target does not support weak symbols, skip this test. |
| 83 |
|
| 84 |
proc dg-require-weak { args } { |
| 85 |
set weak_available [ check_weak_available ] |
| 86 |
if { $weak_available == -1 } { |
| 87 |
upvar name name |
| 88 |
unresolved "$name" |
| 89 |
} |
| 90 |
if { $weak_available != 1 } { |
| 91 |
upvar dg-do-what dg-do-what |
| 92 |
set dg-do-what [list [lindex ${dg-do-what} 0] "N" "P"] |
| 93 |
} |
| 94 |
} |
| 95 |
|
| 96 |
# If this target does not support overriding weak symbols, skip this |
| 97 |
# test. |
| 98 |
|
| 99 |
proc dg-require-weak-override { args } { |
| 100 |
set weak_override_available [ check_weak_override_available ] |
| 101 |
if { $weak_override_available == -1 } { |
| 102 |
upvar name name |
| 103 |
unresolved "$name" |
| 104 |
} |
| 105 |
if { $weak_override_available != 1 } { |
| 106 |
upvar dg-do-what dg-do-what |
| 107 |
set dg-do-what [list [lindex ${dg-do-what} 0] "N" "P"] |
| 108 |
} |
| 109 |
} |
| 110 |
|
| 111 |
# If this target does not support the "visibility" attribute, skip this |
| 112 |
# test. |
| 113 |
|
| 114 |
proc dg-require-visibility { args } { |
| 115 |
set visibility_available [ check_visibility_available [lindex $args 1 ] ] |
| 116 |
if { $visibility_available == -1 } { |
| 117 |
upvar name name |
| 118 |
unresolved "$name" |
| 119 |
} |
| 120 |
if { $visibility_available != 1 } { |
| 121 |
upvar dg-do-what dg-do-what |
| 122 |
set dg-do-what [list [lindex ${dg-do-what} 0] "N" "P"] |
| 123 |
} |
| 124 |
} |
| 125 |
|
| 126 |
# If this target does not support the "alias" attribute, skip this |
| 127 |
# test. |
| 128 |
|
| 129 |
proc dg-require-alias { args } { |
| 130 |
set alias_available [ check_alias_available ] |
| 131 |
if { $alias_available == -1 } { |
| 132 |
upvar name name |
| 133 |
unresolved "$name" |
| 134 |
} |
| 135 |
if { $alias_available < 2 } { |
| 136 |
upvar dg-do-what dg-do-what |
| 137 |
set dg-do-what [list [lindex ${dg-do-what} 0] "N" "P"] |
| 138 |
} |
| 139 |
} |
| 140 |
|
| 141 |
# If this target does not support the "ifunc" attribute, skip this |
| 142 |
# test. |
| 143 |
|
| 144 |
proc dg-require-ifunc { args } { |
| 145 |
if { ![ check_ifunc_available ] } { |
| 146 |
upvar dg-do-what dg-do-what |
| 147 |
set dg-do-what [list [lindex ${dg-do-what} 0] "N" "P"] |
| 148 |
} |
| 149 |
} |
| 150 |
|
| 151 |
# If this target's linker does not support the --gc-sections flag, |
| 152 |
# skip this test. |
| 153 |
|
| 154 |
proc dg-require-gc-sections { args } { |
| 155 |
if { ![ check_gc_sections_available ] } { |
| 156 |
upvar dg-do-what dg-do-what |
| 157 |
set dg-do-what [list [lindex ${dg-do-what} 0] "N" "P"] |
| 158 |
} |
| 159 |
} |
| 160 |
|
| 161 |
# If this target does not support profiling, skip this test. |
| 162 |
|
| 163 |
proc dg-require-profiling { args } { |
| 164 |
if { ![ check_profiling_available [lindex $args 1] ] } { |
| 165 |
upvar dg-do-what dg-do-what |
| 166 |
set dg-do-what [list [lindex ${dg-do-what} 0] "N" "P"] |
| 167 |
} |
| 168 |
} |
| 169 |
|
| 170 |
# If this target does not support DLL attributes skip this test. |
| 171 |
|
| 172 |
proc dg-require-dll { args } { |
| 173 |
# As a special case, the mcore-*-elf supports these attributes. |
| 174 |
# All Symbian OS targets also support these attributes. |
| 175 |
if { [istarget mcore-*-elf] |
| 176 |
|| [istarget *-*-symbianelf] } { |
| 177 |
return |
| 178 |
} |
| 179 |
# PE/COFF targets support dllimport/dllexport. |
| 180 |
if { [gcc_target_object_format] == "pe" } { |
| 181 |
return |
| 182 |
} |
| 183 |
|
| 184 |
upvar dg-do-what dg-do-what |
| 185 |
set dg-do-what [list [lindex ${dg-do-what} 0] "N" "P"] |
| 186 |
} |
| 187 |
|
| 188 |
# If this host does not support an ASCII locale, skip this test. |
| 189 |
|
| 190 |
proc dg-require-ascii-locale { args } { |
| 191 |
if { ![ check_ascii_locale_available] } { |
| 192 |
upvar dg-do-what dg-do-what |
| 193 |
set dg-do-what [list [lindex ${dg-do-what} 0] "N" "P"] |
| 194 |
} |
| 195 |
} |
| 196 |
|
| 197 |
proc dg-require-iconv { args } { |
| 198 |
if { ![ check_iconv_available ${args} ] } { |
| 199 |
upvar dg-do-what dg-do-what |
| 200 |
set dg-do-what [list [lindex ${dg-do-what} 0] "N" "P"] |
| 201 |
} |
| 202 |
} |
| 203 |
|
| 204 |
# If this host does not have "dot", skip this test. |
| 205 |
|
| 206 |
proc dg-require-dot { args } { |
| 207 |
verbose "dg-require-dot" 2 |
| 208 |
if { ![ check_dot_available ] } { |
| 209 |
upvar dg-do-what dg-do-what |
| 210 |
set dg-do-what [list [lindex ${dg-do-what} 0] "N" "P"] |
| 211 |
} |
| 212 |
} |
| 213 |
|
| 214 |
# If this target does not have sufficient stack size, skip this test. |
| 215 |
|
| 216 |
proc dg-require-stack-size { args } { |
| 217 |
if { ![is-effective-target stack_size] } { |
| 218 |
return |
| 219 |
} |
| 220 |
|
| 221 |
set stack_size [dg-effective-target-value stack_size] |
| 222 |
set required [expr [lindex $args 1]] |
| 223 |
if { $stack_size < $required } { |
| 224 |
upvar dg-do-what dg-do-what |
| 225 |
set dg-do-what [list [lindex ${dg-do-what} 0] "N" "P"] |
| 226 |
} |
| 227 |
} |
| 228 |
|
| 229 |
# If this target does not support named sections skip this test. |
| 230 |
|
| 231 |
proc dg-require-named-sections { args } { |
| 232 |
if { ![ check_named_sections_available ] } { |
| 233 |
upvar dg-do-what dg-do-what |
| 234 |
set dg-do-what [list [lindex ${dg-do-what} 0] "N" "P"] |
| 235 |
} |
| 236 |
} |
| 237 |
|
| 238 |
# If the target does not match the required effective target, skip this test. |
| 239 |
# Only apply this if the optional selector matches. |
| 240 |
|
| 241 |
proc dg-require-effective-target { args } { |
| 242 |
set args [lreplace $args 0 0] |
| 243 |
# Verify the number of arguments. The last is optional. |
| 244 |
if { [llength $args] < 1 || [llength $args] > 2 } { |
| 245 |
error "syntax error, need a single effective-target keyword with optional selector" |
| 246 |
} |
| 247 |
|
| 248 |
# Don't bother if we're already skipping the test. |
| 249 |
upvar dg-do-what dg-do-what |
| 250 |
if { [lindex ${dg-do-what} 1] == "N" } { |
| 251 |
return |
| 252 |
} |
| 253 |
|
| 254 |
# Evaluate selector if present. |
| 255 |
if { [llength $args] == 2 } { |
| 256 |
switch [dg-process-target-1 [lindex $args 1]] { |
| 257 |
"S" { } |
| 258 |
"N" { return } |
| 259 |
} |
| 260 |
} |
| 261 |
|
| 262 |
if { ![is-effective-target [lindex $args 0]] } { |
| 263 |
set dg-do-what [list [lindex ${dg-do-what} 0] "N" "P"] |
| 264 |
} |
| 265 |
} |
| 266 |
|
| 267 |
# If this target does not have fork, skip this test. |
| 268 |
|
| 269 |
proc dg-require-fork { args } { |
| 270 |
if { ![check_fork_available] } { |
| 271 |
upvar dg-do-what dg-do-what |
| 272 |
set dg-do-what [list [lindex ${dg-do-what} 0] "N" "P"] |
| 273 |
} |
| 274 |
} |
| 275 |
|
| 276 |
# If this target does not have mkfifo, skip this test. |
| 277 |
|
| 278 |
proc dg-require-mkfifo { args } { |
| 279 |
if { ![check_mkfifo_available] } { |
| 280 |
upvar dg-do-what dg-do-what |
| 281 |
set dg-do-what [list [lindex ${dg-do-what} 0] "N" "P"] |
| 282 |
} |
| 283 |
} |
| 284 |
|
| 285 |
# If this target does not use __cxa_atexit, skip this test. |
| 286 |
|
| 287 |
proc dg-require-cxa-atexit { args } { |
| 288 |
if { ![ check_cxa_atexit_available ] } { |
| 289 |
upvar dg-do-what dg-do-what |
| 290 |
set dg-do-what [list [lindex ${dg-do-what} 0] "N" "P"] |
| 291 |
} |
| 292 |
} |
| 293 |
|
| 294 |
# If the host is remote rather than the same as the build system, skip |
| 295 |
# this test. Some tests are incompatible with DejaGnu's handling of |
| 296 |
# remote hosts, which involves copying the source file to the host and |
| 297 |
# compiling it with a relative path and "-o a.out". |
| 298 |
|
| 299 |
proc dg-require-host-local { args } { |
| 300 |
if [ is_remote host ] { |
| 301 |
upvar dg-do-what dg-do-what |
| 302 |
set dg-do-what [list [lindex ${dg-do-what} 0] "N" "P"] |
| 303 |
} |
| 304 |
} |
| 305 |
|
| 306 |
proc dg-require-linker-plugin { args } { |
| 307 |
set linker_plugin_available [ check_linker_plugin_available ] |
| 308 |
if { $linker_plugin_available == 0 } { |
| 309 |
upvar dg-do-what dg-do-what |
| 310 |
set dg-do-what [list [lindex ${dg-do-what} 0] "N" "P"] |
| 311 |
} |
| 312 |
} |
| 313 |
|
| 314 |
# If this target does not support the "stack-check" option, skip this |
| 315 |
# test. |
| 316 |
|
| 317 |
proc dg-require-stack-check { args } { |
| 318 |
set stack_check_available [ check_stack_check_available [lindex $args 1 ] ] |
| 319 |
if { $stack_check_available == -1 } { |
| 320 |
upvar name name |
| 321 |
unresolved "$name" |
| 322 |
} |
| 323 |
if { $stack_check_available != 1 } { |
| 324 |
upvar dg-do-what dg-do-what |
| 325 |
set dg-do-what [list [lindex ${dg-do-what} 0] "N" "P"] |
| 326 |
} |
| 327 |
} |
| 328 |
|
| 329 |
# Add any target-specific flags needed for accessing the given list |
| 330 |
# of features. This must come after all dg-options. |
| 331 |
|
| 332 |
proc dg-add-options { args } { |
| 333 |
upvar dg-extra-tool-flags extra-tool-flags |
| 334 |
|
| 335 |
foreach arg [lrange $args 1 end] { |
| 336 |
if { [info procs add_options_for_$arg] != "" } { |
| 337 |
set extra-tool-flags \ |
| 338 |
[eval [list add_options_for_$arg ${extra-tool-flags}]] |
| 339 |
} else { |
| 340 |
error "Unrecognized option type: $arg" |
| 341 |
} |
| 342 |
} |
| 343 |
} |
| 344 |
|
| 345 |
# Remove any target-specific flags needed for accessing the given list |
| 346 |
# of features. This must come after all dg-options. |
| 347 |
|
| 348 |
proc dg-remove-options { args } { |
| 349 |
upvar dg-extra-tool-flags extra-tool-flags |
| 350 |
|
| 351 |
foreach arg [lrange $args 1 end] { |
| 352 |
if { [info procs remove_options_for_$arg] != "" } { |
| 353 |
set extra-tool-flags \ |
| 354 |
[eval [list remove_options_for_$arg ${extra-tool-flags}]] |
| 355 |
} else { |
| 356 |
error "Unrecognized option type: $arg" |
| 357 |
} |
| 358 |
} |
| 359 |
} |
| 360 |
|
| 361 |
# Compare flags for a test directive against flags that will be used to |
| 362 |
# compile the test: multilib flags, flags for torture options, and either |
| 363 |
# the default flags for this group of tests or flags specified with a |
| 364 |
# previous dg-options directive. |
| 365 |
|
| 366 |
proc check-flags { args } { |
| 367 |
global compiler_flags |
| 368 |
global TOOL_OPTIONS |
| 369 |
global TEST_ALWAYS_FLAGS |
| 370 |
|
| 371 |
# The args are within another list; pull them out. |
| 372 |
set args [lindex $args 0] |
| 373 |
|
| 374 |
# The next two arguments are optional. If they were not specified, |
| 375 |
# use the defaults. |
| 376 |
if { [llength $args] == 2 } { |
| 377 |
lappend args "*" |
| 378 |
} |
| 379 |
if { [llength $args] == 3 } { |
| 380 |
lappend args "" |
| 381 |
} |
| 382 |
|
| 383 |
# If the option strings are the defaults, or the same as the |
| 384 |
# defaults, there is no need to call check_conditional_xfail to |
| 385 |
# compare them to the actual options. |
| 386 |
if { [string compare [lindex $args 2] "*"] == 0 |
| 387 |
&& [string compare [lindex $args 3] "" ] == 0 } { |
| 388 |
return 1 |
| 389 |
} |
| 390 |
|
| 391 |
# Start the list with a dummy tool name so the list will match "*" |
| 392 |
# if there are no flags. |
| 393 |
set compiler_flags " toolname " |
| 394 |
append compiler_flags [current_compiler_flags] |
| 395 |
# If running a subset of the test suite, $TOOL_OPTIONS may not exist. |
| 396 |
catch {append compiler_flags " $TOOL_OPTIONS "} |
| 397 |
# If running a subset of the test suite, $TEST_ALWAYS_FLAGS may not exist. |
| 398 |
catch {append compiler_flags " $TEST_ALWAYS_FLAGS "} |
| 399 |
set dest [target_info name] |
| 400 |
if [board_info $dest exists cflags] { |
| 401 |
append compiler_flags "[board_info $dest cflags] " |
| 402 |
} |
| 403 |
if [board_info $dest exists multilib_flags] { |
| 404 |
append compiler_flags "[board_info $dest multilib_flags] " |
| 405 |
} |
| 406 |
|
| 407 |
# The target list might be an effective-target keyword, so replace |
| 408 |
# the original list with "*-*-*", since we already know it matches. |
| 409 |
set result [check_conditional_xfail [lreplace $args 1 1 "*-*-*"]] |
| 410 |
|
| 411 |
# Any value in this variable was left over from an earlier test. |
| 412 |
set compiler_flags "" |
| 413 |
|
| 414 |
return $result |
| 415 |
} |
| 416 |
|
| 417 |
# Override dg-do action on target, without setting the test as |
| 418 |
# unsupported on other targets. Multiple such overriders can be |
| 419 |
# present. If the test is already marked as unsupported, it has no |
| 420 |
# effect. Otherwise, if the target selector matches, call dg-do, |
| 421 |
# otherwise leave dg-do-what alone, so that any earlier setting |
| 422 |
# (possibly the default) prevails. |
| 423 |
|
| 424 |
proc dg-do-if { args } { |
| 425 |
set args [lreplace $args 0 0] |
| 426 |
# Verify the number of arguments. |
| 427 |
if { [llength $args] != 2 } { |
| 428 |
error "syntax error, need a single action and target selector" |
| 429 |
} |
| 430 |
|
| 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" } { |
| 434 |
return |
| 435 |
} |
| 436 |
|
| 437 |
# Evaluate selector, return if it does not match. |
| 438 |
switch [dg-process-target-1 [lindex $args 1]] { |
| 439 |
"N" { return } |
| 440 |
"P" { return } |
| 441 |
} |
| 442 |
|
| 443 |
eval dg-do $args |
| 444 |
} |
| 445 |
|
| 446 |
# Skip the test (report it as UNSUPPORTED) if the target list and |
| 447 |
# included flags are matched and the excluded flags are not matched. |
| 448 |
# |
| 449 |
# The first argument is the line number of the dg-skip-if directive |
| 450 |
# within the test file. Remaining arguments are as for xfail lists: |
| 451 |
# message { targets } { include } { exclude } |
| 452 |
# |
| 453 |
# This tests against multilib flags plus either the default flags for this |
| 454 |
# group of tests or flags specified with a previous dg-options command. |
| 455 |
|
| 456 |
proc dg-skip-if { args } { |
| 457 |
# Verify the number of arguments. The last two are optional. |
| 458 |
set args [lreplace $args 0 0] |
| 459 |
if { [llength $args] < 2 || [llength $args] > 4 } { |
| 460 |
error "dg-skip-if 2: need 2, 3, or 4 arguments" |
| 461 |
} |
| 462 |
|
| 463 |
# Don't bother if we're already skipping the test. |
| 464 |
upvar dg-do-what dg-do-what |
| 465 |
if { [lindex ${dg-do-what} 1] == "N" } { |
| 466 |
return |
| 467 |
} |
| 468 |
|
| 469 |
set selector [list target [lindex $args 1]] |
| 470 |
if { [dg-process-target-1 $selector] == "S" } { |
| 471 |
if [check-flags $args] { |
| 472 |
upvar dg-do-what dg-do-what |
| 473 |
set dg-do-what [list [lindex ${dg-do-what} 0] "N" "P"] |
| 474 |
} |
| 475 |
} |
| 476 |
} |
| 477 |
|
| 478 |
# Like check_conditional_xfail, but callable from a dg test. |
| 479 |
|
| 480 |
proc dg-xfail-if { args } { |
| 481 |
# Verify the number of arguments. The last three are optional. |
| 482 |
set args [lreplace $args 0 0] |
| 483 |
if { [llength $args] < 2 || [llength $args] > 4 } { |
| 484 |
error "dg-xfail-if: need 2, 3, or 4 arguments" |
| 485 |
} |
| 486 |
|
| 487 |
# Don't change anything if we're already skipping the test. |
| 488 |
upvar dg-do-what dg-do-what |
| 489 |
if { [lindex ${dg-do-what} 1] == "N" } { |
| 490 |
return |
| 491 |
} |
| 492 |
|
| 493 |
set selector [list target [lindex $args 1]] |
| 494 |
if { [dg-process-target-1 $selector] == "S" } { |
| 495 |
global compiler_conditional_xfail_data |
| 496 |
|
| 497 |
# The target list might be an effective-target keyword. Replace |
| 498 |
# the original list with "*-*-*", since we already know it matches. |
| 499 |
set args [lreplace $args 1 1 "*-*-*"] |
| 500 |
|
| 501 |
# Supply default values for unspecified optional arguments. |
| 502 |
if { [llength $args] == 2 } { |
| 503 |
lappend $args [list "*"] |
| 504 |
} |
| 505 |
if { [llength $args] == 3 } { |
| 506 |
lappend $args [list ""] |
| 507 |
} |
| 508 |
|
| 509 |
set compiler_conditional_xfail_data $args |
| 510 |
} |
| 511 |
} |
| 512 |
|
| 513 |
# Like dg-xfail-if but for the execute step. |
| 514 |
|
| 515 |
proc dg-xfail-run-if { args } { |
| 516 |
# Verify the number of arguments. The last two are optional. |
| 517 |
set args [lreplace $args 0 0] |
| 518 |
if { [llength $args] < 2 || [llength $args] > 4 } { |
| 519 |
error "dg-xfail-run-if: need 2, 3, or 4 arguments" |
| 520 |
} |
| 521 |
|
| 522 |
# Don't bother if we're already skipping the test. |
| 523 |
upvar dg-do-what dg-do-what |
| 524 |
if { [lindex ${dg-do-what} 1] == "N" } { |
| 525 |
return |
| 526 |
} |
| 527 |
|
| 528 |
set selector [list target [lindex $args 1]] |
| 529 |
if { [dg-process-target-1 $selector] == "S" } { |
| 530 |
if [check-flags $args] { |
| 531 |
upvar dg-do-what dg-do-what |
| 532 |
set dg-do-what [list [lindex ${dg-do-what} 0] "S" "F"] |
| 533 |
} |
| 534 |
} |
| 535 |
} |
| 536 |
|
| 537 |
# Record whether the program is expected to return a nonzero status. |
| 538 |
|
| 539 |
set shouldfail 0 |
| 540 |
|
| 541 |
proc dg-shouldfail { args } { |
| 542 |
# Don't bother if we're already skipping the test. |
| 543 |
upvar dg-do-what dg-do-what |
| 544 |
if { [lindex ${dg-do-what} 1] == "N" } { |
| 545 |
return |
| 546 |
} |
| 547 |
|
| 548 |
global shouldfail |
| 549 |
|
| 550 |
set args [lreplace $args 0 0] |
| 551 |
if { [llength $args] > 1 } { |
| 552 |
set selector [list target [lindex $args 1]] |
| 553 |
if { [dg-process-target-1 $selector] == "S" } { |
| 554 |
# The target matches, now check the flags. |
| 555 |
if [check-flags $args] { |
| 556 |
set shouldfail 1 |
| 557 |
} |
| 558 |
} |
| 559 |
} else { |
| 560 |
set shouldfail 1 |
| 561 |
} |
| 562 |
} |
| 563 |
|
| 564 |
# Record whether the compiler is expected (at the moment) to ICE. |
| 565 |
# Used for tests that test bugs that have not been fixed yet. |
| 566 |
|
| 567 |
set expect_ice 0 |
| 568 |
|
| 569 |
proc dg-ice { args } { |
| 570 |
# Don't bother if we're already skipping the test. |
| 571 |
upvar dg-do-what dg-do-what |
| 572 |
if { [lindex ${dg-do-what} 1] == "N" } { |
| 573 |
return |
| 574 |
} |
| 575 |
|
| 576 |
global expect_ice |
| 577 |
|
| 578 |
set args [lreplace $args 0 0] |
| 579 |
if { [llength $args] > 1 } { |
| 580 |
set selector [list target [lindex $args 1]] |
| 581 |
if { [dg-process-target-1 $selector] == "S" } { |
| 582 |
# The target matches, now check the flags. |
| 583 |
if [check-flags $args] { |
| 584 |
set expect_ice 1 |
| 585 |
} |
| 586 |
} |
| 587 |
} else { |
| 588 |
set expect_ice 1 |
| 589 |
} |
| 590 |
} |
| 591 |
|
| 592 |
# Intercept the call to the DejaGnu version of dg-process-target to |
| 593 |
# support use of an effective-target keyword in place of a list of |
| 594 |
# target triplets to xfail or skip a test. |
| 595 |
# |
| 596 |
# The argument to dg-process-target is the keyword "target" or "xfail" |
| 597 |
# followed by a selector: |
| 598 |
# target-triplet-1 ... |
| 599 |
# effective-target-keyword |
| 600 |
# selector-expression |
| 601 |
# |
| 602 |
# For a target list the result is "S" if the target is selected, "N" otherwise. |
| 603 |
# For an xfail list the result is "F" if the target is affected, "P" otherwise. |
| 604 |
|
| 605 |
# In contexts that allow either "target" or "xfail" the argument can be |
| 606 |
# target selector1 xfail selector2 |
| 607 |
# which returns "N" if selector1 is not selected, otherwise the result of |
| 608 |
# "xfail selector2". |
| 609 |
# |
| 610 |
# A selector expression appears within curly braces and uses a single logical |
| 611 |
# operator: !, &&, or ||. An operand is another selector expression, an |
| 612 |
# effective-target keyword, or a list of target triplets within quotes or |
| 613 |
# curly braces. |
| 614 |
|
| 615 |
if { [info procs saved-dg-process-target] == [list] } { |
| 616 |
rename dg-process-target saved-dg-process-target |
| 617 |
|
| 618 |
# Evaluate an operand within a selector expression. |
| 619 |
proc selector_opd { op } { |
| 620 |
set selector "target" |
| 621 |
lappend selector $op |
| 622 |
set answer [ expr { [dg-process-target $selector] == "S" } ] |
| 623 |
verbose "selector_opd: `$op' $answer" 2 |
| 624 |
return $answer |
| 625 |
} |
| 626 |
|
| 627 |
# Evaluate a target triplet list within a selector expression. |
| 628 |
# Unlike other operands, this needs to be expanded from a list to |
| 629 |
# the same string as "target". |
| 630 |
proc selector_list { op } { |
| 631 |
set selector "target [join $op]" |
| 632 |
set answer [ expr { [dg-process-target $selector] == "S" } ] |
| 633 |
verbose "selector_list: `$op' $answer" 2 |
| 634 |
return $answer |
| 635 |
} |
| 636 |
|
| 637 |
# Evaluate a selector expression. |
| 638 |
proc selector_expression { exp } { |
| 639 |
if { [llength $exp] >= 2 |
| 640 |
&& [string match "any-opts" [lindex $exp 0]] } { |
| 641 |
set args [list "" { *-*-* } [lrange $exp 1 end] ""] |
| 642 |
set answer [check_conditional_xfail $args] |
| 643 |
} elseif { [llength $exp] >= 2 |
| 644 |
&& [string match "no-opts" [lindex $exp 0]] } { |
| 645 |
set args [list "" { *-*-* } "*" [lrange $exp 1 end]] |
| 646 |
set answer [check_conditional_xfail $args] |
| 647 |
} elseif { [llength $exp] == 2 } { |
| 648 |
if [string match "!" [lindex $exp 0]] { |
| 649 |
set op1 [lindex $exp 1] |
| 650 |
set answer [expr { ! [selector_opd $op1] }] |
| 651 |
} else { |
| 652 |
# Assume it's a list of target triplets. |
| 653 |
set answer [selector_list $exp] |
| 654 |
} |
| 655 |
} elseif { [llength $exp] == 3 } { |
| 656 |
set op1 [lindex $exp 0] |
| 657 |
set opr [lindex $exp 1] |
| 658 |
set op2 [lindex $exp 2] |
| 659 |
if [string match "&&" $opr] { |
| 660 |
set answer [expr { [selector_opd $op1] && [selector_opd $op2] }] |
| 661 |
} elseif [string match "||" $opr] { |
| 662 |
set answer [expr { [selector_opd $op1] || [selector_opd $op2] }] |
| 663 |
} else { |
| 664 |
# Assume it's a list of target triplets. |
| 665 |
set answer [selector_list $exp] |
| 666 |
} |
| 667 |
} else { |
| 668 |
# Assume it's a list of target triplets. |
| 669 |
set answer [selector_list $exp] |
| 670 |
} |
| 671 |
|
| 672 |
verbose "selector_expression: `$exp' $answer" 2 |
| 673 |
return $answer |
| 674 |
} |
| 675 |
|
| 676 |
# Evaluate "target selector" or "xfail selector". |
| 677 |
|
| 678 |
proc dg-process-target-1 { args } { |
| 679 |
verbose "dg-process-target-1: `$args'" 2 |
| 680 |
|
| 681 |
# Extract the 'what' keyword from the argument list. |
| 682 |
set selector [string trim [lindex $args 0]] |
| 683 |
if [regexp "^xfail " $selector] { |
| 684 |
set what "xfail" |
| 685 |
} elseif [regexp "^target " $selector] { |
| 686 |
set what "target" |
| 687 |
} else { |
| 688 |
error "syntax error in target selector \"$selector\"" |
| 689 |
} |
| 690 |
|
| 691 |
# Extract the rest of the list, which might be a keyword. |
| 692 |
regsub "^${what}" $selector "" rest |
| 693 |
set rest [string trim $rest] |
| 694 |
|
| 695 |
if [is-effective-target-keyword $rest] { |
| 696 |
# The selector is an effective target keyword. |
| 697 |
if [is-effective-target $rest] { |
| 698 |
return [expr { $what == "xfail" ? "F" : "S" }] |
| 699 |
} else { |
| 700 |
return [expr { $what == "xfail" ? "P" : "N" }] |
| 701 |
} |
| 702 |
} |
| 703 |
|
| 704 |
if [string match "{*}" $rest] { |
| 705 |
if [selector_expression [lindex $rest 0]] { |
| 706 |
return [expr { $what == "xfail" ? "F" : "S" }] |
| 707 |
} else { |
| 708 |
return [expr { $what == "xfail" ? "P" : "N" }] |
| 709 |
} |
| 710 |
} |
| 711 |
|
| 712 |
# The selector is not an effective-target keyword, so process |
| 713 |
# the list of target triplets. |
| 714 |
return [saved-dg-process-target $selector] |
| 715 |
} |
| 716 |
|
| 717 |
# Intercept calls to the DejaGnu function. In addition to |
| 718 |
# processing "target selector" or "xfail selector", handle |
| 719 |
# "target selector1 xfail selector2". |
| 720 |
|
| 721 |
proc dg-process-target { args } { |
| 722 |
verbose "replacement dg-process-target: `$args'" 2 |
| 723 |
|
| 724 |
set selector [string trim [lindex $args 0]] |
| 725 |
|
| 726 |
# If the argument list contains both 'target' and 'xfail', |
| 727 |
# process 'target' and, if that succeeds, process 'xfail'. |
| 728 |
if [regexp "^target .* xfail .*" $selector] { |
| 729 |
set xfail_index [string first "xfail" $selector] |
| 730 |
set xfail_selector [string range $selector $xfail_index end] |
| 731 |
set target_selector [string range $selector 0 [expr $xfail_index-1]] |
| 732 |
set target_selector [string trim $target_selector] |
| 733 |
if { [dg-process-target-1 $target_selector] == "N" } { |
| 734 |
return "N" |
| 735 |
} |
| 736 |
return [dg-process-target-1 $xfail_selector] |
| 737 |
|
| 738 |
} |
| 739 |
return [dg-process-target-1 $selector] |
| 740 |
} |
| 741 |
} |
| 742 |
|
| 743 |
# If this target does not support the "symver" attribute, skip this |
| 744 |
# test. |
| 745 |
|
| 746 |
proc dg-require-symver { args } { |
| 747 |
if { ![ check_symver_available ] } { |
| 748 |
upvar dg-do-what dg-do-what |
| 749 |
set dg-do-what [list [lindex ${dg-do-what} 0] "N" "P"] |
| 750 |
} |
| 751 |
} |
| 752 |
|
| 753 |
# If this target does not provide prog named "$args", skip this test. |
| 754 |
|
| 755 |
proc dg-require-prog-name-available { args } { |
| 756 |
# The args are within another list; pull them out. |
| 757 |
set args [lindex $args 0] |
| 758 |
|
| 759 |
set prog [lindex $args 1] |
| 760 |
|
| 761 |
if { ![ check_is_prog_name_available $prog ] } { |
| 762 |
upvar dg-do-what dg-do-what |
| 763 |
set dg-do-what [list [lindex ${dg-do-what} 0] "N" "P"] |
| 764 |
} |
| 765 |
} |
| 766 |
|