Fixed some itemized logging failures:
[rsync/rsync.git] / testsuite / devices.test
CommitLineData
355b8bcd
MP
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
b0e9bafc 10. "$suitedir/rsync.fns"
355b8bcd 11
9ac35913
WD
12chkfile="$scratchdir/rsync.chk"
13outfile="$scratchdir/rsync.out"
14
355b8bcd
MP
15# Build some hardlinks
16
9557eaba
WD
17case $0 in
18*fake*)
19 $RSYNC --version | grep ", xattrs" >/dev/null || test_skipped "Rsync needs xattrs for fake device tests"
9439c0cb 20 RSYNC="$RSYNC --fake-super"
db9c9e27 21 TLS_ARGS=--fake-super
9439c0cb
WD
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
648859bd 52 ;;
9557eaba
WD
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 ;;
f5450e79
WD
65esac
66
355b8bcd
MP
67# TODO: Need to test whether hardlinks are possible on this OS/filesystem
68
69mkdir "$fromdir"
9ac35913 70mkdir "$todir"
9439c0cb
WD
71mknod "$fromdir/char" c 41 67 || test_skipped "Can't create char device node"
72mknod "$fromdir/char2" c 42 68 || test_skipped "Can't create char device node"
73mknod "$fromdir/char3" c 42 69 || test_skipped "Can't create char device node"
74mknod "$fromdir/block" b 42 69 || test_skipped "Can't create block device node"
75mknod "$fromdir/block2" b 42 73 || test_skipped "Can't create block device node"
76mknod "$fromdir/block3" b 105 73 || test_skipped "Can't create block device node"
9ac35913 77ln "$fromdir/block3" "$fromdir/block2.5" || echo "Skipping hard-linked device test..."
9439c0cb 78mkfifo "$fromdir/fifo" || mknod "$fromdir/fifo" p || test_skipped "Can't run mkfifo"
9ac35913
WD
79touch -r "$fromdir/block" "$fromdir/block2"
80
1ed9018e 81$RSYNC -ait "$fromdir/block" "$todir/block2" \
9ac35913
WD
82 | tee "$outfile"
83cat <<EOT >"$chkfile"
fc29efc3 84cD$all_plus block
9ac35913
WD
85EOT
86diff $diffopt "$chkfile" "$outfile" || test_fail "test 1 failed"
87
1ed9018e 88$RSYNC -ait "$fromdir/block2" "$todir/block" \
9ac35913
WD
89 | tee "$outfile"
90cat <<EOT >"$chkfile"
fc29efc3 91cD$all_plus block2
9ac35913
WD
92EOT
93diff $diffopt "$chkfile" "$outfile" || test_fail "test 2 failed"
94
95sleep 1
96
97$RSYNC -Di "$fromdir/block3" "$todir/block" \
98 | tee "$outfile"
99cat <<EOT >"$chkfile"
1ed9018e 100cDc.T.$dots block3
9ac35913
WD
101EOT
102diff $diffopt "$chkfile" "$outfile" || test_fail "test 3 failed"
103
104$RSYNC -aiHvv "$fromdir/" "$todir/" \
105 | tee "$outfile"
106filter_outfile
107cat <<EOT >"$chkfile"
fc29efc3 108.d..t.$dots ./
1ed9018e
WD
109cDc.t.$dots block
110cDc...$dots block2
fc29efc3
WD
111cD$all_plus block3
112hD$all_plus block2.5 => block3
113cD$all_plus char
114cD$all_plus char2
115cD$all_plus char3
116cS$all_plus fifo
9ac35913 117EOT
9439c0cb
WD
118if test ! -r "$fromdir/block2.5"; then
119 sed -e '/block2\.5/d' <"$chkfile" >"$chkfile.new"
9ac35913
WD
120 mv "$chkfile.new" "$chkfile"
121fi
122diff $diffopt "$chkfile" "$outfile" || test_fail "test 4 failed"
355b8bcd 123
9ac35913
WD
124echo "check how the directory listings compare with diff:"
125echo ""
126( cd "$fromdir" && rsync_ls_lR . ) > "$tmpdir/ls-from"
127( cd "$todir" && rsync_ls_lR . ) > "$tmpdir/ls-to"
128diff $diffopt "$tmpdir/ls-from" "$tmpdir/ls-to"
355b8bcd 129
083f75ee
WD
130if test -b "$fromdir/block2.5"; then
131 set -x
132 $RSYNC -aii --link-dest="$todir" "$fromdir/" "$chkdir/" \
133 | tee "$outfile"
134 cat <<EOT >"$chkfile"
fc29efc3
WD
135cd$allspace ./
136hD$allspace block
137hD$allspace block2
138hD$allspace block2.5
139hD$allspace block3
140hD$allspace char
141hD$allspace char2
142hD$allspace char3
143hS$allspace fifo
083f75ee
WD
144EOT
145 diff $diffopt "$chkfile" "$outfile" || test_fail "test 4 failed"
146fi
147
05118158 148# The script would have aborted on error, so getting here means we've won.
355b8bcd 149exit 0