[testsuite] Fix retrieval of testname
[official-gcc.git] / libstdc++-v3 / testsuite / lib / libstdc++.exp
blob02c88ede2abf49b737beb8ef09d2f40906c93a12
1 # libstdc++ "tool init file" for DejaGNU
3 # Copyright (C) 2001-2017 Free Software Foundation, Inc.
5 # This program is free software; you can redistribute it and/or modify
6 # it under the terms of the GNU General Public License as published by
7 # the Free Software Foundation; either version 3 of the License, or
8 # (at your option) any later version.
9 #
10 # This program is distributed in the hope that it will be useful,
11 # but WITHOUT ANY WARRANTY; without even the implied warranty of
12 # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
13 # GNU General Public License for more details.
15 # You should have received a copy of the GNU General Public License
16 # along with this program; see the file COPYING3. If not see
17 # <http://www.gnu.org/licenses/>.
20 # Define callbacks and load other libraries. This file is loaded relatively
21 # early, and before any other file we write ourselves. "load_lib" will
22 # find anything in the DejaGNU installation tree, or in our lib directory.
23 # "load_gcc_lib" will search the core compiler's .exp collection instead.
25 # The naming rule is that dg.exp looks for "tool-" and runtest.exp looks
26 # for "tool_" when finding callbacks. Utility routines we define for
27 # our callbacks begin with "v3-".
29 # libstdc++_* callbacks we don't define, but could:
30 # ..._option_help prints additional --help output
31 # ..._option_proc (--foo) process our own options
32 # ..._init (normal.exp) called once per test file
33 # ..._finish bracketing function for libstdc++_init
34 # ...-dg-prune removing output text, see top of system dg.exp
36 # Useful hook: if ${hostname}_init exists, it will be called, almost
37 # the last thing before testing begins. This can be defined in, e.g.,
38 # ~/.dejagnurc or $DEJAGNU.
40 proc load_gcc_lib { filename } {
41 global srcdir loaded_libs
43 load_file $srcdir/../../gcc/testsuite/lib/$filename
44 set loaded_libs($filename) ""
47 # system routines
48 load_lib dg.exp
49 load_lib libgloss.exp
50 # compiler routines, then ours
51 load_gcc_lib target-supports.exp
52 load_gcc_lib target-supports-dg.exp
53 load_lib prune.exp
54 load_lib dg-options.exp
55 load_gcc_lib scanasm.exp
56 load_gcc_lib target-libpath.exp
57 load_gcc_lib timeout.exp
58 load_gcc_lib timeout-dg.exp
59 load_gcc_lib wrapper.exp
60 load_gcc_lib target-utils.exp
62 # Useful for debugging. Pass the name of a variable and the verbosity
63 # threshold (number of -v's on the command line).
64 proc v3track { var n } {
65 upvar $var val
66 verbose "++ $var is $val" $n
69 # Copy file to the target.
70 proc v3-copy-file {src dst} {
71 if { [catch { set symlink [file readlink $src] } x] } then {
72 remote_download target $src $dst
73 } else {
74 if { [regexp "^/" "$symlink"] } then {
75 remote_download target $symlink $dst
76 } else {
77 set dirname [file dirname $f]
78 remote_download target $dirname/$symlink $dst
83 # Called by v3-init below. "Static" to this file.
84 proc v3-copy-files {srcfiles} {
85 foreach f $srcfiles {
86 v3-copy-file $f [file tail $f]
90 # Called once, during runtest.exp setup.
91 proc libstdc++_init { testfile } {
92 global env
93 global v3-sharedlib v3-libgomp
94 global srcdir blddir objdir tool_root_dir
95 global cc cxx cxxflags cxxpchflags cxxldflags cxxvtvflags
96 global includes
97 global gluefile wrap_flags
98 global ld_library_path
99 global target_triplet
100 global flags_file
101 global tool_timeout
102 global DEFAULT_CXXFLAGS
103 global STATIC_LIBCXXFLAGS
105 # We set LC_ALL and LANG to C so that we get the same error
106 # messages as expected.
107 setenv LC_ALL C
108 setenv LANG C
110 # LANGUAGE changes the behavior of GNU gettext(3) and causes
111 # std::messages tests to fail.
112 array unset env LANGUAGE
114 # Many hosts now default to a non-ASCII C locale, however, so
115 # they can set a charset encoding here if they need.
116 if { [ishost "*-*-cygwin*"] } {
117 setenv LC_ALL C.ASCII
118 setenv LANG C.ASCII
121 set blddir [lookfor_file [get_multilibs] libstdc++-v3]
122 set flags_file "${blddir}/scripts/testsuite_flags"
123 set shlib_ext [get_shlib_extension]
124 v3track flags_file 2
126 # If a test doesn't have special options, use DEFAULT_CXXFLAGS.
127 # Use this variable if the behavior
128 # 1) only applies to libstdc++ testing
129 # 2) might need to be negated
130 # In particular, some tests have to be run without precompiled
131 # headers, or without assertions.
133 if ![info exists DEFAULT_CXXFLAGS] then {
134 set DEFAULT_CXXFLAGS ""
135 # Host specific goo here.
136 if { [string match "powerpc-*-darwin*" $target_triplet] } {
137 append DEFAULT_CXXFLAGS " -multiply_defined suppress"
139 if { [string match "powerpc-ibm-aix*" $target_triplet] } {
140 append DEFAULT_CXXFLAGS " -Wl,-bmaxdata:0x20000000"
143 v3track DEFAULT_CXXFLAGS 2
145 # By default, we assume we want to run program images.
146 global dg-do-what-default
147 set dg-do-what-default run
149 # Copy any required data files.
150 v3-copy-files [glob -nocomplain "$srcdir/data/*.tst"]
151 v3-copy-files [glob -nocomplain "$srcdir/data/*.txt"]
153 set ld_library_path_tmp ""
155 # Locate libgcc.a so we don't need to account for different values of
156 # SHLIB_EXT on different platforms
157 set gccdir [lookfor_file $tool_root_dir gcc/libgcc.a]
158 if {$gccdir != ""} {
159 set gccdir [file dirname $gccdir]
160 append ld_library_path_tmp ":${gccdir}"
162 v3track gccdir 3
164 # Locate libgomp. This is only required for parallel mode.
165 set v3-libgomp 0
166 set libgompdir [lookfor_file $blddir/../libgomp .libs/libgomp.$shlib_ext]
167 if {$libgompdir != ""} {
168 set v3-libgomp 1
169 set libgompdir [file dirname $libgompdir]
170 append ld_library_path_tmp ":${libgompdir}"
171 verbose -log "libgomp support detected"
173 v3track libgompdir 3
175 # Locate libvtv. This is only required for --enable-vtable-verify.
176 set v3-libvtv 0
177 set libvtvdir [lookfor_file $blddir/../libvtv .libs/libvtv.$shlib_ext]
178 if {$libvtvdir != ""} {
179 set v3-libvtv 1
180 set libvtvdir [file dirname $libvtvdir]
181 append ld_library_path_tmp ":${libvtvdir}"
182 verbose -log "libvtv support detected"
184 v3track libvtvdir 3
186 # Locate libstdc++ shared library. (ie libstdc++.so.)
187 set v3-sharedlib 0
188 set sharedlibdir [lookfor_file $blddir src/.libs/libstdc++.$shlib_ext]
189 if {$sharedlibdir != ""} {
190 if { ([string match "*-*-gnu*" $target_triplet]
191 || [string match "*-*-linux*" $target_triplet]
192 || [string match "*-*-solaris*" $target_triplet])
193 && [isnative] } then {
194 set v3-sharedlib 1
195 verbose -log "shared library support detected"
198 v3track v3-sharedlib 3
200 set STATIC_LIBCXXFLAGS ""
201 set staticlibdir [lookfor_file $blddir src/.libs/libstdc++.a]
202 if {$staticlibdir != ""} {
203 set staticlibdir [file dirname $staticlibdir]
204 # Some targets use libstdc++.a%s in their specs, so they need a
205 # -B option for uninstalled testing.
206 set STATIC_LIBCXXFLAGS " -B${staticlibdir} "
209 # Compute what needs to be added to the existing LD_LIBRARY_PATH.
210 if {$gccdir != ""} {
211 set compiler ${gccdir}/xg++
212 set ld_library_path ${ld_library_path_tmp}
213 append ld_library_path ":${blddir}/src/.libs"
215 if { [is_remote host] == 0 && [which $compiler] != 0 } {
216 foreach i "[exec $compiler --print-multi-lib]" {
217 set mldir ""
218 regexp -- "\[a-z0-9=_/\.-\]*;" $i mldir
219 set mldir [string trimright $mldir "\;@"]
220 if { "$mldir" == "." } {
221 continue
223 if { [llength [glob -nocomplain ${gccdir}/${mldir}/libgcc_s*.so.*]] >= 1 } {
224 append ld_library_path ":${gccdir}/${mldir}"
229 set_ld_library_path_env_vars
230 if [info exists env(LD_LIBRARY_PATH)] {
231 verbose -log "LD_LIBRARY_PATH = $env(LD_LIBRARY_PATH)"
233 } else {
234 set compiler [transform "g++"]
237 # Set the default timeout for v3 tests.
238 set tool_timeout 600
240 # Default settings.
241 set cxx [transform "g++"]
242 set cxxflags "-fmessage-length=0"
243 set cxxpchflags ""
244 set cxxvtvflags ""
245 set cxxldflags ""
246 set cc [transform "gcc"]
247 # Locate testsuite_hooks.h and other testsuite headers.
248 set includes "-I${srcdir}/util"
249 # Adapt the defaults for special circumstances.
250 if [is_remote host] {
251 # A remote host does not, in general, have access to the
252 # $srcdir so we copy the testsuite headers into the current
253 # directory, and then add that to the search path.
254 foreach src [glob "${srcdir}/util/*.h" \
255 "${srcdir}/util/*.cc" \
256 "${srcdir}/util/*.tcc" \
257 "${srcdir}/util/*.hpp" \
258 "${srcdir}/util/*/*.h" \
259 "${srcdir}/util/*/*.cc" \
260 "${srcdir}/util/*/*.tcc" \
261 "${srcdir}/util/*/*.hpp" \
262 "${srcdir}/util/*/*/*.h" \
263 "${srcdir}/util/*/*/*.cc" \
264 "${srcdir}/util/*/*/*.tcc" \
265 "${srcdir}/util/*/*/*.hpp" \
266 "${srcdir}/util/*/*/*/*.h" \
267 "${srcdir}/util/*/*/*/*.cc" \
268 "${srcdir}/util/*/*/*/*.tcc" \
269 "${srcdir}/util/*/*/*/*.hpp" \
270 "${srcdir}/util/*/*/*/*/*.h" \
271 "${srcdir}/util/*/*/*/*/*.cc" \
272 "${srcdir}/util/*/*/*/*/*.tcc" \
273 "${srcdir}/util/*/*/*/*/*.hpp" ] {
274 # Remove everything up to "util/..."
275 set dst [string range $src [string length "${srcdir}/"] end]
276 # Create the directory containing the file.
277 set dir [file dirname $dst]
278 remote_exec host "mkdir" [list "-p" "$dir"]
279 # Download the file.
280 set result [remote_download host $src $dst]
281 if { $result == "" } {
282 verbose -log "Unable to download ${srcdir}/${src} to host."
283 return "untested"
286 set includes "-Iutil"
287 } elseif { [file exists $flags_file] } {
288 # If we find a testsuite_flags file, we're testing in the build dir.
289 set cxx [exec sh $flags_file --build-cxx]
290 set cxxflags [exec sh $flags_file --cxxflags]
291 set cxxpchflags [exec sh $flags_file --cxxpchflags]
292 set cxxvtvflags [exec sh $flags_file --cxxvtvflags]
293 set cxxldflags [exec sh $flags_file --cxxldflags]
294 set cc [exec sh $flags_file --build-cc]
295 set includes [exec sh $flags_file --build-includes]
297 append cxxflags " "
298 append cxxflags [getenv CXXFLAGS]
300 if ![regexp ".*-O" $cxxflags] {
301 append cxxflags " -g -O2"
304 v3track cxxflags 2
306 # Should be as good as -fdiagnostics-color=never, but more compatible
307 setenv GCC_COLORS ""
308 # Always use MO files built by this test harness.
309 set ccflags "$cxxflags -DLOCALEDIR=\".\""
310 set cxxflags "$cxxflags -DLOCALEDIR=\".\""
312 # If a PCH file is available, use it. We must delay performing
313 # this check until $cxx and such have been initialized because we
314 # perform a test compilation. (Ideally, gcc --print-file-name would
315 # list PCH files, but it does not.)
316 if { $cxxpchflags != "" } {
317 set src "config[pid].cc"
318 set f [open $src "w"]
319 puts $f "int main () {}"
320 close $f
322 # Fixme: "additional_flags=$cxxpchflags" fails, but would be
323 # useful as then the requested variant of the pre-build PCH
324 # files could be tested to see if it works.
325 set lines [v3_target_compile $src "config[pid].o" object \
326 "additional_flags=-include additional_flags=bits/stdc++.h"]
327 if { $lines != "" } {
328 verbose -log "Requested PCH file: $cxxpchflags"
329 verbose -log "is not working, and will not be used."
330 set cxxpchflags ""
332 file delete $src
334 v3track cxxpchflags 2
336 global PCH_CXXFLAGS
337 if ![info exists PCH_CXXFLAGS] then {
338 set PCH_CXXFLAGS $cxxpchflags
339 v3track PCH_CXXFLAGS 2
342 libstdc++_maybe_build_wrapper "${objdir}/testglue.o" "-fexceptions"
345 # Callback for cleanup routines.
346 proc libstdc++_exit { } {
347 global gluefile;
349 if [info exists gluefile] {
350 file_on_build delete $gluefile;
351 unset gluefile;
355 # Callback from system dg-test.
356 proc libstdc++-dg-test { prog do_what extra_tool_flags } {
357 # Set up the compiler flags, based on what we're going to do.
358 switch $do_what {
359 "preprocess" {
360 set compile_type "preprocess"
361 set output_file "[file rootname [file tail $prog]].i"
363 "compile" {
364 set compile_type "assembly"
365 set output_file "[file rootname [file tail $prog]].s"
367 "assemble" {
368 set compile_type "object"
369 set output_file "[file rootname [file tail $prog]].o"
371 "link" {
372 set compile_type "executable"
373 set output_file "./[file rootname [file tail $prog]].exe"
375 "run" {
376 set compile_type "executable"
377 # FIXME: "./" is to cope with "." not being in $PATH.
378 # Should this be handled elsewhere?
379 # YES.
380 set output_file "./[file rootname [file tail $prog]].exe"
381 # This is the only place where we care if an executable was
382 # created or not. If it was, dg.exp will try to run it.
383 catch { remote_file build delete $output_file }
385 default {
386 perror "$do_what: not a valid dg-do keyword"
387 return ""
391 # Short-circut a bunch of complicated goo here for the special
392 # case of compiling a test file as a "C" file, not as C++. Why? So
393 # -nostdc++ doesn't trip us up. So all the extra object files
394 # don't trip us up. So automatically linking in libstdc++ doesn't
395 # happen. So CXXFLAGS don't error.
396 set select_compile "v3_target_compile"
397 set options ""
398 if { $extra_tool_flags != "" } {
399 verbose -log "extra_tool_flags are:"
400 verbose -log $extra_tool_flags
401 if { [string first "-x c" $extra_tool_flags ] != -1 } {
402 verbose -log "compiling and executing as C, not C++"
403 set edit_tool_flags $extra_tool_flags
404 regsub -all ".x c" $edit_tool_flags "" edit_tool_flags
405 lappend options "additional_flags=$edit_tool_flags"
406 set select_compile "v3_target_compile_as_c"
407 } else {
408 lappend options "additional_flags=$extra_tool_flags"
412 # There is a libstdc++_compile made for us by default (via the tool-
413 # and-target file), but the defaults are lacking in goodness.
414 set comp_output [$select_compile "$prog" "$output_file" "$compile_type" $options];
416 set unsupported_message [libstdc++_check_unsupported_p $comp_output]
417 if { $unsupported_message != "" } {
418 set comp_output "::unsupported::$unsupported_message"
421 return [list $comp_output $output_file]
424 # Override the DejaGnu dg-test in order to clear flags after a test, as
425 # is done for compiler tests in gcc-dg.exp.
427 if { [info procs saved-dg-test] == [list] } {
428 rename dg-test saved-dg-test
430 proc dg-test { args } {
431 global additional_prunes
432 global errorInfo
433 global testname_with_flags
435 if { [ catch { eval saved-dg-test $args } errmsg ] } {
436 set saved_info $errorInfo
437 set additional_prunes ""
438 if [info exists testname_with_flags] {
439 unset testname_with_flags
441 unset_timeout_vars
442 error $errmsg $saved_info
444 set additional_prunes ""
445 unset_timeout_vars
446 if [info exists testname_with_flags] {
447 unset testname_with_flags
452 # True if the library supports wchar_t.
453 set v3-wchar_t 0
455 # True if the library supports threads.
456 set v3-threads 0
458 # True if the library supports symbol versioning.
459 set v3-symver 0
461 # Called from libstdc++-dg-test above. Calls back into system's
462 # target_compile to actually do the work.
463 proc v3_target_compile { source dest type options } {
464 global gluefile
465 global wrap_flags
466 global cxx
467 global cxxflags
468 global cxxvtvflags
469 global cxxldflags
470 global includes
471 global STATIC_LIBCXXFLAGS
472 global tool
474 lappend options "additional_flags=-fno-diagnostics-show-caret -fdiagnostics-color=never"
476 if { [target_info needs_status_wrapper] != "" && [info exists gluefile] } {
477 lappend options "libs=${gluefile}"
478 lappend options "ldflags=${wrap_flags}"
481 set cxx_final $cxx
482 set cxxlibglossflags [libgloss_link_flags]
483 set cxx_final [concat $cxx_final $cxxlibglossflags]
484 set cxx_final [concat $cxx_final $STATIC_LIBCXXFLAGS]
485 set cxx_final [concat $cxx_final $cxxflags]
486 set cxx_final [concat $cxx_final $cxxvtvflags]
487 set cxx_final [concat $cxx_final $includes]
489 # Flag setting based on type argument.
490 if { $type == "executable" } {
491 # Link the support objects into executables.
492 lappend options "additional_flags=./libtestc++.a $cxxldflags"
493 } else {
494 if { $type == "sharedlib" } {
495 # Don't link in anything.
496 set type "executable"
500 lappend options "compiler=$cxx_final"
501 lappend options "timeout=[timeout_value]"
503 set comp_output [target_compile $source $dest $type $options]
505 return $comp_output
509 # Called from libstdc++-dg-test above, but only for "C" compilation.
510 # Calls back into system's target_compile to actually do the work.
511 proc v3_target_compile_as_c { source dest type options } {
512 global gluefile
513 global wrap_flags
514 global includes
515 global flags_file
516 global blddir
517 global cc
518 global cxxflags
519 global STATIC_LIBCXXFLAGS
520 global tool
522 if { [target_info needs_status_wrapper] != "" && [info exists gluefile] } {
523 lappend options "libs=${gluefile}"
524 lappend options "ldflags=${wrap_flags}"
527 set tname [target_info name]
528 set cc_final $cc
529 set cxxlibglossflags [libgloss_link_flags]
530 set cc_final [concat $cc_final $cxxlibglossflags]
531 set cc_final [concat $cc_final $STATIC_LIBCXXFLAGS]
532 set cc_final [concat $cc_final $cxxflags]
533 set cc_final [concat $cc_final $includes]
534 regsub -all {\s[-]nostdinc[+][+]} $cc_final "" cc_final
536 # This is needed for "C" tests, as this type of test may need the
537 # C++ includes. And if we're not testing in the build directory,
538 # the includes variable is not likely to include the necessary
539 # info.
540 if { ![file exists $flags_file] } {
541 # ??? We need a --print-include-dirs option to GCC, so that
542 # we can avoid these hacks. The heuristics here will not
543 # work with non-standard --with-includedir= options.
544 set version [remote_exec host ${cc} -dumpversion]
545 # Remove the trailing newline from the output.
546 set version [string trimright [lindex $version 1]]
547 set machine [remote_exec host ${cc} -dumpmachine]
548 set machine [string trimright [lindex $machine 1]]
549 set comp_base_dir [remote_exec host ${cc} --print-prog-name=cc1]
550 set comp_base_dir [lindex $comp_base_dir 1]
551 set comp_base_dir [file dirname [file dirname [file dirname [file dirname [file dirname $comp_base_dir]]]]]
552 # For a cross compiler, the header files will be located in a
553 # machine-specific subdirectory.
554 set crossbase "${comp_base_dir}/${machine}/include/c++/${version}"
555 set crosstarget "${crossbase}/${machine}"
556 set cc_final [concat $cc_final "-I$crossbase -I$crosstarget"]
557 # For a native compiler, the header files will be located at
558 # the top level.
559 set includesbase "${comp_base_dir}/include/c++/${version}"
560 set includestarget "${includesbase}/${machine}"
561 set cc_final [concat $cc_final "-I$includesbase -I$includestarget"]
563 set libdir "-L${comp_base_dir}/lib"
564 } else {
565 set libdir "-L${blddir}/libsupc++/.libs"
566 set libdir [concat $libdir "-L${blddir}/src/.libs"]
569 set cc_final [concat $cc_final "$libdir"]
571 lappend options "compiler=$cc_final"
572 lappend options "timeout=[timeout_value]"
574 set comp_output [target_compile $source $dest $type $options]
576 return $comp_output
579 # Build the support objects linked in with the libstdc++ tests. In
580 # addition, set v3-wchar_t, v3-threads, and v3-symver appropriately.
581 proc v3-build_support { } {
582 global env
583 global srcdir
584 global v3-wchar_t
585 global v3-threads
586 global v3-symver
587 global v3-sharedlib
589 # Figure out whether or not the library supports certain features.
590 set v3-wchar_t 0
591 set v3-threads 0
592 set v3-symver 0
593 set libtest_objs ""
595 set config_src "config.cc"
596 set config_out "config.ii"
597 set f [open $config_src "w"]
598 puts $f "#include <bits/c++config.h>"
599 puts $f "#include <bits/gthr.h>"
600 close $f
601 v3_target_compile $config_src $config_out preprocess "additional_flags=-dN"
602 set file [open $config_out r]
603 set preprocessed [read $file]
604 close $file
605 if { [string first "_GLIBCXX_USE_WCHAR_T" $preprocessed] != -1 } {
606 verbose -log "wchar_t support detected"
607 set v3-wchar_t 1
609 if { [string first "_GLIBCXX_SYMVER" $preprocessed] != -1 } {
610 verbose -log "symbol versioning support detected"
611 set v3-symver 1
613 if { [string first "__GTHREADS" $preprocessed] != -1 } {
614 verbose -log "thread support detected"
615 set v3-threads 1
618 # Try to build the MO files that are used by some of the locale
619 # tests. If we can't build them, that's OK; it just means that
620 # those tests will fail.
621 foreach lang [list "fr" "de"] {
622 catch {
623 file mkdir "$lang/LC_MESSAGES"
624 remote_exec "build" "msgfmt" "-o $lang/LC_MESSAGES/libstdc++.mo $srcdir/../po/$lang.po"
625 if [is_remote host] {
626 remote_exec "host" "mkdir" "-p $lang/LC_MESSAGES"
627 remote_download "host" "$lang/LC_MESSAGES/libstdc++.mo" "$lang/LC_MESSAGES/libstdc++.mo"
632 # Build the support objects.
633 set source_files [list testsuite_abi.cc testsuite_allocator.cc \
634 testsuite_character.cc testsuite_hooks.cc \
635 io/verified_cmd_line_input.cc \
636 io/prog_bar.cc performance/time/elapsed_timer.cc ]
637 foreach f $source_files {
638 set obj [file rootname $f].o
639 set object_file [file tail $obj]
640 # Compile with "-w" so that warnings issued by the compiler
641 # do not prevent compilation.
642 # Disable LTO so that ar/ranlib don't need the LTO plugin.
643 if { [v3_target_compile $srcdir/util/$f $object_file "object" \
644 [list "incdir=$srcdir" "additional_flags=-w -fno-lto"]]
645 != "" } {
646 error "could not compile $f"
648 append libtest_objs "$object_file "
651 # Collect into libtestc++.a
652 if [info exists env(AR)] {
653 set ar $env(AR)
654 } else {
655 set ar [transform "ar"]
657 set arargs "-rc ./libtestc++.a ${libtest_objs}"
658 verbose -log "$ar $arargs"
659 set result [lindex [remote_exec host "$ar" "$arargs"] 0]
660 verbose "link result is $result"
661 if { $result == 0 } {
662 if [info exists env(RANLIB)] {
663 set ranlib $env(RANLIB)
664 } else {
665 set ranlib [transform "ranlib"]
667 set ranlibargs "./libtestc++.a"
668 verbose -log "$ranlib $ranlibargs"
669 set result [lindex [remote_exec host "$ranlib" "$ranlibargs"] 0]
670 if { $result != 0 } {
671 error "could not link libtestc++.a"
675 # Build any shared objects needed for regression testing.
676 if { ${v3-sharedlib} == 1 } {
677 set source_files [list testsuite_shared.cc]
678 foreach f $source_files {
679 set object_file [file rootname $f].so
680 # Compile with "-w" so that warnings issued by the compiler
681 # do not prevent compilation.
682 if { [v3_target_compile $srcdir/util/$f $object_file "sharedlib" \
683 [list "incdir=$srcdir" "additional_flags=-fno-inline -w -shared -fPIC -DPIC -std=gnu++98"]]
684 != "" } {
685 error "could not compile $f"
691 proc check_v3_target_fileio { } {
692 global et_fileio_saved
693 global et_fileio_target_name
694 global tool
695 global srcdir
697 if { ![info exists et_fileio_target_name] } {
698 set et_fileio_target_name ""
701 # If the target has changed since we set the cached value, clear it.
702 set current_target [current_target_name]
703 if { $current_target != $et_fileio_target_name } {
704 verbose "check_v3_target_fileio: `$et_fileio_target_name'" 2
705 set et_fileio_target_name $current_target
706 if [info exists et_fileio_saved] {
707 verbose "check_v3_target_fileio: removing cached result" 2
708 unset et_fileio_saved
712 if [info exists et_fileio_saved] {
713 verbose "check_v3_target_fileio: using cached result" 2
714 } else {
715 set et_fileio_saved 0
717 # Set up, compile, and execute a C++ test program that tries to use
718 # the file functions
719 set src fileio[pid].cc
720 set exe fileio[pid].x
721 set testfile "cin_unget-1.[pid].txt"
722 v3-copy-file "$srcdir/data/cin_unget-1.txt" "$testfile"
724 set f [open $src "w"]
725 puts $f "#include <sys/types.h>"
726 puts $f "#include <sys/stat.h>"
727 puts $f "#include <fcntl.h>"
728 puts $f "#include <unistd.h>"
729 puts $f "#include <errno.h>"
730 puts $f "#include <string.h>"
731 puts $f "using namespace std;"
732 puts $f "int main ()"
733 puts $f "{"
734 puts $f " int fd = open (\"$testfile\", O_RDONLY);"
735 puts $f " int ret = 0;"
736 puts $f " char buf\[10\];"
737 puts $f " if (fd == -1)"
738 puts $f " ret = 1;"
739 puts $f " else"
740 puts $f " {"
741 puts $f " if (lseek (fd, -1, SEEK_CUR) != -1 || errno != EINVAL)"
742 puts $f " ret = 1;"
743 puts $f " errno = 0;"
744 puts $f " if (lseek (fd, 0, SEEK_CUR) != 0"
745 puts $f " || read (fd, buf, 4) != 4"
746 puts $f " || memcmp (buf, \"1234\", 4) != 0"
747 puts $f " || lseek (fd, -2, SEEK_CUR) != 2"
748 puts $f " || read (fd, buf, 2) != 2"
749 puts $f " || memcmp (buf, \"34\", 2) != 0)"
750 puts $f " ret = 1;"
751 puts $f " close (fd);"
752 puts $f " }"
753 puts $f " return ret;"
754 puts $f "}"
755 close $f
757 set lines [v3_target_compile $src $exe executable ""]
758 file delete $src
760 if [string match "" $lines] {
761 # No error message, compilation succeeded.
762 set result [${tool}_load "./$exe" "" ""]
763 set status [lindex $result 0]
764 remote_file build delete $exe
766 verbose "check_v3_target_fileio: status is <$status>" 2
768 if { $status == "pass" } {
769 set et_fileio_saved 1
771 } else {
772 verbose "check_v3_target_fileio: compilation failed" 2
775 return $et_fileio_saved
778 # Eventually we want C90/C99 determining and switching from this.
779 proc check_v3_target_c_std { } {
780 global et_c_std_saved
781 global et_c_std_target_name
782 global tool
784 if { ![info exists et_c_std_target_name] } {
785 set et_c_std_target_name ""
788 # If the target has changed since we set the cached value, clear it.
789 set current_target [current_target_name]
790 if { $current_target != $et_c_std_target_name } {
791 verbose "check_v3_target_c_std: `$et_c_std_target_name'" 2
792 set et_c_std_target_name $current_target
793 if [info exists et_c_std_saved] {
794 verbose "check_v3_target_c_std: removing cached result" 2
795 unset et_c_std_saved
799 if [info exists et_c_std_saved] {
800 verbose "check_v3_target_c_std: using cached result" 2
801 } else {
802 set et_c_std_saved 0
804 # Set up, compile, and execute a C++ test program that tries to use
805 # C99 functionality.
806 # For math bits, could use check_effective_target_c99_math.
807 set src fileio[pid].cc
808 set exe fileio[pid].x
810 set f [open $src "w"]
811 puts $f "#include <tr1/cmath>"
812 puts $f "#include <cstdlib>"
813 puts $f "int main ()"
814 puts $f "{"
815 puts $f " float f = 45.55;"
816 puts $f " int i = std::tr1::isnan(f);"
817 puts $f " "
818 puts $f " using std::wctomb;"
819 puts $f " return i;"
820 puts $f "}"
821 close $f
823 set lines [v3_target_compile $src $exe executable ""]
824 file delete $src
826 if [string match "" $lines] {
827 # No error message, compilation succeeded.
828 set result [${tool}_load "./$exe" "" ""]
829 set status [lindex $result 0]
830 remote_file build delete $exe
832 verbose "check_v3_target_c_std: status is <$status>" 2
834 if { $status == "pass" } {
835 set et_c_std_saved 1
837 } else {
838 verbose "check_v3_target_c_std: compilation failed" 2
841 return $et_c_std_saved
844 proc check_v3_target_sharedlib { } {
845 global v3-sharedlib
846 return ${v3-sharedlib}
849 proc check_v3_target_time { } {
850 global et_time_saved
851 global et_time_target_name
852 global tool
854 if { ![info exists et_time_target_name] } {
855 set et_time_target_name ""
858 # If the target has changed since we set the cached value, clear it.
859 set current_target [current_target_name]
860 if { $current_target != $et_time_target_name } {
861 verbose "check_v3_target_time: `$et_time_target_name'" 2
862 set et_time_target_name $current_target
863 if [info exists et_time_saved] {
864 verbose "check_v3_target_time: removing cached result" 2
865 unset et_time_saved
869 if [info exists et_time_saved] {
870 verbose "check_v3_target_time: using cached result" 2
871 } else {
872 set et_time_saved 0
874 # Set up and compile a C++ test program that tries to use
875 # the time function
876 set src time[pid].cc
878 set f [open $src "w"]
879 puts $f "#include <time.h>"
880 puts $f "using namespace std;"
881 puts $f "int main ()"
882 puts $f "{"
883 puts $f " time (0);"
884 puts $f "}"
885 close $f
887 set lines [v3_target_compile $src /dev/null executable ""]
888 file delete $src
890 if [string match "" $lines] {
891 # No error message, compilation succeeded.
892 verbose "check_v3_target_time: compilation succeeded" 2
893 set et_time_saved 1
894 } else {
895 verbose "check_v3_target_time: compilation failed" 2
898 return $et_time_saved
901 proc check_v3_target_namedlocale { args } {
902 global et_namedlocale
903 global tool
905 set et_namedlocale 0
907 # Set up, compile, and execute a C++ test program that tries to use
908 # the required named locale.
909 set exe nlocale[pid].x
911 if ![file exists ./$exe] {
912 set src nlocale[pid].cc
914 set f [open $src "w"]
915 puts $f "#include <locale>"
916 puts $f "#include <cstdio>"
917 puts $f "#include <cstring>"
918 puts $f "using namespace std;"
919 puts $f "char *transform_locale(const char *name)"
920 puts $f "{"
921 puts $f " char *result = new char\[50\];"
922 puts $f " strcpy(result, name);"
923 puts $f "#if defined __FreeBSD__ || defined __DragonFly__ || defined __NetBSD__"
924 puts $f " /* fall-through */"
925 puts $f "#else"
926 puts $f " if (strstr(result, \"ISO8859-15\")) {"
927 puts $f " strcat(result, \"@euro\");"
928 puts $f " }"
929 puts $f "#endif"
930 puts $f " return result;"
931 puts $f "}"
932 puts $f "int main (int argc, char** argv)"
933 puts $f "{"
934 puts $f " if (argc < 2)"
935 puts $f " {"
936 puts $f " printf(\"locale support test not supported\\n\");"
937 puts $f " return 1;"
938 puts $f " }"
939 puts $f " const char *namedloc = transform_locale(*(argv + 1));"
940 puts $f " try"
941 puts $f " {"
942 puts $f " locale((const char*)namedloc);"
943 puts $f " delete\[\] namedloc;"
944 puts $f " return 0;"
945 puts $f " }"
946 puts $f " catch(...)"
947 puts $f " {"
948 puts $f " printf(\"locale '%s' not supported\\n\", namedloc);"
949 puts $f " delete\[\] namedloc;"
950 puts $f " return 1;"
951 puts $f " }"
952 puts $f "}"
953 close $f
955 set lines [v3_target_compile $src $exe executable ""]
956 file delete $src
958 if ![string match "" $lines] {
959 verbose "check_v3_target_namedlocale: compilation failed" 2
960 return $et_namedlocale
962 # else No error message, compilation succeeded.
965 set result [${tool}_load "./$exe" "$args" ""]
966 set status [lindex $result 0]
968 verbose "check_v3_target_namedlocale <$args>: status is <$status>" 2
970 if { $status == "pass" } {
971 set et_namedlocale 1
973 return $et_namedlocale
976 proc check_v3_target_debug_mode { } {
977 global et_debug_mode
978 global tool
980 if { ![info exists et_debug_mode_target_name] } {
981 set et_debug_mode_target_name ""
984 # If the target has changed since we set the cached value, clear it.
985 set current_target [current_target_name]
986 if { $current_target != $et_debug_mode_target_name } {
987 verbose "check_v3_target_debug_mode: `$et_debug_mode_target_name'" 2
988 set et_debug_mode_target_name $current_target
989 if [info exists et_debug_mode] {
990 verbose "check_v3_target_debug_mode: removing cached result" 2
991 unset et_debug_mode
995 if [info exists et_debug_mode] {
996 verbose "check_v3_target_debug_mode: using cached result" 2
997 } else {
998 set et_debug_mode 0
1000 # Set up and preprocess a C++ test program that depends
1001 # on debug mode activated.
1002 set src debug_mode[pid].cc
1004 set f [open $src "w"]
1005 puts $f "#ifndef _GLIBCXX_DEBUG"
1006 puts $f "# error No debug mode"
1007 puts $f "#endif"
1008 close $f
1010 set lines [v3_target_compile $src /dev/null preprocess ""]
1011 file delete $src
1013 if [string match "" $lines] {
1014 # No error message, preprocessing succeeded.
1015 set et_debug_mode 1
1018 verbose "check_v3_target_debug_mode: $et_debug_mode" 2
1019 return $et_debug_mode
1022 proc check_v3_target_profile_mode { } {
1023 global et_profile_mode
1024 global tool
1026 if { ![info exists et_profile_mode_target_name] } {
1027 set et_profile_mode_target_name ""
1030 # If the target has changed since we set the cached value, clear it.
1031 set current_target [current_target_name]
1032 if { $current_target != $et_profile_mode_target_name } {
1033 verbose "check_v3_target_profile_mode: `$et_profile_mode_target_name'" 2
1034 set et_profile_mode_target_name $current_target
1035 if [info exists et_profile_mode] {
1036 verbose "check_v3_target_profile_mode: removing cached result" 2
1037 unset et_profile_mode
1041 if [info exists et_profile_mode] {
1042 verbose "check_v3_target_profile_mode: using cached result" 2
1043 } else {
1044 set et_profile_mode 0
1046 # Set up and preprocess a C++ test program that depends
1047 # on profile mode activated.
1048 set src profile_mode[pid].cc
1050 set f [open $src "w"]
1051 puts $f "#ifndef _GLIBCXX_PROFILE"
1052 puts $f "# error No profile mode"
1053 puts $f "#endif"
1054 close $f
1056 set lines [v3_target_compile $src /dev/null preprocess ""]
1057 file delete $src
1059 if [string match "" $lines] {
1060 # No error message, preprocessing succeeded.
1061 set et_profile_mode 1
1064 verbose "check_v3_target_profile_mode: $et_profile_mode" 2
1065 return $et_profile_mode
1068 proc check_v3_target_normal_mode { } {
1069 global et_normal_mode
1070 global tool
1072 if { ![info exists et_normal_mode_target_name] } {
1073 set et_normal_mode_target_name ""
1076 # If the target has changed since we set the cached value, clear it.
1077 set current_target [current_target_name]
1078 if { $current_target != $et_normal_mode_target_name } {
1079 verbose "check_v3_target_normal_mode: `$et_normal_mode_target_name'" 2
1080 set et_normal_mode_target_name $current_target
1081 if [info exists et_normal_mode] {
1082 verbose "check_v3_target_normal_mode: removing cached result" 2
1083 unset et_normal_mode
1087 if [info exists et_normal_mode] {
1088 verbose "check_v3_target_normal_mode: using cached result" 2
1089 } else {
1090 set et_normal_mode 0
1092 # Set up and compile a C++ test program that depends
1093 # on normal mode activated.
1094 set src normal_mode[pid].cc
1096 set f [open $src "w"]
1097 puts $f "#include <bits/c++config.h>"
1098 puts $f "#if defined(_GLIBCXX_DEBUG) || \\"
1099 puts $f " defined(_GLIBCXX_PROFILE) || \\"
1100 puts $f " defined(_GLIBCXX_PARALLEL)"
1101 puts $f "# error No normal mode"
1102 puts $f "#endif"
1103 close $f
1105 set lines [v3_target_compile $src /dev/null preprocess ""]
1106 file delete $src
1108 if [string match "" $lines] {
1109 # No error message, compilation succeeded.
1110 set et_normal_mode 1
1113 verbose "check_v3_target_normal_mode: $et_normal_mode" 2
1114 return $et_normal_mode
1117 proc check_v3_target_normal_namespace { } {
1118 global et_normal_namespace
1119 global tool
1121 if { ![info exists et_normal_namespace_target_name] } {
1122 set et_normal_namespace_target_name ""
1125 # If the target has changed since we set the cached value, clear it.
1126 set current_target [current_target_name]
1127 if { $current_target != $et_normal_namespace_target_name } {
1128 verbose "check_v3_target_normal_namespace: `$et_normal_namespace_target_name'" 2
1129 set et_normal_namespace_target_name $current_target
1130 if [info exists et_normal_namespace] {
1131 verbose "check_v3_target_normal_namespace: removing cached result" 2
1132 unset et_normal_namespace
1136 if [info exists et_normal_namespace] {
1137 verbose "check_v3_target_normal_namespace: using cached result" 2
1138 } else {
1139 set et_normal_namespace 0
1141 # Set up and compile a C++ test program that depends
1142 # on normal std namespace.
1143 set src normal_namespace[pid].cc
1145 set f [open $src "w"]
1146 puts $f "#include <bits/c++config.h>"
1147 puts $f "#if _GLIBCXX_INLINE_VERSION"
1148 puts $f "# error No normal namespace"
1149 puts $f "#endif"
1150 close $f
1152 set lines [v3_target_compile $src /dev/null preprocess ""]
1153 file delete $src
1155 if [string match "" $lines] {
1156 # No error message, compilation succeeded.
1157 set et_normal_namespace 1
1160 verbose "check_v3_target_normal_namespace: $et_normal_namespace" 2
1161 return $et_normal_namespace
1164 proc check_v3_target_parallel_mode { } {
1165 global cxxflags
1166 global v3-libgomp
1167 global et_parallel_mode
1169 global tool
1171 if { ![info exists et_parallel_mode_target_name] } {
1172 set et_parallel_mode_target_name ""
1175 # If the target has changed since we set the cached value, clear it.
1176 set current_target [current_target_name]
1177 if { $current_target != $et_parallel_mode_target_name } {
1178 verbose "check_v3_target_parallel_mode: `$et_parallel_mode_target_name'" 2
1179 set et_parallel_mode_target_name $current_target
1180 if [info exists et_parallel_mode] {
1181 verbose "check_v3_target_parallel_mode: removing cached result" 2
1182 unset et_parallel_mode
1186 if [info exists et_parallel_mode] {
1187 verbose "check_v3_target_parallel_mode: using cached result" 2
1188 } else {
1189 set et_parallel_mode 0
1191 # If 'make check-parallel' is running the test succeeds.
1192 if { ${v3-libgomp} == 1 && [regexp "libgomp" $cxxflags] } {
1193 set et_parallel_mode 1
1196 verbose "check_v3_target_parallel_mode: $et_parallel_mode" 2
1197 return $et_parallel_mode
1200 proc check_v3_target_cstdint { } {
1201 global cxxflags
1202 global DEFAULT_CXXFLAGS
1203 global et_cstdint
1205 global tool
1207 if { ![info exists et_cstdint_target_name] } {
1208 set et_cstdint_target_name ""
1211 # If the target has changed since we set the cached value, clear it.
1212 set current_target [current_target_name]
1213 if { $current_target != $et_cstdint_target_name } {
1214 verbose "check_v3_target_cstdint: `$et_cstdint_target_name'" 2
1215 set et_cstdint_target_name $current_target
1216 if [info exists et_cstdint] {
1217 verbose "check_v3_target_cstdint: removing cached result" 2
1218 unset et_cstdint
1222 if [info exists et_cstdint] {
1223 verbose "check_v3_target_cstdint: using cached result" 2
1224 } else {
1225 set et_cstdint 0
1227 # Set up and preprocess a C++0x test program that depends
1228 # on the C99 stdint facilities to be available.
1229 set src cstdint[pid].cc
1231 set f [open $src "w"]
1232 puts $f "#include <tr1/cstdint>"
1233 puts $f "#ifndef _GLIBCXX_USE_C99_STDINT_TR1"
1234 puts $f "# error No C99 stdint"
1235 puts $f "#endif"
1236 close $f
1238 set cxxflags_saved $cxxflags
1239 set cxxflags "$cxxflags $DEFAULT_CXXFLAGS -Werror"
1241 set lines [v3_target_compile $src /dev/null preprocess ""]
1242 set cxxflags $cxxflags_saved
1243 file delete $src
1245 if [string match "" $lines] {
1246 # No error message, preprocess succeeded.
1247 set et_cstdint 1
1248 } else {
1249 verbose "check_v3_target_cstdint: compilation failed" 2
1252 verbose "check_v3_target_cstdint: $et_cstdint" 2
1253 return $et_cstdint
1256 proc check_v3_target_cmath { } {
1257 global cxxflags
1258 global DEFAULT_CXXFLAGS
1259 global et_c99_math
1261 global tool
1263 if { ![info exists et_c99_math_target_name] } {
1264 set et_c99_math_target_name ""
1267 # If the target has changed since we set the cached value, clear it.
1268 set current_target [current_target_name]
1269 if { $current_target != $et_c99_math_target_name } {
1270 verbose "check_v3_target_c99_math: `$et_c99_math_target_name'" 2
1271 set et_c99_math_target_name $current_target
1272 if [info exists et_c99_math] {
1273 verbose "check_v3_target_c99_math: removing cached result" 2
1274 unset et_c99_math
1278 if [info exists et_c99_math] {
1279 verbose "check_v3_target_c99_math: using cached result" 2
1280 } else {
1281 set et_c99_math 0
1283 # Set up and preprocess a C++0x test program that depends
1284 # on the C99 math facilities to be available.
1285 set src c99_math[pid].cc
1287 set f [open $src "w"]
1288 puts $f "#include <tr1/cmath>"
1289 puts $f "#ifndef _GLIBCXX_USE_C99_MATH_TR1"
1290 puts $f "# error No C99 math"
1291 puts $f "#endif"
1292 close $f
1294 set cxxflags_saved $cxxflags
1295 set cxxflags "$cxxflags $DEFAULT_CXXFLAGS -Werror"
1297 set lines [v3_target_compile $src /dev/null preprocess ""]
1298 set cxxflags $cxxflags_saved
1299 file delete $src
1301 if [string match "" $lines] {
1302 # No error message, preprocess succeeded.
1303 set et_c99_math 1
1304 } else {
1305 verbose "check_v3_target_c99_math: compilation failed" 2
1308 verbose "check_v3_target_c99_math: $et_c99_math" 2
1309 return $et_c99_math
1312 proc check_v3_target_thread_fence { } {
1313 global cxxflags
1314 global DEFAULT_CXXFLAGS
1315 global et_thread_fence
1317 global tool
1319 if { ![info exists et_thread_fence_target_name] } {
1320 set et_thread_fence_target_name ""
1323 # If the target has changed since we set the cached value, clear it.
1324 set current_target [current_target_name]
1325 if { $current_target != $et_thread_fence_target_name } {
1326 verbose "check_v3_target_thread_fence: `$et_thread_fence_target_name'" 2
1327 set et_thread_fence_target_name $current_target
1328 if [info exists et_thread_fence] {
1329 verbose "check_v3_target_thread_fence: removing cached result" 2
1330 unset et_thread_fence
1334 if [info exists et_thread_fence] {
1335 verbose "check_v3_target_thread_fence: using cached result" 2
1336 } else {
1337 set et_thread_fence 0
1339 # Set up and preprocess a C++11 test program that depends
1340 # on the thread fence to be available.
1341 set src thread_fence[pid].cc
1343 set f [open $src "w"]
1344 puts $f "int main() {"
1345 puts $f "__atomic_thread_fence (__ATOMIC_SEQ_CST);"
1346 puts $f "return 0;"
1347 puts $f "}"
1348 close $f
1350 set cxxflags_saved $cxxflags
1351 set cxxflags "$cxxflags $DEFAULT_CXXFLAGS -Werror -std=gnu++11"
1353 set lines [v3_target_compile $src /dev/null executable ""]
1354 set cxxflags $cxxflags_saved
1355 file delete $src
1357 if [string match "" $lines] {
1358 # No error message, linking succeeded.
1359 set et_thread_fence 1
1360 } else {
1361 verbose "check_v3_target_thread_fence: compilation failed" 2
1364 verbose "check_v3_target_thread_fence: $et_thread_fence" 2
1365 return $et_thread_fence
1368 proc check_v3_target_atomic_builtins { } {
1369 global cxxflags
1370 global DEFAULT_CXXFLAGS
1371 global et_atomic_builtins
1373 global tool
1375 if { ![info exists et_atomic_builtins_target_name] } {
1376 set et_atomic_builtins_target_name ""
1379 # If the target has changed since we set the cached value, clear it.
1380 set current_target [current_target_name]
1381 if { $current_target != $et_atomic_builtins_target_name } {
1382 verbose "check_v3_target_atomic_builtins: `$et_atomic_builtins_target_name'" 2
1383 set et_atomic_builtins_target_name $current_target
1384 if [info exists et_atomic_builtins] {
1385 verbose "check_v3_target_atomic_builtins: removing cached result" 2
1386 unset et_atomic_builtins
1390 if [info exists et_atomic_builtins] {
1391 verbose "check_v3_target_atomic_builtins: using cached result" 2
1392 } else {
1393 set et_atomic_builtins 0
1395 # Set up and preprocess a C++11 test program that depends
1396 # on the atomic builtin facilities to be available.
1397 set src atomic_builtins[pid].cc
1399 set f [open $src "w"]
1400 puts $f "#if __GCC_ATOMIC_BOOL_LOCK_FREE < 2"
1401 puts $f "# error No atomic bool"
1402 puts $f "#endif"
1403 puts $f "#if __GCC_ATOMIC_INT_LOCK_FREE < 2"
1404 puts $f "# error No atomic int"
1405 puts $f "#endif"
1406 close $f
1408 set cxxflags_saved $cxxflags
1409 set cxxflags "$cxxflags $DEFAULT_CXXFLAGS -Werror -std=gnu++11"
1411 set lines [v3_target_compile $src /dev/null preprocess ""]
1412 set cxxflags $cxxflags_saved
1413 file delete $src
1415 if [string match "" $lines] {
1416 # No error message, preprocess succeeded.
1417 set et_atomic_builtins 1
1418 } else {
1419 verbose "check_v3_target_atomic_builtins: compilation failed" 2
1422 verbose "check_v3_target_atomic_builtins: $et_atomic_builtins" 2
1423 return $et_atomic_builtins
1426 proc check_v3_target_gthreads { } {
1427 global cxxflags
1428 global DEFAULT_CXXFLAGS
1429 global et_gthreads
1431 global tool
1433 if { ![info exists et_gthreads_target_name] } {
1434 set et_gthreads_target_name ""
1437 # If the target has changed since we set the cached value, clear it.
1438 set current_target [current_target_name]
1439 if { $current_target != $et_gthreads_target_name } {
1440 verbose "check_v3_target_gthreads: `$et_gthreads_target_name'" 2
1441 set et_gthreads_target_name $current_target
1442 if [info exists et_gthreads] {
1443 verbose "check_v3_target_gthreads: removing cached result" 2
1444 unset et_gthreads
1448 if [info exists et_gthreads] {
1449 verbose "check_v3_target_gthreads: using cached result" 2
1450 } else {
1451 set et_gthreads 0
1453 # Set up and preprocess a C++0x test program that depends
1454 # on the gthreads facilities to be available.
1455 set src gthreads[pid].cc
1457 set f [open $src "w"]
1458 puts $f "#include <bits/c++config.h>"
1459 puts $f "#ifndef _GLIBCXX_HAS_GTHREADS"
1460 puts $f "# error No gthread"
1461 puts $f "#endif"
1462 close $f
1464 set cxxflags_saved $cxxflags
1465 set cxxflags "$cxxflags $DEFAULT_CXXFLAGS -Werror"
1467 set lines [v3_target_compile $src /dev/null preprocess ""]
1468 set cxxflags $cxxflags_saved
1469 file delete $src
1471 if [string match "" $lines] {
1472 # No error message, preprocessing succeeded.
1473 set et_gthreads 1
1474 } else {
1475 verbose "check_v3_target_gthreads: compilation failed" 2
1478 verbose "check_v3_target_gthreads: $et_gthreads" 2
1479 return $et_gthreads
1482 proc check_v3_target_gthreads_timed { } {
1483 global cxxflags
1484 global DEFAULT_CXXFLAGS
1485 global et_gthreads_timed
1487 global tool
1489 if { ![info exists et_gthreads_timed_target_name] } {
1490 set et_gthreads_timed_target_name ""
1493 # If the target has changed since we set the cached value, clear it.
1494 set current_target [current_target_name]
1495 if { $current_target != $et_gthreads_timed_target_name } {
1496 verbose "check_v3_target_gthreads_timed: `$et_gthreads_timed_target_name'" 2
1497 set et_gthreads_timed_target_name $current_target
1498 if [info exists et_gthreads_timed] {
1499 verbose "check_v3_target_gthreads_timed: removing cached result" 2
1500 unset et_gthreads_timed
1504 if [info exists et_gthreads_timed] {
1505 verbose "check_v3_target_gthreads_timed: using cached result" 2
1506 } else {
1507 set et_gthreads_timed 0
1509 # Set up and preprocess a C++0x test program that depends
1510 # on the gthreads timed mutex facilities to be available.
1511 set src gthreads_timed[pid].cc
1513 set f [open $src "w"]
1514 puts $f "#include <bits/c++config.h>"
1515 puts $f "#ifndef _GLIBCXX_HAS_GTHREADS"
1516 puts $f "# error No gthread"
1517 puts $f "#endif"
1518 puts $f "#if !_GTHREAD_USE_MUTEX_TIMEDLOCK"
1519 puts $f "# error No gthread timed mutexes"
1520 puts $f "#endif"
1521 close $f
1523 set cxxflags_saved $cxxflags
1524 set cxxflags "$cxxflags $DEFAULT_CXXFLAGS -Werror"
1526 set lines [v3_target_compile $src /dev/null preprocess ""]
1527 set cxxflags $cxxflags_saved
1528 file delete $src
1530 if [string match "" $lines] {
1531 # No error message, preprocessing succeeded.
1532 set et_gthreads_timed 1
1533 } else {
1534 verbose "check_v3_target_gthreads_timed: compilation failed" 2
1537 verbose "check_v3_target_gthreads_timed: $et_gthreads_timed" 2
1538 return $et_gthreads_timed
1542 proc check_v3_target_sleep { } {
1543 global cxxflags
1544 global DEFAULT_CXXFLAGS
1545 global et_sleep
1547 global tool
1549 if { ![info exists et_sleep_target_name] } {
1550 set et_sleep_target_name ""
1553 # If the target has changed since we set the cached value, clear it.
1554 set current_target [current_target_name]
1555 if { $current_target != $et_sleep_target_name } {
1556 verbose "check_v3_target_sleep: `$et_sleep_target_name'" 2
1557 set et_sleep_target_name $current_target
1558 if [info exists et_sleep] {
1559 verbose "check_v3_target_sleep: removing cached result" 2
1560 unset et_sleep
1564 if [info exists et_sleep] {
1565 verbose "check_v3_target_sleep: using cached result" 2
1566 } else {
1567 set et_sleep 0
1569 # Set up and preprocess a C++11 test program that depends
1570 # on the sleep facilities to be available.
1571 set src sleep[pid].cc
1573 set f [open $src "w"]
1574 puts $f "#include <bits/c++config.h>"
1575 puts $f "#ifndef _GLIBCXX_USE_NANOSLEEP"
1576 puts $f "# ifndef _GLIBCXX_HAVE_SLEEP"
1577 puts $f "# error No nanosleep or sleep"
1578 puts $f "# endif"
1579 puts $f "#endif"
1580 close $f
1582 set cxxflags_saved $cxxflags
1583 set cxxflags "$cxxflags $DEFAULT_CXXFLAGS -Werror"
1585 set lines [v3_target_compile $src /dev/null preprocess ""]
1586 set cxxflags $cxxflags_saved
1587 file delete $src
1589 if [string match "" $lines] {
1590 # No error message, preprocessing succeeded.
1591 set et_sleep 1
1592 } else {
1593 verbose "check_v3_target_sleep: compilation failed" 2
1596 verbose "check_v3_target_sleep: $et_sleep" 2
1597 return $et_sleep
1600 proc check_v3_target_sched_yield { } {
1601 global cxxflags
1602 global DEFAULT_CXXFLAGS
1603 global et_sched_yield
1605 global tool
1607 if { ![info exists et_sched_yield_target_name] } {
1608 set et_sched_yield_target_name ""
1611 # If the target has changed since we set the cached value, clear it.
1612 set current_target [current_target_name]
1613 if { $current_target != $et_sched_yield_target_name } {
1614 verbose "check_v3_target_sched_yield: `$et_sched_yield_target_name'" 2
1615 set et_sched_yield_target_name $current_target
1616 if [info exists et_sched_yield] {
1617 verbose "check_v3_target_sched_yield: removing cached result" 2
1618 unset et_sched_yield
1622 if [info exists et_sched_yield] {
1623 verbose "check_v3_target_sched_yield: using cached result" 2
1624 } else {
1625 set et_sched_yield 0
1627 # Set up and preprocess a C++0x test program that depends
1628 # on the sched_yield facility to be available.
1629 set src sched_yield[pid].cc
1631 set f [open $src "w"]
1632 puts $f "#include <bits/c++config.h>"
1633 puts $f "#ifndef _GLIBCXX_USE_SCHED_YIELD"
1634 puts $f "# error No sched yield"
1635 puts $f "#endif"
1636 close $f
1638 set cxxflags_saved $cxxflags
1639 set cxxflags "$cxxflags $DEFAULT_CXXFLAGS -Werror"
1641 set lines [v3_target_compile $src /dev/null preprocess ""]
1642 set cxxflags $cxxflags_saved
1643 file delete $src
1645 if [string match "" $lines] {
1646 # No error message, preprocessing succeeded.
1647 set et_sched_yield 1
1648 } else {
1649 verbose "check_v3_target_sched_yield: compilation failed" 2
1652 verbose "check_v3_target_sched_yield: $et_sched_yield" 2
1653 return $et_sched_yield
1656 proc check_v3_target_string_conversions { } {
1657 global cxxflags
1658 global DEFAULT_CXXFLAGS
1659 global et_string_conversions
1661 global tool
1663 if { ![info exists et_string_conversions_target_name] } {
1664 set et_string_conversions_target_name ""
1667 # If the target has changed since we set the cached value, clear it.
1668 set current_target [current_target_name]
1669 if { $current_target != $et_string_conversions_target_name } {
1670 verbose "check_v3_target_string_conversions: `$et_string_conversions_target_name'" 2
1671 set et_string_conversions_target_name $current_target
1672 if [info exists et_string_conversions] {
1673 verbose "check_v3_target_string_conversions: removing cached result" 2
1674 unset et_string_conversions
1678 if [info exists et_string_conversions] {
1679 verbose "check_v3_target_string_conversions: using cached result" 2
1680 } else {
1681 set et_string_conversions 0
1683 # Set up and preprocess a C++0x test program that depends
1684 # on the string_conversions facilities to be available.
1685 set src string_conversions[pid].cc
1687 set f [open $src "w"]
1688 puts $f "#include <bits/c++config.h>"
1689 puts $f "#if !(_GLIBCXX_USE_C99_STDIO && _GLIBCXX_USE_C99_STDLIB && _GLIBCXX_USE_C99_WCHAR) || defined(_GLIBCXX_HAVE_BROKEN_VSWPRINTF)"
1690 puts $f "# error No string conversions"
1691 puts $f "#endif"
1692 close $f
1694 set cxxflags_saved $cxxflags
1695 set cxxflags "$cxxflags $DEFAULT_CXXFLAGS -Werror"
1697 set lines [v3_target_compile $src /dev/null preprocess ""]
1698 set cxxflags $cxxflags_saved
1699 file delete $src
1701 if [string match "" $lines] {
1702 # No error message, preprocessing succeeded.
1703 set et_string_conversions 1
1704 } else {
1705 verbose "check_v3_target_string_conversions: compilation failed" 2
1708 verbose "check_v3_target_string_conversions: $et_string_conversions" 2
1709 return $et_string_conversions
1712 proc check_v3_target_swprintf { } {
1713 global cxxflags
1714 global DEFAULT_CXXFLAGS
1715 global et_swprintf
1717 global tool
1719 if { ![info exists et_swprintf_target_name] } {
1720 set et_swprintf_target_name ""
1723 # If the target has changed since we set the cached value, clear it.
1724 set current_target [current_target_name]
1725 if { $current_target != $et_swprintf_target_name } {
1726 verbose "check_v3_target_swprintf: `$et_swprintf_target_name'" 2
1727 set et_swprintf_target_name $current_target
1728 if [info exists et_swprintf] {
1729 verbose "check_v3_target_swprintf: removing cached result" 2
1730 unset et_swprintf
1734 if [info exists et_swprintf] {
1735 verbose "check_v3_target_swprintf: using cached result" 2
1736 } else {
1737 set et_swprintf 0
1739 # Set up and preprocess a C++0x test program that depends
1740 # on a standard swprintf function to be available.
1741 set src swprintf[pid].cc
1743 set f [open $src "w"]
1744 puts $f "#include <bits/c++config.h>"
1745 puts $f "#if defined(_GLIBCXX_HAVE_BROKEN_VSWPRINTF)"
1746 puts $f "# error No swprintf"
1747 puts $f "#endif"
1748 close $f
1750 set cxxflags_saved $cxxflags
1751 set cxxflags "$cxxflags $DEFAULT_CXXFLAGS -Werror"
1753 set lines [v3_target_compile $src /dev/null preprocess ""]
1754 set cxxflags $cxxflags_saved
1755 file delete $src
1757 if [string match "" $lines] {
1758 # No error message, preprocessing succeeded.
1759 set et_swprintf 1
1760 } else {
1761 verbose "check_v3_target_swprintf: compilation failed" 2
1764 verbose "check_v3_target_swprintf: $et_swprintf" 2
1765 return $et_swprintf
1768 proc check_v3_target_binary_io { } {
1769 global cxxflags
1770 global DEFAULT_CXXFLAGS
1771 global et_binary_io
1773 global tool
1775 if { ![info exists et_binary_io_target_name] } {
1776 set et_binary_io_target_name ""
1779 # If the target has changed since we set the cached value, clear it.
1780 set current_target [current_target_name]
1781 if { $current_target != $et_binary_io_target_name } {
1782 verbose "check_v3_target_binary_io: `$et_binary_io_target_name'" 2
1783 set et_binary_io_target_name $current_target
1784 if [info exists et_binary_io] {
1785 verbose "check_v3_target_binary_io: removing cached result" 2
1786 unset et_binary_io
1790 if [info exists et_binary_io] {
1791 verbose "check_v3_target_binary_io: using cached result" 2
1792 } else {
1793 set et_binary_io 0
1795 # Set up and preprocess a C++0x test program that depends
1796 # on text and binary I/O being the same.
1797 set src binary_io[pid].cc
1799 set f [open $src "w"]
1800 puts $f "#include <bits/c++config.h>"
1801 puts $f "#if defined(_GLIBCXX_HAVE_DOS_BASED_FILESYSTEM)"
1802 puts $f "# error No binary io"
1803 puts $f "#endif"
1804 close $f
1806 set cxxflags_saved $cxxflags
1807 set cxxflags "$cxxflags $DEFAULT_CXXFLAGS -Werror"
1809 set lines [v3_target_compile $src /dev/null preprocess ""]
1810 set cxxflags $cxxflags_saved
1811 file delete $src
1813 if [string match "" $lines] {
1814 # No error message, preprocessing succeeded.
1815 set et_binary_io 1
1816 } else {
1817 verbose "check_v3_target_binary_io: compilation failed" 2
1820 verbose "check_v3_target_binary_io: $et_binary_io" 2
1821 return $et_binary_io
1824 proc check_v3_target_nprocs { } {
1825 global cxxflags
1826 global DEFAULT_CXXFLAGS
1827 global et_nprocs
1829 global tool
1831 if { ![info exists et_nprocs_target_name] } {
1832 set et_nprocs_target_name ""
1835 # If the target has changed since we set the cached value, clear it.
1836 set current_target [current_target_name]
1837 if { $current_target != $et_nprocs_target_name } {
1838 verbose "check_v3_target_nprocs: `$et_nprocs_target_name'" 2
1839 set et_nprocs_target_name $current_target
1840 if [info exists et_nprocs] {
1841 verbose "check_v3_target_nprocs: removing cached result" 2
1842 unset et_nprocs
1846 if [info exists et_nprocs] {
1847 verbose "check_v3_target_nprocs: using cached result" 2
1848 } else {
1849 set et_nprocs 0
1851 # Set up and preprocess a C++0x test program that depends
1852 # on either get_nprocs or sysconf to be available.
1853 set src nprocs[pid].cc
1855 set f [open $src "w"]
1856 puts $f "#include <bits/c++config.h>"
1857 puts $f "#if defined(_GLIBCXX_USE_GET_NPROCS)"
1858 puts $f "#elif defined(_GLIBCXX_USE_PTHREADS_NUM_PROCESSORS_NP)"
1859 puts $f "#elif defined(_GLIBCXX_USE_SYSCTL_HW_NCPU)"
1860 puts $f "#elif defined(_GLIBCXX_USE_SC_NPROCESSORS_ONLN)"
1861 puts $f "#elif defined(_GLIBCXX_USE_SC_NPROC_ONLN)"
1862 puts $f "#else"
1863 puts $f "# error hardware_concurrency not implemented"
1864 puts $f "#endif"
1865 close $f
1867 set cxxflags_saved $cxxflags
1868 set cxxflags "$cxxflags $DEFAULT_CXXFLAGS -Werror"
1870 set lines [v3_target_compile $src /dev/null preprocess ""]
1871 set cxxflags $cxxflags_saved
1872 file delete $src
1874 if [string match "" $lines] {
1875 # No error message, preprocess succeeded.
1876 set et_nprocs 1
1877 } else {
1878 verbose "check_v3_target_nprocs: compilation failed" 2
1881 verbose "check_v3_target_nprocs: $et_nprocs" 2
1882 return $et_nprocs
1885 proc check_v3_target_static_libstdcxx { } {
1886 global cxxflags
1887 global DEFAULT_CXXFLAGS
1888 global et_static_libstdcxx
1890 global tool
1892 if [info exists et_static_libstdcxx] {
1893 verbose "check_v3_target_static_libstdcxx: using cached result" 2
1894 } else {
1895 set et_static_libstdcxx 0
1897 # Set up and link a C++0x test program that depends
1898 # on static linking
1899 set src static-maybe[pid].cc
1901 set f [open $src "w"]
1902 puts $f "#include <iostream>"
1903 puts $f "int main() {"
1904 puts $f "int i(415);"
1905 puts $f "std::cout<< i << std::endl;"
1906 puts $f "return 0; }"
1907 puts $f ""
1908 close $f
1910 set cxxflags_saved $cxxflags
1911 set cxxflags "$cxxflags $DEFAULT_CXXFLAGS -static-libstdc++"
1913 set lines [v3_target_compile $src /dev/null executable ""]
1914 set cxxflags $cxxflags_saved
1915 file delete $src
1917 if [string match "" $lines] {
1918 # No error message, link succeeded.
1919 set et_static_libstdcxx 1
1920 } else {
1921 verbose "check_v3_target_static_libstdcxx: compilation failed" 2
1924 verbose "check_v3_target_static_libstdcxx: $et_static_libstdcxx" 2
1925 return $et_static_libstdcxx
1928 proc check_v3_target_little_endian { } {
1929 global cxxflags
1930 global DEFAULT_CXXFLAGS
1931 global et_little_endian
1933 global tool
1935 if { ![info exists et_little_endian_target_name] } {
1936 set et_little_endian_target_name ""
1939 # If the target has changed since we set the cached value, clear it.
1940 set current_target [current_target_name]
1941 if { $current_target != $et_little_endian_target_name } {
1942 verbose "check_v3_target_little_endian: `$et_little_endian_target_name'" 2
1943 set et_little_endian_target_name $current_target
1944 if [info exists et_little_endian] {
1945 verbose "check_v3_target_little_endian: removing cached result" 2
1946 unset et_little_endian
1950 if [info exists et_little_endian] {
1951 verbose "check_v3_target_little_endian: using cached result" 2
1952 } else {
1953 set et_little_endian 0
1955 set src little_endian[pid].cc
1957 set f [open $src "w"]
1958 puts $f "#if __BYTE_ORDER__ != __ORDER_LITTLE_ENDIAN__"
1959 puts $f "# error Not little endian"
1960 puts $f "#endif"
1961 close $f
1963 set cxxflags_saved $cxxflags
1964 set cxxflags "$cxxflags $DEFAULT_CXXFLAGS -Werror"
1966 set lines [v3_target_compile $src /dev/null preprocess ""]
1967 set cxxflags $cxxflags_saved
1968 file delete $src
1970 if [string match "" $lines] {
1971 # No error message, preprocessing succeeded.
1972 set et_little_endian 1
1973 } else {
1974 verbose "check_v3_target_little_endian: compilation failed" 2
1977 verbose "check_v3_target_little_endian: $et_little_endian" 2
1978 return $et_little_endian
1981 # Return 1 if the Filesystem TS is supported, 0 otherwise.
1982 # Cache the result.
1983 proc check_v3_target_filesystem_ts { } {
1984 global cxxflags
1985 global DEFAULT_CXXFLAGS
1986 global et_filesystem_ts
1987 global tool
1989 if { ![info exists et_filesystem_ts_target_name] } {
1990 set et_filesystem_ts_target_name ""
1993 # If the target has changed since we set the cached value, clear it.
1994 set current_target [current_target_name]
1995 if { $current_target != $et_filesystem_ts_target_name } {
1996 verbose "check_v3_target_filesystem_ts: `$et_filesystem_ts_target_name'" 2
1997 set et_filesystem_ts_target_name $current_target
1998 if [info exists et_filesystem_ts] {
1999 verbose "check_v3_target_filesystem_ts: removing cached result" 2
2000 unset et_filesystem_ts
2004 if [info exists et_filesystem_ts] {
2005 verbose "check_v3_target_filesystem_ts: using cached result" 2
2006 } else {
2007 set et_filesystem_ts 0
2009 # Set up and preprocess a C++ test program that depends
2010 # on the Filesystem TS feature-test macro being defined.
2011 set src filesystem_ts[pid].cc
2013 set f [open $src "w"]
2014 puts $f "#include <experimental/filesystem>"
2015 puts $f "#if ! __cpp_lib_experimental_filesystem"
2016 puts $f "# error No Filesystem TS support"
2017 puts $f "#endif"
2018 close $f
2020 set cxxflags_saved $cxxflags
2021 set cxxflags "$cxxflags $DEFAULT_CXXFLAGS -Werror"
2023 set lines [v3_target_compile $src /dev/null preprocess ""]
2024 set cxxflags $cxxflags_saved
2025 file delete $src
2027 if [string match "" $lines] {
2028 # No error message, preprocessing succeeded.
2029 set et_filesystem_ts 1
2032 verbose "check_v3_target_filesystem_ts: $et_filesystem_ts" 2
2033 return $et_filesystem_ts
2036 # Return 1 if the "cxx11" ABI is in use using the current flags, 0 otherwise.
2037 proc check_effective_target_cxx11-abi { } {
2038 global cxxflags
2040 # Set up and preprocess a C++ test program that depends
2041 # on the new ABI being enabled.
2042 set src cxx11_abi[pid].cc
2044 set f [open $src "w"]
2045 puts $f "#include <bits/c++config.h>"
2046 puts $f "#if ! _GLIBCXX_USE_CXX11_ABI"
2047 puts $f "# error old ABI in use"
2048 puts $f "#endif"
2049 close $f
2051 set lines [v3_target_compile $src /dev/null preprocess ""]
2052 file delete $src
2054 if [string match "" $lines] {
2055 # No error message, preprocessing succeeded.
2056 verbose "check_v3_cxx11_abi: `1'" 2
2057 return 1
2060 verbose "check_v3_cxx11_abi: `0'" 2
2061 return 0
2064 set additional_prunes ""
2066 if { [info exists env(GCC_RUNTEST_PARALLELIZE_DIR)] \
2067 && [info procs runtest_file_p] != [list] \
2068 && [info procs gcc_parallelize_saved_runtest_file_p] == [list] } then {
2069 global gcc_runtest_parallelize_counter
2070 global gcc_runtest_parallelize_counter_minor
2071 global gcc_runtest_parallelize_enable
2072 global gcc_runtest_parallelize_dir
2073 global gcc_runtest_parallelize_last
2075 set gcc_runtest_parallelize_counter 0
2076 set gcc_runtest_parallelize_counter_minor 0
2077 set gcc_runtest_parallelize_enable 1
2078 set gcc_runtest_parallelize_dir [getenv GCC_RUNTEST_PARALLELIZE_DIR]
2079 set gcc_runtest_parallelize_last 0
2081 proc gcc_parallel_test_run_p { testcase } {
2082 global gcc_runtest_parallelize_counter
2083 global gcc_runtest_parallelize_counter_minor
2084 global gcc_runtest_parallelize_enable
2085 global gcc_runtest_parallelize_dir
2086 global gcc_runtest_parallelize_last
2088 if { $gcc_runtest_parallelize_enable == 0 } {
2089 return 1
2092 # Only test the filesystem every 10th iteration
2093 incr gcc_runtest_parallelize_counter_minor
2094 if { $gcc_runtest_parallelize_counter_minor == 10 } {
2095 set gcc_runtest_parallelize_counter_minor 0
2097 if { $gcc_runtest_parallelize_counter_minor != 1 } {
2098 #verbose -log "gcc_parallel_test_run_p $testcase $gcc_runtest_parallelize_counter $gcc_runtest_parallelize_last"
2099 return $gcc_runtest_parallelize_last
2102 set path $gcc_runtest_parallelize_dir/$gcc_runtest_parallelize_counter
2104 if {![catch {open $path {RDWR CREAT EXCL} 0600} fd]} {
2105 close $fd
2106 set gcc_runtest_parallelize_last 1
2107 #verbose -log "gcc_parallel_test_run_p $testcase $gcc_runtest_parallelize_counter 1"
2108 incr gcc_runtest_parallelize_counter
2109 return 1
2111 set gcc_runtest_parallelize_last 0
2112 #verbose -log "gcc_parallel_test_run_p $testcase $gcc_runtest_parallelize_counter 0"
2113 incr gcc_runtest_parallelize_counter
2114 return 0
2117 proc gcc_parallel_test_enable { val } {
2118 global gcc_runtest_parallelize_enable
2119 set gcc_runtest_parallelize_enable $val
2122 rename runtest_file_p gcc_parallelize_saved_runtest_file_p
2123 proc runtest_file_p { runtests testcase } {
2124 if ![gcc_parallelize_saved_runtest_file_p $runtests $testcase] {
2125 return 0
2127 return [gcc_parallel_test_run_p $testcase]
2130 } else {
2132 proc gcc_parallel_test_run_p { testcase } {
2133 return 1
2136 proc gcc_parallel_test_enable { val } {