Rework readelf -wi tests to grep for expected strings.
[deliverable/binutils-gdb.git] / binutils / testsuite / binutils-all / readelf.exp
index 1123df4cb45c1cb22697f1121ee8bd03b9f2b320..5dff61930a4618ce8926218a6690acfa8780782e 100644 (file)
@@ -183,16 +183,21 @@ proc readelf_test { options binary_file regexp_file xfails } {
     foreach xfail $xfails {
        setup_xfail $xfail
     }
-    
+
     if ![string match "" $got] then {
+       fail "readelf $options (reason: unexpected output)"
        send_log $got
-       fail "readelf $options"
+       send_log "\n"
        return
     }
 
     set target_machine ""
     if [istarget "mips*-*-*"] then {
-      set target_machine mips
+       if { [istarget "mips*-*-*linux*"] } then {
+           set target_machine tmips
+       } else {
+           set target_machine mips
+       }
     }
 
     if { $target_machine != "" && [file exists $srcdir/$subdir/$regexp_file-$readelf_size-$target_machine] } then {
@@ -212,13 +217,110 @@ 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
+}
+
+# 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.
+    set tempfile [remote_download host tmpdir/testprog.o];
+
+    # 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.
+    set output [remote_upload host readelf.out];
+
+    file_on_host delete $tempfile;
+    
+    # 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).*"
+    }
+    
+    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"
+}
 
 
 # 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.
 
-if ![istarget "*-*elf"] then {
+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
+}
+
+if { [istarget *-*-linux*oldld*] \
+     || [istarget *-*-linux*aout*] } {
     verbose "$READELF is only intended for ELF targets" 2
     return
 }
@@ -232,7 +334,7 @@ if ![is_remote host] {
 
 send_user "Version [binutil_version $READELF]"
 
-# Assemle the test file.
+# Assemble the test file.
 if {![binutils_assemble $srcdir/$subdir/bintest.s tmpdir/bintest.o]} then {
     perror "unresolved 1"
     unresolved "readelf - failed to assemble"
@@ -254,20 +356,4 @@ readelf_test -S $tempfile readelf.s  {}
 readelf_test -s $tempfile readelf.ss {}
 readelf_test -r $tempfile readelf.r  {}
 
-
-# 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-*-*}
+readelf_wi_test
This page took 0.042158 seconds and 4 git commands to generate.