Initial import from FreeBSD RELENG_4:
[dragonfly.git] / contrib / libstdc++ / testsuite / lib / libstdc++.exp
1 # Copyright (C) 1997 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 # bug-lib-g++@prep.ai.mit.edu
19
20 # This file was written by Bob Manson. (manson@cygnus.com)
21
22 load_lib "libgloss.exp"
23
24 global tmpdir
25
26 if ![info exists tmpdir] {
27     set tmpdir "/tmp"
28 }
29
30 #
31 # Build the status wrapper library as needed.
32 #
33 proc libstdc++_init { args } {
34     global wrapper_file;
35     global wrap_compile_flags;
36     set wrapper_file "";
37     set wrap_compile_flags "";
38     if [target_info exists needs_status_wrapper] {
39         set result [build_wrapper "testglue.o"];
40         if { $result != "" } {
41             set wrapper_file [lindex $result 0];
42             set wrap_compile_flags [lindex $result 1];
43         } else {
44             warning "Status wrapper failed to build."
45         }
46     }
47 }
48 #
49 # Run the test specified by srcfile and resultfile. compile_args and
50 # exec_args are additional arguments to be passed in when compiling and
51 # running the testcase, respectively.
52 #
53
54 proc test_libstdc++ { options srcfile compile_args inpfile resultfile exec_args } {
55     global base_dir
56     global LIBSTDCPP
57     global srcdir subdir objdir
58     global TOOL_OPTIONS
59     global ld_library_path
60
61     if [info exists LIBSTDCPP] {
62         set libstdcpp $LIBSTDCPP;
63     } else {
64         set gp [get_multilibs];
65         if { $gp != "" } {
66             if [file exists "$gp/libstdc++/libstdc++.a"] {
67                 set libstdcpp "-L$gp/libstdc++ -lstdc++";
68             }
69         }
70         if ![info exists libstdcpp] {
71         set libstdcpp [findfile $base_dir/../../libstdc++/libstdc++.a "-L$base_dir/../../libstdc++ -lstdc++" -lstdc++]
72         }
73     }
74
75     verbose "using LIBSTDCPP = $libstdcpp" 2
76     set args ""
77
78     # Basically we want to build up a colon separated path list from
79     # the value of $libstdcpp.
80
81     # First strip away any -L arguments.
82     regsub -all -- "-L" $libstdcpp "" ld_library_path
83
84     # Then remove any -lstdc++ argument.
85     regsub -all -- " -lstdc.." $ld_library_path "" ld_library_path
86
87     # That's enough to make things work for the normal case.
88     # If we wanted to handle an arbitrary value of libstdcpp,
89     # then we'd have to do a lot more work.
90
91     if { $compile_args != "" } {
92         lappend args "additional_flags=$compile_args"
93     }
94     lappend args "incdir=.."
95     lappend args "incdir=$srcdir/.."
96     lappend args "incdir=$srcdir/../stl"
97     lappend args "incdir=."
98     if [info exists TOOL_OPTIONS] {
99         lappend args "additional_flags=$TOOL_OPTIONS"
100     }
101
102     global wrapper_file wrap_compile_flags;
103     # We have to include libio, for _G_config.h.
104     lappend args "additional_flags=$wrap_compile_flags";
105     lappend args "libs=$wrapper_file";
106     lappend args "libs=$libstdcpp";
107     lappend args "additional_flags=[libio_include_flags]"
108     lappend args debug
109
110     regsub "^.*/(\[^/.\]+)\[.\]\[^/]*$" "$srcfile" "\\1" out
111     set executable "${objdir}/$out"
112     set errname "[file tail $srcfile]"
113     if { $compile_args != "" } {
114         set errname "$errname $compile_args"
115     }
116
117     if { [target_compile $srcfile "$executable" executable $args] != "" } {
118         fail "$errname compilation"
119         setup_xfail "*-*-*"
120         fail "$errname execution"
121         setup_xfail "*-*-*"
122         fail "$errname output"
123         return;
124     }
125     pass "$errname compilation"
126
127     set result [libstdc++_load $executable "$exec_args" "$inpfile"];
128     set status [lindex $result 0];
129     set output [lindex $result 1];
130     $status "$errname execution"
131     if { $status != "pass" } {
132         setup_xfail "*-*-*"
133         fail "$errname output"
134         return;
135     }
136
137     verbose "resultfile is $resultfile"
138     set id [open $resultfile r];
139     set expected ""
140     append expected [read $id];
141     regsub -all "\r" "$output" "" output;
142     regsub "\n*$" $expected "" expected
143     regsub "\n*$" $output "" output
144     regsub "^\n*" $expected "" expected
145     regsub "^\n*" $output "" output
146     regsub -all "\[ \t\]\[ \t\]*" $expected " " expected
147     regsub -all "\[ \t\]*\n\n*" $expected "\n" expected
148     regsub -all "\[ \t\]\[ \t\]*" $output " " output
149     regsub -all "\[ \t\]*\n\n*" $output "\n" output
150     verbose "expected is $expected"
151     verbose "actual is $output"
152     set passed 0;
153     if {$options == "regexp_match"} {
154         if [regexp $expected $output] {
155             set passed 1;
156         }
157     } else {
158         if { $expected == $output } {
159             set passed 1;
160         }
161     }
162     if { $passed == 1 } {
163         pass "$errname output"
164     } else {
165         clone_output "expected was $expected"
166         clone_output "output was $output"
167         fail "$errname output"
168     }
169     close $id;
170 }
171
172 #
173 # libstdc++_version -- extract and print the version number of libstdc++p
174 #
175 proc default_libstdc++_version {} {
176 }
177
178 proc default_libstdc++_start { } {
179 }