]>
Commit | Line | Data |
---|---|---|
f1717362 | 1 | # Copyright (C) 1992-2016 Free Software Foundation, Inc. |
ff79b0cf | 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 | |
f63ff66b | 5 | # the Free Software Foundation; either version 3 of the License, or |
ff79b0cf | 6 | # (at your option) any later version. |
02ba0754 | 7 | # |
ff79b0cf | 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. | |
02ba0754 | 12 | # |
ff79b0cf | 13 | # You should have received a copy of the GNU General Public License |
f63ff66b | 14 | # along with GCC; see the file COPYING3. If not see |
15 | # <http://www.gnu.org/licenses/>. | |
ff79b0cf | 16 | |
ff79b0cf | 17 | # This file was written by Rob Savoye. (rob@cygnus.com) |
18 | ||
02ba0754 | 19 | load_lib file-format.exp |
6a99666a | 20 | load_lib target-supports.exp |
02ba0754 | 21 | |
6a99666a | 22 | # Make sure that the runtime list is re-evaluated for each multilib. |
23 | proc objc-set-runtime-options { dowhat args } { | |
24 | global OBJC_RUNTIME_OPTIONS | |
eec28c87 | 25 | set rtlist [list "-fgnu-runtime" ] |
26 | # At present (4.6), the only NeXT runtime target is Darwin. | |
27 | # The previously used approach of testing trivial compiles is not reliable | |
28 | # for determining the absence of the NeXT runtime, since a non-Darwin | |
29 | # installation can have the objc headers present in the same locations | |
30 | # that Darwin uses. If NeXT is ported to another target, then it should | |
31 | # be listed here. | |
80fad4aa | 32 | if [istarget *-*-darwin*] { |
eec28c87 | 33 | lappend rtlist "-fnext-runtime" |
34 | } | |
35 | if [info exists OBJC_RUNTIME_OPTIONS] { | |
36 | foreach other $OBJC_RUNTIME_OPTIONS { | |
37 | # Don't do tests twice... | |
38 | if { ( $other == "-fnext-runtime" || $other == "-fgnu-runtime" ) } { | |
39 | continue | |
6a99666a | 40 | } |
eec28c87 | 41 | lappend rtlist $other |
42 | } | |
6a99666a | 43 | } |
62a22729 | 44 | |
6a99666a | 45 | set OBJC_RUNTIME_OPTIONS "" |
62a22729 | 46 | |
6a99666a | 47 | foreach type $rtlist { |
48 | global srcdir subdir target_triplet tmpdir | |
49 | ||
50 | set options "additional_flags=$type" | |
51 | if [info exists args] { | |
52 | lappend options $args | |
53 | } | |
54 | verbose "options $options" | |
6a99666a | 55 | if [info exists dowhat] { |
54f87806 | 56 | switch $dowhat { |
57 | "compile" { | |
eec28c87 | 58 | # We should check that the generated asm is sensible, so do |
59 | # the equivalent of -c. | |
60 | set compile_type "object" | |
61 | set output_file "trivial.o" | |
54f87806 | 62 | set comp_output [objc_target_compile \ |
63 | "$srcdir/$subdir/trivial.m" "$output_file" "$compile_type" $options] | |
64 | ||
65 | remote_file build delete $output_file | |
66 | # If we get any error, then we failed. | |
67 | if ![string match "" $comp_output] then { | |
68 | continue; | |
69 | } | |
6a99666a | 70 | } |
54f87806 | 71 | "execute" { |
72 | set test_obj "trivial.exe" | |
73 | set comp_output [objc_target_compile \ | |
74 | "$srcdir/$subdir/trivial.m" $test_obj "executable" $options] | |
75 | ||
76 | # If we get any error, then we failed. | |
77 | if ![string match "" $comp_output] then { | |
78 | remote_file build delete $test_obj | |
79 | continue; | |
80 | } | |
81 | set result [objc_load "$tmpdir/$test_obj" "" ""] | |
82 | set status [lindex $result 0] | |
83 | set output [lindex $result 1] | |
84 | remote_file build delete $test_obj | |
85 | if { $status != "pass" } { | |
86 | verbose -log "trivial execute failed with $status $output" | |
87 | continue; | |
88 | } | |
89 | } | |
90 | default { | |
91 | perror "$dowhat: not a valid objc-torture action" | |
92 | return "" | |
93 | } | |
94 | } | |
95 | } else { | |
96 | set test_obj "trivial.exe" | |
97 | set comp_output [objc_target_compile \ | |
98 | "$srcdir/$subdir/trivial.m" $test_obj executable $options] | |
99 | ||
100 | # If we get any error, then we failed. | |
101 | remote_file build delete $test_obj | |
102 | if ![string match "" $comp_output] then { | |
103 | continue; | |
104 | } | |
6a99666a | 105 | } |
6a99666a | 106 | lappend OBJC_RUNTIME_OPTIONS $type |
62a22729 | 107 | } |
62a22729 | 108 | |
6a99666a | 109 | verbose -log "Using the following runtimes: $OBJC_RUNTIME_OPTIONS" |
110 | } | |
62a22729 | 111 | |
07e23beb | 112 | # The default option list can be overridden by |
113 | # TORTURE_OPTIONS="{ { list1 } ... { listN } }" | |
114 | ||
115 | if [info exists TORTURE_OPTIONS] { | |
116 | set OBJC_TORTURE_OPTIONS $TORTURE_OPTIONS | |
117 | } else { | |
02ba0754 | 118 | # It is theoretically beneficial to group all of the O2/O3 options together, |
119 | # as in many cases the compiler will generate identical executables for | |
120 | # all of them--and the objc-torture testsuite will skip testing identical | |
121 | # executables multiple times. | |
122 | # Also note that -finline-functions is explicitly included in one of the | |
123 | # items below, even though -O3 is also specified, because some ports may | |
124 | # choose to disable inlining functions by default, even when optimizing. | |
07e23beb | 125 | set OBJC_TORTURE_OPTIONS [list \ |
62a22729 | 126 | " -O0 " \ |
127 | " -O1 " \ | |
128 | " -O2 " \ | |
22b48429 | 129 | " -O3 -fomit-frame-pointer -funroll-loops -fpeel-loops -ftracer -finline-functions " \ |
62a22729 | 130 | " -O3 -g " \ |
131 | " -Os " ] | |
ff79b0cf | 132 | } |
133 | ||
4425e8dc | 134 | if [info exists ADDITIONAL_TORTURE_OPTIONS] { |
6a99666a | 135 | set OBJC_TORTURE_OPTIONS \ |
4425e8dc | 136 | [concat $OBJC_TORTURE_OPTIONS $ADDITIONAL_TORTURE_OPTIONS] |
137 | } | |
138 | ||
ff79b0cf | 139 | # |
02ba0754 | 140 | # objc-torture-compile -- runs the Tege OBJC-torture test |
ff79b0cf | 141 | # |
142 | # SRC is the full pathname of the testcase. | |
143 | # OPTION is the specific compiler flag we're testing (eg: -O2). | |
144 | # | |
145 | proc objc-torture-compile { src option } { | |
146 | global output | |
147 | global srcdir tmpdir | |
148 | global host_triplet | |
149 | ||
150 | set output "$tmpdir/[file tail [file rootname $src]].o" | |
151 | ||
b6124398 | 152 | regsub "(?q)$srcdir/" $src "" testcase |
ff79b0cf | 153 | # If we couldn't rip $srcdir out of `src' then just do the best we can. |
154 | # The point is to reduce the unnecessary noise in the logs. Don't strip | |
155 | # out too much because different testcases with the same name can confuse | |
156 | # `test-tool'. | |
157 | if [string match "/*" $testcase] { | |
158 | set testcase "[file tail [file dirname $src]]/[file tail $src]" | |
159 | } | |
160 | ||
161 | verbose "Testing $testcase, $option" 1 | |
162 | ||
163 | # Run the compiler and analyze the results. | |
164 | set options "" | |
ded736d4 | 165 | lappend options "additional_flags=-w $option" |
ff79b0cf | 166 | |
d4213587 | 167 | set comp_output [objc_target_compile "$src" "$output" object $options] |
02ba0754 | 168 | objc_check_compile $testcase $option $output $comp_output |
ff79b0cf | 169 | remote_file build delete $output |
170 | } | |
171 | ||
172 | # | |
173 | # objc-torture-execute -- utility to compile and execute a testcase | |
174 | # | |
175 | # SRC is the full pathname of the testcase. | |
176 | # | |
02ba0754 | 177 | # If the testcase has an associated .x file, we source that to run the |
178 | # test instead. We use .x so that we don't lengthen the existing filename | |
179 | # to more than 14 chars. | |
ff79b0cf | 180 | # |
02ba0754 | 181 | proc objc-torture-execute { src args } { |
182 | global tmpdir tool srcdir output compiler_conditional_xfail_data | |
ff79b0cf | 183 | |
02ba0754 | 184 | if { [llength $args] > 0 } { |
d4213587 | 185 | set additional_flags [lindex $args 0] |
02ba0754 | 186 | } else { |
d4213587 | 187 | set additional_flags "" |
02ba0754 | 188 | } |
ff79b0cf | 189 | # Check for alternate driver. |
02ba0754 | 190 | if [file exists [file rootname $src].x] { |
191 | verbose "Using alternate driver [file rootname [file tail $src]].x" 2 | |
ff79b0cf | 192 | set done_p 0 |
02ba0754 | 193 | catch "set done_p \[source [file rootname $src].x\]" |
ff79b0cf | 194 | if { $done_p } { |
195 | return | |
196 | } | |
197 | } | |
02ba0754 | 198 | |
ff79b0cf | 199 | # Look for a loop within the source code - if we don't find one, |
200 | # don't pass -funroll[-all]-loops. | |
201 | global torture_with_loops torture_without_loops | |
02ba0754 | 202 | if [expr [search_for $src "for*("]+[search_for $src "while*("]] then { |
ff79b0cf | 203 | set option_list $torture_with_loops |
204 | } else { | |
205 | set option_list $torture_without_loops | |
206 | } | |
207 | ||
208 | set executable $tmpdir/[file tail [file rootname $src].x] | |
209 | ||
b6124398 | 210 | regsub "(?q)$srcdir/" $src "" testcase |
ff79b0cf | 211 | # If we couldn't rip $srcdir out of `src' then just do the best we can. |
212 | # The point is to reduce the unnecessary noise in the logs. Don't strip | |
213 | # out too much because different testcases with the same name can confuse | |
214 | # `test-tool'. | |
215 | if [string match "/*" $testcase] { | |
216 | set testcase "[file tail [file dirname $src]]/[file tail $src]" | |
217 | } | |
218 | ||
d4213587 | 219 | set count 0 |
220 | set oldstatus "foo" | |
ff79b0cf | 221 | foreach option $option_list { |
02ba0754 | 222 | if { $count > 0 } { |
6a99666a | 223 | if [info exists oldexec] { |
224 | remote_file build delete $oldexec | |
225 | } | |
d4213587 | 226 | set oldexec $execname |
02ba0754 | 227 | } |
d4213587 | 228 | set execname "${executable}${count}" |
229 | incr count | |
02ba0754 | 230 | |
231 | # torture_{compile,execute}_xfail are set by the .x script | |
ff79b0cf | 232 | # (if present) |
233 | if [info exists torture_compile_xfail] { | |
234 | setup_xfail $torture_compile_xfail | |
235 | } | |
02ba0754 | 236 | |
237 | # torture_execute_before_{compile,execute} can be set by the .x script | |
238 | # (if present) | |
239 | if [info exists torture_eval_before_compile] { | |
6a99666a | 240 | set ignore_me [eval $torture_eval_before_compile] |
02ba0754 | 241 | } |
242 | ||
d4213587 | 243 | remote_file build delete $execname |
ff79b0cf | 244 | verbose "Testing $testcase, $option" 1 |
245 | ||
246 | set options "" | |
ded736d4 | 247 | lappend options "additional_flags=-w $option" |
02ba0754 | 248 | if { $additional_flags != "" } { |
d4213587 | 249 | lappend options "additional_flags=$additional_flags" |
ff79b0cf | 250 | } |
d4213587 | 251 | set comp_output [objc_target_compile "$src" "${execname}" executable $options] |
ff79b0cf | 252 | |
02ba0754 | 253 | if ![objc_check_compile "$testcase compilation" $option $execname $comp_output] { |
254 | unresolved "$testcase execution, $option" | |
255 | remote_file build delete $execname | |
ff79b0cf | 256 | continue |
ff79b0cf | 257 | } |
258 | ||
259 | # See if this source file uses "long long" types, if it does, and | |
260 | # no_long_long is set, skip execution of the test. | |
261 | if [target_info exists no_long_long] then { | |
02ba0754 | 262 | if [expr [search_for $src "long long"]] then { |
263 | unsupported "$testcase execution, $option" | |
6a99666a | 264 | remote_file build delete $execname |
ff79b0cf | 265 | continue |
266 | } | |
267 | } | |
268 | ||
269 | if [info exists torture_execute_xfail] { | |
270 | setup_xfail $torture_execute_xfail | |
271 | } | |
02ba0754 | 272 | |
273 | if [info exists torture_eval_before_execute] { | |
6a99666a | 274 | set ignore_me [eval $torture_eval_before_execute] |
02ba0754 | 275 | } |
276 | ||
277 | ||
278 | # Sometimes we end up creating identical executables for two | |
279 | # consecutive sets of different of compiler options. | |
280 | # | |
281 | # In such cases we know the result of this test will be identical | |
282 | # to the result of the last test. | |
283 | # | |
284 | # So in cases where the time to load and run/simulate the test | |
285 | # is relatively high, compare the two binaries and avoid rerunning | |
286 | # tests if the executables are identical. | |
287 | # | |
288 | # Do not do this for native testing since the cost to load/execute | |
289 | # the test is fairly small and the comparison step actually slows | |
290 | # the entire process down because it usually does not "hit". | |
d4213587 | 291 | set skip 0 |
02ba0754 | 292 | if { ![isnative] && [info exists oldexec] } { |
293 | if { [remote_file build cmp $oldexec $execname] == 0 } { | |
d4213587 | 294 | set skip 1 |
6a99666a | 295 | set status $oldstatus |
02ba0754 | 296 | } |
297 | } | |
298 | if { $skip == 0 } { | |
299 | set result [objc_load "$execname" "" ""] | |
d4213587 | 300 | set status [lindex $result 0] |
301 | set output [lindex $result 1] | |
02ba0754 | 302 | } |
ff79b0cf | 303 | $status "$testcase execution, $option" |
d4213587 | 304 | set oldstatus $status |
6a99666a | 305 | # for each option |
306 | } | |
307 | # tidy up | |
308 | if [info exists execname] { | |
309 | remote_file build delete $execname | |
02ba0754 | 310 | } |
6a99666a | 311 | if [info exists oldexec] { |
312 | remote_file build delete $oldexec | |
ff79b0cf | 313 | } |
314 | } | |
315 | ||
316 | # | |
317 | # search_for -- looks for a string match in a file | |
318 | # | |
319 | proc search_for { file pattern } { | |
320 | set fd [open $file r] | |
321 | while { [gets $fd cur_line]>=0 } { | |
02ba0754 | 322 | if [string match "*$pattern*" $cur_line] then { |
ff79b0cf | 323 | close $fd |
324 | return 1 | |
325 | } | |
326 | } | |
327 | close $fd | |
328 | return 0 | |
329 | } | |
330 | ||
331 | # | |
332 | # objc-torture -- the objc-torture testcase source file processor | |
333 | # | |
334 | # This runs compilation only tests (no execute tests). | |
335 | # SRC is the full pathname of the testcase, or just a file name in which case | |
336 | # we prepend $srcdir/$subdir. | |
337 | # | |
02ba0754 | 338 | # If the testcase has an associated .x file, we source that to run the |
339 | # test instead. We use .x so that we don't lengthen the existing filename | |
340 | # to more than 14 chars. | |
ff79b0cf | 341 | # |
342 | proc objc-torture { args } { | |
02ba0754 | 343 | global srcdir subdir compiler_conditional_xfail_data |
ff79b0cf | 344 | |
d4213587 | 345 | set src [lindex $args 0] |
ff79b0cf | 346 | if { [llength $args] > 1 } { |
d4213587 | 347 | set options [lindex $args 1] |
ff79b0cf | 348 | } else { |
349 | set options "" | |
350 | } | |
351 | ||
352 | # Prepend $srdir/$subdir if missing. | |
353 | if ![string match "*/*" $src] { | |
354 | set src "$srcdir/$subdir/$src" | |
355 | } | |
356 | ||
357 | # Check for alternate driver. | |
02ba0754 | 358 | if [file exists [file rootname $src].x] { |
359 | verbose "Using alternate driver [file rootname [file tail $src]].x" 2 | |
ff79b0cf | 360 | set done_p 0 |
02ba0754 | 361 | catch "set done_p \[source [file rootname $src].x\]" |
ff79b0cf | 362 | if { $done_p } { |
363 | return | |
364 | } | |
365 | } | |
02ba0754 | 366 | |
ff79b0cf | 367 | # Look for a loop within the source code - if we don't find one, |
368 | # don't pass -funroll[-all]-loops. | |
369 | global torture_with_loops torture_without_loops | |
02ba0754 | 370 | if [expr [search_for $src "for*("]+[search_for $src "while*("]] then { |
6a99666a | 371 | set option_list $torture_with_loops |
ff79b0cf | 372 | } else { |
6a99666a | 373 | set option_list $torture_without_loops |
ff79b0cf | 374 | } |
375 | ||
376 | # loop through all the options | |
377 | foreach option $option_list { | |
02ba0754 | 378 | # torture_compile_xfail is set by the .x script (if present) |
ff79b0cf | 379 | if [info exists torture_compile_xfail] { |
380 | setup_xfail $torture_compile_xfail | |
381 | } | |
382 | ||
02ba0754 | 383 | # torture_execute_before_compile is set by the .x script (if present) |
384 | if [info exists torture_eval_before_compile] { | |
6a99666a | 385 | set ignore_me [eval $torture_eval_before_compile] |
02ba0754 | 386 | } |
387 | ||
ff79b0cf | 388 | objc-torture-compile $src "$option $options" |
389 | } | |
390 | } |