]> git.ipfire.org Git - thirdparty/binutils-gdb.git/blob - binutils/testsuite/binutils-all/readelf.exp
* config/sh/tm-sh.h (BELIEVE_PCC_PROMOTION): Define, so that
[thirdparty/binutils-gdb.git] / binutils / testsuite / binutils-all / readelf.exp
1 # Copyright (C) 1999 Free Software Foundation, Inc.
2
3 # This program is free software; you can redistribute it and/or modify
4 # it under the terms of the GNU General Public License as published by
5 # the Free Software Foundation; either version 2 of the License, or
6 # (at your option) any later version.
7 #
8 # This program is distributed in the hope that it will be useful,
9 # but WITHOUT ANY WARRANTY; without even the implied warranty of
10 # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
11 # GNU General Public License for more details.
12 #
13 # You should have received a copy of the GNU General Public License
14 # along with this program; if not, write to the Free Software
15 # Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
16
17 # Please email any bugs, comments, and/or additions to this file to:
18 # bug-dejagnu@prep.ai.mit.edu
19
20 # Written by Nick Clifto <nickc@cygnus.com>
21 # Based on scripts written by Ian Lance Taylor <ian@cygnus.com>
22 # and Ken Raeburn <raeburn@cygnus.com>.
23
24 # First some helpful procedures, then the tests themselves
25
26 # Return the contents of the filename given
27 proc file_contents { filename } {
28 set file [open $filename r]
29 set contents [read $file]
30 close $file
31 return $contents
32 }
33
34 # regexp_diff, based on simple_diff taken from ld test suite
35 # compares two files line-by-line
36 # file1 contains strings, file2 contains regexps and #-comments
37 # blank lines are ignored in either file
38 # returns non-zero if differences exist
39 #
40 proc regexp_diff { file_1 file_2 } {
41
42 set eof -1
43 set end_1 0
44 set end_2 0
45 set differences 0
46 set diff_pass 0
47
48 if [file exists $file_1] then {
49 set file_a [open $file_1 r]
50 } else {
51 warning "$file_1 doesn't exist"
52 return 1
53 }
54
55 if [file exists $file_2] then {
56 set file_b [open $file_2 r]
57 } else {
58 fail "$file_2 doesn't exist"
59 close $file_a
60 return 1
61 }
62
63 verbose " Regexp-diff'ing: $file_1 $file_2" 2
64
65 while { 1 } {
66 set line_a ""
67 set line_b ""
68 while { [string length $line_a] == 0 } {
69 if { [gets $file_a line_a] == $eof } {
70 set end_1 1
71 break
72 }
73 }
74 while { [string length $line_b] == 0 || [string match "#*" $line_b] } {
75 if [ string match "#pass" $line_b ] {
76 set end_2 1
77 set diff_pass 1
78 break
79 }
80 if { [gets $file_b line_b] == $eof } {
81 set end_2 1
82 break
83 }
84 }
85
86 if { $diff_pass } {
87 break
88 } elseif { $end_1 && $end_2 } {
89 break
90 } elseif { $end_1 } {
91 send_log "extra regexps in $file_2 starting with \"^$line_b$\"\nEOF from $file_1\n"
92 verbose "extra regexps in $file_2 starting with \"^$line_b$\"\nEOF from $file_1" 3
93 set differences 1
94 break
95 } elseif { $end_2 } {
96 send_log "extra lines in $file_1 starting with \"^$line_a$\"\nEOF from $file_2\n"
97 verbose "extra lines in $file_1 starting with \"^$line_a$\"\nEOF from $file_2\n" 3
98 set differences 1
99 break
100 } else {
101 verbose "regexp \"^$line_b$\"\nline \"$line_a\"" 3
102 if ![regexp "^$line_b$" "$line_a"] {
103 send_log "regexp_diff match failure\n"
104 send_log "regexp \"^$line_b$\"\nline \"$line_a\"\n"
105 set differences 1
106 break
107 }
108 }
109 }
110
111 if { $differences == 0 && !$diff_pass && [eof $file_a] != [eof $file_b] } {
112 send_log "$file_1 and $file_2 are different lengths\n"
113 verbose "$file_1 and $file_2 are different lengths" 3
114 set differences 1
115 }
116
117 close $file_a
118 close $file_b
119
120 return $differences
121 }
122
123 # Run an individual readelf test.
124 # Basically readelf is run on the binary_file with the given options.
125 # Readelf's output is captured and then compared against the contents
126 # of the regexp_file.
127
128 proc readelf_test { options binary_file regexp_file xfails } {
129
130 global READELF
131 global READELFFLAGS
132
133 send_log "exec $READELF $READELFFLAGS $options $binary_file > readelf.out"
134 catch "exec $READELF $READELFFLAGS $options $binary_file > readelf.out" got
135
136 if { [llength $xfails] != 0 } then {
137 setup_xfail $xfails
138 }
139
140 if ![string match "" $got] then {
141 send_log $got
142 fail "readelf $options"
143 return
144 }
145
146 if { [regexp_diff readelf.out $regexp_file] } then {
147 fail "readelf $options"
148 verbose "output is \n[file_contents readelf.out]" 2
149 return
150 }
151
152 pass "readelf $options"
153 }
154
155
156
157 # COFF and PE based toolchain cannot possibly be expected to work.
158 if [istarget "*-*coff"] then {
159 verbose "$READELF is not intenteded for COFF targets" 2
160 return
161 }
162
163 if [istarget "*-*pe"] then {
164 verbose "$READELF is not intenteded for PE targets" 2
165 return
166 }
167
168 if ![is_remote host] {
169 if {[which $READELF] == 0} then {
170 perror "$READELF does not exist"
171 return
172 }
173 }
174
175 send_user "Version [binutil_version $READELF]"
176
177 # Assemle the test file.
178 if {![binutils_assemble $srcdir/$subdir/bintest.s tmpdir/bintest.o]} then {
179 perror "unresolved 1"
180 unresolved "readelf - failed to assemble"
181 return
182 }
183
184 if ![is_remote host] {
185 set tempfile tmpdir/bintest.o;
186 } else {
187 set tempfile [remote_download host tmpdir/bintest.o]
188 }
189
190 # Run the tests
191 readelf_test -h $tempfile $srcdir/$subdir/readelf.h {}
192 # The v850 fails the next two tests because it creates two special
193 # sections of its own: .call_table_data and .call_table_text
194 # The regexp scripts are not expecting these sections...
195 readelf_test -S $tempfile $srcdir/$subdir/readelf.s {v850*-*}
196 readelf_test -s $tempfile $srcdir/$subdir/readelf.ss {v850*-*}
197 readelf_test -r $tempfile $srcdir/$subdir/readelf.r {}