OSDN Git Service

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