Commit | Line | Data |
---|---|---|
32866df7 | 1 | # Copyright 1999, 2000, 2001, 2003, 2004, 2007 Free Software Foundation, Inc. |
252b5132 RH |
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 | |
32866df7 | 5 | # the Free Software Foundation; either version 3 of the License, or |
252b5132 RH |
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 | |
b43b5d5f | 15 | # Foundation, Inc., 51 Franklin Street - Fifth Floor, Boston, MA 02110-1301, USA. |
252b5132 RH |
16 | |
17 | # Please email any bugs, comments, and/or additions to this file to: | |
18 | # bug-dejagnu@prep.ai.mit.edu | |
19 | ||
113675b7 | 20 | # Written by Nick Clifton <nickc@cygnus.com> |
252b5132 RH |
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 | ||
9921923c HPN |
34 | # Find out the size by reading the output of the EI_CLASS field. |
35 | # Similar to the test for readelf -h, but we're just looking for the | |
36 | # EI_CLASS line here. | |
37 | proc readelf_find_size { binary_file } { | |
38 | global READELF | |
39 | global READELFFLAGS | |
40 | global readelf_size | |
41 | ||
42 | set readelf_size "" | |
43 | set testname "finding out ELF size with readelf -h" | |
7f6a71ff JM |
44 | set got [remote_exec host "$READELF $READELFFLAGS -h $binary_file" "" "/dev/null" "readelf.out"] |
45 | if [is_remote host] then { | |
46 | remote_upload host "readelf.out" | |
47 | } | |
9921923c | 48 | |
7f6a71ff | 49 | if { [lindex $got 0] != 0 || ![string match "" [lindex $got 1]]} then { |
9921923c HPN |
50 | send_log $got |
51 | fail $testname | |
52 | return | |
53 | } | |
54 | ||
55 | if { ! [regexp "\n\[ \]*Class:\[ \]*ELF(\[0-9\]+)\n" \ | |
56 | [file_contents readelf.out] nil readelf_size] } { | |
57 | verbose -log "EI_CLASS field not found in output" | |
58 | verbose -log "output is \n[file_contents readelf.out]" | |
59 | fail $testname | |
60 | return | |
61 | } else { | |
62 | verbose -log "ELF size is $readelf_size" | |
63 | } | |
64 | ||
65 | pass $testname | |
66 | } | |
67 | ||
252b5132 RH |
68 | # Run an individual readelf test. |
69 | # Basically readelf is run on the binary_file with the given options. | |
70 | # Readelf's output is captured and then compared against the contents | |
9921923c | 71 | # of the regexp_file-readelf_size if it exists, else regexp_file. |
252b5132 RH |
72 | |
73 | proc readelf_test { options binary_file regexp_file xfails } { | |
74 | ||
75 | global READELF | |
76 | global READELFFLAGS | |
9921923c | 77 | global readelf_size |
252b5132 RH |
78 | global srcdir |
79 | global subdir | |
80 | ||
9921923c | 81 | send_log "exec $READELF $READELFFLAGS $options $binary_file > readelf.out\n" |
7f6a71ff | 82 | set got [remote_exec host "$READELF $READELFFLAGS $options $binary_file" "" "/dev/null" "readelf.out"] |
252b5132 | 83 | |
9a1c9383 NC |
84 | foreach xfail $xfails { |
85 | setup_xfail $xfail | |
252b5132 | 86 | } |
3f7de0e7 | 87 | |
7f6a71ff | 88 | if { [lindex $got 0] != 0 || ![string match "" [lindex $got 1]] } then { |
3f7de0e7 | 89 | fail "readelf $options (reason: unexpected output)" |
252b5132 | 90 | send_log $got |
3f7de0e7 | 91 | send_log "\n" |
252b5132 RH |
92 | return |
93 | } | |
94 | ||
ade0b24f NC |
95 | set target_machine "" |
96 | if [istarget "mips*-*-*"] then { | |
4be041b2 | 97 | if { [istarget "mips*-*-*linux*"] || [istarget "mips*-sde-elf*"] } then { |
eed3fa3b L |
98 | set target_machine tmips |
99 | } else { | |
100 | set target_machine mips | |
101 | } | |
ade0b24f NC |
102 | } |
103 | ||
104 | if { $target_machine != "" && [file exists $srcdir/$subdir/$regexp_file-$readelf_size-$target_machine] } then { | |
105 | set regexp_file $regexp_file-$readelf_size-$target_machine | |
106 | } elseif { $target_machine != "" && [file exists $srcdir/$subdir/$regexp_file-$target_machine] } then { | |
107 | set regexp_file $regexp_file-$target_machine | |
108 | } elseif { [file exists $srcdir/$subdir/$regexp_file-$readelf_size] } then { | |
9921923c HPN |
109 | set regexp_file $regexp_file-$readelf_size |
110 | } | |
111 | ||
252b5132 RH |
112 | if { [regexp_diff readelf.out $srcdir/$subdir/$regexp_file] } then { |
113 | fail "readelf $options" | |
114 | verbose "output is \n[file_contents readelf.out]" 2 | |
115 | return | |
116 | } | |
117 | ||
118 | pass "readelf $options" | |
119 | } | |
120 | ||
cbb356d9 NC |
121 | # Simple proc to skip certain expected warning messages. |
122 | ||
123 | proc prune_readelf_wi_warnings { text } { | |
124 | regsub -all "(^|\n)(.*Skipping unexpected symbol type.*)" $text "\\1" text | |
125 | return $text | |
126 | } | |
127 | ||
128 | # Testing the "readelf -wi" option is difficult because there | |
129 | # is no guaranteed order to the output, and because some ports | |
130 | # will use indirect string references, whilst others will use | |
131 | # direct references. So instead of having an expected output | |
132 | # file, like the other readelf tests, we grep for strings that | |
133 | # really ought to be there. | |
134 | ||
135 | proc readelf_wi_test {} { | |
136 | global READELF | |
137 | global READELFFLAGS | |
138 | global srcdir | |
139 | global subdir | |
140 | ||
141 | # Compile the second test file. | |
142 | if { [target_compile $srcdir/$subdir/testprog.c tmpdir/testprog.o object debug] != "" } { | |
143 | verbose "Unable to compile test file." | |
144 | untested "readelf -wi" | |
145 | return | |
146 | } | |
147 | ||
148 | # Download it. | |
8d263650 | 149 | set tempfile [remote_download host tmpdir/testprog.o] |
cbb356d9 NC |
150 | |
151 | # Run "readelf -wi" on it. | |
7f6a71ff | 152 | set got [remote_exec host "$READELF $READELFFLAGS -wi $tempfile" "" "/dev/null" "readelf.out"] |
cbb356d9 NC |
153 | |
154 | # Upload the results. | |
8d263650 | 155 | set output [remote_upload host readelf.out] |
cbb356d9 | 156 | |
8d263650 | 157 | file_on_host delete $tempfile |
cbb356d9 NC |
158 | |
159 | # Strip any superflous warnings. | |
7f6a71ff | 160 | set got [prune_readelf_wi_warnings [lindex $got 1]] |
cbb356d9 NC |
161 | |
162 | if ![string match "" $got] then { | |
b279a55c | 163 | fail "readelf $READELFFLAGS -wi (reason: unexpected output)" |
cbb356d9 NC |
164 | send_log $got |
165 | send_log "\n" | |
166 | return | |
167 | } | |
168 | ||
169 | if ![file size $output] then { | |
170 | # If the output file is empty, then this target does not | |
171 | # generate dwarf2 output. This is not a failure. | |
172 | verbose "No output from 'readelf -wi'" | |
173 | untested "readelf -wi" | |
174 | return | |
175 | } | |
176 | ||
177 | # Search for strings that should be in the output. | |
178 | set sought { | |
179 | ".*DW_TAG_compile_unit.*" | |
180 | ".*DW_TAG_subprogram.*" | |
181 | ".*DW_TAG_base_type.*" | |
182 | ".*DW_AT_producer.*(GNU C|indirect string).*" | |
183 | ".*DW_AT_language.*ANSI C.*" | |
184 | ".*DW_AT_name.*(testprog.c|indirect string).*" | |
185 | ".*DW_AT_name.*fn.*" | |
186 | ".*DW_AT_name.*(main|indirect string).*" | |
aaa222e7 | 187 | ".*\(DW_OP_addr: 0\).*" |
cbb356d9 NC |
188 | } |
189 | ||
190 | foreach looked_for $sought { | |
191 | set lines [grep $output $looked_for] | |
192 | if ![llength $lines] then { | |
193 | fail "readelf -wi: missing: $looked_for" | |
194 | send_log readelf.out | |
195 | return | |
196 | } | |
197 | } | |
198 | ||
8d263650 | 199 | file_on_host delete $output |
cbb356d9 NC |
200 | |
201 | # All done. | |
202 | pass "readelf -wi" | |
203 | } | |
252b5132 RH |
204 | |
205 | ||
9ce701e2 L |
206 | # Exclude non-ELF targets. |
207 | if ![is_elf_format] { | |
9921923c | 208 | verbose "$READELF is only intended for ELF targets" 2 |
252b5132 RH |
209 | return |
210 | } | |
211 | ||
212 | if ![is_remote host] { | |
213 | if {[which $READELF] == 0} then { | |
214 | perror "$READELF does not exist" | |
215 | return | |
216 | } | |
217 | } | |
218 | ||
219 | send_user "Version [binutil_version $READELF]" | |
220 | ||
89084430 | 221 | # Assemble the test file. |
252b5132 RH |
222 | if {![binutils_assemble $srcdir/$subdir/bintest.s tmpdir/bintest.o]} then { |
223 | perror "unresolved 1" | |
224 | unresolved "readelf - failed to assemble" | |
225 | return | |
226 | } | |
227 | ||
228 | if ![is_remote host] { | |
8d263650 | 229 | set tempfile tmpdir/bintest.o |
252b5132 RH |
230 | } else { |
231 | set tempfile [remote_download host tmpdir/bintest.o] | |
232 | } | |
233 | ||
9921923c HPN |
234 | # First, determine the size, so specific output matchers can be used. |
235 | readelf_find_size $tempfile | |
236 | ||
237 | # Run the tests. | |
252b5132 | 238 | readelf_test -h $tempfile readelf.h {} |
ade0b24f NC |
239 | readelf_test -S $tempfile readelf.s {} |
240 | readelf_test -s $tempfile readelf.ss {} | |
252b5132 RH |
241 | readelf_test -r $tempfile readelf.r {} |
242 | ||
cbb356d9 | 243 | readelf_wi_test |