OSDN Git Service

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