1 # Copyright (C) 2003 Free Software Foundation, Inc.
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.
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.
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.
17 proc load_gcc_lib { filename } {
19 load_file $srcdir/../../gcc/testsuite/lib/$filename
24 load_gcc_lib target-libpath.exp
25 load_gcc_lib wrapper.exp
28 # Define libffi callbacks for dg.exp.
30 proc libffi-dg-test-1 { target_compile prog do_what extra_tool_flags } {
31 # Set up the compiler flags, based on what we're going to do.
36 set compile_type "assembly"
37 set output_file "[file rootname [file tail $prog]].s"
40 set compile_type "executable"
41 set output_file "[file rootname [file tail $prog]].exe"
42 # The following line is needed for targets like the i960 where
43 # the default output file is b.out. Sigh.
46 set compile_type "executable"
47 # FIXME: "./" is to cope with "." not being in $PATH.
48 # Should this be handled elsewhere?
50 set output_file "./[file rootname [file tail $prog]].exe"
51 # This is the only place where we care if an executable was
52 # created or not. If it was, dg.exp will try to run it.
53 remote_file build delete $output_file;
56 perror "$do_what: not a valid dg-do keyword"
61 if { $extra_tool_flags != "" } {
62 lappend options "additional_flags=$extra_tool_flags"
65 set comp_output [libffi_target_compile "$prog" "$output_file" "$compile_type" $options];
68 return [list $comp_output $output_file]
72 proc libffi-dg-test { prog do_what extra_tool_flags } {
73 return [libffi-dg-test-1 target_compile $prog $do_what $extra_tool_flags]
76 proc libffi-init { args } {
77 global gluefile wrap_flags;
85 global libffi_link_flags
87 global ld_library_path
89 set blddirffi [lookfor_file [get_multilibs] libffi]
90 verbose "libffi $blddirffi"
91 set blddircxx [lookfor_file [get_multilibs] libstdc++-v3]
92 verbose "libstdc++ $blddircxx"
94 set gccdir [lookfor_file $tool_root_dir gcc/libgcc.a]
96 set gccdir [file dirname $gccdir]
98 verbose "gccdir $gccdir"
100 set ld_library_path "."
101 append ld_library_path ":${gccdir}"
103 set compiler "${gccdir}/xgcc"
104 if { [is_remote host] == 0 && [which $compiler] != 0 } {
105 foreach i "[exec $compiler --print-multi-lib]" {
107 regexp -- "\[a-z0-9=/\.-\]*;" $i mldir
108 set mldir [string trimright $mldir "\;@"]
109 if { "$mldir" == "." } {
112 if { [llength [glob -nocomplain ${gccdir}/${mldir}/libgcc_s*.so.*]] >= 1 } {
113 append ld_library_path ":${gccdir}/${mldir}"
117 # add the library path for libffi.
118 append ld_library_path ":${blddirffi}/.libs"
119 # add the library path for libstdc++ as well.
120 append ld_library_path ":${blddircxx}/src/.libs"
122 verbose "ld_library_path: $ld_library_path"
124 # Point to the Libffi headers in libffi.
125 set libffi_include "${blddirffi}/include"
126 verbose "libffi_include $libffi_include"
128 set libffi_dir "${blddirffi}/.libs"
129 verbose "libffi_dir $libffi_dir"
130 if { $libffi_dir != "" } {
131 set libffi_dir [file dirname ${libffi_dir}]
132 set libffi_link_flags "-L${libffi_dir}/.libs"
133 lappend libffi_link_flags "-L${blddircxx}/src/.libs"
136 set_ld_library_path_env_vars
137 libffi_maybe_build_wrapper "${objdir}/testglue.o"
140 proc libffi_exit { } {
143 if [info exists gluefile] {
144 file_on_build delete $gluefile;
149 proc libffi_target_compile { source dest type options } {
150 global gluefile wrap_flags;
154 global libffi_link_flags
155 global libffi_include
156 global target_triplet
159 if { [target_info needs_status_wrapper]!="" && [info exists gluefile] } {
160 lappend options "libs=${gluefile}"
161 lappend options "ldflags=$wrap_flags"
164 # TOOL_OPTIONS must come first, so that it doesn't override testcase
166 if [info exists TOOL_OPTIONS] {
167 lappend options [concat "additional_flags=$TOOL_OPTIONS" $options];
170 # search for ffi_mips.h in srcdir, too
171 lappend options "additional_flags=-I${libffi_include} -I${srcdir}/../include -I${libffi_include}/.."
172 lappend options "additional_flags=${libffi_link_flags}"
174 if { [string match "powerpc-*-darwin*" $target_triplet] } {
175 lappend options "libs= -lgcc_s"
178 lappend options "libs= -lffi"
180 verbose "options: $options"
181 return [target_compile $source $dest $type $options]
187 # search_for -- looks for a string match in a file
189 proc search_for { file pattern } {
190 set fd [open $file r]
191 while { [gets $fd cur_line]>=0 } {
192 if [string match "*$pattern*" $cur_line] then {
201 # Modified dg-runtest that can cycle through a list of optimization options
203 proc libffi-dg-runtest { testcases default-extra-flags } {
206 foreach test $testcases {
207 # If we're only testing specific files and this isn't one of
209 if ![runtest_file_p $runtests $test] {
213 # Look for a loop within the source code - if we don't find one,
214 # don't pass -funroll[-all]-loops.
215 global torture_with_loops torture_without_loops
216 if [expr [search_for $test "for*("]+[search_for $test "while*("]] {
217 set option_list $torture_with_loops
219 set option_list $torture_without_loops
222 set nshort [file tail [file dirname $test]]/[file tail $test]
224 foreach flags $option_list {
225 verbose "Testing $nshort, $flags" 1
226 dg-test $test $flags ${default-extra-flags}
232 # Like check_conditional_xfail, but callable from a dg test.
234 proc dg-xfail-if { args } {
235 set args [lreplace $args 0 0]
236 set selector "target [join [lindex $args 1]]"
237 if { [dg-process-target $selector] == "S" } {
238 global compiler_conditional_xfail_data
239 set compiler_conditional_xfail_data $args
244 # We need to make sure that additional_files and additional_sources
245 # are both cleared out after every test. It is not enough to clear
246 # them out *before* the next test run because gcc-target-compile gets
247 # run directly from some .exp files (outside of any test). (Those
248 # uses should eventually be eliminated.)
250 # Because the DG framework doesn't provide a hook that is run at the
251 # end of a test, we must replace dg-test with a wrapper.
253 if { [info procs saved-dg-test] == [list] } {
254 rename dg-test saved-dg-test
256 proc dg-test { args } {
257 global additional_files
258 global additional_sources
261 if { [ catch { eval saved-dg-test $args } errmsg ] } {
262 set saved_info $errorInfo
263 set additional_files ""
264 set additional_sources ""
265 error $errmsg $saved_info
267 set additional_files ""
268 set additional_sources ""