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