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.
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
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 -fomit-frame-pointer -finline-functions -funroll-all-loops } \
38 { -O2 -fno-repack-arrays } \
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 } {
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
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.
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 remote_file build delete $output
84 if [string match "$fatal_signal 11" $comp_output] then {
85 gfortran_fail $testcase "Got Signal 11, $option"
86 remote_file build delete $output
90 # We shouldn't get these because of -w, but just in case.
91 if [string match "*95*:*warning:*" $comp_output] then {
92 warning "$testcase: (with warnings) $option"
93 send_log "$comp_output\n"
94 unresolved "$testcase, $option"
95 remote_file build delete $output
99 # Prune warnings we know are unwanted.
100 set comp_output [prune_warnings $comp_output]
102 # Report if the testcase is not supported.
103 set unsupported_message [gfortran_check_unsupported_p $comp_output]
104 if { $unsupported_message != "" } {
105 unsupported "$testcase: $unsupported_message"
106 remote_file build delete $output
110 # remove any leftover LF/CR to make sure any output is legit
111 regsub -all -- "\[\r\n\]*" $comp_output "" comp_output
113 # If any message remains, we fail.
114 if ![string match "" $comp_output] then {
115 gfortran_fail $testcase $option
116 remote_file build delete $output
120 gfortran_pass $testcase $option
121 remote_file build delete $output
126 # fortran-torture-execute -- compile and execute a testcase.
128 # SRC is the full pathname of the testcase.
130 # If the testcase has an associated .x file, we source that to run the
131 # test instead. We use .x so that we don't lengthen the existing filename
132 # to more than 14 chars.
134 proc fortran-torture-execute { src } {
138 global compiler_conditional_xfail_data
139 global TORTURE_OPTIONS
141 # Check for alternate driver.
142 if [file exists [file rootname $src].x] {
143 verbose "Using alternate driver [file rootname [file tail $src]].x" 2
145 catch "set done_p \[source [file rootname $src].x\]"
151 # Setup the options for the testcase run.
152 set option_list $TORTURE_OPTIONS
153 set executable $tmpdir/[file tail [file rootname $src].x]
154 regsub "^$srcdir/?" $src "" testcase
156 # If we couldn't rip $srcdir out of `src' then just do the best we can.
157 # The point is to reduce the unnecessary noise in the logs. Don't strip
158 # out too much because different testcases with the same name can confuse
160 if [string match "/*" $testcase] {
161 set testcase "[file tail [file dirname $src]]/[file tail $src]"
164 # Walk the list of options and copmile and run the testcase for all
165 # options that are not explicitly disabled by the .x script (if present).
166 foreach option $option_list {
168 # Torture_{compile,execute}_xfail are set by the .x script.
169 if [info exists torture_compile_xfail] {
170 setup_xfail $torture_compile_xfail
173 # Torture_execute_before_{compile,execute} can be set by the .x script.
174 if [info exists torture_eval_before_compile] {
175 set ignore_me [eval $torture_eval_before_compile]
178 # FIXME: We should make sure that the modules required by this testcase
179 # exist. If not, the testcase should XFAIL.
181 # Compile the testcase.
182 remote_file build delete $executable
183 verbose "Testing $testcase, $option" 1
186 lappend options "additional_flags=-w $option"
187 set comp_output [gfortran_target_compile "$src" "$executable" executable $options];
189 # See if we got something bad.
190 set fatal_signal "*95*: Internal compiler error: program*got fatal signal"
192 if [string match "$fatal_signal 6" $comp_output] then {
193 gfortran_fail $testcase "Got Signal 6, $option"
194 remote_file build delete $executable
198 if [string match "$fatal_signal 11" $comp_output] then {
199 gfortran_fail $testcase "Got Signal 11, $option"
200 remote_file build delete $executable
204 # We shouldn't get these because of -w, but just in case.
205 if [string match "*95*:*warning:*" $comp_output] then {
206 warning "$testcase: (with warnings) $option"
207 send_log "$comp_output\n"
208 unresolved "$testcase, $option"
209 remote_file build delete $executable
213 # Prune warnings we know are unwanted.
214 set comp_output [prune_warnings $comp_output]
216 # Report if the testcase is not supported.
217 set unsupported_message [gfortran_check_unsupported_p $comp_output]
218 if { $unsupported_message != "" } {
219 unsupported "$testcase: $unsupported_message"
221 } elseif ![file exists $executable] {
223 fail "$testcase compilation, $option"
224 untested "$testcase execution, $option"
227 # FIXME: since we can't test for the existance of a remote
228 # file without short of doing an remote file list, we assume
229 # that since we got no output, it must have compiled.
230 pass "$testcase compilation, $option"
233 pass "$testcase compilation, $option"
236 # See if this source file uses INTEGER(KIND=8) types, if it does, and
237 # no_long_long is set, skip execution of the test.
238 # FIXME: We should also look for F95 style "_8" or select_int_kind()
239 # integers, but that is obviously much harder than just regexping this.
240 # So maybe we should just avoid those in testcases.
241 if [target_info exists no_long_long] then {
242 if [expr [search_for $src "integer\*8"] \
243 +[search_for $src "integer *( *8 *)"] \
244 +[search_for $src "integer *( *kind *= *8 *)"]] \
246 untested "$testcase execution, $option"
251 if [info exists torture_execute_xfail] {
252 setup_xfail $torture_execute_xfail
255 if [info exists torture_eval_before_execute] {
256 set ignore_me [eval $torture_eval_before_execute]
259 # Run the testcase, and analyse the output.
260 set result [gfortran_load "$executable" "" ""]
261 set status [lindex $result 0];
262 set output [lindex $result 1];
263 if { $status == "pass" } {
264 remote_file build delete $executable
266 $status "$testcase execution, $option"
272 # search_for -- looks for a string match in a file
274 proc search_for { file pattern } {
275 set fd [open $file r]
276 while { [gets $fd cur_line]>=0 } {
277 set lower [string tolower $cur_line]
278 if [regexp "$pattern" $lower] then {
289 # fortran-torture -- the fortran-torture testcase source file processor
291 # This runs compilation only tests (no execute tests).
293 # SRC is the full pathname of the testcase, or just a file name in which
294 # case we prepend $srcdir/$subdir.
296 # If the testcase has an associated .x file, we source that to run the
297 # test instead. We use .x so that we don't lengthen the existing filename
298 # to more than 14 chars.
300 proc fortran-torture { args } {
302 global compiler_conditional_xfail_data
303 global TORTURE_OPTIONS
305 set src [lindex $args 0];
306 if { [llength $args] > 1 } {
307 set options [lindex $args 1];
312 # Prepend $srdir/$subdir if missing.
313 if ![string match "*/*" $src] {
314 set src "$srcdir/$subdir/$src"
317 # Check for alternate driver.
318 if [file exists [file rootname $src].x] {
319 verbose "Using alternate driver [file rootname [file tail $src]].x" 2
321 catch "set done_p \[source [file rootname $src].x\]"
327 # loop through all the options
328 set option_list $TORTURE_OPTIONS
329 foreach option $option_list {
331 # torture_compile_xfail is set by the .x script (if present)
332 if [info exists torture_compile_xfail] {
333 setup_xfail $torture_compile_xfail
336 # torture_execute_before_compile is set by the .x script (if present)
337 if [info exists torture_eval_before_compile] {
338 set ignore_me [eval $torture_eval_before_compile]
341 fortran-torture-compile $src "$option $options"