1 # Copyright (C) 2001 Free Software Foundation, Inc.
3 # This program is free software; you can redistribute it and/or modify
4 # it under the terms of the GNU General Public License as published by
5 # the Free Software Foundation; either version 2 of the License, or
6 # (at your option) any later version.
8 # This program is distributed in the hope that it will be useful,
9 # but WITHOUT ANY WARRANTY; without even the implied warranty of
10 # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
11 # GNU General Public License for more details.
13 # You should have received a copy of the GNU General Public License
14 # along with this program; if not, write to the Free Software
15 # Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
17 # Please email any bugs, comments, and/or additions to this file to:
18 # libstdc++@gcc.gnu.org
20 # This file is contributed by Gabriel Dos Reis <gdr@codesourcery.com>
22 ## This file contains support routines for dg.exp based testsuite
25 ## The global associative array lib_env contains the totality
26 ## of options necessary to run testcases; the meanings of which are
28 ## lib_env(CXX) The compiler used to run testcases.
29 ## lib_env(CXXFLAGS) Special flags passed to the compiler.
30 ## lib_env(INCLUDES) Includes options to pass to the compiler.
31 ## lib_env(LDFLAGS) Additional library flags.
32 ## lib_env(LIBTOOL) Path to the `libtool' script.
33 ## lib_env(SRC_DIR) Where V3 master source lives.
34 ## lib_env(BUILD_DIR) Where V3 is built.
35 ## lib_env(static) Flags to pass to the linker to build a
36 ## statically linked executable.
37 ## lib_env(shared) Flags to pass to the linker to build a
38 ## dynamically linked executable.
39 ## lib_env(testcase_options) Options specified by current testcase.
40 ## These are specified through the @xxx@-keywords.
45 ## Initialization routine.
46 proc libstdc++-dg-init { args } {
50 global dg-do-what-default
52 # By default, we assume we want to run program images.
53 set dg-do-what-default run
55 # Get out the source and the build directories.
56 set src-dir [lookfor_file $srcdir libstdc++-v3]
57 set build-dir [lookfor_file $outdir libstdc++-v3]
59 # Set proper environment variables for the framework.
60 libstdc++-setup-flags ${src-dir} ${build-dir}
62 # mkcheck.in used to output these information.
63 set output [remote_exec host $lib_env(CXX) -v]
64 if { [lindex $output 0] == 0 } {
65 set output [lindex $output 1]
66 regexp "gcc version.*$" $output version
67 regsub "\n+" $version "" version
68 clone_output "Compiler: $version"
69 clone_output "Compiler flags: $lib_env(CXXFLAGS)"
71 perror "Cannot determine compiler version: [lindex $output 1]"
75 ## dg.exp callback. Called from dg-test to run PROGRAM.
77 ## This is the heart of the framework. For the time being, it is
78 ## pretty much baroque, but it will improve as time goes.
79 proc libstdc++_load { prog } {
81 set opts $lib_env(testcase_options)
82 set results [remote_load target $lib_env(LIBTOOL) "--mode=execute $prog"]
84 if { [lindex $results 0] == "pass" && [info exists opts(diff)] } {
85 # FIXME: We should first test for any mentioned @output@ file here
86 # before taking any other action.
88 set firsts [glob -nocomplain [lindex $opts(diff) 0]]
89 set seconds [glob -nocomplain [lindex $opts(diff) 1]]
90 foreach f $firsts s $seconds {
91 if { [diff $f $s] == 0 } {
92 # FIXME: Well we should report a message. But for the time
93 # being, just pretend there is nothing much to say.
94 # Yes, that is silly, I know. But we need, first, to
95 # to have a working framework.
103 ## Nothing particular to do.
104 proc libstdc++_exit { } {
107 ## Output the version of the libs tested.
108 proc libstdc++_version { } {
110 set version "undeterminated"
112 # This file contains the library configuration, built at configure time.
113 set config-file $lib_env(BUILD_DIR)/include/bits/c++config.h
115 set version_pattern "__GLIBCPP__\[ \t\]\+\[0-9\]\+"
116 if [file exists ${config-file}] {
117 set version [grep ${config-file} $version_pattern]
118 regexp "\[0-9\]\+" $version version
120 clone_output "$lib_env(SRC_DIR) version $version"
124 ## Main loop. Loop over TEST-DIRECTORIES and run each testcase
126 proc libstdc++_runtest { testdirs } {
131 set top-tests-dir [pwd]
132 foreach d $testdirs {
133 set testfiles [glob -nocomplain $d/*.C $d/*.cc]
134 if { [llength $testfiles] == 0 } {
138 # Make the appropriate test-dirs with related .libs/ subdir
139 # to keep libtool happy.
140 set td "$outdir/[dg-trim-dirname $srcdir $d]"
141 maybe-make-directory $td
142 maybe-make-directory $td/.libs
145 foreach testfile $testfiles {
146 # If we're not supposed to test this file, just skip it.
147 if ![runtest_file_p $runtests $testfile] {
151 # verbose "Testing [dg-trim-dirname $srcdir $testfile]"
152 libstdc++_do_test $testfile static
153 libstdc++_do_test $testfile shared
159 ## dg.exp callback. Main test-running routine. Called from
162 ## TESTCASE is the file-name of the program to test;
163 ## COMPILE_TYPE is the kind of compilation to apply to TESTCASE;
164 ## current compilation kinds are: preprocess, compile,
165 ## assemble, link, run.
166 proc libstdc++-dg-test { testfile compile_type additional-options } {
167 global srcdir; global outdir
171 # Prepare for compilation output
174 # By default, we want to use libtool to compile and run tests.
175 set lt $lib_env(LIBTOOL)
176 set lt_args "--tag=CXX"
178 libstdc++-process-options $testfile
179 set output_file [file rootname [file tail $testfile]]
180 switch $compile_type {
183 set lt_args "-E $lib_env(INCLUDES) $testfile -o $output_file.ii"
187 set lt_args "-S $lib_env(INCLUDES) $testfile -o $output_file.s"
190 append lt_args " --mode=compile $lib_env(FLAGS) $testfile"
194 # If we're asked to run a testcase, then just do a `link'.
195 # Later, the framework will load the program image through
196 # libstdc++_load callback.
197 if { $which_library == "static" } {
198 append output_file ".st-exe"
200 append output_file ".sh-exe"
202 append lt_args " --mode=link $lib_env(FLAGS) \
203 $lib_env($which_library) $testfile \
204 -o $output_file $lib_env(LDFLAGS)"
207 perror "$compile_type: option not recognized"
211 set results [remote_exec host $lt "$lt_args ${additional-options}"]
212 if { [lindex $results 0] != 0 } {
213 set comp_output [lindex $results 1];
215 return [list $comp_output $output_file]
218 ## Get options necessary to properly run testcases.
219 ## SRC-DIR is the library top source directory e.g. something like
220 ## /codesourcery/egcs/libstdc++
221 ## BUILD-DIR is top build directory e.g. something like
222 ## /tmp/egcs/i686-pc-linux-gnu/libstdc++
223 proc libstdc++-setup-flags {src-dir build-dir} {
226 set tmp [remote_exec host ${build-dir}/tests_flags "--built-library ${build-dir} ${src-dir}"]
227 set status [lindex $tmp 0]
228 set output [lindex $tmp 1]
229 if { $status == 0 } {
230 set flags [split $output :]
231 set lib_env(BUILD_DIR) [lindex $flags 0]
232 set lib_env(SRC_DIR) [lindex $flags 1]
233 set lib_env(CXX) [lindex $flags 3]
234 set lib_env(CXXFLAGS) [lindex $flags 4]
235 set lib_env(INCLUDES) [lindex $flags 5]
236 set lib_env(LDFLAGS) [lindex $flags 6]
238 # This is really really fragile. We should find a better away to
239 # tell the framework which flags to use for static/shared libraries.
240 set lib_env(static) "-static"
241 set lib_env(shared) ""
243 set lib_env(LIBTOOL) "$lib_env(BUILD_DIR)/libtool"
244 set lib_env(FLAGS) "$lib_env(CXX) -B$lib_env(BUILD_DIR)/ \
245 $lib_env(INCLUDES) $lib_env(CXXFLAGS)"
251 proc maybe-make-directory {dir} {
252 if {![file isdirectory $dir]} {
257 proc libstdc++_do_test { testfile lib } {
258 global which_library; set which_library $lib
259 ## Is it planed to handle -keep-output throught @xxx@-option
260 dg-test -keep-output $testfile "" ""
263 ## Process @xxx@ options.
264 proc libstdc++-process-options { testfile } {
267 array set opts { diff {} output {} require {} }
268 set percent [file rootname [file tail $testfile]]
269 set option-pattern "@.*@.*"
270 set results [grep $testfile ${option-pattern}]
272 if ![string match "" $results] {
274 regexp "@(.*)@(.*)" $o o key value
275 regsub -all "%" $value "$percent" value
277 # Not yet supported: keep-output, output, link-against
285 perror "libstdc++: Invalid option-specification `$o'"
288 set opts($key) $value
292 set lib_env(testcase_options) [array get opts]
294 # copy any required data files.
295 if ![string match "" $opts(require)] {
296 set src [file dirname $testfile]
298 foreach f $opts(require) {
299 foreach t [glob -nocomplain "$src/$f"] {
300 file copy -force $t $dst