fortran-torture.exp 13 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434
  1. # Copyright (C) 2003-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 Steven Bosscher (s.bosscher@student.tudelft.nl)
  18. # based on f-torture.exp, which was written by Rob Savoye.
  19. load_lib target-supports.exp
  20. load_lib fortran-modules.exp
  21. load_lib target-utils.exp
  22. # Return the list of options to use for fortran torture tests.
  23. # The default option list can be overridden by
  24. # TORTURE_OPTIONS="{ { list1 } ... { listN } }"
  25. proc get-fortran-torture-options { } {
  26. global TORTURE_OPTIONS
  27. if [info exists TORTURE_OPTIONS] {
  28. return $TORTURE_OPTIONS
  29. }
  30. # determine if host supports vectorization, and the necessary set
  31. # of options, based on code from testsuite/vect/vect.exp
  32. set vectorizer_options [list "-O2" "-ftree-vectorize"]
  33. if { [istarget powerpc*-*-*]
  34. && [is-effective-target powerpc_altivec_ok]
  35. && [check_vmx_hw_available] } {
  36. lappend vectorizer_options "-maltivec"
  37. set test_tree_vectorize 1
  38. } elseif { [istarget spu-*-*] } {
  39. set test_tree_vectorize 1
  40. } elseif { ( [istarget i?86-*-*] || [istarget x86_64-*-*] )
  41. && [check_effective_target_sse2]
  42. && [check_sse2_hw_available]
  43. && [check_sse_os_support_available] } {
  44. lappend vectorizer_options "-msse2"
  45. set test_tree_vectorize 1
  46. } elseif { [istarget mips*-*-*]
  47. && [check_effective_target_mpaired_single]
  48. && [check_effective_target_nomips16] } {
  49. lappend vectorizer_options "-mpaired-single"
  50. set test_tree_vectorize 1
  51. } elseif { [istarget sparc*-*-*]
  52. && [check_effective_target_ultrasparc_hw] } {
  53. lappend vectorizer_options "-mcpu=ultrasparc" "-mvis"
  54. set test_tree_vectorize 1
  55. } elseif { [istarget alpha*-*-*]
  56. && [check_alpha_max_hw_available] } {
  57. lappend vectorizer_options "-mmax"
  58. set test_tree_vectorize 1
  59. } elseif [istarget ia64-*-*] {
  60. set test_tree_vectorize 1
  61. } else {
  62. set test_tree_vectorize 0
  63. }
  64. set options {}
  65. lappend options \
  66. { -O0 } \
  67. { -O1 } \
  68. { -O2 } \
  69. { -O2 -fomit-frame-pointer -finline-functions } \
  70. { -O2 -fomit-frame-pointer -finline-functions -funroll-loops } \
  71. { -O2 -fbounds-check } \
  72. { -O3 -g } \
  73. { -Os }
  74. if { $test_tree_vectorize } {
  75. lappend options $vectorizer_options
  76. }
  77. if [info exists ADDITIONAL_TORTURE_OPTIONS] {
  78. set options [concat $options $ADDITIONAL_TORTURE_OPTIONS]
  79. }
  80. return $options
  81. }
  82. #
  83. # fortran-torture-compile -- compile a gfortran.fortran-torture testcase.
  84. #
  85. # SRC is the full pathname of the testcase.
  86. # OPTION is the specific compiler flag we're testing (eg: -O2).
  87. #
  88. proc fortran-torture-compile { src option } {
  89. global output
  90. global srcdir tmpdir
  91. global host_triplet
  92. set output "$tmpdir/[file tail [file rootname $src]].o"
  93. regsub "(?q)$srcdir/" $src "" testcase
  94. # If we couldn't rip $srcdir out of `src' then just do the best we can.
  95. # The point is to reduce the unnecessary noise in the logs. Don't strip
  96. # out too much because different testcases with the same name can confuse
  97. # `test-tool'.
  98. if [string match "/*" $testcase] {
  99. set testcase "[file tail [file dirname $src]]/[file tail $src]"
  100. }
  101. verbose "Testing $testcase, $option" 1
  102. # Run the compiler and get results in comp_output.
  103. set options ""
  104. lappend options "additional_flags=-w $option"
  105. set comp_output [gfortran_target_compile "$src" "$output" object $options]
  106. # See if we got something bad.
  107. set fatal_signal "*95*: Internal compiler error: program*got fatal signal"
  108. if [string match "$fatal_signal 6" $comp_output] then {
  109. gfortran_fail $testcase "Got Signal 6, $option"
  110. catch { remote_file build delete $output }
  111. return
  112. }
  113. if [string match "$fatal_signal 11" $comp_output] then {
  114. gfortran_fail $testcase "Got Signal 11, $option"
  115. catch { remote_file build delete $output }
  116. return
  117. }
  118. if [string match "*internal compiler error*" $comp_output] then {
  119. gfortran_fail $testcase "$option (internal compiler error)"
  120. catch { remote_file build delete $output }
  121. return
  122. }
  123. # We shouldn't get these because of -w, but just in case.
  124. if [string match "*95*:*warning:*" $comp_output] then {
  125. warning "$testcase: (with warnings) $option"
  126. send_log "$comp_output\n"
  127. unresolved "$testcase, $option"
  128. catch { remote_file build delete $output }
  129. return
  130. }
  131. # Prune warnings we know are unwanted.
  132. set comp_output [prune_warnings $comp_output]
  133. # Report if the testcase is not supported.
  134. set unsupported_message [gfortran_check_unsupported_p $comp_output]
  135. if { $unsupported_message != "" } {
  136. unsupported "$testcase: $unsupported_message"
  137. catch { remote_file build delete $output }
  138. return
  139. }
  140. # remove any leftover LF/CR to make sure any output is legit
  141. regsub -all -- "\[\r\n\]*" $comp_output "" comp_output
  142. # If any message remains, we fail.
  143. if ![string match "" $comp_output] then {
  144. gfortran_fail $testcase $option
  145. catch { remote_file build delete $output }
  146. return
  147. }
  148. gfortran_pass $testcase $option
  149. catch { remote_file build delete $output }
  150. }
  151. #
  152. # fortran-torture-execute -- compile and execute a testcase.
  153. #
  154. # SRC is the full pathname of the testcase.
  155. #
  156. # If the testcase has an associated .x file, we source that to run the
  157. # test instead. We use .x so that we don't lengthen the existing filename
  158. # to more than 14 chars.
  159. #
  160. proc fortran-torture-execute { src } {
  161. global output
  162. global srcdir tmpdir
  163. global tool
  164. global compiler_conditional_xfail_data
  165. global torture_with_loops
  166. # Check for alternate driver.
  167. set additional_flags ""
  168. if [file exists [file rootname $src].x] {
  169. verbose "Using alternate driver [file rootname [file tail $src]].x" 2
  170. set done_p 0
  171. catch "set done_p \[source [file rootname $src].x\]"
  172. if { $done_p } {
  173. return
  174. }
  175. }
  176. # Setup the options for the testcase run.
  177. set option_list $torture_with_loops
  178. set executable $tmpdir/[file tail [file rootname $src].x]
  179. regsub "(?q)$srcdir/" $src "" testcase
  180. # If we couldn't rip $srcdir out of `src' then just do the best we can.
  181. # The point is to reduce the unnecessary noise in the logs. Don't strip
  182. # out too much because different testcases with the same name can confuse
  183. # `test-tool'.
  184. if [string match "/*" $testcase] {
  185. set testcase "[file tail [file dirname $src]]/[file tail $src]"
  186. }
  187. list-module-names $src
  188. # Walk the list of options and copmile and run the testcase for all
  189. # options that are not explicitly disabled by the .x script (if present).
  190. foreach option $option_list {
  191. # Torture_{compile,execute}_xfail are set by the .x script.
  192. if [info exists torture_compile_xfail] {
  193. setup_xfail $torture_compile_xfail
  194. }
  195. # Torture_execute_before_{compile,execute} can be set by the .x script.
  196. if [info exists torture_eval_before_compile] {
  197. set ignore_me [eval $torture_eval_before_compile]
  198. }
  199. # FIXME: We should make sure that the modules required by this testcase
  200. # exist. If not, the testcase should XFAIL.
  201. # Compile the testcase.
  202. catch { remote_file build delete $executable }
  203. verbose "Testing $testcase, $option" 1
  204. set options ""
  205. lappend options "additional_flags=-w $option"
  206. if { $additional_flags != "" } {
  207. lappend options "additional_flags=$additional_flags"
  208. }
  209. set comp_output [gfortran_target_compile "$src" "$executable" executable $options]
  210. # See if we got something bad.
  211. set fatal_signal "*95*: Internal compiler error: program*got fatal signal"
  212. if [string match "$fatal_signal 6" $comp_output] then {
  213. gfortran_fail $testcase "Got Signal 6, $option"
  214. catch { remote_file build delete $executable }
  215. continue
  216. }
  217. if [string match "$fatal_signal 11" $comp_output] then {
  218. gfortran_fail $testcase "Got Signal 11, $option"
  219. catch { remote_file build delete $executable }
  220. continue
  221. }
  222. if [string match "*internal compiler error*" $comp_output] then {
  223. gfortran_fail $testcase "$option (internal compiler error)"
  224. catch { remote_file build delete $executable }
  225. continue
  226. }
  227. # We shouldn't get these because of -w, but just in case.
  228. if [string match "*95*:*warning:*" $comp_output] then {
  229. warning "$testcase: (with warnings) $option"
  230. send_log "$comp_output\n"
  231. unresolved "$testcase, $option"
  232. catch { remote_file build delete $executable }
  233. continue
  234. }
  235. # Prune warnings we know are unwanted.
  236. set comp_output [prune_warnings $comp_output]
  237. # Report if the testcase is not supported.
  238. set unsupported_message [gfortran_check_unsupported_p $comp_output]
  239. if { $unsupported_message != "" } {
  240. unsupported "$testcase: $unsupported_message"
  241. continue
  242. } elseif ![file exists $executable] {
  243. if ![is3way] {
  244. fail "$testcase compilation, $option"
  245. untested "$testcase execution, $option"
  246. continue
  247. } else {
  248. # FIXME: since we can't test for the existence of a remote
  249. # file without short of doing an remote file list, we assume
  250. # that since we got no output, it must have compiled.
  251. pass "$testcase compilation, $option"
  252. }
  253. } else {
  254. pass "$testcase compilation, $option"
  255. }
  256. # See if this source file uses INTEGER(KIND=8) types, if it does, and
  257. # no_long_long is set, skip execution of the test.
  258. # FIXME: We should also look for F95 style "_8" or select_int_kind()
  259. # integers, but that is obviously much harder than just regexping this.
  260. # So maybe we should just avoid those in testcases.
  261. if [target_info exists no_long_long] then {
  262. if [expr [search_for_re $src "integer\*8"] \
  263. +[search_for_re $src "integer *( *8 *)"] \
  264. +[search_for_re $src "integer *( *kind *= *8 *)"]] \
  265. then {
  266. untested "$testcase execution, $option"
  267. continue
  268. }
  269. }
  270. if [info exists torture_execute_xfail] {
  271. setup_xfail $torture_execute_xfail
  272. }
  273. if [info exists torture_eval_before_execute] {
  274. set ignore_me [eval $torture_eval_before_execute]
  275. }
  276. # Run the testcase, and analyse the output.
  277. set result [gfortran_load "$executable" "" ""]
  278. set status [lindex $result 0]
  279. set output [lindex $result 1]
  280. if { $status == "pass" } {
  281. catch { remote_file build delete $executable }
  282. }
  283. $status "$testcase execution, $option"
  284. }
  285. cleanup-modules ""
  286. }
  287. #
  288. # search_for_re -- looks for a string match in a file
  289. #
  290. proc search_for_re { file pattern } {
  291. set fd [open $file r]
  292. while { [gets $fd cur_line]>=0 } {
  293. set lower [string tolower $cur_line]
  294. if [regexp "$pattern" $lower] then {
  295. close $fd
  296. return 1
  297. }
  298. }
  299. close $fd
  300. return 0
  301. }
  302. #
  303. # fortran-torture -- the fortran-torture testcase source file processor
  304. #
  305. # This runs compilation only tests (no execute tests).
  306. #
  307. # SRC is the full pathname of the testcase, or just a file name in which
  308. # case we prepend $srcdir/$subdir.
  309. #
  310. # If the testcase has an associated .x file, we source that to run the
  311. # test instead. We use .x so that we don't lengthen the existing filename
  312. # to more than 14 chars.
  313. #
  314. proc fortran-torture { args } {
  315. global srcdir subdir
  316. global compiler_conditional_xfail_data
  317. global torture_with_loops
  318. set src [lindex $args 0]
  319. if { [llength $args] > 1 } {
  320. set options [lindex $args 1]
  321. } else {
  322. set options ""
  323. }
  324. # Prepend $srdir/$subdir if missing.
  325. if ![string match "*/*" $src] {
  326. set src "$srcdir/$subdir/$src"
  327. }
  328. # Check for alternate driver.
  329. if [file exists [file rootname $src].x] {
  330. verbose "Using alternate driver [file rootname [file tail $src]].x" 2
  331. set done_p 0
  332. catch "set done_p \[source [file rootname $src].x\]"
  333. if { $done_p } {
  334. return
  335. }
  336. }
  337. list-module-names $src
  338. # loop through all the options
  339. set option_list $torture_with_loops
  340. foreach option $option_list {
  341. # torture_compile_xfail is set by the .x script (if present)
  342. if [info exists torture_compile_xfail] {
  343. setup_xfail $torture_compile_xfail
  344. }
  345. # torture_execute_before_compile is set by the .x script (if present)
  346. if [info exists torture_eval_before_compile] {
  347. set ignore_me [eval $torture_eval_before_compile]
  348. }
  349. fortran-torture-compile $src "$option $options"
  350. cleanup-modules ""
  351. }
  352. }
  353. #
  354. # add-ieee-options -- add options necessary for 100% ieee conformance.
  355. #
  356. proc add-ieee-options { } {
  357. # Ensure that excess precision does not cause problems.
  358. if { [istarget i?86-*-*]
  359. || [istarget m68k-*-*] } then {
  360. uplevel 1 lappend additional_flags "-ffloat-store"
  361. }
  362. # Enable full IEEE compliance mode.
  363. if { [istarget alpha*-*-*]
  364. || [istarget sh*-*-*] } then {
  365. uplevel 1 lappend additional_flags "-mieee"
  366. }
  367. }