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