OSDN Git Service

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