cpio.tests 4.1 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160
  1. #!/bin/sh
  2. # Copyright 2008 by Denys Vlasenko
  3. # Licensed under GPLv2, see file LICENSE in this source tree.
  4. . ./testing.sh
  5. umask 022
  6. # ls -ln shows date. Need to remove that, it's variable.
  7. # sed: coalesce spaces
  8. # cut: remove date
  9. # grep: remove "total NNN" lines
  10. FILTER_LS="sed 's/ */ /g' | cut -d' ' -f 1-5,9- | grep -v '^total '"
  11. # newc cpio archive of directory cpio.testdir with empty x and y hardlinks
  12. hexdump="\
  13. \x42\x5a\x68\x39\x31\x41\x59\x26\x53\x59\x64\x1e\x91\x8c\x00\x00\
  14. \x48\x7f\x80\x4c\x48\x08\x00\x28\x01\xff\xe0\x3f\x24\x14\x00\x0e\
  15. \x20\xdc\x60\x20\x00\x92\x11\xea\xa0\x1a\x00\x00\x00\x03\x20\x8a\
  16. \x93\xd4\x9a\x68\x1a\x0d\x1e\x91\xa1\xa0\x06\x98\xe3\x5c\x2f\xd9\
  17. \x26\xa1\x25\x24\x20\xed\x47\xc7\x21\x40\x2b\x6e\xf2\xe6\xfe\x98\
  18. \x13\x68\xa8\xbd\x82\xb2\x4f\x26\x02\x24\x16\x5b\x22\x16\x72\x74\
  19. \x15\xcd\xc1\xa6\x9e\xa6\x5e\x6c\x16\x37\x35\x01\x99\xc4\x81\x21\
  20. \x29\x28\x4b\x69\x51\xa9\x3c\x1a\x9b\x0a\xe1\xe4\xb4\xaf\x85\x73\
  21. \xba\x23\x10\x59\xe8\xb3\xe1\xa1\x63\x05\x8c\x4f\xc5\xdc\x91\x4e\
  22. \x14\x24\x19\x07\xa4\x63\x00"
  23. user=$(id -u)
  24. group=$(id -g)
  25. rm -rf cpio.testdir cpio.testdir2 2>/dev/null
  26. # testing "test name" "command" "expected result" "file input" "stdin"
  27. optional FEATURE_LS_SORTFILES FEATURE_LS_TIMESTAMPS
  28. testing "cpio extracts zero-sized hardlinks" \
  29. "$ECHO -ne '$hexdump' | bzcat | cpio -i 2>&1; echo \$?;
  30. ls -ln cpio.testdir | $FILTER_LS" \
  31. "\
  32. 1 blocks
  33. 0
  34. -rw-r--r-- 2 $user $group 0 x
  35. -rw-r--r-- 2 $user $group 0 y
  36. " "" ""
  37. SKIP=
  38. test x"$SKIP_KNOWN_BUGS" = x"" && {
  39. # Currently fails. Numerous buglets: "1 blocks" versus "1 block",
  40. # does not list cpio.testdir/x and cpio.testdir/y
  41. testing "cpio lists hardlinks" \
  42. "$ECHO -ne '$hexdump' | bzcat | cpio -t 2>&1; echo \$?" \
  43. "\
  44. cpio.testdir
  45. cpio.testdir/x
  46. cpio.testdir/y
  47. 1 blocks
  48. 0
  49. " "" ""
  50. }
  51. # More complex case
  52. rm -rf cpio.testdir cpio.testdir2 2>/dev/null
  53. mkdir cpio.testdir
  54. touch cpio.testdir/solo
  55. touch cpio.testdir/empty
  56. echo x >cpio.testdir/nonempty
  57. ln cpio.testdir/empty cpio.testdir/empty1
  58. ln cpio.testdir/nonempty cpio.testdir/nonempty1
  59. mkdir cpio.testdir2
  60. optional FEATURE_CPIO_O LONG_OPTS FEATURE_LS_SORTFILES FEATURE_LS_TIMESTAMPS
  61. testing "cpio extracts zero-sized hardlinks 2" \
  62. "find cpio.testdir | cpio -H newc --create | (cd cpio.testdir2 && cpio -i 2>&1); echo \$?;
  63. ls -ln cpio.testdir2/cpio.testdir | $FILTER_LS" \
  64. "\
  65. 2 blocks
  66. 0
  67. -rw-r--r-- 2 $user $group 0 empty
  68. -rw-r--r-- 2 $user $group 0 empty1
  69. -rw-r--r-- 2 $user $group 2 nonempty
  70. -rw-r--r-- 2 $user $group 2 nonempty1
  71. -rw-r--r-- 1 $user $group 0 solo
  72. " "" ""
  73. SKIP=
  74. # Was trying to create "/usr/bin", correct is "usr/bin".
  75. rm -rf cpio.testdir
  76. optional FEATURE_CPIO_P
  77. testing "cpio -p with absolute paths" \
  78. "echo /usr/bin | cpio -dp cpio.testdir 2>&1; echo \$?;
  79. ls cpio.testdir" \
  80. "\
  81. 1 blocks
  82. 0
  83. usr
  84. " "" ""
  85. SKIP=
  86. # chown on a link was affecting file, dropping its suid/sgid bits
  87. rm -rf cpio.testdir
  88. optional FEATURE_CPIO_O FEATURE_STAT_FORMAT
  89. mkdir cpio.testdir
  90. touch cpio.testdir/file
  91. chmod 6755 cpio.testdir/file # sets suid/sgid bits
  92. ln -sf file cpio.testdir/link
  93. testing "cpio restores suid/sgid bits" \
  94. "cd cpio.testdir && { echo file; echo link; } | cpio -ovHnewc >pack.cpio && rm ???? && cpio -idmvu <pack.cpio 2>/dev/null;
  95. stat -c '%a %n' file" \
  96. "\
  97. file
  98. link
  99. 6755 file
  100. " "" ""
  101. SKIP=
  102. # avoid 'not created: newer or same age file exists' message for directories
  103. rm -rf cpio.testdir cpio.testdir2 2>/dev/null
  104. mkdir cpio.testdir
  105. testing "cpio extracts in existing directory" \
  106. "$ECHO -ne '$hexdump' | bzcat | cpio -id 2>&1; echo \$?" \
  107. "\
  108. 1 blocks
  109. 0
  110. " "" ""
  111. SKIP=
  112. optional FEATURE_CPIO_O
  113. testing "cpio uses by default uid/gid" \
  114. "echo $0 | cpio -o -H newc | cpio -tv 2>&1 | head -n1 | awk ' { print \$2 } '; echo \$?" \
  115. "\
  116. $user/$group
  117. 0
  118. " "" ""
  119. SKIP=
  120. optional FEATURE_CPIO_O
  121. testing "cpio -R with create" \
  122. "echo $0 | cpio -o -H newc -R 1234:5678 | cpio -tv 2>&1 | head -n1 | awk ' { print \$2 } '; echo \$?" \
  123. "\
  124. 1234/5678
  125. 0
  126. " "" ""
  127. SKIP=
  128. optional FEATURE_CPIO_O
  129. testing "cpio -R with extract" \
  130. "echo $0 | cpio -o -H newc | cpio -tv -R 8765:4321 2>&1 | head -n1 | awk ' { print \$2 } '; echo \$?" \
  131. "\
  132. 8765/4321
  133. 0
  134. " "" ""
  135. SKIP=
  136. # Clean up
  137. rm -rf cpio.testdir cpio.testdir2 2>/dev/null
  138. exit $FAILCOUNT