OSDN Git Service

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