cpio.tests 2.3 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283
  1. #!/bin/sh
  2. # Copyright 2008 by Denys Vlasenko
  3. # Licensed under GPL v2, see file LICENSE for details.
  4. . testing.sh
  5. # ls -ln shows date. Need to remove that, it's variable.
  6. # sed: coalesce spaces
  7. # cut: remove date
  8. FILTER_LS="sed 's/ */ /g' | cut -d' ' -f 1-5,9-"
  9. # newc cpio archive of directory cpio.testdir with empty x and y hardlinks
  10. hexdump="\
  11. \x42\x5a\x68\x39\x31\x41\x59\x26\x53\x59\x64\x1e\x91\x8c\x00\x00\
  12. \x48\x7f\x80\x4c\x48\x08\x00\x28\x01\xff\xe0\x3f\x24\x14\x00\x0e\
  13. \x20\xdc\x60\x20\x00\x92\x11\xea\xa0\x1a\x00\x00\x00\x03\x20\x8a\
  14. \x93\xd4\x9a\x68\x1a\x0d\x1e\x91\xa1\xa0\x06\x98\xe3\x5c\x2f\xd9\
  15. \x26\xa1\x25\x24\x20\xed\x47\xc7\x21\x40\x2b\x6e\xf2\xe6\xfe\x98\
  16. \x13\x68\xa8\xbd\x82\xb2\x4f\x26\x02\x24\x16\x5b\x22\x16\x72\x74\
  17. \x15\xcd\xc1\xa6\x9e\xa6\x5e\x6c\x16\x37\x35\x01\x99\xc4\x81\x21\
  18. \x29\x28\x4b\x69\x51\xa9\x3c\x1a\x9b\x0a\xe1\xe4\xb4\xaf\x85\x73\
  19. \xba\x23\x10\x59\xe8\xb3\xe1\xa1\x63\x05\x8c\x4f\xc5\xdc\x91\x4e\
  20. \x14\x24\x19\x07\xa4\x63\x00"
  21. user=$(id -u)
  22. group=$(id -g)
  23. rm -rf cpio.testdir cpio.testdir2 2>/dev/null
  24. # testing "test name" "command" "expected result" "file input" "stdin"
  25. testing "cpio extracts zero-sized hardlinks" \
  26. "echo -ne '$hexdump' | bzcat | cpio -i; echo \$?;
  27. ls -ln cpio.testdir | $FILTER_LS" \
  28. "\
  29. 1 blocks
  30. 0
  31. -rw-r--r-- 2 $user $group 0 x
  32. -rw-r--r-- 2 $user $group 0 y
  33. " \
  34. "" ""
  35. # Currently fails. Numerous: "1 blocks" versus "1 block",
  36. # "1 block" must go to stderr, does not list cpio.testdir/x and cpio.testdir/y
  37. testing "cpio lists hardlinks" \
  38. "echo -ne '$hexdump' | bzcat | cpio -t 2>&1; echo \$?" \
  39. "\
  40. 1 block
  41. cpio.testdir
  42. cpio.testdir/x
  43. cpio.testdir/y
  44. 0
  45. " \
  46. "" ""
  47. # More complex case
  48. rm -rf cpio.testdir cpio.testdir2 2>/dev/null
  49. mkdir cpio.testdir
  50. touch cpio.testdir/solo
  51. touch cpio.testdir/empty
  52. echo x >cpio.testdir/nonempty
  53. ln cpio.testdir/empty cpio.testdir/empty1
  54. ln cpio.testdir/nonempty cpio.testdir/nonempty1
  55. mkdir cpio.testdir2
  56. testing "cpio extracts zero-sized hardlinks 2" \
  57. "find cpio.testdir | cpio -H newc --create | (cd cpio.testdir2 && cpio -i); echo \$?;
  58. ls -ln cpio.testdir2/cpio.testdir | $FILTER_LS" \
  59. "\
  60. 0
  61. -rw-r--r-- 2 $user $group 0 empty
  62. -rw-r--r-- 2 $user $group 0 empty1
  63. -rw-r--r-- 2 $user $group 2 nonempty
  64. -rw-r--r-- 2 $user $group 2 nonempty1
  65. -rw-r--r-- 1 $user $group 0 solo
  66. " \
  67. "" ""
  68. # Clean up
  69. rm -rf cpio.testdir cpio.testdir2 2>/dev/null
  70. exit $FAILCOUNT