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

Subversion Repositories openrisc

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

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

powered by: WebSVN 2.1.0

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