1 # Copyright (C) 2017-2023 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 3 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 GCC; see the file COPYING3. If not see
15 # <http://www.gnu.org/licenses/>.
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.
22 proc load_gcc_lib { filename } {
23 global srcdir loaded_libs
25 load_file $srcdir/../../gcc/testsuite/lib/$filename
26 set loaded_libs($filename) ""
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
41 set TESTING_IN_BUILD_TREE 1
43 # Define libphobos callbacks for dg.exp.
45 proc libphobos-dg-test { prog do_what extra_tool_flags } {
49 global libphobos_test_name
51 if { $libphobos_test_name != "" } {
52 set name $libphobos_test_name
55 # Set up the compiler flags, based on what we're going to do.
58 set compile_type "assembly"
59 set output_file "[file rootname [file tail $prog]].s"
62 set compile_type "executable"
63 # FIXME: "./" is to cope with "." not being in $PATH.
64 # Should this be handled elsewhere?
66 set output_file "./[file rootname [file tail $prog]].exe"
67 # This is the only place where we care if an executable was
68 # created or not. If it was, dg.exp will try to run it.
69 catch { remote_file build delete $output_file }
72 set compile_type "executable"
73 set output_file "./[file rootname [file tail $prog]].exe"
76 perror "$do_what: not a valid dg-do keyword"
81 set select_compile "libphobos_target_compile"
83 if { $extra_tool_flags != "" } {
84 lappend options "additional_flags=$extra_tool_flags"
87 set unsupported_message [libphobos_skipped_test_p $name]
88 if { $unsupported_message != "" } {
89 return [list "::unsupported::$unsupported_message" $output_file]
92 set comp_output [$select_compile "$prog" "$output_file" "$compile_type" $options]
93 return [list $comp_output $output_file]
96 # Override the DejaGnu dg-test in order to clear flags after a test, as
97 # is done for compiler tests in gcc-dg.exp.
99 if { [info procs saved-dg-test] == [list] } {
100 rename dg-test saved-dg-test
102 proc dg-test { args } {
103 global additional_prunes
105 global testname_with_flags
108 if { [ catch { eval saved-dg-test $args } errmsg ] } {
109 set saved_info $errorInfo
110 set additional_prunes ""
112 if [info exists testname_with_flags] {
113 unset testname_with_flags
116 error $errmsg $saved_info
118 set additional_prunes ""
121 if [info exists testname_with_flags] {
122 unset testname_with_flags
127 # Prune messages from gdc that aren't useful.
129 set additional_prunes ""
131 proc libphobos-dg-prune { system text } {
133 global additional_prunes
135 foreach p $additional_prunes {
136 if { [string length $p] > 0 } {
137 # Following regexp matches a complete line containing $p.
138 regsub -all "(^|\n)\[^\n\]*$p\[^\n\]*" $text "" text
142 # Ignore harmless warnings from Xcode.
143 regsub -all "(^|\n)\[^\n\]*ld: warning: could not create compact unwind for\[^\n\]*" $text "" text
145 # Ignore dsymutil warning (tool bug is actually linker)
146 regsub -all "(^|\n)\[^\n\]*could not find object file symbol for symbol\[^\n\]*" $text "" text
155 proc libphobos_init { args } {
157 global srcdir blddir objdir tool_root_dir
160 global gdcpaths gdcldflags
161 global gluefile wrap_flags
162 global ld_library_path
164 global DEFAULT_DFLAGS
166 # If a testcase doesn't have special options, use these.
167 if ![info exists DEFAULT_DFLAGS] then {
168 set DEFAULT_DFLAGS ""
171 # By default, we assume we want to run program images.
172 global dg-do-what-default
174 set dg-do-what-default "run"
176 set dg-do-what-default "link"
179 # What arguments to pass to run program images.
180 global libphobos_run_args
181 set libphobos_run_args ""
183 # If the name of the test should be something else.
184 global libphobos_test_name
185 set libphobos_test_name ""
187 global libphobos_skip_tests
188 set libphobos_skip_tests { }
191 set blddir [lookfor_file [get_multilibs] libphobos]
192 set flags_file "${blddir}/testsuite/testsuite_flags"
193 set shlib_ext [get_shlib_extension]
195 set gdc [transform "gdc"]
196 set gdcflags "-fmessage-length=0"
197 set gdcpaths "-I${srcdir}"
200 if { [file exists $flags_file] } {
201 set gdc [exec sh $flags_file --gdc]
202 set gdcflags [exec sh $flags_file --gdcflags]
203 set gdcpaths [exec sh $flags_file --gdcpaths]
204 set gdcldflags [exec sh $flags_file --gdcldflags]
208 if [info exists env(EXEEXT)] {
209 set exeext $env(EXEEXT)
212 # Compute what needs to be added to the existing LD_LIBRARY_PATH.
213 set ld_library_path "."
215 set gccdir [lookfor_file $tool_root_dir gcc/libgcc.a]
217 set gccdir [file dirname $gccdir]
218 append ld_library_path ":${gccdir}"
221 if { [file exists "${blddir}/src/.libs/libgphobos.${shlib_ext}"] } {
222 append ld_library_path ":${blddir}/src/.libs"
225 # Compute what needs to be added to the existing LD_LIBRARY_PATH.
227 set compiler ${gccdir}/gdc
229 if { [is_remote host] == 0 && [which $compiler] != 0 } {
230 foreach i "[exec $compiler --print-multi-lib]" {
232 regexp -- "\[a-z0-9=_/\.-\]*;" $i mldir
233 set mldir [string trimright $mldir "\;@"]
234 if { "$mldir" == "." } {
237 if { [llength [glob -nocomplain ${gccdir}/${mldir}/libgcc_s*.so.*]] >= 1 } {
238 append ld_library_path ":${gccdir}/${mldir}"
244 # Set the default timeout for phobos tests.
247 set_ld_library_path_env_vars
249 libphobos_maybe_build_wrapper "${objdir}/testglue.o"
253 # libphobos_target_compile -- compile a source file.
256 proc libphobos_target_compile { source dest type options } {
258 global gdcpaths gdcldflags
259 global gluefile wrap_flags
261 lappend options "additional_flags=-fno-diagnostics-show-caret -fdiagnostics-color=never"
263 if { [target_info needs_status_wrapper] != "" && [info exists gluefile] } {
264 lappend options "libs=${gluefile}"
265 lappend options "ldflags=${wrap_flags}"
268 # Flag setting based on type argument.
269 if { $type == "executable" } {
270 # Link the support objects into executables.
271 lappend options "additional_flags=$gdcldflags"
274 # Set the compiler, only add D flags and paths if building D sources.
276 if [regexp ".*\.d\$" $source] {
277 set gdc_final [concat $gdc_final $gdcflags]
278 set gdc_final [concat $gdc_final $gdcpaths]
281 lappend options "compiler=$gdc_final"
282 lappend options "timeout=[timeout_value]"
284 set options [dg-additional-files-options $options $source]
285 set comp_output [target_compile $source $dest $type $options]
291 # Helper used by libphobos and libdruntime unittest runner, filters out
292 # D sources that may contain a unittest function.
295 proc filter_libphobos_unittests { list } {
297 foreach filename $list {
298 set fid [open $filename r]
299 if [regexp -- {unittest} [read $fid [file size $filename]]] {
300 lappend res $filename
307 # Skip the unittest (report it as UNSUPPORTED) if the module exists in
308 # libphobos_skip_tests and its target list is matched by dg-process-target.
310 # The expected format of the libphobos_skip_tests file is:
311 # { test { targets } }
312 proc libphobos_skipped_test_p { test } {
313 global libphobos_skip_tests
315 set row [lsearch -inline -index 0 $libphobos_skip_tests $test]
320 if { [llength $row] != 2 } {
321 error "syntax error in libphobos_skip_tests: $row"
324 set selector [list target [lindex $row 1]]
325 if { [dg-process-target-1 $selector] != "S" } {
329 return "skipped test"
332 # Prune any messages matching ARGS[1] (a regexp) from test output.
333 proc dg-prune-output { args } {
334 global additional_prunes
336 if { [llength $args] != 2 } {
337 error "[lindex $args 1]: need one argument"
341 lappend additional_prunes [lindex $args 1]
344 # Return true if the curl library is supported on the target.
345 proc check_effective_target_libcurl_available { } {
346 return [check_no_compiler_messages libcurl_available executable {
347 int main (void) { return 0; }
351 # Return true if the target is linux version < 2.6.39
352 proc check_effective_target_linux_pre_2639 { } {
353 if { ![istarget *-*-linux*] } {
357 if { [check_no_compiler_messages linux_pre_2639 assembly {
358 #include <linux/version.h>
359 #if !defined LINUX_VERSION_CODE || LINUX_VERSION_CODE < KERNEL_VERSION(2,6,39)