tizen 2.4 release
[external/binutils.git] / binutils / testsuite / binutils-all / ar.exp
1 #   Copyright (C) 1995-2014 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 # send_user "Version [binutil_version $AR]"
30
31 # Test long file name support
32
33 proc long_filenames { bfdtests } {
34     global AR
35     global host_triplet
36     global base_dir
37
38     set testname "ar long file names"
39
40     set n1 "abcdefghijklmnopqrstuvwxyz1"
41     set n2 "abcdefghijklmnopqrstuvwxyz2"
42     set file1 tmpdir/$n1
43     set file2 tmpdir/$n2
44
45     remote_file build delete $file1
46     remote_file host delete $n1
47
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]
51     if { $status != 0 } {
52         verbose -log "open tmpdir/$n1 returned $errs"
53         unsupported $testname
54         return
55     }
56     puts $f "first"
57     close $f
58
59     remote_file build delete $file2
60     remote_file host delete $n2
61
62     set status [catch "set f [open tmpdir/$n2 w]" errs]
63     if { $status != 0 } {
64         verbose -log "open tmpdir/$n2 returned $errs"
65         unsupported $testname
66         return
67     }
68     puts $f "second"
69     close $f
70
71     if [is_remote host] {
72         set file1 [remote_download host $file1]
73         set file2 [remote_download host $file2]
74         set dest artest.a
75     } else {
76         set dest tmpdir/artest.a
77     }
78
79     remote_file host delete $dest
80
81     set got [binutils_run $AR "rc $dest $file1 $file2"]
82     if [is_remote host] {
83         remote_upload host $file1 tmpdir/$n1
84     }
85
86     set f [open tmpdir/$n1 r]
87     gets $f string
88     close $f
89     if ![string match "first" $string] {
90         verbose -log "reading tmpdir/$n1 returned $string"
91         unsupported $testname
92         return
93     }
94
95     remote_file host delete $dest
96     set got [binutils_run $AR "rc $dest $file1 $file2"]
97
98     if ![string match "" $got] {
99         fail $testname
100         return
101     }
102
103     remote_file build delete tmpdir/$n1
104     remote_file build delete tmpdir/$n2
105
106     set got [binutils_run $AR "t $dest"]
107     regsub "\[\r\n \t\]*$" "$got" "" got
108     if ![string match "$n1*$n2" $got] {
109         fail $testname
110         return
111     }
112     
113     if [is_remote host] {
114         remote_file host delete $file1
115         remote_file host delete $file2
116     }
117
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
122         fail $testname
123         return
124     }
125
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)"
131             return
132         }
133     }
134
135     if [is_remote host] {
136         remote_upload host $n1 tmpdir/$n1
137         remote_upload host $n2 tmpdir/$n2
138         set file1 tmpdir/$n1
139         set file2 tmpdir/$n2
140     } else {
141         set file1 $n1
142         set file2 $n2
143     }
144
145     if ![file exists $file1] {
146         verbose -log "$file1 does not exist"
147         fail $testname
148         return
149     }
150     if ![file exists $file2] {
151         verbose -log "$file2 does not exist"
152         fail $testname
153         return
154     }
155
156     set f [open $file1 r]
157     if { [gets $f line] == -1 || $line != "first" } {
158         verbose -log "$file1 contents:"
159         verbose -log "$line"
160         close $f
161         fail $testname
162         return
163     }
164     close $f
165
166     set f [open $file2 r]
167     if { [gets $f line] == -1 || $line != "second" } {
168         verbose -log "$file2 contents:"
169         verbose -log "$line"
170         close $f
171         fail $testname
172         return
173     }
174     close $f
175
176     file delete $file1 $file2
177     pass $testname
178 }
179
180 # Test building the symbol table.
181
182 proc symbol_table { } {
183     global AR
184     global AS
185     global NM
186     global srcdir
187     global subdir
188
189     set testname "ar symbol table"
190
191     if ![binutils_assemble $srcdir/$subdir/bintest.s tmpdir/bintest.o] {
192         unresolved $testname
193         return
194     }
195
196     if [is_remote host] {
197         set archive artest.a
198         set objfile [remote_download host tmpdir/bintest.o]
199         remote_file host delete $archive
200     } else {
201         set archive tmpdir/artest.a
202         set objfile tmpdir/bintest.o
203     }
204
205     remote_file build delete tmpdir/artest.a
206
207     set got [binutils_run $AR "rc $archive ${objfile}"]
208     if ![string match "" $got] {
209         fail $testname
210         return
211     }
212
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] } {
220         fail $testname
221         return
222     }
223
224     pass $testname
225 }
226
227 # Test building a thin archive.
228
229 proc thin_archive { bfdtests } {
230     global AR
231     global AS
232     global NM
233     global srcdir
234     global subdir
235     global base_dir
236
237     set testname "ar thin archive"
238
239     if ![binutils_assemble $srcdir/$subdir/bintest.s tmpdir/bintest.o] {
240         unresolved $testname
241         return
242     }
243
244     if [is_remote host] {
245         set archive artest.a
246         set objfile [remote_download host tmpdir/bintest.o]
247         remote_file host delete $archive
248     } else {
249         set archive tmpdir/artest.a
250         set objfile tmpdir/bintest.o
251     }
252
253     remote_file build delete tmpdir/artest.a
254
255     set got [binutils_run $AR "rcT $archive ${objfile}"]
256     if ![string match "" $got] {
257         fail $testname
258         return
259     }
260
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)"
266             return
267         }
268     }
269
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] } {
277         fail $testname
278         return
279     }
280
281     pass $testname
282 }
283
284 # Test building a thin archive with a nested archive.
285
286 proc thin_archive_with_nested { bfdtests } {
287     global AR
288     global AS
289     global NM
290     global srcdir
291     global subdir
292     global base_dir
293
294     set testname "ar thin archive with nested archive"
295
296     if ![binutils_assemble $srcdir/$subdir/bintest.s tmpdir/bintest.o] {
297         unresolved $testname
298         return
299     }
300
301     if [is_remote host] {
302         set archive artest.a
303         set archive2 artest2.a
304         set objfile [remote_download host tmpdir/bintest.o]
305         remote_file host delete $archive
306     } else {
307         set archive tmpdir/artest.a
308         set archive2 tmpdir/artest2.a
309         set objfile tmpdir/bintest.o
310     }
311
312     remote_file build delete tmpdir/artest.a
313
314     set got [binutils_run $AR "rc $archive ${objfile}"]
315     if ![string match "" $got] {
316         fail $testname
317         return
318     }
319
320     remote_file build delete tmpdir/artest2.a
321
322     set got [binutils_run $AR "rcT $archive2 ${archive}"]
323     if ![string match "" $got] {
324         fail $testname
325         return
326     }
327
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)"
333             return
334         }
335
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)"
340             return
341         }
342     }
343
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] } {
351         fail $testname
352         return
353     }
354
355     pass $testname
356 }
357
358 # Test POSIX-compatible argument parsing.
359
360 proc argument_parsing { } {
361     global AR
362     global AS
363     global srcdir
364     global subdir
365
366     set testname "ar argument parsing"
367
368     if ![binutils_assemble $srcdir/$subdir/bintest.s tmpdir/bintest.o] {
369         unresolved $testname
370         return
371     }
372
373     if [is_remote host] {
374         set archive artest.a
375         set objfile [remote_download host tmpdir/bintest.o]
376         remote_file host delete $archive
377     } else {
378         set archive tmpdir/artest.a
379         set objfile tmpdir/bintest.o
380     }
381
382     remote_file build delete tmpdir/artest.a
383
384     set got [binutils_run $AR "-r -c $archive ${objfile}"]
385     if ![string match "" $got] {
386         fail $testname
387         return
388     }
389
390     pass $testname
391 }
392
393 # Test building a deterministic archive.
394
395 proc deterministic_archive { } {
396     global AR
397     global AS
398     global NM
399     global srcdir
400     global subdir
401
402     set testname "ar deterministic archive"
403
404     if ![binutils_assemble $srcdir/$subdir/bintest.s tmpdir/bintest.o] {
405         unresolved $testname
406         return
407     }
408
409     if [is_remote host] {
410         set archive artest.a
411         set objfile [remote_download host tmpdir/bintest.o]
412         remote_file host delete $archive
413     } else {
414         set archive tmpdir/artest.a
415         set objfile tmpdir/bintest.o
416     }
417
418     remote_file build delete tmpdir/artest.a
419
420     set got [binutils_run $AR "rcD $archive ${objfile}"]
421     if ![string match "" $got] {
422         fail $testname
423         return
424     }
425
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] {
430         fail $testname
431         return
432     }
433
434     pass $testname
435 }
436
437 proc unique_symbol { } {
438     global AR
439     global AS
440     global NM
441     global srcdir
442     global subdir
443
444     set testname "ar unique symbol in archive"
445
446     if ![binutils_assemble $srcdir/$subdir/unique.s tmpdir/unique.o] {
447         unresolved $testname
448     }
449
450     if [is_remote host] {
451         set archive artest.a
452         set objfile [remote_download host tmpdir/unique.o]
453         remote_file host delete $archive
454     } else {
455         set archive tmpdir/artest.a
456         set objfile tmpdir/unique.o
457     }
458
459     remote_file build delete tmpdir/artest.a
460
461     set got [binutils_run $AR "-s -r -c $archive ${objfile}"]
462     if ![string match "" $got] {
463         fail $testname
464         return
465     }
466
467     set got [binutils_run $NM "--print-armap $archive"]
468     if ![string match "*foo in *unique.o*" $got] {
469         fail $testname
470         return
471     }
472
473     pass $testname
474 }
475
476 # Test deleting an element.
477
478 proc delete_an_element { } {
479     global AR
480     global AS
481     global srcdir
482     global subdir
483
484     set testname "ar deleting an element"
485
486     if ![binutils_assemble $srcdir/$subdir/bintest.s tmpdir/bintest.o] {
487         unresolved $testname
488         return
489     }
490
491     if [is_remote host] {
492         set archive artest.a
493         set objfile [remote_download host tmpdir/bintest.o]
494         remote_file host delete $archive
495     } else {
496         set archive tmpdir/artest.a
497         set objfile tmpdir/bintest.o
498     }
499
500     remote_file build delete tmpdir/artest.a
501
502     set got [binutils_run $AR "-r -c $archive ${objfile}"]
503     if ![string match "" $got] {
504         fail $testname
505         return
506     }
507
508     set got [binutils_run $AR "-d $archive ${objfile}"]
509     if ![string match "" $got] {
510         fail $testname
511         return
512     }
513
514     pass $testname
515 }
516
517 # Test moving an element.
518
519 proc move_an_element { } {
520     global AR
521     global AS
522     global srcdir
523     global subdir
524
525     set testname "ar moving an element"
526
527     if ![binutils_assemble $srcdir/$subdir/bintest.s tmpdir/bintest.o] {
528         unresolved $testname
529         return
530     }
531
532     if [is_remote host] {
533         set archive artest.a
534         set objfile [remote_download host tmpdir/bintest.o]
535         remote_file host delete $archive
536     } else {
537         set archive tmpdir/artest.a
538         set objfile tmpdir/bintest.o
539     }
540
541     remote_file build delete tmpdir/artest.a
542
543     set got [binutils_run $AR "-r -c $archive ${objfile}"]
544     if ![string match "" $got] {
545         fail $testname
546         return
547     }
548
549     set got [binutils_run $AR "-m $archive ${objfile}"]
550     if ![string match "" $got] {
551         fail $testname
552         return
553     }
554
555     pass $testname
556 }
557
558 # Run the tests.
559
560 # Only run the bfdtest checks if the programs exist.  Since these
561 # programs are built but not installed, running the testsuite on an
562 # installed toolchain will produce ERRORs about missing bfdtest1 and
563 # bfdtest2 executables.
564 if { [file exists $base_dir/bfdtest1] && [file exists $base_dir/bfdtest2] } {
565     set bfdtests [list bfdtest1 bfdtest2]
566
567     long_filenames $bfdtests
568     thin_archive $bfdtests
569     thin_archive_with_nested $bfdtests
570 }
571
572 symbol_table
573 argument_parsing
574 deterministic_archive
575 delete_an_element
576 move_an_element
577
578 if { [is_elf_format]
579      && ![istarget "*-*-hpux*"]
580      && ![istarget "msp*-*-*"] } {
581     unique_symbol
582 }