Btrfs-progs: add make test framework
authorJosef Bacik <jbacik@fusionio.com>
Mon, 9 Sep 2013 20:41:58 +0000 (16:41 -0400)
committerChris Mason <chris.mason@fusionio.com>
Wed, 16 Oct 2013 12:23:11 +0000 (08:23 -0400)
We need to start adding some sanity tests to btrfs-progs to make sure we aren't
breaking things with our patches.  The most important of these tools is btrfsck.
This patch gets things started by adding a basic btrfsck test that makes sure we
can fix a corruption problem we know we can fix.  Thanks,

Signed-off-by: Josef Bacik <jbacik@fusionio.com>
Signed-off-by: David Sterba <dsterba@suse.cz>
Signed-off-by: Chris Mason <chris.mason@fusionio.com>
Makefile
tests/fsck-tests.sh [new file with mode: 0644]
tests/fsck-tests/001-bad-file-extent-bytenr.img [new file with mode: 0644]

index 997abad..4e33648 100644 (file)
--- a/Makefile
+++ b/Makefile
@@ -19,6 +19,7 @@ libbtrfs_objects = send-stream.o send-utils.o rbtree.o btrfs-list.o crc32c.o \
 libbtrfs_headers = send-stream.h send-utils.h send.h rbtree.h btrfs-list.h \
               crc32c.h list.h kerncompat.h radix-tree.h extent-cache.h \
               extent_io.h ioctl.h ctree.h btrfsck.h
+TESTS = fsck-tests.sh
 
 INSTALL = install
 prefix ?= /usr/local
@@ -123,6 +124,12 @@ $(BUILDDIRS):
        @echo "Making all in $(patsubst build-%,%,$@)"
        $(Q)$(MAKE) $(MAKEOPTS) -C $(patsubst build-%,%,$@)
 
+test:
+       $(Q)for t in $(TESTS); do \
+               echo "     [TEST]    $$t"; \
+               bash tests/$$t || exit 1; \
+       done
+
 #
 # NOTE: For static compiles, you need to have all the required libs
 #      static equivalent available
diff --git a/tests/fsck-tests.sh b/tests/fsck-tests.sh
new file mode 100644 (file)
index 0000000..c1490bf
--- /dev/null
@@ -0,0 +1,31 @@
+#!/bin/bash
+#
+# loop through all of our bad images and make sure fsck repairs them properly
+#
+# It's GPL, same as everything else in this tree.
+#
+
+here=`pwd`
+
+_fail()
+{
+       echo "$*" | tee -a fsck-tests-results.txt
+       exit 1
+}
+
+rm -f fsck-tests-results.txt
+
+for i in $(find $here/tests/fsck-tests -name '*.img')
+do
+       echo "testing image $i" >> fsck-tests-results.txt
+       $here/btrfs-image -r $i test.img >> fsck-tests-results.txt 2>&1 \
+               || _fail "restore failed"
+       $here/btrfsck test.img >> fsck-test-results.txt 2>&1
+       [ $? -eq 0 ] && _fail "btrfsck should have detected corruption"
+
+       $here/btrfsck --repair test.img >> fsck-test-results.txt 2>&1 || \
+               _fail "btrfsck should have repaired the image"
+
+       $here/btrfsck test.img >> fsck-test-results.txt 2>&1 || \
+               _fail "btrfsck did not correct corruption"
+done
diff --git a/tests/fsck-tests/001-bad-file-extent-bytenr.img b/tests/fsck-tests/001-bad-file-extent-bytenr.img
new file mode 100644 (file)
index 0000000..d2a05bb
Binary files /dev/null and b/tests/fsck-tests/001-bad-file-extent-bytenr.img differ