3 # Caveats: kills all killable rsyncs
4 # don't disturb test timing by putting too much (extra) load on the machine
6 TESTDIR
=/tmp
/monikop-test
11 MONIKOP_1
="../monikop ../test/monikop.config.test.1"
12 MONIKOP_2
="../monikop ../test/monikop.config.test.2"
13 MONIKOP_3
="../monikop ../test/monikop.config.test.3"
14 POKINOM
="../pokinom ../test/pokinom.config.test"
19 function kill_rsyncd
{
20 kill `cat $TESTDIR/rsync/rsyncd.pid`
23 function start_rsyncd
{
24 kill_rsyncd
2> /dev
/null
25 rm -f $RSYNC/rsyncd.pid
2> /dev
/null
26 chmod o-rwx ..
/test
/rsyncd.secrets.
test
27 rsync
--daemon --config=..
/test
/rsyncd.conf.
test
30 # make_test_drive <name> <size>
31 function make_test_drive
{
33 dd if=/dev
/zero of
=$DEV/$1 bs
=1024 count
=$2 2> /dev
/null
34 /sbin
/mkfs.ext3
-m 0 -Fq $DEV/$1
35 if ! mount
$MNT/$1 2> /dev
/null
; then
36 echo "# Can't mount $DEV/$1 to $MNT/$1."
37 echo "# Redo from start after adding the following line to your /etc/fstab:"
39 echo " $DEV/$1 $MNT/$1 ext3 loop,user,noauto 0 0"
45 # make_test_file <name> <size> <date>
46 function make_test_file
{
47 mkdir
-p `dirname "$1"`
48 dd if=/dev
/zero of
="$1" bs
=1024 count
=$2 2> /dev
/null
49 echo "++++++++++++++++++++++++++$RANDOM***$3---$1" >> "$1"
53 ## # find_and_compare <origin_dir> <origin_dir> ... :: <copy_dir> <copy_dir> ...
54 ## function find_and_compare {
55 ## ORIGIN_DIRS=$1; shift;
56 ## until [[ $1 == "::" ]]; do
57 ## ORIGIN_DIRS="$ORIGIN_DIRS $1"; shift;
65 ## for ORIGIN_DIR in $ORIGIN_DIRS; do
66 ## find $ORIGIN_DIR -type f -print0 2> /dev/null | while read -d $'\000' ORIGIN_FILE; do
67 ## for COPY_DIR in $COPY_DIRS; do
68 ## NAME_IN_COPY_DIR=$COPY_DIR/${ORIGIN_FILE#$ORIGIN_DIR/}
69 ## FOUND=`find $COPY_DIR -path "$NAME_IN_COPY_DIR" -print 2> /dev/null`
70 ## if [[ $FOUND != "" ]] ; then
74 ## if [[ $FOUND == "" ]] ; then
75 ## MISSING="$MISSING $ORIGIN_FILE";
77 ## elif ! cmp --quiet "$ORIGIN_FILE" "$FOUND"; then
78 ## DIVERGING="$DIVERGING $ORIGIN_FILE"
79 ## elif [[ `stat --printf="%Y" $ORIGIN_FILE` != `stat --printf="%Y" $FOUND` ]]; then
80 ## DIVERGING_MTIME="$DIVERGING_MTIME $ORIGIN_FILE"
82 ## echo "MM: $MISSING"
84 ## echo "MMM: $MISSING"
86 ## echo "MMMM: $MISSING"
88 ## if [[ $MISSING != "" ]]; then
90 ## echo "MISSING: $MISSING"
92 ## if [[ $DIVERGING != "" ]]; then
93 ## RETURN_VALUE=$((return_value + 2))
94 ## echo "DIVERGING: $DIVERGING"
96 ## if [[ $DIVERGING_MTIME != "" ]]; then
97 ## RETURN_VALUE=$((return_value + 4))
98 ## echo "DIVERGING MTIME: $DIVERGING_MTIME"
100 ## return $RETURN_VALUE
104 # find_and_compare <origin_dir> <origin_dir> ... :: <copy_dir> <copy_dir> ...
105 function find_and_compare
{
106 ORIGIN_DIRS
=$1; shift;
107 until [[ $1 == "::" ]]; do
108 ORIGIN_DIRS
="$ORIGIN_DIRS $1"; shift;
116 for ORIGIN_DIR
in $ORIGIN_DIRS; do
117 for ORIGIN_FILE
in `find $ORIGIN_DIR -type f 2> /dev/null`; do
118 for COPY_DIR
in $COPY_DIRS; do
119 FOUND
=`find $COPY_DIR -path "$COPY_DIR/${ORIGIN_FILE#$ORIGIN_DIR/}" 2> /dev/null`
120 if [[ $FOUND != "" ]] ; then
124 if [[ $FOUND == "" ]] ; then
125 MISSING
="$MISSING $ORIGIN_FILE";
126 elif ! cmp --quiet $ORIGIN_FILE $FOUND; then
127 DIVERGING
="$DIVERGING $ORIGIN_FILE"
128 elif [[ `stat --printf="%Y" $ORIGIN_FILE` != `stat --printf="%Y" $FOUND` ]]; then
129 DIVERGING_MTIME
="$DIVERGING_MTIME $ORIGIN_FILE"
133 if [[ $MISSING != "" ]]; then
135 echo "MISSING: $MISSING"
137 if [[ $DIVERGING != "" ]]; then
138 RETURN_VALUE
=$
((return_value
+ 2))
139 echo "DIVERGING: $DIVERGING"
141 if [[ $DIVERGING_MTIME != "" ]]; then
142 RETURN_VALUE
=$
((return_value
+ 4))
143 echo "DIVERGING MTIME: $DIVERGING_MTIME"
148 # run_test <expected_return> <test-command> <comment>
151 killall monikop pokinom
2> /dev
/null
153 killall
-KILL monikop pokinom
2> /dev
/null
155 echo "RUNNING $2 [$3]"
156 TEST_COUNT
=$
(( TEST_COUNT
+ 1 ))
159 if [[ $RETURN_VALUE -ne $1 ]]; then
160 FAIL_COUNT
=$
(( FAIL_COUNT
+ 1 ))
161 FAILED_TESTS
="$FAILED_TESTS$2($1? $RETURN_VALUE!) [$3]\n"
162 echo "$2 should have returned $1 but returned $RETURN_VALUE instead."
167 umount
$MNT/* #2> /dev/null
168 rm -rf $DEV $MNT $LOG
169 mkdir
-p $DEV $MNT $RSYNC
171 # Create and mount test drives:
172 for i
in 01 02 03 04; do
173 make_test_drive
$i 102400
174 if [[ $?
== 1 ]]; then
178 make_test_drive
05 307200
179 if [[ $?
== 1 ]]; then
182 if [[ $MOUNTING_PROBLEM == 1 ]]; then exit; fi
184 function fill_sources_with_big_files
{
185 for i
in f1 f2 f3
; do
186 make_test_file
$MNT/01/data
/$i 25000 200703250845.33
188 for i
in f10 f11 f12
; do
189 make_test_file
$MNT/02/data
/$i 25000 200703250845.33
191 for i
in f4 f5 f6
; do
192 make_test_file
$MNT/01/data
/d
1/$i 2000 200703250845.33
193 make_test_file
$MNT/01/data
/d
1/d
2/$i 2000 200703250845.33
195 for i
in f7 f8 f9
; do
196 make_test_file
$MNT/02/data
/d
1/$i 2000 200703250845.33
197 make_test_file
$MNT/02/data
/d
1/d
2/$i 2000 200703250845.33
201 function fill_sources_with_hidden_files
{
203 make_test_file
$MNT/$i/data
/.hidden_dir_
$i/.hidden_file
20 200804250955.10
207 function fill_destinations_with_few_small_files
{
209 for j
in file_one file_two file_three
; do
210 make_test_file
$MNT/$i/measuring_data
/$i/$j 20 200004250955.10
215 # Prepare data sources:
216 fill_sources_with_big_files
218 # Check how fast we are:
220 T1
=`/usr/bin/time --format="%e" rsync --recursive --times $MNT/01/data/ $MNT/03/ 2>&1 &`
221 T2
=`/usr/bin/time --format="%e" rsync --recursive --times $MNT/02/data/ $MNT/04/ 2>&1 &`
222 INTERRUPTION_TIME_0
=`echo "($T1 + $T2) * 3" | bc`
223 INTERRUPTION_TIME_1
=`echo "($T1 + $T2) * .08" | bc`
224 INTERRUPTION_TIME_2
=`echo "($T1 + $T2) * .82" | bc`
225 echo $INTERRUPTION_TIME_0
226 rm -rf $MNT/0{1,2,3,4}/*
230 function test_monikop_simple
{
232 $MONIKOP_1 & sleep $INTERRUPTION_TIME_0; /bin
/kill -TERM $
!
234 find_and_compare
$MNT/0{1,2}/data
:: $MNT/0{3,4}/measuring_data
237 function test_monikop_simple_late_sources
{
239 $MONIKOP_1 & sleep $INTERRUPTION_TIME_2; start_rsyncd
; sleep $INTERRUPTION_TIME_0; /bin
/kill -TERM $
!
241 find_and_compare
$MNT/0{1,2}/data
:: $MNT/0{3,4}/measuring_data
244 function test_monikop_short
{
245 $MONIKOP_1 & sleep $INTERRUPTION_TIME_1; /bin
/kill -TERM $
!
247 find_and_compare
$MNT/0{1,2}/data
:: $MNT/0{3,4}/measuring_data
250 function test_monikop_short_2
{
251 $MONIKOP_2 & sleep $INTERRUPTION_TIME_1; /bin
/kill -TERM $
!
253 find_and_compare
$MNT/0{1,2}/data
:: $MNT/0{3,4,5}/measuring_data
256 function test_monikop_short_kill_rsync_first
{
257 $MONIKOP_2 & sleep $INTERRUPTION_TIME_1; /usr
/bin
/killall
-KILL rsync
; sleep 1; /bin
/kill -TERM $
!
259 find_and_compare
$MNT/0{1,2}/data
:: $MNT/0{3,4,5}/measuring_data
266 function test_monikop_short_cut_sources
{
267 $MONIKOP_2 & sleep $INTERRUPTION_TIME_1; kill_rsyncd
; sleep 1; /bin
/kill -TERM $
!
269 find_and_compare
$MNT/0{1,2}/data
:: $MNT/0{3,4,5}/measuring_data
276 function test_monikop_simple_2
{
277 $MONIKOP_2 & sleep $INTERRUPTION_TIME_0; /bin
/kill -TERM $
!
279 find_and_compare
$MNT/0{1,2}/data
:: $MNT/0{3,4,5}/measuring_data
282 function test_monikop_simple_3
{
283 $MONIKOP_3 & sleep $INTERRUPTION_TIME_0; /bin
/kill -TERM $
!
285 find_and_compare
$MNT/0{1,2}/data
:: $MNT/0{3,4}/measuring_data
/dir_0
{1,2}
288 function test_monikop_overflow
{
289 # Stuff one of the destinations a bit:
290 make_test_file
$MNT/03/stuffing
25000 199903250845
291 $MONIKOP_1 & sleep $INTERRUPTION_TIME_0; /bin
/kill -TERM $
!
293 find_and_compare
$MNT/0{1,2}/data
:: $MNT/0{3,4}/measuring_data
296 function test_monikop_no_destination
{
297 # We test basically if there is something to kill.
299 $MONIKOP_1 & sleep $INTERRUPTION_TIME_2; /bin
/kill -TERM $
!
306 function test_monikop_no_source
{
307 # We test basically if there is something to kill.
309 $MONIKOP_1 & sleep $INTERRUPTION_TIME_2; /bin
/kill -TERM $
!
315 function test_pokinom_clean_finish
{
316 $POKINOM & sleep $INTERRUPTION_TIME_0; /bin
/kill -TERM $
!
318 find_and_compare
$MNT/0{1,2}/data
:: $MNT/05/NEW_DATA
321 function test_pokinom_short
{
322 $POKINOM & sleep $INTERRUPTION_TIME_1; /bin
/kill -TERM $
!
324 find_and_compare
$MNT/0{1,2}/data
:: $MNT/05/NEW_DATA
327 function test_pokinom_late_destination
{
329 $POKINOM & sleep $INTERRUPTION_TIME_2; start_rsyncd
; sleep $INTERRUPTION_TIME_0; /bin
/kill -TERM $
!
331 find_and_compare
$MNT/0{1,2}/data
:: $MNT/05/NEW_DATA
334 function test_dirs_backed_up
{
335 test -d $MNT/03/backed_up
&& test -d $MNT/04/backed_up
338 function test_monikop_deletes_being_deleted_dir
{
339 mkdir
-p $MNT/0{3,4}/{being_deleted
,backed_up
}
340 touch $MNT/0{3,4}/{being_deleted
,backed_up
}/some_file
341 touch $MNT/0{3,4}/{being_deleted
,backed_up
}/.some_hidden_file
342 $MONIKOP_1 & sleep $INTERRUPTION_TIME_2; /bin
/kill -TERM $
!
343 test -d $MNT/03/being_deleted ||
test -d $MNT/04/being_deleted
346 function test_pokinom_deletes_being_deleted_dir
{
347 mkdir
-p $MNT/0{3,4}/being_deleted
348 touch $MNT/0{3,4}/being_deleted
/some_file
349 touch $MNT/0{3,4}/being_deleted
/.some_hidden_file
350 $POKINOM & sleep $INTERRUPTION_TIME_2; /bin
/kill -TERM $
!
351 test -d $MNT/03/being_deleted ||
test -d $MNT/04/being_deleted
354 function test_pokinom_newer_files_win
{
355 fill_destinations_with_few_small_files
356 $POKINOM & sleep $INTERRUPTION_TIME_2; /bin
/kill -TERM $
!
358 mv $MNT/$i/backed_up
$MNT/$i/measuring_data
359 touch $MNT/$i/measuring_data
/$i/*
361 $POKINOM & sleep $INTERRUPTION_TIME_2; /bin
/kill -TERM $
!
363 find_and_compare
$MNT/0{3,4}/backed_up
:: $MNT/05/NEW_DATA
366 function test_pokinom_older_files_lose
{
367 fill_destinations_with_few_small_files
368 $POKINOM & sleep $INTERRUPTION_TIME_2; /bin
/kill -TERM $
!
370 mv $MNT/$i/backed_up
$MNT/$i/measuring_data
372 touch -t 198001011200.00 $MNT/03/measuring_data
/03/file_one
373 $POKINOM & sleep $INTERRUPTION_TIME_2; /bin
/kill -TERM $
!
375 find_and_compare
$MNT/0{3,4}/backed_up
:: $MNT/05/NEW_DATA
380 ##########################
381 ### Run tests: Monikop
382 ##########################
384 fill_sources_with_big_files
386 run_test
1 test_monikop_deletes_being_deleted_dir
"Monikop deletes left-over directory named being_deleted."
388 rm -rf $MNT/0{3,4}/* $LOG
390 chmod a-w
,a-x
$MNT/0{3,4}
391 run_test
1 test_monikop_simple
"Unwritable destination"
392 chmod a
+w
,a
+x
$MNT/0{3,4}
393 run_test
0 test_monikop_simple
"Unwritable destination"
395 rm -rf $MNT/0{3,4}/* $LOG
397 run_test
0 test_monikop_simple_3
"Source-specific directories on disks"
399 rm -rf $MNT/0{3,4}/* $LOG
401 run_test
0 test_monikop_simple_late_sources
"Simple run, sources coming up late."
403 mv $MNT/03/measuring_data
$MNT/03/backed_up
404 mv $MNT/04/measuring_data
$MNT/04/backed_up
407 run_test
0 test_monikop_simple
"Simple run, deletion."
409 rm -rf $MNT/0{3,4}/* $LOG
411 run_test
1 test_monikop_short
"Interruption, finished.* or finished.*.bak deleted."
412 rm -f $LOG/finished.rsync___localhost_2000_test_01_data
$LOG/finished.rsync___localhost_2000_test_02_data.bak
413 run_test
0 test_monikop_simple
"Recovery after interruption, finished.* or finished.*.bak deleted."
415 rm -rf $MNT/0{3,4}/* $LOG
417 run_test
1 test_monikop_short
"Interruption, finished.* and/or log.* deleted."
418 rm -f $LOG/finished.rsync___localhost_2000_test_01_data
$LOG/log.rsync___localhost_2000_test_01_data
419 rm -f $LOG/rm log.rsync___localhost_2000_test_02_data
420 run_test
0 test_monikop_simple
"Recovery after interruption, finished.* and/or log.* deleted."
422 rm -rf $MNT/0{3,4}/* $LOG
424 run_test
1 test_monikop_short_2
"Repeated interruption."
425 run_test
1 test_monikop_short_2
"Repeated interruption (may pass unexpectedly due to test timing)."
426 run_test
0 test_monikop_simple_2
"Repeated interruption."
428 mv $MNT/03/measuring_data
$MNT/03/backed_up
429 mv $MNT/04/measuring_data
$MNT/04/backed_up
430 mv $MNT/05/measuring_data
$MNT/05/backed_up
433 run_test
1 test_monikop_short_2
"Repeated interruption, deletion."
434 run_test
1 test_monikop_short_2
"Repeated interruption, deletion (may pass unexpectedly due to test timing)."
435 run_test
0 test_monikop_simple_2
"Repeated interruption, deletion."
437 rm -rf $MNT/0{3,4,5}/* $LOG
439 run_test
0 test_monikop_no_destination
"No destination available."
440 run_test
0 test_monikop_no_source
"No destination available."
442 rm -rf $MNT/0{3,4}/* $LOG
444 run_test
1 test_monikop_short_kill_rsync_first
"Rsync killed."
446 run_test
0 test_monikop_simple_2
"Rsync killed."
448 rm -rf $MNT/0{3,4,5}/* $LOG
450 run_test
1 test_monikop_short_cut_sources
"Connection to source destroyed."
451 run_test
0 test_monikop_simple_2
"Connection to source destroyed."
453 rm -rf $MNT/0{3,4,5}/* $LOG
455 ##############################
457 ##############################
459 run_test
1 test_pokinom_deletes_being_deleted_dir
"Pokinom deletes left-over directory named being_deleted."
461 rm -rf $MNT/0{3,4,5}/*
463 run_test
0 test_pokinom_newer_files_win
"Pokinom overwrites older files in Destination."
465 run_test
4 test_pokinom_older_files_lose
"Pokinom discards older files on removable disk."
467 ##############################
468 # Monikop and Pokinom together
469 ##############################
471 rm -rf $MNT/0{1,2,3,4,5}/*
472 fill_sources_with_hidden_files
474 run_test
0 test_monikop_simple
"Preparation for simple Pokinom test, hidden files."
475 run_test
0 test_pokinom_clean_finish
"Simple Pokinom test, hidden files."
476 run_test
0 test_dirs_backed_up
"Simple Pokinom test, hidden files."
477 run_test
1 test_monikop_short
"After test with hidden files, this one should do nothing but delete backed_up."
478 run_test
1 test_dirs_backed_up
"Deletion of backed_up with hidden files."
480 rm -rf $MNT/0{1,2,3,4,5}/*
481 fill_sources_with_big_files
483 run_test
0 test_monikop_simple
"Simple run in preparation for simple Pokinom test."
484 run_test
0 test_pokinom_clean_finish
"Simple Pokinom test."
485 run_test
0 test_dirs_backed_up
"Simple Pokinom test: directories renamed?."
487 rm -rf $MNT/05/* $LOG
489 run_test
0 test_monikop_simple
"Preparation for Pokinom's destination overfull."
491 make_test_file
$MNT/05/stuffing
200000 199903250845
492 run_test
1 test_pokinom_clean_finish
"Pokinom's destination overfull."
494 run_test
0 test_pokinom_clean_finish
"Pokinom's destination no longer overfull: recovering."
496 rm -rf $MNT/05/* $LOG
498 run_test
0 test_monikop_simple
"Simple run in preparation for Pokinom, late destination."
499 run_test
0 test_pokinom_late_destination
"Pokinom, late destination."
501 rm -rf $MNT/05/* $LOG
503 run_test
0 test_monikop_simple
"Simple run in preparation for Pokinom stopped early."
504 run_test
1 test_pokinom_short
"Pokinom stopped early."
505 run_test
0 test_monikop_simple
"Simple run after Pokinom having been stopped early."
506 run_test
0 test_pokinom_clean_finish
"Simple run after Pokinom having been stopped early."
508 rm -rf $MNT/05/* $LOG
510 run_test
0 test_monikop_simple
"Simple run in preparation for \"file grown too large\""
512 cat $MNT/01/data
/f1
>> $MNT/01/data
/f2
513 run_test
2 test_monikop_simple
"Repeated run, file grown too large."
514 run_test
2 test_pokinom_clean_finish
"Repeated run, file grown too large."
515 run_test
1 test_monikop_simple
"Repeated run, file grown too large."
516 run_test
0 test_pokinom_clean_finish
"Repeated run, file grown too large."
518 rm -rf $MNT/05/* $LOG
520 run_test
1 test_monikop_overflow
"Initially, too little room on disks."
521 run_test
1 test_pokinom_clean_finish
"Initially, too little room on disks."
522 run_test
1 test_monikop_overflow
"Previously, too little room on disks."
523 run_test
0 test_pokinom_clean_finish
"Previously, too little room on disks."
525 rm -rf $MNT/0{3,4,5}/* $LOG
527 run_test
1 test_monikop_short
"Unfinished by Monikop, then another full cycle."
528 run_test
1 test_pokinom_clean_finish
"Unfinished by Monikop, then another full cycle (Outcome unpredictable)."
529 run_test
1 test_monikop_simple
"Previously unfinished by Monikop, now another full cycle (Outcome unpredictable)."
530 run_test
0 test_pokinom_clean_finish
"Previously unfinished by Monikop, now another full cycle."
532 # TODO: the following fails at least in part due to bugs in the tests themselves.
533 rm -rf $MNT/0{1,2,3,4,5}/* $LOG
534 make_test_file
$MNT/01/data
/d
1/f1
10 200703250845.33
535 make_test_file
$MNT/01/data
/d
2/f3
10 200703250845.33
536 make_test_file
$MNT/01/data
/d
3/d
4/f4
10 200703250845.33
537 make_test_file
$MNT/01/data
/f2
10 200703250845.33
538 make_test_file
$MNT/01/data
/f5
10 200703250845.33
539 mv $MNT/01/data
/d
1/f1
"$MNT/01/data/d1/Große Datei"
540 mv $MNT/01/data
/d1
"$MNT/01/data/Schönes Verzeichnis"
541 mv $MNT/01/data
/f2
"$MNT/01/data/{[cool]} file\ n\\a\\m\\e."
542 # Not sure if this will ever work:
543 mv $MNT/01/data
/d2
$MNT/01/data
/.rsync_partial
544 mv $MNT/01/data
/d
3/d4
$MNT/01/data
/d
3/.rsync_partial
545 run_test
0 test_monikop_simple
"Weird file names."
546 run_test
0 test_pokinom_clean_finish
"Weird file names."
547 run_test
1 test_monikop_short
"Weird file names, second run: nothing to do."
549 ########################################
551 ########################################
554 echo "TOTAL NUMBER OF TESTS: $TEST_COUNT"
555 echo "NUMBER OF FAILED TESTS: $FAIL_COUNT"
557 echo -e "$FAILED_TESTS"