3 # Caveats: - kills all killable instances of rsync, monikop, pokinom
4 # - don't disturb test timing by putting too much (extra) load
9 TESTDIR
=/tmp
/monikop-test
14 MONIKOP_1
="../monikop ../test/monikop.config.test.1"
15 MONIKOP_2
="../monikop ../test/monikop.config.test.2"
16 MONIKOP_3
="../monikop ../test/monikop.config.test.3"
17 POKINOM
="../pokinom ../test/pokinom.config.test"
22 function kill_rsyncd
{
23 kill `cat $TESTDIR/rsync/rsyncd.pid`
26 function start_rsyncd
{
27 kill_rsyncd
2> /dev
/null
28 rm -f $RSYNC/rsyncd.pid
2> /dev
/null
29 chmod o-rwx ..
/test
/rsyncd.secrets.
test
30 rsync
--daemon --config=..
/test
/rsyncd.conf.
test
33 # make_test_drive <name> <size>
34 function make_test_drive
{
36 dd if=/dev
/zero of
=$DEV/$1 bs
=1024 count
=$2 2> /dev
/null
37 /sbin
/mkfs.ext3
-m 0 -Fq $DEV/$1
38 if ! mount
$MNT/$1 2> /dev
/null
; then
39 echo "# Can't mount $DEV/$1 to $MNT/$1."
40 echo "# Redo from start after adding the following line to your /etc/fstab:"
42 echo " $DEV/$1 $MNT/$1 ext3 loop,user,noauto 0 0"
48 # make_test_file <name> <size> <date>
49 function make_test_file
{
50 mkdir
-p `dirname "$1"`
51 dd if=/dev
/zero of
="$1" bs
=1024 count
=$2 2> /dev
/null
52 echo "++++++++++++++++++++++++++$RANDOM***$3---$1" >> "$1"
56 # find_and_compare <origin_dir> <origin_dir> ... :: <copy_dir> <copy_dir> ...
57 function find_and_compare
{
58 ORIGIN_DIRS
=$1; shift;
59 until [[ $1 == "::" ]]; do
60 ORIGIN_DIRS
="$ORIGIN_DIRS $1"; shift;
68 for ORIGIN_DIR
in $ORIGIN_DIRS; do
69 while read -r -d $
'\0' ORIGIN_FILE
; do
70 ORIGIN_FILE_ESCAPED
=${ORIGIN_FILE//\\/\\\\}
71 ORIGIN_FILE_ESCAPED
=${ORIGIN_FILE_ESCAPED//\[/\\[}
72 for COPY_DIR
in $COPY_DIRS; do
73 FOUND
=`find $COPY_DIR -path "$COPY_DIR/${ORIGIN_FILE_ESCAPED#$ORIGIN_DIR/}" -print0 2> /dev/null`
74 if [[ -n "$FOUND" ]] ; then
78 if [[ -z "$FOUND" ]] ; then
79 MISSING
="$MISSING $ORIGIN_FILE";
80 elif ! cmp --quiet "$ORIGIN_FILE" "$FOUND"; then
81 DIVERGING
="$DIVERGING $ORIGIN_FILE"
82 elif [[ `stat --printf="%Y" "$ORIGIN_FILE"` != `stat --printf="%Y" "$FOUND"` ]]; then
83 DIVERGING_MTIME
="$DIVERGING_MTIME $ORIGIN_FILE"
85 done < <(find $ORIGIN_DIR -type f
-print0 2> /dev
/null
)
87 if [[ -n $MISSING ]]; then
89 echo "MISSING: $MISSING"
91 if [[ -n $DIVERGING ]]; then
92 RETURN_VALUE
=$
((return_value
+ 2))
93 echo "DIVERGING: $DIVERGING"
95 if [[ -n $DIVERGING_MTIME ]]; then
96 RETURN_VALUE
=$
((return_value
+ 4))
97 echo "DIVERGING MTIME: $DIVERGING_MTIME"
102 # run_test <return_value> <test> <documentation>
105 killall monikop pokinom
2> /dev
/null
107 killall
-KILL monikop pokinom
2> /dev
/null
109 echo "RUNNING $2 [$3]"
112 if [[ $1 != "ignore" ]]; then
113 TEST_COUNT
=$
(( TEST_COUNT
+ 1 ))
114 if [[ $RETURN_VALUE -ne $1 ]]; then
115 FAIL_COUNT
=$
(( FAIL_COUNT
+ 1 ))
116 FAILED_TESTS
="$FAILED_TESTS$2($1? $RETURN_VALUE!) [$3]\n"
117 echo "$2 should have returned $1 but returned $RETURN_VALUE instead."
120 echo "(DUMMY TEST, IGNORED)"
125 # Create and mount test drives:
126 umount
$MNT/* #2> /dev/null
127 rm -rf $DEV $MNT $LOG
128 mkdir
-p $DEV $MNT $RSYNC
130 for i
in 01 02 03 04; do
131 make_test_drive
$i 102400
132 if [[ $?
== 1 ]]; then
136 make_test_drive
05 307200
137 if [[ $?
== 1 ]]; then
140 if [[ $MOUNTING_PROBLEM == 1 ]]; then exit; fi
142 function fill_sources_with_big_files
{
143 for i
in f1 f2 f3
; do
144 make_test_file
$MNT/01/data
/$i 25000 200703250845.33
146 for i
in f10 f11 f12
; do
147 make_test_file
$MNT/02/data
/$i 25000 200703250845.33
149 for i
in f4 f5 f6
; do
150 make_test_file
$MNT/01/data
/d
1/$i 2000 200703250845.33
151 make_test_file
$MNT/01/data
/d
1/d
2/$i 2000 200703250845.33
153 for i
in f7 f8 f9
; do
154 make_test_file
$MNT/02/data
/d
1/$i 2000 200703250845.33
155 make_test_file
$MNT/02/data
/d
1/d
2/$i 2000 200703250845.33
159 function fill_sources_with_hidden_files
{
161 make_test_file
$MNT/$i/data
/.hidden_dir_
$i/.hidden_file
20 200804250955.10
165 function fill_sources_with_few_small_files
{
167 for j
in file_one file_two file_three
; do
168 make_test_file
$MNT/$i/data
/$j.
$i 20 200004250955.10
173 function fill_destinations_with_few_small_files
{
175 for j
in file_one file_two file_three
; do
176 make_test_file
$MNT/$i/measuring_data
/$i/$j 20 200004250955.10
181 # Check how fast we are:
182 fill_sources_with_big_files
183 T1
=`/usr/bin/time --format="%e" rsync --recursive --times $MNT/01/data/ $MNT/03/ 2>&1 &`
184 T2
=`/usr/bin/time --format="%e" rsync --recursive --times $MNT/02/data/ $MNT/04/ 2>&1 &`
185 INTERRUPTION_TIME_0
=`echo "($T1 + $T2) * 3" | bc`
186 INTERRUPTION_TIME_1
=`echo "($T1 + $T2) * .08" | bc`
187 INTERRUPTION_TIME_2
=`echo "($T1 + $T2) * .82" | bc`
188 echo "One run of a testee takes about $INTERRUPTION_TIME_0 seconds."
189 rm -rf $MNT/0{1,2,3,4}/*
191 ######################################################################
193 ######################################################################
195 function test_monikop_simple
{
197 $MONIKOP_1 & sleep $INTERRUPTION_TIME_0; /bin
/kill -TERM $
!
199 find_and_compare
$MNT/0{1,2}/data
:: $MNT/0{3,4}/measuring_data
202 function test_monikop_simple_late_sources
{
204 $MONIKOP_1 & sleep $INTERRUPTION_TIME_2; start_rsyncd
; sleep $INTERRUPTION_TIME_0; /bin
/kill -TERM $
!
206 find_and_compare
$MNT/0{1,2}/data
:: $MNT/0{3,4}/measuring_data
209 function test_monikop_short
{
210 $MONIKOP_1 & sleep $INTERRUPTION_TIME_1; /bin
/kill -TERM $
!
212 find_and_compare
$MNT/0{1,2}/data
:: $MNT/0{3,4}/measuring_data
215 function test_monikop_short_2
{
216 $MONIKOP_2 & sleep $INTERRUPTION_TIME_1; /bin
/kill -TERM $
!
218 find_and_compare
$MNT/0{1,2}/data
:: $MNT/0{3,4,5}/measuring_data
221 function test_monikop_short_kill_rsync_first
{
222 $MONIKOP_2 & sleep $INTERRUPTION_TIME_1; /usr
/bin
/killall
-KILL rsync
; sleep 1; /bin
/kill -TERM $
!
224 find_and_compare
$MNT/0{1,2}/data
:: $MNT/0{3,4,5}/measuring_data
231 function test_monikop_short_cut_sources
{
232 $MONIKOP_2 & sleep $INTERRUPTION_TIME_1; kill_rsyncd
; sleep 1; /bin
/kill -TERM $
!
234 find_and_compare
$MNT/0{1,2}/data
:: $MNT/0{3,4,5}/measuring_data
241 function test_monikop_simple_2
{
242 $MONIKOP_2 & sleep $INTERRUPTION_TIME_0; /bin
/kill -TERM $
!
244 find_and_compare
$MNT/0{1,2}/data
:: $MNT/0{3,4,5}/measuring_data
247 function test_monikop_simple_3
{
248 $MONIKOP_3 & sleep $INTERRUPTION_TIME_0; /bin
/kill -TERM $
!
250 find_and_compare
$MNT/0{1,2}/data
:: $MNT/0{3,4}/measuring_data
/dir_0
{1,2}
253 function test_monikop_overflow
{
254 # Stuff one of the destinations a bit:
255 make_test_file
$MNT/03/stuffing
25000 199903250845
256 $MONIKOP_1 & sleep $INTERRUPTION_TIME_0; /bin
/kill -TERM $
!
258 find_and_compare
$MNT/0{1,2}/data
:: $MNT/0{3,4}/measuring_data
261 function test_monikop_no_destination
{
262 # We test basically if there is something to kill.
264 $MONIKOP_1 & sleep $INTERRUPTION_TIME_2; /bin
/kill -TERM $
!
271 function test_monikop_no_source
{
272 # We test basically if there is something to kill.
274 $MONIKOP_1 & sleep $INTERRUPTION_TIME_2; /bin
/kill -TERM $
!
280 function test_pokinom_clean_finish
{
281 $POKINOM & sleep $INTERRUPTION_TIME_0; /bin
/kill -TERM $
!
283 find_and_compare
$MNT/0{1,2}/data
:: $MNT/05/NEW_DATA
286 function test_pokinom_short
{
287 $POKINOM & sleep $INTERRUPTION_TIME_1; /bin
/kill -TERM $
!
289 find_and_compare
$MNT/0{1,2}/data
:: $MNT/05/NEW_DATA
292 function test_pokinom_late_destination
{
294 $POKINOM & sleep $INTERRUPTION_TIME_2; start_rsyncd
; sleep $INTERRUPTION_TIME_0; /bin
/kill -TERM $
!
296 find_and_compare
$MNT/0{1,2}/data
:: $MNT/05/NEW_DATA
299 function test_dirs_backed_up
{
300 test -d $MNT/03/backed_up
&& test -d $MNT/04/backed_up
303 function test_monikop_deletes_being_deleted_dir
{
304 mkdir
-p $MNT/0{3,4}/{being_deleted
,backed_up
}
305 touch $MNT/0{3,4}/{being_deleted
,backed_up
}/some_file
306 touch $MNT/0{3,4}/{being_deleted
,backed_up
}/.some_hidden_file
307 $MONIKOP_1 & sleep $INTERRUPTION_TIME_2; /bin
/kill -TERM $
!
308 test -d $MNT/03/being_deleted ||
test -d $MNT/04/being_deleted
311 function test_pokinom_deletes_being_deleted_dir
{
312 mkdir
-p $MNT/0{3,4}/being_deleted
313 touch $MNT/0{3,4}/being_deleted
/some_file
314 touch $MNT/0{3,4}/being_deleted
/.some_hidden_file
315 $POKINOM & sleep $INTERRUPTION_TIME_2; /bin
/kill -TERM $
!
316 test -d $MNT/03/being_deleted ||
test -d $MNT/04/being_deleted
319 function test_pokinom_newer_files_win
{
320 fill_destinations_with_few_small_files
321 $POKINOM & sleep $INTERRUPTION_TIME_2; /bin
/kill -TERM $
!
323 mv $MNT/$i/backed_up
$MNT/$i/measuring_data
324 touch $MNT/$i/measuring_data
/$i/*
326 $POKINOM & sleep $INTERRUPTION_TIME_2; /bin
/kill -TERM $
!
328 find_and_compare
$MNT/0{3,4}/backed_up
:: $MNT/05/NEW_DATA
331 function test_pokinom_older_files_lose
{
332 fill_destinations_with_few_small_files
333 $POKINOM & sleep $INTERRUPTION_TIME_2; /bin
/kill -TERM $
!
335 mv $MNT/$i/backed_up
$MNT/$i/measuring_data
337 touch -t 198001011200.00 $MNT/03/measuring_data
/03/file_one
338 $POKINOM & sleep $INTERRUPTION_TIME_2; /bin
/kill -TERM $
!
340 find_and_compare
$MNT/0{3,4}/backed_up
:: $MNT/05/NEW_DATA
343 ######################################################################
345 ######################################################################
348 #########################
349 ## Run tests: Monikop
350 #########################
352 fill_sources_with_big_files
354 run_test
1 test_monikop_deletes_being_deleted_dir
"Monikop deletes left-over directory named being_deleted."
356 rm -rf $MNT/0{3,4}/* $LOG
358 chmod a-w
,a-x
$MNT/0{3,4}
359 run_test
1 test_monikop_simple
"Unwritable destination"
360 chmod a
+w
,a
+x
$MNT/0{3,4}
361 run_test
0 test_monikop_simple
"Unwritable destination"
363 rm -rf $MNT/0{3,4}/* $LOG
365 run_test
0 test_monikop_simple_3
"Source-specific directories on disks"
367 rm -rf $MNT/0{3,4}/* $LOG
369 run_test
0 test_monikop_simple_late_sources
"Simple run, sources coming up late."
371 mv $MNT/03/measuring_data
$MNT/03/backed_up
372 mv $MNT/04/measuring_data
$MNT/04/backed_up
375 run_test
0 test_monikop_simple
"Simple run, deletion."
377 rm -rf $MNT/0{3,4}/* $LOG
379 run_test
1 test_monikop_short
"Interruption, finished.* or finished.*.bak deleted."
380 rm -f $LOG/finished.rsync___localhost_2000_test_01_data
$LOG/finished.rsync___localhost_2000_test_02_data.bak
381 run_test
0 test_monikop_simple
"Recovery after interruption, finished.* or finished.*.bak deleted."
383 rm -rf $MNT/0{3,4}/* $LOG
385 run_test
1 test_monikop_short
"Interruption, finished.* and/or log.* deleted."
386 rm -f $LOG/finished.rsync___localhost_2000_test_01_data
$LOG/log.rsync___localhost_2000_test_01_data
387 rm -f $LOG/rm log.rsync___localhost_2000_test_02_data
388 run_test
0 test_monikop_simple
"Recovery after interruption, finished.* and/or log.* deleted."
390 rm -rf $MNT/0{3,4}/* $LOG
392 run_test
1 test_monikop_short_2
"Repeated interruption."
393 run_test ignore test_monikop_short_2
"Repeated interruption (No test, side effect only)."
394 run_test
0 test_monikop_simple_2
"Repeated interruption."
396 mv $MNT/03/measuring_data
$MNT/03/backed_up
397 mv $MNT/04/measuring_data
$MNT/04/backed_up
398 mv $MNT/05/measuring_data
$MNT/05/backed_up
401 run_test
1 test_monikop_short_2
"Repeated interruption, deletion."
402 run_test ignore test_monikop_short_2
"Repeated interruption, deletion (No test, side offect only)."
403 run_test
0 test_monikop_simple_2
"Repeated interruption, deletion."
405 rm -rf $MNT/0{3,4,5}/* $LOG
407 run_test
0 test_monikop_no_destination
"No destination available."
408 run_test
0 test_monikop_no_source
"No destination available."
410 rm -rf $MNT/0{3,4}/* $LOG
412 run_test
1 test_monikop_short_kill_rsync_first
"Rsync killed."
414 run_test
0 test_monikop_simple_2
"Rsync killed."
416 rm -rf $MNT/0{3,4,5}/* $LOG
418 run_test
1 test_monikop_short_cut_sources
"Connection to source destroyed."
419 run_test
0 test_monikop_simple_2
"Connection to source destroyed."
421 rm -rf $MNT/0{3,4,5}/* $LOG
423 fill_sources_with_few_small_files
425 run_test
0 test_monikop_simple
"Don't re-rsync after deletion of finished.* (Preparation #1)."
426 rm -rf $MNT/{03,04}/*
427 run_test
1 test_monikop_short
"Don't re-rsync after deletion of finished.* (Preparation #2, fill finished.*)."
428 rm -f $LOG/log.rsync___localhost_2000_test_
*
429 rm -f $LOG/finished.rsync___localhost_2000_test_
*_data
430 run_test
1 test_monikop_short
"Don't re-rsync after deletion of finished.*"
431 rm -rf $MNT/0{3,4}/* $LOG
432 run_test
0 test_monikop_simple
"Don't re-rsync after deletion of finished.*.bak (Preparation #1)."
433 rm -rf $MNT/{03,04}/*
434 run_test
1 test_monikop_short
"Don't re-rsync after deletion of finished.*.bak (Preparation #2, fill finished.*)."
435 rm -f $LOG/log.rsync___localhost_2000_test_
*
436 rm -f $LOG/finished.rsync___localhost_2000_test_
*_data.bak
437 run_test
1 test_monikop_short
"Don't re-rsync after deletion of finished.*.bak."
439 rm -rf $MNT/0{3,4}/* $LOG
441 ##############################
443 ##############################
445 run_test
1 test_pokinom_deletes_being_deleted_dir
"Pokinom deletes left-over directory named being_deleted."
447 rm -rf $MNT/0{3,4,5}/*
449 run_test
0 test_pokinom_newer_files_win
"Pokinom overwrites older files in Destination."
451 run_test
4 test_pokinom_older_files_lose
"Pokinom discards older files on removable disk."
453 ##################################################
454 # Run tests: Monikop and Pokinom together
455 ##################################################
457 rm -rf $MNT/0{1,2,3,4,5}/*
458 fill_sources_with_hidden_files
460 run_test
0 test_monikop_simple
"Preparation for simple Pokinom test, hidden files."
461 run_test
0 test_pokinom_clean_finish
"Simple Pokinom test, hidden files."
462 run_test
0 test_dirs_backed_up
"Simple Pokinom test, hidden files."
463 run_test
1 test_monikop_short
"After test with hidden files, this one should do nothing but delete backed_up."
464 run_test
1 test_dirs_backed_up
"Deletion of backed_up with hidden files."
466 rm -rf $MNT/0{1,2,3,4,5}/*
467 fill_sources_with_big_files
469 run_test
0 test_monikop_simple
"Simple run in preparation for simple Pokinom test."
470 run_test
0 test_pokinom_clean_finish
"Simple Pokinom test."
471 run_test
0 test_dirs_backed_up
"Simple Pokinom test: directories renamed?."
473 rm -rf $MNT/05/* $LOG
475 run_test
0 test_monikop_simple
"Preparation for Pokinom's destination overfull."
477 make_test_file
$MNT/05/stuffing
200000 199903250845
478 run_test
1 test_pokinom_clean_finish
"Pokinom's destination overfull."
480 run_test
0 test_pokinom_clean_finish
"Pokinom's destination no longer overfull: recovering."
482 rm -rf $MNT/05/* $LOG
484 run_test
0 test_monikop_simple
"Simple run in preparation for Pokinom, late destination."
485 run_test
0 test_pokinom_late_destination
"Pokinom, late destination."
487 rm -rf $MNT/05/* $LOG
489 run_test
0 test_monikop_simple
"Simple run in preparation for Pokinom stopped early."
490 run_test
1 test_pokinom_short
"Pokinom stopped early."
491 run_test
0 test_monikop_simple
"Simple run after Pokinom having been stopped early."
492 run_test
0 test_pokinom_clean_finish
"Simple run after Pokinom having been stopped early."
494 rm -rf $MNT/05/* $LOG
496 run_test
0 test_monikop_simple
"Simple run in preparation for \"file grown too large\""
498 cat $MNT/01/data
/f1
>> $MNT/01/data
/f2
499 run_test
2 test_monikop_simple
"Repeated run, file grown too large."
500 run_test
2 test_pokinom_clean_finish
"Repeated run, file grown too large."
501 run_test
1 test_monikop_simple
"Repeated run, file grown too large."
502 run_test
0 test_pokinom_clean_finish
"Repeated run, file grown too large."
504 rm -rf $MNT/05/* $LOG
506 run_test
1 test_monikop_overflow
"Initially, too little room on disks."
507 run_test
1 test_pokinom_clean_finish
"Initially, too little room on disks."
508 run_test
1 test_monikop_overflow
"Previously, too little room on disks."
509 run_test
0 test_pokinom_clean_finish
"Previously, too little room on disks."
511 rm -rf $MNT/0{3,4,5}/* $LOG
513 run_test
1 test_monikop_short
"Unfinished by Monikop, then another full cycle."
514 run_test ignore test_pokinom_clean_finish
"Unfinished by Monikop, then another full cycle (Outcome unpredictable)."
515 run_test ignore test_monikop_simple
"Previously unfinished by Monikop, now another full cycle (Outcome unpredictable)."
516 run_test
0 test_pokinom_clean_finish
"Previously unfinished by Monikop, now another full cycle."
518 rm -rf $MNT/0{1,2,3,4,5}/* $LOG
520 make_test_file
$MNT/01/data
/d
1/f1
10 200703250845.33
521 make_test_file
$MNT/01/data
/d
2/f3
10 200703250845.33
522 make_test_file
$MNT/01/data
/f4
10 200703250845.33
523 make_test_file
$MNT/01/data
/f5
10 200703250845.33
524 make_test_file
$MNT/01/data
/f6
10 200703250845.33
525 make_test_file
$MNT/01/data
/f7
10 200703250845.33
526 make_test_file
$MNT/01/data
/f8
10 200703250845.33
527 make_test_file
$MNT/01/data
/f9
10 200703250845.33
528 make_test_file
$MNT/01/data
/f10
10 200703250845.33
529 make_test_file
$MNT/01/data
/.f11
10 200703250845.33
530 make_test_file
$MNT/01/data
/d
3/d
4/f4
10 200703250845.33
531 mv $MNT/01/data
/d
1/f1
"$MNT/01/data/d1/Große Datei"
532 mv $MNT/01/data
/d1
"$MNT/01/data/Schönes Verzeichnis"
533 mv $MNT/01/data
/f4
"$MNT/01/data/[square brackets]"
534 mv $MNT/01/data
/f5
"$MNT/01/data/\`backquotes\`"
535 mv $MNT/01/data
/f6
"$MNT/01/data/'single quotes'"
536 mv $MNT/01/data
/f7
"$MNT/01/data/\"double quotes\""
537 mv $MNT/01/data
/f8
"$MNT/01/data/b\\a\\ckslashes"
538 mv $MNT/01/data
/f9
"`echo -e "$MNT/01/data
/newlines
\nin
\nname
"`";
540 #mv $MNT/01/data/d2 $MNT/01/data/.rsync_partial
541 #mv $MNT/01/data/d3/d4 $MNT/01/data/d3/.rsync_partial
542 run_test
0 test_monikop_simple
"Weird file names."
543 run_test
0 test_pokinom_clean_finish
"Weird file names."
544 run_test
1 test_monikop_short
"Weird file names, second run: nothing to do."
546 ########################################
548 ########################################
551 echo "TOTAL NUMBER OF TESTS: $TEST_COUNT"
552 echo "NUMBER OF FAILED TESTS: $FAIL_COUNT"
554 echo -e "$FAILED_TESTS"