1 # Copyright (C) 1995-2016 Free Software Foundation, Inc.
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 3 of the License, or
6 # (at your option) any later version.
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.
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., 51 Franklin Street - Fifth Floor, Boston, MA 02110-1301, USA.
17 # Please email any bugs, comments, and/or additions to this file to:
18 # bug-dejagnu@prep.ai.mit.edu
20 # Written by Ian Lance Taylor <ian@cygnus.com>
22 if ![is_remote host] {
23 if {[which $AR] == 0} then {
24 perror "$AR does not exist"
29 # send_user "Version [binutil_version $AR]"
31 # Test long file name support
33 proc long_filenames { bfdtests } {
38 set testname "ar long file names"
40 set n1 "abcdefghijklmnopqrstuvwxyz1"
41 set n2 "abcdefghijklmnopqrstuvwxyz2"
45 remote_file build delete $file1
46 remote_file host delete $n1
48 # Some file systems truncate file names at 14 characters, which
49 # makes it impossible to run this test. Check for that now.
50 set status [catch "set f [open tmpdir/$n1 w]" errs]
52 verbose -log "open tmpdir/$n1 returned $errs"
59 remote_file build delete $file2
60 remote_file host delete $n2
62 set status [catch "set f [open tmpdir/$n2 w]" errs]
64 verbose -log "open tmpdir/$n2 returned $errs"
72 set file1 [remote_download host $file1]
73 set file2 [remote_download host $file2]
76 set dest tmpdir/artest.a
79 remote_file host delete $dest
81 set got [binutils_run $AR "rc $dest $file1 $file2"]
83 remote_upload host $file1 tmpdir/$n1
86 set f [open tmpdir/$n1 r]
89 if ![string match "first" $string] {
90 verbose -log "reading tmpdir/$n1 returned $string"
95 remote_file host delete $dest
96 set got [binutils_run $AR "rc $dest $file1 $file2"]
98 if ![string match "" $got] {
103 remote_file build delete tmpdir/$n1
104 remote_file build delete tmpdir/$n2
106 set got [binutils_run $AR "t $dest"]
107 regsub "\[\r\n \t\]*$" "$got" "" got
108 if ![string match "$n1*$n2" $got] {
113 if [is_remote host] {
114 remote_file host delete $file1
115 remote_file host delete $file2
118 set exec_output [binutils_run $AR "x $dest"]
119 set exec_output [prune_warnings $exec_output]
120 if ![string match "" $exec_output] {
121 verbose -log $exec_output
126 foreach bfdtest $bfdtests {
127 set exec_output [binutils_run "$base_dir/$bfdtest" "$dest"]
128 if ![string match "" $exec_output] {
129 verbose -log $exec_output
130 fail "$testname ($bfdtest)"
135 if [is_remote host] {
136 remote_upload host $n1 tmpdir/$n1
137 remote_upload host $n2 tmpdir/$n2
145 if ![file exists $file1] {
146 verbose -log "$file1 does not exist"
150 if ![file exists $file2] {
151 verbose -log "$file2 does not exist"
156 set f [open $file1 r]
157 if { [gets $f line] == -1 || $line != "first" } {
158 verbose -log "$file1 contents:"
166 set f [open $file2 r]
167 if { [gets $f line] == -1 || $line != "second" } {
168 verbose -log "$file2 contents:"
176 file delete $file1 $file2
180 # Test building the symbol table.
182 proc symbol_table { } {
189 set testname "ar symbol table"
191 if ![binutils_assemble $srcdir/$subdir/bintest.s tmpdir/bintest.o] {
196 if [is_remote host] {
198 set objfile [remote_download host tmpdir/bintest.o]
199 remote_file host delete $archive
201 set archive tmpdir/artest.a
202 set objfile tmpdir/bintest.o
205 remote_file build delete tmpdir/artest.a
207 set got [binutils_run $AR "rc $archive ${objfile}"]
208 if ![string match "" $got] {
213 set got [binutils_run $NM "--print-armap $archive"]
214 if { ![string match "*text_symbol in bintest.o*" $got] \
215 || ![string match "*data_symbol in bintest.o*" $got] \
216 || ![string match "*common_symbol in bintest.o*" $got] \
217 || [string match "*static_text_symbol in bintest.o*" $got] \
218 || [string match "*static_data_symbol in bintest.o*" $got] \
219 || [string match "*external_symbol in bintest.o*" $got] } {
227 # Test building a thin archive.
229 proc thin_archive { bfdtests } {
237 set testname "ar thin archive"
239 if ![binutils_assemble $srcdir/$subdir/bintest.s tmpdir/bintest.o] {
244 if [is_remote host] {
246 set objfile [remote_download host tmpdir/bintest.o]
247 remote_file host delete $archive
249 set archive tmpdir/artest.a
250 set objfile tmpdir/bintest.o
253 remote_file build delete tmpdir/artest.a
255 set got [binutils_run $AR "rcT $archive ${objfile}"]
256 if ![string match "" $got] {
261 foreach bfdtest $bfdtests {
262 set exec_output [binutils_run "$base_dir/$bfdtest" "$archive"]
263 if ![string match "" $exec_output] {
264 verbose -log $exec_output
265 fail "$testname ($bfdtest)"
270 set got [binutils_run $NM "--print-armap $archive"]
271 if { ![string match "*text_symbol in *bintest.o*" $got] \
272 || ![string match "*data_symbol in *bintest.o*" $got] \
273 || ![string match "*common_symbol in *bintest.o*" $got] \
274 || [string match "*static_text_symbol in *bintest.o*" $got] \
275 || [string match "*static_data_symbol in *bintest.o*" $got] \
276 || [string match "*external_symbol in *bintest.o*" $got] } {
284 # Test building a thin archive with a nested archive.
286 proc thin_archive_with_nested { bfdtests } {
294 set testname "ar thin archive with nested archive"
296 if ![binutils_assemble $srcdir/$subdir/bintest.s tmpdir/bintest.o] {
301 if [is_remote host] {
303 set archive2 artest2.a
304 set objfile [remote_download host tmpdir/bintest.o]
305 remote_file host delete $archive
307 set archive tmpdir/artest.a
308 set archive2 tmpdir/artest2.a
309 set objfile tmpdir/bintest.o
312 remote_file build delete tmpdir/artest.a
314 set got [binutils_run $AR "rc $archive ${objfile}"]
315 if ![string match "" $got] {
320 remote_file build delete tmpdir/artest2.a
322 set got [binutils_run $AR "rcT $archive2 ${archive}"]
323 if ![string match "" $got] {
328 foreach bfdtest $bfdtests {
329 set exec_output [binutils_run "$base_dir/$bfdtest" "$archive"]
330 if ![string match "" $exec_output] {
331 verbose -log $exec_output
332 fail "$testname ($bfdtest)"
336 set exec_output [binutils_run "$base_dir/$bfdtest" "$archive2"]
337 if ![string match "" $exec_output] {
338 verbose -log $exec_output
339 fail "$testname ($bfdtest)"
344 set got [binutils_run $NM "--print-armap $archive"]
345 if { ![string match "*text_symbol in *bintest.o*" $got] \
346 || ![string match "*data_symbol in *bintest.o*" $got] \
347 || ![string match "*common_symbol in *bintest.o*" $got] \
348 || [string match "*static_text_symbol in *bintest.o*" $got] \
349 || [string match "*static_data_symbol in *bintest.o*" $got] \
350 || [string match "*external_symbol in *bintest.o*" $got] } {
358 # Test POSIX-compatible argument parsing.
360 proc argument_parsing { } {
366 set testname "ar argument parsing"
368 if ![binutils_assemble $srcdir/$subdir/bintest.s tmpdir/bintest.o] {
373 if [is_remote host] {
375 set objfile [remote_download host tmpdir/bintest.o]
376 remote_file host delete $archive
378 set archive tmpdir/artest.a
379 set objfile tmpdir/bintest.o
382 remote_file build delete tmpdir/artest.a
384 set got [binutils_run $AR "-r -c $archive ${objfile}"]
385 if ![string match "" $got] {
393 # Test building a deterministic archive.
395 proc deterministic_archive { } {
402 set testname "ar deterministic archive"
404 if ![binutils_assemble $srcdir/$subdir/bintest.s tmpdir/bintest.o] {
409 if [is_remote host] {
411 set objfile [remote_download host tmpdir/bintest.o]
412 remote_file host delete $archive
414 set archive tmpdir/artest.a
415 set objfile tmpdir/bintest.o
418 remote_file build delete tmpdir/artest.a
420 set got [binutils_run $AR "rcD $archive ${objfile}"]
421 if ![string match "" $got] {
426 set got [binutils_run $AR "tv $archive"]
427 # This only checks the file mode and uid/gid. We can't easily match
428 # date because it's printed with the user's timezone.
429 if ![string match "rw-r--r-- 0/0 *bintest.o*" $got] {
437 proc unique_symbol { } {
444 set testname "ar unique symbol in archive"
446 if ![binutils_assemble $srcdir/$subdir/unique.s tmpdir/unique.o] {
450 if [is_remote host] {
452 set objfile [remote_download host tmpdir/unique.o]
453 remote_file host delete $archive
455 set archive tmpdir/artest.a
456 set objfile tmpdir/unique.o
459 remote_file build delete tmpdir/artest.a
461 set got [binutils_run $AR "-s -r -c $archive ${objfile}"]
462 if ![string match "" $got] {
467 set got [binutils_run $NM "--print-armap $archive"]
468 if ![string match "*foo in *unique.o*" $got] {
476 # Test deleting an element.
478 proc delete_an_element { } {
484 set testname "ar deleting an element"
486 if ![binutils_assemble $srcdir/$subdir/bintest.s tmpdir/bintest.o] {
491 if [is_remote host] {
493 set objfile [remote_download host tmpdir/bintest.o]
494 remote_file host delete $archive
496 set archive tmpdir/artest.a
497 set objfile tmpdir/bintest.o
500 remote_file build delete tmpdir/artest.a
502 set got [binutils_run $AR "-r -c $archive ${objfile}"]
503 if ![string match "" $got] {
508 set got [binutils_run $AR "-d $archive ${objfile}"]
509 if ![string match "" $got] {
517 # Test moving an element.
519 proc move_an_element { } {
525 set testname "ar moving an element"
527 if ![binutils_assemble $srcdir/$subdir/bintest.s tmpdir/bintest.o] {
532 if [is_remote host] {
534 set objfile [remote_download host tmpdir/bintest.o]
535 remote_file host delete $archive
537 set archive tmpdir/artest.a
538 set objfile tmpdir/bintest.o
541 remote_file build delete tmpdir/artest.a
543 set got [binutils_run $AR "-r -c $archive ${objfile}"]
544 if ![string match "" $got] {
549 set got [binutils_run $AR "-m $archive ${objfile}"]
550 if ![string match "" $got] {
558 # PR 19775: Test creating and listing archives with an empty element.
560 proc empty_archive { } {
565 set testname "archive with empty element"
567 # FIXME: There ought to be a way to dynamically create an empty file.
568 set empty $srcdir/$subdir/empty
570 if [is_remote host] {
572 set objfile [remote_download host $empty]
573 remote_file host delete $archive
575 set archive tmpdir/artest.a
579 remote_file build delete tmpdir/artest.a
581 set got [binutils_run $AR "-r -c $archive ${objfile}"]
582 if ![string match "" $got] {
587 # This commmand used to fail with: "Malformed archive".
588 set got [binutils_run $AR "-t $archive"]
589 if ![string match "empty
" $got] {
599 # Only run the bfdtest checks if the programs exist. Since these
600 # programs are built but not installed, running the testsuite on an
601 # installed toolchain will produce ERRORs about missing bfdtest1 and
602 # bfdtest2 executables.
603 if { [file exists $base_dir/bfdtest1] && [file exists $base_dir/bfdtest2] } {
604 set bfdtests [list bfdtest1 bfdtest2]
606 long_filenames $bfdtests
607 thin_archive $bfdtests
608 thin_archive_with_nested $bfdtests
613 deterministic_archive
619 && ![istarget "*-*-hpux*"]
620 && ![istarget "msp*-*-*"] } {