1 # libstdc
++ "tool init file" for DejaGNU
3 # Copyright
(C
) 2001, 2002, 2003, 2004, 2005 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
2 of the License
, or
8 #
(at your option
) any later version.
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; if not
, write to the Free Software
17 # Foundation
, Inc.
, 51 Franklin Street
, Fifth Floor
, Boston
, MA
21 #
Define callbacks and
load other libraries. This file is loaded relatively
22 # early
, and before
any other file we write ourselves.
"load_lib" will
23 # find anything in the DejaGNU installation tree
, or in our lib directory.
24 #
"load_gcc_lib" will search the core compiler's .exp collection instead.
26 # The naming rule is that dg.exp looks
for "tool-" and runtest.exp looks
27 #
for "tool_" when finding callbacks. Utility routines we define for
28 # our callbacks begin with
"v3-".
30 # libstdc
++_
* callbacks we don
't define, but could:
31 # ..._option_help prints additional --help output
32 # ..._option_proc (--foo) process our own options
33 # ..._init (normal.exp) called once per test file
34 # ..._finish bracketing function for libstdc++_init
35 # ...-dg-prune removing output text, see top of system dg.exp
37 # Useful hook: if ${hostname}_init exists, it will be called, almost
38 # the last thing before testing begins. This can be defined in, e.g.,
39 # ~/.dejagnurc or $DEJAGNU.
41 proc load_gcc_lib { filename } {
43 load_file $srcdir/../../gcc/testsuite/lib/$filename
49 # compiler routines, then ours
50 load_gcc_lib target-supports.exp
51 load_gcc_lib target-supports-dg.exp
53 load_lib dg-options.exp
54 load_gcc_lib target-libpath.exp
55 load_gcc_lib wrapper.exp
57 # Useful for debugging. Pass the name of a variable and the verbosity
58 # threshold (number of -v's
on the command line
).
59 proc v3track
{ var n
} {
61 verbose
"++ $var is $val" $n
64 # Called by v3
-init below.
"Static" to this file.
65 proc v3
-copy
-files
{srcfiles
} {
67 if { [catch
{ set symlink
[file readlink $f
] } x
] } then {
68 remote_download target $f
70 if { [regexp
"^/" "$symlink"] } then {
71 remote_download target $symlink
73 set dirname
[file dirname $f
]
74 remote_download target $dirname
/$symlink
80 # Called once
, during runtest.exp setup.
81 proc libstdc
++_init
{ testfile
} {
84 global srcdir blddir objdir tool_root_dir
87 global gluefile wrap_flags
88 global ld_library_path
91 # We
set LC_ALL and LANG to C so that we
get the same error
92 # messages as expected.
96 set blddir
[lookfor_file
[get_multilibs
] libstdc
++-v3
]
97 set flags_file
"${blddir}/scripts/testsuite_flags"
100 #
If a test doesn
't have special options, use DEFAULT_CXXFLAGS.
101 # Use this variable if the behavior
102 # 1) only applies to libstdc++ testing
103 # 2) might need to be negated
104 # In particular, some tests have to be run without precompiled
105 # headers, or without assertions.
106 global DEFAULT_CXXFLAGS
107 if ![info exists DEFAULT_CXXFLAGS] then {
108 set DEFAULT_CXXFLAGS ""
109 # Host specific goo here.
110 if { [string match "powerpc-*-darwin*" $target_triplet] } {
111 append DEFAULT_CXXFLAGS " -multiply_defined suppress"
114 v3track DEFAULT_CXXFLAGS 2
116 # By default, we assume we want to run program images.
117 global dg-do-what-default
118 set dg-do-what-default run
120 # Copy any required data files.
121 v3-copy-files [glob -nocomplain "$srcdir/data/*.tst"]
122 v3-copy-files [glob -nocomplain "$srcdir/data/*.txt"]
124 # Locate libgcc.a so we don't need to account
for different
values of
125 # SHLIB_EXT
on different platforms
126 set gccdir
[lookfor_file $tool_root_dir gcc
/libgcc.a
]
128 set gccdir
[file dirname $gccdir
]
132 # Look
for shared library.
(ie libstdc
++.so.
)
134 set sharedlibdir
[lookfor_file $blddir src
/.libs
/libstdc
++.so
]
135 if {$sharedlibdir
!= ""} {
136 if { [string match
"*-*-linux*" $target_triplet] && [isnative] } {
138 verbose
-log "shared library support detected"
141 v3track v3
-sharedlib
3
143 # Compute what needs to be added to the existing LD_LIBRARY_PATH.
145 set ld_library_path
""
146 append ld_library_path
":${gccdir}"
147 set compiler $
{gccdir
}/g
++
148 append ld_library_path
":${blddir}/src/.libs"
150 if { [is_remote host
] == 0 && [which $compiler
] != 0 } {
151 foreach i
"[exec $compiler --print-multi-lib]" {
153 regexp
-- "\[a-z0-9=/\.-\]*;" $i mldir
154 set mldir
[string trimright $mldir
"\;@"]
155 if { "$mldir" == "." } {
158 if { [llength
[glob
-nocomplain $
{gccdir
}/$
{mldir
}/libgcc_s
*.so.
*]] >= 1 } {
159 append ld_library_path
":${gccdir}/${mldir}"
164 set_ld_library_path_env_vars
165 if [info exists env
(LD_LIBRARY_PATH
)] {
166 verbose
-log "LD_LIBRARY_PATH = $env(LD_LIBRARY_PATH)"
169 set compiler
[transform
"g++"]
172 #
Do a bunch of handstands and backflips
for cross compiling and
173 # finding simulators...
174 if [is_remote host
] {
175 set header
[remote_download host $
{blddir
}/testsuite
/testsuite_hooks.h
]
176 if { $header
== "" } {
177 verbose
-log "Unable to download ${blddir}/testsuite/testsuite_hooks.h to host."
180 set cxx
[transform
"g++"]
181 set cxxflags
"-ggdb3"
184 #
If we find a testsuite_flags file
, we
're testing in the build dir.
185 if { [file exists $flags_file] } {
186 set cxx [exec sh $flags_file --build-cxx]
187 set cxxflags [exec sh $flags_file --cxxflags]
188 set includes [exec sh $flags_file --build-includes]
190 set cxx [transform "g++"]
191 set cxxflags "-g -O2 -D_GLIBCXX_ASSERT -fmessage-length=0"
192 set includes "-I${srcdir}"
193 # Guess at the location of the installed locale files.
194 # (It would be nice if "gcc --print-file-name" could find
195 # message files, but it cannot.)
196 set absolute_cxx [which $cxx]
197 if { $absolute_cxx != "" } {
198 set localedir "[file dirname $absolute_cxx]/../share/locale"
200 set cxxflags "$cxxflags -DLOCALEDIR=\"$localedir\""
204 # If a PCH file is available, use it. We must delay performing
205 # this check until $cxx and such have been initialized because we
206 # perform a test compilation. (Ideally, gcc --print-file-name would
207 # list PCH files, but it does not.)
209 if ![info exists PCH_CXXFLAGS] then {
210 set src "config[pid].cc"
211 set f [open $src "w"]
212 puts $f "int main () {}"
215 set lines [v3_target_compile $src "config[pid].o" object \
216 "additional_flags=-include additional_flags=bits/stdc++.h"]
218 set PCH_CXXFLAGS "-include bits/stdc++.h"
223 v3track PCH_CXXFLAGS 2
226 libstdc++_maybe_build_wrapper "${objdir}/testglue.o"
229 # Callback for cleanup routines.
230 proc libstdc++_exit { } {
233 if [info exists gluefile] {
234 file_on_build delete $gluefile;
239 # Callback from system dg-test.
240 proc libstdc++-dg-test { prog do_what extra_tool_flags } {
241 # Set up the compiler flags, based on what we're going to
do.
244 set compile_type
"preprocess"
245 set output_file
"[file rootname [file tail $prog]].i"
248 set compile_type
"assembly"
249 set output_file
"[file rootname [file tail $prog]].s"
252 set compile_type
"object"
253 set output_file
"[file rootname [file tail $prog]].o"
256 set compile_type
"executable"
257 set output_file
"./[file rootname [file tail $prog]].exe"
260 set compile_type
"executable"
261 # FIXME
: "./" is to cope with "." not being in $PATH.
262 # Should this be handled elsewhere?
264 set output_file
"./[file rootname [file tail $prog]].exe"
265 # This is the only place where we care
if an executable was
266 # created or not.
If it was
, dg.exp will try to run it.
267 catch
{ remote_file build
delete $output_file
}
270 perror
"$do_what: not a valid dg-do keyword"
276 if { $extra_tool_flags
!= "" } {
277 verbose
-log "extra_tool_flags are:"
278 verbose
-log $extra_tool_flags
279 if { [string first
"-x c" $extra_tool_flags ] != -1 } {
280 # Short
-circut a bunch of complicated goo here
for the
281 # special case of compiling a test file as a
"C" file, not
282 # as C
++: just use target_compile
, instead of the usual
284 verbose
-log "compiling and executing as C, not C++"
285 set compile_type
"executable"
286 set output_file
"./[file rootname [file tail $prog]].exe"
287 remote_file build
delete $output_file
;
288 lappend options
"additional_flags=$extra_tool_flags"
289 set comp_output
[target_compile
"$prog" "$output_file" "$compile_type" $options];
290 set comp_output
[ prune_g
++_output $comp_output
];
291 return [list $comp_output $output_file
]
293 lappend options
"additional_flags=$extra_tool_flags"
297 # There is a libstdc
++_compile made
for us by default
(via the tool
-
298 # and
-target file
), but the defaults are lacking in goodness.
299 set comp_output
[v3_target_compile
"$prog" "$output_file" "$compile_type" $options];
300 set comp_output
[ prune_g
++_output $comp_output
];
302 return [list $comp_output $output_file
]
305 # True
if the library supports wchar_t.
308 # True
if the library supports threads.
311 # True
if the library supports symbol versioning.
314 # A string naming object files to be linked into all tests.
317 # Called from libstdc
++-dg
-test above. Calls
back into
system's
318 # target_compile to actually do the work.
319 proc v3_target_compile { source dest type options } {
328 if { [target_info needs_status_wrapper] != "" && [info exists gluefile] } {
329 lappend options "libs=${gluefile}"
330 lappend options "ldflags=${wrap_flags}"
334 set cxxlibglossflags [libgloss_link_flags]
335 set cxx_final [concat $cxx_final $cxxlibglossflags]
336 set cxx_final [concat $cxx_final $cxxflags]
337 set cxx_final [concat $cxx_final $includes]
339 # Flag setting based on type argument.
340 if { $type == "executable" } {
341 # Link the support objects into executables.
342 set cxx_final [concat $cxx_final ${v3-test_objs}]
344 if { $type == "sharedlib" } {
345 # Don't link in anything.
346 set type
"executable"
350 lappend options
"compiler=$cxx_final"
352 return [target_compile $source $dest $type $options
]
356 # Build the support objects linked in with the libstdc
++ tests. In
357 # addition
, set v3
-wchar_t
, v3
-threads
, v3
-test_objs
, and v3
-symver
359 proc v3
-build_support
{ } {
367 # Figure out whether or not the library supports certain features.
373 set config_src
"config.cc"
374 set f
[open $config_src
"w"]
375 puts $f
"#include <bits/c++config.h>"
376 puts $f
"#include <bits/gthr.h>"
378 set preprocessed
[v3_target_compile $config_src
"" \
379 preprocess
"additional_flags=-dN"]
380 if { [string first
"_GLIBCXX_USE_WCHAR_T" $preprocessed] != -1 } {
381 verbose
-log "wchar_t support detected"
384 if { [string first
"_GLIBCXX_SYMVER" $preprocessed] != -1 } {
385 verbose
-log "symbol versioning support detected"
388 if { [string first
"__GTHREADS" $preprocessed] != -1 } {
389 verbose
-log "thread support detected"
393 # Build the support objects.
395 [list testsuite_abi.cc testsuite_allocator.cc testsuite_character.cc testsuite_hooks.cc
]
396 foreach f $source_files
{
397 set object_file
[file rootname $f
].o
398 #
Compile with
"-w" so that warnings issued by the compiler
399 #
do not prevent compilation.
400 if { [v3_target_compile $srcdir
/$f $object_file
"object" \
401 [list
"incdir=$srcdir" "additional_flags=-w"]]
403 error
"could not compile $f"
405 append v3
-test_objs
"$object_file "
408 # Build the shared support objects.
409 if { $
{v3
-sharedlib
} == 1 } {
411 [list testsuite_shared.cc
]
412 foreach f $source_files
{
413 set object_file
[file rootname $f
].so
414 #
Compile with
"-w" so that warnings issued by the compiler
415 #
do not prevent compilation.
416 if { [v3_target_compile $srcdir
/$f $object_file
"sharedlib" \
417 [list
"incdir=$srcdir" "additional_flags=-w -shared -fPIC -DPIC"]]
419 error
"could not compile $f"
425 proc check_v3_target_sharedlib
{ } {
427 return $
{v3
-sharedlib
}
430 proc check_v3_target_namedlocale
{ } {
431 global et_namedlocale_saved
432 global et_namedlocale_target_name
435 if { ![info exists et_namedlocale_target_name
] } {
436 set et_namedlocale_target_name
""
439 #
If the target has changed since we
set the cached value
, clear it.
440 set current_target
[current_target_name
]
441 if { $current_target
!= $et_namedlocale_target_name
} {
442 verbose
"check_v3_target_namedlocale: `$et_namedlocale_target_name'" 2
443 set et_namedlocale_target_name $current_target
444 if [info exists et_namedlocale_saved
] {
445 verbose
"check_v3_target_namedlocale: removing cached result" 2
446 unset et_namedlocale_saved
450 if [info exists et_namedlocale_saved
] {
451 verbose
"check_v3_target_namedlocale: using cached result" 2
453 set et_namedlocale_saved
0
455 #
Set up
, compile, and
execute a C
++ test
program that tries to use
456 # all the required named locales.
457 set src nlocale
[pid
].cc
458 set exe nlocale
[pid
].x
460 set f
[open $src
"w"]
461 puts $f
"#include <locale>"
462 puts $f
"using namespace std;"
463 puts $f
"int main ()"
467 puts $f
" locale(\"\");"
468 puts $f
" locale(\"de_DE\");"
469 puts $f
" locale(\"de_DE.ISO-8859-15@euro\");"
470 puts $f
" locale(\"de_DE@euro\");"
471 puts $f
" locale(\"en_HK\");"
472 puts $f
" locale(\"en_PH\");"
473 puts $f
" locale(\"en_US\");"
474 puts $f
" locale(\"en_US.ISO-8859-1\");"
475 puts $f
" locale(\"en_US.ISO-8859-15\");"
476 puts $f
" locale(\"en_US.UTF-8\");"
477 puts $f
" locale(\"es_ES\");"
478 puts $f
" locale(\"es_MX\");"
479 puts $f
" locale(\"fr_FR\");"
480 puts $f
" locale(\"fr_FR@euro\");"
481 puts $f
" locale(\"is_IS\");"
482 puts $f
" locale(\"is_IS.UTF-8\");"
483 puts $f
" locale(\"it_IT\");"
484 puts $f
" locale(\"ja_JP.eucjp\");"
485 puts $f
" locale(\"se_NO.UTF-8\");"
486 puts $f
" locale(\"ta_IN\");"
487 puts $f
" locale(\"zh_TW\");"
490 puts $f
" catch(...)"
497 set lines
[v3_target_compile $src $exe executable
""]
500 if [string match
"" $lines] {
501 # No error message
, compilation succeeded.
502 set result
[$
{tool
}_load
"./$exe" "" ""]
503 set status [lindex $result
0]
504 remote_file build
delete $exe
506 verbose
"check_v3_target_namedlocale: status is <$status>" 2
508 if { $
status == "pass" } {
509 set et_namedlocale_saved
1
512 verbose
"check_v3_target_namedlocale: compilation failed" 2
515 return $et_namedlocale_saved
518 proc check_v3_target_cxa_atexit
{ } {
520 global et_cxa_atexit_target_name
523 if { ![info exists et_cxa_atexit_target_name
] } {
524 set et_cxa_atexit_target_name
""
527 #
If the target has changed since we
set the cached value
, clear it.
528 set current_target
[current_target_name
]
529 if { $current_target
!= $et_cxa_atexit_target_name
} {
530 verbose
"check_v3_target_cxa_atexit: `$et_cxa_atexit_target_name'" 2
531 set et_cxa_atexit_target_name $current_target
532 if [info exists et_cxa_atexit
] {
533 verbose
"check_v3_target_cxa_atexit: removing cached result" 2
538 if [info exists et_cxa_atexit
] {
539 verbose
"check_v3_target_cxa_atexit: using cached result" 2
543 #
Set up
, compile, and
execute a C
++ test
program that depends
544 #
on correct ordering of static object destructors. This is
545 # indicative of the presence and use of __cxa_atexit.
546 set src cxaatexit
[pid
].cc
547 set exe cxaatexit
[pid
].x
549 set f
[open $src
"w"]
550 puts $f
"#include <stdlib.h>"
551 puts $f
"static unsigned int count;"
554 puts $f
" X() { count = 1; }"
557 puts $f
" if (count != 3)"
559 puts $f
" count = 4;"
564 puts $f
" static X x;"
568 puts $f
" Y() { f(); count = 2; }"
571 puts $f
" if (count != 2)"
573 puts $f
" count = 3;"
578 puts $f
"{ return 0; }"
581 set lines
[v3_target_compile $src $exe executable
""]
584 if [string match
"" $lines] {
585 # No error message
, compilation succeeded.
586 set result
[$
{tool
}_load
"./$exe" "" ""]
587 set status [lindex $result
0]
588 remote_file build
delete $exe
590 verbose
"check_v3_target_cxa_atexit: status is <$status>" 2
592 if { $
status == "pass" } {
596 verbose
"check_v3_target_cxa_atexit: compilation failed" 2
599 return $et_cxa_atexit
602 proc check_v3_target_debug_mode
{ } {
608 if { ![info exists et_debug_mode_target_name
] } {
609 set et_debug_mode_target_name
""
612 #
If the target has changed since we
set the cached value
, clear it.
613 set current_target
[current_target_name
]
614 if { $current_target
!= $et_debug_mode_target_name
} {
615 verbose
"check_v3_target_debug_mode: `$et_debug_mode_target_name'" 2
616 set et_debug_mode_target_name $current_target
617 if [info exists et_debug_mode
] {
618 verbose
"check_v3_target_debug_mode: removing cached result" 2
623 if [info exists et_debug_mode
] {
624 verbose
"check_v3_target_debug_mode: using cached result" 2
628 #
Set up
, compile, and
execute a C
++ test
program that depends
629 #
on debug
mode working.
630 set src debug_mode
[pid
].cc
631 set exe debug_mode
[pid
].exe
633 set f
[open $src
"w"]
634 puts $f
"#include <string>"
635 puts $f
"using namespace std;"
637 puts $f
"{ return 0; }"
640 set cxxflags_saved $cxxflags
641 set cxxflags
"$cxxflags -Werror -O0 -D_GLIBCXX_DEBUG"
642 set lines
[v3_target_compile $src $exe executable
""]
643 set cxxflags $cxxflags_saved
646 if [string match
"" $lines] {
647 # No error message
, compilation succeeded.
651 verbose
"check_v3_target_debug_mode: $et_debug_mode" 2
652 return $et_debug_mode