From ae5c125cd4854edd04e16f31aed519316e835617 Mon Sep 17 00:00:00 2001 From: Vitaliy Filippov Date: Wed, 15 Jan 2014 14:23:39 +0000 Subject: [PATCH] Fix tests: sh/dash compatibility, error messages, e2fsck on a fresh ext2 --- mkimage.sh | 5 +++-- run-tests.pl | 40 ++++++++++++++++++++-------------------- test-mkimages.sh | 3 +++ 3 files changed, 26 insertions(+), 22 deletions(-) diff --git a/mkimage.sh b/mkimage.sh index 52952b7..cc88eb8 100644 --- a/mkimage.sh +++ b/mkimage.sh @@ -14,12 +14,13 @@ mkdir -p dir mount -o loop $FILE dir # For block moving test: create a sparse file with many extents dd if=/dev/urandom of=dir/f_random bs=1k count=1 -for i in {1..2500}; do +for i in $(seq 1 2500); do dd if=dir/f_random of=dir/f_sparse bs=1k count=1 seek=$((2400-i*2)) conv=notrunc 2>/dev/null done # For inode moving test: create 1201 1kb sized files dd if=/dev/zero of=dir/f_zero bs=1k count=1 -for i in {1..1200}; do +for i in $(seq 1 1200); do cp dir/f_zero dir/f$i done +sleep 1 umount dir diff --git a/run-tests.pl b/run-tests.pl index 0639541..4781850 100644 --- a/run-tests.pl +++ b/run-tests.pl @@ -21,34 +21,34 @@ for (@$tests) { my ($name, $file, $inodes, $patch) = @$_; print "\n*** $name ***\n\n"; - system("cp $file.img test.img") && last; + system("cp $file.img test.img") && err("Failed to copy $file.img to test.img: $!"); if ($patch) { unlink("test.img.patch"); unlink("test.img.backup"); - last if -e "test.img.patch"; - last if -e "test.img.backup"; - system("./realloc-inodes --patch test.img.patch test.img $inodes") && last; - system("diff $file.img test.img") && last; - system("./e2patch backup test.img test.img.patch test.img.backup") && last; - system("./e2patch apply test.img test.img.patch") && last; - system("/sbin/e2fsck -f test.img") && last; - system("cp $file.img test.img") && last; - system("./e2patch apply test.img test.img.patch") && last; - system("diff $file.img test.img") || last; - system("./e2patch apply test.img test.img.backup") && last; - system("diff $file.img test.img") && last; + err("Failed to remove test.img.patch") if -e "test.img.patch"; + err("Failed to remove test.img.backup") if -e "test.img.backup"; + system("./realloc-inodes --patch test.img.patch test.img $inodes") && err("realloc-inodes failed with code $?"); + system("diff $file.img test.img") && err("patch I/O has modified $file.img (it differs from test.img)"); + system("./e2patch backup test.img test.img.patch test.img.backup") && err("e2patch backup failed with code $?"); + system("./e2patch apply test.img test.img.patch") && err("e2patch apply failed with code $?"); + system("/sbin/e2fsck -f test.img") && err("filesystem is modified by e2fsck after applying realloc patch"); + system("cp $file.img test.img") && err("failed to copy $file.img to test.img"); + system("./e2patch apply test.img test.img.patch") && err("e2patch apply failed with code $?"); + system("diff $file.img test.img") || err("$file.img does not differ from test.img after patching"); + system("./e2patch apply test.img test.img.backup") && err("e2patch restore backup failed with code $?"); + system("diff $file.img test.img") && err("$file.img differs from test.img after restoring backup"); } - system("./realloc-inodes test.img $inodes") && last; - system("/sbin/e2fsck -f test.img") && last; + system("./realloc-inodes test.img $inodes") && err("realloc-inodes failed with code $?"); + system("/sbin/e2fsck -f test.img") && err("filesystem is modified by e2fsck after realloc"); $ok++; } -if ($ok < @$tests) +sub err { print "\n!!! FAILED !!!\n"; + print "Error: ", @_, "\n"; + exit(1); } -else -{ - print "\n*** All tests OK ***\n"; -} + +print "\n*** All tests OK ***\n"; diff --git a/test-mkimages.sh b/test-mkimages.sh index 2a76de7..fdeedd0 100644 --- a/test-mkimages.sh +++ b/test-mkimages.sh @@ -3,6 +3,9 @@ # Basic ext2 test FS=ext2 FILE=test-ext2.img sh mkimage.sh +# ??? e2fsck rehashes dir indexes on a fresh ext2 O_o +e2fsck -f test-ext2.img + # Basic ext4 test FS=ext4 FILE=test-ext4.img sh mkimage.sh