]> git.ipfire.org Git - thirdparty/gcc.git/blob - gcc/testsuite/lib/fortran-torture.exp
Merge tree-ssa-20020619-branch into mainline.
[thirdparty/gcc.git] / gcc / testsuite / lib / fortran-torture.exp
1 # Copyright (C) 2003 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 # the author.
19
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.
22
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.
27
28
29 # The default option list can be overridden by
30 # TORTURE_OPTIONS="{ { list1 } ... { listN } }"
31
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 } \
39 { -O3 -g } \
40 { -Os }]
41 }
42
43
44 #
45 # fortran-torture-compile -- compile a gfortran.fortran-torture testcase.
46 #
47 # SRC is the full pathname of the testcase.
48 # OPTION is the specific compiler flag we're testing (eg: -O2).
49 #
50 proc fortran-torture-compile { src option } {
51 global output
52 global srcdir tmpdir
53 global host_triplet
54
55 set output "$tmpdir/[file tail [file rootname $src]].o"
56
57 regsub "^$srcdir/?" $src "" testcase
58
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]"
65 }
66
67 verbose "Testing $testcase, $option" 1
68
69 # Run the compiler and get results in comp_output.
70 set options ""
71 lappend options "additional_flags=-w $option"
72
73 set comp_output [gfortran_target_compile "$src" "$output" object $options];
74
75 # See if we got something bad.
76 set fatal_signal "*95*: Internal compiler error: program*got fatal signal"
77
78 if [string match "$fatal_signal 6" $comp_output] then {
79 gfortran_fail $testcase "Got Signal 6, $option"
80 remote_file build delete $output
81 return
82 }
83
84 if [string match "$fatal_signal 11" $comp_output] then {
85 gfortran_fail $testcase "Got Signal 11, $option"
86 remote_file build delete $output
87 return
88 }
89
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
96 return
97 }
98
99 # Prune warnings we know are unwanted.
100 set comp_output [prune_warnings $comp_output]
101
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
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
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
117 return
118 }
119
120 gfortran_pass $testcase $option
121 remote_file build delete $output
122 }
123
124
125 #
126 # fortran-torture-execute -- compile and execute a testcase.
127 #
128 # SRC is the full pathname of the testcase.
129 #
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.
133 #
134 proc fortran-torture-execute { src } {
135 global output
136 global srcdir tmpdir
137 global tool
138 global compiler_conditional_xfail_data
139 global TORTURE_OPTIONS
140
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
144 set done_p 0
145 catch "set done_p \[source [file rootname $src].x\]"
146 if { $done_p } {
147 return
148 }
149 }
150
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
155
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
159 # `test-tool'.
160 if [string match "/*" $testcase] {
161 set testcase "[file tail [file dirname $src]]/[file tail $src]"
162 }
163
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 {
167
168 # Torture_{compile,execute}_xfail are set by the .x script.
169 if [info exists torture_compile_xfail] {
170 setup_xfail $torture_compile_xfail
171 }
172
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]
176 }
177
178 # FIXME: We should make sure that the modules required by this testcase
179 # exist. If not, the testcase should XFAIL.
180
181 # Compile the testcase.
182 remote_file build delete $executable
183 verbose "Testing $testcase, $option" 1
184
185 set options ""
186 lappend options "additional_flags=-w $option"
187 set comp_output [gfortran_target_compile "$src" "$executable" executable $options];
188
189 # See if we got something bad.
190 set fatal_signal "*95*: Internal compiler error: program*got fatal signal"
191
192 if [string match "$fatal_signal 6" $comp_output] then {
193 gfortran_fail $testcase "Got Signal 6, $option"
194 remote_file build delete $executable
195 continue
196 }
197
198 if [string match "$fatal_signal 11" $comp_output] then {
199 gfortran_fail $testcase "Got Signal 11, $option"
200 remote_file build delete $executable
201 continue
202 }
203
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
210 continue
211 }
212
213 # Prune warnings we know are unwanted.
214 set comp_output [prune_warnings $comp_output]
215
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"
220 continue
221 } elseif ![file exists $executable] {
222 if ![is3way] {
223 fail "$testcase compilation, $option"
224 untested "$testcase execution, $option"
225 continue
226 } else {
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"
231 }
232 } else {
233 pass "$testcase compilation, $option"
234 }
235
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 *)"]] \
245 then {
246 untested "$testcase execution, $option"
247 continue
248 }
249 }
250
251 if [info exists torture_execute_xfail] {
252 setup_xfail $torture_execute_xfail
253 }
254
255 if [info exists torture_eval_before_execute] {
256 set ignore_me [eval $torture_eval_before_execute]
257 }
258
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
265 }
266 $status "$testcase execution, $option"
267 }
268 }
269
270
271 #
272 # search_for -- looks for a string match in a file
273 #
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 {
279 close $fd
280 return 1
281 }
282 }
283 close $fd
284 return 0
285 }
286
287
288 #
289 # fortran-torture -- the fortran-torture testcase source file processor
290 #
291 # This runs compilation only tests (no execute tests).
292 #
293 # SRC is the full pathname of the testcase, or just a file name in which
294 # case we prepend $srcdir/$subdir.
295 #
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.
299 #
300 proc fortran-torture { args } {
301 global srcdir subdir
302 global compiler_conditional_xfail_data
303 global TORTURE_OPTIONS
304
305 set src [lindex $args 0];
306 if { [llength $args] > 1 } {
307 set options [lindex $args 1];
308 } else {
309 set options ""
310 }
311
312 # Prepend $srdir/$subdir if missing.
313 if ![string match "*/*" $src] {
314 set src "$srcdir/$subdir/$src"
315 }
316
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
320 set done_p 0
321 catch "set done_p \[source [file rootname $src].x\]"
322 if { $done_p } {
323 return
324 }
325 }
326
327 # loop through all the options
328 set option_list $TORTURE_OPTIONS
329 foreach option $option_list {
330
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
334 }
335
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]
339 }
340
341 fortran-torture-compile $src "$option $options"
342 }
343 }
344