1 # Copyright (C) 2003, 2006, 2007, 2008, 2010 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.
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
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
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
31 if [info exists TORTURE_OPTIONS] {
32 return $TORTURE_OPTIONS
35 # determine if host supports vectorization, and the necessary set
36 # of options, based on code from testsuite/vect/vect.exp
38 set vectorizer_options [list "-O2" "-ftree-vectorize"]
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_effective_target_sse2]
49 && [check_sse2_hw_available] } {
50 lappend vectorizer_options "-msse2"
51 set test_tree_vectorize 1
52 } elseif { [istarget "mips*-*-*"]
53 && [check_effective_target_mpaired_single]
54 && [check_effective_target_nomips16] } {
55 lappend vectorizer_options "-mpaired-single"
56 set test_tree_vectorize 1
57 } elseif { [istarget "sparc*-*-*"]
58 && [check_effective_target_ultrasparc_hw] } {
59 lappend vectorizer_options "-mcpu=ultrasparc" "-mvis"
60 set test_tree_vectorize 1
61 } elseif { [istarget "alpha*-*-*"]
62 && [check_alpha_max_hw_available] } {
63 lappend vectorizer_options "-mmax"
64 set test_tree_vectorize 1
65 } elseif [istarget "ia64-*-*"] {
66 set test_tree_vectorize 1
68 set test_tree_vectorize 0
77 { -O2 -fomit-frame-pointer -finline-functions } \
78 { -O2 -fomit-frame-pointer -finline-functions -funroll-loops } \
79 { -O2 -fbounds-check } \
82 if { $test_tree_vectorize } {
83 lappend options $vectorizer_options
86 if [info exists ADDITIONAL_TORTURE_OPTIONS] {
87 set options [concat $options $ADDITIONAL_TORTURE_OPTIONS]
95 # fortran-torture-compile -- compile a gfortran.fortran-torture testcase.
97 # SRC is the full pathname of the testcase.
98 # OPTION is the specific compiler flag we're testing (eg: -O2).
100 proc fortran-torture-compile { src option } {
105 set output "$tmpdir/[file tail [file rootname $src]].o"
107 regsub "(?q)$srcdir/" $src "" testcase
109 # If we couldn't rip $srcdir out of `src' then just do the best we can.
110 # The point is to reduce the unnecessary noise in the logs. Don't strip
111 # out too much because different testcases with the same name can confuse
113 if [string match "/*" $testcase] {
114 set testcase "[file tail [file dirname $src]]/[file tail $src]"
117 verbose "Testing $testcase, $option" 1
119 # Run the compiler and get results in comp_output.
121 lappend options "additional_flags=-w $option"
123 set comp_output [gfortran_target_compile "$src" "$output" object $options]
125 # See if we got something bad.
126 set fatal_signal "*95*: Internal compiler error: program*got fatal signal"
128 if [string match "$fatal_signal 6" $comp_output] then {
129 gfortran_fail $testcase "Got Signal 6, $option"
130 catch { remote_file build delete $output }
134 if [string match "$fatal_signal 11" $comp_output] then {
135 gfortran_fail $testcase "Got Signal 11, $option"
136 catch { remote_file build delete $output }
140 if [string match "*internal compiler error*" $comp_output] then {
141 gfortran_fail $testcase "$option (internal compiler error)"
142 catch { remote_file build delete $output }
146 # We shouldn't get these because of -w, but just in case.
147 if [string match "*95*:*warning:*" $comp_output] then {
148 warning "$testcase: (with warnings) $option"
149 send_log "$comp_output\n"
150 unresolved "$testcase, $option"
151 catch { remote_file build delete $output }
155 # Prune warnings we know are unwanted.
156 set comp_output [prune_warnings $comp_output]
158 # Report if the testcase is not supported.
159 set unsupported_message [gfortran_check_unsupported_p $comp_output]
160 if { $unsupported_message != "" } {
161 unsupported "$testcase: $unsupported_message"
162 catch { remote_file build delete $output }
166 # remove any leftover LF/CR to make sure any output is legit
167 regsub -all -- "\[\r\n\]*" $comp_output "" comp_output
169 # If any message remains, we fail.
170 if ![string match "" $comp_output] then {
171 gfortran_fail $testcase $option
172 catch { remote_file build delete $output }
176 gfortran_pass $testcase $option
177 catch { remote_file build delete $output }
182 # fortran-torture-execute -- compile and execute a testcase.
184 # SRC is the full pathname of the testcase.
186 # If the testcase has an associated .x file, we source that to run the
187 # test instead. We use .x so that we don't lengthen the existing filename
188 # to more than 14 chars.
190 proc fortran-torture-execute { src } {
194 global compiler_conditional_xfail_data
195 global torture_with_loops
197 # Check for alternate driver.
198 set additional_flags ""
199 if [file exists [file rootname $src].x] {
200 verbose "Using alternate driver [file rootname [file tail $src]].x" 2
202 catch "set done_p \[source [file rootname $src].x\]"
208 # Setup the options for the testcase run.
209 set option_list $torture_with_loops
210 set executable $tmpdir/[file tail [file rootname $src].x]
211 regsub "(?q)$srcdir/" $src "" testcase
213 # If we couldn't rip $srcdir out of `src' then just do the best we can.
214 # The point is to reduce the unnecessary noise in the logs. Don't strip
215 # out too much because different testcases with the same name can confuse
217 if [string match "/*" $testcase] {
218 set testcase "[file tail [file dirname $src]]/[file tail $src]"
221 # Walk the list of options and copmile and run the testcase for all
222 # options that are not explicitly disabled by the .x script (if present).
223 foreach option $option_list {
225 # Torture_{compile,execute}_xfail are set by the .x script.
226 if [info exists torture_compile_xfail] {
227 setup_xfail $torture_compile_xfail
230 # Torture_execute_before_{compile,execute} can be set by the .x script.
231 if [info exists torture_eval_before_compile] {
232 set ignore_me [eval $torture_eval_before_compile]
235 # FIXME: We should make sure that the modules required by this testcase
236 # exist. If not, the testcase should XFAIL.
238 # Compile the testcase.
239 catch { remote_file build delete $executable }
240 verbose "Testing $testcase, $option" 1
243 lappend options "additional_flags=-w $option"
244 if { $additional_flags != "" } {
245 lappend options "additional_flags=$additional_flags"
247 set comp_output [gfortran_target_compile "$src" "$executable" executable $options]
249 # See if we got something bad.
250 set fatal_signal "*95*: Internal compiler error: program*got fatal signal"
252 if [string match "$fatal_signal 6" $comp_output] then {
253 gfortran_fail $testcase "Got Signal 6, $option"
254 catch { remote_file build delete $executable }
258 if [string match "$fatal_signal 11" $comp_output] then {
259 gfortran_fail $testcase "Got Signal 11, $option"
260 catch { remote_file build delete $executable }
264 if [string match "*internal compiler error*" $comp_output] then {
265 gfortran_fail $testcase "$option (internal compiler error)"
266 catch { remote_file build delete $executable }
270 # We shouldn't get these because of -w, but just in case.
271 if [string match "*95*:*warning:*" $comp_output] then {
272 warning "$testcase: (with warnings) $option"
273 send_log "$comp_output\n"
274 unresolved "$testcase, $option"
275 catch { remote_file build delete $executable }
279 # Prune warnings we know are unwanted.
280 set comp_output [prune_warnings $comp_output]
282 # Report if the testcase is not supported.
283 set unsupported_message [gfortran_check_unsupported_p $comp_output]
284 if { $unsupported_message != "" } {
285 unsupported "$testcase: $unsupported_message"
287 } elseif ![file exists $executable] {
289 fail "$testcase compilation, $option"
290 untested "$testcase execution, $option"
293 # FIXME: since we can't test for the existence of a remote
294 # file without short of doing an remote file list, we assume
295 # that since we got no output, it must have compiled.
296 pass "$testcase compilation, $option"
299 pass "$testcase compilation, $option"
302 # See if this source file uses INTEGER(KIND=8) types, if it does, and
303 # no_long_long is set, skip execution of the test.
304 # FIXME: We should also look for F95 style "_8" or select_int_kind()
305 # integers, but that is obviously much harder than just regexping this.
306 # So maybe we should just avoid those in testcases.
307 if [target_info exists no_long_long] then {
308 if [expr [search_for_re $src "integer\*8"] \
309 +[search_for_re $src "integer *( *8 *)"] \
310 +[search_for_re $src "integer *( *kind *= *8 *)"]] \
312 untested "$testcase execution, $option"
317 if [info exists torture_execute_xfail] {
318 setup_xfail $torture_execute_xfail
321 if [info exists torture_eval_before_execute] {
322 set ignore_me [eval $torture_eval_before_execute]
325 # Run the testcase, and analyse the output.
326 set result [gfortran_load "$executable" "" ""]
327 set status [lindex $result 0]
328 set output [lindex $result 1]
329 if { $status == "pass" } {
330 catch { remote_file build delete $executable }
332 $status "$testcase execution, $option"
338 # search_for_re -- looks for a string match in a file
340 proc search_for_re { file pattern } {
341 set fd [open $file r]
342 while { [gets $fd cur_line]>=0 } {
343 set lower [string tolower $cur_line]
344 if [regexp "$pattern" $lower] then {
355 # fortran-torture -- the fortran-torture testcase source file processor
357 # This runs compilation only tests (no execute tests).
359 # SRC is the full pathname of the testcase, or just a file name in which
360 # case we prepend $srcdir/$subdir.
362 # If the testcase has an associated .x file, we source that to run the
363 # test instead. We use .x so that we don't lengthen the existing filename
364 # to more than 14 chars.
366 proc fortran-torture { args } {
368 global compiler_conditional_xfail_data
369 global torture_with_loops
371 set src [lindex $args 0]
372 if { [llength $args] > 1 } {
373 set options [lindex $args 1]
378 # Prepend $srdir/$subdir if missing.
379 if ![string match "*/*" $src] {
380 set src "$srcdir/$subdir/$src"
383 # Check for alternate driver.
384 if [file exists [file rootname $src].x] {
385 verbose "Using alternate driver [file rootname [file tail $src]].x" 2
387 catch "set done_p \[source [file rootname $src].x\]"
393 # loop through all the options
394 set option_list $torture_with_loops
395 foreach option $option_list {
397 # torture_compile_xfail is set by the .x script (if present)
398 if [info exists torture_compile_xfail] {
399 setup_xfail $torture_compile_xfail
402 # torture_execute_before_compile is set by the .x script (if present)
403 if [info exists torture_eval_before_compile] {
404 set ignore_me [eval $torture_eval_before_compile]
407 fortran-torture-compile $src "$option $options"
412 # add-ieee-options -- add options necessary for 100% ieee conformance.
414 proc add-ieee-options { } {
415 # Ensure that excess precision does not cause problems.
416 if { [istarget "i?86-*-*"]
417 || [istarget "m68k-*-*"] } then {
418 uplevel 1 lappend additional_flags "-ffloat-store"
421 # Enable full IEEE compliance mode.
422 if { [istarget "alpha*-*-*"]
423 || [istarget "sh*-*-*"] } then {
424 uplevel 1 lappend additional_flags "-mieee"