Rather than literally "nobody", try using uid/gid = 65534 as
[rsync/rsync.git] / testsuite / rsync.fns
CommitLineData
d820215b
MP
1#! /bin/sh
2
3# Copyright (C) 2001 by Martin Pool <mbp@samba.org>
4
5# General-purpose test functions for rsync.
3a4c683f 6
0154b302
MP
7# This program is free software; you can redistribute it and/or modify
8# it under the terms of the GNU General Public License version
9# 2 as published by the Free Software Foundation.
10#
11# This program is distributed in the hope that it will be useful, but
12# WITHOUT ANY WARRANTY; without even the implied warranty of
13# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
14# Lesser General Public License for more details.
15#
16# You should have received a copy of the GNU Lesser General Public
17# License along with this program; if not, write to the Free Software
18# Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
19
20
3a4c683f
MP
21TMP="$scratchdir"
22FROM=${TMP}/from
23TO=${TMP}/to
3a4c683f 24LOG=${TMP}/log
3fedd74b 25RSYNC="$rsync_bin"
3a4c683f 26
2094283b 27# Berkley's nice.
96553aa7 28PATH="$PATH:/usr/ucb"
2094283b 29
3a4c683f
MP
30runtest() {
31 echo $ECHO_N "Test $1: $ECHO_C"
501972bf
MP
32 if eval "$2"
33 then
34 echo "${ECHO_T} done."
35 return 0
36 else
37 echo "${ECHO_T} failed!"
38 return 1
39 fi
3a4c683f
MP
40}
41
42printmsg() {
43 echo "$1"
44}
45
e052b21f 46
6773a779 47rsync_ls_lR() {
57835c00
MP
48 find "$@" -print | sort | xargs $TLS
49}
50
51
e052b21f
MP
52####################
53# Build test directories TO and FROM, with FROM full of files.
54
3a4c683f 55hands_setup() {
501972bf
MP
56 # Clean before creation
57 rm -rf $FROM
58 rm -rf $TO
3d807132
MP
59
60 [ -d $TMP ] || mkdir $TMP
3a4c683f
MP
61 [ -d $FROM ] || mkdir $FROM
62 [ -d $TO ] || mkdir $TO
63
e052b21f
MP
64 # On some BSD systems, the umask affects the mode of created
65 # symlinks, even though the mode apparently has no effect on how
66 # the links behave in the future, and it cannot be changed using
67 # chmod! rsync always sets its umask to 000 so that it can
68 # accurately recreate permissions, but this script is probably run
69 # with a different umask.
70
71 # This causes a little problem that "ls -l" of the two will not be
72 # the same. So, we need to set our umask before doing any creations.
73
3a4c683f
MP
74 # set up test data
75 touch ${FROM}/empty
76 mkdir ${FROM}/emptydir
e8ca5901 77
571a4b26 78 # a hundred lines of text or so
3d807132 79 rsync_ls_lR "${srcdir}" > ${FROM}/filelist
3a4c683f
MP
80
81 # This might fail on systems that don't have -n
82 echo $ECHO_N "This file has no trailing lf$ECHO_C" > ${FROM}/nolf
0154b302 83 umask 0
3a4c683f 84 ln -s nolf ${FROM}/nolf-symlink
4c80c473 85 umask 022
0154b302 86
4c80c473 87 cat $srcdir/*.c > ${FROM}/text
3a4c683f 88 mkdir ${FROM}/dir
4c80c473 89 cp ${FROM}/text ${FROM}/dir
3a4c683f
MP
90 mkdir ${FROM}/dir/subdir
91 mkdir ${FROM}/dir/subdir/subsubdir
92 ls -ltr /etc > ${FROM}/dir/subdir/subsubdir/etc-ltr-list
93 mkdir ${FROM}/dir/subdir/subsubdir2
94 ls -lt /bin > ${FROM}/dir/subdir/subsubdir2/bin-lt-list
7d691654 95
8f98c608
MP
96# echo testing head:
97# ls -lR ${srcdir} | head -10 || echo failed
3a4c683f 98}
3fedd74b
MP
99
100
3d807132
MP
101hands_cleanup() {
102 rm -r "$TMP"
103}
104
105
e052b21f 106
99cdaff7
MP
107
108####################
109# Many machines do not have "mkdir -p", so we have to build up long paths.
110# How boring.
111makepath () {
7c1b7890 112 echo " makepath $1"
99cdaff7
MP
113 p="$1"
114 (
115 # Absolut Unix.
116 if echo $p | grep '^/' >/dev/null
117 then
118 cd /
119 fi
120
121 # This will break if $1 contains a space.
122 for c in `echo $p | tr '/' ' '`
123 do
112e7311
MP
124 if [ -d "$c" ] || mkdir "$c"
125 then
126 cd "$c" || return $?
127 else
128 echo "failed to create $c" >&2; return $?
129 fi
99cdaff7
MP
130 done
131 )
132}
133
134
135
3fedd74b
MP
136###########################
137# Run a test (in '$1') then compare directories $2 and $3 to see if
138# there are any difference. If there are, explain them.
139
f494f286
MP
140# So normally basically $1 should be an rsync command, and $2 and $3
141# the source and destination directories. This is only good when you
142# expect to transfer the whole directory exactly as is. If some files
143# should be excluded, you might need to use something else.
144
3fedd74b 145checkit() {
3fedd74b 146 failed=
3fedd74b 147
cf72f204
MP
148 # We can just write everything to stdout/stderr, because the
149 # wrapper hides it unless there is a problem.
150
151 echo "Running: \"$1\""
152 eval "$1"
3fedd74b
MP
153 status=$?
154 if [ $status != 0 ]; then
155 failed="YES";
156 fi
157
cf72f204
MP
158 echo "-------------"
159 echo "check how the files compare with diff:"
160 echo ""
d58e4c27
MP
161 for f in `cd "$2"; find . -type f -print `
162 do
371d1c36 163 diff -c "$2"/"$f" "$3"/"$f" || failed=YES
d58e4c27
MP
164 done
165
cf72f204
MP
166 echo "-------------"
167 echo "check how the directory listings compare with diff:"
168 echo ""
169 ( cd "$2" && rsync_ls_lR . ) > ${TMP}/ls-from
170 ( cd "$3" && rsync_ls_lR . ) > ${TMP}/ls-to
171 diff -c ${TMP}/ls-from ${TMP}/ls-to || failed=YES
3fedd74b 172 if [ -z "${failed}" ] ; then
3fedd74b
MP
173 return 0
174 else
3fedd74b
MP
175 return 1
176 fi
177}
178
863dff51
MP
179
180# In fact, we need a more general feature of capturing all stderr/log files,
181# and dumping them if something goes wrong.
182
183checkforlogs() {
184 # skip it if we're under debian-test
185 if test -n "${Debian}" ; then return 0 ; fi
186
187 if [ -f $1 -a -s $1 ] ; then
188 echo "Failures have occurred. $1 follows:" >&2
189 cat $1 >&2
190 exit 1
191 fi
192}
193
d2094cc3 194
4a7cb3e8 195build_rsyncd_conf() {
d2094cc3
MP
196 # Build an appropriate configuration file
197 conf="$scratchdir/test-rsyncd.conf"
198 echo "building configuration $conf"
199
200 port=2612
201 pidfile="$scratchdir/rsyncd.pid"
202 logfile="$scratchdir/rsyncd.log"
203
204 cat >$conf <<EOF
3aae15ec 205# rsyncd configuration file autogenerated by $0
d2094cc3 206
3aae15ec
MP
207pid file = $pidfile
208use chroot = no
209hosts allow = localhost, 127.0.0.1
210log file = $logfile
d2094cc3 211
98c1b325
MP
212# We don't know if this machine has "nobody" or "nogroup", so use the quasi-canonical
213# values of (uint16_t) -2.
214
215uid = 65534
216gid = 65534
217
2e6c7f45
MP
218[test-from]
219 path = $FROM
3aae15ec 220 read only = yes
d2094cc3 221
2e6c7f45
MP
222[test-to]
223 path = $TO
3aae15ec 224 read only = no
d2094cc3
MP
225EOF
226}
227
228
3cd2af41
MP
229build_symlinks() {
230 fromdir="$scratchdir/from"
231 todir="$scratchdir/to"
232 mkdir "$fromdir"
233 date >"$fromdir/referent"
234 ln -s referent "$fromdir/relative"
235 ln -s "$fromdir/referent" "$fromdir/absolute"
236 ln -s nonexistent "$fromdir/dangling"
1db8b61d 237 ln -s "$srcdir/rsync.c" "$fromdir/unsafe"
3cd2af41
MP
238}
239
240test_fail() {
241 echo "$@" >&2
242 exit 1
243}
244
a217ad30
MP
245test_skipped() {
246 echo "$@" >&2
7d821932 247 echo "$@" > "$TMP/whyskipped"
a217ad30
MP
248 exit 77
249}
250
be2f866b
MP
251# It failed, but we expected that. don't dump out error logs,
252# because most users won't want to see them. But do leave
253# the working directory around.
254test_xfail() {
255 echo "$@" >&2
256 exit 78
257}
258
d96d3893
MP
259# Test whether something is a link, allowing for shell peculiarities
260is_a_link() {
261 test -L "$1" || test -h "$1" || /usr/bin/test -L "$1" || /usr/bin/test -h "$1"
262}
263
3d807132
MP
264# be reproducible
265umask 077