X-Git-Url: http://drtracing.org/?a=blobdiff_plain;f=binutils%2Ftestsuite%2Fbinutils-all%2Freadelf.exp;h=c879af736cd9e023b0d06187ecb138d43c1de2de;hb=1b315056928c75e989b6a0fa858577141da5cc4f;hp=059955d01c7821ac78b2a9a7e658267c7dd7dca1;hpb=86651999acf60eb76a233cc1445fe978885f2006;p=deliverable%2Fbinutils-gdb.git diff --git a/binutils/testsuite/binutils-all/readelf.exp b/binutils/testsuite/binutils-all/readelf.exp index 059955d01c..c879af736c 100644 --- a/binutils/testsuite/binutils-all/readelf.exp +++ b/binutils/testsuite/binutils-all/readelf.exp @@ -1,8 +1,8 @@ -# Copyright 1999, 2000 Free Software Foundation, Inc. +# Copyright 1999, 2000, 2001, 2003, 2004, 2007 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 +# the Free Software Foundation; either version 3 of the License, or # (at your option) any later version. # # This program is distributed in the hope that it will be useful, @@ -12,7 +12,7 @@ # # 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. +# Foundation, Inc., 51 Franklin Street - Fifth Floor, Boston, MA 02110-1301, USA. # Please email any bugs, comments, and/or additions to this file to: # bug-dejagnu@prep.ai.mit.edu @@ -21,6 +21,12 @@ # Based on scripts written by Ian Lance Taylor # and Ken Raeburn . +# Exclude non-ELF targets. +if ![is_elf_format] { + verbose "$READELF is only intended for ELF targets" 2 + return +} + # First some helpful procedures, then the tests themselves # Return the contents of the filename given @@ -31,108 +37,6 @@ proc file_contents { filename } { 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 - } 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 - } - 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 -} - # 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. @@ -143,9 +47,12 @@ proc readelf_find_size { binary_file } { set readelf_size "" set testname "finding out ELF size with readelf -h" - catch "exec $READELF $READELFFLAGS -h $binary_file > readelf.out" got + set got [remote_exec host "$READELF $READELFFLAGS -h $binary_file" "" "/dev/null" "readelf.out"] + if [is_remote host] then { + remote_upload host "readelf.out" + } - if ![string match "" $got] then { + if { [lindex $got 0] != 0 || ![string match "" [lindex $got 1]]} then { send_log $got fail $testname return @@ -178,21 +85,22 @@ proc readelf_test { options binary_file regexp_file xfails } { global subdir send_log "exec $READELF $READELFFLAGS $options $binary_file > readelf.out\n" - catch "exec $READELF $READELFFLAGS $options $binary_file > readelf.out" got + set got [remote_exec host "$READELF $READELFFLAGS $options $binary_file" "" "/dev/null" "readelf.out"] foreach xfail $xfails { setup_xfail $xfail } - - if ![string match "" $got] then { + + if { [lindex $got 0] != 0 || ![string match "" [lindex $got 1]] } then { + fail "readelf $options (reason: unexpected output)" send_log $got - fail "readelf $options" + send_log "\n" return } set target_machine "" if [istarget "mips*-*-*"] then { - if { [istarget "mips*-*-*linux*"] } then { + if { [istarget "mips*-*-*linux*"] || [istarget "mips*-sde-elf*"] } then { set target_machine tmips } else { set target_machine mips @@ -216,29 +124,179 @@ proc readelf_test { options binary_file regexp_file xfails } { pass "readelf $options" } +# 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 +} -# Only ELF based toolchains need readelf. -# For now be paranoid and assume that if ELF is not mentioned -# in the target string, then the target is not an ELF based port. +# 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. -if { ![istarget *-*-elf*] \ - && ![istarget *-*-linux*] \ - && ![istarget i?86-*-sysv4*] \ - && ![istarget i?86-*-unixware] \ - && ![istarget mips*-*-irix5*] \ - && ![istarget mips*-*-irix6*] \ - && ![istarget powerpc-*-sysv4*] \ - && ![istarget powerpc-*-eabi*] \ - && ![istarget sparc*-*-solaris2*] } { - verbose "$READELF is only intended for ELF targets" 2 - return +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. + set tempfile [remote_download host tmpdir/testprog.o] + + # Run "readelf -wi" on it. + set got [remote_exec host "$READELF $READELFFLAGS -wi $tempfile" "" "/dev/null" "readelf.out"] + + # Upload the results. + set output [remote_upload host readelf.out] + + file_on_host delete $tempfile + + # Strip any superflous warnings. + set got [prune_readelf_wi_warnings [lindex $got 1]] + + if ![string match "" $got] then { + fail "readelf $READELFFLAGS -wi (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).*" + ".*\(DW_OP_addr: 0\).*" + } + + 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 + } + } + + file_on_host delete $output + + # All done. + pass "readelf -wi" } -if { [istarget *-*-linux*oldld*] \ - || [istarget *-*-linux*aout*] } { - verbose "$READELF is only intended for ELF targets" 2 - return +# This tests "readelf -wa", but on a file with a compressed +# .debug_abbrev section. + +proc readelf_compressed_wa_test {} { + global READELF + global READELFFLAGS + global srcdir + global subdir + + # Compile the compressed-debug-section test file. + if { [target_compile $srcdir/$subdir/dw2-compressed.S tmpdir/dw2-compressed.o object debug] != "" } { + verbose "Unable to compile test file." + untested "readelf -wa (compressed)" + return + } + + # Download it. + set tempfile [remote_download host tmpdir/dw2-compressed.o] + + # Run "readelf -wa" on it. + set got [remote_exec host "$READELF $READELFFLAGS -wa $tempfile" "" "/dev/null" "readelf.out"] + + # Upload the results. + set output [remote_upload host readelf.out] + + file_on_host delete $tempfile + + if { [string compare [file_contents readelf.out] [file_contents $srcdir/$subdir/readelf.wa]] != 0 } then { + fail "readelf -wa (compressed)" + verbose "output is \n[file_contents readelf.out]" 2 + verbose "expected is \n[file_contents $srcdir/$subdir/readelf.wa]" 2 + return + } + + pass "readelf -wa (compressed)" +} + +# Test readelf's dumping abilities. + +proc readelf_dump_test {} { + global READELF + global READELFFLAGS + global srcdir + global subdir + + # Assemble the dump test file. + if {![binutils_assemble $srcdir/$subdir/dumptest.s tmpdir/dumptest.o]} then { + unresolved "readelf -p: failed to assemble dump test file" + return + } + # Download it. + set tempfile [remote_download host tmpdir/dumptest.o] + + # Run "readelf -p.data" on it. + set got [remote_exec host "$READELF $READELFFLAGS -p.data $tempfile" "" "/dev/null" "readelf.out"] + set got [lindex $got 1] + + # Upload the results. + set output [remote_upload host readelf.out] + + # Check for something going wrong. + if ![string match "" $got] then { + fail "readelf -p: unexpected output" + send_log $got + send_log "\n" + return + } + + # Search for strings that should be in the output. + set sought { + ".*test_string.*" + } + + foreach looked_for $sought { + set lines [grep $output $looked_for] + if ![llength $lines] then { + fail "readelf -p: missing: $looked_for" + send_log readelf.out + return + } + } + + file_on_host delete $tempfile + file_on_host delete $output + + # All done. + pass "readelf -p" + + # XXX FIXME: Add test of readelf -x here } if ![is_remote host] { @@ -252,13 +310,13 @@ send_user "Version [binutil_version $READELF]" # Assemble the test file. if {![binutils_assemble $srcdir/$subdir/bintest.s tmpdir/bintest.o]} then { - perror "unresolved 1" + perror "could not assemble test file" unresolved "readelf - failed to assemble" return } if ![is_remote host] { - set tempfile tmpdir/bintest.o; + set tempfile tmpdir/bintest.o } else { set tempfile [remote_download host tmpdir/bintest.o] } @@ -272,20 +330,7 @@ readelf_test -S $tempfile readelf.s {} readelf_test -s $tempfile readelf.ss {} readelf_test -r $tempfile readelf.r {} +readelf_wi_test +readelf_compressed_wa_test -# Compile the second test file. -if { [target_compile $srcdir/$subdir/testprog.c tmpdir/testprog.o object debug] != "" } { - untested "readelf -w" - return -} - -if [is_remote host] { - set tempfile [remote_download host tmpdir/testprog.o]; -} else { - set tempfile tmpdir/testprog.o -} - -# The xfail targets here do not default to DWARF2 format debug information -# The symptom is that the output of 'readelf -wi' is empty. - -readelf_test -wi $tempfile readelf.wi {v850*-*-* cris-*-* mips*-*-elf* *-*-linux* h8300*-*-*} +readelf_dump_test