* binutils-all/objcopy.exp: Add setup_xfail for a29k-*-vxworks*
[platform/upstream/binutils.git] / binutils / testsuite / binutils-all / objcopy.exp
1 #   Copyright (C) 1994 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 Ian Lance Taylor <ian@cygnus.com>
21
22 if {[which $OBJCOPY] == 0} then {
23     perror "$OBJCOPY does not exist"
24     return
25 }
26
27 send_user "Version [binutil_version $OBJCOPY]"
28
29
30 if {![binutils_assemble $AS $srcdir$subdir/bintest.s tmpdir/bintest.o]} then {
31     return
32 }
33
34 # Test that objcopy does not modify a file when copying it.
35
36 set got [binutils_run $OBJCOPY "$OBJCOPYFLAGS tmpdir/bintest.o tmpdir/copy.o"]
37
38 if ![string match "" $got] then {
39     fail "objcopy (simple copy)"
40 } else {
41     send_log "cmp tmpdir/bintest.o tmpdir/copy.o\n"
42     verbose "cmp tmpdir/bintest.o tmpdir/copy.o"
43     catch "exec cmp tmpdir/bintest.o tmpdir/copy.o" exec_output
44
45     # On some systems the result of objcopy will not be identical.
46     # Usually this is just because gas isn't using bfd to write the files
47     # in the first place, and may order things a little differently.
48     # Those systems should use setup_xfail here.
49
50     setup_xfail "sh-*-coff" "sh-*-hms" 
51     setup_xfail "arm-*-pe" 
52     setup_xfail "m68*-*-hpux*" "m68*-*-sunos*" "m68*-*-coff" "m68*-*-vxworks*"
53     setup_xfail "m68*-ericsson-ose"
54     setup_xfail "i*86-*-linux"
55     setup_xfail "a29k-*-udi" "a29k-*-coff" "a29k-*-vxworks*"
56     setup_xfail "i960-*-vxworks*" "i960-*-coff"
57     setup_xfail "h8300-*-hms" "h8300-*-coff"
58     setup_xfail "h8500-*-hms" "h8500-*-coff"
59     setup_xfail "hppa*-*-*"
60     clear_xfail "hppa*-*-*elf*"
61     setup_xfail "m88*-*-coff"
62     setup_xfail "z8*-*-coff"
63
64     if [string match "" $exec_output] then {
65         pass "objcopy (simple copy)"
66     } else {
67         send_log "$exec_output\n"
68         verbose "$exec_output" 1
69
70         fail "objcopy (simple copy)"
71     }
72 }
73
74 # Test generating S records.
75
76 set got [binutils_run $OBJCOPY "$OBJCOPYFLAGS -O srec tmpdir/bintest.o tmpdir/copy.srec"]
77
78 if ![string match "" $got] then {
79     fail "objcopy -O srec"
80 } else {
81     set file [open tmpdir/copy.srec r]
82
83     # The first S record is fixed by the file name we are using.
84     gets $file line
85     send_log "$line\n"
86     verbose $line
87     if ![string match $line "S0130000746D706469722F636F70792E7372656397\r"] {
88         fail "objcopy -O srec (bad header)"
89     } else {
90         while {[gets $file line] != -1 \
91                && [regexp "^S\[123\]\[0-9a-fA-F\]+\r$" $line]} {
92             send_log "$line\n"
93             verbose $line
94             set line "**EOF**"
95         }
96         send_log "$line\n"
97         verbose $line
98         if ![regexp "^S\[789\]\[0-9a-fA-F\]+\r$" $line] then {
99             fail "objcopy -O srec (bad trailer)"
100         } else {
101             if {[gets $file line] != -1} then {
102                 send_log "$line\n"
103                 verbose $line
104                 fail "objcopy -O srec (garbage at end)"
105             } else {
106                 set got [binutils_run $OBJDUMP "$OBJDUMPFLAGS -f tmpdir/copy.srec"]
107                 if ![regexp "file format srec" $got] then {
108                     fail "objcopy -O srec (objdump failed)"
109                 } else {
110                     pass "objcopy -O srec"
111                 }
112             }
113         }
114     }
115
116     close $file
117 }
118
119 # Test setting and adjusting the start address.  We only test this
120 # while generating S records, because we may not be able to set the
121 # start address for other object file formats, and the S record case
122 # is the only useful one anyhow.
123
124 set got [binutils_run $OBJDUMP "$OBJDUMPFLAGS -f tmpdir/bintest.o"]
125 if ![regexp "start address (\[0-9a-fA-FxX\]+)" $got all origstart] then {
126     perror "objdump can not recognize bintest.o"
127     set origstart ""
128 } else {
129     set got [binutils_run $OBJCOPY "$OBJCOPYFLAGS -O srec tmpdir/bintest.o tmpdir/copy.srec --set-start 0x7654"]
130     if ![string match "" $got] then {
131         fail "objcopy --set-start"
132     } else {
133         set got [binutils_run $OBJDUMP "$OBJDUMPFLAGS -f tmpdir/copy.srec"]
134         if ![regexp "file format srec.*start address (\[0-9a-fA-FxX\]+)" $got all srecstart] then {
135             fail "objcopy --set-start"
136         } else {
137             if {$srecstart != 0x7654} then {
138                 fail "objcopy --set-start ($srecstart != 0x7654)"
139             } else {
140                 pass "objcopy --set-start"
141             }
142         }
143     }
144
145     set got [binutils_run $OBJCOPY "$OBJCOPYFLAGS -O srec tmpdir/bintest.o tmpdir/copy.srec --adjust-start 0x123"]
146     if ![string match "" $got] then {
147         fail "objcopy --adjust-start"
148     } else {
149         set got [binutils_run $OBJDUMP "$OBJDUMPFLAGS -f tmpdir/copy.srec"]
150         if ![regexp "file format srec.*start address (\[0-9a-fA-FxX\]+)" $got all srecstart] then {
151             fail "objcopy --adjust-start"
152         } else {
153             if {$srecstart != $origstart + 0x123} then {
154                 fail "objcopy --adjust-start ($srecstart != $origstart + 0x123)"
155             } else {
156                 pass "objcopy --adjust-start"
157             }
158         }
159     }
160 }
161
162 # Test adjusting the overall VMA, and adjusting the VMA of a
163 # particular section.  We again only test this when # generating S
164 # records.
165
166 set low ""
167 set lowname ""
168
169 set headers [binutils_run $OBJDUMP "$OBJDUMPFLAGS -h tmpdir/bintest.o"]
170
171 set headers_regexp "SECTION\[   0-9\]+\\\[(\[^\]\]*)\\\]\[^\n\r\]*size\[        \]*(\[0-9a-fA-F\]+)\[   \]*vma\[        \]*(\[0-9a-fA-F\]+)(.*)"
172
173 set got $headers
174 while {[regexp $headers_regexp $got all name size vma rest]} {
175     set vma 0x$vma
176     if {$low == "" || $vma < $low} then {
177         set low $vma
178         set lowname $name
179     }
180     set got $rest
181 }
182
183 if {$low == "" || $origstart == ""} then {
184     perror "objdump can not recognize bintest.o"
185 } else {
186     set got [binutils_run $OBJCOPY "$OBJCOPYFLAGS -O srec tmpdir/bintest.o tmpdir/copy.srec --adjust-vma 0x123"]
187     if ![string match "" $got] then {
188         fail "objcopy --adjust-vma"
189     } else {
190         set got [binutils_run $OBJDUMP "$OBJDUMPFLAGS -fh tmpdir/copy.srec"]
191         set want "file format srec.*start address\[     \]*(\[0-9a-fA-FxX\]+).*vma\[    \]*(\[0-9a-fA-F\]+)"
192         if ![regexp $want $got all start vma] then {
193             fail "objcopy --adjust-vma"
194         } else {
195             set vma 0x$vma
196             if {$vma != $low + 0x123} then {
197                 fail "objcopy --adjust-vma ($vma != $low + 0x123)"
198             } else {
199                 if {$start != $origstart + 0x123} then {
200                     fail "objcopy --adjust-vma ($start != $origstart + 0x123)"
201                 } else {
202                     pass "objcopy --adjust-vma"
203                 }
204             }
205         }
206     }
207
208     set arg ""
209     set got $headers
210     while {[regexp $headers_regexp $got all name size vma rest]} {
211         set vma 0x$vma
212         if {$vma == $low} then {
213             set arg "$arg --adjust-section-vma $name+4"
214         }
215         set got $rest
216     }
217
218     set got [binutils_run $OBJCOPY "$OBJCOPYFLAGS -O srec tmpdir/bintest.o tmpdir/copy.srec $arg"]
219     if ![string match "" $got] then {
220         fail "objcopy --adjust-section-vma +"
221     } else {
222         set got [binutils_run $OBJDUMP "$OBJDUMPFLAGS -h tmpdir/copy.srec"]
223         set want "file format srec.*SECTION\[   \]*0\[^\n\r\]*vma\[     \]*(\[0-9a-fA-F\]+)"
224         if ![regexp $want $got all vma] then {
225             fail "objcopy --adjust-section-vma +"
226         } else {
227             set vma 0x$vma
228             if {$vma != $low + 4} then {
229                 fail "objcopy --adjust-section-vma + ($vma != $low + 4)"
230             } else {
231                 pass "objcopy --adjust-section-vma +"
232             }
233         }
234     }
235
236     regsub -all "\\+4" $arg "=[expr $low + 4]" argeq
237     set got [binutils_run $OBJCOPY "$OBJCOPYFLAGS -O srec tmpdir/bintest.o tmpdir/copy.srec $argeq"]
238     if ![string match "" $got] then {
239         fail "objcopy --adjust-section-vma ="
240     } else {
241         set got [binutils_run $OBJDUMP "$OBJDUMPFLAGS -h tmpdir/copy.srec"]
242         set want "file format srec.*SECTION\[   \]*0\[^\n\r\]*vma\[     \]*(\[0-9a-fA-F\]+)"
243         if ![regexp $want $got all vma] then {
244             fail "objcopy --adjust-section-vma ="
245         } else {
246             set vma 0x$vma
247             if {$vma != $low + 4} then {
248                 fail "objcopy --adjust-section-vma = ($vma != $low + 4)"
249             } else {
250                 pass "objcopy --adjust-section-vma ="
251             }
252         }
253     }
254 }