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 && [check_sse_os_support_available] } {
51 lappend vectorizer_options "-msse2"
52 set test_tree_vectorize 1
53 } elseif { [istarget mips*-*-*]
54 && [check_effective_target_mpaired_single]
55 && [check_effective_target_nomips16] } {
56 lappend vectorizer_options "-mpaired-single"
57 set test_tree_vectorize 1
58 } elseif { [istarget sparc*-*-*]
59 && [check_effective_target_ultrasparc_hw] } {
60 lappend vectorizer_options "-mcpu=ultrasparc" "-mvis"
61 set test_tree_vectorize 1
62 } elseif { [istarget alpha*-*-*]
63 && [check_alpha_max_hw_available] } {
64 lappend vectorizer_options "-mmax"
65 set test_tree_vectorize 1
66 } elseif [istarget ia64-*-*] {
67 set test_tree_vectorize 1
69 set test_tree_vectorize 0
78 { -O2 -fomit-frame-pointer -finline-functions } \
79 { -O2 -fomit-frame-pointer -finline-functions -funroll-loops } \
80 { -O2 -fbounds-check } \
83 if { $test_tree_vectorize } {
84 lappend options $vectorizer_options
87 if [info exists ADDITIONAL_TORTURE_OPTIONS] {
88 set options [concat $options $ADDITIONAL_TORTURE_OPTIONS]
96 # fortran-torture-compile -- compile a gfortran.fortran-torture testcase.
98 # SRC is the full pathname of the testcase.
99 # OPTION is the specific compiler flag we're testing (eg: -O2).
101 proc fortran-torture-compile { src option } {
106 set output "$tmpdir/[file tail [file rootname $src]].o"
108 regsub "(?q)$srcdir/" $src "" testcase
110 # If we couldn't rip $srcdir out of `src' then just do the best we can.
111 # The point is to reduce the unnecessary noise in the logs. Don't strip
112 # out too much because different testcases with the same name can confuse
114 if [string match "/*" $testcase] {
115 set testcase "[file tail [file dirname $src]]/[file tail $src]"
118 verbose "Testing $testcase, $option" 1
120 # Run the compiler and get results in comp_output.
122 lappend options "additional_flags=-w $option"
124 set comp_output [gfortran_target_compile "$src" "$output" object $options]
126 # See if we got something bad.
127 set fatal_signal "*95*: Internal compiler error: program*got fatal signal"
129 if [string match "$fatal_signal 6" $comp_output] then {
130 gfortran_fail $testcase "Got Signal 6, $option"
131 catch { remote_file build delete $output }
135 if [string match "$fatal_signal 11" $comp_output] then {
136 gfortran_fail $testcase "Got Signal 11, $option"
137 catch { remote_file build delete $output }
141 if [string match "*internal compiler error*" $comp_output] then {
142 gfortran_fail $testcase "$option (internal compiler error)"
143 catch { remote_file build delete $output }
147 # We shouldn't get these because of -w, but just in case.
148 if [string match "*95*:*warning:*" $comp_output] then {
149 warning "$testcase: (with warnings) $option"
150 send_log "$comp_output\n"
151 unresolved "$testcase, $option"
152 catch { remote_file build delete $output }
156 # Prune warnings we know are unwanted.
157 set comp_output [prune_warnings $comp_output]
159 # Report if the testcase is not supported.
160 set unsupported_message [gfortran_check_unsupported_p $comp_output]
161 if { $unsupported_message != "" } {
162 unsupported "$testcase: $unsupported_message"
163 catch { remote_file build delete $output }
167 # remove any leftover LF/CR to make sure any output is legit
168 regsub -all -- "\[\r\n\]*" $comp_output "" comp_output
170 # If any message remains, we fail.
171 if ![string match "" $comp_output] then {
172 gfortran_fail $testcase $option
173 catch { remote_file build delete $output }
177 gfortran_pass $testcase $option
178 catch { remote_file build delete $output }
183 # fortran-torture-execute -- compile and execute a testcase.
185 # SRC is the full pathname of the testcase.
187 # If the testcase has an associated .x file, we source that to run the
188 # test instead. We use .x so that we don't lengthen the existing filename
189 # to more than 14 chars.
191 proc fortran-torture-execute { src } {
195 global compiler_conditional_xfail_data
196 global torture_with_loops
198 # Check for alternate driver.
199 set additional_flags ""
200 if [file exists [file rootname $src].x] {
201 verbose "Using alternate driver [file rootname [file tail $src]].x" 2
203 catch "set done_p \[source [file rootname $src].x\]"
209 # Setup the options for the testcase run.
210 set option_list $torture_with_loops
211 set executable $tmpdir/[file tail [file rootname $src].x]
212 regsub "(?q)$srcdir/" $src "" testcase
214 # If we couldn't rip $srcdir out of `src' then just do the best we can.
215 # The point is to reduce the unnecessary noise in the logs. Don't strip
216 # out too much because different testcases with the same name can confuse
218 if [string match "/*" $testcase] {
219 set testcase "[file tail [file dirname $src]]/[file tail $src]"
222 # Walk the list of options and copmile and run the testcase for all
223 # options that are not explicitly disabled by the .x script (if present).
224 foreach option $option_list {
226 # Torture_{compile,execute}_xfail are set by the .x script.
227 if [info exists torture_compile_xfail] {
228 setup_xfail $torture_compile_xfail
231 # Torture_execute_before_{compile,execute} can be set by the .x script.
232 if [info exists torture_eval_before_compile] {
233 set ignore_me [eval $torture_eval_before_compile]
236 # FIXME: We should make sure that the modules required by this testcase
237 # exist. If not, the testcase should XFAIL.
239 # Compile the testcase.
240 catch { remote_file build delete $executable }
241 verbose "Testing $testcase, $option" 1
244 lappend options "additional_flags=-w $option"
245 if { $additional_flags != "" } {
246 lappend options "additional_flags=$additional_flags"
248 set comp_output [gfortran_target_compile "$src" "$executable" executable $options]
250 # See if we got something bad.
251 set fatal_signal "*95*: Internal compiler error: program*got fatal signal"
253 if [string match "$fatal_signal 6" $comp_output] then {
254 gfortran_fail $testcase "Got Signal 6, $option"
255 catch { remote_file build delete $executable }
259 if [string match "$fatal_signal 11" $comp_output] then {
260 gfortran_fail $testcase "Got Signal 11, $option"
261 catch { remote_file build delete $executable }
265 if [string match "*internal compiler error*" $comp_output] then {
266 gfortran_fail $testcase "$option (internal compiler error)"
267 catch { remote_file build delete $executable }
271 # We shouldn't get these because of -w, but just in case.
272 if [string match "*95*:*warning:*" $comp_output] then {
273 warning "$testcase: (with warnings) $option"
274 send_log "$comp_output\n"
275 unresolved "$testcase, $option"
276 catch { remote_file build delete $executable }
280 # Prune warnings we know are unwanted.
281 set comp_output [prune_warnings $comp_output]
283 # Report if the testcase is not supported.
284 set unsupported_message [gfortran_check_unsupported_p $comp_output]
285 if { $unsupported_message != "" } {
286 unsupported "$testcase: $unsupported_message"
288 } elseif ![file exists $executable] {
290 fail "$testcase compilation, $option"
291 untested "$testcase execution, $option"
294 # FIXME: since we can't test for the existence of a remote
295 # file without short of doing an remote file list, we assume
296 # that since we got no output, it must have compiled.
297 pass "$testcase compilation, $option"
300 pass "$testcase compilation, $option"
303 # See if this source file uses INTEGER(KIND=8) types, if it does, and
304 # no_long_long is set, skip execution of the test.
305 # FIXME: We should also look for F95 style "_8" or select_int_kind()
306 # integers, but that is obviously much harder than just regexping this.
307 # So maybe we should just avoid those in testcases.
308 if [target_info exists no_long_long] then {
309 if [expr [search_for_re $src "integer\*8"] \
310 +[search_for_re $src "integer *( *8 *)"] \
311 +[search_for_re $src "integer *( *kind *= *8 *)"]] \
313 untested "$testcase execution, $option"
318 if [info exists torture_execute_xfail] {
319 setup_xfail $torture_execute_xfail
322 if [info exists torture_eval_before_execute] {
323 set ignore_me [eval $torture_eval_before_execute]
326 # Run the testcase, and analyse the output.
327 set result [gfortran_load "$executable" "" ""]
328 set status [lindex $result 0]
329 set output [lindex $result 1]
330 if { $status == "pass" } {
331 catch { remote_file build delete $executable }
333 $status "$testcase execution, $option"
339 # search_for_re -- looks for a string match in a file
341 proc search_for_re { file pattern } {
342 set fd [open $file r]
343 while { [gets $fd cur_line]>=0 } {
344 set lower [string tolower $cur_line]
345 if [regexp "$pattern" $lower] then {
356 # fortran-torture -- the fortran-torture testcase source file processor
358 # This runs compilation only tests (no execute tests).
360 # SRC is the full pathname of the testcase, or just a file name in which
361 # case we prepend $srcdir/$subdir.
363 # If the testcase has an associated .x file, we source that to run the
364 # test instead. We use .x so that we don't lengthen the existing filename
365 # to more than 14 chars.
367 proc fortran-torture { args } {
369 global compiler_conditional_xfail_data
370 global torture_with_loops
372 set src [lindex $args 0]
373 if { [llength $args] > 1 } {
374 set options [lindex $args 1]
379 # Prepend $srdir/$subdir if missing.
380 if ![string match "*/*" $src] {
381 set src "$srcdir/$subdir/$src"
384 # Check for alternate driver.
385 if [file exists [file rootname $src].x] {
386 verbose "Using alternate driver [file rootname [file tail $src]].x" 2
388 catch "set done_p \[source [file rootname $src].x\]"
394 # loop through all the options
395 set option_list $torture_with_loops
396 foreach option $option_list {
398 # torture_compile_xfail is set by the .x script (if present)
399 if [info exists torture_compile_xfail] {
400 setup_xfail $torture_compile_xfail
403 # torture_execute_before_compile is set by the .x script (if present)
404 if [info exists torture_eval_before_compile] {
405 set ignore_me [eval $torture_eval_before_compile]
408 fortran-torture-compile $src "$option $options"
413 # add-ieee-options -- add options necessary for 100% ieee conformance.
415 proc add-ieee-options { } {
416 # Ensure that excess precision does not cause problems.
417 if { [istarget i?86-*-*]
418 || [istarget m68k-*-*] } then {
419 uplevel 1 lappend additional_flags "-ffloat-store"
422 # Enable full IEEE compliance mode.
423 if { [istarget alpha*-*-*]
424 || [istarget sh*-*-*] } then {
425 uplevel 1 lappend additional_flags "-mieee"