OpenCores
URL https://opencores.org/ocsvn/openrisc/openrisc/trunk

Subversion Repositories openrisc

[/] [openrisc/] [trunk/] [gnu-dev/] [or1k-gcc/] [gcc/] [testsuite/] [lib/] [objc-torture.exp] - Blame information for rev 774

Go to most recent revision | Details | Compare with Previous | View Log

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

powered by: WebSVN 2.1.0

© copyright 1999-2024 OpenCores.org, equivalent to Oliscience, all rights reserved. OpenCores®, registered trademark.