target-supports-dg.exp 18 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600
  1. # Copyright (C) 1997-2015 Free Software Foundation, Inc.
  2. # This program is free software; you can redistribute it and/or modify
  3. # it under the terms of the GNU General Public License as published by
  4. # the Free Software Foundation; either version 3 of the License, or
  5. # (at your option) any later version.
  6. #
  7. # This program is distributed in the hope that it will be useful,
  8. # but WITHOUT ANY WARRANTY; without even the implied warranty of
  9. # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
  10. # GNU General Public License for more details.
  11. #
  12. # You should have received a copy of the GNU General Public License
  13. # along with GCC; see the file COPYING3. If not see
  14. # <http://www.gnu.org/licenses/>.
  15. # DejaGnu's dg-test defines extra flags that are used to compile a test.
  16. # Access them for directives that need to examine all options that are
  17. # used for a test, including checks for non-cached effective targets.
  18. # We don't know how far up the call chain it is but we know we'll hit
  19. # it eventually, and that we're at least 3 calls down.
  20. proc current_compiler_flags { } {
  21. set frames 2
  22. while { ![info exists flags1] } {
  23. set frames [expr $frames + 1]
  24. upvar $frames dg-extra-tool-flags flags1
  25. }
  26. upvar $frames tool_flags flags2
  27. return "$flags1 $flags2"
  28. }
  29. # DejaGnu's dg-test defines a test name that includes torture options
  30. # which is used in most pass/fail messages. Grab a copy of it.
  31. proc testname-for-summary { } {
  32. global testname_with_flags
  33. # A variable called "name" is too generic, so identify dg-test by
  34. # the existence of dg-extra-tool-flags.
  35. if ![info exists testname_with_flags] {
  36. set frames 2
  37. while { ![info exists flags] } {
  38. set frames [expr $frames + 1]
  39. upvar $frames dg-extra-tool-flags flags
  40. }
  41. # We've got the stack level for dg-test; get the variable we want.
  42. upvar $frames name name
  43. set testname_with_flags $name
  44. # If there are flags, add an extra space to improve readability of
  45. # the test summary.
  46. if { [llength $testname_with_flags] > 1 } {
  47. set testname_with_flags "$testname_with_flags "
  48. }
  49. }
  50. return "$testname_with_flags"
  51. }
  52. # If this target does not support weak symbols, skip this test.
  53. proc dg-require-weak { args } {
  54. set weak_available [ check_weak_available ]
  55. if { $weak_available == -1 } {
  56. upvar name name
  57. unresolved "$name"
  58. }
  59. if { $weak_available != 1 } {
  60. upvar dg-do-what dg-do-what
  61. set dg-do-what [list [lindex ${dg-do-what} 0] "N" "P"]
  62. }
  63. }
  64. # If this target does not support overriding weak symbols, skip this
  65. # test.
  66. proc dg-require-weak-override { args } {
  67. set weak_override_available [ check_weak_override_available ]
  68. if { $weak_override_available == -1 } {
  69. upvar name name
  70. unresolved "$name"
  71. }
  72. if { $weak_override_available != 1 } {
  73. upvar dg-do-what dg-do-what
  74. set dg-do-what [list [lindex ${dg-do-what} 0] "N" "P"]
  75. }
  76. }
  77. # If this target does not support the "visibility" attribute, skip this
  78. # test.
  79. proc dg-require-visibility { args } {
  80. set visibility_available [ check_visibility_available [lindex $args 1 ] ]
  81. if { $visibility_available == -1 } {
  82. upvar name name
  83. unresolved "$name"
  84. }
  85. if { $visibility_available != 1 } {
  86. upvar dg-do-what dg-do-what
  87. set dg-do-what [list [lindex ${dg-do-what} 0] "N" "P"]
  88. }
  89. }
  90. # If this target does not support the "alias" attribute, skip this
  91. # test.
  92. proc dg-require-alias { args } {
  93. set alias_available [ check_alias_available ]
  94. if { $alias_available == -1 } {
  95. upvar name name
  96. unresolved "$name"
  97. }
  98. if { $alias_available < 2 } {
  99. upvar dg-do-what dg-do-what
  100. set dg-do-what [list [lindex ${dg-do-what} 0] "N" "P"]
  101. }
  102. }
  103. # If this target does not support the "ifunc" attribute, skip this
  104. # test.
  105. proc dg-require-ifunc { args } {
  106. if { ![ check_ifunc_available ] } {
  107. upvar dg-do-what dg-do-what
  108. set dg-do-what [list [lindex ${dg-do-what} 0] "N" "P"]
  109. }
  110. }
  111. # If this target's linker does not support the --gc-sections flag,
  112. # skip this test.
  113. proc dg-require-gc-sections { args } {
  114. if { ![ check_gc_sections_available ] } {
  115. upvar dg-do-what dg-do-what
  116. set dg-do-what [list [lindex ${dg-do-what} 0] "N" "P"]
  117. }
  118. }
  119. # If this target does not support profiling, skip this test.
  120. proc dg-require-profiling { args } {
  121. if { ![ check_profiling_available [lindex $args 1] ] } {
  122. upvar dg-do-what dg-do-what
  123. set dg-do-what [list [lindex ${dg-do-what} 0] "N" "P"]
  124. }
  125. }
  126. # If this target does not support DLL attributes skip this test.
  127. proc dg-require-dll { args } {
  128. # As a special case, the mcore-*-elf supports these attributes.
  129. # All Symbian OS targets also support these attributes.
  130. if { [istarget mcore-*-elf]
  131. || [istarget *-*-symbianelf] } {
  132. return
  133. }
  134. # PE/COFF targets support dllimport/dllexport.
  135. if { [gcc_target_object_format] == "pe" } {
  136. return
  137. }
  138. upvar dg-do-what dg-do-what
  139. set dg-do-what [list [lindex ${dg-do-what} 0] "N" "P"]
  140. }
  141. # If this host does not support an ASCII locale, skip this test.
  142. proc dg-require-ascii-locale { args } {
  143. if { ![ check_ascii_locale_available] } {
  144. upvar dg-do-what dg-do-what
  145. set dg-do-what [list [lindex ${dg-do-what} 0] "N" "P"]
  146. }
  147. }
  148. proc dg-require-iconv { args } {
  149. if { ![ check_iconv_available ${args} ] } {
  150. upvar dg-do-what dg-do-what
  151. set dg-do-what [list [lindex ${dg-do-what} 0] "N" "P"]
  152. }
  153. }
  154. # If this target does not support named sections skip this test.
  155. proc dg-require-named-sections { args } {
  156. if { ![ check_named_sections_available ] } {
  157. upvar dg-do-what dg-do-what
  158. set dg-do-what [list [lindex ${dg-do-what} 0] "N" "P"]
  159. }
  160. }
  161. # If the target does not match the required effective target, skip this test.
  162. # Only apply this if the optional selector matches.
  163. proc dg-require-effective-target { args } {
  164. set args [lreplace $args 0 0]
  165. # Verify the number of arguments. The last is optional.
  166. if { [llength $args] < 1 || [llength $args] > 2 } {
  167. error "syntax error, need a single effective-target keyword with optional selector"
  168. }
  169. # Don't bother if we're already skipping the test.
  170. upvar dg-do-what dg-do-what
  171. if { [lindex ${dg-do-what} 1] == "N" } {
  172. return
  173. }
  174. # Evaluate selector if present.
  175. if { [llength $args] == 2 } {
  176. switch [dg-process-target-1 [lindex $args 1]] {
  177. "S" { }
  178. "N" { return }
  179. }
  180. }
  181. if { ![is-effective-target [lindex $args 0]] } {
  182. set dg-do-what [list [lindex ${dg-do-what} 0] "N" "P"]
  183. }
  184. }
  185. # If this target does not have fork, skip this test.
  186. proc dg-require-fork { args } {
  187. if { ![check_fork_available] } {
  188. upvar dg-do-what dg-do-what
  189. set dg-do-what [list [lindex ${dg-do-what} 0] "N" "P"]
  190. }
  191. }
  192. # If this target does not have mkfifo, skip this test.
  193. proc dg-require-mkfifo { args } {
  194. if { ![check_mkfifo_available] } {
  195. upvar dg-do-what dg-do-what
  196. set dg-do-what [list [lindex ${dg-do-what} 0] "N" "P"]
  197. }
  198. }
  199. # If this target does not use __cxa_atexit, skip this test.
  200. proc dg-require-cxa-atexit { args } {
  201. if { ![ check_cxa_atexit_available ] } {
  202. upvar dg-do-what dg-do-what
  203. set dg-do-what [list [lindex ${dg-do-what} 0] "N" "P"]
  204. }
  205. }
  206. # If the host is remote rather than the same as the build system, skip
  207. # this test. Some tests are incompatible with DejaGnu's handling of
  208. # remote hosts, which involves copying the source file to the host and
  209. # compiling it with a relative path and "-o a.out".
  210. proc dg-require-host-local { args } {
  211. if [ is_remote host ] {
  212. upvar dg-do-what dg-do-what
  213. set dg-do-what [list [lindex ${dg-do-what} 0] "N" "P"]
  214. }
  215. }
  216. proc dg-require-linker-plugin { args } {
  217. set linker_plugin_available [ check_linker_plugin_available ]
  218. if { $linker_plugin_available == 0 } {
  219. upvar dg-do-what dg-do-what
  220. set dg-do-what [list [lindex ${dg-do-what} 0] "N" "P"]
  221. }
  222. }
  223. # Add any target-specific flags needed for accessing the given list
  224. # of features. This must come after all dg-options.
  225. proc dg-add-options { args } {
  226. upvar dg-extra-tool-flags extra-tool-flags
  227. foreach arg [lrange $args 1 end] {
  228. if { [info procs add_options_for_$arg] != "" } {
  229. set extra-tool-flags \
  230. [eval [list add_options_for_$arg ${extra-tool-flags}]]
  231. } else {
  232. error "Unrecognized option type: $arg"
  233. }
  234. }
  235. }
  236. # Compare flags for a test directive against flags that will be used to
  237. # compile the test: multilib flags, flags for torture options, and either
  238. # the default flags for this group of tests or flags specified with a
  239. # previous dg-options directive.
  240. proc check-flags { args } {
  241. global compiler_flags
  242. global TOOL_OPTIONS
  243. global TEST_ALWAYS_FLAGS
  244. # The args are within another list; pull them out.
  245. 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. # If running a subset of the test suite, $TEST_ALWAYS_FLAGS may not exist.
  253. catch {append compiler_flags " $TEST_ALWAYS_FLAGS "}
  254. set dest [target_info name]
  255. if [board_info $dest exists cflags] {
  256. append compiler_flags "[board_info $dest cflags] "
  257. }
  258. if [board_info $dest exists multilib_flags] {
  259. append compiler_flags "[board_info $dest multilib_flags] "
  260. }
  261. # The next two arguments are optional. If they were not specified,
  262. # use the defaults.
  263. if { [llength $args] == 2 } {
  264. lappend $args [list "*"]
  265. }
  266. if { [llength $args] == 3 } {
  267. lappend $args [list ""]
  268. }
  269. # If the option strings are the defaults, or the same as the
  270. # defaults, there is no need to call check_conditional_xfail to
  271. # compare them to the actual options.
  272. if { [string compare [lindex $args 2] "*"] == 0
  273. && [string compare [lindex $args 3] "" ] == 0 } {
  274. set result 1
  275. } else {
  276. # The target list might be an effective-target keyword, so replace
  277. # the original list with "*-*-*", since we already know it matches.
  278. set result [check_conditional_xfail [lreplace $args 1 1 "*-*-*"]]
  279. }
  280. # Any value in this variable was left over from an earlier test.
  281. set compiler_flags ""
  282. return $result
  283. }
  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.
  286. #
  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 }
  290. #
  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.
  293. proc dg-skip-if { args } {
  294. # Verify the number of arguments. The last two are optional.
  295. set args [lreplace $args 0 0]
  296. if { [llength $args] < 2 || [llength $args] > 4 } {
  297. error "dg-skip-if 2: need 2, 3, or 4 arguments"
  298. }
  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" } {
  302. return
  303. }
  304. set selector [list target [lindex $args 1]]
  305. if { [dg-process-target-1 $selector] == "S" } {
  306. if [check-flags $args] {
  307. upvar dg-do-what dg-do-what
  308. set dg-do-what [list [lindex ${dg-do-what} 0] "N" "P"]
  309. }
  310. }
  311. }
  312. # Like check_conditional_xfail, but callable from a dg test.
  313. proc dg-xfail-if { args } {
  314. # Verify the number of arguments. The last three are optional.
  315. set args [lreplace $args 0 0]
  316. if { [llength $args] < 2 || [llength $args] > 4 } {
  317. error "dg-xfail-if: need 2, 3, or 4 arguments"
  318. }
  319. # Don't change anything if we're already skipping the test.
  320. upvar dg-do-what dg-do-what
  321. if { [lindex ${dg-do-what} 1] == "N" } {
  322. return
  323. }
  324. set selector [list target [lindex $args 1]]
  325. if { [dg-process-target-1 $selector] == "S" } {
  326. global compiler_conditional_xfail_data
  327. # The target list might be an effective-target keyword. Replace
  328. # the original list with "*-*-*", since we already know it matches.
  329. set args [lreplace $args 1 1 "*-*-*"]
  330. # Supply default values for unspecified optional arguments.
  331. if { [llength $args] == 2 } {
  332. lappend $args [list "*"]
  333. }
  334. if { [llength $args] == 3 } {
  335. lappend $args [list ""]
  336. }
  337. set compiler_conditional_xfail_data $args
  338. }
  339. }
  340. # Like dg-xfail-if but for the execute step.
  341. proc dg-xfail-run-if { args } {
  342. # Verify the number of arguments. The last two are optional.
  343. set args [lreplace $args 0 0]
  344. if { [llength $args] < 2 || [llength $args] > 4 } {
  345. error "dg-xfail-run-if: need 2, 3, or 4 arguments"
  346. }
  347. # Don't bother if we're already skipping the test.
  348. upvar dg-do-what dg-do-what
  349. if { [lindex ${dg-do-what} 1] == "N" } {
  350. return
  351. }
  352. set selector [list target [lindex $args 1]]
  353. if { [dg-process-target-1 $selector] == "S" } {
  354. if [check-flags $args] {
  355. upvar dg-do-what dg-do-what
  356. set dg-do-what [list [lindex ${dg-do-what} 0] "S" "F"]
  357. }
  358. }
  359. }
  360. # Record whether the program is expected to return a nonzero status.
  361. set shouldfail 0
  362. proc dg-shouldfail { args } {
  363. # Don't bother if we're already skipping the test.
  364. upvar dg-do-what dg-do-what
  365. if { [lindex ${dg-do-what} 1] == "N" } {
  366. return
  367. }
  368. global shouldfail
  369. set args [lreplace $args 0 0]
  370. if { [llength $args] > 1 } {
  371. set selector [list target [lindex $args 1]]
  372. if { [dg-process-target-1 $selector] == "S" } {
  373. # The target matches, now check the flags.
  374. if [check-flags $args] {
  375. set shouldfail 1
  376. }
  377. }
  378. } else {
  379. set shouldfail 1
  380. }
  381. }
  382. # Intercept the call to the DejaGnu version of dg-process-target to
  383. # support use of an effective-target keyword in place of a list of
  384. # target triplets to xfail or skip a test.
  385. #
  386. # The argument to dg-process-target is the keyword "target" or "xfail"
  387. # followed by a selector:
  388. # target-triplet-1 ...
  389. # effective-target-keyword
  390. # selector-expression
  391. #
  392. # For a target list the result is "S" if the target is selected, "N" otherwise.
  393. # For an xfail list the result is "F" if the target is affected, "P" otherwise.
  394. # In contexts that allow either "target" or "xfail" the argument can be
  395. # target selector1 xfail selector2
  396. # which returns "N" if selector1 is not selected, otherwise the result of
  397. # "xfail selector2".
  398. #
  399. # A selector expression appears within curly braces and uses a single logical
  400. # operator: !, &&, or ||. An operand is another selector expression, an
  401. # effective-target keyword, or a list of target triplets within quotes or
  402. # curly braces.
  403. if { [info procs saved-dg-process-target] == [list] } {
  404. rename dg-process-target saved-dg-process-target
  405. # Evaluate an operand within a selector expression.
  406. proc selector_opd { op } {
  407. set selector "target"
  408. lappend selector $op
  409. set answer [ expr { [dg-process-target $selector] == "S" } ]
  410. verbose "selector_opd: `$op' $answer" 2
  411. return $answer
  412. }
  413. # Evaluate a target triplet list within a selector expression.
  414. # Unlike other operands, this needs to be expanded from a list to
  415. # the same string as "target".
  416. proc selector_list { op } {
  417. set selector "target [join $op]"
  418. set answer [ expr { [dg-process-target $selector] == "S" } ]
  419. verbose "selector_list: `$op' $answer" 2
  420. return $answer
  421. }
  422. # Evaluate a selector expression.
  423. proc selector_expression { exp } {
  424. if { [llength $exp] == 2 } {
  425. if [string match "!" [lindex $exp 0]] {
  426. set op1 [lindex $exp 1]
  427. set answer [expr { ! [selector_opd $op1] }]
  428. } else {
  429. # Assume it's a list of target triplets.
  430. set answer [selector_list $exp]
  431. }
  432. } elseif { [llength $exp] == 3 } {
  433. set op1 [lindex $exp 0]
  434. set opr [lindex $exp 1]
  435. set op2 [lindex $exp 2]
  436. if [string match "&&" $opr] {
  437. set answer [expr { [selector_opd $op1] && [selector_opd $op2] }]
  438. } elseif [string match "||" $opr] {
  439. set answer [expr { [selector_opd $op1] || [selector_opd $op2] }]
  440. } else {
  441. # Assume it's a list of target triplets.
  442. set answer [selector_list $exp]
  443. }
  444. } else {
  445. # Assume it's a list of target triplets.
  446. set answer [selector_list $exp]
  447. }
  448. verbose "selector_expression: `$exp' $answer" 2
  449. return $answer
  450. }
  451. # Evaluate "target selector" or "xfail selector".
  452. proc dg-process-target-1 { args } {
  453. verbose "dg-process-target-1: `$args'" 2
  454. # Extract the 'what' keyword from the argument list.
  455. set selector [string trim [lindex $args 0]]
  456. if [regexp "^xfail " $selector] {
  457. set what "xfail"
  458. } elseif [regexp "^target " $selector] {
  459. set what "target"
  460. } else {
  461. error "syntax error in target selector \"$selector\""
  462. }
  463. # Extract the rest of the list, which might be a keyword.
  464. regsub "^${what}" $selector "" rest
  465. set rest [string trim $rest]
  466. if [is-effective-target-keyword $rest] {
  467. # The selector is an effective target keyword.
  468. if [is-effective-target $rest] {
  469. return [expr { $what == "xfail" ? "F" : "S" }]
  470. } else {
  471. return [expr { $what == "xfail" ? "P" : "N" }]
  472. }
  473. }
  474. if [string match "{*}" $rest] {
  475. if [selector_expression [lindex $rest 0]] {
  476. return [expr { $what == "xfail" ? "F" : "S" }]
  477. } else {
  478. return [expr { $what == "xfail" ? "P" : "N" }]
  479. }
  480. }
  481. # The selector is not an effective-target keyword, so process
  482. # the list of target triplets.
  483. return [saved-dg-process-target $selector]
  484. }
  485. # Intercept calls to the DejaGnu function. In addition to
  486. # processing "target selector" or "xfail selector", handle
  487. # "target selector1 xfail selector2".
  488. proc dg-process-target { args } {
  489. verbose "replacement dg-process-target: `$args'" 2
  490. set selector [string trim [lindex $args 0]]
  491. # If the argument list contains both 'target' and 'xfail',
  492. # process 'target' and, if that succeeds, process 'xfail'.
  493. if [regexp "^target .* xfail .*" $selector] {
  494. set xfail_index [string first "xfail" $selector]
  495. set xfail_selector [string range $selector $xfail_index end]
  496. set target_selector [string range $selector 0 [expr $xfail_index-1]]
  497. set target_selector [string trim $target_selector]
  498. if { [dg-process-target-1 $target_selector] == "N" } {
  499. return "N"
  500. }
  501. return [dg-process-target-1 $xfail_selector]
  502. }
  503. return [dg-process-target-1 $selector]
  504. }
  505. }