devices.test 3.9 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151
  1. #! /bin/sh
  2. # Copyright (C) 2002 by Martin Pool <mbp@samba.org>
  3. # This program is distributable under the terms of the GNU GPL (see
  4. # COPYING).
  5. # Test rsync handling of devices. This can only run if you're root.
  6. . "$suitedir/rsync.fns"
  7. chkfile="$scratchdir/rsync.chk"
  8. outfile="$scratchdir/rsync.out"
  9. # Build some hardlinks
  10. case $0 in
  11. *fake*)
  12. $RSYNC --version | grep ", xattrs" >/dev/null || test_skipped "Rsync needs xattrs for fake device tests"
  13. RSYNC="$RSYNC --fake-super"
  14. TLS_ARGS="$TLS_ARGS --fake-super"
  15. case "`xattr 2>&1`" in
  16. *--list:*)
  17. mknod() {
  18. fn="$1"
  19. case "$2" in
  20. p) mode=10644 ;;
  21. c) mode=20644 ;;
  22. b) mode=60644 ;;
  23. esac
  24. maj="${3:-0}"
  25. min="${4:-0}"
  26. touch "$fn"
  27. xattr -s 'rsync.%stat' "$mode $maj,$min 0:0" "$fn"
  28. }
  29. ;;
  30. *)
  31. mknod() {
  32. fn="$1"
  33. case "$2" in
  34. p) mode=10644 ;;
  35. c) mode=20644 ;;
  36. b) mode=60644 ;;
  37. esac
  38. maj="${3:-0}"
  39. min="${4:-0}"
  40. touch "$fn"
  41. setfattr -n 'user.rsync.%stat' -v "$mode $maj,$min 0:0" "$fn"
  42. }
  43. ;;
  44. esac
  45. ;;
  46. *)
  47. case `get_testuid` in
  48. '') ;; # If "id" failed, try to continue...
  49. 0) ;;
  50. *) if [ -f /usr/bin/fakeroot ]; then
  51. echo "Let's try re-running the script under fakeroot..."
  52. exec /usr/bin/fakeroot /bin/sh $RUNSHFLAGS "$0"
  53. fi
  54. test_skipped "Rsync needs root/fakeroot for device tests"
  55. ;;
  56. esac
  57. ;;
  58. esac
  59. # TODO: Need to test whether hardlinks are possible on this OS/filesystem
  60. mkdir "$fromdir"
  61. mkdir "$todir"
  62. mknod "$fromdir/char" c 41 67 || test_skipped "Can't create char device node"
  63. mknod "$fromdir/char2" c 42 68 || test_skipped "Can't create char device node"
  64. mknod "$fromdir/char3" c 42 69 || test_skipped "Can't create char device node"
  65. mknod "$fromdir/block" b 42 69 || test_skipped "Can't create block device node"
  66. mknod "$fromdir/block2" b 42 73 || test_skipped "Can't create block device node"
  67. mknod "$fromdir/block3" b 105 73 || test_skipped "Can't create block device node"
  68. ln "$fromdir/block3" "$fromdir/block2.5" || echo "Skipping hard-linked device test..."
  69. mkfifo "$fromdir/fifo" || mknod "$fromdir/fifo" p || test_skipped "Can't run mkfifo"
  70. # Work around time rounding/truncating issue by touching both files.
  71. touch -r "$fromdir/block" "$fromdir/block" "$fromdir/block2"
  72. $RSYNC -ai "$fromdir/block" "$todir/block2" \
  73. | tee "$outfile"
  74. cat <<EOT >"$chkfile"
  75. cD$all_plus block
  76. EOT
  77. diff $diffopt "$chkfile" "$outfile" || test_fail "test 1 failed"
  78. $RSYNC -ai "$fromdir/block2" "$todir/block" \
  79. | tee "$outfile"
  80. cat <<EOT >"$chkfile"
  81. cD$all_plus block2
  82. EOT
  83. diff $diffopt "$chkfile" "$outfile" || test_fail "test 2 failed"
  84. sleep 1
  85. $RSYNC -Di "$fromdir/block3" "$todir/block" \
  86. | tee "$outfile"
  87. cat <<EOT >"$chkfile"
  88. cDc.T.$dots block3
  89. EOT
  90. diff $diffopt "$chkfile" "$outfile" || test_fail "test 3 failed"
  91. $RSYNC -aiHvv "$fromdir/" "$todir/" \
  92. | tee "$outfile"
  93. filter_outfile
  94. cat <<EOT >"$chkfile"
  95. .d..t.$dots ./
  96. cDc.t.$dots block
  97. cDc...$dots block2
  98. cD$all_plus block3
  99. hD$all_plus block2.5 => block3
  100. cD$all_plus char
  101. cD$all_plus char2
  102. cD$all_plus char3
  103. cS$all_plus fifo
  104. EOT
  105. if test ! -r "$fromdir/block2.5"; then
  106. grep -v block2.5 <"$chkfile" >"$chkfile.new"
  107. mv "$chkfile.new" "$chkfile"
  108. fi
  109. diff $diffopt "$chkfile" "$outfile" || test_fail "test 4 failed"
  110. echo "check how the directory listings compare with diff:"
  111. echo ""
  112. ( cd "$fromdir" && rsync_ls_lR . ) > "$tmpdir/ls-from"
  113. ( cd "$todir" && rsync_ls_lR . ) > "$tmpdir/ls-to"
  114. diff $diffopt "$tmpdir/ls-from" "$tmpdir/ls-to"
  115. if test -r "$fromdir/block2.5"; then
  116. set -x
  117. $RSYNC -aii --link-dest="$todir" "$fromdir/" "$chkdir/" \
  118. | tee "$outfile"
  119. cat <<EOT >"$chkfile"
  120. cd$allspace ./
  121. hD$allspace block
  122. hD$allspace block2
  123. hD$allspace block2.5
  124. hD$allspace block3
  125. hD$allspace char
  126. hD$allspace char2
  127. hD$allspace char3
  128. hS$allspace fifo
  129. EOT
  130. diff $diffopt "$chkfile" "$outfile" || test_fail "test 5 failed"
  131. fi
  132. # The script would have aborted on error, so getting here means we've won.
  133. exit 0