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

Subversion Repositories open8_urisc

[/] [open8_urisc/] [trunk/] [gnu/] [binutils/] [ld/] [testsuite/] [ld-sh/] [arch/] [arch.exp] - Blame information for rev 286

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

Line No. Rev Author Line
1 106 khays
# Copyright (C) 2004, 2005, 2006, 2007, 2008
2
# Free Software Foundation, Inc.
3
#
4
# This file is part of the GNU Binutils.
5
#
6
# This program is free software; you can redistribute it and/or modify
7
# it under the terms of the GNU General Public License as published by
8
# the Free Software Foundation; either version 3 of the License, or
9
# (at your option) any later version.
10
#
11
# This program is distributed in the hope that it will be useful,
12
# but WITHOUT ANY WARRANTY; without even the implied warranty of
13
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
14
# GNU General Public License for more details.
15
#
16
# You should have received a copy of the GNU General Public License
17
# along with this program; if not, write to the Free Software
18
# Foundation, Inc., 51 Franklin Street - Fifth Floor, Boston,
19
# MA 02110-1301, USA.
20
 
21
 
22
# Please email any bugs, comments, and/or additions to this file to:
23
# binutils@sources.redhat.com
24
 
25
# This scripts tests of all available SH architectures with all other SH
26
# architectures. It ensures that those combinations which should not work
27
# do not work, and that those that should work produce the correct output
28
# architecture.
29
#
30
# It looks for files in the same directory as this file named sh*.s .
31
# Each file must contain one or more instructions which uniquely identifies
32
# that architecture. The architecture name is inferred from the file name.
33
# It is best to use the same files used by the assembler testsuite.
34
#
35
# It also creates another architecture named 'sh-unknown' by modifying
36
# another arch type (there is no way to assemble such an arch) in order
37
# to test what the linker would do with an older object file.
38
#
39
# The script generates the architecture permutations automatically,
40
# but it reads the expected results from the file arch_expected.txt (also
41
# found in the same directory as this script).
42
#
43
# The arch_expected.txt file should NOT be hand edited. Whenever the script
44
# is run (e.g. with 'make check') it creates a new (usually identical) file
45
# named arch_results.txt in the /ld/testsuite directory. When the
46
# expected results change (or new architectures are added) this new file
47
# can be used to replace arch_expected.txt with no modification required.
48
 
49
 
50
# The procedure extracts the architecture name from the objdump output.
51
# If there is no architecture name (or objdump output changes significantly)
52
# then the behaviour is undefined, but it will most likely return junk.
53
 
54
proc get_sh_arch { ofile } {
55
    global OBJDUMP
56
 
57
    set cmd "$OBJDUMP -f $ofile"
58
    verbose -log $cmd
59
    catch "exec $cmd" objdump_output
60
    verbose -log $objdump_output
61
 
62
    set objdump_output [string replace $objdump_output 0 \
63
            [expr [string first "architecture:" $objdump_output] + 13] ""]
64
 
65
    return [string range $objdump_output 0 [expr [string first "," $objdump_output] - 1]]
66
}
67
 
68
 
69
# This procedure runs two tests:
70
#   Test 1: Check the linker can link the given files.
71
#   Test 2: Check that the resultant architecture is as expected.
72
# It also writes an entry to the arch_results.txt file.
73
 
74
proc test_arch { file1 file2 arch resultfile } {
75
    global LD
76
 
77
    set name1 [file tail $file1]
78
    set rootname1 [file rootname $name1]
79
 
80
    set name2 [file tail $file2]
81
    set rootname2 [file rootname $name2]
82
 
83
    set flags [big_or_little_endian]
84
 
85
    # This must use -r to prevent LD trying to relocate the (unrealistic) file
86
    send_log "$LD $flags -r -o ${rootname1}_${rootname2}.o $file1 $file2\n"
87
    catch "exec $LD $flags -r -o ${rootname1}_${rootname2}.o $file1 $file2" ld_output
88
    send_log $ld_output
89
 
90
    if {[string equal $ld_output ""] == 1} then {
91
        pass "$rootname1 file should link with $rootname2 file"
92
 
93
        set result [get_sh_arch "${rootname1}_${rootname2}.o"]
94
        puts $resultfile [format "%-20s %-20s %s" $file1 $file2 $result]
95
 
96
        if {$result == $arch} then {
97
            pass "$rootname1 file with $rootname2 file should link to arch $arch"
98
            file delete "${rootname1}_${rootname2}.o"
99
        } else {
100
            fail "$rootname1 file with $rootname2 file should link to arch $arch"
101
        }
102
    } else {
103
        fail "$rootname1 file should link with $rootname2 file"
104
 
105
        puts $resultfile [format "%-20s %-20s ERROR" $file1 $file2]
106
        untested "$rootname2 file with $rootname2 file should link to arch $arch"
107
    }
108
 
109
}
110
 
111
 
112
 
113
# This procedure tests that a pair of files that are not
114
# suposed to link does, in fact, not link.
115
# It also writes an entry to the arch_results.txt file.
116
 
117
proc test_arch_error { file1 file2 resultfile} {
118
    global link_output LD
119
 
120
    set name1 [file tail $file1]
121
    set rootname1 [file rootname $name1]
122
 
123
    set name2 [file tail $file2]
124
    set rootname2 [file rootname $name2]
125
 
126
    # This must use -r to prevent LD trying to relocate the (unrealistic) file
127
    send_log "$LD -r -o ${rootname1}_${rootname2}.o $file1 $file2\n"
128
    catch "exec $LD -r -o ${rootname1}_${rootname2}.o $file1 $file2" ld_output
129
    send_log $ld_output
130
 
131
    if {[string equal $ld_output ""] == 1} then {
132
        fail "$rootname1 file should NOT link with $rootname2 file"
133
        puts $resultfile [format "%-20s %-20s [get_sh_arch ${rootname1}_${rootname2}.o]" $file1 $file2]
134
    } else {
135
        pass "$rootname1 file should NOT link with $rootname2 file"
136
        puts $resultfile [format "%-20s %-20s ERROR" $file1 $file2]
137
    }
138
}
139
 
140
# These tests are not suitable for sh-coff because
141
# coff does not store the architecture information.
142
 
143
if [istarget sh*-*-elf] then {
144
    global subdir srcdir
145
    global AS
146
 
147
    # Find all the architectures and assemble all the files
148
    # we will use for the linker tests.
149
 
150
    set sfilelist [lsort -ascii [glob "$srcdir/$subdir/sh*.s"]]
151
    set ofilelist {}
152
    foreach sfile $sfilelist {
153
        set ofile "[file rootname [file tail $sfile]].o"
154
        lappend ofilelist $ofile
155
 
156
        set endian "-big"
157
        if [string equal [big_or_little_endian] " -EL"] then {
158
            set endian "-little"
159
        }
160
 
161
        set cmd "$AS $endian -isa=any $sfile -o $ofile"
162
        verbose -log $cmd
163
        catch "exec $cmd" as_output
164
        if ![file exists $ofile] then {
165
            verbose -log $as_output
166
            perror "$sfile: assembly failed"
167
        }
168
    }
169
 
170
    # Create the default arch ofile
171
    # This cannot be created with the assembler
172
    # sh4al-dsp is number 6, sh-unknown is 0
173
 
174
    lappend ofilelist "sh-unknown.o"
175
 
176
    if [string equal [big_or_little_endian] " -EL"] then {
177
        set cmd {xxd sh4al-dsp.o | sed {s/\(^0000020: .... .... \)06/\100/} | xxd -r - sh-unknown.o}
178
    } else {
179
        set cmd {xxd sh4al-dsp.o | sed {s/\(^0000020: .... .... .... ..\)06/\100/} | xxd -r - sh-unknown.o}
180
    }
181
    verbose -log $cmd
182
    catch "exec $cmd" xxd_output
183
    verbose -log $xxd_output
184
    if [string equal [get_sh_arch "sh-unknown.o"] "sh4al-dsp"] then {
185
        perror "sh-unknown.o not generated correctly"
186
    }
187
 
188
 
189
    # Initialise the results file
190
 
191
    set outfile [open "arch_results.txt" w 0666]
192
    puts $outfile "# Generated file. DO NOT EDIT"
193
    puts $outfile "#"
194
    puts $outfile "# This file is generated by ld/testsuite/ld-sh/arch/arch.exp ."
195
    puts $outfile "# It contains the expected results of the tests."
196
    puts $outfile "# If the tests are failing because the expected results"
197
    puts $outfile "# have changed then run 'make check' and copy the new file"
198
    puts $outfile "# from /ld/arch_results.txt"
199
    puts $outfile "# to   /ld/testsuite/ld-sh/arch/arch_expected.txt ."
200
    puts $outfile "# Make sure the new expected results are ALL correct."
201
    puts $outfile "#"
202
    puts $outfile [format "# %-18s %-20s %s" "FILE1" "FILE2" "OUTPUT"]
203
    puts $outfile [format "# %-18s %-20s %s" "-----" "-----" "------"]
204
 
205
    # Open the expected results file and skip the header
206
 
207
    set infile [open "$srcdir/$subdir/arch_expected.txt" r]
208
    while {[gets $infile line] >= 0 && [string match {\#*} $line]} {verbose -log "reading '$line'"}
209
 
210
    foreach file1 $ofilelist {
211
        foreach file2 $ofilelist {
212
            set name1 [file tail $file1]
213
            set rootname1 [file rootname $name1]
214
 
215
            set name2 [file tail $file2]
216
            set rootname2 [file rootname $name2]
217
 
218
            # Decode the expected result from the file
219
 
220
            scan $line "%s %s %s" exfile1 exfile2 exarch
221
            verbose -log "exfile1 = '$exfile1', exfile2 = '$exfile2', exarch = '$exarch'"
222
            verbose -log "  name1 = '$name1',   name2 = '$name2'"
223
 
224
            if {[string equal $exfile1 $name1] && [string equal $exfile2 $file2]} then {
225
                # The expected result file makes sense and
226
                # appears up-to-date (the file and options match)
227
 
228
                if {[string equal $exarch "ERROR"]} then {
229
                    test_arch_error $file1 $file2 $outfile
230
                } else {
231
                    test_arch $file1 $file2 $exarch $outfile
232
                }
233
            } else {
234
                # The expected result file isn't right somehow
235
                # so just try any old test. This will cause
236
                # many failures, but will genrate the results file.
237
 
238
                test_arch $file1 $file2 $rootname1 $outfile
239
            }
240
 
241
            # Read the next line from the expected result file.
242
            # This is at the end because the process of skipping
243
            # the header reads the first real line
244
 
245
            if [gets $infile line] then {
246
                verbose -log "reading '$line'"
247
            }
248
        }
249
    }
250
 
251
    close $infile
252
    close $outfile
253
 
254
    foreach file $ofilelist {
255
        file delete $file
256
    }
257
}

powered by: WebSVN 2.1.0

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