go-torture.exp 11 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379
  1. # Copyright (C) 2009-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. # Please email any bugs, comments, and/or additions to this file to
  16. # the author.
  17. # This file was written by Ian Lance Taylor <iant@google.com> based on
  18. # fortran-torture.exp by Steven Bosscher and Rob Savoye.
  19. load_lib target-supports.exp
  20. load_lib target-utils.exp
  21. # The default option list can be overridden by
  22. # TORTURE_OPTIONS="{ { list1 } ... { listN } }"
  23. if ![info exists TORTURE_OPTIONS] {
  24. set TORTURE_OPTIONS [list \
  25. { -O0 } { -O1 } { -O2 } \
  26. { -O2 -fomit-frame-pointer -finline-functions } \
  27. { -O2 -fomit-frame-pointer -finline-functions -funroll-loops } \
  28. { -O2 -fbounds-check } \
  29. { -O3 -g } \
  30. { -Os }]
  31. }
  32. #
  33. # go-torture-compile -- compile a go.go-torture testcase.
  34. #
  35. # SRC is the full pathname of the testcase.
  36. # OPTION is the specific compiler flag we're testing (eg: -O2).
  37. #
  38. proc go-torture-compile { src option } {
  39. global output
  40. global srcdir tmpdir
  41. global host_triplet
  42. set output "$tmpdir/[file tail [file rootname $src]].o"
  43. regsub "(?q)$srcdir/" $src "" testcase
  44. # If we couldn't rip $srcdir out of `src' then just do the best we can.
  45. # The point is to reduce the unnecessary noise in the logs. Don't strip
  46. # out too much because different testcases with the same name can confuse
  47. # `test-tool'.
  48. if [string match "/*" $testcase] {
  49. set testcase "[file tail [file dirname $src]]/[file tail $src]"
  50. }
  51. verbose "Testing $testcase, $option" 1
  52. # Run the compiler and get results in comp_output.
  53. set options ""
  54. lappend options "additional_flags=-w $option"
  55. set comp_output [go_target_compile "$src" "$output" object $options]
  56. # See if we got something bad.
  57. set fatal_signal "*go*: Internal compiler error: program*got fatal signal"
  58. if [string match "$fatal_signal 6" $comp_output] then {
  59. go_fail $testcase "Got Signal 6, $option"
  60. catch { remote_file build delete $output }
  61. return
  62. }
  63. if [string match "$fatal_signal 11" $comp_output] then {
  64. go_fail $testcase "Got Signal 11, $option"
  65. catch { remote_file build delete $output }
  66. return
  67. }
  68. if [string match "*internal compiler error*" $comp_output] then {
  69. go_fail $testcase "$option (internal compiler error)"
  70. catch { remote_file build delete $output }
  71. return
  72. }
  73. # We shouldn't get these because of -w, but just in case.
  74. if [string match "*go*:*warning:*" $comp_output] then {
  75. warning "$testcase: (with warnings) $option"
  76. send_log "$comp_output\n"
  77. unresolved "$testcase, $option"
  78. catch { remote_file build delete $output }
  79. return
  80. }
  81. # Prune warnings we know are unwanted.
  82. set comp_output [prune_warnings $comp_output]
  83. # Report if the testcase is not supported.
  84. set unsupported_message [go_check_unsupported_p $comp_output]
  85. if { $unsupported_message != "" } {
  86. unsupported "$testcase: $unsupported_message"
  87. catch { remote_file build delete $output }
  88. return
  89. }
  90. # remove any leftover LF/CR to make sure any output is legit
  91. regsub -all -- "\[\r\n\]*" $comp_output "" comp_output
  92. # If any message remains, we fail.
  93. if ![string match "" $comp_output] then {
  94. go_fail $testcase $option
  95. catch { remote_file build delete $output }
  96. return
  97. }
  98. go_pass $testcase $option
  99. catch { remote_file build delete $output }
  100. }
  101. #
  102. # go-torture-execute -- compile and execute a testcase.
  103. #
  104. # SRC is the full pathname of the testcase.
  105. #
  106. # If the testcase has an associated .x file, we source that to run the
  107. # test instead. We use .x so that we don't lengthen the existing filename
  108. # to more than 14 chars.
  109. #
  110. proc go-torture-execute { src } {
  111. global output
  112. global srcdir tmpdir
  113. global tool
  114. global compiler_conditional_xfail_data
  115. global TORTURE_OPTIONS
  116. global go_compile_args
  117. global go_execute_args
  118. # Check for alternate driver.
  119. set additional_flags ""
  120. if [file exists [file rootname $src].x] {
  121. verbose "Using alternate driver [file rootname [file tail $src]].x" 2
  122. set done_p 0
  123. catch "set done_p \[source [file rootname $src].x\]"
  124. if { $done_p } {
  125. return
  126. }
  127. }
  128. # Setup the options for the testcase run.
  129. set option_list $TORTURE_OPTIONS
  130. set executable $tmpdir/[file tail [file rootname $src].x]
  131. regsub "(?q)$srcdir/" $src "" testcase
  132. if { ! [info exists go_compile_args] } {
  133. set go_compile_args ""
  134. }
  135. if { ! [info exists go_execute_args] } {
  136. set go_execute_args ""
  137. }
  138. # If we couldn't rip $srcdir out of `src' then just do the best we can.
  139. # The point is to reduce the unnecessary noise in the logs. Don't strip
  140. # out too much because different testcases with the same name can confuse
  141. # `test-tool'.
  142. if [string match "/*" $testcase] {
  143. set testcase "[file tail [file dirname $src]]/[file tail $src]"
  144. }
  145. # Walk the list of options and copmile and run the testcase for all
  146. # options that are not explicitly disabled by the .x script (if present).
  147. foreach option $option_list {
  148. # Torture_{compile,execute}_xfail are set by the .x script.
  149. if [info exists torture_compile_xfail] {
  150. setup_xfail $torture_compile_xfail
  151. }
  152. # Torture_execute_before_{compile,execute} can be set by the .x script.
  153. if [info exists torture_eval_before_compile] {
  154. set ignore_me [eval $torture_eval_before_compile]
  155. }
  156. # FIXME: We should make sure that the modules required by this testcase
  157. # exist. If not, the testcase should XFAIL.
  158. # Compile the testcase.
  159. catch { remote_file build delete $executable }
  160. verbose "Testing $testcase, $option" 1
  161. set options ""
  162. lappend options "additional_flags=-w $option"
  163. if { $additional_flags != "" } {
  164. lappend options "additional_flags=$additional_flags"
  165. }
  166. if { $go_compile_args != "" } {
  167. lappend options "additional_flags=$go_compile_args"
  168. }
  169. set comp_output [go_target_compile "$src" "$executable" executable $options]
  170. # See if we got something bad.
  171. set fatal_signal "*go*: Internal compiler error: program*got fatal signal"
  172. if [string match "$fatal_signal 6" $comp_output] then {
  173. go_fail $testcase "Got Signal 6, $option"
  174. catch { remote_file build delete $executable }
  175. continue
  176. }
  177. if [string match "$fatal_signal 11" $comp_output] then {
  178. go_fail $testcase "Got Signal 11, $option"
  179. catch { remote_file build delete $executable }
  180. continue
  181. }
  182. if [string match "*internal compiler error*" $comp_output] then {
  183. go_fail $testcase "$option (internal compiler error)"
  184. catch { remote_file build delete $executable }
  185. continue
  186. }
  187. # We shouldn't get these because of -w, but just in case.
  188. if [string match "*go*:*warning:*" $comp_output] then {
  189. warning "$testcase: (with warnings) $option"
  190. send_log "$comp_output\n"
  191. unresolved "$testcase, $option"
  192. catch { remote_file build delete $executable }
  193. continue
  194. }
  195. # Prune warnings we know are unwanted.
  196. set comp_output [prune_warnings $comp_output]
  197. # Report if the testcase is not supported.
  198. set unsupported_message [go_check_unsupported_p $comp_output]
  199. if { $unsupported_message != "" } {
  200. unsupported "$testcase: $unsupported_message"
  201. continue
  202. } elseif ![file exists $executable] {
  203. if ![is3way] {
  204. fail "$testcase compilation, $option"
  205. untested "$testcase execution, $option"
  206. continue
  207. } else {
  208. # FIXME: since we can't test for the existence of a remote
  209. # file without short of doing an remote file list, we assume
  210. # that since we got no output, it must have compiled.
  211. pass "$testcase compilation, $option"
  212. }
  213. } else {
  214. pass "$testcase compilation, $option"
  215. }
  216. if [info exists torture_execute_xfail] {
  217. setup_xfail $torture_execute_xfail
  218. }
  219. if [info exists torture_eval_before_execute] {
  220. set ignore_me [eval $torture_eval_before_execute]
  221. }
  222. # Run the testcase, and analyse the output.
  223. set result [go_load "$executable" "$go_execute_args" ""]
  224. set status [lindex $result 0]
  225. set output [lindex $result 1]
  226. # In order to cooperate nicely with the master Go testsuite,
  227. # if the output contains the string BUG, we treat the test as
  228. # failing.
  229. if [ string match "*BUG*" $output ] {
  230. set status "fail"
  231. }
  232. if { $status == "pass" } {
  233. catch { remote_file build delete $executable }
  234. }
  235. $status "$testcase execution, $option"
  236. }
  237. }
  238. #
  239. # search_for_re -- looks for a string match in a file
  240. #
  241. proc search_for_re { file pattern } {
  242. set fd [open $file r]
  243. while { [gets $fd cur_line]>=0 } {
  244. set lower [string tolower $cur_line]
  245. if [regexp "$pattern" $lower] then {
  246. close $fd
  247. return 1
  248. }
  249. }
  250. close $fd
  251. return 0
  252. }
  253. #
  254. # go-torture -- the go-torture testcase source file processor
  255. #
  256. # This runs compilation only tests (no execute tests).
  257. #
  258. # SRC is the full pathname of the testcase, or just a file name in which
  259. # case we prepend $srcdir/$subdir.
  260. #
  261. # If the testcase has an associated .x file, we source that to run the
  262. # test instead. We use .x so that we don't lengthen the existing filename
  263. # to more than 14 chars.
  264. #
  265. proc go-torture { args } {
  266. global srcdir subdir
  267. global compiler_conditional_xfail_data
  268. global TORTURE_OPTIONS
  269. set src [lindex $args 0]
  270. if { [llength $args] > 1 } {
  271. set options [lindex $args 1]
  272. } else {
  273. set options ""
  274. }
  275. # Prepend $srdir/$subdir if missing.
  276. if ![string match "*/*" $src] {
  277. set src "$srcdir/$subdir/$src"
  278. }
  279. # Check for alternate driver.
  280. if [file exists [file rootname $src].x] {
  281. verbose "Using alternate driver [file rootname [file tail $src]].x" 2
  282. set done_p 0
  283. catch "set done_p \[source [file rootname $src].x\]"
  284. if { $done_p } {
  285. return
  286. }
  287. }
  288. # loop through all the options
  289. set option_list $TORTURE_OPTIONS
  290. foreach option $option_list {
  291. # torture_compile_xfail is set by the .x script (if present)
  292. if [info exists torture_compile_xfail] {
  293. setup_xfail $torture_compile_xfail
  294. }
  295. # torture_execute_before_compile is set by the .x script (if present)
  296. if [info exists torture_eval_before_compile] {
  297. set ignore_me [eval $torture_eval_before_compile]
  298. }
  299. go-torture-compile $src "$option $options"
  300. }
  301. }
  302. #
  303. # add-ieee-options -- add options necessary for 100% ieee conformance.
  304. #
  305. proc add-ieee-options { } {
  306. # Ensure that excess precision does not cause problems.
  307. if { [istarget i?86-*-*]
  308. || [istarget m68k-*-*] } then {
  309. uplevel 1 lappend additional_flags "-ffloat-store"
  310. }
  311. # Enable full IEEE compliance mode.
  312. if { [istarget alpha*-*-*]
  313. || [istarget sh*-*-*] } then {
  314. uplevel 1 lappend additional_flags "-mieee"
  315. }
  316. }