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