OSDN Git Service

gcc/testsuite:
[pf3gnuchains/gcc-fork.git] / libmudflap / testsuite / lib / libmudflap.exp
1 # Copyright (C) 2001, 2002, 2003, 2004 Free Software Foundation, Inc.
2
3 # This program is free software; you can redistribute it and/or modify
4 # it under the terms of the GNU General Public License as published by
5 # the Free Software Foundation; either version 2 of the License, or
6 # (at your option) any later version.
7
8 # This program is distributed in the hope that it will be useful,
9 # but WITHOUT ANY WARRANTY; without even the implied warranty of
10 # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
11 # GNU General Public License for more details.
12
13 # You should have received a copy of the GNU General Public License
14 # along with this program; if not, write to the Free Software
15 # Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.  
16
17 # Define libmudflap callbacks for dg.exp.
18 # This file is a copy of libstdc++-v3's dejagnu driver, with minor changes.
19
20 load_lib mfdg.exp
21 load_lib libgloss.exp
22
23
24 proc libmudflap-init { language } {
25     global srcdir
26     global outdir
27     global blddir
28     global cxx
29     global includes
30     global libs
31     global cxxflags
32     global objdir
33     global gluefile wrap_flags
34     global ld_library_path
35     global tool_root_dir
36
37     switch $language {
38         "c" { set cxx [find_gcc] }
39         "c++" { set cxx [find_g++] }
40         default { error "bad language code $language"; return }
41     }
42
43     verbose -log "libmudflap-init $cxx"
44
45     set blddir [lookfor_file [get_multilibs] libmudflap]
46     set cxxblddir [lookfor_file [get_multilibs] libstdc++-v3]
47     set cxxflags_file "${cxxblddir}/scripts/testsuite_flags"
48
49     # By default, we assume we want to run program images.
50     global dg-do-what-default
51     set dg-do-what-default run
52
53     # set LD_LIBRARY_PATH so that libgcc_s, libstdc++ binaries can be found.
54     # locate libgcc.a so we don't need to account for different values of
55     # SHLIB_EXT on different platforms
56     set gccdir [lookfor_file $tool_root_dir gcc/libgcc.a]
57     if {$gccdir != ""} {
58         set gccdir [file dirname $gccdir]
59     }
60
61     set ld_library_path "."
62     append ld_library_path ":${gccdir}"
63     append ld_library_path ":${cxxblddir}/src/.libs"
64     if {[is_remote host] == 0} {
65         foreach i "[exec ${gccdir}/xgcc --print-multi-lib]" {
66             set mldir ""
67             regexp -- "\[a-z0-9=/\.-\]*;" $i mldir
68             set mldir [string trimright $mldir "\;@"]
69             if { "$mldir" == "." } {
70                 continue
71             }
72             if { [llength [glob -nocomplain ${gccdir}/${mldir}/libgcc_s*.so.*]] >= 1 } {
73                 append ld_library_path ":${gccdir}/${mldir}"
74             }
75         }
76     }
77     append ld_library_path ":${blddir}/.libs"
78
79     set libs "-L${blddir}/.libs"
80     set cxxflags "-ggdb3 -DDEBUG_ASSERT"
81     set includes "-I${srcdir} -I.."
82
83     if {$language == "c++"} {
84         if {[file exists $cxxflags_file]} then {
85             set includes "${includes} [exec sh $cxxflags_file --build-includes]"
86             set cxxflags "${cxxflags} [exec sh $cxxflags_file --cxxflags]"
87             # c++ libs are included by --build-cxx below
88             set cxx "[exec sh $cxxflags_file --build-cxx]"
89         } else {
90             lappend libs "-L${cxxblddir}src/.libs"
91             lappend includes "-I../../libstdc++-v3/include"
92         }
93     }
94
95     global mfconfig_libs
96     global add_flags
97     append add_flags " $mfconfig_libs"
98
99     verbose -log "ld_library_path=$ld_library_path"
100     setenv  LD_LIBRARY_PATH     $ld_library_path
101     setenv  SHLIB_PATH          $ld_library_path
102     setenv  LD_RUN_PATH         $ld_library_path
103     setenv  LD_LIBRARYN32_PATH  $ld_library_path
104     setenv  LD_LIBRARY64_PATH   $ld_library_path
105
106     if { [target_info needs_status_wrapper]!=""} {
107       file delete ${objdir}/testglue.o;
108       set gluefile ${objdir}/testglue.o;
109       set result [build_wrapper $gluefile];
110       if { $result != "" } {
111           set gluefile [lindex $result 0];
112           set wrap_flags [lindex $result 1];
113       } else {
114           unset gluefile
115       }
116     }
117 }
118
119 proc libmudflap-dg-test { prog do_what extra_tool_flags } {
120     # Set up the compiler flags, based on what we're going to do.
121
122     switch $do_what {
123         "preprocess" {
124             set compile_type "preprocess"
125             set output_file "[file rootname [file tail $prog]].i"
126         }
127         "compile" {
128             set compile_type "assembly"
129             set output_file "[file rootname [file tail $prog]].s"
130         }
131         "assemble" {
132             set compile_type "object"
133             set output_file "[file rootname [file tail $prog]].o"
134         }
135         "link" {
136             set compile_type "executable"
137             set output_file "./[file rootname [file tail $prog]].exe"
138         }
139         "run" {
140             set compile_type "executable"
141             # FIXME: "./" is to cope with "." not being in $PATH.
142             # Should this be handled elsewhere?
143             # YES.
144             set output_file "./[file rootname [file tail $prog]].exe"
145             # This is the only place where we care if an executable was
146             # created or not.  If it was, dg.exp will try to run it.
147             remote_file build delete $output_file;
148         }
149         default {
150             perror "$do_what: not a valid dg-do keyword"
151             return ""
152         }
153     }
154     set options ""
155     if { $extra_tool_flags != "" } {
156         lappend options "additional_flags=$extra_tool_flags"
157     }
158
159     global mfconfig_libs
160     lappend options "libs=$mfconfig_libs"
161
162     set comp_output [libmudflap_target_compile "$prog" "$output_file" "$compile_type" $options];
163     set comp_output [prune_gcc_output $comp_output ];
164
165     return [list $comp_output $output_file]
166 }
167
168
169 proc libmudflap_target_compile { source dest type options } {
170     global gluefile 
171     global wrap_flags
172     global cxx
173     global cxxflags
174     global includes
175     global libs
176     global blddir
177
178     if { [target_info needs_status_wrapper] != "" && [info exists gluefile] } {
179         lappend options "libs=${gluefile}"
180         lappend options "ldflags=${wrap_flags}"
181     }
182
183     set cxx_final $cxx
184     set cxxlibglossflags  [libgloss_link_flags]
185     set cxx_final [concat $cxx_final $cxxlibglossflags]
186     set cxx_final [concat $cxx_final $cxxflags]
187     set cxx_final [concat $cxx_final $includes]
188     set cxx_final [concat $cxx_final $libs]
189
190     lappend options "compiler=$cxx_final"
191
192     # Picks up the freshly-built testsuite library corresponding to the
193     # multilib under test.
194     lappend options "ldflags=-L${blddir}/testsuite"
195
196     return [target_compile $source $dest $type $options]
197 }
198
199
200 # A bit sloppy...  Returns a list of source files (full pathnames) to
201 # compile.  We mimic the mkcheck script in that the first time this is run,
202 # all existing files are listed in "testsuite_files" in the output
203 # directory.  Subsequent runs pull the list from that file, allowing users
204 # to trim the list down to problematic tests.
205 ### This is supposed to be done via RUNTESTFLAGS, but that doesn't work.
206 proc libmudflap-list-sourcefiles { } {
207     global srcdir
208     global outdir
209
210     set files_file "${outdir}/testsuite_files"
211     set sfiles ""
212     if { [file exists $files_file] } {
213         set f [open $files_file]
214         while { ! [eof $f] } {
215             set t [gets $f]
216             if { [string length "$t"] != 0 } {
217                 lappend sfiles ${srcdir}/${t}
218             }
219         }
220     } else {
221         set f [open $files_file "w"]
222         set where_we_were [pwd]
223         cd $srcdir
224         foreach s [lsort [glob -nocomplain "*/*.cc" "*/*/*.cc" "{,*/}*/*/*/*.cc" ]] {
225             lappend sfiles ${srcdir}/${s}
226             puts $f $s
227         }
228         cd $where_we_were
229     }
230     close $f
231
232     # Disable wchar_t tests if library not configured to support
233     # wchar_t testing. 
234     set wchar_file "${outdir}/testsuite_wchar_t"    
235     if { [file exists $wchar_file] } {
236         return $sfiles
237     } else {
238         # Remove wchar_t tests files from list.
239         set res {}
240         foreach w $sfiles {
241             if [regexp "wchar_t" $w] {
242                 verbose -log "element out list is $w"
243             } else {
244                 verbose -log "element in list is $w"
245                 lappend res $w
246             }
247         }
248         return $res
249     }
250 }
251
252
253 proc prune_gcc_output { text } {
254     regsub -all {(^|\n)[^\n]*ld: warning: libgcc_s[^\n]*not found[^\n]*try using[^\n]*} $text "" text
255     regsub -all {(^|\n)[^\n]*In function.*pthread_create[^\n]*} $text "" text
256     regsub -all {(^|\n)[^\n]*the use of .pthread.*is deprecated[^\n]*} $text "" text
257     regsub -all {(^|\n)[^\n]*Dwarf Error:.*FORM value: 14[^\n]*} $text "" text
258     regsub -all {(^|\n)[^\n]*In function[^\n]*} $text "" text
259     regsub -all {(^|\n)[^\n]*Using.*in statically linked applications requires[^\n]*} $text "" text
260
261     return $text
262 }