1 # Copyright (C) 2009-2023 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 Ian Lance Taylor <iant@google.com> based on
21 # fortran-torture.exp by Steven Bosscher and Rob Savoye.
23 load_lib target-supports.exp
25 load_lib target-utils.exp
27 # The default option list can be overridden by
28 # TORTURE_OPTIONS="{ { list1 } ... { listN } }"
30 if ![info exists TORTURE_OPTIONS] {
31 set TORTURE_OPTIONS [list \
32 { -O0 } { -O1 } { -O2 } \
33 { -O2 -fomit-frame-pointer -finline-functions } \
34 { -O2 -fomit-frame-pointer -finline-functions -funroll-loops } \
35 { -O2 -fbounds-check } \
39 if [check_effective_target_lto] {
41 [concat $TORTURE_OPTIONS [list {-flto}]]
46 # go-torture-compile -- compile a go.go-torture testcase.
48 # SRC is the full pathname of the testcase.
49 # OPTION is the specific compiler flag we're testing (eg: -O2).
51 proc go-torture-compile { src option } {
56 set output "$tmpdir/[file tail [file rootname $src]].o"
58 regsub "(?q)$srcdir/" $src "" testcase
60 # If we couldn't rip $srcdir out of `src' then just do the best we can.
61 # The point is to reduce the unnecessary noise in the logs. Don't strip
62 # out too much because different testcases with the same name can confuse
64 if [string match "/*" $testcase] {
65 set testcase "[file tail [file dirname $src]]/[file tail $src]"
68 verbose "Testing $testcase, $option" 1
70 # Run the compiler and get results in comp_output.
72 lappend options "additional_flags=-w $option"
74 set comp_output [go_target_compile "$src" "$output" object $options]
76 # See if we got something bad.
77 set fatal_signal "*go*: Internal compiler error: program*got fatal signal"
79 if [string match "$fatal_signal 6" $comp_output] then {
80 go_fail $testcase "Got Signal 6, $option"
81 catch { remote_file build delete $output }
85 if [string match "$fatal_signal 11" $comp_output] then {
86 go_fail $testcase "Got Signal 11, $option"
87 catch { remote_file build delete $output }
91 if [regexp -line -- "internal compiler error.*" $comp_output ice] then {
92 go_fail $testcase "$option ($ice)"
93 catch { remote_file build delete $output }
97 # We shouldn't get these because of -w, but just in case.
98 if [string match "*go*:*warning:*" $comp_output] then {
99 warning "$testcase: (with warnings) $option"
100 send_log "$comp_output\n"
101 unresolved "$testcase, $option"
102 catch { remote_file build delete $output }
106 # Prune warnings we know are unwanted.
107 set comp_output [prune_warnings $comp_output]
109 # Report if the testcase is not supported.
110 set unsupported_message [go_check_unsupported_p $comp_output]
111 if { $unsupported_message != "" } {
112 unsupported "$testcase: $unsupported_message"
113 catch { remote_file build delete $output }
117 # remove any leftover LF/CR to make sure any output is legit
118 regsub -all -- "\[\r\n\]*" $comp_output "" comp_output
120 # If any message remains, we fail.
121 if ![string match "" $comp_output] then {
122 go_fail $testcase $option
123 catch { remote_file build delete $output }
127 go_pass $testcase $option
128 catch { remote_file build delete $output }
133 # go-torture-execute -- compile and execute a testcase.
135 # SRC is the full pathname of the testcase.
137 # If the testcase has an associated .x file, we source that to run the
138 # test instead. We use .x so that we don't lengthen the existing filename
139 # to more than 14 chars.
141 proc go-torture-execute { src } {
145 global compiler_conditional_xfail_data
146 global TORTURE_OPTIONS
147 global go_compile_args
148 global go_execute_args
150 # Check for alternate driver.
151 set additional_flags ""
152 if [file exists [file rootname $src].x] {
153 verbose "Using alternate driver [file rootname [file tail $src]].x" 2
155 catch "set done_p \[source [file rootname $src].x\]"
161 # Setup the options for the testcase run.
162 set option_list $TORTURE_OPTIONS
163 set executable $tmpdir/[file tail [file rootname $src].x]
164 regsub "(?q)$srcdir/" $src "" testcase
166 if { ! [info exists go_compile_args] } {
167 set go_compile_args ""
169 if { ! [info exists go_execute_args] } {
170 set go_execute_args ""
173 # If we couldn't rip $srcdir out of `src' then just do the best we can.
174 # The point is to reduce the unnecessary noise in the logs. Don't strip
175 # out too much because different testcases with the same name can confuse
177 if [string match "/*" $testcase] {
178 set testcase "[file tail [file dirname $src]]/[file tail $src]"
181 # Walk the list of options and copmile and run the testcase for all
182 # options that are not explicitly disabled by the .x script (if present).
183 foreach option $option_list {
185 # Torture_{compile,execute}_xfail are set by the .x script.
186 if [info exists torture_compile_xfail] {
187 setup_xfail $torture_compile_xfail
190 # Torture_execute_before_{compile,execute} can be set by the .x script.
191 if [info exists torture_eval_before_compile] {
192 set ignore_me [eval $torture_eval_before_compile]
195 # FIXME: We should make sure that the modules required by this testcase
196 # exist. If not, the testcase should XFAIL.
198 # Compile the testcase.
199 catch { remote_file build delete $executable }
200 verbose "Testing $testcase, $option" 1
203 lappend options "additional_flags=-w $option"
204 if { $additional_flags != "" } {
205 lappend options "additional_flags=$additional_flags"
207 if { $go_compile_args != "" } {
208 lappend options "additional_flags=$go_compile_args"
210 set comp_output [go_target_compile "$src" "$executable" executable $options]
212 # See if we got something bad.
213 set fatal_signal "*go*: Internal compiler error: program*got fatal signal"
215 if [string match "$fatal_signal 6" $comp_output] then {
216 go_fail $testcase "Got Signal 6, $option"
217 catch { remote_file build delete $executable }
221 if [string match "$fatal_signal 11" $comp_output] then {
222 go_fail $testcase "Got Signal 11, $option"
223 catch { remote_file build delete $executable }
227 if [regexp -line -- "internal compiler error.*" $comp_output ice] then {
228 go_fail $testcase "$option ($ice)"
229 catch { remote_file build delete $executable }
233 # We shouldn't get these because of -w, but just in case.
234 if [string match "*go*:*warning:*" $comp_output] then {
235 warning "$testcase: (with warnings) $option"
236 send_log "$comp_output\n"
237 unresolved "$testcase, $option"
238 catch { remote_file build delete $executable }
242 # Prune warnings we know are unwanted.
243 set comp_output [prune_warnings $comp_output]
245 # Report if the testcase is not supported.
246 set unsupported_message [go_check_unsupported_p $comp_output]
247 if { $unsupported_message != "" } {
248 unsupported "$testcase: $unsupported_message"
250 } elseif ![file exists $executable] {
252 fail "$testcase compilation, $option"
253 untested "$testcase execution, $option"
256 # FIXME: since we can't test for the existence of a remote
257 # file without short of doing an remote file list, we assume
258 # that since we got no output, it must have compiled.
259 pass "$testcase compilation, $option"
262 pass "$testcase compilation, $option"
265 if [info exists torture_execute_xfail] {
266 setup_xfail $torture_execute_xfail
269 if [info exists torture_eval_before_execute] {
270 set ignore_me [eval $torture_eval_before_execute]
273 # Run the testcase, and analyse the output.
274 set result [go_load "$executable" "$go_execute_args" ""]
275 set status [lindex $result 0]
276 set output [lindex $result 1]
278 # In order to cooperate nicely with the master Go testsuite,
279 # if the output contains the string BUG, we treat the test as
281 if [ string match "*BUG*" $output ] {
285 if { $status == "pass" } {
286 catch { remote_file build delete $executable }
288 $status "$testcase execution, $option"
294 # search_for_re -- looks for a string match in a file
296 proc search_for_re { file pattern } {
297 set fd [open $file r]
298 while { [gets $fd cur_line]>=0 } {
299 set lower [string tolower $cur_line]
300 if [regexp "$pattern" $lower] then {
311 # go-torture -- the go-torture testcase source file processor
313 # This runs compilation only tests (no execute tests).
315 # SRC is the full pathname of the testcase, or just a file name in which
316 # case we prepend $srcdir/$subdir.
318 # If the testcase has an associated .x file, we source that to run the
319 # test instead. We use .x so that we don't lengthen the existing filename
320 # to more than 14 chars.
322 proc go-torture { args } {
324 global compiler_conditional_xfail_data
325 global TORTURE_OPTIONS
327 set src [lindex $args 0]
328 if { [llength $args] > 1 } {
329 set options [lindex $args 1]
334 # Prepend $srdir/$subdir if missing.
335 if ![string match "*/*" $src] {
336 set src "$srcdir/$subdir/$src"
339 # Check for alternate driver.
340 if [file exists [file rootname $src].x] {
341 verbose "Using alternate driver [file rootname [file tail $src]].x" 2
343 catch "set done_p \[source [file rootname $src].x\]"
349 # loop through all the options
350 set option_list $TORTURE_OPTIONS
351 foreach option $option_list {
353 # torture_compile_xfail is set by the .x script (if present)
354 if [info exists torture_compile_xfail] {
355 setup_xfail $torture_compile_xfail
358 # torture_execute_before_compile is set by the .x script (if present)
359 if [info exists torture_eval_before_compile] {
360 set ignore_me [eval $torture_eval_before_compile]
363 go-torture-compile $src "$option $options"
368 # add-ieee-options -- add options necessary for 100% ieee conformance.
370 proc add-ieee-options { } {
371 # Ensure that excess precision does not cause problems.
372 if { [istarget i?86-*-*]
373 || [istarget m68k-*-*] } then {
374 uplevel 1 lappend additional_flags "-ffloat-store"
377 # Enable full IEEE compliance mode.
378 if { [istarget alpha*-*-*]
379 || [istarget sh*-*-*] } then {
380 uplevel 1 lappend additional_flags "-mieee"