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