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 # send_user "Version [binutil_version $AR]"
32 # Test long file name support
34 proc long_filenames { bfdtests } {
39 set testname "ar long file names"
41 set n1 "abcdefghijklmnopqrstuvwxyz1"
42 set n2 "abcdefghijklmnopqrstuvwxyz2"
46 remote_file build delete $file1
47 remote_file host delete $n1
49 # Some file systems truncate file names at 14 characters, which
50 # makes it impossible to run this test. Check for that now.
51 set status [catch "set f [open tmpdir/$n1 w]" errs]
53 verbose -log "open tmpdir/$n1 returned $errs"
60 remote_file build delete $file2
61 remote_file host delete $n2
63 set status [catch "set f [open tmpdir/$n2 w]" errs]
65 verbose -log "open tmpdir/$n2 returned $errs"
73 set file1 [remote_download host $file1]
74 set file2 [remote_download host $file2]
77 set dest tmpdir/artest.a
80 remote_file host delete $dest
82 set got [binutils_run $AR "rc $dest $file1 $file2"]
84 remote_upload host $file1 tmpdir/$n1
87 set f [open tmpdir/$n1 r]
90 if ![string match "first" $string] {
91 verbose -log "reading tmpdir/$n1 returned $string"
96 remote_file host delete $dest
97 set got [binutils_run $AR "rc $dest $file1 $file2"]
99 if ![string match "" $got] {
104 remote_file build delete tmpdir/$n1
105 remote_file build delete tmpdir/$n2
107 set got [binutils_run $AR "t $dest"]
108 regsub "\[\r\n \t\]*$" "$got" "" got
109 if ![string match "$n1*$n2" $got] {
114 if [is_remote host] {
115 remote_file host delete $file1
116 remote_file host delete $file2
119 set exec_output [binutils_run $AR "x $dest"]
120 set exec_output [prune_warnings $exec_output]
121 if ![string match "" $exec_output] {
122 verbose -log $exec_output
127 foreach bfdtest $bfdtests {
128 set exec_output [binutils_run "$base_dir/$bfdtest" "$dest"]
129 if ![string match "" $exec_output] {
130 verbose -log $exec_output
131 fail "$testname ($bfdtest)"
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 { bfdtests } {
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 foreach bfdtest $bfdtests {
263 set exec_output [binutils_run "$base_dir/$bfdtest" "$archive"]
264 if ![string match "" $exec_output] {
265 verbose -log $exec_output
266 fail "$testname ($bfdtest)"
271 set got [binutils_run $NM "--print-armap $archive"]
272 if { ![string match "*text_symbol in *bintest.o*" $got] \
273 || ![string match "*data_symbol in *bintest.o*" $got] \
274 || ![string match "*common_symbol in *bintest.o*" $got] \
275 || [string match "*static_text_symbol in *bintest.o*" $got] \
276 || [string match "*static_data_symbol in *bintest.o*" $got] \
277 || [string match "*external_symbol in *bintest.o*" $got] } {
285 # Test building a thin archive with a nested archive.
287 proc thin_archive_with_nested { bfdtests } {
295 set testname "ar thin archive with nested archive"
297 if ![binutils_assemble $srcdir/$subdir/bintest.s tmpdir/bintest.o] {
302 if [is_remote host] {
304 set archive2 artest2.a
305 set objfile [remote_download host tmpdir/bintest.o]
306 remote_file host delete $archive
308 set archive tmpdir/artest.a
309 set archive2 tmpdir/artest2.a
310 set objfile tmpdir/bintest.o
313 remote_file build delete tmpdir/artest.a
315 set got [binutils_run $AR "rc $archive ${objfile}"]
316 if ![string match "" $got] {
321 remote_file build delete tmpdir/artest2.a
323 set got [binutils_run $AR "rcT $archive2 ${archive}"]
324 if ![string match "" $got] {
329 foreach bfdtest $bfdtests {
330 set exec_output [binutils_run "$base_dir/$bfdtest" "$archive"]
331 if ![string match "" $exec_output] {
332 verbose -log $exec_output
333 fail "$testname ($bfdtest)"
337 set exec_output [binutils_run "$base_dir/$bfdtest" "$archive2"]
338 if ![string match "" $exec_output] {
339 verbose -log $exec_output
340 fail "$testname ($bfdtest)"
345 set got [binutils_run $NM "--print-armap $archive"]
346 if { ![string match "*text_symbol in *bintest.o*" $got] \
347 || ![string match "*data_symbol in *bintest.o*" $got] \
348 || ![string match "*common_symbol in *bintest.o*" $got] \
349 || [string match "*static_text_symbol in *bintest.o*" $got] \
350 || [string match "*static_data_symbol in *bintest.o*" $got] \
351 || [string match "*external_symbol in *bintest.o*" $got] } {
359 # Test POSIX-compatible argument parsing.
361 proc argument_parsing { } {
367 set testname "ar argument parsing"
369 if ![binutils_assemble $srcdir/$subdir/bintest.s tmpdir/bintest.o] {
374 if [is_remote host] {
376 set objfile [remote_download host tmpdir/bintest.o]
377 remote_file host delete $archive
379 set archive tmpdir/artest.a
380 set objfile tmpdir/bintest.o
383 remote_file build delete tmpdir/artest.a
385 set got [binutils_run $AR "-r -c $archive ${objfile}"]
386 if ![string match "" $got] {
394 # Test building a deterministic archive.
396 proc deterministic_archive { } {
403 set testname "ar deterministic archive"
405 if ![binutils_assemble $srcdir/$subdir/bintest.s tmpdir/bintest.o] {
410 if [is_remote host] {
412 set objfile [remote_download host tmpdir/bintest.o]
413 remote_file host delete $archive
415 set archive tmpdir/artest.a
416 set objfile tmpdir/bintest.o
419 remote_file build delete tmpdir/artest.a
421 set got [binutils_run $AR "rcD $archive ${objfile}"]
422 if ![string match "" $got] {
427 set got [binutils_run $AR "tv $archive"]
428 # This only checks the file mode and uid/gid. We can't easily match
429 # date because it's printed with the user's timezone.
430 if ![string match "rw-r--r-- 0/0 *bintest.o*" $got] {
438 proc unique_symbol { } {
445 set testname "ar unique symbol in archive"
447 if ![binutils_assemble $srcdir/$subdir/unique.s tmpdir/unique.o] {
451 if [is_remote host] {
453 set objfile [remote_download host tmpdir/unique.o]
454 remote_file host delete $archive
456 set archive tmpdir/artest.a
457 set objfile tmpdir/unique.o
460 remote_file build delete tmpdir/artest.a
462 set got [binutils_run $AR "-s -r -c $archive ${objfile}"]
463 if ![string match "" $got] {
468 set got [binutils_run $NM "--print-armap $archive"]
469 if ![string match "*foo in *unique.o*" $got] {
477 # Test deleting an element.
479 proc delete_an_element { } {
485 set testname "ar deleting an element"
487 if ![binutils_assemble $srcdir/$subdir/bintest.s tmpdir/bintest.o] {
492 if [is_remote host] {
494 set objfile [remote_download host tmpdir/bintest.o]
495 remote_file host delete $archive
497 set archive tmpdir/artest.a
498 set objfile tmpdir/bintest.o
501 remote_file build delete tmpdir/artest.a
503 set got [binutils_run $AR "-r -c $archive ${objfile}"]
504 if ![string match "" $got] {
509 set got [binutils_run $AR "-d $archive ${objfile}"]
510 if ![string match "" $got] {
518 # Test moving an element.
520 proc move_an_element { } {
526 set testname "ar moving an element"
528 if ![binutils_assemble $srcdir/$subdir/bintest.s tmpdir/bintest.o] {
533 if [is_remote host] {
535 set objfile [remote_download host tmpdir/bintest.o]
536 remote_file host delete $archive
538 set archive tmpdir/artest.a
539 set objfile tmpdir/bintest.o
542 remote_file build delete tmpdir/artest.a
544 set got [binutils_run $AR "-r -c $archive ${objfile}"]
545 if ![string match "" $got] {
550 set got [binutils_run $AR "-m $archive ${objfile}"]
551 if ![string match "" $got] {
561 set bfdtests [list bfdtest1 bfdtest2]
563 long_filenames $bfdtests
565 thin_archive $bfdtests
566 thin_archive_with_nested $bfdtests
568 deterministic_archive
572 && ![istarget "*-*-hpux*"]
573 && ![istarget "msp*-*-*"] } {