2005-03-03 11:52:12 +00:00
|
|
|
# Copyright 1999, 2000, 2001, 2003, 2004 Free Software Foundation, Inc.
|
1999-05-03 07:29:11 +00:00
|
|
|
|
|
|
|
# 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
|
2005-05-08 14:17:41 +00:00
|
|
|
# Foundation, Inc., 51 Franklin Street - Fifth Floor, Boston, MA 02110-1301, USA.
|
1999-05-03 07:29:11 +00:00
|
|
|
|
|
|
|
# Please email any bugs, comments, and/or additions to this file to:
|
|
|
|
# bug-dejagnu@prep.ai.mit.edu
|
|
|
|
|
2000-05-02 12:47:19 +00:00
|
|
|
# Written by Nick Clifton <nickc@cygnus.com>
|
1999-05-03 07:29:11 +00:00
|
|
|
# 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
|
2000-11-03 01:59:12 +00:00
|
|
|
} elseif [ string match "#..." $line_b ] {
|
|
|
|
if { [gets $file_b line_b] == $eof } {
|
|
|
|
set end_2 1
|
|
|
|
break
|
|
|
|
}
|
|
|
|
verbose "looking for \"^$line_b$\"" 3
|
|
|
|
while { ![regexp "^$line_b$" "$line_a"] } {
|
|
|
|
verbose "skipping \"$line_a\"" 3
|
|
|
|
if { [gets $file_a line_a] == $eof } {
|
|
|
|
set end_1 1
|
|
|
|
break
|
|
|
|
}
|
|
|
|
}
|
|
|
|
break
|
1999-05-03 07:29:11 +00:00
|
|
|
}
|
|
|
|
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
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
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
|
|
|
|
}
|
|
|
|
|
2000-06-14 01:21:35 +00:00
|
|
|
# Find out the size by reading the output of the EI_CLASS field.
|
|
|
|
# Similar to the test for readelf -h, but we're just looking for the
|
|
|
|
# EI_CLASS line here.
|
|
|
|
proc readelf_find_size { binary_file } {
|
|
|
|
global READELF
|
|
|
|
global READELFFLAGS
|
|
|
|
global readelf_size
|
|
|
|
|
|
|
|
set readelf_size ""
|
|
|
|
set testname "finding out ELF size with readelf -h"
|
|
|
|
catch "exec $READELF $READELFFLAGS -h $binary_file > readelf.out" got
|
|
|
|
|
|
|
|
if ![string match "" $got] then {
|
|
|
|
send_log $got
|
|
|
|
fail $testname
|
|
|
|
return
|
|
|
|
}
|
|
|
|
|
|
|
|
if { ! [regexp "\n\[ \]*Class:\[ \]*ELF(\[0-9\]+)\n" \
|
|
|
|
[file_contents readelf.out] nil readelf_size] } {
|
|
|
|
verbose -log "EI_CLASS field not found in output"
|
|
|
|
verbose -log "output is \n[file_contents readelf.out]"
|
|
|
|
fail $testname
|
|
|
|
return
|
|
|
|
} else {
|
|
|
|
verbose -log "ELF size is $readelf_size"
|
|
|
|
}
|
|
|
|
|
|
|
|
pass $testname
|
|
|
|
}
|
|
|
|
|
1999-05-03 07:29:11 +00:00
|
|
|
# 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
|
2000-06-14 01:21:35 +00:00
|
|
|
# of the regexp_file-readelf_size if it exists, else regexp_file.
|
1999-05-03 07:29:11 +00:00
|
|
|
|
|
|
|
proc readelf_test { options binary_file regexp_file xfails } {
|
|
|
|
|
|
|
|
global READELF
|
|
|
|
global READELFFLAGS
|
2000-06-14 01:21:35 +00:00
|
|
|
global readelf_size
|
1999-05-03 07:29:11 +00:00
|
|
|
global srcdir
|
|
|
|
global subdir
|
|
|
|
|
2000-06-14 01:21:35 +00:00
|
|
|
send_log "exec $READELF $READELFFLAGS $options $binary_file > readelf.out\n"
|
1999-05-03 07:29:11 +00:00
|
|
|
catch "exec $READELF $READELFFLAGS $options $binary_file > readelf.out" got
|
|
|
|
|
2000-10-19 18:04:56 +00:00
|
|
|
foreach xfail $xfails {
|
|
|
|
setup_xfail $xfail
|
1999-05-03 07:29:11 +00:00
|
|
|
}
|
2003-04-23 17:36:08 +00:00
|
|
|
|
1999-05-03 07:29:11 +00:00
|
|
|
if ![string match "" $got] then {
|
2003-04-23 17:36:08 +00:00
|
|
|
fail "readelf $options (reason: unexpected output)"
|
1999-05-03 07:29:11 +00:00
|
|
|
send_log $got
|
2003-04-23 17:36:08 +00:00
|
|
|
send_log "\n"
|
1999-05-03 07:29:11 +00:00
|
|
|
return
|
|
|
|
}
|
|
|
|
|
2000-11-03 01:59:12 +00:00
|
|
|
set target_machine ""
|
|
|
|
if [istarget "mips*-*-*"] then {
|
2001-08-25 00:48:49 +00:00
|
|
|
if { [istarget "mips*-*-*linux*"] } then {
|
2001-05-25 18:58:10 +00:00
|
|
|
set target_machine tmips
|
|
|
|
} else {
|
|
|
|
set target_machine mips
|
|
|
|
}
|
2000-11-03 01:59:12 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
if { $target_machine != "" && [file exists $srcdir/$subdir/$regexp_file-$readelf_size-$target_machine] } then {
|
|
|
|
set regexp_file $regexp_file-$readelf_size-$target_machine
|
|
|
|
} elseif { $target_machine != "" && [file exists $srcdir/$subdir/$regexp_file-$target_machine] } then {
|
|
|
|
set regexp_file $regexp_file-$target_machine
|
|
|
|
} elseif { [file exists $srcdir/$subdir/$regexp_file-$readelf_size] } then {
|
2000-06-14 01:21:35 +00:00
|
|
|
set regexp_file $regexp_file-$readelf_size
|
|
|
|
}
|
|
|
|
|
1999-05-03 07:29:11 +00:00
|
|
|
if { [regexp_diff readelf.out $srcdir/$subdir/$regexp_file] } then {
|
|
|
|
fail "readelf $options"
|
|
|
|
verbose "output is \n[file_contents readelf.out]" 2
|
|
|
|
return
|
|
|
|
}
|
|
|
|
|
|
|
|
pass "readelf $options"
|
|
|
|
}
|
|
|
|
|
2003-04-26 07:53:20 +00:00
|
|
|
# Simple proc to skip certain expected warning messages.
|
|
|
|
|
|
|
|
proc prune_readelf_wi_warnings { text } {
|
|
|
|
regsub -all "(^|\n)(.*Skipping unexpected symbol type.*)" $text "\\1" text
|
|
|
|
return $text
|
|
|
|
}
|
|
|
|
|
|
|
|
# Testing the "readelf -wi" option is difficult because there
|
|
|
|
# is no guaranteed order to the output, and because some ports
|
|
|
|
# will use indirect string references, whilst others will use
|
|
|
|
# direct references. So instead of having an expected output
|
|
|
|
# file, like the other readelf tests, we grep for strings that
|
|
|
|
# really ought to be there.
|
|
|
|
|
|
|
|
proc readelf_wi_test {} {
|
|
|
|
global READELF
|
|
|
|
global READELFFLAGS
|
|
|
|
global srcdir
|
|
|
|
global subdir
|
|
|
|
|
|
|
|
# Compile the second test file.
|
|
|
|
if { [target_compile $srcdir/$subdir/testprog.c tmpdir/testprog.o object debug] != "" } {
|
|
|
|
verbose "Unable to compile test file."
|
|
|
|
untested "readelf -wi"
|
|
|
|
return
|
|
|
|
}
|
|
|
|
|
|
|
|
# Download it.
|
2004-05-12 03:28:46 +00:00
|
|
|
set tempfile [remote_download host tmpdir/testprog.o]
|
2003-04-26 07:53:20 +00:00
|
|
|
|
|
|
|
# Run "readelf -wi" on it.
|
|
|
|
send_log "exec $READELF $READELFFLAGS -wi $tempfile > readelf.out\n"
|
|
|
|
catch "exec $READELF $READELFFLAGS -wi $tempfile > readelf.out" got
|
|
|
|
|
|
|
|
# Upload the results.
|
2004-05-12 03:28:46 +00:00
|
|
|
set output [remote_upload host readelf.out]
|
2003-04-26 07:53:20 +00:00
|
|
|
|
2004-05-12 03:28:46 +00:00
|
|
|
file_on_host delete $tempfile
|
2003-04-26 07:53:20 +00:00
|
|
|
|
|
|
|
# Strip any superflous warnings.
|
|
|
|
set got [prune_readelf_wi_warnings $got]
|
|
|
|
|
|
|
|
if ![string match "" $got] then {
|
|
|
|
fail "readelf $options (reason: unexpected output)"
|
|
|
|
send_log $got
|
|
|
|
send_log "\n"
|
|
|
|
return
|
|
|
|
}
|
|
|
|
|
|
|
|
if ![file size $output] then {
|
|
|
|
# If the output file is empty, then this target does not
|
|
|
|
# generate dwarf2 output. This is not a failure.
|
|
|
|
verbose "No output from 'readelf -wi'"
|
|
|
|
untested "readelf -wi"
|
|
|
|
return
|
|
|
|
}
|
|
|
|
|
|
|
|
# Search for strings that should be in the output.
|
|
|
|
set sought {
|
|
|
|
".*DW_TAG_compile_unit.*"
|
|
|
|
".*DW_TAG_subprogram.*"
|
|
|
|
".*DW_TAG_base_type.*"
|
|
|
|
".*DW_AT_producer.*(GNU C|indirect string).*"
|
|
|
|
".*DW_AT_language.*ANSI C.*"
|
|
|
|
".*DW_AT_name.*(testprog.c|indirect string).*"
|
|
|
|
".*DW_AT_name.*fn.*"
|
|
|
|
".*DW_AT_name.*(main|indirect string).*"
|
2003-04-26 07:57:26 +00:00
|
|
|
".*\(DW_OP_addr: 0\).*"
|
2003-04-26 07:53:20 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
foreach looked_for $sought {
|
|
|
|
set lines [grep $output $looked_for]
|
|
|
|
if ![llength $lines] then {
|
|
|
|
fail "readelf -wi: missing: $looked_for"
|
|
|
|
send_log readelf.out
|
|
|
|
return
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2004-05-12 03:28:46 +00:00
|
|
|
file_on_host delete $output
|
2003-04-26 07:53:20 +00:00
|
|
|
|
|
|
|
# All done.
|
|
|
|
pass "readelf -wi"
|
|
|
|
}
|
1999-05-03 07:29:11 +00:00
|
|
|
|
|
|
|
|
2003-09-30 00:15:54 +00:00
|
|
|
# Exclude non-ELF targets.
|
|
|
|
if ![is_elf_format] {
|
2000-06-14 01:21:35 +00:00
|
|
|
verbose "$READELF is only intended for ELF targets" 2
|
1999-05-03 07:29:11 +00:00
|
|
|
return
|
|
|
|
}
|
|
|
|
|
|
|
|
if ![is_remote host] {
|
|
|
|
if {[which $READELF] == 0} then {
|
|
|
|
perror "$READELF does not exist"
|
|
|
|
return
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
send_user "Version [binutil_version $READELF]"
|
|
|
|
|
2001-06-21 07:44:32 +00:00
|
|
|
# Assemble the test file.
|
1999-05-03 07:29:11 +00:00
|
|
|
if {![binutils_assemble $srcdir/$subdir/bintest.s tmpdir/bintest.o]} then {
|
|
|
|
perror "unresolved 1"
|
|
|
|
unresolved "readelf - failed to assemble"
|
|
|
|
return
|
|
|
|
}
|
|
|
|
|
|
|
|
if ![is_remote host] {
|
2004-05-12 03:28:46 +00:00
|
|
|
set tempfile tmpdir/bintest.o
|
1999-05-03 07:29:11 +00:00
|
|
|
} else {
|
|
|
|
set tempfile [remote_download host tmpdir/bintest.o]
|
|
|
|
}
|
|
|
|
|
2000-06-14 01:21:35 +00:00
|
|
|
# First, determine the size, so specific output matchers can be used.
|
|
|
|
readelf_find_size $tempfile
|
|
|
|
|
|
|
|
# Run the tests.
|
1999-05-03 07:29:11 +00:00
|
|
|
readelf_test -h $tempfile readelf.h {}
|
2000-11-03 01:59:12 +00:00
|
|
|
readelf_test -S $tempfile readelf.s {}
|
|
|
|
readelf_test -s $tempfile readelf.ss {}
|
1999-05-03 07:29:11 +00:00
|
|
|
readelf_test -r $tempfile readelf.r {}
|
|
|
|
|
2003-04-26 07:53:20 +00:00
|
|
|
readelf_wi_test
|