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

Subversion Repositories openrisc

[/] [openrisc/] [trunk/] [gnu-old/] [gcc-4.2.2/] [gcc/] [testsuite/] [lib/] [compat.exp] - Blame information for rev 816

Details | Compare with Previous | View Log

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

powered by: WebSVN 2.1.0

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