Add a makepath() function to cope with machines that do not have
[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
24F1=text1
25LOG=${TMP}/log
26RSYNC="$rsync_bin"
27
28runtest() {
29 echo $ECHO_N "Test $1: $ECHO_C"
30 eval "$2"
31}
32
33printmsg() {
34 echo "$1"
35}
36
37
38####################
39# Build test directories TO and FROM, with FROM full of files.
40
41hands_setup() {
42 [ -d $FROM ] || mkdir $FROM
43 [ -d $TO ] || mkdir $TO
44
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
55 # set up test data
56 touch ${FROM}/empty
57 mkdir ${FROM}/emptydir
58
59 # a few hundred lines of test
60 ls -lR / | head -200 > ${FROM}/filelist
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
64 umask 0
65 ln -s nolf ${FROM}/nolf-symlink
66 umask 077
67
68 cat $srcdir/*.c | head -2000 > ${FROM}/${F1}
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}
77
78
79
80
81####################
82# Many machines do not have "mkdir -p", so we have to build up long paths.
83# How boring.
84makepath () {
85 p="$1"
86 (
87 # Absolut Unix.
88 if echo $p | grep '^/' >/dev/null
89 then
90 cd /
91 fi
92
93 # This will break if $1 contains a space.
94 for c in `echo $p | tr '/' ' '`
95 do
96 [ -d "$c" ] || mkdir "$c" || return $?
97 cd "$c" || return $?
98 done
99 )
100}
101
102
103
104###########################
105# Run a test (in '$1') then compare directories $2 and $3 to see if
106# there are any difference. If there are, explain them.
107
108checkit() {
109 log=${LOG}
110 failed=
111 # the log accumulates all output; we only display it if there
112 # is a problem.
113
114 echo "Running: \"$1\"" >${log}
115 echo "">>${log}
116 eval "$1" >>${log} 2>&1
117 status=$?
118 if [ $status != 0 ]; then
119 failed="YES";
120 fi
121
122 echo "-------------">>${log}
123 echo "check how the files compare with diff:">>${log}
124 echo "">>${log}
125 diff -cr $2 $3 >>${log} 2>&1 || failed=YES
126 echo "-------------">>${log}
127 echo "check how the directory listings compare with diff:">>${log}
128 echo "">>${log}
129 ( cd $2 ; ls -laR ) > ${TMP}/ls-from 2>>${log}
130 ( cd $3 ; ls -laR ) > ${TMP}/ls-to 2>>${log}
131 diff -c ${TMP}/ls-from ${TMP}/ls-to >>${log} 2>&1 || failed=YES
132 if [ -z "${failed}" ] ; then
133 echo "${ECHO_T} done."
134 rm $log
135 return 0
136 else
137 echo "${ECHO_T} failed!"
138 cat ${log}
139 rm ${log}
140 return 1
141 fi
142}
143
144
145# In fact, we need a more general feature of capturing all stderr/log files,
146# and dumping them if something goes wrong.
147
148checkforlogs() {
149 # skip it if we're under debian-test
150 if test -n "${Debian}" ; then return 0 ; fi
151
152 if [ -f $1 -a -s $1 ] ; then
153 echo "Failures have occurred. $1 follows:" >&2
154 cat $1 >&2
155 exit 1
156 fi
157}
158
159
160build_rsyncd_conf() {
161 # Build an appropriate configuration file
162 conf="$scratchdir/test-rsyncd.conf"
163 echo "building configuration $conf"
164
165 port=2612
166 pidfile="$scratchdir/rsyncd.pid"
167 logfile="$scratchdir/rsyncd.log"
168
169 cat >$conf <<EOF
170# rsyncd configuration file autogenerated by $0
171
172pid file = $pidfile
173use chroot = no
174hosts allow = localhost, 127.0.0.1
175log file = $logfile
176
177[test-from] = $scratchdir/daemon-from/
178 read only = yes
179
180[test-to] = $scratchdir/daemon-to/
181 read only = no
182EOF
183}
184
185