* gcc.dg/cpp/_Pragma6.c: Fix comment.
[official-gcc.git] / libstdc++-v3 / testsuite / lib / libstdc++.exp
blobd7da29f77c3d1dfbcd18586f199b03e0c29a725b
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"
199 # Always use MO files built by this test harness.
200 set cxxflags "$cxxflags -DLOCALEDIR=\".\""
202 # If a PCH file is available, use it. We must delay performing
203 # this check until $cxx and such have been initialized because we
204 # perform a test compilation. (Ideally, gcc --print-file-name would
205 # list PCH files, but it does not.)
206 global PCH_CXXFLAGS
207 if ![info exists PCH_CXXFLAGS] then {
208 set src "config[pid].cc"
209 set f [open $src "w"]
210 puts $f "int main () {}"
211 close $f
213 set lines [v3_target_compile $src "config[pid].o" object \
214 "additional_flags=-include additional_flags=bits/stdc++.h"]
215 if {$lines == "" } {
216 set PCH_CXXFLAGS "-include bits/stdc++.h"
217 } else {
218 set PCH_CXXFLAGS ""
220 file delete $src
221 v3track PCH_CXXFLAGS 2
224 libstdc++_maybe_build_wrapper "${objdir}/testglue.o"
227 # Callback for cleanup routines.
228 proc libstdc++_exit { } {
229 global gluefile;
231 if [info exists gluefile] {
232 file_on_build delete $gluefile;
233 unset gluefile;
237 # Callback from system dg-test.
238 proc libstdc++-dg-test { prog do_what extra_tool_flags } {
239 # Set up the compiler flags, based on what we're going to do.
240 switch $do_what {
241 "preprocess" {
242 set compile_type "preprocess"
243 set output_file "[file rootname [file tail $prog]].i"
245 "compile" {
246 set compile_type "assembly"
247 set output_file "[file rootname [file tail $prog]].s"
249 "assemble" {
250 set compile_type "object"
251 set output_file "[file rootname [file tail $prog]].o"
253 "link" {
254 set compile_type "executable"
255 set output_file "./[file rootname [file tail $prog]].exe"
257 "run" {
258 set compile_type "executable"
259 # FIXME: "./" is to cope with "." not being in $PATH.
260 # Should this be handled elsewhere?
261 # YES.
262 set output_file "./[file rootname [file tail $prog]].exe"
263 # This is the only place where we care if an executable was
264 # created or not. If it was, dg.exp will try to run it.
265 catch { remote_file build delete $output_file }
267 default {
268 perror "$do_what: not a valid dg-do keyword"
269 return ""
273 set options ""
274 if { $extra_tool_flags != "" } {
275 verbose -log "extra_tool_flags are:"
276 verbose -log $extra_tool_flags
277 if { [string first "-x c" $extra_tool_flags ] != -1 } {
278 # Short-circut a bunch of complicated goo here for the
279 # special case of compiling a test file as a "C" file, not
280 # as C++: just use target_compile, instead of the usual
281 # gimmicks.
282 verbose -log "compiling and executing as C, not C++"
283 set compile_type "executable"
284 set output_file "./[file rootname [file tail $prog]].exe"
285 remote_file build delete $output_file;
286 lappend options "additional_flags=$extra_tool_flags"
287 set comp_output [target_compile "$prog" "$output_file" "$compile_type" $options];
288 set comp_output [ prune_g++_output $comp_output ];
289 return [list $comp_output $output_file]
290 } else {
291 lappend options "additional_flags=$extra_tool_flags"
295 # There is a libstdc++_compile made for us by default (via the tool-
296 # and-target file), but the defaults are lacking in goodness.
297 set comp_output [v3_target_compile "$prog" "$output_file" "$compile_type" $options];
298 set comp_output [ prune_g++_output $comp_output ];
300 return [list $comp_output $output_file]
303 # True if the library supports wchar_t.
304 set v3-wchar_t 0
306 # True if the library supports threads.
307 set v3-threads 0
309 # True if the library supports symbol versioning.
310 set v3-symver 0
312 # A string naming object files to be linked into all tests.
313 set v3-test_objs ""
315 # Called from libstdc++-dg-test above. Calls back into system's
316 # target_compile to actually do the work.
317 proc v3_target_compile { source dest type options } {
318 global gluefile
319 global wrap_flags
320 global cxx
321 global cxxflags
322 global cxxldflags
323 global includes
324 global blddir
325 global v3-test_objs
327 if { [target_info needs_status_wrapper] != "" && [info exists gluefile] } {
328 lappend options "libs=${gluefile}"
329 lappend options "ldflags=${wrap_flags}"
332 set cxx_final $cxx
333 set cxxlibglossflags [libgloss_link_flags]
334 set cxx_final [concat $cxx_final $cxxlibglossflags]
335 set cxx_final [concat $cxx_final $cxxflags]
336 set cxx_final [concat $cxx_final $includes]
338 # Flag setting based on type argument.
339 if { $type == "executable" } {
340 # Link the support objects into executables.
341 set cxx_final [concat $cxx_final ${v3-test_objs}]
342 set cxx_final [concat $cxx_final $cxxldflags]
343 } else {
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
358 # appropriately.
359 proc v3-build_support { } {
360 global srcdir
361 global v3-wchar_t
362 global v3-threads
363 global v3-test_objs
364 global v3-symver
365 global v3-sharedlib
367 # Figure out whether or not the library supports certain features.
368 set v3-wchar_t 0
369 set v3-threads 0
370 set v3-symver 0
371 set v3-test_objs ""
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>"
377 close $f
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"
382 set v3-wchar_t 1
384 if { [string first "_GLIBCXX_SYMVER" $preprocessed] != -1 } {
385 verbose -log "symbol versioning support detected"
386 set v3-symver 1
388 if { [string first "__GTHREADS" $preprocessed] != -1 } {
389 verbose -log "thread support detected"
390 set v3-threads 1
393 # Try to build the MO files that are used by some of the locale
394 # tests. If we can't build them, that's OK; it just means that
395 # those tests will fail.
396 foreach lang [list "fr" "de"] {
397 catch {
398 file mkdir "$lang/LC_MESSAGES"
399 remote_exec "build" "msgfmt" "-o $lang/LC_MESSAGES/libstdc++.mo $srcdir/../po/$lang.po"
400 if [is_remote host] {
401 remote_exec "host" "mkdir" "-p $lang/LC_MESSAGES"
402 remote_download "host" "$lang/LC_MESSAGES/libstdc++.mo" "$lang/LC_MESSAGES/libstdc++.mo"
407 # Build the support objects.
408 set source_files [list testsuite_abi.cc testsuite_allocator.cc \
409 testsuite_character.cc testsuite_hooks.cc \
410 rng/twister_rand_gen.cc io/verified_cmd_line_input.cc \
411 io/prog_bar.cc regression/res_mng/dbg_ex_allocator_base.cc \
412 performance/time/elapsed_timer.cc ]
413 foreach f $source_files {
414 set obj [file rootname $f].o
415 set object_file [file tail $obj]
416 # Compile with "-w" so that warnings issued by the compiler
417 # do not prevent compilation.
418 if { [v3_target_compile $srcdir/util/$f $object_file "object" \
419 [list "incdir=$srcdir" "additional_flags=-w"]]
420 != "" } {
421 error "could not compile $f"
423 append v3-test_objs "$object_file "
426 # Collect into libtestc++.a
427 set arcommand "ar -rc ./libtestc++.a ${v3-test_objs}"
428 set result [lindex [local_exec "$arcommand" "" "" 300] 0]
429 verbose "link result is $result"
430 if { $result == 0 } {
431 set ranlibcommand "ranlib ./libtestc++.a"
432 set result [lindex [local_exec "$ranlibcommand" "" "" 300] 0]
433 if { $result != 0 } {
434 error "could not link libtestc++.a"
436 # We cannot actually use libtestc++.a because it's hard to
437 # position this library after the test file being compiled
438 # on the constructed compile line. However, we use this as
439 # a convenience for performance testing.
440 #set v3-test_objs "./libtestc++.a"
444 # Build any shared objects needed for regression testing.
445 if { ${v3-sharedlib} == 1 } {
446 set source_files [list testsuite_shared.cc]
447 foreach f $source_files {
448 set object_file [file rootname $f].so
449 # Compile with "-w" so that warnings issued by the compiler
450 # do not prevent compilation.
451 if { [v3_target_compile $srcdir/util/$f $object_file "sharedlib" \
452 [list "incdir=$srcdir" "additional_flags=-w -shared -fPIC -DPIC"]]
453 != "" } {
454 error "could not compile $f"
460 proc check_v3_target_sharedlib { } {
461 global v3-sharedlib
462 return ${v3-sharedlib}
465 proc check_v3_target_namedlocale { } {
466 global et_namedlocale_saved
467 global et_namedlocale_target_name
468 global tool
470 if { ![info exists et_namedlocale_target_name] } {
471 set et_namedlocale_target_name ""
474 # If the target has changed since we set the cached value, clear it.
475 set current_target [current_target_name]
476 if { $current_target != $et_namedlocale_target_name } {
477 verbose "check_v3_target_namedlocale: `$et_namedlocale_target_name'" 2
478 set et_namedlocale_target_name $current_target
479 if [info exists et_namedlocale_saved] {
480 verbose "check_v3_target_namedlocale: removing cached result" 2
481 unset et_namedlocale_saved
485 if [info exists et_namedlocale_saved] {
486 verbose "check_v3_target_namedlocale: using cached result" 2
487 } else {
488 set et_namedlocale_saved 0
490 # Set up, compile, and execute a C++ test program that tries to use
491 # all the required named locales.
492 set src nlocale[pid].cc
493 set exe nlocale[pid].x
495 set f [open $src "w"]
496 puts $f "#include <locale>"
497 puts $f "using namespace std;"
498 puts $f "int main ()"
499 puts $f "{"
500 puts $f " try"
501 puts $f " {"
502 puts $f " locale(\"\");"
503 puts $f " locale(\"de_DE\");"
504 puts $f " locale(\"de_DE.ISO-8859-15@euro\");"
505 puts $f " locale(\"de_DE@euro\");"
506 puts $f " locale(\"en_HK\");"
507 puts $f " locale(\"en_PH\");"
508 puts $f " locale(\"en_US\");"
509 puts $f " locale(\"en_US.ISO-8859-1\");"
510 puts $f " locale(\"en_US.ISO-8859-15\");"
511 puts $f " locale(\"en_US.UTF-8\");"
512 puts $f " locale(\"es_ES\");"
513 puts $f " locale(\"es_MX\");"
514 puts $f " locale(\"fr_FR\");"
515 puts $f " locale(\"fr_FR@euro\");"
516 puts $f " locale(\"is_IS\");"
517 puts $f " locale(\"is_IS.UTF-8\");"
518 puts $f " locale(\"it_IT\");"
519 puts $f " locale(\"ja_JP.eucjp\");"
520 puts $f " locale(\"se_NO.UTF-8\");"
521 puts $f " locale(\"ta_IN\");"
522 puts $f " locale(\"zh_TW\");"
523 puts $f " return 0;"
524 puts $f " }"
525 puts $f " catch(...)"
526 puts $f " {"
527 puts $f " return 1;"
528 puts $f " }"
529 puts $f "}"
530 close $f
532 set lines [v3_target_compile $src $exe executable ""]
533 file delete $src
535 if [string match "" $lines] {
536 # No error message, compilation succeeded.
537 set result [${tool}_load "./$exe" "" ""]
538 set status [lindex $result 0]
539 remote_file build delete $exe
541 verbose "check_v3_target_namedlocale: status is <$status>" 2
543 if { $status == "pass" } {
544 set et_namedlocale_saved 1
546 } else {
547 verbose "check_v3_target_namedlocale: compilation failed" 2
550 return $et_namedlocale_saved
553 proc check_v3_target_debug_mode { } {
554 global cxxflags
555 global et_debug_mode
557 global tool
559 if { ![info exists et_debug_mode_target_name] } {
560 set et_debug_mode_target_name ""
563 # If the target has changed since we set the cached value, clear it.
564 set current_target [current_target_name]
565 if { $current_target != $et_debug_mode_target_name } {
566 verbose "check_v3_target_debug_mode: `$et_debug_mode_target_name'" 2
567 set et_debug_mode_target_name $current_target
568 if [info exists et_debug_mode] {
569 verbose "check_v3_target_debug_mode: removing cached result" 2
570 unset et_debug_mode
574 if [info exists et_debug_mode] {
575 verbose "check_v3_target_debug_mode: using cached result" 2
576 } else {
577 set et_debug_mode 0
579 # Set up, compile, and execute a C++ test program that depends
580 # on debug mode working.
581 set src debug_mode[pid].cc
582 set exe debug_mode[pid].exe
584 set f [open $src "w"]
585 puts $f "#include <string>"
586 puts $f "using namespace std;"
587 puts $f "int main()"
588 puts $f "{ return 0; }"
589 close $f
591 set cxxflags_saved $cxxflags
592 set cxxflags "$cxxflags -Werror -O0 -D_GLIBCXX_DEBUG"
593 set lines [v3_target_compile $src $exe executable ""]
594 set cxxflags $cxxflags_saved
595 file delete $src
597 if [string match "" $lines] {
598 # No error message, compilation succeeded.
599 set et_debug_mode 1
602 verbose "check_v3_target_debug_mode: $et_debug_mode" 2
603 return $et_debug_mode