Doc.
[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
24F1=text1
25LOG=${TMP}/log
3fedd74b 26RSYNC="$rsync_bin"
3a4c683f
MP
27
28runtest() {
29 echo $ECHO_N "Test $1: $ECHO_C"
30 eval "$2"
31}
32
33printmsg() {
34 echo "$1"
35}
36
e052b21f
MP
37
38####################
39# Build test directories TO and FROM, with FROM full of files.
40
3a4c683f
MP
41hands_setup() {
42 [ -d $FROM ] || mkdir $FROM
43 [ -d $TO ] || mkdir $TO
44
e052b21f
MP
45 # On some BSD systems, the umask affects the mode of created
46 # symlinks, even though the mode apparently has no effect on how
47 # the links behave in the future, and it cannot be changed using
48 # chmod! rsync always sets its umask to 000 so that it can
49 # accurately recreate permissions, but this script is probably run
50 # with a different umask.
51
52 # This causes a little problem that "ls -l" of the two will not be
53 # the same. So, we need to set our umask before doing any creations.
54
3a4c683f
MP
55 # set up test data
56 touch ${FROM}/empty
57 mkdir ${FROM}/emptydir
e8ca5901
MP
58
59 # a few hundred lines of test
60 ls -lR / | head -200 > ${FROM}/filelist
3a4c683f
MP
61
62 # This might fail on systems that don't have -n
63 echo $ECHO_N "This file has no trailing lf$ECHO_C" > ${FROM}/nolf
0154b302 64 umask 0
3a4c683f 65 ln -s nolf ${FROM}/nolf-symlink
0154b302
MP
66 umask 077
67
751411c4 68 cat $srcdir/*.c | head -2000 > ${FROM}/${F1}
3a4c683f
MP
69 mkdir ${FROM}/dir
70 cp ${FROM}/${F1} ${FROM}/dir
71 mkdir ${FROM}/dir/subdir
72 mkdir ${FROM}/dir/subdir/subsubdir
73 ls -ltr /etc > ${FROM}/dir/subdir/subsubdir/etc-ltr-list
74 mkdir ${FROM}/dir/subdir/subsubdir2
75 ls -lt /bin > ${FROM}/dir/subdir/subsubdir2/bin-lt-list
76}
3fedd74b
MP
77
78
e052b21f 79
3fedd74b
MP
80###########################
81# Run a test (in '$1') then compare directories $2 and $3 to see if
82# there are any difference. If there are, explain them.
83
84checkit() {
85 log=${LOG}
86 failed=
87 # the log accumulates all output; we only display it if there
88 # is a problem.
89
90 echo "Running: \"$1\"" >${log}
91 echo "">>${log}
92 eval "$1" >>${log} 2>&1
93 status=$?
94 if [ $status != 0 ]; then
95 failed="YES";
96 fi
97
98 echo "-------------">>${log}
99 echo "check how the files compare with diff:">>${log}
100 echo "">>${log}
37c3cf43 101 diff -cr $2 $3 >>${log} 2>&1 || failed=YES
3fedd74b
MP
102 echo "-------------">>${log}
103 echo "check how the directory listings compare with diff:">>${log}
104 echo "">>${log}
105 ( cd $2 ; ls -laR ) > ${TMP}/ls-from 2>>${log}
106 ( cd $3 ; ls -laR ) > ${TMP}/ls-to 2>>${log}
37c3cf43 107 diff -c ${TMP}/ls-from ${TMP}/ls-to >>${log} 2>&1 || failed=YES
3fedd74b
MP
108 if [ -z "${failed}" ] ; then
109 echo "${ECHO_T} done."
110 rm $log
111 return 0
112 else
113 echo "${ECHO_T} failed!"
114 cat ${log}
115 rm ${log}
116 return 1
117 fi
118}
119
863dff51
MP
120
121# In fact, we need a more general feature of capturing all stderr/log files,
122# and dumping them if something goes wrong.
123
124checkforlogs() {
125 # skip it if we're under debian-test
126 if test -n "${Debian}" ; then return 0 ; fi
127
128 if [ -f $1 -a -s $1 ] ; then
129 echo "Failures have occurred. $1 follows:" >&2
130 cat $1 >&2
131 exit 1
132 fi
133}
134
d2094cc3 135
4a7cb3e8 136build_rsyncd_conf() {
d2094cc3
MP
137 # Build an appropriate configuration file
138 conf="$scratchdir/test-rsyncd.conf"
139 echo "building configuration $conf"
140
141 port=2612
142 pidfile="$scratchdir/rsyncd.pid"
143 logfile="$scratchdir/rsyncd.log"
144
145 cat >$conf <<EOF
3aae15ec 146# rsyncd configuration file autogenerated by $0
d2094cc3 147
3aae15ec
MP
148pid file = $pidfile
149use chroot = no
150hosts allow = localhost, 127.0.0.1
151log file = $logfile
d2094cc3 152
3aae15ec
MP
153[test-from] = $scratchdir/daemon-from/
154 read only = yes
d2094cc3 155
3aae15ec
MP
156[test-to] = $scratchdir/daemon-to/
157 read only = no
d2094cc3
MP
158EOF
159}
160
161