Add tests of readelf.
This commit is contained in:
parent
7c5c8a5e46
commit
5cee067a58
@ -1,3 +1,28 @@
|
||||
1999-01-29 Nick Clifton <nickc@cygnus.com>
|
||||
|
||||
* config/default.exp: Add definitions of READELF and READELFFLAGS.
|
||||
|
||||
* binutils-all/readelf.exp: New file: Readelf tests
|
||||
* binutils-all/readelf.h: New file: Expected results for 'readelf -h'
|
||||
* binutils-all/readelf.s: New file: Expected results for 'readelf -S'
|
||||
* binutils-all/readelf.ss: New file: Expected results for 'readelf -s'
|
||||
* binutils-all/readelf.r: New file: Expected results for 'readelf -r'
|
||||
|
||||
Wed Dec 9 19:11:39 1998 Jeffrey A Law (law@cygnus.com)
|
||||
|
||||
* binutils-all/objcopy.exp (copy_executable): Expect comparison
|
||||
failure for mips*-*-elf.
|
||||
|
||||
Fri Oct 16 22:57:12 1998 Felix Lee <flee@cygnus.com>
|
||||
|
||||
* binutils-all/objcopy.exp: fix "no symbols" message.
|
||||
|
||||
Tue Jul 28 15:14:04 1998 Jeffrey A Law (law@cygnus.com)
|
||||
|
||||
* binutils-all/objcopy.exp: Keep "main" and "_main" for strip with
|
||||
saving symbol tests. Look for either "main" or "_main" in the output
|
||||
file. Fix test for "no symbols" in the output file.
|
||||
|
||||
1998-07-22 Vladimir N. Makarov <vmakarov@cygnus.com>
|
||||
|
||||
* binutils-all/objcopy.exp: Polish output about fail for objcopy
|
||||
|
190
binutils/testsuite/binutils-all/readelf.exp
Normal file
190
binutils/testsuite/binutils-all/readelf.exp
Normal file
@ -0,0 +1,190 @@
|
||||
# Copyright (C) 1999 Free Software Foundation, Inc.
|
||||
|
||||
# This program is free software; you can redistribute it and/or modify
|
||||
# it under the terms of the GNU General Public License as published by
|
||||
# the Free Software Foundation; either version 2 of the License, or
|
||||
# (at your option) any later version.
|
||||
#
|
||||
# This program is distributed in the hope that it will be useful,
|
||||
# but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||
# GNU General Public License for more details.
|
||||
#
|
||||
# You should have received a copy of the GNU General Public License
|
||||
# along with this program; if not, write to the Free Software
|
||||
# Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
|
||||
|
||||
# Please email any bugs, comments, and/or additions to this file to:
|
||||
# bug-dejagnu@prep.ai.mit.edu
|
||||
|
||||
# Written by Nick Clifto <nickc@cygnus.com>
|
||||
# Based on scripts written by Ian Lance Taylor <ian@cygnus.com>
|
||||
# and Ken Raeburn <raeburn@cygnus.com>.
|
||||
|
||||
# First some helpful procedures, then the tests themselves
|
||||
|
||||
# Return the contents of the filename given
|
||||
proc file_contents { filename } {
|
||||
set file [open $filename r]
|
||||
set contents [read $file]
|
||||
close $file
|
||||
return $contents
|
||||
}
|
||||
|
||||
# regexp_diff, based on simple_diff taken from ld test suite
|
||||
# compares two files line-by-line
|
||||
# file1 contains strings, file2 contains regexps and #-comments
|
||||
# blank lines are ignored in either file
|
||||
# returns non-zero if differences exist
|
||||
#
|
||||
proc regexp_diff { file_1 file_2 } {
|
||||
|
||||
set eof -1
|
||||
set end_1 0
|
||||
set end_2 0
|
||||
set differences 0
|
||||
set diff_pass 0
|
||||
|
||||
if [file exists $file_1] then {
|
||||
set file_a [open $file_1 r]
|
||||
} else {
|
||||
warning "$file_1 doesn't exist"
|
||||
return 1
|
||||
}
|
||||
|
||||
if [file exists $file_2] then {
|
||||
set file_b [open $file_2 r]
|
||||
} else {
|
||||
fail "$file_2 doesn't exist"
|
||||
close $file_a
|
||||
return 1
|
||||
}
|
||||
|
||||
verbose " Regexp-diff'ing: $file_1 $file_2" 2
|
||||
|
||||
while { 1 } {
|
||||
set line_a ""
|
||||
set line_b ""
|
||||
while { [string length $line_a] == 0 } {
|
||||
if { [gets $file_a line_a] == $eof } {
|
||||
set end_1 1
|
||||
break
|
||||
}
|
||||
}
|
||||
while { [string length $line_b] == 0 || [string match "#*" $line_b] } {
|
||||
if [ string match "#pass" $line_b ] {
|
||||
set end_2 1
|
||||
set diff_pass 1
|
||||
break
|
||||
}
|
||||
if { [gets $file_b line_b] == $eof } {
|
||||
set end_2 1
|
||||
break
|
||||
}
|
||||
}
|
||||
|
||||
if { $diff_pass } {
|
||||
break
|
||||
} elseif { $end_1 && $end_2 } {
|
||||
break
|
||||
} elseif { $end_1 } {
|
||||
send_log "extra regexps in $file_2 starting with \"^$line_b$\"\nEOF from $file_1\n"
|
||||
verbose "extra regexps in $file_2 starting with \"^$line_b$\"\nEOF from $file_1" 3
|
||||
set differences 1
|
||||
break
|
||||
} elseif { $end_2 } {
|
||||
send_log "extra lines in $file_1 starting with \"^$line_a$\"\nEOF from $file_2\n"
|
||||
verbose "extra lines in $file_1 starting with \"^$line_a$\"\nEOF from $file_2\n" 3
|
||||
set differences 1
|
||||
break
|
||||
} else {
|
||||
verbose "regexp \"^$line_b$\"\nline \"$line_a\"" 3
|
||||
if ![regexp "^$line_b$" "$line_a"] {
|
||||
send_log "regexp_diff match failure\n"
|
||||
send_log "regexp \"^$line_b$\"\nline \"$line_a\"\n"
|
||||
set differences 1
|
||||
break
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
if { $differences == 0 && !$diff_pass && [eof $file_a] != [eof $file_b] } {
|
||||
send_log "$file_1 and $file_2 are different lengths\n"
|
||||
verbose "$file_1 and $file_2 are different lengths" 3
|
||||
set differences 1
|
||||
}
|
||||
|
||||
close $file_a
|
||||
close $file_b
|
||||
|
||||
return $differences
|
||||
}
|
||||
|
||||
# Run an individual readelf test.
|
||||
# Basically readelf is run on the binary_file with the given options.
|
||||
# Readelf's output is captured and then compared against the contents
|
||||
# of the regexp_file.
|
||||
|
||||
proc readelf_test { options binary_file regexp_file } {
|
||||
|
||||
global READELF
|
||||
global READELFFLAGS
|
||||
|
||||
send_log "exec $READELF $READELFFLAGS $options $binary_file > readelf.out"
|
||||
catch "exec $READELF $READELFFLAGS $options $binary_file > readelf.out" got
|
||||
|
||||
if ![string match "" $got] then {
|
||||
send_log $got
|
||||
fail "readelf $options"
|
||||
return
|
||||
}
|
||||
|
||||
if { [regexp_diff readelf.out $regexp_file] } then {
|
||||
fail "readelf $options"
|
||||
verbose "output is \n[file_contents readelf.out]" 2
|
||||
return
|
||||
}
|
||||
|
||||
pass "readelf $options"
|
||||
}
|
||||
|
||||
|
||||
|
||||
# COFF and PE based toolchain cannot possibly be expected to work.
|
||||
if [istarget "*-*coff"] then {
|
||||
verbose "$READELF is not intenteded for COFF targets" 2
|
||||
return
|
||||
}
|
||||
|
||||
if [istarget "*-*pe"] then {
|
||||
verbose "$READELF is not intenteded for PE targets" 2
|
||||
return
|
||||
}
|
||||
|
||||
if ![is_remote host] {
|
||||
if {[which $READELF] == 0} then {
|
||||
perror "$READELF does not exist"
|
||||
return
|
||||
}
|
||||
}
|
||||
|
||||
send_user "Version [binutil_version $READELF]"
|
||||
|
||||
# Assemle the test file.
|
||||
if {![binutils_assemble $srcdir/$subdir/bintest.s tmpdir/bintest.o]} then {
|
||||
perror "unresolved 1"
|
||||
unresolved "readelf - failed to assemble"
|
||||
return
|
||||
}
|
||||
|
||||
if ![is_remote host] {
|
||||
set tempfile tmpdir/bintest.o;
|
||||
} else {
|
||||
set tempfile [remote_download host tmpdir/bintest.o]
|
||||
}
|
||||
|
||||
# Run the tests
|
||||
readelf_test -h $tempfile $srcdir/$subdir/readelf.h
|
||||
readelf_test -S $tempfile $srcdir/$subdir/readelf.s
|
||||
readelf_test -s $tempfile $srcdir/$subdir/readelf.ss
|
||||
readelf_test -r $tempfile $srcdir/$subdir/readelf.r
|
16
binutils/testsuite/binutils-all/readelf.h
Normal file
16
binutils/testsuite/binutils-all/readelf.h
Normal file
@ -0,0 +1,16 @@
|
||||
ELF Header:
|
||||
Magic: 7f 45 4c 46 0[12] 0[12] 01 00 00 00 00 00 00 00 00 00
|
||||
Type: REL \(Relocatable file\)
|
||||
Machine: .*
|
||||
Version: 0x1
|
||||
Data: ELFDATA.* endian\)
|
||||
Entry point address: 0x0
|
||||
Start of program headers: 0 \(bytes into file\)
|
||||
Start of section headers: .* \(bytes into file\)
|
||||
Flags: .*
|
||||
Size of this header: .* \(bytes\)
|
||||
Size of program headers: 0 \(bytes\)
|
||||
Number of program headers: 0
|
||||
Size of section headers: .* \(bytes\)
|
||||
Number of section headers: 8
|
||||
Section header string table index: 5
|
4
binutils/testsuite/binutils-all/readelf.r
Normal file
4
binutils/testsuite/binutils-all/readelf.r
Normal file
@ -0,0 +1,4 @@
|
||||
|
||||
Relocation section '.rel..text' at offset 0x2b8 contains 1 entries:
|
||||
Offset Info Type Symbol's Value Symbol's Name Addend
|
||||
00000004 00.* R_.* 00000000 external_symbol \+ 0
|
13
binutils/testsuite/binutils-all/readelf.s
Normal file
13
binutils/testsuite/binutils-all/readelf.s
Normal file
@ -0,0 +1,13 @@
|
||||
There are 8 section headers, starting at offset 78:
|
||||
|
||||
Section Headers:
|
||||
\[Nr\] Name Type Addr Off Size ES Flg Lk Inf Al
|
||||
\[ 0\] NULL 00000000 000000 000000 00 0 0 0
|
||||
\[ 1\] .text PROGBITS 00000000 000034 000008 00 AX 0 0 1
|
||||
\[ 2\] .rela.text RELA 00000000 0002b8 00000c 0c 6 1 4
|
||||
\[ 3\] .data PROGBITS 00000000 00003c 000004 00 WA 0 0 1
|
||||
\[ 4\] .bss NOBITS 00000000 000040 000000 00 WA 0 0 1
|
||||
\[ 5\] .shstrtab STRTAB 00000000 000040 000037 00 0 0 1
|
||||
\[ 6\] .symtab SYMTAB 00000000 0001b8 0000a0 10 7 6 4
|
||||
\[ 7\] .strtab STRTAB 00000000 000258 00005d 00 0 0 1
|
||||
|
13
binutils/testsuite/binutils-all/readelf.ss
Normal file
13
binutils/testsuite/binutils-all/readelf.ss
Normal file
@ -0,0 +1,13 @@
|
||||
|
||||
Symbol table '.symtab' contains 10 entries:
|
||||
Num: Value Size Type Bind Ot Ndx Name
|
||||
0: 0 0 NOTYPE LOCAL 0 UND
|
||||
1: 0 0 SECTION LOCAL 0 1
|
||||
2: 0 0 SECTION LOCAL 0 3
|
||||
3: 0 0 SECTION LOCAL 0 4
|
||||
4: 0 0 NOTYPE LOCAL 0 1 static_text_symbol
|
||||
5: 0 0 NOTYPE LOCAL 0 3 static_data_symbol
|
||||
6: 0 0 NOTYPE GLOBAL 0 1 text_symbol
|
||||
7: 0 0 NOTYPE GLOBAL 0 UND external_symbol
|
||||
8: 0 0 NOTYPE GLOBAL 0 3 data_symbol
|
||||
9: 4 4 OBJECT GLOBAL 0 COM common_symbol
|
Loading…
Reference in New Issue
Block a user