OSDN Git Service

Cleanup and bug-fix patch from Felix Lee.
[pf3gnuchains/gcc-fork.git] / gcc / testsuite / lib / gcc.exp
1 # Copyright (C) 1992, 1993, 1994, 1996, 1997, 1999 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, 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
16
17 # Please email any bugs, comments, and/or additions to this file to:
18 # bug-gcc@prep.ai.mit.edu
19
20 # This file was written by Rob Savoye (rob@cygnus.com)
21 # Currently maintained by Doug Evans (dje@cygnus.com)
22
23 # This file is loaded by the tool init file (eg: unix.exp).  It provides
24 # default definitions for gcc_start, etc. and other supporting cast members.
25
26 # These globals are used by gcc_start if no compiler arguments are provided.
27 # They are also used by the various testsuites to define the environment:
28 # where to find stdio.h, libc.a, etc.
29
30 # we want to use libgloss so we can get find_gcc.
31 load_lib libgloss.exp
32
33 #
34 # GCC_UNDER_TEST is the compiler under test.
35 #
36
37 #
38 # default_gcc_version -- extract and print the version number of the compiler
39 #
40
41 proc default_gcc_version { } {
42     global GCC_UNDER_TEST
43
44     gcc_init;
45
46     # ignore any arguments after the command
47     set compiler [lindex $GCC_UNDER_TEST 0]
48
49     if ![is_remote host] {
50         set compiler_name [which $compiler];
51     } else {
52         set compiler_name $compiler;
53     }
54
55     # verify that the compiler exists
56     if { $compiler_name != 0 } then {
57         set tmp [remote_exec host "$compiler -v"]
58         set status [lindex $tmp 0];
59         set output [lindex $tmp 1];
60         regexp "version.*$" $output version
61         if { $status == 0 && [info exists version] } then {
62             clone_output "$compiler_name $version\n"
63         } else {
64             clone_output "Couldn't determine version of $compiler_name: $output\n"
65         }
66     } else {
67         # compiler does not exist (this should have already been detected)
68         warning "$compiler does not exist"
69     }
70 }
71
72 #
73 # Call gcc_version. We do it this way so we can override it if needed.
74 #
75 proc gcc_version { } {
76     default_gcc_version;
77 }
78
79 #
80 # gcc_init -- called at the start of each .exp script.
81 #
82 # There currently isn't much to do, but always using it allows us to
83 # make some enhancements without having to go back and rewrite the scripts.
84 #
85
86 set gcc_initialized 0
87
88 proc gcc_init { args } {
89     global tmpdir
90     global libdir
91     global gluefile wrap_flags
92     global gcc_initialized
93     global GCC_UNDER_TEST
94     global TOOL_EXECUTABLE
95
96     if { $gcc_initialized == 1 } { return; }
97
98     if ![info exists GCC_UNDER_TEST] {
99         if [info exists TOOL_EXECUTABLE] {
100             set GCC_UNDER_TEST $TOOL_EXECUTABLE;
101         } else {
102             set GCC_UNDER_TEST "[find_gcc]"
103         }
104     }
105
106     if ![info exists tmpdir] then {
107         set tmpdir /tmp
108     }
109     if { [target_info needs_status_wrapper]!="" && ![info exists gluefile] } {
110         set gluefile ${tmpdir}/testglue.o;
111         set result [build_wrapper $gluefile];
112         if { $result != "" } {
113             set gluefile [lindex $result 0];
114             set wrap_flags [lindex $result 1];
115         } else {
116             unset gluefile
117         }
118     }
119 }
120
121 proc gcc_target_compile { source dest type options } {
122     global tmpdir;
123     global gluefile wrap_flags;
124     global GCC_UNDER_TEST
125     global TOOL_OPTIONS
126
127     if { [target_info needs_status_wrapper]!="" && [info exists gluefile] } {
128         lappend options "libs=${gluefile}"
129         lappend options "ldflags=$wrap_flags"
130     }
131
132     if [target_info exists gcc,stack_size] {
133         lappend options "additional_flags=-DSTACK_SIZE=[target_info gcc,stack_size]"
134     }
135     if [target_info exists gcc,no_trampolines] {
136         lappend options "additional_flags=-DNO_TRAMPOLINES"
137     }
138     if [target_info exists gcc,no_label_values] {
139         lappend options "additional_flags=-DNO_LABEL_VALUES"
140     }
141     if [info exists TOOL_OPTIONS] {
142         lappend options "additional_flags=$TOOL_OPTIONS"
143     }
144     if [target_info exists gcc,no_varargs] {
145         lappend options "additional_flags=-DNO_VARARGS"
146     }
147     lappend options "compiler=$GCC_UNDER_TEST"
148     return [target_compile $source $dest $type $options]
149 }
150
151
152 # Reports pass/fail for a gcc compilation and returns true/false.
153 proc gcc_check_compile {testcase option objname gcc_output} {
154
155     set fatal_signal "*cc: Internal compiler error: program*got fatal signal"
156  
157     if [string match "$fatal_signal 6" $gcc_output] then {
158         gcc_fail $testcase "Got Signal 6, $option"
159         return 0
160     }
161
162     if [string match "$fatal_signal 11" $gcc_output] then {
163         gcc_fail $testcase "Got Signal 11, $option"
164         return 0
165     }
166
167     # We shouldn't get these because of -w, but just in case.
168     if [string match "*cc:*warning:*" $gcc_output] then {
169         warning "$testcase: (with warnings) $option"
170         send_log "$gcc_output\n"
171         unresolved "$testcase, $option"
172         return 0
173     }
174
175     set gcc_output [prune_warnings $gcc_output]
176
177     set unsupported_message [gcc_check_unsupported_p $gcc_output]
178     if { $unsupported_message != "" } {
179         unsupported "$testcase: $unsupported_message"
180         return 0
181     }
182
183     # remove any leftover LF/CR to make sure any output is legit
184     regsub -all -- "\[\r\n\]*" $gcc_output "" gcc_output
185
186     # If any message remains, we fail.
187     if ![string match "" $gcc_output] then {
188         gcc_fail $testcase $option
189         return 0
190     }
191
192     # fail if the desired object file doesn't exist.
193     # FIXME: there's no way of checking for existence on a remote host.
194     if {$objname != "" && ![is3way] && ![file exists $objname]} {
195         gcc_fail $testcase $option
196         return 0
197     }
198
199     gcc_pass $testcase $option
200     return 1
201 }
202
203
204
205 #
206 # gcc_pass -- utility to record a testcase passed
207 #
208
209 proc gcc_pass { testcase cflags } {
210     if { "$cflags" == "" } {
211         pass "$testcase"
212     } else {
213         pass "$testcase, $cflags"
214     }
215 }
216
217 #
218 # gcc_fail -- utility to record a testcase failed
219 #
220
221 proc gcc_fail { testcase cflags } {
222     if { "$cflags" == "" } {
223         fail "$testcase"
224     } else {
225         fail "$testcase, $cflags"
226     }
227 }
228
229 #
230 # gcc_finish -- called at the end of every .exp script that calls gcc_init
231 #
232 # The purpose of this proc is to hide all quirks of the testing environment
233 # from the testsuites.  It also exists to undo anything that gcc_init did
234 # (that needs undoing).
235 #
236
237 proc gcc_finish { } {
238     # The testing harness apparently requires this.
239     global errorInfo;
240
241     if [info exists errorInfo] then {
242         unset errorInfo
243     }
244
245     # Might as well reset these (keeps our caller from wondering whether
246     # s/he has to or not).
247     global prms_id bug_id
248     set prms_id 0
249     set bug_id 0
250 }
251
252 proc gcc_exit { } {
253     global gluefile;
254
255     if [info exists gluefile] {
256         file_on_build delete $gluefile;
257         unset gluefile;
258     }
259 }
260     
261 # If this is an older version of dejagnu (without runtest_file_p),
262 # provide one and assume the old syntax: foo1.exp bar1.c foo2.exp bar2.c.
263 # This can be deleted after next dejagnu release.
264
265 if { [info procs runtest_file_p] == "" } then {
266     proc runtest_file_p { runtests testcase } {
267         if { $runtests != "" && [regexp "\[.\]\[cC\]" $runtests] } then {
268             if { [lsearch $runtests [file tail $testcase]] >= 0 } then {
269                 return 1
270             } else {
271                 return 0
272             }
273         }
274         return 1
275     }
276 }
277
278 # Provide a definition of this if missing (delete after next dejagnu release).
279
280 if { [info procs prune_warnings] == "" } then {
281     proc prune_warnings { text } {
282         return $text
283     }
284 }
285
286 # Utility used by mike-gcc.exp and c-torture.exp.
287 # Check the compiler(/assembler/linker) output for text indicating that
288 # the testcase should be marked as "unsupported".
289 #
290 # When dealing with a large number of tests, it's difficult to weed out the
291 # ones that are too big for a particular cpu (eg: 16 bit with a small amount
292 # of memory).  There are various ways to deal with this.  Here's one.
293 # Fortunately, all of the cases where this is likely to happen will be using
294 # gld so we can tell what the error text will look like.
295
296 proc ${tool}_check_unsupported_p { output } {
297     if [regexp "(^|\n)\[^\n\]*: region \[^\n\]* is full" $output] {
298         return "memory full"
299     }
300     return ""
301 }
302
303 # Prune messages from gcc that aren't useful.
304
305 proc prune_gcc_output { text } {
306     #send_user "Before:$text\n"
307     regsub -all "(^|\n)\[^\n\]*: In (function|method) \[^\n\]*" $text "" text
308     regsub -all "(^|\n)\[^\n\]*: At top level:\[^\n\]*" $text "" text
309
310     # It would be nice to avoid passing anything to gcc that would cause it to
311     # issue these messages (since ignoring them seems like a hack on our part),
312     # but that's too difficult in the general case.  For example, sometimes
313     # you need to use -B to point gcc at crt0.o, but there are some targets
314     # that don't have crt0.o.
315     regsub -all "(^|\n)\[^\n\]*file path prefix \[^\n\]* never used" $text "" text
316     regsub -all "(^|\n)\[^\n\]*linker input file unused since linking not done" $text "" text
317
318     #send_user "After:$text\n"
319
320     return $text
321 }
322