Reverting merge from trunk
[official-gcc.git] / gcc / testsuite / lib / objc.exp
blob38fe25c2f5b385cb8ef7fba450d6d402cde4fb72
1 # Copyright (C) 1992-2013 Free Software Foundation, Inc.
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 3 of the License, or
6 # (at your option) any later version.
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.
13 # You should have received a copy of the GNU General Public License
14 # along with GCC; see the file COPYING3. If not see
15 # <http://www.gnu.org/licenses/>.
17 # This file was written by Rob Savoye (rob@cygnus.com)
18 # Currently maintained by Doug Evans (dje@cygnus.com)
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.
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.
27 load_lib libgloss.exp
28 load_lib prune.exp
29 load_lib gcc-defs.exp
30 load_lib timeout.exp
31 load_lib target-libpath.exp
34 # OBJC_UNDER_TEST is the compiler under test.
38 # default_objc_version -- extract and print the version number of the compiler
41 proc default_objc_version { } {
42 global OBJC_UNDER_TEST
44 objc_init
46 # Ignore any arguments after the command.
47 set compiler [lindex $OBJC_UNDER_TEST 0]
49 if ![is_remote host] {
50 set compiler_name [which $compiler]
51 } else {
52 set compiler_name $compiler
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 \[^\n\r\]*" $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"
66 } else {
67 # Compiler does not exist (this should have already been detected).
68 warning "$compiler does not exist"
73 # Call objc_version. We do it this way so we can override it if needed.
75 proc objc_version { } {
76 default_objc_version
80 # objc_init -- called at the start of each .exp script.
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.
86 set objc_initialized 0
88 proc objc_init { args } {
89 global rootme
90 global tmpdir
91 global libdir
92 global gluefile wrap_flags
93 global objc_initialized
94 global OBJC_UNDER_TEST
95 global TOOL_EXECUTABLE
96 global objc_libgcc_s_path
97 global gcc_warning_prefix
98 global gcc_error_prefix
100 # We set LC_ALL and LANG to C so that we get the same error messages as
101 # expected.
102 setenv LC_ALL C
103 setenv LANG C
105 # Many hosts now default to a non-ASCII C locale, however, so
106 # they can set a charset encoding here if they need.
107 if { [ishost "*-*-cygwin*"] } {
108 setenv LC_ALL C.ASCII
109 setenv LANG C.ASCII
112 if { $objc_initialized == 1 } { return; }
114 if ![info exists OBJC_UNDER_TEST] then {
115 if [info exists TOOL_EXECUTABLE] {
116 set OBJC_UNDER_TEST $TOOL_EXECUTABLE
117 } else {
118 set OBJC_UNDER_TEST [find_gcc]
122 if ![info exists tmpdir] then {
123 set tmpdir /tmp
126 set gcc_warning_prefix "warning:"
127 set gcc_error_prefix "error:"
129 objc_maybe_build_wrapper "${tmpdir}/objc-testglue.o"
131 set objc_libgcc_s_path [gcc-set-multilib-library-path $OBJC_UNDER_TEST]
134 proc objc_target_compile { source dest type options } {
135 global rootme
136 global tmpdir
137 global gluefile wrap_flags
138 global srcdir
139 global OBJC_UNDER_TEST
140 global TOOL_OPTIONS
141 global ld_library_path
142 global objc_libgcc_s_path
143 global shlib_ext
144 global TEST_ALWAYS_FLAGS
146 set shlib_ext [get_shlib_extension]
147 set ld_library_path ".:${objc_libgcc_s_path}"
149 # We have to figure out which runtime will be used on darwin because
150 # we need to add the include path for the gnu runtime if that is in
151 # use.
152 # First set the default...
153 if { [istarget *-*-darwin*] } {
154 set nextruntime 1
155 } else {
156 set nextruntime 0
158 verbose "initial next runtime state : $nextruntime" 2
159 # Next, see if we define the option in dg-options...
160 foreach opt $options {
161 if [regexp ".*-fnext-runtime.*" $opt] {
162 set nextruntime 1
164 if [regexp ".*-fgnu-runtime.*" $opt] {
165 set nextruntime 0
168 verbose "next runtime state after dg opts: $nextruntime" 2
170 set tgt [target_info name]
171 if [board_info $tgt exists multilib_flags] {
172 set lb [board_info $tgt multilib_flags]
173 verbose "board multilib_flags $lb" 2
174 foreach opt $lb {
175 if [regexp ".*-fnext-runtime.*" $opt] {
176 set nextruntime 1
178 if [regexp ".*-fgnu-runtime.*" $opt] {
179 set nextruntime 0
183 verbose "next runtime state after any multilib opts: $nextruntime" 2
185 lappend options "libs=-lobjc"
186 verbose "shared lib extension: $shlib_ext" 3
188 if { [target_info needs_status_wrapper]!="" && [info exists gluefile] } {
189 lappend options "libs=${gluefile}"
190 lappend options "ldflags=$wrap_flags"
193 if [target_info exists objc,stack_size] {
194 lappend options "additional_flags=-DSTACK_SIZE=[target_info objc,stack_size]"
196 if [target_info exists objc,no_trampolines] {
197 lappend options "additional_flags=-DNO_TRAMPOLINES"
199 if [target_info exists objc,no_label_values] {
200 lappend options "additional_flags=-DNO_LABEL_VALUES"
203 # TEST_ALWAYS_FLAGS are flags that should be passed to every
204 # compilation. They are passed first to allow individual
205 # tests to override them.
206 if [info exists TEST_ALWAYS_FLAGS] {
207 set options [concat "{additional_flags=$TEST_ALWAYS_FLAGS}" $options]
210 # TOOL_OPTIONS must come first, so that it doesn't override testcase
211 # specific options.
212 if [info exists TOOL_OPTIONS] {
213 set options [concat "{additional_flags=$TOOL_OPTIONS}" $options]
216 # If we have built libobjc along with the compiler, point the test harness
217 # at it (and associated headers).
219 set objcpath "[get_multilibs]"
221 set libobjc_dir [lookfor_file ${objcpath} libobjc/.libs/libobjc.a]
222 if { $libobjc_dir == "" } {
223 # On darwin there is, potentially, a gnu runtime too.
224 set libobjc_dir [lookfor_file ${objcpath} libobjc/.libs/libobjc-gnu.a]
226 # Perhaps we didn't build static libs.
227 if { $libobjc_dir == "" } {
228 set libobjc_dir [lookfor_file ${objcpath} libobjc/.libs/libobjc.${shlib_ext}]
229 # On darwin there is, potentially, a gnu runtime too.
230 if { $libobjc_dir == "" } {
231 set libobjc_dir [lookfor_file ${objcpath} libobjc/.libs/libobjc-gnu.${shlib_ext}]
235 if { $libobjc_dir != "" } {
236 # If we are using the gnu runtime, add its includes.
237 if { $nextruntime == 0 } {
238 set objc_include_dir "${srcdir}/../../libobjc"
239 lappend options "additional_flags=-I${objc_include_dir}"
240 verbose "adding gnu runtime include dir: $objc_include_dir "
242 set libobjc_dir [file dirname ${libobjc_dir}]
243 # Allow for %s spec substitutions..
244 set objc_link_flags " -B${libobjc_dir} "
245 lappend options "additional_flags=${objc_link_flags}"
246 set objc_link_flags " -L${libobjc_dir} "
247 lappend options "additional_flags=${objc_link_flags}"
248 append ld_library_path ":${libobjc_dir}"
250 if { $type == "precompiled_header" } {
251 # If we generating a precompiled header, we have say this is an
252 # objective-C header.
253 set source [concat "-x objective-c-header" $source]
255 lappend options "compiler=$OBJC_UNDER_TEST"
256 lappend options "timeout=[timeout_value]"
258 set_ld_library_path_env_vars
260 set options [dg-additional-files-options $options $source]
262 return [target_compile $source $dest $type $options]
266 # objc_pass -- utility to record a testcase passed.
269 proc objc_pass { testcase cflags } {
270 if { "$cflags" == "" } {
271 pass "$testcase"
272 } else {
273 pass "$testcase, $cflags"
278 # objc_fail -- utility to record a testcase failed
281 proc objc_fail { testcase cflags } {
282 if { "$cflags" == "" } {
283 fail "$testcase"
284 } else {
285 fail "$testcase, $cflags"
290 # objc_finish -- called at the end of every .exp script that calls objc_init
292 # The purpose of this proc is to hide all quirks of the testing environment
293 # from the testsuites. It also exists to undo anything that objc_init did
294 # (that needs undoing).
297 proc objc_finish { } {
298 # The testing harness apparently requires this.
299 global errorInfo
301 if [info exists errorInfo] then {
302 unset errorInfo
305 # Might as well reset these (keeps our caller from wondering whether
306 # s/he has to or not).
307 global prms_id bug_id
308 set prms_id 0
309 set bug_id 0
312 proc objc_exit { } {
313 global gluefile
315 if [info exists gluefile] {
316 file_on_build delete $gluefile
317 unset gluefile
321 # If this is an older version of dejagnu (without runtest_file_p),
322 # provide one and assume the old syntax: foo1.exp bar1.c foo2.exp bar2.c.
323 # This can be deleted after next dejagnu release.
325 if { [info procs runtest_file_p] == "" } then {
326 proc runtest_file_p { runtests testcase } {
327 if { $runtests != "" && [regexp "\[.\]\[cC\]" $runtests] } then {
328 if { [lsearch $runtests [file tail $testcase]] >= 0 } then {
329 return 1
330 } else {
331 return 0
334 return 1
338 # Provide a definition of this if missing (delete after next dejagnu release).
340 if { [info procs prune_warnings] == "" } then {
341 proc prune_warnings { text } {
342 return $text
346 # Utility used by mike-gcc.exp and c-torture.exp.
347 # Check the compiler(/assembler/linker) output for text indicating that
348 # the testcase should be marked as "unsupported".
350 # When dealing with a large number of tests, it's difficult to weed out the
351 # ones that are too big for a particular cpu (eg: 16 bit with a small amount
352 # of memory). There are various ways to deal with this. Here's one.
353 # Fortunately, all of the cases where this is likely to happen will be using
354 # gld so we can tell what the error text will look like.
356 proc ${tool}_check_unsupported_p { output } {
357 if [regexp "(^|\n)\[^\n\]*: region \[^\n\]* is full" $output] {
358 return "memory full"
360 return ""
363 # Prune messages from objc that aren't useful.
365 proc prune_objc_output { text } {
366 #send_user "Before:$text\n"
367 regsub -all "(^|\n)\[^\n\]*: In (function|method) \[^\n\]*" $text "" text
368 regsub -all "(^|\n)\[^\n\]*: At top level:\[^\n\]*" $text "" text
370 # It would be nice to avoid passing anything to objc that would cause it to
371 # issue these messages (since ignoring them seems like a hack on our part),
372 # but that's too difficult in the general case. For example, sometimes
373 # you need to use -B to point objc at crt0.o, but there are some targets
374 # that don't have crt0.o.
375 regsub -all "(^|\n)\[^\n\]*file path prefix \[^\n\]* never used" $text "" text
376 regsub -all "(^|\n)\[^\n\]*linker input file unused since linking not done" $text "" text
378 #send_user "After:$text\n"
380 return $text