re PR boehm-gc/11412 (boehm-gc testing problems)
[gcc.git] / boehm-gc / testsuite / lib / boehm-gc.exp
1 # Copyright (C) 2011 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 3 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; see the file COPYING3. If not see
15 # <http://www.gnu.org/licenses/>.
16
17 proc load_gcc_lib { filename } {
18 global srcdir loaded_libs
19 load_file $srcdir/../../gcc/testsuite/lib/$filename
20 set loaded_libs($filename) ""
21 }
22
23 load_lib dg.exp
24 load_gcc_lib target-libpath.exp
25 load_gcc_lib wrapper.exp
26 # Required by target-supports-dg.exp.
27 load_gcc_lib target-supports.exp
28 # For dg-skip-if.
29 load_gcc_lib target-supports-dg.exp
30 # For ${tool}_exit.
31 load_gcc_lib gcc-defs.exp
32 # For prune_gcc_output.
33 load_gcc_lib prune.exp
34
35 set dg-do-what-default run
36
37 # Define boehm-gc callbacks for dg.exp.
38
39 # FIXME: The next two are independent of boehm-gc; move to some library.
40 proc ${tool}-dg-test-1 { target_compile prog do_what extra_tool_flags } {
41
42 # Set up the compiler flags, based on what we're going to do.
43
44 set options [list]
45 switch $do_what {
46 "compile" {
47 set compile_type "assembly"
48 set output_file "[file rootname [file tail $prog]].s"
49 }
50 "assemble" {
51 set compile_type "object"
52 set output_file "[file rootname [file tail $prog]].o"
53 }
54 "ltassemble" {
55 # Needs to be different from assemble since we cannot determine
56 # from $prog whether to produce a regular or a libtool object.
57 set compile_type "object"
58 set output_file "[file rootname [file tail $prog]].lo"
59 }
60 "link" {
61 set compile_type "executable"
62 # Don't add .exe extension, libtool may strip if from output file.
63 set output_file "[file rootname [file tail $prog]]"
64 # If we're linking a libtool object, produce a libtool library.
65 if { [file extension $prog] == ".lo" } {
66 set output_file "lib$output_file.la"
67 }
68 }
69 "run" {
70 set compile_type "executable"
71 # FIXME: "./" is to cope with "." not being in $PATH.
72 # Should this be handled elsewhere?
73 # YES.
74 set output_file "./[file rootname [file tail $prog]]"
75 # This is the only place where we care if an executable was
76 # created or not. If it was, dg.exp will try to run it.
77 remote_file build delete $output_file
78 }
79 default {
80 perror "$do_what: not a valid dg-do keyword"
81 return ""
82 }
83 }
84
85 if { $extra_tool_flags != "" } {
86 lappend options "additional_flags=$extra_tool_flags"
87 }
88
89 set comp_output [$target_compile "$prog" "$output_file" "$compile_type" $options];
90
91 return [list $comp_output $output_file]
92 }
93
94 proc ${tool}-dg-test { prog do_what extra_tool_flags } {
95 global tool
96
97 return [${tool}-dg-test-1 ${tool}_target_compile $prog $do_what $extra_tool_flags]
98 }
99
100 proc boehm-gc-init { args } {
101 global gluefile wrap_flags
102 global srcdir
103 global blddirgc
104 global TOOL_EXECUTABLE
105 global GCC_UNDER_TEST
106 global objdir
107 global gc_include
108 global gc_lib
109 global gc_lib_conv
110 global tool
111 global tool_root_dir
112 global ld_library_path
113
114 set blddirgc [lookfor_file [get_multilibs] ${tool}]
115 verbose "blddirgc: $blddirgc"
116
117 if ![info exists GCC_UNDER_TEST] then {
118 if [info exists TOOL_EXECUTABLE] {
119 set GCC_UNDER_TEST $TOOL_EXECUTABLE
120 } else {
121 set GCC_UNDER_TEST "[find_gcc]"
122 }
123 }
124
125 set gccdir [lookfor_file $tool_root_dir gcc/libgcc.a]
126 if {$gccdir != ""} {
127 set gccdir [file dirname $gccdir]
128 }
129 verbose "gccdir: $gccdir"
130
131 set ld_library_path "."
132 append ld_library_path ":${gccdir}"
133
134 set compiler "${gccdir}/xgcc"
135 if { [is_remote host] == 0 && [which $compiler] != 0 } {
136 foreach i "[exec $compiler --print-multi-lib]" {
137 set mldir ""
138 regexp -- "\[a-z0-9=_/\.-\]*;" $i mldir
139 set mldir [string trimright $mldir "\;@"]
140 if { "$mldir" == "." } {
141 continue
142 }
143 if { [llength [glob -nocomplain ${gccdir}/${mldir}/libgcc_s*.so.*]] >= 1 } {
144 append ld_library_path ":${gccdir}/${mldir}"
145 }
146 }
147 }
148 # Add the library path for boehm-gc.
149 append ld_library_path ":${blddirgc}/.libs"
150
151 # Add the library path for boehm-gc.lib libtool libraries.
152 append ld_library_path ":.libs"
153
154 verbose "ld_library_path: $ld_library_path"
155
156 # Point to the headers in boehm-gc.
157 set gc_include "${blddirgc}/include"
158 verbose "gc_include: $gc_include"
159
160 set gc_lib "${blddirgc}/libgcjgc.la"
161 verbose "gc_lib: $gc_lib"
162
163 set gc_lib_conv "${blddirgc}/libgcjgc_convenience.la"
164 verbose "gc_lib_conv: $gc_lib_conv"
165
166 set_ld_library_path_env_vars
167 boehm-gc_maybe_build_wrapper "${objdir}/testglue.o"
168 }
169
170 proc boehm-gc_target_compile { source dest type options } {
171 global gluefile wrap_flags;
172 global srcdir
173 global TOOL_OPTIONS
174 global GCC_UNDER_TEST
175 global libtool
176 global gc_include
177 global gc_lib
178 global gc_lib_conv
179 global threadcflags
180 global threadlibs
181 global extra_test_libs
182
183 if { [target_info needs_status_wrapper]!="" && [info exists gluefile] } {
184 lappend options "libs=${gluefile}"
185 lappend options "ldflags=$wrap_flags"
186 }
187
188 # TOOL_OPTIONS must come first, so that it doesn't override testcase
189 # specific options.
190 if [info exists TOOL_OPTIONS] {
191 lappend options [concat "additional_flags=$TOOL_OPTIONS" $options];
192 }
193
194 # Map type to libtool mode.
195 switch $type {
196 "object" {
197 set mode "compile"
198 }
199 "executable" {
200 set mode "link"
201 }
202 default {
203 perror "$type: unhandled type"
204 return ""
205 }
206 }
207
208 # Set this once for reuse in boehm-gc.lib/lib.exp.
209 set libtool "../libtool"
210 # We have to run silently to avoid DejaGnu lossage.
211 lappend options "compiler=$libtool --silent --tag=CC --mode=$mode \
212 $GCC_UNDER_TEST"
213
214 lappend options "additional_flags=-I${gc_include} -I${srcdir}/../include"
215 lappend options "additional_flags=${threadcflags}"
216
217 lappend options "libs=-Wc,-shared-libgcc"
218
219 if { [file extension $dest] == ".la" } {
220 lappend options "libs=${gc_lib_conv}"
221 } else {
222 lappend options "libs=${gc_lib}"
223 }
224 lappend options "libs=${threadlibs} ${extra_test_libs}"
225
226 verbose "options: $options"
227 return [target_compile $source $dest $type $options]
228 }
229
230 # Prune harmless messages.
231 proc boehm-gc-dg-prune { system text } {
232 # Prune the same messages as the gcc testsuite does.
233 set text [prune_gcc_output $text]
234
235 # Ignore harmless Darwin ranlib warnings.
236 regsub -all "(^|\n)(ranlib: file: \[^\n\]* has no symbols\n?)+" $text "\\1" text
237
238 return $text
239 }
240
241 # Build shared library from LIB.
242 proc boehm-gc-build-shlib { lib flags extra-flags } {
243 global subdir
244 global dg-do-what-default
245 global libtool
246 global gc_lib_conv
247
248 # Determine basename.
249 set basename "[file rootname [file tail $lib]]"
250 verbose "basename: $basename"
251
252 # DejaGnu 1.4.4 doesn't support nested calls to dg-test. Restore
253 # original state before calling it again.
254 if { [info procs dg-save-unknown] != [list] } {
255 rename unknown ""
256 rename dg-save-unknown unknown
257 }
258
259 set saved-dg-do-what ${dg-do-what-default}
260
261 # Compile $lib into libtool object.
262 set dg-do-what-default ltassemble
263 dg-test -keep-output $lib $flags ${extra-flags}
264
265 # FIXME: Explain options.
266 set shopt "-version-info 1:2:0 -no-undefined -rpath /nowhere"
267
268 # There's no way to get output_file out of dg-test, only
269 # ${tool}-dg-test returns it, so hardcode that here.
270 set dg-do-what-default link
271 dg-test -keep-output $basename.lo $flags "${extra-flags} $shopt"
272
273 set dg-do-what-default ${saved-dg-do-what}
274
275 # Restore unknown, dg-save-unknown as DejaGnu 1.4.4 dg-test expects them.
276 if { [info procs dg-save-unknown] == [list] } {
277 rename unknown dg-save-unknown
278 proc unknown {} {
279 }
280 }
281
282 remote_exec host $libtool "--mode=clean rm -f $basename.lo"
283
284 return lib$basename.la
285 }
286
287 # Handle dg-add-shlib.
288 proc dg-add-shlib { args } {
289 global tool
290 global srcdir subdir
291 global shlib
292
293 if { [llength $args] > 2 } {
294 error "[lindex $args 0]: too many arguments"
295 return
296 }
297
298 set lib [lindex $args 1]
299 set lib "$srcdir/$subdir/$lib"
300 verbose -log "dg-add-shlib $lib"
301
302 upvar tool_flags flags
303 upvar default_extra_tool_flags extra-flags
304 # Build support library.
305 set shlib [boehm-gc-build-shlib $lib $flags ${extra-flags}]
306
307 uplevel lappend tool_flags $shlib
308 }
309
310 # Run boehm-gc testcases.
311 proc boehm-gc-dg-runtest { testcases flags extra-flags } {
312 global runtests
313 global libtool
314 global shlib
315
316 set shlib ""
317
318 foreach testcase $testcases {
319 # If we're only testing specific files and this isn't one of them,
320 # skip it.
321 if ![runtest_file_p $runtests $testcase] {
322 return
323 }
324
325 # Run testcase.
326 # Keep output, otherwise libtool below won't remove the corresponding
327 # file in .libs.
328 dg-test -keep-output $testcase $flags ${extra-flags}
329
330 # Remove $execname and eventually $shlib.
331 remote_exec host $libtool "--mode=clean rm -f \
332 [file rootname [file tail $testcase]] $shlib"
333 }
334 }