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