Bump version
[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
MP
26
27runtest() {
28 echo $ECHO_N "Test $1: $ECHO_C"
501972bf
MP
29 if eval "$2"
30 then
31 echo "${ECHO_T} done."
32 return 0
33 else
34 echo "${ECHO_T} failed!"
35 return 1
36 fi
3a4c683f
MP
37}
38
39printmsg() {
40 echo "$1"
41}
42
e052b21f 43
6773a779 44rsync_ls_lR() {
57835c00
MP
45 find "$@" -print | sort | xargs $TLS
46}
47
48
e052b21f
MP
49####################
50# Build test directories TO and FROM, with FROM full of files.
51
3a4c683f 52hands_setup() {
501972bf
MP
53 # Clean before creation
54 rm -rf $FROM
55 rm -rf $TO
3d807132
MP
56
57 [ -d $TMP ] || mkdir $TMP
3a4c683f
MP
58 [ -d $FROM ] || mkdir $FROM
59 [ -d $TO ] || mkdir $TO
60
e052b21f
MP
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.
67
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.
70
3a4c683f
MP
71 # set up test data
72 touch ${FROM}/empty
73 mkdir ${FROM}/emptydir
e8ca5901 74
571a4b26 75 # a hundred lines of text or so
3d807132 76 rsync_ls_lR "${srcdir}" > ${FROM}/filelist
3a4c683f
MP
77
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
0154b302 80 umask 0
3a4c683f 81 ln -s nolf ${FROM}/nolf-symlink
4c80c473 82 umask 022
0154b302 83
4c80c473 84 cat $srcdir/*.c > ${FROM}/text
3a4c683f 85 mkdir ${FROM}/dir
4c80c473 86 cp ${FROM}/text ${FROM}/dir
3a4c683f
MP
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
7d691654 92
8f98c608
MP
93# echo testing head:
94# ls -lR ${srcdir} | head -10 || echo failed
3a4c683f 95}
3fedd74b
MP
96
97
3d807132
MP
98hands_cleanup() {
99 rm -r "$TMP"
100}
101
102
e052b21f 103
99cdaff7
MP
104
105####################
106# Many machines do not have "mkdir -p", so we have to build up long paths.
107# How boring.
108makepath () {
7c1b7890 109 echo " makepath $1"
99cdaff7
MP
110 p="$1"
111 (
112 # Absolut Unix.
113 if echo $p | grep '^/' >/dev/null
114 then
115 cd /
116 fi
117
118 # This will break if $1 contains a space.
119 for c in `echo $p | tr '/' ' '`
120 do
112e7311
MP
121 if [ -d "$c" ] || mkdir "$c"
122 then
123 cd "$c" || return $?
124 else
125 echo "failed to create $c" >&2; return $?
126 fi
99cdaff7
MP
127 done
128 )
129}
130
131
132
3fedd74b
MP
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.
136
137checkit() {
138 log=${LOG}
139 failed=
140 # the log accumulates all output; we only display it if there
141 # is a problem.
142
143 echo "Running: \"$1\"" >${log}
144 echo "">>${log}
145 eval "$1" >>${log} 2>&1
146 status=$?
147 if [ $status != 0 ]; then
148 failed="YES";
149 fi
150
151 echo "-------------">>${log}
152 echo "check how the files compare with diff:">>${log}
153 echo "">>${log}
37c3cf43 154 diff -cr $2 $3 >>${log} 2>&1 || failed=YES
3fedd74b
MP
155 echo "-------------">>${log}
156 echo "check how the directory listings compare with diff:">>${log}
157 echo "">>${log}
3d807132
MP
158 ( cd "$2" && rsync_ls_lR . ) > ${TMP}/ls-from 2>>${log}
159 ( cd "$3" && rsync_ls_lR . ) > ${TMP}/ls-to 2>>${log}
37c3cf43 160 diff -c ${TMP}/ls-from ${TMP}/ls-to >>${log} 2>&1 || failed=YES
3fedd74b 161 if [ -z "${failed}" ] ; then
3fedd74b
MP
162 rm $log
163 return 0
164 else
3fedd74b
MP
165 cat ${log}
166 rm ${log}
167 return 1
168 fi
169}
170
863dff51
MP
171
172# In fact, we need a more general feature of capturing all stderr/log files,
173# and dumping them if something goes wrong.
174
175checkforlogs() {
176 # skip it if we're under debian-test
177 if test -n "${Debian}" ; then return 0 ; fi
178
179 if [ -f $1 -a -s $1 ] ; then
180 echo "Failures have occurred. $1 follows:" >&2
181 cat $1 >&2
182 exit 1
183 fi
184}
185
d2094cc3 186
4a7cb3e8 187build_rsyncd_conf() {
d2094cc3
MP
188 # Build an appropriate configuration file
189 conf="$scratchdir/test-rsyncd.conf"
190 echo "building configuration $conf"
191
192 port=2612
193 pidfile="$scratchdir/rsyncd.pid"
194 logfile="$scratchdir/rsyncd.log"
195
196 cat >$conf <<EOF
3aae15ec 197# rsyncd configuration file autogenerated by $0
d2094cc3 198
3aae15ec
MP
199pid file = $pidfile
200use chroot = no
201hosts allow = localhost, 127.0.0.1
202log file = $logfile
d2094cc3 203
3aae15ec
MP
204[test-from] = $scratchdir/daemon-from/
205 read only = yes
d2094cc3 206
3aae15ec
MP
207[test-to] = $scratchdir/daemon-to/
208 read only = no
d2094cc3
MP
209EOF
210}
211
212
3cd2af41
MP
213build_symlinks() {
214 fromdir="$scratchdir/from"
215 todir="$scratchdir/to"
216 mkdir "$fromdir"
217 date >"$fromdir/referent"
218 ln -s referent "$fromdir/relative"
219 ln -s "$fromdir/referent" "$fromdir/absolute"
220 ln -s nonexistent "$fromdir/dangling"
1db8b61d 221 ln -s "$srcdir/rsync.c" "$fromdir/unsafe"
3cd2af41
MP
222}
223
224test_fail() {
225 echo "$@" >&2
226 exit 1
227}
228
3d807132
MP
229# be reproducible
230umask 077