Set the "max verbosity" global to 9.
[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
27# Berkley's nice.
28PATH="$PATH:/usr/ucb"
29
30if diff -u $srcdir/testsuite/rsync.fns $srcdir/testsuite/rsync.fns >/dev/null 2>&1; then
31 diffopt="-u"
32else
33 diffopt="-c"
34fi
35
36runtest() {
37 echo $ECHO_N "Test $1: $ECHO_C"
38 if eval "$2"
39 then
40 echo "${ECHO_T} done."
41 return 0
42 else
43 echo "${ECHO_T} failed!"
44 return 1
45 fi
46}
47
48printmsg() {
49 echo "$1"
50}
51
52
53rsync_ls_lR() {
54 find "$@" -print | sort | xargs "$TOOLDIR/tls"
55}
56
57rsync_getgroups() {
58 "$TOOLDIR/getgroups"
59}
60
61
62####################
63# Build test directories TO and FROM, with FROM full of files.
64
65hands_setup() {
66 # Clean before creation
67 rm -rf $FROM
68 rm -rf $TO
69
70 [ -d $TMP ] || mkdir $TMP
71 [ -d $FROM ] || mkdir $FROM
72 [ -d $TO ] || mkdir $TO
73
74 # On some BSD systems, the umask affects the mode of created
75 # symlinks, even though the mode apparently has no effect on how
76 # the links behave in the future, and it cannot be changed using
77 # chmod! rsync always sets its umask to 000 so that it can
78 # accurately recreate permissions, but this script is probably run
79 # with a different umask.
80
81 # This causes a little problem that "ls -l" of the two will not be
82 # the same. So, we need to set our umask before doing any creations.
83
84 # set up test data
85 touch ${FROM}/empty
86 mkdir ${FROM}/emptydir
87
88 # a hundred lines of text or so
89 rsync_ls_lR "${srcdir}" > ${FROM}/filelist
90
91 # This might fail on systems that don't have -n
92 echo $ECHO_N "This file has no trailing lf$ECHO_C" > ${FROM}/nolf
93 umask 0
94 ln -s nolf ${FROM}/nolf-symlink
95 umask 022
96
97 cat $srcdir/*.c > ${FROM}/text
98 mkdir ${FROM}/dir
99 cp ${FROM}/text ${FROM}/dir
100 mkdir ${FROM}/dir/subdir
101 mkdir ${FROM}/dir/subdir/subsubdir
102 ls -ltr /etc > ${FROM}/dir/subdir/subsubdir/etc-ltr-list
103 mkdir ${FROM}/dir/subdir/subsubdir2
104 ls -lt /bin > ${FROM}/dir/subdir/subsubdir2/bin-lt-list
105
106# echo testing head:
107# ls -lR ${srcdir} | head -10 || echo failed
108}
109
110
111####################
112# Many machines do not have "mkdir -p", so we have to build up long paths.
113# How boring.
114makepath () {
115 echo " makepath $1"
116 p="$1"
117 (
118 # Absolut Unix.
119 if echo $p | grep '^/' >/dev/null
120 then
121 cd /
122 fi
123
124 # This will break if $1 contains a space.
125 for c in `echo $p | tr '/' ' '`
126 do
127 if [ -d "$c" ] || mkdir "$c"
128 then
129 cd "$c" || return $?
130 else
131 echo "failed to create $c" >&2; return $?
132 fi
133 done
134 )
135}
136
137
138
139###########################
140# Run a test (in '$1') then compare directories $2 and $3 to see if
141# there are any difference. If there are, explain them.
142
143# So normally basically $1 should be an rsync command, and $2 and $3
144# the source and destination directories. This is only good when you
145# expect to transfer the whole directory exactly as is. If some files
146# should be excluded, you might need to use something else.
147
148checkit() {
149 failed=
150
151 # We can just write everything to stdout/stderr, because the
152 # wrapper hides it unless there is a problem.
153
154 echo "Running: \"$1\""
155 eval "$1"
156 status=$?
157 if [ $status != 0 ]; then
158 failed="YES";
159 fi
160
161 echo "-------------"
162 echo "check how the files compare with diff:"
163 echo ""
164 for f in `cd "$2"; find . -type f -print `
165 do
166 diff $diffopt "$2"/"$f" "$3"/"$f" || failed=YES
167 done
168
169 echo "-------------"
170 echo "check how the directory listings compare with diff:"
171 echo ""
172 ( cd "$2" && rsync_ls_lR . ) > ${TMP}/ls-from
173 ( cd "$3" && rsync_ls_lR . ) > ${TMP}/ls-to
174 diff $diffopt ${TMP}/ls-from ${TMP}/ls-to || failed=YES
175 if [ -z "${failed}" ] ; then
176 return 0
177 else
178 return 1
179 fi
180}
181
182
183build_rsyncd_conf() {
184 # Build an appropriate configuration file
185 conf="$scratchdir/test-rsyncd.conf"
186 echo "building configuration $conf"
187
188 port=2612
189 pidfile="$scratchdir/rsyncd.pid"
190 logfile="$scratchdir/rsyncd.log"
191
192 cat >$conf <<EOF
193# rsyncd configuration file autogenerated by $0
194
195pid file = $pidfile
196use chroot = no
197hosts allow = localhost, 127.0.0.1
198log file = $logfile
199max verbosity = 9
200
201uid = 0
202gid = 0
203
204[test-from]
205 path = $FROM
206 read only = yes
207
208[test-to]
209 path = $TO
210 read only = no
211EOF
212}
213
214
215build_symlinks() {
216 fromdir="$scratchdir/from"
217 todir="$scratchdir/to"
218 mkdir "$fromdir"
219 date >"$fromdir/referent"
220 ln -s referent "$fromdir/relative"
221 ln -s "$fromdir/referent" "$fromdir/absolute"
222 ln -s nonexistent "$fromdir/dangling"
223 ln -s "$srcdir/rsync.c" "$fromdir/unsafe"
224}
225
226test_fail() {
227 echo "$@" >&2
228 exit 1
229}
230
231test_skipped() {
232 echo "$@" >&2
233 echo "$@" > "$TMP/whyskipped"
234 exit 77
235}
236
237# It failed, but we expected that. don't dump out error logs,
238# because most users won't want to see them. But do leave
239# the working directory around.
240test_xfail() {
241 echo "$@" >&2
242 exit 78
243}
244
245# Determine what shell command will appropriately test for links.
246ln -s foo "$scratchdir/testlink"
247for cmd in test /bin/test /usr/bin/test /usr/ucb/bin/test /usr/ucb/test
248do
249 for switch in -h -L
250 do
251 if $cmd $switch "$scratchdir/testlink" 2>/dev/null
252 then
253 # how nice
254 TEST_SYMLINK_CMD="$cmd $switch"
255 # i wonder if break 2 is portable?
256 break 2
257 fi
258 done
259done
260# ok, now get rid of it
261rm "$scratchdir/testlink"
262
263
264if [ "x$TEST_SYMLINK_CMD" = 'x' ]
265then
266 test_fail "Couldn't determine how to test for symlinks"
267else
268 echo "Testing for symlinks using '$TEST_SYMLINK_CMD'"
269fi
270
271
272# Test whether something is a link, allowing for shell peculiarities
273is_a_link() {
274 # note the variable contains the first option and therefore is not quoted
275 $TEST_SYMLINK_CMD "$1"
276}
277
278
279# We need to set the umask to be reproducible. Note also that when we
280# do some daemon tests as root, we will setuid() and therefore the
281# directory has to be writable by the nobody user in some cases. The
282# best thing is probably to explicitly chmod those directories after
283# creation.
284
285umask 022