]> git.ipfire.org Git - thirdparty/binutils-gdb.git/blob - binutils/testsuite/binutils-all/readelf.exp
Fix typos
[thirdparty/binutils-gdb.git] / binutils / testsuite / binutils-all / readelf.exp
1 # Copyright 1999, 2000 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 Clifton <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 } elseif [ string match "#..." $line_b ] {
80 if { [gets $file_b line_b] == $eof } {
81 set end_2 1
82 break
83 }
84 verbose "looking for \"^$line_b$\"" 3
85 while { ![regexp "^$line_b$" "$line_a"] } {
86 verbose "skipping \"$line_a\"" 3
87 if { [gets $file_a line_a] == $eof } {
88 set end_1 1
89 break
90 }
91 }
92 break
93 }
94 if { [gets $file_b line_b] == $eof } {
95 set end_2 1
96 break
97 }
98 }
99
100 if { $diff_pass } {
101 break
102 } elseif { $end_1 && $end_2 } {
103 break
104 } elseif { $end_1 } {
105 send_log "extra regexps in $file_2 starting with \"^$line_b$\"\nEOF from $file_1\n"
106 verbose "extra regexps in $file_2 starting with \"^$line_b$\"\nEOF from $file_1" 3
107 set differences 1
108 break
109 } elseif { $end_2 } {
110 send_log "extra lines in $file_1 starting with \"^$line_a$\"\nEOF from $file_2\n"
111 verbose "extra lines in $file_1 starting with \"^$line_a$\"\nEOF from $file_2\n" 3
112 set differences 1
113 break
114 } else {
115 verbose "regexp \"^$line_b$\"\nline \"$line_a\"" 3
116 if ![regexp "^$line_b$" "$line_a"] {
117 send_log "regexp_diff match failure\n"
118 send_log "regexp \"^$line_b$\"\nline \"$line_a\"\n"
119 set differences 1
120 }
121 }
122 }
123
124 if { $differences == 0 && !$diff_pass && [eof $file_a] != [eof $file_b] } {
125 send_log "$file_1 and $file_2 are different lengths\n"
126 verbose "$file_1 and $file_2 are different lengths" 3
127 set differences 1
128 }
129
130 close $file_a
131 close $file_b
132
133 return $differences
134 }
135
136 # Find out the size by reading the output of the EI_CLASS field.
137 # Similar to the test for readelf -h, but we're just looking for the
138 # EI_CLASS line here.
139 proc readelf_find_size { binary_file } {
140 global READELF
141 global READELFFLAGS
142 global readelf_size
143
144 set readelf_size ""
145 set testname "finding out ELF size with readelf -h"
146 catch "exec $READELF $READELFFLAGS -h $binary_file > readelf.out" got
147
148 if ![string match "" $got] then {
149 send_log $got
150 fail $testname
151 return
152 }
153
154 if { ! [regexp "\n\[ \]*Class:\[ \]*ELF(\[0-9\]+)\n" \
155 [file_contents readelf.out] nil readelf_size] } {
156 verbose -log "EI_CLASS field not found in output"
157 verbose -log "output is \n[file_contents readelf.out]"
158 fail $testname
159 return
160 } else {
161 verbose -log "ELF size is $readelf_size"
162 }
163
164 pass $testname
165 }
166
167 # Run an individual readelf test.
168 # Basically readelf is run on the binary_file with the given options.
169 # Readelf's output is captured and then compared against the contents
170 # of the regexp_file-readelf_size if it exists, else regexp_file.
171
172 proc readelf_test { options binary_file regexp_file xfails } {
173
174 global READELF
175 global READELFFLAGS
176 global readelf_size
177 global srcdir
178 global subdir
179
180 send_log "exec $READELF $READELFFLAGS $options $binary_file > readelf.out\n"
181 catch "exec $READELF $READELFFLAGS $options $binary_file > readelf.out" got
182
183 foreach xfail $xfails {
184 setup_xfail $xfail
185 }
186
187 if ![string match "" $got] then {
188 send_log $got
189 fail "readelf $options"
190 return
191 }
192
193 set target_machine ""
194 if [istarget "mips*-*-*"] then {
195 if { [istarget mips*el-*-*] || [istarget "mips*-*-*linux*"] } then {
196 set target_machine tmips
197 } else {
198 set target_machine mips
199 }
200 }
201
202 if { $target_machine != "" && [file exists $srcdir/$subdir/$regexp_file-$readelf_size-$target_machine] } then {
203 set regexp_file $regexp_file-$readelf_size-$target_machine
204 } elseif { $target_machine != "" && [file exists $srcdir/$subdir/$regexp_file-$target_machine] } then {
205 set regexp_file $regexp_file-$target_machine
206 } elseif { [file exists $srcdir/$subdir/$regexp_file-$readelf_size] } then {
207 set regexp_file $regexp_file-$readelf_size
208 }
209
210 if { [regexp_diff readelf.out $srcdir/$subdir/$regexp_file] } then {
211 fail "readelf $options"
212 verbose "output is \n[file_contents readelf.out]" 2
213 return
214 }
215
216 pass "readelf $options"
217 }
218
219
220
221 # Only ELF based toolchains need readelf.
222 # For now be paranoid and assume that if ELF is not mentioned
223 # in the target string, then the target is not an ELF based port.
224
225 if { ![istarget *-*-elf*] \
226 && ![istarget *-*-linux*] \
227 && ![istarget i?86-*-sysv4*] \
228 && ![istarget i?86-*-unixware] \
229 && ![istarget mips*-*-irix5*] \
230 && ![istarget mips*-*-irix6*] \
231 && ![istarget powerpc-*-sysv4*] \
232 && ![istarget sparc*-*-solaris2*] } {
233 verbose "$READELF is only intended for ELF targets" 2
234 return
235 }
236
237 if { [istarget *-*-linux*oldld*] \
238 || [istarget *-*-linux*aout*] } {
239 verbose "$READELF is only intended for ELF targets" 2
240 return
241 }
242
243 if ![is_remote host] {
244 if {[which $READELF] == 0} then {
245 perror "$READELF does not exist"
246 return
247 }
248 }
249
250 send_user "Version [binutil_version $READELF]"
251
252 # Assemble the test file.
253 if {![binutils_assemble $srcdir/$subdir/bintest.s tmpdir/bintest.o]} then {
254 perror "unresolved 1"
255 unresolved "readelf - failed to assemble"
256 return
257 }
258
259 if ![is_remote host] {
260 set tempfile tmpdir/bintest.o;
261 } else {
262 set tempfile [remote_download host tmpdir/bintest.o]
263 }
264
265 # First, determine the size, so specific output matchers can be used.
266 readelf_find_size $tempfile
267
268 # Run the tests.
269 readelf_test -h $tempfile readelf.h {}
270 readelf_test -S $tempfile readelf.s {}
271 readelf_test -s $tempfile readelf.ss {}
272 readelf_test -r $tempfile readelf.r {}
273
274
275 # Compile the second test file.
276 if { [target_compile $srcdir/$subdir/testprog.c tmpdir/testprog.o object debug] != "" } {
277 untested "readelf -w"
278 return
279 }
280
281 if [is_remote host] {
282 set tempfile [remote_download host tmpdir/testprog.o];
283 } else {
284 set tempfile tmpdir/testprog.o
285 }
286
287 # The xfail targets here do not default to DWARF2 format debug information
288 # The symptom is that the output of 'readelf -wi' is empty.
289
290 readelf_test -wi $tempfile readelf.wi {v850*-*-* cris-*-* *-*-linux*}