OSDN Git Service

2004-09-12 Andrew Pinski <apinski@apple.com>
[pf3gnuchains/gcc-fork.git] / gcc / testsuite / lib / objc.exp
1 # Copyright (C) 1992, 1993, 1994, 1996, 1997, 2000, 2001, 2002
2 # Free Software Foundation, Inc.
3
4 # This program is free software; you can redistribute it and/or modify
5 # it under the terms of the GNU General Public License as published by
6 # the Free Software Foundation; either version 2 of the License, or
7 # (at your option) any later version.
8
9 # This program is distributed in the hope that it will be useful,
10 # but WITHOUT ANY WARRANTY; without even the implied warranty of
11 # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
12 # GNU General Public License for more details.
13
14 # You should have received a copy of the GNU General Public License
15 # along with this program; if not, write to the Free Software
16 # Foundation, 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
17
18 # This file was written by Rob Savoye (rob@cygnus.com)
19 # Currently maintained by Doug Evans (dje@cygnus.com)
20
21 # This file is loaded by the tool init file (eg: unix.exp).  It provides
22 # default definitions for objc_start, etc. and other supporting cast members.
23
24 # These globals are used by objc_start if no compiler arguments are provided.
25 # They are also used by the various testsuites to define the environment:
26 # where to find stdio.h, libc.a, etc.
27
28 load_lib libgloss.exp
29 load_lib prune.exp
30 load_lib gcc-defs.exp
31
32 #
33 # OBJC_UNDER_TEST is the compiler under test.
34 #
35
36 #
37 # default_objc_version -- extract and print the version number of the compiler
38 #
39
40 proc default_objc_version { } {
41     global OBJC_UNDER_TEST
42
43     objc_init;
44
45     # ignore any arguments after the command
46     set compiler [lindex $OBJC_UNDER_TEST 0]
47
48     if ![is_remote host] {
49         set compiler_name [which $compiler];
50     } else {
51         set compiler_name $compiler;
52     }
53
54     # verify that the compiler exists
55     if { $compiler_name != 0 } then {
56         set tmp [remote_exec host "$compiler -v"]
57         set status [lindex $tmp 0];
58         set output [lindex $tmp 1];
59         regexp " version \[^\n\r\]*" $output version
60         if { $status == 0 && [info exists version] } then {
61             clone_output "$compiler_name $version\n"
62         } else {
63             clone_output "Couldn't determine version of $compiler_name: $output\n"
64         }
65     } else {
66         # compiler does not exist (this should have already been detected)
67         warning "$compiler does not exist"
68     }
69 }
70
71 #
72 # Call objc_version. We do it this way so we can override it if needed.
73 #
74 proc objc_version { } {
75     default_objc_version;
76 }
77
78 #
79 # objc_init -- called at the start of each .exp script.
80 #
81 # There currently isn't much to do, but always using it allows us to
82 # make some enhancements without having to go back and rewrite the scripts.
83 #
84
85 set objc_initialized 0
86
87 proc objc_init { args } {
88     global rootme
89     global tmpdir
90     global libdir
91     global gluefile wrap_flags
92     global objc_initialized
93     global OBJC_UNDER_TEST
94     global TOOL_EXECUTABLE
95     global objc_libgcc_s_path
96
97     if { $objc_initialized == 1 } { return; }
98
99     if ![info exists OBJC_UNDER_TEST] then {
100         if [info exists TOOL_EXECUTABLE] {
101             set OBJC_UNDER_TEST $TOOL_EXECUTABLE;
102         } else {
103             set OBJC_UNDER_TEST [find_gcc]
104         }
105     }
106
107     if ![info exists tmpdir] then {
108         set tmpdir /tmp
109     }
110     if { [target_info needs_status_wrapper]!="" && ![info exists gluefile] } {
111         set gluefile ${tmpdir}/objc-testglue.o;
112         set result [build_wrapper $gluefile];
113         if { $result != "" } {
114             set gluefile [lindex $result 0];
115             set wrap_flags [lindex $result 1];
116         } else {
117             unset gluefile
118         }
119     }
120
121     set objc_libgcc_s_path "${rootme}"
122     set compiler [lindex $OBJC_UNDER_TEST 0]
123     if { [is_remote host] == 0 && [which $compiler] != 0 } {
124         foreach i "[exec $compiler --print-multi-lib]" {
125             set mldir ""
126             regexp -- "\[a-z0-9=/\.-\]*;" $i mldir
127             set mldir [string trimright $mldir "\;@"]
128             if { "$mldir" == "." } {
129                 continue
130             }
131             if { [llength [glob -nocomplain ${rootme}/${mldir}/libgcc_s*.so.*]] == 1 } {
132                 append objc_libgcc_s_path ":${rootme}/${mldir}"
133             }
134         }
135     }
136 }
137
138 proc objc_target_compile { source dest type options } {
139     global rootme;
140     global tmpdir;
141     global gluefile wrap_flags;
142     global srcdir
143     global OBJC_UNDER_TEST
144     global TOOL_OPTIONS
145     global ld_library_path
146     global objc_libgcc_s_path
147
148     set ld_library_path ".:${objc_libgcc_s_path}"
149     lappend options "libs=-lobjc"
150
151     if { [target_info needs_status_wrapper]!="" && [info exists gluefile] } {
152         lappend options "libs=${gluefile}"
153         lappend options "ldflags=$wrap_flags"
154     }
155
156     if [target_info exists objc,stack_size] {
157         lappend options "additional_flags=-DSTACK_SIZE=[target_info objc,stack_size]"
158     }
159     if [target_info exists objc,no_trampolines] {
160         lappend options "additional_flags=-DNO_TRAMPOLINES"
161     }
162     if [target_info exists objc,no_label_values] {
163         lappend options "additional_flags=-DNO_LABEL_VALUES"
164     }
165     # TOOL_OPTIONS must come first, so that it doesn't override testcase
166     # specific options.
167     if [info exists TOOL_OPTIONS] {
168         set options [concat "additional_flags=$TOOL_OPTIONS" $options];
169     }
170
171     # If we have built libobjc along with the compiler (which usually
172     # _is not_ the case on Mac OS X systems), point the test harness
173     # at it (and associated headers).
174
175     set objcpath "[get_multilibs]"
176
177     set libobjc_dir [lookfor_file ${objcpath} libobjc/.libs/libobjc.a]
178     if { $libobjc_dir == ""} {
179       verbose "see if we have -fgnu-runtime in [target_info name]"
180       if [regexp ".*-fgnu-runtime.*" [target_info name]] {
181         set libobjc_dir [lookfor_file ${objcpath} libobjc/.libs/libobjc-gnu.a]
182       }
183     }
184     if { $libobjc_dir != "" } {
185         set objc_include_dir "${srcdir}/../../libobjc"
186         lappend options "additional_flags=-I${objc_include_dir}"
187         set libobjc_dir [file dirname ${libobjc_dir}]
188         set objc_link_flags "-L${libobjc_dir}"
189         lappend options "additional_flags=${objc_link_flags}"
190         append ld_library_path ":${libobjc_dir}"
191     }
192     lappend options "compiler=$OBJC_UNDER_TEST"
193
194     # On IRIX 6, we have to set variables akin to LD_LIBRARY_PATH, but
195     # called LD_LIBRARYN32_PATH (for the N32 ABI) and LD_LIBRARY64_PATH
196     # (for the 64-bit ABI).  The right way to do this would be to modify
197     # unix.exp -- but that's not an option since it's part of DejaGNU
198     # proper, so we do it here.
199     # The same applies to Darwin (DYLD_LIBRARY_PATH), Solaris 32 bit
200     # (LD_LIBRARY_PATH_32), Solaris 64 bit (LD_LIBRARY_PATH_64), and HP-UX
201     # (SHLIB_PATH).
202     setenv  LD_LIBRARY_PATH     $ld_library_path
203     setenv  SHLIB_PATH          $ld_library_path
204     setenv  LD_LIBRARYN32_PATH  $ld_library_path
205     setenv  LD_LIBRARY64_PATH   $ld_library_path
206     setenv  LD_LIBRARY_PATH_32  $ld_library_path
207     setenv  LD_LIBRARY_PATH_64  $ld_library_path
208     setenv  DYLD_LIBRARY_PATH   $ld_library_path
209
210     return [target_compile $source $dest $type $options]
211 }
212
213 #
214 # objc_pass -- utility to record a testcase passed
215 #
216
217 proc objc_pass { testcase cflags } {
218     if { "$cflags" == "" } {
219         pass "$testcase"
220     } else {
221         pass "$testcase, $cflags"
222     }
223 }
224
225 #
226 # objc_fail -- utility to record a testcase failed
227 #
228
229 proc objc_fail { testcase cflags } {
230     if { "$cflags" == "" } {
231         fail "$testcase"
232     } else {
233         fail "$testcase, $cflags"
234     }
235 }
236
237 #
238 # objc_finish -- called at the end of every .exp script that calls objc_init
239 #
240 # The purpose of this proc is to hide all quirks of the testing environment
241 # from the testsuites.  It also exists to undo anything that objc_init did
242 # (that needs undoing).
243 #
244
245 proc objc_finish { } {
246     # The testing harness apparently requires this.
247     global errorInfo;
248
249     if [info exists errorInfo] then {
250         unset errorInfo
251     }
252
253     # Might as well reset these (keeps our caller from wondering whether
254     # s/he has to or not).
255     global prms_id bug_id
256     set prms_id 0
257     set bug_id 0
258 }
259
260 proc objc_exit { } {
261     global gluefile;
262
263     if [info exists gluefile] {
264         file_on_build delete $gluefile;
265         unset gluefile;
266     }
267 }
268     
269 # If this is an older version of dejagnu (without runtest_file_p),
270 # provide one and assume the old syntax: foo1.exp bar1.c foo2.exp bar2.c.
271 # This can be deleted after next dejagnu release.
272
273 if { [info procs runtest_file_p] == "" } then {
274     proc runtest_file_p { runtests testcase } {
275         if { $runtests != "" && [regexp "\[.\]\[cC\]" $runtests] } then {
276             if { [lsearch $runtests [file tail $testcase]] >= 0 } then {
277                 return 1
278             } else {
279                 return 0
280             }
281         }
282         return 1
283     }
284 }
285
286 # Provide a definition of this if missing (delete after next dejagnu release).
287
288 if { [info procs prune_warnings] == "" } then {
289     proc prune_warnings { text } {
290         return $text
291     }
292 }
293
294 # Utility used by mike-gcc.exp and c-torture.exp.
295 # Check the compiler(/assembler/linker) output for text indicating that
296 # the testcase should be marked as "unsupported".
297 #
298 # When dealing with a large number of tests, it's difficult to weed out the
299 # ones that are too big for a particular cpu (eg: 16 bit with a small amount
300 # of memory).  There are various ways to deal with this.  Here's one.
301 # Fortunately, all of the cases where this is likely to happen will be using
302 # gld so we can tell what the error text will look like.
303
304 proc ${tool}_check_unsupported_p { output } {
305     if [regexp "(^|\n)\[^\n\]*: region \[^\n\]* is full" $output] {
306         return "memory full"
307     }
308     return ""
309 }
310
311 # Prune messages from objc that aren't useful.
312
313 proc prune_objc_output { text } {
314     #send_user "Before:$text\n"
315     regsub -all "(^|\n)\[^\n\]*: In (function|method) \[^\n\]*" $text "" text
316     regsub -all "(^|\n)\[^\n\]*: At top level:\[^\n\]*" $text "" text
317
318     # It would be nice to avoid passing anything to objc that would cause it to
319     # issue these messages (since ignoring them seems like a hack on our part),
320     # but that's too difficult in the general case.  For example, sometimes
321     # you need to use -B to point objc at crt0.o, but there are some targets
322     # that don't have crt0.o.
323     regsub -all "(^|\n)\[^\n\]*file path prefix \[^\n\]* never used" $text "" text
324     regsub -all "(^|\n)\[^\n\]*linker input file unused since linking not done" $text "" text
325
326     #send_user "After:$text\n"
327
328     return $text
329 }
330