1 # Copyright 1995, 1997, 2002, 2004, 2007, 2008, 2009, 2010, 2012
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 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
129 set exec_output [binutils_run $bfdtest1 "$dest"]
130 if ![string match "" $exec_output] {
131 verbose -log $exec_output
132 fail "$testname (bfdtest1)"
136 if [is_remote host] {
137 remote_upload host $n1 tmpdir/$n1
138 remote_upload host $n2 tmpdir/$n2
146 if ![file exists $file1] {
147 verbose -log "$file1 does not exist"
151 if ![file exists $file2] {
152 verbose -log "$file2 does not exist"
157 set f [open $file1 r]
158 if { [gets $f line] == -1 || $line != "first" } {
159 verbose -log "$file1 contents:"
167 set f [open $file2 r]
168 if { [gets $f line] == -1 || $line != "second" } {
169 verbose -log "$file2 contents:"
177 file delete $file1 $file2
181 # Test building the symbol table.
183 proc symbol_table { } {
190 set testname "ar symbol table"
192 if ![binutils_assemble $srcdir/$subdir/bintest.s tmpdir/bintest.o] {
197 if [is_remote host] {
199 set objfile [remote_download host tmpdir/bintest.o]
200 remote_file host delete $archive
202 set archive tmpdir/artest.a
203 set objfile tmpdir/bintest.o
206 remote_file build delete tmpdir/artest.a
208 set got [binutils_run $AR "rc $archive ${objfile}"]
209 if ![string match "" $got] {
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] } {
228 # Test building a thin archive.
230 proc thin_archive { } {
238 set testname "ar thin archive"
240 if ![binutils_assemble $srcdir/$subdir/bintest.s tmpdir/bintest.o] {
245 if [is_remote host] {
247 set objfile [remote_download host tmpdir/bintest.o]
248 remote_file host delete $archive
250 set archive tmpdir/artest.a
251 set objfile tmpdir/bintest.o
254 remote_file build delete tmpdir/artest.a
256 set got [binutils_run $AR "rcT $archive ${objfile}"]
257 if ![string match "" $got] {
262 set exec_output [binutils_run $bfdtest1 "$archive"]
263 if ![string match "" $exec_output] {
264 verbose -log $exec_output
265 fail "$testname (bfdtest1)"
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] } {
283 # Test building a thin archive with a nested archive.
285 proc thin_archive_with_nested { } {
293 set testname "ar thin archive with nested archive"
295 if ![binutils_assemble $srcdir/$subdir/bintest.s tmpdir/bintest.o] {
300 if [is_remote host] {
302 set archive2 artest2.a
303 set objfile [remote_download host tmpdir/bintest.o]
304 remote_file host delete $archive
306 set archive tmpdir/artest.a
307 set archive2 tmpdir/artest2.a
308 set objfile tmpdir/bintest.o
311 remote_file build delete tmpdir/artest.a
313 set got [binutils_run $AR "rc $archive ${objfile}"]
314 if ![string match "" $got] {
319 remote_file build delete tmpdir/artest2.a
321 set got [binutils_run $AR "rcT $archive2 ${archive}"]
322 if ![string match "" $got] {
327 set exec_output [binutils_run $bfdtest1 "$archive"]
328 if ![string match "" $exec_output] {
329 verbose -log $exec_output
330 fail "$testname (bfdtest1)"
334 set exec_output [binutils_run $bfdtest1 "$archive2"]
335 if ![string match "" $exec_output] {
336 verbose -log $exec_output
337 fail "$testname (bfdtest1)"
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] } {
355 # Test POSIX-compatible argument parsing.
357 proc argument_parsing { } {
363 set testname "ar argument parsing"
365 if ![binutils_assemble $srcdir/$subdir/bintest.s tmpdir/bintest.o] {
370 if [is_remote host] {
372 set objfile [remote_download host tmpdir/bintest.o]
373 remote_file host delete $archive
375 set archive tmpdir/artest.a
376 set objfile tmpdir/bintest.o
379 remote_file build delete tmpdir/artest.a
381 set got [binutils_run $AR "-r -c $archive ${objfile}"]
382 if ![string match "" $got] {
390 # Test building a deterministic archive.
392 proc deterministic_archive { } {
399 set testname "ar deterministic archive"
401 if ![binutils_assemble $srcdir/$subdir/bintest.s tmpdir/bintest.o] {
406 if [is_remote host] {
408 set objfile [remote_download host tmpdir/bintest.o]
409 remote_file host delete $archive
411 set archive tmpdir/artest.a
412 set objfile tmpdir/bintest.o
415 remote_file build delete tmpdir/artest.a
417 set got [binutils_run $AR "rcD $archive ${objfile}"]
418 if ![string match "" $got] {
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] {
434 proc unique_symbol { } {
441 set testname "ar unique symbol in archive"
443 if ![binutils_assemble $srcdir/$subdir/unique.s tmpdir/unique.o] {
447 if [is_remote host] {
449 set objfile [remote_download host tmpdir/unique.o]
450 remote_file host delete $archive
452 set archive tmpdir/artest.a
453 set objfile tmpdir/unique.o
456 remote_file build delete tmpdir/artest.a
458 set got [binutils_run $AR "-s -r -c $archive ${objfile}"]
459 if ![string match "" $got] {
464 set got [binutils_run $NM "--print-armap $archive"]
465 if ![string match "*foo in *unique.o*" $got] {
473 # Test deleting an element.
475 proc delete_an_element { } {
481 set testname "ar deleting an element"
483 if ![binutils_assemble $srcdir/$subdir/bintest.s tmpdir/bintest.o] {
488 if [is_remote host] {
490 set objfile [remote_download host tmpdir/bintest.o]
491 remote_file host delete $archive
493 set archive tmpdir/artest.a
494 set objfile tmpdir/bintest.o
497 remote_file build delete tmpdir/artest.a
499 set got [binutils_run $AR "-r -c $archive ${objfile}"]
500 if ![string match "" $got] {
505 set got [binutils_run $AR "-d $archive ${objfile}"]
506 if ![string match "" $got] {
514 # Test moving an element.
516 proc move_an_element { } {
522 set testname "ar moving an element"
524 if ![binutils_assemble $srcdir/$subdir/bintest.s tmpdir/bintest.o] {
529 if [is_remote host] {
531 set objfile [remote_download host tmpdir/bintest.o]
532 remote_file host delete $archive
534 set archive tmpdir/artest.a
535 set objfile tmpdir/bintest.o
538 remote_file build delete tmpdir/artest.a
540 set got [binutils_run $AR "-r -c $archive ${objfile}"]
541 if ![string match "" $got] {
546 set got [binutils_run $AR "-m $archive ${objfile}"]
547 if ![string match "" $got] {
560 thin_archive_with_nested
562 deterministic_archive
566 && ![istarget "*-*-hpux*"]
567 && ![istarget "msp*-*-*"] } {