Dead
[official-gcc.git] / gomp-20050608-branch / libstdc++-v3 / testsuite / lib / libstdc++.exp
blobf93dc6efc8f0878b4df916d347c770f9a028ea9a
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.
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; if not, write to the Free Software
17 # Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA
18 # 02110-1301, USA.
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 } {
42 global srcdir
43 load_file $srcdir/../../gcc/testsuite/lib/$filename
46 # system routines
47 load_lib dg.exp
48 load_lib libgloss.exp
49 # compiler routines, then ours
50 load_gcc_lib target-supports.exp
51 load_gcc_lib target-supports-dg.exp
52 load_lib prune.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 } {
60 upvar $var val
61 verbose "++ $var is $val" $n
64 # Called by v3-init below. "Static" to this file.
65 proc v3-copy-files {srcfiles} {
66 foreach f $srcfiles {
67 if { [catch { set symlink [file readlink $f] } x] } then {
68 remote_download target $f
69 } else {
70 if { [regexp "^/" "$symlink"] } then {
71 remote_download target $symlink
72 } else {
73 set dirname [file dirname $f]
74 remote_download target $dirname/$symlink
80 # Called once, during runtest.exp setup.
81 proc libstdc++_init { testfile } {
82 global env
83 global v3-sharedlib
84 global srcdir blddir objdir tool_root_dir
85 global cxx cxxflags cxxldflags
86 global includes
87 global gluefile wrap_flags
88 global ld_library_path
89 global target_triplet
91 # We set LC_ALL and LANG to C so that we get the same error
92 # messages as expected.
93 setenv LC_ALL C
94 setenv LANG C
96 set blddir [lookfor_file [get_multilibs] libstdc++-v3]
97 set flags_file "${blddir}/scripts/testsuite_flags"
98 v3track flags_file 2
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]
127 if {$gccdir != ""} {
128 set gccdir [file dirname $gccdir]
130 v3track gccdir 3
132 # Look for shared library. (ie libstdc++.so.)
133 set v3-sharedlib 0
134 set sharedlibdir [lookfor_file $blddir src/.libs/libstdc++.so]
135 if {$sharedlibdir != ""} {
136 if { [string match "*-*-linux*" $target_triplet] && [isnative] } {
137 set v3-sharedlib 1
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.
144 if {$gccdir != ""} {
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]" {
152 set mldir ""
153 regexp -- "\[a-z0-9=/\.-\]*;" $i mldir
154 set mldir [string trimright $mldir "\;@"]
155 if { "$mldir" == "." } {
156 continue
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)"
168 } else {
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."
178 return "untested"
180 set cxx [transform "g++"]
181 set cxxflags "-ggdb3"
182 set cxxldflags ""
183 set includes "-I./"
184 } else {
185 # If we find a testsuite_flags file, we're testing in the build dir.
186 if { [file exists $flags_file] } {
187 set cxx [exec sh $flags_file --build-cxx]
188 set cxxflags [exec sh $flags_file --cxxflags]
189 set cxxldflags [exec sh $flags_file --cxxldflags]
190 set includes [exec sh $flags_file --build-includes]
191 } else {
192 set cxx [transform "g++"]
193 set includes "-I${srcdir}"
194 set cxxldflags ""
195 set cxxflags "-g -O2 -D_GLIBCXX_ASSERT -fmessage-length=0"
196 # Guess at the location of the installed locale files.
197 # (It would be nice if "gcc --print-file-name" could find
198 # message files, but it cannot.)
199 set absolute_cxx [which $cxx]
200 if { $absolute_cxx != "" } {
201 set localedir "[file dirname $absolute_cxx]/../share/locale"
203 set cxxflags "$cxxflags -DLOCALEDIR=\"$localedir\""
207 # If a PCH file is available, use it. We must delay performing
208 # this check until $cxx and such have been initialized because we
209 # perform a test compilation. (Ideally, gcc --print-file-name would
210 # list PCH files, but it does not.)
211 global PCH_CXXFLAGS
212 if ![info exists PCH_CXXFLAGS] then {
213 set src "config[pid].cc"
214 set f [open $src "w"]
215 puts $f "int main () {}"
216 close $f
218 set lines [v3_target_compile $src "config[pid].o" object \
219 "additional_flags=-include additional_flags=bits/stdc++.h"]
220 if {$lines == "" } {
221 set PCH_CXXFLAGS "-include bits/stdc++.h"
222 } else {
223 set PCH_CXXFLAGS ""
225 file delete $src
226 v3track PCH_CXXFLAGS 2
229 libstdc++_maybe_build_wrapper "${objdir}/testglue.o"
232 # Callback for cleanup routines.
233 proc libstdc++_exit { } {
234 global gluefile;
236 if [info exists gluefile] {
237 file_on_build delete $gluefile;
238 unset gluefile;
242 # Callback from system dg-test.
243 proc libstdc++-dg-test { prog do_what extra_tool_flags } {
244 # Set up the compiler flags, based on what we're going to do.
245 switch $do_what {
246 "preprocess" {
247 set compile_type "preprocess"
248 set output_file "[file rootname [file tail $prog]].i"
250 "compile" {
251 set compile_type "assembly"
252 set output_file "[file rootname [file tail $prog]].s"
254 "assemble" {
255 set compile_type "object"
256 set output_file "[file rootname [file tail $prog]].o"
258 "link" {
259 set compile_type "executable"
260 set output_file "./[file rootname [file tail $prog]].exe"
262 "run" {
263 set compile_type "executable"
264 # FIXME: "./" is to cope with "." not being in $PATH.
265 # Should this be handled elsewhere?
266 # YES.
267 set output_file "./[file rootname [file tail $prog]].exe"
268 # This is the only place where we care if an executable was
269 # created or not. If it was, dg.exp will try to run it.
270 catch { remote_file build delete $output_file }
272 default {
273 perror "$do_what: not a valid dg-do keyword"
274 return ""
278 set options ""
279 if { $extra_tool_flags != "" } {
280 verbose -log "extra_tool_flags are:"
281 verbose -log $extra_tool_flags
282 if { [string first "-x c" $extra_tool_flags ] != -1 } {
283 # Short-circut a bunch of complicated goo here for the
284 # special case of compiling a test file as a "C" file, not
285 # as C++: just use target_compile, instead of the usual
286 # gimmicks.
287 verbose -log "compiling and executing as C, not C++"
288 set compile_type "executable"
289 set output_file "./[file rootname [file tail $prog]].exe"
290 remote_file build delete $output_file;
291 lappend options "additional_flags=$extra_tool_flags"
292 set comp_output [target_compile "$prog" "$output_file" "$compile_type" $options];
293 set comp_output [ prune_g++_output $comp_output ];
294 return [list $comp_output $output_file]
295 } else {
296 lappend options "additional_flags=$extra_tool_flags"
300 # There is a libstdc++_compile made for us by default (via the tool-
301 # and-target file), but the defaults are lacking in goodness.
302 set comp_output [v3_target_compile "$prog" "$output_file" "$compile_type" $options];
303 set comp_output [ prune_g++_output $comp_output ];
305 return [list $comp_output $output_file]
308 # True if the library supports wchar_t.
309 set v3-wchar_t 0
311 # True if the library supports threads.
312 set v3-threads 0
314 # True if the library supports symbol versioning.
315 set v3-symver 0
317 # A string naming object files to be linked into all tests.
318 set v3-test_objs ""
320 # Called from libstdc++-dg-test above. Calls back into system's
321 # target_compile to actually do the work.
322 proc v3_target_compile { source dest type options } {
323 global gluefile
324 global wrap_flags
325 global cxx
326 global cxxflags
327 global cxxldflags
328 global includes
329 global blddir
330 global v3-test_objs
332 if { [target_info needs_status_wrapper] != "" && [info exists gluefile] } {
333 lappend options "libs=${gluefile}"
334 lappend options "ldflags=${wrap_flags}"
337 set cxx_final $cxx
338 set cxxlibglossflags [libgloss_link_flags]
339 set cxx_final [concat $cxx_final $cxxlibglossflags]
340 set cxx_final [concat $cxx_final $cxxflags]
341 set cxx_final [concat $cxx_final $includes]
343 # Flag setting based on type argument.
344 if { $type == "executable" } {
345 # Link the support objects into executables.
346 set cxx_final [concat $cxx_final ${v3-test_objs}]
347 set cxx_final [concat $cxx_final $cxxldflags]
348 } else {
349 if { $type == "sharedlib" } {
350 # Don't link in anything.
351 set type "executable"
355 lappend options "compiler=$cxx_final"
357 return [target_compile $source $dest $type $options]
361 # Build the support objects linked in with the libstdc++ tests. In
362 # addition, set v3-wchar_t, v3-threads, v3-test_objs, and v3-symver
363 # appropriately.
364 proc v3-build_support { } {
365 global srcdir
366 global v3-wchar_t
367 global v3-threads
368 global v3-test_objs
369 global v3-symver
370 global v3-sharedlib
372 # Figure out whether or not the library supports certain features.
373 set v3-wchar_t 0
374 set v3-threads 0
375 set v3-symver 0
376 set v3-test_objs ""
378 set config_src "config.cc"
379 set f [open $config_src "w"]
380 puts $f "#include <bits/c++config.h>"
381 puts $f "#include <bits/gthr.h>"
382 close $f
383 set preprocessed [v3_target_compile $config_src "" \
384 preprocess "additional_flags=-dN"]
385 if { [string first "_GLIBCXX_USE_WCHAR_T" $preprocessed] != -1 } {
386 verbose -log "wchar_t support detected"
387 set v3-wchar_t 1
389 if { [string first "_GLIBCXX_SYMVER" $preprocessed] != -1 } {
390 verbose -log "symbol versioning support detected"
391 set v3-symver 1
393 if { [string first "__GTHREADS" $preprocessed] != -1 } {
394 verbose -log "thread support detected"
395 set v3-threads 1
398 # Build the support objects.
399 set source_files \
400 [list testsuite_abi.cc testsuite_allocator.cc testsuite_character.cc testsuite_hooks.cc ]
401 foreach f $source_files {
402 set object_file [file rootname $f].o
403 # Compile with "-w" so that warnings issued by the compiler
404 # do not prevent compilation.
405 if { [v3_target_compile $srcdir/$f $object_file "object" \
406 [list "incdir=$srcdir" "additional_flags=-w"]]
407 != "" } {
408 error "could not compile $f"
410 append v3-test_objs "$object_file "
413 # Build the shared support objects.
414 if { ${v3-sharedlib} == 1 } {
415 set source_files \
416 [list testsuite_shared.cc]
417 foreach f $source_files {
418 set object_file [file rootname $f].so
419 # Compile with "-w" so that warnings issued by the compiler
420 # do not prevent compilation.
421 if { [v3_target_compile $srcdir/$f $object_file "sharedlib" \
422 [list "incdir=$srcdir" "additional_flags=-w -shared -fPIC -DPIC"]]
423 != "" } {
424 error "could not compile $f"
430 proc check_v3_target_sharedlib { } {
431 global v3-sharedlib
432 return ${v3-sharedlib}
435 proc check_v3_target_namedlocale { } {
436 global et_namedlocale_saved
437 global et_namedlocale_target_name
438 global tool
440 if { ![info exists et_namedlocale_target_name] } {
441 set et_namedlocale_target_name ""
444 # If the target has changed since we set the cached value, clear it.
445 set current_target [current_target_name]
446 if { $current_target != $et_namedlocale_target_name } {
447 verbose "check_v3_target_namedlocale: `$et_namedlocale_target_name'" 2
448 set et_namedlocale_target_name $current_target
449 if [info exists et_namedlocale_saved] {
450 verbose "check_v3_target_namedlocale: removing cached result" 2
451 unset et_namedlocale_saved
455 if [info exists et_namedlocale_saved] {
456 verbose "check_v3_target_namedlocale: using cached result" 2
457 } else {
458 set et_namedlocale_saved 0
460 # Set up, compile, and execute a C++ test program that tries to use
461 # all the required named locales.
462 set src nlocale[pid].cc
463 set exe nlocale[pid].x
465 set f [open $src "w"]
466 puts $f "#include <locale>"
467 puts $f "using namespace std;"
468 puts $f "int main ()"
469 puts $f "{"
470 puts $f " try"
471 puts $f " {"
472 puts $f " locale(\"\");"
473 puts $f " locale(\"de_DE\");"
474 puts $f " locale(\"de_DE.ISO-8859-15@euro\");"
475 puts $f " locale(\"de_DE@euro\");"
476 puts $f " locale(\"en_HK\");"
477 puts $f " locale(\"en_PH\");"
478 puts $f " locale(\"en_US\");"
479 puts $f " locale(\"en_US.ISO-8859-1\");"
480 puts $f " locale(\"en_US.ISO-8859-15\");"
481 puts $f " locale(\"en_US.UTF-8\");"
482 puts $f " locale(\"es_ES\");"
483 puts $f " locale(\"es_MX\");"
484 puts $f " locale(\"fr_FR\");"
485 puts $f " locale(\"fr_FR@euro\");"
486 puts $f " locale(\"is_IS\");"
487 puts $f " locale(\"is_IS.UTF-8\");"
488 puts $f " locale(\"it_IT\");"
489 puts $f " locale(\"ja_JP.eucjp\");"
490 puts $f " locale(\"se_NO.UTF-8\");"
491 puts $f " locale(\"ta_IN\");"
492 puts $f " locale(\"zh_TW\");"
493 puts $f " return 0;"
494 puts $f " }"
495 puts $f " catch(...)"
496 puts $f " {"
497 puts $f " return 1;"
498 puts $f " }"
499 puts $f "}"
500 close $f
502 set lines [v3_target_compile $src $exe executable ""]
503 file delete $src
505 if [string match "" $lines] {
506 # No error message, compilation succeeded.
507 set result [${tool}_load "./$exe" "" ""]
508 set status [lindex $result 0]
509 remote_file build delete $exe
511 verbose "check_v3_target_namedlocale: status is <$status>" 2
513 if { $status == "pass" } {
514 set et_namedlocale_saved 1
516 } else {
517 verbose "check_v3_target_namedlocale: compilation failed" 2
520 return $et_namedlocale_saved
523 proc check_v3_target_cxa_atexit { } {
524 global et_cxa_atexit
525 global et_cxa_atexit_target_name
526 global tool
528 if { ![info exists et_cxa_atexit_target_name] } {
529 set et_cxa_atexit_target_name ""
532 # If the target has changed since we set the cached value, clear it.
533 set current_target [current_target_name]
534 if { $current_target != $et_cxa_atexit_target_name } {
535 verbose "check_v3_target_cxa_atexit: `$et_cxa_atexit_target_name'" 2
536 set et_cxa_atexit_target_name $current_target
537 if [info exists et_cxa_atexit] {
538 verbose "check_v3_target_cxa_atexit: removing cached result" 2
539 unset et_cxa_atexit
543 if [info exists et_cxa_atexit] {
544 verbose "check_v3_target_cxa_atexit: using cached result" 2
545 } else {
546 set et_cxa_atexit 0
548 # Set up, compile, and execute a C++ test program that depends
549 # on correct ordering of static object destructors. This is
550 # indicative of the presence and use of __cxa_atexit.
551 set src cxaatexit[pid].cc
552 set exe cxaatexit[pid].x
554 set f [open $src "w"]
555 puts $f "#include <stdlib.h>"
556 puts $f "static unsigned int count;"
557 puts $f "struct X"
558 puts $f "{"
559 puts $f " X() { count = 1; }"
560 puts $f " ~X()"
561 puts $f " {"
562 puts $f " if (count != 3)"
563 puts $f " exit(1);"
564 puts $f " count = 4;"
565 puts $f " }"
566 puts $f "};"
567 puts $f "void f()"
568 puts $f "{"
569 puts $f " static X x;"
570 puts $f "}"
571 puts $f "struct Y"
572 puts $f "{"
573 puts $f " Y() { f(); count = 2; }"
574 puts $f " ~Y()"
575 puts $f " {"
576 puts $f " if (count != 2)"
577 puts $f " exit(1);"
578 puts $f " count = 3;"
579 puts $f " }"
580 puts $f "};"
581 puts $f "Y y;"
582 puts $f "int main()"
583 puts $f "{ return 0; }"
584 close $f
586 set lines [v3_target_compile $src $exe executable ""]
587 file delete $src
589 if [string match "" $lines] {
590 # No error message, compilation succeeded.
591 set result [${tool}_load "./$exe" "" ""]
592 set status [lindex $result 0]
593 remote_file build delete $exe
595 verbose "check_v3_target_cxa_atexit: status is <$status>" 2
597 if { $status == "pass" } {
598 set et_cxa_atexit 1
600 } else {
601 verbose "check_v3_target_cxa_atexit: compilation failed" 2
604 return $et_cxa_atexit
607 proc check_v3_target_debug_mode { } {
608 global cxxflags
609 global et_debug_mode
611 global tool
613 if { ![info exists et_debug_mode_target_name] } {
614 set et_debug_mode_target_name ""
617 # If the target has changed since we set the cached value, clear it.
618 set current_target [current_target_name]
619 if { $current_target != $et_debug_mode_target_name } {
620 verbose "check_v3_target_debug_mode: `$et_debug_mode_target_name'" 2
621 set et_debug_mode_target_name $current_target
622 if [info exists et_debug_mode] {
623 verbose "check_v3_target_debug_mode: removing cached result" 2
624 unset et_debug_mode
628 if [info exists et_debug_mode] {
629 verbose "check_v3_target_debug_mode: using cached result" 2
630 } else {
631 set et_debug_mode 0
633 # Set up, compile, and execute a C++ test program that depends
634 # on debug mode working.
635 set src debug_mode[pid].cc
636 set exe debug_mode[pid].exe
638 set f [open $src "w"]
639 puts $f "#include <string>"
640 puts $f "using namespace std;"
641 puts $f "int main()"
642 puts $f "{ return 0; }"
643 close $f
645 set cxxflags_saved $cxxflags
646 set cxxflags "$cxxflags -Werror -O0 -D_GLIBCXX_DEBUG"
647 set lines [v3_target_compile $src $exe executable ""]
648 set cxxflags $cxxflags_saved
649 file delete $src
651 if [string match "" $lines] {
652 # No error message, compilation succeeded.
653 set et_debug_mode 1
656 verbose "check_v3_target_debug_mode: $et_debug_mode" 2
657 return $et_debug_mode