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 for ORIGIN_FILE
in `find $ORIGIN_DIR -type f 2> /dev/null`; do
67 for COPY_DIR
in $COPY_DIRS; do
68 FOUND
=`find $COPY_DIR -path "$COPY_DIR/${ORIGIN_FILE#$ORIGIN_DIR/}" 2> /dev/null`
69 if [[ $FOUND != "" ]] ; then
73 if [[ $FOUND == "" ]] ; then
74 MISSING
="$MISSING $ORIGIN_FILE";
75 elif ! cmp --quiet $ORIGIN_FILE $FOUND; then
76 DIVERGING
="$DIVERGING $ORIGIN_FILE"
77 elif [[ `stat --printf="%Y" $ORIGIN_FILE` != `stat --printf="%Y" $FOUND` ]]; then
78 DIVERGING_MTIME
="$DIVERGING_MTIME $ORIGIN_FILE"
82 if [[ $MISSING != "" ]]; then
84 echo "MISSING: $MISSING"
86 if [[ $DIVERGING != "" ]]; then
87 RETURN_VALUE
=$
((return_value
+ 2))
88 echo "DIVERGING: $DIVERGING"
90 if [[ $DIVERGING_MTIME != "" ]]; then
91 RETURN_VALUE
=$
((return_value
+ 4))
92 echo "DIVERGING MTIME: $DIVERGING_MTIME"
97 # run_test <expected_return> <test-command> <comment>
100 killall monikop pokinom
2> /dev
/null
102 killall
-KILL monikop pokinom
2> /dev
/null
104 echo "RUNNING $2 [$3]"
105 TEST_COUNT
=$
(( TEST_COUNT
+ 1 ))
108 if [[ $RETURN_VALUE -ne $1 ]]; then
109 FAIL_COUNT
=$
(( FAIL_COUNT
+ 1 ))
110 FAILED_TESTS
="$FAILED_TESTS$2($1? $RETURN_VALUE!) [$3]\n"
111 echo "$2 should have returned $1 but returned $RETURN_VALUE instead."
116 umount
$MNT/* #2> /dev/null
117 rm -rf $DEV $MNT $LOG
118 mkdir
-p $DEV $MNT $RSYNC
120 # Create and mount test drives:
121 for i
in 01 02 03 04; do
122 make_test_drive
$i 102400
123 if [[ $?
== 1 ]]; then
127 make_test_drive
05 307200
128 if [[ $?
== 1 ]]; then
131 if [[ $MOUNTING_PROBLEM == 1 ]]; then exit; fi
133 function fill_sources_with_big_files
{
134 for i
in f1 f2 f3
; do
135 make_test_file
$MNT/01/data
/$i 25000 200703250845.33
137 for i
in f10 f11 f12
; do
138 make_test_file
$MNT/02/data
/$i 25000 200703250845.33
140 for i
in f4 f5 f6
; do
141 make_test_file
$MNT/01/data
/d
1/$i 2000 200703250845.33
142 make_test_file
$MNT/01/data
/d
1/d
2/$i 2000 200703250845.33
144 for i
in f7 f8 f9
; do
145 make_test_file
$MNT/02/data
/d
1/$i 2000 200703250845.33
146 make_test_file
$MNT/02/data
/d
1/d
2/$i 2000 200703250845.33
150 function fill_sources_with_hidden_files
{
152 make_test_file
$MNT/$i/data
/.hidden_dir_
$i/.hidden_file
20 200804250955.10
156 function fill_destinations_with_few_small_files
{
158 for j
in file_one file_two file_three
; do
159 make_test_file
$MNT/$i/measuring_data
/$i/$j 20 200004250955.10
164 # Prepare data sources:
165 fill_sources_with_big_files
167 # Check how fast we are:
169 T1
=`/usr/bin/time --format="%e" rsync --recursive --times $MNT/01/data/ $MNT/03/ 2>&1 &`
170 T2
=`/usr/bin/time --format="%e" rsync --recursive --times $MNT/02/data/ $MNT/04/ 2>&1 &`
171 INTERRUPTION_TIME_0
=`echo "($T1 + $T2) * 3" | bc`
172 INTERRUPTION_TIME_1
=`echo "($T1 + $T2) * .08" | bc`
173 INTERRUPTION_TIME_2
=`echo "($T1 + $T2) * .82" | bc`
174 echo $INTERRUPTION_TIME_0
175 rm -rf $MNT/0{1,2,3,4}/*
179 function test_monikop_simple
{
181 $MONIKOP_1 & sleep $INTERRUPTION_TIME_0; /bin
/kill -TERM $
!
183 find_and_compare
$MNT/0{1,2}/data
:: $MNT/0{3,4}/measuring_data
186 function test_monikop_simple_late_sources
{
188 $MONIKOP_1 & sleep $INTERRUPTION_TIME_2; start_rsyncd
; sleep $INTERRUPTION_TIME_0; /bin
/kill -TERM $
!
190 find_and_compare
$MNT/0{1,2}/data
:: $MNT/0{3,4}/measuring_data
193 function test_monikop_short
{
194 $MONIKOP_1 & sleep $INTERRUPTION_TIME_1; /bin
/kill -TERM $
!
196 find_and_compare
$MNT/0{1,2}/data
:: $MNT/0{3,4}/measuring_data
199 function test_monikop_short_2
{
200 $MONIKOP_2 & sleep $INTERRUPTION_TIME_1; /bin
/kill -TERM $
!
202 find_and_compare
$MNT/0{1,2}/data
:: $MNT/0{3,4,5}/measuring_data
205 function test_monikop_short_kill_rsync_first
{
206 $MONIKOP_2 & sleep $INTERRUPTION_TIME_1; /usr
/bin
/killall
-KILL rsync
; sleep 1; /bin
/kill -TERM $
!
208 find_and_compare
$MNT/0{1,2}/data
:: $MNT/0{3,4,5}/measuring_data
215 function test_monikop_short_cut_sources
{
216 $MONIKOP_2 & sleep $INTERRUPTION_TIME_1; kill_rsyncd
; sleep 1; /bin
/kill -TERM $
!
218 find_and_compare
$MNT/0{1,2}/data
:: $MNT/0{3,4,5}/measuring_data
225 function test_monikop_simple_2
{
226 $MONIKOP_2 & sleep $INTERRUPTION_TIME_0; /bin
/kill -TERM $
!
228 find_and_compare
$MNT/0{1,2}/data
:: $MNT/0{3,4,5}/measuring_data
231 function test_monikop_simple_3
{
232 $MONIKOP_3 & sleep $INTERRUPTION_TIME_0; /bin
/kill -TERM $
!
234 find_and_compare
$MNT/0{1,2}/data
:: $MNT/0{3,4}/measuring_data
/dir_0
{1,2}
237 function test_monikop_overflow
{
238 # Stuff one of the destinations a bit:
239 make_test_file
$MNT/03/stuffing
25000 199903250845
240 $MONIKOP_1 & sleep $INTERRUPTION_TIME_0; /bin
/kill -TERM $
!
242 find_and_compare
$MNT/0{1,2}/data
:: $MNT/0{3,4}/measuring_data
245 function test_monikop_no_destination
{
246 # We test basically if there is something to kill.
248 $MONIKOP_1 & sleep $INTERRUPTION_TIME_2; /bin
/kill -TERM $
!
255 function test_monikop_no_source
{
256 # We test basically if there is something to kill.
258 $MONIKOP_1 & sleep $INTERRUPTION_TIME_2; /bin
/kill -TERM $
!
264 function test_pokinom_clean_finish
{
265 $POKINOM & sleep $INTERRUPTION_TIME_0; /bin
/kill -TERM $
!
267 find_and_compare
$MNT/0{1,2}/data
:: $MNT/05/NEW_DATA
270 function test_pokinom_short
{
271 $POKINOM & sleep $INTERRUPTION_TIME_1; /bin
/kill -TERM $
!
273 find_and_compare
$MNT/0{1,2}/data
:: $MNT/05/NEW_DATA
276 function test_pokinom_late_destination
{
278 $POKINOM & sleep $INTERRUPTION_TIME_2; start_rsyncd
; sleep $INTERRUPTION_TIME_0; /bin
/kill -TERM $
!
280 find_and_compare
$MNT/0{1,2}/data
:: $MNT/05/NEW_DATA
283 function test_dirs_backed_up
{
284 test -d $MNT/03/backed_up
&& test -d $MNT/04/backed_up
287 function test_monikop_deletes_being_deleted_dir
{
288 mkdir
-p $MNT/0{3,4}/{being_deleted
,backed_up
}
289 touch $MNT/0{3,4}/{being_deleted
,backed_up
}/some_file
290 touch $MNT/0{3,4}/{being_deleted
,backed_up
}/.some_hidden_file
291 $MONIKOP_1 & sleep $INTERRUPTION_TIME_2; /bin
/kill -TERM $
!
292 test -d $MNT/03/being_deleted ||
test -d $MNT/04/being_deleted
295 function test_pokinom_deletes_being_deleted_dir
{
296 mkdir
-p $MNT/0{3,4}/being_deleted
297 touch $MNT/0{3,4}/being_deleted
/some_file
298 touch $MNT/0{3,4}/being_deleted
/.some_hidden_file
299 $POKINOM & sleep $INTERRUPTION_TIME_2; /bin
/kill -TERM $
!
300 test -d $MNT/03/being_deleted ||
test -d $MNT/04/being_deleted
303 function test_pokinom_newer_files_win
{
304 fill_destinations_with_few_small_files
305 $POKINOM & sleep $INTERRUPTION_TIME_2; /bin
/kill -TERM $
!
307 mv $MNT/$i/backed_up
$MNT/$i/measuring_data
308 touch $MNT/$i/measuring_data
/$i/*
310 $POKINOM & sleep $INTERRUPTION_TIME_2; /bin
/kill -TERM $
!
312 find_and_compare
$MNT/0{3,4}/backed_up
:: $MNT/05/NEW_DATA
315 function test_pokinom_older_files_lose
{
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
321 touch -t 198001011200.00 $MNT/03/measuring_data
/03/file_one
322 $POKINOM & sleep $INTERRUPTION_TIME_2; /bin
/kill -TERM $
!
324 find_and_compare
$MNT/0{3,4}/backed_up
:: $MNT/05/NEW_DATA
329 ##########################
330 ### Run tests: Monikop
331 ##########################
333 fill_sources_with_big_files
335 run_test
1 test_monikop_deletes_being_deleted_dir
"Monikop deletes left-over directory named being_deleted."
337 rm -rf $MNT/0{3,4}/* $LOG
339 chmod a-w
,a-x
$MNT/0{3,4}
340 run_test
1 test_monikop_simple
"Unwritable destination"
341 chmod a
+w
,a
+x
$MNT/0{3,4}
342 run_test
0 test_monikop_simple
"Unwritable destination"
344 rm -rf $MNT/0{3,4}/* $LOG
346 run_test
0 test_monikop_simple_3
"Source-specific directories on disks"
348 rm -rf $MNT/0{3,4}/* $LOG
350 run_test
0 test_monikop_simple_late_sources
"Simple run, sources coming up late."
352 mv $MNT/03/measuring_data
$MNT/03/backed_up
353 mv $MNT/04/measuring_data
$MNT/04/backed_up
356 run_test
0 test_monikop_simple
"Simple run, deletion."
358 rm -rf $MNT/0{3,4}/* $LOG
360 run_test
1 test_monikop_short
"Interruption, finished.* or finished.*.bak deleted."
361 rm -f $LOG/finished.rsync___localhost_2000_test_01_data
$LOG/finished.rsync___localhost_2000_test_02_data.bak
362 run_test
0 test_monikop_simple
"Recovery after interruption, finished.* or finished.*.bak deleted."
364 rm -rf $MNT/0{3,4}/* $LOG
366 run_test
1 test_monikop_short
"Interruption, finished.* and/or log.* deleted."
367 rm -f $LOG/finished.rsync___localhost_2000_test_01_data
$LOG/log.rsync___localhost_2000_test_01_data
368 rm -f $LOG/rm log.rsync___localhost_2000_test_02_data
369 run_test
0 test_monikop_simple
"Recovery after interruption, finished.* and/or log.* deleted."
371 rm -rf $MNT/0{3,4}/* $LOG
373 run_test
1 test_monikop_short_2
"Repeated interruption."
374 run_test
1 test_monikop_short_2
"Repeated interruption (may pass unexpectedly due to test timing)."
375 run_test
0 test_monikop_simple_2
"Repeated interruption."
377 mv $MNT/03/measuring_data
$MNT/03/backed_up
378 mv $MNT/04/measuring_data
$MNT/04/backed_up
379 mv $MNT/05/measuring_data
$MNT/05/backed_up
382 run_test
1 test_monikop_short_2
"Repeated interruption, deletion."
383 run_test
1 test_monikop_short_2
"Repeated interruption, deletion (may pass unexpectedly due to test timing)."
384 run_test
0 test_monikop_simple_2
"Repeated interruption, deletion."
386 rm -rf $MNT/0{3,4,5}/* $LOG
388 run_test
0 test_monikop_no_destination
"No destination available."
389 run_test
0 test_monikop_no_source
"No destination available."
391 rm -rf $MNT/0{3,4}/* $LOG
393 run_test
1 test_monikop_short_kill_rsync_first
"Rsync killed."
395 run_test
0 test_monikop_simple_2
"Rsync killed."
397 rm -rf $MNT/0{3,4,5}/* $LOG
399 run_test
1 test_monikop_short_cut_sources
"Connection to source destroyed."
400 run_test
0 test_monikop_simple_2
"Connection to source destroyed."
402 rm -rf $MNT/0{3,4,5}/* $LOG
404 ##############################
406 ##############################
408 run_test
1 test_pokinom_deletes_being_deleted_dir
"Pokinom deletes left-over directory named being_deleted."
410 rm -rf $MNT/0{3,4,5}/*
412 run_test
0 test_pokinom_newer_files_win
"Pokinom overwrites older files in Destination."
414 run_test
4 test_pokinom_older_files_lose
"Pokinom discards older files on removable disk."
416 ##############################
417 # Monikop and Pokinom together
418 ##############################
420 rm -rf $MNT/0{1,2,3,4,5}/*
421 fill_sources_with_hidden_files
423 run_test
0 test_monikop_simple
"Preparation for simple Pokinom test, hidden files."
424 run_test
0 test_pokinom_clean_finish
"Simple Pokinom test, hidden files."
425 run_test
0 test_dirs_backed_up
"Simple Pokinom test, hidden files."
426 run_test
1 test_monikop_short
"After test with hidden files, this one should do nothing but delete backed_up."
427 run_test
1 test_dirs_backed_up
"Deletion of backed_up with hidden files."
429 rm -rf $MNT/0{1,2,3,4,5}/*
430 fill_sources_with_big_files
432 run_test
0 test_monikop_simple
"Simple run in preparation for simple Pokinom test."
433 run_test
0 test_pokinom_clean_finish
"Simple Pokinom test."
434 run_test
0 test_dirs_backed_up
"Simple Pokinom test: directories renamed?."
436 rm -rf $MNT/05/* $LOG
438 run_test
0 test_monikop_simple
"Preparation for Pokinom's destination overfull."
440 make_test_file
$MNT/05/stuffing
200000 199903250845
441 run_test
1 test_pokinom_clean_finish
"Pokinom's destination overfull."
443 run_test
0 test_pokinom_clean_finish
"Pokinom's destination no longer overfull: recovering."
445 rm -rf $MNT/05/* $LOG
447 run_test
0 test_monikop_simple
"Simple run in preparation for Pokinom, late destination."
448 run_test
0 test_pokinom_late_destination
"Pokinom, late destination."
450 rm -rf $MNT/05/* $LOG
452 run_test
0 test_monikop_simple
"Simple run in preparation for Pokinom stopped early."
453 run_test
1 test_pokinom_short
"Pokinom stopped early."
454 run_test
0 test_monikop_simple
"Simple run after Pokinom having been stopped early."
455 run_test
0 test_pokinom_clean_finish
"Simple run after Pokinom having been stopped early."
457 rm -rf $MNT/05/* $LOG
459 run_test
0 test_monikop_simple
"Simple run in preparation for \"file grown too large\""
461 cat $MNT/01/data
/f1
>> $MNT/01/data
/f2
462 run_test
2 test_monikop_simple
"Repeated run, file grown too large."
463 run_test
2 test_pokinom_clean_finish
"Repeated run, file grown too large."
464 run_test
1 test_monikop_simple
"Repeated run, file grown too large."
465 run_test
0 test_pokinom_clean_finish
"Repeated run, file grown too large."
467 rm -rf $MNT/05/* $LOG
469 run_test
1 test_monikop_overflow
"Initially, too little room on disks."
470 run_test
1 test_pokinom_clean_finish
"Initially, too little room on disks."
471 run_test
1 test_monikop_overflow
"Previously, too little room on disks."
472 run_test
0 test_pokinom_clean_finish
"Previously, too little room on disks."
474 rm -rf $MNT/0{3,4,5}/* $LOG
476 run_test
1 test_monikop_short
"Unfinished by Monikop, then another full cycle."
477 run_test
1 test_pokinom_clean_finish
"Unfinished by Monikop, then another full cycle (Outcome unpredictable)."
478 run_test
1 test_monikop_simple
"Previously unfinished by Monikop, now another full cycle (Outcome unpredictable)."
479 run_test
0 test_pokinom_clean_finish
"Previously unfinished by Monikop, now another full cycle."
481 # TODO: the following fails at least in part due to bugs in the tests themselves.
482 rm -rf $MNT/0{1,2,3,4,5}/* $LOG
483 make_test_file
$MNT/01/data
/d
1/f1
10 200703250845.33
484 make_test_file
$MNT/01/data
/d
2/f3
10 200703250845.33
485 make_test_file
$MNT/01/data
/d
3/d
4/f4
10 200703250845.33
486 make_test_file
$MNT/01/data
/f2
10 200703250845.33
487 make_test_file
$MNT/01/data
/f5
10 200703250845.33
488 mv $MNT/01/data
/d
1/f1
"$MNT/01/data/d1/Große Datei"
489 mv $MNT/01/data
/d1
"$MNT/01/data/Schönes Verzeichnis"
490 mv $MNT/01/data
/f2
"$MNT/01/data/{[cool]} file\ n\\a\\m\\e."
491 # Not sure if this will ever work:
492 mv $MNT/01/data
/d2
$MNT/01/data
/.rsync_partial
493 mv $MNT/01/data
/d
3/d4
$MNT/01/data
/d
3/.rsync_partial
494 run_test
0 test_monikop_simple
"Weird file names."
495 run_test
0 test_pokinom_clean_finish
"Weird file names."
496 run_test
1 test_monikop_short
"Weird file names, second run: nothing to do."
498 ########################################
500 ########################################
503 echo "TOTAL NUMBER OF TESTS: $TEST_COUNT"
504 echo "NUMBER OF FAILED TESTS: $FAIL_COUNT"
506 echo -e "$FAILED_TESTS"