Home | History | Annotate | Download | only in tests
      1 #!/bin/bash
      2 
      3 [ -f testing.sh ] && . testing.sh
      4 
      5 # We need to test name and file padding.
      6 # This means all possible values of strlen(name)+1 % 4,
      7 # plus file sizes of at least 0-4.
      8 
      9 touch a bb ccc dddd
     10 testing "name padding" "cpio -o -H newc|cpio -it" "a\nbb\nccc\ndddd\n" "" "a\nbb\nccc\ndddd\n"
     11 rm a bb ccc dddd
     12 
     13 touch a
     14 printf '1' >b
     15 printf '22' >c
     16 printf '333' >d
     17 testing "file padding" "cpio -o -H newc|cpio -it" "a\nb\nc\nd\n" "" "a\nb\nc\nd\n"
     18 rm a b c d
     19 
     20 touch a
     21 printf '1' >bb
     22 printf '22' >ccc
     23 printf '333' >dddd
     24 # With the proper padding, header length, and file length, 
     25 # the relevant bit should be here:
     26 # 110*5 + 4*3 + 2 + 6*3 = 550 + 12 + 20 = 582
     27 # files are padded to n*4, names are padded to 2 + n*4 due to the header length
     28 testing "archive length" "cpio -o -H newc|dd ibs=2 skip=291 count=5 2>/dev/null" "TRAILER!!!" "" "a\nbb\nccc\ndddd\n"
     29 testing "archive magic" "cpio -o -H newc|dd ibs=2 count=3 2>/dev/null" "070701" "" "a\n"
     30 # check name length (8 bytes before the empty "crc")
     31 testing "name length" "cpio -o -H newc|dd ibs=2 skip=47 count=4 2>/dev/null" "00000002" "" "a\n"
     32 rm a bb ccc dddd
     33 
     34 # archive dangling symlinks and empty files even if we cannot open them
     35 touch a; chmod a-rwx a; ln -s a/cant b
     36 testing "archives unreadable empty files" "cpio -o -H newc|cpio -it" "a\nb\n" "" "a\nb\n"
     37 chmod u+rw a; rm -f a b
     38 
     39 
     40