1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
|
# Copyright (C) 2017-2023 Free Software Foundation, Inc.
# This program is free software; you can redistribute it and/or modify
# it under the terms of the GNU General Public License as published by
# the Free Software Foundation; either version 3 of the License, or
# (at your option) any later version.
#
# This program is distributed in the hope that it will be useful,
# but WITHOUT ANY WARRANTY; without even the implied warranty of
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
# GNU General Public License for more details.
#
# You should have received a copy of the GNU General Public License
# along with GCC; see the file COPYING3. If not see
# <http://www.gnu.org/licenses/>.
#
# DejaGnu does not have proper library search paths for load_lib.
# We have to explicitly load everything that gdc.exp wants to load.
#
proc load_gcc_lib { filename } {
global srcdir loaded_libs
load_file $srcdir/../../gcc/testsuite/lib/$filename
set loaded_libs($filename) ""
}
load_lib dg.exp
load_lib libgloss.exp
load_gcc_lib target-supports.exp
load_gcc_lib target-supports-dg.exp
load_gcc_lib dg-options.exp
load_gcc_lib target-libpath.exp
load_gcc_lib timeout.exp
load_gcc_lib wrapper.exp
load_gcc_lib target-utils.exp
load_gcc_lib gcc-defs.exp
set TESTING_IN_BUILD_TREE 1
# Define libphobos callbacks for dg.exp.
proc libphobos-dg-test { prog do_what extra_tool_flags } {
set compile_type ""
set output_file ""
global libphobos_test_name
upvar name name
if { $libphobos_test_name != "" } {
set name $libphobos_test_name
}
# Set up the compiler flags, based on what we're going to do.
switch $do_what {
"compile" {
set compile_type "assembly"
set output_file "[file rootname [file tail $prog]].s"
}
"run" {
set compile_type "executable"
# FIXME: "./" is to cope with "." not being in $PATH.
# Should this be handled elsewhere?
# YES.
set output_file "./[file rootname [file tail $prog]].exe"
# This is the only place where we care if an executable was
# created or not. If it was, dg.exp will try to run it.
catch { remote_file build delete $output_file }
}
"link" {
set compile_type "executable"
set output_file "./[file rootname [file tail $prog]].exe"
}
default {
perror "$do_what: not a valid dg-do keyword"
return ""
}
}
set select_compile "libphobos_target_compile"
set options ""
if { $extra_tool_flags != "" } {
lappend options "additional_flags=$extra_tool_flags"
}
set unsupported_message [libphobos_skipped_test_p $name]
if { $unsupported_message != "" } {
return [list "::unsupported::$unsupported_message" $output_file]
}
set comp_output [$select_compile "$prog" "$output_file" "$compile_type" $options]
return [list $comp_output $output_file]
}
# Override the DejaGnu dg-test in order to clear flags after a test, as
# is done for compiler tests in gcc-dg.exp.
if { [info procs saved-dg-test] == [list] } {
rename dg-test saved-dg-test
proc dg-test { args } {
global additional_prunes
global errorInfo
global testname_with_flags
global shouldfail
if { [ catch { eval saved-dg-test $args } errmsg ] } {
set saved_info $errorInfo
set additional_prunes ""
set shouldfail 0
if [info exists testname_with_flags] {
unset testname_with_flags
}
unset_timeout_vars
error $errmsg $saved_info
}
set additional_prunes ""
set shouldfail 0
unset_timeout_vars
if [info exists testname_with_flags] {
unset testname_with_flags
}
}
}
# Prune messages from gdc that aren't useful.
set additional_prunes ""
proc libphobos-dg-prune { system text } {
global additional_prunes
foreach p $additional_prunes {
if { [string length $p] > 0 } {
# Following regexp matches a complete line containing $p.
regsub -all "(^|\n)\[^\n\]*$p\[^\n\]*" $text "" text
}
}
# Ignore harmless warnings from Xcode.
regsub -all "(^|\n)\[^\n\]*ld: warning: could not create compact unwind for\[^\n\]*" $text "" text
# Ignore dsymutil warning (tool bug is actually linker)
regsub -all "(^|\n)\[^\n\]*could not find object file symbol for symbol\[^\n\]*" $text "" text
return $text
}
#
# libphobos_init
#
proc libphobos_init { args } {
global env
global srcdir blddir objdir tool_root_dir
global exeext
global gdc gdcflags
global gdcpaths gdcldflags
global gluefile wrap_flags
global ld_library_path
global tool_timeout
global DEFAULT_DFLAGS
# If a testcase doesn't have special options, use these.
if ![info exists DEFAULT_DFLAGS] then {
set DEFAULT_DFLAGS ""
}
# By default, we assume we want to run program images.
global dg-do-what-default
if [isnative] {
set dg-do-what-default "run"
} else {
set dg-do-what-default "link"
}
# What arguments to pass to run program images.
global libphobos_run_args
set libphobos_run_args ""
# If the name of the test should be something else.
global libphobos_test_name
set libphobos_test_name ""
global libphobos_skip_tests
set libphobos_skip_tests { }
# Default settings.
set blddir [lookfor_file [get_multilibs] libphobos]
set flags_file "${blddir}/testsuite/testsuite_flags"
set shlib_ext [get_shlib_extension]
set gdc [transform "gdc"]
set gdcflags "-fmessage-length=0"
set gdcpaths "-I${srcdir}"
set gdcldflags ""
if { [file exists $flags_file] } {
set gdc [exec sh $flags_file --gdc]
set gdcflags [exec sh $flags_file --gdcflags]
set gdcpaths [exec sh $flags_file --gdcpaths]
set gdcldflags [exec sh $flags_file --gdcldflags]
}
set exeext ""
if [info exists env(EXEEXT)] {
set exeext $env(EXEEXT)
}
# Compute what needs to be added to the existing LD_LIBRARY_PATH.
set ld_library_path "."
set gccdir [lookfor_file $tool_root_dir gcc/libgcc.a]
if {$gccdir != ""} {
set gccdir [file dirname $gccdir]
append ld_library_path ":${gccdir}"
}
if { [file exists "${blddir}/src/.libs/libgphobos.${shlib_ext}"] } {
append ld_library_path ":${blddir}/src/.libs"
}
# Compute what needs to be added to the existing LD_LIBRARY_PATH.
if {$gccdir != ""} {
set compiler ${gccdir}/gdc
if { [is_remote host] == 0 && [which $compiler] != 0 } {
foreach i "[exec $compiler --print-multi-lib]" {
set mldir ""
regexp -- "\[a-z0-9=_/\.-\]*;" $i mldir
set mldir [string trimright $mldir "\;@"]
if { "$mldir" == "." } {
continue
}
if { [llength [glob -nocomplain ${gccdir}/${mldir}/libgcc_s*.so.*]] >= 1 } {
append ld_library_path ":${gccdir}/${mldir}"
}
}
}
}
# Set the default timeout for phobos tests.
set tool_timeout 600
set_ld_library_path_env_vars
libphobos_maybe_build_wrapper "${objdir}/testglue.o"
}
#
# libphobos_target_compile -- compile a source file.
#
proc libphobos_target_compile { source dest type options } {
global gdc gdcflags
global gdcpaths gdcldflags
global gluefile wrap_flags
lappend options "additional_flags=-fno-diagnostics-show-caret -fdiagnostics-color=never"
if { [target_info needs_status_wrapper] != "" && [info exists gluefile] } {
lappend options "libs=${gluefile}"
lappend options "ldflags=${wrap_flags}"
}
# Flag setting based on type argument.
if { $type == "executable" } {
# Link the support objects into executables.
lappend options "additional_flags=$gdcldflags"
}
# Set the compiler, only add D flags and paths if building D sources.
set gdc_final $gdc
if [regexp ".*\.d\$" $source] {
set gdc_final [concat $gdc_final $gdcflags]
set gdc_final [concat $gdc_final $gdcpaths]
}
lappend options "compiler=$gdc_final"
lappend options "timeout=[timeout_value]"
set options [dg-additional-files-options $options $source]
set comp_output [target_compile $source $dest $type $options]
return $comp_output
}
#
# Helper used by libphobos and libdruntime unittest runner, filters out
# D sources that may contain a unittest function.
#
proc filter_libphobos_unittests { list } {
set res {}
foreach filename $list {
set fid [open $filename r]
if [regexp -- {unittest} [read $fid [file size $filename]]] {
lappend res $filename
}
close $fid
}
return $res
}
# Skip the unittest (report it as UNSUPPORTED) if the module exists in
# libphobos_skip_tests and its target list is matched by dg-process-target.
#
# The expected format of the libphobos_skip_tests file is:
# { test { targets } }
proc libphobos_skipped_test_p { test } {
global libphobos_skip_tests
set row [lsearch -inline -index 0 $libphobos_skip_tests $test]
if { $row eq "" } {
return ""
}
if { [llength $row] != 2 } {
error "syntax error in libphobos_skip_tests: $row"
}
set selector [list target [lindex $row 1]]
if { [dg-process-target-1 $selector] != "S" } {
return ""
}
return "skipped test"
}
# Prune any messages matching ARGS[1] (a regexp) from test output.
proc dg-prune-output { args } {
global additional_prunes
if { [llength $args] != 2 } {
error "[lindex $args 1]: need one argument"
return
}
lappend additional_prunes [lindex $args 1]
}
# Return true if the curl library is supported on the target.
proc check_effective_target_libcurl_available { } {
return [check_no_compiler_messages libcurl_available executable {
int main (void) { return 0; }
} "-lcurl"]
}
# Return true if the target is linux version < 2.6.39
proc check_effective_target_linux_pre_2639 { } {
if { ![istarget *-*-linux*] } {
return 0
}
if { [check_no_compiler_messages linux_pre_2639 assembly {
#include <linux/version.h>
#if !defined LINUX_VERSION_CODE || LINUX_VERSION_CODE < KERNEL_VERSION(2,6,39)
#error Yes, it is.
#endif
}] } {
return 0
}
return 1
}
|