File:  [ELWIX - Embedded LightWeight unIX -] / embedaddon / rsync / testsuite / devices.test
Revision 1.1.1.3 (vendor branch): download - view: text, annotated - select for diffs - revision graph
Wed Mar 17 00:32:36 2021 UTC (3 years, 5 months ago) by misho
Branches: rsync, MAIN
CVS tags: v3_2_3, HEAD
rsync 3.2.3

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

FreeBSD-CVSweb <freebsd-cvsweb@FreeBSD.org>