OSDN Git Service

2002-01-22 H.J. Lu <hjl@gnu.org>
[pf3gnuchains/gcc-fork.git] / gcc / testsuite / lib / mike-g++.exp
1 # Copyright (C) 1988, 90, 91, 92, 95, 96, 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, 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
16
17 # This file was written by Mike Stump <mrs@cygnus.com>
18
19 #
20 # mike_cleanup -- remove any files that are created by the testcase
21 #
22 proc mike_cleanup { src_code output_file assembly_file } {
23     remote_file build delete $output_file $assembly_file;
24 }
25
26 #
27 # prebase -- sets up a Mike Stump (mrs@cygnus.com) style G++ test
28 #
29 proc prebase { } {
30     global compiler_output
31     global not_compiler_output
32     global compiler_result
33     global not_compiler_result
34     global program_output
35     global groups
36     global run 
37     global actions
38     global target_regexp
39
40     set compiler_output "^$"
41     set not_compiler_output ".*Internal compiler error.*"
42     set compiler_result ""
43     set not_compiler_result ""
44     set program_output ".*PASS.*"
45     set groups {}
46     set run no
47     set actions assemble
48     set target_regexp ".*"
49 }
50
51 #
52 # run the test
53 #
54 proc postbase  { src_code run groups args } {
55     global verbose
56     global srcdir
57     global subdir
58     global not_compiler_output
59     global compiler_output
60     global compiler_result
61     global not_compiler_result
62     global program_output
63     global actions
64     global target_regexp
65     global host_triplet
66     global target_triplet
67     global tool
68     global tmpdir
69     global objdir
70     global base_dir
71
72     if ![regexp $target_regexp $target_triplet] {
73         unsupported $subdir/$src_code
74         return
75     }
76
77     if { [llength $args] > 0 } {
78         set comp_options [lindex $args 0];
79     } else {
80         set comp_options ""
81     }
82
83     set fail_message $subdir/$src_code
84     set pass_message $subdir/$src_code
85
86     if [info exists GROUP] {
87         if {[lsearch $groups $GROUP] == -1} {
88             return
89         }
90     }
91
92     if [string match $run yes] {
93         set actions run
94     }
95
96     set output_file "$tmpdir/[file tail [file rootname $src_code]]"
97     set assembly_file "$output_file"
98     append assembly_file ".S"
99
100     set compile_type "none"
101
102     case $actions {
103         compile
104         {
105             set compile_type "assembly";
106             set output_file $assembly_file;
107         }
108         assemble
109         {
110             set compile_type "object";
111             append output_file ".o";
112         }
113         link
114         {
115             set compile_type "executable";
116             append output_file ".exe";
117         }
118         run
119         {
120             set compile_type "executable";
121             append output_file ".exe";
122             set run yes;
123         }
124         default
125         {
126             set output_file "";
127             set compile_type "none";
128         }
129     }
130
131     set src_file "$srcdir/$subdir/$src_code"
132     set options ""
133
134     if { $comp_options != "" } {
135         lappend options "additional_flags=$comp_options"
136     }
137
138     if ![ishost "*-dos-*"] {
139         lappend options "libs=-lstdc++ -lg++"
140     } else {
141         lappend options "libs=-lstdcxx -lgxx"
142     }
143
144     set comp_output [g++_target_compile $src_file $output_file $compile_type $options]
145
146     set pass no
147
148     # Delete things like "ld.so warning" messages.
149     set comp_output [prune_warnings $comp_output]
150
151     if [regexp -- $not_compiler_output $comp_output] {
152         if { $verbose > 1 } {
153             send_user "\nChecking:\n$not_compiler_output\nto make sure it does not match:\n$comp_output\nbut it does.\n\n"
154         } else {
155             send_log "\nCompiler output:\n$comp_output\n\n"
156         }
157         fail $fail_message
158         # The framework doesn't like to see any error remnants,
159         # so remove them.
160         uplevel {
161             if [info exists errorInfo] {
162                 unset errorInfo
163             }
164         }
165         mike_cleanup $src_code $output_file $assembly_file
166         return
167     }
168
169     # remove any leftover CRs.
170     regsub -all -- "\r" $comp_output "" comp_output
171
172     regsub -all "(^|\n)\[^\n\]*linker input file unused since linking not done" $comp_output "" comp_output
173     regsub -all "(^|\n)\[^\n\]*file path prefix \[^\n\]* never used" $comp_output "" comp_output
174
175     set unsupported_message [${tool}_check_unsupported_p $comp_output]
176     if { $unsupported_message != "" } {
177         unsupported "$subdir/$src_code: $unsupported_message"
178         mike_cleanup $src_code $output_file $assembly_file
179         return
180     }
181
182     if { $verbose > 1 } {
183         send_user "\nChecking:\n$compiler_output\nto see if it matches:\n$comp_output\n"
184     } else {
185         send_log "\nCompiler output:\n$comp_output\n\n"
186     }
187     if [regexp -- $compiler_output $comp_output] {
188         if { $verbose > 1 } {
189             send_user "Yes, it matches.\n\n"
190         }
191         set pass yes
192         if [file exists [file rootname [file tail $src_code]].s] {
193             set fd [open [file rootname [file tail $src_code]].s r]
194             set dot_s [read $fd]
195             close $fd
196             if { $compiler_result != "" } {
197                 verbose "Checking .s file for $compiler_result" 2
198                 if [regexp -- $compiler_result $dot_s] {
199                     verbose "Yes, it matches." 2
200                 } else {
201                     verbose "Nope, doesn't match." 2
202                     verbose $dot_s 4
203                     set pass no
204                 }
205             }
206             if { $not_compiler_result != "" } {
207                 verbose "Checking .s file for not $not_compiler_result" 2
208                 if ![regexp -- $not_compiler_result $dot_s] {
209                     verbose "Nope, not found (that's good)." 2
210                 } else {
211                     verbose "Uh oh, it was found." 2
212                     verbose $dot_s 4
213                     set pass no
214                 }
215             }
216         }
217         if [string match $run yes] {
218             set result [g++_load $output_file]
219             set status [lindex $result 0];
220             set output [lindex $result 1];
221
222             if { $status == -1 } {
223                 mike_cleanup $src_code $output_file $assembly_file;
224                 return;
225             }
226             if { $verbose > 1 } {
227                 send_user "Checking:\n$program_output\nto see if it matches:\n$output\n\n"
228             }
229             if ![regexp -- $program_output $output] {
230                 set pass no
231                 if { $verbose > 1 } {
232                     send_user "Nope, does not match.\n\n"
233                 }
234             } else {
235                 if { $verbose > 1 } {
236                     send_user "Yes, it matches.\n\n"
237                 }
238             }
239         }
240     } else {
241         if { $verbose > 1 } {
242             send_user "Nope, does not match.\n\n"
243         }
244     }
245
246     if [string match $pass "yes"] {
247         pass $pass_message
248     } else {
249         fail $fail_message
250     }
251
252     # The framework doesn't like to see any error remnants,
253     # so remove them.
254     uplevel {
255         if [info exists errorInfo] {
256             unset errorInfo
257         }
258     }
259
260     mike_cleanup $src_code $output_file $assembly_file
261 }