Fixed some itemized logging failures:
[rsync/rsync.git] / testsuite / devices.test
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=--fake-super
22     case "`xattr 2>&1`" in
23     *--list:*)
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     *)
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             setfattr -n 'user.rsync.%stat' -v "$mode $maj,$min 0:0" "$fn"
49         }
50         ;;
51     esac
52     ;;
53 *)
54     case `id -u` in
55     '') ;; # If "id" failed, try to continue...
56     0)  ;;
57     *)  if [ -f /usr/bin/fakeroot ]; then
58             echo "Let's try re-running the script under fakeroot..."
59             exec /usr/bin/fakeroot /bin/sh $RUNSHFLAGS "$0"
60         fi
61         test_skipped "Rsync needs root/fakeroot for device tests"
62         ;;
63     esac
64     ;;
65 esac
66
67 # TODO: Need to test whether hardlinks are possible on this OS/filesystem
68
69 mkdir "$fromdir"
70 mkdir "$todir"
71 mknod "$fromdir/char" c 41 67  || test_skipped "Can't create char device node"
72 mknod "$fromdir/char2" c 42 68  || test_skipped "Can't create char device node"
73 mknod "$fromdir/char3" c 42 69  || test_skipped "Can't create char device node"
74 mknod "$fromdir/block" b 42 69 || test_skipped "Can't create block device node"
75 mknod "$fromdir/block2" b 42 73 || test_skipped "Can't create block device node"
76 mknod "$fromdir/block3" b 105 73 || test_skipped "Can't create block device node"
77 ln "$fromdir/block3" "$fromdir/block2.5" || echo "Skipping hard-linked device test..."
78 mkfifo "$fromdir/fifo" || mknod "$fromdir/fifo" p || test_skipped "Can't run mkfifo"
79 touch -r "$fromdir/block" "$fromdir/block2"
80
81 $RSYNC -ait "$fromdir/block" "$todir/block2" \
82     | tee "$outfile"
83 cat <<EOT >"$chkfile"
84 cD$all_plus block
85 EOT
86 diff $diffopt "$chkfile" "$outfile" || test_fail "test 1 failed"
87
88 $RSYNC -ait "$fromdir/block2" "$todir/block" \
89     | tee "$outfile"
90 cat <<EOT >"$chkfile"
91 cD$all_plus block2
92 EOT
93 diff $diffopt "$chkfile" "$outfile" || test_fail "test 2 failed"
94
95 sleep 1
96
97 $RSYNC -Di "$fromdir/block3" "$todir/block" \
98     | tee "$outfile"
99 cat <<EOT >"$chkfile"
100 cDc.T.$dots block3
101 EOT
102 diff $diffopt "$chkfile" "$outfile" || test_fail "test 3 failed"
103
104 $RSYNC -aiHvv "$fromdir/" "$todir/" \
105     | tee "$outfile"
106 filter_outfile
107 cat <<EOT >"$chkfile"
108 .d..t.$dots ./
109 cDc.t.$dots block
110 cDc...$dots block2
111 cD$all_plus block3
112 hD$all_plus block2.5 => block3
113 cD$all_plus char
114 cD$all_plus char2
115 cD$all_plus char3
116 cS$all_plus fifo
117 EOT
118 if test ! -r "$fromdir/block2.5"; then
119     sed -e '/block2\.5/d' <"$chkfile" >"$chkfile.new"
120     mv "$chkfile.new" "$chkfile"
121 fi
122 diff $diffopt "$chkfile" "$outfile" || test_fail "test 4 failed"
123
124 echo "check how the directory listings compare with diff:"
125 echo ""
126 ( cd "$fromdir" && rsync_ls_lR . ) > "$tmpdir/ls-from"
127 ( cd "$todir" && rsync_ls_lR . ) > "$tmpdir/ls-to"
128 diff $diffopt "$tmpdir/ls-from" "$tmpdir/ls-to"
129
130 if test -b "$fromdir/block2.5"; then
131     set -x
132     $RSYNC -aii --link-dest="$todir" "$fromdir/" "$chkdir/" \
133         | tee "$outfile"
134     cat <<EOT >"$chkfile"
135 cd$allspace ./
136 hD$allspace block
137 hD$allspace block2
138 hD$allspace block2.5
139 hD$allspace block3
140 hD$allspace char
141 hD$allspace char2
142 hD$allspace char3
143 hS$allspace fifo
144 EOT
145     diff $diffopt "$chkfile" "$outfile" || test_fail "test 4 failed"
146 fi
147
148 # The script would have aborted on error, so getting here means we've won.
149 exit 0