]> git.ipfire.org Git - thirdparty/gcc.git/blame - gcc/testsuite/lib/c-torture.exp
* doc/invoke.texi (-fwhopr): Merge into -flto section.
[thirdparty/gcc.git] / gcc / testsuite / lib / c-torture.exp
CommitLineData
cfaf579d 1# Copyright (C) 1992-1998, 1999, 2000, 2007, 2008
2# Free Software Foundation, Inc.
912f9e81 3
4# This program is free software; you can redistribute it and/or modify
5# it under the terms of the GNU General Public License as published by
f63ff66b 6# the Free Software Foundation; either version 3 of the License, or
912f9e81 7# (at your option) any later version.
3326bbb9 8#
912f9e81 9# This program is distributed in the hope that it will be useful,
10# but WITHOUT ANY WARRANTY; without even the implied warranty of
11# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
12# GNU General Public License for more details.
3326bbb9 13#
912f9e81 14# You should have received a copy of the GNU General Public License
f63ff66b 15# along with GCC; see the file COPYING3. If not see
16# <http://www.gnu.org/licenses/>.
912f9e81 17
912f9e81 18# This file was written by Rob Savoye. (rob@cygnus.com)
19
7bfefa9d 20load_lib target-supports.exp
0f1adac2 21load_lib file-format.exp
c4328bcc 22load_lib target-libpath.exp
0f1adac2 23
912f9e81 24# The default option list can be overridden by
25# TORTURE_OPTIONS="{ { list1 } ... { listN } }"
26
07e23beb 27if [info exists TORTURE_OPTIONS] {
28 set C_TORTURE_OPTIONS $TORTURE_OPTIONS
29} else {
56a33d0c 30 # It is theoretically beneficial to group all of the O2/O3 options together,
a504aabf 31 # as in many cases the compiler will generate identical executables for
32 # all of them--and the c-torture testsuite will skip testing identical
33 # executables multiple times.
56a33d0c 34 # Also note that -finline-functions is explicitly included in one of the
35 # items below, even though -O3 is also specified, because some ports may
36 # choose to disable inlining functions by default, even when optimizing.
07e23beb 37 set C_TORTURE_OPTIONS [list \
56a33d0c 38 { -O0 } \
39 { -O1 } \
40 { -O2 } \
41 { -O3 -fomit-frame-pointer } \
42 { -O3 -fomit-frame-pointer -funroll-loops } \
43 { -O3 -fomit-frame-pointer -funroll-all-loops -finline-functions } \
44 { -O3 -g } \
45 { -Os } ]
912f9e81 46}
47
4425e8dc 48if [info exists ADDITIONAL_TORTURE_OPTIONS] {
49 set C_TORTURE_OPTIONS \
50 [concat $C_TORTURE_OPTIONS $ADDITIONAL_TORTURE_OPTIONS]
51}
52
7bfefa9d 53set LTO_TORTURE_OPTIONS ""
54if [check_effective_target_lto] {
55 set LTO_TORTURE_OPTIONS [list \
cbcf2791 56 { -O2 -flto -flto-partition=none } \
57 { -O2 -flto }
7bfefa9d 58 ]
59}
60
c4328bcc 61global GCC_UNDER_TEST
62if ![info exists GCC_UNDER_TEST] {
63 set GCC_UNDER_TEST "[find_gcc]"
64}
65
f09e0522 66global orig_environment_saved
67
68# This file may be sourced, so don't override environment settings
69# that have been previously setup.
70if { $orig_environment_saved == 0 } {
71 append ld_library_path [gcc-set-multilib-library-path $GCC_UNDER_TEST]
72 set_ld_library_path_env_vars
73}
74
912f9e81 75#
76# c-torture-compile -- runs the Tege C-torture test
77#
78# SRC is the full pathname of the testcase.
79# OPTION is the specific compiler flag we're testing (eg: -O2).
80#
81proc c-torture-compile { src option } {
82 global output
83 global srcdir tmpdir
84 global host_triplet
85
86 set output "$tmpdir/[file tail [file rootname $src]].o"
87
b6124398 88 regsub "(?q)$srcdir/" $src "" testcase
912f9e81 89 # If we couldn't rip $srcdir out of `src' then just do the best we can.
90 # The point is to reduce the unnecessary noise in the logs. Don't strip
91 # out too much because different testcases with the same name can confuse
92 # `test-tool'.
93 if [string match "/*" $testcase] {
94 set testcase "[file tail [file dirname $src]]/[file tail $src]"
95 }
96
97 verbose "Testing $testcase, $option" 1
98
99 # Run the compiler and analyze the results.
100 set options ""
101 lappend options "additional_flags=-w $option"
102
d4213587 103 set comp_output [gcc_target_compile "$src" "$output" object $options]
1fa8aee0 104 gcc_check_compile $testcase $option $output $comp_output
76f3b287 105 file_on_host delete $output
912f9e81 106}
107
108#
109# c-torture-execute -- utility to compile and execute a testcase
110#
3a2bdc46 111# SOURCES is a list of full pathnames to the test source files.
112# The first filename in this list forms the "testcase".
912f9e81 113#
2b6d9ca1 114# If the testcase has an associated .x file, we source that to run the
115# test instead. We use .x so that we don't lengthen the existing filename
116# to more than 14 chars.
912f9e81 117#
3a2bdc46 118proc c-torture-execute { sources args } {
4f0fdaee 119 global tmpdir tool srcdir output compiler_conditional_xfail_data
912f9e81 120
3a2bdc46 121 # Use the first source filename given as the filename under test.
122 set src [lindex $sources 0]
123
a504aabf 124 if { [llength $args] > 0 } {
d4213587 125 set additional_flags [lindex $args 0]
a504aabf 126 } else {
d4213587 127 set additional_flags ""
a504aabf 128 }
912f9e81 129 # Check for alternate driver.
2b6d9ca1 130 if [file exists [file rootname $src].x] {
131 verbose "Using alternate driver [file rootname [file tail $src]].x" 2
912f9e81 132 set done_p 0
2b6d9ca1 133 catch "set done_p \[source [file rootname $src].x\]"
912f9e81 134 if { $done_p } {
135 return
136 }
137 }
3326bbb9 138
912f9e81 139 # Look for a loop within the source code - if we don't find one,
140 # don't pass -funroll[-all]-loops.
141 global torture_with_loops torture_without_loops
142 if [expr [search_for $src "for*("]+[search_for $src "while*("]] then {
143 set option_list $torture_with_loops
144 } else {
145 set option_list $torture_without_loops
146 }
147
148 set executable $tmpdir/[file tail [file rootname $src].x]
149
b6124398 150 regsub "(?q)$srcdir/" $src "" testcase
912f9e81 151 # If we couldn't rip $srcdir out of `src' then just do the best we can.
152 # The point is to reduce the unnecessary noise in the logs. Don't strip
153 # out too much because different testcases with the same name can confuse
154 # `test-tool'.
155 if [string match "/*" $testcase] {
156 set testcase "[file tail [file dirname $src]]/[file tail $src]"
157 }
158
d4213587 159 set count 0
160 set oldstatus "foo"
912f9e81 161 foreach option $option_list {
a504aabf 162 if { $count > 0 } {
d4213587 163 set oldexec $execname
a504aabf 164 }
d4213587 165 set execname "${executable}${count}"
166 incr count
a504aabf 167
2b6d9ca1 168 # torture_{compile,execute}_xfail are set by the .x script
912f9e81 169 # (if present)
170 if [info exists torture_compile_xfail] {
171 setup_xfail $torture_compile_xfail
172 }
3326bbb9 173
b137f460 174 # torture_execute_before_{compile,execute} can be set by the .x script
175 # (if present)
176 if [info exists torture_eval_before_compile] {
177 set ignore_me [eval $torture_eval_before_compile]
178 }
3326bbb9 179
76f3b287 180 file_on_host delete $execname
912f9e81 181 verbose "Testing $testcase, $option" 1
182
183 set options ""
184 lappend options "additional_flags=-w $option"
a504aabf 185 if { $additional_flags != "" } {
d4213587 186 lappend options "additional_flags=$additional_flags"
a504aabf 187 }
d4213587 188 set comp_output [gcc_target_compile "$sources" "${execname}" executable $options]
912f9e81 189
1fa8aee0 190 if ![gcc_check_compile "$testcase compilation" $option $execname $comp_output] {
191 unresolved "$testcase execution, $option"
76f3b287 192 file_on_host delete $execname
912f9e81 193 continue
194 }
912f9e81 195
196 # See if this source file uses "long long" types, if it does, and
197 # no_long_long is set, skip execution of the test.
198 if [target_info exists no_long_long] then {
199 if [expr [search_for $src "long long"]] then {
1fa8aee0 200 unsupported "$testcase execution, $option"
912f9e81 201 continue
202 }
203 }
204
205 if [info exists torture_execute_xfail] {
206 setup_xfail $torture_execute_xfail
207 }
b137f460 208
209 if [info exists torture_eval_before_execute] {
210 set ignore_me [eval $torture_eval_before_execute]
211 }
3326bbb9 212
499ec5b1 213
214 # Sometimes we end up creating identical executables for two
215 # consecutive sets of different of compiler options.
216 #
217 # In such cases we know the result of this test will be identical
218 # to the result of the last test.
219 #
220 # So in cases where the time to load and run/simulate the test
221 # is relatively high, compare the two binaries and avoid rerunning
222 # tests if the executables are identical.
223 #
224 # Do not do this for native testing since the cost to load/execute
225 # the test is fairly small and the comparison step actually slows
226 # the entire process down because it usually does not "hit".
d4213587 227 set skip 0
499ec5b1 228 if { ![isnative] && [info exists oldexec] } {
76f3b287 229 if { [file_on_host cmp $oldexec $execname] == 0 } {
d4213587 230 set skip 1
a504aabf 231 }
232 }
233 if { $skip == 0 } {
234 set result [gcc_load "$execname" "" ""]
d4213587 235 set status [lindex $result 0]
236 set output [lindex $result 1]
a504aabf 237 }
238 if { $oldstatus == "pass" } {
76f3b287 239 file_on_host delete $oldexec
912f9e81 240 }
241 $status "$testcase execution, $option"
d4213587 242 set oldstatus $status
a504aabf 243 }
244 if [info exists status] {
245 if { $status == "pass" } {
76f3b287 246 file_on_host delete $execname
a504aabf 247 }
912f9e81 248 }
249}
250
251#
252# search_for -- looks for a string match in a file
253#
254proc search_for { file pattern } {
255 set fd [open $file r]
256 while { [gets $fd cur_line]>=0 } {
257 if [string match "*$pattern*" $cur_line] then {
258 close $fd
259 return 1
260 }
261 }
262 close $fd
263 return 0
264}
265
266#
267# c-torture -- the c-torture testcase source file processor
268#
269# This runs compilation only tests (no execute tests).
270# SRC is the full pathname of the testcase, or just a file name in which case
271# we prepend $srcdir/$subdir.
272#
2b6d9ca1 273# If the testcase has an associated .x file, we source that to run the
274# test instead. We use .x so that we don't lengthen the existing filename
275# to more than 14 chars.
912f9e81 276#
277proc c-torture { args } {
fc7880b8 278 global srcdir subdir compiler_conditional_xfail_data
912f9e81 279
d4213587 280 set src [lindex $args 0]
912f9e81 281 if { [llength $args] > 1 } {
d4213587 282 set options [lindex $args 1]
912f9e81 283 } else {
284 set options ""
285 }
286
287 # Prepend $srdir/$subdir if missing.
288 if ![string match "*/*" $src] {
289 set src "$srcdir/$subdir/$src"
290 }
291
292 # Check for alternate driver.
2b6d9ca1 293 if [file exists [file rootname $src].x] {
294 verbose "Using alternate driver [file rootname [file tail $src]].x" 2
912f9e81 295 set done_p 0
2b6d9ca1 296 catch "set done_p \[source [file rootname $src].x\]"
912f9e81 297 if { $done_p } {
298 return
299 }
300 }
3326bbb9 301
912f9e81 302 # Look for a loop within the source code - if we don't find one,
303 # don't pass -funroll[-all]-loops.
304 global torture_with_loops torture_without_loops
305 if [expr [search_for $src "for*("]+[search_for $src "while*("]] then {
306 set option_list $torture_with_loops
307 } else {
308 set option_list $torture_without_loops
309 }
310
311 # loop through all the options
312 foreach option $option_list {
2b6d9ca1 313 # torture_compile_xfail is set by the .x script (if present)
912f9e81 314 if [info exists torture_compile_xfail] {
315 setup_xfail $torture_compile_xfail
316 }
317
b137f460 318 # torture_execute_before_compile is set by the .x script (if present)
319 if [info exists torture_eval_before_compile] {
320 set ignore_me [eval $torture_eval_before_compile]
321 }
3326bbb9 322
912f9e81 323 c-torture-compile $src "$option $options"
324 }
325}