OSDN Git Service

2004-10-07 Phil Edwards <phil@codesourcery.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_lib prune.exp
51 load_lib dg-options.exp
52 load_gcc_lib wrapper.exp
53
54 # Useful for debugging.  Pass the name of a variable and the verbosity
55 # threshold (number of -v's on the command line).
56 proc v3track { var n } {
57     upvar $var val
58     verbose "++ $var is $val" $n
59 }
60
61 # Called by v3-init below.  "Static" to this file.
62 proc v3-copy-files {srcfiles} {
63     foreach f $srcfiles {
64         if { [catch { set symlink [file readlink $f] } x] } then {
65             remote_download target $f
66         } else {
67             if { [regexp "^/" "$symlink"] } then {
68                 remote_download target $symlink
69             } else {
70                 set dirname [file dirname $f]
71                 remote_download target $dirname/$symlink
72             }
73         }
74     }
75 }
76
77 # Called once, during runtest.exp setup.
78 proc libstdc++_init { testfile } {
79     global env
80     global srcdir blddir objdir tool_root_dir
81     global cxx cxxflags
82     global includes
83     global gluefile wrap_flags
84     global original_ld_library_path
85     global target_triplet
86
87     set blddir [lookfor_file [get_multilibs] libstdc++-v3]
88     set flags_file "${blddir}/scripts/testsuite_flags"
89     v3track flags_file 2
90
91     # If a test doesn't have special options, use DEFAULT_CXXFLAGS.
92     # Use this variable if the behavior
93     #   1) only applies to libstdc++ testing
94     #   2) might need to be negated 
95     # In particular, some tests have to be run without precompiled
96     # headers, or without assertions.
97     global DEFAULT_CXXFLAGS
98     if ![info exists DEFAULT_CXXFLAGS] then {
99         # Set up includes for stdc++.h.gch, the precompiled header file.
100         if { [file exists $flags_file] } {
101             set cxxpchflags [exec sh $flags_file --cxxpchflags]
102         } else {
103             set cxxpchflags ""
104         }
105         set DEFAULT_CXXFLAGS " ${cxxpchflags}"
106
107         # Host specific goo here.
108         if { [string match "powerpc-*-darwin*" $target_triplet] } {
109             append DEFAULT_CXXFLAGS " -multiply_defined suppress"
110         } 
111     }
112     v3track DEFAULT_CXXFLAGS 2
113
114     # By default, we assume we want to run program images.
115     global dg-do-what-default
116     set dg-do-what-default run
117
118     # Copy any required data files.
119     v3-copy-files [glob -nocomplain "$srcdir/data/*.tst"]
120     v3-copy-files [glob -nocomplain "$srcdir/data/*.txt"]
121
122     # Setup LD_LIBRARY_PATH so that libgcc_s, libstdc++ binaries can be found.
123     # Find the existing LD_LIBRARY_PATH.
124     if [info exists env(LD_LIBRARY_PATH)] {
125         set original_ld_library_path $env(LD_LIBRARY_PATH)
126         # For HP-UX
127     } elseif [info exists env(SHLIB_PATH)] {
128         set original_ld_library_path $env(SHLIB_PATH)
129         # For Darwin:
130     } elseif [info exists env(DYLD_LIBRARY_PATH)] {
131         set original_ld_library_path $env(DYLD_LIBRARY_PATH)
132         # For Solaris 32 bit:
133     } elseif [info exists env(LD_LIBRARY_PATH_32)] {
134         set original_ld_library_path $env(LD_LIBRARY_PATH_32)
135         # For Solaris 64 bit:
136     } elseif [info exists env(LD_LIBRARY_PATH_64)] {
137         set original_ld_library_path $env(LD_LIBRARY_PATH_64)
138     } else {
139         set original_ld_library_path ""
140     }
141
142     # Locate libgcc.a so we don't need to account for different values of
143     # SHLIB_EXT on different platforms
144     set gccdir [lookfor_file $tool_root_dir gcc/libgcc.a]
145     if {$gccdir != ""} {
146         set gccdir [file dirname $gccdir]
147     }
148     v3track gccdir 3
149
150     # Compute what needs to be added to the existing LD_LIBRARY_PATH.
151     set ld_library_path ""
152     append ld_library_path ":${gccdir}"
153     set compiler ${gccdir}/g++
154     if { [is_remote host] == 0 && [which $compiler] != 0 } {
155       foreach i "[exec $compiler --print-multi-lib]" {
156         set mldir ""
157         regexp -- "\[a-z0-9=/\.-\]*;" $i mldir
158         set mldir [string trimright $mldir "\;@"]
159         if { "$mldir" == "." } {
160           continue
161         }
162         if { [llength [glob -nocomplain ${gccdir}/${mldir}/libgcc_s*.so.*]] == 1 } {
163           append ld_library_path ":${gccdir}/${mldir}"
164         }
165       }
166     }
167     append ld_library_path ":${blddir}/src/.libs"
168
169     # On IRIX 6, we have to set variables akin to LD_LIBRARY_PATH, but
170     # called LD_LIBRARYN32_PATH (for the N32 ABI) and LD_LIBRARY64_PATH
171     # (for the 64-bit ABI).  The right way to do this would be to modify
172     # unix.exp -- but that's not an option since it's part of DejaGNU
173     # proper, so we do it here.
174     # The same applies to darwin (DYLD_LIBRARY_PATH), solaris 32 bit
175     # (LD_LIBRARY_PATH_32), solaris 64 bit (LD_LIBRARY_PATH_64), and HP-UX
176     # (SHLIB_PATH).
177     setenv  LD_LIBRARY_PATH     "$ld_library_path:$original_ld_library_path"
178     setenv  SHLIB_PATH          "$ld_library_path:$original_ld_library_path"
179     setenv  LD_LIBRARYN32_PATH  "$ld_library_path:$original_ld_library_path"
180     setenv  LD_LIBRARY64_PATH   "$ld_library_path:$original_ld_library_path"
181     setenv  LD_RUN_PATH         "$ld_library_path:$original_ld_library_path"
182     setenv  LD_LIBRARY_PATH_32  "$ld_library_path:$original_ld_library_path"
183     setenv  LD_LIBRARY_PATH_64  "$ld_library_path:$original_ld_library_path"
184     setenv  DYLD_LIBRARY_PATH   "$ld_library_path:$original_ld_library_path"
185     verbose -log "LD_LIBRARY_PATH = $env(LD_LIBRARY_PATH)"
186
187     # Do a bunch of handstands and backflips for cross compiling and
188     # finding simulators...
189     if [is_remote host] {
190         set header [remote_download host ${blddir}/testsuite/testsuite_hooks.h]
191         if { $header == "" } {
192             verbose -log "Unable to download ${blddir}/testsuite/testsuite_hooks.h to host."
193             return "untested"
194         }
195       set cxx [transform "g++"]
196       set cxxflags "-ggdb3"
197       set includes "-I./"
198     } else {
199         # If we find a testsuite_flags file, we're testing in the build dir.
200         if { [file exists $flags_file] } {
201             set cxx [exec sh $flags_file --build-cxx]
202             set cxxflags [exec sh $flags_file --cxxflags]
203             set includes [exec sh $flags_file --build-includes]
204         } else {
205             set cxx [transform "g++"]
206             set cxxflags "-ggdb3"
207             set includes "-I${srcdir}"
208         }
209     }
210
211     libstdc++_maybe_build_wrapper "${objdir}/testglue.o"
212 }
213
214 # Callback for cleanup routines.
215 proc libstdc++_exit { } {
216     global gluefile;
217
218     if [info exists gluefile] {
219         file_on_build delete $gluefile;
220         unset gluefile;
221     }
222 }
223
224 # Callback from system dg-test.
225 proc libstdc++-dg-test { prog do_what extra_tool_flags } {
226     # Set up the compiler flags, based on what we're going to do.
227     switch $do_what {
228         "preprocess" {
229             set compile_type "preprocess"
230             set output_file "[file rootname [file tail $prog]].i"
231         }
232         "compile" {
233             set compile_type "assembly"
234             set output_file "[file rootname [file tail $prog]].s"
235         }
236         "assemble" {
237             set compile_type "object"
238             set output_file "[file rootname [file tail $prog]].o"
239         }
240         "link" {
241             set compile_type "executable"
242             set output_file "./[file rootname [file tail $prog]].exe"
243         }
244         "run" {
245             set compile_type "executable"
246             # FIXME: "./" is to cope with "." not being in $PATH.
247             # Should this be handled elsewhere?
248             # YES.
249             set output_file "./[file rootname [file tail $prog]].exe"
250             # This is the only place where we care if an executable was
251             # created or not.  If it was, dg.exp will try to run it.
252             remote_file build delete $output_file;
253         }
254         default {
255             perror "$do_what: not a valid dg-do keyword"
256             return ""
257         }
258     }
259     set options ""
260     if { $extra_tool_flags != "" } {
261         lappend options "additional_flags=$extra_tool_flags"
262     }
263
264     # There is a libstdc++_compile made for us by default (via the tool-
265     # and-target file), but the defaults are lacking in goodness.
266     set comp_output [v3_target_compile "$prog" "$output_file" "$compile_type" $options];
267     set comp_output [ prune_g++_output $comp_output ];
268
269     return [list $comp_output $output_file]
270 }
271
272 # Called from libstdc++-dg-test above.  Calls back into system's
273 # target_compile to actually do the work.
274 proc v3_target_compile { source dest type options } {
275     global gluefile 
276     global wrap_flags
277     global cxx
278     global cxxflags
279     global includes
280     global blddir
281
282     if { [target_info needs_status_wrapper] != "" && [info exists gluefile] } {
283         lappend options "libs=${gluefile}"
284         lappend options "ldflags=${wrap_flags}"
285     }
286
287     set cxx_final $cxx
288     set cxxlibglossflags  [libgloss_link_flags]
289     set cxx_final [concat $cxx_final $cxxlibglossflags]
290     set cxx_final [concat $cxx_final $cxxflags]
291     set cxx_final [concat $cxx_final $includes]
292
293     lappend options "compiler=$cxx_final"
294
295     # Picks up the freshly-built testsuite library corresponding to the
296     # multilib under test.
297     lappend options "ldflags=-L${blddir}/testsuite"
298     lappend options "libs=-lv3test"
299
300     return [target_compile $source $dest $type $options]
301 }
302
303
304 # Called once, from libstdc++/normal.exp.
305 proc v3-list-tests { filename } {
306     global srcdir
307     global blddir
308
309     set tests_file "${blddir}/testsuite/${filename}"
310     set sfiles ""
311
312     verbose -log "In v3-list-tests"
313     verbose -log "blddir = ${blddir}"
314     verbose -log "tests_file = $tests_file"
315
316     # If there is a testsuite_file, use it. 
317     if { [file exists $tests_file] } {
318         set f [open $tests_file]
319         while { ! [eof $f] } {
320             set t [gets $f]
321             if { [string length "$t"] != 0 } {
322                 lappend sfiles  ${srcdir}/${t}
323             }
324         } 
325         close $f
326     } else {
327         verbose "cannot open $tests_file"
328     }
329     return $sfiles
330 }