]> git.ipfire.org Git - thirdparty/gcc.git/blame - gcc/testsuite/lib/go-torture.exp
Update copyright years.
[thirdparty/gcc.git] / gcc / testsuite / lib / go-torture.exp
CommitLineData
83ffe9cd 1# Copyright (C) 2009-2023 Free Software Foundation, Inc.
7a938933
ILT
2
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.
7#
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.
12#
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/>.
16
17# Please email any bugs, comments, and/or additions to this file to
18# the author.
19
20# This file was written by Ian Lance Taylor <iant@google.com> based on
21# fortran-torture.exp by Steven Bosscher and Rob Savoye.
22
23load_lib target-supports.exp
24
f63950e5
KT
25load_lib target-utils.exp
26
7a938933
ILT
27# The default option list can be overridden by
28# TORTURE_OPTIONS="{ { list1 } ... { listN } }"
29
30if ![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 } \
36 { -O3 -g } \
c1d9a8f5 37 { -Os }]
7a938933 38
c1d9a8f5
CC
39 if [check_effective_target_lto] {
40 set TORTURE_OPTIONS \
41 [concat $TORTURE_OPTIONS [list {-flto}]]
42 }
43}
7a938933
ILT
44
45#
46# go-torture-compile -- compile a go.go-torture testcase.
47#
48# SRC is the full pathname of the testcase.
49# OPTION is the specific compiler flag we're testing (eg: -O2).
50#
51proc go-torture-compile { src option } {
52 global output
53 global srcdir tmpdir
54 global host_triplet
55
56 set output "$tmpdir/[file tail [file rootname $src]].o"
57
58 regsub "(?q)$srcdir/" $src "" testcase
59
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
63 # `test-tool'.
64 if [string match "/*" $testcase] {
65 set testcase "[file tail [file dirname $src]]/[file tail $src]"
66 }
67
68 verbose "Testing $testcase, $option" 1
69
70 # Run the compiler and get results in comp_output.
71 set options ""
72 lappend options "additional_flags=-w $option"
73
74 set comp_output [go_target_compile "$src" "$output" object $options]
75
76 # See if we got something bad.
77 set fatal_signal "*go*: Internal compiler error: program*got fatal signal"
78
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 }
82 return
83 }
84
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 }
88 return
89 }
90
45b768cb
TS
91 if [regexp -line -- "internal compiler error.*" $comp_output ice] then {
92 go_fail $testcase "$option ($ice)"
7a938933
ILT
93 catch { remote_file build delete $output }
94 return
95 }
96
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 }
103 return
104 }
105
106 # Prune warnings we know are unwanted.
107 set comp_output [prune_warnings $comp_output]
108
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 }
114 return
115 }
116
117 # remove any leftover LF/CR to make sure any output is legit
118 regsub -all -- "\[\r\n\]*" $comp_output "" comp_output
119
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 }
124 return
125 }
126
127 go_pass $testcase $option
128 catch { remote_file build delete $output }
129}
130
131
132#
133# go-torture-execute -- compile and execute a testcase.
134#
135# SRC is the full pathname of the testcase.
136#
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.
140#
141proc go-torture-execute { src } {
142 global output
143 global srcdir tmpdir
144 global tool
145 global compiler_conditional_xfail_data
146 global TORTURE_OPTIONS
efcf639f 147 global go_compile_args
7a938933
ILT
148 global go_execute_args
149
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
154 set done_p 0
155 catch "set done_p \[source [file rootname $src].x\]"
156 if { $done_p } {
157 return
158 }
159 }
160
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
165
efcf639f
ILT
166 if { ! [info exists go_compile_args] } {
167 set go_compile_args ""
168 }
7a938933
ILT
169 if { ! [info exists go_execute_args] } {
170 set go_execute_args ""
171 }
172
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
176 # `test-tool'.
177 if [string match "/*" $testcase] {
178 set testcase "[file tail [file dirname $src]]/[file tail $src]"
179 }
180
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 {
184
185 # Torture_{compile,execute}_xfail are set by the .x script.
186 if [info exists torture_compile_xfail] {
187 setup_xfail $torture_compile_xfail
188 }
189
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]
193 }
194
195 # FIXME: We should make sure that the modules required by this testcase
196 # exist. If not, the testcase should XFAIL.
197
198 # Compile the testcase.
199 catch { remote_file build delete $executable }
200 verbose "Testing $testcase, $option" 1
201
202 set options ""
203 lappend options "additional_flags=-w $option"
204 if { $additional_flags != "" } {
205 lappend options "additional_flags=$additional_flags"
206 }
efcf639f
ILT
207 if { $go_compile_args != "" } {
208 lappend options "additional_flags=$go_compile_args"
209 }
7a938933
ILT
210 set comp_output [go_target_compile "$src" "$executable" executable $options]
211
212 # See if we got something bad.
213 set fatal_signal "*go*: Internal compiler error: program*got fatal signal"
214
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 }
218 continue
219 }
220
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 }
224 continue
225 }
226
45b768cb
TS
227 if [regexp -line -- "internal compiler error.*" $comp_output ice] then {
228 go_fail $testcase "$option ($ice)"
7a938933
ILT
229 catch { remote_file build delete $executable }
230 continue
231 }
232
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 }
239 continue
240 }
241
242 # Prune warnings we know are unwanted.
243 set comp_output [prune_warnings $comp_output]
244
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"
249 continue
250 } elseif ![file exists $executable] {
251 if ![is3way] {
252 fail "$testcase compilation, $option"
253 untested "$testcase execution, $option"
254 continue
255 } else {
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"
260 }
261 } else {
262 pass "$testcase compilation, $option"
263 }
264
265 if [info exists torture_execute_xfail] {
266 setup_xfail $torture_execute_xfail
267 }
268
269 if [info exists torture_eval_before_execute] {
270 set ignore_me [eval $torture_eval_before_execute]
271 }
272
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]
277
278 # In order to cooperate nicely with the master Go testsuite,
279 # if the output contains the string BUG, we treat the test as
280 # failing.
281 if [ string match "*BUG*" $output ] {
282 set status "fail"
283 }
284
285 if { $status == "pass" } {
286 catch { remote_file build delete $executable }
287 }
288 $status "$testcase execution, $option"
289 }
290}
291
292
293#
294# search_for_re -- looks for a string match in a file
295#
296proc 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 {
301 close $fd
302 return 1
303 }
304 }
305 close $fd
306 return 0
307}
308
309
310#
311# go-torture -- the go-torture testcase source file processor
312#
313# This runs compilation only tests (no execute tests).
314#
315# SRC is the full pathname of the testcase, or just a file name in which
316# case we prepend $srcdir/$subdir.
317#
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.
321#
322proc go-torture { args } {
323 global srcdir subdir
324 global compiler_conditional_xfail_data
325 global TORTURE_OPTIONS
326
327 set src [lindex $args 0]
328 if { [llength $args] > 1 } {
329 set options [lindex $args 1]
330 } else {
331 set options ""
332 }
333
334 # Prepend $srdir/$subdir if missing.
335 if ![string match "*/*" $src] {
336 set src "$srcdir/$subdir/$src"
337 }
338
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
342 set done_p 0
343 catch "set done_p \[source [file rootname $src].x\]"
344 if { $done_p } {
345 return
346 }
347 }
348
349 # loop through all the options
350 set option_list $TORTURE_OPTIONS
351 foreach option $option_list {
352
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
356 }
357
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]
361 }
362
363 go-torture-compile $src "$option $options"
364 }
365}
366
367#
368# add-ieee-options -- add options necessary for 100% ieee conformance.
369#
370proc add-ieee-options { } {
371 # Ensure that excess precision does not cause problems.
19073ebc
UB
372 if { [istarget i?86-*-*]
373 || [istarget m68k-*-*] } then {
7a938933
ILT
374 uplevel 1 lappend additional_flags "-ffloat-store"
375 }
376
377 # Enable full IEEE compliance mode.
19073ebc
UB
378 if { [istarget alpha*-*-*]
379 || [istarget sh*-*-*] } then {
7a938933
ILT
380 uplevel 1 lappend additional_flags "-mieee"
381 }
382}