OSDN Git Service

* config/i386.i386.c (ix86_return_in_memory): Reformat. Return true
[pf3gnuchains/gcc-fork.git] / gcc / testsuite / lib / compat.exp
1 # Copyright (C) 2002 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., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
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
50 set option_list $COMPAT_OPTIONS
51
52 load_lib dg.exp
53
54 #
55 # compat-obj -- compile to an object file
56 #
57 # SOURCE is the source file
58 # DEST is the object file
59 # OPTALL is the list of compiler options to use with all tests
60 # OPTFILE is the list of compiler options to use with this file
61 # OPTSTR is the options to print with test messages
62 #
63 proc compat-obj { source dest optall optfile optstr } {
64     global testcase
65     global tool
66
67     # Set up the options for compiling this file.
68     set options ""
69     lappend options "additional_flags=$optfile $optall"
70
71     set comp_output [${tool}_target_compile "$source" "$dest" object $options]
72     ${tool}_check_compile "$testcase $dest compile" $optstr $dest $comp_output
73 }
74
75 # compat-run -- link and run an executable
76 #
77 # TESTNAME is the mixture of object files to link
78 # OBJLIST is the list of object files to link
79 # DEST is the name of the executable
80 # OPTALL is a list of compiler and linker options to use for all tests
81 # OPTFILE is a list of compiler and linker options to use for this test
82 # OPTSTR is the list of options to list in messages
83 #
84 proc compat-run { testname objlist dest optall optfile optstr } {
85     global testcase
86     global tool
87
88     # Check that all of the objects were built successfully.
89     foreach obj [split $objlist] {
90         if ![file exists $obj] then {
91             unresolved "$testcase $testname link $optstr"
92             unresolved "$testcase $testname execute $optstr"
93             return
94         }
95     }
96
97     # Set up the options for linking this test.
98     set options ""
99     lappend options "additional_flags=$optfile $optall"
100
101     # Link the objects into an executable.
102     set comp_output [${tool}_target_compile "$objlist" $dest executable \
103                      "$options"]
104     if ![${tool}_check_compile "$testcase $testname link" "" \
105          $dest $comp_output] then {
106         unresolved "$testcase $testname execute $optstr"
107         return
108     }
109
110     # Run the self-checking executable.
111     if ![string match "*/*" $dest] then {
112         set dest "./$dest"
113     }
114     set result [${tool}_load $dest "" ""]
115     set status [lindex $result 0]
116     if { $status == "pass" } then {
117         remote_file build delete $dest
118     }
119     $status "$testcase $testname execute $optstr"
120 }
121
122 #
123 # compat-flags -- get special tool flags to use for a source file
124 #
125 # SRC is the full patchname of the source file.
126 # The result is a list of options to use.
127 #
128 # This code is copied from proc dg-test in dg.exp from DejaGNU.
129 #
130 proc compat-get-options { src } {
131     # Define our own special function `unknown` so we catch spelling errors.
132     # But first rename the existing one so we can restore it afterwards.
133     catch {rename dg-save-unknown ""}
134     rename unknown dg-save-unknown
135     proc unknown { args } {
136         return -code error "unknown dg option: $args"
137     }
138
139     # dg-options sets a variable called dg-extra-tool-flags.
140     set dg-extra-tool-flags ""
141     set tmp [dg-get-options $src]
142     foreach op $tmp {
143         set cmd [lindex $op 0]
144         if ![string compare "dg-options" $cmd] {
145             set status [catch "$op" errmsg]
146             if { $status != 0 } {
147                 perror "src: $errmsg for \"$op\"\n"
148                 unresolved "$src: $errmsg for \"$op\""
149                 return
150             }
151         } else {
152             # Ignore unrecognized dg- commands, but warn about them.
153             warning "compat.exp does not support $cmd"
154         }
155     }
156
157     # Restore normal error handling.
158     rename unknown ""
159     rename dg-save-unknown unknown
160
161     return ${dg-extra-tool-flags}
162 }
163
164 #
165 # compat-execute -- compile with compatible compilers
166 #
167 # SRC1 is the full pathname of the main file of the testcase.
168 # SID identifies a test suite in the names of temporary files.
169 # USE_ALT is nonzero if we're using an alternate compiler as well as
170 #   the compiler under test.
171 #
172 proc compat-execute { src1 sid use_alt } {
173     global srcdir tmpdir
174     global option_list
175     global tool
176     global verbose
177     global testcase
178     global gluefile
179
180     # Set up the names of the other source files.
181     regsub "_main.*" $src1 "" base
182     regsub ".*/" $base "" base
183     regsub "_main" $src1 "_x" src2
184     regsub "_main" $src1 "_y" src3
185
186     # Use the dg-options mechanism to specify extra flags for this test. 
187     # The extra flags in each file are used to compile that file, and the
188     # extra flags in *_main.* are also used for linking.
189     set extra_flags_1 [compat-get-options $src1]
190     set extra_flags_2 [compat-get-options $src2]
191     set extra_flags_3 [compat-get-options $src3]
192
193     # Define the names of the object files.
194     regsub "sid" "sid_main_tst.o" $sid obj1
195     regsub "sid" "sid_x_tst.o" $sid obj2_tst
196     regsub "sid" "sid_x_alt.o" $sid obj2_alt
197     regsub "sid" "sid_y_tst.o" $sid obj3_tst
198     regsub "sid" "sid_y_alt.o" $sid obj3_alt
199
200     # Get the base name of this test, for use in messages.
201     regsub "^$srcdir/?" $src1 "" testcase
202     regsub "_main.*" $testcase "" testcase
203     # Set up the base name of executable files so they'll be unique.
204     regsub -all "\[./\]" $testcase "-" execbase
205
206     # If we couldn't rip $srcdir out of `src1' then just do the best we can.
207     # The point is to reduce the unnecessary noise in the logs.  Don't strip
208     # out too much because different testcases with the same name can confuse
209     # `test-tool'.
210     if [string match "/*" $testcase] then {
211         set testcase "[file tail [file dirname $src1]]/[file tail $src1]"
212     }
213
214     # Loop through all of the option lists used for this test.
215
216     set count 0
217     foreach option_pair $option_list {
218
219         # Pick out each set of options.
220         set tst_option [lindex $option_pair 0]
221         set alt_option [lindex $option_pair 1]
222         set optstr ""
223         if { ![string match $tst_option ""] \
224              || ![string match $alt_option ""] } then {
225             set optstr "\"$tst_option\",\"$alt_option\""
226         }
227         verbose "Testing $testcase, $optstr" 1
228
229         # There's a unique name for each executable we generate, based on
230         # the set of options and how the pieces of the tests are compiled.
231         set execname1 "${execbase}-${count}1"
232         set execname2 "${execbase}-${count}2"
233         set execname3 "${execbase}-${count}3"
234         set execname4 "${execbase}-${count}4"
235         incr count
236
237         remote_file build delete $execname1
238         remote_file build delete $execname2
239         remote_file build delete $execname3
240         remote_file build delete $execname4
241
242         # Compile pieces with the alternate compiler; we'll catch problems
243         # later.  Skip this if we don't have an alternate compiler.
244         if { $use_alt != 0 } then {
245             compat-use-alt-compiler
246             compat-obj "$src2" "$obj2_alt" $alt_option $extra_flags_2 $optstr
247             compat-obj "$src3" "$obj3_alt" $alt_option $extra_flags_3 $optstr
248         }
249
250         # Compile pieces with the compiler under test.
251         compat-use-tst-compiler
252         compat-obj "$src1" "$obj1" $tst_option $extra_flags_1 $optstr
253         compat-obj "$src2" "$obj2_tst" $tst_option $extra_flags_2 $optstr
254         compat-obj "$src3" "$obj3_tst" $tst_option $extra_flags_3 $optstr
255
256         # Link (using the compiler under test), run, and clean up tests.
257         compat-run "${obj2_tst}-${obj3_tst}" \
258             "$obj1 $obj2_tst $obj3_tst" $execname1 \
259             $tst_option $extra_flags_1 $optstr
260
261         # If we've got an alternate compiler try some combinations.
262         if { $use_alt != 0 } then {
263             compat-run "${obj2_tst}-${obj3_alt}" "$obj1 $obj2_tst $obj3_alt" \
264                        $execname2 $tst_option $extra_flags_1 $optstr
265             compat-run "${obj2_alt}-${obj3_tst}" "$obj1 $obj2_alt $obj3_tst" \
266                        $execname3 $tst_option $extra_flags_1 $optstr
267             compat-run "${obj2_alt}-${obj3_alt}" "$obj1 $obj2_alt $obj3_alt" \
268                        $execname4 $tst_option $extra_flags_1 $optstr
269         }
270
271         # Clean up object files.
272         set files [glob -nocomplain ${sid}_*.o]
273         if { $files != "" } {
274             foreach objfile $files {
275                 if { ![info exists gluefile] || $objfile != $gluefile } {
276                     eval "remote_file build delete $objfile"
277                 }
278             }
279         }
280     }
281 }