3 # Caveats: kills all killable rsyncs
4 # don't disturb test timing by putting too much (extra) load on the machine
5 # Debian: install packages bc, time
7 TESTDIR
=/tmp
/monikop-test
12 MONIKOP_1
="../monikop ../test/monikop.config.test.1"
13 MONIKOP_2
="../monikop ../test/monikop.config.test.2"
18 function kill_rsyncd
{
19 kill `cat $TESTDIR/rsync/rsyncd.pid`
22 function start_rsyncd
{
23 kill_rsyncd
2> /dev
/null
24 rm -f $RSYNC/rsyncd.pid
2> /dev
/null
25 rsync
--daemon --config=..
/test
/rsyncd.conf.
test
28 # make_test_drive <name> <size>
29 function make_test_drive
{
31 dd if=/dev
/zero of
=$DEV/$1 bs
=1024 count
=$2 2> /dev
/null
32 /sbin
/mkfs.ext3
-m 0 -Fq $DEV/$1
33 if ! mount
$MNT/$1 2> /dev
/null
; then
34 echo "# Can't mount $DEV/$1 to $MNT/$1."
35 echo "# Redo from start after adding the following line to your /etc/fstab:"
37 echo " $DEV/$1 $MNT/$1 ext3 loop,user,noauto 0 0"
43 # make_test_file <name> <size> <date>
44 function make_test_file
{
45 dd if=/dev
/zero of
=$1 bs
=1024 count
=$2 2> /dev
/null
46 echo ++++++++++++++++++++++++++$RANDOM***$3---$1 >> $1
50 # find_and_compare <origin_dir> <origin_dir> ... :: <copy_dir> <copy_dir> ...
51 function find_and_compare
{
52 ORIGIN_DIRS
=$1; shift;
53 until [[ $1 == "::" ]]; do
54 ORIGIN_DIRS
="$ORIGIN_DIRS $1"; shift;
61 for i
in `find $ORIGIN_DIRS -type f 2> /dev/null`; do
62 FOUND
=`find $@ -path "$MNT/*/measuring_data/${i#$MNT/*/data/}" 2> /dev/null`
63 if [[ $FOUND == "" ]] ; then
64 MISSING
="$MISSING $i";
65 elif ! cmp --quiet $i $FOUND; then
66 DIVERGING
="$DIVERGING $i"
67 elif [[ `stat --printf="%Y" $i` != `stat --printf="%Y" $FOUND` ]]; then
68 DIVERGING_MTIME
="$DIVERGING_MTIME $i"
71 if [[ $MISSING != "" ]]; then
73 echo "MISSING: $MISSING"
75 if [[ $DIVERGING != "" ]]; then
76 RETURN_VALUE
=$
((return_value
+ 2))
77 echo "DIVERGING: $DIVERGING"
79 if [[ $DIVERGING_MTIME != "" ]]; then
80 RETURN_VALUE
=$
((return_value
+ 4))
81 echo "DIVERGING MTIME: $DIVERGING_MTIME"
86 # run_test <expected_return> <test-command> <comment>
88 echo "RUNNING $2 [$3]"
89 TEST_COUNT
=$
(( TEST_COUNT
+ 1 ))
92 if [[ $RETURN_VALUE -ne $1 ]]; then
93 FAIL_COUNT
=$
(( FAIL_COUNT
+ 1 ))
94 FAILED_TESTS
="$FAILED_TESTS$2($1? $RETURN_VALUE!) [$3]\n"
95 echo "$2 should have returned $1 but returned $RETURN_VALUE instead."
100 umount
$MNT/* #2> /dev/null
101 rm -rf $DEV $MNT $LOG
102 mkdir
-p $DEV $MNT $RSYNC
104 # Create and mount test drives:
105 for i
in 01 02 03 04; do
106 make_test_drive
$i 102400
107 if [[ $?
== 1 ]]; then
111 make_test_drive
05 102400
112 if [[ $?
== 1 ]]; then
115 if [[ $MOUNTING_PROBLEM == 1 ]]; then exit; fi
117 # Prepare data sources:
118 mkdir
-p $MNT/01/data
/d
1/d2
119 mkdir
-p $MNT/02/data
/d
1/d2
120 for i
in f1 f2 f3
; do
121 make_test_file
$MNT/01/data
/$i 25000 200703250845.33
123 for i
in f10 f11 f12
; do
124 make_test_file
$MNT/02/data
/$i 25000 200703250845.33
126 for i
in f4 f5 f6
; do
127 make_test_file
$MNT/01/data
/d
1/$i 2000 200703250845.33
128 make_test_file
$MNT/01/data
/d
1/d
2/$i 2000 200703250845.33
130 for i
in f7 f8 f9
; do
131 make_test_file
$MNT/02/data
/d
1/$i 2000 200703250845.33
132 make_test_file
$MNT/02/data
/d
1/d
2/$i 2000 200703250845.33
135 # Check how fast we are:
137 T1
=`/usr/bin/time --format="%e" rsync --recursive --times $MNT/01/data/ $MNT/03/ 2>&1 &`
138 T2
=`/usr/bin/time --format="%e" rsync --recursive --times $MNT/02/data/ $MNT/04/ 2>&1 &`
139 INTERRUPTION_TIME_0
=`echo "($T1 + $T2) * 3" | bc`
140 INTERRUPTION_TIME_1
=`echo "($T1 + $T2) * .1" | bc`
141 INTERRUPTION_TIME_2
=`echo "($T1 + $T2) * .82" | bc`
142 echo $INTERRUPTION_TIME_0
143 rm -rf $MNT/03/* $MNT/04/*
145 function test_monikop_simple
{
146 $MONIKOP_1 & sleep $INTERRUPTION_TIME_0; /bin
/kill -TERM $
!
147 find_and_compare
$TESTDIR/mnt
/0{1,2}/data
:: $TESTDIR/mnt
/0{3,4}/measuring_data
150 function test_monikop_simple_late_sources
{
152 $MONIKOP_1 & sleep $INTERRUPTION_TIME_2; start_rsyncd
; sleep $INTERRUPTION_TIME_0; /bin
/kill -TERM $
!
153 find_and_compare
$TESTDIR/mnt
/0{1,2}/data
:: $TESTDIR/mnt
/0{3,4}/measuring_data
156 function test_monikop_short
{
157 $MONIKOP_1 & sleep $INTERRUPTION_TIME_1; /bin
/kill -TERM $
!
158 find_and_compare
$TESTDIR/mnt
/0{1,2}/data
:: $TESTDIR/mnt
/0{3,4}/measuring_data
161 function test_monikop_short_2
{
162 $MONIKOP_2 & sleep $INTERRUPTION_TIME_1; /bin
/kill -TERM $
!
163 find_and_compare
$TESTDIR/mnt
/0{1,2}/data
:: $TESTDIR/mnt
/0{3,4,5}/measuring_data
166 function test_monikop_short_kill_rsync_first
{
167 $MONIKOP_2 & sleep $INTERRUPTION_TIME_1; /usr
/bin
/killall
-KILL rsync
; sleep 1; /bin
/kill -TERM $
!
168 find_and_compare
$TESTDIR/mnt
/0{1,2}/data
:: $TESTDIR/mnt
/0{3,4,5}/measuring_data
175 function test_monikop_short_cut_sources
{
176 $MONIKOP_2 & sleep $INTERRUPTION_TIME_1; kill_rsyncd
; sleep 1; /bin
/kill -TERM $
!
177 find_and_compare
$TESTDIR/mnt
/0{1,2}/data
:: $TESTDIR/mnt
/0{3,4,5}/measuring_data
184 function test_monikop_simple_2
{
185 $MONIKOP_2 & sleep $INTERRUPTION_TIME_0; /bin
/kill -TERM $
!
186 find_and_compare
$TESTDIR/mnt
/0{1,2}/data
:: $TESTDIR/mnt
/0{3,4,5}/measuring_data
189 function test_monikop_overflow
{
190 # Stuff one of the destinations a bit:
191 make_test_file
$MNT/03/stuffing
25000 199903250845
192 $MONIKOP_1 & sleep $INTERRUPTION_TIME_0; /bin
/kill -TERM $
!
193 find_and_compare
$TESTDIR/mnt
/0{1,2}/data
:: $TESTDIR/mnt
/0{3,4}/measuring_data
196 function test_monikop_no_destination
{
197 # We test basically if there is something to kill.
199 $MONIKOP_1 & sleep $INTERRUPTION_TIME_2; /bin
/kill -TERM $
!
206 function test_monikop_no_source
{
207 # We test basically if there is something to kill.
209 $MONIKOP_1 & sleep $INTERRUPTION_TIME_2; /bin
/kill -TERM $
!
217 ##########################
218 ### Run tests: Monikop
219 ##########################
221 # run_test 0 test_monikop_simple "Simple run."
223 # rm -rf $MNT/0{3,4}/* $LOG
225 # chmod a-w,a-x $MNT/0{3,4}
226 # run_test 1 test_monikop_simple "Unwritable destination"
227 # chmod a+w,a+x $MNT/0{3,4}
228 # run_test 0 test_monikop_simple "Unwritable destination"
232 # rm -rf $MNT/0{3,4}/* $LOG
234 # run_test 0 test_monikop_simple_late_sources "Simple run, sources coming up late."
236 # mv $MNT/03/measuring_data $MNT/03/backed_up
237 # mv $MNT/04/measuring_data $MNT/04/backed_up
240 # run_test 0 test_monikop_simple "Simple run, deletion."
242 # rm -rf $MNT/0{3,4}/* $LOG
244 # run_test 1 test_monikop_short_2 "Repeated interruption."
245 # run_test 1 test_monikop_short_2 "Repeated interruption (may pass unexpectedly due to test timing)."
246 # run_test 0 test_monikop_simple_2 "Repeated interruption."
248 # mv $MNT/03/measuring_data $MNT/03/backed_up
249 # mv $MNT/04/measuring_data $MNT/04/backed_up
250 # mv $MNT/05/measuring_data $MNT/05/backed_up
253 # run_test 1 test_monikop_short_2 "Repeated interruption, deletion."
254 # run_test 1 test_monikop_short_2 "Repeated interruption, deletion (may pass unexpectedly due to test timing)."
255 # run_test 0 test_monikop_simple_2 "Repeated interruption, deletion."
257 # rm -rf $MNT/0{3,4,5}/* $LOG
259 # run_test 1 test_monikop_overflow
261 # rm -rf $MNT/0{3,4}/* $LOG
263 # run_test 0 test_monikop_no_destination "No destination available."
264 # run_test 0 test_monikop_no_source "No destination available."
266 # rm -rf $MNT/0{3,4}/* $LOG
268 # run_test 1 test_monikop_short_kill_rsync_first "Rsync killed."
269 # ps aux | grep rsync
270 # run_test 0 test_monikop_simple_2 "Rsync killed."
272 # rm -rf $MNT/0{3,4,5}/* $LOG
274 # run_test 1 test_monikop_short_cut_sources "Connection to source destroyed."
275 # run_test 0 test_monikop_simple_2 "Connection to source destroyed."
277 # rm -rf $MNT/0{3,4,5}/* $LOG
281 # unfinished: Pokinom must recover from this mess
282 run_test
0 test_monikop_simple
"Simple run."
284 cat $MNT/01/data
/f1
>> $MNT/01/data
/f2
285 run_test
1 test_monikop_simple
"Repeated run, file grown too large."
286 rm -f $MNT/0{3,4}/measuring_data
/f3
287 run_test
0 test_monikop_simple
"Repeated run, file grown too large."
290 make_test_file
$MNT/01/data
/$i 25000 200703250845.33
296 echo "TOTAL NUMBER OF TESTS: $TEST_COUNT"
297 echo "NUMBER OF FAILED TESTS: $FAIL_COUNT"
299 echo -e "$FAILED_TESTS"