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