1 # Copyright 1995, 1997, 2002, 2004, 2007, 2008, 2009, 2010
2 # Free Software Foundation, Inc.
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
6 # the Free Software Foundation; either version 3 of the License, or
7 # (at your option) any later version.
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.
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., 51 Franklin Street - Fifth Floor, Boston, MA 02110-1301, USA.
18 # Please email any bugs, comments, and/or additions to this file to:
19 # bug-dejagnu@prep.ai.mit.edu
21 # Written by Ian Lance Taylor <ian@cygnus.com>
23 if ![is_remote host] {
24 if {[which $AR] == 0} then {
25 perror "$AR does not exist"
30 set bfdtest1 [findfile $base_dir/bfdtest1]
32 # send_user "Version [binutil_version $AR]"
34 # Test long file name support
36 proc long_filenames { } {
41 set testname "ar long file names"
43 set n1 "abcdefghijklmnopqrstuvwxyz1"
44 set n2 "abcdefghijklmnopqrstuvwxyz2"
48 remote_file build delete $file1
49 remote_file host delete $n1
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]
55 verbose -log "open tmpdir/$n1 returned $errs"
62 remote_file build delete $file2
63 remote_file host delete $n2
65 set status [catch "set f [open tmpdir/$n2 w]" errs]
67 verbose -log "open tmpdir/$n2 returned $errs"
75 set file1 [remote_download host $file1]
76 set file2 [remote_download host $file2]
79 set dest tmpdir/artest.a
82 remote_file host delete $dest
84 set got [binutils_run $AR "rc $dest $file1 $file2"]
86 remote_upload host $file1 tmpdir/$n1
89 set f [open tmpdir/$n1 r]
92 if ![string match "first" $string] {
93 verbose -log "reading tmpdir/$n1 returned $string"
98 remote_file host delete $dest
99 set got [binutils_run $AR "rc $dest $file1 $file2"]
101 if ![string match "" $got] {
106 remote_file build delete tmpdir/$n1
107 remote_file build delete tmpdir/$n2
109 set got [binutils_run $AR "t $dest"]
110 regsub "\[\r\n \t\]*$" "$got" "" got
111 if ![string match "$n1*$n2" $got] {
116 if [is_remote host] {
117 remote_file host delete $file1
118 remote_file host delete $file2
121 verbose -log "$AR x $dest"
122 set exec_output [binutils_run $AR "x $dest"]
123 set exec_output [prune_warnings $exec_output]
124 if ![string match "" $exec_output] {
125 verbose -log $exec_output
130 verbose -log "$bfdtest1 $dest"
131 set exec_output [binutils_run $bfdtest1 "$dest"]
132 if ![string match "" $exec_output] {
133 verbose -log $exec_output
134 fail "$testname (bfdtest1)"
138 if [is_remote host] {
139 remote_upload host $n1 tmpdir/$n1
140 remote_upload host $n2 tmpdir/$n2
148 if ![file exists $file1] {
149 verbose -log "$file1 does not exist"
153 if ![file exists $file2] {
154 verbose -log "$file2 does not exist"
159 set f [open $file1 r]
160 if { [gets $f line] == -1 || $line != "first" } {
161 verbose -log "$file1 contents:"
169 set f [open $file2 r]
170 if { [gets $f line] == -1 || $line != "second" } {
171 verbose -log "$file2 contents:"
179 file delete $file1 $file2
183 # Test building the symbol table.
185 proc symbol_table { } {
192 set testname "ar symbol table"
194 if ![binutils_assemble $srcdir/$subdir/bintest.s tmpdir/bintest.o] {
199 if [is_remote host] {
201 set objfile [remote_download host tmpdir/bintest.o]
202 remote_file host delete $archive
204 set archive tmpdir/artest.a
205 set objfile tmpdir/bintest.o
208 remote_file build delete tmpdir/artest.a
210 set got [binutils_run $AR "rc $archive ${objfile}"]
211 if ![string match "" $got] {
216 set got [binutils_run $NM "--print-armap $archive"]
217 if { ![string match "*text_symbol in bintest.o*" $got] \
218 || ![string match "*data_symbol in bintest.o*" $got] \
219 || ![string match "*common_symbol in bintest.o*" $got] \
220 || [string match "*static_text_symbol in bintest.o*" $got] \
221 || [string match "*static_data_symbol in bintest.o*" $got] \
222 || [string match "*external_symbol in bintest.o*" $got] } {
230 # Test building a thin archive.
232 proc thin_archive { } {
240 set testname "ar thin archive"
242 if ![binutils_assemble $srcdir/$subdir/bintest.s tmpdir/bintest.o] {
247 if [is_remote host] {
249 set objfile [remote_download host tmpdir/bintest.o]
250 remote_file host delete $archive
252 set archive tmpdir/artest.a
253 set objfile tmpdir/bintest.o
256 remote_file build delete tmpdir/artest.a
258 set got [binutils_run $AR "rcT $archive ${objfile}"]
259 if ![string match "" $got] {
264 verbose -log "$bfdtest1 $archive"
265 set exec_output [binutils_run $bfdtest1 "$archive"]
266 if ![string match "" $exec_output] {
267 verbose -log $exec_output
268 fail "$testname (bfdtest1)"
272 set got [binutils_run $NM "--print-armap $archive"]
273 if { ![string match "*text_symbol in *bintest.o*" $got] \
274 || ![string match "*data_symbol in *bintest.o*" $got] \
275 || ![string match "*common_symbol in *bintest.o*" $got] \
276 || [string match "*static_text_symbol in *bintest.o*" $got] \
277 || [string match "*static_data_symbol in *bintest.o*" $got] \
278 || [string match "*external_symbol in *bintest.o*" $got] } {
286 # Test building a thin archive with a nested archive.
288 proc thin_archive_with_nested { } {
296 set testname "ar thin archive with nested archive"
298 if ![binutils_assemble $srcdir/$subdir/bintest.s tmpdir/bintest.o] {
303 if [is_remote host] {
305 set archive2 artest2.a
306 set objfile [remote_download host tmpdir/bintest.o]
307 remote_file host delete $archive
309 set archive tmpdir/artest.a
310 set archive2 tmpdir/artest2.a
311 set objfile tmpdir/bintest.o
314 remote_file build delete tmpdir/artest.a
316 set got [binutils_run $AR "rc $archive ${objfile}"]
317 if ![string match "" $got] {
322 remote_file build delete tmpdir/artest2.a
324 set got [binutils_run $AR "rcT $archive2 ${archive}"]
325 if ![string match "" $got] {
330 verbose -log "$bfdtest1 $archive"
331 set exec_output [binutils_run $bfdtest1 "$archive"]
332 if ![string match "" $exec_output] {
333 verbose -log $exec_output
334 fail "$testname (bfdtest1)"
338 set got [binutils_run $NM "--print-armap $archive"]
339 if { ![string match "*text_symbol in *bintest.o*" $got] \
340 || ![string match "*data_symbol in *bintest.o*" $got] \
341 || ![string match "*common_symbol in *bintest.o*" $got] \
342 || [string match "*static_text_symbol in *bintest.o*" $got] \
343 || [string match "*static_data_symbol in *bintest.o*" $got] \
344 || [string match "*external_symbol in *bintest.o*" $got] } {
352 # Test POSIX-compatible argument parsing.
354 proc argument_parsing { } {
360 set testname "ar argument parsing"
362 if ![binutils_assemble $srcdir/$subdir/bintest.s tmpdir/bintest.o] {
367 if [is_remote host] {
369 set objfile [remote_download host tmpdir/bintest.o]
370 remote_file host delete $archive
372 set archive tmpdir/artest.a
373 set objfile tmpdir/bintest.o
376 remote_file build delete tmpdir/artest.a
378 set got [binutils_run $AR "-r -c $archive ${objfile}"]
379 if ![string match "" $got] {
387 # Test building a deterministic archive.
389 proc deterministic_archive { } {
396 set testname "ar deterministic archive"
398 if ![binutils_assemble $srcdir/$subdir/bintest.s tmpdir/bintest.o] {
403 if [is_remote host] {
405 set objfile [remote_download host tmpdir/bintest.o]
406 remote_file host delete $archive
408 set archive tmpdir/artest.a
409 set objfile tmpdir/bintest.o
412 remote_file build delete tmpdir/artest.a
414 set got [binutils_run $AR "rcD $archive ${objfile}"]
415 if ![string match "" $got] {
420 set got [binutils_run $AR "tv $archive"]
421 # This only checks the file mode and uid/gid. We can't easily match
422 # date because it's printed with the user's timezone.
423 if ![string match "rw-r--r-- 0/0 *bintest.o*" $got] {
431 proc unique_symbol { } {
438 set testname "ar unique symbol in archive"
440 if ![binutils_assemble $srcdir/$subdir/unique.s tmpdir/unique.o] {
444 if [is_remote host] {
446 set objfile [remote_download host tmpdir/unique.o]
447 remote_file host delete $archive
449 set archive tmpdir/artest.a
450 set objfile tmpdir/unique.o
453 remote_file build delete tmpdir/artest.a
455 set got [binutils_run $AR "-s -r -c $archive ${objfile}"]
456 if ![string match "" $got] {
461 set got [binutils_run $NM "--print-armap $archive"]
462 if ![string match "*foo in *unique.o*" $got] {
470 # Test deleting an element.
472 proc delete_an_element { } {
478 set testname "ar deleting an element"
480 if ![binutils_assemble $srcdir/$subdir/bintest.s tmpdir/bintest.o] {
485 if [is_remote host] {
487 set objfile [remote_download host tmpdir/bintest.o]
488 remote_file host delete $archive
490 set archive tmpdir/artest.a
491 set objfile tmpdir/bintest.o
494 remote_file build delete tmpdir/artest.a
496 set got [binutils_run $AR "-r -c $archive ${objfile}"]
497 if ![string match "" $got] {
502 set got [binutils_run $AR "-d $archive ${objfile}"]
503 if ![string match "" $got] {
511 # Test moving an element.
513 proc move_an_element { } {
519 set testname "ar moving an element"
521 if ![binutils_assemble $srcdir/$subdir/bintest.s tmpdir/bintest.o] {
526 if [is_remote host] {
528 set objfile [remote_download host tmpdir/bintest.o]
529 remote_file host delete $archive
531 set archive tmpdir/artest.a
532 set objfile tmpdir/bintest.o
535 remote_file build delete tmpdir/artest.a
537 set got [binutils_run $AR "-r -c $archive ${objfile}"]
538 if ![string match "" $got] {
543 set got [binutils_run $AR "-m $archive ${objfile}"]
544 if ![string match "" $got] {
557 thin_archive_with_nested
559 deterministic_archive
563 && ![istarget "*-*-hpux*"]
564 && ![istarget "msp*-*-*"] } {