c-torture.exp 10 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336
  1. # Copyright (C) 1992-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. # This file was written by Rob Savoye. (rob@cygnus.com)
  16. load_lib target-supports.exp
  17. load_lib file-format.exp
  18. load_lib target-libpath.exp
  19. load_lib target-utils.exp
  20. # The default option list can be overridden by
  21. # TORTURE_OPTIONS="{ { list1 } ... { listN } }"
  22. if [info exists TORTURE_OPTIONS] {
  23. set C_TORTURE_OPTIONS $TORTURE_OPTIONS
  24. } else {
  25. # It is theoretically beneficial to group all of the O2/O3 options together,
  26. # as in many cases the compiler will generate identical executables for
  27. # all of them--and the c-torture testsuite will skip testing identical
  28. # executables multiple times.
  29. # Also note that -finline-functions is explicitly included in one of the
  30. # items below, even though -O3 is also specified, because some ports may
  31. # choose to disable inlining functions by default, even when optimizing.
  32. set C_TORTURE_OPTIONS [list \
  33. { -O0 } \
  34. { -O1 } \
  35. { -O2 } \
  36. { -O3 -fomit-frame-pointer } \
  37. { -O3 -fomit-frame-pointer -funroll-loops } \
  38. { -O3 -fomit-frame-pointer -funroll-all-loops -finline-functions } \
  39. { -O3 -g } \
  40. { -Os } \
  41. { -Og -g } ]
  42. }
  43. if [info exists ADDITIONAL_TORTURE_OPTIONS] {
  44. set C_TORTURE_OPTIONS \
  45. [concat $C_TORTURE_OPTIONS $ADDITIONAL_TORTURE_OPTIONS]
  46. }
  47. global GCC_UNDER_TEST
  48. if ![info exists GCC_UNDER_TEST] {
  49. set GCC_UNDER_TEST "[find_gcc]"
  50. }
  51. global orig_environment_saved
  52. # This file may be sourced, so don't override environment settings
  53. # that have been previously setup.
  54. if { $orig_environment_saved == 0 } {
  55. append ld_library_path [gcc-set-multilib-library-path $GCC_UNDER_TEST]
  56. set_ld_library_path_env_vars
  57. }
  58. set LTO_TORTURE_OPTIONS ""
  59. if [check_effective_target_lto] {
  60. # When having plugin test both slim and fat LTO and plugin/nonplugin
  61. # path.
  62. if [check_linker_plugin_available] {
  63. set LTO_TORTURE_OPTIONS [list \
  64. { -O2 -flto -fno-use-linker-plugin -flto-partition=none } \
  65. { -O2 -flto -fuse-linker-plugin -fno-fat-lto-objects }
  66. ]
  67. } else {
  68. set LTO_TORTURE_OPTIONS [list \
  69. { -O2 -flto -flto-partition=none } \
  70. { -O2 -flto }
  71. ]
  72. }
  73. }
  74. #
  75. # c-torture-compile -- runs the Tege C-torture test
  76. #
  77. # SRC is the full pathname of the testcase.
  78. # OPTION is the specific compiler flag we're testing (eg: -O2).
  79. #
  80. proc c-torture-compile { src option } {
  81. global output
  82. global srcdir tmpdir
  83. global host_triplet
  84. set output "$tmpdir/[file tail [file rootname $src]].o"
  85. regsub "(?q)$srcdir/" $src "" testcase
  86. # If we couldn't rip $srcdir out of `src' then just do the best we can.
  87. # The point is to reduce the unnecessary noise in the logs. Don't strip
  88. # out too much because different testcases with the same name can confuse
  89. # `test-tool'.
  90. if [string match "/*" $testcase] {
  91. set testcase "[file tail [file dirname $src]]/[file tail $src]"
  92. }
  93. verbose "Testing $testcase, $option" 1
  94. # Run the compiler and analyze the results.
  95. set options ""
  96. lappend options "additional_flags=-w $option"
  97. set comp_output [gcc_target_compile "$src" "$output" object $options]
  98. gcc_check_compile $testcase $option $output $comp_output
  99. file_on_host delete $output
  100. }
  101. #
  102. # c-torture-execute -- utility to compile and execute a testcase
  103. #
  104. # SOURCES is a list of full pathnames to the test source files.
  105. # The first filename in this list forms the "testcase".
  106. #
  107. # If the testcase has an associated .x file, we source that to run the
  108. # test instead. We use .x so that we don't lengthen the existing filename
  109. # to more than 14 chars.
  110. #
  111. proc c-torture-execute { sources args } {
  112. global tmpdir tool srcdir output compiler_conditional_xfail_data
  113. # Use the first source filename given as the filename under test.
  114. set src [lindex $sources 0]
  115. if { [llength $args] > 0 } {
  116. set additional_flags [lindex $args 0]
  117. } else {
  118. set additional_flags ""
  119. }
  120. # Check for alternate driver.
  121. if [file exists [file rootname $src].x] {
  122. verbose "Using alternate driver [file rootname [file tail $src]].x" 2
  123. set done_p 0
  124. catch "set done_p \[source [file rootname $src].x\]"
  125. if { $done_p } {
  126. return
  127. }
  128. }
  129. # Look for a loop within the source code - if we don't find one,
  130. # don't pass -funroll[-all]-loops.
  131. global torture_with_loops torture_without_loops
  132. if [expr [search_for $src "for*("]+[search_for $src "while*("]] then {
  133. set option_list $torture_with_loops
  134. } else {
  135. set option_list $torture_without_loops
  136. }
  137. set executable $tmpdir/[file tail [file rootname $src].x]
  138. regsub "(?q)$srcdir/" $src "" testcase
  139. # If we couldn't rip $srcdir out of `src' then just do the best we can.
  140. # The point is to reduce the unnecessary noise in the logs. Don't strip
  141. # out too much because different testcases with the same name can confuse
  142. # `test-tool'.
  143. if [string match "/*" $testcase] {
  144. set testcase "[file tail [file dirname $src]]/[file tail $src]"
  145. }
  146. set count 0
  147. set oldstatus "foo"
  148. foreach option $option_list {
  149. if { $count > 0 } {
  150. set oldexec $execname
  151. }
  152. set execname "${executable}${count}"
  153. incr count
  154. # torture_{compile,execute}_xfail are set by the .x script
  155. # (if present)
  156. if [info exists torture_compile_xfail] {
  157. setup_xfail $torture_compile_xfail
  158. }
  159. # torture_execute_before_{compile,execute} can be set by the .x script
  160. # (if present)
  161. if [info exists torture_eval_before_compile] {
  162. set ignore_me [eval $torture_eval_before_compile]
  163. }
  164. file_on_host delete $execname
  165. verbose "Testing $testcase, $option" 1
  166. set options ""
  167. lappend options "additional_flags=-w $option"
  168. if { $additional_flags != "" } {
  169. lappend options "additional_flags=$additional_flags"
  170. }
  171. set comp_output [gcc_target_compile "$sources" "${execname}" executable $options]
  172. if ![gcc_check_compile "$testcase compilation" $option $execname $comp_output] {
  173. unresolved "$testcase execution, $option"
  174. file_on_host delete $execname
  175. continue
  176. }
  177. # See if this source file uses "long long" types, if it does, and
  178. # no_long_long is set, skip execution of the test.
  179. if [target_info exists no_long_long] then {
  180. if [expr [search_for $src "long long"]] then {
  181. unsupported "$testcase execution, $option"
  182. continue
  183. }
  184. }
  185. if [info exists torture_execute_xfail] {
  186. setup_xfail $torture_execute_xfail
  187. }
  188. if [info exists torture_eval_before_execute] {
  189. set ignore_me [eval $torture_eval_before_execute]
  190. }
  191. # Sometimes we end up creating identical executables for two
  192. # consecutive sets of different of compiler options.
  193. #
  194. # In such cases we know the result of this test will be identical
  195. # to the result of the last test.
  196. #
  197. # So in cases where the time to load and run/simulate the test
  198. # is relatively high, compare the two binaries and avoid rerunning
  199. # tests if the executables are identical.
  200. #
  201. # Do not do this for native testing since the cost to load/execute
  202. # the test is fairly small and the comparison step actually slows
  203. # the entire process down because it usually does not "hit".
  204. set skip 0
  205. if { ![isnative] && [info exists oldexec] } {
  206. if { [file_on_host cmp $oldexec $execname] == 0 } {
  207. set skip 1
  208. }
  209. }
  210. if { $skip == 0 } {
  211. set result [gcc_load "$execname" "" ""]
  212. set status [lindex $result 0]
  213. set output [lindex $result 1]
  214. }
  215. if { $oldstatus == "pass" } {
  216. file_on_host delete $oldexec
  217. }
  218. $status "$testcase execution, $option"
  219. set oldstatus $status
  220. }
  221. if [info exists status] {
  222. if { $status == "pass" } {
  223. file_on_host delete $execname
  224. }
  225. }
  226. }
  227. #
  228. # search_for -- looks for a string match in a file
  229. #
  230. proc search_for { file pattern } {
  231. set fd [open $file r]
  232. while { [gets $fd cur_line]>=0 } {
  233. if [string match "*$pattern*" $cur_line] then {
  234. close $fd
  235. return 1
  236. }
  237. }
  238. close $fd
  239. return 0
  240. }
  241. #
  242. # c-torture -- the c-torture testcase source file processor
  243. #
  244. # This runs compilation only tests (no execute tests).
  245. # SRC is the full pathname of the testcase, or just a file name in which case
  246. # we prepend $srcdir/$subdir.
  247. #
  248. # If the testcase has an associated .x file, we source that to run the
  249. # test instead. We use .x so that we don't lengthen the existing filename
  250. # to more than 14 chars.
  251. #
  252. proc c-torture { args } {
  253. global srcdir subdir compiler_conditional_xfail_data
  254. set src [lindex $args 0]
  255. if { [llength $args] > 1 } {
  256. set options [lindex $args 1]
  257. } else {
  258. set options ""
  259. }
  260. # Prepend $srdir/$subdir if missing.
  261. if ![string match "*/*" $src] {
  262. set src "$srcdir/$subdir/$src"
  263. }
  264. # Check for alternate driver.
  265. if [file exists [file rootname $src].x] {
  266. verbose "Using alternate driver [file rootname [file tail $src]].x" 2
  267. set done_p 0
  268. catch "set done_p \[source [file rootname $src].x\]"
  269. if { $done_p } {
  270. return
  271. }
  272. }
  273. # Look for a loop within the source code - if we don't find one,
  274. # don't pass -funroll[-all]-loops.
  275. global torture_with_loops torture_without_loops
  276. if [expr [search_for $src "for*("]+[search_for $src "while*("]] then {
  277. set option_list $torture_with_loops
  278. } else {
  279. set option_list $torture_without_loops
  280. }
  281. # loop through all the options
  282. foreach option $option_list {
  283. # torture_compile_xfail is set by the .x script (if present)
  284. if [info exists torture_compile_xfail] {
  285. setup_xfail $torture_compile_xfail
  286. }
  287. # torture_execute_before_compile is set by the .x script (if present)
  288. if [info exists torture_eval_before_compile] {
  289. set ignore_me [eval $torture_eval_before_compile]
  290. }
  291. c-torture-compile $src "$option $options"
  292. }
  293. }