OSDN Git Service

fortran/
[pf3gnuchains/gcc-fork.git] / libffi / testsuite / lib / libffi-dg.exp
1 #   Copyright (C) 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 proc load_gcc_lib { filename } {
18     global srcdir
19     load_file $srcdir/../../gcc/testsuite/lib/$filename
20 }
21
22 load_lib dg.exp
23 load_lib libgloss.exp
24 load_gcc_lib target-libpath.exp
25 load_gcc_lib wrapper.exp
26
27
28 # Define libffi callbacks for dg.exp.
29
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.
32
33     set options [list]
34     switch $do_what {
35         "compile" {
36             set compile_type "assembly"
37             set output_file "[file rootname [file tail $prog]].s"
38         }
39         "link" {
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.
44         }
45         "run" {
46             set compile_type "executable"
47             # FIXME: "./" is to cope with "." not being in $PATH.
48             # Should this be handled elsewhere?
49             # YES.
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;
54         }
55         default {
56             perror "$do_what: not a valid dg-do keyword"
57             return ""
58         }
59     }
60
61     if { $extra_tool_flags != "" } {
62         lappend options "additional_flags=$extra_tool_flags"
63     }
64
65     set comp_output [libffi_target_compile "$prog" "$output_file" "$compile_type" $options];
66
67
68     return [list $comp_output $output_file]
69 }
70
71
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]
74 }
75
76 proc libffi-init { args } {
77     global gluefile wrap_flags;
78     global srcdir
79     global blddirffi
80     global objdir
81     global blddircxx
82     global TOOL_OPTIONS
83     global tool
84     global libffi_include
85     global libffi_link_flags
86     global tool_root_dir
87     global ld_library_path
88
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"
93
94     set gccdir [lookfor_file $tool_root_dir gcc/libgcc.a]
95     if {$gccdir != ""} {
96         set gccdir [file dirname $gccdir]
97     }
98     verbose "gccdir $gccdir"
99
100     set ld_library_path "."
101     append ld_library_path ":${gccdir}"
102
103     set compiler "${gccdir}/xgcc"
104     if { [is_remote host] == 0 && [which $compiler] != 0 } {
105         foreach i "[exec $compiler --print-multi-lib]" {
106             set mldir ""
107             regexp -- "\[a-z0-9=/\.-\]*;" $i mldir
108             set mldir [string trimright $mldir "\;@"]
109             if { "$mldir" == "." } {
110                 continue
111             }
112             if { [llength [glob -nocomplain ${gccdir}/${mldir}/libgcc_s*.so.*]] >= 1 } {
113                 append ld_library_path ":${gccdir}/${mldir}"
114             }
115         }
116     }
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"
121
122     verbose "ld_library_path: $ld_library_path"
123
124     # Point to the Libffi headers in libffi.
125     set libffi_include "${blddirffi}/include"
126     verbose "libffi_include $libffi_include"
127
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"
134     }
135
136     set_ld_library_path_env_vars
137     libffi_maybe_build_wrapper "${objdir}/testglue.o"
138 }
139
140 proc libffi_exit { } {
141     global gluefile;
142
143     if [info exists gluefile] {
144         file_on_build delete $gluefile;
145         unset gluefile;
146     }
147 }
148
149 proc libffi_target_compile { source dest type options } {
150     global gluefile wrap_flags;
151     global srcdir
152     global blddirffi
153     global TOOL_OPTIONS
154     global libffi_link_flags
155     global libffi_include
156     global target_triplet
157
158
159     if { [target_info needs_status_wrapper]!="" && [info exists gluefile] } {
160         lappend options "libs=${gluefile}"
161         lappend options "ldflags=$wrap_flags"
162     }
163
164     # TOOL_OPTIONS must come first, so that it doesn't override testcase
165     # specific options.
166     if [info exists TOOL_OPTIONS] {
167         lappend  options [concat "additional_flags=$TOOL_OPTIONS" $options];
168     }
169
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}"
173
174     if { [string match "powerpc-*-darwin*" $target_triplet] } {
175         lappend options "libs= -lgcc_s"
176     }
177
178     lappend options "libs= -lffi"
179
180     verbose "options: $options"
181     return [target_compile $source $dest $type $options]
182 }
183
184 # Utility routines.
185
186 #
187 # search_for -- looks for a string match in a file
188 #
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 {
193             close $fd
194             return 1
195         }
196     }
197     close $fd
198     return 0
199 }
200
201 # Modified dg-runtest that can cycle through a list of optimization options
202 # as c-torture does.
203 proc libffi-dg-runtest { testcases default-extra-flags } {
204     global runtests
205
206     foreach test $testcases {
207         # If we're only testing specific files and this isn't one of
208         # them, skip it.
209         if ![runtest_file_p $runtests $test] {
210             continue
211         }
212
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
218         } else {
219             set option_list $torture_without_loops
220         }
221
222         set nshort [file tail [file dirname $test]]/[file tail $test]
223
224         foreach flags $option_list {
225             verbose "Testing $nshort, $flags" 1
226             dg-test $test $flags ${default-extra-flags}
227         }
228     }
229 }
230
231
232 # Like check_conditional_xfail, but callable from a dg test.
233
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
240     }
241 }
242
243
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.)
249
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.
252
253 if { [info procs saved-dg-test] == [list] } {
254     rename dg-test saved-dg-test
255
256     proc dg-test { args } {
257         global additional_files
258         global additional_sources
259         global errorInfo
260
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
266         }
267         set additional_files ""
268         set additional_sources ""
269     }
270 }
271
272 # Local Variables:
273 # tcl-indent-level:4
274 # End: