OSDN Git Service

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