OSDN Git Service

2005-04-08 Benjamin Kosnik <bkoz@redhat.com>
[pf3gnuchains/gcc-fork.git] / libstdc++-v3 / testsuite / lib / libstdc++.exp
1 # libstdc++ "tool init file" for DejaGNU
2
3 # Copyright (C) 2001, 2002, 2003, 2004 Free Software Foundation, Inc.
4 #
5 # This program is free software; you can redistribute it and/or modify
6 # it under the terms of the GNU General Public License as published by
7 # the Free Software Foundation; either version 2 of the License, or
8 # (at your option) any later version.
9
10 # This program is distributed in the hope that it will be useful,
11 # but WITHOUT ANY WARRANTY; without even the implied warranty of
12 # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
13 # GNU General Public License for more details.
14
15 # You should have received a copy of the GNU General Public License
16 # along with this program; if not, write to the Free Software
17 # Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.  
18
19
20 # Define callbacks and load other libraries.  This file is loaded relatively
21 # early, and before any other file we write ourselves.  "load_lib" will
22 # find anything in the DejaGNU installation tree, or in our lib directory.
23 # "load_gcc_lib" will search the core compiler's .exp collection instead.
24 #
25 # The naming rule is that dg.exp looks for "tool-" and runtest.exp looks
26 # for "tool_" when finding callbacks.  Utility routines we define for
27 # our callbacks begin with "v3-".
28 #
29 # libstdc++_* callbacks we don't define, but could:
30 # ..._option_help           prints additional --help output
31 # ..._option_proc (--foo)   process our own options
32 # ..._init (normal.exp)     called once per test file
33 # ..._finish                bracketing function for libstdc++_init
34 # ...-dg-prune              removing output text, see top of system dg.exp
35 #
36 # Useful hook:  if ${hostname}_init exists, it will be called, almost
37 # the last thing before testing begins.  This can be defined in, e.g.,
38 # ~/.dejagnurc or $DEJAGNU.
39
40 proc load_gcc_lib { filename } {
41     global srcdir
42     load_file $srcdir/../../gcc/testsuite/lib/$filename
43 }
44
45 # system routines
46 load_lib dg.exp
47 load_lib libgloss.exp
48 # compiler routines, then ours
49 load_gcc_lib target-supports.exp
50 load_gcc_lib target-supports-dg.exp
51 load_lib prune.exp
52 load_lib dg-options.exp
53 load_gcc_lib target-libpath.exp
54 load_gcc_lib wrapper.exp
55
56 # Useful for debugging.  Pass the name of a variable and the verbosity
57 # threshold (number of -v's on the command line).
58 proc v3track { var n } {
59     upvar $var val
60     verbose "++ $var is $val" $n
61 }
62
63 # Called by v3-init below.  "Static" to this file.
64 proc v3-copy-files {srcfiles} {
65     foreach f $srcfiles {
66         if { [catch { set symlink [file readlink $f] } x] } then {
67             remote_download target $f
68         } else {
69             if { [regexp "^/" "$symlink"] } then {
70                 remote_download target $symlink
71             } else {
72                 set dirname [file dirname $f]
73                 remote_download target $dirname/$symlink
74             }
75         }
76     }
77 }
78
79 # Called once, during runtest.exp setup.
80 proc libstdc++_init { testfile } {
81     global env
82     global srcdir blddir objdir tool_root_dir
83     global cxx cxxflags
84     global includes
85     global gluefile wrap_flags
86     global ld_library_path
87     global target_triplet
88
89     # We set LC_ALL and LANG to C so that we get the same error
90     # messages as expected.
91     setenv LC_ALL C
92     setenv LANG C
93
94     set blddir [lookfor_file [get_multilibs] libstdc++-v3]
95     set flags_file "${blddir}/scripts/testsuite_flags"
96     v3track flags_file 2
97
98     # If a test doesn't have special options, use DEFAULT_CXXFLAGS.
99     # Use this variable if the behavior
100     #   1) only applies to libstdc++ testing
101     #   2) might need to be negated 
102     # In particular, some tests have to be run without precompiled
103     # headers, or without assertions.
104     global DEFAULT_CXXFLAGS
105     if ![info exists DEFAULT_CXXFLAGS] then {
106         # Set up includes for stdc++.h.gch, the precompiled header file.
107         if { [file exists $flags_file] } {
108             set cxxpchflags [exec sh $flags_file --cxxpchflags]
109         } else {
110             set cxxpchflags ""
111         }
112         set DEFAULT_CXXFLAGS " ${cxxpchflags}"
113
114         # Host specific goo here.
115         if { [string match "powerpc-*-darwin*" $target_triplet] } {
116             append DEFAULT_CXXFLAGS " -multiply_defined suppress"
117         } 
118     }
119     v3track DEFAULT_CXXFLAGS 2
120
121     # By default, we assume we want to run program images.
122     global dg-do-what-default
123     set dg-do-what-default run
124
125     # Copy any required data files.
126     v3-copy-files [glob -nocomplain "$srcdir/data/*.tst"]
127     v3-copy-files [glob -nocomplain "$srcdir/data/*.txt"]
128
129     # Locate libgcc.a so we don't need to account for different values of
130     # SHLIB_EXT on different platforms
131     set gccdir [lookfor_file $tool_root_dir gcc/libgcc.a]
132     if {$gccdir != ""} {
133         set gccdir [file dirname $gccdir]
134     }
135     v3track gccdir 3
136
137     # Compute what needs to be added to the existing LD_LIBRARY_PATH.
138     if {$gccdir != ""} {
139         set ld_library_path ""
140         append ld_library_path ":${gccdir}"
141         set compiler ${gccdir}/g++
142         append ld_library_path ":${blddir}/src/.libs"
143
144         if { [is_remote host] == 0 && [which $compiler] != 0 } {
145           foreach i "[exec $compiler --print-multi-lib]" {
146             set mldir ""
147             regexp -- "\[a-z0-9=/\.-\]*;" $i mldir
148             set mldir [string trimright $mldir "\;@"]
149             if { "$mldir" == "." } {
150               continue
151             }
152             if { [llength [glob -nocomplain ${gccdir}/${mldir}/libgcc_s*.so.*]] >= 1 } {
153               append ld_library_path ":${gccdir}/${mldir}"
154             }
155           }
156         }
157
158         set_ld_library_path_env_vars
159         if [info exists env(LD_LIBRARY_PATH)] {
160           verbose -log "LD_LIBRARY_PATH = $env(LD_LIBRARY_PATH)"
161         }
162     } else {
163         set compiler [transform "g++"]
164     }
165
166     # Do a bunch of handstands and backflips for cross compiling and
167     # finding simulators...
168     if [is_remote host] {
169         set header [remote_download host ${blddir}/testsuite/testsuite_hooks.h]
170         if { $header == "" } {
171             verbose -log "Unable to download ${blddir}/testsuite/testsuite_hooks.h to host."
172             return "untested"
173         }
174       set cxx [transform "g++"]
175       set cxxflags "-ggdb3"
176       set includes "-I./"
177     } else {
178         # If we find a testsuite_flags file, we're testing in the build dir.
179         if { [file exists $flags_file] } {
180             set cxx [exec sh $flags_file --build-cxx]
181             set cxxflags [exec sh $flags_file --cxxflags]
182             set includes [exec sh $flags_file --build-includes]
183         } else {
184             set cxx [transform "g++"]
185             set cxxflags "-g -O2 -D_GLIBCXX_ASSERT -fmessage-length=0" 
186             set includes "-I${srcdir}"
187             # Guess at the location of the installed locale files.
188             # (It would be nice if "gcc --print-file-name" could find
189             # message files, but it cannot.)
190             set absolute_cxx [which $cxx]
191             if { $absolute_cxx != "" } {
192                 set localedir "[file dirname $absolute_cxx]/../share/locale"
193             }
194             set cxxflags "$cxxflags -DLOCALEDIR=\"$localedir\""
195         }
196     }
197
198     libstdc++_maybe_build_wrapper "${objdir}/testglue.o"
199 }
200
201 # Callback for cleanup routines.
202 proc libstdc++_exit { } {
203     global gluefile;
204
205     if [info exists gluefile] {
206         file_on_build delete $gluefile;
207         unset gluefile;
208     }
209 }
210
211 # Callback from system dg-test.
212 proc libstdc++-dg-test { prog do_what extra_tool_flags } {
213     # Set up the compiler flags, based on what we're going to do.
214     switch $do_what {
215         "preprocess" {
216             set compile_type "preprocess"
217             set output_file "[file rootname [file tail $prog]].i"
218         }
219         "compile" {
220             set compile_type "assembly"
221             set output_file "[file rootname [file tail $prog]].s"
222         }
223         "assemble" {
224             set compile_type "object"
225             set output_file "[file rootname [file tail $prog]].o"
226         }
227         "link" {
228             set compile_type "executable"
229             set output_file "./[file rootname [file tail $prog]].exe"
230         }
231         "run" {
232             set compile_type "executable"
233             # FIXME: "./" is to cope with "." not being in $PATH.
234             # Should this be handled elsewhere?
235             # YES.
236             set output_file "./[file rootname [file tail $prog]].exe"
237             # This is the only place where we care if an executable was
238             # created or not.  If it was, dg.exp will try to run it.
239             remote_file build delete $output_file;
240         }
241         default {
242             perror "$do_what: not a valid dg-do keyword"
243             return ""
244         }
245     }
246     set options ""
247     if { $extra_tool_flags != "" } {
248         lappend options "additional_flags=$extra_tool_flags"
249     }
250
251     # There is a libstdc++_compile made for us by default (via the tool-
252     # and-target file), but the defaults are lacking in goodness.
253     set comp_output [v3_target_compile "$prog" "$output_file" "$compile_type" $options];
254     set comp_output [ prune_g++_output $comp_output ];
255
256     return [list $comp_output $output_file]
257 }
258
259 # True if the library supports wchar_t.
260 set v3-wchar_t 0
261
262 # True if the library supports threads.
263 set v3-threads 0
264
265 # A string naming object files to be linked into all tests.
266 set v3-test_objs ""
267
268 # Called from libstdc++-dg-test above.  Calls back into system's
269 # target_compile to actually do the work.
270 proc v3_target_compile { source dest type options } {
271     global gluefile 
272     global wrap_flags
273     global cxx
274     global cxxflags
275     global includes
276     global blddir
277     global v3-test_objs
278
279     if { [target_info needs_status_wrapper] != "" && [info exists gluefile] } {
280         lappend options "libs=${gluefile}"
281         lappend options "ldflags=${wrap_flags}"
282     }
283
284     set cxx_final $cxx
285     set cxxlibglossflags  [libgloss_link_flags]
286     set cxx_final [concat $cxx_final $cxxlibglossflags]
287     set cxx_final [concat $cxx_final $cxxflags]
288     set cxx_final [concat $cxx_final $includes]
289     # Link the support objects into executables.
290     if { $type == "executable" } {
291         set cxx_final [concat $cxx_final ${v3-test_objs}]
292     }
293
294     lappend options "compiler=$cxx_final"
295
296     return [target_compile $source $dest $type $options]
297 }
298
299
300 # Build the support objects linked in with the libstdc++ tests.  In
301 # addition, set v3-wchar_t, v3-threads, and v3-test_objs
302 # appropriately.
303 proc v3-build_support {} {
304     global srcdir
305     global v3-wchar_t
306     global v3-threads
307     global v3-test_objs
308
309     # Figure out whether or not the library supports certain features.
310     set v3-wchar_t 0
311     set v3-threads 0
312     set v3-test_objs ""
313
314     set config_src "config.cc"
315     set f [open $config_src "w"]
316     puts $f "#include <bits/c++config.h>"
317     close $f
318     set preprocessed [v3_target_compile $config_src "" \
319                        preprocess "additional_flags=-dN"]
320     foreach l $preprocessed {
321         if { [string first "_GLIBCXX_USE_WCHAR_T" $l] != -1 } {
322             verbose -log "wchar_t support detected"
323             set v3-wchar_t 1
324         } elseif { [string first "_GLIBCXX_HAVE_GTHR_DEFAULT" $l] != -1 } {
325             verbose -log "thread support detected"
326             set v3-threads 1
327         }
328     }
329
330     # Build the support objects.
331     set source_files \
332         [list testsuite_abi.cc testsuite_allocator.cc testsuite_character.cc testsuite_hooks.cc]
333     foreach f $source_files {
334         set object_file [file rootname $f].o
335         # Compile with "-w" so that warnings issued by the compiler
336         # do not prevent compilation.
337         if { [v3_target_compile $srcdir/$f $object_file "object" \
338                   [list "incdir=$srcdir" "additional_flags=-w"]]
339              != "" } {
340             error "could not compile $f"
341         }
342         append v3-test_objs "$object_file "
343     }
344 }