]> git.ipfire.org Git - thirdparty/gcc.git/blob - libmudflap/testsuite/lib/libmudflap.exp
Merge tree-ssa-20020619-branch into mainline.
[thirdparty/gcc.git] / libmudflap / testsuite / lib / libmudflap.exp
1 # Copyright (C) 2001, 2002, 2003 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
21 load_lib mfdg.exp
22 load_lib libgloss.exp
23
24 proc libmudflap-init { compiler } {
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 verbose "libmudflap-init $compiler"
38
39 set blddir [lookfor_file [get_multilibs] libmudflap]
40
41 # By default, we assume we want to run program images.
42 global dg-do-what-default
43 set dg-do-what-default run
44
45 # set LD_LIBRARY_PATH so that libgcc_s, libstdc++ binaries can be found.
46 # locate libgcc.a so we don't need to account for different values of
47 # SHLIB_EXT on different platforms
48 set gccdir [lookfor_file $tool_root_dir gcc/libgcc.a]
49 if {$gccdir != ""} {
50 set gccdir [file dirname $gccdir]
51 }
52
53 set ld_library_path "."
54 append ld_library_path ":${gccdir}"
55 append ld_library_path ":../../libstdc++-v3/src/.libs"
56 if {[is_remote host] == 0} {
57 foreach i "[exec ${gccdir}/xgcc --print-multi-lib]" {
58 set mldir ""
59 regexp -- "\[a-z0-9=/\.-\]*;" $i mldir
60 set mldir [string trimright $mldir "\;@"]
61 if { "$mldir" == "." } {
62 continue
63 }
64 if { [llength [glob -nocomplain ${gccdir}/${mldir}/libgcc_s*.so.*]] == 1 } {
65 append ld_library_path ":${gccdir}/${mldir}"
66 append ld_library_path ":../../libstdc++-v3/${mldir}/src/.libs"
67 }
68 }
69 }
70 append ld_library_path ":${blddir}/.libs"
71 set cxx $compiler
72 set libs "-L../.libs -L../../libstdc++-v3/src/.libs -L../../../gcc"
73 set cxxflags "-ggdb3 -DDEBUG_ASSERT"
74 set includes "-I${srcdir} -I.."
75
76 verbose "ld_library_path=$ld_library_path"
77 setenv LD_LIBRARY_PATH $ld_library_path
78 setenv SHLIB_PATH $ld_library_path
79 setenv LD_LIBRARYN32_PATH $ld_library_path
80 setenv LD_LIBRARY64_PATH $ld_library_path
81
82 if { [target_info needs_status_wrapper]!=""} {
83 file delete ${objdir}/testglue.o;
84 set gluefile ${objdir}/testglue.o;
85 set result [build_wrapper $gluefile];
86 if { $result != "" } {
87 set gluefile [lindex $result 0];
88 set wrap_flags [lindex $result 1];
89 } else {
90 unset gluefile
91 }
92 }
93 }
94
95 proc libmudflap-dg-test { prog do_what extra_tool_flags } {
96 # Set up the compiler flags, based on what we're going to do.
97
98 switch $do_what {
99 "preprocess" {
100 set compile_type "preprocess"
101 set output_file "[file rootname [file tail $prog]].i"
102 }
103 "compile" {
104 set compile_type "assembly"
105 set output_file "[file rootname [file tail $prog]].s"
106 }
107 "assemble" {
108 set compile_type "object"
109 set output_file "[file rootname [file tail $prog]].o"
110 }
111 "link" {
112 set compile_type "executable"
113 set output_file "./[file rootname [file tail $prog]].exe"
114 }
115 "run" {
116 set compile_type "executable"
117 # FIXME: "./" is to cope with "." not being in $PATH.
118 # Should this be handled elsewhere?
119 # YES.
120 set output_file "./[file rootname [file tail $prog]].exe"
121 # This is the only place where we care if an executable was
122 # created or not. If it was, dg.exp will try to run it.
123 remote_file build delete $output_file;
124 }
125 default {
126 perror "$do_what: not a valid dg-do keyword"
127 return ""
128 }
129 }
130 set options ""
131 if { $extra_tool_flags != "" } {
132 lappend options "additional_flags=$extra_tool_flags"
133 }
134
135 set comp_output [libmudflap_target_compile "$prog" "$output_file" "$compile_type" $options];
136 set comp_output [prune_gcc_output $comp_output ];
137
138 return [list $comp_output $output_file]
139 }
140
141
142 proc libmudflap_target_compile { source dest type options } {
143 global gluefile
144 global wrap_flags
145 global cxx
146 global cxxflags
147 global includes
148 global libs
149 global blddir
150
151 if { [target_info needs_status_wrapper] != "" && [info exists gluefile] } {
152 lappend options "libs=${gluefile}"
153 lappend options "ldflags=${wrap_flags}"
154 }
155
156 set cxx_final $cxx
157 set cxxlibglossflags [libgloss_link_flags]
158 set cxx_final [concat $cxx_final $cxxlibglossflags]
159 set cxx_final [concat $cxx_final $cxxflags]
160 set cxx_final [concat $cxx_final $includes]
161 set cxx_final [concat $cxx_final $libs]
162
163 lappend options "compiler=$cxx_final"
164
165 # Picks up the freshly-built testsuite library corresponding to the
166 # multilib under test.
167 lappend options "ldflags=-L${blddir}/testsuite"
168
169 return [target_compile $source $dest $type $options]
170 }
171
172
173 # A bit sloppy... Returns a list of source files (full pathnames) to
174 # compile. We mimic the mkcheck script in that the first time this is run,
175 # all existing files are listed in "testsuite_files" in the output
176 # directory. Subsequent runs pull the list from that file, allowing users
177 # to trim the list down to problematic tests.
178 ### This is supposed to be done via RUNTESTFLAGS, but that doesn't work.
179 proc libmudflap-list-sourcefiles { } {
180 global srcdir
181 global outdir
182
183 set files_file "${outdir}/testsuite_files"
184 set sfiles ""
185 if { [file exists $files_file] } {
186 set f [open $files_file]
187 while { ! [eof $f] } {
188 set t [gets $f]
189 if { [string length "$t"] != 0 } {
190 lappend sfiles ${srcdir}/${t}
191 }
192 }
193 } else {
194 set f [open $files_file "w"]
195 set where_we_were [pwd]
196 cd $srcdir
197 foreach s [lsort [glob -nocomplain "*/*.cc" "*/*/*.cc" "{,*/}*/*/*/*.cc" ]] {
198 lappend sfiles ${srcdir}/${s}
199 puts $f $s
200 }
201 cd $where_we_were
202 }
203 close $f
204
205 # Disable wchar_t tests if library not configured to support
206 # wchar_t testing.
207 set wchar_file "${outdir}/testsuite_wchar_t"
208 if { [file exists $wchar_file] } {
209 return $sfiles
210 } else {
211 # Remove wchar_t tests files from list.
212 set res {}
213 foreach w $sfiles {
214 if [regexp "wchar_t" $w] {
215 verbose "element out list is $w"
216 } else {
217 verbose "element in list is $w"
218 lappend res $w
219 }
220 }
221 return $res
222 }
223 }
224
225
226 proc prune_gcc_output { text } {
227
228 regsub -all {(^|\n)[^\n]*ld: warning: libgcc_s[^\n]*not found[^\n]*try using[^\n]*} $text "" text
229
230 regsub -all {(^|\n)[^\n]*In function.*pthread_create[^\n]*} $text "" text
231
232 regsub -all {(^|\n)[^\n]*the use of .pthread.*is deprecated[^\n]*} $text "" text
233
234 regsub -all {(^|\n)[^\n]*Dwarf Error:.*FORM value: 14[^\n]*} $text "" text
235
236 return $text
237 }