daily update
[deliverable/binutils-gdb.git] / binutils / testsuite / binutils-all / ar.exp
CommitLineData
eb4dc530 1# Copyright 1995, 1997, 2002, 2004, 2007, 2008, 2009, 2010, 2012
aa820537 2# Free Software Foundation, Inc.
252b5132
RH
3
4# This program is free software; you can redistribute it and/or modify
5# it under the terms of the GNU General Public License as published by
32866df7 6# the Free Software Foundation; either version 3 of the License, or
252b5132
RH
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
b43b5d5f 16# Foundation, Inc., 51 Franklin Street - Fifth Floor, Boston, MA 02110-1301, USA.
252b5132
RH
17
18# Please email any bugs, comments, and/or additions to this file to:
19# bug-dejagnu@prep.ai.mit.edu
20
21# Written by Ian Lance Taylor <ian@cygnus.com>
22
23if ![is_remote host] {
24 if {[which $AR] == 0} then {
25 perror "$AR does not exist"
26 return
27 }
28}
29
96a62921 30set bfdtest1 $base_dir/bfdtest1
58f594cd 31
252b5132
RH
32# send_user "Version [binutil_version $AR]"
33
34# Test long file name support
35
36proc long_filenames { } {
37 global AR
38 global host_triplet
58f594cd 39 global bfdtest1
252b5132
RH
40
41 set testname "ar long file names"
42
43 set n1 "abcdefghijklmnopqrstuvwxyz1"
44 set n2 "abcdefghijklmnopqrstuvwxyz2"
45 set file1 tmpdir/$n1
46 set file2 tmpdir/$n2
47
48 remote_file build delete $file1
7f6a71ff 49 remote_file host delete $n1
252b5132
RH
50
51 # Some file systems truncate file names at 14 characters, which
52 # makes it impossible to run this test. Check for that now.
53 set status [catch "set f [open tmpdir/$n1 w]" errs]
54 if { $status != 0 } {
55 verbose -log "open tmpdir/$n1 returned $errs"
56 unsupported $testname
57 return
58 }
59 puts $f "first"
60 close $f
61
252b5132 62 remote_file build delete $file2
7f6a71ff 63 remote_file host delete $n2
252b5132
RH
64
65 set status [catch "set f [open tmpdir/$n2 w]" errs]
66 if { $status != 0 } {
67 verbose -log "open tmpdir/$n2 returned $errs"
68 unsupported $testname
69 return
70 }
71 puts $f "second"
72 close $f
73
74 if [is_remote host] {
8d263650
BE
75 set file1 [remote_download host $file1]
76 set file2 [remote_download host $file2]
252b5132
RH
77 set dest artest.a
78 } else {
79 set dest tmpdir/artest.a
80 }
81
8d263650 82 remote_file host delete $dest
252b5132
RH
83
84 set got [binutils_run $AR "rc $dest $file1 $file2"]
85 if [is_remote host] {
86 remote_upload host $file1 tmpdir/$n1
87 }
88
89 set f [open tmpdir/$n1 r]
90 gets $f string
91 close $f
92 if ![string match "first" $string] {
93 verbose -log "reading tmpdir/$n1 returned $string"
94 unsupported $testname
95 return
96 }
97
8d263650 98 remote_file host delete $dest
252b5132
RH
99 set got [binutils_run $AR "rc $dest $file1 $file2"]
100
101 if ![string match "" $got] {
102 fail $testname
103 return
104 }
105
106 remote_file build delete tmpdir/$n1
107 remote_file build delete tmpdir/$n2
108
109 set got [binutils_run $AR "t $dest"]
8d263650 110 regsub "\[\r\n \t\]*$" "$got" "" got
252b5132
RH
111 if ![string match "$n1*$n2" $got] {
112 fail $testname
113 return
114 }
115
116 if [is_remote host] {
8d263650
BE
117 remote_file host delete $file1
118 remote_file host delete $file2
252b5132
RH
119 }
120
252b5132
RH
121 set exec_output [binutils_run $AR "x $dest"]
122 set exec_output [prune_warnings $exec_output]
123 if ![string match "" $exec_output] {
124 verbose -log $exec_output
125 fail $testname
126 return
127 }
128
58f594cd
L
129 set exec_output [binutils_run $bfdtest1 "$dest"]
130 if ![string match "" $exec_output] {
131 verbose -log $exec_output
132 fail "$testname (bfdtest1)"
133 return
134 }
135
252b5132 136 if [is_remote host] {
8d263650
BE
137 remote_upload host $n1 tmpdir/$n1
138 remote_upload host $n2 tmpdir/$n2
252b5132
RH
139 set file1 tmpdir/$n1
140 set file2 tmpdir/$n2
141 } else {
142 set file1 $n1
143 set file2 $n2
144 }
145
146 if ![file exists $file1] {
147 verbose -log "$file1 does not exist"
148 fail $testname
149 return
150 }
151 if ![file exists $file2] {
152 verbose -log "$file2 does not exist"
153 fail $testname
154 return
155 }
156
157 set f [open $file1 r]
158 if { [gets $f line] == -1 || $line != "first" } {
159 verbose -log "$file1 contents:"
160 verbose -log "$line"
161 close $f
162 fail $testname
163 return
164 }
165 close $f
166
167 set f [open $file2 r]
168 if { [gets $f line] == -1 || $line != "second" } {
169 verbose -log "$file2 contents:"
170 verbose -log "$line"
171 close $f
172 fail $testname
173 return
174 }
175 close $f
176
690649be 177 file delete $file1 $file2
252b5132
RH
178 pass $testname
179}
180
181# Test building the symbol table.
182
183proc symbol_table { } {
184 global AR
185 global AS
186 global NM
187 global srcdir
188 global subdir
189
190 set testname "ar symbol table"
191
192 if ![binutils_assemble $srcdir/$subdir/bintest.s tmpdir/bintest.o] {
193 unresolved $testname
194 return
195 }
196
197 if [is_remote host] {
198 set archive artest.a
199 set objfile [remote_download host tmpdir/bintest.o]
200 remote_file host delete $archive
201 } else {
202 set archive tmpdir/artest.a
203 set objfile tmpdir/bintest.o
204 }
205
206 remote_file build delete tmpdir/artest.a
207
208 set got [binutils_run $AR "rc $archive ${objfile}"]
209 if ![string match "" $got] {
210 fail $testname
211 return
212 }
213
214 set got [binutils_run $NM "--print-armap $archive"]
215 if { ![string match "*text_symbol in bintest.o*" $got] \
216 || ![string match "*data_symbol in bintest.o*" $got] \
217 || ![string match "*common_symbol in bintest.o*" $got] \
218 || [string match "*static_text_symbol in bintest.o*" $got] \
219 || [string match "*static_data_symbol in bintest.o*" $got] \
220 || [string match "*external_symbol in bintest.o*" $got] } {
221 fail $testname
222 return
223 }
224
225 pass $testname
226}
227
a8da6403
NC
228# Test building a thin archive.
229
230proc thin_archive { } {
231 global AR
232 global AS
233 global NM
234 global srcdir
235 global subdir
58f594cd 236 global bfdtest1
a8da6403
NC
237
238 set testname "ar thin archive"
239
240 if ![binutils_assemble $srcdir/$subdir/bintest.s tmpdir/bintest.o] {
241 unresolved $testname
242 return
243 }
244
245 if [is_remote host] {
246 set archive artest.a
247 set objfile [remote_download host tmpdir/bintest.o]
248 remote_file host delete $archive
249 } else {
250 set archive tmpdir/artest.a
251 set objfile tmpdir/bintest.o
252 }
253
254 remote_file build delete tmpdir/artest.a
255
256 set got [binutils_run $AR "rcT $archive ${objfile}"]
257 if ![string match "" $got] {
258 fail $testname
259 return
260 }
261
58f594cd
L
262 set exec_output [binutils_run $bfdtest1 "$archive"]
263 if ![string match "" $exec_output] {
264 verbose -log $exec_output
265 fail "$testname (bfdtest1)"
266 return
267 }
268
a8da6403
NC
269 set got [binutils_run $NM "--print-armap $archive"]
270 if { ![string match "*text_symbol in *bintest.o*" $got] \
271 || ![string match "*data_symbol in *bintest.o*" $got] \
272 || ![string match "*common_symbol in *bintest.o*" $got] \
273 || [string match "*static_text_symbol in *bintest.o*" $got] \
274 || [string match "*static_data_symbol in *bintest.o*" $got] \
275 || [string match "*external_symbol in *bintest.o*" $got] } {
276 fail $testname
277 return
278 }
279
280 pass $testname
281}
282
283# Test building a thin archive with a nested archive.
284
285proc thin_archive_with_nested { } {
286 global AR
287 global AS
288 global NM
289 global srcdir
290 global subdir
58f594cd 291 global bfdtest1
a8da6403
NC
292
293 set testname "ar thin archive with nested archive"
294
295 if ![binutils_assemble $srcdir/$subdir/bintest.s tmpdir/bintest.o] {
296 unresolved $testname
297 return
298 }
299
300 if [is_remote host] {
301 set archive artest.a
302 set archive2 artest2.a
303 set objfile [remote_download host tmpdir/bintest.o]
304 remote_file host delete $archive
305 } else {
306 set archive tmpdir/artest.a
307 set archive2 tmpdir/artest2.a
308 set objfile tmpdir/bintest.o
309 }
310
311 remote_file build delete tmpdir/artest.a
312
313 set got [binutils_run $AR "rc $archive ${objfile}"]
314 if ![string match "" $got] {
315 fail $testname
316 return
317 }
318
319 remote_file build delete tmpdir/artest2.a
320
321 set got [binutils_run $AR "rcT $archive2 ${archive}"]
322 if ![string match "" $got] {
323 fail $testname
324 return
325 }
326
58f594cd
L
327 set exec_output [binutils_run $bfdtest1 "$archive"]
328 if ![string match "" $exec_output] {
329 verbose -log $exec_output
330 fail "$testname (bfdtest1)"
331 return
332 }
333
eb4dc530
L
334 set exec_output [binutils_run $bfdtest1 "$archive2"]
335 if ![string match "" $exec_output] {
336 verbose -log $exec_output
337 fail "$testname (bfdtest1)"
338 return
339 }
340
a8da6403
NC
341 set got [binutils_run $NM "--print-armap $archive"]
342 if { ![string match "*text_symbol in *bintest.o*" $got] \
343 || ![string match "*data_symbol in *bintest.o*" $got] \
344 || ![string match "*common_symbol in *bintest.o*" $got] \
345 || [string match "*static_text_symbol in *bintest.o*" $got] \
346 || [string match "*static_data_symbol in *bintest.o*" $got] \
347 || [string match "*external_symbol in *bintest.o*" $got] } {
348 fail $testname
349 return
350 }
351
352 pass $testname
353}
354
af865222
AS
355# Test POSIX-compatible argument parsing.
356
357proc argument_parsing { } {
358 global AR
359 global AS
360 global srcdir
361 global subdir
362
363 set testname "ar argument parsing"
364
365 if ![binutils_assemble $srcdir/$subdir/bintest.s tmpdir/bintest.o] {
366 unresolved $testname
367 return
368 }
369
370 if [is_remote host] {
371 set archive artest.a
372 set objfile [remote_download host tmpdir/bintest.o]
373 remote_file host delete $archive
374 } else {
375 set archive tmpdir/artest.a
376 set objfile tmpdir/bintest.o
377 }
378
379 remote_file build delete tmpdir/artest.a
380
381 set got [binutils_run $AR "-r -c $archive ${objfile}"]
382 if ![string match "" $got] {
383 fail $testname
384 return
385 }
386
387 pass $testname
388}
389
36e4dce6
CD
390# Test building a deterministic archive.
391
392proc deterministic_archive { } {
393 global AR
394 global AS
395 global NM
396 global srcdir
397 global subdir
398
399 set testname "ar deterministic archive"
400
401 if ![binutils_assemble $srcdir/$subdir/bintest.s tmpdir/bintest.o] {
402 unresolved $testname
403 return
404 }
405
406 if [is_remote host] {
407 set archive artest.a
408 set objfile [remote_download host tmpdir/bintest.o]
409 remote_file host delete $archive
410 } else {
411 set archive tmpdir/artest.a
412 set objfile tmpdir/bintest.o
413 }
414
415 remote_file build delete tmpdir/artest.a
416
417 set got [binutils_run $AR "rcD $archive ${objfile}"]
418 if ![string match "" $got] {
419 fail $testname
420 return
421 }
422
423 set got [binutils_run $AR "tv $archive"]
424 # This only checks the file mode and uid/gid. We can't easily match
425 # date because it's printed with the user's timezone.
426 if ![string match "rw-r--r-- 0/0 *bintest.o*" $got] {
427 fail $testname
428 return
429 }
430
431 pass $testname
432}
433
a45fc993
AM
434proc unique_symbol { } {
435 global AR
436 global AS
437 global NM
438 global srcdir
439 global subdir
440
441 set testname "ar unique symbol in archive"
442
443 if ![binutils_assemble $srcdir/$subdir/unique.s tmpdir/unique.o] {
444 unresolved $testname
445 }
446
447 if [is_remote host] {
448 set archive artest.a
449 set objfile [remote_download host tmpdir/unique.o]
450 remote_file host delete $archive
451 } else {
452 set archive tmpdir/artest.a
453 set objfile tmpdir/unique.o
454 }
455
456 remote_file build delete tmpdir/artest.a
457
458 set got [binutils_run $AR "-s -r -c $archive ${objfile}"]
459 if ![string match "" $got] {
460 fail $testname
461 return
462 }
463
464 set got [binutils_run $NM "--print-armap $archive"]
465 if ![string match "*foo in *unique.o*" $got] {
466 fail $testname
467 return
468 }
469
470 pass $testname
471}
472
fde6f1fc
L
473# Test deleting an element.
474
475proc delete_an_element { } {
476 global AR
477 global AS
478 global srcdir
479 global subdir
480
481 set testname "ar deleting an element"
482
483 if ![binutils_assemble $srcdir/$subdir/bintest.s tmpdir/bintest.o] {
484 unresolved $testname
485 return
486 }
487
488 if [is_remote host] {
489 set archive artest.a
490 set objfile [remote_download host tmpdir/bintest.o]
491 remote_file host delete $archive
492 } else {
493 set archive tmpdir/artest.a
494 set objfile tmpdir/bintest.o
495 }
496
497 remote_file build delete tmpdir/artest.a
498
499 set got [binutils_run $AR "-r -c $archive ${objfile}"]
500 if ![string match "" $got] {
501 fail $testname
502 return
503 }
504
505 set got [binutils_run $AR "-d $archive ${objfile}"]
506 if ![string match "" $got] {
507 fail $testname
508 return
509 }
510
511 pass $testname
512}
513
514# Test moving an element.
515
516proc move_an_element { } {
517 global AR
518 global AS
519 global srcdir
520 global subdir
521
522 set testname "ar moving an element"
523
524 if ![binutils_assemble $srcdir/$subdir/bintest.s tmpdir/bintest.o] {
525 unresolved $testname
526 return
527 }
528
529 if [is_remote host] {
530 set archive artest.a
531 set objfile [remote_download host tmpdir/bintest.o]
532 remote_file host delete $archive
533 } else {
534 set archive tmpdir/artest.a
535 set objfile tmpdir/bintest.o
536 }
537
538 remote_file build delete tmpdir/artest.a
539
540 set got [binutils_run $AR "-r -c $archive ${objfile}"]
541 if ![string match "" $got] {
542 fail $testname
543 return
544 }
545
546 set got [binutils_run $AR "-m $archive ${objfile}"]
547 if ![string match "" $got] {
548 fail $testname
549 return
550 }
551
552 pass $testname
553}
554
252b5132
RH
555# Run the tests.
556
557long_filenames
558symbol_table
a8da6403
NC
559thin_archive
560thin_archive_with_nested
af865222 561argument_parsing
36e4dce6 562deterministic_archive
fde6f1fc
L
563delete_an_element
564move_an_element
4cd28456
AM
565if { [is_elf_format]
566 && ![istarget "*-*-hpux*"]
567 && ![istarget "msp*-*-*"] } {
a45fc993
AM
568 unique_symbol
569}
This page took 0.616783 seconds and 4 git commands to generate.