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