]> git.ipfire.org Git - thirdparty/gcc.git/blame - libstdc++-v3/testsuite/lib/libstdc++.exp
Add parallel mode.
[thirdparty/gcc.git] / libstdc++-v3 / testsuite / lib / libstdc++.exp
CommitLineData
23834577 1# libstdc++ "tool init file" for DejaGNU
2cb1c928 2
9e451553 3# Copyright (C) 2001, 2002, 2003, 2004, 2005, 2006, 2007
0ded1615 4# Free Software Foundation, Inc.
23834577 5#
b3f2a032
PE
6# This program is free software; you can redistribute it and/or modify
7# it under the terms of the GNU General Public License as published by
8# the Free Software Foundation; either version 2 of the License, or
9# (at your option) any later version.
10#
11# This program is distributed in the hope that it will be useful,
12# but WITHOUT ANY WARRANTY; without even the implied warranty of
13# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
14# GNU General Public License for more details.
15#
16# You should have received a copy of the GNU General Public License
17# along with this program; if not, write to the Free Software
2f9f6cef
BK
18# Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA
19# 02110-1301, USA.
2cb1c928 20
b3f2a032 21
23834577
PE
22# Define callbacks and load other libraries. This file is loaded relatively
23# early, and before any other file we write ourselves. "load_lib" will
24# find anything in the DejaGNU installation tree, or in our lib directory.
25# "load_gcc_lib" will search the core compiler's .exp collection instead.
26#
27# The naming rule is that dg.exp looks for "tool-" and runtest.exp looks
28# for "tool_" when finding callbacks. Utility routines we define for
29# our callbacks begin with "v3-".
30#
31# libstdc++_* callbacks we don't define, but could:
32# ..._option_help prints additional --help output
33# ..._option_proc (--foo) process our own options
23834577
PE
34# ..._init (normal.exp) called once per test file
35# ..._finish bracketing function for libstdc++_init
36# ...-dg-prune removing output text, see top of system dg.exp
37#
38# Useful hook: if ${hostname}_init exists, it will be called, almost
39# the last thing before testing begins. This can be defined in, e.g.,
40# ~/.dejagnurc or $DEJAGNU.
41
42proc load_gcc_lib { filename } {
43 global srcdir
44 load_file $srcdir/../../gcc/testsuite/lib/$filename
45}
46
47# system routines
b3f2a032
PE
48load_lib dg.exp
49load_lib libgloss.exp
23834577 50# compiler routines, then ours
58adf39c 51load_gcc_lib target-supports.exp
75d1ddc1 52load_gcc_lib target-supports-dg.exp
b3f2a032 53load_lib prune.exp
23834577 54load_lib dg-options.exp
1df8e834 55load_gcc_lib target-libpath.exp
90c609e5 56load_gcc_lib wrapper.exp
23834577
PE
57
58# Useful for debugging. Pass the name of a variable and the verbosity
59# threshold (number of -v's on the command line).
60proc v3track { var n } {
61 upvar $var val
62 verbose "++ $var is $val" $n
63}
b3f2a032 64
caf21254 65# Called by v3-init below. "Static" to this file.
d8fe7b29 66proc v3-copy-files {srcfiles} {
b3f2a032 67 foreach f $srcfiles {
caf21254 68 if { [catch { set symlink [file readlink $f] } x] } then {
d8fe7b29 69 remote_download target $f
caf21254
PE
70 } else {
71 if { [regexp "^/" "$symlink"] } then {
d8fe7b29 72 remote_download target $symlink
caf21254
PE
73 } else {
74 set dirname [file dirname $f]
d8fe7b29 75 remote_download target $dirname/$symlink
caf21254
PE
76 }
77 }
b3f2a032
PE
78 }
79}
80
23834577
PE
81# Called once, during runtest.exp setup.
82proc libstdc++_init { testfile } {
83 global env
2f9f6cef 84 global v3-sharedlib
d8fe7b29 85 global srcdir blddir objdir tool_root_dir
6c1e7e26 86 global cc cxx cxxflags cxxldflags
b3f2a032 87 global includes
b3f2a032 88 global gluefile wrap_flags
1df8e834 89 global ld_library_path
23834577 90 global target_triplet
5f90c88f 91 global flags_file
b3f2a032 92
5305b1ae
BK
93 # We set LC_ALL and LANG to C so that we get the same error
94 # messages as expected.
690e11b8
AP
95 setenv LC_ALL C
96 setenv LANG C
97
b3f2a032 98 set blddir [lookfor_file [get_multilibs] libstdc++-v3]
23834577
PE
99 set flags_file "${blddir}/scripts/testsuite_flags"
100 v3track flags_file 2
101
102 # If a test doesn't have special options, use DEFAULT_CXXFLAGS.
103 # Use this variable if the behavior
104 # 1) only applies to libstdc++ testing
105 # 2) might need to be negated
106 # In particular, some tests have to be run without precompiled
107 # headers, or without assertions.
108 global DEFAULT_CXXFLAGS
109 if ![info exists DEFAULT_CXXFLAGS] then {
8b60fb43 110 set DEFAULT_CXXFLAGS ""
23834577
PE
111 # Host specific goo here.
112 if { [string match "powerpc-*-darwin*" $target_triplet] } {
113 append DEFAULT_CXXFLAGS " -multiply_defined suppress"
114 }
115 }
116 v3track DEFAULT_CXXFLAGS 2
b3f2a032
PE
117
118 # By default, we assume we want to run program images.
119 global dg-do-what-default
120 set dg-do-what-default run
121
122 # Copy any required data files.
d8fe7b29
DJ
123 v3-copy-files [glob -nocomplain "$srcdir/data/*.tst"]
124 v3-copy-files [glob -nocomplain "$srcdir/data/*.txt"]
b3f2a032 125
645112dd 126 # Locate libgcc.a so we don't need to account for different values of
b3f2a032
PE
127 # SHLIB_EXT on different platforms
128 set gccdir [lookfor_file $tool_root_dir gcc/libgcc.a]
129 if {$gccdir != ""} {
caf21254 130 set gccdir [file dirname $gccdir]
b3f2a032 131 }
23834577 132 v3track gccdir 3
b3f2a032 133
2f9f6cef
BK
134 # Look for shared library. (ie libstdc++.so.)
135 set v3-sharedlib 0
136 set sharedlibdir [lookfor_file $blddir src/.libs/libstdc++.so]
137 if {$sharedlibdir != ""} {
f05c19d1 138 if { [string match "*-*-linux*" $target_triplet] && [isnative] } {
f81ab296
BK
139 set v3-sharedlib 1
140 verbose -log "shared library support detected"
141 }
2f9f6cef
BK
142 }
143 v3track v3-sharedlib 3
144
645112dd 145 # Compute what needs to be added to the existing LD_LIBRARY_PATH.
0b3deaaf
MM
146 if {$gccdir != ""} {
147 set ld_library_path ""
148 append ld_library_path ":${gccdir}"
149 set compiler ${gccdir}/g++
150 append ld_library_path ":${blddir}/src/.libs"
151
152 if { [is_remote host] == 0 && [which $compiler] != 0 } {
153 foreach i "[exec $compiler --print-multi-lib]" {
154 set mldir ""
615baed7 155 regexp -- "\[a-z0-9=_/\.-\]*;" $i mldir
0b3deaaf
MM
156 set mldir [string trimright $mldir "\;@"]
157 if { "$mldir" == "." } {
158 continue
159 }
160 if { [llength [glob -nocomplain ${gccdir}/${mldir}/libgcc_s*.so.*]] >= 1 } {
161 append ld_library_path ":${gccdir}/${mldir}"
162 }
163 }
164 }
b3f2a032 165
0b3deaaf
MM
166 set_ld_library_path_env_vars
167 if [info exists env(LD_LIBRARY_PATH)] {
168 verbose -log "LD_LIBRARY_PATH = $env(LD_LIBRARY_PATH)"
169 }
170 } else {
171 set compiler [transform "g++"]
1df8e834 172 }
b3f2a032 173
fa6763a6
DJ
174 # Default settings.
175 set cxx [transform "g++"]
176 set cxxflags "-g -O2 -D_GLIBCXX_ASSERT -fmessage-length=0"
177 set cxxldflags ""
178 set cc [transform "gcc"]
179 # Locate testsuite_hooks.h and other testsuite headers.
180 set includes "-I${srcdir}/util"
6cd5b96f 181 # Adapt the defaults for special circumstances.
b3f2a032 182 if [is_remote host] {
6cd5b96f
MM
183 # A remote host does not, in general, have access to the
184 # $srcdir so we copy the testsuite headers into the current
185 # directory, and then add that to the search path.
186 foreach src [glob "${srcdir}/util/*.h" \
187 "${srcdir}/util/*.cc" \
188 "${srcdir}/util/*/*.hpp" \
189 "${srcdir}/util/*/*.cc" \
190 "${srcdir}/util/*/*.hpp" \
191 "${srcdir}/util/*/*/*.cc" \
192 "${srcdir}/util/*/*/*.hpp" \
193 "${srcdir}/util/*/*/*/*.cc" \
194 "${srcdir}/util/*/*/*/*.hpp" \
195 "${srcdir}/util/*/*/*/*/*.cc" \
196 "${srcdir}/util/*/*/*/*/*.hpp" ] {
197 # Remove everything up to "util/..."
198 set dst [string range $src [string length "${srcdir}/"] end]
199 # Create the directory containing the file.
200 set dir [file dirname $dst]
201 remote_exec host "mkdir" [list "-p" "$dir"]
6c1e7e26 202 # Download the file.
6cd5b96f
MM
203 set result [remote_download host $src $dst]
204 if { $result == "" } {
6c1e7e26 205 verbose -log "Unable to download ${srcdir}/${src} to host."
6cd5b96f
MM
206 return "untested"
207 }
208 }
209 set includes "-Iutil"
210 } elseif { [file exists $flags_file] } {
b3f2a032 211 # If we find a testsuite_flags file, we're testing in the build dir.
6cd5b96f
MM
212 set cxx [exec sh $flags_file --build-cxx]
213 set cxxflags [exec sh $flags_file --cxxflags]
6c1e7e26
NS
214 set cxxldflags [exec sh $flags_file --cxxldflags]
215 set cc [exec sh $flags_file --build-cc]
6cd5b96f 216 set includes [exec sh $flags_file --build-includes]
b3f2a032 217 }
bd1a56a0
BK
218 append cxxflags " "
219 append cxxflags [getenv CXXFLAGS]
220 v3track cxxflags 2
b3f2a032 221
b5b3739a
MM
222 # Always use MO files built by this test harness.
223 set cxxflags "$cxxflags -DLOCALEDIR=\".\""
6c1e7e26 224 set ccflags "$cxxflags -DLOCALEDIR=\".\""
b5b3739a 225
8b60fb43
MM
226 # If a PCH file is available, use it. We must delay performing
227 # this check until $cxx and such have been initialized because we
228 # perform a test compilation. (Ideally, gcc --print-file-name would
229 # list PCH files, but it does not.)
230 global PCH_CXXFLAGS
231 if ![info exists PCH_CXXFLAGS] then {
232 set src "config[pid].cc"
233 set f [open $src "w"]
234 puts $f "int main () {}"
235 close $f
236
237 set lines [v3_target_compile $src "config[pid].o" object \
f67a67d8 238 "additional_flags=-include additional_flags=bits/stdtr1c++.h"]
8b60fb43 239 if {$lines == "" } {
6cbd871c 240# set PCH_CXXFLAGS "-include bits/extc++.h"
06e74494
BK
241# set PCH_CXXFLAGS "-include bits/stdtr1c++.h"
242 set PCH_CXXFLAGS "-include bits/stdc++.h"
8b60fb43
MM
243 } else {
244 set PCH_CXXFLAGS ""
245 }
246 file delete $src
247 v3track PCH_CXXFLAGS 2
248 }
249
d1fb5e1c 250 libstdc++_maybe_build_wrapper "${objdir}/testglue.o" "-fexceptions"
b3f2a032
PE
251}
252
ebd9dfc9 253# Callback for cleanup routines.
446e8778
RE
254proc libstdc++_exit { } {
255 global gluefile;
256
257 if [info exists gluefile] {
258 file_on_build delete $gluefile;
259 unset gluefile;
260 }
261}
262
b3f2a032 263# Callback from system dg-test.
caf21254 264proc libstdc++-dg-test { prog do_what extra_tool_flags } {
b3f2a032 265 # Set up the compiler flags, based on what we're going to do.
b3f2a032 266 switch $do_what {
caf21254
PE
267 "preprocess" {
268 set compile_type "preprocess"
269 set output_file "[file rootname [file tail $prog]].i"
270 }
271 "compile" {
272 set compile_type "assembly"
273 set output_file "[file rootname [file tail $prog]].s"
274 }
275 "assemble" {
276 set compile_type "object"
277 set output_file "[file rootname [file tail $prog]].o"
278 }
279 "link" {
280 set compile_type "executable"
281 set output_file "./[file rootname [file tail $prog]].exe"
282 }
283 "run" {
284 set compile_type "executable"
285 # FIXME: "./" is to cope with "." not being in $PATH.
286 # Should this be handled elsewhere?
287 # YES.
288 set output_file "./[file rootname [file tail $prog]].exe"
289 # This is the only place where we care if an executable was
290 # created or not. If it was, dg.exp will try to run it.
8e289297 291 catch { remote_file build delete $output_file }
caf21254 292 }
cddfb1c7 293 default {
caf21254
PE
294 perror "$do_what: not a valid dg-do keyword"
295 return ""
296 }
b3f2a032 297 }
cddfb1c7 298
0ded1615
BK
299 # Short-circut a bunch of complicated goo here for the special
300 # case of compiling a test file as a "C" file, not as C++. Why? So
301 # -nostdc++ doesn't trip us up. So all the extra object files
302 # don't trip us up. So automatically linking in libstdc++ doesn't
303 # happen. So CXXFLAGS don't error.
3c6430a3 304 set select_compile "v3_target_compile"
b3f2a032
PE
305 set options ""
306 if { $extra_tool_flags != "" } {
cddfb1c7
BK
307 verbose -log "extra_tool_flags are:"
308 verbose -log $extra_tool_flags
309 if { [string first "-x c" $extra_tool_flags ] != -1 } {
cddfb1c7 310 verbose -log "compiling and executing as C, not C++"
3c6430a3
BK
311 set edit_tool_flags $extra_tool_flags
312 regsub -all ".x c" $edit_tool_flags "" edit_tool_flags
313 lappend options "additional_flags=$edit_tool_flags"
3c6430a3 314 set select_compile "v3_target_compile_as_c"
cddfb1c7
BK
315 } else {
316 lappend options "additional_flags=$extra_tool_flags"
317 }
b3f2a032
PE
318 }
319
23834577
PE
320 # There is a libstdc++_compile made for us by default (via the tool-
321 # and-target file), but the defaults are lacking in goodness.
3c6430a3 322 set comp_output [$select_compile "$prog" "$output_file" "$compile_type" $options];
b3f2a032
PE
323 set comp_output [ prune_g++_output $comp_output ];
324
325 return [list $comp_output $output_file]
326}
327
0b3deaaf 328# True if the library supports wchar_t.
0b694555 329set v3-wchar_t 0
0b3deaaf
MM
330
331# True if the library supports threads.
0b694555 332set v3-threads 0
0b3deaaf 333
84946e72
BK
334# True if the library supports symbol versioning.
335set v3-symver 0
336
caf21254 337# Called from libstdc++-dg-test above. Calls back into system's
b3f2a032 338# target_compile to actually do the work.
caf21254 339proc v3_target_compile { source dest type options } {
b3f2a032
PE
340 global gluefile
341 global wrap_flags
342 global cxx
343 global cxxflags
952c7b74 344 global cxxldflags
b3f2a032 345 global includes
b3f2a032
PE
346
347 if { [target_info needs_status_wrapper] != "" && [info exists gluefile] } {
caf21254
PE
348 lappend options "libs=${gluefile}"
349 lappend options "ldflags=${wrap_flags}"
b3f2a032
PE
350 }
351
352 set cxx_final $cxx
353 set cxxlibglossflags [libgloss_link_flags]
354 set cxx_final [concat $cxx_final $cxxlibglossflags]
355 set cxx_final [concat $cxx_final $cxxflags]
356 set cxx_final [concat $cxx_final $includes]
31a7113e
BK
357
358 # Flag setting based on type argument.
0b3deaaf 359 if { $type == "executable" } {
31a7113e 360 # Link the support objects into executables.
952c7b74 361 set cxx_final [concat $cxx_final $cxxldflags]
0ded1615 362 lappend options "additional_flags=./libtestc++.a"
31a7113e
BK
363 } else {
364 if { $type == "sharedlib" } {
365 # Don't link in anything.
366 set type "executable"
367 }
0b3deaaf 368 }
b3f2a032
PE
369
370 lappend options "compiler=$cxx_final"
a0895ebf 371 lappend options "timeout=600"
b3f2a032 372
b3f2a032
PE
373 return [target_compile $source $dest $type $options]
374}
375
5305b1ae 376
3c6430a3
BK
377# Called from libstdc++-dg-test above, but only for "C" compilation.
378# Calls back into system's target_compile to actually do the work.
379proc v3_target_compile_as_c { source dest type options } {
380 global gluefile
381 global wrap_flags
382 global includes
5f90c88f 383 global flags_file
9e451553 384 global blddir
6c1e7e26 385 global cc
c2ba9709 386 global cxxflags
3c6430a3
BK
387
388 if { [target_info needs_status_wrapper] != "" && [info exists gluefile] } {
389 lappend options "libs=${gluefile}"
390 lappend options "ldflags=${wrap_flags}"
391 }
392
393 set tname [target_info name]
5f90c88f
BK
394 set cc_final $cc
395 set cxxlibglossflags [libgloss_link_flags]
3c6430a3 396 set cc_final [concat $cc_final $cxxlibglossflags]
c2ba9709 397 set cc_final [concat $cc_final $cxxflags]
3c6430a3 398 set cc_final [concat $cc_final $includes]
8f1a19e2 399 regsub -all {\s[-]nostdinc[+][+]} $cc_final "" cc_final
3c6430a3 400
5f90c88f
BK
401 # This is needed for "C" tests, as this type of test may need the
402 # C++ includes. And if we're not testing in the build directory,
6cd5b96f
MM
403 # the includes variable is not likely to include the necessary
404 # info.
5f90c88f 405 if { ![file exists $flags_file] } {
357480ce
MM
406 # ??? We need a --print-include-dirs option to GCC, so that
407 # we can avoid these hacks. The heuristics here will not
408 # work with non-standard --with-includedir= options.
6cd5b96f 409 set version [remote_exec host ${cc} -dumpversion]
7504beb4
MM
410 # Remove the trailing newline from the output.
411 set version [string trimright [lindex $version 1]]
412 set machine [remote_exec host ${cc} -dumpmachine]
413 set machine [string trimright [lindex $machine 1]]
6cd5b96f
MM
414 set comp_base_dir [remote_exec host ${cc} --print-prog-name=cc1]
415 set comp_base_dir [lindex $comp_base_dir 1]
416 set comp_base_dir [file dirname [file dirname [file dirname [file dirname [file dirname $comp_base_dir]]]]]
357480ce
MM
417 # For a cross compiler, the header files will be located in a
418 # machine-specific subdirectory.
419 set crossbase "${comp_base_dir}/${machine}/include/c++/${version}"
420 set crosstarget "${crossbase}/${machine}"
421 set cc_final [concat $cc_final "-I$crossbase -I$crosstarget"]
422 # For a native compiler, the header files will be located at
423 # the top level.
5f90c88f
BK
424 set includesbase "${comp_base_dir}/include/c++/${version}"
425 set includestarget "${includesbase}/${machine}"
426 set cc_final [concat $cc_final "-I$includesbase -I$includestarget"]
9e451553
BK
427
428 set libsup "${comp_base_dir}/lib"
429 } else {
430 set libsup "${blddir}/libsupc++/.libs"
5f90c88f
BK
431 }
432
9e451553
BK
433 set cc_final [concat $cc_final "-L$libsup"]
434
3c6430a3
BK
435 lappend options "compiler=$cc_final"
436 lappend options "timeout=600"
437
438 return [target_compile $source $dest $type $options]
439}
440
0b3deaaf 441# Build the support objects linked in with the libstdc++ tests. In
0ded1615 442# addition, set v3-wchar_t, v3-threads, and v3-symver appropriately.
451e92db 443proc v3-build_support { } {
43e03430 444 global env
c85b032a 445 global srcdir
0b694555
MM
446 global v3-wchar_t
447 global v3-threads
84946e72 448 global v3-symver
2f9f6cef 449 global v3-sharedlib
0b3deaaf
MM
450
451 # Figure out whether or not the library supports certain features.
0b694555
MM
452 set v3-wchar_t 0
453 set v3-threads 0
84946e72 454 set v3-symver 0
0ded1615 455 set libtest_objs ""
0b3deaaf
MM
456
457 set config_src "config.cc"
7cff41e8 458 set config_out "config.ii"
0b3deaaf
MM
459 set f [open $config_src "w"]
460 puts $f "#include <bits/c++config.h>"
08cce8fe 461 puts $f "#include <bits/gthr.h>"
0b3deaaf 462 close $f
7cff41e8
JM
463 v3_target_compile $config_src $config_out preprocess "additional_flags=-dN"
464 set file [open $config_out r]
465 set preprocessed [read $file]
466 close $file
08cce8fe
MM
467 if { [string first "_GLIBCXX_USE_WCHAR_T" $preprocessed] != -1 } {
468 verbose -log "wchar_t support detected"
469 set v3-wchar_t 1
470 }
84946e72
BK
471 if { [string first "_GLIBCXX_SYMVER" $preprocessed] != -1 } {
472 verbose -log "symbol versioning support detected"
473 set v3-symver 1
474 }
08cce8fe
MM
475 if { [string first "__GTHREADS" $preprocessed] != -1 } {
476 verbose -log "thread support detected"
477 set v3-threads 1
0b3deaaf 478 }
c85b032a 479
b5b3739a
MM
480 # Try to build the MO files that are used by some of the locale
481 # tests. If we can't build them, that's OK; it just means that
482 # those tests will fail.
483 foreach lang [list "fr" "de"] {
484 catch {
485 file mkdir "$lang/LC_MESSAGES"
486 remote_exec "build" "msgfmt" "-o $lang/LC_MESSAGES/libstdc++.mo $srcdir/../po/$lang.po"
487 if [is_remote host] {
488 remote_exec "host" "mkdir" "-p $lang/LC_MESSAGES"
489 remote_download "host" "$lang/LC_MESSAGES/libstdc++.mo" "$lang/LC_MESSAGES/libstdc++.mo"
490 }
491 }
492 }
493
0b3deaaf 494 # Build the support objects.
4569a895
AT
495 set source_files [list testsuite_abi.cc testsuite_allocator.cc \
496 testsuite_character.cc testsuite_hooks.cc \
497 rng/twister_rand_gen.cc io/verified_cmd_line_input.cc \
a86151e1 498 io/prog_bar.cc performance/time/elapsed_timer.cc ]
0b3deaaf 499 foreach f $source_files {
4569a895
AT
500 set obj [file rootname $f].o
501 set object_file [file tail $obj]
510d8ecc
MM
502 # Compile with "-w" so that warnings issued by the compiler
503 # do not prevent compilation.
3416d7cd 504 if { [v3_target_compile $srcdir/util/$f $object_file "object" \
510d8ecc 505 [list "incdir=$srcdir" "additional_flags=-w"]]
0b3deaaf
MM
506 != "" } {
507 error "could not compile $f"
508 }
0ded1615 509 append libtest_objs "$object_file "
b3f2a032 510 }
2f9f6cef 511
4569a895 512 # Collect into libtestc++.a
6ed80bc4
HPN
513 if [info exists env(AR)] {
514 set ar $env(AR)
43e03430
HPN
515 } else {
516 set ar [transform "ar"]
517 }
7cff41e8
JM
518 set arargs "-rc ./libtestc++.a ${libtest_objs}"
519 verbose -log "$ar $arargs"
520 set result [lindex [remote_exec host "$ar" "$arargs"] 0]
4569a895
AT
521 verbose "link result is $result"
522 if { $result == 0 } {
6ed80bc4
HPN
523 if [info exists env(RANLIB)] {
524 set ranlib $env(RANLIB)
43e03430
HPN
525 } else {
526 set ranlib [transform "ranlib"]
527 }
7cff41e8
JM
528 set ranlibargs "./libtestc++.a"
529 verbose -log "$ranlib $ranlibargs"
530 set result [lindex [remote_exec host "$ranlib" "$ranlibargs"] 0]
4569a895
AT
531 if { $result != 0 } {
532 error "could not link libtestc++.a"
4569a895
AT
533 }
534 }
535
536 # Build any shared objects needed for regression testing.
2f9f6cef 537 if { ${v3-sharedlib} == 1 } {
4569a895 538 set source_files [list testsuite_shared.cc]
2f9f6cef
BK
539 foreach f $source_files {
540 set object_file [file rootname $f].so
541 # Compile with "-w" so that warnings issued by the compiler
542 # do not prevent compilation.
3416d7cd 543 if { [v3_target_compile $srcdir/util/$f $object_file "sharedlib" \
2f9f6cef
BK
544 [list "incdir=$srcdir" "additional_flags=-w -shared -fPIC -DPIC"]]
545 != "" } {
546 error "could not compile $f"
547 }
548 }
549 }
550}
551
0c20e4ec
NS
552proc check_v3_target_fileio { } {
553 global et_fileio_saved
554 global et_fileio_target_name
555 global tool
556
557 if { ![info exists et_fileio_target_name] } {
558 set et_fileio_target_name ""
559 }
560
561 # If the target has changed since we set the cached value, clear it.
562 set current_target [current_target_name]
563 if { $current_target != $et_fileio_target_name } {
564 verbose "check_v3_target_fileio: `$et_fileio_target_name'" 2
565 set et_fileio_target_name $current_target
566 if [info exists et_fileio_saved] {
567 verbose "check_v3_target_fileio: removing cached result" 2
568 unset et_fileio_saved
569 }
570 }
571
572 if [info exists et_fileio_saved] {
573 verbose "check_v3_target_fileio: using cached result" 2
574 } else {
575 set et_fileio_saved 0
576
577 # Set up, compile, and execute a C++ test program that tries to use
578 # the file functions
579 set src fileio[pid].cc
580 set exe fileio[pid].x
581
582 set f [open $src "w"]
583 puts $f "#include <sys/types.h>"
584 puts $f "#include <sys/stat.h>"
585 puts $f "#include <fcntl.h>"
586 puts $f "#include <unistd.h>"
587 puts $f "#include <errno.h>"
588 puts $f "using namespace std;"
589 puts $f "int main ()"
590 puts $f "{"
591 puts $f " int fd = open (\".\", O_RDONLY);"
592 puts $f " if (fd == -1)"
593 puts $f " {"
594 puts $f " int err = errno;"
595 puts $f " if (err == EIO || err == ENOSYS)"
596 puts $f " return 1;"
597 puts $f " }"
598 puts $f " else"
599 puts $f " close (fd);"
600 puts $f " return 0;"
601 puts $f "}"
602 close $f
603
604 set lines [v3_target_compile $src $exe executable ""]
605 file delete $src
606
607 if [string match "" $lines] {
608 # No error message, compilation succeeded.
609 set result [${tool}_load "./$exe" "" ""]
610 set status [lindex $result 0]
611 remote_file build delete $exe
612
613 verbose "check_v3_target_fileio: status is <$status>" 2
614
615 if { $status == "pass" } {
616 set et_fileio_saved 1
617 }
618 } else {
619 verbose "check_v3_target_fileio: compilation failed" 2
620 }
621 }
622 return $et_fileio_saved
623}
624
803f183a 625# Eventually we want C90/C99 determining and switching from this.
7c62b943
BK
626proc check_v3_target_c_std { } {
627 global et_c_std_saved
628 global et_c_std_target_name
629 global tool
630
631 if { ![info exists et_c_std_target_name] } {
632 set et_c_std_target_name ""
633 }
634
635 # If the target has changed since we set the cached value, clear it.
636 set current_target [current_target_name]
637 if { $current_target != $et_c_std_target_name } {
638 verbose "check_v3_target_c_std: `$et_c_std_target_name'" 2
639 set et_c_std_target_name $current_target
640 if [info exists et_c_std_saved] {
641 verbose "check_v3_target_c_std: removing cached result" 2
642 unset et_c_std_saved
643 }
644 }
645
646 if [info exists et_c_std_saved] {
647 verbose "check_v3_target_c_std: using cached result" 2
648 } else {
649 set et_c_std_saved 0
650
651 # Set up, compile, and execute a C++ test program that tries to use
652 # C99 functionality.
803f183a 653 # For math bits, could use check_effective_target_c99_math.
7c62b943
BK
654 set src fileio[pid].cc
655 set exe fileio[pid].x
656
657 set f [open $src "w"]
658 puts $f "#include <tr1/cmath>"
803f183a 659 puts $f "#include <cstdlib>"
7c62b943
BK
660 puts $f "int main ()"
661 puts $f "{"
662 puts $f " float f = 45.55;"
663 puts $f " int i = std::tr1::isnan(f);"
803f183a
BK
664 puts $f " "
665 puts $f " using std::wctomb;"
7c62b943
BK
666 puts $f " return 0;"
667 puts $f "}"
668 close $f
669
670 set lines [v3_target_compile $src $exe executable ""]
671 file delete $src
672
673 if [string match "" $lines] {
674 # No error message, compilation succeeded.
675 set result [${tool}_load "./$exe" "" ""]
676 set status [lindex $result 0]
677 remote_file build delete $exe
678
679 verbose "check_v3_target_c_std: status is <$status>" 2
680
681 if { $status == "pass" } {
682 set et_c_std_saved 1
683 }
684 } else {
685 verbose "check_v3_target_c_std: compilation failed" 2
686 }
687 }
688 return $et_c_std_saved
689}
690
2f9f6cef
BK
691proc check_v3_target_sharedlib { } {
692 global v3-sharedlib
693 return ${v3-sharedlib}
b3f2a032 694}
f63a8495 695
0c20e4ec
NS
696proc check_v3_target_time { } {
697 global et_time_saved
698 global et_time_target_name
699 global tool
700
701 if { ![info exists et_time_target_name] } {
702 set et_time_target_name ""
703 }
704
705 # If the target has changed since we set the cached value, clear it.
706 set current_target [current_target_name]
707 if { $current_target != $et_time_target_name } {
708 verbose "check_v3_target_time: `$et_time_target_name'" 2
709 set et_time_target_name $current_target
710 if [info exists et_time_saved] {
711 verbose "check_v3_target_time: removing cached result" 2
712 unset et_time_saved
713 }
714 }
715
716 if [info exists et_time_saved] {
717 verbose "check_v3_target_time: using cached result" 2
718 } else {
719 set et_time_saved 0
720
721 # Set up and compile a C++ test program that tries to use
722 # the time function
723 set src time[pid].cc
724 set exe time[pid].x
725
726 set f [open $src "w"]
727 puts $f "#include <time.h>"
728 puts $f "using namespace std;"
729 puts $f "int main ()"
730 puts $f "{"
731 puts $f " time (0);"
732 puts $f "}"
733 close $f
734
735 set lines [v3_target_compile $src $exe executable ""]
736 file delete $src
737
738 if [string match "" $lines] {
739 # No error message, compilation succeeded.
740 verbose "check_v3_target_time: compilation succeeded" 2
741 remote_file build delete $exe
742 set et_time_saved 1
743 } else {
744 verbose "check_v3_target_time: compilation failed" 2
745 }
746 }
747 return $et_time_saved
748}
749
f63a8495
PC
750proc check_v3_target_namedlocale { } {
751 global et_namedlocale_saved
752 global et_namedlocale_target_name
753 global tool
754
755 if { ![info exists et_namedlocale_target_name] } {
756 set et_namedlocale_target_name ""
757 }
758
759 # If the target has changed since we set the cached value, clear it.
760 set current_target [current_target_name]
761 if { $current_target != $et_namedlocale_target_name } {
762 verbose "check_v3_target_namedlocale: `$et_namedlocale_target_name'" 2
763 set et_namedlocale_target_name $current_target
764 if [info exists et_namedlocale_saved] {
765 verbose "check_v3_target_namedlocale: removing cached result" 2
766 unset et_namedlocale_saved
767 }
768 }
769
770 if [info exists et_namedlocale_saved] {
771 verbose "check_v3_target_namedlocale: using cached result" 2
772 } else {
773 set et_namedlocale_saved 0
774
775 # Set up, compile, and execute a C++ test program that tries to use
776 # all the required named locales.
777 set src nlocale[pid].cc
778 set exe nlocale[pid].x
779
780 set f [open $src "w"]
781 puts $f "#include <locale>"
782 puts $f "using namespace std;"
783 puts $f "int main ()"
784 puts $f "{"
785 puts $f " try"
786 puts $f " {"
787 puts $f " locale(\"\");"
788 puts $f " locale(\"de_DE\");"
789 puts $f " locale(\"de_DE.ISO-8859-15@euro\");"
790 puts $f " locale(\"de_DE@euro\");"
791 puts $f " locale(\"en_HK\");"
792 puts $f " locale(\"en_PH\");"
793 puts $f " locale(\"en_US\");"
794 puts $f " locale(\"en_US.ISO-8859-1\");"
795 puts $f " locale(\"en_US.ISO-8859-15\");"
796 puts $f " locale(\"en_US.UTF-8\");"
797 puts $f " locale(\"es_ES\");"
798 puts $f " locale(\"es_MX\");"
799 puts $f " locale(\"fr_FR\");"
800 puts $f " locale(\"fr_FR@euro\");"
801 puts $f " locale(\"is_IS\");"
802 puts $f " locale(\"is_IS.UTF-8\");"
803 puts $f " locale(\"it_IT\");"
804 puts $f " locale(\"ja_JP.eucjp\");"
805 puts $f " locale(\"se_NO.UTF-8\");"
806 puts $f " locale(\"ta_IN\");"
807 puts $f " locale(\"zh_TW\");"
808 puts $f " return 0;"
809 puts $f " }"
810 puts $f " catch(...)"
811 puts $f " {"
812 puts $f " return 1;"
813 puts $f " }"
814 puts $f "}"
815 close $f
816
817 set lines [v3_target_compile $src $exe executable ""]
818 file delete $src
819
820 if [string match "" $lines] {
821 # No error message, compilation succeeded.
822 set result [${tool}_load "./$exe" "" ""]
823 set status [lindex $result 0]
824 remote_file build delete $exe
825
826 verbose "check_v3_target_namedlocale: status is <$status>" 2
827
828 if { $status == "pass" } {
829 set et_namedlocale_saved 1
830 }
831 } else {
832 verbose "check_v3_target_namedlocale: compilation failed" 2
833 }
834 }
835 return $et_namedlocale_saved
836}
a1340af7 837
451e92db
BK
838proc check_v3_target_debug_mode { } {
839 global cxxflags
840 global et_debug_mode
451e92db
BK
841 global tool
842
843 if { ![info exists et_debug_mode_target_name] } {
844 set et_debug_mode_target_name ""
845 }
846
847 # If the target has changed since we set the cached value, clear it.
848 set current_target [current_target_name]
849 if { $current_target != $et_debug_mode_target_name } {
850 verbose "check_v3_target_debug_mode: `$et_debug_mode_target_name'" 2
851 set et_debug_mode_target_name $current_target
852 if [info exists et_debug_mode] {
853 verbose "check_v3_target_debug_mode: removing cached result" 2
854 unset et_debug_mode
855 }
856 }
857
858 if [info exists et_debug_mode] {
859 verbose "check_v3_target_debug_mode: using cached result" 2
860 } else {
861 set et_debug_mode 0
862
863 # Set up, compile, and execute a C++ test program that depends
cddfb1c7 864 # on debug mode working.
451e92db 865 set src debug_mode[pid].cc
797308b2 866 set exe debug_mode[pid].exe
451e92db
BK
867
868 set f [open $src "w"]
869 puts $f "#include <string>"
870 puts $f "using namespace std;"
871 puts $f "int main()"
872 puts $f "{ return 0; }"
873 close $f
874
875 set cxxflags_saved $cxxflags
876 set cxxflags "$cxxflags -Werror -O0 -D_GLIBCXX_DEBUG"
877 set lines [v3_target_compile $src $exe executable ""]
878 set cxxflags $cxxflags_saved
879 file delete $src
880
881 if [string match "" $lines] {
882 # No error message, compilation succeeded.
883 set et_debug_mode 1
884 }
885 }
886 verbose "check_v3_target_debug_mode: $et_debug_mode" 2
887 return $et_debug_mode
888}
c2ba9709
JS
889
890proc check_v3_target_parallel_mode { } {
891 global cxxflags
892 global DEFAULT_CXXFLAGS
893 global et_parallel_mode
894
895 global tool
896
897 if { ![info exists et_parallel_mode_target_name] } {
898 set et_parallel_mode_target_name ""
899 }
900
901 # If the target has changed since we set the cached value, clear it.
902 set current_target [current_target_name]
903 if { $current_target != $et_parallel_mode_target_name } {
904 verbose "check_v3_target_parallel_mode: `$et_parallel_mode_target_name'" 2
905 set et_parallel_mode_target_name $current_target
906 if [info exists et_parallel_mode] {
907 verbose "check_v3_target_parallel_mode: removing cached result" 2
908 unset et_parallel_mode
909 }
910 }
911
912 if [info exists et_parallel_mode] {
913 verbose "check_v3_target_parallel_mode: using cached result" 2
914 } else {
915 set et_parallel_mode 0
916
917 # Set up, compile, and execute a C++ test program that depends
918 # on parallel mode working.
919 set src parallel_mode[pid].cc
920 set exe parallel_mode[pid].exe
921
922 set f [open $src "w"]
923 puts $f "#include <omp.h>"
924 puts $f "int main()"
925 puts $f "{ return 0; }"
926 close $f
927
928 set cxxflags_saved $cxxflags
929 set cxxflags "$cxxflags $DEFAULT_CXXFLAGS -Werror"
930
931 set lines [v3_target_compile $src $exe executable ""]
932 set cxxflags $cxxflags_saved
933 file delete $src
934
935 if [string match "" $lines] {
936 # No error message, compilation succeeded.
937 set et_parallel_mode 1
938 } else {
939 verbose "check_v3_target_parallel_mode: compilation failed" 2
940 }
941 }
942 verbose "check_v3_target_parallel_mode: $et_parallel_mode" 2
943 return $et_parallel_mode
944}