This commit was manufactured by cvs2svn to create branch 'binutils-
[external/binutils.git] / binutils / testsuite / binutils-all / readelf.exp
index d8ba1c0..e611cb2 100644 (file)
@@ -1,4 +1,5 @@
-#   Copyright 1999, 2000, 2001, 2003, 2004, 2007 Free Software Foundation, Inc.
+#   Copyright 1999, 2000, 2001, 2003, 2004, 2007, 2009, 2012
+#   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
 # Based on scripts written by Ian Lance Taylor <ian@cygnus.com>
 # and Ken Raeburn <raeburn@cygnus.com>.
 
+# 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
@@ -94,7 +101,9 @@ proc readelf_test { options binary_file regexp_file xfails } {
 
     set target_machine ""
     if [istarget "mips*-*-*"] then {
-       if { [istarget "mips*-*-*linux*"] || [istarget "mips*-sde-elf*"] } then {
+       if { [istarget "mips*-*-*linux*"]
+            || [istarget "mips*-sde-elf*"]
+            || [istarget "mips*-*freebsd*"] } then {
            set target_machine tmips
        } else {
            set target_machine mips
@@ -202,11 +211,95 @@ proc readelf_wi_test {} {
     pass "readelf -wi"
 }
 
+# This tests "readelf -wa", but on a file with a compressed
+# .debug_abbrev section.
 
-# Exclude non-ELF targets.
-if ![is_elf_format] {
-    verbose "$READELF is only intended for ELF targets" 2
-    return
+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] {
@@ -220,7 +313,7 @@ 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
 }
@@ -241,3 +334,21 @@ readelf_test -s $tempfile readelf.ss {}
 readelf_test -r $tempfile readelf.r  {}
 
 readelf_wi_test
+readelf_compressed_wa_test
+
+readelf_dump_test
+
+# PR 13482 - Check for off-by-one errors when dumping .note sections.
+if {![binutils_assemble $srcdir/$subdir/version.s tmpdir/version.o]} then {
+    perror "could not assemble version note test file"
+    unresolved "readelf - failed to assemble"
+    return
+}
+
+if ![is_remote host] {
+    set tempfile tmpdir/version.o
+} else {
+    set tempfile [remote_download host tmpdir/version.o]
+}
+
+readelf_test -n $tempfile readelf.n  {}