Commit | Line | Data |
---|---|---|
1b19eb81 AO |
1 | # Expect script for ld-sh tests |
2 | # Copyright (C) 2000, 2001, 2002 Free Software Foundation | |
3 | # | |
4 | # This file is free software; you can redistribute it and/or modify | |
5 | # it under the terms of the GNU General Public License as published by | |
6 | # the Free Software Foundation; either version 2 of the License, or | |
7 | # (at your option) any later version. | |
8 | # | |
9 | # This program is distributed in the hope that it will be useful, | |
10 | # but WITHOUT ANY WARRANTY; without even the implied warranty of | |
11 | # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the | |
12 | # GNU General Public License for more details. | |
13 | # | |
14 | # You should have received a copy of the GNU General Public License | |
15 | # along with this program; if not, write to the Free Software | |
16 | # Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. | |
17 | # | |
18 | ||
19 | # Test SH linking; all types of relocs. This tests the assembler and | |
20 | # tools like objdump as well as the linker. | |
21 | ||
22 | if ![istarget sh64-*-*] { | |
23 | return | |
24 | } | |
25 | ||
26 | # FIXME: This isn't set by testsuite/config/default.exp; make it. | |
27 | if ![info exists readelf] then { | |
28 | set readelf [findfile $base_dir/../binutils/readelf] | |
29 | } | |
30 | ||
31 | # List contains test-items with 3 items followed by 2 lists: | |
32 | # 0:name 1:ld options 2:assembler options | |
33 | # 3:filenames of assembler files 4: action and options. | |
34 | ||
35 | # Actions: | |
36 | # objdump: Apply objdump options on result. Compare with regex (last arg). | |
37 | # nm: Apply nm options on result. Compare with regex (last arg). | |
38 | ||
39 | # Note that the contents dump is the same for "inter-file datalabel | |
40 | # references, 64-bit ABI" as for 32-bit ABI and ELF so we re-use it. | |
41 | ||
42 | set sh64tests { | |
43 | {"SH64 linking, 64-bit ABI" "-mshelf64" | |
44 | "--abi=64" {sh64-1.s sh64-2.s} | |
45 | {{objdump -sr abi64.sd} {objdump -x abi64.xd}}} | |
46 | {"SH64 linking, 64-bit ABI, -no-expand" "-mshelf64" | |
47 | "--abi=64 -no-expand" {sh64-1.s sh64-2.s} | |
48 | {{objdump -sr abixx-noexp.sd}}} | |
49 | {"SH64 linking, 32-bit ABI" "-mshelf32" | |
50 | "--abi=32" {sh64-1.s sh64-2.s} | |
51 | {{objdump -sr abi32.sd} {objdump -x abi32.xd}}} | |
52 | {"SH64 linking, 32-bit ABI, -no-expand" "-mshelf32" | |
53 | "--abi=32 -no-expand" {sh64-1.s sh64-2.s} | |
54 | {{objdump -sr abixx-noexp.sd}}} | |
55 | {"SH64 linking, single multi-ISA object" "-mshelf32" | |
56 | "--abi=32" {shmix-1.s} | |
57 | {{objdump -sr mix1.sd} {objdump -x mix1.xd}}} | |
58 | {"SH64 linking, single multi-ISA object, -no-expand" "-mshelf32" | |
59 | "--abi=32 -no-expand" {shmix-1.s} | |
60 | {{objdump -sr mix1-noexp.sd}}} | |
61 | {"SH64 linking, two different-ISA objects" "-mshelf32" | |
62 | "--abi=32" {shmix-2.s shmix-3.s} | |
63 | {{objdump -sr mix2.sd} {objdump -x mix2.xd}}} | |
64 | {"SH64 linking, two different-ISA objects, -no-expand" "-mshelf32" | |
65 | "--abi=32 -no-expand" {shmix-2.s shmix-3.s} | |
66 | {{objdump -sr mix2-noexp.sd}}} | |
67 | {"SH64 linking, single SHcompact" "-mshelf32" | |
68 | "--isa=SHcompact" {shcmp-1.s} | |
69 | {{objdump -sr cmpct1.sd} {objdump -x cmpct1.xd}}} | |
70 | {"SH64 inter-file datalabel references, 64-bit ABI" "-mshelf64" | |
71 | "--abi=64" {shdl-1.s shdl-2.s} | |
72 | {{objdump -sr shdl64.sd} {objdump -x shdl64.xd}}} | |
73 | {"SH64 inter-file datalabel references, 32-bit ABI" "-mshelf32" | |
74 | "--abi=32" {shdl-1.s shdl-2.s} | |
75 | {{objdump -sr shdl64.sd} {objdump -x shdl32.xd}}} | |
76 | {"SH64 simple partial linking, 32-bit ABI" "-mshelf32 -r" | |
77 | "--abi=32" {rel-1.s rel-2.s} | |
78 | {{objdump -sx rel32.xd}}} | |
79 | {"SH64 simple partial linking, 64-bit ABI" "-mshelf64 -r" | |
80 | "--abi=64" {rel-1.s rel-2.s} | |
81 | {{objdump -sx rel64.xd}}} | |
82 | {"SH64 partial linking with datalabel references, 32-bit ABI" "-mshelf32 -r" | |
83 | "--abi=32" {reldl-1.s reldl-2.s} | |
84 | {{readelf {-s -r -x 1 -x 3} reldl32.rd}}} | |
85 | {"SH64 partial linking with datalabel references, 64-bit ABI" "-mshelf64 -r" | |
86 | "--abi=64" {reldl-1.s reldl-2.s} | |
87 | {{readelf {-s -r -x 1 -x 3} reldl64.rd}}} | |
88 | {"Handling SH64 assembler-generated .cranges" "-mshelf32" | |
89 | "--abi=32" {crange-2a.s crange-1.s} | |
90 | {{readelf {-S -s -r -x 1 -x 2 -x 9} crange1.rd}}} | |
91 | {"Handling SH64 assembler-generated .cranges, partial linking" "-mshelf32 -r" | |
92 | "--abi=32" {crange-2a.s} | |
93 | {{readelf {-S -s -r -x 2 -x 5} crangerel1.rd}}} | |
94 | {"Mixing SH64 assembler-generated with linker-generated .cranges" "-mshelf32" | |
95 | "--abi=32" {crange-2a.s crange-2b.s crange-1.s} | |
96 | {{readelf {-S -s -r -x 2 -x 9} crange2.rd}}} | |
97 | {"Mixing SH64 assembler-generated with linker-generated .cranges, partial linking" | |
98 | "-mshelf32 -r" | |
99 | "--abi=32" {crange-2a.s crange-2c.s crange-2d.s crange-2e.s} | |
100 | {{readelf {-S -s -r -x 2 -x 5} crangerel2.rd}}} | |
101 | {"Merge and use of SH64 .cranges, some not originally in order" "-mshelf32" | |
102 | "--abi=32" | |
103 | {crange-2e.s crange-2f.s crange-2g.s crange-2a.s crange-2d.s crange-2i.s | |
104 | crange-2h.s crange-1.s} | |
105 | {{readelf {-S -s -x 2 -x 9} crange3.rd} {objdump -d crange3.dd}}} | |
106 | {"Sorted SH64 .cranges, entry at SHcompact code" "-mshelf32 --entry diversion" | |
107 | "--abi=32" | |
108 | {crange-2e.s crange-2f.s crange-2g.s crange-2a.s crange-2d.s crange-2i.s | |
109 | crange-2h.s crange-1.s} | |
110 | {{readelf {-h -S -s -x 2 -x 9} crange3-cmpct.rd}}} | |
111 | {"Sorted SH64 .cranges, entry at SHmedia code" "-mshelf32 --entry diversion2" | |
112 | "--abi=32" | |
113 | {crange-2e.s crange-2f.s crange-2g.s crange-2a.s crange-2d.s crange-2i.s | |
114 | crange-2h.s crange-1.s} | |
115 | {{readelf {-h -S -s -x 2 -x 9} crange3-media.rd}}} | |
116 | {"SH64 Big Endianness" "-mshelf64 -Tendian.ld" | |
117 | "--abi=64" {endian.s} | |
118 | {{objdump -s endian.sbd} {objdump -d endian.dbd}}} | |
119 | {"SH64 Little Endianness" "-mshlelf64 -Tendian.ld" | |
120 | "--abi=64 --little" {endian.s} | |
121 | {{objdump -s endian.sld} {objdump -d endian.dld}}} | |
122 | ||
123 | } | |
124 | ||
125 | # FIXME: Generalize and move this to ld-lib.exp | |
126 | ||
127 | proc run_ld_link_tests { ldtests } { | |
128 | global ld | |
129 | global as | |
130 | global nm | |
131 | global objdump | |
132 | global readelf | |
133 | global srcdir | |
134 | global subdir | |
135 | ||
136 | set binfile "tmpdir/linked" | |
137 | ||
138 | foreach testitem $ldtests { | |
139 | set testname [lindex $testitem 0] | |
140 | set ld_options [lindex $testitem 1] | |
141 | set as_options [lindex $testitem 2] | |
142 | set as_files [lindex $testitem 3] | |
143 | set actions [lindex $testitem 4] | |
144 | set objfiles {} | |
145 | set is_unresolved 0 | |
146 | set failed 0 | |
147 | ||
148 | # verbose -log "Testname is $testname" | |
149 | # verbose -log "ld_options is $ld_options" | |
150 | # verbose -log "as_options is $as_options" | |
151 | # verbose -log "as_files is $as_files" | |
152 | # verbose -log "actions is $actions" | |
153 | ||
154 | # Assemble each file in the test. | |
155 | foreach as_file $as_files { | |
156 | set objfile "tmpdir/[file rootname $as_file].o" | |
157 | lappend objfiles $objfile | |
158 | ||
159 | if ![ld_assemble $as "$as_options $srcdir/$subdir/$as_file" $objfile] { | |
160 | set is_unresolved 1 | |
161 | break | |
162 | } | |
163 | } | |
164 | ||
165 | # Catch assembler errors. | |
166 | if { $is_unresolved != 0 } { | |
167 | unresolved $testname | |
168 | continue | |
169 | } | |
170 | ||
171 | if ![ld_simple_link $ld $binfile "-L$srcdir/$subdir $ld_options $objfiles"] { | |
172 | fail $testname | |
173 | } else { | |
174 | set failed 0 | |
175 | foreach actionlist $actions { | |
176 | set action [lindex $actionlist 0] | |
177 | set progopts [lindex $actionlist 1] | |
178 | ||
179 | # There are actions where we run regexp_diff on the | |
180 | # output, and there are other actions (presumably). | |
181 | # Handling of the former look the same. | |
182 | set dump_prog "" | |
183 | switch -- $action { | |
184 | objdump | |
185 | { set dump_prog $objdump } | |
186 | nm | |
187 | { set dump_prog $nm } | |
188 | readelf | |
189 | { set dump_prog $readelf } | |
190 | default | |
191 | { | |
192 | perror "Unrecognized action $action" | |
193 | set is_unresolved 1 | |
194 | break | |
195 | } | |
196 | } | |
197 | ||
198 | if { $dump_prog != "" } { | |
199 | set dumpfile [lindex $actionlist 2] | |
200 | set binary $dump_prog | |
201 | ||
202 | send_log "$binary $progopts $binfile > dump.out\n" | |
203 | catch "exec $binary $progopts $binfile > dump.out" comp_output | |
204 | set comp_output [prune_warnings $comp_output] | |
205 | ||
206 | if ![string match "" $comp_output] then { | |
207 | send_log "$comp_output\n" | |
208 | set failed 1 | |
209 | break | |
210 | } | |
211 | ||
212 | if { [regexp_diff "dump.out" "$srcdir/$subdir/$dumpfile"] } then { | |
213 | verbose "output is [file_contents "dump.out"]" 2 | |
214 | set failed 1 | |
215 | break | |
216 | } | |
217 | } | |
218 | } | |
219 | ||
220 | if { $failed != 0 } { | |
221 | fail $testname | |
222 | } else { if { $is_unresolved == 0 } { | |
223 | pass $testname | |
224 | } } | |
225 | } | |
226 | ||
227 | # Catch action errors. | |
228 | if { $is_unresolved != 0 } { | |
229 | unresolved $testname | |
230 | continue | |
231 | } | |
232 | } | |
233 | } | |
234 | ||
235 | # FIXME: Move this to ld-lib.exp or higher up. | |
236 | ||
237 | # regexp_diff, based on simple_diff taken from ld test suite | |
238 | # compares two files line-by-line | |
239 | # file1 contains strings, file2 contains regexps and #-comments | |
240 | # blank lines are ignored in either file | |
241 | # returns non-zero if differences exist | |
242 | # | |
243 | proc regexp_diff { file_1 file_2 } { | |
244 | ||
245 | set eof -1 | |
246 | set end_1 0 | |
247 | set end_2 0 | |
248 | set differences 0 | |
249 | set diff_pass 0 | |
250 | ||
251 | if [file exists $file_1] then { | |
252 | set file_a [open $file_1 r] | |
253 | } else { | |
254 | warning "$file_1 doesn't exist" | |
255 | return 1 | |
256 | } | |
257 | ||
258 | if [file exists $file_2] then { | |
259 | set file_b [open $file_2 r] | |
260 | } else { | |
261 | fail "$file_2 doesn't exist" | |
262 | close $file_a | |
263 | return 1 | |
264 | } | |
265 | ||
266 | verbose " Regexp-diff'ing: $file_1 $file_2" 2 | |
267 | ||
268 | while { 1 } { | |
269 | set line_a "" | |
270 | set line_b "" | |
271 | while { [string length $line_a] == 0 } { | |
272 | if { [gets $file_a line_a] == $eof } { | |
273 | set end_1 1 | |
274 | break | |
275 | } | |
276 | } | |
277 | while { [string length $line_b] == 0 || [string match "#*" $line_b] } { | |
278 | if [ string match "#pass" $line_b ] { | |
279 | set end_2 1 | |
280 | set diff_pass 1 | |
281 | break | |
282 | } elseif [ string match "#..." $line_b ] { | |
283 | if { [gets $file_b line_b] == $eof } { | |
284 | set end_2 1 | |
285 | break | |
286 | } | |
287 | verbose "looking for \"^$line_b$\"" 3 | |
288 | while { ![regexp "^$line_b$" "$line_a"] } { | |
289 | verbose "skipping \"$line_a\"" 3 | |
290 | if { [gets $file_a line_a] == $eof } { | |
291 | set end_1 1 | |
292 | break | |
293 | } | |
294 | } | |
295 | break | |
296 | } | |
297 | if { [gets $file_b line_b] == $eof } { | |
298 | set end_2 1 | |
299 | break | |
300 | } | |
301 | } | |
302 | ||
303 | if { $diff_pass } { | |
304 | break | |
305 | } elseif { $end_1 && $end_2 } { | |
306 | break | |
307 | } elseif { $end_1 } { | |
308 | send_log "extra regexps in $file_2 starting with \"^$line_b$\"\nEOF from $file_1\n" | |
309 | verbose "extra regexps in $file_2 starting with \"^$line_b$\"\nEOF from $file_1" 3 | |
310 | set differences 1 | |
311 | break | |
312 | } elseif { $end_2 } { | |
313 | send_log "extra lines in $file_1 starting with \"^$line_a$\"\nEOF from $file_2\n" | |
314 | verbose "extra lines in $file_1 starting with \"^$line_a$\"\nEOF from $file_2\n" 3 | |
315 | set differences 1 | |
316 | break | |
317 | } else { | |
318 | verbose "regexp \"^$line_b$\"\nline \"$line_a\"" 3 | |
319 | if ![regexp "^$line_b$" "$line_a"] { | |
320 | send_log "regexp_diff match failure\n" | |
321 | send_log "regexp \"^$line_b$\"\nline \"$line_a\"\n" | |
322 | set differences 1 | |
323 | } | |
324 | } | |
325 | } | |
326 | ||
327 | if { $differences == 0 && !$diff_pass && [eof $file_a] != [eof $file_b] } { | |
328 | send_log "$file_1 and $file_2 are different lengths\n" | |
329 | verbose "$file_1 and $file_2 are different lengths" 3 | |
330 | set differences 1 | |
331 | } | |
332 | ||
333 | close $file_a | |
334 | close $file_b | |
335 | ||
336 | return $differences | |
337 | } | |
338 | ||
339 | proc file_contents { filename } { | |
340 | set file [open $filename r] | |
341 | set contents [read $file] | |
342 | close $file | |
343 | return $contents | |
344 | } | |
345 | ||
346 | run_ld_link_tests $sh64tests |