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

Subversion Repositories open8_urisc

[/] [open8_urisc/] [trunk/] [gnu/] [binutils/] [binutils/] [testsuite/] [binutils-all/] [readelf.exp] - Blame information for rev 15

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

Line No. Rev Author Line
1 15 khays
#   Copyright 1999, 2000, 2001, 2003, 2004, 2007, 2009
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 this program; if not, write to the Free Software
16
# Foundation, Inc., 51 Franklin Street - Fifth Floor, Boston, MA 02110-1301, USA.
17
 
18
# Please email any bugs, comments, and/or additions to this file to:
19
# bug-dejagnu@prep.ai.mit.edu
20
 
21
# Written by Nick Clifton 
22
# Based on scripts written by Ian Lance Taylor 
23
# and Ken Raeburn .
24
 
25
# Exclude non-ELF targets.
26
if ![is_elf_format] {
27
    verbose "$READELF is only intended for ELF targets" 2
28
    return
29
}
30
 
31
# First some helpful procedures, then the tests themselves
32
 
33
# Return the contents of the filename given
34
proc file_contents { filename } {
35
    set file [open $filename r]
36
    set contents [read $file]
37
    close $file
38
    return $contents
39
}
40
 
41
# Find out the size by reading the output of the EI_CLASS field.
42
# Similar to the test for readelf -h, but we're just looking for the
43
# EI_CLASS line here.
44
proc readelf_find_size { binary_file } {
45
    global READELF
46
    global READELFFLAGS
47
    global readelf_size
48
 
49
    set readelf_size ""
50
    set testname "finding out ELF size with readelf -h"
51
    set got [remote_exec host "$READELF $READELFFLAGS -h $binary_file" "" "/dev/null" "readelf.out"]
52
    if [is_remote host] then {
53
        remote_upload host "readelf.out"
54
    }
55
 
56
    if { [lindex $got 0] != 0 || ![string match "" [lindex $got 1]]} then {
57
        send_log $got
58
        fail $testname
59
        return
60
    }
61
 
62
    if { ! [regexp "\n\[ \]*Class:\[ \]*ELF(\[0-9\]+)\n" \
63
            [file_contents readelf.out] nil readelf_size] } {
64
        verbose -log "EI_CLASS field not found in output"
65
        verbose -log "output is \n[file_contents readelf.out]"
66
        fail $testname
67
        return
68
    } else {
69
        verbose -log "ELF size is $readelf_size"
70
    }
71
 
72
    pass $testname
73
}
74
 
75
# Run an individual readelf test.
76
# Basically readelf is run on the binary_file with the given options.
77
# Readelf's output is captured and then compared against the contents
78
# of the regexp_file-readelf_size if it exists, else regexp_file.
79
 
80
proc readelf_test { options binary_file regexp_file xfails } {
81
 
82
    global READELF
83
    global READELFFLAGS
84
    global readelf_size
85
    global srcdir
86
    global subdir
87
 
88
    send_log "exec $READELF $READELFFLAGS $options $binary_file > readelf.out\n"
89
    set got [remote_exec host "$READELF $READELFFLAGS $options $binary_file" "" "/dev/null" "readelf.out"]
90
 
91
    foreach xfail $xfails {
92
        setup_xfail $xfail
93
    }
94
 
95
    if { [lindex $got 0] != 0 || ![string match "" [lindex $got 1]] } then {
96
        fail "readelf $options (reason: unexpected output)"
97
        send_log $got
98
        send_log "\n"
99
        return
100
    }
101
 
102
    set target_machine ""
103
    if [istarget "mips*-*-*"] then {
104
        if { [istarget "mips*-*-*linux*"]
105
             || [istarget "mips*-sde-elf*"]
106
             || [istarget "mips*-*freebsd*"] } then {
107
            set target_machine tmips
108
        } else {
109
            set target_machine mips
110
        }
111
    }
112
 
113
    if { $target_machine != "" && [file exists $srcdir/$subdir/$regexp_file-$readelf_size-$target_machine] } then {
114
        set regexp_file $regexp_file-$readelf_size-$target_machine
115
    } elseif { $target_machine != "" && [file exists $srcdir/$subdir/$regexp_file-$target_machine] } then {
116
        set regexp_file $regexp_file-$target_machine
117
    } elseif { [file exists $srcdir/$subdir/$regexp_file-$readelf_size] } then {
118
        set regexp_file $regexp_file-$readelf_size
119
    }
120
 
121
    if { [regexp_diff readelf.out $srcdir/$subdir/$regexp_file] } then {
122
        fail "readelf $options"
123
        verbose "output is \n[file_contents readelf.out]" 2
124
        return
125
    }
126
 
127
    pass "readelf $options"
128
}
129
 
130
# Simple proc to skip certain expected warning messages.
131
 
132
proc prune_readelf_wi_warnings { text } {
133
    regsub -all "(^|\n)(.*Skipping unexpected symbol type.*)" $text "\\1" text
134
    return $text
135
}
136
 
137
# Testing the "readelf -wi" option is difficult because there
138
# is no guaranteed order to the output, and because some ports
139
# will use indirect string references, whilst others will use
140
# direct references.  So instead of having an expected output
141
# file, like the other readelf tests, we grep for strings that
142
# really ought to be there.
143
 
144
proc readelf_wi_test {} {
145
    global READELF
146
    global READELFFLAGS
147
    global srcdir
148
    global subdir
149
 
150
    # Compile the second test file.
151
    if { [target_compile $srcdir/$subdir/testprog.c tmpdir/testprog.o object debug] != "" } {
152
        verbose "Unable to compile test file."
153
        untested "readelf -wi"
154
        return
155
    }
156
 
157
    # Download it.
158
    set tempfile [remote_download host tmpdir/testprog.o]
159
 
160
    # Run "readelf -wi" on it.
161
    set got [remote_exec host "$READELF $READELFFLAGS -wi $tempfile" "" "/dev/null" "readelf.out"]
162
 
163
    # Upload the results.
164
    set output [remote_upload host readelf.out]
165
 
166
    file_on_host delete $tempfile
167
 
168
    # Strip any superflous warnings.
169
    set got [prune_readelf_wi_warnings [lindex $got 1]]
170
 
171
    if ![string match "" $got] then {
172
        fail "readelf $READELFFLAGS -wi (reason: unexpected output)"
173
        send_log $got
174
        send_log "\n"
175
        return
176
    }
177
 
178
    if ![file size $output] then {
179
        # If the output file is empty, then this target does not
180
        # generate dwarf2 output.  This is not a failure.
181
        verbose "No output from 'readelf -wi'"
182
        untested "readelf -wi"
183
        return
184
    }
185
 
186
    # Search for strings that should be in the output.
187
    set sought {
188
        ".*DW_TAG_compile_unit.*"
189
        ".*DW_TAG_subprogram.*"
190
        ".*DW_TAG_base_type.*"
191
        ".*DW_AT_producer.*(GNU C|indirect string).*"
192
        ".*DW_AT_language.*ANSI C.*"
193
        ".*DW_AT_name.*(testprog.c|indirect string).*"
194
        ".*DW_AT_name.*fn.*"
195
        ".*DW_AT_name.*(main|indirect string).*"
196
        ".*\(DW_OP_addr: 0\).*"
197
    }
198
 
199
    foreach looked_for $sought {
200
        set lines [grep $output $looked_for]
201
        if ![llength $lines] then {
202
            fail "readelf -wi: missing: $looked_for"
203
            send_log readelf.out
204
            return
205
        }
206
    }
207
 
208
    file_on_host delete $output
209
 
210
    # All done.
211
    pass "readelf -wi"
212
}
213
 
214
# This tests "readelf -wa", but on a file with a compressed
215
# .debug_abbrev section.
216
 
217
proc readelf_compressed_wa_test {} {
218
    global READELF
219
    global READELFFLAGS
220
    global srcdir
221
    global subdir
222
 
223
    # Compile the compressed-debug-section test file.
224
    if { [target_compile $srcdir/$subdir/dw2-compressed.S tmpdir/dw2-compressed.o object debug] != "" } {
225
        verbose "Unable to compile test file."
226
        untested "readelf -wa (compressed)"
227
        return
228
    }
229
 
230
    # Download it.
231
    set tempfile [remote_download host tmpdir/dw2-compressed.o]
232
 
233
    # Run "readelf -wa" on it.
234
    set got [remote_exec host "$READELF $READELFFLAGS -wa $tempfile" "" "/dev/null" "readelf.out"]
235
 
236
    # Upload the results.
237
    set output [remote_upload host readelf.out]
238
 
239
    file_on_host delete $tempfile
240
 
241
    if { [string compare [file_contents readelf.out] [file_contents $srcdir/$subdir/readelf.wa]] != 0 } then {
242
        fail "readelf -wa (compressed)"
243
        verbose "output is \n[file_contents readelf.out]" 2
244
        verbose "expected is \n[file_contents $srcdir/$subdir/readelf.wa]" 2
245
        return
246
    }
247
 
248
    pass "readelf -wa (compressed)"
249
}
250
 
251
# Test readelf's dumping abilities.
252
 
253
proc readelf_dump_test {} {
254
    global READELF
255
    global READELFFLAGS
256
    global srcdir
257
    global subdir
258
 
259
    # Assemble the dump test file.
260
    if {![binutils_assemble $srcdir/$subdir/dumptest.s tmpdir/dumptest.o]} then {
261
      unresolved "readelf -p: failed to assemble dump test file"
262
      return
263
    }
264
    # Download it.
265
    set tempfile [remote_download host tmpdir/dumptest.o]
266
 
267
    # Run "readelf -p.data" on it.
268
    set got [remote_exec host "$READELF $READELFFLAGS -p.data $tempfile" "" "/dev/null" "readelf.out"]
269
    set got [lindex $got 1]
270
 
271
    # Upload the results.
272
    set output [remote_upload host readelf.out]
273
 
274
    # Check for something going wrong.
275
    if ![string match "" $got] then {
276
        fail "readelf -p: unexpected output"
277
        send_log $got
278
        send_log "\n"
279
        return
280
    }
281
 
282
    # Search for strings that should be in the output.
283
    set sought {
284
        ".*test_string.*"
285
    }
286
 
287
    foreach looked_for $sought {
288
        set lines [grep $output $looked_for]
289
        if ![llength $lines] then {
290
            fail "readelf -p: missing: $looked_for"
291
            send_log readelf.out
292
            return
293
        }
294
    }
295
 
296
    file_on_host delete $tempfile
297
    file_on_host delete $output
298
 
299
    # All done.
300
    pass "readelf -p"
301
 
302
    # XXX FIXME: Add test of readelf -x here
303
}
304
 
305
if ![is_remote host] {
306
    if {[which $READELF] == 0} then {
307
        perror "$READELF does not exist"
308
        return
309
    }
310
}
311
 
312
send_user "Version [binutil_version $READELF]"
313
 
314
# Assemble the test file.
315
if {![binutils_assemble $srcdir/$subdir/bintest.s tmpdir/bintest.o]} then {
316
    perror "could not assemble test file"
317
    unresolved "readelf - failed to assemble"
318
    return
319
}
320
 
321
if ![is_remote host] {
322
    set tempfile tmpdir/bintest.o
323
} else {
324
    set tempfile [remote_download host tmpdir/bintest.o]
325
}
326
 
327
# First, determine the size, so specific output matchers can be used.
328
readelf_find_size $tempfile
329
 
330
# Run the tests.
331
readelf_test -h $tempfile readelf.h  {}
332
readelf_test -S $tempfile readelf.s  {}
333
readelf_test -s $tempfile readelf.ss {}
334
readelf_test -r $tempfile readelf.r  {}
335
 
336
readelf_wi_test
337
readelf_compressed_wa_test
338
 
339
readelf_dump_test

powered by: WebSVN 2.1.0

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