]>
Commit | Line | Data |
---|---|---|
8d9254fc | 1 | # Copyright (C) 2017-2020 Free Software Foundation, Inc. |
b4c522fa IB |
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 GCC; see the file COPYING3. If not see | |
15 | # <http://www.gnu.org/licenses/>. | |
16 | ||
17 | # | |
18 | # DejaGnu does not have proper library search paths for load_lib. | |
19 | # We have to explicitly load everything that gdc.exp wants to load. | |
20 | # | |
21 | ||
22 | proc load_gcc_lib { filename } { | |
23 | global srcdir loaded_libs | |
24 | ||
25 | load_file $srcdir/../../gcc/testsuite/lib/$filename | |
26 | set loaded_libs($filename) "" | |
27 | } | |
28 | ||
29 | load_lib dg.exp | |
30 | load_lib libgloss.exp | |
31 | ||
32 | load_gcc_lib target-supports.exp | |
33 | load_gcc_lib target-supports-dg.exp | |
34 | load_gcc_lib dg-options.exp | |
35 | load_gcc_lib target-libpath.exp | |
36 | load_gcc_lib timeout.exp | |
37 | load_gcc_lib wrapper.exp | |
38 | load_gcc_lib target-utils.exp | |
39 | load_gcc_lib gcc-defs.exp | |
40 | ||
41 | set TESTING_IN_BUILD_TREE 1 | |
42 | ||
43 | # Define libphobos callbacks for dg.exp. | |
44 | ||
45 | proc libphobos-dg-test { prog do_what extra_tool_flags } { | |
46 | set compile_type "" | |
47 | set output_file "" | |
48 | ||
0d6aae24 | 49 | global libphobos_test_name |
540bc8a8 | 50 | upvar name name |
0d6aae24 | 51 | if { $libphobos_test_name != "" } { |
0d6aae24 IB |
52 | set name $libphobos_test_name |
53 | } | |
54 | ||
b4c522fa IB |
55 | # Set up the compiler flags, based on what we're going to do. |
56 | switch $do_what { | |
cc2cc3be RO |
57 | "run" { |
58 | set compile_type "executable" | |
59 | # FIXME: "./" is to cope with "." not being in $PATH. | |
60 | # Should this be handled elsewhere? | |
61 | # YES. | |
62 | set output_file "./[file rootname [file tail $prog]].exe" | |
63 | # This is the only place where we care if an executable was | |
64 | # created or not. If it was, dg.exp will try to run it. | |
65 | catch { remote_file build delete $output_file } | |
66 | } | |
67 | "link" { | |
68 | set compile_type "executable" | |
69 | set output_file "./[file rootname [file tail $prog]].exe" | |
70 | } | |
71 | default { | |
72 | perror "$do_what: not a valid dg-do keyword" | |
73 | return "" | |
74 | } | |
b4c522fa IB |
75 | } |
76 | ||
77 | set select_compile "libphobos_target_compile" | |
78 | set options "" | |
79 | if { $extra_tool_flags != "" } { | |
cc2cc3be | 80 | lappend options "additional_flags=$extra_tool_flags" |
b4c522fa IB |
81 | } |
82 | ||
540bc8a8 IB |
83 | set unsupported_message [libphobos_skipped_test_p $name] |
84 | if { $unsupported_message != "" } { | |
85 | return [list "::unsupported::$unsupported_message" $output_file] | |
86 | } | |
b4c522fa | 87 | |
540bc8a8 | 88 | set comp_output [$select_compile "$prog" "$output_file" "$compile_type" $options] |
b4c522fa IB |
89 | return [list $comp_output $output_file] |
90 | } | |
91 | ||
540bc8a8 IB |
92 | proc libphobos-dg-prune { system text } { |
93 | return $text | |
94 | } | |
95 | ||
b4c522fa IB |
96 | # |
97 | # libphobos_init | |
98 | # | |
99 | ||
100 | proc libphobos_init { args } { | |
101 | global env | |
102 | global srcdir blddir objdir tool_root_dir | |
103 | global exeext | |
104 | global gdc gdcflags | |
105 | global gdcpaths gdcldflags | |
106 | global gluefile wrap_flags | |
107 | global ld_library_path | |
108 | global DEFAULT_DFLAGS | |
109 | ||
110 | # If a testcase doesn't have special options, use these. | |
111 | if ![info exists DEFAULT_DFLAGS] then { | |
cc2cc3be | 112 | set DEFAULT_DFLAGS "" |
b4c522fa IB |
113 | } |
114 | ||
115 | # By default, we assume we want to run program images. | |
116 | global dg-do-what-default | |
117 | if [isnative] { | |
cc2cc3be | 118 | set dg-do-what-default "run" |
b4c522fa | 119 | } else { |
cc2cc3be | 120 | set dg-do-what-default "link" |
b4c522fa IB |
121 | } |
122 | ||
123 | # What arguments to pass to run program images. | |
124 | global libphobos_run_args | |
125 | set libphobos_run_args "" | |
126 | ||
0d6aae24 IB |
127 | # If the name of the test should be something else. |
128 | global libphobos_test_name | |
129 | set libphobos_test_name "" | |
130 | ||
540bc8a8 IB |
131 | global libphobos_skip_tests |
132 | set libphobos_skip_tests { } | |
133 | ||
b4c522fa IB |
134 | # Default settings. |
135 | set blddir [lookfor_file [get_multilibs] libphobos] | |
136 | set flags_file "${blddir}/testsuite/testsuite_flags" | |
137 | set shlib_ext [get_shlib_extension] | |
138 | ||
139 | set gdc [transform "gdc"] | |
140 | set gdcflags "-fmessage-length=0" | |
141 | set gdcpaths "-I${srcdir}" | |
142 | set gdcldflags "" | |
143 | ||
144 | if { [file exists $flags_file] } { | |
cc2cc3be RO |
145 | set gdc [exec sh $flags_file --gdc] |
146 | set gdcflags [exec sh $flags_file --gdcflags] | |
147 | set gdcpaths [exec sh $flags_file --gdcpaths] | |
148 | set gdcldflags [exec sh $flags_file --gdcldflags] | |
b4c522fa IB |
149 | } |
150 | ||
151 | set exeext "" | |
152 | if [info exists env(EXEEXT)] { | |
cc2cc3be | 153 | set exeext $env(EXEEXT) |
b4c522fa IB |
154 | } |
155 | ||
156 | # Compute what needs to be added to the existing LD_LIBRARY_PATH. | |
540bc8a8 | 157 | set ld_library_path "." |
b4c522fa IB |
158 | |
159 | set gccdir [lookfor_file $tool_root_dir gcc/libgcc.a] | |
160 | if {$gccdir != ""} { | |
cc2cc3be RO |
161 | set gccdir [file dirname $gccdir] |
162 | append ld_library_path ":${gccdir}" | |
b4c522fa IB |
163 | } |
164 | ||
165 | if { [file exists "${blddir}/libdruntime/.libs/libgdruntime.${shlib_ext}"] } { | |
cc2cc3be | 166 | append ld_library_path ":${blddir}/libdruntime/.libs" |
b4c522fa IB |
167 | } |
168 | ||
169 | if { [file exists "${blddir}/src/.libs/libgphobos.${shlib_ext}"] } { | |
cc2cc3be | 170 | append ld_library_path ":${blddir}/src/.libs" |
b4c522fa IB |
171 | } |
172 | ||
bca30736 BE |
173 | # Compute what needs to be added to the existing LD_LIBRARY_PATH. |
174 | if {$gccdir != ""} { | |
175 | set compiler ${gccdir}/gdc | |
176 | ||
177 | if { [is_remote host] == 0 && [which $compiler] != 0 } { | |
178 | foreach i "[exec $compiler --print-multi-lib]" { | |
179 | set mldir "" | |
180 | regexp -- "\[a-z0-9=_/\.-\]*;" $i mldir | |
181 | set mldir [string trimright $mldir "\;@"] | |
182 | if { "$mldir" == "." } { | |
183 | continue | |
184 | } | |
185 | if { [llength [glob -nocomplain ${gccdir}/${mldir}/libgcc_s*.so.*]] >= 1 } { | |
186 | append ld_library_path ":${gccdir}/${mldir}" | |
187 | } | |
188 | } | |
189 | } | |
190 | } | |
191 | ||
b4c522fa IB |
192 | set_ld_library_path_env_vars |
193 | ||
194 | libphobos_maybe_build_wrapper "${objdir}/testglue.o" | |
195 | } | |
196 | ||
197 | # | |
198 | # libphobos_target_compile -- compile a source file. | |
199 | # | |
200 | ||
201 | proc libphobos_target_compile { source dest type options } { | |
202 | global gdc gdcflags | |
203 | global gdcpaths gdcldflags | |
204 | global gluefile wrap_flags | |
205 | ||
206 | lappend options "additional_flags=-fno-diagnostics-show-caret -fdiagnostics-color=never" | |
207 | ||
208 | if { [target_info needs_status_wrapper] != "" && [info exists gluefile] } { | |
cc2cc3be RO |
209 | lappend options "libs=${gluefile}" |
210 | lappend options "ldflags=${wrap_flags}" | |
b4c522fa IB |
211 | } |
212 | ||
213 | # Flag setting based on type argument. | |
214 | if { $type == "executable" } { | |
cc2cc3be RO |
215 | # Link the support objects into executables. |
216 | lappend options "additional_flags=$gdcldflags" | |
b4c522fa IB |
217 | } |
218 | ||
219 | # Set the compiler, only add D flags and paths if building D sources. | |
220 | set gdc_final $gdc | |
221 | if [regexp ".*\.d\$" $source] { | |
cc2cc3be RO |
222 | set gdc_final [concat $gdc_final $gdcflags] |
223 | set gdc_final [concat $gdc_final $gdcpaths] | |
b4c522fa IB |
224 | } |
225 | ||
226 | lappend options "compiler=$gdc_final" | |
227 | lappend options "timeout=[timeout_value]" | |
228 | ||
229 | set options [dg-additional-files-options $options $source] | |
230 | set comp_output [target_compile $source $dest $type $options] | |
231 | ||
232 | return $comp_output | |
233 | } | |
0d6aae24 IB |
234 | |
235 | # | |
236 | # Helper used by libphobos and libdruntime unittest runner, filters out | |
237 | # D sources that may contain a unittest function. | |
238 | # | |
239 | ||
240 | proc filter_libphobos_unittests { list } { | |
241 | set res {} | |
242 | foreach filename $list { | |
243 | set fid [open $filename r] | |
244 | if [regexp -- {unittest} [read $fid [file size $filename]]] { | |
245 | lappend res $filename | |
246 | } | |
247 | close $fid | |
248 | } | |
249 | return $res | |
250 | } | |
540bc8a8 IB |
251 | |
252 | # Skip the unittest (report it as UNSUPPORTED) if the module exists in | |
253 | # libphobos_skip_tests and its target list is matched by dg-process-target. | |
254 | # | |
255 | # The expected format of the libphobos_skip_tests file is: | |
256 | # { test { targets } } | |
257 | proc libphobos_skipped_test_p { test } { | |
258 | global libphobos_skip_tests | |
259 | ||
260 | set row [lsearch -inline -index 0 $libphobos_skip_tests $test] | |
261 | if { $row eq "" } { | |
262 | return "" | |
263 | } | |
264 | ||
265 | if { [llength $row] != 2 } { | |
266 | error "syntax error in libphobos_skip_tests: $row" | |
267 | } | |
268 | ||
269 | set selector [list target [lindex $row 1]] | |
270 | if { [dg-process-target-1 $selector] != "S" } { | |
271 | return "" | |
272 | } | |
273 | ||
274 | return "skipped test" | |
275 | } | |
276 | ||
277 | # Return true if the curl library is supported on the target. | |
278 | proc check_effective_target_libcurl_available { } { | |
279 | return [check_no_compiler_messages libcurl_available executable { | |
280 | int main (void) { return 0; } | |
281 | } "-lcurl"] | |
282 | } | |
58990c4d IB |
283 | |
284 | # Return true if the target is linux version < 2.6.39 | |
285 | proc check_effective_target_linux_pre_2639 { } { | |
286 | if { ![istarget *-*-linux*] } { | |
287 | return 0 | |
288 | } | |
289 | ||
290 | if { [check_no_compiler_messages linux_pre_2639 assembly { | |
291 | #include <linux/version.h> | |
292 | #if !defined LINUX_VERSION_CODE || LINUX_VERSION_CODE < KERNEL_VERSION(2.6.39) | |
293 | #error Yes, it is. | |
294 | #endif | |
295 | }] } { | |
296 | return 0 | |
297 | } | |
298 | return 1 | |
299 | } |