OSDN Git Service

b8721a5029541ddff4ef965347f36e96f3ad0962
[pf3gnuchains/gcc-fork.git] / gcc / testsuite / lib / f-torture.exp
1 # Copyright (C) 1992, 1993, 1994, 1995, 1996, 1997, 1998, 2000 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 # Please email any bugs, comments, and/or additions to this file to:
18 # bug-dejagnu@gnu.org.
19
20 # This file was written by Rob Savoye. (rob@cygnus.com)
21
22 # The default option list can be overridden by
23 # TORTURE_OPTIONS="{ { list1 } ... { listN } }"
24
25 if ![info exists TORTURE_OPTIONS] {
26     set TORTURE_OPTIONS [list \
27         { -O0 } { -O1 } { -O2 } \
28         { -O2 -fomit-frame-pointer -finline-functions } \
29         { -O2 -fomit-frame-pointer -finline-functions -funroll-loops } \
30         { -O2 -fomit-frame-pointer -finline-functions -funroll-all-loops } \
31         { -O3 -g } \
32         { -Os }]
33 }
34
35
36 # Split TORTURE_OPTIONS into two choices: one for testcases with loops and
37 # one for testcases without loops.
38
39 set torture_with_loops $TORTURE_OPTIONS
40 set torture_without_loops ""
41 foreach option $TORTURE_OPTIONS {
42     if ![string match "*loop*" $option] {
43         lappend torture_without_loops $option
44     }
45 }
46
47 #
48 # f-torture-compile -- runs the Tege C-torture test
49 #
50 # SRC is the full pathname of the testcase.
51 # OPTION is the specific compiler flag we're testing (eg: -O2).
52 #
53 proc f-torture-compile { src option } {
54     global output
55     global srcdir tmpdir
56     global host_triplet
57
58     set output "$tmpdir/[file tail [file rootname $src]].o"
59
60     regsub "^$srcdir/?" $src "" testcase
61     # If we couldn't rip $srcdir out of `src' then just do the best we can.
62     # The point is to reduce the unnecessary noise in the logs.  Don't strip
63     # out too much because different testcases with the same name can confuse
64     # `test-tool'.
65     if [string match "/*" $testcase] {
66         set testcase "[file tail [file dirname $src]]/[file tail $src]"
67     }
68
69     verbose "Testing $testcase, $option" 1
70
71     # Run the compiler and analyze the results.
72     set options ""
73     lappend options "additional_flags=-w $option"
74
75     set comp_output [g77_target_compile "$src" "$output" object $options];
76     
77     # Set a few common compiler messages.
78     set fatal_signal "*77*: Internal compiler error: program*got fatal signal"
79  
80     if [string match "$fatal_signal 6" $comp_output] then {
81         g77_fail $testcase "Got Signal 6, $option"
82         remote_file build delete $output
83         return
84     }
85
86     if [string match "$fatal_signal 11" $comp_output] then {
87         g77_fail $testcase "Got Signal 11, $option"
88         remote_file build delete $output
89         return
90     }
91
92     # We shouldn't get these because of -w, but just in case.
93     if [string match "*77*:*warning:*" $comp_output] then {
94         warning "$testcase: (with warnings) $option"
95         send_log "$comp_output\n"
96         unresolved "$testcase, $option"
97         remote_file build delete $output
98         return
99     }
100
101     set comp_output [prune_warnings $comp_output]
102
103     set unsupported_message [g77_check_unsupported_p $comp_output]
104     if { $unsupported_message != "" } {
105         unsupported "$testcase: $unsupported_message"
106         remote_file build delete $output
107         return
108     }
109
110     # remove any leftover LF/CR to make sure any output is legit
111     regsub -all -- "\[\r\n\]*" $comp_output "" comp_output
112     # If any message remains, we fail.
113     if ![string match "" $comp_output] then {
114         g77_fail $testcase $option
115         remote_file build delete $output
116         return
117     }
118
119     g77_pass $testcase $option
120     remote_file build delete $output
121 }
122
123 #
124 # f-torture-execute -- utility to compile and execute a testcase
125 #
126 # SRC is the full pathname of the testcase.
127 #
128 # If the testcase has an associated .x file, we source that to run the
129 # test instead.  We use .x so that we don't lengthen the existing filename
130 # to more than 14 chars.
131 #
132 proc f-torture-execute { src } {
133     global tmpdir tool srcdir output compiler_conditional_xfail_data
134
135     # Check for alternate driver.
136     if [file exists [file rootname $src].x] {
137         verbose "Using alternate driver [file rootname [file tail $src]].x" 2
138         set done_p 0
139         catch "set done_p \[source [file rootname $src].x\]"
140         if { $done_p } {
141             return
142         }
143     }
144    
145     # Look for a loop within the source code - if we don't find one,
146     # don't pass -funroll[-all]-loops.
147     global torture_with_loops torture_without_loops
148     if [expr [search_for $src "do *\[0-9\]"]+[search_for $src "end *do"]] then {
149         set option_list $torture_with_loops
150     } else {
151         set option_list $torture_without_loops
152     }
153
154     set executable $tmpdir/[file tail [file rootname $src].x]
155
156     regsub "^$srcdir/?" $src "" testcase
157     # If we couldn't rip $srcdir out of `src' then just do the best we can.
158     # The point is to reduce the unnecessary noise in the logs.  Don't strip
159     # out too much because different testcases with the same name can confuse
160     # `test-tool'.
161     if [string match "/*" $testcase] {
162         set testcase "[file tail [file dirname $src]]/[file tail $src]"
163     }
164
165     foreach option $option_list {
166         # torture_{compile,execute}_xfail are set by the .x script
167         # (if present)
168         if [info exists torture_compile_xfail] {
169             setup_xfail $torture_compile_xfail
170         }
171
172         # torture_execute_before_{compile,execute} can be set by the .x script
173         # (if present)
174         if [info exists torture_eval_before_compile] {
175             set ignore_me [eval $torture_eval_before_compile]
176         }
177
178         remote_file build delete $executable
179         verbose "Testing $testcase, $option" 1
180
181         set options ""
182         lappend options "additional_flags=-w $option"
183         set comp_output [g77_target_compile "$src" "$executable" executable $options];
184
185         # Set a few common compiler messages.
186         set fatal_signal "*77*: Internal compiler error: program*got fatal signal"
187         
188         if [string match "$fatal_signal 6" $comp_output] then {
189             g77_fail $testcase "Got Signal 6, $option"
190             remote_file build delete $executable
191             continue
192         }
193         
194         if [string match "$fatal_signal 11" $comp_output] then {
195             g77_fail $testcase "Got Signal 11, $option"
196             remote_file build delete $executable
197             continue
198         }
199         
200         # We shouldn't get these because of -w, but just in case.
201         if [string match "*77*:*warning:*" $comp_output] then {
202             warning "$testcase: (with warnings) $option"
203             send_log "$comp_output\n"
204             unresolved "$testcase, $option"
205             remote_file build delete $executable
206             continue
207         }
208         
209         set comp_output [prune_warnings $comp_output]
210         
211         set unsupported_message [g77_check_unsupported_p $comp_output]
212
213         if { $unsupported_message != "" } {
214             unsupported "$testcase: $unsupported_message"
215             continue
216         } elseif ![file exists $executable] {
217             if ![is3way] {
218                 fail "$testcase compilation, $option"
219                 untested "$testcase execution, $option"
220                 continue
221             } else {
222                 # FIXME: since we can't test for the existance of a remote
223                 # file without short of doing an remote file list, we assume
224                 # that since we got no output, it must have compiled.
225                 pass "$testcase compilation, $option"           
226             }
227         } else {
228             pass "$testcase compilation, $option"
229         }
230
231         # See if this source file uses "long long" types, if it does, and
232         # no_long_long is set, skip execution of the test.
233         if [target_info exists no_long_long] then {
234             if [expr [search_for $src "integer\*8"]] then {
235                 untested "$testcase execution, $option"
236                 continue
237             }
238         }
239
240         if [info exists torture_execute_xfail] {
241             setup_xfail $torture_execute_xfail
242         }
243
244         if [info exists torture_eval_before_execute] {
245             set ignore_me [eval $torture_eval_before_execute]
246         }
247
248         set result [g77_load "$executable" "" ""]
249         set status [lindex $result 0];
250         set output [lindex $result 1];
251         if { $status == "pass" } {
252             remote_file build delete $executable
253         }
254         $status "$testcase execution, $option"
255     }
256 }
257
258 #
259 # search_for -- looks for a string match in a file
260 #
261 proc search_for { file pattern } {
262     set fd [open $file r]
263     while { [gets $fd cur_line]>=0 } {
264         set lower [string tolower $cur_line]
265         if [regexp "$pattern" $lower] then {
266             close $fd
267             return 1
268         }
269     }
270     close $fd
271     return 0
272 }
273
274 #
275 # f-torture -- the f-torture testcase source file processor
276 #
277 # This runs compilation only tests (no execute tests).
278 # SRC is the full pathname of the testcase, or just a file name in which case
279 # we prepend $srcdir/$subdir.
280 #
281 # If the testcase has an associated .x file, we source that to run the
282 # test instead.  We use .x so that we don't lengthen the existing filename
283 # to more than 14 chars.
284 #
285 proc f-torture { args } {
286     global srcdir subdir compiler_conditional_xfail_data
287
288     set src [lindex $args 0];
289     if { [llength $args] > 1 } {
290         set options [lindex $args 1];
291     } else {
292         set options ""
293     }
294
295     # Prepend $srdir/$subdir if missing.
296     if ![string match "*/*" $src] {
297         set src "$srcdir/$subdir/$src"
298     }
299
300     # Check for alternate driver.
301     if [file exists [file rootname $src].x] {
302         verbose "Using alternate driver [file rootname [file tail $src]].x" 2
303         set done_p 0
304         catch "set done_p \[source [file rootname $src].x\]"
305         if { $done_p } {
306             return
307         }
308     }
309    
310     # Look for a loop within the source code - if we don't find one,
311     # don't pass -funroll[-all]-loops.
312     global torture_with_loops torture_without_loops
313     if [expr [search_for $src "do *\[0-9\]"]+[search_for $src "end *do"]] then {
314         set option_list $torture_with_loops
315     } else {
316         set option_list $torture_without_loops
317     }
318
319     # loop through all the options
320     foreach option $option_list {
321         # torture_compile_xfail is set by the .x script (if present)
322         if [info exists torture_compile_xfail] {
323             setup_xfail $torture_compile_xfail
324         }
325
326         # torture_execute_before_compile is set by the .x script (if present)
327         if [info exists torture_eval_before_compile] {
328             set ignore_me [eval $torture_eval_before_compile]
329         }
330
331         f-torture-compile $src "$option $options"
332     }
333 }