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

Subversion Repositories openrisc_me

[/] [openrisc/] [trunk/] [gnu-src/] [gcc-4.5.1/] [gcc/] [testsuite/] [lib/] [compat.exp] - Blame information for rev 327

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

Line No. Rev Author Line
1 306 jeremybenn
# Copyright (C) 2002, 2003, 2004, 2005, 2007, 2008
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 Janis Johnson, 
19
 
20
 
21
# Test interoperability of two compilers that follow the same ABI, or
22
# compatibility of two versions of GCC.
23
#
24
# Each test has a main program that does nothing but call a function,
25
# plus two additional source files that contain parts of a program that
26
# rely on the ABI.  those source files are compiled into relocatable
27
# object files with both compilers.  Executables are built using various
28
# combinations of those object files, with the main program compiled
29
# with the compiler under test and using that compiler's runtime support.
30
 
31
# The including .exp file must define these callback procedures.
32
if [string match "" [info procs "compat-use-alt-compiler"]] then {
33
    error "Proc compat-use-alt-compiler is not defined."
34
}
35
if [string match "" [info procs "compat-use-tst-compiler"]] then {
36
    error "Proc compat-use-tst-compiler is not defined."
37
}
38
 
39
# Each test is run with each pair of compiler options from this list.
40
# The first set of options in each pair is used by the compiler under
41
# test, and the second set is used by the alternate compiler.
42
# The default option lists can be overridden by
43
# COMPAT_OPTIONS="[list [list {tst_1} {alt_1}]...[list {tst_n} {alt_n}]]"
44
# where tst_i and alt_i are lists of options.  You can put this in the
45
# environment before site.exp is written or add it to site.exp directly.
46
if ![info exists COMPAT_OPTIONS] {
47
    set COMPAT_OPTIONS [list \
48
        [list {} {}]]
49
}
50
 
51
set compat_option_list $COMPAT_OPTIONS
52
 
53
# Subsets of tests can be selectively disabled by members of this list:
54
#  - ATTRIBUTE: disable all tests using the __attribute__ extension,
55
#  - COMPLEX: disable all tests using the complex types feature,
56
#  - COMPLEX_INT: disable all tests using the complex integral types extension,
57
#  - VA: disable all tests using the variable number of arguments feature,
58
#  - VLA_IN_STRUCT: disable all tests using the variable-length arrays as
59
#    structure members extension,
60
#  - ZERO_ARRAY: disable all tests using the zero-sized arrays extension.
61
# The default skip lists can be overriden by
62
# COMPAT_SKIPS="[list {skip_1}...{skip_n}]"
63
# where skip_i are skip identifiers.  You can put this in the environment
64
# before site.exp is written or add it to site.exp directly.
65
if ![info exists COMPAT_SKIPS] {
66
    set COMPAT_SKIPS [list {}]
67
}
68
 
69
global compat_skip_list
70
set compat_skip_list $COMPAT_SKIPS
71
 
72
load_lib dg.exp
73
load_lib gcc-dg.exp
74
 
75
#
76
# compat-obj -- compile to an object file
77
#
78
# SOURCE is the source file
79
# DEST is the object file
80
# OPTALL is the list of compiler options to use with all tests
81
# OPTFILE is the list of compiler options to use with this file
82
# OPTSTR is the options to print with test messages
83
# XFAILDATA is the xfail data to be passed to the compiler
84
#
85
proc compat-obj { source dest optall optfile optstr xfaildata } {
86
    global testcase
87
    global tool
88
    global compiler_conditional_xfail_data
89
    global compat_skip_list
90
 
91
    # Add the skip specifiers.
92
    foreach skip $compat_skip_list {
93
        if { ![string match $skip ""] } {
94
            lappend optall "-DSKIP_$skip"
95
        }
96
    }
97
 
98
    # Set up the options for compiling this file.
99
    set options ""
100
    lappend options "additional_flags=$optfile $optall"
101
 
102
    set compiler_conditional_xfail_data $xfaildata
103
    set comp_output [${tool}_target_compile "$source" "$dest" object $options]
104
    ${tool}_check_compile "$testcase $dest compile" $optstr $dest $comp_output
105
}
106
 
107
# compat-run -- link and run an executable
108
#
109
# TESTNAME is the mixture of object files to link
110
# OBJLIST is the list of object files to link
111
# DEST is the name of the executable
112
# OPTALL is a list of compiler and linker options to use for all tests
113
# OPTFILE is a list of compiler and linker options to use for this test
114
# OPTSTR is the list of options to list in messages
115
#
116
proc compat-run { testname objlist dest optall optfile optstr } {
117
    global testcase
118
    global tool
119
 
120
    # Check that all of the objects were built successfully.
121
    foreach obj [split $objlist] {
122
        if ![file_on_host exists $obj] then {
123
            unresolved "$testcase $testname link $optstr"
124
            unresolved "$testcase $testname execute $optstr"
125
            return
126
        }
127
    }
128
 
129
    # Set up the options for linking this test.
130
    set options ""
131
    lappend options "additional_flags=$optfile $optall"
132
 
133
    # Link the objects into an executable.
134
    set comp_output [${tool}_target_compile "$objlist" $dest executable \
135
                     "$options"]
136
    if ![${tool}_check_compile "$testcase $testname link" "" \
137
         $dest $comp_output] then {
138
        unresolved "$testcase $testname execute $optstr"
139
        return
140
    }
141
 
142
    # Run the self-checking executable.
143
    if ![string match "*/*" $dest] then {
144
        set dest "./$dest"
145
    }
146
    set result [${tool}_load $dest "" ""]
147
    set status [lindex $result 0]
148
    if { $status == "pass" } then {
149
        file_on_host delete $dest
150
    }
151
    $status "$testcase $testname execute $optstr"
152
}
153
 
154
#
155
# compat-get-options-main -- get target requirements for a test and
156
# options for the primary source file and the test as a whole
157
#
158
# SRC is the full pathname of the primary source file.
159
#
160
proc compat-get-options-main { src } {
161
    # dg-options sets a variable called dg-extra-tool-flags.
162
    set dg-extra-tool-flags ""
163
    # dg-options sets a variable called tool_flags.
164
    set tool_flags ""
165
 
166
    # dg-require-* sets dg-do-what.
167
    upvar dg-do-what dg-do-what
168
 
169
    set tmp [dg-get-options $src]
170
    foreach op $tmp {
171
        set cmd [lindex $op 0]
172
        if { ![string compare "dg-options" $cmd] \
173
             || [string match "dg-prune-output" $cmd] \
174
             || [string match "dg-skip-if" $cmd] \
175
             || [string match "dg-require-*" $cmd]  } {
176
            set status [catch "$op" errmsg]
177
            if { $status != 0 } {
178
                perror "src: $errmsg for \"$op\"\n"
179
                unresolved "$src: $errmsg for \"$op\""
180
                return
181
            }
182
        } elseif { ![string compare "dg-xfail-if" $cmd] } {
183
            warning "compat.exp does not support $cmd in primary source file"
184
        } else {
185
            # Ignore unrecognized dg- commands, but warn about them.
186
            warning "compat.exp does not support $cmd"
187
        }
188
    }
189
 
190
    # Return flags to use for compiling the primary source file and for
191
    # linking.
192
    return ${dg-extra-tool-flags}
193
}
194
 
195
#
196
# compat-get-options -- get special tool flags to use for a secondary
197
# source file
198
#
199
# SRC is the full pathname of the source file.
200
# The result is a list of options to use.
201
#
202
# This code is copied from proc dg-test in dg.exp from DejaGNU.
203
#
204
proc compat-get-options { src } {
205
    # dg-options sets a variable called dg-extra-tool-flags.
206
    set dg-extra-tool-flags ""
207
 
208
    # dg-xfail-if sets compiler_conditional_xfail_data.
209
    global compiler_conditional_xfail_data
210
    set compiler_conditional_xfail_data ""
211
 
212
    # dg-xfail-if needs access to dg-do-what.
213
    upvar dg-do-what dg-do-what
214
 
215
    set tmp [dg-get-options $src]
216
    foreach op $tmp {
217
        set cmd [lindex $op 0]
218
        if { ![string compare "dg-options" $cmd] \
219
             || ![string compare "dg-prune-output" $cmd] \
220
             || ![string compare "dg-xfail-if" $cmd] } {
221
            set status [catch "$op" errmsg]
222
            if { $status != 0 } {
223
                perror "src: $errmsg for \"$op\"\n"
224
                unresolved "$src: $errmsg for \"$op\""
225
                return
226
            }
227
        } elseif { [string match "dg-require-*" $cmd] } {
228
            warning "compat.exp does not support $cmd in secondary source files"
229
        } else {
230
            # Ignore unrecognized dg- commands, but warn about them.
231
            warning "compat.exp does not support $cmd"
232
        }
233
    }
234
 
235
    return ${dg-extra-tool-flags}
236
}
237
 
238
#
239
# compat-execute -- compile with compatible compilers
240
#
241
# SRC1 is the full pathname of the main file of the testcase.
242
# SID identifies a test suite in the names of temporary files.
243
# USE_ALT is nonzero if we're using an alternate compiler as well as
244
#   the compiler under test.
245
#
246
proc compat-execute { src1 sid use_alt } {
247
    global srcdir tmpdir
248
    global compat_option_list
249
    global tool
250
    global verbose
251
    global testcase
252
    global gluefile
253
    global compiler_conditional_xfail_data
254
    global dg-do-what-default
255
 
256
    # Get extra flags for this test from the primary source file, and
257
    # process other dg-* options that this suite supports.  Warn about
258
    # unsupported flags.
259
    verbose "compat-execute: $src1" 1
260
    set dg-do-what [list ${dg-do-what-default} "" P]
261
    set extra_flags_1 [compat-get-options-main $src1]
262
 
263
    # Check whether this test is supported for this target.
264
    if { [lindex ${dg-do-what} 1 ] == "N" } {
265
        unsupported "$src1"
266
        verbose "$src1 not supported on this target, skipping it" 3
267
        return
268
    }
269
 
270
    # Set up the names of the other source files.
271
    set dir [file dirname $src1]
272
    set ext [file extension $src1]
273
    set base [file rootname $src1]
274
    set base [string range $base [string length $dir] end]
275
    regsub "_main" $base "" base
276
    set src2 "${dir}/${base}_x${ext}"
277
    set src3 "${dir}/${base}_y${ext}"
278
 
279
    # Use the dg-options mechanism to specify extra flags for this test.
280
    # The extra flags in each file are used to compile that file, and the
281
    # extra flags in *_main.* are also used for linking.
282
    set extra_flags_2 [compat-get-options $src2]
283
    set compile_xfail_2 $compiler_conditional_xfail_data
284
    set extra_flags_3 [compat-get-options $src3]
285
    set compile_xfail_3 $compiler_conditional_xfail_data
286
 
287
    # On the SPU, most of the compat test cases exceed local store size.
288
    # Use automatic overlay support to make them fit.
289
    if { [check_effective_target_spu_auto_overlay] } {
290
        set extra_flags_1 "$extra_flags_1 -Wl,--auto-overlay"
291
        set extra_flags_1 "$extra_flags_1 -ffunction-sections"
292
        set extra_flags_2 "$extra_flags_2 -ffunction-sections"
293
        set extra_flags_3 "$extra_flags_3 -ffunction-sections"
294
    }
295
 
296
    # Define the names of the object files.
297
    regsub "sid" "sid_main_tst.o" $sid obj1
298
    regsub "sid" "sid_x_tst.o" $sid obj2_tst
299
    regsub "sid" "sid_x_alt.o" $sid obj2_alt
300
    regsub "sid" "sid_y_tst.o" $sid obj3_tst
301
    regsub "sid" "sid_y_alt.o" $sid obj3_alt
302
 
303
    # Get the base name of this test, for use in messages.
304
    set testcase "$src1"
305
    # Remove the $srcdir and $tmpdir prefixes from $src1.  (It would
306
    # be possible to use "regsub" here, if we were careful to escape
307
    # all regular expression characters in $srcdir and $tmpdir, but
308
    # that would be more complicated that this approach.)
309
    if {[string first "$srcdir/" "$src1"] == 0} {
310
        set testcase [string range "$src1" [string length "$srcdir/"] end]
311
    }
312
    if {[string first "$tmpdir/" "$testcase"] == 0} {
313
        set testcase [string range "$testcase" [string length "$tmpdir/"] end]
314
        set testcase "tmpdir-$testcase"
315
    }
316
    regsub "_main.*" $testcase "" testcase
317
    # Set up the base name of executable files so they'll be unique.
318
    regsub -all "\[./\]" $testcase "-" execbase
319
 
320
    # If we couldn't rip $srcdir out of `src1' then just do the best we can.
321
    # The point is to reduce the unnecessary noise in the logs.  Don't strip
322
    # out too much because different testcases with the same name can confuse
323
    # `test-tool'.
324
    if [string match "/*" $testcase] then {
325
        set testcase "[file tail [file dirname $src1]]/[file tail $src1]"
326
    }
327
 
328
    # Loop through all of the option lists used for this test.
329
 
330
    set count 0
331
    foreach option_pair $compat_option_list {
332
 
333
        # Pick out each set of options.
334
        set tst_option [lindex $option_pair 0]
335
        set alt_option [lindex $option_pair 1]
336
        set optstr ""
337
        if { ![string match $tst_option ""] \
338
             || ![string match $alt_option ""] } then {
339
            set optstr "\"$tst_option\",\"$alt_option\""
340
        }
341
        verbose "Testing $testcase, $optstr" 1
342
 
343
        # There's a unique name for each executable we generate, based on
344
        # the set of options and how the pieces of the tests are compiled.
345
        set execname1 "${execbase}-${count}1.exe"
346
        set execname2 "${execbase}-${count}2.exe"
347
        set execname3 "${execbase}-${count}3.exe"
348
        set execname4 "${execbase}-${count}4.exe"
349
        incr count
350
 
351
        file_on_host delete $execname1
352
        file_on_host delete $execname2
353
        file_on_host delete $execname3
354
        file_on_host delete $execname4
355
 
356
        # Compile pieces with the alternate compiler; we'll catch problems
357
        # later.  Skip this if we don't have an alternate compiler.
358
        if { $use_alt != 0 } then {
359
            compat-use-alt-compiler
360
            compat-obj "$src2" "$obj2_alt" $alt_option $extra_flags_2 \
361
                       $optstr $compile_xfail_2
362
            compat-obj "$src3" "$obj3_alt" $alt_option $extra_flags_3 \
363
                       $optstr $compile_xfail_3
364
        }
365
 
366
        # Compile pieces with the compiler under test.
367
        compat-use-tst-compiler
368
        compat-obj "$src1" "$obj1" $tst_option $extra_flags_1 $optstr ""
369
        compat-obj "$src2" "$obj2_tst" $tst_option $extra_flags_2 \
370
                   $optstr $compile_xfail_2
371
        compat-obj "$src3" "$obj3_tst" $tst_option $extra_flags_3 \
372
                   $optstr $compile_xfail_3
373
 
374
        # Link (using the compiler under test), run, and clean up tests.
375
        compat-run "${obj2_tst}-${obj3_tst}" \
376
            "$obj1 $obj2_tst $obj3_tst" $execname1 \
377
            $tst_option $extra_flags_1 $optstr
378
 
379
        # If we've got an alternate compiler try some combinations.
380
        if { $use_alt != 0 } then {
381
            compat-run "${obj2_tst}-${obj3_alt}" "$obj1 $obj2_tst $obj3_alt" \
382
                       $execname2 $tst_option $extra_flags_1 $optstr
383
            compat-run "${obj2_alt}-${obj3_tst}" "$obj1 $obj2_alt $obj3_tst" \
384
                       $execname3 $tst_option $extra_flags_1 $optstr
385
            compat-run "${obj2_alt}-${obj3_alt}" "$obj1 $obj2_alt $obj3_alt" \
386
                       $execname4 $tst_option $extra_flags_1 $optstr
387
        }
388
 
389
        # Clean up object files.
390
        set files [glob -nocomplain ${sid}_*.o]
391
        if { $files != "" } {
392
            foreach objfile $files {
393
                if { ![info exists gluefile] || $objfile != $gluefile } {
394
                    eval "file_on_host delete $objfile"
395
                }
396
            }
397
        }
398
    }
399
}

powered by: WebSVN 2.1.0

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