Merged with mainline at revision 128810.
[official-gcc.git] / gcc / testsuite / lib / c-torture.exp
blobabd2eb6b743e7d0144c043fe5b98ba8e5978ce92
1 # Copyright (C) 1992-1998, 1999, 2000, 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 # This file was written by Rob Savoye. (rob@cygnus.com)
19 load_lib file-format.exp
20 load_lib target-libpath.exp
22 # The default option list can be overridden by
23 # TORTURE_OPTIONS="{ { list1 } ... { listN } }"
25 if ![info exists TORTURE_OPTIONS] {
26 # It is theoretically beneficial to group all of the O2/O3 options together,
27 # as in many cases the compiler will generate identical executables for
28 # all of them--and the c-torture testsuite will skip testing identical
29 # executables multiple times.
30 # Also note that -finline-functions is explicitly included in one of the
31 # items below, even though -O3 is also specified, because some ports may
32 # choose to disable inlining functions by default, even when optimizing.
33 set TORTURE_OPTIONS [list \
34 { -O0 } \
35 { -O1 } \
36 { -O2 } \
37 { -O3 -fomit-frame-pointer } \
38 { -O3 -fomit-frame-pointer -funroll-loops } \
39 { -O3 -fomit-frame-pointer -funroll-all-loops -finline-functions } \
40 { -O3 -g } \
41 { -Os } ]
44 global GCC_UNDER_TEST
45 if ![info exists GCC_UNDER_TEST] {
46 set GCC_UNDER_TEST "[find_gcc]"
49 global orig_environment_saved
51 # This file may be sourced, so don't override environment settings
52 # that have been previously setup.
53 if { $orig_environment_saved == 0 } {
54 append ld_library_path [gcc-set-multilib-library-path $GCC_UNDER_TEST]
55 set_ld_library_path_env_vars
58 # Split TORTURE_OPTIONS into two choices: one for testcases with loops and
59 # one for testcases without loops.
61 set torture_with_loops $TORTURE_OPTIONS
62 set torture_without_loops ""
63 foreach option $TORTURE_OPTIONS {
64 if ![string match "*loop*" $option] {
65 lappend torture_without_loops $option
70 # c-torture-compile -- runs the Tege C-torture test
72 # SRC is the full pathname of the testcase.
73 # OPTION is the specific compiler flag we're testing (eg: -O2).
75 proc c-torture-compile { src option } {
76 global output
77 global srcdir tmpdir
78 global host_triplet
80 set output "$tmpdir/[file tail [file rootname $src]].o"
82 regsub "(?q)$srcdir/" $src "" testcase
83 # If we couldn't rip $srcdir out of `src' then just do the best we can.
84 # The point is to reduce the unnecessary noise in the logs. Don't strip
85 # out too much because different testcases with the same name can confuse
86 # `test-tool'.
87 if [string match "/*" $testcase] {
88 set testcase "[file tail [file dirname $src]]/[file tail $src]"
91 verbose "Testing $testcase, $option" 1
93 # Run the compiler and analyze the results.
94 set options ""
95 lappend options "additional_flags=-w $option"
97 set comp_output [gcc_target_compile "$src" "$output" object $options]
98 gcc_check_compile $testcase $option $output $comp_output
99 file_on_host delete $output
103 # c-torture-execute -- utility to compile and execute a testcase
105 # SOURCES is a list of full pathnames to the test source files.
106 # The first filename in this list forms the "testcase".
108 # If the testcase has an associated .x file, we source that to run the
109 # test instead. We use .x so that we don't lengthen the existing filename
110 # to more than 14 chars.
112 proc c-torture-execute { sources args } {
113 global tmpdir tool srcdir output compiler_conditional_xfail_data
115 # Use the first source filename given as the filename under test.
116 set src [lindex $sources 0]
118 if { [llength $args] > 0 } {
119 set additional_flags [lindex $args 0]
120 } else {
121 set additional_flags ""
123 # Check for alternate driver.
124 if [file exists [file rootname $src].x] {
125 verbose "Using alternate driver [file rootname [file tail $src]].x" 2
126 set done_p 0
127 catch "set done_p \[source [file rootname $src].x\]"
128 if { $done_p } {
129 return
133 # Look for a loop within the source code - if we don't find one,
134 # don't pass -funroll[-all]-loops.
135 global torture_with_loops torture_without_loops
136 if [expr [search_for $src "for*("]+[search_for $src "while*("]] then {
137 set option_list $torture_with_loops
138 } else {
139 set option_list $torture_without_loops
142 set executable $tmpdir/[file tail [file rootname $src].x]
144 regsub "(?q)$srcdir/" $src "" testcase
145 # If we couldn't rip $srcdir out of `src' then just do the best we can.
146 # The point is to reduce the unnecessary noise in the logs. Don't strip
147 # out too much because different testcases with the same name can confuse
148 # `test-tool'.
149 if [string match "/*" $testcase] {
150 set testcase "[file tail [file dirname $src]]/[file tail $src]"
153 set count 0
154 set oldstatus "foo"
155 foreach option $option_list {
156 if { $count > 0 } {
157 set oldexec $execname
159 set execname "${executable}${count}"
160 incr count
162 # torture_{compile,execute}_xfail are set by the .x script
163 # (if present)
164 if [info exists torture_compile_xfail] {
165 setup_xfail $torture_compile_xfail
168 # torture_execute_before_{compile,execute} can be set by the .x script
169 # (if present)
170 if [info exists torture_eval_before_compile] {
171 set ignore_me [eval $torture_eval_before_compile]
174 file_on_host delete $execname
175 verbose "Testing $testcase, $option" 1
177 set options ""
178 lappend options "additional_flags=-w $option"
179 if { $additional_flags != "" } {
180 lappend options "additional_flags=$additional_flags"
182 set comp_output [gcc_target_compile "$sources" "${execname}" executable $options]
184 if ![gcc_check_compile "$testcase compilation" $option $execname $comp_output] {
185 unresolved "$testcase execution, $option"
186 file_on_host delete $execname
187 continue
190 # See if this source file uses "long long" types, if it does, and
191 # no_long_long is set, skip execution of the test.
192 if [target_info exists no_long_long] then {
193 if [expr [search_for $src "long long"]] then {
194 unsupported "$testcase execution, $option"
195 continue
199 if [info exists torture_execute_xfail] {
200 setup_xfail $torture_execute_xfail
203 if [info exists torture_eval_before_execute] {
204 set ignore_me [eval $torture_eval_before_execute]
208 # Sometimes we end up creating identical executables for two
209 # consecutive sets of different of compiler options.
211 # In such cases we know the result of this test will be identical
212 # to the result of the last test.
214 # So in cases where the time to load and run/simulate the test
215 # is relatively high, compare the two binaries and avoid rerunning
216 # tests if the executables are identical.
218 # Do not do this for native testing since the cost to load/execute
219 # the test is fairly small and the comparison step actually slows
220 # the entire process down because it usually does not "hit".
221 set skip 0
222 if { ![isnative] && [info exists oldexec] } {
223 if { [file_on_host cmp $oldexec $execname] == 0 } {
224 set skip 1
227 if { $skip == 0 } {
228 set result [gcc_load "$execname" "" ""]
229 set status [lindex $result 0]
230 set output [lindex $result 1]
232 if { $oldstatus == "pass" } {
233 file_on_host delete $oldexec
235 $status "$testcase execution, $option"
236 set oldstatus $status
238 if [info exists status] {
239 if { $status == "pass" } {
240 file_on_host delete $execname
246 # search_for -- looks for a string match in a file
248 proc search_for { file pattern } {
249 set fd [open $file r]
250 while { [gets $fd cur_line]>=0 } {
251 if [string match "*$pattern*" $cur_line] then {
252 close $fd
253 return 1
256 close $fd
257 return 0
261 # c-torture -- the c-torture testcase source file processor
263 # This runs compilation only tests (no execute tests).
264 # SRC is the full pathname of the testcase, or just a file name in which case
265 # we prepend $srcdir/$subdir.
267 # If the testcase has an associated .x file, we source that to run the
268 # test instead. We use .x so that we don't lengthen the existing filename
269 # to more than 14 chars.
271 proc c-torture { args } {
272 global srcdir subdir compiler_conditional_xfail_data
274 set src [lindex $args 0]
275 if { [llength $args] > 1 } {
276 set options [lindex $args 1]
277 } else {
278 set options ""
281 # Prepend $srdir/$subdir if missing.
282 if ![string match "*/*" $src] {
283 set src "$srcdir/$subdir/$src"
286 # Check for alternate driver.
287 if [file exists [file rootname $src].x] {
288 verbose "Using alternate driver [file rootname [file tail $src]].x" 2
289 set done_p 0
290 catch "set done_p \[source [file rootname $src].x\]"
291 if { $done_p } {
292 return
296 # Look for a loop within the source code - if we don't find one,
297 # don't pass -funroll[-all]-loops.
298 global torture_with_loops torture_without_loops
299 if [expr [search_for $src "for*("]+[search_for $src "while*("]] then {
300 set option_list $torture_with_loops
301 } else {
302 set option_list $torture_without_loops
305 # loop through all the options
306 foreach option $option_list {
307 # torture_compile_xfail is set by the .x script (if present)
308 if [info exists torture_compile_xfail] {
309 setup_xfail $torture_compile_xfail
312 # torture_execute_before_compile is set by the .x script (if present)
313 if [info exists torture_eval_before_compile] {
314 set ignore_me [eval $torture_eval_before_compile]
317 c-torture-compile $src "$option $options"