OSDN Git Service

* lib/{objc.exp,objc-torture.exp}: New files for objc testing harness.
[pf3gnuchains/gcc-fork.git] / gcc / testsuite / lib / objc.exp
1 # Copyright (C) 1992, 1993, 1994, 1996, 1997 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 objc_start, etc. and other supporting cast members.
22
23 # These globals are used by objc_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 #
28 # OBJC_UNDER_TEST is the compiler under test.
29 #
30
31 #
32 # default_objc_version -- extract and print the version number of the compiler
33 #
34
35 proc default_objc_version { } {
36     global OBJC_UNDER_TEST
37
38     objc_init;
39
40     # ignore any arguments after the command
41     set compiler [lindex $OBJC_UNDER_TEST 0]
42
43     if ![is_remote host] {
44         set compiler_name [which $compiler];
45     } else {
46         set compiler_name $compiler;
47     }
48
49     # verify that the compiler exists
50     if { $compiler_name != 0 } then {
51         set tmp [remote_exec host "$compiler -v"]
52         set status [lindex $tmp 0];
53         set output [lindex $tmp 1];
54         regexp "version.*$" $output version
55         if { $status == 0 && [info exists version] } then {
56             clone_output "$compiler_name $version\n"
57         } else {
58             clone_output "Couldn't determine version of $compiler_name: $output\n"
59         }
60     } else {
61         # compiler does not exist (this should have already been detected)
62         warning "$compiler does not exist"
63     }
64 }
65
66 #
67 # Call objc_version. We do it this way so we can override it if needed.
68 #
69 proc objc_version { } {
70     default_objc_version;
71 }
72
73 #
74 # objc_init -- called at the start of each .exp script.
75 #
76 # There currently isn't much to do, but always using it allows us to
77 # make some enhancements without having to go back and rewrite the scripts.
78 #
79
80 set objc_initialized 0
81
82 proc objc_init { args } {
83     global tmpdir
84     global libdir
85     global gluefile wrap_flags
86     global objc_initialized
87     global OBJC_UNDER_TEST
88     global TOOL_EXECUTABLE
89
90     if { $objc_initialized == 1 } { return; }
91
92     if ![info exists OBJC_UNDER_TEST] then {
93         if [info exists TOOL_EXECUTABLE] {
94             set OBJC_UNDER_TEST $TOOL_EXECUTABLE;
95         } else {
96             set OBJC_UNDER_TEST [find_gcc]
97         }
98     }
99
100     if ![info exists tmpdir] then {
101         set tmpdir /tmp
102     }
103     if { [target_info needs_status_wrapper]!="" && ![info exists gluefile] } {
104         set gluefile ${tmpdir}/testglue.o;
105         set result [build_wrapper $gluefile];
106         if { $result != "" } {
107             set gluefile [lindex $result 0];
108             set wrap_flags [lindex $result 1];
109         } else {
110             unset gluefile
111         }
112     }
113 }
114
115 proc objc_target_compile { source dest type options } {
116     global tmpdir;
117     global gluefile wrap_flags;
118     global OBJC_UNDER_TEST
119     global TOOL_OPTIONS
120
121     lappend options "libs=-lobjc"
122     if { [target_info needs_status_wrapper]!="" && [info exists gluefile] } {
123         lappend options "libs=${gluefile}"
124         lappend options "ldflags=$wrap_flags"
125     }
126
127     if [target_info exists objc,stack_size] {
128         lappend options "additional_flags=-DSTACK_SIZE=[target_info objc,stack_size]"
129     }
130     if [target_info exists objc,no_trampolines] {
131         lappend options "additional_flags=-DNO_TRAMPOLINES"
132     }
133     if [target_info exists objc,no_label_values] {
134         lappend options "additional_flags=-DNO_LABEL_VALUES"
135     }
136     if [info exists TOOL_OPTIONS] {
137         lappend options "additional_flags=$TOOL_OPTIONS"
138     }
139     if [target_info exists objc,no_varargs] {
140         lappend options "additional_flags=-DNO_VARARGS"
141     }
142     lappend options "compiler=$OBJC_UNDER_TEST"
143     return [target_compile $source $dest $type $options]
144 }
145
146 #
147 # objc_pass -- utility to record a testcase passed
148 #
149
150 proc objc_pass { testcase cflags } {
151     if { "$cflags" == "" } {
152         pass "$testcase"
153     } else {
154         pass "$testcase, $cflags"
155     }
156 }
157
158 #
159 # objc_fail -- utility to record a testcase failed
160 #
161
162 proc objc_fail { testcase cflags } {
163     if { "$cflags" == "" } {
164         fail "$testcase"
165     } else {
166         fail "$testcase, $cflags"
167     }
168 }
169
170 #
171 # objc_finish -- called at the end of every .exp script that calls objc_init
172 #
173 # The purpose of this proc is to hide all quirks of the testing environment
174 # from the testsuites.  It also exists to undo anything that objc_init did
175 # (that needs undoing).
176 #
177
178 proc objc_finish { } {
179     # The testing harness apparently requires this.
180     global errorInfo;
181
182     if [info exists errorInfo] then {
183         unset errorInfo
184     }
185
186     # Might as well reset these (keeps our caller from wondering whether
187     # s/he has to or not).
188     global prms_id bug_id
189     set prms_id 0
190     set bug_id 0
191 }
192
193 proc objc_exit { } {
194     global gluefile;
195
196     if [info exists gluefile] {
197         file_on_build delete $gluefile;
198         unset gluefile;
199     }
200 }
201     
202 # If this is an older version of dejagnu (without runtest_file_p),
203 # provide one and assume the old syntax: foo1.exp bar1.c foo2.exp bar2.c.
204 # This can be deleted after next dejagnu release.
205
206 if { [info procs runtest_file_p] == "" } then {
207     proc runtest_file_p { runtests testcase } {
208         if { $runtests != "" && [regexp "\[.\]\[cC\]" $runtests] } then {
209             if { [lsearch $runtests [file tail $testcase]] >= 0 } then {
210                 return 1
211             } else {
212                 return 0
213             }
214         }
215         return 1
216     }
217 }
218
219 # Provide a definition of this if missing (delete after next dejagnu release).
220
221 if { [info procs prune_warnings] == "" } then {
222     proc prune_warnings { text } {
223         return $text
224     }
225 }
226
227 # Utility used by mike-gcc.exp and c-torture.exp.
228 # Check the compiler(/assembler/linker) output for text indicating that
229 # the testcase should be marked as "unsupported".
230 #
231 # When dealing with a large number of tests, it's difficult to weed out the
232 # ones that are too big for a particular cpu (eg: 16 bit with a small amount
233 # of memory).  There are various ways to deal with this.  Here's one.
234 # Fortunately, all of the cases where this is likely to happen will be using
235 # gld so we can tell what the error text will look like.
236
237 proc ${tool}_check_unsupported_p { output } {
238     if [regexp "(^|\n)\[^\n\]*: region \[^\n\]* is full" $output] {
239         return "memory full"
240     }
241     return ""
242 }
243
244 # Prune messages from objc that aren't useful.
245
246 proc prune_objc_output { text } {
247     #send_user "Before:$text\n"
248     regsub -all "(^|\n)\[^\n\]*: In (function|method) \[^\n\]*" $text "" text
249     regsub -all "(^|\n)\[^\n\]*: At top level:\[^\n\]*" $text "" text
250
251     # It would be nice to avoid passing anything to objc that would cause it to
252     # issue these messages (since ignoring them seems like a hack on our part),
253     # but that's too difficult in the general case.  For example, sometimes
254     # you need to use -B to point objc at crt0.o, but there are some targets
255     # that don't have crt0.o.
256     regsub -all "(^|\n)\[^\n\]*file path prefix \[^\n\]* never used" $text "" text
257     regsub -all "(^|\n)\[^\n\]*linker input file unused since linking not done" $text "" text
258
259     #send_user "After:$text\n"
260
261     return $text
262 }
263