From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: from dkim2.fusionio.com ([66.114.96.54]:36641 "EHLO dkim2.fusionio.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1755652Ab3IIUmM (ORCPT ); Mon, 9 Sep 2013 16:42:12 -0400 Received: from mx2.fusionio.com (unknown [10.101.1.160]) by dkim2.fusionio.com (Postfix) with ESMTP id 621A69A04FA for ; Mon, 9 Sep 2013 14:42:12 -0600 (MDT) Received: from CAS1.int.fusionio.com (cas1.int.fusionio.com [10.101.1.40]) by mx2.fusionio.com with ESMTP id oDZwB9qp5O75VpFu (version=TLSv1 cipher=AES128-SHA bits=128 verify=NO) for ; Mon, 09 Sep 2013 14:42:11 -0600 (MDT) From: Josef Bacik To: Subject: [PATCH 5/5] Btrfs-progs: add make test framework Date: Mon, 9 Sep 2013 16:41:58 -0400 Message-ID: <1378759318-3305-5-git-send-email-jbacik@fusionio.com> In-Reply-To: <1378759318-3305-1-git-send-email-jbacik@fusionio.com> References: <1378759318-3305-1-git-send-email-jbacik@fusionio.com> MIME-Version: 1.0 Content-Type: text/plain Sender: linux-btrfs-owner@vger.kernel.org List-ID: 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 --- Makefile | 7 +++++ tests/fsck-tests.sh | 31 +++++++++++++++++++++++ tests/fsck-tests/001-bad-file-extent-bytenr.img | Bin 0 -> 4096 bytes 3 files changed, 38 insertions(+), 0 deletions(-) create mode 100644 tests/fsck-tests.sh create mode 100644 tests/fsck-tests/001-bad-file-extent-bytenr.img diff --git a/Makefile b/Makefile index 3fade14..0e812cc 100644 --- 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 index 0000000..c1490bf --- /dev/null +++ b/tests/fsck-tests.sh @@ -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 index 0000000000000000000000000000000000000000..d2a05bb8f83d7f1bdc4be1441d3d8d35a89e142e GIT binary patch literal 4096 zcmeH}eK^y5AIJB=HZis#ld?QS9Mv4_Of8wMb+Xy{-7?nK7F$e6QQb1IAX+fGlXZfMf;0!Vkj zJvX_KWEOFo=%gw@5vC86umI%0Q@Kpn;Kos~t8AM#5}}Iev<%H_=M(YY>vRsP6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