1 # Copyright (C) 2003, 2006, 2007 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 # The default option list can be overridden by
26 # TORTURE_OPTIONS="{ { list1 } ... { listN } }"
28 if ![info exists TORTURE_OPTIONS] {
29 # determine if host supports vectorization, and the necessary set
30 # of options, based on code from testsuite/vect/vect.exp
32 set vectorizer_options [list "-O2" "-ftree-vectorize"]
34 if { [istarget "powerpc*-*-*"]
35 && [is-effective-target powerpc_altivec_ok]
36 && [check_vmx_hw_available] } {
37 lappend vectorizer_options "-maltivec"
38 set test_tree_vectorize 1
39 } elseif { [istarget "spu-*-*"] } {
40 set test_tree_vectorize 1
41 } elseif { [istarget "i?86-*-*"] || [istarget "x86_64-*-*"] } {
42 lappend vectorizer_options "-msse2"
43 set test_tree_vectorize 1
44 } elseif { [istarget "mipsisa64*-*-*"]
45 && [check_effective_target_mpaired_single] } {
46 lappend vectorizer_options "-mpaired-single"
47 set test_tree_vectorize 1
48 } elseif [istarget "sparc*-*-*"] {
49 lappend vectorizer_options "-mcpu=ultrasparc" "-mvis"
50 set test_tree_vectorize 1
51 } elseif { [istarget "alpha*-*-*"]
52 && [check_alpha_max_hw_available] } {
53 lappend vectorizer_options "-mmax"
54 set test_tree_vectorize 1
55 } elseif [istarget "ia64-*-*"] {
56 set test_tree_vectorize 1
58 set test_tree_vectorize 0
61 set TORTURE_OPTIONS [list \
62 { -O0 } { -O1 } { -O2 } \
63 { -O2 -fomit-frame-pointer -finline-functions } \
64 { -O2 -fomit-frame-pointer -finline-functions -funroll-loops } \
65 { -O2 -fbounds-check } \
69 if { $test_tree_vectorize } {
70 lappend TORTURE_OPTIONS $vectorizer_options
76 # fortran-torture-compile -- compile a gfortran.fortran-torture testcase.
78 # SRC is the full pathname of the testcase.
79 # OPTION is the specific compiler flag we're testing (eg: -O2).
81 proc fortran-torture-compile { src option } {
86 set output "$tmpdir/[file tail [file rootname $src]].o"
88 regsub "(?q)$srcdir/" $src "" testcase
90 # If we couldn't rip $srcdir out of `src' then just do the best we can.
91 # The point is to reduce the unnecessary noise in the logs. Don't strip
92 # out too much because different testcases with the same name can confuse
94 if [string match "/*" $testcase] {
95 set testcase "[file tail [file dirname $src]]/[file tail $src]"
98 verbose "Testing $testcase, $option" 1
100 # Run the compiler and get results in comp_output.
102 lappend options "additional_flags=-w $option"
104 set comp_output [gfortran_target_compile "$src" "$output" object $options]
106 # See if we got something bad.
107 set fatal_signal "*95*: Internal compiler error: program*got fatal signal"
109 if [string match "$fatal_signal 6" $comp_output] then {
110 gfortran_fail $testcase "Got Signal 6, $option"
111 catch { remote_file build delete $output }
115 if [string match "$fatal_signal 11" $comp_output] then {
116 gfortran_fail $testcase "Got Signal 11, $option"
117 catch { remote_file build delete $output }
121 if [string match "*internal compiler error*" $comp_output] then {
122 gfortran_fail $testcase "$option (internal compiler error)"
123 catch { remote_file build delete $output }
127 # We shouldn't get these because of -w, but just in case.
128 if [string match "*95*:*warning:*" $comp_output] then {
129 warning "$testcase: (with warnings) $option"
130 send_log "$comp_output\n"
131 unresolved "$testcase, $option"
132 catch { remote_file build delete $output }
136 # Prune warnings we know are unwanted.
137 set comp_output [prune_warnings $comp_output]
139 # Report if the testcase is not supported.
140 set unsupported_message [gfortran_check_unsupported_p $comp_output]
141 if { $unsupported_message != "" } {
142 unsupported "$testcase: $unsupported_message"
143 catch { remote_file build delete $output }
147 # remove any leftover LF/CR to make sure any output is legit
148 regsub -all -- "\[\r\n\]*" $comp_output "" comp_output
150 # If any message remains, we fail.
151 if ![string match "" $comp_output] then {
152 gfortran_fail $testcase $option
153 catch { remote_file build delete $output }
157 gfortran_pass $testcase $option
158 catch { remote_file build delete $output }
163 # fortran-torture-execute -- compile and execute a testcase.
165 # SRC is the full pathname of the testcase.
167 # If the testcase has an associated .x file, we source that to run the
168 # test instead. We use .x so that we don't lengthen the existing filename
169 # to more than 14 chars.
171 proc fortran-torture-execute { src } {
175 global compiler_conditional_xfail_data
176 global TORTURE_OPTIONS
178 # Check for alternate driver.
179 set additional_flags ""
180 if [file exists [file rootname $src].x] {
181 verbose "Using alternate driver [file rootname [file tail $src]].x" 2
183 catch "set done_p \[source [file rootname $src].x\]"
189 # Setup the options for the testcase run.
190 set option_list $TORTURE_OPTIONS
191 set executable $tmpdir/[file tail [file rootname $src].x]
192 regsub "(?q)$srcdir/" $src "" testcase
194 # If we couldn't rip $srcdir out of `src' then just do the best we can.
195 # The point is to reduce the unnecessary noise in the logs. Don't strip
196 # out too much because different testcases with the same name can confuse
198 if [string match "/*" $testcase] {
199 set testcase "[file tail [file dirname $src]]/[file tail $src]"
202 # Walk the list of options and copmile and run the testcase for all
203 # options that are not explicitly disabled by the .x script (if present).
204 foreach option $option_list {
206 # Torture_{compile,execute}_xfail are set by the .x script.
207 if [info exists torture_compile_xfail] {
208 setup_xfail $torture_compile_xfail
211 # Torture_execute_before_{compile,execute} can be set by the .x script.
212 if [info exists torture_eval_before_compile] {
213 set ignore_me [eval $torture_eval_before_compile]
216 # FIXME: We should make sure that the modules required by this testcase
217 # exist. If not, the testcase should XFAIL.
219 # Compile the testcase.
220 catch { remote_file build delete $executable }
221 verbose "Testing $testcase, $option" 1
224 lappend options "additional_flags=-w $option"
225 if { $additional_flags != "" } {
226 lappend options "additional_flags=$additional_flags"
228 set comp_output [gfortran_target_compile "$src" "$executable" executable $options]
230 # See if we got something bad.
231 set fatal_signal "*95*: Internal compiler error: program*got fatal signal"
233 if [string match "$fatal_signal 6" $comp_output] then {
234 gfortran_fail $testcase "Got Signal 6, $option"
235 catch { remote_file build delete $executable }
239 if [string match "$fatal_signal 11" $comp_output] then {
240 gfortran_fail $testcase "Got Signal 11, $option"
241 catch { remote_file build delete $executable }
245 if [string match "*internal compiler error*" $comp_output] then {
246 gfortran_fail $testcase "$option (internal compiler error)"
247 catch { remote_file build delete $executable }
251 # We shouldn't get these because of -w, but just in case.
252 if [string match "*95*:*warning:*" $comp_output] then {
253 warning "$testcase: (with warnings) $option"
254 send_log "$comp_output\n"
255 unresolved "$testcase, $option"
256 catch { remote_file build delete $executable }
260 # Prune warnings we know are unwanted.
261 set comp_output [prune_warnings $comp_output]
263 # Report if the testcase is not supported.
264 set unsupported_message [gfortran_check_unsupported_p $comp_output]
265 if { $unsupported_message != "" } {
266 unsupported "$testcase: $unsupported_message"
268 } elseif ![file exists $executable] {
270 fail "$testcase compilation, $option"
271 untested "$testcase execution, $option"
274 # FIXME: since we can't test for the existence of a remote
275 # file without short of doing an remote file list, we assume
276 # that since we got no output, it must have compiled.
277 pass "$testcase compilation, $option"
280 pass "$testcase compilation, $option"
283 # See if this source file uses INTEGER(KIND=8) types, if it does, and
284 # no_long_long is set, skip execution of the test.
285 # FIXME: We should also look for F95 style "_8" or select_int_kind()
286 # integers, but that is obviously much harder than just regexping this.
287 # So maybe we should just avoid those in testcases.
288 if [target_info exists no_long_long] then {
289 if [expr [search_for_re $src "integer\*8"] \
290 +[search_for_re $src "integer *( *8 *)"] \
291 +[search_for_re $src "integer *( *kind *= *8 *)"]] \
293 untested "$testcase execution, $option"
298 if [info exists torture_execute_xfail] {
299 setup_xfail $torture_execute_xfail
302 if [info exists torture_eval_before_execute] {
303 set ignore_me [eval $torture_eval_before_execute]
306 # Run the testcase, and analyse the output.
307 set result [gfortran_load "$executable" "" ""]
308 set status [lindex $result 0]
309 set output [lindex $result 1]
310 if { $status == "pass" } {
311 catch { remote_file build delete $executable }
313 $status "$testcase execution, $option"
319 # search_for_re -- looks for a string match in a file
321 proc search_for_re { file pattern } {
322 set fd [open $file r]
323 while { [gets $fd cur_line]>=0 } {
324 set lower [string tolower $cur_line]
325 if [regexp "$pattern" $lower] then {
336 # fortran-torture -- the fortran-torture testcase source file processor
338 # This runs compilation only tests (no execute tests).
340 # SRC is the full pathname of the testcase, or just a file name in which
341 # case we prepend $srcdir/$subdir.
343 # If the testcase has an associated .x file, we source that to run the
344 # test instead. We use .x so that we don't lengthen the existing filename
345 # to more than 14 chars.
347 proc fortran-torture { args } {
349 global compiler_conditional_xfail_data
351 set src [lindex $args 0]
352 if { [llength $args] > 1 } {
353 set options [lindex $args 1]
358 # Prepend $srdir/$subdir if missing.
359 if ![string match "*/*" $src] {
360 set src "$srcdir/$subdir/$src"
363 # Check for alternate driver.
364 if [file exists [file rootname $src].x] {
365 verbose "Using alternate driver [file rootname [file tail $src]].x" 2
367 catch "set done_p \[source [file rootname $src].x\]"
373 # loop through all the options
374 set option_list [list { "-O" } ]
375 foreach option $option_list {
377 # torture_compile_xfail is set by the .x script (if present)
378 if [info exists torture_compile_xfail] {
379 setup_xfail $torture_compile_xfail
382 # torture_execute_before_compile is set by the .x script (if present)
383 if [info exists torture_eval_before_compile] {
384 set ignore_me [eval $torture_eval_before_compile]
387 fortran-torture-compile $src "$option $options"
392 # add-ieee-options -- add options necessary for 100% ieee conformance.
394 proc add-ieee-options { } {
395 # Ensure that excess precision does not cause problems.
396 if { [istarget "i?86-*-*"]
397 || [istarget "m68k-*-*"] } then {
398 uplevel 1 lappend additional_flags "-ffloat-store"
401 # Enable full IEEE compliance mode.
402 if { [istarget "alpha*-*-*"]
403 || [istarget "sh*-*-*"] } then {
404 uplevel 1 lappend additional_flags "-mieee"