compat.exp 14 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399
  1. # Copyright (C) 2002-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 Janis Johnson, <janis187@us.ibm.com>
  16. # Test interoperability of two compilers that follow the same ABI, or
  17. # compatibility of two versions of GCC.
  18. #
  19. # Each test has a main program that does nothing but call a function,
  20. # plus two additional source files that contain parts of a program that
  21. # rely on the ABI. those source files are compiled into relocatable
  22. # object files with both compilers. Executables are built using various
  23. # combinations of those object files, with the main program compiled
  24. # with the compiler under test and using that compiler's runtime support.
  25. # The including .exp file must define these callback procedures.
  26. if [string match "" [info procs "compat-use-alt-compiler"]] then {
  27. error "Proc compat-use-alt-compiler is not defined."
  28. }
  29. if [string match "" [info procs "compat-use-tst-compiler"]] then {
  30. error "Proc compat-use-tst-compiler is not defined."
  31. }
  32. # Each test is run with each pair of compiler options from this list.
  33. # The first set of options in each pair is used by the compiler under
  34. # test, and the second set is used by the alternate compiler.
  35. # The default option lists can be overridden by
  36. # COMPAT_OPTIONS="[list [list {tst_1} {alt_1}]...[list {tst_n} {alt_n}]]"
  37. # where tst_i and alt_i are lists of options. You can put this in the
  38. # environment before site.exp is written or add it to site.exp directly.
  39. if ![info exists COMPAT_OPTIONS] {
  40. set COMPAT_OPTIONS [list \
  41. [list {} {}]]
  42. }
  43. set compat_option_list $COMPAT_OPTIONS
  44. # Subsets of tests can be selectively disabled by members of this list:
  45. # - ATTRIBUTE: disable all tests using the __attribute__ extension,
  46. # - COMPLEX: disable all tests using the complex types feature,
  47. # - COMPLEX_INT: disable all tests using the complex integral types extension,
  48. # - VA: disable all tests using the variable number of arguments feature,
  49. # - VLA_IN_STRUCT: disable all tests using the variable-length arrays as
  50. # structure members extension,
  51. # - ZERO_ARRAY: disable all tests using the zero-sized arrays extension.
  52. # The default skip lists can be overriden by
  53. # COMPAT_SKIPS="[list {skip_1}...{skip_n}]"
  54. # where skip_i are skip identifiers. You can put this in the environment
  55. # before site.exp is written or add it to site.exp directly.
  56. if ![info exists COMPAT_SKIPS] {
  57. set COMPAT_SKIPS [list {}]
  58. }
  59. global compat_skip_list
  60. set compat_skip_list $COMPAT_SKIPS
  61. load_lib dg.exp
  62. load_lib gcc-dg.exp
  63. #
  64. # compat-obj -- compile to an object file
  65. #
  66. # SOURCE is the source file
  67. # DEST is the object file
  68. # OPTALL is the list of compiler options to use with all tests
  69. # OPTFILE is the list of compiler options to use with this file
  70. # OPTSTR is the options to print with test messages
  71. # XFAILDATA is the xfail data to be passed to the compiler
  72. #
  73. proc compat-obj { source dest optall optfile optstr xfaildata } {
  74. global testcase
  75. global tool
  76. global compiler_conditional_xfail_data
  77. global compat_skip_list
  78. # Add the skip specifiers.
  79. foreach skip $compat_skip_list {
  80. if { ![string match $skip ""] } {
  81. lappend optall "-DSKIP_$skip"
  82. }
  83. }
  84. # Set up the options for compiling this file.
  85. set options ""
  86. lappend options "additional_flags=$optfile $optall"
  87. set compiler_conditional_xfail_data $xfaildata
  88. set comp_output [${tool}_target_compile "$source" "$dest" object $options]
  89. ${tool}_check_compile "$testcase $dest compile" $optstr $dest $comp_output
  90. }
  91. # compat-run -- link and run an executable
  92. #
  93. # TESTNAME is the mixture of object files to link
  94. # OBJLIST is the list of object files to link
  95. # DEST is the name of the executable
  96. # OPTALL is a list of compiler and linker options to use for all tests
  97. # OPTFILE is a list of compiler and linker options to use for this test
  98. # OPTSTR is the list of options to list in messages
  99. #
  100. proc compat-run { testname objlist dest optall optfile optstr } {
  101. global testcase
  102. global tool
  103. # Check that all of the objects were built successfully.
  104. foreach obj [split $objlist] {
  105. if ![file_on_host exists $obj] then {
  106. unresolved "$testcase $testname link $optstr"
  107. unresolved "$testcase $testname execute $optstr"
  108. return
  109. }
  110. }
  111. # Set up the options for linking this test.
  112. set options ""
  113. lappend options "additional_flags=$optfile $optall"
  114. # Link the objects into an executable.
  115. set comp_output [${tool}_target_compile "$objlist" $dest executable \
  116. "$options"]
  117. if ![${tool}_check_compile "$testcase $testname link" "" \
  118. $dest $comp_output] then {
  119. return
  120. }
  121. # Run the self-checking executable.
  122. if ![string match "*/*" $dest] then {
  123. set dest "./$dest"
  124. }
  125. set result [${tool}_load $dest "" ""]
  126. set status [lindex $result 0]
  127. if { $status == "pass" } then {
  128. file_on_host delete $dest
  129. }
  130. $status "$testcase $testname execute $optstr"
  131. }
  132. #
  133. # compat-get-options-main -- get target requirements for a test and
  134. # options for the primary source file and the test as a whole
  135. #
  136. # SRC is the full pathname of the primary source file.
  137. #
  138. proc compat-get-options-main { src } {
  139. # dg-options sets a variable called dg-extra-tool-flags.
  140. set dg-extra-tool-flags ""
  141. # dg-options sets a variable called tool_flags.
  142. set tool_flags ""
  143. # dg-require-* sets dg-do-what.
  144. upvar dg-do-what dg-do-what
  145. set tmp [dg-get-options $src]
  146. foreach op $tmp {
  147. set cmd [lindex $op 0]
  148. if { ![string compare "dg-options" $cmd] \
  149. || [string match "dg-prune-output" $cmd] \
  150. || [string match "dg-skip-if" $cmd] \
  151. || [string match "dg-require-*" $cmd] } {
  152. set status [catch "$op" errmsg]
  153. if { $status != 0 } {
  154. perror "src: $errmsg for \"$op\"\n"
  155. unresolved "$src: $errmsg for \"$op\""
  156. return
  157. }
  158. } elseif { ![string compare "dg-xfail-if" $cmd] } {
  159. warning "compat.exp does not support $cmd in primary source file"
  160. } else {
  161. # Ignore unrecognized dg- commands, but warn about them.
  162. warning "compat.exp does not support $cmd"
  163. }
  164. }
  165. # Return flags to use for compiling the primary source file and for
  166. # linking.
  167. return ${dg-extra-tool-flags}
  168. }
  169. #
  170. # compat-get-options -- get special tool flags to use for a secondary
  171. # source file
  172. #
  173. # SRC is the full pathname of the source file.
  174. # The result is a list of options to use.
  175. #
  176. # This code is copied from proc dg-test in dg.exp from DejaGNU.
  177. #
  178. proc compat-get-options { src } {
  179. # dg-options sets a variable called dg-extra-tool-flags.
  180. set dg-extra-tool-flags ""
  181. # dg-xfail-if sets compiler_conditional_xfail_data.
  182. global compiler_conditional_xfail_data
  183. set compiler_conditional_xfail_data ""
  184. # dg-xfail-if needs access to dg-do-what.
  185. upvar dg-do-what dg-do-what
  186. set tmp [dg-get-options $src]
  187. foreach op $tmp {
  188. set cmd [lindex $op 0]
  189. if { ![string compare "dg-options" $cmd] \
  190. || ![string compare "dg-prune-output" $cmd] \
  191. || ![string compare "dg-xfail-if" $cmd] } {
  192. set status [catch "$op" errmsg]
  193. if { $status != 0 } {
  194. perror "src: $errmsg for \"$op\"\n"
  195. unresolved "$src: $errmsg for \"$op\""
  196. return
  197. }
  198. } elseif { [string match "dg-require-*" $cmd] } {
  199. warning "compat.exp does not support $cmd in secondary source files"
  200. } else {
  201. # Ignore unrecognized dg- commands, but warn about them.
  202. warning "compat.exp does not support $cmd"
  203. }
  204. }
  205. return ${dg-extra-tool-flags}
  206. }
  207. #
  208. # compat-execute -- compile with compatible compilers
  209. #
  210. # SRC1 is the full pathname of the main file of the testcase.
  211. # SID identifies a test suite in the names of temporary files.
  212. # USE_ALT is nonzero if we're using an alternate compiler as well as
  213. # the compiler under test.
  214. #
  215. proc compat-execute { src1 sid use_alt } {
  216. global srcdir tmpdir
  217. global compat_option_list
  218. global tool
  219. global verbose
  220. global testcase
  221. global gluefile
  222. global compiler_conditional_xfail_data
  223. global dg-do-what-default
  224. # Get extra flags for this test from the primary source file, and
  225. # process other dg-* options that this suite supports. Warn about
  226. # unsupported flags.
  227. verbose "compat-execute: $src1" 1
  228. set dg-do-what [list ${dg-do-what-default} "" P]
  229. set extra_flags_1 [compat-get-options-main $src1]
  230. # Set up the names of the other source files.
  231. set dir [file dirname $src1]
  232. set ext [file extension $src1]
  233. set base [file rootname $src1]
  234. set base [string range $base [string length $dir] end]
  235. regsub "_main" $base "" base
  236. set src2 "${dir}/${base}_x${ext}"
  237. set src3 "${dir}/${base}_y${ext}"
  238. # Use the dg-options mechanism to specify extra flags for this test.
  239. # The extra flags in each file are used to compile that file, and the
  240. # extra flags in *_main.* are also used for linking.
  241. set extra_flags_2 [compat-get-options $src2]
  242. set compile_xfail_2 $compiler_conditional_xfail_data
  243. set extra_flags_3 [compat-get-options $src3]
  244. set compile_xfail_3 $compiler_conditional_xfail_data
  245. # On the SPU, most of the compat test cases exceed local store size.
  246. # Use automatic overlay support to make them fit.
  247. if { [check_effective_target_spu_auto_overlay] } {
  248. set extra_flags_1 "$extra_flags_1 -Wl,--auto-overlay"
  249. set extra_flags_1 "$extra_flags_1 -Wl,--extra-stack-space=8192"
  250. set extra_flags_1 "$extra_flags_1 -ffunction-sections"
  251. set extra_flags_2 "$extra_flags_2 -ffunction-sections"
  252. set extra_flags_3 "$extra_flags_3 -ffunction-sections"
  253. }
  254. # Define the names of the object files.
  255. regsub "sid" "sid_main_tst.o" $sid obj1
  256. regsub "sid" "sid_x_tst.o" $sid obj2_tst
  257. regsub "sid" "sid_x_alt.o" $sid obj2_alt
  258. regsub "sid" "sid_y_tst.o" $sid obj3_tst
  259. regsub "sid" "sid_y_alt.o" $sid obj3_alt
  260. # Get the base name of this test, for use in messages.
  261. set testcase "$src1"
  262. # Remove the $srcdir and $tmpdir prefixes from $src1. (It would
  263. # be possible to use "regsub" here, if we were careful to escape
  264. # all regular expression characters in $srcdir and $tmpdir, but
  265. # that would be more complicated that this approach.)
  266. if {[string first "$srcdir/" "$src1"] == 0} {
  267. set testcase [string range "$src1" [string length "$srcdir/"] end]
  268. }
  269. if {[string first "$tmpdir/" "$testcase"] == 0} {
  270. set testcase [string range "$testcase" [string length "$tmpdir/"] end]
  271. set testcase "tmpdir-$testcase"
  272. }
  273. # If we couldn't rip $srcdir out of `src1' then just do the best we can.
  274. # The point is to reduce the unnecessary noise in the logs. Don't strip
  275. # out too much because different testcases with the same name can confuse
  276. # `test-tool'.
  277. if [string match "/*" $testcase] then {
  278. set testcase "[file tail [file dirname $src1]]/[file tail $src1]"
  279. }
  280. # Check whether this test is supported for this target.
  281. if { [lindex ${dg-do-what} 1 ] == "N" } {
  282. unsupported "$testcase"
  283. verbose "$testcase not supported on this target, skipping it" 3
  284. return
  285. }
  286. regsub "_main.*" $testcase "" testcase
  287. # Set up the base name of executable files so they'll be unique.
  288. regsub -all "\[./\]" $testcase "-" execbase
  289. # Loop through all of the option lists used for this test.
  290. set count 0
  291. foreach option_pair $compat_option_list {
  292. # Pick out each set of options.
  293. set tst_option [lindex $option_pair 0]
  294. set alt_option [lindex $option_pair 1]
  295. set optstr ""
  296. if { ![string match $tst_option ""] \
  297. || ![string match $alt_option ""] } then {
  298. set optstr "\"$tst_option\",\"$alt_option\""
  299. }
  300. verbose "Testing $testcase, $optstr" 1
  301. # There's a unique name for each executable we generate, based on
  302. # the set of options and how the pieces of the tests are compiled.
  303. set execname1 "${execbase}-${count}1.exe"
  304. set execname2 "${execbase}-${count}2.exe"
  305. set execname3 "${execbase}-${count}3.exe"
  306. set execname4 "${execbase}-${count}4.exe"
  307. incr count
  308. file_on_host delete $execname1
  309. file_on_host delete $execname2
  310. file_on_host delete $execname3
  311. file_on_host delete $execname4
  312. # Compile pieces with the alternate compiler; we'll catch problems
  313. # later. Skip this if we don't have an alternate compiler.
  314. if { $use_alt != 0 } then {
  315. compat-use-alt-compiler
  316. compat-obj "$src2" "$obj2_alt" $alt_option $extra_flags_2 \
  317. $optstr $compile_xfail_2
  318. compat-obj "$src3" "$obj3_alt" $alt_option $extra_flags_3 \
  319. $optstr $compile_xfail_3
  320. }
  321. # Compile pieces with the compiler under test.
  322. compat-use-tst-compiler
  323. compat-obj "$src1" "$obj1" $tst_option $extra_flags_1 $optstr ""
  324. compat-obj "$src2" "$obj2_tst" $tst_option $extra_flags_2 \
  325. $optstr $compile_xfail_2
  326. compat-obj "$src3" "$obj3_tst" $tst_option $extra_flags_3 \
  327. $optstr $compile_xfail_3
  328. # Link (using the compiler under test), run, and clean up tests.
  329. compat-run "${obj2_tst}-${obj3_tst}" \
  330. "$obj1 $obj2_tst $obj3_tst" $execname1 \
  331. $tst_option $extra_flags_1 $optstr
  332. # If we've got an alternate compiler try some combinations.
  333. if { $use_alt != 0 } then {
  334. compat-run "${obj2_tst}-${obj3_alt}" "$obj1 $obj2_tst $obj3_alt" \
  335. $execname2 $tst_option $extra_flags_1 $optstr
  336. compat-run "${obj2_alt}-${obj3_tst}" "$obj1 $obj2_alt $obj3_tst" \
  337. $execname3 $tst_option $extra_flags_1 $optstr
  338. compat-run "${obj2_alt}-${obj3_alt}" "$obj1 $obj2_alt $obj3_alt" \
  339. $execname4 $tst_option $extra_flags_1 $optstr
  340. }
  341. # Clean up object files.
  342. set files [glob -nocomplain ${sid}_*.o]
  343. if { $files != "" } {
  344. foreach objfile $files {
  345. if { ![info exists gluefile] || $objfile != $gluefile } {
  346. eval "file_on_host delete $objfile"
  347. }
  348. }
  349. }
  350. }
  351. }