OSDN Git Service

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