You cannot do "export VAR=VALUE" all on one line; the export must be
[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
MP
43
44####################
45# Build test directories TO and FROM, with FROM full of files.
46
3a4c683f 47hands_setup() {
501972bf
MP
48 # Clean before creation
49 rm -rf $FROM
50 rm -rf $TO
51
3a4c683f
MP
52 [ -d $FROM ] || mkdir $FROM
53 [ -d $TO ] || mkdir $TO
54
e052b21f
MP
55 # On some BSD systems, the umask affects the mode of created
56 # symlinks, even though the mode apparently has no effect on how
57 # the links behave in the future, and it cannot be changed using
58 # chmod! rsync always sets its umask to 000 so that it can
59 # accurately recreate permissions, but this script is probably run
60 # with a different umask.
61
62 # This causes a little problem that "ls -l" of the two will not be
63 # the same. So, we need to set our umask before doing any creations.
64
3a4c683f
MP
65 # set up test data
66 touch ${FROM}/empty
67 mkdir ${FROM}/emptydir
e8ca5901 68
571a4b26 69 # a hundred lines of text or so
4c80c473 70 ls -lR ${srcdir} > ${FROM}/filelist
3a4c683f
MP
71
72 # This might fail on systems that don't have -n
73 echo $ECHO_N "This file has no trailing lf$ECHO_C" > ${FROM}/nolf
0154b302 74 umask 0
3a4c683f 75 ln -s nolf ${FROM}/nolf-symlink
4c80c473 76 umask 022
0154b302 77
4c80c473 78 cat $srcdir/*.c > ${FROM}/text
3a4c683f 79 mkdir ${FROM}/dir
4c80c473 80 cp ${FROM}/text ${FROM}/dir
3a4c683f
MP
81 mkdir ${FROM}/dir/subdir
82 mkdir ${FROM}/dir/subdir/subsubdir
83 ls -ltr /etc > ${FROM}/dir/subdir/subsubdir/etc-ltr-list
84 mkdir ${FROM}/dir/subdir/subsubdir2
85 ls -lt /bin > ${FROM}/dir/subdir/subsubdir2/bin-lt-list
86}
3fedd74b
MP
87
88
e052b21f 89
99cdaff7
MP
90
91####################
92# Many machines do not have "mkdir -p", so we have to build up long paths.
93# How boring.
94makepath () {
95 p="$1"
96 (
97 # Absolut Unix.
98 if echo $p | grep '^/' >/dev/null
99 then
100 cd /
101 fi
102
103 # This will break if $1 contains a space.
104 for c in `echo $p | tr '/' ' '`
105 do
106 [ -d "$c" ] || mkdir "$c" || return $?
107 cd "$c" || return $?
108 done
109 )
110}
111
112
113
3fedd74b
MP
114###########################
115# Run a test (in '$1') then compare directories $2 and $3 to see if
116# there are any difference. If there are, explain them.
117
118checkit() {
119 log=${LOG}
120 failed=
121 # the log accumulates all output; we only display it if there
122 # is a problem.
123
124 echo "Running: \"$1\"" >${log}
125 echo "">>${log}
126 eval "$1" >>${log} 2>&1
127 status=$?
128 if [ $status != 0 ]; then
129 failed="YES";
130 fi
131
132 echo "-------------">>${log}
133 echo "check how the files compare with diff:">>${log}
134 echo "">>${log}
37c3cf43 135 diff -cr $2 $3 >>${log} 2>&1 || failed=YES
3fedd74b
MP
136 echo "-------------">>${log}
137 echo "check how the directory listings compare with diff:">>${log}
138 echo "">>${log}
139 ( cd $2 ; ls -laR ) > ${TMP}/ls-from 2>>${log}
140 ( cd $3 ; ls -laR ) > ${TMP}/ls-to 2>>${log}
37c3cf43 141 diff -c ${TMP}/ls-from ${TMP}/ls-to >>${log} 2>&1 || failed=YES
3fedd74b 142 if [ -z "${failed}" ] ; then
3fedd74b
MP
143 rm $log
144 return 0
145 else
3fedd74b
MP
146 cat ${log}
147 rm ${log}
148 return 1
149 fi
150}
151
863dff51
MP
152
153# In fact, we need a more general feature of capturing all stderr/log files,
154# and dumping them if something goes wrong.
155
156checkforlogs() {
157 # skip it if we're under debian-test
158 if test -n "${Debian}" ; then return 0 ; fi
159
160 if [ -f $1 -a -s $1 ] ; then
161 echo "Failures have occurred. $1 follows:" >&2
162 cat $1 >&2
163 exit 1
164 fi
165}
166
d2094cc3 167
4a7cb3e8 168build_rsyncd_conf() {
d2094cc3
MP
169 # Build an appropriate configuration file
170 conf="$scratchdir/test-rsyncd.conf"
171 echo "building configuration $conf"
172
173 port=2612
174 pidfile="$scratchdir/rsyncd.pid"
175 logfile="$scratchdir/rsyncd.log"
176
177 cat >$conf <<EOF
3aae15ec 178# rsyncd configuration file autogenerated by $0
d2094cc3 179
3aae15ec
MP
180pid file = $pidfile
181use chroot = no
182hosts allow = localhost, 127.0.0.1
183log file = $logfile
d2094cc3 184
3aae15ec
MP
185[test-from] = $scratchdir/daemon-from/
186 read only = yes
d2094cc3 187
3aae15ec
MP
188[test-to] = $scratchdir/daemon-to/
189 read only = no
d2094cc3
MP
190EOF
191}
192
193