On Solaris, put /usr/ucb/bin at the end of the path to help find
[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
3a4c683f 24LOG=${TMP}/log
3fedd74b 25RSYNC="$rsync_bin"
3a4c683f 26
2094283b
MP
27# Berkley's nice.
28PATH="$PATH:/usr/ucb/bin"
29
3a4c683f
MP
30runtest() {
31 echo $ECHO_N "Test $1: $ECHO_C"
501972bf
MP
32 if eval "$2"
33 then
34 echo "${ECHO_T} done."
35 return 0
36 else
37 echo "${ECHO_T} failed!"
38 return 1
39 fi
3a4c683f
MP
40}
41
42printmsg() {
43 echo "$1"
44}
45
e052b21f 46
6773a779 47rsync_ls_lR() {
57835c00
MP
48 find "$@" -print | sort | xargs $TLS
49}
50
51
e052b21f
MP
52####################
53# Build test directories TO and FROM, with FROM full of files.
54
3a4c683f 55hands_setup() {
501972bf
MP
56 # Clean before creation
57 rm -rf $FROM
58 rm -rf $TO
3d807132
MP
59
60 [ -d $TMP ] || mkdir $TMP
3a4c683f
MP
61 [ -d $FROM ] || mkdir $FROM
62 [ -d $TO ] || mkdir $TO
63
e052b21f
MP
64 # On some BSD systems, the umask affects the mode of created
65 # symlinks, even though the mode apparently has no effect on how
66 # the links behave in the future, and it cannot be changed using
67 # chmod! rsync always sets its umask to 000 so that it can
68 # accurately recreate permissions, but this script is probably run
69 # with a different umask.
70
71 # This causes a little problem that "ls -l" of the two will not be
72 # the same. So, we need to set our umask before doing any creations.
73
3a4c683f
MP
74 # set up test data
75 touch ${FROM}/empty
76 mkdir ${FROM}/emptydir
e8ca5901 77
571a4b26 78 # a hundred lines of text or so
3d807132 79 rsync_ls_lR "${srcdir}" > ${FROM}/filelist
3a4c683f
MP
80
81 # This might fail on systems that don't have -n
82 echo $ECHO_N "This file has no trailing lf$ECHO_C" > ${FROM}/nolf
0154b302 83 umask 0
3a4c683f 84 ln -s nolf ${FROM}/nolf-symlink
4c80c473 85 umask 022
0154b302 86
4c80c473 87 cat $srcdir/*.c > ${FROM}/text
3a4c683f 88 mkdir ${FROM}/dir
4c80c473 89 cp ${FROM}/text ${FROM}/dir
3a4c683f
MP
90 mkdir ${FROM}/dir/subdir
91 mkdir ${FROM}/dir/subdir/subsubdir
92 ls -ltr /etc > ${FROM}/dir/subdir/subsubdir/etc-ltr-list
93 mkdir ${FROM}/dir/subdir/subsubdir2
94 ls -lt /bin > ${FROM}/dir/subdir/subsubdir2/bin-lt-list
7d691654 95
8f98c608
MP
96# echo testing head:
97# ls -lR ${srcdir} | head -10 || echo failed
3a4c683f 98}
3fedd74b
MP
99
100
3d807132
MP
101hands_cleanup() {
102 rm -r "$TMP"
103}
104
105
e052b21f 106
99cdaff7
MP
107
108####################
109# Many machines do not have "mkdir -p", so we have to build up long paths.
110# How boring.
111makepath () {
7c1b7890 112 echo " makepath $1"
99cdaff7
MP
113 p="$1"
114 (
115 # Absolut Unix.
116 if echo $p | grep '^/' >/dev/null
117 then
118 cd /
119 fi
120
121 # This will break if $1 contains a space.
122 for c in `echo $p | tr '/' ' '`
123 do
112e7311
MP
124 if [ -d "$c" ] || mkdir "$c"
125 then
126 cd "$c" || return $?
127 else
128 echo "failed to create $c" >&2; return $?
129 fi
99cdaff7
MP
130 done
131 )
132}
133
134
135
3fedd74b
MP
136###########################
137# Run a test (in '$1') then compare directories $2 and $3 to see if
138# there are any difference. If there are, explain them.
139
140checkit() {
3fedd74b 141 failed=
3fedd74b 142
cf72f204
MP
143 # We can just write everything to stdout/stderr, because the
144 # wrapper hides it unless there is a problem.
145
146 echo "Running: \"$1\""
147 eval "$1"
3fedd74b
MP
148 status=$?
149 if [ $status != 0 ]; then
150 failed="YES";
151 fi
152
cf72f204
MP
153 echo "-------------"
154 echo "check how the files compare with diff:"
155 echo ""
d58e4c27
MP
156 for f in `cd "$2"; find . -type f -print `
157 do
371d1c36 158 diff -c "$2"/"$f" "$3"/"$f" || failed=YES
d58e4c27
MP
159 done
160
cf72f204
MP
161 echo "-------------"
162 echo "check how the directory listings compare with diff:"
163 echo ""
164 ( cd "$2" && rsync_ls_lR . ) > ${TMP}/ls-from
165 ( cd "$3" && rsync_ls_lR . ) > ${TMP}/ls-to
166 diff -c ${TMP}/ls-from ${TMP}/ls-to || failed=YES
3fedd74b 167 if [ -z "${failed}" ] ; then
3fedd74b
MP
168 return 0
169 else
3fedd74b
MP
170 return 1
171 fi
172}
173
863dff51
MP
174
175# In fact, we need a more general feature of capturing all stderr/log files,
176# and dumping them if something goes wrong.
177
178checkforlogs() {
179 # skip it if we're under debian-test
180 if test -n "${Debian}" ; then return 0 ; fi
181
182 if [ -f $1 -a -s $1 ] ; then
183 echo "Failures have occurred. $1 follows:" >&2
184 cat $1 >&2
185 exit 1
186 fi
187}
188
d2094cc3 189
4a7cb3e8 190build_rsyncd_conf() {
d2094cc3
MP
191 # Build an appropriate configuration file
192 conf="$scratchdir/test-rsyncd.conf"
193 echo "building configuration $conf"
194
195 port=2612
196 pidfile="$scratchdir/rsyncd.pid"
197 logfile="$scratchdir/rsyncd.log"
198
199 cat >$conf <<EOF
3aae15ec 200# rsyncd configuration file autogenerated by $0
d2094cc3 201
3aae15ec
MP
202pid file = $pidfile
203use chroot = no
204hosts allow = localhost, 127.0.0.1
205log file = $logfile
d2094cc3 206
2e6c7f45
MP
207[test-from]
208 path = $FROM
3aae15ec 209 read only = yes
d2094cc3 210
2e6c7f45
MP
211[test-to]
212 path = $TO
3aae15ec 213 read only = no
d2094cc3
MP
214EOF
215}
216
217
3cd2af41
MP
218build_symlinks() {
219 fromdir="$scratchdir/from"
220 todir="$scratchdir/to"
221 mkdir "$fromdir"
222 date >"$fromdir/referent"
223 ln -s referent "$fromdir/relative"
224 ln -s "$fromdir/referent" "$fromdir/absolute"
225 ln -s nonexistent "$fromdir/dangling"
1db8b61d 226 ln -s "$srcdir/rsync.c" "$fromdir/unsafe"
3cd2af41
MP
227}
228
229test_fail() {
230 echo "$@" >&2
231 exit 1
232}
233
a217ad30
MP
234test_skipped() {
235 echo "$@" >&2
236 exit 77
237}
238
be2f866b
MP
239# It failed, but we expected that. don't dump out error logs,
240# because most users won't want to see them. But do leave
241# the working directory around.
242test_xfail() {
243 echo "$@" >&2
244 exit 78
245}
246
d96d3893
MP
247# Test whether something is a link, allowing for shell peculiarities
248is_a_link() {
249 test -L "$1" || test -h "$1" || /usr/bin/test -L "$1" || /usr/bin/test -h "$1"
250}
251
3d807132
MP
252# be reproducible
253umask 077