OSDN Git Service

2001-01-28 Gabriel Dos Reis <gdr@codesourcery.com>
[pf3gnuchains/gcc-fork.git] / libstdc++-v3 / testsuite / lib / libstdc++.exp
1 # Copyright (C) 2001 Free Software Foundation, Inc.
2
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.
7
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.
12
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.  
16
17 # Please email any bugs, comments, and/or additions to this file to:
18 # libstdc++@gcc.gnu.org
19 #
20 # This file is contributed by Gabriel Dos Reis <gdr@codesourcery.com>
21
22 ## This file contains support routines for dg.exp based testsuite
23 ## framework.
24
25 ## The global associative array lib_env contains the totality
26 ## of options necessary to run testcases; the meanings of which are
27 ## as follows:
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.
41
42
43 load_lib dg.exp
44
45 ## Initialization routine.
46 proc libstdc++-dg-init { args } {
47     global lib_env
48     global srcdir
49     global outdir
50     global dg-do-what-default
51
52     # By default, we assume we want to run program images.
53     set dg-do-what-default run
54
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]
58
59     # Set proper environment variables for the framework.
60     libstdc++-setup-flags ${src-dir} ${build-dir}
61     
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)"
70     } else {
71         perror "Cannot determine compiler version: [lindex $output 1]"
72     }
73 }
74
75 ## dg.exp callback.  Called from dg-test to run PROGRAM.
76 ##
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 } {
80     global lib_env
81     set opts $lib_env(testcase_options)
82     set results [remote_load target $lib_env(LIBTOOL) "--mode=execute $prog"]
83
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.
87
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.
96                 break
97             }
98         }
99     }
100     return $results
101 }
102
103 ## Nothing particular to do.
104 proc libstdc++_exit { } {
105 }
106
107 ## Output the version of the libs tested.
108 proc libstdc++_version { } {
109     global lib_env
110     set version "undeterminated" 
111
112     # This file contains the library configuration, built at configure time.
113     set config-file $lib_env(BUILD_DIR)/include/bits/c++config.h
114     
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
119     }
120     clone_output "$lib_env(SRC_DIR) version $version"
121     return 0
122 }
123
124 ## Main loop.  Loop over TEST-DIRECTORIES and run each testcase
125 ## found therein.
126 proc libstdc++_runtest { testdirs } {
127     global runtests
128     global srcdir
129     global outdir
130
131     set top-tests-dir [pwd]
132     foreach d $testdirs {
133         set testfiles [glob -nocomplain $d/*.C $d/*.cc]
134         if { [llength $testfiles] == 0 } {
135             continue
136         }
137         
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
143
144         cd $td;
145         foreach testfile $testfiles {
146             # If we're not supposed to test this file, just skip it.
147             if ![runtest_file_p $runtests $testfile] {
148                 continue
149             }
150             
151 #           verbose "Testing [dg-trim-dirname $srcdir $testfile]"
152             libstdc++_do_test $testfile static
153             libstdc++_do_test $testfile shared
154         }
155         cd ${top-tests-dir}
156     }
157 }
158
159 ## dg.exp callback.  Main test-running routine.  Called from
160 ## dg-test.
161 ##
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
168     global lib_env
169     global which_library
170     
171     # Prepare for compilation output
172     set comp_output ""
173
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"
177     
178     libstdc++-process-options $testfile
179     set output_file [file rootname [file tail $testfile]]
180     switch $compile_type {
181         "preprocess" {
182             set lt $lib_env(CXX)
183             set lt_args "-E $lib_env(INCLUDES) $testfile -o $output_file.ii"
184         }
185         "compile" {
186             set lt $lib_env(CXX)
187             set lt_args "-S $lib_env(INCLUDES) $testfile -o $output_file.s"
188         }
189         "assemble" {
190             append lt_args " --mode=compile $lib_env(FLAGS) $testfile"
191         }
192         "run" -
193         "link" {
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"
199             } else {
200                 append output_file ".sh-exe"
201             }
202             append lt_args " --mode=link $lib_env(FLAGS) \
203                     $lib_env($which_library) $testfile \
204                     -o $output_file $lib_env(LDFLAGS)"
205         }
206         default {
207             perror "$compile_type: option not recognized"
208         }
209     }
210
211     set results [remote_exec host $lt "$lt_args ${additional-options}"]
212     if { [lindex $results 0] != 0 } {
213         set comp_output [lindex $results 1];
214     }
215     return [list $comp_output $output_file]
216 }
217
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} {
224     global lib_env
225     
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]
237         
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) ""
242
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)"
246     } else {
247         perror "$output"
248     }
249 }
250
251 proc maybe-make-directory {dir} {
252     if {![file isdirectory $dir]} {
253         file mkdir $dir
254     }
255 }
256
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 "" ""
261 }
262
263 ## Process @xxx@ options.
264 proc libstdc++-process-options { testfile } {
265     global lib_env
266
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}]
271
272     if ![string match "" $results] {
273         foreach o $results {
274             regexp "@(.*)@(.*)" $o o key value
275             regsub -all "%" $value "$percent" value
276
277             # Not yet supported: keep-output, output, link-against
278             switch $key {
279                 "diff" -
280                 "keep-output" -
281                 "link-against" -
282                 "output" -
283                 "require" { }
284                 default {
285                     perror "libstdc++: Invalid option-specification `$o'"
286                 }
287             }
288             set opts($key) $value 
289             unset key value
290         }
291     }
292     set lib_env(testcase_options) [array get opts]
293     
294     # copy any required data files.
295     if ![string match "" $opts(require)] {
296         set src [file dirname $testfile]
297         set dst [pwd]
298         foreach f $opts(require) {
299             foreach t [glob -nocomplain "$src/$f"] {
300                 file copy -force $t $dst
301             }
302         }
303     }
304 }