OSDN Git Service

* testsuite/lib/libstdc++.exp (libstdc++_wchar_t): Rename to ...
[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 messages as expected.
90     setenv LC_ALL C
91     setenv LANG C
92
93     set blddir [lookfor_file [get_multilibs] libstdc++-v3]
94     set flags_file "${blddir}/scripts/testsuite_flags"
95     v3track flags_file 2
96
97     # If a test doesn't have special options, use DEFAULT_CXXFLAGS.
98     # Use this variable if the behavior
99     #   1) only applies to libstdc++ testing
100     #   2) might need to be negated 
101     # In particular, some tests have to be run without precompiled
102     # headers, or without assertions.
103     global DEFAULT_CXXFLAGS
104     if ![info exists DEFAULT_CXXFLAGS] then {
105         # Set up includes for stdc++.h.gch, the precompiled header file.
106         if { [file exists $flags_file] } {
107             set cxxpchflags [exec sh $flags_file --cxxpchflags]
108         } else {
109             set cxxpchflags ""
110         }
111         set DEFAULT_CXXFLAGS " ${cxxpchflags}"
112
113         # Host specific goo here.
114         if { [string match "powerpc-*-darwin*" $target_triplet] } {
115             append DEFAULT_CXXFLAGS " -multiply_defined suppress"
116         } 
117     }
118     v3track DEFAULT_CXXFLAGS 2
119
120     # By default, we assume we want to run program images.
121     global dg-do-what-default
122     set dg-do-what-default run
123
124     # Copy any required data files.
125     v3-copy-files [glob -nocomplain "$srcdir/data/*.tst"]
126     v3-copy-files [glob -nocomplain "$srcdir/data/*.txt"]
127
128     # Locate libgcc.a so we don't need to account for different values of
129     # SHLIB_EXT on different platforms
130     set gccdir [lookfor_file $tool_root_dir gcc/libgcc.a]
131     if {$gccdir != ""} {
132         set gccdir [file dirname $gccdir]
133     }
134     v3track gccdir 3
135
136     # Compute what needs to be added to the existing LD_LIBRARY_PATH.
137     if {$gccdir != ""} {
138         set ld_library_path ""
139         append ld_library_path ":${gccdir}"
140         set compiler ${gccdir}/g++
141         append ld_library_path ":${blddir}/src/.libs"
142
143         if { [is_remote host] == 0 && [which $compiler] != 0 } {
144           foreach i "[exec $compiler --print-multi-lib]" {
145             set mldir ""
146             regexp -- "\[a-z0-9=/\.-\]*;" $i mldir
147             set mldir [string trimright $mldir "\;@"]
148             if { "$mldir" == "." } {
149               continue
150             }
151             if { [llength [glob -nocomplain ${gccdir}/${mldir}/libgcc_s*.so.*]] >= 1 } {
152               append ld_library_path ":${gccdir}/${mldir}"
153             }
154           }
155         }
156
157         set_ld_library_path_env_vars
158         if [info exists env(LD_LIBRARY_PATH)] {
159           verbose -log "LD_LIBRARY_PATH = $env(LD_LIBRARY_PATH)"
160         }
161     } else {
162         set compiler [transform "g++"]
163     }
164
165     # Do a bunch of handstands and backflips for cross compiling and
166     # finding simulators...
167     if [is_remote host] {
168         set header [remote_download host ${blddir}/testsuite/testsuite_hooks.h]
169         if { $header == "" } {
170             verbose -log "Unable to download ${blddir}/testsuite/testsuite_hooks.h to host."
171             return "untested"
172         }
173       set cxx [transform "g++"]
174       set cxxflags "-ggdb3"
175       set includes "-I./"
176     } else {
177         # If we find a testsuite_flags file, we're testing in the build dir.
178         if { [file exists $flags_file] } {
179             set cxx [exec sh $flags_file --build-cxx]
180             set cxxflags [exec sh $flags_file --cxxflags]
181             set includes [exec sh $flags_file --build-includes]
182         } else {
183             set cxx [transform "g++"]
184             set cxxflags "-g -O2 -D_GLIBCXX_ASSERT -fmessage-length=0" 
185             set includes "-I${srcdir}"
186         }
187     }
188
189     libstdc++_maybe_build_wrapper "${objdir}/testglue.o"
190 }
191
192 # Callback for cleanup routines.
193 proc libstdc++_exit { } {
194     global gluefile;
195
196     if [info exists gluefile] {
197         file_on_build delete $gluefile;
198         unset gluefile;
199     }
200 }
201
202 # Callback from system dg-test.
203 proc libstdc++-dg-test { prog do_what extra_tool_flags } {
204     # Set up the compiler flags, based on what we're going to do.
205     switch $do_what {
206         "preprocess" {
207             set compile_type "preprocess"
208             set output_file "[file rootname [file tail $prog]].i"
209         }
210         "compile" {
211             set compile_type "assembly"
212             set output_file "[file rootname [file tail $prog]].s"
213         }
214         "assemble" {
215             set compile_type "object"
216             set output_file "[file rootname [file tail $prog]].o"
217         }
218         "link" {
219             set compile_type "executable"
220             set output_file "./[file rootname [file tail $prog]].exe"
221         }
222         "run" {
223             set compile_type "executable"
224             # FIXME: "./" is to cope with "." not being in $PATH.
225             # Should this be handled elsewhere?
226             # YES.
227             set output_file "./[file rootname [file tail $prog]].exe"
228             # This is the only place where we care if an executable was
229             # created or not.  If it was, dg.exp will try to run it.
230             remote_file build delete $output_file;
231         }
232         default {
233             perror "$do_what: not a valid dg-do keyword"
234             return ""
235         }
236     }
237     set options ""
238     if { $extra_tool_flags != "" } {
239         lappend options "additional_flags=$extra_tool_flags"
240     }
241
242     # There is a libstdc++_compile made for us by default (via the tool-
243     # and-target file), but the defaults are lacking in goodness.
244     set comp_output [v3_target_compile "$prog" "$output_file" "$compile_type" $options];
245     set comp_output [ prune_g++_output $comp_output ];
246
247     return [list $comp_output $output_file]
248 }
249
250 # True if the library supports wchar_t.
251 set v3-wchar_t 0
252
253 # True if the library supports threads.
254 set v3-threads 0
255
256 # A string naming object files to be linked into all tests.
257 set v3-test_objs ""
258
259 # Called from libstdc++-dg-test above.  Calls back into system's
260 # target_compile to actually do the work.
261 proc v3_target_compile { source dest type options } {
262     global gluefile 
263     global wrap_flags
264     global cxx
265     global cxxflags
266     global includes
267     global blddir
268     global v3-test_objs
269
270     if { [target_info needs_status_wrapper] != "" && [info exists gluefile] } {
271         lappend options "libs=${gluefile}"
272         lappend options "ldflags=${wrap_flags}"
273     }
274
275     set cxx_final $cxx
276     set cxxlibglossflags  [libgloss_link_flags]
277     set cxx_final [concat $cxx_final $cxxlibglossflags]
278     set cxx_final [concat $cxx_final $cxxflags]
279     set cxx_final [concat $cxx_final $includes]
280     # Link the support objects into executables.
281     if { $type == "executable" } {
282         set cxx_final [concat $cxx_final ${v3-test_objs}]
283     }
284
285     lappend options "compiler=$cxx_final"
286
287     return [target_compile $source $dest $type $options]
288 }
289
290 # Build the support objects linked in with the libstdc++ tests.  In
291 # addition, set v3-wchar_t, v3-threads, and v3-test_objs
292 # appropriately.
293 proc v3-build_support {} {
294     global srcdir
295     global v3-wchar_t
296     global v3-threads
297     global v3-test_objs
298
299     # Figure out whether or not the library supports certain features.
300     set v3-wchar_t 0
301     set v3-threads 0
302     set v3-test_objs ""
303
304     set config_src "config.cc"
305     set f [open $config_src "w"]
306     puts $f "#include <bits/c++config.h>"
307     close $f
308     set preprocessed [v3_target_compile $config_src "" \
309                        preprocess "additional_flags=-dN"]
310     foreach l $preprocessed {
311         if { [string first "_GLIBCXX_USE_WCHAR_T" $l] != -1 } {
312             verbose -log "wchar_t support detected"
313             set v3-wchar_t 1
314         } elseif { [string first "_GLIBCXX_HAVE_GTHR_DEFAULT" $l] != -1 } {
315             verbose -log "thread support detected"
316             set v3-threads 1
317         }
318     }
319
320     # Build the support objects.
321     set source_files \
322         [list testsuite_abi.cc testsuite_allocator.cc testsuite_hooks.cc]
323     foreach f $source_files {
324         set object_file [file rootname $f].o
325         if { [v3_target_compile $srcdir/$f $object_file "object" \
326                "incdir=$srcdir"] 
327              != "" } {
328             error "could not compile $f"
329         }
330         append v3-test_objs "$object_file "
331     }
332 }