Btrfs-progs: add make test framework
Subsystems (2)
PATCH 1/1 Btrfs-progs: add make test framework
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,
--- Makefile | 7 +++++++ tests/bad-file-extent-bytenr.img | Bin 0 -> 4096 bytes tests/fsck-tests.sh | 34 ++++++++++++++++++++++++++++++++++ 3 files changed, 41 insertions(+), 0 deletions(-) create mode 100644 tests/bad-file-extent-bytenr.img create mode 100644 tests/fsck-tests.sh
Makefile +7 -0
@@ -19,6 +19,7 @@ libbtrfs_headers = send-stream.h send-utils.h send.h rbtree.h btrfs-list.h \ CHECKFLAGS= -D__linux__ -Dlinux -D__STDC__ -Dunix -D__unix__ -Wbitwise \ -Wuninitialized -Wshadow -Wundef DEPFLAGS = -Wp,-MMD,$(@D)/.$(@F).d,-MT,$@ +TESTS = fsck-tests.sh INSTALL = install prefix ?= /usr/local
@@ -87,6 +88,12 @@ endif all: version.h $(progs) manpages +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
tests/bad-file-extent-bytenr.img new file binary +0 -0
tests/fsck-tests.sh new file +34 -0
@@ -0,0 +1,34 @@ +#!/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. +# + +TEST_DEV="" +here=`pwd` + +_fail() +{ + echo "$*" | tee -a fsck-tests-results.txt + exit 1 +} + +[ -z $TEST_DEV ] && echo "Cannot run without a test device set" && exit 0 + +rm -f fsck-tests-results.txt + +for i in $(find tests -name '*.img') +do + echo "testing image $i" >> fsck-tests-results.txt + $here/btrfs-image -r $i $TEST_DEV >> fsck-tests-results.txt 2>&1 \ + || _fail "restore failed" + $here/btrfsck $TEST_DEV >> fsck-test-results.txt 2>&1 + [ $? -eq 0 ] && _fail "btrfsck should have detected corruption" + + $here/btrfsck --repair $TEST_DEV >> fsck-test-results.txt 2>&1 || \ + _fail "btrfsck should have repaired the image" + + $here/btrfsck $TEST_DEV >> fsck-test-results.txt 2>&1 || \ + _fail "btrfsck did not correct corruption" +done
Signature · 1 line
1.7.7.6
Quoted 4 lines · Josef Bacik
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,
That's great. I hope we're going to gather more tests so let's separate them to more categories from the beginning (mkfs, options coverage, corrupt-block, restore maybe, dunno what else).
This makes it possible to do a quick run a subset of the tests (eg. mkfs related) after a fix is committed.
Quoted 2 lines
tests/bad-file-extent-bytenr.img | Bin 0 -> 4096 bytes tests/fsck-tests.sh | 34 ++++++++++++++++++++++++++++++++++
I suggest to put them into a subdirectory (eg.) 'fsck' and prefix the images with numbers (just a sequence number).
tests/fsck-tests.sh line 8
Quoted 11 lines
tests/fsck-tests.sh new file +8
-0@@ -0,0 +1,34 @@ +#!/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. +# + +TEST_DEV=""
I found the current test hard to use, eg. I can't just do 'make test' from the toplevel dir. The script fsck-tests.sh expects TEST_DEV to be set, but there's no way to do that, because it's set unconditionally to empty string.
Quoted 26 lines
tests/fsck-tests.sh new file +26
-0+here=`pwd` + +_fail() +{ + echo "$*" | tee -a fsck-tests-results.txt + exit 1 +} + +[ -z $TEST_DEV ] && echo "Cannot run without a test device set" && exit 0 + +rm -f fsck-tests-results.txt + +for i in $(find tests -name '*.img') +do + echo "testing image $i" >> fsck-tests-results.txt + $here/btrfs-image -r $i $TEST_DEV >> fsck-tests-results.txt 2>&1 \ + || _fail "restore failed" + $here/btrfsck $TEST_DEV >> fsck-test-results.txt 2>&1 + [ $? -eq 0 ] && _fail "btrfsck should have detected corruption" + + $here/btrfsck --repair $TEST_DEV >> fsck-test-results.txt 2>&1 || \ + _fail "btrfsck should have repaired the image" + + $here/btrfsck $TEST_DEV >> fsck-test-results.txt 2>&1 || \ + _fail "btrfsck did not correct corruption" +done
Quoted 10 lines · David Sterba
Quoted 4 lines · Josef Bacik
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,
That's great. I hope we're going to gather more tests so let's separate them to more categories from the beginning (mkfs, options coverage, corrupt-block, restore maybe, dunno what else).
Quoted 8 lines
This makes it possible to do a quick run a subset of the tests (eg. mkfs related) after a fix is committed.
Quoted 2 lines
tests/bad-file-extent-bytenr.img | Bin 0 -> 4096 bytes tests/fsck-tests.sh | 34 ++++++++++++++++++++++++++++++++++I suggest to put them into a subdirectory (eg.) 'fsck' and prefix the images with numbers (just a sequence number).
I'm not prefixing with numbers, I want to make it easy to tell what each image is testing for. I will move them into a fsck directory tho.
Quoted 17 lines
tests/fsck-tests.sh line 8
Quoted 12 lines
tests/fsck-tests.sh new file +8
-0@@ -0,0 +1,34 @@ +#!/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. +# + +TEST_DEV=""I found the current test hard to use, eg. I can't just do 'make test' from the toplevel dir. The script
fsck-tests.shexpectsTEST_DEVto be set, but there's no way to do that, because it's set unconditionally to empty string.
Yeah I wasn't sure how I wanted to do this. At first I thought about making the fsck tester just make a loop device, but I didn't want to override something if people were already using a loop device. But maybe I'll just default to using loop5 or something big like that and then if the user wants to change it they can go into the script and change it themselves. How does that sound? Thanks,
Josef
Quoted 14 lines · Josef Bacik
Quoted 13 lines · David Sterba
Quoted 4 lines · Josef Bacik
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,
That's great. I hope we're going to gather more tests so let's separate them to more categories from the beginning (mkfs, options coverage, corrupt-block, restore maybe, dunno what else).
This makes it possible to do a quick run a subset of the tests (eg. mkfs related) after a fix is committed.
Quoted 8 lines
Quoted 5 lines
Quoted 2 lines
tests/bad-file-extent-bytenr.img | Bin 0 -> 4096 bytes tests/fsck-tests.sh | 34 ++++++++++++++++++++++++++++++++++I suggest to put them into a subdirectory (eg.) 'fsck' and prefix the images with numbers (just a sequence number).
I'm not prefixing with numbers, I want to make it easy to tell what each image is testing for. I will move them into a fsck directory tho.
David might have meant "001-bad-file-extent-bytenr.img" though.
Quoted 18 lines
Quoted 17 lines
tests/fsck-tests.sh line 8
Quoted 12 lines
tests/fsck-tests.sh new file +8
-0@@ -0,0 +1,34 @@ +#!/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. +# + +TEST_DEV=""I found the current test hard to use, eg. I can't just do 'make test' from the toplevel dir. The script
fsck-tests.shexpectsTEST_DEVto be set, but there's no way to do that, because it's set unconditionally to empty string.
Quoted 5 lines
Yeah I wasn't sure how I wanted to do this. At first I thought about making the fsck tester just make a loop device, but I didn't want to override something if people were already using a loop device. But maybe I'll just default to using loop5 or something big like that and then if the user wants to change it they can go into the script and change it themselves. How does that sound? Thanks,
Dumb question, can you just point btrfsck at the image itself w/o setting up loopback? i.e. do something like:
# btrfs-image -r 001-bad-file-extent-bytenr.img test.img # btrfsck --repair test.img
-Eric
Quoted 6 lines
Josef
--
To unsubscribe from this list: send the line "unsubscribe linux-btrfs" in the body of a message to [email protected]
More majordomo info at http://vger.kernel.org/majordomo-info.html
Quoted 18 lines · Eric Sandeen
Quoted 17 lines · Josef Bacik
Quoted 16 lines · David Sterba
Quoted 4 lines · Josef Bacik
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,
That's great. I hope we're going to gather more tests so let's separate them to more categories from the beginning (mkfs, options coverage, corrupt-block, restore maybe, dunno what else).
This makes it possible to do a quick run a subset of the tests (eg. mkfs related) after a fix is committed.
Quoted 2 lines
tests/bad-file-extent-bytenr.img | Bin 0 -> 4096 bytes tests/fsck-tests.sh | 34 ++++++++++++++++++++++++++++++++++
Quoted 7 lines
Quoted 5 lines
Quoted 2 lines
I suggest to put them into a subdirectory (eg.) 'fsck' and prefix the images with numbers (just a sequence number).
I'm not prefixing with numbers, I want to make it easy to tell what each image is testing for. I will move them into a fsck directory tho.
David might have meant "001-bad-file-extent-bytenr.img" though.
Oh yeah that may be good then.
Quoted 25 lines
Quoted 19 lines
Quoted 18 lines
tests/fsck-tests.sh line 8
Quoted 13 lines
tests/fsck-tests.sh new file +8
-0@@ -0,0 +1,34 @@ +#!/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. +# + +TEST_DEV=""I found the current test hard to use, eg. I can't just do 'make test' from the toplevel dir. The script
fsck-tests.shexpectsTEST_DEVto be set, but there's no way to do that, because it's set unconditionally to empty string.Quoted 5 lines
Yeah I wasn't sure how I wanted to do this. At first I thought about making the fsck tester just make a loop device, but I didn't want to override something if people were already using a loop device. But maybe I'll just default to using loop5 or something big like that and then if the user wants to change it they can go into the script and change it themselves. How does that sound? Thanks,
Quoted 5 lines
Dumb question, can you just point btrfsck at the image itself w/o setting up loopback? i.e. do something like:
# btrfs-image -r 001-bad-file-extent-bytenr.img test.img # btrfsck --repair test.img
Huh, I'm not sure...yes it looks like it, well that solves that problem. Thanks,
Josef
Quoted 10 lines
-Eric
Quoted 6 lines
Josef
--
To unsubscribe from this list: send the line "unsubscribe linux-btrfs" in the body of a message to [email protected]
More majordomo info at http://vger.kernel.org/majordomo-info.html
Quoted 4 lines · Josef Bacik
Quoted 2 lines · Eric Sandeen
On 9/9/13 12:13 PM, Josef Bacik wrote:
David might have meant "001-bad-file-extent-bytenr.img" though.Oh yeah that may be good then.
Yes that's what I meant. I thought the number could be useful as a shortcut additional to the human-readable part.
Quoted 6 lines
Quoted 6 lines
Quoted 5 lines
Yeah I wasn't sure how I wanted to do this. At first I thought about making the fsck tester just make a loop device, but I didn't want to override something if people were already using a loop device. But maybe I'll just default to using loop5 or something big like that and then if the user wants to change it they can go into the script and change it themselves. How does that sound? Thanks,
Quoted 8 lines
Quoted 5 lines
Dumb question, can you just point btrfsck at the image itself w/o setting up loopback? i.e. do something like:
# btrfs-image -r 001-bad-file-extent-bytenr.img test.img # btrfsck --repair test.imgHuh, I'm not sure...yes it looks like it, well that solves that problem. Thanks,
If you need a blockdevice, you can use
$ losetup -f /the/file (get a free loopdev)
$ losetup -j /the/file /dev/loop2: ...
and parse the loop name from the output.