PageRenderTime 26ms CodeModel.GetById 14ms RepoModel.GetById 0ms app.codeStats 0ms

/gcc/testsuite/lib/gcc-defs.exp

https://gitlab.com/4144/gcc
Expect | 405 lines | 256 code | 72 blank | 77 comment | 65 complexity | 3b055956c342df580e0f88dc1f9ba440 MD5 | raw file
  1. # Copyright (C) 2001-2019 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. load_lib target-libpath.exp
  16. load_lib wrapper.exp
  17. load_lib target-utils.exp
  18. #
  19. # ${tool}_check_compile -- Reports and returns pass/fail for a compilation
  20. #
  21. proc ${tool}_check_compile {testcase option objname gcc_output} {
  22. global tool
  23. set fatal_signal "*cc: Internal compiler error: program*got fatal signal"
  24. if [string match "$fatal_signal 6" $gcc_output] then {
  25. ${tool}_fail $testcase "Got Signal 6, $option"
  26. return 0
  27. }
  28. if [string match "$fatal_signal 11" $gcc_output] then {
  29. ${tool}_fail $testcase "Got Signal 11, $option"
  30. return 0
  31. }
  32. if [string match "*internal compiler error*" $gcc_output] then {
  33. ${tool}_fail $testcase "$option (internal compiler error)"
  34. return 0
  35. }
  36. # We shouldn't get these because of -w, but just in case.
  37. if [string match "*cc:*warning:*" $gcc_output] then {
  38. warning "$testcase: (with warnings) $option"
  39. send_log "$gcc_output\n"
  40. unresolved "$testcase, $option"
  41. return 0
  42. }
  43. set gcc_output [prune_warnings $gcc_output]
  44. if { [info proc ${tool}-dg-prune] != "" } {
  45. global target_triplet
  46. set gcc_output [${tool}-dg-prune $target_triplet $gcc_output]
  47. if [string match "*::unsupported::*" $gcc_output] then {
  48. regsub -- "::unsupported::" $gcc_output "" gcc_output
  49. unsupported "$testcase: $gcc_output"
  50. return 0
  51. }
  52. } else {
  53. set unsupported_message [${tool}_check_unsupported_p $gcc_output]
  54. if { $unsupported_message != "" } {
  55. unsupported "$testcase: $unsupported_message"
  56. return 0
  57. }
  58. }
  59. # remove any leftover LF/CR to make sure any output is legit
  60. regsub -all -- "\[\r\n\]*" $gcc_output "" gcc_output
  61. # If any message remains, we fail.
  62. if ![string match "" $gcc_output] then {
  63. ${tool}_fail $testcase $option
  64. return 0
  65. }
  66. # fail if the desired object file doesn't exist.
  67. # FIXME: there's no way of checking for existence on a remote host.
  68. if {$objname != "" && ![is3way] && ![file exists $objname]} {
  69. ${tool}_fail $testcase $option
  70. return 0
  71. }
  72. ${tool}_pass $testcase $option
  73. return 1
  74. }
  75. #
  76. # ${tool}_pass -- utility to record a testcase passed
  77. #
  78. proc ${tool}_pass { testcase cflags } {
  79. if { "$cflags" == "" } {
  80. pass "$testcase"
  81. } else {
  82. pass "$testcase, $cflags"
  83. }
  84. }
  85. #
  86. # ${tool}_fail -- utility to record a testcase failed
  87. #
  88. proc ${tool}_fail { testcase cflags } {
  89. if { "$cflags" == "" } {
  90. fail "$testcase"
  91. } else {
  92. fail "$testcase, $cflags"
  93. }
  94. }
  95. #
  96. # ${tool}_finish -- called at the end of every script that calls ${tool}_init
  97. #
  98. # Hide all quirks of the testing environment from the testsuites. Also
  99. # undo anything that ${tool}_init did that needs undoing.
  100. #
  101. proc ${tool}_finish { } {
  102. # The testing harness apparently requires this.
  103. global errorInfo
  104. if [info exists errorInfo] then {
  105. unset errorInfo
  106. }
  107. # Might as well reset these (keeps our caller from wondering whether
  108. # s/he has to or not).
  109. global prms_id bug_id
  110. set prms_id 0
  111. set bug_id 0
  112. }
  113. #
  114. # ${tool}_exit -- Does final cleanup when testing is complete
  115. #
  116. proc ${tool}_exit { } {
  117. global gluefile
  118. if [info exists gluefile] {
  119. file_on_build delete $gluefile
  120. unset gluefile
  121. }
  122. }
  123. #
  124. # runtest_file_p -- Provide a definition for older dejagnu releases
  125. # and assume the old syntax: foo1.exp bar1.c foo2.exp bar2.c.
  126. # (delete after next dejagnu release).
  127. #
  128. if { [info procs runtest_file_p] == "" } then {
  129. proc runtest_file_p { runtests testcase } {
  130. if { $runtests != "" && [regexp "\[.\]\[cC\]" $runtests] } then {
  131. if { [lsearch $runtests [file tail $testcase]] >= 0 } then {
  132. return 1
  133. } else {
  134. return 0
  135. }
  136. }
  137. return 1
  138. }
  139. }
  140. if { [info exists env(GCC_RUNTEST_PARALLELIZE_DIR)] \
  141. && [info procs runtest_file_p] != [list] \
  142. && [info procs gcc_parallelize_saved_runtest_file_p] == [list] } then {
  143. global gcc_runtest_parallelize_counter
  144. global gcc_runtest_parallelize_counter_minor
  145. global gcc_runtest_parallelize_enable
  146. global gcc_runtest_parallelize_dir
  147. global gcc_runtest_parallelize_last
  148. set gcc_runtest_parallelize_counter 0
  149. set gcc_runtest_parallelize_counter_minor 0
  150. set gcc_runtest_parallelize_enable 1
  151. set gcc_runtest_parallelize_dir [getenv GCC_RUNTEST_PARALLELIZE_DIR]
  152. set gcc_runtest_parallelize_last 0
  153. proc gcc_parallel_test_run_p { testcase } {
  154. global gcc_runtest_parallelize_counter
  155. global gcc_runtest_parallelize_counter_minor
  156. global gcc_runtest_parallelize_enable
  157. global gcc_runtest_parallelize_dir
  158. global gcc_runtest_parallelize_last
  159. if { $gcc_runtest_parallelize_enable == 0 } {
  160. return 1
  161. }
  162. # Only test the filesystem every 10th iteration
  163. incr gcc_runtest_parallelize_counter_minor
  164. if { $gcc_runtest_parallelize_counter_minor == 10 } {
  165. set gcc_runtest_parallelize_counter_minor 0
  166. }
  167. if { $gcc_runtest_parallelize_counter_minor != 1 } {
  168. #verbose -log "gcc_parallel_test_run_p $testcase $gcc_runtest_parallelize_counter $gcc_runtest_parallelize_last"
  169. return $gcc_runtest_parallelize_last
  170. }
  171. set path $gcc_runtest_parallelize_dir/$gcc_runtest_parallelize_counter
  172. if {![catch {open $path {RDWR CREAT EXCL} 0600} fd]} {
  173. close $fd
  174. set gcc_runtest_parallelize_last 1
  175. #verbose -log "gcc_parallel_test_run_p $testcase $gcc_runtest_parallelize_counter 1"
  176. incr gcc_runtest_parallelize_counter
  177. return 1
  178. }
  179. set gcc_runtest_parallelize_last 0
  180. #verbose -log "gcc_parallel_test_run_p $testcase $gcc_runtest_parallelize_counter 0"
  181. incr gcc_runtest_parallelize_counter
  182. return 0
  183. }
  184. proc gcc_parallel_test_enable { val } {
  185. global gcc_runtest_parallelize_enable
  186. set gcc_runtest_parallelize_enable $val
  187. }
  188. rename runtest_file_p gcc_parallelize_saved_runtest_file_p
  189. proc runtest_file_p { runtests testcase } {
  190. if ![gcc_parallelize_saved_runtest_file_p $runtests $testcase] {
  191. return 0
  192. }
  193. return [gcc_parallel_test_run_p $testcase]
  194. }
  195. } else {
  196. proc gcc_parallel_test_run_p { testcase } {
  197. return 1
  198. }
  199. proc gcc_parallel_test_enable { val } {
  200. }
  201. }
  202. # Like dg-options, but adds to the default options rather than replacing them.
  203. proc dg-additional-options { args } {
  204. upvar dg-extra-tool-flags extra-tool-flags
  205. if { [llength $args] > 3 } {
  206. error "[lindex $args 0]: too many arguments"
  207. return
  208. }
  209. if { [llength $args] >= 3 } {
  210. switch [dg-process-target [lindex $args 2]] {
  211. "S" { eval lappend extra-tool-flags [lindex $args 1] }
  212. "N" { }
  213. "F" { error "[lindex $args 0]: `xfail' not allowed here" }
  214. "P" { error "[lindex $args 0]: `xfail' not allowed here" }
  215. }
  216. } else {
  217. eval lappend extra-tool-flags [lindex $args 1]
  218. }
  219. }
  220. # Record additional sources files that must be compiled along with the
  221. # main source file.
  222. set additional_sources ""
  223. set additional_sources_used ""
  224. proc dg-additional-sources { args } {
  225. global additional_sources
  226. set additional_sources [lindex $args 1]
  227. }
  228. # Record additional files -- other than source files -- that must be
  229. # present on the system where the compiler runs.
  230. set additional_files ""
  231. proc dg-additional-files { args } {
  232. global additional_files
  233. set additional_files [lindex $args 1]
  234. }
  235. # Return an updated version of OPTIONS that mentions any additional
  236. # source files registered with dg-additional-sources. SOURCE is the
  237. # name of the test case.
  238. proc dg-additional-files-options { options source } {
  239. global additional_sources
  240. global additional_sources_used
  241. global additional_files
  242. set to_download [list]
  243. if { $additional_sources != "" } then {
  244. if [is_remote host] {
  245. lappend options "additional_flags=$additional_sources"
  246. }
  247. regsub -all "^| " $additional_sources " [file dirname $source]/" additional_sources
  248. if ![is_remote host] {
  249. lappend options "additional_flags=$additional_sources"
  250. }
  251. set to_download [concat $to_download $additional_sources]
  252. set additional_sources_used "$additional_sources"
  253. set additional_sources ""
  254. }
  255. if { $additional_files != "" } then {
  256. regsub -all "^| " $additional_files " [file dirname $source]/" additional_files
  257. set to_download [concat $to_download $additional_files]
  258. set additional_files ""
  259. }
  260. if [is_remote host] {
  261. foreach file $to_download {
  262. remote_download host $file
  263. }
  264. }
  265. return $options
  266. }
  267. # Return a colon-separate list of directories to search for libraries
  268. # for COMPILER, including multilib directories.
  269. proc gcc-set-multilib-library-path { compiler } {
  270. global rootme
  271. # ??? rootme will not be set when testing an installed compiler.
  272. # In that case, we should perhaps use some other method to find
  273. # libraries.
  274. if {![info exists rootme]} {
  275. return ""
  276. }
  277. set libpath ":${rootme}"
  278. set options [lrange $compiler 1 end]
  279. set compiler [lindex $compiler 0]
  280. if { [is_remote host] == 0 && [which $compiler] != 0 } {
  281. foreach i "[eval exec $compiler $options --print-multi-lib]" {
  282. set mldir ""
  283. regexp -- "\[a-z0-9=_/\.-\]*;" $i mldir
  284. set mldir [string trimright $mldir "\;@"]
  285. if { "$mldir" == "." } {
  286. continue
  287. }
  288. if { [llength [glob -nocomplain ${rootme}/${mldir}/libgcc_s*.so.*]] >= 1 } {
  289. append libpath ":${rootme}/${mldir}"
  290. }
  291. }
  292. }
  293. return $libpath
  294. }
  295. # A list of all uses of dg-regexp, each entry of the form:
  296. # line-number regexp
  297. # This is cleared at the end of each test by gcc-dg.exp's wrapper for dg-test.
  298. set freeform_regexps []
  299. # Directive for looking for a regexp, without any line numbers or other
  300. # prefixes.
  301. proc dg-regexp { args } {
  302. verbose "dg-regexp: args: $args" 2
  303. global freeform_regexps
  304. lappend freeform_regexps $args
  305. }
  306. # Hook to be called by prune.exp's prune_gcc_output to
  307. # look for the expected dg-regexp expressions, pruning them,
  308. # reporting PASS for those that are found, and FAIL for
  309. # those that weren't found.
  310. #
  311. # It returns a pruned version of its output.
  312. proc handle-dg-regexps { text } {
  313. global freeform_regexps
  314. global testname_with_flags
  315. foreach entry $freeform_regexps {
  316. verbose " entry: $entry" 3
  317. set linenum [lindex $entry 0]
  318. set rexp [lindex $entry 1]
  319. # Escape newlines in $rexp so that we can print them in
  320. # pass/fail results.
  321. set escaped_regex [string map {"\n" "\\n"} $rexp]
  322. verbose "escaped_regex: ${escaped_regex}" 4
  323. set title "$testname_with_flags dg-regexp $linenum"
  324. # Use "regsub" to attempt to prune the pattern from $text
  325. if {[regsub -line $rexp $text "" text]} {
  326. # Success; the multiline pattern was pruned.
  327. pass "$title was found: \"$escaped_regex\""
  328. } else {
  329. fail "$title not found: \"$escaped_regex\""
  330. }
  331. }
  332. return $text
  333. }