2003-12-26 Guilhem Lavaux <guilhem@kaffe.org>
[official-gcc.git] / libffi / testsuite / lib / libffi-dg.exp
blob95d09c17da6e414533d5b7d80e8a5a9930c52077
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 load_lib dg.exp
18 load_lib libgloss.exp
22 # Define libffi callbacks for dg.exp.
24 proc libffi-dg-test-1 { target_compile prog do_what extra_tool_flags } {
25 # Set up the compiler flags, based on what we're going to do.
27 set options [list]
28 switch $do_what {
29 "compile" {
30 set compile_type "assembly"
31 set output_file "[file rootname [file tail $prog]].s"
33 "link" {
34 set compile_type "executable"
35 set output_file "[file rootname [file tail $prog]].exe"
36 # The following line is needed for targets like the i960 where
37 # the default output file is b.out. Sigh.
39 "run" {
40 set compile_type "executable"
41 # FIXME: "./" is to cope with "." not being in $PATH.
42 # Should this be handled elsewhere?
43 # YES.
44 set output_file "./[file rootname [file tail $prog]].exe"
45 # This is the only place where we care if an executable was
46 # created or not. If it was, dg.exp will try to run it.
47 remote_file build delete $output_file;
49 default {
50 perror "$do_what: not a valid dg-do keyword"
51 return ""
55 if { $extra_tool_flags != "" } {
56 lappend options "additional_flags=$extra_tool_flags"
59 set comp_output [libffi_target_compile "$prog" "$output_file" "$compile_type" $options];
62 return [list $comp_output $output_file]
66 proc libffi-dg-test { prog do_what extra_tool_flags } {
67 return [libffi-dg-test-1 target_compile $prog $do_what $extra_tool_flags]
70 proc libffi-init { args } {
71 global gluefile wrap_flags;
72 global srcdir
73 global blddirffi
74 global blddircxx
75 global TOOL_OPTIONS
76 global ld_library_path
77 global libffi_include
78 global libffi_link_flags
79 global tool_root_dir
81 set blddirffi [lookfor_file [get_multilibs] libffi]
82 verbose "libffi $blddirffi"
83 set blddircxx [lookfor_file [get_multilibs] libstdc++-v3]
84 verbose "libstdc++ $blddircxx"
86 set gccdir [lookfor_file $tool_root_dir gcc/libgcc.a]
87 if {$gccdir != ""} {
88 set gccdir [file dirname $gccdir]
90 verbose "gccdir $gccdir"
92 set ld_library_path "."
93 append ld_library_path ":${gccdir}"
95 set compiler "${gccdir}/xgcc"
96 if { [is_remote host] == 0 && [which $compiler] != 0 } {
97 foreach i "[exec $compiler --print-multi-lib]" {
98 set mldir ""
99 regexp -- "\[a-z0-9=/\.-\]*;" $i mldir
100 set mldir [string trimright $mldir "\;@"]
101 if { "$mldir" == "." } {
102 continue
104 if { [llength [glob -nocomplain ${gccdir}/${mldir}/libgcc_s*.so.*]] == 1 } {
105 append ld_library_path ":${gccdir}/${mldir}"
109 # add the library path for libffi.
110 append ld_library_path ":${blddirffi}/.libs"
111 # add the library path for libstdc++ as well.
112 append ld_library_path ":${blddircxx}/src/.libs"
114 verbose "ld_library_path: $ld_library_path"
116 # Point to the Libffi headers in libffi.
117 set libffi_include "${blddirffi}/include"
118 verbose "libffi_include $libffi_include"
120 set libffi_dir "${blddirffi}/.libs"
121 verbose "libffi_dir $libffi_dir"
122 if { $libffi_dir != "" } {
123 set libffi_dir [file dirname ${libffi_dir}]
124 set libffi_link_flags "-L${libffi_dir}/.libs"
125 lappend libffi_link_flags "-L${blddircxx}/src/.libs"
128 # On IRIX 6, we have to set variables akin to LD_LIBRARY_PATH, but
129 # called LD_LIBRARYN32_PATH (for the N32 ABI) and LD_LIBRARY64_PATH
130 # (for the 64-bit ABI). The right way to do this would be to modify
131 # unix.exp -- but that's not an option since it's part of DejaGNU
132 # proper, so we do it here. We really only need to do
133 # this on IRIX, but it shouldn't hurt to do it anywhere else.
134 setenv LD_LIBRARY_PATH $ld_library_path
135 setenv SHLIB_PATH $ld_library_path
136 setenv LD_LIBRARYN32_PATH $ld_library_path
137 setenv LD_LIBRARY64_PATH $ld_library_path
138 setenv LD_LIBRARY_PATH_64 $ld_library_path
139 setenv DYLD_LIBRARY_PATH $ld_library_path
142 proc libffi_target_compile { source dest type options } {
143 global gluefile wrap_flags;
144 global srcdir
145 global blddirffi
146 global TOOL_OPTIONS
147 global ld_library_path
148 global libffi_link_flags
149 global libffi_include
150 global target_triplet
153 if { [target_info needs_status_wrapper]!="" && [info exists gluefile] } {
154 lappend options "libs=${gluefile}"
155 lappend options "ldflags=$wrap_flags"
158 # TOOL_OPTIONS must come first, so that it doesn't override testcase
159 # specific options.
160 if [info exists TOOL_OPTIONS] {
161 lappend options [concat "additional_flags=$TOOL_OPTIONS" $options];
164 # search for ffi_mips.h in srcdir, too
165 lappend options "additional_flags=-I${libffi_include} -I${srcdir}/../include -I${libffi_include}/.."
166 lappend options "additional_flags=${libffi_link_flags}"
168 if { [string match "powerpc-*-darwin*" $target_triplet] } {
169 lappend options "libs= -lgcc_s"
172 lappend options "libs= -lffi"
174 verbose "options: $options"
175 return [target_compile $source $dest $type $options]
178 # Utility routines.
181 # search_for -- looks for a string match in a file
183 proc search_for { file pattern } {
184 set fd [open $file r]
185 while { [gets $fd cur_line]>=0 } {
186 if [string match "*$pattern*" $cur_line] then {
187 close $fd
188 return 1
191 close $fd
192 return 0
195 # Modified dg-runtest that can cycle through a list of optimization options
196 # as c-torture does.
197 proc libffi-dg-runtest { testcases default-extra-flags } {
198 global runtests
200 foreach test $testcases {
201 # If we're only testing specific files and this isn't one of
202 # them, skip it.
203 if ![runtest_file_p $runtests $test] {
204 continue
207 # Look for a loop within the source code - if we don't find one,
208 # don't pass -funroll[-all]-loops.
209 global torture_with_loops torture_without_loops
210 if [expr [search_for $test "for*("]+[search_for $test "while*("]] {
211 set option_list $torture_with_loops
212 } else {
213 set option_list $torture_without_loops
216 set nshort [file tail [file dirname $test]]/[file tail $test]
218 foreach flags $option_list {
219 verbose "Testing $nshort, $flags" 1
220 dg-test $test $flags ${default-extra-flags}
226 # Like check_conditional_xfail, but callable from a dg test.
228 proc dg-xfail-if { args } {
229 set args [lreplace $args 0 0]
230 set selector "target [join [lindex $args 1]]"
231 if { [dg-process-target $selector] == "S" } {
232 global compiler_conditional_xfail_data
233 set compiler_conditional_xfail_data $args
238 # We need to make sure that additional_files and additional_sources
239 # are both cleared out after every test. It is not enough to clear
240 # them out *before* the next test run because gcc-target-compile gets
241 # run directly from some .exp files (outside of any test). (Those
242 # uses should eventually be eliminated.)
244 # Because the DG framework doesn't provide a hook that is run at the
245 # end of a test, we must replace dg-test with a wrapper.
247 if { [info procs saved-dg-test] == [list] } {
248 rename dg-test saved-dg-test
250 proc dg-test { args } {
251 global additional_files
252 global additional_sources
253 global errorInfo
255 if { [ catch { eval saved-dg-test $args } errmsg ] } {
256 set saved_info $errorInfo
257 set additional_files ""
258 set additional_sources ""
259 error $errmsg $saved_info
261 set additional_files ""
262 set additional_sources ""
266 # Local Variables:
267 # tcl-indent-level:4
268 # End: