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