| 1 | # Copyright 1995, 1997, 2002, 2004, 2007, 2008 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 { } { |
| 34 | global AR |
| 35 | global host_triplet |
| 36 | |
| 37 | set testname "ar long file names" |
| 38 | |
| 39 | set n1 "abcdefghijklmnopqrstuvwxyz1" |
| 40 | set n2 "abcdefghijklmnopqrstuvwxyz2" |
| 41 | set file1 tmpdir/$n1 |
| 42 | set file2 tmpdir/$n2 |
| 43 | |
| 44 | remote_file build delete $file1 |
| 45 | remote_file host delete $n1 |
| 46 | |
| 47 | # Some file systems truncate file names at 14 characters, which |
| 48 | # makes it impossible to run this test. Check for that now. |
| 49 | set status [catch "set f [open tmpdir/$n1 w]" errs] |
| 50 | if { $status != 0 } { |
| 51 | verbose -log "open tmpdir/$n1 returned $errs" |
| 52 | unsupported $testname |
| 53 | return |
| 54 | } |
| 55 | puts $f "first" |
| 56 | close $f |
| 57 | |
| 58 | remote_file build delete $file2 |
| 59 | remote_file host delete $n2 |
| 60 | |
| 61 | set status [catch "set f [open tmpdir/$n2 w]" errs] |
| 62 | if { $status != 0 } { |
| 63 | verbose -log "open tmpdir/$n2 returned $errs" |
| 64 | unsupported $testname |
| 65 | return |
| 66 | } |
| 67 | puts $f "second" |
| 68 | close $f |
| 69 | |
| 70 | if [is_remote host] { |
| 71 | set file1 [remote_download host $file1] |
| 72 | set file2 [remote_download host $file2] |
| 73 | set dest artest.a |
| 74 | } else { |
| 75 | set dest tmpdir/artest.a |
| 76 | } |
| 77 | |
| 78 | remote_file host delete $dest |
| 79 | |
| 80 | set got [binutils_run $AR "rc $dest $file1 $file2"] |
| 81 | if [is_remote host] { |
| 82 | remote_upload host $file1 tmpdir/$n1 |
| 83 | } |
| 84 | |
| 85 | set f [open tmpdir/$n1 r] |
| 86 | gets $f string |
| 87 | close $f |
| 88 | if ![string match "first" $string] { |
| 89 | verbose -log "reading tmpdir/$n1 returned $string" |
| 90 | unsupported $testname |
| 91 | return |
| 92 | } |
| 93 | |
| 94 | remote_file host delete $dest |
| 95 | set got [binutils_run $AR "rc $dest $file1 $file2"] |
| 96 | |
| 97 | if ![string match "" $got] { |
| 98 | fail $testname |
| 99 | return |
| 100 | } |
| 101 | |
| 102 | remote_file build delete tmpdir/$n1 |
| 103 | remote_file build delete tmpdir/$n2 |
| 104 | |
| 105 | set got [binutils_run $AR "t $dest"] |
| 106 | regsub "\[\r\n \t\]*$" "$got" "" got |
| 107 | if ![string match "$n1*$n2" $got] { |
| 108 | fail $testname |
| 109 | return |
| 110 | } |
| 111 | |
| 112 | if [is_remote host] { |
| 113 | remote_file host delete $file1 |
| 114 | remote_file host delete $file2 |
| 115 | } |
| 116 | |
| 117 | verbose -log "$AR x $dest" |
| 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 | if [is_remote host] { |
| 127 | remote_upload host $n1 tmpdir/$n1 |
| 128 | remote_upload host $n2 tmpdir/$n2 |
| 129 | set file1 tmpdir/$n1 |
| 130 | set file2 tmpdir/$n2 |
| 131 | } else { |
| 132 | set file1 $n1 |
| 133 | set file2 $n2 |
| 134 | } |
| 135 | |
| 136 | if ![file exists $file1] { |
| 137 | verbose -log "$file1 does not exist" |
| 138 | fail $testname |
| 139 | return |
| 140 | } |
| 141 | if ![file exists $file2] { |
| 142 | verbose -log "$file2 does not exist" |
| 143 | fail $testname |
| 144 | return |
| 145 | } |
| 146 | |
| 147 | set f [open $file1 r] |
| 148 | if { [gets $f line] == -1 || $line != "first" } { |
| 149 | verbose -log "$file1 contents:" |
| 150 | verbose -log "$line" |
| 151 | close $f |
| 152 | fail $testname |
| 153 | return |
| 154 | } |
| 155 | close $f |
| 156 | |
| 157 | set f [open $file2 r] |
| 158 | if { [gets $f line] == -1 || $line != "second" } { |
| 159 | verbose -log "$file2 contents:" |
| 160 | verbose -log "$line" |
| 161 | close $f |
| 162 | fail $testname |
| 163 | return |
| 164 | } |
| 165 | close $f |
| 166 | |
| 167 | file delete $file1 $file2 |
| 168 | pass $testname |
| 169 | } |
| 170 | |
| 171 | # Test building the symbol table. |
| 172 | |
| 173 | proc symbol_table { } { |
| 174 | global AR |
| 175 | global AS |
| 176 | global NM |
| 177 | global srcdir |
| 178 | global subdir |
| 179 | |
| 180 | set testname "ar symbol table" |
| 181 | |
| 182 | if ![binutils_assemble $srcdir/$subdir/bintest.s tmpdir/bintest.o] { |
| 183 | unresolved $testname |
| 184 | return |
| 185 | } |
| 186 | |
| 187 | if [is_remote host] { |
| 188 | set archive artest.a |
| 189 | set objfile [remote_download host tmpdir/bintest.o] |
| 190 | remote_file host delete $archive |
| 191 | } else { |
| 192 | set archive tmpdir/artest.a |
| 193 | set objfile tmpdir/bintest.o |
| 194 | } |
| 195 | |
| 196 | remote_file build delete tmpdir/artest.a |
| 197 | |
| 198 | set got [binutils_run $AR "rc $archive ${objfile}"] |
| 199 | if ![string match "" $got] { |
| 200 | fail $testname |
| 201 | return |
| 202 | } |
| 203 | |
| 204 | set got [binutils_run $NM "--print-armap $archive"] |
| 205 | if { ![string match "*text_symbol in bintest.o*" $got] \ |
| 206 | || ![string match "*data_symbol in bintest.o*" $got] \ |
| 207 | || ![string match "*common_symbol in bintest.o*" $got] \ |
| 208 | || [string match "*static_text_symbol in bintest.o*" $got] \ |
| 209 | || [string match "*static_data_symbol in bintest.o*" $got] \ |
| 210 | || [string match "*external_symbol in bintest.o*" $got] } { |
| 211 | fail $testname |
| 212 | return |
| 213 | } |
| 214 | |
| 215 | pass $testname |
| 216 | } |
| 217 | |
| 218 | # Test building a thin archive. |
| 219 | |
| 220 | proc thin_archive { } { |
| 221 | global AR |
| 222 | global AS |
| 223 | global NM |
| 224 | global srcdir |
| 225 | global subdir |
| 226 | |
| 227 | set testname "ar thin archive" |
| 228 | |
| 229 | if ![binutils_assemble $srcdir/$subdir/bintest.s tmpdir/bintest.o] { |
| 230 | unresolved $testname |
| 231 | return |
| 232 | } |
| 233 | |
| 234 | if [is_remote host] { |
| 235 | set archive artest.a |
| 236 | set objfile [remote_download host tmpdir/bintest.o] |
| 237 | remote_file host delete $archive |
| 238 | } else { |
| 239 | set archive tmpdir/artest.a |
| 240 | set objfile tmpdir/bintest.o |
| 241 | } |
| 242 | |
| 243 | remote_file build delete tmpdir/artest.a |
| 244 | |
| 245 | set got [binutils_run $AR "rcT $archive ${objfile}"] |
| 246 | if ![string match "" $got] { |
| 247 | fail $testname |
| 248 | return |
| 249 | } |
| 250 | |
| 251 | set got [binutils_run $NM "--print-armap $archive"] |
| 252 | if { ![string match "*text_symbol in *bintest.o*" $got] \ |
| 253 | || ![string match "*data_symbol in *bintest.o*" $got] \ |
| 254 | || ![string match "*common_symbol in *bintest.o*" $got] \ |
| 255 | || [string match "*static_text_symbol in *bintest.o*" $got] \ |
| 256 | || [string match "*static_data_symbol in *bintest.o*" $got] \ |
| 257 | || [string match "*external_symbol in *bintest.o*" $got] } { |
| 258 | fail $testname |
| 259 | return |
| 260 | } |
| 261 | |
| 262 | pass $testname |
| 263 | } |
| 264 | |
| 265 | # Test building a thin archive with a nested archive. |
| 266 | |
| 267 | proc thin_archive_with_nested { } { |
| 268 | global AR |
| 269 | global AS |
| 270 | global NM |
| 271 | global srcdir |
| 272 | global subdir |
| 273 | |
| 274 | set testname "ar thin archive with nested archive" |
| 275 | |
| 276 | if ![binutils_assemble $srcdir/$subdir/bintest.s tmpdir/bintest.o] { |
| 277 | unresolved $testname |
| 278 | return |
| 279 | } |
| 280 | |
| 281 | if [is_remote host] { |
| 282 | set archive artest.a |
| 283 | set archive2 artest2.a |
| 284 | set objfile [remote_download host tmpdir/bintest.o] |
| 285 | remote_file host delete $archive |
| 286 | } else { |
| 287 | set archive tmpdir/artest.a |
| 288 | set archive2 tmpdir/artest2.a |
| 289 | set objfile tmpdir/bintest.o |
| 290 | } |
| 291 | |
| 292 | remote_file build delete tmpdir/artest.a |
| 293 | |
| 294 | set got [binutils_run $AR "rc $archive ${objfile}"] |
| 295 | if ![string match "" $got] { |
| 296 | fail $testname |
| 297 | return |
| 298 | } |
| 299 | |
| 300 | remote_file build delete tmpdir/artest2.a |
| 301 | |
| 302 | set got [binutils_run $AR "rcT $archive2 ${archive}"] |
| 303 | if ![string match "" $got] { |
| 304 | fail $testname |
| 305 | return |
| 306 | } |
| 307 | |
| 308 | set got [binutils_run $NM "--print-armap $archive"] |
| 309 | if { ![string match "*text_symbol in *bintest.o*" $got] \ |
| 310 | || ![string match "*data_symbol in *bintest.o*" $got] \ |
| 311 | || ![string match "*common_symbol in *bintest.o*" $got] \ |
| 312 | || [string match "*static_text_symbol in *bintest.o*" $got] \ |
| 313 | || [string match "*static_data_symbol in *bintest.o*" $got] \ |
| 314 | || [string match "*external_symbol in *bintest.o*" $got] } { |
| 315 | fail $testname |
| 316 | return |
| 317 | } |
| 318 | |
| 319 | pass $testname |
| 320 | } |
| 321 | |
| 322 | # Test POSIX-compatible argument parsing. |
| 323 | |
| 324 | proc argument_parsing { } { |
| 325 | global AR |
| 326 | global AS |
| 327 | global srcdir |
| 328 | global subdir |
| 329 | |
| 330 | set testname "ar argument parsing" |
| 331 | |
| 332 | if ![binutils_assemble $srcdir/$subdir/bintest.s tmpdir/bintest.o] { |
| 333 | unresolved $testname |
| 334 | return |
| 335 | } |
| 336 | |
| 337 | if [is_remote host] { |
| 338 | set archive artest.a |
| 339 | set objfile [remote_download host tmpdir/bintest.o] |
| 340 | remote_file host delete $archive |
| 341 | } else { |
| 342 | set archive tmpdir/artest.a |
| 343 | set objfile tmpdir/bintest.o |
| 344 | } |
| 345 | |
| 346 | remote_file build delete tmpdir/artest.a |
| 347 | |
| 348 | set got [binutils_run $AR "-r -c $archive ${objfile}"] |
| 349 | if ![string match "" $got] { |
| 350 | fail $testname |
| 351 | return |
| 352 | } |
| 353 | |
| 354 | pass $testname |
| 355 | } |
| 356 | |
| 357 | # Test building a deterministic archive. |
| 358 | |
| 359 | proc deterministic_archive { } { |
| 360 | global AR |
| 361 | global AS |
| 362 | global NM |
| 363 | global srcdir |
| 364 | global subdir |
| 365 | |
| 366 | set testname "ar deterministic archive" |
| 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 "rcD $archive ${objfile}"] |
| 385 | if ![string match "" $got] { |
| 386 | fail $testname |
| 387 | return |
| 388 | } |
| 389 | |
| 390 | set got [binutils_run $AR "tv $archive"] |
| 391 | # This only checks the file mode and uid/gid. We can't easily match |
| 392 | # date because it's printed with the user's timezone. |
| 393 | if ![string match "rw-r--r-- 0/0 *bintest.o*" $got] { |
| 394 | fail $testname |
| 395 | return |
| 396 | } |
| 397 | |
| 398 | pass $testname |
| 399 | } |
| 400 | |
| 401 | # Run the tests. |
| 402 | |
| 403 | long_filenames |
| 404 | symbol_table |
| 405 | thin_archive |
| 406 | thin_archive_with_nested |
| 407 | argument_parsing |
| 408 | deterministic_archive |