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