# 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 # Based on scripts written by Ian Lance Taylor # and Ken Raeburn . # 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 xfails } { global READELF global READELFFLAGS global srcdir global subdir send_log "exec $READELF $READELFFLAGS $options $binary_file > readelf.out" catch "exec $READELF $READELFFLAGS $options $binary_file > readelf.out" got if { [llength $xfails] != 0 } then { setup_xfail $xfails } if ![string match "" $got] then { send_log $got fail "readelf $options" return } 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" } # 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 { verbose "$READELF is only intenteded for ELF 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 readelf.h {} # The v850 fails the next two tests because it creates two special # sections of its own: .call_table_data and .call_table_text # The regexp scripts are not expecting these sections... readelf_test -S $tempfile readelf.s {v850*-*-*} readelf_test -s $tempfile readelf.ss {v850*-*-*} 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*-*-*}