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