1 # Copyright (C) 1992, 1993, 1994, 1995, 1996, 1997, 1998 Free Software Foundation, Inc.
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.
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.
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.
17 # Please email any bugs, comments, and/or additions to this file to:
18 # bug-dejagnu@gnu.org.
20 # This file was written by Rob Savoye. (rob@cygnus.com)
22 # The default option list can be overridden by
23 # TORTURE_OPTIONS="{ { list1 } ... { listN } }"
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 } \
39 # Split TORTURE_OPTIONS into two choices: one for testcases with loops and
40 # one for testcases without loops.
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
51 # c-torture-compile -- runs the Tege C-torture test
53 # SRC is the full pathname of the testcase.
54 # OPTION is the specific compiler flag we're testing (eg: -O2).
56 proc c-torture-compile { src option } {
61 set output "$tmpdir/[file tail [file rootname $src]].o"
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
68 if [string match "/*" $testcase] {
69 set testcase "[file tail [file dirname $src]]/[file tail $src]"
72 verbose "Testing $testcase, $option" 1
74 # Run the compiler and analyze the results.
76 lappend options "additional_flags=-w $option"
78 set comp_output [gcc_target_compile "$src" "$output" object $options];
80 # Set a few common compiler messages.
81 set fatal_signal "*cc: Internal compiler error: program*got fatal signal"
83 if [string match "$fatal_signal 6" $comp_output] then {
84 gcc_fail $testcase "Got Signal 6, $option"
85 remote_file build delete $output
89 if [string match "$fatal_signal 11" $comp_output] then {
90 gcc_fail $testcase "Got Signal 11, $option"
91 remote_file build delete $output
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
104 set comp_output [prune_warnings $comp_output]
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
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
122 gcc_pass $testcase $option
123 remote_file build delete $output
127 # c-torture-execute -- utility to compile and execute a testcase
129 # SRC is the full pathname of the testcase.
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.
135 proc c-torture-execute { src args } {
136 global tmpdir tool srcdir output
138 if { [llength $args] > 0 } {
139 set additional_flags [lindex $args 0];
141 set additional_flags "";
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
147 catch "set done_p \[source [file rootname $src].x\]"
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
159 set option_list $torture_without_loops
162 set executable $tmpdir/[file tail [file rootname $src].x]
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
169 if [string match "/*" $testcase] {
170 set testcase "[file tail [file dirname $src]]/[file tail $src]"
175 foreach option $option_list {
177 set oldexec $execname;
179 set execname "${executable}${count}";
182 # torture_{compile,execute}_xfail are set by the .x script
184 if [info exists torture_compile_xfail] {
185 setup_xfail $torture_compile_xfail
188 # torture_execute_before_{compile,execute} can be set by the .x script
190 if [info exists torture_eval_before_compile] {
191 set ignore_me [eval $torture_eval_before_compile]
194 remote_file build delete $execname;
195 verbose "Testing $testcase, $option" 1
198 lappend options "additional_flags=-w $option"
199 if { $additional_flags != "" } {
200 lappend options "additional_flags=$additional_flags";
202 set comp_output [gcc_target_compile "$src" "${execname}" executable $options];
204 # Set a few common compiler messages.
205 set fatal_signal "*cc: Internal compiler error: program*got fatal signal"
207 if [string match "$fatal_signal 6" $comp_output] then {
208 gcc_fail $testcase "Got Signal 6, $option"
209 remote_file build delete $execname
213 if [string match "$fatal_signal 11" $comp_output] then {
214 gcc_fail $testcase "Got Signal 11, $option"
215 remote_file build delete $execname
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
228 set comp_output [prune_warnings $comp_output]
230 set unsupported_message [gcc_check_unsupported_p $comp_output]
232 if { $unsupported_message != "" } {
233 unsupported "$testcase: $unsupported_message"
235 } elseif ![file exists $execname] {
237 fail "$testcase compilation, $option"
238 untested "$testcase execution, $option"
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"
247 pass "$testcase compilation, $option"
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"
259 if [info exists torture_execute_xfail] {
260 setup_xfail $torture_execute_xfail
263 if [info exists torture_eval_before_execute] {
264 set ignore_me [eval $torture_eval_before_execute]
268 if [info exists oldexec] {
269 if { [remote_file build cmp $oldexec $execname] == 0 } {
274 set result [gcc_load "$execname" "" ""]
275 set status [lindex $result 0];
276 set output [lindex $result 1];
278 if { $oldstatus == "pass" } {
279 remote_file build delete $oldexec;
281 $status "$testcase execution, $option"
282 set oldstatus $status;
284 if [info exists status] {
285 if { $status == "pass" } {
286 remote_file build delete $execname;
292 # search_for -- looks for a string match in a file
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 {
307 # c-torture -- the c-torture testcase source file processor
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.
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.
317 proc c-torture { args } {
320 set src [lindex $args 0];
321 if { [llength $args] > 1 } {
322 set options [lindex $args 1];
327 # Prepend $srdir/$subdir if missing.
328 if ![string match "*/*" $src] {
329 set src "$srcdir/$subdir/$src"
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
336 catch "set done_p \[source [file rootname $src].x\]"
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
348 set option_list $torture_without_loops
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
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]
363 c-torture-compile $src "$option $options"