1 # Copyright (C) 2003, 2006, 2007, 2008 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_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
67 set test_tree_vectorize 0
76 { -O2 -fomit-frame-pointer -finline-functions } \
77 { -O2 -fomit-frame-pointer -finline-functions -funroll-loops } \
78 { -O2 -fbounds-check } \
81 if { $test_tree_vectorize } {
82 lappend options $vectorizer_options
85 if [info exists ADDITIONAL_TORTURE_OPTIONS] {
86 set options [concat $options $ADDITIONAL_TORTURE_OPTIONS]
94 # fortran-torture-compile -- compile a gfortran.fortran-torture testcase.
96 # SRC is the full pathname of the testcase.
97 # OPTION is the specific compiler flag we're testing (eg: -O2).
99 proc fortran-torture-compile { src option } {
104 set output "$tmpdir/[file tail [file rootname $src]].o"
106 regsub "(?q)$srcdir/" $src "" testcase
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
112 if [string match "/*" $testcase] {
113 set testcase "[file tail [file dirname $src]]/[file tail $src]"
116 verbose "Testing $testcase, $option" 1
118 # Run the compiler and get results in comp_output.
120 lappend options "additional_flags=-w $option"
122 set comp_output [gfortran_target_compile "$src" "$output" object $options]
124 # See if we got something bad.
125 set fatal_signal "*95*: Internal compiler error: program*got fatal signal"
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 }
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 }
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 }
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 }
154 # Prune warnings we know are unwanted.
155 set comp_output [prune_warnings $comp_output]
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 }
165 # remove any leftover LF/CR to make sure any output is legit
166 regsub -all -- "\[\r\n\]*" $comp_output "" comp_output
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 }
175 gfortran_pass $testcase $option
176 catch { remote_file build delete $output }
181 # fortran-torture-execute -- compile and execute a testcase.
183 # SRC is the full pathname of the testcase.
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.
189 proc fortran-torture-execute { src } {
193 global compiler_conditional_xfail_data
194 global torture_with_loops
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
201 catch "set done_p \[source [file rootname $src].x\]"
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
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
216 if [string match "/*" $testcase] {
217 set testcase "[file tail [file dirname $src]]/[file tail $src]"
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 {
224 # Torture_{compile,execute}_xfail are set by the .x script.
225 if [info exists torture_compile_xfail] {
226 setup_xfail $torture_compile_xfail
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]
234 # FIXME: We should make sure that the modules required by this testcase
235 # exist. If not, the testcase should XFAIL.
237 # Compile the testcase.
238 catch { remote_file build delete $executable }
239 verbose "Testing $testcase, $option" 1
242 lappend options "additional_flags=-w $option"
243 if { $additional_flags != "" } {
244 lappend options "additional_flags=$additional_flags"
246 set comp_output [gfortran_target_compile "$src" "$executable" executable $options]
248 # See if we got something bad.
249 set fatal_signal "*95*: Internal compiler error: program*got fatal signal"
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 }
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 }
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 }
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 }
278 # Prune warnings we know are unwanted.
279 set comp_output [prune_warnings $comp_output]
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"
286 } elseif ![file exists $executable] {
288 fail "$testcase compilation, $option"
289 untested "$testcase execution, $option"
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"
298 pass "$testcase compilation, $option"
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 *)"]] \
311 untested "$testcase execution, $option"
316 if [info exists torture_execute_xfail] {
317 setup_xfail $torture_execute_xfail
320 if [info exists torture_eval_before_execute] {
321 set ignore_me [eval $torture_eval_before_execute]
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 }
331 $status "$testcase execution, $option"
337 # search_for_re -- looks for a string match in a file
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 {
354 # fortran-torture -- the fortran-torture testcase source file processor
356 # This runs compilation only tests (no execute tests).
358 # SRC is the full pathname of the testcase, or just a file name in which
359 # case we prepend $srcdir/$subdir.
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.
365 proc fortran-torture { args } {
367 global compiler_conditional_xfail_data
368 global torture_with_loops
370 set src [lindex $args 0]
371 if { [llength $args] > 1 } {
372 set options [lindex $args 1]
377 # Prepend $srdir/$subdir if missing.
378 if ![string match "*/*" $src] {
379 set src "$srcdir/$subdir/$src"
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
386 catch "set done_p \[source [file rootname $src].x\]"
392 # loop through all the options
393 set option_list $torture_with_loops
394 foreach option $option_list {
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
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]
406 fortran-torture-compile $src "$option $options"
411 # add-ieee-options -- add options necessary for 100% ieee conformance.
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"
420 # Enable full IEEE compliance mode.
421 if { [istarget "alpha*-*-*"]
422 || [istarget "sh*-*-*"] } then {
423 uplevel 1 lappend additional_flags "-mieee"