OSDN Git Service

* gcc.c-torture/execute/execute.exp: Change copyright header to refer to version
[pf3gnuchains/gcc-fork.git] / gcc / testsuite / lib / fortran-torture.exp
1 # Copyright (C) 2003, 2006, 2007 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 3 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 GCC; see the file COPYING3.  If not see
15 # <http://www.gnu.org/licenses/>.
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 load_lib target-supports.exp
24
25 # The default option list can be overridden by
26 # TORTURE_OPTIONS="{ { list1 } ... { listN } }"
27
28 if ![info exists TORTURE_OPTIONS] {
29     # determine if host supports vectorization, and the necessary set
30     # of options, based on code from testsuite/vect/vect.exp
31
32     set vectorizer_options [list "-O2" "-ftree-vectorize"]
33
34     if { [istarget "powerpc*-*-*"]
35          && [is-effective-target powerpc_altivec_ok]
36          && [check_vmx_hw_available] } {
37         lappend vectorizer_options "-maltivec"
38         set test_tree_vectorize 1
39     } elseif { [istarget  "spu-*-*"] } {
40         set test_tree_vectorize 1
41     } elseif { [istarget "i?86-*-*"] || [istarget "x86_64-*-*"] } {
42         lappend vectorizer_options "-msse2"
43         set test_tree_vectorize 1
44     } elseif { [istarget "mipsisa64*-*-*"]
45                && [check_effective_target_mpaired_single] } {
46         lappend vectorizer_options "-mpaired-single"
47         set test_tree_vectorize 1
48     } elseif [istarget "sparc*-*-*"] {
49         lappend vectorizer_options "-mcpu=ultrasparc" "-mvis"
50         set test_tree_vectorize 1
51     } elseif { [istarget "alpha*-*-*"]
52                && [check_alpha_max_hw_available] } {
53         lappend vectorizer_options "-mmax"
54         set test_tree_vectorize 1
55     } elseif [istarget "ia64-*-*"] {
56         set test_tree_vectorize 1
57     } else {
58         set test_tree_vectorize 0
59     }
60
61     set TORTURE_OPTIONS [list \
62         { -O0 } { -O1 } { -O2 } \
63         { -O2 -fomit-frame-pointer -finline-functions } \
64         { -O2 -fomit-frame-pointer -finline-functions -funroll-loops } \
65         { -O2 -fbounds-check } \
66         { -O3 -g } \
67         { -Os }]
68
69     if { $test_tree_vectorize } {
70         lappend TORTURE_OPTIONS $vectorizer_options
71     }
72 }
73
74
75 #
76 # fortran-torture-compile -- compile a gfortran.fortran-torture testcase.
77 #
78 # SRC is the full pathname of the testcase.
79 # OPTION is the specific compiler flag we're testing (eg: -O2).
80 #
81 proc fortran-torture-compile { src option } {
82     global output
83     global srcdir tmpdir
84     global host_triplet
85
86     set output "$tmpdir/[file tail [file rootname $src]].o"
87
88     regsub "(?q)$srcdir/" $src "" testcase
89
90     # If we couldn't rip $srcdir out of `src' then just do the best we can.
91     # The point is to reduce the unnecessary noise in the logs.  Don't strip
92     # out too much because different testcases with the same name can confuse
93     # `test-tool'.
94     if [string match "/*" $testcase] {
95         set testcase "[file tail [file dirname $src]]/[file tail $src]"
96     }
97
98     verbose "Testing $testcase, $option" 1
99
100     # Run the compiler and get results in comp_output.
101     set options ""
102     lappend options "additional_flags=-w $option"
103
104     set comp_output [gfortran_target_compile "$src" "$output" object $options]
105     
106     # See if we got something bad.
107     set fatal_signal "*95*: Internal compiler error: program*got fatal signal"
108  
109     if [string match "$fatal_signal 6" $comp_output] then {
110         gfortran_fail $testcase "Got Signal 6, $option"
111         catch { remote_file build delete $output }
112         return
113     }
114
115     if [string match "$fatal_signal 11" $comp_output] then {
116         gfortran_fail $testcase "Got Signal 11, $option"
117         catch { remote_file build delete $output }
118         return
119     }
120
121     if [string match "*internal compiler error*" $comp_output] then {
122         gfortran_fail $testcase "$option (internal compiler error)"
123         catch { remote_file build delete $output }
124         return
125     }
126
127     # We shouldn't get these because of -w, but just in case.
128     if [string match "*95*:*warning:*" $comp_output] then {
129         warning "$testcase: (with warnings) $option"
130         send_log "$comp_output\n"
131         unresolved "$testcase, $option"
132         catch { remote_file build delete $output }
133         return
134     }
135
136     # Prune warnings we know are unwanted.
137     set comp_output [prune_warnings $comp_output]
138
139     # Report if the testcase is not supported.
140     set unsupported_message [gfortran_check_unsupported_p $comp_output]
141     if { $unsupported_message != "" } {
142         unsupported "$testcase: $unsupported_message"
143         catch { remote_file build delete $output }
144         return
145     }
146
147     # remove any leftover LF/CR to make sure any output is legit
148     regsub -all -- "\[\r\n\]*" $comp_output "" comp_output
149
150     # If any message remains, we fail.
151     if ![string match "" $comp_output] then {
152         gfortran_fail $testcase $option
153         catch { remote_file build delete $output }
154         return
155     }
156
157     gfortran_pass $testcase $option
158     catch { remote_file build delete $output }
159 }
160
161
162 #
163 # fortran-torture-execute -- compile and execute a testcase.
164 #
165 # SRC is the full pathname of the testcase.
166 #
167 # If the testcase has an associated .x file, we source that to run the
168 # test instead.  We use .x so that we don't lengthen the existing filename
169 # to more than 14 chars.
170 #
171 proc fortran-torture-execute { src } {
172     global output
173     global srcdir tmpdir
174     global tool
175     global compiler_conditional_xfail_data
176     global TORTURE_OPTIONS
177
178     # Check for alternate driver.
179     set additional_flags ""
180     if [file exists [file rootname $src].x] {
181         verbose "Using alternate driver [file rootname [file tail $src]].x" 2
182         set done_p 0
183         catch "set done_p \[source [file rootname $src].x\]"
184         if { $done_p } {
185             return
186         }
187     }
188
189     # Setup the options for the testcase run.
190     set option_list $TORTURE_OPTIONS
191     set executable $tmpdir/[file tail [file rootname $src].x]
192     regsub "(?q)$srcdir/" $src "" testcase
193
194     # If we couldn't rip $srcdir out of `src' then just do the best we can.
195     # The point is to reduce the unnecessary noise in the logs.  Don't strip
196     # out too much because different testcases with the same name can confuse
197     # `test-tool'.
198     if [string match "/*" $testcase] {
199         set testcase "[file tail [file dirname $src]]/[file tail $src]"
200     }
201
202     # Walk the list of options and copmile and run the testcase for all
203     # options that are not explicitly disabled by the .x script (if present).
204     foreach option $option_list {
205
206         # Torture_{compile,execute}_xfail are set by the .x script.
207         if [info exists torture_compile_xfail] {
208             setup_xfail $torture_compile_xfail
209         }
210
211         # Torture_execute_before_{compile,execute} can be set by the .x script.
212         if [info exists torture_eval_before_compile] {
213             set ignore_me [eval $torture_eval_before_compile]
214         }
215
216         # FIXME: We should make sure that the modules required by this testcase
217         # exist.  If not, the testcase should XFAIL.
218
219         # Compile the testcase.
220         catch { remote_file build delete $executable }
221         verbose "Testing $testcase, $option" 1
222
223         set options ""
224         lappend options "additional_flags=-w $option"
225         if { $additional_flags != "" } {
226             lappend options "additional_flags=$additional_flags"
227         }
228         set comp_output [gfortran_target_compile "$src" "$executable" executable $options]
229
230         # See if we got something bad.
231         set fatal_signal "*95*: Internal compiler error: program*got fatal signal"
232         
233         if [string match "$fatal_signal 6" $comp_output] then {
234             gfortran_fail $testcase "Got Signal 6, $option"
235             catch { remote_file build delete $executable }
236             continue
237         }
238         
239         if [string match "$fatal_signal 11" $comp_output] then {
240             gfortran_fail $testcase "Got Signal 11, $option"
241             catch { remote_file build delete $executable }
242             continue
243         }
244
245         if [string match "*internal compiler error*" $comp_output] then {
246             gfortran_fail $testcase "$option (internal compiler error)"
247             catch { remote_file build delete $executable }
248             continue
249         }
250         
251         # We shouldn't get these because of -w, but just in case.
252         if [string match "*95*:*warning:*" $comp_output] then {
253             warning "$testcase: (with warnings) $option"
254             send_log "$comp_output\n"
255             unresolved "$testcase, $option"
256             catch { remote_file build delete $executable }
257             continue
258         }
259         
260         # Prune warnings we know are unwanted.
261         set comp_output [prune_warnings $comp_output]
262
263         # Report if the testcase is not supported.
264         set unsupported_message [gfortran_check_unsupported_p $comp_output]
265         if { $unsupported_message != "" } {
266             unsupported "$testcase: $unsupported_message"
267             continue
268         } elseif ![file exists $executable] {
269             if ![is3way] {
270                 fail "$testcase compilation, $option"
271                 untested "$testcase execution, $option"
272                 continue
273             } else {
274                 # FIXME: since we can't test for the existence of a remote
275                 # file without short of doing an remote file list, we assume
276                 # that since we got no output, it must have compiled.
277                 pass "$testcase compilation, $option"           
278             }
279         } else {
280             pass "$testcase compilation, $option"
281         }
282
283         # See if this source file uses INTEGER(KIND=8) types, if it does, and
284         # no_long_long is set, skip execution of the test.
285         # FIXME: We should also look for F95 style "_8" or select_int_kind()
286         # integers, but that is obviously much harder than just regexping this.
287         # So maybe we should just avoid those in testcases.
288         if [target_info exists no_long_long] then {
289             if [expr [search_for_re $src "integer\*8"] \
290                      +[search_for_re $src "integer *( *8 *)"] \
291                      +[search_for_re $src "integer *( *kind *= *8 *)"]] \
292               then {
293                 untested "$testcase execution, $option"
294                 continue
295             }
296         }
297
298         if [info exists torture_execute_xfail] {
299             setup_xfail $torture_execute_xfail
300         }
301
302         if [info exists torture_eval_before_execute] {
303             set ignore_me [eval $torture_eval_before_execute]
304         }
305
306         # Run the testcase, and analyse the output.
307         set result [gfortran_load "$executable" "" ""]
308         set status [lindex $result 0]
309         set output [lindex $result 1]
310         if { $status == "pass" } {
311             catch { remote_file build delete $executable }
312         }
313         $status "$testcase execution, $option"
314     }
315 }
316
317
318 #
319 # search_for_re -- looks for a string match in a file
320 #
321 proc search_for_re { file pattern } {
322     set fd [open $file r]
323     while { [gets $fd cur_line]>=0 } {
324         set lower [string tolower $cur_line]
325         if [regexp "$pattern" $lower] then {
326             close $fd
327             return 1
328         }
329     }
330     close $fd
331     return 0
332 }
333
334
335 #
336 # fortran-torture -- the fortran-torture testcase source file processor
337 #
338 # This runs compilation only tests (no execute tests).
339 #
340 # SRC is the full pathname of the testcase, or just a file name in which
341 # case we prepend $srcdir/$subdir.
342 #
343 # If the testcase has an associated .x file, we source that to run the
344 # test instead.  We use .x so that we don't lengthen the existing filename
345 # to more than 14 chars.
346 #
347 proc fortran-torture { args } {
348     global srcdir subdir
349     global compiler_conditional_xfail_data
350
351     set src [lindex $args 0]
352     if { [llength $args] > 1 } {
353         set options [lindex $args 1]
354     } else {
355         set options ""
356     }
357
358     # Prepend $srdir/$subdir if missing.
359     if ![string match "*/*" $src] {
360         set src "$srcdir/$subdir/$src"
361     }
362
363     # Check for alternate driver.
364     if [file exists [file rootname $src].x] {
365         verbose "Using alternate driver [file rootname [file tail $src]].x" 2
366         set done_p 0
367         catch "set done_p \[source [file rootname $src].x\]"
368         if { $done_p } {
369             return
370         }
371     }
372    
373     # loop through all the options
374     set option_list [list { "-O" } ]
375     foreach option $option_list {
376
377         # torture_compile_xfail is set by the .x script (if present)
378         if [info exists torture_compile_xfail] {
379             setup_xfail $torture_compile_xfail
380         }
381
382         # torture_execute_before_compile is set by the .x script (if present)
383         if [info exists torture_eval_before_compile] {
384             set ignore_me [eval $torture_eval_before_compile]
385         }
386
387         fortran-torture-compile $src "$option $options"
388     }
389 }
390
391 #
392 # add-ieee-options -- add options necessary for 100% ieee conformance.
393 #
394 proc add-ieee-options { } {
395     # Ensure that excess precision does not cause problems.
396     if { [istarget "i?86-*-*"]
397          || [istarget "m68k-*-*"] } then {
398       uplevel 1 lappend additional_flags "-ffloat-store"
399     }
400
401     # Enable full IEEE compliance mode.
402     if { [istarget "alpha*-*-*"]
403          || [istarget "sh*-*-*"] } then {
404       uplevel 1 lappend additional_flags "-mieee"
405     }
406 }