* lib/gcc-dg.exp (gcc-dg-test-1): Detect and report ICE.
[official-gcc.git] / gcc / testsuite / lib / fortran-torture.exp
blob182711553ce2652b40ee3929a5927d5891964ace
1 # Copyright (C) 2003 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.
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.
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, 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
17 # Please email any bugs, comments, and/or additions to this file to
18 # the author.
20 # This file was written by Steven Bosscher (s.bosscher@student.tudelft.nl)
21 # based on f-torture.exp, which was written by Rob Savoye.
23 # The biggest change from g77 is that we always test all testcases with
24 # loop options, because it is much harder to figure out whether a testcase
25 # has loops if you have array syntax, like Fortran 95. In fact, the whole
26 # point of F95 is arrays, so loops show up in most testcases anyway.
29 # The default option list can be overridden by
30 # TORTURE_OPTIONS="{ { list1 } ... { listN } }"
32 if ![info exists TORTURE_OPTIONS] {
33 set TORTURE_OPTIONS [list \
34 { -O0 } { -O1 } { -O2 } \
35 { -O2 -fomit-frame-pointer -finline-functions } \
36 { -O2 -fomit-frame-pointer -finline-functions -funroll-loops } \
37 { -O2 -fbounds-check } \
38 { -O2 -fno-repack-arrays } \
39 { -O3 -g } \
40 { -Os }]
45 # fortran-torture-compile -- compile a gfortran.fortran-torture testcase.
47 # SRC is the full pathname of the testcase.
48 # OPTION is the specific compiler flag we're testing (eg: -O2).
50 proc fortran-torture-compile { src option } {
51 global output
52 global srcdir tmpdir
53 global host_triplet
55 set output "$tmpdir/[file tail [file rootname $src]].o"
57 regsub "^$srcdir/?" $src "" testcase
59 # If we couldn't rip $srcdir out of `src' then just do the best we can.
60 # The point is to reduce the unnecessary noise in the logs. Don't strip
61 # out too much because different testcases with the same name can confuse
62 # `test-tool'.
63 if [string match "/*" $testcase] {
64 set testcase "[file tail [file dirname $src]]/[file tail $src]"
67 verbose "Testing $testcase, $option" 1
69 # Run the compiler and get results in comp_output.
70 set options ""
71 lappend options "additional_flags=-w $option"
73 set comp_output [gfortran_target_compile "$src" "$output" object $options]
75 # See if we got something bad.
76 set fatal_signal "*95*: Internal compiler error: program*got fatal signal"
78 if [string match "$fatal_signal 6" $comp_output] then {
79 gfortran_fail $testcase "Got Signal 6, $option"
80 catch { remote_file build delete $output }
81 return
84 if [string match "$fatal_signal 11" $comp_output] then {
85 gfortran_fail $testcase "Got Signal 11, $option"
86 catch { remote_file build delete $output }
87 return
90 if [string match "*internal compiler error*" $comp_output] then {
91 gfortran_fail $testcase "$option (internal compiler error)"
92 catch { remote_file build delete $output }
93 return
96 # We shouldn't get these because of -w, but just in case.
97 if [string match "*95*:*warning:*" $comp_output] then {
98 warning "$testcase: (with warnings) $option"
99 send_log "$comp_output\n"
100 unresolved "$testcase, $option"
101 catch { remote_file build delete $output }
102 return
105 # Prune warnings we know are unwanted.
106 set comp_output [prune_warnings $comp_output]
108 # Report if the testcase is not supported.
109 set unsupported_message [gfortran_check_unsupported_p $comp_output]
110 if { $unsupported_message != "" } {
111 unsupported "$testcase: $unsupported_message"
112 catch { remote_file build delete $output }
113 return
116 # remove any leftover LF/CR to make sure any output is legit
117 regsub -all -- "\[\r\n\]*" $comp_output "" comp_output
119 # If any message remains, we fail.
120 if ![string match "" $comp_output] then {
121 gfortran_fail $testcase $option
122 catch { remote_file build delete $output }
123 return
126 gfortran_pass $testcase $option
127 catch { remote_file build delete $output }
132 # fortran-torture-execute -- compile and execute a testcase.
134 # SRC is the full pathname of the testcase.
136 # If the testcase has an associated .x file, we source that to run the
137 # test instead. We use .x so that we don't lengthen the existing filename
138 # to more than 14 chars.
140 proc fortran-torture-execute { src } {
141 global output
142 global srcdir tmpdir
143 global tool
144 global compiler_conditional_xfail_data
145 global TORTURE_OPTIONS
147 # Check for alternate driver.
148 set additional_flags ""
149 if [file exists [file rootname $src].x] {
150 verbose "Using alternate driver [file rootname [file tail $src]].x" 2
151 set done_p 0
152 catch "set done_p \[source [file rootname $src].x\]"
153 if { $done_p } {
154 return
158 # Setup the options for the testcase run.
159 set option_list $TORTURE_OPTIONS
160 set executable $tmpdir/[file tail [file rootname $src].x]
161 regsub "^$srcdir/?" $src "" testcase
163 # If we couldn't rip $srcdir out of `src' then just do the best we can.
164 # The point is to reduce the unnecessary noise in the logs. Don't strip
165 # out too much because different testcases with the same name can confuse
166 # `test-tool'.
167 if [string match "/*" $testcase] {
168 set testcase "[file tail [file dirname $src]]/[file tail $src]"
171 # Walk the list of options and copmile and run the testcase for all
172 # options that are not explicitly disabled by the .x script (if present).
173 foreach option $option_list {
175 # Torture_{compile,execute}_xfail are set by the .x script.
176 if [info exists torture_compile_xfail] {
177 setup_xfail $torture_compile_xfail
180 # Torture_execute_before_{compile,execute} can be set by the .x script.
181 if [info exists torture_eval_before_compile] {
182 set ignore_me [eval $torture_eval_before_compile]
185 # FIXME: We should make sure that the modules required by this testcase
186 # exist. If not, the testcase should XFAIL.
188 # Compile the testcase.
189 catch { remote_file build delete $executable }
190 verbose "Testing $testcase, $option" 1
192 set options ""
193 lappend options "additional_flags=-w $option"
194 if { $additional_flags != "" } {
195 lappend options "additional_flags=$additional_flags"
197 set comp_output [gfortran_target_compile "$src" "$executable" executable $options]
199 # See if we got something bad.
200 set fatal_signal "*95*: Internal compiler error: program*got fatal signal"
202 if [string match "$fatal_signal 6" $comp_output] then {
203 gfortran_fail $testcase "Got Signal 6, $option"
204 catch { remote_file build delete $executable }
205 continue
208 if [string match "$fatal_signal 11" $comp_output] then {
209 gfortran_fail $testcase "Got Signal 11, $option"
210 catch { remote_file build delete $executable }
211 continue
214 if [string match "*internal compiler error*" $comp_output] then {
215 gfortran_fail $testcase "$option (internal compiler error)"
216 catch { remote_file build delete $executable }
217 continue
220 # We shouldn't get these because of -w, but just in case.
221 if [string match "*95*:*warning:*" $comp_output] then {
222 warning "$testcase: (with warnings) $option"
223 send_log "$comp_output\n"
224 unresolved "$testcase, $option"
225 catch { remote_file build delete $executable }
226 continue
229 # Prune warnings we know are unwanted.
230 set comp_output [prune_warnings $comp_output]
232 # Report if the testcase is not supported.
233 set unsupported_message [gfortran_check_unsupported_p $comp_output]
234 if { $unsupported_message != "" } {
235 unsupported "$testcase: $unsupported_message"
236 continue
237 } elseif ![file exists $executable] {
238 if ![is3way] {
239 fail "$testcase compilation, $option"
240 untested "$testcase execution, $option"
241 continue
242 } else {
243 # FIXME: since we can't test for the existance of a remote
244 # file without short of doing an remote file list, we assume
245 # that since we got no output, it must have compiled.
246 pass "$testcase compilation, $option"
248 } else {
249 pass "$testcase compilation, $option"
252 # See if this source file uses INTEGER(KIND=8) types, if it does, and
253 # no_long_long is set, skip execution of the test.
254 # FIXME: We should also look for F95 style "_8" or select_int_kind()
255 # integers, but that is obviously much harder than just regexping this.
256 # So maybe we should just avoid those in testcases.
257 if [target_info exists no_long_long] then {
258 if [expr [search_for_re $src "integer\*8"] \
259 +[search_for_re $src "integer *( *8 *)"] \
260 +[search_for_re $src "integer *( *kind *= *8 *)"]] \
261 then {
262 untested "$testcase execution, $option"
263 continue
267 if [info exists torture_execute_xfail] {
268 setup_xfail $torture_execute_xfail
271 if [info exists torture_eval_before_execute] {
272 set ignore_me [eval $torture_eval_before_execute]
275 # Run the testcase, and analyse the output.
276 set result [gfortran_load "$executable" "" ""]
277 set status [lindex $result 0]
278 set output [lindex $result 1]
279 if { $status == "pass" } {
280 catch { remote_file build delete $executable }
282 $status "$testcase execution, $option"
288 # search_for_re -- looks for a string match in a file
290 proc search_for_re { file pattern } {
291 set fd [open $file r]
292 while { [gets $fd cur_line]>=0 } {
293 set lower [string tolower $cur_line]
294 if [regexp "$pattern" $lower] then {
295 close $fd
296 return 1
299 close $fd
300 return 0
305 # fortran-torture -- the fortran-torture testcase source file processor
307 # This runs compilation only tests (no execute tests).
309 # SRC is the full pathname of the testcase, or just a file name in which
310 # case we prepend $srcdir/$subdir.
312 # If the testcase has an associated .x file, we source that to run the
313 # test instead. We use .x so that we don't lengthen the existing filename
314 # to more than 14 chars.
316 proc fortran-torture { args } {
317 global srcdir subdir
318 global compiler_conditional_xfail_data
320 set src [lindex $args 0]
321 if { [llength $args] > 1 } {
322 set options [lindex $args 1]
323 } else {
324 set options ""
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
335 set done_p 0
336 catch "set done_p \[source [file rootname $src].x\]"
337 if { $done_p } {
338 return
342 # loop through all the options
343 set option_list [list { "-O" } ]
344 foreach option $option_list {
346 # torture_compile_xfail is set by the .x script (if present)
347 if [info exists torture_compile_xfail] {
348 setup_xfail $torture_compile_xfail
351 # torture_execute_before_compile is set by the .x script (if present)
352 if [info exists torture_eval_before_compile] {
353 set ignore_me [eval $torture_eval_before_compile]
356 fortran-torture-compile $src "$option $options"
361 # add-ieee-options -- add options necessary for 100% ieee conformance.
363 proc add-ieee-options { } {
364 # Ensure that excess precision does not cause problems.
365 if { [istarget "i?86-*-*"]
366 || [istarget "m68k-*-*"] } then {
367 uplevel 1 lappend additional_flags "-ffloat-store"
370 # Enable full IEEE compliance mode.
371 if { [istarget "alpha*-*-*"]
372 || [istarget "sh*-*-*"] } then {
373 uplevel 1 lappend additional_flags "-mieee"