3 # Copyright (C) 2001 by Martin Pool <mbp@samba.org>
5 # General-purpose test functions for rsync.
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.
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.
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.
28 echo $ECHO_N "Test $1: $ECHO_C"
31 echo "${ECHO_T} done."
34 echo "${ECHO_T} failed!"
45 find "$@" -print | sort | xargs $TLS
50 # Build test directories TO and FROM, with FROM full of files.
53 # Clean before creation
57 [ -d $TMP ] || mkdir $TMP
58 [ -d $FROM ] || mkdir $FROM
59 [ -d $TO ] || mkdir $TO
61 # On some BSD systems, the umask affects the mode of created
62 # symlinks, even though the mode apparently has no effect on how
63 # the links behave in the future, and it cannot be changed using
64 # chmod! rsync always sets its umask to 000 so that it can
65 # accurately recreate permissions, but this script is probably run
66 # with a different umask.
68 # This causes a little problem that "ls -l" of the two will not be
69 # the same. So, we need to set our umask before doing any creations.
73 mkdir ${FROM}/emptydir
75 # a hundred lines of text or so
76 rsync_ls_lR "${srcdir}" > ${FROM}/filelist
78 # This might fail on systems that don't have -n
79 echo $ECHO_N "This file has no trailing lf$ECHO_C" > ${FROM}/nolf
81 ln -s nolf ${FROM}/nolf-symlink
84 cat $srcdir/*.c > ${FROM}/text
86 cp ${FROM}/text ${FROM}/dir
87 mkdir ${FROM}/dir/subdir
88 mkdir ${FROM}/dir/subdir/subsubdir
89 ls -ltr /etc > ${FROM}/dir/subdir/subsubdir/etc-ltr-list
90 mkdir ${FROM}/dir/subdir/subsubdir2
91 ls -lt /bin > ${FROM}/dir/subdir/subsubdir2/bin-lt-list
94 # ls -lR ${srcdir} | head -10 || echo failed
106 # Many machines do not have "mkdir -p", so we have to build up long paths.
113 if echo $p | grep '^/' >/dev/null
118 # This will break if $1 contains a space.
119 for c in `echo $p | tr '/' ' '`
121 if [ -d "$c" ] || mkdir "$c"
125 echo "failed to create $c" >&2; return $?
133 ###########################
134 # Run a test (in '$1') then compare directories $2 and $3 to see if
135 # there are any difference. If there are, explain them.
140 # the log accumulates all output; we only display it if there
143 echo "Running: \"$1\"" >${log}
145 eval "$1" >>${log} 2>&1
147 if [ $status != 0 ]; then
151 echo "-------------">>${log}
152 echo "check how the files compare with diff:">>${log}
154 diff -cr $2 $3 >>${log} 2>&1 || failed=YES
155 echo "-------------">>${log}
156 echo "check how the directory listings compare with diff:">>${log}
158 ( cd "$2" && rsync_ls_lR . ) > ${TMP}/ls-from 2>>${log}
159 ( cd "$3" && rsync_ls_lR . ) > ${TMP}/ls-to 2>>${log}
160 diff -c ${TMP}/ls-from ${TMP}/ls-to >>${log} 2>&1 || failed=YES
161 if [ -z "${failed}" ] ; then
172 # In fact, we need a more general feature of capturing all stderr/log files,
173 # and dumping them if something goes wrong.
176 # skip it if we're under debian-test
177 if test -n "${Debian}" ; then return 0 ; fi
179 if [ -f $1 -a -s $1 ] ; then
180 echo "Failures have occurred. $1 follows:" >&2
187 build_rsyncd_conf() {
188 # Build an appropriate configuration file
189 conf="$scratchdir/test-rsyncd.conf"
190 echo "building configuration $conf"
193 pidfile="$scratchdir/rsyncd.pid"
194 logfile="$scratchdir/rsyncd.log"
197 # rsyncd configuration file autogenerated by $0
201 hosts allow = localhost, 127.0.0.1
204 [test-from] = $scratchdir/daemon-from/
207 [test-to] = $scratchdir/daemon-to/