OSDN Git Service

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