]>
Commit | Line | Data |
---|---|---|
f1717362 | 1 | # Copyright (C) 2002-2016 Free Software Foundation, Inc. |
a22c581b | 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 | |
f63ff66b | 5 | # the Free Software Foundation; either version 3 of the License, or |
a22c581b | 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 | |
f63ff66b | 14 | # along with GCC; see the file COPYING3. If not see |
15 | # <http://www.gnu.org/licenses/>. | |
a22c581b | 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 | ||
7aec5662 | 50 | set compat_option_list $COMPAT_OPTIONS |
a22c581b | 51 | |
8a423303 | 52 | # Subsets of tests can be selectively disabled by members of this list: |
53 | # - ATTRIBUTE: disable all tests using the __attribute__ extension, | |
6198329e | 54 | # - COMPLEX: disable all tests using the complex types feature, |
8a423303 | 55 | # - COMPLEX_INT: disable all tests using the complex integral types extension, |
56 | # - VA: disable all tests using the variable number of arguments feature, | |
6198329e | 57 | # - VLA_IN_STRUCT: disable all tests using the variable-length arrays as |
58 | # structure members extension, | |
8a423303 | 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 | ||
41a20961 | 68 | global compat_skip_list |
69 | set compat_skip_list $COMPAT_SKIPS | |
8a423303 | 70 | |
1aa14d2c | 71 | load_lib dg.exp |
b4bb872a | 72 | load_lib gcc-dg.exp |
1aa14d2c | 73 | |
a22c581b | 74 | # |
75 | # compat-obj -- compile to an object file | |
76 | # | |
77 | # SOURCE is the source file | |
78 | # DEST is the object file | |
1aa14d2c | 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 | |
a22c581b | 81 | # OPTSTR is the options to print with test messages |
b4bb872a | 82 | # XFAILDATA is the xfail data to be passed to the compiler |
a22c581b | 83 | # |
b4bb872a | 84 | proc compat-obj { source dest optall optfile optstr xfaildata } { |
a22c581b | 85 | global testcase |
86 | global tool | |
b4bb872a | 87 | global compiler_conditional_xfail_data |
41a20961 | 88 | global compat_skip_list |
8a423303 | 89 | |
90 | # Add the skip specifiers. | |
41a20961 | 91 | foreach skip $compat_skip_list { |
8a423303 | 92 | if { ![string match $skip ""] } { |
93 | lappend optall "-DSKIP_$skip" | |
94 | } | |
95 | } | |
a22c581b | 96 | |
1aa14d2c | 97 | # Set up the options for compiling this file. |
98 | set options "" | |
99 | lappend options "additional_flags=$optfile $optall" | |
100 | ||
b4bb872a | 101 | set compiler_conditional_xfail_data $xfaildata |
a22c581b | 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 | |
1aa14d2c | 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 | |
a22c581b | 113 | # OPTSTR is the list of options to list in messages |
114 | # | |
1aa14d2c | 115 | proc compat-run { testname objlist dest optall optfile optstr } { |
a22c581b | 116 | global testcase |
117 | global tool | |
118 | ||
119 | # Check that all of the objects were built successfully. | |
120 | foreach obj [split $objlist] { | |
76f3b287 | 121 | if ![file_on_host exists $obj] then { |
a22c581b | 122 | unresolved "$testcase $testname link $optstr" |
123 | unresolved "$testcase $testname execute $optstr" | |
124 | return | |
125 | } | |
126 | } | |
127 | ||
1aa14d2c | 128 | # Set up the options for linking this test. |
129 | set options "" | |
130 | lappend options "additional_flags=$optfile $optall" | |
131 | ||
a22c581b | 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 { | |
a22c581b | 137 | return |
138 | } | |
139 | ||
140 | # Run the self-checking executable. | |
8f51ee83 | 141 | if ![string match "*/*" $dest] then { |
142 | set dest "./$dest" | |
143 | } | |
a22c581b | 144 | set result [${tool}_load $dest "" ""] |
145 | set status [lindex $result 0] | |
146 | if { $status == "pass" } then { | |
76f3b287 | 147 | file_on_host delete $dest |
a22c581b | 148 | } |
149 | $status "$testcase $testname execute $optstr" | |
150 | } | |
151 | ||
1aa14d2c | 152 | # |
ec801c5a | 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 | |
1aa14d2c | 155 | # |
ec801c5a | 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 "" | |
fc986522 | 161 | # dg-options sets a variable called tool_flags. |
162 | set tool_flags "" | |
ec801c5a | 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] \ | |
258becb9 | 171 | || [string match "dg-prune-output" $cmd] \ |
fc986522 | 172 | || [string match "dg-skip-if" $cmd] \ |
ec801c5a | 173 | || [string match "dg-require-*" $cmd] } { |
174 | set status [catch "$op" errmsg] | |
175 | if { $status != 0 } { | |
176 | perror "src: $errmsg for \"$op\"\n" | |
177 | unresolved "$src: $errmsg for \"$op\"" | |
178 | return | |
179 | } | |
180 | } elseif { ![string compare "dg-xfail-if" $cmd] } { | |
181 | warning "compat.exp does not support $cmd in primary source file" | |
182 | } else { | |
183 | # Ignore unrecognized dg- commands, but warn about them. | |
184 | warning "compat.exp does not support $cmd" | |
185 | } | |
186 | } | |
187 | ||
188 | # Return flags to use for compiling the primary source file and for | |
189 | # linking. | |
190 | return ${dg-extra-tool-flags} | |
191 | } | |
192 | ||
193 | # | |
194 | # compat-get-options -- get special tool flags to use for a secondary | |
195 | # source file | |
196 | # | |
197 | # SRC is the full pathname of the source file. | |
1aa14d2c | 198 | # The result is a list of options to use. |
199 | # | |
200 | # This code is copied from proc dg-test in dg.exp from DejaGNU. | |
201 | # | |
202 | proc compat-get-options { src } { | |
1aa14d2c | 203 | # dg-options sets a variable called dg-extra-tool-flags. |
204 | set dg-extra-tool-flags "" | |
b4bb872a | 205 | |
206 | # dg-xfail-if sets compiler_conditional_xfail_data. | |
207 | global compiler_conditional_xfail_data | |
208 | set compiler_conditional_xfail_data "" | |
209 | ||
d67138fe | 210 | # dg-xfail-if needs access to dg-do-what. |
211 | upvar dg-do-what dg-do-what | |
212 | ||
1aa14d2c | 213 | set tmp [dg-get-options $src] |
214 | foreach op $tmp { | |
215 | set cmd [lindex $op 0] | |
911eca6f | 216 | if { ![string compare "dg-options" $cmd] \ |
258becb9 | 217 | || ![string compare "dg-prune-output" $cmd] \ |
911eca6f | 218 | || ![string compare "dg-xfail-if" $cmd] } { |
1aa14d2c | 219 | set status [catch "$op" errmsg] |
220 | if { $status != 0 } { | |
221 | perror "src: $errmsg for \"$op\"\n" | |
222 | unresolved "$src: $errmsg for \"$op\"" | |
223 | return | |
224 | } | |
ec801c5a | 225 | } elseif { [string match "dg-require-*" $cmd] } { |
226 | warning "compat.exp does not support $cmd in secondary source files" | |
1aa14d2c | 227 | } else { |
228 | # Ignore unrecognized dg- commands, but warn about them. | |
229 | warning "compat.exp does not support $cmd" | |
230 | } | |
231 | } | |
232 | ||
1aa14d2c | 233 | return ${dg-extra-tool-flags} |
234 | } | |
235 | ||
a22c581b | 236 | # |
237 | # compat-execute -- compile with compatible compilers | |
238 | # | |
239 | # SRC1 is the full pathname of the main file of the testcase. | |
2a04f36a | 240 | # SID identifies a test suite in the names of temporary files. |
a22c581b | 241 | # USE_ALT is nonzero if we're using an alternate compiler as well as |
242 | # the compiler under test. | |
243 | # | |
2a04f36a | 244 | proc compat-execute { src1 sid use_alt } { |
a22c581b | 245 | global srcdir tmpdir |
7aec5662 | 246 | global compat_option_list |
a22c581b | 247 | global tool |
248 | global verbose | |
249 | global testcase | |
6ad19b84 | 250 | global gluefile |
b4bb872a | 251 | global compiler_conditional_xfail_data |
ec801c5a | 252 | global dg-do-what-default |
253 | ||
254 | # Get extra flags for this test from the primary source file, and | |
255 | # process other dg-* options that this suite supports. Warn about | |
256 | # unsupported flags. | |
257 | verbose "compat-execute: $src1" 1 | |
258 | set dg-do-what [list ${dg-do-what-default} "" P] | |
259 | set extra_flags_1 [compat-get-options-main $src1] | |
260 | ||
a22c581b | 261 | # Set up the names of the other source files. |
241fb2d5 | 262 | set dir [file dirname $src1] |
263 | set ext [file extension $src1] | |
264 | set base [file rootname $src1] | |
265 | set base [string range $base [string length $dir] end] | |
266 | regsub "_main" $base "" base | |
267 | set src2 "${dir}/${base}_x${ext}" | |
268 | set src3 "${dir}/${base}_y${ext}" | |
a22c581b | 269 | |
1aa14d2c | 270 | # Use the dg-options mechanism to specify extra flags for this test. |
271 | # The extra flags in each file are used to compile that file, and the | |
272 | # extra flags in *_main.* are also used for linking. | |
1aa14d2c | 273 | set extra_flags_2 [compat-get-options $src2] |
b4bb872a | 274 | set compile_xfail_2 $compiler_conditional_xfail_data |
1aa14d2c | 275 | set extra_flags_3 [compat-get-options $src3] |
b4bb872a | 276 | set compile_xfail_3 $compiler_conditional_xfail_data |
1aa14d2c | 277 | |
7866d1ab | 278 | # On the SPU, most of the compat test cases exceed local store size. |
279 | # Use automatic overlay support to make them fit. | |
3dd2807f | 280 | if { [check_effective_target_spu_auto_overlay] } { |
7866d1ab | 281 | set extra_flags_1 "$extra_flags_1 -Wl,--auto-overlay" |
7baab7bd | 282 | set extra_flags_1 "$extra_flags_1 -Wl,--extra-stack-space=8192" |
7866d1ab | 283 | set extra_flags_1 "$extra_flags_1 -ffunction-sections" |
284 | set extra_flags_2 "$extra_flags_2 -ffunction-sections" | |
285 | set extra_flags_3 "$extra_flags_3 -ffunction-sections" | |
286 | } | |
287 | ||
a22c581b | 288 | # Define the names of the object files. |
2a04f36a | 289 | regsub "sid" "sid_main_tst.o" $sid obj1 |
290 | regsub "sid" "sid_x_tst.o" $sid obj2_tst | |
291 | regsub "sid" "sid_x_alt.o" $sid obj2_alt | |
292 | regsub "sid" "sid_y_tst.o" $sid obj3_tst | |
293 | regsub "sid" "sid_y_alt.o" $sid obj3_alt | |
a22c581b | 294 | |
295 | # Get the base name of this test, for use in messages. | |
3abcd981 | 296 | set testcase "$src1" |
297 | # Remove the $srcdir and $tmpdir prefixes from $src1. (It would | |
298 | # be possible to use "regsub" here, if we were careful to escape | |
299 | # all regular expression characters in $srcdir and $tmpdir, but | |
300 | # that would be more complicated that this approach.) | |
301 | if {[string first "$srcdir/" "$src1"] == 0} { | |
302 | set testcase [string range "$src1" [string length "$srcdir/"] end] | |
303 | } | |
7930beb4 | 304 | if {[string first "$tmpdir/" "$testcase"] == 0} { |
cdde9a4c | 305 | set testcase [string range "$testcase" [string length "$tmpdir/"] end] |
6306e10d | 306 | set testcase "tmpdir-$testcase" |
3abcd981 | 307 | } |
a22c581b | 308 | # If we couldn't rip $srcdir out of `src1' then just do the best we can. |
309 | # The point is to reduce the unnecessary noise in the logs. Don't strip | |
310 | # out too much because different testcases with the same name can confuse | |
311 | # `test-tool'. | |
312 | if [string match "/*" $testcase] then { | |
313 | set testcase "[file tail [file dirname $src1]]/[file tail $src1]" | |
314 | } | |
315 | ||
7e9f24e0 | 316 | # Check whether this test is supported for this target. |
317 | if { [lindex ${dg-do-what} 1 ] == "N" } { | |
318 | unsupported "$testcase" | |
319 | verbose "$testcase not supported on this target, skipping it" 3 | |
320 | return | |
321 | } | |
322 | ||
323 | regsub "_main.*" $testcase "" testcase | |
324 | # Set up the base name of executable files so they'll be unique. | |
325 | regsub -all "\[./\]" $testcase "-" execbase | |
326 | ||
a22c581b | 327 | # Loop through all of the option lists used for this test. |
328 | ||
329 | set count 0 | |
7aec5662 | 330 | foreach option_pair $compat_option_list { |
a22c581b | 331 | |
332 | # Pick out each set of options. | |
333 | set tst_option [lindex $option_pair 0] | |
334 | set alt_option [lindex $option_pair 1] | |
335 | set optstr "" | |
336 | if { ![string match $tst_option ""] \ | |
337 | || ![string match $alt_option ""] } then { | |
338 | set optstr "\"$tst_option\",\"$alt_option\"" | |
339 | } | |
340 | verbose "Testing $testcase, $optstr" 1 | |
341 | ||
a22c581b | 342 | # There's a unique name for each executable we generate, based on |
343 | # the set of options and how the pieces of the tests are compiled. | |
d3b4b97f | 344 | set execname1 "${execbase}-${count}1.exe" |
345 | set execname2 "${execbase}-${count}2.exe" | |
346 | set execname3 "${execbase}-${count}3.exe" | |
347 | set execname4 "${execbase}-${count}4.exe" | |
a22c581b | 348 | incr count |
349 | ||
76f3b287 | 350 | file_on_host delete $execname1 |
351 | file_on_host delete $execname2 | |
352 | file_on_host delete $execname3 | |
353 | file_on_host delete $execname4 | |
a22c581b | 354 | |
355 | # Compile pieces with the alternate compiler; we'll catch problems | |
356 | # later. Skip this if we don't have an alternate compiler. | |
357 | if { $use_alt != 0 } then { | |
358 | compat-use-alt-compiler | |
911eca6f | 359 | compat-obj "$src2" "$obj2_alt" $alt_option $extra_flags_2 \ |
360 | $optstr $compile_xfail_2 | |
361 | compat-obj "$src3" "$obj3_alt" $alt_option $extra_flags_3 \ | |
362 | $optstr $compile_xfail_3 | |
a22c581b | 363 | } |
364 | ||
365 | # Compile pieces with the compiler under test. | |
366 | compat-use-tst-compiler | |
b4bb872a | 367 | compat-obj "$src1" "$obj1" $tst_option $extra_flags_1 $optstr "" |
911eca6f | 368 | compat-obj "$src2" "$obj2_tst" $tst_option $extra_flags_2 \ |
369 | $optstr $compile_xfail_2 | |
370 | compat-obj "$src3" "$obj3_tst" $tst_option $extra_flags_3 \ | |
371 | $optstr $compile_xfail_3 | |
a22c581b | 372 | |
373 | # Link (using the compiler under test), run, and clean up tests. | |
374 | compat-run "${obj2_tst}-${obj3_tst}" \ | |
1aa14d2c | 375 | "$obj1 $obj2_tst $obj3_tst" $execname1 \ |
376 | $tst_option $extra_flags_1 $optstr | |
a22c581b | 377 | |
378 | # If we've got an alternate compiler try some combinations. | |
379 | if { $use_alt != 0 } then { | |
380 | compat-run "${obj2_tst}-${obj3_alt}" "$obj1 $obj2_tst $obj3_alt" \ | |
1aa14d2c | 381 | $execname2 $tst_option $extra_flags_1 $optstr |
a22c581b | 382 | compat-run "${obj2_alt}-${obj3_tst}" "$obj1 $obj2_alt $obj3_tst" \ |
1aa14d2c | 383 | $execname3 $tst_option $extra_flags_1 $optstr |
a22c581b | 384 | compat-run "${obj2_alt}-${obj3_alt}" "$obj1 $obj2_alt $obj3_alt" \ |
1aa14d2c | 385 | $execname4 $tst_option $extra_flags_1 $optstr |
a22c581b | 386 | } |
387 | ||
388 | # Clean up object files. | |
2a04f36a | 389 | set files [glob -nocomplain ${sid}_*.o] |
a22c581b | 390 | if { $files != "" } { |
6ad19b84 | 391 | foreach objfile $files { |
50eeec2e | 392 | if { ![info exists gluefile] || $objfile != $gluefile } { |
76f3b287 | 393 | eval "file_on_host delete $objfile" |
6ad19b84 | 394 | } |
395 | } | |
a22c581b | 396 | } |
397 | } | |
398 | } |