3 # Caveats: - kills all killable rsyncs
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]"
110 TEST_COUNT
=$
(( TEST_COUNT
+ 1 ))
113 if [[ $RETURN_VALUE -ne $1 ]]; then
114 FAIL_COUNT
=$
(( FAIL_COUNT
+ 1 ))
115 FAILED_TESTS
="$FAILED_TESTS$2($1? $RETURN_VALUE!) [$3]\n"
116 echo "$2 should have returned $1 but returned $RETURN_VALUE instead."
121 # Create and mount test drives:
122 umount
$MNT/* #2> /dev/null
123 rm -rf $DEV $MNT $LOG
124 mkdir
-p $DEV $MNT $RSYNC
126 for i
in 01 02 03 04; do
127 make_test_drive
$i 102400
128 if [[ $?
== 1 ]]; then
132 make_test_drive
05 307200
133 if [[ $?
== 1 ]]; then
136 if [[ $MOUNTING_PROBLEM == 1 ]]; then exit; fi
138 function fill_sources_with_big_files
{
139 for i
in f1 f2 f3
; do
140 make_test_file
$MNT/01/data
/$i 25000 200703250845.33
142 for i
in f10 f11 f12
; do
143 make_test_file
$MNT/02/data
/$i 25000 200703250845.33
145 for i
in f4 f5 f6
; do
146 make_test_file
$MNT/01/data
/d
1/$i 2000 200703250845.33
147 make_test_file
$MNT/01/data
/d
1/d
2/$i 2000 200703250845.33
149 for i
in f7 f8 f9
; do
150 make_test_file
$MNT/02/data
/d
1/$i 2000 200703250845.33
151 make_test_file
$MNT/02/data
/d
1/d
2/$i 2000 200703250845.33
155 function fill_sources_with_hidden_files
{
157 make_test_file
$MNT/$i/data
/.hidden_dir_
$i/.hidden_file
20 200804250955.10
161 function fill_sources_with_few_small_files
{
163 for j
in file_one file_two file_three
; do
164 make_test_file
$MNT/$i/data
/$j.
$i 20 200004250955.10
169 function fill_destinations_with_few_small_files
{
171 for j
in file_one file_two file_three
; do
172 make_test_file
$MNT/$i/measuring_data
/$i/$j 20 200004250955.10
177 # Check how fast we are:
178 fill_sources_with_big_files
179 T1
=`/usr/bin/time --format="%e" rsync --recursive --times $MNT/01/data/ $MNT/03/ 2>&1 &`
180 T2
=`/usr/bin/time --format="%e" rsync --recursive --times $MNT/02/data/ $MNT/04/ 2>&1 &`
181 INTERRUPTION_TIME_0
=`echo "($T1 + $T2) * 3" | bc`
182 INTERRUPTION_TIME_1
=`echo "($T1 + $T2) * .08" | bc`
183 INTERRUPTION_TIME_2
=`echo "($T1 + $T2) * .82" | bc`
184 echo "One run of a testee takes about $INTERRUPTION_TIME_0 seconds."
185 rm -rf $MNT/0{1,2,3,4}/*
187 ######################################################################
189 ######################################################################
191 function test_monikop_simple
{
193 $MONIKOP_1 & sleep $INTERRUPTION_TIME_0; /bin
/kill -TERM $
!
195 find_and_compare
$MNT/0{1,2}/data
:: $MNT/0{3,4}/measuring_data
198 function test_monikop_simple_late_sources
{
200 $MONIKOP_1 & sleep $INTERRUPTION_TIME_2; start_rsyncd
; sleep $INTERRUPTION_TIME_0; /bin
/kill -TERM $
!
202 find_and_compare
$MNT/0{1,2}/data
:: $MNT/0{3,4}/measuring_data
205 function test_monikop_short
{
206 $MONIKOP_1 & sleep $INTERRUPTION_TIME_1; /bin
/kill -TERM $
!
208 find_and_compare
$MNT/0{1,2}/data
:: $MNT/0{3,4}/measuring_data
211 function test_monikop_short_2
{
212 $MONIKOP_2 & sleep $INTERRUPTION_TIME_1; /bin
/kill -TERM $
!
214 find_and_compare
$MNT/0{1,2}/data
:: $MNT/0{3,4,5}/measuring_data
217 function test_monikop_short_kill_rsync_first
{
218 $MONIKOP_2 & sleep $INTERRUPTION_TIME_1; /usr
/bin
/killall
-KILL rsync
; sleep 1; /bin
/kill -TERM $
!
220 find_and_compare
$MNT/0{1,2}/data
:: $MNT/0{3,4,5}/measuring_data
227 function test_monikop_short_cut_sources
{
228 $MONIKOP_2 & sleep $INTERRUPTION_TIME_1; kill_rsyncd
; sleep 1; /bin
/kill -TERM $
!
230 find_and_compare
$MNT/0{1,2}/data
:: $MNT/0{3,4,5}/measuring_data
237 function test_monikop_simple_2
{
238 $MONIKOP_2 & sleep $INTERRUPTION_TIME_0; /bin
/kill -TERM $
!
240 find_and_compare
$MNT/0{1,2}/data
:: $MNT/0{3,4,5}/measuring_data
243 function test_monikop_simple_3
{
244 $MONIKOP_3 & sleep $INTERRUPTION_TIME_0; /bin
/kill -TERM $
!
246 find_and_compare
$MNT/0{1,2}/data
:: $MNT/0{3,4}/measuring_data
/dir_0
{1,2}
249 function test_monikop_overflow
{
250 # Stuff one of the destinations a bit:
251 make_test_file
$MNT/03/stuffing
25000 199903250845
252 $MONIKOP_1 & sleep $INTERRUPTION_TIME_0; /bin
/kill -TERM $
!
254 find_and_compare
$MNT/0{1,2}/data
:: $MNT/0{3,4}/measuring_data
257 function test_monikop_no_destination
{
258 # We test basically if there is something to kill.
260 $MONIKOP_1 & sleep $INTERRUPTION_TIME_2; /bin
/kill -TERM $
!
267 function test_monikop_no_source
{
268 # We test basically if there is something to kill.
270 $MONIKOP_1 & sleep $INTERRUPTION_TIME_2; /bin
/kill -TERM $
!
276 function test_pokinom_clean_finish
{
277 $POKINOM & sleep $INTERRUPTION_TIME_0; /bin
/kill -TERM $
!
279 find_and_compare
$MNT/0{1,2}/data
:: $MNT/05/NEW_DATA
282 function test_pokinom_short
{
283 $POKINOM & sleep $INTERRUPTION_TIME_1; /bin
/kill -TERM $
!
285 find_and_compare
$MNT/0{1,2}/data
:: $MNT/05/NEW_DATA
288 function test_pokinom_late_destination
{
290 $POKINOM & sleep $INTERRUPTION_TIME_2; start_rsyncd
; sleep $INTERRUPTION_TIME_0; /bin
/kill -TERM $
!
292 find_and_compare
$MNT/0{1,2}/data
:: $MNT/05/NEW_DATA
295 function test_dirs_backed_up
{
296 test -d $MNT/03/backed_up
&& test -d $MNT/04/backed_up
299 function test_monikop_deletes_being_deleted_dir
{
300 mkdir
-p $MNT/0{3,4}/{being_deleted
,backed_up
}
301 touch $MNT/0{3,4}/{being_deleted
,backed_up
}/some_file
302 touch $MNT/0{3,4}/{being_deleted
,backed_up
}/.some_hidden_file
303 $MONIKOP_1 & sleep $INTERRUPTION_TIME_2; /bin
/kill -TERM $
!
304 test -d $MNT/03/being_deleted ||
test -d $MNT/04/being_deleted
307 function test_pokinom_deletes_being_deleted_dir
{
308 mkdir
-p $MNT/0{3,4}/being_deleted
309 touch $MNT/0{3,4}/being_deleted
/some_file
310 touch $MNT/0{3,4}/being_deleted
/.some_hidden_file
311 $POKINOM & sleep $INTERRUPTION_TIME_2; /bin
/kill -TERM $
!
312 test -d $MNT/03/being_deleted ||
test -d $MNT/04/being_deleted
315 function test_pokinom_newer_files_win
{
316 fill_destinations_with_few_small_files
317 $POKINOM & sleep $INTERRUPTION_TIME_2; /bin
/kill -TERM $
!
319 mv $MNT/$i/backed_up
$MNT/$i/measuring_data
320 touch $MNT/$i/measuring_data
/$i/*
322 $POKINOM & sleep $INTERRUPTION_TIME_2; /bin
/kill -TERM $
!
324 find_and_compare
$MNT/0{3,4}/backed_up
:: $MNT/05/NEW_DATA
327 function test_pokinom_older_files_lose
{
328 fill_destinations_with_few_small_files
329 $POKINOM & sleep $INTERRUPTION_TIME_2; /bin
/kill -TERM $
!
331 mv $MNT/$i/backed_up
$MNT/$i/measuring_data
333 touch -t 198001011200.00 $MNT/03/measuring_data
/03/file_one
334 $POKINOM & sleep $INTERRUPTION_TIME_2; /bin
/kill -TERM $
!
336 find_and_compare
$MNT/0{3,4}/backed_up
:: $MNT/05/NEW_DATA
339 ######################################################################
341 ######################################################################
344 #########################
345 ## Run tests: Monikop
346 #########################
348 fill_sources_with_big_files
350 run_test
1 test_monikop_deletes_being_deleted_dir
"Monikop deletes left-over directory named being_deleted."
352 rm -rf $MNT/0{3,4}/* $LOG
354 chmod a-w
,a-x
$MNT/0{3,4}
355 run_test
1 test_monikop_simple
"Unwritable destination"
356 chmod a
+w
,a
+x
$MNT/0{3,4}
357 run_test
0 test_monikop_simple
"Unwritable destination"
359 rm -rf $MNT/0{3,4}/* $LOG
361 run_test
0 test_monikop_simple_3
"Source-specific directories on disks"
363 rm -rf $MNT/0{3,4}/* $LOG
365 run_test
0 test_monikop_simple_late_sources
"Simple run, sources coming up late."
367 mv $MNT/03/measuring_data
$MNT/03/backed_up
368 mv $MNT/04/measuring_data
$MNT/04/backed_up
371 run_test
0 test_monikop_simple
"Simple run, deletion."
373 rm -rf $MNT/0{3,4}/* $LOG
375 run_test
1 test_monikop_short
"Interruption, finished.* or finished.*.bak deleted."
376 rm -f $LOG/finished.rsync___localhost_2000_test_01_data
$LOG/finished.rsync___localhost_2000_test_02_data.bak
377 run_test
0 test_monikop_simple
"Recovery after interruption, finished.* or finished.*.bak deleted."
379 rm -rf $MNT/0{3,4}/* $LOG
381 run_test
1 test_monikop_short
"Interruption, finished.* and/or log.* deleted."
382 rm -f $LOG/finished.rsync___localhost_2000_test_01_data
$LOG/log.rsync___localhost_2000_test_01_data
383 rm -f $LOG/rm log.rsync___localhost_2000_test_02_data
384 run_test
0 test_monikop_simple
"Recovery after interruption, finished.* and/or log.* deleted."
386 rm -rf $MNT/0{3,4}/* $LOG
388 run_test
1 test_monikop_short_2
"Repeated interruption."
389 run_test
1 test_monikop_short_2
"Repeated interruption (may pass unexpectedly due to test timing)."
390 run_test
0 test_monikop_simple_2
"Repeated interruption."
392 mv $MNT/03/measuring_data
$MNT/03/backed_up
393 mv $MNT/04/measuring_data
$MNT/04/backed_up
394 mv $MNT/05/measuring_data
$MNT/05/backed_up
397 run_test
1 test_monikop_short_2
"Repeated interruption, deletion."
398 run_test
1 test_monikop_short_2
"Repeated interruption, deletion (may pass unexpectedly due to test timing)."
399 run_test
0 test_monikop_simple_2
"Repeated interruption, deletion."
401 rm -rf $MNT/0{3,4,5}/* $LOG
403 run_test
0 test_monikop_no_destination
"No destination available."
404 run_test
0 test_monikop_no_source
"No destination available."
406 rm -rf $MNT/0{3,4}/* $LOG
408 run_test
1 test_monikop_short_kill_rsync_first
"Rsync killed."
410 run_test
0 test_monikop_simple_2
"Rsync killed."
412 rm -rf $MNT/0{3,4,5}/* $LOG
414 run_test
1 test_monikop_short_cut_sources
"Connection to source destroyed."
415 run_test
0 test_monikop_simple_2
"Connection to source destroyed."
417 rm -rf $MNT/0{3,4,5}/* $LOG
419 fill_sources_with_few_small_files
421 run_test
0 test_monikop_short
"Don't re-rsync after deletion of finished.* (Preparation #1)."
422 rm -rf $MNT/{03,04}/*
423 run_test
1 test_monikop_short
"Don't re-rsync after deletion of finished.* (Preparation #2, fill finished.*)."
424 rm -f $LOG/log.rsync___localhost_2000_test_
*
425 rm -f $LOG/finished.rsync___localhost_2000_test_
*_data
426 run_test
1 test_monikop_short
"Don't re-rsync after deletion of finished.*"
427 rm -rf $MNT/0{3,4}/* $LOG
428 run_test
0 test_monikop_short
"Don't re-rsync after deletion of finished.*.bak (Preparation #1)."
429 rm -rf $MNT/{03,04}/*
430 run_test
1 test_monikop_short
"Don't re-rsync after deletion of finished.*.bak (Preparation #2, fill finished.*)."
431 rm -f $LOG/log.rsync___localhost_2000_test_
*
432 rm -f $LOG/finished.rsync___localhost_2000_test_
*_data.bak
433 run_test
1 test_monikop_short
"Don't re-rsync after deletion of finished.*.bak."
435 rm -rf $MNT/0{3,4}/* $LOG
437 ##############################
439 ##############################
441 run_test
1 test_pokinom_deletes_being_deleted_dir
"Pokinom deletes left-over directory named being_deleted."
443 rm -rf $MNT/0{3,4,5}/*
445 run_test
0 test_pokinom_newer_files_win
"Pokinom overwrites older files in Destination."
447 run_test
4 test_pokinom_older_files_lose
"Pokinom discards older files on removable disk."
449 ##################################################
450 # Run tests: Monikop and Pokinom together
451 ##################################################
453 rm -rf $MNT/0{1,2,3,4,5}/*
454 fill_sources_with_hidden_files
456 run_test
0 test_monikop_simple
"Preparation for simple Pokinom test, hidden files."
457 run_test
0 test_pokinom_clean_finish
"Simple Pokinom test, hidden files."
458 run_test
0 test_dirs_backed_up
"Simple Pokinom test, hidden files."
459 run_test
1 test_monikop_short
"After test with hidden files, this one should do nothing but delete backed_up."
460 run_test
1 test_dirs_backed_up
"Deletion of backed_up with hidden files."
462 rm -rf $MNT/0{1,2,3,4,5}/*
463 fill_sources_with_big_files
465 run_test
0 test_monikop_simple
"Simple run in preparation for simple Pokinom test."
466 run_test
0 test_pokinom_clean_finish
"Simple Pokinom test."
467 run_test
0 test_dirs_backed_up
"Simple Pokinom test: directories renamed?."
469 rm -rf $MNT/05/* $LOG
471 run_test
0 test_monikop_simple
"Preparation for Pokinom's destination overfull."
473 make_test_file
$MNT/05/stuffing
200000 199903250845
474 run_test
1 test_pokinom_clean_finish
"Pokinom's destination overfull."
476 run_test
0 test_pokinom_clean_finish
"Pokinom's destination no longer overfull: recovering."
478 rm -rf $MNT/05/* $LOG
480 run_test
0 test_monikop_simple
"Simple run in preparation for Pokinom, late destination."
481 run_test
0 test_pokinom_late_destination
"Pokinom, late destination."
483 rm -rf $MNT/05/* $LOG
485 run_test
0 test_monikop_simple
"Simple run in preparation for Pokinom stopped early."
486 run_test
1 test_pokinom_short
"Pokinom stopped early."
487 run_test
0 test_monikop_simple
"Simple run after Pokinom having been stopped early."
488 run_test
0 test_pokinom_clean_finish
"Simple run after Pokinom having been stopped early."
490 rm -rf $MNT/05/* $LOG
492 run_test
0 test_monikop_simple
"Simple run in preparation for \"file grown too large\""
494 cat $MNT/01/data
/f1
>> $MNT/01/data
/f2
495 run_test
2 test_monikop_simple
"Repeated run, file grown too large."
496 run_test
2 test_pokinom_clean_finish
"Repeated run, file grown too large."
497 run_test
1 test_monikop_simple
"Repeated run, file grown too large."
498 run_test
0 test_pokinom_clean_finish
"Repeated run, file grown too large."
500 rm -rf $MNT/05/* $LOG
502 run_test
1 test_monikop_overflow
"Initially, too little room on disks."
503 run_test
1 test_pokinom_clean_finish
"Initially, too little room on disks."
504 run_test
1 test_monikop_overflow
"Previously, too little room on disks."
505 run_test
0 test_pokinom_clean_finish
"Previously, too little room on disks."
507 rm -rf $MNT/0{3,4,5}/* $LOG
509 run_test
1 test_monikop_short
"Unfinished by Monikop, then another full cycle."
510 run_test
1 test_pokinom_clean_finish
"Unfinished by Monikop, then another full cycle (Outcome unpredictable)."
511 run_test
1 test_monikop_simple
"Previously unfinished by Monikop, now another full cycle (Outcome unpredictable)."
512 run_test
0 test_pokinom_clean_finish
"Previously unfinished by Monikop, now another full cycle."
514 rm -rf $MNT/0{1,2,3,4,5}/* $LOG
516 make_test_file
$MNT/01/data
/d
1/f1
10 200703250845.33
517 make_test_file
$MNT/01/data
/d
2/f3
10 200703250845.33
518 make_test_file
$MNT/01/data
/f4
10 200703250845.33
519 make_test_file
$MNT/01/data
/f5
10 200703250845.33
520 make_test_file
$MNT/01/data
/f6
10 200703250845.33
521 make_test_file
$MNT/01/data
/f7
10 200703250845.33
522 make_test_file
$MNT/01/data
/f8
10 200703250845.33
523 make_test_file
$MNT/01/data
/f9
10 200703250845.33
524 make_test_file
$MNT/01/data
/f10
10 200703250845.33
525 make_test_file
$MNT/01/data
/.f11
10 200703250845.33
526 make_test_file
$MNT/01/data
/d
3/d
4/f4
10 200703250845.33
527 mv $MNT/01/data
/d
1/f1
"$MNT/01/data/d1/Große Datei"
528 mv $MNT/01/data
/d1
"$MNT/01/data/Schönes Verzeichnis"
529 mv $MNT/01/data
/f4
"$MNT/01/data/[square brackets]"
530 mv $MNT/01/data
/f5
"$MNT/01/data/\`backquotes\`"
531 mv $MNT/01/data
/f6
"$MNT/01/data/'single quotes'"
532 mv $MNT/01/data
/f7
"$MNT/01/data/\"double quotes\""
533 mv $MNT/01/data
/f8
"$MNT/01/data/b\\a\\ckslashes"
534 mv $MNT/01/data
/f9
"`echo -e "$MNT/01/data
/newlines
\nin
\nname
"`";
536 #mv $MNT/01/data/d2 $MNT/01/data/.rsync_partial
537 #mv $MNT/01/data/d3/d4 $MNT/01/data/d3/.rsync_partial
538 run_test
0 test_monikop_simple
"Weird file names."
539 run_test
0 test_pokinom_clean_finish
"Weird file names."
540 run_test
1 test_monikop_short
"Weird file names, second run: nothing to do."
542 ########################################
544 ########################################
547 echo "TOTAL NUMBER OF TESTS: $TEST_COUNT"
548 echo "NUMBER OF FAILED TESTS: $FAIL_COUNT"
550 echo -e "$FAILED_TESTS"