From 0d342f8fcb5d99fbdc0765974570d6c335460904 Mon Sep 17 00:00:00 2001 From: Josef Bacik Date: Mon, 9 Sep 2013 16:41:58 -0400 Subject: 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, Signed-off-by: Josef Bacik Signed-off-by: David Sterba Signed-off-by: Chris Mason --- tests/fsck-tests.sh | 31 ++++++++++++++++++++++++ tests/fsck-tests/001-bad-file-extent-bytenr.img | Bin 0 -> 4096 bytes 2 files changed, 31 insertions(+) create mode 100644 tests/fsck-tests.sh create mode 100644 tests/fsck-tests/001-bad-file-extent-bytenr.img (limited to 'tests') diff --git a/tests/fsck-tests.sh b/tests/fsck-tests.sh new file mode 100644 index 00000000..c1490bf3 --- /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 00000000..d2a05bb8 Binary files /dev/null and b/tests/fsck-tests/001-bad-file-extent-bytenr.img differ -- cgit v1.2.3 From 2454473dd1647e83d6eba9852eeb08d331e9ea9a Mon Sep 17 00:00:00 2001 From: Josef Bacik Date: Tue, 1 Oct 2013 08:58:33 -0400 Subject: Btrfs-progs: add a test image for the transid fixer in btrfsck This is a verification test for the transid recow functionality of btrfsck. I've also adjusted the test script to spit out which image it's testing so I can be sure the image was getting tested. Thanks, Signed-off-by: Josef Bacik Signed-off-by: David Sterba Signed-off-by: Chris Mason --- tests/fsck-tests.sh | 1 + tests/fsck-tests/002-bad-transid.img | Bin 0 -> 4096 bytes 2 files changed, 1 insertion(+) create mode 100644 tests/fsck-tests/002-bad-transid.img (limited to 'tests') diff --git a/tests/fsck-tests.sh b/tests/fsck-tests.sh index c1490bf3..25c390d0 100644 --- a/tests/fsck-tests.sh +++ b/tests/fsck-tests.sh @@ -17,6 +17,7 @@ rm -f fsck-tests-results.txt for i in $(find $here/tests/fsck-tests -name '*.img') do + echo " [TEST] $(basename $i)" echo "testing image $i" >> fsck-tests-results.txt $here/btrfs-image -r $i test.img >> fsck-tests-results.txt 2>&1 \ || _fail "restore failed" diff --git a/tests/fsck-tests/002-bad-transid.img b/tests/fsck-tests/002-bad-transid.img new file mode 100644 index 00000000..85bd87cd Binary files /dev/null and b/tests/fsck-tests/002-bad-transid.img differ -- cgit v1.2.3 From 2100836188672d64adf0def8975dceea710ce51c Mon Sep 17 00:00:00 2001 From: Adam Buchbinder Date: Wed, 21 May 2014 10:20:27 -0700 Subject: btrfs-progs: Add some simple end-to-end tests for btrfs-convert These use the system's mke2fs, and don't require loop devices or root privileges. They don't pick up anything with the default flags right now, but they do pick up some sanitizer issues when the tools are compiled with any of -fsanitize={address,memory,thread}. Signed-off-by: Adam Buchbinder Signed-off-by: David Sterba --- tests/convert-tests.sh | 35 +++++++++++++++++++++++++++++++++++ 1 file changed, 35 insertions(+) create mode 100644 tests/convert-tests.sh (limited to 'tests') diff --git a/tests/convert-tests.sh b/tests/convert-tests.sh new file mode 100644 index 00000000..87369c5e --- /dev/null +++ b/tests/convert-tests.sh @@ -0,0 +1,35 @@ +#!/bin/bash +# +# convert ext2/3/4 images to btrfs images, and make sure the results are +# clean. +# + +here=`pwd` + +_fail() +{ + echo "$*" | tee -a convert-tests-results.txt + exit 1 +} + +rm -f convert-tests-results.txt +rm -f test.img + +test(){ + echo " [TEST] $1" + shift + echo "creating ext image with: $*" >> convert-tests-results.txt + # 256MB is the smallest acceptable btrfs image. + dd if=/dev/zero of=$here/test.img bs=1024 count=$((256*1024)) \ + >> convert-tests-results.txt 2>&1 || _fail "dd failed" + $* -F $here/test.img >> convert-tests-results.txt 2>&1 \ + || _fail "filesystem create failed" + $here/btrfs-convert $here/test.img >> convert-tests-results.txt 2>&1 \ + || _fail "btrfs-convert failed" + $here/btrfsck $here/test.img >> convert-tests-results.txt 2>&1 \ + || _fail "btrfsck detected errors" +} + +test "ext2, 4k blocksize" mke2fs -b 4096 +test "ext3, 4k blocksize" mke2fs -j -b 4096 +test "ext4, 4k blocksize" mke2fs -t ext4 -b 4096 -- cgit v1.2.3 From 4156fadc5399adfb4681f01908a1927760d12bdc Mon Sep 17 00:00:00 2001 From: Adam Buchbinder Date: Thu, 12 Jun 2014 09:08:33 -0700 Subject: btrfs-progs: Use sparse files for filesystem conversion tests On my system, this brings the FS conversion test suite's runtime from over ten seconds down to under two. Thanks to Julien Muchembled for the suggestion. Signed-off-by: Adam Buchbinder Signed-off-by: David Sterba --- tests/convert-tests.sh | 18 ++++++++++-------- 1 file changed, 10 insertions(+), 8 deletions(-) (limited to 'tests') diff --git a/tests/convert-tests.sh b/tests/convert-tests.sh index 87369c5e..9f7a5c8b 100644 --- a/tests/convert-tests.sh +++ b/tests/convert-tests.sh @@ -13,15 +13,16 @@ _fail() } rm -f convert-tests-results.txt -rm -f test.img test(){ echo " [TEST] $1" - shift - echo "creating ext image with: $*" >> convert-tests-results.txt + shift + echo "creating ext image with: $*" >> convert-tests-results.txt # 256MB is the smallest acceptable btrfs image. - dd if=/dev/zero of=$here/test.img bs=1024 count=$((256*1024)) \ - >> convert-tests-results.txt 2>&1 || _fail "dd failed" + rm -f $here/test.img >> convert-tests-results.txt 2>&1 \ + || _fail "could not remove test image file" + truncate -s 256M $here/test.img >> convert-tests-results.txt 2>&1 \ + || _fail "could not create test image file" $* -F $here/test.img >> convert-tests-results.txt 2>&1 \ || _fail "filesystem create failed" $here/btrfs-convert $here/test.img >> convert-tests-results.txt 2>&1 \ @@ -30,6 +31,7 @@ test(){ || _fail "btrfsck detected errors" } -test "ext2, 4k blocksize" mke2fs -b 4096 -test "ext3, 4k blocksize" mke2fs -j -b 4096 -test "ext4, 4k blocksize" mke2fs -t ext4 -b 4096 +# btrfs-convert requires 4k blocksize. +test "ext2" mke2fs -b 4096 +test "ext3" mke2fs -j -b 4096 +test "ext4" mke2fs -t ext4 -b 4096 -- cgit v1.2.3 From 8efdd3ca4cbeaf51908f04ba9ea1fb689a30241f Mon Sep 17 00:00:00 2001 From: Wang Shilong Date: Thu, 29 May 2014 18:01:44 +0800 Subject: Btrfs-progs: fsck: add tests for extent tree rebuilding We need test to verify extent tree rebuilding work, this test create a strange filesystem with some snapshots, destroy extent root node, and run fsck with "--init-extent-tree". Since this tests need btrfs internal tool(btrfs-corrupt-block),so i add this test into btrfs-progs. Signed-off-by: Wang Shilong Signed-off-by: David Sterba --- tests/fsck-tests.sh | 69 ++++++++++++++++++++++++++++++++++++++++++++--------- 1 file changed, 58 insertions(+), 11 deletions(-) (limited to 'tests') diff --git a/tests/fsck-tests.sh b/tests/fsck-tests.sh index 25c390d0..b783b78e 100644 --- a/tests/fsck-tests.sh +++ b/tests/fsck-tests.sh @@ -6,27 +6,74 @@ # here=`pwd` +TEST_DEV= +TEST_MNT= +RESULT="fsck-tests-results.txt" _fail() { - echo "$*" | tee -a fsck-tests-results.txt + echo "$*" | tee -a $RESULT exit 1 } -rm -f fsck-tests-results.txt +run_check() +{ + echo "############### $@" >> $RESULT 2>&1 + "$@" >> $RESULT 2>&1 || _fail "failed: $@" +} + +rm -f $RESULT + +if [ -z $TEST_DEV ] || [ -z $TEST_MNT ];then + _fail "please set TEST_DEV and TEST_MNT" +fi + +# test rely on corrupting blocks tool +run_check make btrfs-corrupt-block for i in $(find $here/tests/fsck-tests -name '*.img') do echo " [TEST] $(basename $i)" - 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" + echo "testing image $i" >> $RESULT + + run_check $here/btrfs-image -r $i test.img - $here/btrfsck --repair test.img >> fsck-test-results.txt 2>&1 || \ - _fail "btrfsck should have repaired the image" + $here/btrfsck test.img >> $RESULT 2>&1 + [ $? -eq 0 ] && _fail "btrfsck should have detected corruption" - $here/btrfsck test.img >> fsck-test-results.txt 2>&1 || \ - _fail "btrfsck did not correct corruption" + run_check $here/btrfsck --repair test.img + run_check $here/btrfsck test.img done + +# test whether fsck can rebuild a corrupted extent tree +test_extent_tree_rebuild() +{ + echo " [TEST] extent tree rebuild" + $here/mkfs.btrfs -f $TEST_DEV >> /dev/null 2>&1 || _fail "fail to mkfs" + + run_check mount $TEST_DEV $TEST_MNT + cp -aR /lib/modules/`uname -r`/ $TEST_MNT 2>&1 + + for i in `seq 1 100`;do + $here/btrfs sub snapshot $TEST_MNT \ + $TEST_MNT/snapaaaaaaa_$i >& /dev/null + done + run_check umount $TEST_DEV + + # get extent root bytenr + extent_root_bytenr=`$here/btrfs-debug-tree -r $TEST_DEV | grep extent | awk '{print $7}'` + if [ -z $extent_root_bytenr ];then + _fail "fail to get extent root bytenr" + fi + + # corrupt extent root node block + run_check $here/btrfs-corrupt-block -l $extent_root_bytenr \ + -b 4096 $TEST_DEV + + $here/btrfs check $TEST_DEV >& /dev/null && \ + _fail "fsck should detect failure" + run_check $here/btrfs check --init-extent-tree $TEST_DEV + run_check $here/btrfs check $TEST_DEV +} + +test_extent_tree_rebuild -- cgit v1.2.3 From 935457f16446012841f8da5a5c9804063d76b366 Mon Sep 17 00:00:00 2001 From: Josef Bacik Date: Fri, 3 Oct 2014 10:59:36 -0400 Subject: btrfs-progs: skip extent rebuild test if no testdev It is highly obnoxious to have to go put in a testdev when all you really want is to run the quick image tests. Make this part optional so if we don't have a testdev specified we just don't run that particular test. Thanks, Signed-off-by: Josef Bacik Signed-off-by: David Sterba --- tests/fsck-tests.sh | 9 +++++---- 1 file changed, 5 insertions(+), 4 deletions(-) (limited to 'tests') diff --git a/tests/fsck-tests.sh b/tests/fsck-tests.sh index b783b78e..867366b9 100644 --- a/tests/fsck-tests.sh +++ b/tests/fsck-tests.sh @@ -24,10 +24,6 @@ run_check() rm -f $RESULT -if [ -z $TEST_DEV ] || [ -z $TEST_MNT ];then - _fail "please set TEST_DEV and TEST_MNT" -fi - # test rely on corrupting blocks tool run_check make btrfs-corrupt-block @@ -45,6 +41,11 @@ do run_check $here/btrfsck test.img done +if [ -z $TEST_DEV ] || [ -z $TEST_MNT ];then + echo " [NOTRUN] extent tree rebuild" + exit 0 +fi + # test whether fsck can rebuild a corrupted extent tree test_extent_tree_rebuild() { -- cgit v1.2.3 From 6863bcf74fa8bf335d73c04248fc25ac6ada3121 Mon Sep 17 00:00:00 2001 From: Josef Bacik Date: Fri, 10 Oct 2014 16:57:06 -0400 Subject: Btrfs-progs: repair missing dir index If we have an inode backref entry then we know enough to add back a missing dir index. When messing with the inode backrefs we need to do all of that first before we process the inode recs themselves as we may clear errors on the inode recs as we fix the directory indexes. This adds the framework for fixing backref errors and fixes missing dir index issues. Thanks, Signed-off-by: Josef Bacik Signed-off-by: David Sterba --- tests/fsck-tests/004-no-dir-index.img | Bin 0 -> 4096 bytes 1 file changed, 0 insertions(+), 0 deletions(-) create mode 100644 tests/fsck-tests/004-no-dir-index.img (limited to 'tests') diff --git a/tests/fsck-tests/004-no-dir-index.img b/tests/fsck-tests/004-no-dir-index.img new file mode 100644 index 00000000..6f2483e6 Binary files /dev/null and b/tests/fsck-tests/004-no-dir-index.img differ -- cgit v1.2.3 From 187b85436b8d2209bb0df1d67a97be711663615e Mon Sep 17 00:00:00 2001 From: Josef Bacik Date: Fri, 3 Oct 2014 10:45:29 -0400 Subject: btrfs-progs: add the ability to fix shifted item offsets A user had a corrupted fs where the items had been shifted improperly. This patch adds the ability to fix this sort of problem within fsck. We will simply shift the item over to the proper offset and update the offsets to make sure they are correct. I tested this with a hand crafted fs that was broken in the same way as the user, and I've included the file as a new test. Thanks, Signed-off-by: Josef Bacik Signed-off-by: David Sterba --- tests/fsck-tests/003-shift-offsets.img | Bin 0 -> 4096 bytes 1 file changed, 0 insertions(+), 0 deletions(-) create mode 100644 tests/fsck-tests/003-shift-offsets.img (limited to 'tests') diff --git a/tests/fsck-tests/003-shift-offsets.img b/tests/fsck-tests/003-shift-offsets.img new file mode 100644 index 00000000..ce23f673 Binary files /dev/null and b/tests/fsck-tests/003-shift-offsets.img differ -- cgit v1.2.3 From 01f868b5a99b412212ede924a81aa15e6d408381 Mon Sep 17 00:00:00 2001 From: Josef Bacik Date: Fri, 3 Oct 2014 10:54:26 -0400 Subject: btrfs-progs: make fsck deal with bogus items We can deal with corrupt items by deleting them in a few cases. Fsck can easily recover from a missing extent item or a dir index item. So if we notice a item is completely bogus and it is of a key that we know we can repair then just delete it and carry on. Thanks, Signed-off-by: Josef Bacik Signed-off-by: David Sterba --- tests/fsck-tests/005-bad-item-offset.img | Bin 0 -> 398336 bytes 1 file changed, 0 insertions(+), 0 deletions(-) create mode 100644 tests/fsck-tests/005-bad-item-offset.img (limited to 'tests') diff --git a/tests/fsck-tests/005-bad-item-offset.img b/tests/fsck-tests/005-bad-item-offset.img new file mode 100644 index 00000000..e11e1e32 Binary files /dev/null and b/tests/fsck-tests/005-bad-item-offset.img differ -- cgit v1.2.3 From 555b7feaebc109bbc184f333779bd664adc34125 Mon Sep 17 00:00:00 2001 From: Filipe Manana Date: Fri, 17 Oct 2014 18:20:08 +0100 Subject: Btrfs-progs: check, ability to detect and fix outdated snapshot root items This change adds code to detect and fix the issue introduced in the kernel release 3.17, where creation of read-only snapshots lead to a corrupted filesystem if they were created at a moment when the source subvolume/snapshot had orphan items. The issue was that the on-disk root items became incorrect, referring to the pre orphan cleanup root node instead of the post orphan cleanup root node. A test filesystem can be generated with the test case recently submitted for xfstests/fstests, which is essencially the following (bash script): workout() { ops=$1 procs=$2 num_snapshots=$3 _scratch_mkfs >> $seqres.full 2>&1 _scratch_mount snapshot_cmd="$BTRFS_UTIL_PROG subvolume snapshot -r $SCRATCH_MNT" snapshot_cmd="$snapshot_cmd $SCRATCH_MNT/snap_\`date +'%H_%M_%S_%N'\`" run_check $FSSTRESS_PROG -p $procs \ -x "$snapshot_cmd" -X $num_snapshots -d $SCRATCH_MNT -n $ops } ops=10000 procs=4 snapshots=500 workout $ops $procs $snapshots Example of btrfsck's (btrfs check) behaviour against such filesystem: $ btrfsck /dev/loop0 root item for root 311, current bytenr 44630016, current gen 60, current level 1, new bytenr 44957696, new gen 61, new level 1 root item for root 1480, current bytenr 1003569152, current gen 1271, current level 1, new bytenr 1004175360, new gen 1272, new level 1 root item for root 1509, current bytenr 1037434880, current gen 1300, current level 1, new bytenr 1038467072, new gen 1301, new level 1 root item for root 1562, current bytenr 33636352, current gen 1354, current level 1, new bytenr 34455552, new gen 1355, new level 1 root item for root 3094, current bytenr 1011712000, current gen 2935, current level 1, new bytenr 1008484352, new gen 2936, new level 1 root item for root 3716, current bytenr 80805888, current gen 3578, current level 1, new bytenr 73515008, new gen 3579, new level 1 root item for root 4085, current bytenr 714031104, current gen 3958, current level 1, new bytenr 716816384, new gen 3959, new level 1 Found 7 roots with an outdated root item. Please run a filesystem check with the option --repair to fix them. $ echo $? 1 $ btrfsck --repair /dev/loop0 enabling repair mode fixing root item for root 311, current bytenr 44630016, current gen 60, current level 1, new bytenr 44957696, new gen 61, new level 1 fixing root item for root 1480, current bytenr 1003569152, current gen 1271, current level 1, new bytenr 1004175360, new gen 1272, new level 1 fixing root item for root 1509, current bytenr 1037434880, current gen 1300, current level 1, new bytenr 1038467072, new gen 1301, new level 1 fixing root item for root 1562, current bytenr 33636352, current gen 1354, current level 1, new bytenr 34455552, new gen 1355, new level 1 fixing root item for root 3094, current bytenr 1011712000, current gen 2935, current level 1, new bytenr 1008484352, new gen 2936, new level 1 fixing root item for root 3716, current bytenr 80805888, current gen 3578, current level 1, new bytenr 73515008, new gen 3579, new level 1 fixing root item for root 4085, current bytenr 714031104, current gen 3958, current level 1, new bytenr 716816384, new gen 3959, new level 1 Fixed 7 roots. Checking filesystem on /dev/loop0 UUID: 2186e9b9-c977-4a35-9c7b-69c6609d4620 checking extents checking free space cache cache and super generation don't match, space cache will be invalidated checking fs roots checking csums checking root refs found 618537000 bytes used err is 0 total csum bytes: 130824 total tree bytes: 601620480 total fs tree bytes: 580288512 total extent tree bytes: 18464768 btree space waste bytes: 136939144 file data blocks allocated: 34150318080 referenced 27815415808 Btrfs v3.17-rc3-2-gbbe1dd8 $ echo $? 0 Signed-off-by: Filipe Manana Signed-off-by: David Sterba --- tests/fsck-tests.sh | 15 +++++++++++++-- tests/fsck-tests/006-bad_root_items_fs.tar.xz | Bin 0 -> 24980 bytes tests/fsck-tests/007-bad_root_items_fs_skinny.tar.xz | Bin 0 -> 26520 bytes 3 files changed, 13 insertions(+), 2 deletions(-) create mode 100644 tests/fsck-tests/006-bad_root_items_fs.tar.xz create mode 100644 tests/fsck-tests/007-bad_root_items_fs_skinny.tar.xz (limited to 'tests') diff --git a/tests/fsck-tests.sh b/tests/fsck-tests.sh index 867366b9..3f04626e 100644 --- a/tests/fsck-tests.sh +++ b/tests/fsck-tests.sh @@ -27,12 +27,23 @@ rm -f $RESULT # test rely on corrupting blocks tool run_check make btrfs-corrupt-block -for i in $(find $here/tests/fsck-tests -name '*.img') +# Some broken filesystem images are kept as .img files, created by the tool +# btrfs-image, and others are kept as .tar.xz files that contain raw filesystem +# image (the backing file of a loop device, as a sparse file). The reason for +# keeping some as tarballs of raw images is that for these cases btrfs-image +# isn't able to preserve all the (bad) filesystem structure for some reason. +for i in $(find $here/tests/fsck-tests -name '*.img' -o -name '*.tar.xz') do echo " [TEST] $(basename $i)" echo "testing image $i" >> $RESULT - run_check $here/btrfs-image -r $i test.img + extension=${i#*.} + + if [ $extension == "img" ]; then + run_check $here/btrfs-image -r $i test.img + else + run_check tar xJf $i + fi $here/btrfsck test.img >> $RESULT 2>&1 [ $? -eq 0 ] && _fail "btrfsck should have detected corruption" diff --git a/tests/fsck-tests/006-bad_root_items_fs.tar.xz b/tests/fsck-tests/006-bad_root_items_fs.tar.xz new file mode 100644 index 00000000..125d8e7d Binary files /dev/null and b/tests/fsck-tests/006-bad_root_items_fs.tar.xz differ diff --git a/tests/fsck-tests/007-bad_root_items_fs_skinny.tar.xz b/tests/fsck-tests/007-bad_root_items_fs_skinny.tar.xz new file mode 100644 index 00000000..ed99dc4d Binary files /dev/null and b/tests/fsck-tests/007-bad_root_items_fs_skinny.tar.xz differ -- cgit v1.2.3 From b9a799eb897f43e860f45ff5378dfa290d768c5d Mon Sep 17 00:00:00 2001 From: David Sterba Date: Fri, 17 Oct 2014 18:26:08 +0200 Subject: btrfs-progs: run fsck image tests in filename order Signed-off-by: David Sterba --- tests/fsck-tests.sh | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) (limited to 'tests') diff --git a/tests/fsck-tests.sh b/tests/fsck-tests.sh index 3f04626e..8987d044 100644 --- a/tests/fsck-tests.sh +++ b/tests/fsck-tests.sh @@ -32,7 +32,7 @@ run_check make btrfs-corrupt-block # image (the backing file of a loop device, as a sparse file). The reason for # keeping some as tarballs of raw images is that for these cases btrfs-image # isn't able to preserve all the (bad) filesystem structure for some reason. -for i in $(find $here/tests/fsck-tests -name '*.img' -o -name '*.tar.xz') +for i in $(find $here/tests/fsck-tests -name '*.img' -o -name '*.tar.xz' | sort) do echo " [TEST] $(basename $i)" echo "testing image $i" >> $RESULT -- cgit v1.2.3 From 1e3da6d65ebdcf83b1d85f11284cde79777277b9 Mon Sep 17 00:00:00 2001 From: Josef Bacik Date: Fri, 31 Oct 2014 13:49:07 -0400 Subject: Btrfs-progs: test images for new btrfsck functionality These test the recreating of missing dir item/dir index pairs, fixing the no rootdir inode item and no inode item for normal files. Thanks, Signed-off-by: Josef Bacik --- tests/fsck-tests/010-no-dir-item-or-index.img | Bin 0 -> 4953088 bytes tests/fsck-tests/011-no-rootdir-inode-item.img | Bin 0 -> 398336 bytes tests/fsck-tests/012-no-inode-item.img | Bin 0 -> 398336 bytes 3 files changed, 0 insertions(+), 0 deletions(-) create mode 100644 tests/fsck-tests/010-no-dir-item-or-index.img create mode 100644 tests/fsck-tests/011-no-rootdir-inode-item.img create mode 100644 tests/fsck-tests/012-no-inode-item.img (limited to 'tests') diff --git a/tests/fsck-tests/010-no-dir-item-or-index.img b/tests/fsck-tests/010-no-dir-item-or-index.img new file mode 100644 index 00000000..d7f22692 Binary files /dev/null and b/tests/fsck-tests/010-no-dir-item-or-index.img differ diff --git a/tests/fsck-tests/011-no-rootdir-inode-item.img b/tests/fsck-tests/011-no-rootdir-inode-item.img new file mode 100644 index 00000000..6b66fdad Binary files /dev/null and b/tests/fsck-tests/011-no-rootdir-inode-item.img differ diff --git a/tests/fsck-tests/012-no-inode-item.img b/tests/fsck-tests/012-no-inode-item.img new file mode 100644 index 00000000..352fc021 Binary files /dev/null and b/tests/fsck-tests/012-no-inode-item.img differ -- cgit v1.2.3 From 6856b0a4cab6eae794f0fe012391fa76a8dd3b4e Mon Sep 17 00:00:00 2001 From: David Sterba Date: Fri, 12 Dec 2014 15:50:41 +0100 Subject: btrfs-progs: tests: use 'btrfs check' instead of btrfsck Signed-off-by: David Sterba --- tests/convert-tests.sh | 4 ++-- tests/fsck-tests.sh | 10 +++++----- 2 files changed, 7 insertions(+), 7 deletions(-) (limited to 'tests') diff --git a/tests/convert-tests.sh b/tests/convert-tests.sh index 9f7a5c8b..ed341426 100644 --- a/tests/convert-tests.sh +++ b/tests/convert-tests.sh @@ -27,8 +27,8 @@ test(){ || _fail "filesystem create failed" $here/btrfs-convert $here/test.img >> convert-tests-results.txt 2>&1 \ || _fail "btrfs-convert failed" - $here/btrfsck $here/test.img >> convert-tests-results.txt 2>&1 \ - || _fail "btrfsck detected errors" + $here/btrfs check $here/test.img >> convert-tests-results.txt 2>&1 \ + || _fail "btrfs check detected errors" } # btrfs-convert requires 4k blocksize. diff --git a/tests/fsck-tests.sh b/tests/fsck-tests.sh index 8987d044..285bcf65 100644 --- a/tests/fsck-tests.sh +++ b/tests/fsck-tests.sh @@ -45,11 +45,11 @@ do run_check tar xJf $i fi - $here/btrfsck test.img >> $RESULT 2>&1 - [ $? -eq 0 ] && _fail "btrfsck should have detected corruption" + $here/btrfs check test.img >> $RESULT 2>&1 + [ $? -eq 0 ] && _fail "btrfs check should have detected corruption" - run_check $here/btrfsck --repair test.img - run_check $here/btrfsck test.img + run_check $here/btrfs check --repair test.img + run_check $here/btrfs check test.img done if [ -z $TEST_DEV ] || [ -z $TEST_MNT ];then @@ -83,7 +83,7 @@ test_extent_tree_rebuild() -b 4096 $TEST_DEV $here/btrfs check $TEST_DEV >& /dev/null && \ - _fail "fsck should detect failure" + _fail "btrfs check should detect failure" run_check $here/btrfs check --init-extent-tree $TEST_DEV run_check $here/btrfs check $TEST_DEV } -- cgit v1.2.3 From 4f9d8b1ffafd4ce1bf1c4c805a22bd089ade9861 Mon Sep 17 00:00:00 2001 From: David Sterba Date: Fri, 12 Dec 2014 15:49:26 +0100 Subject: btrfs-progs: tests: build prerequisities, btrfs-image and btrfs Build required utilities from the main Makefile and just check in the test scripts. Signed-off-by: David Sterba --- tests/fsck-tests.sh | 11 ++++++++++- 1 file changed, 10 insertions(+), 1 deletion(-) (limited to 'tests') diff --git a/tests/fsck-tests.sh b/tests/fsck-tests.sh index 285bcf65..24fb1090 100644 --- a/tests/fsck-tests.sh +++ b/tests/fsck-tests.sh @@ -22,10 +22,19 @@ run_check() "$@" >> $RESULT 2>&1 || _fail "failed: $@" } +check_prereq() +{ + if ! [ -f $here/$1 ]; then + _fail "Failed prerequisities: $1"; + fi +} + rm -f $RESULT # test rely on corrupting blocks tool -run_check make btrfs-corrupt-block +check_prereq btrfs-corrupt-block +check_prereq btrfs-image +check_prereq btrfs # Some broken filesystem images are kept as .img files, created by the tool # btrfs-image, and others are kept as .tar.xz files that contain raw filesystem -- cgit v1.2.3 From 2ac6d5a76b110565c6cc6cebb8622e755cb3d2d4 Mon Sep 17 00:00:00 2001 From: Josef Bacik Date: Fri, 10 Oct 2014 16:50:42 -0400 Subject: Btrfs-progs: add two new test images This adds two new test images 1) 008-bad-offset-snapshots. This has a corrupt item with multiple snapshots pointing to it, to make sure the bad block repair stuff doesn't loop and actually repairs stuff. It also requires the dir index repair stuff to pass our built in tests which is why it's not tied to the same commit. 2) 009-bad-dir-index-name.img. This has a corrupt name in a dir index to make sure our dir index repair stuff is working properly. Thanks, Signed-off-by: Josef Bacik --- tests/fsck-tests/008-bad-offset-snapshots.img | Bin 0 -> 249856 bytes tests/fsck-tests/009-bad-dir-index-name.img | Bin 0 -> 4096 bytes 2 files changed, 0 insertions(+), 0 deletions(-) create mode 100644 tests/fsck-tests/008-bad-offset-snapshots.img create mode 100644 tests/fsck-tests/009-bad-dir-index-name.img (limited to 'tests') diff --git a/tests/fsck-tests/008-bad-offset-snapshots.img b/tests/fsck-tests/008-bad-offset-snapshots.img new file mode 100644 index 00000000..b87e9977 Binary files /dev/null and b/tests/fsck-tests/008-bad-offset-snapshots.img differ diff --git a/tests/fsck-tests/009-bad-dir-index-name.img b/tests/fsck-tests/009-bad-dir-index-name.img new file mode 100644 index 00000000..e004737f Binary files /dev/null and b/tests/fsck-tests/009-bad-dir-index-name.img differ -- cgit v1.2.3 From 501c8eeda2fb082eca999af825a14ad8a5ce0fb5 Mon Sep 17 00:00:00 2001 From: Qu Wenruo Date: Mon, 15 Dec 2014 11:16:29 +0800 Subject: btrfs-progs: Add testcase for leaf-corrupted btrfsck repairing. Add testcase for leaf-corrupted btrfsck repairing using the new generate_image.sh method. Signed-off-by: Qu Wenruo --- .../013-leaf-corruption-no-extent-data.tar.xz | Bin 0 -> 177600 bytes 1 file changed, 0 insertions(+), 0 deletions(-) create mode 100644 tests/fsck-tests/013-leaf-corruption-no-extent-data.tar.xz (limited to 'tests') diff --git a/tests/fsck-tests/013-leaf-corruption-no-extent-data.tar.xz b/tests/fsck-tests/013-leaf-corruption-no-extent-data.tar.xz new file mode 100644 index 00000000..cc90b58e Binary files /dev/null and b/tests/fsck-tests/013-leaf-corruption-no-extent-data.tar.xz differ -- cgit v1.2.3 From 5287625fcffc45fca9c857fc5b9422cbc7e1711f Mon Sep 17 00:00:00 2001 From: Qu Wenruo Date: Thu, 25 Dec 2014 09:32:11 +0800 Subject: btrfs-progs: New btrfsck test infrastructure Change the old btrfsck test infrastructure (btrfs-image dump or xz raw dump) to the new test infrastructure. 1) Test case layout The new infrastructure is dir based, each dir is one test type, and can contain multiple images/scripts for different corner cases. So layout will be the following: btrfs-progs |-tests |-fsck-tests |-001-SOME-CORRUPT-TYPE |-IMAGE-FOR-CASE1 |-IMAGE-FOR-CASE2 2) Test case image types Only 2 types for test case images. a) btrfs-image dump This one is the simplest case, one only needs to add the image to corresponding dir. b) custom script This one is for all the resting cases which can't fit btrfs-image, like csum error or script can generate the image (this reduces the size obviously and good for review) The old binary dump also belongs to this type, so need to add script to extract them. Signed-off-by: Qu Wenruo Signed-off-by: David Sterba --- tests/common | 49 ++++++++++++++++++++++++++ tests/fsck-tests.sh | 99 +++++++++++++++++++++++++++-------------------------- 2 files changed, 99 insertions(+), 49 deletions(-) create mode 100644 tests/common mode change 100644 => 100755 tests/fsck-tests.sh (limited to 'tests') diff --git a/tests/common b/tests/common new file mode 100644 index 00000000..80a53816 --- /dev/null +++ b/tests/common @@ -0,0 +1,49 @@ +#!/bin/bash +# +# Common routines for all tests +# + +_fail() +{ + echo "$*" | tee -a $RESULT + exit 1 +} + +run_check() +{ + echo "############### $@" >> $RESULT 2>&1 + "$@" >> $RESULT 2>&1 || _fail "failed: $@" +} + +check_prereq() +{ + if ! [ -f $top/$1 ]; then + _fail "Failed prerequisities: $1"; + fi +} + +check_image() +{ + image=$1 + echo "testing image $(basename $image)" >> $RESULT + $top/btrfs check $image >> $RESULT 2>&1 + [ $? -eq 0 ] && _fail "btrfs check should have detected corruption" + + run_check $top/btrfs check --repair $image + run_check $top/btrfs check $image +} + +check_all_images() +{ + dir=$1 + for i in $(find $dir -iname '*.img') + do + echo "extracting image $(basename $i)" >> $RESULT + $top/btrfs-image -r $i $i.restored || \ + _fail "failed to extract image $i" + + check_image $i.restored + + rm $i.restored + done +} diff --git a/tests/fsck-tests.sh b/tests/fsck-tests.sh old mode 100644 new mode 100755 index 24fb1090..a992b45b --- a/tests/fsck-tests.sh +++ b/tests/fsck-tests.sh @@ -5,60 +5,60 @@ # It's GPL, same as everything else in this tree. # -here=`pwd` -TEST_DEV= -TEST_MNT= -RESULT="fsck-tests-results.txt" - -_fail() -{ - echo "$*" | tee -a $RESULT - exit 1 -} - -run_check() -{ - echo "############### $@" >> $RESULT 2>&1 - "$@" >> $RESULT 2>&1 || _fail "failed: $@" -} - -check_prereq() -{ - if ! [ -f $here/$1 ]; then - _fail "Failed prerequisities: $1"; - fi -} +unset top +unset LANG +LANG=C +script_dir=$(dirname $(realpath $0)) +top=$(realpath $script_dir/../) +TEST_DEV=${TEST_DEV:-} +TEST_MNT=${TEST_MNT:-$top/tests/mnt} +RESULT="$top/tests/fsck-tests-results.txt" + +source $top/tests/common + +# Allow child test to use $top and $RESULT +export top +export RESULT +# For custom script needs to verfiy recovery +export TEST_MNT +export LANG rm -f $RESULT +mkdir -p $TEST_MNT || _fail "unable to create mount point on $TEST_MNT" # test rely on corrupting blocks tool check_prereq btrfs-corrupt-block check_prereq btrfs-image check_prereq btrfs -# Some broken filesystem images are kept as .img files, created by the tool -# btrfs-image, and others are kept as .tar.xz files that contain raw filesystem -# image (the backing file of a loop device, as a sparse file). The reason for -# keeping some as tarballs of raw images is that for these cases btrfs-image -# isn't able to preserve all the (bad) filesystem structure for some reason. -for i in $(find $here/tests/fsck-tests -name '*.img' -o -name '*.tar.xz' | sort) +# Each dir contains one type of error for btrfsck test. +# Each dir must be one of the following 2 types: +# 1) Only btrfs-image dump +# Only contains one or several btrfs-image dumps (.img) +# Each image will be tested by generic test routine +# (btrfsck --repair and btrfsck). +# This is for case that btree-healthy images. +# 2) Custom test script +# This dir contains test.sh which will do custom image +# generation/check/verification. +# This is for case btrfs-image can't dump or case needs extra +# check/verify + +for i in $(find $top/tests/fsck-tests -maxdepth 1 -mindepth 1 -type d | sort) do echo " [TEST] $(basename $i)" - echo "testing image $i" >> $RESULT - - extension=${i#*.} - - if [ $extension == "img" ]; then - run_check $here/btrfs-image -r $i test.img + cd $i + if [ -x test.sh ]; then + # Type 2 + ./test.sh + if [ $? -ne 0 ]; then + _fail "test failed for case $(basename $i)" + fi else - run_check tar xJf $i + # Type 1 + check_all_images `pwd` fi - - $here/btrfs check test.img >> $RESULT 2>&1 - [ $? -eq 0 ] && _fail "btrfs check should have detected corruption" - - run_check $here/btrfs check --repair test.img - run_check $here/btrfs check test.img + cd $top done if [ -z $TEST_DEV ] || [ -z $TEST_MNT ];then @@ -70,31 +70,32 @@ fi test_extent_tree_rebuild() { echo " [TEST] extent tree rebuild" - $here/mkfs.btrfs -f $TEST_DEV >> /dev/null 2>&1 || _fail "fail to mkfs" + $top/mkfs.btrfs -f $TEST_DEV >> /dev/null 2>&1 || _fail "fail to mkfs" run_check mount $TEST_DEV $TEST_MNT cp -aR /lib/modules/`uname -r`/ $TEST_MNT 2>&1 for i in `seq 1 100`;do - $here/btrfs sub snapshot $TEST_MNT \ + $top/btrfs sub snapshot $TEST_MNT \ $TEST_MNT/snapaaaaaaa_$i >& /dev/null done run_check umount $TEST_DEV # get extent root bytenr - extent_root_bytenr=`$here/btrfs-debug-tree -r $TEST_DEV | grep extent | awk '{print $7}'` + extent_root_bytenr=`$top/btrfs-debug-tree -r $TEST_DEV | \ + grep extent | awk '{print $7}'` if [ -z $extent_root_bytenr ];then _fail "fail to get extent root bytenr" fi # corrupt extent root node block - run_check $here/btrfs-corrupt-block -l $extent_root_bytenr \ + run_check $top/btrfs-corrupt-block -l $extent_root_bytenr \ -b 4096 $TEST_DEV - $here/btrfs check $TEST_DEV >& /dev/null && \ + $top/btrfs check $TEST_DEV >& /dev/null && \ _fail "btrfs check should detect failure" - run_check $here/btrfs check --init-extent-tree $TEST_DEV - run_check $here/btrfs check $TEST_DEV + run_check $top/btrfs check --init-extent-tree $TEST_DEV + run_check $top/btrfs check $TEST_DEV } test_extent_tree_rebuild -- cgit v1.2.3 From ebe2f5cac36748eca2866bd78151c12d18d00bfc Mon Sep 17 00:00:00 2001 From: Qu Wenruo Date: Thu, 25 Dec 2014 09:32:12 +0800 Subject: btrfs-progs: Move btrfs-image dump to corresponding dir Move these obvious btrfs-image to its corresponding dir to use the new infrastructure. Signed-off-by: Qu Wenruo Signed-off-by: David Sterba --- tests/fsck-tests/001-bad-file-extent-bytenr.img | Bin 4096 -> 0 bytes .../001-bad-file-extent-bytenr/default_case.img | Bin 0 -> 4096 bytes tests/fsck-tests/002-bad-transid.img | Bin 4096 -> 0 bytes tests/fsck-tests/002-bad-transid/default_case.img | Bin 0 -> 4096 bytes tests/fsck-tests/003-shift-offsets.img | Bin 4096 -> 0 bytes tests/fsck-tests/003-shift-offsets/default_case.img | Bin 0 -> 4096 bytes tests/fsck-tests/004-no-dir-index.img | Bin 4096 -> 0 bytes tests/fsck-tests/004-no-dir-index/default_case.img | Bin 0 -> 4096 bytes tests/fsck-tests/005-bad-item-offset.img | Bin 398336 -> 0 bytes tests/fsck-tests/005-bad-item-offset/default_case.img | Bin 0 -> 398336 bytes .../007-bad-offset-snapshots/default_case.img | Bin 0 -> 249856 bytes .../008-bad-dir-index-name/default_case.img | Bin 0 -> 4096 bytes tests/fsck-tests/008-bad-offset-snapshots.img | Bin 249856 -> 0 bytes tests/fsck-tests/009-bad-dir-index-name.img | Bin 4096 -> 0 bytes .../009-no-dir-item-or-index/default_case.img | Bin 0 -> 4953088 bytes tests/fsck-tests/010-no-dir-item-or-index.img | Bin 4953088 -> 0 bytes .../010-no-rootdir-inode-item/default_case.img | Bin 0 -> 398336 bytes tests/fsck-tests/011-no-inode-item/default_case.img | Bin 0 -> 398336 bytes tests/fsck-tests/011-no-rootdir-inode-item.img | Bin 398336 -> 0 bytes tests/fsck-tests/012-no-inode-item.img | Bin 398336 -> 0 bytes 20 files changed, 0 insertions(+), 0 deletions(-) delete mode 100644 tests/fsck-tests/001-bad-file-extent-bytenr.img create mode 100644 tests/fsck-tests/001-bad-file-extent-bytenr/default_case.img delete mode 100644 tests/fsck-tests/002-bad-transid.img create mode 100644 tests/fsck-tests/002-bad-transid/default_case.img delete mode 100644 tests/fsck-tests/003-shift-offsets.img create mode 100644 tests/fsck-tests/003-shift-offsets/default_case.img delete mode 100644 tests/fsck-tests/004-no-dir-index.img create mode 100644 tests/fsck-tests/004-no-dir-index/default_case.img delete mode 100644 tests/fsck-tests/005-bad-item-offset.img create mode 100644 tests/fsck-tests/005-bad-item-offset/default_case.img create mode 100644 tests/fsck-tests/007-bad-offset-snapshots/default_case.img create mode 100644 tests/fsck-tests/008-bad-dir-index-name/default_case.img delete mode 100644 tests/fsck-tests/008-bad-offset-snapshots.img delete mode 100644 tests/fsck-tests/009-bad-dir-index-name.img create mode 100644 tests/fsck-tests/009-no-dir-item-or-index/default_case.img delete mode 100644 tests/fsck-tests/010-no-dir-item-or-index.img create mode 100644 tests/fsck-tests/010-no-rootdir-inode-item/default_case.img create mode 100644 tests/fsck-tests/011-no-inode-item/default_case.img delete mode 100644 tests/fsck-tests/011-no-rootdir-inode-item.img delete mode 100644 tests/fsck-tests/012-no-inode-item.img (limited to 'tests') diff --git a/tests/fsck-tests/001-bad-file-extent-bytenr.img b/tests/fsck-tests/001-bad-file-extent-bytenr.img deleted file mode 100644 index d2a05bb8..00000000 Binary files a/tests/fsck-tests/001-bad-file-extent-bytenr.img and /dev/null differ diff --git a/tests/fsck-tests/001-bad-file-extent-bytenr/default_case.img b/tests/fsck-tests/001-bad-file-extent-bytenr/default_case.img new file mode 100644 index 00000000..d2a05bb8 Binary files /dev/null and b/tests/fsck-tests/001-bad-file-extent-bytenr/default_case.img differ diff --git a/tests/fsck-tests/002-bad-transid.img b/tests/fsck-tests/002-bad-transid.img deleted file mode 100644 index 85bd87cd..00000000 Binary files a/tests/fsck-tests/002-bad-transid.img and /dev/null differ diff --git a/tests/fsck-tests/002-bad-transid/default_case.img b/tests/fsck-tests/002-bad-transid/default_case.img new file mode 100644 index 00000000..85bd87cd Binary files /dev/null and b/tests/fsck-tests/002-bad-transid/default_case.img differ diff --git a/tests/fsck-tests/003-shift-offsets.img b/tests/fsck-tests/003-shift-offsets.img deleted file mode 100644 index ce23f673..00000000 Binary files a/tests/fsck-tests/003-shift-offsets.img and /dev/null differ diff --git a/tests/fsck-tests/003-shift-offsets/default_case.img b/tests/fsck-tests/003-shift-offsets/default_case.img new file mode 100644 index 00000000..ce23f673 Binary files /dev/null and b/tests/fsck-tests/003-shift-offsets/default_case.img differ diff --git a/tests/fsck-tests/004-no-dir-index.img b/tests/fsck-tests/004-no-dir-index.img deleted file mode 100644 index 6f2483e6..00000000 Binary files a/tests/fsck-tests/004-no-dir-index.img and /dev/null differ diff --git a/tests/fsck-tests/004-no-dir-index/default_case.img b/tests/fsck-tests/004-no-dir-index/default_case.img new file mode 100644 index 00000000..6f2483e6 Binary files /dev/null and b/tests/fsck-tests/004-no-dir-index/default_case.img differ diff --git a/tests/fsck-tests/005-bad-item-offset.img b/tests/fsck-tests/005-bad-item-offset.img deleted file mode 100644 index e11e1e32..00000000 Binary files a/tests/fsck-tests/005-bad-item-offset.img and /dev/null differ diff --git a/tests/fsck-tests/005-bad-item-offset/default_case.img b/tests/fsck-tests/005-bad-item-offset/default_case.img new file mode 100644 index 00000000..e11e1e32 Binary files /dev/null and b/tests/fsck-tests/005-bad-item-offset/default_case.img differ diff --git a/tests/fsck-tests/007-bad-offset-snapshots/default_case.img b/tests/fsck-tests/007-bad-offset-snapshots/default_case.img new file mode 100644 index 00000000..b87e9977 Binary files /dev/null and b/tests/fsck-tests/007-bad-offset-snapshots/default_case.img differ diff --git a/tests/fsck-tests/008-bad-dir-index-name/default_case.img b/tests/fsck-tests/008-bad-dir-index-name/default_case.img new file mode 100644 index 00000000..e004737f Binary files /dev/null and b/tests/fsck-tests/008-bad-dir-index-name/default_case.img differ diff --git a/tests/fsck-tests/008-bad-offset-snapshots.img b/tests/fsck-tests/008-bad-offset-snapshots.img deleted file mode 100644 index b87e9977..00000000 Binary files a/tests/fsck-tests/008-bad-offset-snapshots.img and /dev/null differ diff --git a/tests/fsck-tests/009-bad-dir-index-name.img b/tests/fsck-tests/009-bad-dir-index-name.img deleted file mode 100644 index e004737f..00000000 Binary files a/tests/fsck-tests/009-bad-dir-index-name.img and /dev/null differ diff --git a/tests/fsck-tests/009-no-dir-item-or-index/default_case.img b/tests/fsck-tests/009-no-dir-item-or-index/default_case.img new file mode 100644 index 00000000..d7f22692 Binary files /dev/null and b/tests/fsck-tests/009-no-dir-item-or-index/default_case.img differ diff --git a/tests/fsck-tests/010-no-dir-item-or-index.img b/tests/fsck-tests/010-no-dir-item-or-index.img deleted file mode 100644 index d7f22692..00000000 Binary files a/tests/fsck-tests/010-no-dir-item-or-index.img and /dev/null differ diff --git a/tests/fsck-tests/010-no-rootdir-inode-item/default_case.img b/tests/fsck-tests/010-no-rootdir-inode-item/default_case.img new file mode 100644 index 00000000..6b66fdad Binary files /dev/null and b/tests/fsck-tests/010-no-rootdir-inode-item/default_case.img differ diff --git a/tests/fsck-tests/011-no-inode-item/default_case.img b/tests/fsck-tests/011-no-inode-item/default_case.img new file mode 100644 index 00000000..352fc021 Binary files /dev/null and b/tests/fsck-tests/011-no-inode-item/default_case.img differ diff --git a/tests/fsck-tests/011-no-rootdir-inode-item.img b/tests/fsck-tests/011-no-rootdir-inode-item.img deleted file mode 100644 index 6b66fdad..00000000 Binary files a/tests/fsck-tests/011-no-rootdir-inode-item.img and /dev/null differ diff --git a/tests/fsck-tests/012-no-inode-item.img b/tests/fsck-tests/012-no-inode-item.img deleted file mode 100644 index 352fc021..00000000 Binary files a/tests/fsck-tests/012-no-inode-item.img and /dev/null differ -- cgit v1.2.3 From a65701b88e2e56d56b1ea7ba7c48019ec7fbbe48 Mon Sep 17 00:00:00 2001 From: Qu Wenruo Date: Thu, 25 Dec 2014 09:32:13 +0800 Subject: btrfs-progs: Move bad root items test cases to its corresponding dir Now 006-bad-root-items has two cases, one for default case, and one for skinny metadata case. Signed-off-by: Qu Wenruo Signed-off-by: David Sterba --- tests/fsck-tests/006-bad-root-items/default_case.tar.xz | Bin 0 -> 24980 bytes tests/fsck-tests/006-bad-root-items/skinny_case.tar.xz | Bin 0 -> 26520 bytes tests/fsck-tests/006-bad-root-items/test.sh | 15 +++++++++++++++ tests/fsck-tests/006-bad_root_items_fs.tar.xz | Bin 24980 -> 0 bytes tests/fsck-tests/007-bad_root_items_fs_skinny.tar.xz | Bin 26520 -> 0 bytes 5 files changed, 15 insertions(+) create mode 100644 tests/fsck-tests/006-bad-root-items/default_case.tar.xz create mode 100644 tests/fsck-tests/006-bad-root-items/skinny_case.tar.xz create mode 100755 tests/fsck-tests/006-bad-root-items/test.sh delete mode 100644 tests/fsck-tests/006-bad_root_items_fs.tar.xz delete mode 100644 tests/fsck-tests/007-bad_root_items_fs_skinny.tar.xz (limited to 'tests') diff --git a/tests/fsck-tests/006-bad-root-items/default_case.tar.xz b/tests/fsck-tests/006-bad-root-items/default_case.tar.xz new file mode 100644 index 00000000..125d8e7d Binary files /dev/null and b/tests/fsck-tests/006-bad-root-items/default_case.tar.xz differ diff --git a/tests/fsck-tests/006-bad-root-items/skinny_case.tar.xz b/tests/fsck-tests/006-bad-root-items/skinny_case.tar.xz new file mode 100644 index 00000000..ed99dc4d Binary files /dev/null and b/tests/fsck-tests/006-bad-root-items/skinny_case.tar.xz differ diff --git a/tests/fsck-tests/006-bad-root-items/test.sh b/tests/fsck-tests/006-bad-root-items/test.sh new file mode 100755 index 00000000..2c0e1c63 --- /dev/null +++ b/tests/fsck-tests/006-bad-root-items/test.sh @@ -0,0 +1,15 @@ +#!/bin/bash + +source $top/tests/common + +echo "extracting image default_case.tar.xz" >> $RESULT +tar xJf default_case.tar.xz || \ + _fail "failed to extract default_case.tar.xz" +check_image test.img + +echo "extracting image skinny_case.tar.xz" >> $RESULT +tar xJf skinny_case.tar.xz || \ + _fail "failed to extract skinny_case.tar.xz" +check_image test.img + +rm test.img diff --git a/tests/fsck-tests/006-bad_root_items_fs.tar.xz b/tests/fsck-tests/006-bad_root_items_fs.tar.xz deleted file mode 100644 index 125d8e7d..00000000 Binary files a/tests/fsck-tests/006-bad_root_items_fs.tar.xz and /dev/null differ diff --git a/tests/fsck-tests/007-bad_root_items_fs_skinny.tar.xz b/tests/fsck-tests/007-bad_root_items_fs_skinny.tar.xz deleted file mode 100644 index ed99dc4d..00000000 Binary files a/tests/fsck-tests/007-bad_root_items_fs_skinny.tar.xz and /dev/null differ -- cgit v1.2.3 From 21afe4a316eb82d437b1cb2b8dab69c8b06a74bf Mon Sep 17 00:00:00 2001 From: Qu Wenruo Date: Thu, 25 Dec 2014 09:32:14 +0800 Subject: btrfs-progs: Move leaf-corruption no extent data case and add verification script Move leaf-corruption type no extent data case to its dir, and add verification script in test.sh The verification script is based on manual btrfs-debug-tree check. The image can also be reused to other leaf-corruption type, like corrupted leaf contains regular file extent data case. Signed-off-by: Qu Wenruo Signed-off-by: David Sterba --- .../012-leaf-corruption/no_data_extent.tar.xz | Bin 0 -> 177600 bytes tests/fsck-tests/012-leaf-corruption/test.sh | 119 +++++++++++++++++++++ .../013-leaf-corruption-no-extent-data.tar.xz | Bin 177600 -> 0 bytes 3 files changed, 119 insertions(+) create mode 100644 tests/fsck-tests/012-leaf-corruption/no_data_extent.tar.xz create mode 100755 tests/fsck-tests/012-leaf-corruption/test.sh delete mode 100644 tests/fsck-tests/013-leaf-corruption-no-extent-data.tar.xz (limited to 'tests') diff --git a/tests/fsck-tests/012-leaf-corruption/no_data_extent.tar.xz b/tests/fsck-tests/012-leaf-corruption/no_data_extent.tar.xz new file mode 100644 index 00000000..cc90b58e Binary files /dev/null and b/tests/fsck-tests/012-leaf-corruption/no_data_extent.tar.xz differ diff --git a/tests/fsck-tests/012-leaf-corruption/test.sh b/tests/fsck-tests/012-leaf-corruption/test.sh new file mode 100755 index 00000000..edf77193 --- /dev/null +++ b/tests/fsck-tests/012-leaf-corruption/test.sh @@ -0,0 +1,119 @@ +#!/bin/bash + +source $top/tests/common + +# Check file list for leaf corruption, no regular/preallocated +# file extent case. +# Corrupted leaf is 20832256, which contains inode 1862~1872 +# +# 1862, ref from leaf 20828160 key 24(DIR_ITEM) +# 1863, ref from leaf 605388 item key 11(DIR_ITEM) +# 1864, no ref to rebuild, no need to rebuild +# 1865, ref from leaf 19767296 key 23(DIR_ITEM) +# 1866-1868 no ref to rebuild, all refs in corrupted leaf +# 1869, ref from leaf 4976640 key 22(DIR_ITEM) +# 1870 no ref to rebuild, all refs in corrupted leaf +# 1871, ref from leaf 19746816 key 38(DIR_ITEM) +# 1872, ref from leaf 19767296 key 14(DIR_ITEM) +# The list format is: +# INO SIZE MODE NAME +# INO: inode number +# SIZE: file size, only checked for regular file +# MODE: raw file mode, get from stat +# NAME: file name +leaf_no_data_ext_list=( + 1862 0 40700 "install.d" + 1862 0 40700 "install.d" + 1863 0 40700 "gdb" + 1865 0 40700 "iptables" + 1869 0 40700 "snmp" + 1871 0 100700 "machine-id" + 1872 0 100700 "adjtime" +) + +generate_leaf_corrupt_no_data_ext() +{ + dest=$1 + echo "generating leaf_corrupt_no_data_ext.btrfs-image" >> $RESULT + tar xJf ./no_data_extent.tar.xz || \ + _fail "failed to extract leaf_corrupt_no_data_ext.btrfs-image" + btrfs-image -r test.img.btrfs-image $dest || \ + _fail "failed to extract leaf_corrupt_no_data_ext.btrfs-image" + + # leaf at 20832256 contains no regular data extent, clear its csum to + # corrupt the leaf. + dd if=/dev/zero of=$dest bs=1 count=32 conv=notrunc seek=20832256 \ + 1>/dev/null 2>&1 +} + +check_inode() +{ + path=$1 + ino=$2 + size=$3 + mode=$4 + name=$5 + + # Check whether the inode exists + exists=$(find $path -inum $ino) + if [ -z "$exists" ]; then + _fail "inode $ino not recovered correctly" + fi + + # Check inode type + found_mode=$(printf "%o" 0x$(stat $exists -c %f)) + if [ $found_mode -ne $mode ]; then + echo "$found_mode" + _fail "inode $ino modes not recovered" + fi + + # Check inode size + found_size=$(stat $exists -c %s) + if [ $mode -ne 41700 -a $found_size -ne $size ]; then + _fail "inode $ino size not recovered correctly" + fi + + # Check inode name + if [ "$(basename $exists)" != "$name" ]; then + _fail "inode $ino name not recovered correctly" + else + return 0 + fi +} + +# Check salvaged data in the recovered image +check_leaf_corrupt_no_data_ext() +{ + image=$1 + if [ $UID -ne 0 ]; then + echo " [NOTRUN] verify recovery. need root privilege" + exit 0 + fi + if [ -z $TEST_MNT ]; then + echo "\$TEST_MNT not set, use $(pwd)/tmp as fallback" + TEST_MNT="$(pwd)/tmp" + fi + mkdir -p $TEST_MNT || _fail "failed to create mount point" + mount $image -o ro $TEST_MNT + + i=0 + while [ $i -lt ${#leaf_no_data_ext_list[@]} ]; do + check_inode $TEST_MNT/lost+found \ + ${leaf_no_data_ext_list[i]} \ + ${leaf_no_data_ext_list[i + 1]} \ + ${leaf_no_data_ext_list[i + 2]} \ + ${leaf_no_data_ext_list[i + 3]} \ + ${leaf_no_data_ext_list[i + 4]} + ((i+=4)) + done + umount $TEST_MNT +} + +generate_leaf_corrupt_no_data_ext test.img +check_image test.img +check_leaf_corrupt_no_data_ext test.img + +rm test.img +rm test.img.btrfs-image +# Not used, its function is the same as generate_leaf_corrupt_no_data_ext() +rm generate_image.sh diff --git a/tests/fsck-tests/013-leaf-corruption-no-extent-data.tar.xz b/tests/fsck-tests/013-leaf-corruption-no-extent-data.tar.xz deleted file mode 100644 index cc90b58e..00000000 Binary files a/tests/fsck-tests/013-leaf-corruption-no-extent-data.tar.xz and /dev/null differ -- cgit v1.2.3 From e6bc739148adf8cd8edd18de7c1e36aad31a6ac6 Mon Sep 17 00:00:00 2001 From: Qu Wenruo Date: Thu, 25 Dec 2014 09:32:15 +0800 Subject: btrfs-progs: Move extent tree rebuild test to its dir Move extent tree rebuild teset to its dir. Signed-off-by: Qu Wenruo Signed-off-by: David Sterba --- tests/fsck-tests.sh | 39 -------------------- tests/fsck-tests/013-extent-tree-rebuild/test.sh | 47 ++++++++++++++++++++++++ 2 files changed, 47 insertions(+), 39 deletions(-) create mode 100755 tests/fsck-tests/013-extent-tree-rebuild/test.sh (limited to 'tests') diff --git a/tests/fsck-tests.sh b/tests/fsck-tests.sh index a992b45b..df214230 100755 --- a/tests/fsck-tests.sh +++ b/tests/fsck-tests.sh @@ -60,42 +60,3 @@ do fi cd $top done - -if [ -z $TEST_DEV ] || [ -z $TEST_MNT ];then - echo " [NOTRUN] extent tree rebuild" - exit 0 -fi - -# test whether fsck can rebuild a corrupted extent tree -test_extent_tree_rebuild() -{ - echo " [TEST] extent tree rebuild" - $top/mkfs.btrfs -f $TEST_DEV >> /dev/null 2>&1 || _fail "fail to mkfs" - - run_check mount $TEST_DEV $TEST_MNT - cp -aR /lib/modules/`uname -r`/ $TEST_MNT 2>&1 - - for i in `seq 1 100`;do - $top/btrfs sub snapshot $TEST_MNT \ - $TEST_MNT/snapaaaaaaa_$i >& /dev/null - done - run_check umount $TEST_DEV - - # get extent root bytenr - extent_root_bytenr=`$top/btrfs-debug-tree -r $TEST_DEV | \ - grep extent | awk '{print $7}'` - if [ -z $extent_root_bytenr ];then - _fail "fail to get extent root bytenr" - fi - - # corrupt extent root node block - run_check $top/btrfs-corrupt-block -l $extent_root_bytenr \ - -b 4096 $TEST_DEV - - $top/btrfs check $TEST_DEV >& /dev/null && \ - _fail "btrfs check should detect failure" - run_check $top/btrfs check --init-extent-tree $TEST_DEV - run_check $top/btrfs check $TEST_DEV -} - -test_extent_tree_rebuild diff --git a/tests/fsck-tests/013-extent-tree-rebuild/test.sh b/tests/fsck-tests/013-extent-tree-rebuild/test.sh new file mode 100755 index 00000000..ce51e07d --- /dev/null +++ b/tests/fsck-tests/013-extent-tree-rebuild/test.sh @@ -0,0 +1,47 @@ +#!/bin/bash + +source $top/tests/common + +if [ -z $TEST_DEV ]; then + echo " [NOTRUN] extent tree rebuild, need TEST_DEV variant" + exit 0 +fi + +if [ -z $TEST_MNT ];then + echo " [NOTRUN] extent tree rebuild, need TEST_MNT variant" + exit 0 +fi + +# test whether fsck can rebuild a corrupted extent tree +test_extent_tree_rebuild() +{ + echo " [TEST] extent tree rebuild" + $top/mkfs.btrfs -f $TEST_DEV >> /dev/null 2>&1 || _fail "fail to mkfs" + + run_check mount $TEST_DEV $TEST_MNT + cp -aR /lib/modules/`uname -r`/ $TEST_MNT 2>&1 + + for i in `seq 1 100`;do + $top/btrfs sub snapshot $TEST_MNT \ + $TEST_MNT/snapaaaaaaa_$i >& /dev/null + done + run_check umount $TEST_DEV + + # get extent root bytenr + extent_root_bytenr=`$top/btrfs-debug-tree -r $TEST_DEV | \ + grep extent | awk '{print $7}'` + if [ -z $extent_root_bytenr ];then + _fail "fail to get extent root bytenr" + fi + + # corrupt extent root node block + run_check $top/btrfs-corrupt-block -l $extent_root_bytenr \ + -b 4096 $TEST_DEV + + $top/btrfs check $TEST_DEV >& /dev/null && \ + _fail "btrfs check should detect failure" + run_check $top/btrfs check --init-extent-tree $TEST_DEV + run_check $top/btrfs check $TEST_DEV +} + +test_extent_tree_rebuild -- cgit v1.2.3 From 522e13d6d92f0083c8739f1137faa40aa98d7b03 Mon Sep 17 00:00:00 2001 From: David Sterba Date: Wed, 14 Jan 2015 18:07:43 +0100 Subject: btrfs-progs: tests, add support for running commands under root Most of the checks run fine without root, but some of them may need to do a mount test or access the data. Add the support to selectively run commands under root, hardcoded to sudo for now. Signed-off-by: David Sterba --- tests/common | 15 +++++++++++++++ 1 file changed, 15 insertions(+) (limited to 'tests') diff --git a/tests/common b/tests/common index 80a53816..84a4b9d3 100644 --- a/tests/common +++ b/tests/common @@ -47,3 +47,18 @@ check_all_images() rm $i.restored done } + +# some tests need to mount the recovered image and do verifications call +# 'setup_root_helper' and then check for have_root_helper == 1 if the test +# needs to fail otherwise; using sudo by default for now +sudo= +have_root_helper=0 +export sudo +export have_root_helper +setup_root_helper() +{ + if [ $UID != 0 ]; then + sudo=sudo + fi + have_root_helper=1 +} -- cgit v1.2.3 From 8fa12c10e79da38c80af20f46a2b5daeab8f1f37 Mon Sep 17 00:00:00 2001 From: David Sterba Date: Wed, 14 Jan 2015 18:13:21 +0100 Subject: btrfs-progs: tests, use the root helper in 012 We need it to mount/umount, to traverse lost+found and stat the results. Signed-off-by: David Sterba --- tests/fsck-tests/012-leaf-corruption/test.sh | 16 +++++++++------- 1 file changed, 9 insertions(+), 7 deletions(-) (limited to 'tests') diff --git a/tests/fsck-tests/012-leaf-corruption/test.sh b/tests/fsck-tests/012-leaf-corruption/test.sh index edf77193..896f717a 100755 --- a/tests/fsck-tests/012-leaf-corruption/test.sh +++ b/tests/fsck-tests/012-leaf-corruption/test.sh @@ -55,20 +55,20 @@ check_inode() name=$5 # Check whether the inode exists - exists=$(find $path -inum $ino) + exists=$($sudo find $path -inum $ino) if [ -z "$exists" ]; then _fail "inode $ino not recovered correctly" fi # Check inode type - found_mode=$(printf "%o" 0x$(stat $exists -c %f)) + found_mode=$(printf "%o" 0x$($sudo stat $exists -c %f)) if [ $found_mode -ne $mode ]; then echo "$found_mode" _fail "inode $ino modes not recovered" fi # Check inode size - found_size=$(stat $exists -c %s) + found_size=$($sudo stat $exists -c %s) if [ $mode -ne 41700 -a $found_size -ne $size ]; then _fail "inode $ino size not recovered correctly" fi @@ -85,8 +85,8 @@ check_inode() check_leaf_corrupt_no_data_ext() { image=$1 - if [ $UID -ne 0 ]; then - echo " [NOTRUN] verify recovery. need root privilege" + if [ $have_root_helper -ne 1 ]; then + echo " [NOTRUN] root privileges needed to verify recovery" exit 0 fi if [ -z $TEST_MNT ]; then @@ -94,7 +94,7 @@ check_leaf_corrupt_no_data_ext() TEST_MNT="$(pwd)/tmp" fi mkdir -p $TEST_MNT || _fail "failed to create mount point" - mount $image -o ro $TEST_MNT + $sudo mount $image -o ro $TEST_MNT i=0 while [ $i -lt ${#leaf_no_data_ext_list[@]} ]; do @@ -106,9 +106,11 @@ check_leaf_corrupt_no_data_ext() ${leaf_no_data_ext_list[i + 4]} ((i+=4)) done - umount $TEST_MNT + $sudo umount $TEST_MNT } +setup_root_helper + generate_leaf_corrupt_no_data_ext test.img check_image test.img check_leaf_corrupt_no_data_ext test.img -- cgit v1.2.3 From ca7b429f263ab19acf606846dd560be7e8519302 Mon Sep 17 00:00:00 2001 From: David Sterba Date: Wed, 14 Jan 2015 18:32:17 +0100 Subject: btrfs-progs: tests, adjust alignment of the pretty command name Signed-off-by: David Sterba --- tests/convert-tests.sh | 2 +- tests/fsck-tests.sh | 2 +- tests/fsck-tests/013-extent-tree-rebuild/test.sh | 4 ++-- 3 files changed, 4 insertions(+), 4 deletions(-) (limited to 'tests') diff --git a/tests/convert-tests.sh b/tests/convert-tests.sh index ed341426..6094287b 100644 --- a/tests/convert-tests.sh +++ b/tests/convert-tests.sh @@ -15,7 +15,7 @@ _fail() rm -f convert-tests-results.txt test(){ - echo " [TEST] $1" + echo " [TEST] $1" shift echo "creating ext image with: $*" >> convert-tests-results.txt # 256MB is the smallest acceptable btrfs image. diff --git a/tests/fsck-tests.sh b/tests/fsck-tests.sh index df214230..54bd3532 100755 --- a/tests/fsck-tests.sh +++ b/tests/fsck-tests.sh @@ -46,7 +46,7 @@ check_prereq btrfs for i in $(find $top/tests/fsck-tests -maxdepth 1 -mindepth 1 -type d | sort) do - echo " [TEST] $(basename $i)" + echo " [TEST] $(basename $i)" cd $i if [ -x test.sh ]; then # Type 2 diff --git a/tests/fsck-tests/013-extent-tree-rebuild/test.sh b/tests/fsck-tests/013-extent-tree-rebuild/test.sh index ce51e07d..0542c279 100755 --- a/tests/fsck-tests/013-extent-tree-rebuild/test.sh +++ b/tests/fsck-tests/013-extent-tree-rebuild/test.sh @@ -3,12 +3,12 @@ source $top/tests/common if [ -z $TEST_DEV ]; then - echo " [NOTRUN] extent tree rebuild, need TEST_DEV variant" + echo " [NOTRUN] extent tree rebuild, need TEST_DEV variant" exit 0 fi if [ -z $TEST_MNT ];then - echo " [NOTRUN] extent tree rebuild, need TEST_MNT variant" + echo " [NOTRUN] extent tree rebuild, need TEST_MNT variant" exit 0 fi -- cgit v1.2.3 From 188e79e2fcac8cdf474d9a23adfcce48e319c745 Mon Sep 17 00:00:00 2001 From: David Sterba Date: Mon, 19 Jan 2015 19:09:28 +0100 Subject: btrfs-progs: tests, use non-interactive sudo helper Sudo may not be configured to run without user prompt, in that case the tests would be stuck. Reported-by: Qu Wenruo Signed-off-by: David Sterba --- tests/common | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) (limited to 'tests') diff --git a/tests/common b/tests/common index 84a4b9d3..d7d2e9be 100644 --- a/tests/common +++ b/tests/common @@ -58,7 +58,7 @@ export have_root_helper setup_root_helper() { if [ $UID != 0 ]; then - sudo=sudo + sudo="sudo --non-interactive" fi have_root_helper=1 } -- cgit v1.2.3 From 8ab2d7a9dd3099c9a5fdc5acd354b57e1039d18a Mon Sep 17 00:00:00 2001 From: Josef Bacik Date: Tue, 13 Jan 2015 15:23:41 -0500 Subject: btrfs-progs: deal with no extent info Previously we used to just set FULL_BACKREF if we couldn't lookup an extent info for an extent. Now we just bail out if we can't lookup the extent info, which is less than good since fsck is supposed to fix these very problems. So instead figure out the flag we are supposed to use and pass that along instead. This patch also provides a test image to test this functionality. Thanks, Signed-off-by: Josef Bacik --- tests/fsck-tests/014-no-extent-info/default_case.img | Bin 0 -> 4096 bytes 1 file changed, 0 insertions(+), 0 deletions(-) create mode 100644 tests/fsck-tests/014-no-extent-info/default_case.img (limited to 'tests') diff --git a/tests/fsck-tests/014-no-extent-info/default_case.img b/tests/fsck-tests/014-no-extent-info/default_case.img new file mode 100644 index 00000000..1ff27434 Binary files /dev/null and b/tests/fsck-tests/014-no-extent-info/default_case.img differ -- cgit v1.2.3 From a624680b0e45e0f7ea1c847f8ccebe04aa52ba75 Mon Sep 17 00:00:00 2001 From: Qu Wenruo Date: Mon, 2 Mar 2015 11:41:50 +0800 Subject: btrfs-progs: fsck-test: Add check_sudo to check valid root/sudo privilege Although fsck-test/012 uses sudo, it uses 'sudo -n', which won't prompt user to input password and will return 1 if no valid credential is found. And this makes test result quite annoying since it fails to mount and still continue, which will always fail. This patch will check 'sudo -v -n' and 'sudo -n true' to determine whether sudo works fine in different version/settings, since in some setting/version, 'sudo -v -n' will fail even the user is set NOPASSWD. Also, remove the 'have_root_helper' variant, since there is a possibility that sudo credential will timeout during the test and 'have_root_helper' won't help to detect such problem. New '_sudo' command will do credential check if needed to avoid such problem. Signed-off-by: Qu Wenruo Signed-off-by: David Sterba --- tests/common | 50 ++++++++++++++++++++++++---- tests/fsck-tests/012-leaf-corruption/test.sh | 14 +++----- 2 files changed, 48 insertions(+), 16 deletions(-) (limited to 'tests') diff --git a/tests/common b/tests/common index d7d2e9be..ccdadd5f 100644 --- a/tests/common +++ b/tests/common @@ -9,6 +9,12 @@ _fail() exit 1 } +_not_run() +{ + echo " [NOTRUN] $*" + exit 0 +} + run_check() { echo "############### $@" >> $RESULT 2>&1 @@ -51,14 +57,44 @@ check_all_images() # some tests need to mount the recovered image and do verifications call # 'setup_root_helper' and then check for have_root_helper == 1 if the test # needs to fail otherwise; using sudo by default for now -sudo= -have_root_helper=0 -export sudo -export have_root_helper +_sudo= +need_validate=-1 +export _sudo +export need_validate +root_helper() +{ + if [ $UID -eq 0 ]; then + $* + else + if [ $need_validate -eq 1 ]; then + sudo -v -n &> /dev/null || \ + _not_run "Need validate sudo credential" + sudo -n $* + elif [ $need_validate -eq 0 ]; then + sudo -n true &> /dev/null || \ + _not_run "Need validate sudo user setting" + sudo -n $* + else + # should not happen + _not_run "Need validate root privilege" + fi + fi +} + setup_root_helper() { - if [ $UID != 0 ]; then - sudo="sudo --non-interactive" + if [ $UID -eq 0 ]; then + return + fi + # Test for old sudo or special setting, which makes sudo -v fails even + # user is set NOPASSWD + sudo -n true &> /dev/null && need_validate=0 + + # Newer sudo or default sudo setting + sudo -v -n &> /dev/null && need_validate=1 + + if [ $need_validate -eq -1 ]; then + _not_run "Need validate root privilege" fi - have_root_helper=1 + _sudo=root_helper } diff --git a/tests/fsck-tests/012-leaf-corruption/test.sh b/tests/fsck-tests/012-leaf-corruption/test.sh index 896f717a..5873e3fb 100755 --- a/tests/fsck-tests/012-leaf-corruption/test.sh +++ b/tests/fsck-tests/012-leaf-corruption/test.sh @@ -55,20 +55,20 @@ check_inode() name=$5 # Check whether the inode exists - exists=$($sudo find $path -inum $ino) + exists=$($_sudo find $path -inum $ino) if [ -z "$exists" ]; then _fail "inode $ino not recovered correctly" fi # Check inode type - found_mode=$(printf "%o" 0x$($sudo stat $exists -c %f)) + found_mode=$(printf "%o" 0x$($_sudo stat $exists -c %f)) if [ $found_mode -ne $mode ]; then echo "$found_mode" _fail "inode $ino modes not recovered" fi # Check inode size - found_size=$($sudo stat $exists -c %s) + found_size=$($_sudo stat $exists -c %s) if [ $mode -ne 41700 -a $found_size -ne $size ]; then _fail "inode $ino size not recovered correctly" fi @@ -85,16 +85,12 @@ check_inode() check_leaf_corrupt_no_data_ext() { image=$1 - if [ $have_root_helper -ne 1 ]; then - echo " [NOTRUN] root privileges needed to verify recovery" - exit 0 - fi if [ -z $TEST_MNT ]; then echo "\$TEST_MNT not set, use $(pwd)/tmp as fallback" TEST_MNT="$(pwd)/tmp" fi mkdir -p $TEST_MNT || _fail "failed to create mount point" - $sudo mount $image -o ro $TEST_MNT + $_sudo mount $image -o ro $TEST_MNT i=0 while [ $i -lt ${#leaf_no_data_ext_list[@]} ]; do @@ -106,7 +102,7 @@ check_leaf_corrupt_no_data_ext() ${leaf_no_data_ext_list[i + 4]} ((i+=4)) done - $sudo umount $TEST_MNT + $_sudo umount $TEST_MNT } setup_root_helper -- cgit v1.2.3 From 02e1c10e28b34c3c702a2a218e2a7148124e7425 Mon Sep 17 00:00:00 2001 From: David Sterba Date: Mon, 9 Mar 2015 12:30:26 +0100 Subject: btrfs-progs: tests, clean up scripts Rename variables, use caps, call true by full path, add quotation to variables and a few wording fixes. Signed-off-by: David Sterba --- tests/common | 43 ++++++++++++++-------------- tests/fsck-tests/012-leaf-corruption/test.sh | 10 +++---- 2 files changed, 27 insertions(+), 26 deletions(-) (limited to 'tests') diff --git a/tests/common b/tests/common index ccdadd5f..a35d438e 100644 --- a/tests/common +++ b/tests/common @@ -57,26 +57,26 @@ check_all_images() # some tests need to mount the recovered image and do verifications call # 'setup_root_helper' and then check for have_root_helper == 1 if the test # needs to fail otherwise; using sudo by default for now -_sudo= -need_validate=-1 -export _sudo -export need_validate +SUDO_HELPER= +NEED_SUDO_VALIDATE=unknown +export SUDO_HELPER +export NEED_SUDO_VALIDATE root_helper() { if [ $UID -eq 0 ]; then - $* + "$@" else - if [ $need_validate -eq 1 ]; then - sudo -v -n &> /dev/null || \ - _not_run "Need validate sudo credential" - sudo -n $* - elif [ $need_validate -eq 0 ]; then - sudo -n true &> /dev/null || \ - _not_run "Need validate sudo user setting" - sudo -n $* + if [ "$NEED_SUDO_VALIDATE" = 'yes' ]; then + sudo -v -n &>/dev/null || \ + _not_run "Need to validate sudo credentials" + sudo -n "$@" + elif [ "$NEED_SUDO_VALIDATE" = 'no' ]; then + sudo -n /bin/true &> /dev/null || \ + _not_run "Need to validate sudo user settings" + sudo -n "$@" else # should not happen - _not_run "Need validate root privilege" + _not_run "Need to validate root privileges" fi fi } @@ -86,15 +86,16 @@ setup_root_helper() if [ $UID -eq 0 ]; then return fi - # Test for old sudo or special setting, which makes sudo -v fails even - # user is set NOPASSWD - sudo -n true &> /dev/null && need_validate=0 + + # Test for old sudo or special settings, which make sudo -v fail even + # if user setting is NOPASSWD + sudo -n /bin/true &>/dev/null && NEED_SUDO_VALIDATE=no # Newer sudo or default sudo setting - sudo -v -n &> /dev/null && need_validate=1 + sudo -v -n &>/dev/null && NEED_SUDO_VALIDATE=yes - if [ $need_validate -eq -1 ]; then - _not_run "Need validate root privilege" + if [ "$NEED_SUDO_VALIDATE" = 'yes' ]; then + _not_run "Need to validate root privileges" fi - _sudo=root_helper + SUDO_HELPER=root_helper } diff --git a/tests/fsck-tests/012-leaf-corruption/test.sh b/tests/fsck-tests/012-leaf-corruption/test.sh index 5873e3fb..8f82fd16 100755 --- a/tests/fsck-tests/012-leaf-corruption/test.sh +++ b/tests/fsck-tests/012-leaf-corruption/test.sh @@ -55,20 +55,20 @@ check_inode() name=$5 # Check whether the inode exists - exists=$($_sudo find $path -inum $ino) + exists=$($SUDO_HELPER find $path -inum $ino) if [ -z "$exists" ]; then _fail "inode $ino not recovered correctly" fi # Check inode type - found_mode=$(printf "%o" 0x$($_sudo stat $exists -c %f)) + found_mode=$(printf "%o" 0x$($SUDO_HELPER stat $exists -c %f)) if [ $found_mode -ne $mode ]; then echo "$found_mode" _fail "inode $ino modes not recovered" fi # Check inode size - found_size=$($_sudo stat $exists -c %s) + found_size=$($SUDO_HELPER stat $exists -c %s) if [ $mode -ne 41700 -a $found_size -ne $size ]; then _fail "inode $ino size not recovered correctly" fi @@ -90,7 +90,7 @@ check_leaf_corrupt_no_data_ext() TEST_MNT="$(pwd)/tmp" fi mkdir -p $TEST_MNT || _fail "failed to create mount point" - $_sudo mount $image -o ro $TEST_MNT + $SUDO_HELPER mount $image -o ro $TEST_MNT i=0 while [ $i -lt ${#leaf_no_data_ext_list[@]} ]; do @@ -102,7 +102,7 @@ check_leaf_corrupt_no_data_ext() ${leaf_no_data_ext_list[i + 4]} ((i+=4)) done - $_sudo umount $TEST_MNT + $SUDO_HELPER umount $TEST_MNT } setup_root_helper -- cgit v1.2.3 From c392c2b5afa3373a078c16c680b101b8acdf1384 Mon Sep 17 00:00:00 2001 From: David Sterba Date: Tue, 10 Mar 2015 14:11:18 +0100 Subject: btrfs-progs: tests, common: fix typo after cleanup The previous value for unknown was -1. Reported-by: Qu Wenruo Signed-off-by: David Sterba --- tests/common | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) (limited to 'tests') diff --git a/tests/common b/tests/common index a35d438e..91a73e1b 100644 --- a/tests/common +++ b/tests/common @@ -94,7 +94,7 @@ setup_root_helper() # Newer sudo or default sudo setting sudo -v -n &>/dev/null && NEED_SUDO_VALIDATE=yes - if [ "$NEED_SUDO_VALIDATE" = 'yes' ]; then + if [ "$NEED_SUDO_VALIDATE" = 'unknown' ]; then _not_run "Need to validate root privileges" fi SUDO_HELPER=root_helper -- cgit v1.2.3 From 362936b03e61e9d68ef9c6620b1d1dd1fdbcf705 Mon Sep 17 00:00:00 2001 From: Sebastian Thorarensen Date: Fri, 20 Mar 2015 02:11:29 +0100 Subject: btrfs-progs: Add nodesize test for btrfs-convert convert-tests now test both 4096 and 16384 nodesizes. Signed-off-by: Sebastian Thorarensen Signed-off-by: David Sterba --- tests/convert-tests.sh | 15 ++++++++++----- 1 file changed, 10 insertions(+), 5 deletions(-) (limited to 'tests') diff --git a/tests/convert-tests.sh b/tests/convert-tests.sh index 6094287b..3d912f34 100644 --- a/tests/convert-tests.sh +++ b/tests/convert-tests.sh @@ -16,7 +16,8 @@ rm -f convert-tests-results.txt test(){ echo " [TEST] $1" - shift + nodesize=$2 + shift 2 echo "creating ext image with: $*" >> convert-tests-results.txt # 256MB is the smallest acceptable btrfs image. rm -f $here/test.img >> convert-tests-results.txt 2>&1 \ @@ -25,13 +26,17 @@ test(){ || _fail "could not create test image file" $* -F $here/test.img >> convert-tests-results.txt 2>&1 \ || _fail "filesystem create failed" - $here/btrfs-convert $here/test.img >> convert-tests-results.txt 2>&1 \ + $here/btrfs-convert -N "$nodesize" $here/test.img \ + >> convert-tests-results.txt 2>&1 \ || _fail "btrfs-convert failed" $here/btrfs check $here/test.img >> convert-tests-results.txt 2>&1 \ || _fail "btrfs check detected errors" } # btrfs-convert requires 4k blocksize. -test "ext2" mke2fs -b 4096 -test "ext3" mke2fs -j -b 4096 -test "ext4" mke2fs -t ext4 -b 4096 +test "ext2 4k nodesize" 4096 mke2fs -b 4096 +test "ext3 4k nodesize" 4096 mke2fs -j -b 4096 +test "ext4 4k nodesize" 4096 mke2fs -t ext4 -b 4096 +test "ext2 16k nodesize" 16384 mke2fs -b 4096 +test "ext3 16k nodesize" 16384 mke2fs -j -b 4096 +test "ext4 16k nodesize" 16384 mke2fs -t ext4 -b 4096 -- cgit v1.2.3 From d738c3d292135342c094c32d0ec03eed23842213 Mon Sep 17 00:00:00 2001 From: David Sterba Date: Mon, 23 Mar 2015 16:57:03 +0100 Subject: btrfs-progs: convert tests: add remaining supported nodesizes That's 8k, 32k and 64k. Signed-off-by: David Sterba --- tests/convert-tests.sh | 9 +++++++++ 1 file changed, 9 insertions(+) (limited to 'tests') diff --git a/tests/convert-tests.sh b/tests/convert-tests.sh index 3d912f34..f6b919d2 100644 --- a/tests/convert-tests.sh +++ b/tests/convert-tests.sh @@ -37,6 +37,15 @@ test(){ test "ext2 4k nodesize" 4096 mke2fs -b 4096 test "ext3 4k nodesize" 4096 mke2fs -j -b 4096 test "ext4 4k nodesize" 4096 mke2fs -t ext4 -b 4096 +test "ext2 8k nodesize" 8192 mke2fs -b 4096 +test "ext3 8k nodesize" 8192 mke2fs -j -b 4096 +test "ext4 8k nodesize" 8192 mke2fs -t ext4 -b 4096 test "ext2 16k nodesize" 16384 mke2fs -b 4096 test "ext3 16k nodesize" 16384 mke2fs -j -b 4096 test "ext4 16k nodesize" 16384 mke2fs -t ext4 -b 4096 +test "ext2 32k nodesize" 32768 mke2fs -b 4096 +test "ext3 32k nodesize" 32768 mke2fs -j -b 4096 +test "ext4 32k nodesize" 32768 mke2fs -t ext4 -b 4096 +test "ext2 64k nodesize" 65536 mke2fs -b 4096 +test "ext3 64k nodesize" 65536 mke2fs -j -b 4096 +test "ext4 64k nodesize" 65536 mke2fs -t ext4 -b 4096 -- cgit v1.2.3 From 8720e15cd1dc3993729141f54d2c6301cce4415a Mon Sep 17 00:00:00 2001 From: Qu Wenruo Date: Fri, 3 Apr 2015 15:01:12 +0800 Subject: btrfs-progs: test-frame: Update variant names Use upper case variant name for the following variants: 1) top -> TOP 2) script_dir -> SCRIPT_DIR And change the following variant name: 1) RESULT -> RESULTS Signed-off-by: Qu Wenruo Signed-off-by: David Sterba --- tests/common | 20 ++++++++++---------- tests/fsck-tests.sh | 24 ++++++++++++------------ tests/fsck-tests/006-bad-root-items/test.sh | 6 +++--- tests/fsck-tests/012-leaf-corruption/test.sh | 4 ++-- tests/fsck-tests/013-extent-tree-rebuild/test.sh | 16 ++++++++-------- 5 files changed, 35 insertions(+), 35 deletions(-) (limited to 'tests') diff --git a/tests/common b/tests/common index 91a73e1b..94cf913c 100644 --- a/tests/common +++ b/tests/common @@ -5,7 +5,7 @@ _fail() { - echo "$*" | tee -a $RESULT + echo "$*" | tee -a $RESULTS exit 1 } @@ -17,13 +17,13 @@ _not_run() run_check() { - echo "############### $@" >> $RESULT 2>&1 - "$@" >> $RESULT 2>&1 || _fail "failed: $@" + echo "############### $@" >> $RESULTS 2>&1 + "$@" >> $RESULTS 2>&1 || _fail "failed: $@" } check_prereq() { - if ! [ -f $top/$1 ]; then + if ! [ -f $TOP/$1 ]; then _fail "Failed prerequisities: $1"; fi } @@ -31,12 +31,12 @@ check_prereq() check_image() { image=$1 - echo "testing image $(basename $image)" >> $RESULT - $top/btrfs check $image >> $RESULT 2>&1 + echo "testing image $(basename $image)" >> $RESULTS + $TOP/btrfs check $image >> $RESULTS 2>&1 [ $? -eq 0 ] && _fail "btrfs check should have detected corruption" - run_check $top/btrfs check --repair $image - run_check $top/btrfs check $image + run_check $TOP/btrfs check --repair $image + run_check $TOP/btrfs check $image } check_all_images() @@ -44,8 +44,8 @@ check_all_images() dir=$1 for i in $(find $dir -iname '*.img') do - echo "extracting image $(basename $i)" >> $RESULT - $top/btrfs-image -r $i $i.restored || \ + echo "extracting image $(basename $i)" >> $RESULTS + $TOP/btrfs-image -r $i $i.restored || \ _fail "failed to extract image $i" check_image $i.restored diff --git a/tests/fsck-tests.sh b/tests/fsck-tests.sh index 54bd3532..046b33de 100755 --- a/tests/fsck-tests.sh +++ b/tests/fsck-tests.sh @@ -5,25 +5,25 @@ # It's GPL, same as everything else in this tree. # -unset top +unset TOP unset LANG LANG=C -script_dir=$(dirname $(realpath $0)) -top=$(realpath $script_dir/../) +SCRIPT_DIR=$(dirname $(realpath $0)) +TOP=$(realpath $SCRIPT_DIR/../) TEST_DEV=${TEST_DEV:-} -TEST_MNT=${TEST_MNT:-$top/tests/mnt} -RESULT="$top/tests/fsck-tests-results.txt" +TEST_MNT=${TEST_MNT:-$TOP/tests/mnt} +RESULTS="$TOP/tests/fsck-tests-results.txt" -source $top/tests/common +source $TOP/tests/common -# Allow child test to use $top and $RESULT -export top -export RESULT +# Allow child test to use $TOP and $RESULTS +export TOP +export RESULTS # For custom script needs to verfiy recovery export TEST_MNT export LANG -rm -f $RESULT +rm -f $RESULTS mkdir -p $TEST_MNT || _fail "unable to create mount point on $TEST_MNT" # test rely on corrupting blocks tool @@ -44,7 +44,7 @@ check_prereq btrfs # This is for case btrfs-image can't dump or case needs extra # check/verify -for i in $(find $top/tests/fsck-tests -maxdepth 1 -mindepth 1 -type d | sort) +for i in $(find $TOP/tests/fsck-tests -maxdepth 1 -mindepth 1 -type d | sort) do echo " [TEST] $(basename $i)" cd $i @@ -58,5 +58,5 @@ do # Type 1 check_all_images `pwd` fi - cd $top + cd $TOP done diff --git a/tests/fsck-tests/006-bad-root-items/test.sh b/tests/fsck-tests/006-bad-root-items/test.sh index 2c0e1c63..bfbfcfcc 100755 --- a/tests/fsck-tests/006-bad-root-items/test.sh +++ b/tests/fsck-tests/006-bad-root-items/test.sh @@ -1,13 +1,13 @@ #!/bin/bash -source $top/tests/common +source $TOP/tests/common -echo "extracting image default_case.tar.xz" >> $RESULT +echo "extracting image default_case.tar.xz" >> $RESULTS tar xJf default_case.tar.xz || \ _fail "failed to extract default_case.tar.xz" check_image test.img -echo "extracting image skinny_case.tar.xz" >> $RESULT +echo "extracting image skinny_case.tar.xz" >> $RESULTS tar xJf skinny_case.tar.xz || \ _fail "failed to extract skinny_case.tar.xz" check_image test.img diff --git a/tests/fsck-tests/012-leaf-corruption/test.sh b/tests/fsck-tests/012-leaf-corruption/test.sh index 8f82fd16..fe5c2260 100755 --- a/tests/fsck-tests/012-leaf-corruption/test.sh +++ b/tests/fsck-tests/012-leaf-corruption/test.sh @@ -1,6 +1,6 @@ #!/bin/bash -source $top/tests/common +source $TOP/tests/common # Check file list for leaf corruption, no regular/preallocated # file extent case. @@ -34,7 +34,7 @@ leaf_no_data_ext_list=( generate_leaf_corrupt_no_data_ext() { dest=$1 - echo "generating leaf_corrupt_no_data_ext.btrfs-image" >> $RESULT + echo "generating leaf_corrupt_no_data_ext.btrfs-image" >> $RESULTS tar xJf ./no_data_extent.tar.xz || \ _fail "failed to extract leaf_corrupt_no_data_ext.btrfs-image" btrfs-image -r test.img.btrfs-image $dest || \ diff --git a/tests/fsck-tests/013-extent-tree-rebuild/test.sh b/tests/fsck-tests/013-extent-tree-rebuild/test.sh index 0542c279..cde97db3 100755 --- a/tests/fsck-tests/013-extent-tree-rebuild/test.sh +++ b/tests/fsck-tests/013-extent-tree-rebuild/test.sh @@ -1,6 +1,6 @@ #!/bin/bash -source $top/tests/common +source $TOP/tests/common if [ -z $TEST_DEV ]; then echo " [NOTRUN] extent tree rebuild, need TEST_DEV variant" @@ -16,32 +16,32 @@ fi test_extent_tree_rebuild() { echo " [TEST] extent tree rebuild" - $top/mkfs.btrfs -f $TEST_DEV >> /dev/null 2>&1 || _fail "fail to mkfs" + $TOP/mkfs.btrfs -f $TEST_DEV >> /dev/null 2>&1 || _fail "fail to mkfs" run_check mount $TEST_DEV $TEST_MNT cp -aR /lib/modules/`uname -r`/ $TEST_MNT 2>&1 for i in `seq 1 100`;do - $top/btrfs sub snapshot $TEST_MNT \ + $TOP/btrfs sub snapshot $TEST_MNT \ $TEST_MNT/snapaaaaaaa_$i >& /dev/null done run_check umount $TEST_DEV # get extent root bytenr - extent_root_bytenr=`$top/btrfs-debug-tree -r $TEST_DEV | \ + extent_root_bytenr=`$TOP/btrfs-debug-tree -r $TEST_DEV | \ grep extent | awk '{print $7}'` if [ -z $extent_root_bytenr ];then _fail "fail to get extent root bytenr" fi # corrupt extent root node block - run_check $top/btrfs-corrupt-block -l $extent_root_bytenr \ + run_check $TOP/btrfs-corrupt-block -l $extent_root_bytenr \ -b 4096 $TEST_DEV - $top/btrfs check $TEST_DEV >& /dev/null && \ + $TOP/btrfs check $TEST_DEV >& /dev/null && \ _fail "btrfs check should detect failure" - run_check $top/btrfs check --init-extent-tree $TEST_DEV - run_check $top/btrfs check $TEST_DEV + run_check $TOP/btrfs check --init-extent-tree $TEST_DEV + run_check $TOP/btrfs check $TEST_DEV } test_extent_tree_rebuild -- cgit v1.2.3 From 74dc9d82af372aff660dd3165617e9e1bc521e96 Mon Sep 17 00:00:00 2001 From: Qu Wenruo Date: Fri, 3 Apr 2015 15:01:13 +0800 Subject: btrfs-progs: fsck-tests: Remove duplicatesd TEST_MNT setup. Since we have already had TEST_MNT fallback setup to $TOP/tests/mnt, just remove duplicated setting in 012-leaf-corruption/test.sh Signed-off-by: Qu Wenruo Signed-off-by: David Sterba --- tests/fsck-tests/012-leaf-corruption/test.sh | 4 ---- 1 file changed, 4 deletions(-) (limited to 'tests') diff --git a/tests/fsck-tests/012-leaf-corruption/test.sh b/tests/fsck-tests/012-leaf-corruption/test.sh index fe5c2260..4db47101 100755 --- a/tests/fsck-tests/012-leaf-corruption/test.sh +++ b/tests/fsck-tests/012-leaf-corruption/test.sh @@ -85,10 +85,6 @@ check_inode() check_leaf_corrupt_no_data_ext() { image=$1 - if [ -z $TEST_MNT ]; then - echo "\$TEST_MNT not set, use $(pwd)/tmp as fallback" - TEST_MNT="$(pwd)/tmp" - fi mkdir -p $TEST_MNT || _fail "failed to create mount point" $SUDO_HELPER mount $image -o ro $TEST_MNT -- cgit v1.2.3 From 691695fe342688a2c85735ad556d3bf5a82ffc0c Mon Sep 17 00:00:00 2001 From: Qu Wenruo Date: Fri, 3 Apr 2015 15:01:14 +0800 Subject: btrfs-progs: fsck-tests: Update 013-extent-tree-rebuild to use more test framework infrastructure. Update 013-extent-tree-rebuild to use more framework infrastructure, including: 1) Use run_check other than open-coded redirect 2) Add root privillege 3) Add dependency on 'btrfs-debug-tree' command Signed-off-by: Qu Wenruo Signed-off-by: David Sterba --- tests/fsck-tests/013-extent-tree-rebuild/test.sh | 25 +++++++++++++----------- 1 file changed, 14 insertions(+), 11 deletions(-) (limited to 'tests') diff --git a/tests/fsck-tests/013-extent-tree-rebuild/test.sh b/tests/fsck-tests/013-extent-tree-rebuild/test.sh index cde97db3..7453ed7c 100755 --- a/tests/fsck-tests/013-extent-tree-rebuild/test.sh +++ b/tests/fsck-tests/013-extent-tree-rebuild/test.sh @@ -2,6 +2,9 @@ source $TOP/tests/common +check_prereq btrfs-debug-tree +setup_root_helper + if [ -z $TEST_DEV ]; then echo " [NOTRUN] extent tree rebuild, need TEST_DEV variant" exit 0 @@ -16,32 +19,32 @@ fi test_extent_tree_rebuild() { echo " [TEST] extent tree rebuild" - $TOP/mkfs.btrfs -f $TEST_DEV >> /dev/null 2>&1 || _fail "fail to mkfs" + run_check $SUDO_HELPER $TOP/mkfs.btrfs -f $TEST_DEV - run_check mount $TEST_DEV $TEST_MNT - cp -aR /lib/modules/`uname -r`/ $TEST_MNT 2>&1 + run_check $SUDO_HELPER mount $TEST_DEV $TEST_MNT + run_check $SUDO_HELPER cp -aR /lib/modules/`uname -r`/ $TEST_MNT for i in `seq 1 100`;do - $TOP/btrfs sub snapshot $TEST_MNT \ - $TEST_MNT/snapaaaaaaa_$i >& /dev/null + run_check $SUDO_HELPER $TOP/btrfs sub snapshot $TEST_MNT \ + $TEST_MNT/snapaaaaaaa_$i done - run_check umount $TEST_DEV + run_check $SUDO_HELPER umount $TEST_DEV # get extent root bytenr - extent_root_bytenr=`$TOP/btrfs-debug-tree -r $TEST_DEV | \ + extent_root_bytenr=`$SUDO_HELPER $TOP/btrfs-debug-tree -r $TEST_DEV | \ grep extent | awk '{print $7}'` if [ -z $extent_root_bytenr ];then _fail "fail to get extent root bytenr" fi # corrupt extent root node block - run_check $TOP/btrfs-corrupt-block -l $extent_root_bytenr \ + run_check $SUDO_HELPER $TOP/btrfs-corrupt-block -l $extent_root_bytenr \ -b 4096 $TEST_DEV - $TOP/btrfs check $TEST_DEV >& /dev/null && \ + $SUDO_HELPER $TOP/btrfs check $TEST_DEV >& /dev/null && \ _fail "btrfs check should detect failure" - run_check $TOP/btrfs check --init-extent-tree $TEST_DEV - run_check $TOP/btrfs check $TEST_DEV + run_check $SUDO_HELPER $TOP/btrfs check --init-extent-tree $TEST_DEV + run_check $SUDO_HELPER $TOP/btrfs check $TEST_DEV } test_extent_tree_rebuild -- cgit v1.2.3 From a18f8b1665b7218f853ce527cf765f5697a4654c Mon Sep 17 00:00:00 2001 From: Qu Wenruo Date: Fri, 3 Apr 2015 15:01:15 +0800 Subject: btrfs-progs: fsck-tests: Add fallback TEST_DEV for test case 013 Add fallback TEST_DEV for test case 013. Fallback to $TOP/tests/test.img. Now all test cases of btrfs-progs need no extra setting except sudo. Signed-off-by: Qu Wenruo Signed-off-by: David Sterba --- tests/fsck-tests/013-extent-tree-rebuild/test.sh | 9 +++++++-- 1 file changed, 7 insertions(+), 2 deletions(-) (limited to 'tests') diff --git a/tests/fsck-tests/013-extent-tree-rebuild/test.sh b/tests/fsck-tests/013-extent-tree-rebuild/test.sh index 7453ed7c..e05a035f 100755 --- a/tests/fsck-tests/013-extent-tree-rebuild/test.sh +++ b/tests/fsck-tests/013-extent-tree-rebuild/test.sh @@ -6,8 +6,13 @@ check_prereq btrfs-debug-tree setup_root_helper if [ -z $TEST_DEV ]; then - echo " [NOTRUN] extent tree rebuild, need TEST_DEV variant" - exit 0 + echo "\$TEST_DEV not given, use $TOP/test/test.img as fallback" >> \ + $RESULTS + TEST_DEV="$TOP/tests/test.img" + + # Need at least 1G to avoid mixed block group, which extent tree + # rebuild doesn't support. + run_check truncate -s 1G $TEST_DEV fi if [ -z $TEST_MNT ];then -- cgit v1.2.3 From 0d9bbdc5e32bdaf5666c6a8be8782840dd481c2b Mon Sep 17 00:00:00 2001 From: Qu Wenruo Date: Fri, 3 Apr 2015 15:01:16 +0800 Subject: btrfs-progs: convert-tests: Update to use test framework infrastructure. Also change the test() to convert_test(), to avoid conflict name with bash test function. Signed-off-by: Qu Wenruo Signed-off-by: David Sterba --- tests/convert-tests.sh | 68 ++++++++++++++++++++++++-------------------------- 1 file changed, 33 insertions(+), 35 deletions(-) (limited to 'tests') diff --git a/tests/convert-tests.sh b/tests/convert-tests.sh index f6b919d2..7652a6ca 100644 --- a/tests/convert-tests.sh +++ b/tests/convert-tests.sh @@ -4,48 +4,46 @@ # clean. # -here=`pwd` +unset TOP +unset LANG +LANG=C +SCRIPT_DIR=$(dirname $(realpath $0)) +TOP=$(realpath $SCRIPT_DIR/../) +TEST_DEV=${TEST_DEV:-} +TEST_MNT=${TEST_MNT:-$TOP/tests/mnt} +RESULTS="$TOP/tests/convert-tests-results.txt" +IMAGE="$TOP/tests/test.img" -_fail() -{ - echo "$*" | tee -a convert-tests-results.txt - exit 1 -} +source $TOP/tests/common -rm -f convert-tests-results.txt +rm -f $RESULTS -test(){ +convert_test() { echo " [TEST] $1" nodesize=$2 shift 2 - echo "creating ext image with: $*" >> convert-tests-results.txt + echo "creating ext image with: $*" >> $RESULTS # 256MB is the smallest acceptable btrfs image. - rm -f $here/test.img >> convert-tests-results.txt 2>&1 \ - || _fail "could not remove test image file" - truncate -s 256M $here/test.img >> convert-tests-results.txt 2>&1 \ - || _fail "could not create test image file" - $* -F $here/test.img >> convert-tests-results.txt 2>&1 \ - || _fail "filesystem create failed" - $here/btrfs-convert -N "$nodesize" $here/test.img \ - >> convert-tests-results.txt 2>&1 \ - || _fail "btrfs-convert failed" - $here/btrfs check $here/test.img >> convert-tests-results.txt 2>&1 \ - || _fail "btrfs check detected errors" + run_check rm -f $IMAGE + run_check truncate -s 256M $IMAGE + run_check $* -F $IMAGE + run_check $TOP/btrfs-convert -N "$nodesize" $IMAGE + run_check $TOP/btrfs check $IMAGE } # btrfs-convert requires 4k blocksize. -test "ext2 4k nodesize" 4096 mke2fs -b 4096 -test "ext3 4k nodesize" 4096 mke2fs -j -b 4096 -test "ext4 4k nodesize" 4096 mke2fs -t ext4 -b 4096 -test "ext2 8k nodesize" 8192 mke2fs -b 4096 -test "ext3 8k nodesize" 8192 mke2fs -j -b 4096 -test "ext4 8k nodesize" 8192 mke2fs -t ext4 -b 4096 -test "ext2 16k nodesize" 16384 mke2fs -b 4096 -test "ext3 16k nodesize" 16384 mke2fs -j -b 4096 -test "ext4 16k nodesize" 16384 mke2fs -t ext4 -b 4096 -test "ext2 32k nodesize" 32768 mke2fs -b 4096 -test "ext3 32k nodesize" 32768 mke2fs -j -b 4096 -test "ext4 32k nodesize" 32768 mke2fs -t ext4 -b 4096 -test "ext2 64k nodesize" 65536 mke2fs -b 4096 -test "ext3 64k nodesize" 65536 mke2fs -j -b 4096 -test "ext4 64k nodesize" 65536 mke2fs -t ext4 -b 4096 +convert_test "ext2 4k nodesize" 4096 mke2fs -b 4096 +convert_test "ext3 4k nodesize" 4096 mke2fs -j -b 4096 +convert_test "ext4 4k nodesize" 4096 mke2fs -t ext4 -b 4096 +convert_test "ext2 8k nodesize" 8192 mke2fs -b 4096 +convert_test "ext3 8k nodesize" 8192 mke2fs -j -b 4096 +convert_test "ext4 8k nodesize" 8192 mke2fs -t ext4 -b 4096 +convert_test "ext2 16k nodesize" 16384 mke2fs -b 4096 +convert_test "ext3 16k nodesize" 16384 mke2fs -j -b 4096 +convert_test "ext4 16k nodesize" 16384 mke2fs -t ext4 -b 4096 +convert_test "ext2 32k nodesize" 32768 mke2fs -b 4096 +convert_test "ext3 32k nodesize" 32768 mke2fs -j -b 4096 +convert_test "ext4 32k nodesize" 32768 mke2fs -t ext4 -b 4096 +convert_test "ext2 64k nodesize" 65536 mke2fs -b 4096 +convert_test "ext3 64k nodesize" 65536 mke2fs -j -b 4096 +convert_test "ext4 64k nodesize" 65536 mke2fs -t ext4 -b 4096 -- cgit v1.2.3 From 45678c3048a1d74b99303763cea0729fe5df798b Mon Sep 17 00:00:00 2001 From: Qu Wenruo Date: Fri, 3 Apr 2015 15:01:17 +0800 Subject: btrfs-progs: convert-tests: Add check for converted btrfs with regular file extent. Regression test for previous patch "btrfs-progs: convert: Make ext*_image file obey datacsum setting." Signed-off-by: Qu Wenruo Signed-off-by: David Sterba --- tests/convert-tests.sh | 10 +++++++++- 1 file changed, 9 insertions(+), 1 deletion(-) (limited to 'tests') diff --git a/tests/convert-tests.sh b/tests/convert-tests.sh index 7652a6ca..42cbeb60 100644 --- a/tests/convert-tests.sh +++ b/tests/convert-tests.sh @@ -9,7 +9,6 @@ unset LANG LANG=C SCRIPT_DIR=$(dirname $(realpath $0)) TOP=$(realpath $SCRIPT_DIR/../) -TEST_DEV=${TEST_DEV:-} TEST_MNT=${TEST_MNT:-$TOP/tests/mnt} RESULTS="$TOP/tests/convert-tests-results.txt" IMAGE="$TOP/tests/test.img" @@ -18,6 +17,8 @@ source $TOP/tests/common rm -f $RESULTS +setup_root_helper + convert_test() { echo " [TEST] $1" nodesize=$2 @@ -27,6 +28,13 @@ convert_test() { run_check rm -f $IMAGE run_check truncate -s 256M $IMAGE run_check $* -F $IMAGE + + # create a file to check btrfs-convert can convert regular file + # correct + run_check $SUDO_HELPER mount $IMAGE $TEST_MNT + run_check $SUDO_HELPER dd if=/dev/zero of=$TEST_MNT/test bs=$nodesize \ + count=1 1>/dev/null 2>&1 + run_check $SUDO_HELPER umount $TEST_MNT run_check $TOP/btrfs-convert -N "$nodesize" $IMAGE run_check $TOP/btrfs check $IMAGE } -- cgit v1.2.3 From 35d53302ac961d8d7706318f9d6d12282f712703 Mon Sep 17 00:00:00 2001 From: David Sterba Date: Tue, 7 Apr 2015 18:09:18 +0200 Subject: btrfs-progs: convert tests: preserve test image permissions If the test image is eg. on NFS it's not writable for root, so chmod 0777 fixes that but then we must not delete the file. Signed-off-by: David Sterba --- tests/convert-tests.sh | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-) (limited to 'tests') diff --git a/tests/convert-tests.sh b/tests/convert-tests.sh index 42cbeb60..7976f662 100644 --- a/tests/convert-tests.sh +++ b/tests/convert-tests.sh @@ -24,8 +24,10 @@ convert_test() { nodesize=$2 shift 2 echo "creating ext image with: $*" >> $RESULTS + # IMAGE not removed as the file might have special permissions, eg. + # when test image is on NFS and would not be writable for root + run_check truncate -s 0 $IMAGE # 256MB is the smallest acceptable btrfs image. - run_check rm -f $IMAGE run_check truncate -s 256M $IMAGE run_check $* -F $IMAGE -- cgit v1.2.3 From 047dd1bf5d6c7d8cb92e2d94d1f4eca15f14152b Mon Sep 17 00:00:00 2001 From: David Sterba Date: Tue, 7 Apr 2015 18:29:05 +0200 Subject: btrfs-progs: tests: split make rule for fsck and convert tests, fix prerequisities We'd like to run each class of tests separately. There were some missing prerequisities that should be/are verified by the tests, makefile rules have been synced. Signed-off-by: David Sterba --- tests/fsck-tests/013-extent-tree-rebuild/test.sh | 1 + 1 file changed, 1 insertion(+) (limited to 'tests') diff --git a/tests/fsck-tests/013-extent-tree-rebuild/test.sh b/tests/fsck-tests/013-extent-tree-rebuild/test.sh index e05a035f..9b291dd7 100755 --- a/tests/fsck-tests/013-extent-tree-rebuild/test.sh +++ b/tests/fsck-tests/013-extent-tree-rebuild/test.sh @@ -3,6 +3,7 @@ source $TOP/tests/common check_prereq btrfs-debug-tree +check_prereq mkfs.btrfs setup_root_helper if [ -z $TEST_DEV ]; then -- cgit v1.2.3 From 54d316b5ecb1be4e7ae18160bb23c139b84951be Mon Sep 17 00:00:00 2001 From: David Sterba Date: Tue, 7 Apr 2015 18:34:00 +0200 Subject: btrfs-progs: tests: remove duplicate output for fsck test 013 The test name is logged since it lives in it's own directory. Signed-off-by: David Sterba --- tests/fsck-tests/013-extent-tree-rebuild/test.sh | 1 - 1 file changed, 1 deletion(-) (limited to 'tests') diff --git a/tests/fsck-tests/013-extent-tree-rebuild/test.sh b/tests/fsck-tests/013-extent-tree-rebuild/test.sh index 9b291dd7..3290cd72 100755 --- a/tests/fsck-tests/013-extent-tree-rebuild/test.sh +++ b/tests/fsck-tests/013-extent-tree-rebuild/test.sh @@ -24,7 +24,6 @@ fi # test whether fsck can rebuild a corrupted extent tree test_extent_tree_rebuild() { - echo " [TEST] extent tree rebuild" run_check $SUDO_HELPER $TOP/mkfs.btrfs -f $TEST_DEV run_check $SUDO_HELPER mount $TEST_DEV $TEST_MNT -- cgit v1.2.3 From c5b2f66d634741ec04c028106bce647701cb8944 Mon Sep 17 00:00:00 2001 From: WorMzy Tykashi Date: Wed, 8 Apr 2015 15:50:04 +0100 Subject: btrfs-progs: use local btrfs-image in leaf corruption test Currently this test uses the system btrfs-image. If there isn't a btrfs-image on $PATH, the test fails. The test should be using the locally compiled btrfs-image, not the system one. Signed-off-by: WorMzy Tykashi Reviewed-by: Qu Wenruo Signed-off-by: David Sterba --- tests/fsck-tests/012-leaf-corruption/test.sh | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) (limited to 'tests') diff --git a/tests/fsck-tests/012-leaf-corruption/test.sh b/tests/fsck-tests/012-leaf-corruption/test.sh index 4db47101..98e31856 100755 --- a/tests/fsck-tests/012-leaf-corruption/test.sh +++ b/tests/fsck-tests/012-leaf-corruption/test.sh @@ -37,7 +37,7 @@ generate_leaf_corrupt_no_data_ext() echo "generating leaf_corrupt_no_data_ext.btrfs-image" >> $RESULTS tar xJf ./no_data_extent.tar.xz || \ _fail "failed to extract leaf_corrupt_no_data_ext.btrfs-image" - btrfs-image -r test.img.btrfs-image $dest || \ + $TOP/btrfs-image -r test.img.btrfs-image $dest || \ _fail "failed to extract leaf_corrupt_no_data_ext.btrfs-image" # leaf at 20832256 contains no regular data extent, clear its csum to -- cgit v1.2.3 From 7c6801606e11a4664c0a2a195a1422cb86fe7dad Mon Sep 17 00:00:00 2001 From: David Sterba Date: Thu, 21 May 2015 15:04:29 +0200 Subject: btrfs-progs: tests: log the test name in results file Signed-off-by: David Sterba --- tests/fsck-tests.sh | 1 + 1 file changed, 1 insertion(+) (limited to 'tests') diff --git a/tests/fsck-tests.sh b/tests/fsck-tests.sh index 046b33de..fff1b421 100755 --- a/tests/fsck-tests.sh +++ b/tests/fsck-tests.sh @@ -48,6 +48,7 @@ for i in $(find $TOP/tests/fsck-tests -maxdepth 1 -mindepth 1 -type d | sort) do echo " [TEST] $(basename $i)" cd $i + echo "=== Entering $i" >> $RESULTS if [ -x test.sh ]; then # Type 2 ./test.sh -- cgit v1.2.3 From d6cedbcdd334174468f6f8815fb030b90704df74 Mon Sep 17 00:00:00 2001 From: David Sterba Date: Thu, 21 May 2015 16:33:16 +0200 Subject: btrfs-progs: tests: support more formats of test images We're using he meta-dump images, now we support compressed meta-dump, raw and compressed raw images. Signed-off-by: David Sterba --- tests/common | 47 +++++++++++++++++++++++++++++++++++++++++------ 1 file changed, 41 insertions(+), 6 deletions(-) (limited to 'tests') diff --git a/tests/common b/tests/common index 94cf913c..e02359c7 100644 --- a/tests/common +++ b/tests/common @@ -30,6 +30,8 @@ check_prereq() check_image() { + local image + image=$1 echo "testing image $(basename $image)" >> $RESULTS $TOP/btrfs check $image >> $RESULTS 2>&1 @@ -39,18 +41,51 @@ check_image() run_check $TOP/btrfs check $image } +# Process all image dumps in a given directory, +# - raw btrfs filesystem images, suffix .raw +# - dtto compressed by XZ, suffix .raw.xz +# - meta-dump images with suffix .img +# - dtto compressed by XZ, suffix .img.xz check_all_images() { dir=$1 - for i in $(find $dir -iname '*.img') + for image in $(find $dir \( -iname '*.img' -o \ + -iname '*.img.xz' -o \ + -iname '*.raw' -o \ + -iname '*.raw.xz' \) ) do - echo "extracting image $(basename $i)" >> $RESULTS - $TOP/btrfs-image -r $i $i.restored || \ - _fail "failed to extract image $i" + cleanme= + case "$image" in + *.img) + rm -f $image.restored + : ;; + *.img.xz) + xz --decompress --keep "$image" || \ + _fail "failed to decompress image $image" + image=${image%%.xz} + rm -f $image.restored + cleanme=$image + ;; + *.raw) + cp --sparse=auto $image $image.restored + ;; + *.raw.xz) + xz --decompress --keep "$image" || \ + _fail "failed to decompress image $image" + image=${image%%.xz} + mv "$image" "$image".restored + ;; + esac + + if ! [ -f $image.restored ]; then + echo "restoring image $(basename $image)" >> $RESULTS + $TOP/btrfs-image -r $image $image.restored || \ + _fail "failed to restore image $image" + fi - check_image $i.restored + check_image $image.restored - rm $i.restored + rm -f $image.restored $cleanme done } -- cgit v1.2.3 From 9e3e423d688b5c825db83efd9c6ac5aa0355be55 Mon Sep 17 00:00:00 2001 From: David Sterba Date: Thu, 21 May 2015 18:48:55 +0200 Subject: btrfs-progs: tests: use readlink -f to resolve path The utility 'realpath' from coreutils is new enough to be missing on my "old" reference build host. Signed-off-by: David Sterba --- tests/convert-tests.sh | 4 ++-- tests/fsck-tests.sh | 4 ++-- 2 files changed, 4 insertions(+), 4 deletions(-) (limited to 'tests') diff --git a/tests/convert-tests.sh b/tests/convert-tests.sh index 7976f662..9234c7ba 100644 --- a/tests/convert-tests.sh +++ b/tests/convert-tests.sh @@ -7,8 +7,8 @@ unset TOP unset LANG LANG=C -SCRIPT_DIR=$(dirname $(realpath $0)) -TOP=$(realpath $SCRIPT_DIR/../) +SCRIPT_DIR=$(dirname $(readlink -f $0)) +TOP=$(readlink -f $SCRIPT_DIR/../) TEST_MNT=${TEST_MNT:-$TOP/tests/mnt} RESULTS="$TOP/tests/convert-tests-results.txt" IMAGE="$TOP/tests/test.img" diff --git a/tests/fsck-tests.sh b/tests/fsck-tests.sh index fff1b421..b0ded6ae 100755 --- a/tests/fsck-tests.sh +++ b/tests/fsck-tests.sh @@ -8,8 +8,8 @@ unset TOP unset LANG LANG=C -SCRIPT_DIR=$(dirname $(realpath $0)) -TOP=$(realpath $SCRIPT_DIR/../) +SCRIPT_DIR=$(dirname $(readlink -f $0)) +TOP=$(readlink -f $SCRIPT_DIR/../) TEST_DEV=${TEST_DEV:-} TEST_MNT=${TEST_MNT:-$TOP/tests/mnt} RESULTS="$TOP/tests/fsck-tests-results.txt" -- cgit v1.2.3 From e413938ea986092222be56fabf83c8cde86d4b48 Mon Sep 17 00:00:00 2001 From: David Sterba Date: Mon, 25 May 2015 15:35:58 +0200 Subject: btrfs-progs: tests: sort image files If a test has several images let filenames enforce a particular order of checks if desired. Signed-off-by: David Sterba --- tests/common | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) (limited to 'tests') diff --git a/tests/common b/tests/common index e02359c7..e690c85a 100644 --- a/tests/common +++ b/tests/common @@ -52,7 +52,7 @@ check_all_images() for image in $(find $dir \( -iname '*.img' -o \ -iname '*.img.xz' -o \ -iname '*.raw' -o \ - -iname '*.raw.xz' \) ) + -iname '*.raw.xz' \) | sort) do cleanme= case "$image" in -- cgit v1.2.3 From 1497c92e67233d7c467eb94203add879662272fd Mon Sep 17 00:00:00 2001 From: David Sterba Date: Mon, 25 May 2015 15:39:29 +0200 Subject: btrfs-progs: test: 015-check-bad-memory-access Crafted images may trigger out-of-bounds access during check, fixed by "btrfs-progs: Enhance read_tree_block to avoid memory corruption" Now adding image for the first one, the other need enhancements in the testing framework. Reference: https://bugzilla.kernel.org/show_bug.cgi?id=97171 Reference: https://bugzilla.kernel.org/show_bug.cgi?id=97191 Reference: https://bugzilla.kernel.org/show_bug.cgi?id=97271 Signed-off-by: David Sterba --- .../bko-97171-btrfs-image.raw.txt | 254 +++++++++++++++++++++ .../bko-97171-btrfs-image.raw.xz | Bin 0 -> 6748 bytes 2 files changed, 254 insertions(+) create mode 100644 tests/fsck-tests/015-check-bad-memory-access/bko-97171-btrfs-image.raw.txt create mode 100644 tests/fsck-tests/015-check-bad-memory-access/bko-97171-btrfs-image.raw.xz (limited to 'tests') diff --git a/tests/fsck-tests/015-check-bad-memory-access/bko-97171-btrfs-image.raw.txt b/tests/fsck-tests/015-check-bad-memory-access/bko-97171-btrfs-image.raw.txt new file mode 100644 index 00000000..9685ed46 --- /dev/null +++ b/tests/fsck-tests/015-check-bad-memory-access/bko-97171-btrfs-image.raw.txt @@ -0,0 +1,254 @@ +URL: https://bugzilla.kernel.org/show_bug.cgi?id=97171 + +The btrfs-image attached to this bug causes the btrfs-userland tool to use +uninitialized memory and ultimately overwrite what seems to be arbitrary memory +locations, dying in the process. Reproduced on x86-64 and i686. + +The kernel seems to be less affected and fails to mount the image. If +/usr/sbin/btrfs is not setuid (which it probably never is), things should be +safe. I didn't investigate further though. + +gdb output: + +GNU gdb (GDB) Fedora 7.8.2-38.fc21 +[... lots of other errors...] +Ignoring transid failure +root 5 inode 260 errors 1000, some csum missing + unresolved ref dir 256 index 7 namelen 5 name b.bin filetype 1 errors 2, no dir index + unresolved ref dir 256 index 7 namelen 5 name b.fin filetype 1 errors 5, no dir item, no inode ref +root 5 inode 261 errors 200, dir isize wrong + +Program received signal SIGSEGV, Segmentation fault. +0x000000000089bb70 in ?? () +(gdb) bt +#0 0x000000000089bb70 in ?? () +#1 0x00007fffffffdb50 in ?? () +#2 0x0000000000894b20 in ?? () +#3 0x00000032629b88e0 in _IO_2_1_stdout_ () from /lib64/libc.so.6 +#4 0x000000000088c010 in ?? () +#5 0x0000000000000000 in ?? () + + +valgrind output: + +[...lots of errors...] +==12638== Conditional jump or move depends on uninitialised value(s) +==12638== at 0x436E77: check_block.part.14 (ctree.c:548) +==12638== by 0x438954: UnknownInlinedFun (kerncompat.h:91) +==12638== by 0x438954: btrfs_search_slot (ctree.c:1120) +==12638== by 0x40DD1F: count_csum_range (cmds-check.c:1419) +==12638== by 0x40DD1F: process_file_extent (cmds-check.c:1551) +==12638== by 0x40DD1F: process_one_leaf (cmds-check.c:1617) +==12638== by 0x40DD1F: walk_down_tree (cmds-check.c:1742) +==12638== by 0x40DD1F: check_fs_root (cmds-check.c:3380) +==12638== by 0x40DD1F: check_fs_roots.isra.51 (cmds-check.c:3516) +==12638== by 0x4C64B0F: ??? +==12638== by 0x4C30A2F: ??? +==12638== by 0x4C468CF: ??? +==12638== by 0x32629B88DF: ??? (in /usr/lib64/libc-2.20.so) +==12638== by 0x4C3657F: ??? +==12638== +==12638== Conditional jump or move depends on uninitialised value(s) +==12638== at 0x4A0B0E7: memcpy@@GLIBC_2.14 (in /usr/lib64/valgrind/vgpreload_memcheck-amd64-linux.so) +==12638== by 0x436E99: UnknownInlinedFun (ctree.h:1613) +==12638== by 0x436E99: check_block.part.14 (ctree.c:550) +==12638== by 0x438954: UnknownInlinedFun (kerncompat.h:91) +==12638== by 0x438954: btrfs_search_slot (ctree.c:1120) +==12638== by 0x40DD1F: count_csum_range (cmds-check.c:1419) +==12638== by 0x40DD1F: process_file_extent (cmds-check.c:1551) +==12638== by 0x40DD1F: process_one_leaf (cmds-check.c:1617) +==12638== by 0x40DD1F: walk_down_tree (cmds-check.c:1742) +==12638== by 0x40DD1F: check_fs_root (cmds-check.c:3380) +==12638== by 0x40DD1F: check_fs_roots.isra.51 (cmds-check.c:3516) +==12638== by 0x4C64B0F: ??? +==12638== by 0x4C30A2F: ??? +==12638== by 0x4C468CF: ??? +==12638== by 0x32629B88DF: ??? (in /usr/lib64/libc-2.20.so) +==12638== by 0x4C3657F: ??? +==12638== +==12638== Conditional jump or move depends on uninitialised value(s) +==12638== at 0x4A0B2AC: memcpy@@GLIBC_2.14 (in /usr/lib64/valgrind/vgpreload_memcheck-amd64-linux.so) +==12638== by 0x436E99: UnknownInlinedFun (ctree.h:1613) +==12638== by 0x436E99: check_block.part.14 (ctree.c:550) +==12638== by 0x438954: UnknownInlinedFun (kerncompat.h:91) +==12638== by 0x438954: btrfs_search_slot (ctree.c:1120) +==12638== by 0x40DD1F: count_csum_range (cmds-check.c:1419) +==12638== by 0x40DD1F: process_file_extent (cmds-check.c:1551) +==12638== by 0x40DD1F: process_one_leaf (cmds-check.c:1617) +==12638== by 0x40DD1F: walk_down_tree (cmds-check.c:1742) +==12638== by 0x40DD1F: check_fs_root (cmds-check.c:3380) +==12638== by 0x40DD1F: check_fs_roots.isra.51 (cmds-check.c:3516) +==12638== by 0x4C64B0F: ??? +==12638== by 0x4C30A2F: ??? +==12638== by 0x4C468CF: ??? +==12638== by 0x32629B88DF: ??? (in /usr/lib64/libc-2.20.so) +==12638== by 0x4C3657F: ??? +==12638== +==12638== Conditional jump or move depends on uninitialised value(s) +==12638== at 0x4A0B151: memcpy@@GLIBC_2.14 (in /usr/lib64/valgrind/vgpreload_memcheck-amd64-linux.so) +==12638== by 0x436E99: UnknownInlinedFun (ctree.h:1613) +==12638== by 0x436E99: check_block.part.14 (ctree.c:550) +==12638== by 0x438954: UnknownInlinedFun (kerncompat.h:91) +==12638== by 0x438954: btrfs_search_slot (ctree.c:1120) +==12638== by 0x40DD1F: count_csum_range (cmds-check.c:1419) +==12638== by 0x40DD1F: process_file_extent (cmds-check.c:1551) +==12638== by 0x40DD1F: process_one_leaf (cmds-check.c:1617) +==12638== by 0x40DD1F: walk_down_tree (cmds-check.c:1742) +==12638== by 0x40DD1F: check_fs_root (cmds-check.c:3380) +==12638== by 0x40DD1F: check_fs_roots.isra.51 (cmds-check.c:3516) +==12638== by 0x4C64B0F: ??? +==12638== by 0x4C30A2F: ??? +==12638== by 0x4C468CF: ??? +==12638== by 0x32629B88DF: ??? (in /usr/lib64/libc-2.20.so) +==12638== by 0x4C3657F: ??? +==12638== +==12638== Conditional jump or move depends on uninitialised value(s) +==12638== at 0x4A0B162: memcpy@@GLIBC_2.14 (in /usr/lib64/valgrind/vgpreload_memcheck-amd64-linux.so) +==12638== by 0x436E99: UnknownInlinedFun (ctree.h:1613) +==12638== by 0x436E99: check_block.part.14 (ctree.c:550) +==12638== by 0x438954: UnknownInlinedFun (kerncompat.h:91) +==12638== by 0x438954: btrfs_search_slot (ctree.c:1120) +==12638== by 0x40DD1F: count_csum_range (cmds-check.c:1419) +==12638== by 0x40DD1F: process_file_extent (cmds-check.c:1551) +==12638== by 0x40DD1F: process_one_leaf (cmds-check.c:1617) +==12638== by 0x40DD1F: walk_down_tree (cmds-check.c:1742) +==12638== by 0x40DD1F: check_fs_root (cmds-check.c:3380) +==12638== by 0x40DD1F: check_fs_roots.isra.51 (cmds-check.c:3516) +==12638== by 0x4C64B0F: ??? +==12638== by 0x4C30A2F: ??? +==12638== by 0x4C468CF: ??? +==12638== by 0x32629B88DF: ??? (in /usr/lib64/libc-2.20.so) +==12638== by 0x4C3657F: ??? +==12638== +==12638== Conditional jump or move depends on uninitialised value(s) +==12638== at 0x4A0B176: memcpy@@GLIBC_2.14 (in /usr/lib64/valgrind/vgpreload_memcheck-amd64-linux.so) +==12638== by 0x436E99: UnknownInlinedFun (ctree.h:1613) +==12638== by 0x436E99: check_block.part.14 (ctree.c:550) +==12638== by 0x438954: UnknownInlinedFun (kerncompat.h:91) +==12638== by 0x438954: btrfs_search_slot (ctree.c:1120) +==12638== by 0x40DD1F: count_csum_range (cmds-check.c:1419) +==12638== by 0x40DD1F: process_file_extent (cmds-check.c:1551) +==12638== by 0x40DD1F: process_one_leaf (cmds-check.c:1617) +==12638== by 0x40DD1F: walk_down_tree (cmds-check.c:1742) +==12638== by 0x40DD1F: check_fs_root (cmds-check.c:3380) +==12638== by 0x40DD1F: check_fs_roots.isra.51 (cmds-check.c:3516) +==12638== by 0x4C64B0F: ??? +==12638== by 0x4C30A2F: ??? +==12638== by 0x4C468CF: ??? +==12638== by 0x32629B88DF: ??? (in /usr/lib64/libc-2.20.so) +==12638== by 0x4C3657F: ??? +==12638== +==12638== Conditional jump or move depends on uninitialised value(s) +==12638== at 0x4A0B2CE: memcpy@@GLIBC_2.14 (in /usr/lib64/valgrind/vgpreload_memcheck-amd64-linux.so) +==12638== by 0x436E99: UnknownInlinedFun (ctree.h:1613) +==12638== by 0x436E99: check_block.part.14 (ctree.c:550) +==12638== by 0x438954: UnknownInlinedFun (kerncompat.h:91) +==12638== by 0x438954: btrfs_search_slot (ctree.c:1120) +==12638== by 0x40DD1F: count_csum_range (cmds-check.c:1419) +==12638== by 0x40DD1F: process_file_extent (cmds-check.c:1551) +==12638== by 0x40DD1F: process_one_leaf (cmds-check.c:1617) +==12638== by 0x40DD1F: walk_down_tree (cmds-check.c:1742) +==12638== by 0x40DD1F: check_fs_root (cmds-check.c:3380) +==12638== by 0x40DD1F: check_fs_roots.isra.51 (cmds-check.c:3516) +==12638== by 0x4C64B0F: ??? +==12638== by 0x4C30A2F: ??? +==12638== by 0x4C468CF: ??? +==12638== by 0x32629B88DF: ??? (in /usr/lib64/libc-2.20.so) +==12638== by 0x4C3657F: ??? +==12638== +==12638== Conditional jump or move depends on uninitialised value(s) +==12638== at 0x4A0B34A: memcpy@@GLIBC_2.14 (in /usr/lib64/valgrind/vgpreload_memcheck-amd64-linux.so) +==12638== by 0x436E99: UnknownInlinedFun (ctree.h:1613) +==12638== by 0x436E99: check_block.part.14 (ctree.c:550) +==12638== by 0x438954: UnknownInlinedFun (kerncompat.h:91) +==12638== by 0x438954: btrfs_search_slot (ctree.c:1120) +==12638== by 0x40DD1F: count_csum_range (cmds-check.c:1419) +==12638== by 0x40DD1F: process_file_extent (cmds-check.c:1551) +==12638== by 0x40DD1F: process_one_leaf (cmds-check.c:1617) +==12638== by 0x40DD1F: walk_down_tree (cmds-check.c:1742) +==12638== by 0x40DD1F: check_fs_root (cmds-check.c:3380) +==12638== by 0x40DD1F: check_fs_roots.isra.51 (cmds-check.c:3516) +==12638== by 0x4C64B0F: ??? +==12638== by 0x4C30A2F: ??? +==12638== by 0x4C468CF: ??? +==12638== by 0x32629B88DF: ??? (in /usr/lib64/libc-2.20.so) +==12638== by 0x4C3657F: ??? +==12638== +==12638== Use of uninitialised value of size 8 +==12638== at 0x4A0B3A0: memcpy@@GLIBC_2.14 (in /usr/lib64/valgrind/vgpreload_memcheck-amd64-linux.so) +==12638== by 0x436E99: UnknownInlinedFun (ctree.h:1613) +==12638== by 0x436E99: check_block.part.14 (ctree.c:550) +==12638== by 0x438954: UnknownInlinedFun (kerncompat.h:91) +==12638== by 0x438954: btrfs_search_slot (ctree.c:1120) +==12638== by 0x40DD1F: count_csum_range (cmds-check.c:1419) +==12638== by 0x40DD1F: process_file_extent (cmds-check.c:1551) +==12638== by 0x40DD1F: process_one_leaf (cmds-check.c:1617) +==12638== by 0x40DD1F: walk_down_tree (cmds-check.c:1742) +==12638== by 0x40DD1F: check_fs_root (cmds-check.c:3380) +==12638== by 0x40DD1F: check_fs_roots.isra.51 (cmds-check.c:3516) +==12638== by 0x4C64B0F: ??? +==12638== by 0x4C30A2F: ??? +==12638== by 0x4C468CF: ??? +==12638== by 0x32629B88DF: ??? (in /usr/lib64/libc-2.20.so) +==12638== by 0x4C3657F: ??? +==12638== +==12638== Invalid read of size 1 +==12638== at 0x4A0B3A0: memcpy@@GLIBC_2.14 (in /usr/lib64/valgrind/vgpreload_memcheck-amd64-linux.so) +==12638== by 0x436E99: UnknownInlinedFun (ctree.h:1613) +==12638== by 0x436E99: check_block.part.14 (ctree.c:550) +==12638== by 0x438954: UnknownInlinedFun (kerncompat.h:91) +==12638== by 0x438954: btrfs_search_slot (ctree.c:1120) +==12638== by 0x40DD1F: count_csum_range (cmds-check.c:1419) +==12638== by 0x40DD1F: process_file_extent (cmds-check.c:1551) +==12638== by 0x40DD1F: process_one_leaf (cmds-check.c:1617) +==12638== by 0x40DD1F: walk_down_tree (cmds-check.c:1742) +==12638== by 0x40DD1F: check_fs_root (cmds-check.c:3380) +==12638== by 0x40DD1F: check_fs_roots.isra.51 (cmds-check.c:3516) +==12638== by 0x4C64B0F: ??? +==12638== by 0x4C30A2F: ??? +==12638== by 0x4C468CF: ??? +==12638== by 0x32629B88DF: ??? (in /usr/lib64/libc-2.20.so) +==12638== by 0x4C3657F: ??? +==12638== Address 0xa25c9de9 is not stack'd, malloc'd or (recently) free'd +==12638== +==12638== +==12638== Process terminating with default action of signal 11 (SIGSEGV) +==12638== Access not within mapped region at address 0xA25C9DE9 +==12638== at 0x4A0B3A0: memcpy@@GLIBC_2.14 (in /usr/lib64/valgrind/vgpreload_memcheck-amd64-linux.so) +==12638== by 0x436E99: UnknownInlinedFun (ctree.h:1613) +==12638== by 0x436E99: check_block.part.14 (ctree.c:550) +==12638== by 0x438954: UnknownInlinedFun (kerncompat.h:91) +==12638== by 0x438954: btrfs_search_slot (ctree.c:1120) +==12638== by 0x40DD1F: count_csum_range (cmds-check.c:1419) +==12638== by 0x40DD1F: process_file_extent (cmds-check.c:1551) +==12638== by 0x40DD1F: process_one_leaf (cmds-check.c:1617) +==12638== by 0x40DD1F: walk_down_tree (cmds-check.c:1742) +==12638== by 0x40DD1F: check_fs_root (cmds-check.c:3380) +==12638== by 0x40DD1F: check_fs_roots.isra.51 (cmds-check.c:3516) +==12638== by 0x4C64B0F: ??? +==12638== by 0x4C30A2F: ??? +==12638== by 0x4C468CF: ??? +==12638== by 0x32629B88DF: ??? (in /usr/lib64/libc-2.20.so) +==12638== by 0x4C3657F: ??? +==12638== If you believe this happened as a result of a stack +==12638== overflow in your program's main thread (unlikely but +==12638== possible), you can try to increase the size of the +==12638== main thread stack using the --main-stacksize= flag. +==12638== The main thread stack size used in this run was 8388608. +==12638== +==12638== HEAP SUMMARY: +==12638== in use at exit: 46,260 bytes in 56 blocks +==12638== total heap usage: 380 allocs, 324 frees, 218,054 bytes allocated +==12638== +==12638== LEAK SUMMARY: +==12638== definitely lost: 272 bytes in 2 blocks +==12638== indirectly lost: 800 bytes in 8 blocks +==12638== possibly lost: 88 bytes in 1 blocks +==12638== still reachable: 45,100 bytes in 45 blocks +==12638== suppressed: 0 bytes in 0 blocks +==12638== Rerun with --leak-check=full to see details of leaked memory +==12638== +==12638== For counts of detected and suppressed errors, rerun with: -v +==12638== Use --track-origins=yes to see where uninitialised values come from +==12638== ERROR SUMMARY: 10 errors from 10 contexts (suppressed: 0 from 0) +[1] 12638 segmentation fault valgrind btrfs check btrfs_fukked_memorycorruption.bin diff --git a/tests/fsck-tests/015-check-bad-memory-access/bko-97171-btrfs-image.raw.xz b/tests/fsck-tests/015-check-bad-memory-access/bko-97171-btrfs-image.raw.xz new file mode 100644 index 00000000..f3f0944d Binary files /dev/null and b/tests/fsck-tests/015-check-bad-memory-access/bko-97171-btrfs-image.raw.xz differ -- cgit v1.2.3 From b51cc1d32555082d02a68d946cbbed0983f82270 Mon Sep 17 00:00:00 2001 From: David Sterba Date: Mon, 25 May 2015 16:08:46 +0200 Subject: btrfs-progs: tests: add script to clean intermediate images Signed-off-by: David Sterba --- tests/clean-tests.sh | 19 +++++++++++++++++++ 1 file changed, 19 insertions(+) create mode 100755 tests/clean-tests.sh (limited to 'tests') diff --git a/tests/clean-tests.sh b/tests/clean-tests.sh new file mode 100755 index 00000000..c1dc56af --- /dev/null +++ b/tests/clean-tests.sh @@ -0,0 +1,19 @@ +#!/bin/sh +# remove all intermediate files from tests + +if [ "$BUILD_VERBOSE" = 1 ]; then + verbose=-print +fi + +SCRIPT_DIR=$(dirname $(readlink -f $0)) +TOP=$(readlink -f $SCRIPT_DIR/../) + +if ! cd $TOP/tests; then + echo "ERROR: cannot cd to $TOP/tests" + exit 1 +fi + +find fsck-tests -type f -name '*.restored' $verbose -delete + +# do not remove, the file could have special permissions set +echo -n > test.img -- cgit v1.2.3 From 10b6b0b3a8288ed825d003788d9ff5d657f2e404 Mon Sep 17 00:00:00 2001 From: David Sterba Date: Tue, 2 Jun 2015 15:00:32 +0200 Subject: btrfs-progs: tests: add driver script for misc tests Signed-off-by: David Sterba --- tests/misc-tests.sh | 47 +++++++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 47 insertions(+) create mode 100755 tests/misc-tests.sh (limited to 'tests') diff --git a/tests/misc-tests.sh b/tests/misc-tests.sh new file mode 100755 index 00000000..5bbe9140 --- /dev/null +++ b/tests/misc-tests.sh @@ -0,0 +1,47 @@ +#!/bin/bash +# +# Misc tests + +unset TOP +unset LANG +LANG=C +SCRIPT_DIR=$(dirname $(readlink -f $0)) +TOP=$(readlink -f $SCRIPT_DIR/../) +TEST_DEV=${TEST_DEV:-} +TEST_MNT=${TEST_MNT:-$TOP/tests/mnt} +RESULTS="$TOP/tests/misc-tests-results.txt" +IMAGE="$TOP/tests/test.img" + +source $TOP/tests/common + +# Allow child test to use $TOP and $RESULTS +export TOP +export RESULTS +# For custom script needs to verfiy recovery +export TEST_MNT +export LANG + +rm -f $RESULTS +mkdir -p $TEST_MNT || _fail "unable to create mount point on $TEST_MNT" + +# test rely on corrupting blocks tool +check_prereq btrfs-corrupt-block +check_prereq btrfs-image +check_prereq btrfstune +check_prereq btrfs + +# The tests are driven by their custom script called 'test.sh' + +for i in $(find $TOP/tests/misc-tests -maxdepth 1 -mindepth 1 -type d | sort) +do + echo " [TEST] $(basename $i)" + cd $i + echo "=== Entering $i" >> $RESULTS + if [ -x test.sh ]; then + ./test.sh + if [ $? -ne 0 ]; then + _fail "test failed for case $(basename $i)" + fi + fi + cd $TOP +done -- cgit v1.2.3 From cf3d13132b92abd9e149f905b06d7a6b61a5d72b Mon Sep 17 00:00:00 2001 From: David Sterba Date: Tue, 2 Jun 2015 15:57:51 +0200 Subject: btrfs-progs: tests: common: add helper run_check_stdout Sometimes we need to process the output of the command, but run_check captures all the output into results file. Signed-off-by: David Sterba --- tests/common | 8 ++++++++ 1 file changed, 8 insertions(+) (limited to 'tests') diff --git a/tests/common b/tests/common index e690c85a..899ec7b1 100644 --- a/tests/common +++ b/tests/common @@ -21,6 +21,14 @@ run_check() "$@" >> $RESULTS 2>&1 || _fail "failed: $@" } +# same as run_check but the stderr+stdout output is duplicated on stdout and +# can be processed further +run_check_stdout() +{ + echo "############### $@" >> $RESULTS 2>&1 + "$@" 2>&1 | tee -a $RESULTS || _fail "failed: $@" +} + check_prereq() { if ! [ -f $TOP/$1 ]; then -- cgit v1.2.3 From 1e9a6b698479ad759270270d585a5af36253cc30 Mon Sep 17 00:00:00 2001 From: David Sterba Date: Tue, 2 Jun 2015 16:37:20 +0200 Subject: btrfs-progs: tests: add misc test for fs features A sample test for the misc-test category. Verify that btrfstune sets the requested fs features. Now implemented extrefs, skinny-metadata and seeding. Signed-off-by: David Sterba --- tests/misc-tests/001-btrfstune-features/test.sh | 56 +++++++++++++++++++++++++ 1 file changed, 56 insertions(+) create mode 100755 tests/misc-tests/001-btrfstune-features/test.sh (limited to 'tests') diff --git a/tests/misc-tests/001-btrfstune-features/test.sh b/tests/misc-tests/001-btrfstune-features/test.sh new file mode 100755 index 00000000..4ce3411f --- /dev/null +++ b/tests/misc-tests/001-btrfstune-features/test.sh @@ -0,0 +1,56 @@ +#!/bin/bash +# test btrfstune options that enable filesystem features + +source $TOP/tests/common + +check_prereq btrfs-debug-tree +check_prereq btrfs-show-super +check_prereq mkfs.btrfs +setup_root_helper + +if [ -z $TEST_DEV ]; then + echo "\$TEST_DEV not given, use $TOP/test/test.img as fallback" >> \ + $RESULTS + TEST_DEV="$TOP/tests/test.img" + + # Need at least 1G to avoid mixed block group, which extent tree + # rebuild doesn't support. + run_check truncate -s 1G $TEST_DEV +fi + +if [ -z $TEST_MNT ];then + echo " [NOTRUN] extent tree rebuild, need TEST_MNT variant" + exit 0 +fi + +# test whether fsck can rebuild a corrupted extent tree +# parameters: +# - option for mkfs.btrfs -O, empty for defaults +# - option for btrfstune +# - string representing the feature in btrfs-show-super dump +test_feature() +{ + local mkfsfeatures + local tuneopt + local sbflag + + mkfsfeatures=${1:+-O ^$1} + tuneopt="$2" + sbflag="$3" + + run_check $SUDO_HELPER $TOP/mkfs.btrfs -f $mkfsfeatures $TEST_DEV + if run_check_stdout $TOP/btrfs-show-super $TEST_DEV | \ + grep -q "$sbflag"; then + _fail "FAIL: feature $sbflag must not be set on the base image" + fi + run_check $TOP/btrfstune $tuneopt $TEST_DEV + if ! run_check_stdout $TOP/btrfs-show-super $TEST_DEV | \ + grep -q "$sbflag"; then + _fail "FAIL: feature $sbflag not set" + fi + run_check $SUDO_HELPER $TOP/btrfs check $TEST_DEV +} + +test_feature extref -r EXTENDED_IREF +test_feature skinny-metadata -x SKINNY_METADATA +test_feature '' '-S 1' SEEDING -- cgit v1.2.3 From 6a4a3acbc21d08065d64d57b08bb0d7f78e388ca Mon Sep 17 00:00:00 2001 From: David Sterba Date: Tue, 2 Jun 2015 18:41:01 +0200 Subject: btrfs-progs: btrfstune: add option to enable NO_HOLES New option -n to enable the NO_HOLES feature. Signed-off-by: David Sterba --- tests/misc-tests/001-btrfstune-features/test.sh | 1 + 1 file changed, 1 insertion(+) (limited to 'tests') diff --git a/tests/misc-tests/001-btrfstune-features/test.sh b/tests/misc-tests/001-btrfstune-features/test.sh index 4ce3411f..c9981e6e 100755 --- a/tests/misc-tests/001-btrfstune-features/test.sh +++ b/tests/misc-tests/001-btrfstune-features/test.sh @@ -53,4 +53,5 @@ test_feature() test_feature extref -r EXTENDED_IREF test_feature skinny-metadata -x SKINNY_METADATA +test_feature no-holes -n NO_HOLES test_feature '' '-S 1' SEEDING -- cgit v1.2.3 From 551c4bb064808d500e089e395886c73384576a6d Mon Sep 17 00:00:00 2001 From: David Sterba Date: Wed, 3 Jun 2015 13:59:55 +0200 Subject: btrfs-progs: tests: add misc tests for uuid rewrite Simple tests of the -u/-U options of btrfstune. Signed-off-by: David Sterba --- tests/misc-tests/002-uuid-rewrite/test.sh | 75 +++++++++++++++++++++++++++++++ 1 file changed, 75 insertions(+) create mode 100755 tests/misc-tests/002-uuid-rewrite/test.sh (limited to 'tests') diff --git a/tests/misc-tests/002-uuid-rewrite/test.sh b/tests/misc-tests/002-uuid-rewrite/test.sh new file mode 100755 index 00000000..488f756e --- /dev/null +++ b/tests/misc-tests/002-uuid-rewrite/test.sh @@ -0,0 +1,75 @@ +#!/bin/bash +# test btrfstune uuid rewriting options + +source $TOP/tests/common + +check_prereq btrfs-debug-tree +check_prereq btrfs-show-super +check_prereq mkfs.btrfs +check_prereq btrfstune + +if [ -z $TEST_DEV ]; then + echo "\$TEST_DEV not given, use $TOP/test/test.img as fallback" >> \ + $RESULTS + TEST_DEV="$TOP/tests/test.img" + + # Need at least 1G to avoid mixed block group, which extent tree + # rebuild doesn't support. + run_check truncate -s 1G $TEST_DEV +fi + +if [ -z $TEST_MNT ];then + echo " [NOTRUN] extent tree rebuild, need TEST_MNT variant" + exit 0 +fi + +get_fs_uuid() { + local image + + image="$1" + run_check_stdout $TOP/btrfs-show-super "$image" | \ + grep '^fsid' | awk '{print $2}' +} + +test_uuid_random() +{ + local origuuid + + origuuid=11111111-a101-4031-b29a-379d4f8b7a2d + + run_check $SUDO_HELPER $TOP/mkfs.btrfs -f \ + --uuid $origuuid \ + --rootdir $TOP/Documentation \ + $TEST_DEV + run_check $TOP/btrfs-show-super "$TEST_DEV" + run_check $TOP/btrfstune -f -u $TEST_DEV + # btrfs-show-super is called within get_fs_uuid + fsid=$(get_fs_uuid $TEST_DEV) + run_check $SUDO_HELPER $TOP/btrfs check $TEST_DEV +} + +test_uuid_user() +{ + local origuuid + local newuuid + + origuuid=22222222-d324-4f92-80e9-7658bf3b845f + newuuid=33333333-bfc9-4045-9399-a396dc6893b3 + + run_check $SUDO_HELPER $TOP/mkfs.btrfs -f \ + --uuid $origuuid \ + --rootdir $TOP/Documentation \ + $TEST_DEV + run_check $TOP/btrfs-show-super "$TEST_DEV" + run_check $TOP/btrfstune -f -U $newuuid \ + $TEST_DEV + # btrfs-show-super is called within get_fs_uuid + fsid=$(get_fs_uuid $TEST_DEV) + if ! [ $fsid = $newuuid ]; then + _fail "FAIL: UUID not rewritten" + fi + run_check $SUDO_HELPER $TOP/btrfs check $TEST_DEV +} + +test_uuid_random +test_uuid_user -- cgit v1.2.3 From 567d7569d8dd50c14c28a9808891b2dc757f7628 Mon Sep 17 00:00:00 2001 From: David Sterba Date: Thu, 4 Jun 2015 19:09:52 +0200 Subject: btrfs-progs: tests: update convert tests to set fs features Signed-off-by: David Sterba --- tests/convert-tests.sh | 48 ++++++++++++++++++++++++++++++------------------ 1 file changed, 30 insertions(+), 18 deletions(-) mode change 100644 => 100755 tests/convert-tests.sh (limited to 'tests') diff --git a/tests/convert-tests.sh b/tests/convert-tests.sh old mode 100644 new mode 100755 index 9234c7ba..14dde1fe --- a/tests/convert-tests.sh +++ b/tests/convert-tests.sh @@ -20,7 +20,17 @@ rm -f $RESULTS setup_root_helper convert_test() { - echo " [TEST] $1" + local features + local nodesize + + features="$1" + shift + + if [ -z "$features" ]; then + echo " [TEST] $1, btrfs defaults" + else + echo " [TEST] $1, btrfs $features" + fi nodesize=$2 shift 2 echo "creating ext image with: $*" >> $RESULTS @@ -37,23 +47,25 @@ convert_test() { run_check $SUDO_HELPER dd if=/dev/zero of=$TEST_MNT/test bs=$nodesize \ count=1 1>/dev/null 2>&1 run_check $SUDO_HELPER umount $TEST_MNT - run_check $TOP/btrfs-convert -N "$nodesize" $IMAGE + run_check $TOP/btrfs-convert ${features:+-O "$features"} -N "$nodesize" $IMAGE run_check $TOP/btrfs check $IMAGE + run_check $TOP/btrfs-show-super $IMAGE } -# btrfs-convert requires 4k blocksize. -convert_test "ext2 4k nodesize" 4096 mke2fs -b 4096 -convert_test "ext3 4k nodesize" 4096 mke2fs -j -b 4096 -convert_test "ext4 4k nodesize" 4096 mke2fs -t ext4 -b 4096 -convert_test "ext2 8k nodesize" 8192 mke2fs -b 4096 -convert_test "ext3 8k nodesize" 8192 mke2fs -j -b 4096 -convert_test "ext4 8k nodesize" 8192 mke2fs -t ext4 -b 4096 -convert_test "ext2 16k nodesize" 16384 mke2fs -b 4096 -convert_test "ext3 16k nodesize" 16384 mke2fs -j -b 4096 -convert_test "ext4 16k nodesize" 16384 mke2fs -t ext4 -b 4096 -convert_test "ext2 32k nodesize" 32768 mke2fs -b 4096 -convert_test "ext3 32k nodesize" 32768 mke2fs -j -b 4096 -convert_test "ext4 32k nodesize" 32768 mke2fs -t ext4 -b 4096 -convert_test "ext2 64k nodesize" 65536 mke2fs -b 4096 -convert_test "ext3 64k nodesize" 65536 mke2fs -j -b 4096 -convert_test "ext4 64k nodesize" 65536 mke2fs -t ext4 -b 4096 +for feature in '' 'extref' 'skinny-metadata' 'no-holes'; do + convert_test "$feature" "ext2 4k nodesize" 4096 mke2fs -b 4096 + convert_test "$feature" "ext3 4k nodesize" 4096 mke2fs -j -b 4096 + convert_test "$feature" "ext4 4k nodesize" 4096 mke2fs -t ext4 -b 4096 + convert_test "$feature" "ext2 8k nodesize" 8192 mke2fs -b 4096 + convert_test "$feature" "ext3 8k nodesize" 8192 mke2fs -j -b 4096 + convert_test "$feature" "ext4 8k nodesize" 8192 mke2fs -t ext4 -b 4096 + convert_test "$feature" "ext2 16k nodesize" 16384 mke2fs -b 4096 + convert_test "$feature" "ext3 16k nodesize" 16384 mke2fs -j -b 4096 + convert_test "$feature" "ext4 16k nodesize" 16384 mke2fs -t ext4 -b 4096 + convert_test "$feature" "ext2 32k nodesize" 32768 mke2fs -b 4096 + convert_test "$feature" "ext3 32k nodesize" 32768 mke2fs -j -b 4096 + convert_test "$feature" "ext4 32k nodesize" 32768 mke2fs -t ext4 -b 4096 + convert_test "$feature" "ext2 64k nodesize" 65536 mke2fs -b 4096 + convert_test "$feature" "ext3 64k nodesize" 65536 mke2fs -j -b 4096 + convert_test "$feature" "ext4 64k nodesize" 65536 mke2fs -t ext4 -b 4096 +done -- cgit v1.2.3 From 281be9e7d5bc978940ea8b30f836b28c4fc99b47 Mon Sep 17 00:00:00 2001 From: David Sterba Date: Fri, 5 Jun 2015 18:26:32 +0200 Subject: btrfs-progs: tests: add test for zero-log Simple test to verify that the log_root is reset after the command, but we yet need to provide a testing image with log_root set to something sensible or crafted images with borked log_root pointer. Signed-off-by: David Sterba --- tests/misc-tests/003-zero-log/test.sh | 66 +++++++++++++++++++++++++++++++++++ 1 file changed, 66 insertions(+) create mode 100755 tests/misc-tests/003-zero-log/test.sh (limited to 'tests') diff --git a/tests/misc-tests/003-zero-log/test.sh b/tests/misc-tests/003-zero-log/test.sh new file mode 100755 index 00000000..da5b3510 --- /dev/null +++ b/tests/misc-tests/003-zero-log/test.sh @@ -0,0 +1,66 @@ +#!/bin/bash +# test zero-log + +source $TOP/tests/common + +check_prereq btrfs-show-super +check_prereq mkfs.btrfs +check_prereq btrfs + +if [ -z $TEST_DEV ]; then + echo "\$TEST_DEV not given, use $TOP/test/test.img as fallback" >> \ + $RESULTS + TEST_DEV="$TOP/tests/test.img" + + # Need at least 1G to avoid mixed block group, which extent tree + # rebuild doesn't support. + run_check truncate -s 1G $TEST_DEV +fi + +if [ -z $TEST_MNT ];then + echo " [NOTRUN] extent tree rebuild, need TEST_MNT variant" + exit 0 +fi + +get_log_root() +{ + local image + + image="$1" + $TOP/btrfs-show-super "$image" | \ + grep '^log_root\>' | awk '{print $2}' +} +get_log_root_level() { + local image + + image="$1" + $TOP/btrfs-show-super "$image" | \ + grep '^log_root_level' | awk '{print $2}' +} + +test_zero_log() +{ + # FIXME: we need an image with existing log_root + run_check $SUDO_HELPER $TOP/mkfs.btrfs -f \ + --rootdir $TOP/Documentation \ + $TEST_DEV + run_check $TOP/btrfs-show-super $TEST_DEV + if [ "$1" = 'standalone' ]; then + run_check $TOP/btrfs rescue zero-log $TEST_DEV + else + run_check $TOP/btrfs-zero-log $TEST_DEV + fi + log_root=$(get_log_root $TEST_DEV) + log_root_level=$(get_log_root $TEST_DEV) + if [ "$log_root" != 0 ]; then + _fail "FAIL: log_root not reset" + fi + if [ "$log_root_level" != 0 ]; then + _fail "FAIL: log_root_level not reset" + fi + run_check $TOP/btrfs-show-super $TEST_DEV + run_check $SUDO_HELPER $TOP/btrfs check $TEST_DEV +} + +test_zero_log standalone +test_zero_log internal -- cgit v1.2.3 From 4b4d742b26bb81575f67002ac7f3b7a0efffbd95 Mon Sep 17 00:00:00 2001 From: David Sterba Date: Thu, 18 Jun 2015 19:35:58 +0200 Subject: btrfs-progs: tests: verify btrfstune output during uuid-rewrite The 'Current fsid:' value does not match the real fsid. Reported-by: Mike Fleetwood Signed-off-by: David Sterba --- tests/misc-tests/002-uuid-rewrite/test.sh | 9 ++++++--- 1 file changed, 6 insertions(+), 3 deletions(-) (limited to 'tests') diff --git a/tests/misc-tests/002-uuid-rewrite/test.sh b/tests/misc-tests/002-uuid-rewrite/test.sh index 488f756e..6c2a3930 100755 --- a/tests/misc-tests/002-uuid-rewrite/test.sh +++ b/tests/misc-tests/002-uuid-rewrite/test.sh @@ -42,9 +42,12 @@ test_uuid_random() --rootdir $TOP/Documentation \ $TEST_DEV run_check $TOP/btrfs-show-super "$TEST_DEV" - run_check $TOP/btrfstune -f -u $TEST_DEV - # btrfs-show-super is called within get_fs_uuid - fsid=$(get_fs_uuid $TEST_DEV) + currentfsid=$(run_check_stdout $TOP/btrfstune -f -u $TEST_DEV | \ + grep -i 'current fsid:' | awk '{print $3}') + if ! [ $currentfsid = $origuuid ]; then + _fail "FAIL: current UUID mismatch" + fi + run_check $TOP/btrfs-show-super "$TEST_DEV" run_check $SUDO_HELPER $TOP/btrfs check $TEST_DEV } -- cgit v1.2.3 From fabf14c540be8b85676c2637ad3741728bfe80fc Mon Sep 17 00:00:00 2001 From: Qu Wenruo Date: Thu, 2 Jul 2015 14:36:04 +0800 Subject: btrfs-progs: tests: Add test case for I_ERR_FILE_WRONG_NBYTES repair Add a new test case for I_ERR_FILE_WRONG_NBYTES. The new btrfs-image dump image contains a file in 12K size. But nbytes in its inode item is a random number. Signed-off-by: Qu Wenruo --- .../016-wrong-inode-nbytes/default_case.img.xz | Bin 0 -> 1996 bytes 1 file changed, 0 insertions(+), 0 deletions(-) create mode 100644 tests/fsck-tests/016-wrong-inode-nbytes/default_case.img.xz (limited to 'tests') diff --git a/tests/fsck-tests/016-wrong-inode-nbytes/default_case.img.xz b/tests/fsck-tests/016-wrong-inode-nbytes/default_case.img.xz new file mode 100644 index 00000000..d513acf5 Binary files /dev/null and b/tests/fsck-tests/016-wrong-inode-nbytes/default_case.img.xz differ -- cgit v1.2.3 From a57606e815f3e1c4fe66c61ce3c6e3621ea522e9 Mon Sep 17 00:00:00 2001 From: Filipe Manana Date: Thu, 16 Jul 2015 16:47:13 +0100 Subject: Btrfs-progs: add feature to get mininum size for resizing a fs/device Currently there is not way for a user to know what is the minimum size a device of a btrfs filesystem can be resized to. Sometimes the value of total allocated space (sum of all allocated chunks/device extents), which can be parsed from 'btrfs filesystem show' and 'btrfs filesystem usage', works as the minimum size, but sometimes it does not, namely when device extents have to relocated to holes (unallocated space) within the new size of the device (the total allocated space sum). This change adds the ability to reliably compute such minimum value and extents 'btrfs filesystem resize' with the following syntax to get such value: btrfs filesystem resize [devid:]get_min_size Signed-off-by: Filipe Manana Signed-off-by: David Sterba --- tests/misc-tests.sh | 2 + tests/misc-tests/004-shrink-fs/test.sh | 69 ++++++++++++++++++++++++++++++++++ 2 files changed, 71 insertions(+) create mode 100755 tests/misc-tests/004-shrink-fs/test.sh (limited to 'tests') diff --git a/tests/misc-tests.sh b/tests/misc-tests.sh index 5bbe9140..2ae99db9 100755 --- a/tests/misc-tests.sh +++ b/tests/misc-tests.sh @@ -20,6 +20,8 @@ export RESULTS # For custom script needs to verfiy recovery export TEST_MNT export LANG +# For tests that only use a loop device +export IMAGE rm -f $RESULTS mkdir -p $TEST_MNT || _fail "unable to create mount point on $TEST_MNT" diff --git a/tests/misc-tests/004-shrink-fs/test.sh b/tests/misc-tests/004-shrink-fs/test.sh new file mode 100755 index 00000000..393cccf5 --- /dev/null +++ b/tests/misc-tests/004-shrink-fs/test.sh @@ -0,0 +1,69 @@ +#!/bin/bash +# +# Test getting the minimum size a filesystem can be resized to and verify we +# are able to resize (shrink) it to that size. +# + +source $TOP/tests/common + +check_prereq mkfs.btrfs +setup_root_helper + +shrink_test() +{ + min_size=$($SUDO_HELPER $TOP/btrfs filesystem resize get_min_size $TEST_MNT) + if [ $? != 0 ]; then + _fail "Failed to get minimum size" + fi + min_size=$(echo $min_size | cut -d ' ' -f 1) + echo "min size = ${min_size}" >> $RESULTS + run_check $SUDO_HELPER $TOP/btrfs filesystem resize $min_size $TEST_MNT +} + +run_check truncate -s 20G $IMAGE +run_check $TOP/mkfs.btrfs -f $IMAGE +run_check $SUDO_HELPER mount $IMAGE $TEST_MNT +run_check $SUDO_HELPER chmod a+rw $TEST_MNT + +# Create 7 data block groups, each with a size of 1Gb. +for ((i = 1; i <= 7; i++)); do + run_check fallocate -l 1G $TEST_MNT/foo$i +done + +# Make sure they are persisted (all the chunk, device and block group items +# added to the chunk/dev/extent trees). +run_check $TOP/btrfs filesystem sync $TEST_MNT + +# Now remove 3 of those 1G files. This will result in 3 block groups becoming +# unused, which will be automatically deleted by the cleaner kthread, and this +# will result in 3 holes (unallocated space) in the device (each with a size +# of 1Gb). + +run_check rm -f $TEST_MNT/foo2 +run_check rm -f $TEST_MNT/foo4 +run_check rm -f $TEST_MNT/foo6 + +# Sync once to wake up the cleaner kthread which will delete the unused block +# groups - it could have been sleeping when they became unused. Then wait a bit +# to allow the cleaner kthread to delete them and then finally ensure the +# transaction started by the cleaner kthread is committed. +run_check $TOP/btrfs filesystem sync $TEST_MNT +sleep 3 +run_check $TOP/btrfs filesystem sync $TEST_MNT + +# Now attempt to get the minimum size we can resize the filesystem to and verify +# the resize operation succeeds. This size closely matches the sum of the size +# of all the allocated device extents. +for ((i = 1; i <= 3; i++)); do + shrink_test +done + +# Now convert metadata and system chunks to the single profile and check we are +# still able to get a correct minimum size and shrink to that size. +run_check $SUDO_HELPER $TOP/btrfs balance start -mconvert=single \ + -sconvert=single -f $TEST_MNT +for ((i = 1; i <= 3; i++)); do + shrink_test +done + +run_check $SUDO_HELPER umount $TEST_MNT -- cgit v1.2.3 From 5b1c5b88786297a8582c8ad211289a090f8e8435 Mon Sep 17 00:00:00 2001 From: David Sterba Date: Mon, 20 Jul 2015 17:31:43 +0200 Subject: btrfs-progs: inspect: add command min-dev-size Previously in 'filesystem resize get_min_size', now 'inspect-internal min-dev-size'. We'd like to avoid cluttering the 'resize' syntax further. The test has been updated to exercise the new option. Signed-off-by: David Sterba --- tests/misc-tests/004-shrink-fs/test.sh | 11 ++++++----- 1 file changed, 6 insertions(+), 5 deletions(-) (limited to 'tests') diff --git a/tests/misc-tests/004-shrink-fs/test.sh b/tests/misc-tests/004-shrink-fs/test.sh index 393cccf5..b1321520 100755 --- a/tests/misc-tests/004-shrink-fs/test.sh +++ b/tests/misc-tests/004-shrink-fs/test.sh @@ -9,14 +9,15 @@ source $TOP/tests/common check_prereq mkfs.btrfs setup_root_helper +# Optionally take id of the device to shrink shrink_test() { - min_size=$($SUDO_HELPER $TOP/btrfs filesystem resize get_min_size $TEST_MNT) - if [ $? != 0 ]; then - _fail "Failed to get minimum size" - fi + min_size=$(run_check_stdout $SUDO_HELPER $TOP/btrfs inspect-internal min-dev-size ${1:+--id $1} $TEST_MNT) min_size=$(echo $min_size | cut -d ' ' -f 1) echo "min size = ${min_size}" >> $RESULTS + if [ -z "$min_size" ]; then + _fail "Failed to parse minimum size" + fi run_check $SUDO_HELPER $TOP/btrfs filesystem resize $min_size $TEST_MNT } @@ -63,7 +64,7 @@ done run_check $SUDO_HELPER $TOP/btrfs balance start -mconvert=single \ -sconvert=single -f $TEST_MNT for ((i = 1; i <= 3; i++)); do - shrink_test + shrink_test 1 done run_check $SUDO_HELPER umount $TEST_MNT -- cgit v1.2.3 From 9842d5769117eb46ad116b8e9fb65a5b8cf27856 Mon Sep 17 00:00:00 2001 From: David Sterba Date: Sat, 11 Jul 2015 00:31:02 +0200 Subject: btrfs-progs: fsck tests: move code to a function Signed-off-by: David Sterba --- tests/fsck-tests.sh | 35 +++++++++++++++++++++-------------- 1 file changed, 21 insertions(+), 14 deletions(-) (limited to 'tests') diff --git a/tests/fsck-tests.sh b/tests/fsck-tests.sh index b0ded6ae..7e90f25e 100755 --- a/tests/fsck-tests.sh +++ b/tests/fsck-tests.sh @@ -31,6 +31,26 @@ check_prereq btrfs-corrupt-block check_prereq btrfs-image check_prereq btrfs +run_one_test() { + local testname + + testname="$1" + echo " [TEST] $(basename $testname)" + cd $testname + echo "=== Entering $testname" >> $RESULTS + if [ -x test.sh ]; then + # Type 2 + ./test.sh + if [ $? -ne 0 ]; then + _fail "test failed for case $(basename $testname)" + fi + else + # Type 1 + check_all_images `pwd` + fi + cd $TOP +} + # Each dir contains one type of error for btrfsck test. # Each dir must be one of the following 2 types: # 1) Only btrfs-image dump @@ -46,18 +66,5 @@ check_prereq btrfs for i in $(find $TOP/tests/fsck-tests -maxdepth 1 -mindepth 1 -type d | sort) do - echo " [TEST] $(basename $i)" - cd $i - echo "=== Entering $i" >> $RESULTS - if [ -x test.sh ]; then - # Type 2 - ./test.sh - if [ $? -ne 0 ]; then - _fail "test failed for case $(basename $i)" - fi - else - # Type 1 - check_all_images `pwd` - fi - cd $TOP + run_one_test "$i" done -- cgit v1.2.3 From a5afa55a30a07f18c17527ad09420afb9bc5ff69 Mon Sep 17 00:00:00 2001 From: David Sterba Date: Sat, 11 Jul 2015 00:38:07 +0200 Subject: btrfs-progs: tests: support testname glob To run a given test set the variable TEST like $ make test TEST=002-bad-transid $ make test TEST=002-* and only tests matching the value will be run. The pattern is glob and pased to 'find -name'. The convert tests do not follow the fsck and misc layout and are skipped if TEST is set. Signed-off-by: David Sterba --- tests/convert-tests.sh | 5 +++++ tests/fsck-tests.sh | 3 ++- tests/misc-tests.sh | 3 ++- 3 files changed, 9 insertions(+), 2 deletions(-) (limited to 'tests') diff --git a/tests/convert-tests.sh b/tests/convert-tests.sh index 14dde1fe..b395e25e 100755 --- a/tests/convert-tests.sh +++ b/tests/convert-tests.sh @@ -52,6 +52,11 @@ convert_test() { run_check $TOP/btrfs-show-super $IMAGE } +if ! [ -z "$TEST" ]; then + echo " [TEST] skipped all convert tests, TEST=$TEST" + exit 0 +fi + for feature in '' 'extref' 'skinny-metadata' 'no-holes'; do convert_test "$feature" "ext2 4k nodesize" 4096 mke2fs -b 4096 convert_test "$feature" "ext3 4k nodesize" 4096 mke2fs -j -b 4096 diff --git a/tests/fsck-tests.sh b/tests/fsck-tests.sh index 7e90f25e..73538fec 100755 --- a/tests/fsck-tests.sh +++ b/tests/fsck-tests.sh @@ -64,7 +64,8 @@ run_one_test() { # This is for case btrfs-image can't dump or case needs extra # check/verify -for i in $(find $TOP/tests/fsck-tests -maxdepth 1 -mindepth 1 -type d | sort) +for i in $(find $TOP/tests/fsck-tests -maxdepth 1 -mindepth 1 -type d \ + ${TEST:+-name "$TEST"} | sort) do run_one_test "$i" done diff --git a/tests/misc-tests.sh b/tests/misc-tests.sh index 2ae99db9..1ed8850e 100755 --- a/tests/misc-tests.sh +++ b/tests/misc-tests.sh @@ -34,7 +34,8 @@ check_prereq btrfs # The tests are driven by their custom script called 'test.sh' -for i in $(find $TOP/tests/misc-tests -maxdepth 1 -mindepth 1 -type d | sort) +for i in $(find $TOP/tests/misc-tests -maxdepth 1 -mindepth 1 -type d \ + ${TEST:+-name "$TEST"} | sort) do echo " [TEST] $(basename $i)" cd $i -- cgit v1.2.3 From 9e99b99fa05036b09f11fc7a1d64c4dedd6b2ced Mon Sep 17 00:00:00 2001 From: Zhao Lei Date: Mon, 27 Jul 2015 21:01:50 +0800 Subject: btrfs-progs: tests: Add -o loop to fsck-tests/012-leaf-corruption To avoid following mount error in test: mount: /root/btrfs/progs/tests/fsck-tests/012-leaf-corruption/test.img is not a block device (maybe try `-o loop'?) Signed-off-by: Zhao Lei Signed-off-by: David Sterba --- tests/fsck-tests/012-leaf-corruption/test.sh | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) (limited to 'tests') diff --git a/tests/fsck-tests/012-leaf-corruption/test.sh b/tests/fsck-tests/012-leaf-corruption/test.sh index 98e31856..f8701ad7 100755 --- a/tests/fsck-tests/012-leaf-corruption/test.sh +++ b/tests/fsck-tests/012-leaf-corruption/test.sh @@ -86,7 +86,7 @@ check_leaf_corrupt_no_data_ext() { image=$1 mkdir -p $TEST_MNT || _fail "failed to create mount point" - $SUDO_HELPER mount $image -o ro $TEST_MNT + $SUDO_HELPER mount -o loop $image -o ro $TEST_MNT i=0 while [ $i -lt ${#leaf_no_data_ext_list[@]} ]; do -- cgit v1.2.3 From bafc3a33f5527f3cdd4f27be17687703256d0914 Mon Sep 17 00:00:00 2001 From: Zhao Lei Date: Mon, 27 Jul 2015 20:24:31 +0800 Subject: btrfs-progs: tests: Move code to create loop device to common This code block is used several tests, move it to ./common and add a helper. Signed-off-by: Zhao Lei Signed-off-by: David Sterba --- tests/common | 16 ++++++++++++++++ tests/fsck-tests/013-extent-tree-rebuild/test.sh | 11 +---------- tests/misc-tests/001-btrfstune-features/test.sh | 11 +---------- tests/misc-tests/002-uuid-rewrite/test.sh | 11 +---------- tests/misc-tests/003-zero-log/test.sh | 11 +---------- 5 files changed, 20 insertions(+), 40 deletions(-) (limited to 'tests') diff --git a/tests/common b/tests/common index 899ec7b1..2d337b0b 100644 --- a/tests/common +++ b/tests/common @@ -142,3 +142,19 @@ setup_root_helper() fi SUDO_HELPER=root_helper } + +prepare_test_dev() +{ + # num[K/M/G/T...] + local size="$1" + + [[ "$TEST_DEV" ]] && return + [[ "$size" ]] || size='1G' + + echo "\$TEST_DEV not given, use $TOP/test/test.img as fallback" >> \ + $RESULTS + TEST_DEV="$TOP/tests/test.img" + + truncate -s "$size" "$TEST_DEV" || _not_run "create file for loop device failed" +} + diff --git a/tests/fsck-tests/013-extent-tree-rebuild/test.sh b/tests/fsck-tests/013-extent-tree-rebuild/test.sh index 3290cd72..88a66cc2 100755 --- a/tests/fsck-tests/013-extent-tree-rebuild/test.sh +++ b/tests/fsck-tests/013-extent-tree-rebuild/test.sh @@ -5,16 +5,7 @@ source $TOP/tests/common check_prereq btrfs-debug-tree check_prereq mkfs.btrfs setup_root_helper - -if [ -z $TEST_DEV ]; then - echo "\$TEST_DEV not given, use $TOP/test/test.img as fallback" >> \ - $RESULTS - TEST_DEV="$TOP/tests/test.img" - - # Need at least 1G to avoid mixed block group, which extent tree - # rebuild doesn't support. - run_check truncate -s 1G $TEST_DEV -fi +prepare_test_dev 1G if [ -z $TEST_MNT ];then echo " [NOTRUN] extent tree rebuild, need TEST_MNT variant" diff --git a/tests/misc-tests/001-btrfstune-features/test.sh b/tests/misc-tests/001-btrfstune-features/test.sh index c9981e6e..ea33954d 100755 --- a/tests/misc-tests/001-btrfstune-features/test.sh +++ b/tests/misc-tests/001-btrfstune-features/test.sh @@ -7,16 +7,7 @@ check_prereq btrfs-debug-tree check_prereq btrfs-show-super check_prereq mkfs.btrfs setup_root_helper - -if [ -z $TEST_DEV ]; then - echo "\$TEST_DEV not given, use $TOP/test/test.img as fallback" >> \ - $RESULTS - TEST_DEV="$TOP/tests/test.img" - - # Need at least 1G to avoid mixed block group, which extent tree - # rebuild doesn't support. - run_check truncate -s 1G $TEST_DEV -fi +prepare_test_dev if [ -z $TEST_MNT ];then echo " [NOTRUN] extent tree rebuild, need TEST_MNT variant" diff --git a/tests/misc-tests/002-uuid-rewrite/test.sh b/tests/misc-tests/002-uuid-rewrite/test.sh index 6c2a3930..bffa9b85 100755 --- a/tests/misc-tests/002-uuid-rewrite/test.sh +++ b/tests/misc-tests/002-uuid-rewrite/test.sh @@ -7,16 +7,7 @@ check_prereq btrfs-debug-tree check_prereq btrfs-show-super check_prereq mkfs.btrfs check_prereq btrfstune - -if [ -z $TEST_DEV ]; then - echo "\$TEST_DEV not given, use $TOP/test/test.img as fallback" >> \ - $RESULTS - TEST_DEV="$TOP/tests/test.img" - - # Need at least 1G to avoid mixed block group, which extent tree - # rebuild doesn't support. - run_check truncate -s 1G $TEST_DEV -fi +prepare_test_dev if [ -z $TEST_MNT ];then echo " [NOTRUN] extent tree rebuild, need TEST_MNT variant" diff --git a/tests/misc-tests/003-zero-log/test.sh b/tests/misc-tests/003-zero-log/test.sh index da5b3510..edab5dbc 100755 --- a/tests/misc-tests/003-zero-log/test.sh +++ b/tests/misc-tests/003-zero-log/test.sh @@ -6,16 +6,7 @@ source $TOP/tests/common check_prereq btrfs-show-super check_prereq mkfs.btrfs check_prereq btrfs - -if [ -z $TEST_DEV ]; then - echo "\$TEST_DEV not given, use $TOP/test/test.img as fallback" >> \ - $RESULTS - TEST_DEV="$TOP/tests/test.img" - - # Need at least 1G to avoid mixed block group, which extent tree - # rebuild doesn't support. - run_check truncate -s 1G $TEST_DEV -fi +prepare_test_dev if [ -z $TEST_MNT ];then echo " [NOTRUN] extent tree rebuild, need TEST_MNT variant" -- cgit v1.2.3 From 02abd61aa0566cde9e3a324cb207241e2259564d Mon Sep 17 00:00:00 2001 From: Zhao Lei Date: Mon, 27 Jul 2015 20:24:32 +0800 Subject: btrfs-progs: Introduce a misc test for thread conflict in btrfs-convert Current code of btrfs-convert have a bug of thread conflict, which caused invalid memory accessing between threads, and make program panic. This patch add a test item for above bug, as: # ./misc-tests.sh [TEST] 001-btrfstune-features [TEST] 002-uuid-rewrite [TEST] 003-zero-log [TEST] 004-convert-thread-conflict failed: btrfs-convert /root/btrfsprogs/tests/test.img test failed for case 004-convert-thread-conflict # # cat misc-tests-results.txt ... ############### btrfs-convert /root/btrfsprogs/tests/test.img trans 7 running 5 ctree.c:363: btrfs_cow_block: Assertion `1` failed. btrfs-convert(btrfs_cow_block+0x92)[0x40acaf] btrfs-convert(btrfs_search_slot+0x1cb)[0x40c50f] btrfs-convert(btrfs_csum_file_block+0x20f)[0x41d83a] btrfs-convert[0x43422d] btrfs-convert[0x4342cd] btrfs-convert[0x4345ca] btrfs-convert[0x434767] btrfs-convert[0x435770] btrfs-convert[0x439748] btrfs-convert(main+0x13f8)[0x43b09d] /lib64/libc.so.6(__libc_start_main+0xfd)[0x335e01ecdd] btrfs-convert[0x407649] create btrfs filesystem: blocksize: 4096 nodesize: 16384 features: extref, skinny-metadata (default) creating btrfs metadata. creating ext2fs image file. failed: btrfs-convert /root/btrfsprogs/tests/test.img test failed for case 004-convert-thread-conflict # Note that this bug is not happened every time, especilly in slow device as loop(slow cpu with fast block device is likely to trigger). I set loop count to 20 to make bug happened in 90% tests. Suggested-by: David Sterba Signed-off-by: Zhao Lei Signed-off-by: David Sterba --- tests/misc-tests/005-convert-progress-thread-crash/test.sh | 14 ++++++++++++++ 1 file changed, 14 insertions(+) create mode 100755 tests/misc-tests/005-convert-progress-thread-crash/test.sh (limited to 'tests') diff --git a/tests/misc-tests/005-convert-progress-thread-crash/test.sh b/tests/misc-tests/005-convert-progress-thread-crash/test.sh new file mode 100755 index 00000000..09ac8a3a --- /dev/null +++ b/tests/misc-tests/005-convert-progress-thread-crash/test.sh @@ -0,0 +1,14 @@ +#!/bin/bash +# test convert-thread-conflict + +source $TOP/tests/common + +check_prereq btrfs +mkfs.ext4 -V &>/dev/null || _not_run "mkfs.ext4 not found" +prepare_test_dev 1G + +for ((i = 0; i < 20; i++)); do + echo "loop $i" >>$RESULTS + mkfs.ext4 -F "$TEST_DEV" &>>$RESULTS || _not_run "mkfs.ext4 failed" + run_check $TOP/btrfs-convert "$TEST_DEV" +done -- cgit v1.2.3 From cc31e6cf507a4a6cf19265e63d9be1acdd3111a9 Mon Sep 17 00:00:00 2001 From: Qu Wenruo Date: Wed, 5 Aug 2015 16:03:14 +0800 Subject: btrfs-progs: fsck-tests: add case for inode losing all its extents Add test case for inode with no file extents, but still non-zero size. To test whether fsck will infinite loop. Signed-off-by: Qu Wenruo Signed-off-by: David Sterba --- .../017-missing-all-file-extent/default_case.img.xz | Bin 0 -> 1104 bytes 1 file changed, 0 insertions(+), 0 deletions(-) create mode 100644 tests/fsck-tests/017-missing-all-file-extent/default_case.img.xz (limited to 'tests') diff --git a/tests/fsck-tests/017-missing-all-file-extent/default_case.img.xz b/tests/fsck-tests/017-missing-all-file-extent/default_case.img.xz new file mode 100644 index 00000000..10cd4c78 Binary files /dev/null and b/tests/fsck-tests/017-missing-all-file-extent/default_case.img.xz differ -- cgit v1.2.3 From e547fdb16667b97ad3db4ce08a3a46b7449497f2 Mon Sep 17 00:00:00 2001 From: David Sterba Date: Tue, 25 Aug 2015 18:32:41 +0200 Subject: btrfs-progs: tests, add more common helpers Add support for failures of commands, log the output. Signed-off-by: David Sterba --- tests/common | 13 +++++++++++++ 1 file changed, 13 insertions(+) (limited to 'tests') diff --git a/tests/common b/tests/common index 2d337b0b..cf463e82 100644 --- a/tests/common +++ b/tests/common @@ -9,6 +9,12 @@ _fail() exit 1 } +# log a message to the results file +_log() +{ + echo "$*" | tee -a $RESULTS +} + _not_run() { echo " [NOTRUN] $*" @@ -29,6 +35,13 @@ run_check_stdout() "$@" 2>&1 | tee -a $RESULTS || _fail "failed: $@" } +# same as run_check but does not fail the test, output is logged +run_mayfail() +{ + echo "############### $@" >> $RESULTS 2>&1 + "$@" >> $RESULTS 2>&1 || _log "failed (ignored): $@" +} + check_prereq() { if ! [ -f $TOP/$1 ]; then -- cgit v1.2.3 From 59df5b6e9aacd222b79f27886b6989bff3eef2a9 Mon Sep 17 00:00:00 2001 From: David Sterba Date: Tue, 25 Aug 2015 18:38:36 +0200 Subject: btrfs-progs: tests, verify that btrfs-image works on a missing device Create a 2 device raid1 filesystem, fill with some data, delete one device (the device node must not exist) and try to dump a filesystem image. Signed-off-by: David Sterba --- .../misc-tests/006-image-on-missing-device/test.sh | 78 ++++++++++++++++++++++ 1 file changed, 78 insertions(+) create mode 100755 tests/misc-tests/006-image-on-missing-device/test.sh (limited to 'tests') diff --git a/tests/misc-tests/006-image-on-missing-device/test.sh b/tests/misc-tests/006-image-on-missing-device/test.sh new file mode 100755 index 00000000..8680a707 --- /dev/null +++ b/tests/misc-tests/006-image-on-missing-device/test.sh @@ -0,0 +1,78 @@ +#!/bin/bash +# test btrfs-image with a missing device (uses loop devices) +# +# - btrfs-image must not loop indefinetelly +# - btrfs-image will expectedly fail to produce the dump + +source $TOP/tests/common + +check_prereq btrfs-show-super +check_prereq btrfs-image +check_prereq mkfs.btrfs +check_prereq btrfs + +ndevs=2 +declare -a devs +dev1= +dev2= + +setup_root_helper + + +# TODO: move the helpers to common + +prepare_devices() +{ + for i in `seq $ndevs`; do + touch img$i + chmod a+rw img$i + truncate -s0 img$i + truncate -s2g img$i + devs[$i]=`run_check_stdout $SUDO_HELPER losetup --find --show img$i` + done +} + +cleanup_devices() +{ + for dev in ${devs[@]}; do + run_mayfail $SUDO_HELPER losetup -d $dev + done + for i in `seq $ndevs`; do + truncate -s0 img$i + done + run_check $SUDO_HELPER losetup --list +} + +test_image_dump() +{ + run_check $SUDO_HELPER $TOP/btrfs check $dev1 + # the output file will be deleted + run_mayfail $SUDO_HELPER $TOP/btrfs-image $dev1 /tmp/test-img.dump +} + +test_run() +{ + run_check $SUDO_HELPER $TOP/mkfs.btrfs -f -d raid1 -m raid1 $dev1 $dev2 + + # we need extents to trigger reading from all devices + run_check $SUDO_HELPER mount $dev1 $TEST_MNT + run_check $SUDO_HELPER dd if=/dev/zero of=$TEST_MNT/a bs=1M count=10 + run_check $SUDO_HELPER dd if=/dev/zero of=$TEST_MNT/b bs=4k count=1000 conv=sync + run_check $SUDO_HELPER umount $TEST_MNT + + test_image_dump + run_check btrfs fi show $dev1 + # create a degraded raid1 filesystem, check must succeed + # btrfs-image must not loop + run_mayfail wipefs -a $dev2 + run_check $SUDO_HELPER losetup -d $dev2 + run_check btrfs fi show $dev1 + + test_image_dump +} + +prepare_devices +dev1=${devs[1]} +dev2=${devs[2]} +test_run +cleanup_devices -- cgit v1.2.3 From f7ad593ca0561c799c2c3cb25f4ecc1c99913440 Mon Sep 17 00:00:00 2001 From: Zhao Lei Date: Fri, 28 Aug 2015 11:42:11 +0800 Subject: btrfs-progs: tests: Introduce subvolume sync test Current code have following bug for subvolume sync: 1: If there are more than 1 subvolume to sync, the program will infinitely loop. 2: return !0 in exit This patch add misc-tests/007-subvolume-sync for above case. Signed-off-by: Zhao Lei Signed-off-by: David Sterba --- tests/misc-tests/007-subvolume-sync/test.sh | 32 +++++++++++++++++++++++++++++ 1 file changed, 32 insertions(+) create mode 100755 tests/misc-tests/007-subvolume-sync/test.sh (limited to 'tests') diff --git a/tests/misc-tests/007-subvolume-sync/test.sh b/tests/misc-tests/007-subvolume-sync/test.sh new file mode 100755 index 00000000..d4019f43 --- /dev/null +++ b/tests/misc-tests/007-subvolume-sync/test.sh @@ -0,0 +1,32 @@ +#!/bin/bash +# test btrfs subvolume run normally with more than one subvolume +# +# - btrfs subvolume must not loop indefinetelly +# - btrfs subvolume return 0 in normal case + +source $TOP/tests/common + +check_prereq mkfs.btrfs +check_prereq btrfs + +setup_root_helper +prepare_test_dev + +run_check $SUDO_HELPER $TOP/mkfs.btrfs -f "$TEST_DEV" +run_check $SUDO_HELPER mount "$TEST_DEV" "$TEST_MNT" + +# to check following thing in both 1 and multiple subvolume case: +# 1: is subvolume sync loop indefinetelly +# 2: is return value right +# +run_check $SUDO_HELPER $TOP/btrfs subvolume create "$TEST_MNT"/mysubvol1 +run_check $SUDO_HELPER $TOP/btrfs subvolume create "$TEST_MNT"/mysubvol2 +run_check $SUDO_HELPER $TOP/btrfs subvolume delete "$TEST_MNT"/mysubvol1 +run_check $SUDO_HELPER $TOP/btrfs subvolume delete "$TEST_MNT"/mysubvol2 +run_check $SUDO_HELPER $TOP/btrfs subvolume sync "$TEST_MNT" + +run_check $SUDO_HELPER $TOP/btrfs subvolume create "$TEST_MNT"/mysubvol +run_check $SUDO_HELPER $TOP/btrfs subvolume delete "$TEST_MNT"/mysubvol +run_check $SUDO_HELPER $TOP/btrfs subvolume sync "$TEST_MNT" + +run_check $SUDO_HELPER umount $TEST_MNT -- cgit v1.2.3 From d4d500d341a352c882169a67b1a0c8119ed4257e Mon Sep 17 00:00:00 2001 From: Zhao Lei Date: Mon, 31 Aug 2015 13:04:36 +0800 Subject: btrfs-progs: tests: Introduce init_env to initialize common env variant For example, $TEST_DIR is common used in severial tests, and have duplicated code for initialize. These duplicated code not only benifits harddisk vendor, but have inconsistent details, as: convert-tests.sh: lack of mkdir fsck-tests/012-leaf-corruption/test.sh: unnecessary mkdir fsck-tests/013-extent-tree-rebuild/test.sh: unnecessary init misc-tests/XXX ... And severial error message: _fail "unable to create mount point on $TEST_MNT" _fail "failed to create mount point" ... This patch move initizlizaton of $TEST_DIR to common init_env(), to avoid above problem, and init_env() can be used to add more things in future. Signed-off-by: Zhao Lei Signed-off-by: David Sterba --- tests/common | 7 +++++++ tests/convert-tests.sh | 1 - tests/fsck-tests.sh | 3 --- tests/fsck-tests/012-leaf-corruption/test.sh | 1 - tests/fsck-tests/013-extent-tree-rebuild/test.sh | 5 ----- tests/misc-tests.sh | 3 --- tests/misc-tests/001-btrfstune-features/test.sh | 5 ----- tests/misc-tests/002-uuid-rewrite/test.sh | 5 ----- tests/misc-tests/003-zero-log/test.sh | 5 ----- 9 files changed, 7 insertions(+), 28 deletions(-) (limited to 'tests') diff --git a/tests/common b/tests/common index cf463e82..c5979159 100644 --- a/tests/common +++ b/tests/common @@ -171,3 +171,10 @@ prepare_test_dev() truncate -s "$size" "$TEST_DEV" || _not_run "create file for loop device failed" } +init_env() +{ + TEST_MNT="${TEST_MNT:-$TOP/tests/mnt}" + export TEST_MNT + mkdir -p "$TEST_MNT" || { echo "Failed mkdir -p $TEST_MNT"; exit 1; } +} +init_env diff --git a/tests/convert-tests.sh b/tests/convert-tests.sh index b395e25e..68c03dc6 100755 --- a/tests/convert-tests.sh +++ b/tests/convert-tests.sh @@ -9,7 +9,6 @@ unset LANG LANG=C SCRIPT_DIR=$(dirname $(readlink -f $0)) TOP=$(readlink -f $SCRIPT_DIR/../) -TEST_MNT=${TEST_MNT:-$TOP/tests/mnt} RESULTS="$TOP/tests/convert-tests-results.txt" IMAGE="$TOP/tests/test.img" diff --git a/tests/fsck-tests.sh b/tests/fsck-tests.sh index 73538fec..b910e851 100755 --- a/tests/fsck-tests.sh +++ b/tests/fsck-tests.sh @@ -11,7 +11,6 @@ LANG=C SCRIPT_DIR=$(dirname $(readlink -f $0)) TOP=$(readlink -f $SCRIPT_DIR/../) TEST_DEV=${TEST_DEV:-} -TEST_MNT=${TEST_MNT:-$TOP/tests/mnt} RESULTS="$TOP/tests/fsck-tests-results.txt" source $TOP/tests/common @@ -20,11 +19,9 @@ source $TOP/tests/common export TOP export RESULTS # For custom script needs to verfiy recovery -export TEST_MNT export LANG rm -f $RESULTS -mkdir -p $TEST_MNT || _fail "unable to create mount point on $TEST_MNT" # test rely on corrupting blocks tool check_prereq btrfs-corrupt-block diff --git a/tests/fsck-tests/012-leaf-corruption/test.sh b/tests/fsck-tests/012-leaf-corruption/test.sh index f8701ad7..a37ceda7 100755 --- a/tests/fsck-tests/012-leaf-corruption/test.sh +++ b/tests/fsck-tests/012-leaf-corruption/test.sh @@ -85,7 +85,6 @@ check_inode() check_leaf_corrupt_no_data_ext() { image=$1 - mkdir -p $TEST_MNT || _fail "failed to create mount point" $SUDO_HELPER mount -o loop $image -o ro $TEST_MNT i=0 diff --git a/tests/fsck-tests/013-extent-tree-rebuild/test.sh b/tests/fsck-tests/013-extent-tree-rebuild/test.sh index 88a66cc2..b7909d28 100755 --- a/tests/fsck-tests/013-extent-tree-rebuild/test.sh +++ b/tests/fsck-tests/013-extent-tree-rebuild/test.sh @@ -7,11 +7,6 @@ check_prereq mkfs.btrfs setup_root_helper prepare_test_dev 1G -if [ -z $TEST_MNT ];then - echo " [NOTRUN] extent tree rebuild, need TEST_MNT variant" - exit 0 -fi - # test whether fsck can rebuild a corrupted extent tree test_extent_tree_rebuild() { diff --git a/tests/misc-tests.sh b/tests/misc-tests.sh index 1ed8850e..a87ece28 100755 --- a/tests/misc-tests.sh +++ b/tests/misc-tests.sh @@ -8,7 +8,6 @@ LANG=C SCRIPT_DIR=$(dirname $(readlink -f $0)) TOP=$(readlink -f $SCRIPT_DIR/../) TEST_DEV=${TEST_DEV:-} -TEST_MNT=${TEST_MNT:-$TOP/tests/mnt} RESULTS="$TOP/tests/misc-tests-results.txt" IMAGE="$TOP/tests/test.img" @@ -18,13 +17,11 @@ source $TOP/tests/common export TOP export RESULTS # For custom script needs to verfiy recovery -export TEST_MNT export LANG # For tests that only use a loop device export IMAGE rm -f $RESULTS -mkdir -p $TEST_MNT || _fail "unable to create mount point on $TEST_MNT" # test rely on corrupting blocks tool check_prereq btrfs-corrupt-block diff --git a/tests/misc-tests/001-btrfstune-features/test.sh b/tests/misc-tests/001-btrfstune-features/test.sh index ea33954d..836e8d32 100755 --- a/tests/misc-tests/001-btrfstune-features/test.sh +++ b/tests/misc-tests/001-btrfstune-features/test.sh @@ -9,11 +9,6 @@ check_prereq mkfs.btrfs setup_root_helper prepare_test_dev -if [ -z $TEST_MNT ];then - echo " [NOTRUN] extent tree rebuild, need TEST_MNT variant" - exit 0 -fi - # test whether fsck can rebuild a corrupted extent tree # parameters: # - option for mkfs.btrfs -O, empty for defaults diff --git a/tests/misc-tests/002-uuid-rewrite/test.sh b/tests/misc-tests/002-uuid-rewrite/test.sh index bffa9b85..9b103aaf 100755 --- a/tests/misc-tests/002-uuid-rewrite/test.sh +++ b/tests/misc-tests/002-uuid-rewrite/test.sh @@ -9,11 +9,6 @@ check_prereq mkfs.btrfs check_prereq btrfstune prepare_test_dev -if [ -z $TEST_MNT ];then - echo " [NOTRUN] extent tree rebuild, need TEST_MNT variant" - exit 0 -fi - get_fs_uuid() { local image diff --git a/tests/misc-tests/003-zero-log/test.sh b/tests/misc-tests/003-zero-log/test.sh index edab5dbc..b650930e 100755 --- a/tests/misc-tests/003-zero-log/test.sh +++ b/tests/misc-tests/003-zero-log/test.sh @@ -8,11 +8,6 @@ check_prereq mkfs.btrfs check_prereq btrfs prepare_test_dev -if [ -z $TEST_MNT ];then - echo " [NOTRUN] extent tree rebuild, need TEST_MNT variant" - exit 0 -fi - get_log_root() { local image -- cgit v1.2.3 From 107adbd05d037567d20211732e5c9039853319ed Mon Sep 17 00:00:00 2001 From: Zhao Lei Date: Mon, 31 Aug 2015 13:04:38 +0800 Subject: btrfs-progs: tests: umount TEST_MNT in clean-tests.sh If a testcase failed, we can't run it(or other tests needs mount) again, # ./misc-tests.sh 007 [TEST] 007-subvolume-sync failed: fail test failed for case 007-subvolume-sync # ./misc-tests.sh 007 [TEST] 007-subvolume-sync failed: mount /root/btrfs-progs/tests/test.img /root/btrfs-progs/tests/mnt test failed for case 007-subvolume-sync This patch add "umount $TEST_MNT" to clean-tests.sh, to let user clean mountpoint easily. After patch: # ./misc-tests.sh 007 [TEST] 007-subvolume-sync failed: fail test failed for case 007-subvolume-sync # # clean-tests.sh # # ./misc-tests.sh 007 [TEST] 007-subvolume-sync failed: fail test failed for case 007-subvolume-sync Suggested-by: David Sterba Signed-off-by: Zhao Lei [added sudo helper to umount] Signed-off-by: David Sterba --- tests/clean-tests.sh | 9 +++++++-- 1 file changed, 7 insertions(+), 2 deletions(-) (limited to 'tests') diff --git a/tests/clean-tests.sh b/tests/clean-tests.sh index c1dc56af..f7fefdda 100755 --- a/tests/clean-tests.sh +++ b/tests/clean-tests.sh @@ -1,12 +1,17 @@ #!/bin/sh # remove all intermediate files from tests +SCRIPT_DIR=$(dirname $(readlink -f $0)) +TOP=$(readlink -f $SCRIPT_DIR/../) +source $TOP/tests/common + +setup_root_helper + if [ "$BUILD_VERBOSE" = 1 ]; then verbose=-print fi -SCRIPT_DIR=$(dirname $(readlink -f $0)) -TOP=$(readlink -f $SCRIPT_DIR/../) +$SUDO_HELPER umount "$TEST_MNT" &>/dev/null if ! cd $TOP/tests; then echo "ERROR: cannot cd to $TOP/tests" -- cgit v1.2.3 From 3ca185850bca6e227adf584851343dd69c2aaf05 Mon Sep 17 00:00:00 2001 From: Zhao Lei Date: Tue, 1 Sep 2015 18:03:14 +0800 Subject: btrfs-progs: tests: Use --no-same-owner option for tar Some test failed in my nfs dir: ... [TEST] 006-bad-root-items tar: test.img: Cannot change ownership to uid 1000, gid 1000: Invalid argument tar: Exiting with failure status due to previous errors failed to extract default_case.tar.xz test failed for case 006-bad-root-items It is because the image file's owner is: # tar tvf default_case.tar.xz -rw-r--r-- fdmanana/fdmanana 2147483648 2014-10-17 17:59 test.img And make tar failed in chown in nfs. It is not a big issue because we don't use nfs commonly, but extract the image file with ownership of current user will be a better choice. Signed-off-by: Zhao Lei Signed-off-by: David Sterba --- tests/fsck-tests/006-bad-root-items/test.sh | 4 ++-- tests/fsck-tests/012-leaf-corruption/test.sh | 2 +- 2 files changed, 3 insertions(+), 3 deletions(-) (limited to 'tests') diff --git a/tests/fsck-tests/006-bad-root-items/test.sh b/tests/fsck-tests/006-bad-root-items/test.sh index bfbfcfcc..421e2258 100755 --- a/tests/fsck-tests/006-bad-root-items/test.sh +++ b/tests/fsck-tests/006-bad-root-items/test.sh @@ -3,12 +3,12 @@ source $TOP/tests/common echo "extracting image default_case.tar.xz" >> $RESULTS -tar xJf default_case.tar.xz || \ +tar --no-same-owner -xJf default_case.tar.xz || \ _fail "failed to extract default_case.tar.xz" check_image test.img echo "extracting image skinny_case.tar.xz" >> $RESULTS -tar xJf skinny_case.tar.xz || \ +tar --no-same-owner -xJf skinny_case.tar.xz || \ _fail "failed to extract skinny_case.tar.xz" check_image test.img diff --git a/tests/fsck-tests/012-leaf-corruption/test.sh b/tests/fsck-tests/012-leaf-corruption/test.sh index a37ceda7..6e231451 100755 --- a/tests/fsck-tests/012-leaf-corruption/test.sh +++ b/tests/fsck-tests/012-leaf-corruption/test.sh @@ -35,7 +35,7 @@ generate_leaf_corrupt_no_data_ext() { dest=$1 echo "generating leaf_corrupt_no_data_ext.btrfs-image" >> $RESULTS - tar xJf ./no_data_extent.tar.xz || \ + tar --no-same-owner -xJf ./no_data_extent.tar.xz || \ _fail "failed to extract leaf_corrupt_no_data_ext.btrfs-image" $TOP/btrfs-image -r test.img.btrfs-image $dest || \ _fail "failed to extract leaf_corrupt_no_data_ext.btrfs-image" -- cgit v1.2.3 From 421e41df492f838b9b78db7bfae1315f1f7c7336 Mon Sep 17 00:00:00 2001 From: Zhao Lei Date: Tue, 1 Sep 2015 14:45:22 +0200 Subject: btrfs-progs: tests: introduce test dev mount helpers mount command in old system can not add "-o loop" option automatically for a loop device, and make following test 013-extent-tree-rebuild fail. Considering that $TEST_DEV can be block or loop device, we need to determine our mount option in a condition for both case. Introduce a wrapper that will add the loop options if needed. Signed-off-by: Zhao Lei Signed-off-by: David Sterba --- tests/common | 26 ++++++++++++++++++++++++++ 1 file changed, 26 insertions(+) (limited to 'tests') diff --git a/tests/common b/tests/common index c5979159..63b0d9f6 100644 --- a/tests/common +++ b/tests/common @@ -171,6 +171,32 @@ prepare_test_dev() truncate -s "$size" "$TEST_DEV" || _not_run "create file for loop device failed" } +run_check_mount_test_dev() +{ + setup_root_helper + + local loop_opt + if [[ -b "$TEST_DEV" ]]; then + loop_opt="" + elif [[ -f "$TEST_DEV" ]]; then + loop_opt="-o loop" + else + _fail "Invalid \$TEST_DEV: $TEST_DEV" + fi + + [[ -d "$TEST_MNT" ]] || { + _fail "Invalid \$TEST_MNT: $TEST_MNT" + } + + run_check $SUDO_HELPER mount $loop_opt "$@" "$TEST_DEV" "$TEST_MNT" +} + +run_check_umount_test_dev() +{ + setup_root_helper + run_check $SUDO_HELPER umount "$@" "$TEST_DEV" +} + init_env() { TEST_MNT="${TEST_MNT:-$TOP/tests/mnt}" -- cgit v1.2.3 From d4c4443c2dc417b5ad8d3da8971e1c1996d7b1ed Mon Sep 17 00:00:00 2001 From: Zhao Lei Date: Tue, 1 Sep 2015 14:40:13 +0200 Subject: btrfs-progs: tests: Fix mount fail of 013-extent-tree-rebuild mount command in old system can not add "-o loop" option automatically for loop device, and make following test failed: # ./fsck-tests.sh ... [TEST] 013-extent-tree-rebuild failed: mount /data/btrfsprogs/tests/test.img /data/btrfsprogs/tests/mnt test failed for case 013-extent-tree-rebuild Considering that $TEST_DEV can be block or loop device, we need determine our mount option in a condition for both case. This patch create a wrapper function for above request, to solve current problem in 013-extent-tree-rebuild, and support similar request in future. Signed-off-by: Zhao Lei Signed-off-by: David Sterba --- tests/fsck-tests/013-extent-tree-rebuild/test.sh | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) (limited to 'tests') diff --git a/tests/fsck-tests/013-extent-tree-rebuild/test.sh b/tests/fsck-tests/013-extent-tree-rebuild/test.sh index b7909d28..7419d6ea 100755 --- a/tests/fsck-tests/013-extent-tree-rebuild/test.sh +++ b/tests/fsck-tests/013-extent-tree-rebuild/test.sh @@ -12,14 +12,14 @@ test_extent_tree_rebuild() { run_check $SUDO_HELPER $TOP/mkfs.btrfs -f $TEST_DEV - run_check $SUDO_HELPER mount $TEST_DEV $TEST_MNT + run_check_mount_test_dev run_check $SUDO_HELPER cp -aR /lib/modules/`uname -r`/ $TEST_MNT for i in `seq 1 100`;do run_check $SUDO_HELPER $TOP/btrfs sub snapshot $TEST_MNT \ $TEST_MNT/snapaaaaaaa_$i done - run_check $SUDO_HELPER umount $TEST_DEV + run_check_umount_test_dev # get extent root bytenr extent_root_bytenr=`$SUDO_HELPER $TOP/btrfs-debug-tree -r $TEST_DEV | \ -- cgit v1.2.3 From 34fa747ec86105ec28715a498d0bfd38ff3e8b98 Mon Sep 17 00:00:00 2001 From: Zhao Lei Date: Tue, 1 Sep 2015 18:03:28 +0800 Subject: btrfs-progs: tests: Use mount_test_dev for misc-tests/007-subvolume-sync So this test can support both block device and loop device simply. Signed-off-by: Zhao Lei Signed-off-by: David Sterba --- tests/misc-tests/007-subvolume-sync/test.sh | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) (limited to 'tests') diff --git a/tests/misc-tests/007-subvolume-sync/test.sh b/tests/misc-tests/007-subvolume-sync/test.sh index d4019f43..a745fb56 100755 --- a/tests/misc-tests/007-subvolume-sync/test.sh +++ b/tests/misc-tests/007-subvolume-sync/test.sh @@ -13,7 +13,7 @@ setup_root_helper prepare_test_dev run_check $SUDO_HELPER $TOP/mkfs.btrfs -f "$TEST_DEV" -run_check $SUDO_HELPER mount "$TEST_DEV" "$TEST_MNT" +run_check_mount_test_dev # to check following thing in both 1 and multiple subvolume case: # 1: is subvolume sync loop indefinetelly @@ -29,4 +29,4 @@ run_check $SUDO_HELPER $TOP/btrfs subvolume create "$TEST_MNT"/mysubvol run_check $SUDO_HELPER $TOP/btrfs subvolume delete "$TEST_MNT"/mysubvol run_check $SUDO_HELPER $TOP/btrfs subvolume sync "$TEST_MNT" -run_check $SUDO_HELPER umount $TEST_MNT +run_check_umount_test_dev -- cgit v1.2.3 From a365b84a322f6c5e208c167b3d64a58bfbd726ad Mon Sep 17 00:00:00 2001 From: David Sterba Date: Wed, 9 Sep 2015 17:04:12 +0200 Subject: btrfs-progs: tests: add crafted and fuzzed images A collection of several images that were produced in a non-standard way and cause various errors in check or image tools. They do not fit into the fsck tests as we're not able to repair any of them, but the tools should not crash or do out-of-bounds access. Signed-off-by: David Sterba --- tests/fuzz-tests/images/bad-superblock-1.raw.xz | Bin 0 -> 228 bytes tests/fuzz-tests/images/bad-superblock-2.raw.xz | Bin 0 -> 228 bytes tests/fuzz-tests/images/bad-superblock-3.raw.xz | Bin 0 -> 228 bytes tests/fuzz-tests/images/bad-superblock.txt | 17 +++ .../images/bko-104131-fsck-oob-read.raw.xz | Bin 0 -> 192 bytes .../fuzz-tests/images/bko-104131-fsck-oob-read.txt | 31 +++++ .../images/bko-104141-fsck-exception.raw.xz | Bin 0 -> 196 bytes .../images/bko-104141-fsck-exception.txt | 9 ++ .../images/bko-97191-btrfs-image.raw.txt | 137 +++++++++++++++++++++ .../fuzz-tests/images/bko-97191-btrfs-image.raw.xz | Bin 0 -> 7076 bytes .../images/bko-97271-btrfs-image.raw.txt | 54 ++++++++ .../fuzz-tests/images/bko-97271-btrfs-image.raw.xz | Bin 0 -> 6580 bytes 12 files changed, 248 insertions(+) create mode 100644 tests/fuzz-tests/images/bad-superblock-1.raw.xz create mode 100644 tests/fuzz-tests/images/bad-superblock-2.raw.xz create mode 100644 tests/fuzz-tests/images/bad-superblock-3.raw.xz create mode 100644 tests/fuzz-tests/images/bad-superblock.txt create mode 100644 tests/fuzz-tests/images/bko-104131-fsck-oob-read.raw.xz create mode 100644 tests/fuzz-tests/images/bko-104131-fsck-oob-read.txt create mode 100644 tests/fuzz-tests/images/bko-104141-fsck-exception.raw.xz create mode 100644 tests/fuzz-tests/images/bko-104141-fsck-exception.txt create mode 100644 tests/fuzz-tests/images/bko-97191-btrfs-image.raw.txt create mode 100644 tests/fuzz-tests/images/bko-97191-btrfs-image.raw.xz create mode 100644 tests/fuzz-tests/images/bko-97271-btrfs-image.raw.txt create mode 100644 tests/fuzz-tests/images/bko-97271-btrfs-image.raw.xz (limited to 'tests') diff --git a/tests/fuzz-tests/images/bad-superblock-1.raw.xz b/tests/fuzz-tests/images/bad-superblock-1.raw.xz new file mode 100644 index 00000000..3d6358f0 Binary files /dev/null and b/tests/fuzz-tests/images/bad-superblock-1.raw.xz differ diff --git a/tests/fuzz-tests/images/bad-superblock-2.raw.xz b/tests/fuzz-tests/images/bad-superblock-2.raw.xz new file mode 100644 index 00000000..7db7610b Binary files /dev/null and b/tests/fuzz-tests/images/bad-superblock-2.raw.xz differ diff --git a/tests/fuzz-tests/images/bad-superblock-3.raw.xz b/tests/fuzz-tests/images/bad-superblock-3.raw.xz new file mode 100644 index 00000000..4aa31483 Binary files /dev/null and b/tests/fuzz-tests/images/bad-superblock-3.raw.xz differ diff --git a/tests/fuzz-tests/images/bad-superblock.txt b/tests/fuzz-tests/images/bad-superblock.txt new file mode 100644 index 00000000..f7dd9aa0 --- /dev/null +++ b/tests/fuzz-tests/images/bad-superblock.txt @@ -0,0 +1,17 @@ +bad-superblock-*.txt + +Crafted images from Jiri Slaby, produced by some symbolic execution framework +that finds unhandled cases at mount time. + +Relevant kernel patches to backport: + +e3540eab29e1b2260bc4b9b3979a49a00e3e3af8 +btrfs: add more checks to btrfs_read_sys_array + +ce7fca5f57ed0fcd7e7b3d7b1a3e1791f8e56fa3 +btrfs: add checks for sys_chunk_array sizes + +75d6ad382bb91f363452119d34238e156589ca2d +btrfs: more superblock checks, lower bounds on devices and sectorsize/nodesize + +(and more from fs/btrfs/super.c) diff --git a/tests/fuzz-tests/images/bko-104131-fsck-oob-read.raw.xz b/tests/fuzz-tests/images/bko-104131-fsck-oob-read.raw.xz new file mode 100644 index 00000000..7848f8b1 Binary files /dev/null and b/tests/fuzz-tests/images/bko-104131-fsck-oob-read.raw.xz differ diff --git a/tests/fuzz-tests/images/bko-104131-fsck-oob-read.txt b/tests/fuzz-tests/images/bko-104131-fsck-oob-read.txt new file mode 100644 index 00000000..0e829c2e --- /dev/null +++ b/tests/fuzz-tests/images/bko-104131-fsck-oob-read.txt @@ -0,0 +1,31 @@ +URL: https://bugzilla.kernel.org/show_bug.cgi?id=104131 +Hanno Boeck 2015-09-07 07:24:32 UTC + +Created attachment 186941 [details] +malformed btrfs filesystem causing oob read + +The attached malformed filesystem image will cause an invalid heap out of bounds memory read in btrfsck. + +This was found while fuzzing btrfs-progs with american fuzzy lop. + +Stack trace from Address Sanitizer: +==31289==ERROR: AddressSanitizer: heap-buffer-overflow on address 0x60f00000f003 at pc 0x0000005d0dbb bp 0x7ffdf444c180 sp 0x7ffdf444c178 +READ of size 8 at 0x60f00000f003 thread T0 + #0 0x5d0dba in btrfs_header_bytenr /mnt/ram/btrfs-progs-v4.1.2/./ctree.h:1797:1 + #1 0x5d0dba in check_tree_block /mnt/ram/btrfs-progs-v4.1.2/disk-io.c:60 + #2 0x5d0dba in read_tree_block /mnt/ram/btrfs-progs-v4.1.2/disk-io.c:337 + #3 0x5dc00e in btrfs_setup_chunk_tree_and_device_map /mnt/ram/btrfs-progs-v4.1.2/disk-io.c:1169:30 + #4 0x5dcf89 in __open_ctree_fd /mnt/ram/btrfs-progs-v4.1.2/disk-io.c:1261:8 + #5 0x5dc50a in open_ctree_fs_info /mnt/ram/btrfs-progs-v4.1.2/disk-io.c:1302:9 + #6 0x52f22f in cmd_check /mnt/ram/btrfs-progs-v4.1.2/cmds-check.c:9333:9 + #7 0x4e7bcc in main /mnt/ram/btrfs-progs-v4.1.2/btrfs.c:245:7 + #8 0x7f98bb101f9f in __libc_start_main /var/tmp/portage/sys-libs/glibc-2.20-r2/work/glibc-2.20/csu/libc-start.c:289 + #9 0x41f748 in _start (/mnt/ram/btrfs/btrfs+0x41f748) + +0x60f00000f003 is located 3 bytes to the right of 176-byte region [0x60f00000ef50,0x60f00000f000) +allocated by thread T0 here: + #0 0x4bade8 in malloc (/mnt/ram/btrfs/btrfs+0x4bade8) + #1 0x622c24 in __alloc_extent_buffer /mnt/ram/btrfs-progs-v4.1.2/extent_io.c:541:7 + #2 0x622c24 in alloc_extent_buffer /mnt/ram/btrfs-progs-v4.1.2/extent_io.c:648 + #3 0x5cf436 in btrfs_find_create_tree_block /mnt/ram/btrfs-progs-v4.1.2/disk-io.c:186:9 + #4 0x5cf436 in read_tree_block /mnt/ram/btrfs-progs-v4.1.2/disk-io.c:314 diff --git a/tests/fuzz-tests/images/bko-104141-fsck-exception.raw.xz b/tests/fuzz-tests/images/bko-104141-fsck-exception.raw.xz new file mode 100644 index 00000000..d24a32f8 Binary files /dev/null and b/tests/fuzz-tests/images/bko-104141-fsck-exception.raw.xz differ diff --git a/tests/fuzz-tests/images/bko-104141-fsck-exception.txt b/tests/fuzz-tests/images/bko-104141-fsck-exception.txt new file mode 100644 index 00000000..aed91909 --- /dev/null +++ b/tests/fuzz-tests/images/bko-104141-fsck-exception.txt @@ -0,0 +1,9 @@ +URL: https://bugzilla.kernel.org/show_bug.cgi?id=104141 +Hanno Boeck 2015-09-07 07:27:58 UTC + +Created attachment 186951 [details] +malformed filesystem causing floating point exception + +The attacked file will cause a floating point exception in btrfsck. + +This was found while fuzzing btrfs-progs with american fuzzy lop. diff --git a/tests/fuzz-tests/images/bko-97191-btrfs-image.raw.txt b/tests/fuzz-tests/images/bko-97191-btrfs-image.raw.txt new file mode 100644 index 00000000..f0d81894 --- /dev/null +++ b/tests/fuzz-tests/images/bko-97191-btrfs-image.raw.txt @@ -0,0 +1,137 @@ +URL: https://bugzilla.kernel.org/show_bug.cgi?id=97191 +Lukas Lueg 2015-04-23 22:20:35 UTC + +Running btrfs-progs v3.19.1 + +The btrfs-image attached to this bug causes the btrfs-userland tool to +overflow some data structures, leading to unallocated memory being written to +and read from. A segfault results shortly after. Reproduced on x86-64 and +i686. + +The kernel seems to be less affected and fails to mount the image. I didn't +investigate whether the reads/writes could be used to gain control over $EIP. +Since the first invalid write of 8 bytes seems to run into adjacent heap +blocks (crash in unlink()), it may be possible though. + +gdb output: + +Program received signal SIGSEGV, Segmentation fault. +malloc_consolidate (av=av@entry=0x32629b7cc0 ) at malloc.c:4151 +4151 unlink(av, p, bck, fwd); +(gdb) bt +#0 malloc_consolidate (av=av@entry=0x32629b7cc0 ) at malloc.c:4151 +#1 0x0000003262680628 in _int_malloc (av=av@entry=0x32629b7cc0 , bytes=bytes@entry=4224) at malloc.c:3420 +#2 0x000000326268315e in __GI___libc_malloc (bytes=4224) at malloc.c:2896 +#3 0x0000000000449d15 in __alloc_extent_buffer (tree=0x88c078, bytenr=4288512, blocksize=4096) at extent_io.c:541 +#4 0x000000000044a8b4 in alloc_extent_buffer (tree=0x88c078, bytenr=4288512, blocksize=4096) at extent_io.c:648 +#5 0x000000000043b1a0 in btrfs_find_create_tree_block (root=root@entry=0x895840, bytenr=, + blocksize=) at disk-io.c:159 +#6 0x000000000043ca4e in read_tree_block (root=root@entry=0x895840, bytenr=, blocksize=, + parent_transid=13) at disk-io.c:287 +#7 0x000000000043ccb7 in find_and_setup_root (tree_root=0x88c250, fs_info=, objectid=5, root=0x895840) + at disk-io.c:557 +#8 0x000000000043ce92 in btrfs_read_fs_root_no_cache (fs_info=fs_info@entry=0x88c010, location=location@entry=0x7fffffffd960) + at disk-io.c:640 +#9 0x000000000043d060 in btrfs_read_fs_root (fs_info=fs_info@entry=0x88c010, location=location@entry=0x7fffffffd960) + at disk-io.c:739 +#10 0x000000000043d48c in btrfs_setup_all_roots (fs_info=fs_info@entry=0x88c010, root_tree_bytenr=, + root_tree_bytenr@entry=0, flags=flags@entry=OPEN_CTREE_EXCLUSIVE) at disk-io.c:988 +#11 0x000000000043d802 in __open_ctree_fd (fp=fp@entry=3, path=path@entry=0x7fffffffe20d "ramdisk/btrfs_fukked.bin", + sb_bytenr=65536, sb_bytenr@entry=0, root_tree_bytenr=root_tree_bytenr@entry=0, flags=flags@entry=OPEN_CTREE_EXCLUSIVE) + at disk-io.c:1199 +#12 0x000000000043d965 in open_ctree_fs_info (filename=0x7fffffffe20d "ramdisk/btrfs_fukked.bin", sb_bytenr=sb_bytenr@entry=0, + root_tree_bytenr=root_tree_bytenr@entry=0, flags=flags@entry=OPEN_CTREE_EXCLUSIVE) at disk-io.c:1231 +#13 0x0000000000427bf5 in cmd_check (argc=1, argv=0x7fffffffdea0) at cmds-check.c:9326 +#14 0x000000000040e5a2 in main (argc=2, argv=0x7fffffffdea0) at btrfs.c:245 + + +valgrind output: + +==32463== Memcheck, a memory error detector +==32463== Copyright (C) 2002-2013, and GNU GPL'd, by Julian Seward et al. +==32463== Using Valgrind-3.10.1 and LibVEX; rerun with -h for copyright info +==32463== Command: btrfs check ramdisk/btrfs_fukked.bin +==32463== +==32463== Invalid write of size 8 +==32463== at 0x4386FB: btrfs_search_slot (ctree.c:1119) +==32463== by 0x4427F7: UnknownInlinedFun (extent-tree.c:3117) +==32463== by 0x4427F7: btrfs_read_block_groups (extent-tree.c:3167) +==32463== by 0x43D4F2: btrfs_setup_all_roots (disk-io.c:983) +==32463== by 0x43D801: __open_ctree_fd (disk-io.c:1199) +==32463== by 0x43D964: open_ctree_fs_info (disk-io.c:1231) +==32463== by 0x427BF4: cmd_check (cmds-check.c:9326) +==32463== by 0x40E5A1: main (btrfs.c:245) +==32463== Address 0x4c409f0 is 16 bytes after a block of size 144 alloc'd +==32463== at 0x4A08946: calloc (in /usr/lib64/valgrind/vgpreload_memcheck-amd64-linux.so) +==32463== by 0x4427AB: btrfs_read_block_groups (extent-tree.c:3162) +==32463== by 0x43D4F2: btrfs_setup_all_roots (disk-io.c:983) +==32463== by 0x43D801: __open_ctree_fd (disk-io.c:1199) +==32463== by 0x43D964: open_ctree_fs_info (disk-io.c:1231) +==32463== by 0x427BF4: cmd_check (cmds-check.c:9326) +==32463== by 0x40E5A1: main (btrfs.c:245) +==32463== +==32463== Invalid read of size 8 +==32463== at 0x436E70: check_block.part.14 (ctree.c:548) +==32463== by 0x438954: UnknownInlinedFun (kerncompat.h:91) +==32463== by 0x438954: btrfs_search_slot (ctree.c:1120) +==32463== by 0x4427F7: UnknownInlinedFun (extent-tree.c:3117) +==32463== by 0x4427F7: btrfs_read_block_groups (extent-tree.c:3167) +==32463== by 0x43D4F2: btrfs_setup_all_roots (disk-io.c:983) +==32463== by 0x43D801: __open_ctree_fd (disk-io.c:1199) +==32463== by 0x43D964: open_ctree_fs_info (disk-io.c:1231) +==32463== by 0x427BF4: cmd_check (cmds-check.c:9326) +==32463== by 0x40E5A1: main (btrfs.c:245) +==32463== Address 0x4c409f8 is 24 bytes after a block of size 144 in arena "client" +==32463== +==32463== Invalid read of size 4 +==32463== at 0x436E84: UnknownInlinedFun (ctree.h:1605) +==32463== by 0x436E84: UnknownInlinedFun (ctree.h:1612) +==32463== by 0x436E84: check_block.part.14 (ctree.c:550) +==32463== by 0x438954: UnknownInlinedFun (kerncompat.h:91) +==32463== by 0x438954: btrfs_search_slot (ctree.c:1120) +==32463== by 0x4427F7: UnknownInlinedFun (extent-tree.c:3117) +==32463== by 0x4427F7: btrfs_read_block_groups (extent-tree.c:3167) +==32463== by 0x43D4F2: btrfs_setup_all_roots (disk-io.c:983) +==32463== by 0x43D801: __open_ctree_fd (disk-io.c:1199) +==32463== by 0x43D964: open_ctree_fs_info (disk-io.c:1231) +==32463== by 0x427BF4: cmd_check (cmds-check.c:9326) +==32463== by 0x40E5A1: main (btrfs.c:245) +==32463== Address 0x4c409e4 is 4 bytes after a block of size 144 alloc'd +==32463== at 0x4A08946: calloc (in /usr/lib64/valgrind/vgpreload_memcheck-amd64-linux.so) +==32463== by 0x4427AB: btrfs_read_block_groups (extent-tree.c:3162) +==32463== by 0x43D4F2: btrfs_setup_all_roots (disk-io.c:983) +==32463== by 0x43D801: __open_ctree_fd (disk-io.c:1199) +==32463== by 0x43D964: open_ctree_fs_info (disk-io.c:1231) +==32463== by 0x427BF4: cmd_check (cmds-check.c:9326) +==32463== by 0x40E5A1: main (btrfs.c:245) +==32463== +==32463== Invalid read of size 1 +==32463== at 0x4A0B3A0: memcpy@@GLIBC_2.14 (in /usr/lib64/valgrind/vgpreload_memcheck-amd64-linux.so) +==32463== by 0x436E99: UnknownInlinedFun (ctree.h:1613) +==32463== by 0x436E99: check_block.part.14 (ctree.c:550) +==32463== by 0x438954: UnknownInlinedFun (kerncompat.h:91) +==32463== by 0x438954: btrfs_search_slot (ctree.c:1120) +==32463== by 0x4427F7: UnknownInlinedFun (extent-tree.c:3117) +==32463== by 0x4427F7: btrfs_read_block_groups (extent-tree.c:3167) +==32463== by 0x43D4F2: btrfs_setup_all_roots (disk-io.c:983) +==32463== by 0x43D801: __open_ctree_fd (disk-io.c:1199) +==32463== by 0x43D964: open_ctree_fs_info (disk-io.c:1231) +==32463== by 0x427BF4: cmd_check (cmds-check.c:9326) +==32463== by 0x40E5A1: main (btrfs.c:245) +==32463== Address 0x1b1 is not stack'd, malloc'd or (recently) free'd +==32463== +==32463== +==32463== Process terminating with default action of signal 11 (SIGSEGV) +==32463== Access not within mapped region at address 0x1B1 +==32463== at 0x4A0B3A0: memcpy@@GLIBC_2.14 (in /usr/lib64/valgrind/vgpreload_memcheck-amd64-linux.so) +==32463== by 0x436E99: UnknownInlinedFun (ctree.h:1613) +==32463== by 0x436E99: check_block.part.14 (ctree.c:550) +==32463== by 0x438954: UnknownInlinedFun (kerncompat.h:91) +==32463== by 0x438954: btrfs_search_slot (ctree.c:1120) +==32463== by 0x4427F7: UnknownInlinedFun (extent-tree.c:3117) +==32463== by 0x4427F7: btrfs_read_block_groups (extent-tree.c:3167) +==32463== by 0x43D4F2: btrfs_setup_all_roots (disk-io.c:983) +==32463== by 0x43D801: __open_ctree_fd (disk-io.c:1199) +==32463== by 0x43D964: open_ctree_fs_info (disk-io.c:1231) +==32463== by 0x427BF4: cmd_check (cmds-check.c:9326) +==32463== by 0x40E5A1: main (btrfs.c:245) diff --git a/tests/fuzz-tests/images/bko-97191-btrfs-image.raw.xz b/tests/fuzz-tests/images/bko-97191-btrfs-image.raw.xz new file mode 100644 index 00000000..b2e48c08 Binary files /dev/null and b/tests/fuzz-tests/images/bko-97191-btrfs-image.raw.xz differ diff --git a/tests/fuzz-tests/images/bko-97271-btrfs-image.raw.txt b/tests/fuzz-tests/images/bko-97271-btrfs-image.raw.txt new file mode 100644 index 00000000..67f20968 --- /dev/null +++ b/tests/fuzz-tests/images/bko-97271-btrfs-image.raw.txt @@ -0,0 +1,54 @@ +URL: https://bugzilla.kernel.org/show_bug.cgi?id=97271 +Lukas Lueg 2015-04-25 20:34:39 UTC + +The attached btrfs-image causes "btrfs check" to write outside of allocated +memory locations and ultimately die due to a segfault. An adjacent heap block's +control structure is overwritten with a `struct extent_buffer *`, which is not +controllable by the user. + +"btrfs version" is v3.19.1. Running "btrfs check" immediately dies with + +*** Error in `btrfs': double free or corruption (!prev): 0x0000000002396ec0 *** +*** Error in `btrfs': malloc(): memory corruption: 0x0000000002396f60 *** + +Debugging with valgrind and gdb gives + +==11670== Invalid write of size 8 +==11670== at 0x4386FB: btrfs_search_slot (ctree.c:1119) +==11670== by 0x44E16E: btrfs_read_chunk_tree (volumes.c:1814) +==11670== by 0x43D654: btrfs_setup_chunk_tree_and_device_map (disk-io.c:1115) +==11670== by 0x43D7D0: __open_ctree_fd (disk-io.c:1190) +==11670== by 0x43D964: open_ctree_fs_info (disk-io.c:1231) +==11670== by 0x427BF4: cmd_check (cmds-check.c:9326) +==11670== by 0x40E5A1: main (btrfs.c:245) +==11670== Address 0x4c3bb98 is 8 bytes after a block of size 144 alloc'd +==11670== at 0x4A08946: calloc (in /usr/lib64/valgrind/vgpreload_memcheck-amd64-linux.so) +==11670== by 0x44E133: btrfs_read_chunk_tree (volumes.c:1801) +==11670== by 0x43D654: btrfs_setup_chunk_tree_and_device_map (disk-io.c:1115) +==11670== by 0x43D7D0: __open_ctree_fd (disk-io.c:1190) +==11670== by 0x43D964: open_ctree_fs_info (disk-io.c:1231) +==11670== by 0x427BF4: cmd_check (cmds-check.c:9326) +==11670== by 0x40E5A1: main (btrfs.c:245) + +Program received signal SIGTRAP, Trace/breakpoint trap. +btrfs_search_slot (trans=trans@entry=0x0, root=root@entry=0x4c36d30, key=key@entry=0xffefff830, p=p@entry=0x4c3bb00, + ins_len=ins_len@entry=0, cow=cow@entry=0) at ctree.c:1119 +1119 p->nodes[level] = b; +(gdb) p p->nodes +$1 = {0x0, 0x0, 0x0, 0x0, 0x0, 0x0, 0x0, 0x0} +(gdb) p p +$2 = (struct btrfs_path *) 0x4c3bb00 +(gdb) p b +$3 = (struct extent_buffer *) 0x4c3a990 + + +The corresponding part in ctree.c:btrfs_search_slot() seems to fail to check if `level` overflows outside of `node`: + +level = btrfs_header_level(b); +... +if (level != btrfs_header_level(b)) + WARN_ON(1); +level = btrfs_header_level(b); +p->nodes[level] = b; // <- Illegal write + +Maybe the repeated calls to btrfs_header_level() were meant to do something once, they seem to be noise. diff --git a/tests/fuzz-tests/images/bko-97271-btrfs-image.raw.xz b/tests/fuzz-tests/images/bko-97271-btrfs-image.raw.xz new file mode 100644 index 00000000..3c79edb5 Binary files /dev/null and b/tests/fuzz-tests/images/bko-97271-btrfs-image.raw.xz differ -- cgit v1.2.3 From ebd6d2e68373a0e4ac38c384a618263d56386584 Mon Sep 17 00:00:00 2001 From: Zhao Lei Date: Tue, 15 Sep 2015 17:22:17 +0800 Subject: btrfs-progs: tests: Add '-o loop' to mount command line in convert-tests.sh To fix following bug: # ./convert-tests.sh [TEST] ext2 4k nodesize, btrfs defaults failed: mount /root/btrfsprogs/tests/test.img /root/btrfsprogs/tests/mnt # tail convert-tests-results.txt ... ############### mount /root/btrfsprogs/tests/test.img /root/btrfsprogs/tests/mnt mount: /root/btrfsprogs/tests/test.img is not a block device (maybe try `-o loop'?) failed: mount /root/btrfsprogs/tests/test.img /root/btrfsprogs/tests/mnt Signed-off-by: Zhao Lei Signed-off-by: David Sterba --- tests/convert-tests.sh | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) (limited to 'tests') diff --git a/tests/convert-tests.sh b/tests/convert-tests.sh index 68c03dc6..4d99a61c 100755 --- a/tests/convert-tests.sh +++ b/tests/convert-tests.sh @@ -42,7 +42,7 @@ convert_test() { # create a file to check btrfs-convert can convert regular file # correct - run_check $SUDO_HELPER mount $IMAGE $TEST_MNT + run_check $SUDO_HELPER mount -o loop $IMAGE $TEST_MNT run_check $SUDO_HELPER dd if=/dev/zero of=$TEST_MNT/test bs=$nodesize \ count=1 1>/dev/null 2>&1 run_check $SUDO_HELPER umount $TEST_MNT -- cgit v1.2.3 From 5627eee02b6e8b0a933ae88767e998923eb359f8 Mon Sep 17 00:00:00 2001 From: Zhao Lei Date: Wed, 23 Sep 2015 15:19:04 +0800 Subject: btrfs-progs: tests: Move extract_image out of check_all_images for common use Move code for extract image file to a function from check_all_images() for common use, so caller can use this function to extrace single image file. Signed-off-by: Zhao Lei [minor reformatting and updates] Signed-off-by: David Sterba --- tests/common | 82 +++++++++++++++++++++++++++++++++++------------------------- 1 file changed, 48 insertions(+), 34 deletions(-) (limited to 'tests') diff --git a/tests/common b/tests/common index 63b0d9f6..67d15588 100644 --- a/tests/common +++ b/tests/common @@ -62,51 +62,65 @@ check_image() run_check $TOP/btrfs check $image } -# Process all image dumps in a given directory, +# Extract a usable image from packed formats # - raw btrfs filesystem images, suffix .raw # - dtto compressed by XZ, suffix .raw.xz # - meta-dump images with suffix .img # - dtto compressed by XZ, suffix .img.xz +extract_image() +{ + local image + local cleanme + + image="$1" + case "$image" in + *.img) + rm -f $image.restored + : ;; + *.img.xz) + xz --decompress --keep "$image" || \ + _fail "failed to decompress image $image" >&2 + image=${image%%.xz} + rm -f $image.restored + cleanme=$image + ;; + *.raw) + cp --sparse=auto $image $image.restored + ;; + *.raw.xz) + xz --decompress --keep "$image" || \ + _fail "failed to decompress image $image" >&2 + image=${image%%.xz} + mv "$image" "$image".restored + ;; + esac + + if ! [ -f $image.restored ]; then + echo "restoring image $(basename $image)" >> $RESULTS + $TOP/btrfs-image -r $image $image.restored || \ + _fail "failed to restore image $image" >&2 + fi + + [ -f "$cleanme" ] && rm -f "$cleanme" + + echo "$image.restored" +} + +# Process all image dumps in a given directory check_all_images() { - dir=$1 + local dir + local extracted + + dir="$1" for image in $(find $dir \( -iname '*.img' -o \ -iname '*.img.xz' -o \ -iname '*.raw' -o \ -iname '*.raw.xz' \) | sort) do - cleanme= - case "$image" in - *.img) - rm -f $image.restored - : ;; - *.img.xz) - xz --decompress --keep "$image" || \ - _fail "failed to decompress image $image" - image=${image%%.xz} - rm -f $image.restored - cleanme=$image - ;; - *.raw) - cp --sparse=auto $image $image.restored - ;; - *.raw.xz) - xz --decompress --keep "$image" || \ - _fail "failed to decompress image $image" - image=${image%%.xz} - mv "$image" "$image".restored - ;; - esac - - if ! [ -f $image.restored ]; then - echo "restoring image $(basename $image)" >> $RESULTS - $TOP/btrfs-image -r $image $image.restored || \ - _fail "failed to restore image $image" - fi - - check_image $image.restored - - rm -f $image.restored $cleanme + extracted=$(extract_image "$image") + check_image "$extracted" + rm -f "$extracted" done } -- cgit v1.2.3 From 5f77daa6a1673b130a566130144c80ce86ed1d0d Mon Sep 17 00:00:00 2001 From: Zhao Lei Date: Wed, 23 Sep 2015 15:19:05 +0800 Subject: btrfs-progs: tests: Introduce fsck-tests/018-leaf-crossing-stripes To test if fsck can check detec "leaf crossing stripes". This function was introduced from patch titled: btrfs-progs: fsck: Check if a metadata tree block crossing stripe boundary Signed-off-by: Zhao Lei [renamed and other minor changes] Signed-off-by: David Sterba --- .../018-leaf-crossing-stripes/default_case.raw.xz | Bin 0 -> 105064 bytes tests/fsck-tests/018-leaf-crossing-stripes/test.sh | 12 ++++++++++++ 2 files changed, 12 insertions(+) create mode 100644 tests/fsck-tests/018-leaf-crossing-stripes/default_case.raw.xz create mode 100755 tests/fsck-tests/018-leaf-crossing-stripes/test.sh (limited to 'tests') diff --git a/tests/fsck-tests/018-leaf-crossing-stripes/default_case.raw.xz b/tests/fsck-tests/018-leaf-crossing-stripes/default_case.raw.xz new file mode 100644 index 00000000..60eb2f97 Binary files /dev/null and b/tests/fsck-tests/018-leaf-crossing-stripes/default_case.raw.xz differ diff --git a/tests/fsck-tests/018-leaf-crossing-stripes/test.sh b/tests/fsck-tests/018-leaf-crossing-stripes/test.sh new file mode 100755 index 00000000..c453ab5c --- /dev/null +++ b/tests/fsck-tests/018-leaf-crossing-stripes/test.sh @@ -0,0 +1,12 @@ +#!/bin/bash + +source $TOP/tests/common + +check_prereq btrfs + +image=$(extract_image "./default_case.raw.xz") +run_check_stdout $TOP/btrfs check "$image" 2>&1 | + grep -q "crossing stripe boundary" || + _fail "no expected error message in the output" + +rm -f "$image" -- cgit v1.2.3 From 9e0c8e148d5d7240e540f825546a434a24ac2660 Mon Sep 17 00:00:00 2001 From: Zhao Lei Date: Wed, 23 Sep 2015 15:19:06 +0800 Subject: btrfs-progs: tests: Introduce misc-tests/008-leaf-crossing-stripes To check is btrfs-convert create bad filesystem with leaf across stripes. It is happened in progs version <=v4.1.2, and fixed by patch titled: btrfs: convert: Avoid allocating metadata extent crossing stripe boundary which was merged in v4.2. Notice thar this testcase can not report error in old version of btrfs-progs, because "btrfs check" can't check this type of error in those version, but we have another testcase in fsck-tests, to check is "btrfs check" support this check. So, the above 2 testcase together can check leaf-crossing-stripes bug in all versions. Signed-off-by: Zhao Lei [renamed and other minor changes] Signed-off-by: David Sterba --- tests/misc-tests/008-leaf-crossing-stripes/test.sh | 25 ++++++++++++++++++++++ 1 file changed, 25 insertions(+) create mode 100755 tests/misc-tests/008-leaf-crossing-stripes/test.sh (limited to 'tests') diff --git a/tests/misc-tests/008-leaf-crossing-stripes/test.sh b/tests/misc-tests/008-leaf-crossing-stripes/test.sh new file mode 100755 index 00000000..03818062 --- /dev/null +++ b/tests/misc-tests/008-leaf-crossing-stripes/test.sh @@ -0,0 +1,25 @@ +#!/bin/bash +# test if btrfs-convert creates a filesystem without leaf crossing stripes + +source $TOP/tests/common + +check_prereq btrfs-convert +check_prereq btrfs + +# In my test, it happened in 514M~560M, 737M~769M, 929M~917M, +# and HAVE_ERROR=((size + 1) / 2) % 2 if size >= 970 +# +SIZE_FROM=514 +SIZE_END=560 +A_PRIME_NUM=17 +for ((size = SIZE_FROM; size <= SIZE_END; size += A_PRIME_NUM)); do + run_check truncate -s "$size"M "$IMAGE" + run_check mkfs.ext4 -F "$IMAGE" + run_check $TOP/btrfs-convert "$IMAGE" + run_check_stdout $TOP/btrfs check "$IMAGE" 2>&1 | + grep -q "crossing stripe boundary" && + _fail "leaf crossing stripes after btrfs-convert" +done + +# grep will expectedly fail +exit 0 -- cgit v1.2.3 From 9c3ce57e6bdb8f6af86e2c517bc8ea713e93a2c2 Mon Sep 17 00:00:00 2001 From: Zhao Lei Date: Tue, 28 Jul 2015 10:28:13 +0800 Subject: btrfs-progs: tests: Avoid printing useless warning in fsck tests 002-bad-transid outout 'transid verify failed' message in screen which is just a warning in btrfs-image in normal condition of this test. This patch move above warning into $RESULTS, to: 1: Avoid trouble screen output 2: Let user known detail if other error happened in btrfs-image Before patch: # ./fsck-tests.sh [TEST] 001-bad-file-extent-bytenr [TEST] 002-bad-transid parent transid verify failed on 29360128 wanted 9 found 755944791 parent transid verify failed on 29360128 wanted 9 found 755944791 Ignoring transid failure [TEST] 003-shift-offsets [TEST] 004-no-dir-index ... After patch: # ./fsck-tests.sh [TEST] 001-bad-file-extent-bytenr [TEST] 002-bad-transid [TEST] 003-shift-offsets [TEST] 004-no-dir-index ... Signed-off-by: Zhao Lei Signed-off-by: David Sterba --- tests/common | 5 +++-- 1 file changed, 3 insertions(+), 2 deletions(-) (limited to 'tests') diff --git a/tests/common b/tests/common index 67d15588..45713506 100644 --- a/tests/common +++ b/tests/common @@ -97,8 +97,9 @@ extract_image() if ! [ -f $image.restored ]; then echo "restoring image $(basename $image)" >> $RESULTS - $TOP/btrfs-image -r $image $image.restored || \ - _fail "failed to restore image $image" >&2 + $TOP/btrfs-image -r $image $image.restored \ + &>> $RESULTS \ + || _fail "failed to restore image $image" >&2 fi [ -f "$cleanme" ] && rm -f "$cleanme" -- cgit v1.2.3 From 982950b74b7754a99e8a2d302a57b1b4348f7574 Mon Sep 17 00:00:00 2001 From: David Sterba Date: Tue, 6 Oct 2015 13:11:09 +0200 Subject: btrfs-progs: misc tests: add 009-subvolume-sync-must-wait Test to verify that subovolume sync waits until the subvolume is cleaned. Signed-off-by: David Sterba --- .../009-subvolume-sync-must-wait/test.sh | 50 ++++++++++++++++++++++ 1 file changed, 50 insertions(+) create mode 100755 tests/misc-tests/009-subvolume-sync-must-wait/test.sh (limited to 'tests') diff --git a/tests/misc-tests/009-subvolume-sync-must-wait/test.sh b/tests/misc-tests/009-subvolume-sync-must-wait/test.sh new file mode 100755 index 00000000..66d38ea5 --- /dev/null +++ b/tests/misc-tests/009-subvolume-sync-must-wait/test.sh @@ -0,0 +1,50 @@ +#!/bin/bash +# +# Verify that subovolume sync waits until the subvolume is cleaned + +source $TOP/tests/common + +check_prereq mkfs.btrfs +setup_root_helper + +run_check truncate -s 2G $IMAGE +run_check $TOP/mkfs.btrfs -f $IMAGE +run_check $SUDO_HELPER mount $IMAGE $TEST_MNT +run_check $SUDO_HELPER chmod a+rw $TEST_MNT + +cd $TEST_MNT + +for i in `seq 5`; do + run_check dd if=/dev/zero of=file$i bs=1M count=10 +done + +for sn in `seq 4`;do + run_check $SUDO_HELPER $TOP/btrfs subvolume snapshot . snap$sn + for i in `seq 10`; do + run_check dd if=/dev/zero of=snap$sn/file$i bs=1M count=10 + done +done + +run_check $SUDO_HELPER $TOP/btrfs subvolume list . +run_check $SUDO_HELPER $TOP/btrfs subvolume list -d . + +idtodel=`run_check_stdout $SUDO_HELPER $TOP/btrfs inspect-internal rootid snap3` + +# delete, sync after some time +run_check $SUDO_HELPER $TOP/btrfs subvolume delete -c snap3 +{ sleep 5; run_check $TOP/btrfs filesystem sync $TEST_MNT; } & + +run_check $SUDO_HELPER $TOP/btrfs subvolume sync . $idtodel + +if run_check_stdout $SUDO_HELPER $TOP/btrfs subvolume list -d . | + grep -q "ID $idtodel.*DELETED"; then + _fail "sync did not wait for the subvolume cleanup" +fi + +run_check $TOP/btrfs filesystem sync $TEST_MNT +run_check $SUDO_HELPER $TOP/btrfs subvolume list -d . + +wait +cd .. + +run_check $SUDO_HELPER umount $TEST_MNT -- cgit v1.2.3 From c2e85337f6600bed1b348c9e86f83c27f753df6b Mon Sep 17 00:00:00 2001 From: David Sterba Date: Tue, 6 Oct 2015 14:16:39 +0200 Subject: btrfs-progs: tests: print commands on terminal if requested Set the variable TEST_LOG=tty (in the enviroment or as parameter to make) to print commands executed by 'run_check' helpers to terminal (ie. /dev/tty). This might be useful to see the test progress beside watching the results file. Signed-off-by: David Sterba --- tests/common | 3 +++ 1 file changed, 3 insertions(+) (limited to 'tests') diff --git a/tests/common b/tests/common index 45713506..d70ce54a 100644 --- a/tests/common +++ b/tests/common @@ -24,6 +24,7 @@ _not_run() run_check() { echo "############### $@" >> $RESULTS 2>&1 + if [ "$TEST_LOG" = 'tty' ]; then echo "CMD: $@" > /dev/tty; fi "$@" >> $RESULTS 2>&1 || _fail "failed: $@" } @@ -32,6 +33,7 @@ run_check() run_check_stdout() { echo "############### $@" >> $RESULTS 2>&1 + if [ "$TEST_LOG" = 'tty' ]; then echo "CMD(stdout): $@" > /dev/tty; fi "$@" 2>&1 | tee -a $RESULTS || _fail "failed: $@" } @@ -39,6 +41,7 @@ run_check_stdout() run_mayfail() { echo "############### $@" >> $RESULTS 2>&1 + if [ "$TEST_LOG" = 'tty' ]; then echo "CMD(mayfail): $@" > /dev/tty; fi "$@" >> $RESULTS 2>&1 || _log "failed (ignored): $@" } -- cgit v1.2.3 From a141d516967be938493e3d6cc815ccab0ddc29a5 Mon Sep 17 00:00:00 2001 From: David Sterba Date: Mon, 19 Oct 2015 17:27:55 +0200 Subject: btrfs-progs: tests: add mkfs tests Mkfs deserves it's own. Signed-off-by: David Sterba --- tests/mkfs-tests.sh | 44 ++++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 44 insertions(+) create mode 100755 tests/mkfs-tests.sh (limited to 'tests') diff --git a/tests/mkfs-tests.sh b/tests/mkfs-tests.sh new file mode 100755 index 00000000..4780b543 --- /dev/null +++ b/tests/mkfs-tests.sh @@ -0,0 +1,44 @@ +#!/bin/bash +# +# mkfs.btrfs tests + +unset TOP +unset LANG +LANG=C +SCRIPT_DIR=$(dirname $(readlink -f $0)) +TOP=$(readlink -f $SCRIPT_DIR/../) +TEST_DEV=${TEST_DEV:-} +RESULTS="$TOP/tests/mkfs-tests-results.txt" +IMAGE="$TOP/tests/test.img" + +source $TOP/tests/common + +# Allow child test to use $TOP and $RESULTS +export TOP +export RESULTS +# For custom script needs to verfiy recovery +export LANG +# For tests that only use a loop device +export IMAGE + +rm -f $RESULTS + +check_prereq mkfs.btrfs +check_prereq btrfs + +# The tests are driven by their custom script called 'test.sh' + +for i in $(find $TOP/tests/mkfs-tests -maxdepth 1 -mindepth 1 -type d \ + ${TEST:+-name "$TEST"} | sort) +do + echo " [TEST] $(basename $i)" + cd $i + echo "=== Entering $i" >> $RESULTS + if [ -x test.sh ]; then + ./test.sh + if [ $? -ne 0 ]; then + _fail "test failed for case $(basename $i)" + fi + fi + cd $TOP +done -- cgit v1.2.3 From ed54f0eee38435183015cac38f0c1fc1bf365556 Mon Sep 17 00:00:00 2001 From: David Sterba Date: Mon, 19 Oct 2015 17:29:14 +0200 Subject: btrfs-progs: tests: add 001-basic-profiles mkfs tests Basic test to cover block group profile combinations. Signed-off-by: David Sterba --- tests/mkfs-tests/001-basic-profiles/test.sh | 89 +++++++++++++++++++++++++++++ 1 file changed, 89 insertions(+) create mode 100755 tests/mkfs-tests/001-basic-profiles/test.sh (limited to 'tests') diff --git a/tests/mkfs-tests/001-basic-profiles/test.sh b/tests/mkfs-tests/001-basic-profiles/test.sh new file mode 100755 index 00000000..0861f36f --- /dev/null +++ b/tests/mkfs-tests/001-basic-profiles/test.sh @@ -0,0 +1,89 @@ +#!/bin/bash +# test various blockgroup profile combinations, use loop devices as block +# devices + +source $TOP/tests/common + +check_prereq btrfs-show-super +check_prereq mkfs.btrfs +check_prereq btrfs + +ndevs=4 +declare -a devs +dev1= + +setup_root_helper + +prepare_devices() +{ + for i in `seq $ndevs`; do + touch img$i + chmod a+rw img$i + truncate -s0 img$i + truncate -s2g img$i + devs[$i]=`run_check_stdout $SUDO_HELPER losetup --find --show img$i` + done +} + +cleanup_devices() +{ + for dev in ${devs[@]}; do + run_check $SUDO_HELPER losetup -d $dev + done + for i in `seq $ndevs`; do + truncate -s0 img$i + done + run_check $SUDO_HELPER losetup --list +} + +test_get_info() +{ + run_check $TOP/btrfs-show-super $dev1 + run_check $SUDO_HELPER $TOP/btrfs check $dev1 + run_check $SUDO_HELPER mount $dev1 $TEST_MNT + run_check $TOP/btrfs filesystem df $TEST_MNT + run_check $SUDO_HELPER $TOP/btrfs filesystem usage $TEST_MNT + run_check $SUDO_HELPER $TOP/btrfs device usage $TEST_MNT + run_check $SUDO_HELPER umount "$TEST_MNT" +} +test_do_mkfs() +{ + run_check $SUDO_HELPER $TOP/mkfs.btrfs -f \ + $@ +} + +test_mkfs_single() +{ + test_do_mkfs $@ $dev1 + test_get_info +} +test_mkfs_multi() +{ + test_do_mkfs $@ ${devs[@]} + test_get_info +} + +prepare_devices +dev1=${devs[1]} + +test_mkfs_single +test_mkfs_single -d single -m single +test_mkfs_single -d single -m single --mixed +test_mkfs_single -d single -m dup +test_mkfs_single -d dup -m dup --mixed + +test_mkfs_multi +test_mkfs_multi -d single -m single +test_mkfs_multi -d single -m single --mixed +test_mkfs_multi -d raid0 -m raid0 +test_mkfs_multi -d raid0 -m raid0 --mixed +test_mkfs_multi -d raid1 -m raid1 +test_mkfs_multi -d raid1 -m raid1 --mixed +test_mkfs_multi -d raid10 -m raid10 +test_mkfs_multi -d raid10 -m raid10 --mixed +test_mkfs_multi -d raid5 -m raid5 +test_mkfs_multi -d raid5 -m raid5 --mixed +test_mkfs_multi -d raid6 -m raid6 +test_mkfs_multi -d raid6 -m raid6 --mixed + +cleanup_devices -- cgit v1.2.3 From 1e92cd0d9bc0d9ed8efce639cef0b552901c2cb4 Mon Sep 17 00:00:00 2001 From: David Sterba Date: Mon, 19 Oct 2015 18:12:35 +0200 Subject: btrfs-progs: tests: add 002-no-force-mixed-on-small-volume Verify that we do not force mixed block groups on small volumes anymore. Signed-off-by: David Sterba --- tests/mkfs-tests/002-no-force-mixed-on-small-volume/test.sh | 13 +++++++++++++ 1 file changed, 13 insertions(+) create mode 100755 tests/mkfs-tests/002-no-force-mixed-on-small-volume/test.sh (limited to 'tests') diff --git a/tests/mkfs-tests/002-no-force-mixed-on-small-volume/test.sh b/tests/mkfs-tests/002-no-force-mixed-on-small-volume/test.sh new file mode 100755 index 00000000..007a0eb9 --- /dev/null +++ b/tests/mkfs-tests/002-no-force-mixed-on-small-volume/test.sh @@ -0,0 +1,13 @@ +#!/bin/bash +# +# Verify that we do not force mixed block groups on small volumes anymore + +source $TOP/tests/common + +check_prereq btrfs-show-super +check_prereq mkfs.btrfs +setup_root_helper + +run_check truncate -s 512M $IMAGE +mixed=$(run_check_stdout $TOP/mkfs.btrfs -n 64k -f $IMAGE | egrep 'Data|Metadata') +echo "$mixed" | grep -q -v 'Data+Metadata:' || _fail "unexpected: created a mixed-bg filesystem" -- cgit v1.2.3 From 11f7a8c8deb53a75af8c030563e2b770c190734e Mon Sep 17 00:00:00 2001 From: David Sterba Date: Fri, 23 Oct 2015 11:43:41 +0200 Subject: btrfs-progs: tests: add 010-convert-delete-ext2-subvol Testcase for "Btrfs-progs: fix btrfs-convert rollback to check ROOT_BACKREF", make sure we don't try a rollback if the ext2_subvol is half-deleted. Signed-off-by: David Sterba --- .../010-convert-delete-ext2-subvol/test.sh | 24 ++++++++++++++++++++++ 1 file changed, 24 insertions(+) create mode 100755 tests/misc-tests/010-convert-delete-ext2-subvol/test.sh (limited to 'tests') diff --git a/tests/misc-tests/010-convert-delete-ext2-subvol/test.sh b/tests/misc-tests/010-convert-delete-ext2-subvol/test.sh new file mode 100755 index 00000000..48936479 --- /dev/null +++ b/tests/misc-tests/010-convert-delete-ext2-subvol/test.sh @@ -0,0 +1,24 @@ +#!/bin/bash +# +# verify that convert rollback finds the ext2_subvolume intact and fails if it +# was partially deleted + +source $TOP/tests/common + +check_prereq btrfs-convert +check_prereq btrfs +setup_root_helper +prepare_test_dev + +run_check truncate -s 2G "$TEST_DEV" +run_check mkfs.ext4 -F "$TEST_DEV" +run_check $TOP/btrfs-convert "$TEST_DEV" +run_check $TOP/btrfs-debug-tree "$TEST_DEV" +run_check_mount_test_dev +run_check $SUDO_HELPER $TOP/btrfs subvolume delete -c "$TEST_MNT/ext2_saved" +run_check_umount_test_dev +run_check $TOP/btrfs-debug-tree "$TEST_DEV" +run_check_stdout $TOP/btrfs-convert --rollback "$TEST_DEV" | + grep -q 'is it deleted' || _fail "unexpected rollback" + +exit 0 -- cgit v1.2.3 From 6105df64a1a137e2449e735f4ce8c67e07567b29 Mon Sep 17 00:00:00 2001 From: David Sterba Date: Fri, 23 Oct 2015 11:25:55 +0200 Subject: btrfs-progs: tests: set default test image size to 2G Signed-off-by: David Sterba --- tests/common | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) (limited to 'tests') diff --git a/tests/common b/tests/common index d70ce54a..785280f0 100644 --- a/tests/common +++ b/tests/common @@ -180,7 +180,7 @@ prepare_test_dev() local size="$1" [[ "$TEST_DEV" ]] && return - [[ "$size" ]] || size='1G' + [[ "$size" ]] || size='2G' echo "\$TEST_DEV not given, use $TOP/test/test.img as fallback" >> \ $RESULTS -- cgit v1.2.3 From 1fcb190793b55317463cf1674a3d0bb2f00fe4d7 Mon Sep 17 00:00:00 2001 From: David Sterba Date: Fri, 23 Oct 2015 11:34:50 +0200 Subject: btrfs-progs: tests: do not run sudo helper tests if not necessary We use setup_root_helper in some helpers to make sure that the sudo helper is set up, and adding that to each test. Make the real test run only once. Signed-off-by: David Sterba --- tests/common | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) (limited to 'tests') diff --git a/tests/common b/tests/common index 785280f0..4542fa89 100644 --- a/tests/common +++ b/tests/common @@ -157,7 +157,7 @@ root_helper() setup_root_helper() { - if [ $UID -eq 0 ]; then + if [ $UID -eq 0 -o -n "$SUDO_HELPER" ]; then return fi -- cgit v1.2.3 From b85c7b76949017234ccc6ceafe503cc50917ebd2 Mon Sep 17 00:00:00 2001 From: David Sterba Date: Mon, 26 Oct 2015 14:35:34 +0100 Subject: btrfs-progs: tests: add test driver for fuzzed images Signed-off-by: David Sterba --- tests/fuzz-tests.sh | 41 +++++++++++++++++++++++++++++++++++++++++ 1 file changed, 41 insertions(+) create mode 100755 tests/fuzz-tests.sh (limited to 'tests') diff --git a/tests/fuzz-tests.sh b/tests/fuzz-tests.sh new file mode 100755 index 00000000..0e59832e --- /dev/null +++ b/tests/fuzz-tests.sh @@ -0,0 +1,41 @@ +#!/bin/bash +# +# misc tests on fuzzed or crafted images + +unset TOP +unset LANG +LANG=C +SCRIPT_DIR=$(dirname $(readlink -f $0)) +TOP=$(readlink -f $SCRIPT_DIR/../) +TEST_DEV=${TEST_DEV:-} +RESULTS="$TOP/tests/fuzz-tests-results.txt" +IMAGE="$TOP/tests/test.img" + +source $TOP/tests/common + +export TOP +export RESULTS +export LANG +export IMAGE + +rm -f $RESULTS + +check_prereq btrfs + +# The tests are driven by their custom script called 'test.sh' + +for i in $(find $TOP/tests/fuzz-tests -maxdepth 1 -mindepth 1 -type d \ + ${TEST:+-name "$TEST"} | sort) +do + name=$(basename $i) + cd $i + if [ -x test.sh ]; then + echo "=== Entering $i" >> $RESULTS + echo " [TEST] $name" + ./test.sh + if [ $? -ne 0 ]; then + _fail "test failed for case $(basename $i)" + fi + fi + cd $TOP +done -- cgit v1.2.3 From dfed5799dbc3f77c16da8f435b6cbabf1cb9b0c2 Mon Sep 17 00:00:00 2001 From: David Sterba Date: Mon, 26 Oct 2015 14:36:47 +0100 Subject: btrfs-progs: tests: 001-simple-unmounted: iterate over fuzzed images and run check Signed-off-by: David Sterba --- tests/fuzz-tests/001-simple-unmounted/test.sh | 20 ++++++++++++++++++++ 1 file changed, 20 insertions(+) create mode 100755 tests/fuzz-tests/001-simple-unmounted/test.sh (limited to 'tests') diff --git a/tests/fuzz-tests/001-simple-unmounted/test.sh b/tests/fuzz-tests/001-simple-unmounted/test.sh new file mode 100755 index 00000000..bf01a3a4 --- /dev/null +++ b/tests/fuzz-tests/001-simple-unmounted/test.sh @@ -0,0 +1,20 @@ +#!/bin/sh + +# iterate over all fuzzed images and run 'btrfs check' + +source $TOP/tests/common + +setup_root_helper +check_prereq btrfs + +# redefine the one provided by common +check_image() { + local image + + image=$1 + run_mayfail $TOP/btrfs check "$image" +} + +check_all_images $TOP/tests/fuzz-tests/images + +exit 0 -- cgit v1.2.3 From 1c4aefc2b80df30fde528fb47d34f72dade18fc2 Mon Sep 17 00:00:00 2001 From: David Sterba Date: Mon, 26 Oct 2015 15:03:37 +0100 Subject: btrfs-progs: tests: add support for command instrumentation Add a way to wrap commands executed by the tests. This means the common wrappers: run_check, run_check_stdout and run_mayfail , with the exception of the use root_helper. The contents of the shell variable INSTRUMENT are prepended to the command, without quotes. Use with care. Example: this has been tested with valgrind, the output goes to the RESULTS file. $ INSTRUMENT=valgrind make test-misc Any use of root_helper/SUDO_HELPER will skip the instrumentation. Signed-off-by: David Sterba --- tests/common | 18 +++++++++++++++--- 1 file changed, 15 insertions(+), 3 deletions(-) (limited to 'tests') diff --git a/tests/common b/tests/common index 4542fa89..ea9a569b 100644 --- a/tests/common +++ b/tests/common @@ -25,7 +25,11 @@ run_check() { echo "############### $@" >> $RESULTS 2>&1 if [ "$TEST_LOG" = 'tty' ]; then echo "CMD: $@" > /dev/tty; fi - "$@" >> $RESULTS 2>&1 || _fail "failed: $@" + if [ "$1" = 'root_helper' ]; then + "$@" >> $RESULTS 2>&1 || _fail "failed: $@" + else + $INSTRUMENT "$@" >> $RESULTS 2>&1 || _fail "failed: $@" + fi } # same as run_check but the stderr+stdout output is duplicated on stdout and @@ -34,7 +38,11 @@ run_check_stdout() { echo "############### $@" >> $RESULTS 2>&1 if [ "$TEST_LOG" = 'tty' ]; then echo "CMD(stdout): $@" > /dev/tty; fi - "$@" 2>&1 | tee -a $RESULTS || _fail "failed: $@" + if [ "$1" = 'root_helper' ]; then + "$@" 2>&1 | tee -a $RESULTS || _fail "failed: $@" + else + $INSTRUMENT "$@" 2>&1 | tee -a $RESULTS || _fail "failed: $@" + fi } # same as run_check but does not fail the test, output is logged @@ -42,7 +50,11 @@ run_mayfail() { echo "############### $@" >> $RESULTS 2>&1 if [ "$TEST_LOG" = 'tty' ]; then echo "CMD(mayfail): $@" > /dev/tty; fi - "$@" >> $RESULTS 2>&1 || _log "failed (ignored): $@" + if [ "$1" = 'root_helper' ]; then + "$@" >> $RESULTS 2>&1 || _log "failed (ignored): $@" + else + $INSTRUMENT "$@" >> $RESULTS 2>&1 || _log "failed (ignored): $@" + fi } check_prereq() -- cgit v1.2.3 From 425274ed8f7a525e997a64abf3492573f3ed967d Mon Sep 17 00:00:00 2001 From: David Sterba Date: Mon, 26 Oct 2015 19:51:10 +0100 Subject: btrfs-progs: tests: do not log output of run_mayfail to terminal No need to log expected failures to the terminal, the results file is fine; pass the return value of the command. Signed-off-by: David Sterba --- tests/common | 8 ++++++-- 1 file changed, 6 insertions(+), 2 deletions(-) (limited to 'tests') diff --git a/tests/common b/tests/common index ea9a569b..61780486 100644 --- a/tests/common +++ b/tests/common @@ -51,9 +51,13 @@ run_mayfail() echo "############### $@" >> $RESULTS 2>&1 if [ "$TEST_LOG" = 'tty' ]; then echo "CMD(mayfail): $@" > /dev/tty; fi if [ "$1" = 'root_helper' ]; then - "$@" >> $RESULTS 2>&1 || _log "failed (ignored): $@" + "$@" >> $RESULTS 2>&1 else - $INSTRUMENT "$@" >> $RESULTS 2>&1 || _log "failed (ignored): $@" + $INSTRUMENT "$@" >> $RESULTS 2>&1 + fi + if [ $? != 0 ]; then + echo "failed (ignored): $@" >> $RESULTS + return 1 fi } -- cgit v1.2.3 From cb10f56cb6e7d0c34286320a775aef9328e0627f Mon Sep 17 00:00:00 2001 From: David Sterba Date: Mon, 26 Oct 2015 19:54:57 +0100 Subject: btrfs-progs: tests: add 003-mixed-with-wrong-nodesize Mixed mode needs equal sectorsize and nodesize. This was fixed by "Btrfs-progs: Prevent creation of filesystem with 'mixed bgs' and having differing sectorsize and nodesize" Signed-off-by: David Sterba --- tests/mkfs-tests/003-mixed-with-wrong-nodesize/test.sh | 12 ++++++++++++ 1 file changed, 12 insertions(+) create mode 100755 tests/mkfs-tests/003-mixed-with-wrong-nodesize/test.sh (limited to 'tests') diff --git a/tests/mkfs-tests/003-mixed-with-wrong-nodesize/test.sh b/tests/mkfs-tests/003-mixed-with-wrong-nodesize/test.sh new file mode 100755 index 00000000..289d5ff0 --- /dev/null +++ b/tests/mkfs-tests/003-mixed-with-wrong-nodesize/test.sh @@ -0,0 +1,12 @@ +#!/bin/bash +# +# Mixed mode needs equal sectorsize and nodesize + +source $TOP/tests/common + +check_prereq mkfs.btrfs + +run_check truncate -s 512M $IMAGE +run_mayfail $TOP/mkfs.btrfs -f -M -s 4096 -n 16384 "$IMAGE" && _fail + +exit 0 -- cgit v1.2.3 From 835821f36a32bc7662f4aaa0f9a2a27a35eb60ed Mon Sep 17 00:00:00 2001 From: David Sterba Date: Tue, 27 Oct 2015 17:17:47 +0100 Subject: btrfs-progs: add initial tests/README Signed-off-by: David Sterba --- tests/README.md | 136 ++++++++++++++++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 136 insertions(+) create mode 100644 tests/README.md (limited to 'tests') diff --git a/tests/README.md b/tests/README.md new file mode 100644 index 00000000..be3bda82 --- /dev/null +++ b/tests/README.md @@ -0,0 +1,136 @@ +# Btrfs-progs tests + +Run the tests from the top directory: + +```shell +$ make test +$ make test-fsck +$ make test-convert +``` + +or selectively from the `tests/` directory: + +```shell +$ ./fsck-tests.sh +$ ./misc-tests.sh +``` + +The verbose output of the tests is logged into a file named after the test +category, eg. `fsck-tests-results.txt`. + +## Selective testing + +The test are prefixed by a number for ordering and uniquenes. To run a +particular test use: + +```shell +$ make TEST=MASK test +``` + +where `MASK` is a glob expression that will execute only tests +that match the MASK. Here the test number comes handy: + +```shell +$ make TEST=001\* test-fsck +$ TEST=001\* ./fsck-tests.sh +``` + +will run the first test in fsck-tests subdirectory. + + +## Test structure + +*tests/fsck-tests/:* + + * tests targeted at bugs that are fixable by fsck + +*tests/convert-tests/:* + + * coverage tests of ext2/3/4 and btrfs-convert options + +*tests/fuzz-tests/:* + + * collection of fuzzed or crafted images + * tests that are supposed to run various utilities on the images and not + crash + +*tests/misc-tests/:* + + * anything that does not fit to the above, the test driver script will only + execute `./test.sh` in the test directory + +*tests/common:* + + * script with helpers + +*tests/test.img:* + + * default testing image, the file is never deleted by the scripts but + truncated to 0 bytes, so it keeps it's permissions. It's eg. possible to + host it on NFS, make it `chmod a+w` for root. + + +## Other tuning, environment variables + +### Instrumentation + +It's possible to wrap the tested commands to utilities that might do more +checking or catch failures at runtime. This can be done by setting the +`INSTRUMENT` environment variable: + +```shell +INSTRUMENT=valgrind ./fuzz-tests.sh # in tests/ +make INSTRUMENT=valgrind test-fuzz # in the top directory +``` + +The variable is prepended to the command *unquoted*, all sorts of shell tricks +are possible. + +Note: instrumentation is not applied to privileged commands (anything that uses +the root helper). + +### Verbosity + +Setting the variable `TEST_LOG=tty` will print all commands executed by some of +the wrappers (`run_check` etc), other commands are silent. + +### Permissions + +Some commands require root privileges (to mount/umount, access loop devices). +It is assumed that `sudo` will work in some way (no password, password asked +and cached). Note that instrumentation is not applied in this case, for safety +reasons. You need to modify the test script instead. + +### Cleanup + +The tests are supposed to cleanup after themselves if they pass. In case of +failure, the rest of the tests are skipped and intermediate files, mounts and +loop devices are kept. This should help to investigate the test failure but at +least the mounts and loop devices need to be cleaned before the next run. + +This is partially done by the script `clean-tests.sh`, you may want to check +the loop devices as they are managed on a per-test basis. + +## New test + +1. Pick the category for the new test or fallback to `misc-tests` if not sure. For +an easy start copy an existing `test.sh` script from some test that might be +close to the purpose of your new test. + +* Use the highest unused number in the sequence, write a short descriptive title +and join by dashes `-`. + +* Write a short description of the bug and how it's teste to the comment at the +begining of `test.sh`. + +* Write the test commands, comment anything that's not obvious. + +* Test your test. Use the `TEST` variable to jump right to your test: +```shell +$ make TEST=012\* tests-misc # from top directory +$ TEST=012\* ./misc-tests.sh # from tests/ +``` + +* The commit changelog should reference a commit that either introduced or + fixed the bug (or both). Subject line of the shall mention the name of the + new directory for ease of search, eg. `btrfs-progs: tests: add 012-subvolume-sync-must-wait` -- cgit v1.2.3 From f2c844f65ffdb6673467eb838049a48dc316dcaf Mon Sep 17 00:00:00 2001 From: David Sterba Date: Thu, 5 Nov 2015 14:22:10 +0100 Subject: btrfs-progs: mkfs: do not truncate the image when --rootdir is set With the rootdir option we try to guess the final size of the image and fill it with zeros, preceded by truncation. After patch "Btrfs-progs: Do not force mixed block group creation unless '-M' option is specified" the misc test 002 will fail, because of the non-mixed mode. I think we should not touch the image size (no change for block devices) and try to fit into whatever is provided by user. Signed-off-by: David Sterba --- tests/mkfs-tests/004-rootdir-keeps-size/test.sh | 30 +++++++++++++++++++++++++ 1 file changed, 30 insertions(+) create mode 100755 tests/mkfs-tests/004-rootdir-keeps-size/test.sh (limited to 'tests') diff --git a/tests/mkfs-tests/004-rootdir-keeps-size/test.sh b/tests/mkfs-tests/004-rootdir-keeps-size/test.sh new file mode 100755 index 00000000..a78a3dec --- /dev/null +++ b/tests/mkfs-tests/004-rootdir-keeps-size/test.sh @@ -0,0 +1,30 @@ +#!/bin/bash +# make sure that mkfs.btrfs --rootsize does not change size of the image + +source $TOP/tests/common + +check_prereq mkfs.btrfs +prepare_test_dev + +test_mkfs_with_size() { + local size + local imgsize + local tmp + + size="$1" + run_check truncate -s$size $TEST_DEV + imgsize=$(run_check_stdout stat --format=%s $TEST_DEV) + run_check $SUDO_HELPER $TOP/mkfs.btrfs -f \ + --rootdir $TOP/Documentation \ + $TEST_DEV + tmp=$(run_check_stdout stat --format=%s $TEST_DEV) + if ! [ "$imgsize" = "$tmp" ]; then + _fail "image size changed from $imgsize to $tmp" + fi +} + +test_mkfs_with_size 128M +test_mkfs_with_size 256M +test_mkfs_with_size 512M +test_mkfs_with_size 1G +test_mkfs_with_size 2G -- cgit v1.2.3 From 87ab14013a38a93930dd47a16eec68930ec8f320 Mon Sep 17 00:00:00 2001 From: David Sterba Date: Fri, 13 Nov 2015 16:49:55 +0100 Subject: btrfs-progs: tests: add 011-delete-missing-device Test for "btrfs-progs: allow device deletion using 'missing' keyword again". Signed-off-by: David Sterba --- tests/misc-tests/011-delete-missing-device/test.sh | 82 ++++++++++++++++++++++ 1 file changed, 82 insertions(+) create mode 100755 tests/misc-tests/011-delete-missing-device/test.sh (limited to 'tests') diff --git a/tests/misc-tests/011-delete-missing-device/test.sh b/tests/misc-tests/011-delete-missing-device/test.sh new file mode 100755 index 00000000..70eddbc0 --- /dev/null +++ b/tests/misc-tests/011-delete-missing-device/test.sh @@ -0,0 +1,82 @@ +#!/bin/bash +# make sure that 'missing' is accepted for device deletion + +source $TOP/tests/common + +check_prereq mkfs.btrfs +check_prereq btrfs + +ndevs=4 +declare -a devs +dev1= +devtodel= + +setup_root_helper + +prepare_devices() +{ + for i in `seq $ndevs`; do + touch img$i + chmod a+rw img$i + truncate -s0 img$i + truncate -s2g img$i + devs[$i]=`run_check_stdout $SUDO_HELPER losetup --find --show img$i` + done +} + +cleanup_devices() +{ + for dev in ${devs[@]}; do + run_mayfail $SUDO_HELPER losetup -d $dev + done + for i in `seq $ndevs`; do + truncate -s0 img$i + done + run_check $SUDO_HELPER losetup --list +} + +test_do_mkfs() +{ + run_check $SUDO_HELPER $TOP/mkfs.btrfs -f $@ ${devs[@]} + run_check $TOP/btrfs-show-super $dev1 + run_check $SUDO_HELPER $TOP/btrfs check $dev1 + run_check $TOP/btrfs filesystem show +} + +test_wipefs() +{ + run_check wipefs -a $devtodel + run_check $SUDO_HELPER losetup -d $devtodel + run_check losetup -a + run_check $TOP/btrfs filesystem show +} +test_delete_missing() +{ + run_check_mount_test_dev -o degraded + run_check $SUDO_HELPER $TOP/btrfs filesystem show $TEST_MNT + run_check $SUDO_HELPER $TOP/btrfs device delete missing $TEST_MNT + run_check $SUDO_HELPER $TOP/btrfs filesystem show $TEST_MNT + run_check_umount_test_dev + + run_check_mount_test_dev + local out + out="$(run_check_stdout $SUDO_HELPER $TOP/btrfs filesystem show $TEST_MNT)" + if echo "$out" | grep -q -- "$devtodel"; then + _fail "device $devtodel not deleted" + fi + if echo "$out" | grep -q missing; then + _fail "missing device still present" + fi + run_check_umount_test_dev +} + +prepare_devices +dev1=${devs[1]} +devtodel=${devs[3]} +TEST_DEV=$dev1 + +test_do_mkfs +test_wipefs +test_delete_missing + +cleanup_devices -- cgit v1.2.3 From 1b9876f761305e499efc3bc6a4dc7d199831cdf8 Mon Sep 17 00:00:00 2001 From: David Sterba Date: Fri, 13 Nov 2015 17:29:11 +0100 Subject: btrfs-progs: tests: add 005-long-device-name-for-ssd A test for "btrfs-progs: mkfs: increase buffer size in is_ssd". Create a device with a long name through loop device wrapped to a device mapper linear device, switch it to the "ssd" mode status. Signed-off-by: David Sterba --- .../005-long-device-name-for-ssd/test.sh | 39 ++++++++++++++++++++++ 1 file changed, 39 insertions(+) create mode 100755 tests/mkfs-tests/005-long-device-name-for-ssd/test.sh (limited to 'tests') diff --git a/tests/mkfs-tests/005-long-device-name-for-ssd/test.sh b/tests/mkfs-tests/005-long-device-name-for-ssd/test.sh new file mode 100755 index 00000000..02692eeb --- /dev/null +++ b/tests/mkfs-tests/005-long-device-name-for-ssd/test.sh @@ -0,0 +1,39 @@ +#!/bin/bash +# a long device name must pass the SSD test + +source $TOP/tests/common + +check_prereq mkfs.btrfs +check_prereq btrfs +setup_root_helper +prepare_test_dev + +# prep device +dmname=\ +btrfs-test-with-very-long-name-AAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAA +dmdev=/dev/mapper/$dmname + +run_check truncate -s0 img +chmod a+w img +run_check truncate -s2g img + +loopdev=`run_check_stdout $SUDO_HELPER losetup --find --show img` +run_check $SUDO_HELPER dmsetup create $dmname --table "0 1048576 linear $loopdev 0" + +base=`basename "$loopdev"` +rot=/sys/class/block/$base/queue/rotational + +# switch rotational +run_check cat $rot +echo 0 | run_check $SUDO_HELPER tee $rot +run_check cat $rot + +# test +run_check_stdout $SUDO_HELPER $TOP/mkfs.btrfs -f $@ $dmdev | + grep -q 'SSD detected:.*yes' || _fail 'SSD not detected' +run_check $TOP/btrfs-show-super $dmdev + +# cleanup +run_check $SUDO_HELPER dmsetup remove $dmname +run_mayfail $SUDO_HELPER losetup -d $loopdev +run_check truncate -s0 img -- cgit v1.2.3 From a343805d585facd2ea04a43ae070f76ef2a5cedb Mon Sep 17 00:00:00 2001 From: David Sterba Date: Fri, 13 Nov 2015 18:43:04 +0100 Subject: btrfs-progs: tests: add 006-partitioned-loopdev Create filesystem on a partitioned loop device, test for "btrfs-progs: Fix partitioned loop devices resolving". Signed-off-by: David Sterba --- .../006-partitioned-loopdev/partition-1g-1g | Bin 0 -> 512 bytes tests/mkfs-tests/006-partitioned-loopdev/test.sh | 26 +++++++++++++++++++++ 2 files changed, 26 insertions(+) create mode 100644 tests/mkfs-tests/006-partitioned-loopdev/partition-1g-1g create mode 100755 tests/mkfs-tests/006-partitioned-loopdev/test.sh (limited to 'tests') diff --git a/tests/mkfs-tests/006-partitioned-loopdev/partition-1g-1g b/tests/mkfs-tests/006-partitioned-loopdev/partition-1g-1g new file mode 100644 index 00000000..eb057769 Binary files /dev/null and b/tests/mkfs-tests/006-partitioned-loopdev/partition-1g-1g differ diff --git a/tests/mkfs-tests/006-partitioned-loopdev/test.sh b/tests/mkfs-tests/006-partitioned-loopdev/test.sh new file mode 100755 index 00000000..5c92facd --- /dev/null +++ b/tests/mkfs-tests/006-partitioned-loopdev/test.sh @@ -0,0 +1,26 @@ +#!/bin/bash +# recognize partitioned loop devices + +source $TOP/tests/common + +check_prereq mkfs.btrfs +check_prereq btrfs +setup_root_helper + +run_check truncate -s0 img +chmod a+w img +cp partition-1g-1g img +run_check truncate -s2g img + +loopdev=$(run_check_stdout $SUDO_HELPER losetup --partscan --find --show img) +base=$(basename $loopdev) + +# expect partitions named like loop0p1 etc +for looppart in $(ls /dev/$base?*); do + run_check $SUDO_HELPER $TOP/mkfs.btrfs -f $looppart + run_check $TOP/btrfs-show-super $looppart +done + +# cleanup +run_check $SUDO_HELPER losetup -d $loopdev +run_check truncate -s0 img -- cgit v1.2.3 From b7a69afe6947d913fed4ad64eca6471c6059a1ec Mon Sep 17 00:00:00 2001 From: David Sterba Date: Thu, 19 Nov 2015 16:37:15 +0100 Subject: btrfs-progs: tests: add 007-mix-nodesize-sectorsize Test combinations of sectorsize and nodesize on a single device. Signed-off-by: David Sterba --- .../mkfs-tests/007-mix-nodesize-sectorsize/test.sh | 35 ++++++++++++++++++++++ 1 file changed, 35 insertions(+) create mode 100755 tests/mkfs-tests/007-mix-nodesize-sectorsize/test.sh (limited to 'tests') diff --git a/tests/mkfs-tests/007-mix-nodesize-sectorsize/test.sh b/tests/mkfs-tests/007-mix-nodesize-sectorsize/test.sh new file mode 100755 index 00000000..bb3c6620 --- /dev/null +++ b/tests/mkfs-tests/007-mix-nodesize-sectorsize/test.sh @@ -0,0 +1,35 @@ +#!/bin/bash +# iterate over nodesize and sectorsize combinations + +source $TOP/tests/common + +check_prereq btrfs-show-super +check_prereq mkfs.btrfs +check_prereq btrfs +setup_root_helper +prepare_test_dev + +test_mkfs_single() +{ + run_check $SUDO_HELPER $TOP/mkfs.btrfs -f "$@" $TEST_DEV + run_check $TOP/btrfs-show-super $TEST_DEV + run_check $SUDO_HELPER $TOP/btrfs check $TEST_DEV +} + +# default +test_mkfs_single + +# nodesize >= sectorsize +for nodesize in 4096 8192 16384 32768 65536; do + for sectorsize in 4096 8192 16384 32768 65536; do + [ $nodesize -lt $sectorsize ] && continue + test_mkfs_single -n $nodesize -s $sectorsize -d single -m single + test_mkfs_single -n $nodesize -s $sectorsize -d single -m dup + done +done + +# nodesize, mixed mode +for nodesize in 4k 8k 16k 32k 64k; do + test_mkfs_single -n $nodesize -s $nodesize -d single -m single --mixed + test_mkfs_single -n $nodesize -s $nodesize -d dup -m dup --mixed +done -- cgit v1.2.3 From 3504df7f02a11fb52cbddc26071a7118cd23f20c Mon Sep 17 00:00:00 2001 From: David Sterba Date: Thu, 26 Nov 2015 15:20:05 +0100 Subject: btrfs-progs: tests: add 019-non-skinny-false-alert Catch a buggy condition fixed by "btrfs-progs: fsck: Fix a false alert where extent record has wrong metadata flag" Signed-off-by: David Sterba --- .../019-non-skinny-false-alert/default_case.img.xz | Bin 0 -> 15236 bytes .../fsck-tests/019-non-skinny-false-alert/test.sh | 23 +++++++++++++++++++++ 2 files changed, 23 insertions(+) create mode 100644 tests/fsck-tests/019-non-skinny-false-alert/default_case.img.xz create mode 100755 tests/fsck-tests/019-non-skinny-false-alert/test.sh (limited to 'tests') diff --git a/tests/fsck-tests/019-non-skinny-false-alert/default_case.img.xz b/tests/fsck-tests/019-non-skinny-false-alert/default_case.img.xz new file mode 100644 index 00000000..c35f8bc6 Binary files /dev/null and b/tests/fsck-tests/019-non-skinny-false-alert/default_case.img.xz differ diff --git a/tests/fsck-tests/019-non-skinny-false-alert/test.sh b/tests/fsck-tests/019-non-skinny-false-alert/test.sh new file mode 100755 index 00000000..a7f8e862 --- /dev/null +++ b/tests/fsck-tests/019-non-skinny-false-alert/test.sh @@ -0,0 +1,23 @@ +#!/bin/bash +# +# $ btrfs check img +# Checking filesystem on img +# UUID: 17f2bf15-f4c2-4ebc-b1f7-39b7af26257a +# checking extents +# bad extent [29376512, 29392896), type mismatch with chunk +# bad extent [29442048, 29458432), type mismatch with chunk +# bad extent [29589504, 29605888), type mismatch with chunk +# ... +# +# a buggy check leads to the above messages + +source $TOP/tests/common + +check_prereq btrfs + +image=$(extract_image "./default_case.img.xz") +run_check_stdout $TOP/btrfs check "$image" 2>&1 | + grep -q "type mismatch with chunk" && + _fail "unexpected error message in the output" + +rm -f "$image" -- cgit v1.2.3 From 1d37645dc35bdd6152399be88d8300318b0651de Mon Sep 17 00:00:00 2001 From: David Sterba Date: Thu, 26 Nov 2015 16:22:16 +0100 Subject: btrfs-progs: tests: enhance 001-basic-profiles with --data DUP Add the remaining valid combinations. Signed-off-by: David Sterba --- tests/mkfs-tests/001-basic-profiles/test.sh | 2 ++ 1 file changed, 2 insertions(+) (limited to 'tests') diff --git a/tests/mkfs-tests/001-basic-profiles/test.sh b/tests/mkfs-tests/001-basic-profiles/test.sh index 0861f36f..2747d429 100755 --- a/tests/mkfs-tests/001-basic-profiles/test.sh +++ b/tests/mkfs-tests/001-basic-profiles/test.sh @@ -70,6 +70,8 @@ test_mkfs_single test_mkfs_single -d single -m single test_mkfs_single -d single -m single --mixed test_mkfs_single -d single -m dup +test_mkfs_single -d dup -m single +test_mkfs_single -d dup -m dup test_mkfs_single -d dup -m dup --mixed test_mkfs_multi -- cgit v1.2.3 From 16e240eca7a03515889678001e6c0559d40402a2 Mon Sep 17 00:00:00 2001 From: Qu Wenruo Date: Mon, 30 Nov 2015 09:39:30 +0800 Subject: btrfs-progs: tests: mkfs, check sectorsize and nodesize combinations Add mkfs selftest for invalid and valid sectorsize/nodesize combinations. Signed-off-by: Qu Wenruo [ switched to TEST_DEV ] Signed-off-by: David Sterba --- .../008-secorsize-nodesize-combination/test.sh | 49 ++++++++++++++++++++++ 1 file changed, 49 insertions(+) create mode 100755 tests/mkfs-tests/008-secorsize-nodesize-combination/test.sh (limited to 'tests') diff --git a/tests/mkfs-tests/008-secorsize-nodesize-combination/test.sh b/tests/mkfs-tests/008-secorsize-nodesize-combination/test.sh new file mode 100755 index 00000000..68b79427 --- /dev/null +++ b/tests/mkfs-tests/008-secorsize-nodesize-combination/test.sh @@ -0,0 +1,49 @@ +#!/bin/bash +# test various sectorsize and node size combinations +# including valid and invalid ones +# only do mkfs and fsck check, no mounting as +# sub/multi-pagesize is not supported yet + +source $TOP/tests/common + +check_prereq mkfs.btrfs +check_prereq btrfs +prepare_test_dev + +# disable mixed bg to avoid sectorsize == nodesize check +features="^mixed-bg" + +# caller need to check whether the combination is valid +do_test() +{ + sectorsize=$1 + nodesize=$2 + run_mayfail $TOP/mkfs.btrfs -O $features -n $nodesize -s $sectorsize \ + $TEST_DEV + ret=$? + if [ $ret == 0 ]; then + run_check $TOP/btrfs check $TEST_DEV + fi + return $ret +} + +# Invalid: Unaligned sectorsize and nodesize +do_test 8191 8191 && _fail + +# Invalid: Aligned sectorsize with unaligned nodesize +do_test 4k 16385 && _fail + +# Invalid: Ungliend sectorsize with aligned nodesize +do_test 8191 16k && _fail + +# Valid: Aligned sectorsize and nodesize +do_test 4k 16k || _fail + +# Invalid: Sectorsize larger than nodesize +do_test 8k 4k && _fail + +# Invalid: too large nodesize +do_test 16k 128k && _fail + +# Valid: large sectorsize +do_test 64k 64k || _fail -- cgit v1.2.3 From 5f03d1fc23a575988c33098d4dea828bc19c1db6 Mon Sep 17 00:00:00 2001 From: David Sterba Date: Mon, 30 Nov 2015 17:42:15 +0100 Subject: btrfs-progs: tests: add sys-array-num-stripes-0.raw.xz Signed-off-by: David Sterba --- .../images/sys-array-num-stripes-0.raw.txt | 30 +++++++++++++++++++++ .../images/sys-array-num-stripes-0.raw.xz | Bin 0 -> 8364 bytes 2 files changed, 30 insertions(+) create mode 100644 tests/fuzz-tests/images/sys-array-num-stripes-0.raw.txt create mode 100644 tests/fuzz-tests/images/sys-array-num-stripes-0.raw.xz (limited to 'tests') diff --git a/tests/fuzz-tests/images/sys-array-num-stripes-0.raw.txt b/tests/fuzz-tests/images/sys-array-num-stripes-0.raw.txt new file mode 100644 index 00000000..bdde4e70 --- /dev/null +++ b/tests/fuzz-tests/images/sys-array-num-stripes-0.raw.txt @@ -0,0 +1,30 @@ +URL: http://article.gmane.org/gmane.comp.file-systems.btrfs/50230 +Vegard Nossum, 2015-11-15 + +If sys_array::num_stripes == 0, we hit a BUG_ON during mount: + +BTRFS: device fsid 9006933e-2a9a-44f0-917f-514252aeec2c devid 1 transid 7 /dev/loop0 +BTRFS info (device loop0): disk space caching is enabled +BUG: failure at fs/btrfs/ctree.h:337/btrfs_chunk_item_size()! +Kernel panic - not syncing: BUG! +CPU: 0 PID: 313 Comm: mount Not tainted 4.2.5-00657-ge047887-dirty #25 +Stack: + 637af890 60062489 602aeb2e 604192ba + 60387961 00000011 637af8a0 6038a835 + 637af9c0 6038776b 634ef32b 00000000 +Call Trace: + [<6001c86d>] show_stack+0xfe/0x15b + [<6038a835>] dump_stack+0x2a/0x2c + [<6038776b>] panic+0x13e/0x2b3 + [<6020f099>] btrfs_read_sys_array+0x25d/0x2ff + [<601cfbbe>] open_ctree+0x192d/0x27af + [<6019c2c1>] btrfs_mount+0x8f5/0xb9a + [<600bc9a7>] mount_fs+0x11/0xf3 + [<600d5167>] vfs_kern_mount+0x75/0x11a + [<6019bcb0>] btrfs_mount+0x2e4/0xb9a + [<600bc9a7>] mount_fs+0x11/0xf3 + [<600d5167>] vfs_kern_mount+0x75/0x11a + [<600d710b>] do_mount+0xa35/0xbc9 + [<600d7557>] SyS_mount+0x95/0xc8 + +Fixed by patch (kernel and btrfs-progs): btrfs: handle invalid num_stripes in sys_array diff --git a/tests/fuzz-tests/images/sys-array-num-stripes-0.raw.xz b/tests/fuzz-tests/images/sys-array-num-stripes-0.raw.xz new file mode 100644 index 00000000..d64fb300 Binary files /dev/null and b/tests/fuzz-tests/images/sys-array-num-stripes-0.raw.xz differ -- cgit v1.2.3 From 05d4159946cf1f54e18729b708d2fd6c3a1225c4 Mon Sep 17 00:00:00 2001 From: David Sterba Date: Mon, 30 Nov 2015 18:13:01 +0100 Subject: btrfs-progs: tests: print test type Makes it a bit more clear: [TEST/conv] ext4 32k nodesize, btrfs no-holes [TEST/conv] ext2 64k nodesize, btrfs no-holes [TEST/conv] ext3 64k nodesize, btrfs no-holes [TEST/conv] ext4 64k nodesize, btrfs no-holes [TEST] misc-tests.sh [TEST/misc] 001-btrfstune-features [TEST/misc] 002-uuid-rewrite [TEST/misc] 003-zero-log [TEST/misc] 004-shrink-fs [TEST/misc] 005-convert-progress-thread-crash [TEST/misc] 006-image-on-missing-device [TEST/misc] 007-subvolume-sync [TEST/misc] 008-leaf-crossing-stripes [TEST/misc] 009-subvolume-sync-must-wait [TEST/misc] 010-convert-delete-ext2-subvol [TEST/misc] 011-delete-missing-device [TEST] fuzz-tests.sh [TEST/fuzz] 001-simple-unmounted Signed-off-by: David Sterba --- tests/convert-tests.sh | 6 +++--- tests/fsck-tests.sh | 2 +- tests/fuzz-tests.sh | 2 +- tests/misc-tests.sh | 2 +- tests/mkfs-tests.sh | 2 +- 5 files changed, 7 insertions(+), 7 deletions(-) (limited to 'tests') diff --git a/tests/convert-tests.sh b/tests/convert-tests.sh index 4d99a61c..b26c0698 100755 --- a/tests/convert-tests.sh +++ b/tests/convert-tests.sh @@ -26,9 +26,9 @@ convert_test() { shift if [ -z "$features" ]; then - echo " [TEST] $1, btrfs defaults" + echo " [TEST/conv] $1, btrfs defaults" else - echo " [TEST] $1, btrfs $features" + echo " [TEST/conv] $1, btrfs $features" fi nodesize=$2 shift 2 @@ -52,7 +52,7 @@ convert_test() { } if ! [ -z "$TEST" ]; then - echo " [TEST] skipped all convert tests, TEST=$TEST" + echo " [TEST/conv] skipped all convert tests, TEST=$TEST" exit 0 fi diff --git a/tests/fsck-tests.sh b/tests/fsck-tests.sh index b910e851..2aab4ff2 100755 --- a/tests/fsck-tests.sh +++ b/tests/fsck-tests.sh @@ -32,7 +32,7 @@ run_one_test() { local testname testname="$1" - echo " [TEST] $(basename $testname)" + echo " [TEST/fsck] $(basename $testname)" cd $testname echo "=== Entering $testname" >> $RESULTS if [ -x test.sh ]; then diff --git a/tests/fuzz-tests.sh b/tests/fuzz-tests.sh index 0e59832e..204dce2d 100755 --- a/tests/fuzz-tests.sh +++ b/tests/fuzz-tests.sh @@ -31,7 +31,7 @@ do cd $i if [ -x test.sh ]; then echo "=== Entering $i" >> $RESULTS - echo " [TEST] $name" + echo " [TEST/fuzz] $name" ./test.sh if [ $? -ne 0 ]; then _fail "test failed for case $(basename $i)" diff --git a/tests/misc-tests.sh b/tests/misc-tests.sh index a87ece28..2a7f57c5 100755 --- a/tests/misc-tests.sh +++ b/tests/misc-tests.sh @@ -34,7 +34,7 @@ check_prereq btrfs for i in $(find $TOP/tests/misc-tests -maxdepth 1 -mindepth 1 -type d \ ${TEST:+-name "$TEST"} | sort) do - echo " [TEST] $(basename $i)" + echo " [TEST/misc] $(basename $i)" cd $i echo "=== Entering $i" >> $RESULTS if [ -x test.sh ]; then diff --git a/tests/mkfs-tests.sh b/tests/mkfs-tests.sh index 4780b543..c0635ad1 100755 --- a/tests/mkfs-tests.sh +++ b/tests/mkfs-tests.sh @@ -31,7 +31,7 @@ check_prereq btrfs for i in $(find $TOP/tests/mkfs-tests -maxdepth 1 -mindepth 1 -type d \ ${TEST:+-name "$TEST"} | sort) do - echo " [TEST] $(basename $i)" + echo " [TEST/mkfs] $(basename $i)" cd $i echo "=== Entering $i" >> $RESULTS if [ -x test.sh ]; then -- cgit v1.2.3 From ebb66f20aeee76a776d0d64502a9f85d6e8fb77b Mon Sep 17 00:00:00 2001 From: Naohiro Aota Date: Tue, 8 Dec 2015 11:07:13 +0900 Subject: btrfs-progs: tests: test multiple-linked file corruption This commit extends the leaf corruption test to try to repair a file linked from multiple directory. It stresses a case that some links to a file is broken but others kept valid. Signed-off-by: Naohiro Aota Signed-off-by: David Sterba --- .../012-leaf-corruption/no_data_extent.tar.xz | Bin 177600 -> 130260 bytes tests/fsck-tests/012-leaf-corruption/test.sh | 11 +++++++---- 2 files changed, 7 insertions(+), 4 deletions(-) (limited to 'tests') diff --git a/tests/fsck-tests/012-leaf-corruption/no_data_extent.tar.xz b/tests/fsck-tests/012-leaf-corruption/no_data_extent.tar.xz index cc90b58e..547e5455 100644 Binary files a/tests/fsck-tests/012-leaf-corruption/no_data_extent.tar.xz and b/tests/fsck-tests/012-leaf-corruption/no_data_extent.tar.xz differ diff --git a/tests/fsck-tests/012-leaf-corruption/test.sh b/tests/fsck-tests/012-leaf-corruption/test.sh index 6e231451..830fd8d5 100755 --- a/tests/fsck-tests/012-leaf-corruption/test.sh +++ b/tests/fsck-tests/012-leaf-corruption/test.sh @@ -29,6 +29,7 @@ leaf_no_data_ext_list=( 1869 0 40700 "snmp" 1871 0 100700 "machine-id" 1872 0 100700 "adjtime" + 1877 0 40700 "del" ) generate_leaf_corrupt_no_data_ext() @@ -40,10 +41,12 @@ generate_leaf_corrupt_no_data_ext() $TOP/btrfs-image -r test.img.btrfs-image $dest || \ _fail "failed to extract leaf_corrupt_no_data_ext.btrfs-image" - # leaf at 20832256 contains no regular data extent, clear its csum to - # corrupt the leaf. - dd if=/dev/zero of=$dest bs=1 count=32 conv=notrunc seek=20832256 \ - 1>/dev/null 2>&1 + # leaf at 4206592 and 20905984 contains no regular data + # extent, clear its csum to corrupt the leaf. + for x in 4206592 20905984; do + dd if=/dev/zero of=$dest bs=1 count=32 conv=notrunc seek=$x \ + 1>/dev/null 2>&1 + done } check_inode() -- cgit v1.2.3 From ac45d64c041b763221d0fb4cd41a0e207c688c14 Mon Sep 17 00:00:00 2001 From: David Sterba Date: Tue, 12 Jan 2016 15:16:11 +0100 Subject: btrfs-progs: tests: add missing prerequisites Signed-off-by: David Sterba --- tests/fsck-tests/006-bad-root-items/test.sh | 2 ++ tests/fsck-tests/012-leaf-corruption/test.sh | 2 ++ tests/fsck-tests/013-extent-tree-rebuild/test.sh | 3 +++ tests/misc-tests/001-btrfstune-features/test.sh | 3 +++ tests/misc-tests/002-uuid-rewrite/test.sh | 2 ++ tests/misc-tests/004-shrink-fs/test.sh | 2 ++ tests/misc-tests/005-convert-progress-thread-crash/test.sh | 3 ++- tests/misc-tests/009-subvolume-sync-must-wait/test.sh | 2 ++ tests/misc-tests/010-convert-delete-ext2-subvol/test.sh | 2 ++ tests/misc-tests/011-delete-missing-device/test.sh | 1 + tests/mkfs-tests/002-no-force-mixed-on-small-volume/test.sh | 2 +- tests/mkfs-tests/004-rootdir-keeps-size/test.sh | 1 + tests/mkfs-tests/005-long-device-name-for-ssd/test.sh | 3 ++- tests/mkfs-tests/006-partitioned-loopdev/test.sh | 3 ++- tests/mkfs-tests/007-mix-nodesize-sectorsize/test.sh | 1 + tests/mkfs-tests/008-secorsize-nodesize-combination/test.sh | 1 + 16 files changed, 29 insertions(+), 4 deletions(-) (limited to 'tests') diff --git a/tests/fsck-tests/006-bad-root-items/test.sh b/tests/fsck-tests/006-bad-root-items/test.sh index 421e2258..84332348 100755 --- a/tests/fsck-tests/006-bad-root-items/test.sh +++ b/tests/fsck-tests/006-bad-root-items/test.sh @@ -2,6 +2,8 @@ source $TOP/tests/common +check_prereq btrfs + echo "extracting image default_case.tar.xz" >> $RESULTS tar --no-same-owner -xJf default_case.tar.xz || \ _fail "failed to extract default_case.tar.xz" diff --git a/tests/fsck-tests/012-leaf-corruption/test.sh b/tests/fsck-tests/012-leaf-corruption/test.sh index 830fd8d5..a308727d 100755 --- a/tests/fsck-tests/012-leaf-corruption/test.sh +++ b/tests/fsck-tests/012-leaf-corruption/test.sh @@ -2,6 +2,8 @@ source $TOP/tests/common +check_prereq btrfs-image + # Check file list for leaf corruption, no regular/preallocated # file extent case. # Corrupted leaf is 20832256, which contains inode 1862~1872 diff --git a/tests/fsck-tests/013-extent-tree-rebuild/test.sh b/tests/fsck-tests/013-extent-tree-rebuild/test.sh index 7419d6ea..ff7d28e5 100755 --- a/tests/fsck-tests/013-extent-tree-rebuild/test.sh +++ b/tests/fsck-tests/013-extent-tree-rebuild/test.sh @@ -2,8 +2,11 @@ source $TOP/tests/common +check_prereq btrfs-corrupt-block check_prereq btrfs-debug-tree check_prereq mkfs.btrfs +check_prereq btrfs + setup_root_helper prepare_test_dev 1G diff --git a/tests/misc-tests/001-btrfstune-features/test.sh b/tests/misc-tests/001-btrfstune-features/test.sh index 836e8d32..c858d701 100755 --- a/tests/misc-tests/001-btrfstune-features/test.sh +++ b/tests/misc-tests/001-btrfstune-features/test.sh @@ -6,6 +6,9 @@ source $TOP/tests/common check_prereq btrfs-debug-tree check_prereq btrfs-show-super check_prereq mkfs.btrfs +check_prereq btrfstune +check_prereq btrfs + setup_root_helper prepare_test_dev diff --git a/tests/misc-tests/002-uuid-rewrite/test.sh b/tests/misc-tests/002-uuid-rewrite/test.sh index 9b103aaf..d84ec6ca 100755 --- a/tests/misc-tests/002-uuid-rewrite/test.sh +++ b/tests/misc-tests/002-uuid-rewrite/test.sh @@ -7,6 +7,8 @@ check_prereq btrfs-debug-tree check_prereq btrfs-show-super check_prereq mkfs.btrfs check_prereq btrfstune +check_prereq btrfs + prepare_test_dev get_fs_uuid() { diff --git a/tests/misc-tests/004-shrink-fs/test.sh b/tests/misc-tests/004-shrink-fs/test.sh index b1321520..88740358 100755 --- a/tests/misc-tests/004-shrink-fs/test.sh +++ b/tests/misc-tests/004-shrink-fs/test.sh @@ -7,6 +7,8 @@ source $TOP/tests/common check_prereq mkfs.btrfs +check_prereq btrfs + setup_root_helper # Optionally take id of the device to shrink diff --git a/tests/misc-tests/005-convert-progress-thread-crash/test.sh b/tests/misc-tests/005-convert-progress-thread-crash/test.sh index 09ac8a3a..054069c2 100755 --- a/tests/misc-tests/005-convert-progress-thread-crash/test.sh +++ b/tests/misc-tests/005-convert-progress-thread-crash/test.sh @@ -3,7 +3,8 @@ source $TOP/tests/common -check_prereq btrfs +check_prereq btrfs-convert + mkfs.ext4 -V &>/dev/null || _not_run "mkfs.ext4 not found" prepare_test_dev 1G diff --git a/tests/misc-tests/009-subvolume-sync-must-wait/test.sh b/tests/misc-tests/009-subvolume-sync-must-wait/test.sh index 66d38ea5..056584e5 100755 --- a/tests/misc-tests/009-subvolume-sync-must-wait/test.sh +++ b/tests/misc-tests/009-subvolume-sync-must-wait/test.sh @@ -5,6 +5,8 @@ source $TOP/tests/common check_prereq mkfs.btrfs +check_prereq btrfs + setup_root_helper run_check truncate -s 2G $IMAGE diff --git a/tests/misc-tests/010-convert-delete-ext2-subvol/test.sh b/tests/misc-tests/010-convert-delete-ext2-subvol/test.sh index 48936479..451e453a 100755 --- a/tests/misc-tests/010-convert-delete-ext2-subvol/test.sh +++ b/tests/misc-tests/010-convert-delete-ext2-subvol/test.sh @@ -6,7 +6,9 @@ source $TOP/tests/common check_prereq btrfs-convert +check_prereq btrfs-debug-tree check_prereq btrfs + setup_root_helper prepare_test_dev diff --git a/tests/misc-tests/011-delete-missing-device/test.sh b/tests/misc-tests/011-delete-missing-device/test.sh index 70eddbc0..26645f10 100755 --- a/tests/misc-tests/011-delete-missing-device/test.sh +++ b/tests/misc-tests/011-delete-missing-device/test.sh @@ -3,6 +3,7 @@ source $TOP/tests/common +check_prereq btrfs-show-super check_prereq mkfs.btrfs check_prereq btrfs diff --git a/tests/mkfs-tests/002-no-force-mixed-on-small-volume/test.sh b/tests/mkfs-tests/002-no-force-mixed-on-small-volume/test.sh index 007a0eb9..855fbd18 100755 --- a/tests/mkfs-tests/002-no-force-mixed-on-small-volume/test.sh +++ b/tests/mkfs-tests/002-no-force-mixed-on-small-volume/test.sh @@ -4,8 +4,8 @@ source $TOP/tests/common -check_prereq btrfs-show-super check_prereq mkfs.btrfs + setup_root_helper run_check truncate -s 512M $IMAGE diff --git a/tests/mkfs-tests/004-rootdir-keeps-size/test.sh b/tests/mkfs-tests/004-rootdir-keeps-size/test.sh index a78a3dec..7038c8ea 100755 --- a/tests/mkfs-tests/004-rootdir-keeps-size/test.sh +++ b/tests/mkfs-tests/004-rootdir-keeps-size/test.sh @@ -4,6 +4,7 @@ source $TOP/tests/common check_prereq mkfs.btrfs + prepare_test_dev test_mkfs_with_size() { diff --git a/tests/mkfs-tests/005-long-device-name-for-ssd/test.sh b/tests/mkfs-tests/005-long-device-name-for-ssd/test.sh index 02692eeb..c89ee0e1 100755 --- a/tests/mkfs-tests/005-long-device-name-for-ssd/test.sh +++ b/tests/mkfs-tests/005-long-device-name-for-ssd/test.sh @@ -4,7 +4,8 @@ source $TOP/tests/common check_prereq mkfs.btrfs -check_prereq btrfs +check_prereq btrfs-show-super + setup_root_helper prepare_test_dev diff --git a/tests/mkfs-tests/006-partitioned-loopdev/test.sh b/tests/mkfs-tests/006-partitioned-loopdev/test.sh index 5c92facd..7c9fb829 100755 --- a/tests/mkfs-tests/006-partitioned-loopdev/test.sh +++ b/tests/mkfs-tests/006-partitioned-loopdev/test.sh @@ -4,7 +4,8 @@ source $TOP/tests/common check_prereq mkfs.btrfs -check_prereq btrfs +check_prereq btrfs-show-super + setup_root_helper run_check truncate -s0 img diff --git a/tests/mkfs-tests/007-mix-nodesize-sectorsize/test.sh b/tests/mkfs-tests/007-mix-nodesize-sectorsize/test.sh index bb3c6620..d5374cbd 100755 --- a/tests/mkfs-tests/007-mix-nodesize-sectorsize/test.sh +++ b/tests/mkfs-tests/007-mix-nodesize-sectorsize/test.sh @@ -6,6 +6,7 @@ source $TOP/tests/common check_prereq btrfs-show-super check_prereq mkfs.btrfs check_prereq btrfs + setup_root_helper prepare_test_dev diff --git a/tests/mkfs-tests/008-secorsize-nodesize-combination/test.sh b/tests/mkfs-tests/008-secorsize-nodesize-combination/test.sh index 68b79427..79cc2b22 100755 --- a/tests/mkfs-tests/008-secorsize-nodesize-combination/test.sh +++ b/tests/mkfs-tests/008-secorsize-nodesize-combination/test.sh @@ -8,6 +8,7 @@ source $TOP/tests/common check_prereq mkfs.btrfs check_prereq btrfs + prepare_test_dev # disable mixed bg to avoid sectorsize == nodesize check -- cgit v1.2.3 From cc57faac2e33d49e43aa44118f51cd2b43c45aa1 Mon Sep 17 00:00:00 2001 From: "Lakshmipathi.G" Date: Mon, 25 Jan 2016 21:38:33 +0530 Subject: btrfs-progs: tests: do checksum verification with convert-tests Signed-off-by: Lakshmipathi.G Signed-off-by: David Sterba --- tests/convert-tests.sh | 4 ++++ 1 file changed, 4 insertions(+) (limited to 'tests') diff --git a/tests/convert-tests.sh b/tests/convert-tests.sh index b26c0698..f78f5d38 100755 --- a/tests/convert-tests.sh +++ b/tests/convert-tests.sh @@ -45,10 +45,14 @@ convert_test() { run_check $SUDO_HELPER mount -o loop $IMAGE $TEST_MNT run_check $SUDO_HELPER dd if=/dev/zero of=$TEST_MNT/test bs=$nodesize \ count=1 1>/dev/null 2>&1 + run_check_stdout $SUDO_HELPER md5sum $TEST_MNT/test > $TEST_MNT/test.md5sum run_check $SUDO_HELPER umount $TEST_MNT run_check $TOP/btrfs-convert ${features:+-O "$features"} -N "$nodesize" $IMAGE run_check $TOP/btrfs check $IMAGE run_check $TOP/btrfs-show-super $IMAGE + run_check $SUDO_HELPER mount -o loop $IMAGE $TEST_MNT + run_check_stdout $SUDO_HELPER md5sum -c $TEST_MNT/test.md5sum | grep -q 'OK' || _fail "file validation failed." + run_check $SUDO_HELPER umount $TEST_MNT } if ! [ -z "$TEST" ]; then -- cgit v1.2.3 From 0ad5efde1a5614718e009f4d401fa75ad92c9281 Mon Sep 17 00:00:00 2001 From: David Sterba Date: Thu, 11 Feb 2016 19:21:24 +0100 Subject: btrfs-progs: tests: store checksums in /tmp We don't want to store the checksum on filesystem that we're converting. Signed-off-by: David Sterba --- tests/convert-tests.sh | 9 +++++++-- 1 file changed, 7 insertions(+), 2 deletions(-) (limited to 'tests') diff --git a/tests/convert-tests.sh b/tests/convert-tests.sh index f78f5d38..07a89740 100755 --- a/tests/convert-tests.sh +++ b/tests/convert-tests.sh @@ -18,6 +18,8 @@ rm -f $RESULTS setup_root_helper +CHECKSUMTMP=$(mktemp --tmpdir btrfs-progs-convert.XXXXXXXXXX) + convert_test() { local features local nodesize @@ -45,13 +47,14 @@ convert_test() { run_check $SUDO_HELPER mount -o loop $IMAGE $TEST_MNT run_check $SUDO_HELPER dd if=/dev/zero of=$TEST_MNT/test bs=$nodesize \ count=1 1>/dev/null 2>&1 - run_check_stdout $SUDO_HELPER md5sum $TEST_MNT/test > $TEST_MNT/test.md5sum + run_check_stdout md5sum $TEST_MNT/test > $CHECKSUMTMP run_check $SUDO_HELPER umount $TEST_MNT run_check $TOP/btrfs-convert ${features:+-O "$features"} -N "$nodesize" $IMAGE run_check $TOP/btrfs check $IMAGE run_check $TOP/btrfs-show-super $IMAGE run_check $SUDO_HELPER mount -o loop $IMAGE $TEST_MNT - run_check_stdout $SUDO_HELPER md5sum -c $TEST_MNT/test.md5sum | grep -q 'OK' || _fail "file validation failed." + run_check_stdout md5sum -c $CHECKSUMTMP | + grep -q 'OK' || _fail "file validation failed." run_check $SUDO_HELPER umount $TEST_MNT } @@ -77,3 +80,5 @@ for feature in '' 'extref' 'skinny-metadata' 'no-holes'; do convert_test "$feature" "ext3 64k nodesize" 65536 mke2fs -j -b 4096 convert_test "$feature" "ext4 64k nodesize" 65536 mke2fs -t ext4 -b 4096 done + +rm $CHECKSUMTMP -- cgit v1.2.3 From 476d17fe388cecb3a5b4f97d1e9073cbf7c47a14 Mon Sep 17 00:00:00 2001 From: David Sterba Date: Thu, 11 Feb 2016 19:26:26 +0100 Subject: btrfs-progs: tests: use common variables and helpers Use TEST_DEV and the associated helpers to manage the tested image. Signed-off-by: David Sterba --- tests/convert-tests.sh | 26 ++++++++++++++------------ 1 file changed, 14 insertions(+), 12 deletions(-) mode change 100755 => 100644 tests/convert-tests.sh (limited to 'tests') diff --git a/tests/convert-tests.sh b/tests/convert-tests.sh old mode 100755 new mode 100644 index 07a89740..0bfb41f8 --- a/tests/convert-tests.sh +++ b/tests/convert-tests.sh @@ -10,13 +10,13 @@ LANG=C SCRIPT_DIR=$(dirname $(readlink -f $0)) TOP=$(readlink -f $SCRIPT_DIR/../) RESULTS="$TOP/tests/convert-tests-results.txt" -IMAGE="$TOP/tests/test.img" source $TOP/tests/common rm -f $RESULTS setup_root_helper +prepare_test_dev 256M CHECKSUMTMP=$(mktemp --tmpdir btrfs-progs-convert.XXXXXXXXXX) @@ -35,27 +35,29 @@ convert_test() { nodesize=$2 shift 2 echo "creating ext image with: $*" >> $RESULTS - # IMAGE not removed as the file might have special permissions, eg. + # TEST_DEV not removed as the file might have special permissions, eg. # when test image is on NFS and would not be writable for root - run_check truncate -s 0 $IMAGE + run_check truncate -s 0 $TEST_DEV # 256MB is the smallest acceptable btrfs image. - run_check truncate -s 256M $IMAGE - run_check $* -F $IMAGE + run_check truncate -s 256M $TEST_DEV + run_check $* -F $TEST_DEV # create a file to check btrfs-convert can convert regular file # correct - run_check $SUDO_HELPER mount -o loop $IMAGE $TEST_MNT + run_check_mount_test_dev run_check $SUDO_HELPER dd if=/dev/zero of=$TEST_MNT/test bs=$nodesize \ count=1 1>/dev/null 2>&1 run_check_stdout md5sum $TEST_MNT/test > $CHECKSUMTMP - run_check $SUDO_HELPER umount $TEST_MNT - run_check $TOP/btrfs-convert ${features:+-O "$features"} -N "$nodesize" $IMAGE - run_check $TOP/btrfs check $IMAGE - run_check $TOP/btrfs-show-super $IMAGE - run_check $SUDO_HELPER mount -o loop $IMAGE $TEST_MNT + run_check_umount_test_dev + + run_check $TOP/btrfs-convert ${features:+-O "$features"} -N "$nodesize" $TEST_DEV + run_check $TOP/btrfs check $TEST_DEV + run_check $TOP/btrfs-show-super $TEST_DEV + + run_check_mount_test_dev run_check_stdout md5sum -c $CHECKSUMTMP | grep -q 'OK' || _fail "file validation failed." - run_check $SUDO_HELPER umount $TEST_MNT + run_check_umount_test_dev } if ! [ -z "$TEST" ]; then -- cgit v1.2.3 From 154d28dd99da6fd3aef2621ead327c09c0d87bb6 Mon Sep 17 00:00:00 2001 From: Qu Wenruo Date: Mon, 22 Feb 2016 14:59:57 +0800 Subject: btrfs-progs: misc-test: Add regression test for find-root gives empty result Add regression test for btrfs-find-root gives empty result even the fs is OK. Signed-off-by: Qu Wenruo [ enhanced test ] Signed-off-by: David Sterba --- .../first_meta_chunk.btrfs-image | Bin 0 -> 4096 bytes tests/misc-tests/012-find-root-no-result/test.sh | 24 +++++++++++++++++++++ 2 files changed, 24 insertions(+) create mode 100644 tests/misc-tests/012-find-root-no-result/first_meta_chunk.btrfs-image create mode 100755 tests/misc-tests/012-find-root-no-result/test.sh (limited to 'tests') diff --git a/tests/misc-tests/012-find-root-no-result/first_meta_chunk.btrfs-image b/tests/misc-tests/012-find-root-no-result/first_meta_chunk.btrfs-image new file mode 100644 index 00000000..7bf6c509 Binary files /dev/null and b/tests/misc-tests/012-find-root-no-result/first_meta_chunk.btrfs-image differ diff --git a/tests/misc-tests/012-find-root-no-result/test.sh b/tests/misc-tests/012-find-root-no-result/test.sh new file mode 100755 index 00000000..983a8a1e --- /dev/null +++ b/tests/misc-tests/012-find-root-no-result/test.sh @@ -0,0 +1,24 @@ +#!/bin/bash +# Regression test for case btrfs-find-root may print no result on a +# recent fs or balanced fs, whose metadata chunk is the first chunk +# and the only metadata chunk + +source $TOP/tests/common + +check_prereq btrfs-find-root +check_prereq btrfs-image + +run_check $TOP/btrfs-image -r first_meta_chunk.btrfs-image test.img || \ + _fail "failed to extract first_meta_chunk.btrfs-image" + +result=$(run_check_stdout $TOP/btrfs-find-root test.img | sed '/^Superblock/d') + +if [ -z "$result" ]; then + _fail "btrfs-find-root failed to find tree root" +fi + +if ! echo "$result" | grep -q 'Found tree root at'; then + _fail "btrfs-find-root failed to find tree root, unexpected output" +fi + +rm test.img -- cgit v1.2.3 From 49fef369ffa7d66608b14640b485c16e725a9714 Mon Sep 17 00:00:00 2001 From: David Sterba Date: Tue, 1 Mar 2016 18:44:56 +0100 Subject: btrfs-progs: tests: fix misc/005-long-device-name-for-ssd We use a device mapper device on top of a loop device, the change in rotational status does not always propagate if change it at the loop device sysfs node. Signed-off-by: David Sterba --- tests/mkfs-tests/005-long-device-name-for-ssd/test.sh | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) (limited to 'tests') diff --git a/tests/mkfs-tests/005-long-device-name-for-ssd/test.sh b/tests/mkfs-tests/005-long-device-name-for-ssd/test.sh index c89ee0e1..cff495e6 100755 --- a/tests/mkfs-tests/005-long-device-name-for-ssd/test.sh +++ b/tests/mkfs-tests/005-long-device-name-for-ssd/test.sh @@ -21,7 +21,8 @@ run_check truncate -s2g img loopdev=`run_check_stdout $SUDO_HELPER losetup --find --show img` run_check $SUDO_HELPER dmsetup create $dmname --table "0 1048576 linear $loopdev 0" -base=`basename "$loopdev"` +dmbase=`readlink -f $dmdev` +base=`basename "$dmbase"` rot=/sys/class/block/$base/queue/rotational # switch rotational -- cgit v1.2.3 From 9f76654de8a8c573e957c3f6b0877724f8c04bd9 Mon Sep 17 00:00:00 2001 From: David Sterba Date: Tue, 8 Mar 2016 15:43:13 +0100 Subject: btrfs-progs: tests: add image for bko#96971 (bad checksum type) Signed-off-by: David Sterba --- .../fuzz-tests/images/bko-96971-btrfs-image.raw.xz | Bin 0 -> 6448 bytes tests/fuzz-tests/images/bko-96971-btrfs-image.txt | 69 +++++++++++++++++++++ 2 files changed, 69 insertions(+) create mode 100644 tests/fuzz-tests/images/bko-96971-btrfs-image.raw.xz create mode 100644 tests/fuzz-tests/images/bko-96971-btrfs-image.txt (limited to 'tests') diff --git a/tests/fuzz-tests/images/bko-96971-btrfs-image.raw.xz b/tests/fuzz-tests/images/bko-96971-btrfs-image.raw.xz new file mode 100644 index 00000000..21aa33b0 Binary files /dev/null and b/tests/fuzz-tests/images/bko-96971-btrfs-image.raw.xz differ diff --git a/tests/fuzz-tests/images/bko-96971-btrfs-image.txt b/tests/fuzz-tests/images/bko-96971-btrfs-image.txt new file mode 100644 index 00000000..ff85540d --- /dev/null +++ b/tests/fuzz-tests/images/bko-96971-btrfs-image.txt @@ -0,0 +1,69 @@ +URL: https://bugzilla.kernel.org/show_bug.cgi?id=96971 + Lukas Lueg 2015-04-20 23:01:44 UTC + +I've identified some problems in the btrfs code and attached a btrfs-image +which causes the userland tools to crash and the kernel to immediately freeze +once the filesystem get's mounted and one of the files is accessed. Putting +the image onto a usb-drive gives you a freeze-on-a-stick :-) + +"btrfs check" crashes due to a SIGFPE in count_csum_range(). The culprit is +struct btrfs_root->fs_info->super_copy->csum_size being 0, which goes +unchecked before entering a division. I was not able to identify where the +kernel crashes (system goes down the tubes), yet the problem is probably the +same. + +"btrfs version" is v3.19.1; bug is also present in latest git (kdave and +unstable) as of 2015/04/21 + + +Full gdb output: + +gdb btrfs +GNU gdb (GDB) Fedora 7.8.2-38.fc21 +Copyright (C) 2014 Free Software Foundation, Inc. +License GPLv3+: GNU GPL version 3 or later +This is free software: you are free to change and redistribute it. +There is NO WARRANTY, to the extent permitted by law. Type "show copying" +and "show warranty" for details. +This GDB was configured as "x86_64-redhat-linux-gnu". +Type "show configuration" for configuration details. +For bug reporting instructions, please see: +. +Find the GDB manual and other documentation resources online at: +. +For help, type "help". +Type "apropos word" to search for commands related to "word"... +Reading symbols from btrfs...Reading symbols from /usr/lib/debug/usr/sbin/btrfs.debug...done. +done. +(gdb) run check btrfs_fukked.bin +Starting program: /usr/sbin/btrfs check btrfs_fukked.bin +[Thread debugging using libthread_db enabled] +Using host libthread_db library "/lib64/libthread_db.so.1". +Checking filesystem on btrfs_fukked.bin +UUID: cdd8684f-9eb1-40a4-91ec-1ed7c3cb444c +checking extents +checking free space cache +checking fs roots + +Program received signal SIGFPE, Arithmetic exception. +count_csum_range (root=, root=, + found=, len=7385088, start=7471104) at cmds-check.c:1455 +1455 csum_end = key.offset + (size / csum_size) * root->sectorsize; +(gdb) bt +#0 count_csum_range (root=, root=, + found=, len=7385088, start=7471104) at cmds-check.c:1455 +#1 process_file_extent (active_node=0x7fffffffd710, key=0x7fffffffd680, + slot=11, eb=, root=0x894b10) at cmds-check.c:1551 +#2 process_one_leaf (wc=0x7fffffffd6c0, eb=, root=0x894b10) + at cmds-check.c:1617 +#3 walk_down_tree (level=, wc=0x7fffffffd6c0, + path=0x7fffffffd7f0, root=0x894b10) at cmds-check.c:1742 +#4 check_fs_root (wc=0x7fffffffd6c0, root_cache=0x7fffffffdb20, root=0x894b10) + at cmds-check.c:3380 +#5 check_fs_roots (root_cache=root_cache@entry=0x7fffffffdb20, root=0x894b10) + at cmds-check.c:3516 +#6 0x0000000000428aea in cmd_check (argc=, + argv=) at cmds-check.c:9465 +#7 0x000000000040e5a2 in main (argc=2, argv=0x7fffffffdeb0) at btrfs.c:245 +(gdb) p csum_size +$2 = 0 -- cgit v1.2.3 From 974d2ed5644a258d2b27fe28c989b36fb3bec75c Mon Sep 17 00:00:00 2001 From: David Sterba Date: Thu, 17 Mar 2016 14:22:24 +0100 Subject: btrfs-progs: tests: add 013-subvolume-sync-crash Test for "btrfs-progs: subvol sync: fix memory corruption, undersized array", a lot of deleted subvolumes in the 'subvol sync' will not fit into the array, should result in a glibc report. Signed-off-by: David Sterba --- tests/misc-tests/013-subvolume-sync-crash/test.sh | 49 +++++++++++++++++++++++ 1 file changed, 49 insertions(+) create mode 100755 tests/misc-tests/013-subvolume-sync-crash/test.sh (limited to 'tests') diff --git a/tests/misc-tests/013-subvolume-sync-crash/test.sh b/tests/misc-tests/013-subvolume-sync-crash/test.sh new file mode 100755 index 00000000..c7955269 --- /dev/null +++ b/tests/misc-tests/013-subvolume-sync-crash/test.sh @@ -0,0 +1,49 @@ +#!/bin/bash +# +# Verify that subovolume sync waits until the subvolume is cleaned and does not +# crash at the end + +source $TOP/tests/common + +check_prereq mkfs.btrfs +check_prereq btrfs + +setup_root_helper + +run_check truncate -s 2G $IMAGE +run_check $TOP/mkfs.btrfs -f $IMAGE +run_check $SUDO_HELPER mount $IMAGE $TEST_MNT +run_check $SUDO_HELPER chmod a+rw $TEST_MNT + +cd $TEST_MNT + +for i in `seq 5`; do + run_check dd if=/dev/zero of=file$i bs=1M count=10 +done + +# 128 is minimum +for sn in `seq 130`;do + run_check $SUDO_HELPER $TOP/btrfs subvolume snapshot . snap$sn + for i in `seq 10`; do + run_check dd if=/dev/zero of=snap$sn/file$i bs=1M count=1 + done +done + +run_check $SUDO_HELPER $TOP/btrfs subvolume list . +run_check $SUDO_HELPER $TOP/btrfs subvolume list -d . + +idtodel=`run_check_stdout $SUDO_HELPER $TOP/btrfs inspect-internal rootid snap3` + +# delete, sync after some time +run_check $SUDO_HELPER $TOP/btrfs subvolume delete -c snap* +{ sleep 5; run_check $TOP/btrfs filesystem sync $TEST_MNT; } & + +run_check $SUDO_HELPER $TOP/btrfs subvolume sync . + +run_check $TOP/btrfs filesystem sync $TEST_MNT +run_check $SUDO_HELPER $TOP/btrfs subvolume list -d . + +wait +cd .. + +run_check $SUDO_HELPER umount $TEST_MNT -- cgit v1.2.3 From 971d8e7476885c7670fe71708d58c081440daa2c Mon Sep 17 00:00:00 2001 From: "Lakshmipathi.G" Date: Tue, 8 Mar 2016 20:30:06 +0530 Subject: btrfs-progs: tests: populate fs with small dataset for convert tests Signed-off-by: Lakshmipathi.G [ minor tweaks ] Signed-off-by: David Sterba --- tests/convert-tests.sh | 87 +++++++++++++++++++++++++++++++++++++++++++++++--- 1 file changed, 82 insertions(+), 5 deletions(-) mode change 100644 => 100755 tests/convert-tests.sh (limited to 'tests') diff --git a/tests/convert-tests.sh b/tests/convert-tests.sh old mode 100644 new mode 100755 index 0bfb41f8..17f5889d --- a/tests/convert-tests.sh +++ b/tests/convert-tests.sh @@ -10,16 +10,92 @@ LANG=C SCRIPT_DIR=$(dirname $(readlink -f $0)) TOP=$(readlink -f $SCRIPT_DIR/../) RESULTS="$TOP/tests/convert-tests-results.txt" +# how many files to create. +DATASET_SIZE=50 source $TOP/tests/common rm -f $RESULTS setup_root_helper -prepare_test_dev 256M +prepare_test_dev 512M CHECKSUMTMP=$(mktemp --tmpdir btrfs-progs-convert.XXXXXXXXXX) +generate_dataset() { + + dataset_type="$1" + dirpath=$TEST_MNT/$dataset_type + run_check $SUDO_HELPER mkdir -p $dirpath + + case $dataset_type in + small) + for num in $(seq 1 $DATASET_SIZE); do + run_check $SUDO_HELPER dd if=/dev/urandom of=$dirpath/$dataset_type.$num bs=10K \ + count=1 >/dev/null 2>&1 + done + ;; + + hardlink) + for num in $(seq 1 $DATASET_SIZE); do + run_check $SUDO_HELPER touch $dirpath/$dataset_type.$num + run_check $SUDO_HELPER ln $dirpath/$dataset_type.$num $dirpath/hlink.$num + done + ;; + + symlink) + for num in $(seq 1 $DATASET_SIZE); do + run_check $SUDO_HELPER touch $dirpath/$dataset_type.$num + run_check $SUDO_HELPER ln -s $dirpath/$dataset_type.$num $dirpath/slink.$num + done + ;; + + brokenlink) + for num in $(seq 1 $DATASET_SIZE); do + run_check $SUDO_HELPER ln -s $dirpath/$dataset_type.$num $dirpath/blink.$num + done + ;; + + perm) + for modes in $(seq 1 7777); do + if [[ "$modes" == *9* ]] || [[ "$modes" == *8* ]] + then + continue; + else + run_check $SUDO_HELPER touch $dirpath/$dataset_type.$modes + run_check $SUDO_HELPER chmod $modes $dirpath/$dataset_type.$modes + fi + done + ;; + + sparse) + for num in $(seq 1 $DATASET_SIZE); do + run_check $SUDO_HELPER dd if=/dev/urandom of=$dirpath/$dataset_type.$num bs=10K \ + count=1 >/dev/null 2>&1 + run_check $SUDO_HELPER truncate -s 500K $dirpath/$dataset_type.$num + run_check $SUDO_HELPER dd if=/dev/urandom of=$dirpath/$dataset_type.$num bs=10K \ + oflag=append conv=notrunc count=1 >/dev/null 2>&1 + run_check $SUDO_HELPER truncate -s 800K $dirpath/$dataset_type.$num + done + ;; + + acls) + for num in $(seq 1 $DATASET_SIZE); do + run_check $SUDO_HELPER touch $dirpath/$dataset_type.$num + run_check $SUDO_HELPER setfacl -m "u:root:x" $dirpath/$dataset_type.$num + run_check $SUDO_HELPER setfattr -n user.foo -v bar$num $dirpath/$dataset_type.$num + done + ;; + esac +} + +populate_fs() { + + for dataset_type in 'small' 'hardlink' 'symlink' 'brokenlink' 'perm' 'sparse' 'acls'; do + generate_dataset "$dataset_type" + done +} + convert_test() { local features local nodesize @@ -39,15 +115,16 @@ convert_test() { # when test image is on NFS and would not be writable for root run_check truncate -s 0 $TEST_DEV # 256MB is the smallest acceptable btrfs image. - run_check truncate -s 256M $TEST_DEV + run_check truncate -s 512M $TEST_DEV run_check $* -F $TEST_DEV # create a file to check btrfs-convert can convert regular file # correct run_check_mount_test_dev + populate_fs run_check $SUDO_HELPER dd if=/dev/zero of=$TEST_MNT/test bs=$nodesize \ - count=1 1>/dev/null 2>&1 - run_check_stdout md5sum $TEST_MNT/test > $CHECKSUMTMP + count=1 >/dev/null 2>&1 + run_check_stdout find $TEST_MNT -type f ! -name 'image' -exec md5sum {} \+ > $CHECKSUMTMP run_check_umount_test_dev run_check $TOP/btrfs-convert ${features:+-O "$features"} -N "$nodesize" $TEST_DEV @@ -56,7 +133,7 @@ convert_test() { run_check_mount_test_dev run_check_stdout md5sum -c $CHECKSUMTMP | - grep -q 'OK' || _fail "file validation failed." + grep -q 'FAILED' && _fail "file validation failed." run_check_umount_test_dev } -- cgit v1.2.3 From 92e922bafe6b45fbd504e3ff69d4fe446c216133 Mon Sep 17 00:00:00 2001 From: David Sterba Date: Fri, 18 Mar 2016 17:11:25 +0100 Subject: btrfs-progs: tests: enumerate RWX in convert tests Generating all valid combinations takes too much time. Signed-off-by: David Sterba --- tests/convert-tests.sh | 5 ++++- 1 file changed, 4 insertions(+), 1 deletion(-) (limited to 'tests') diff --git a/tests/convert-tests.sh b/tests/convert-tests.sh index 17f5889d..06d8419e 100755 --- a/tests/convert-tests.sh +++ b/tests/convert-tests.sh @@ -57,7 +57,10 @@ generate_dataset() { ;; perm) - for modes in $(seq 1 7777); do + for modes in 777 775 755 750 700 666 664 644 640 600 444 440 400 000 \ + 1777 1775 1755 1750 1700 1666 1664 1644 1640 1600 1444 1440 1400 1000 \ + 2777 2775 2755 2750 2700 2666 2664 2644 2640 2600 2444 2440 2400 2000 \ + 4777 4775 4755 4750 4700 4666 4664 4644 4640 4600 4444 4440 4400 4000; do if [[ "$modes" == *9* ]] || [[ "$modes" == *8* ]] then continue; -- cgit v1.2.3 From 10d308d5ead864fe6b3db5228ed7833163bbca97 Mon Sep 17 00:00:00 2001 From: David Sterba Date: Tue, 22 Mar 2016 18:47:18 +0100 Subject: btrfs-progs: tests: introduce mustfail helper Invalid syntax, expected failure on corrupted data etc. Failure is success. Signed-off-by: David Sterba --- tests/common | 26 ++++++++++++++++++++++++++ 1 file changed, 26 insertions(+) (limited to 'tests') diff --git a/tests/common b/tests/common index 61780486..91682eff 100644 --- a/tests/common +++ b/tests/common @@ -61,6 +61,32 @@ run_mayfail() fi } +# first argument is error message to print if it fails, otherwise +# same as run_check but expects the command to fail, output is logged +run_mustfail() +{ + local msg + + msg="$1" + shift + + echo "############### $@" >> $RESULTS 2>&1 + if [ "$TEST_LOG" = 'tty' ]; then echo "CMD(mustfail): $@" > /dev/tty; fi + if [ "$1" = 'root_helper' ]; then + "$@" >> $RESULTS 2>&1 + else + $INSTRUMENT "$@" >> $RESULTS 2>&1 + fi + if [ $? != 0 ]; then + echo "failed (expected): $@" >> $RESULTS + return 0 + else + echo "succeeded (unexpected!): $@" >> $RESULTS + _fail "unexpected success: $msg" + return 1 + fi +} + check_prereq() { if ! [ -f $TOP/$1 ]; then -- cgit v1.2.3 From d7477bcd0b714a984f83b78aa19a9785bf3c8039 Mon Sep 17 00:00:00 2001 From: David Sterba Date: Tue, 22 Mar 2016 19:01:39 +0100 Subject: btrfs-progs: tests: add misc 014-filesystem-label Test various label lengths on a mounted filesystem. Signed-off-by: David Sterba --- tests/misc-tests/014-filesystem-label/test.sh | 69 +++++++++++++++++++++++++++ 1 file changed, 69 insertions(+) create mode 100755 tests/misc-tests/014-filesystem-label/test.sh (limited to 'tests') diff --git a/tests/misc-tests/014-filesystem-label/test.sh b/tests/misc-tests/014-filesystem-label/test.sh new file mode 100755 index 00000000..a5e08ccc --- /dev/null +++ b/tests/misc-tests/014-filesystem-label/test.sh @@ -0,0 +1,69 @@ +#!/bin/bash +# +# test label settings + +source $TOP/tests/common + +check_prereq mkfs.btrfs +check_prereq btrfs + +setup_root_helper + +run_check truncate -s 2G $IMAGE +run_check $TOP/mkfs.btrfs -L BTRFS-TEST-LABEL -f $IMAGE +run_check $SUDO_HELPER mount $IMAGE $TEST_MNT +run_check $SUDO_HELPER chmod a+rw $TEST_MNT + +cd $TEST_MNT +run_check $SUDO_HELPER $TOP/btrfs filesystem label $TEST_MNT +# shortest label +run_check $SUDO_HELPER $TOP/btrfs filesystem label $TEST_MNT a +run_check $SUDO_HELPER $TOP/btrfs filesystem label $TEST_MNT +run_check $SUDO_HELPER $TOP/btrfs filesystem label $TEST_MNT '' + +longlabel=\ +0123456789\ +0123456789\ +0123456789\ +0123456789\ +0123456789\ +\ +0123456789\ +0123456789\ +0123456789\ +0123456789\ +0123456789\ +\ +0123456789\ +0123456789\ +0123456789\ +0123456789\ +0123456789\ +\ +0123456789\ +0123456789\ +0123456789\ +0123456789\ +0123456789\ +\ +0123456789\ +0123456789\ +0123456789\ +0123456789\ +0123456789\ +\ +01234 + +run_check $SUDO_HELPER $TOP/btrfs filesystem label $TEST_MNT "$longlabel" +run_check $SUDO_HELPER $TOP/btrfs filesystem label $TEST_MNT +# 256, must fail +run_mustfail "label 256 bytes long succeeded" \ + $SUDO_HELPER $TOP/btrfs filesystem label $TEST_MNT "$longlabel"5 +run_check $SUDO_HELPER $TOP/btrfs filesystem label $TEST_MNT +run_mustfail "label 2 * 255 bytes long succeeded" \ + $SUDO_HELPER $TOP/btrfs filesystem label $TEST_MNT "$longlabel$longlabel" +run_check $SUDO_HELPER $TOP/btrfs filesystem label $TEST_MNT + +cd .. + +run_check $SUDO_HELPER umount $TEST_MNT -- cgit v1.2.3 From 39992e60a344ee357a0bd1afefd96141ed74f9a9 Mon Sep 17 00:00:00 2001 From: David Sterba Date: Wed, 30 Mar 2016 16:18:49 +0200 Subject: btrfs-progs: tests: update 001-basic-profiles, dup on multidev fs Testcase for "btrfs-progs: mkfs: fix an error when using DUP on multidev fs" Signed-off-by: David Sterba --- tests/mkfs-tests/001-basic-profiles/test.sh | 2 ++ 1 file changed, 2 insertions(+) (limited to 'tests') diff --git a/tests/mkfs-tests/001-basic-profiles/test.sh b/tests/mkfs-tests/001-basic-profiles/test.sh index 2747d429..a6769214 100755 --- a/tests/mkfs-tests/001-basic-profiles/test.sh +++ b/tests/mkfs-tests/001-basic-profiles/test.sh @@ -87,5 +87,7 @@ test_mkfs_multi -d raid5 -m raid5 test_mkfs_multi -d raid5 -m raid5 --mixed test_mkfs_multi -d raid6 -m raid6 test_mkfs_multi -d raid6 -m raid6 --mixed +test_mkfs_multi -d dup -m dup +test_mkfs_multi -d dup -m dup --mixed cleanup_devices -- cgit v1.2.3 From d75f0c12d2de062dd84c2aefa640c21dc0571c5b Mon Sep 17 00:00:00 2001 From: David Sterba Date: Sun, 20 Mar 2016 15:34:10 +0100 Subject: btrfs-progs: tests: add support for command line coverage tests Signed-off-by: David Sterba --- tests/cli-tests.sh | 41 +++++++++++++++++++++++++++++++++++++++ tests/cli-tests/001-btrfs/test.sh | 15 ++++++++++++++ 2 files changed, 56 insertions(+) create mode 100755 tests/cli-tests.sh create mode 100755 tests/cli-tests/001-btrfs/test.sh (limited to 'tests') diff --git a/tests/cli-tests.sh b/tests/cli-tests.sh new file mode 100755 index 00000000..e65e7f50 --- /dev/null +++ b/tests/cli-tests.sh @@ -0,0 +1,41 @@ +#!/bin/bash +# +# command line interface coverage tests + +unset TOP +unset LANG +LANG=C +SCRIPT_DIR=$(dirname $(readlink -f $0)) +TOP=$(readlink -f $SCRIPT_DIR/../) +TEST_DEV=${TEST_DEV:-} +RESULTS="$TOP/tests/cli-tests-results.txt" +IMAGE="$TOP/tests/test.img" + +source $TOP/tests/common + +export TOP +export RESULTS +export LANG +export IMAGE + +rm -f $RESULTS + +check_prereq btrfs + +# The tests are driven by their custom script called 'test.sh' + +for i in $(find $TOP/tests/cli-tests -maxdepth 1 -mindepth 1 -type d \ + ${TEST:+-name "$TEST"} | sort) +do + name=$(basename $i) + cd $i + if [ -x test.sh ]; then + echo "=== Entering $i" >> $RESULTS + echo " [TEST/cli] $name" + ./test.sh + if [ $? -ne 0 ]; then + _fail "test failed for case $(basename $i)" + fi + fi + cd $TOP +done diff --git a/tests/cli-tests/001-btrfs/test.sh b/tests/cli-tests/001-btrfs/test.sh new file mode 100755 index 00000000..1de2f6f2 --- /dev/null +++ b/tests/cli-tests/001-btrfs/test.sh @@ -0,0 +1,15 @@ +#!/bin/bash +# test commands of btrfs + +source $TOP/tests/common + +check_prereq btrfs + +# returns 1 +run_mayfail $TOP/btrfs || true +run_check $TOP/btrfs version +run_check $TOP/btrfs version -- +run_check $TOP/btrfs help +run_check $TOP/btrfs help -- +run_check $TOP/btrfs --help +run_check $TOP/btrfs --help --full -- cgit v1.2.3 From 0121270a799df52dab8de852b326ebdaf05e19c9 Mon Sep 17 00:00:00 2001 From: David Sterba Date: Mon, 2 May 2016 14:59:48 +0200 Subject: btrfs-progs: tests: add 002-balance-full-no-filters Coverage of new balance option --full-balance. Signed-off-by: David Sterba --- tests/cli-tests/002-balance-full-no-filters/test.sh | 21 +++++++++++++++++++++ 1 file changed, 21 insertions(+) create mode 100755 tests/cli-tests/002-balance-full-no-filters/test.sh (limited to 'tests') diff --git a/tests/cli-tests/002-balance-full-no-filters/test.sh b/tests/cli-tests/002-balance-full-no-filters/test.sh new file mode 100755 index 00000000..c2757f24 --- /dev/null +++ b/tests/cli-tests/002-balance-full-no-filters/test.sh @@ -0,0 +1,21 @@ +#!/bin/bash +# +# coverage of balance --full-balance + +source $TOP/tests/common + +check_prereq mkfs.btrfs +check_prereq btrfs + +setup_root_helper +prepare_test_dev 2g + +run_check $TOP/mkfs.btrfs -f $IMAGE +run_check_mount_test_dev + +run_check $SUDO_HELPER $TOP/btrfs balance start --full-balance $TEST_MNT +run_check $SUDO_HELPER $TOP/btrfs balance start $TEST_MNT +run_check $SUDO_HELPER $TOP/btrfs balance --full-balance $TEST_MNT +run_check $SUDO_HELPER $TOP/btrfs balance $TEST_MNT + +run_check_umount_test_dev -- cgit v1.2.3 From f2873c47d74c5972cec555620716a3753c02cb2b Mon Sep 17 00:00:00 2001 From: Liu Bo Date: Mon, 2 May 2016 11:18:55 -0700 Subject: btrfs-progs: add fuzzed testing images, superblock and chunks This adds 4 fuzz testing images, btrfsck either doesn't detect errors in them or crashes immediately. Reported-by: Vegard Nossum Reported-by: Quentin Casasnovas Signed-off-by: Liu Bo Signed-off-by: David Sterba --- .../images/superblock-stripsize-bogus.raw.txt | 32 ++++++++++++ .../images/superblock-stripsize-bogus.raw.xz | Bin 0 -> 41512 bytes .../images/superblock-total-bytes-0.raw.txt | 50 +++++++++++++++++++ .../images/superblock-total-bytes-0.raw.xz | Bin 0 -> 41424 bytes .../images/sys-chunk-stripe-len-bogus.raw.txt | 54 ++++++++++++++++++++ .../images/sys-chunk-stripe-len-bogus.raw.xz | Bin 0 -> 41440 bytes .../fuzz-tests/images/sys-chunk-type-bogus.raw.txt | 55 +++++++++++++++++++++ .../fuzz-tests/images/sys-chunk-type-bogus.raw.xz | Bin 0 -> 41524 bytes 8 files changed, 191 insertions(+) create mode 100644 tests/fuzz-tests/images/superblock-stripsize-bogus.raw.txt create mode 100644 tests/fuzz-tests/images/superblock-stripsize-bogus.raw.xz create mode 100644 tests/fuzz-tests/images/superblock-total-bytes-0.raw.txt create mode 100644 tests/fuzz-tests/images/superblock-total-bytes-0.raw.xz create mode 100644 tests/fuzz-tests/images/sys-chunk-stripe-len-bogus.raw.txt create mode 100644 tests/fuzz-tests/images/sys-chunk-stripe-len-bogus.raw.xz create mode 100644 tests/fuzz-tests/images/sys-chunk-type-bogus.raw.txt create mode 100644 tests/fuzz-tests/images/sys-chunk-type-bogus.raw.xz (limited to 'tests') diff --git a/tests/fuzz-tests/images/superblock-stripsize-bogus.raw.txt b/tests/fuzz-tests/images/superblock-stripsize-bogus.raw.txt new file mode 100644 index 00000000..80e073f6 --- /dev/null +++ b/tests/fuzz-tests/images/superblock-stripsize-bogus.raw.txt @@ -0,0 +1,32 @@ +[ 125.415910] BTRFS info (device loop0): disk space caching is enabled +[ 125.550479] ------------[ cut here ]------------ +[ 125.551145] WARNING: CPU: 6 PID: 1496 at fs/btrfs/locking.c:251 btrfs_tree_lock+0x22e/0x250 +[ 125.552292] Modules linked in: +[ 125.552602] CPU: 6 PID: 1496 Comm: btrfs.exe Tainted: G W 4.6.0-rc5 #130 +[ 125.553138] Hardware name: QEMU Standard PC (i440FX + PIIX, 1996), BIOS 1.8.2-20150714_191134- 04/01/2014 +[ 125.553775] 0000000000000286 000000009b4bdd50 ffff88006a7478e0 ffffffff8157e563 +[ 125.554299] 0000000000000000 0000000000000000 ffff88006a747920 ffffffff810a74ab +[ 125.554825] 000000fb8146c531 ffff88006bfec460 ffff88006bc63000 0000000000000000 +[ 125.555373] Call Trace: +[ 125.555545] [] dump_stack+0x85/0xc2 +[ 125.555892] [] __warn+0xcb/0xf0 +[ 125.556226] [] warn_slowpath_null+0x1d/0x20 +[ 125.556654] [] btrfs_tree_lock+0x22e/0x250 +[ 125.557041] [] btrfs_init_new_buffer+0x81/0x160 +[ 125.557458] [] btrfs_alloc_tree_block+0x22a/0x430 +[ 125.557883] [] __btrfs_cow_block+0x141/0x590 +[ 125.558279] [] btrfs_cow_block+0x11f/0x1f0 +[ 125.558666] [] btrfs_search_slot+0x1fe/0xa30 +[ 125.559063] [] ? kmem_cache_alloc+0xfd/0x240 +[ 125.559482] [] btrfs_del_inode_ref+0x80/0x380 +[ 125.559884] [] ? btrfs_del_inode_ref_in_log+0x8a/0x160 +[ 125.560340] [] btrfs_del_inode_ref_in_log+0xbd/0x160 +[ 125.560776] [] __btrfs_unlink_inode+0x1d7/0x470 +[ 125.561188] [] btrfs_rename2+0x327/0x790 +[ 125.561568] [] vfs_rename+0x4d8/0x840 +[ 125.561928] [] SyS_rename+0x371/0x390 +[ 125.562289] [] entry_SYSCALL_64_fastpath+0x1f/0xbd +[ 125.562743] ---[ end trace 3b751f511705fb90 ]--- + +--------------------------------------------------------------------------- +Fixed by patch: diff --git a/tests/fuzz-tests/images/superblock-stripsize-bogus.raw.xz b/tests/fuzz-tests/images/superblock-stripsize-bogus.raw.xz new file mode 100644 index 00000000..f8b3bf54 Binary files /dev/null and b/tests/fuzz-tests/images/superblock-stripsize-bogus.raw.xz differ diff --git a/tests/fuzz-tests/images/superblock-total-bytes-0.raw.txt b/tests/fuzz-tests/images/superblock-total-bytes-0.raw.txt new file mode 100644 index 00000000..d5e1f936 --- /dev/null +++ b/tests/fuzz-tests/images/superblock-total-bytes-0.raw.txt @@ -0,0 +1,50 @@ +[342246.846031] BTRFS info (device loop0): disk space caching is enabled +[342246.862115] ------------[ cut here ]------------ +[342246.862500] kernel BUG at fs/btrfs/inode.c:978! +[342246.862861] invalid opcode: 0000 [#1] SMP +[342246.863176] Modules linked in: +[342246.863410] CPU: 2 PID: 14504 Comm: btrfs.exe Tainted: G W 4.6.0-rc5 #130 +[342246.864010] Hardware name: QEMU Standard PC (i440FX + PIIX, 1996), BIOS 1.8.2-20150714_191134- 04/01/2014 +[342246.864674] task: ffff88006fdf0000 ti: ffff8800702e0000 task.ti: ffff8800702e0000 +[342246.865186] RIP: 0010:[] [] cow_file_range+0x3f7/0x440 +[342246.865770] RSP: 0018:ffff8800702e39e0 EFLAGS: 00010206 +[342246.866157] RAX: ffff88006bb23000 RBX: 0000000000000001 RCX: 0000000000010000 +[342246.866687] RDX: 0000000000000000 RSI: 0000000000001000 RDI: 0000000000010000 +[342246.867191] RBP: ffff8800702e3a70 R08: 0000000000000000 R09: 0000000000000000 +[342246.867682] R10: 000000000000ffff R11: 0000000000010000 R12: ffff8800702e3bc0 +[342246.868170] R13: ffff8800702e3b3c R14: 0000000000000000 R15: ffff880075369c10 +[342246.868660] FS: 00007f96f5a38700(0000) GS:ffff88007ca00000(0000) knlGS:0000000000000000 +[342246.869212] CS: 0010 DS: 0000 ES: 0000 CR0: 0000000080050033 +[342246.869642] CR2: 000000000060f4bf CR3: 000000006fc9f000 CR4: 00000000000006e0 +[342246.870146] Stack: +[342246.870295] 0000000000000000 0000000000000001 000000000000ffff ffffea00010c08c0 +[342246.870838] ffff8800753698e8 0000000000010000 ffff88006fe0f000 000000000000ffff +[342246.871397] 000000000000ffff ffffffff814683e5 ffff8800753698c8 ffff8800753698e8 +[342246.871944] Call Trace: +[342246.872124] [] ? test_range_bit+0xe5/0x130 +[342246.872522] [] run_delalloc_range+0x396/0x3d0 +[342246.872975] [] writepage_delalloc.isra.42+0x10f/0x170 +[342246.873437] [] __extent_writepage+0xf4/0x370 +[342246.873848] [] extent_write_cache_pages.isra.39.constprop.57+0x304/0x3f0 +[342246.874419] [] extent_writepages+0x5c/0x90 +[342246.874818] [] ? btrfs_real_readdir+0x5f0/0x5f0 +[342246.875245] [] btrfs_writepages+0x28/0x30 +[342246.875641] [] do_writepages+0x21/0x30 +[342246.876031] [] __filemap_fdatawrite_range+0xc6/0x100 +[342246.876487] [] filemap_fdatawrite_range+0x13/0x20 +[342246.876949] [] btrfs_fdatawrite_range+0x20/0x50 +[342246.877375] [] start_ordered_ops+0x19/0x30 +[342246.877774] [] btrfs_sync_file+0x82/0x3f0 +[342246.878166] [] ? update_fast_ctr+0x17/0x30 +[342246.878564] [] vfs_fsync_range+0x4b/0xb0 +[342246.878987] [] ? __fget_light+0x66/0x90 +[342246.879368] [] do_fsync+0x3d/0x70 +[342246.879708] [] SyS_fdatasync+0x13/0x20 +[342246.880099] [] entry_SYSCALL_64_fastpath+0x1f/0xbd +[342246.880554] Code: 03 00 00 48 c7 c7 00 b3 c9 81 c6 05 54 b6 b1 00 01 e8 0e 8c c5 ff e9 e5 fe ff ff 49 8b 57 40 e9 c0 fe ff ff bb f4 ff ff ff eb a1 <0f> 0b 48 8b 55 80 41 b9 0f 00 00 00 41 b8 68 00 00 00 31 c9 31 +[342246.882394] RIP [] cow_file_range+0x3f7/0x440 +[342246.882810] RSP +[342246.883076] ---[ end trace 094193b6df6e45e7 ]--- + +-------------------------------------------------------- +Fixed by patch: diff --git a/tests/fuzz-tests/images/superblock-total-bytes-0.raw.xz b/tests/fuzz-tests/images/superblock-total-bytes-0.raw.xz new file mode 100644 index 00000000..4b25020e Binary files /dev/null and b/tests/fuzz-tests/images/superblock-total-bytes-0.raw.xz differ diff --git a/tests/fuzz-tests/images/sys-chunk-stripe-len-bogus.raw.txt b/tests/fuzz-tests/images/sys-chunk-stripe-len-bogus.raw.txt new file mode 100644 index 00000000..d3dcb0a4 --- /dev/null +++ b/tests/fuzz-tests/images/sys-chunk-stripe-len-bogus.raw.txt @@ -0,0 +1,54 @@ +[ 135.166891] BTRFS info (device loop0): disk space caching is enabled +[ 135.169199] divide error: 0000 [#1] SMP +[ 135.169581] Modules linked in: +[ 135.169819] CPU: 2 PID: 1512 Comm: btrfs.exe Tainted: G W 4.6.0-rc5 #130 +[ 135.170285] Hardware name: QEMU Standard PC (i440FX + PIIX, 1996), BIOS 1.8.2-20150714_191134- 04/01/2014 +[ 135.170958] task: ffff880074925180 ti: ffff880077fa4000 task.ti: ffff880077fa4000 +[ 135.171583] RIP: 0010:[] [] __btrfs_map_block+0xc0/0x11b0 +[ 135.172096] RSP: 0000:ffff880077fa77b0 EFLAGS: 00010206 +[ 135.172374] RAX: 0000000000020000 RBX: 0000000000020000 RCX: 0000000000000000 +[ 135.172754] RDX: 0000000000000000 RSI: 0000000000400000 RDI: ffff880076258270 +[ 135.173143] RBP: ffff880077fa7898 R08: 0000000000400000 R09: 0000000000000000 +[ 135.173523] R10: 0000000000000001 R11: 0000000000000000 R12: 0000000000020000 +[ 135.173916] R13: ffff880076258270 R14: ffff880077fa78e0 R15: ffff88006bb3b000 +[ 135.174290] FS: 00007fd8267dc700(0000) GS:ffff88007ca00000(0000) knlGS:0000000000000000 +[ 135.174718] CS: 0010 DS: 0000 ES: 0000 CR0: 0000000080050033 +[ 135.175019] CR2: 00007ffe9c378df7 CR3: 0000000078788000 CR4: 00000000000006e0 +[ 135.175392] Stack: +[ 135.175503] ffff88007cbe2c40 0000000000000000 ffff88007cbe2c50 ffff880074925180 +[ 135.175924] ffff880074926560 ffff880074925180 0000000200000000 0000000000000000 +[ 135.176340] ffffffffffffffff 0007ffffffffffff ffffffff8143eb18 0240004000000000 +[ 135.176778] Call Trace: +[ 135.176913] [] ? btrfs_bio_wq_end_io+0x28/0x70 +[ 135.177234] [] btrfs_map_bio+0x88/0x350 +[ 135.177522] [] ? btrfs_bio_wq_end_io+0x28/0x70 +[ 135.177960] [] btree_submit_bio_hook+0x6d/0x110 +[ 135.178410] [] submit_one_bio+0x6d/0xa0 +[ 135.178814] [] read_extent_buffer_pages+0x1c1/0x350 +[ 135.179276] [] ? free_root_pointers+0x70/0x70 +[ 135.179708] [] btree_read_extent_buffer_pages.constprop.55+0xac/0x110 +[ 135.180261] [] read_tree_block+0x36/0x60 +[ 135.180647] [] open_ctree+0x17a2/0x2900 +[ 135.181027] [] btrfs_mount+0xd05/0xe60 +[ 135.181400] [] ? __mutex_unlock_slowpath+0xfa/0x1c0 +[ 135.181850] [] ? lockdep_init_map+0x64/0x710 +[ 135.182241] [] mount_fs+0x38/0x170 +[ 135.182609] [] vfs_kern_mount+0x6b/0x150 +[ 135.182998] [] btrfs_mount+0x1c6/0xe60 +[ 135.183372] [] ? __mutex_unlock_slowpath+0xfa/0x1c0 +[ 135.183825] [] ? lockdep_init_map+0x64/0x710 +[ 135.184233] [] mount_fs+0x38/0x170 +[ 135.184583] [] vfs_kern_mount+0x6b/0x150 +[ 135.184971] [] do_mount+0x256/0xeb0 +[ 135.185318] [] ? __kmalloc_track_caller+0x113/0x290 +[ 135.185759] [] ? block_ioctl+0x43/0x50 +[ 135.186124] [] ? memdup_user+0x53/0x80 +[ 135.186488] [] SyS_mount+0x95/0xe0 +[ 135.186877] [] entry_SYSCALL_64_fastpath+0x1f/0xbd +[ 135.187308] Code: 8b 70 20 4c 8d 04 31 4c 39 c3 0f 87 2f 0b 00 00 48 8b 45 a8 49 89 dc 31 d2 49 29 cc 48 8b 40 70 48 63 48 10 48 89 45 a0 4c 89 e0 <48> f7 f1 49 89 cf 48 89 45 b8 48 0f af c1 49 39 c4 0f 82 c3 0a +[ 135.189097] RIP [] __btrfs_map_block+0xc0/0x11b0 +[ 135.189527] RSP +[ 135.189819] ---[ end trace ea21fae64670799a ]--- + +--------------------------------------------------------------------------- +Fixed by patch: diff --git a/tests/fuzz-tests/images/sys-chunk-stripe-len-bogus.raw.xz b/tests/fuzz-tests/images/sys-chunk-stripe-len-bogus.raw.xz new file mode 100644 index 00000000..57d2a72f Binary files /dev/null and b/tests/fuzz-tests/images/sys-chunk-stripe-len-bogus.raw.xz differ diff --git a/tests/fuzz-tests/images/sys-chunk-type-bogus.raw.txt b/tests/fuzz-tests/images/sys-chunk-type-bogus.raw.txt new file mode 100644 index 00000000..2559924d --- /dev/null +++ b/tests/fuzz-tests/images/sys-chunk-type-bogus.raw.txt @@ -0,0 +1,55 @@ +[ 145.676440] BTRFS error (device loop0): bad tree block start 0 131072 +[ 145.677032] ------------[ cut here ]------------ +[ 145.677307] kernel BUG at fs/btrfs/raid56.c:2142! +[ 145.677627] invalid opcode: 0000 [#1] SMP +[ 145.677955] Modules linked in: +[ 145.678182] CPU: 3 PID: 1538 Comm: btrfs.exe Tainted: G W 4.6.0-rc5 #130 +[ 145.678734] Hardware name: QEMU Standard PC (i440FX + PIIX, 1996), BIOS 1.8.2-20150714_191134- 04/01/2014 +[ 145.679402] task: ffff88006c830000 ti: ffff88006fc74000 task.ti: ffff88006fc74000 +[ 145.679919] RIP: 0010:[] [] raid56_parity_recover+0xc4/0x160 +[ 145.680514] RSP: 0018:ffff88006fc77868 EFLAGS: 00010286 +[ 145.680865] RAX: ffff88006f725280 RBX: ffff880070ba0a68 RCX: 0000000000020000 +[ 145.681373] RDX: 0000000000000100 RSI: 00000000ffffffff RDI: ffffffff831229e8 +[ 145.681866] RBP: ffff88006fc77898 R08: 0000000000010000 R09: ffff8800768ff400 +[ 145.682380] R10: ffff88007c003180 R11: 0000000000030000 R12: ffff88006f725280 +[ 145.682870] R13: ffff88007b449000 R14: 0000000000000001 R15: ffff8800768ff400 +[ 145.683363] FS: 00007f68b95a8700(0000) GS:ffff88007cc00000(0000) knlGS:0000000000000000 +[ 145.683941] CS: 0010 DS: 0000 ES: 0000 CR0: 0000000080050033 +[ 145.684340] CR2: 00007fff0d130f98 CR3: 000000006bfd7000 CR4: 00000000000006e0 +[ 145.684832] Stack: +[ 145.684977] 00000002e6816dd1 ffff880070ba0a68 ffff88007b449000 0000000000000001 +[ 145.685541] 0000000000020000 0000000000000002 ffff88006fc77920 ffffffff814773cd +[ 145.686082] ffff880000000001 0000000002400040 ffff88006fc778f8 0000000081247c9d +[ 145.686654] Call Trace: +[ 145.686831] [] btrfs_map_bio+0x23d/0x350 +[ 145.687217] [] btree_submit_bio_hook+0x6d/0x110 +[ 145.687649] [] submit_one_bio+0x6d/0xa0 +[ 145.688028] [] read_extent_buffer_pages+0x1c1/0x350 +[ 145.688501] [] ? free_root_pointers+0x70/0x70 +[ 145.688916] [] btree_read_extent_buffer_pages.constprop.55+0xac/0x110 +[ 145.689474] [] read_tree_block+0x36/0x60 +[ 145.689861] [] open_ctree+0x17a2/0x2900 +[ 145.690242] [] btrfs_mount+0xd05/0xe60 +[ 145.690623] [] ? __mutex_unlock_slowpath+0xfa/0x1c0 +[ 145.691064] [] ? lockdep_init_map+0x64/0x710 +[ 145.691510] [] mount_fs+0x38/0x170 +[ 145.691852] [] vfs_kern_mount+0x6b/0x150 +[ 145.692227] [] btrfs_mount+0x1c6/0xe60 +[ 145.692594] [] ? __mutex_unlock_slowpath+0xfa/0x1c0 +[ 145.693032] [] ? lockdep_init_map+0x64/0x710 +[ 145.693453] [] mount_fs+0x38/0x170 +[ 145.693793] [] vfs_kern_mount+0x6b/0x150 +[ 145.694168] [] do_mount+0x256/0xeb0 +[ 145.694537] [] ? __kmalloc_track_caller+0x113/0x290 +[ 145.694974] [] ? block_ioctl+0x43/0x50 +[ 145.695338] [] ? memdup_user+0x53/0x80 +[ 145.695703] [] SyS_mount+0x95/0xe0 +[ 145.696046] [] entry_SYSCALL_64_fastpath+0x1f/0xbd +[ 145.696480] Code: 1f 48 8b 78 58 31 c0 48 8b 14 c7 48 39 d1 72 08 4c 01 c2 48 39 d1 72 15 48 83 c0 01 39 c6 7f e7 41 c7 87 3c 01 00 00 ff ff ff ff <0f> 0b 45 85 f6 41 89 87 3c 01 00 00 75 35 4c 89 e7 e8 e6 02 fb +[ 145.698326] RIP [] raid56_parity_recover+0xc4/0x160 +[ 145.698771] RSP +[ 145.699047] ---[ end trace 22f39f01df276367 ]--- + +----------------------------------------------------- +Fixed by patch: + diff --git a/tests/fuzz-tests/images/sys-chunk-type-bogus.raw.xz b/tests/fuzz-tests/images/sys-chunk-type-bogus.raw.xz new file mode 100644 index 00000000..ef971ca3 Binary files /dev/null and b/tests/fuzz-tests/images/sys-chunk-type-bogus.raw.xz differ -- cgit v1.2.3 From bd2cc320aff5789fe4034736fa6da8b4ebae475f Mon Sep 17 00:00:00 2001 From: Nicholas D Steeves Date: Wed, 11 May 2016 19:50:36 -0400 Subject: btrfs-progs: typo review of strings and comments Signed-off-by: Nicholas D Steeves Signed-off-by: David Sterba --- tests/README.md | 4 ++-- tests/common | 2 +- tests/fsck-tests.sh | 2 +- tests/misc-tests.sh | 2 +- tests/misc-tests/007-subvolume-sync/test.sh | 4 ++-- tests/misc-tests/009-subvolume-sync-must-wait/test.sh | 2 +- tests/misc-tests/013-subvolume-sync-crash/test.sh | 2 +- tests/mkfs-tests.sh | 2 +- tests/mkfs-tests/008-secorsize-nodesize-combination/test.sh | 2 +- 9 files changed, 11 insertions(+), 11 deletions(-) (limited to 'tests') diff --git a/tests/README.md b/tests/README.md index be3bda82..a5837479 100644 --- a/tests/README.md +++ b/tests/README.md @@ -20,7 +20,7 @@ category, eg. `fsck-tests-results.txt`. ## Selective testing -The test are prefixed by a number for ordering and uniquenes. To run a +The test are prefixed by a number for ordering and uniqueness. To run a particular test use: ```shell @@ -120,7 +120,7 @@ close to the purpose of your new test. * Use the highest unused number in the sequence, write a short descriptive title and join by dashes `-`. -* Write a short description of the bug and how it's teste to the comment at the +* Write a short description of the bug and how it's tested to the comment at the begining of `test.sh`. * Write the test commands, comment anything that's not obvious. diff --git a/tests/common b/tests/common index 91682eff..8a626b6a 100644 --- a/tests/common +++ b/tests/common @@ -90,7 +90,7 @@ run_mustfail() check_prereq() { if ! [ -f $TOP/$1 ]; then - _fail "Failed prerequisities: $1"; + _fail "Failed prerequisites: $1"; fi } diff --git a/tests/fsck-tests.sh b/tests/fsck-tests.sh index 2aab4ff2..fb861635 100755 --- a/tests/fsck-tests.sh +++ b/tests/fsck-tests.sh @@ -18,7 +18,7 @@ source $TOP/tests/common # Allow child test to use $TOP and $RESULTS export TOP export RESULTS -# For custom script needs to verfiy recovery +# For custom script needs to verify recovery export LANG rm -f $RESULTS diff --git a/tests/misc-tests.sh b/tests/misc-tests.sh index 2a7f57c5..0cf8c4b2 100755 --- a/tests/misc-tests.sh +++ b/tests/misc-tests.sh @@ -16,7 +16,7 @@ source $TOP/tests/common # Allow child test to use $TOP and $RESULTS export TOP export RESULTS -# For custom script needs to verfiy recovery +# For custom script needs to verify recovery export LANG # For tests that only use a loop device export IMAGE diff --git a/tests/misc-tests/007-subvolume-sync/test.sh b/tests/misc-tests/007-subvolume-sync/test.sh index a745fb56..243bb8cc 100755 --- a/tests/misc-tests/007-subvolume-sync/test.sh +++ b/tests/misc-tests/007-subvolume-sync/test.sh @@ -1,7 +1,7 @@ #!/bin/bash # test btrfs subvolume run normally with more than one subvolume # -# - btrfs subvolume must not loop indefinetelly +# - btrfs subvolume must not loop indefinitely # - btrfs subvolume return 0 in normal case source $TOP/tests/common @@ -16,7 +16,7 @@ run_check $SUDO_HELPER $TOP/mkfs.btrfs -f "$TEST_DEV" run_check_mount_test_dev # to check following thing in both 1 and multiple subvolume case: -# 1: is subvolume sync loop indefinetelly +# 1: is subvolume sync loop indefinitely # 2: is return value right # run_check $SUDO_HELPER $TOP/btrfs subvolume create "$TEST_MNT"/mysubvol1 diff --git a/tests/misc-tests/009-subvolume-sync-must-wait/test.sh b/tests/misc-tests/009-subvolume-sync-must-wait/test.sh index 056584e5..92c896f9 100755 --- a/tests/misc-tests/009-subvolume-sync-must-wait/test.sh +++ b/tests/misc-tests/009-subvolume-sync-must-wait/test.sh @@ -1,6 +1,6 @@ #!/bin/bash # -# Verify that subovolume sync waits until the subvolume is cleaned +# Verify that subvolume sync waits until the subvolume is cleaned source $TOP/tests/common diff --git a/tests/misc-tests/013-subvolume-sync-crash/test.sh b/tests/misc-tests/013-subvolume-sync-crash/test.sh index c7955269..4cb1b4e7 100755 --- a/tests/misc-tests/013-subvolume-sync-crash/test.sh +++ b/tests/misc-tests/013-subvolume-sync-crash/test.sh @@ -1,6 +1,6 @@ #!/bin/bash # -# Verify that subovolume sync waits until the subvolume is cleaned and does not +# Verify that subvolume sync waits until the subvolume is cleaned and does not # crash at the end source $TOP/tests/common diff --git a/tests/mkfs-tests.sh b/tests/mkfs-tests.sh index c0635ad1..363a865e 100755 --- a/tests/mkfs-tests.sh +++ b/tests/mkfs-tests.sh @@ -16,7 +16,7 @@ source $TOP/tests/common # Allow child test to use $TOP and $RESULTS export TOP export RESULTS -# For custom script needs to verfiy recovery +# For custom script needs to verify recovery export LANG # For tests that only use a loop device export IMAGE diff --git a/tests/mkfs-tests/008-secorsize-nodesize-combination/test.sh b/tests/mkfs-tests/008-secorsize-nodesize-combination/test.sh index 79cc2b22..151e7b77 100755 --- a/tests/mkfs-tests/008-secorsize-nodesize-combination/test.sh +++ b/tests/mkfs-tests/008-secorsize-nodesize-combination/test.sh @@ -34,7 +34,7 @@ do_test 8191 8191 && _fail # Invalid: Aligned sectorsize with unaligned nodesize do_test 4k 16385 && _fail -# Invalid: Ungliend sectorsize with aligned nodesize +# Invalid: Unaligned sectorsize with aligned nodesize do_test 8191 16k && _fail # Valid: Aligned sectorsize and nodesize -- cgit v1.2.3 From 9071a102102f26c2e83932be1906e628eae4cb73 Mon Sep 17 00:00:00 2001 From: Lu Fengqi Date: Mon, 30 May 2016 10:58:13 +0800 Subject: btrfs-progs: tests: add 020-extent-ref-cases In order to confirm that btrfsck supports to check a variety of refs, add the following cases: * keyed_block_ref * keyed_data_ref * shared_block_ref * shared_data_ref * no_inline_ref (a extent item without inline ref) * no_skinny_ref Signed-off-by: Lu Fengqi Signed-off-by: David Sterba --- .../020-extent-ref-cases/keyed_block_ref.img | Bin 0 -> 10240 bytes .../020-extent-ref-cases/keyed_data_ref.img | Bin 0 -> 4096 bytes .../020-extent-ref-cases/no_inline_ref.img | Bin 0 -> 4096 bytes .../020-extent-ref-cases/no_skinny_ref.img | Bin 0 -> 3072 bytes .../020-extent-ref-cases/shared_block_ref.img | Bin 0 -> 23552 bytes .../020-extent-ref-cases/shared_data_ref.img | Bin 0 -> 5120 bytes tests/fsck-tests/020-extent-ref-cases/test.sh | 23 +++++++++++++++++++++ 7 files changed, 23 insertions(+) create mode 100644 tests/fsck-tests/020-extent-ref-cases/keyed_block_ref.img create mode 100644 tests/fsck-tests/020-extent-ref-cases/keyed_data_ref.img create mode 100644 tests/fsck-tests/020-extent-ref-cases/no_inline_ref.img create mode 100644 tests/fsck-tests/020-extent-ref-cases/no_skinny_ref.img create mode 100644 tests/fsck-tests/020-extent-ref-cases/shared_block_ref.img create mode 100644 tests/fsck-tests/020-extent-ref-cases/shared_data_ref.img create mode 100755 tests/fsck-tests/020-extent-ref-cases/test.sh (limited to 'tests') diff --git a/tests/fsck-tests/020-extent-ref-cases/keyed_block_ref.img b/tests/fsck-tests/020-extent-ref-cases/keyed_block_ref.img new file mode 100644 index 00000000..289d37bc Binary files /dev/null and b/tests/fsck-tests/020-extent-ref-cases/keyed_block_ref.img differ diff --git a/tests/fsck-tests/020-extent-ref-cases/keyed_data_ref.img b/tests/fsck-tests/020-extent-ref-cases/keyed_data_ref.img new file mode 100644 index 00000000..2ac0ae53 Binary files /dev/null and b/tests/fsck-tests/020-extent-ref-cases/keyed_data_ref.img differ diff --git a/tests/fsck-tests/020-extent-ref-cases/no_inline_ref.img b/tests/fsck-tests/020-extent-ref-cases/no_inline_ref.img new file mode 100644 index 00000000..b05ae73f Binary files /dev/null and b/tests/fsck-tests/020-extent-ref-cases/no_inline_ref.img differ diff --git a/tests/fsck-tests/020-extent-ref-cases/no_skinny_ref.img b/tests/fsck-tests/020-extent-ref-cases/no_skinny_ref.img new file mode 100644 index 00000000..900b65ca Binary files /dev/null and b/tests/fsck-tests/020-extent-ref-cases/no_skinny_ref.img differ diff --git a/tests/fsck-tests/020-extent-ref-cases/shared_block_ref.img b/tests/fsck-tests/020-extent-ref-cases/shared_block_ref.img new file mode 100644 index 00000000..8d7b50f7 Binary files /dev/null and b/tests/fsck-tests/020-extent-ref-cases/shared_block_ref.img differ diff --git a/tests/fsck-tests/020-extent-ref-cases/shared_data_ref.img b/tests/fsck-tests/020-extent-ref-cases/shared_data_ref.img new file mode 100644 index 00000000..aa2dafa5 Binary files /dev/null and b/tests/fsck-tests/020-extent-ref-cases/shared_data_ref.img differ diff --git a/tests/fsck-tests/020-extent-ref-cases/test.sh b/tests/fsck-tests/020-extent-ref-cases/test.sh new file mode 100755 index 00000000..c2b6a006 --- /dev/null +++ b/tests/fsck-tests/020-extent-ref-cases/test.sh @@ -0,0 +1,23 @@ +#!/bin/bash +# In order to confirm that btrfsck supports to check a variety of refs, add the +# following cases: +# +# * keyed_block_ref +# * keyed_data_ref +# * shared_block_ref +# * shared_data_ref +# * no_inline_ref (a extent item without inline ref) +# * no_skinny_ref + +source $TOP/tests/common + +check_prereq btrfs + +for img in *.img +do + image=$(extract_image $img) + run_check_stdout $TOP/btrfs check "$image" 2>&1 | + grep -q "Errors found in extent allocation tree or chunk allocation" && + _fail "unexpected error occurred when checking $img" + rm -f "$image" +done -- cgit v1.2.3 From 3f063f6bdc67e067b12898f018ef31df8c14c96c Mon Sep 17 00:00:00 2001 From: David Sterba Date: Mon, 30 May 2016 17:07:35 +0200 Subject: btrfs-progs: tests: convert, run md5sum with sudo helper Some of the files might not end up in the checksum list because of permissions. This is reported by md5sum as incorrectly formatted lines. Signed-off-by: David Sterba --- tests/convert-tests.sh | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) (limited to 'tests') diff --git a/tests/convert-tests.sh b/tests/convert-tests.sh index 06d8419e..d42d287b 100755 --- a/tests/convert-tests.sh +++ b/tests/convert-tests.sh @@ -127,7 +127,7 @@ convert_test() { populate_fs run_check $SUDO_HELPER dd if=/dev/zero of=$TEST_MNT/test bs=$nodesize \ count=1 >/dev/null 2>&1 - run_check_stdout find $TEST_MNT -type f ! -name 'image' -exec md5sum {} \+ > $CHECKSUMTMP + run_check_stdout $SUDO_HELPER find $TEST_MNT -type f ! -name 'image' -exec md5sum {} \+ > $CHECKSUMTMP run_check_umount_test_dev run_check $TOP/btrfs-convert ${features:+-O "$features"} -N "$nodesize" $TEST_DEV @@ -135,7 +135,7 @@ convert_test() { run_check $TOP/btrfs-show-super $TEST_DEV run_check_mount_test_dev - run_check_stdout md5sum -c $CHECKSUMTMP | + run_check_stdout $SUDO_HELPER md5sum -c $CHECKSUMTMP | grep -q 'FAILED' && _fail "file validation failed." run_check_umount_test_dev } -- cgit v1.2.3 From 0993ae5a73d5d0709b543faa0c528931a0f7fc36 Mon Sep 17 00:00:00 2001 From: David Sterba Date: Mon, 30 May 2016 17:11:19 +0200 Subject: btrfs-progs: tests: run rollback after conversion Signed-off-by: David Sterba --- tests/convert-tests.sh | 3 +++ 1 file changed, 3 insertions(+) (limited to 'tests') diff --git a/tests/convert-tests.sh b/tests/convert-tests.sh index d42d287b..cbcd1cf9 100755 --- a/tests/convert-tests.sh +++ b/tests/convert-tests.sh @@ -138,6 +138,9 @@ convert_test() { run_check_stdout $SUDO_HELPER md5sum -c $CHECKSUMTMP | grep -q 'FAILED' && _fail "file validation failed." run_check_umount_test_dev + + run_check $TOP/btrfs-convert --rollback $TEST_DEV + run_check fsck -n -t ext2,ext3,ext4 $TEST_DEV } if ! [ -z "$TEST" ]; then -- cgit v1.2.3 From bff682877848b2b8750a0f37221f90aec5e834ba Mon Sep 17 00:00:00 2001 From: David Sterba Date: Tue, 31 May 2016 19:17:02 +0200 Subject: btrfs-progs: tests: convert: dump all superblocks after conversion We want to see all of them, even if they're not valid. Signed-off-by: David Sterba --- tests/convert-tests.sh | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) (limited to 'tests') diff --git a/tests/convert-tests.sh b/tests/convert-tests.sh index cbcd1cf9..94285170 100755 --- a/tests/convert-tests.sh +++ b/tests/convert-tests.sh @@ -132,7 +132,7 @@ convert_test() { run_check $TOP/btrfs-convert ${features:+-O "$features"} -N "$nodesize" $TEST_DEV run_check $TOP/btrfs check $TEST_DEV - run_check $TOP/btrfs-show-super $TEST_DEV + run_check $TOP/btrfs-show-super -Ffa $TEST_DEV run_check_mount_test_dev run_check_stdout $SUDO_HELPER md5sum -c $CHECKSUMTMP | -- cgit v1.2.3 From 205bd5edbea4be51fe366e1e7588a88b7cead1b7 Mon Sep 17 00:00:00 2001 From: David Sterba Date: Wed, 1 Jun 2016 13:22:44 +0200 Subject: btrfs-progs: tests: document cli-tests in readme Signed-off-by: David Sterba --- tests/README.md | 7 +++++++ 1 file changed, 7 insertions(+) (limited to 'tests') diff --git a/tests/README.md b/tests/README.md index a5837479..19d27ab8 100644 --- a/tests/README.md +++ b/tests/README.md @@ -54,6 +54,13 @@ will run the first test in fsck-tests subdirectory. * tests that are supposed to run various utilities on the images and not crash +*tests/cli-tests/:* + + * tests for command line interface, option coverage, weird optin combinations that should not work + * not necessary to do any functional testing, could be rather lightweight + * functional tests should go to to other test dirs + * the driver script will only execute `./test.sh` in the test directory + *tests/misc-tests/:* * anything that does not fit to the above, the test driver script will only -- cgit v1.2.3 From bb3c2ea224ea4e3caa35c3e63187a48e2f9dfe18 Mon Sep 17 00:00:00 2001 From: Qu Wenruo Date: Wed, 1 Jun 2016 09:51:21 +0800 Subject: btrfs-progs: convert-tests: Add test for backup superblock migration New convert framework uses new and simpler chunk layout, while the cost is the more complex superblock range migration logical, compared to old convert. Enhance the convert test script to create file which will takes up 2nd backup superblock space, to ensure the superblock migration is working as expected. Suggested-by: David Sterba Signed-off-by: Qu Wenruo Signed-off-by: David Sterba --- tests/convert-tests.sh | 6 ++++++ 1 file changed, 6 insertions(+) (limited to 'tests') diff --git a/tests/convert-tests.sh b/tests/convert-tests.sh index 94285170..94477b47 100755 --- a/tests/convert-tests.sh +++ b/tests/convert-tests.sh @@ -124,6 +124,12 @@ convert_test() { # create a file to check btrfs-convert can convert regular file # correct run_check_mount_test_dev + + # create a file inside the fs before convert, to make sure there is + # data covering btrfs backup superblock range (64M) + run_check $SUDO_HELPER dd if=/dev/zero bs=1M count=64 \ + of=$TEST_MNT/convert_space_holder + populate_fs run_check $SUDO_HELPER dd if=/dev/zero of=$TEST_MNT/test bs=$nodesize \ count=1 >/dev/null 2>&1 -- cgit v1.2.3 From fde5ae2e49a9cd7091fb8db8d748d7687a544d23 Mon Sep 17 00:00:00 2001 From: Qu Wenruo Date: Fri, 3 Jun 2016 10:34:25 +0800 Subject: btrfs-progs: convert-tests: Add support for custom test scripts Add support for custom convert test scripts, just like fsck tests. Instead of generic convert tests, we need more specifically created images for new convert tests. This patch provide the needed infrastructure for later convert test cases. Signed-off-by: Qu Wenruo Signed-off-by: David Sterba --- tests/common | 8 ++++++++ tests/convert-tests.sh | 31 +++++++++++++++++++++++++++++++ 2 files changed, 39 insertions(+) (limited to 'tests') diff --git a/tests/common b/tests/common index 8a626b6a..c50b661f 100644 --- a/tests/common +++ b/tests/common @@ -94,6 +94,14 @@ check_prereq() fi } +check_global_prereq() +{ + which $1 &> /dev/null + if [ $? -ne 0 ]; then + _fail "Failed system wide prerequisities: $1"; + fi +} + check_image() { local image diff --git a/tests/convert-tests.sh b/tests/convert-tests.sh index 94477b47..32793b2f 100755 --- a/tests/convert-tests.sh +++ b/tests/convert-tests.sh @@ -15,6 +15,11 @@ DATASET_SIZE=50 source $TOP/tests/common +# Allow child test to use $TOP and $RESULTS +export TOP +export RESULTS +export LANG + rm -f $RESULTS setup_root_helper @@ -22,6 +27,25 @@ prepare_test_dev 512M CHECKSUMTMP=$(mktemp --tmpdir btrfs-progs-convert.XXXXXXXXXX) +run_one_test() { + local testname + + testname="$1" + echo " [TEST/conv] $testname" + cd $testname + echo "=== Entering $testname" >> $RESULTS + if [ -x test.sh ]; then + # Difference convert test case needs different tools to restore + # and check image, so only support custom test scripts + ./test.sh + if [ $? -ne 0 ]; then + _fail "test failed for case $(basename $testname)" + fi + else + _fail "custom test script not found" + fi +} + generate_dataset() { dataset_type="$1" @@ -172,4 +196,11 @@ for feature in '' 'extref' 'skinny-metadata' 'no-holes'; do convert_test "$feature" "ext4 64k nodesize" 65536 mke2fs -t ext4 -b 4096 done +# Test special images +for i in $(find $TOP/tests/convert-tests -maxdepth 1 -mindepth 1 -type d \ + ${TEST:+-name "$TEST"} | sort) +do + run_one_test "$i" +done + rm $CHECKSUMTMP -- cgit v1.2.3 From dc4bbc37a1f2b8677f2f45cda6a06f9cf462895e Mon Sep 17 00:00:00 2001 From: Qu Wenruo Date: Fri, 3 Jun 2016 10:34:26 +0800 Subject: btrfs-progs: convert-tests: Add test case for backup superblock migration New convert introduced simpler chunk/extent allocation algorithm, at the cost of complex backup superblock migration codes. Use specially built ext2 images to test if btrfs-convert can convert and rollback images without problem. All these special ext2 image have blocks/holes across 2nd btrfs backup superblock. The naming of test image is like the following: |<------superblock migration range----->| 64M 64M + 64K |-Data--|-Data--|/Hole//|-Data--|/Hole//|-Data--|--Data--| = drdhdhdrd These test cases should check all typical layouts and make sure new convert works. Signed-off-by: Qu Wenruo Signed-off-by: David Sterba --- .../drdhdhdrd.e2image.raw.xz | Bin 0 -> 84564 bytes .../drdhdhrh.e2image.raw.xz | Bin 0 -> 84568 bytes .../hrhdhdrd.e2image.raw.xz | Bin 0 -> 84556 bytes .../hrhdhrh.e2image.raw.xz | Bin 0 -> 84568 bytes .../004-ext2-backup-superblock-ranges/test.sh | 39 +++++++++++++++++++++ 5 files changed, 39 insertions(+) create mode 100644 tests/convert-tests/004-ext2-backup-superblock-ranges/drdhdhdrd.e2image.raw.xz create mode 100644 tests/convert-tests/004-ext2-backup-superblock-ranges/drdhdhrh.e2image.raw.xz create mode 100644 tests/convert-tests/004-ext2-backup-superblock-ranges/hrhdhdrd.e2image.raw.xz create mode 100644 tests/convert-tests/004-ext2-backup-superblock-ranges/hrhdhrh.e2image.raw.xz create mode 100755 tests/convert-tests/004-ext2-backup-superblock-ranges/test.sh (limited to 'tests') diff --git a/tests/convert-tests/004-ext2-backup-superblock-ranges/drdhdhdrd.e2image.raw.xz b/tests/convert-tests/004-ext2-backup-superblock-ranges/drdhdhdrd.e2image.raw.xz new file mode 100644 index 00000000..73e2309c Binary files /dev/null and b/tests/convert-tests/004-ext2-backup-superblock-ranges/drdhdhdrd.e2image.raw.xz differ diff --git a/tests/convert-tests/004-ext2-backup-superblock-ranges/drdhdhrh.e2image.raw.xz b/tests/convert-tests/004-ext2-backup-superblock-ranges/drdhdhrh.e2image.raw.xz new file mode 100644 index 00000000..0d5442ff Binary files /dev/null and b/tests/convert-tests/004-ext2-backup-superblock-ranges/drdhdhrh.e2image.raw.xz differ diff --git a/tests/convert-tests/004-ext2-backup-superblock-ranges/hrhdhdrd.e2image.raw.xz b/tests/convert-tests/004-ext2-backup-superblock-ranges/hrhdhdrd.e2image.raw.xz new file mode 100644 index 00000000..a1a30429 Binary files /dev/null and b/tests/convert-tests/004-ext2-backup-superblock-ranges/hrhdhdrd.e2image.raw.xz differ diff --git a/tests/convert-tests/004-ext2-backup-superblock-ranges/hrhdhrh.e2image.raw.xz b/tests/convert-tests/004-ext2-backup-superblock-ranges/hrhdhrh.e2image.raw.xz new file mode 100644 index 00000000..ac0dbc60 Binary files /dev/null and b/tests/convert-tests/004-ext2-backup-superblock-ranges/hrhdhrh.e2image.raw.xz differ diff --git a/tests/convert-tests/004-ext2-backup-superblock-ranges/test.sh b/tests/convert-tests/004-ext2-backup-superblock-ranges/test.sh new file mode 100755 index 00000000..493e4db5 --- /dev/null +++ b/tests/convert-tests/004-ext2-backup-superblock-ranges/test.sh @@ -0,0 +1,39 @@ +#!/bin/bash + +# Specially created e2image dump to test backup superblock migration for +# new convert. +# These images will cause the following problems if convert doesn't handle +# backup superblock migration well: +# 1) Assert while building free space tree +# 2) Error copying inodes +# 3) Discontinuous file extents after convert +# 4) Overlap file extents +# 5) Unable to rollback + +source $TOP/tests/common + +check_prereq btrfs-convert +check_prereq btrfs +check_prereq btrfs-show-super +check_global_prereq e2fsck +check_global_prereq xzcat + +setup_root_helper +prepare_test_dev 512M + +for src in $(find . -iname "*.e2image.raw.xz"); do + extracted=$(extract_image "$src") + run_check $SUDO_HELPER e2fsck -n -f $extracted + run_check $SUDO_HELPER $TOP/btrfs-convert $extracted + run_check $SUDO_HELPER $TOP/btrfs check $extracted + run_check $SUDO_HELPER $TOP/btrfs-show-super $extracted + + run_check $SUDO_HELPER mount -o loop $extracted $TEST_MNT + run_check $SUDO_HELPER e2fsck -n -f $TEST_MNT/ext2_saved/image + run_check $SUDO_HELPER umount $TEST_MNT + + run_check $SUDO_HELPER $TOP/btrfs check $extracted + run_check $SUDO_HELPER $TOP/btrfs-convert -r $extracted + run_check $SUDO_HELPER e2fsck -n -f $extracted + rm -f $extracted +done -- cgit v1.2.3 From a8e6d4fdfb70e63e810fff41b261430a42aae6d6 Mon Sep 17 00:00:00 2001 From: David Sterba Date: Fri, 3 Jun 2016 15:28:44 +0200 Subject: btrfs-progs: tests: move convert helpers to a separate file Signed-off-by: David Sterba --- tests/common.convert | 135 +++++++++++++++++++++++++++++++++++++++++++++++++ tests/convert-tests.sh | 134 +----------------------------------------------- 2 files changed, 136 insertions(+), 133 deletions(-) create mode 100644 tests/common.convert (limited to 'tests') diff --git a/tests/common.convert b/tests/common.convert new file mode 100644 index 00000000..22b0c4de --- /dev/null +++ b/tests/common.convert @@ -0,0 +1,135 @@ +#!/bin/bash +# helpers for btrfs-convert tests + +# how many files to create. +DATASET_SIZE=50 + +generate_dataset() { + + dataset_type="$1" + dirpath=$TEST_MNT/$dataset_type + run_check $SUDO_HELPER mkdir -p $dirpath + + case $dataset_type in + small) + for num in $(seq 1 $DATASET_SIZE); do + run_check $SUDO_HELPER dd if=/dev/urandom of=$dirpath/$dataset_type.$num bs=10K \ + count=1 >/dev/null 2>&1 + done + ;; + + hardlink) + for num in $(seq 1 $DATASET_SIZE); do + run_check $SUDO_HELPER touch $dirpath/$dataset_type.$num + run_check $SUDO_HELPER ln $dirpath/$dataset_type.$num $dirpath/hlink.$num + done + ;; + + symlink) + for num in $(seq 1 $DATASET_SIZE); do + run_check $SUDO_HELPER touch $dirpath/$dataset_type.$num + run_check $SUDO_HELPER ln -s $dirpath/$dataset_type.$num $dirpath/slink.$num + done + ;; + + brokenlink) + for num in $(seq 1 $DATASET_SIZE); do + run_check $SUDO_HELPER ln -s $dirpath/$dataset_type.$num $dirpath/blink.$num + done + ;; + + perm) + for modes in 777 775 755 750 700 666 664 644 640 600 444 440 400 000 \ + 1777 1775 1755 1750 1700 1666 1664 1644 1640 1600 1444 1440 1400 1000 \ + 2777 2775 2755 2750 2700 2666 2664 2644 2640 2600 2444 2440 2400 2000 \ + 4777 4775 4755 4750 4700 4666 4664 4644 4640 4600 4444 4440 4400 4000; do + if [[ "$modes" == *9* ]] || [[ "$modes" == *8* ]] + then + continue; + else + run_check $SUDO_HELPER touch $dirpath/$dataset_type.$modes + run_check $SUDO_HELPER chmod $modes $dirpath/$dataset_type.$modes + fi + done + ;; + + sparse) + for num in $(seq 1 $DATASET_SIZE); do + run_check $SUDO_HELPER dd if=/dev/urandom of=$dirpath/$dataset_type.$num bs=10K \ + count=1 >/dev/null 2>&1 + run_check $SUDO_HELPER truncate -s 500K $dirpath/$dataset_type.$num + run_check $SUDO_HELPER dd if=/dev/urandom of=$dirpath/$dataset_type.$num bs=10K \ + oflag=append conv=notrunc count=1 >/dev/null 2>&1 + run_check $SUDO_HELPER truncate -s 800K $dirpath/$dataset_type.$num + done + ;; + + acls) + for num in $(seq 1 $DATASET_SIZE); do + run_check $SUDO_HELPER touch $dirpath/$dataset_type.$num + run_check $SUDO_HELPER setfacl -m "u:root:x" $dirpath/$dataset_type.$num + run_check $SUDO_HELPER setfattr -n user.foo -v bar$num $dirpath/$dataset_type.$num + done + ;; + esac +} + +populate_fs() { + + for dataset_type in 'small' 'hardlink' 'symlink' 'brokenlink' 'perm' 'sparse' 'acls'; do + generate_dataset "$dataset_type" + done +} + +convert_test() { + local features + local nodesize + + features="$1" + shift + + if [ -z "$features" ]; then + echo " [TEST/conv] $1, btrfs defaults" + else + echo " [TEST/conv] $1, btrfs $features" + fi + nodesize=$2 + shift 2 + echo "creating ext image with: $*" >> $RESULTS + # TEST_DEV not removed as the file might have special permissions, eg. + # when test image is on NFS and would not be writable for root + run_check truncate -s 0 $TEST_DEV + # 256MB is the smallest acceptable btrfs image. + run_check truncate -s 512M $TEST_DEV + run_check $* -F $TEST_DEV + CHECKSUMTMP=$(mktemp --tmpdir btrfs-progs-convert.XXXXXXXXXX) + + # create a file to check btrfs-convert can convert regular file + # correct + run_check_mount_test_dev + + # create a file inside the fs before convert, to make sure there is + # data covering btrfs backup superblock range (64M) + run_check $SUDO_HELPER dd if=/dev/zero bs=1M count=64 \ + of=$TEST_MNT/convert_space_holder + + populate_fs + run_check $SUDO_HELPER dd if=/dev/zero of=$TEST_MNT/test bs=$nodesize \ + count=1 >/dev/null 2>&1 + run_check_stdout $SUDO_HELPER find $TEST_MNT -type f ! -name 'image' -exec md5sum {} \+ > $CHECKSUMTMP + run_check_umount_test_dev + + run_check $TOP/btrfs-convert ${features:+-O "$features"} -N "$nodesize" $TEST_DEV + run_check $TOP/btrfs check $TEST_DEV + run_check $TOP/btrfs-show-super -Ffa $TEST_DEV + + run_check_mount_test_dev + run_check_stdout $SUDO_HELPER md5sum -c $CHECKSUMTMP | + grep -q 'FAILED' && _fail "file validation failed." + run_check_umount_test_dev + rm $CHECKSUMTMP + + run_check $TOP/btrfs-convert --rollback $TEST_DEV + run_check fsck -n -t ext2,ext3,ext4 $TEST_DEV +} + diff --git a/tests/convert-tests.sh b/tests/convert-tests.sh index 32793b2f..66cadb21 100755 --- a/tests/convert-tests.sh +++ b/tests/convert-tests.sh @@ -10,10 +10,9 @@ LANG=C SCRIPT_DIR=$(dirname $(readlink -f $0)) TOP=$(readlink -f $SCRIPT_DIR/../) RESULTS="$TOP/tests/convert-tests-results.txt" -# how many files to create. -DATASET_SIZE=50 source $TOP/tests/common +source $TOP/tests/common.convert # Allow child test to use $TOP and $RESULTS export TOP @@ -25,8 +24,6 @@ rm -f $RESULTS setup_root_helper prepare_test_dev 512M -CHECKSUMTMP=$(mktemp --tmpdir btrfs-progs-convert.XXXXXXXXXX) - run_one_test() { local testname @@ -46,133 +43,6 @@ run_one_test() { fi } -generate_dataset() { - - dataset_type="$1" - dirpath=$TEST_MNT/$dataset_type - run_check $SUDO_HELPER mkdir -p $dirpath - - case $dataset_type in - small) - for num in $(seq 1 $DATASET_SIZE); do - run_check $SUDO_HELPER dd if=/dev/urandom of=$dirpath/$dataset_type.$num bs=10K \ - count=1 >/dev/null 2>&1 - done - ;; - - hardlink) - for num in $(seq 1 $DATASET_SIZE); do - run_check $SUDO_HELPER touch $dirpath/$dataset_type.$num - run_check $SUDO_HELPER ln $dirpath/$dataset_type.$num $dirpath/hlink.$num - done - ;; - - symlink) - for num in $(seq 1 $DATASET_SIZE); do - run_check $SUDO_HELPER touch $dirpath/$dataset_type.$num - run_check $SUDO_HELPER ln -s $dirpath/$dataset_type.$num $dirpath/slink.$num - done - ;; - - brokenlink) - for num in $(seq 1 $DATASET_SIZE); do - run_check $SUDO_HELPER ln -s $dirpath/$dataset_type.$num $dirpath/blink.$num - done - ;; - - perm) - for modes in 777 775 755 750 700 666 664 644 640 600 444 440 400 000 \ - 1777 1775 1755 1750 1700 1666 1664 1644 1640 1600 1444 1440 1400 1000 \ - 2777 2775 2755 2750 2700 2666 2664 2644 2640 2600 2444 2440 2400 2000 \ - 4777 4775 4755 4750 4700 4666 4664 4644 4640 4600 4444 4440 4400 4000; do - if [[ "$modes" == *9* ]] || [[ "$modes" == *8* ]] - then - continue; - else - run_check $SUDO_HELPER touch $dirpath/$dataset_type.$modes - run_check $SUDO_HELPER chmod $modes $dirpath/$dataset_type.$modes - fi - done - ;; - - sparse) - for num in $(seq 1 $DATASET_SIZE); do - run_check $SUDO_HELPER dd if=/dev/urandom of=$dirpath/$dataset_type.$num bs=10K \ - count=1 >/dev/null 2>&1 - run_check $SUDO_HELPER truncate -s 500K $dirpath/$dataset_type.$num - run_check $SUDO_HELPER dd if=/dev/urandom of=$dirpath/$dataset_type.$num bs=10K \ - oflag=append conv=notrunc count=1 >/dev/null 2>&1 - run_check $SUDO_HELPER truncate -s 800K $dirpath/$dataset_type.$num - done - ;; - - acls) - for num in $(seq 1 $DATASET_SIZE); do - run_check $SUDO_HELPER touch $dirpath/$dataset_type.$num - run_check $SUDO_HELPER setfacl -m "u:root:x" $dirpath/$dataset_type.$num - run_check $SUDO_HELPER setfattr -n user.foo -v bar$num $dirpath/$dataset_type.$num - done - ;; - esac -} - -populate_fs() { - - for dataset_type in 'small' 'hardlink' 'symlink' 'brokenlink' 'perm' 'sparse' 'acls'; do - generate_dataset "$dataset_type" - done -} - -convert_test() { - local features - local nodesize - - features="$1" - shift - - if [ -z "$features" ]; then - echo " [TEST/conv] $1, btrfs defaults" - else - echo " [TEST/conv] $1, btrfs $features" - fi - nodesize=$2 - shift 2 - echo "creating ext image with: $*" >> $RESULTS - # TEST_DEV not removed as the file might have special permissions, eg. - # when test image is on NFS and would not be writable for root - run_check truncate -s 0 $TEST_DEV - # 256MB is the smallest acceptable btrfs image. - run_check truncate -s 512M $TEST_DEV - run_check $* -F $TEST_DEV - - # create a file to check btrfs-convert can convert regular file - # correct - run_check_mount_test_dev - - # create a file inside the fs before convert, to make sure there is - # data covering btrfs backup superblock range (64M) - run_check $SUDO_HELPER dd if=/dev/zero bs=1M count=64 \ - of=$TEST_MNT/convert_space_holder - - populate_fs - run_check $SUDO_HELPER dd if=/dev/zero of=$TEST_MNT/test bs=$nodesize \ - count=1 >/dev/null 2>&1 - run_check_stdout $SUDO_HELPER find $TEST_MNT -type f ! -name 'image' -exec md5sum {} \+ > $CHECKSUMTMP - run_check_umount_test_dev - - run_check $TOP/btrfs-convert ${features:+-O "$features"} -N "$nodesize" $TEST_DEV - run_check $TOP/btrfs check $TEST_DEV - run_check $TOP/btrfs-show-super -Ffa $TEST_DEV - - run_check_mount_test_dev - run_check_stdout $SUDO_HELPER md5sum -c $CHECKSUMTMP | - grep -q 'FAILED' && _fail "file validation failed." - run_check_umount_test_dev - - run_check $TOP/btrfs-convert --rollback $TEST_DEV - run_check fsck -n -t ext2,ext3,ext4 $TEST_DEV -} - if ! [ -z "$TEST" ]; then echo " [TEST/conv] skipped all convert tests, TEST=$TEST" exit 0 @@ -202,5 +72,3 @@ for i in $(find $TOP/tests/convert-tests -maxdepth 1 -mindepth 1 -type d \ do run_one_test "$i" done - -rm $CHECKSUMTMP -- cgit v1.2.3 From 79b0946f033f11e45e677338a8d200477dfb15e7 Mon Sep 17 00:00:00 2001 From: David Sterba Date: Fri, 3 Jun 2016 15:37:25 +0200 Subject: btrfs-progs: tests: convert: separate ext2 tests Signed-off-by: David Sterba --- tests/convert-tests.sh | 5 ----- tests/convert-tests/001-ext2-basic/test.sh | 16 ++++++++++++++++ 2 files changed, 16 insertions(+), 5 deletions(-) create mode 100755 tests/convert-tests/001-ext2-basic/test.sh (limited to 'tests') diff --git a/tests/convert-tests.sh b/tests/convert-tests.sh index 66cadb21..196df608 100755 --- a/tests/convert-tests.sh +++ b/tests/convert-tests.sh @@ -49,19 +49,14 @@ if ! [ -z "$TEST" ]; then fi for feature in '' 'extref' 'skinny-metadata' 'no-holes'; do - convert_test "$feature" "ext2 4k nodesize" 4096 mke2fs -b 4096 convert_test "$feature" "ext3 4k nodesize" 4096 mke2fs -j -b 4096 convert_test "$feature" "ext4 4k nodesize" 4096 mke2fs -t ext4 -b 4096 - convert_test "$feature" "ext2 8k nodesize" 8192 mke2fs -b 4096 convert_test "$feature" "ext3 8k nodesize" 8192 mke2fs -j -b 4096 convert_test "$feature" "ext4 8k nodesize" 8192 mke2fs -t ext4 -b 4096 - convert_test "$feature" "ext2 16k nodesize" 16384 mke2fs -b 4096 convert_test "$feature" "ext3 16k nodesize" 16384 mke2fs -j -b 4096 convert_test "$feature" "ext4 16k nodesize" 16384 mke2fs -t ext4 -b 4096 - convert_test "$feature" "ext2 32k nodesize" 32768 mke2fs -b 4096 convert_test "$feature" "ext3 32k nodesize" 32768 mke2fs -j -b 4096 convert_test "$feature" "ext4 32k nodesize" 32768 mke2fs -t ext4 -b 4096 - convert_test "$feature" "ext2 64k nodesize" 65536 mke2fs -b 4096 convert_test "$feature" "ext3 64k nodesize" 65536 mke2fs -j -b 4096 convert_test "$feature" "ext4 64k nodesize" 65536 mke2fs -t ext4 -b 4096 done diff --git a/tests/convert-tests/001-ext2-basic/test.sh b/tests/convert-tests/001-ext2-basic/test.sh new file mode 100755 index 00000000..8f4f935d --- /dev/null +++ b/tests/convert-tests/001-ext2-basic/test.sh @@ -0,0 +1,16 @@ +#!/bin/bash + +source $TOP/tests/common +source $TOP/tests/common.convert + +setup_root_helper +prepare_test_dev 512M +check_prereq btrfs-convert + +for feature in '' 'extref' 'skinny-metadata' 'no-holes'; do + convert_test "$feature" "ext2 4k nodesize" 4096 mke2fs -b 4096 + convert_test "$feature" "ext2 8k nodesize" 8192 mke2fs -b 4096 + convert_test "$feature" "ext2 16k nodesize" 16384 mke2fs -b 4096 + convert_test "$feature" "ext2 32k nodesize" 32768 mke2fs -b 4096 + convert_test "$feature" "ext2 64k nodesize" 65536 mke2fs -b 4096 +done -- cgit v1.2.3 From cf8cc8ea45b743d48593e853aeda843dca6d9b66 Mon Sep 17 00:00:00 2001 From: David Sterba Date: Fri, 3 Jun 2016 15:37:25 +0200 Subject: btrfs-progs: tests: convert: separate ext3 tests Signed-off-by: David Sterba --- tests/convert-tests.sh | 5 ----- tests/convert-tests/002-ext3-basic/test.sh | 16 ++++++++++++++++ 2 files changed, 16 insertions(+), 5 deletions(-) create mode 100755 tests/convert-tests/002-ext3-basic/test.sh (limited to 'tests') diff --git a/tests/convert-tests.sh b/tests/convert-tests.sh index 196df608..ad0918cb 100755 --- a/tests/convert-tests.sh +++ b/tests/convert-tests.sh @@ -49,15 +49,10 @@ if ! [ -z "$TEST" ]; then fi for feature in '' 'extref' 'skinny-metadata' 'no-holes'; do - convert_test "$feature" "ext3 4k nodesize" 4096 mke2fs -j -b 4096 convert_test "$feature" "ext4 4k nodesize" 4096 mke2fs -t ext4 -b 4096 - convert_test "$feature" "ext3 8k nodesize" 8192 mke2fs -j -b 4096 convert_test "$feature" "ext4 8k nodesize" 8192 mke2fs -t ext4 -b 4096 - convert_test "$feature" "ext3 16k nodesize" 16384 mke2fs -j -b 4096 convert_test "$feature" "ext4 16k nodesize" 16384 mke2fs -t ext4 -b 4096 - convert_test "$feature" "ext3 32k nodesize" 32768 mke2fs -j -b 4096 convert_test "$feature" "ext4 32k nodesize" 32768 mke2fs -t ext4 -b 4096 - convert_test "$feature" "ext3 64k nodesize" 65536 mke2fs -j -b 4096 convert_test "$feature" "ext4 64k nodesize" 65536 mke2fs -t ext4 -b 4096 done diff --git a/tests/convert-tests/002-ext3-basic/test.sh b/tests/convert-tests/002-ext3-basic/test.sh new file mode 100755 index 00000000..64356307 --- /dev/null +++ b/tests/convert-tests/002-ext3-basic/test.sh @@ -0,0 +1,16 @@ +#!/bin/bash + +source $TOP/tests/common +source $TOP/tests/common.convert + +setup_root_helper +prepare_test_dev 512M +check_prereq btrfs-convert + +for feature in '' 'extref' 'skinny-metadata' 'no-holes'; do + convert_test "$feature" "ext3 4k nodesize" 4096 mke2fs -b 4096 + convert_test "$feature" "ext3 8k nodesize" 8192 mke2fs -b 4096 + convert_test "$feature" "ext3 16k nodesize" 16384 mke2fs -b 4096 + convert_test "$feature" "ext3 32k nodesize" 32768 mke2fs -b 4096 + convert_test "$feature" "ext3 64k nodesize" 65536 mke2fs -b 4096 +done -- cgit v1.2.3 From bea73f33b9c651624bddf5ee81db55980c1f8f81 Mon Sep 17 00:00:00 2001 From: David Sterba Date: Fri, 3 Jun 2016 15:37:25 +0200 Subject: btrfs-progs: tests: convert: separate ext4 tests Signed-off-by: David Sterba --- tests/convert-tests.sh | 6 +----- tests/convert-tests/003-ext4-basic/test.sh | 16 ++++++++++++++++ 2 files changed, 17 insertions(+), 5 deletions(-) create mode 100755 tests/convert-tests/003-ext4-basic/test.sh (limited to 'tests') diff --git a/tests/convert-tests.sh b/tests/convert-tests.sh index ad0918cb..c79962f2 100755 --- a/tests/convert-tests.sh +++ b/tests/convert-tests.sh @@ -49,11 +49,7 @@ if ! [ -z "$TEST" ]; then fi for feature in '' 'extref' 'skinny-metadata' 'no-holes'; do - convert_test "$feature" "ext4 4k nodesize" 4096 mke2fs -t ext4 -b 4096 - convert_test "$feature" "ext4 8k nodesize" 8192 mke2fs -t ext4 -b 4096 - convert_test "$feature" "ext4 16k nodesize" 16384 mke2fs -t ext4 -b 4096 - convert_test "$feature" "ext4 32k nodesize" 32768 mke2fs -t ext4 -b 4096 - convert_test "$feature" "ext4 64k nodesize" 65536 mke2fs -t ext4 -b 4096 + : done # Test special images diff --git a/tests/convert-tests/003-ext4-basic/test.sh b/tests/convert-tests/003-ext4-basic/test.sh new file mode 100755 index 00000000..9a81a473 --- /dev/null +++ b/tests/convert-tests/003-ext4-basic/test.sh @@ -0,0 +1,16 @@ +#!/bin/bash + +source $TOP/tests/common +source $TOP/tests/common.convert + +setup_root_helper +prepare_test_dev 512M +check_prereq btrfs-convert + +for feature in '' 'extref' 'skinny-metadata' 'no-holes'; do + convert_test "$feature" "ext4 4k nodesize" 4096 mke2fs -b 4096 + convert_test "$feature" "ext4 8k nodesize" 8192 mke2fs -b 4096 + convert_test "$feature" "ext4 16k nodesize" 16384 mke2fs -b 4096 + convert_test "$feature" "ext4 32k nodesize" 32768 mke2fs -b 4096 + convert_test "$feature" "ext4 64k nodesize" 65536 mke2fs -b 4096 +done -- cgit v1.2.3 From b06f44e50bc0dce2c7301534674119aa3f3aeb64 Mon Sep 17 00:00:00 2001 From: David Sterba Date: Fri, 3 Jun 2016 15:46:39 +0200 Subject: btrfs-progs: tests: clean up the test driver of convert tests Everything is now in separate tests, and TEST=mask now works. Signed-off-by: David Sterba --- tests/convert-tests.sh | 12 ------------ 1 file changed, 12 deletions(-) (limited to 'tests') diff --git a/tests/convert-tests.sh b/tests/convert-tests.sh index c79962f2..df765290 100755 --- a/tests/convert-tests.sh +++ b/tests/convert-tests.sh @@ -21,9 +21,6 @@ export LANG rm -f $RESULTS -setup_root_helper -prepare_test_dev 512M - run_one_test() { local testname @@ -43,15 +40,6 @@ run_one_test() { fi } -if ! [ -z "$TEST" ]; then - echo " [TEST/conv] skipped all convert tests, TEST=$TEST" - exit 0 -fi - -for feature in '' 'extref' 'skinny-metadata' 'no-holes'; do - : -done - # Test special images for i in $(find $TOP/tests/convert-tests -maxdepth 1 -mindepth 1 -type d \ ${TEST:+-name "$TEST"} | sort) -- cgit v1.2.3 From b5ab8d42b71ce06d9fcfbcc0f65f6c388d6b28f1 Mon Sep 17 00:00:00 2001 From: David Sterba Date: Fri, 3 Jun 2016 15:54:32 +0200 Subject: btrfs-progs: tests: convert: set common variables Signed-off-by: David Sterba --- tests/convert-tests.sh | 2 ++ 1 file changed, 2 insertions(+) (limited to 'tests') diff --git a/tests/convert-tests.sh b/tests/convert-tests.sh index df765290..c0080b93 100755 --- a/tests/convert-tests.sh +++ b/tests/convert-tests.sh @@ -9,7 +9,9 @@ unset LANG LANG=C SCRIPT_DIR=$(dirname $(readlink -f $0)) TOP=$(readlink -f $SCRIPT_DIR/../) +TEST_DEV=${TEST_DEV:-} RESULTS="$TOP/tests/convert-tests-results.txt" +IMAGE="$TOP/tests/test.img" source $TOP/tests/common source $TOP/tests/common.convert -- cgit v1.2.3 From e5f80994640df9abdb181c6db1513d8de744c73c Mon Sep 17 00:00:00 2001 From: David Sterba Date: Fri, 3 Jun 2016 16:01:51 +0200 Subject: btrfs-progs: tests: unify test drivers Remove unnecessary code, add exports to all common variables. Signed-off-by: David Sterba --- tests/cli-tests.sh | 3 +-- tests/convert-tests.sh | 6 ++---- tests/fsck-tests.sh | 10 +++------- tests/fuzz-tests.sh | 3 +-- tests/misc-tests.sh | 6 +----- tests/mkfs-tests.sh | 6 +----- 6 files changed, 9 insertions(+), 25 deletions(-) (limited to 'tests') diff --git a/tests/cli-tests.sh b/tests/cli-tests.sh index e65e7f50..72f7865a 100755 --- a/tests/cli-tests.sh +++ b/tests/cli-tests.sh @@ -2,8 +2,6 @@ # # command line interface coverage tests -unset TOP -unset LANG LANG=C SCRIPT_DIR=$(dirname $(readlink -f $0)) TOP=$(readlink -f $SCRIPT_DIR/../) @@ -17,6 +15,7 @@ export TOP export RESULTS export LANG export IMAGE +export TEST_DEV rm -f $RESULTS diff --git a/tests/convert-tests.sh b/tests/convert-tests.sh index c0080b93..064540f1 100755 --- a/tests/convert-tests.sh +++ b/tests/convert-tests.sh @@ -2,10 +2,7 @@ # # convert ext2/3/4 images to btrfs images, and make sure the results are # clean. -# -unset TOP -unset LANG LANG=C SCRIPT_DIR=$(dirname $(readlink -f $0)) TOP=$(readlink -f $SCRIPT_DIR/../) @@ -16,10 +13,11 @@ IMAGE="$TOP/tests/test.img" source $TOP/tests/common source $TOP/tests/common.convert -# Allow child test to use $TOP and $RESULTS export TOP export RESULTS export LANG +export IMAGE +export TEST_DEV rm -f $RESULTS diff --git a/tests/fsck-tests.sh b/tests/fsck-tests.sh index fb861635..d1cd7329 100755 --- a/tests/fsck-tests.sh +++ b/tests/fsck-tests.sh @@ -1,25 +1,21 @@ #!/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. -# -unset TOP -unset LANG LANG=C SCRIPT_DIR=$(dirname $(readlink -f $0)) TOP=$(readlink -f $SCRIPT_DIR/../) TEST_DEV=${TEST_DEV:-} RESULTS="$TOP/tests/fsck-tests-results.txt" +IMAGE="$TOP/tests/test.img" source $TOP/tests/common -# Allow child test to use $TOP and $RESULTS export TOP export RESULTS -# For custom script needs to verify recovery export LANG +export IMAGE +export TEST_DEV rm -f $RESULTS diff --git a/tests/fuzz-tests.sh b/tests/fuzz-tests.sh index 204dce2d..29691cae 100755 --- a/tests/fuzz-tests.sh +++ b/tests/fuzz-tests.sh @@ -2,8 +2,6 @@ # # misc tests on fuzzed or crafted images -unset TOP -unset LANG LANG=C SCRIPT_DIR=$(dirname $(readlink -f $0)) TOP=$(readlink -f $SCRIPT_DIR/../) @@ -17,6 +15,7 @@ export TOP export RESULTS export LANG export IMAGE +export TEST_DEV rm -f $RESULTS diff --git a/tests/misc-tests.sh b/tests/misc-tests.sh index 0cf8c4b2..eefe8a81 100755 --- a/tests/misc-tests.sh +++ b/tests/misc-tests.sh @@ -2,8 +2,6 @@ # # Misc tests -unset TOP -unset LANG LANG=C SCRIPT_DIR=$(dirname $(readlink -f $0)) TOP=$(readlink -f $SCRIPT_DIR/../) @@ -13,12 +11,10 @@ IMAGE="$TOP/tests/test.img" source $TOP/tests/common -# Allow child test to use $TOP and $RESULTS export TOP export RESULTS -# For custom script needs to verify recovery export LANG -# For tests that only use a loop device +export TEST_DEV export IMAGE rm -f $RESULTS diff --git a/tests/mkfs-tests.sh b/tests/mkfs-tests.sh index 363a865e..1afc0282 100755 --- a/tests/mkfs-tests.sh +++ b/tests/mkfs-tests.sh @@ -2,8 +2,6 @@ # # mkfs.btrfs tests -unset TOP -unset LANG LANG=C SCRIPT_DIR=$(dirname $(readlink -f $0)) TOP=$(readlink -f $SCRIPT_DIR/../) @@ -13,13 +11,11 @@ IMAGE="$TOP/tests/test.img" source $TOP/tests/common -# Allow child test to use $TOP and $RESULTS export TOP export RESULTS -# For custom script needs to verify recovery export LANG -# For tests that only use a loop device export IMAGE +export TEST_DEV rm -f $RESULTS -- cgit v1.2.3 From 933de7e03439b3599f493b8baf94a5ea7befccdb Mon Sep 17 00:00:00 2001 From: David Sterba Date: Fri, 3 Jun 2016 16:52:57 +0200 Subject: btrfs-progs: tests: 004-ext2-backup-superblock-ranges, drop unnecessary root privs We really use root only for mount/umount and access to the ext2_saved image (that has 0600). Also switch to common variable so we can use helpers. Signed-off-by: David Sterba --- .../004-ext2-backup-superblock-ranges/test.sh | 21 +++++++++++---------- 1 file changed, 11 insertions(+), 10 deletions(-) (limited to 'tests') diff --git a/tests/convert-tests/004-ext2-backup-superblock-ranges/test.sh b/tests/convert-tests/004-ext2-backup-superblock-ranges/test.sh index 493e4db5..bc6b5ea6 100755 --- a/tests/convert-tests/004-ext2-backup-superblock-ranges/test.sh +++ b/tests/convert-tests/004-ext2-backup-superblock-ranges/test.sh @@ -22,18 +22,19 @@ setup_root_helper prepare_test_dev 512M for src in $(find . -iname "*.e2image.raw.xz"); do - extracted=$(extract_image "$src") - run_check $SUDO_HELPER e2fsck -n -f $extracted - run_check $SUDO_HELPER $TOP/btrfs-convert $extracted - run_check $SUDO_HELPER $TOP/btrfs check $extracted - run_check $SUDO_HELPER $TOP/btrfs-show-super $extracted + TEST_DEV=$(extract_image "$src") + run_check e2fsck -n -f $TEST_DEV + run_check $TOP/btrfs-convert $TEST_DEV + run_check $TOP/btrfs check $TEST_DEV + run_check $TOP/btrfs-show-super $TEST_DEV - run_check $SUDO_HELPER mount -o loop $extracted $TEST_MNT + run_check_mount_test_dev run_check $SUDO_HELPER e2fsck -n -f $TEST_MNT/ext2_saved/image run_check $SUDO_HELPER umount $TEST_MNT - run_check $SUDO_HELPER $TOP/btrfs check $extracted - run_check $SUDO_HELPER $TOP/btrfs-convert -r $extracted - run_check $SUDO_HELPER e2fsck -n -f $extracted - rm -f $extracted + run_check $TOP/btrfs check $TEST_DEV + run_check $TOP/btrfs-convert -r $TEST_DEV + run_check e2fsck -n -f $TEST_DEV + + rm -f $TEST_DEV done -- cgit v1.2.3 From 75bf151ba3d31af27ef7af10fef0ae97295d4318 Mon Sep 17 00:00:00 2001 From: David Sterba Date: Fri, 3 Jun 2016 17:08:43 +0200 Subject: btrfs-progs: tests: 004-ext2-backup-superblock-ranges, use common helpers for image loop Signed-off-by: David Sterba --- tests/convert-tests/004-ext2-backup-superblock-ranges/test.sh | 9 ++++++--- 1 file changed, 6 insertions(+), 3 deletions(-) (limited to 'tests') diff --git a/tests/convert-tests/004-ext2-backup-superblock-ranges/test.sh b/tests/convert-tests/004-ext2-backup-superblock-ranges/test.sh index bc6b5ea6..d85e4de4 100755 --- a/tests/convert-tests/004-ext2-backup-superblock-ranges/test.sh +++ b/tests/convert-tests/004-ext2-backup-superblock-ranges/test.sh @@ -21,8 +21,9 @@ check_global_prereq xzcat setup_root_helper prepare_test_dev 512M -for src in $(find . -iname "*.e2image.raw.xz"); do - TEST_DEV=$(extract_image "$src") +# override common function +function check_image() { + TEST_DEV="$1" run_check e2fsck -n -f $TEST_DEV run_check $TOP/btrfs-convert $TEST_DEV run_check $TOP/btrfs check $TEST_DEV @@ -37,4 +38,6 @@ for src in $(find . -iname "*.e2image.raw.xz"); do run_check e2fsck -n -f $TEST_DEV rm -f $TEST_DEV -done +} + +check_all_images -- cgit v1.2.3 From 81b427afcf105420a25cb3a35be478c9f43f069e Mon Sep 17 00:00:00 2001 From: David Sterba Date: Thu, 16 Jun 2016 13:50:18 +0200 Subject: btrfs-progs: tests: add 003-fi-resize-args Check various resize option combinations. Signed-off-by: David Sterba --- tests/cli-tests/003-fi-resize-args/test.sh | 46 ++++++++++++++++++++++++++++++ 1 file changed, 46 insertions(+) create mode 100755 tests/cli-tests/003-fi-resize-args/test.sh (limited to 'tests') diff --git a/tests/cli-tests/003-fi-resize-args/test.sh b/tests/cli-tests/003-fi-resize-args/test.sh new file mode 100755 index 00000000..2f136fa2 --- /dev/null +++ b/tests/cli-tests/003-fi-resize-args/test.sh @@ -0,0 +1,46 @@ +#!/bin/bash +# +# test parsing of various resize arguments + +source $TOP/tests/common + +check_prereq mkfs.btrfs +check_prereq btrfs + +setup_root_helper +prepare_test_dev 2g + +run_check $TOP/mkfs.btrfs -f $IMAGE +run_check_mount_test_dev + +# missing the one of the required arguments +for sep in '' '--'; do + run_check_stdout $TOP/btrfs filesystem resize $sep | + grep -q "btrfs filesystem resize: too few arguments" + run_check_stdout $TOP/btrfs filesystem resize $sep $TEST_MNT | + grep -q "btrfs filesystem resize: too few arguments" + run_check_stdout $TOP/btrfs filesystem resize $sep -128M | + grep -q "btrfs filesystem resize: too few arguments" + run_check_stdout $TOP/btrfs filesystem resize $sep +128M | + grep -q "btrfs filesystem resize: too few arguments" + run_check_stdout $TOP/btrfs filesystem resize $sep 512M | + grep -q "btrfs filesystem resize: too few arguments" + run_check_stdout $TOP/btrfs filesystem resize $sep 1:-128M | + grep -q "btrfs filesystem resize: too few arguments" + run_check_stdout $TOP/btrfs filesystem resize $sep 1:512M | + grep -q "btrfs filesystem resize: too few arguments" + run_check_stdout $TOP/btrfs filesystem resize $sep 1:+128M | + grep -q "btrfs filesystem resize: too few arguments" +done + +# valid resize +for sep in '' '--'; do + run_check $SUDO_HELPER $TOP/btrfs filesystem resize $sep -128M $TEST_MNT + run_check $SUDO_HELPER $TOP/btrfs filesystem resize $sep +128M $TEST_MNT + run_check $SUDO_HELPER $TOP/btrfs filesystem resize $sep 512M $TEST_MNT + run_check $SUDO_HELPER $TOP/btrfs filesystem resize $sep 1:-128M $TEST_MNT + run_check $SUDO_HELPER $TOP/btrfs filesystem resize $sep 1:512M $TEST_MNT + run_check $SUDO_HELPER $TOP/btrfs filesystem resize $sep 1:+128M $TEST_MNT +done + +run_check_umount_test_dev -- cgit v1.2.3 From f20f2278772d97b16a65827dbc21c3f9ce3cc1a3 Mon Sep 17 00:00:00 2001 From: David Sterba Date: Wed, 22 Jun 2016 11:25:33 +0200 Subject: btrfs-progs: tests: split convert_test Split the big function to several helpers so we can use them separately. Add comments and do minor tweaks. Signed-off-by: David Sterba --- tests/common.convert | 93 +++++++++++++++++++++++++++++++++++++++------------- 1 file changed, 70 insertions(+), 23 deletions(-) (limited to 'tests') diff --git a/tests/common.convert b/tests/common.convert index 22b0c4de..4e3d49c9 100644 --- a/tests/common.convert +++ b/tests/common.convert @@ -81,55 +81,102 @@ populate_fs() { done } -convert_test() { +# verbose message before the test, same arguments as convert_test +convert_test_preamble() { local features - local nodesize + local msg features="$1" - shift - - if [ -z "$features" ]; then - echo " [TEST/conv] $1, btrfs defaults" - else - echo " [TEST/conv] $1, btrfs $features" - fi - nodesize=$2 - shift 2 - echo "creating ext image with: $*" >> $RESULTS + msg="$2" + shift 3 + echo " [TEST/conv] $msg, btrfs" "${features:-defaults}" + echo "creating ext image with: $@" >> $RESULTS +} + +# prepare TEST_DEV before conversion, create filesystem and mount it, image +# size is 512MB +# $@: free form, command to create the filesystem, with appended -F +convert_test_prep_fs() { # TEST_DEV not removed as the file might have special permissions, eg. # when test image is on NFS and would not be writable for root run_check truncate -s 0 $TEST_DEV # 256MB is the smallest acceptable btrfs image. run_check truncate -s 512M $TEST_DEV - run_check $* -F $TEST_DEV - CHECKSUMTMP=$(mktemp --tmpdir btrfs-progs-convert.XXXXXXXXXX) + run_check "$@" -F $TEST_DEV - # create a file to check btrfs-convert can convert regular file - # correct + # create a file to check btrfs-convert can convert regular file correct run_check_mount_test_dev # create a file inside the fs before convert, to make sure there is # data covering btrfs backup superblock range (64M) run_check $SUDO_HELPER dd if=/dev/zero bs=1M count=64 \ of=$TEST_MNT/convert_space_holder +} + +# generate md5 checksums of files on $TEST_MNT +# $1: path where the checksums will be stored +convert_test_gen_checksums() { + local CHECKSUMTMP + CHECKSUMTMP="$1" - populate_fs run_check $SUDO_HELPER dd if=/dev/zero of=$TEST_MNT/test bs=$nodesize \ count=1 >/dev/null 2>&1 - run_check_stdout $SUDO_HELPER find $TEST_MNT -type f ! -name 'image' -exec md5sum {} \+ > $CHECKSUMTMP - run_check_umount_test_dev + run_check_stdout $SUDO_HELPER find $TEST_MNT -type f ! -name 'image' -exec md5sum {} \+ > "$CHECKSUMTMP" +} - run_check $TOP/btrfs-convert ${features:+-O "$features"} -N "$nodesize" $TEST_DEV +# do conversion with given features and nodesize, fsck afterwards +# $1: features, argument of -O, can be empty +# $2: nodesize, argument of -N, can be empty +convert_test_do_convert() { + run_check $TOP/btrfs-convert ${1:+-O "$1"} ${2:+-N "$2"} $TEST_DEV run_check $TOP/btrfs check $TEST_DEV run_check $TOP/btrfs-show-super -Ffa $TEST_DEV +} + +# post conversion checks, verify md5sums +# $1: file with checksums +convert_test_post_check() { + local CHECKSUMTMP + CHECKSUMTMP="$1" run_check_mount_test_dev - run_check_stdout $SUDO_HELPER md5sum -c $CHECKSUMTMP | - grep -q 'FAILED' && _fail "file validation failed." + run_check_stdout $SUDO_HELPER md5sum -c "$CHECKSUMTMP" | + grep -q 'FAILED' && _fail "file validation failed" run_check_umount_test_dev - rm $CHECKSUMTMP +} +# do rollback and fsck +convert_test_post_rollback() { run_check $TOP/btrfs-convert --rollback $TEST_DEV run_check fsck -n -t ext2,ext3,ext4 $TEST_DEV } +# simple wrapper for a convert test +# $1: btrfs features, argument to -O +# $2: description of the test "ext2 8k nodesize" +# $3: nodesize value +# $4 + rest: command to create the ext2 image +convert_test() { + local features + local nodesize + local msg + local CHECKSUMTMP + + features="$1" + msg="$2" + nodesize="$3" + shift 3 + convert_test_preamble "$features" "$msg" "$nodesize" "$@" + convert_test_prep_fs "$@" + populate_fs + CHECKSUMTMP=$(mktemp --tmpdir btrfs-progs-convert.XXXXXXXXXX) + convert_test_gen_checksums "$CHECKSUMTMP" + + run_check_umount_test_dev + + convert_test_do_convert "$features" "$nodesize" + convert_test_post_check "$CHECKSUMTMP" + rm $CHECKSUMTMP + + convert_test_post_rollback +} -- cgit v1.2.3 From 329ff544a4ce36c9f9910402646f4d286696d3e4 Mon Sep 17 00:00:00 2001 From: David Sterba Date: Wed, 22 Jun 2016 11:30:24 +0200 Subject: btrfs-progs: tests: print shorter test name in the output The full path is printed, we're interested in the last path component only. Signed-off-by: David Sterba --- tests/convert-tests.sh | 11 ++++++----- 1 file changed, 6 insertions(+), 5 deletions(-) (limited to 'tests') diff --git a/tests/convert-tests.sh b/tests/convert-tests.sh index 064540f1..0e025f99 100755 --- a/tests/convert-tests.sh +++ b/tests/convert-tests.sh @@ -22,18 +22,19 @@ export TEST_DEV rm -f $RESULTS run_one_test() { + local testdir local testname - testname="$1" + testdir="$1" + testname=$(basename "$testdir") echo " [TEST/conv] $testname" - cd $testname + cd "$testdir" echo "=== Entering $testname" >> $RESULTS if [ -x test.sh ]; then - # Difference convert test case needs different tools to restore - # and check image, so only support custom test scripts + # Only support custom test scripts ./test.sh if [ $? -ne 0 ]; then - _fail "test failed for case $(basename $testname)" + _fail "test failed for case $testname" fi else _fail "custom test script not found" -- cgit v1.2.3 From ac1e484a0a5e575e32df68745e1214cbe7b95daa Mon Sep 17 00:00:00 2001 From: David Sterba Date: Wed, 22 Jun 2016 14:07:46 +0200 Subject: btrfs-progs: tests: add test console Add a wrapper that sets up environment the same way a test would use it. Use it for quick prototyping or testing, the commands and output is logged. Signed-off-by: David Sterba --- tests/test-console.sh | 23 +++++++++++++++++++++++ 1 file changed, 23 insertions(+) create mode 100755 tests/test-console.sh (limited to 'tests') diff --git a/tests/test-console.sh b/tests/test-console.sh new file mode 100755 index 00000000..cc1cdf3c --- /dev/null +++ b/tests/test-console.sh @@ -0,0 +1,23 @@ +#!/bin/sh +# a shell with test environment set up, logged commands and output + +LANG=C +SCRIPT_DIR=$(dirname $(readlink -f $0)) +TOP=$(readlink -f $SCRIPT_DIR/../) +TEST_DEV=${TEST_DEV:-} +RESULTS="$TOP/tests/test-console.txt" +IMAGE="$TOP/tests/test.img" + +source common +source common.convert + +setup_root_helper + +echo "Eval loop in test environment (log: $RESULTS)" +echo -e " ---------------------\nStarting session, `date`" >> "$RESULTS" +echo -n "`pwd`> " +while read x; do + echo "COMMAND: $x" >> "$RESULTS" + { eval $x; } 2>&1 | tee -a "$RESULTS" + echo -n "`pwd`> " +done -- cgit v1.2.3 From 1280c2bbbde23909249230c4717a5781bdb637a9 Mon Sep 17 00:00:00 2001 From: David Sterba Date: Wed, 22 Jun 2016 14:28:23 +0200 Subject: btrfs-progs: tests: update README Signed-off-by: David Sterba --- tests/README.md | 40 +++++++++++++++++++++++++++++----------- 1 file changed, 29 insertions(+), 11 deletions(-) (limited to 'tests') diff --git a/tests/README.md b/tests/README.md index 19d27ab8..6bb3de49 100644 --- a/tests/README.md +++ b/tests/README.md @@ -1,5 +1,14 @@ # Btrfs-progs tests +A testsuite covering functionality of btrfs-progs, ie. the checker, image, mkfs +and similar tools. There are no special requirements on kernel features, the +tests build on top of the core functionality like snapshots and device +management. In some cases optional features are turned on by mkfs and the +filesystem image could be mounted, such tests might fail if there's lack of +support. + +## Quick start + Run the tests from the top directory: ```shell @@ -56,7 +65,7 @@ will run the first test in fsck-tests subdirectory. *tests/cli-tests/:* - * tests for command line interface, option coverage, weird optin combinations that should not work + * tests for command line interface, option coverage, weird option combinations that should not work * not necessary to do any functional testing, could be rather lightweight * functional tests should go to to other test dirs * the driver script will only execute `./test.sh` in the test directory @@ -67,8 +76,9 @@ will run the first test in fsck-tests subdirectory. execute `./test.sh` in the test directory *tests/common:* +*tests/common.convert:* - * script with helpers + * script with shell helpers, separated by functionality *tests/test.img:* @@ -99,7 +109,8 @@ the root helper). ### Verbosity Setting the variable `TEST_LOG=tty` will print all commands executed by some of -the wrappers (`run_check` etc), other commands are silent. +the wrappers (`run_check` etc), other commands are not printed to the terminal +(but the full output is in the log). ### Permissions @@ -118,26 +129,33 @@ least the mounts and loop devices need to be cleaned before the next run. This is partially done by the script `clean-tests.sh`, you may want to check the loop devices as they are managed on a per-test basis. +### Prototyping tests, quick tests + +There's a script `test-console.sh` that will run shell commands in a loop and +logs the output with the testing environment set up. + ## New test 1. Pick the category for the new test or fallback to `misc-tests` if not sure. For an easy start copy an existing `test.sh` script from some test that might be -close to the purpose of your new test. +close to the purpose of your new test. The environment setup includes the +common scripts and/or prepares the test devices. Other scripts contain examples +how to do mkfs, mount, unmount, check, etc. -* Use the highest unused number in the sequence, write a short descriptive title -and join by dashes `-`. +2. Use the highest unused number in the sequence, write a short descriptive title +and join by dashes `-`. This will become the directory name, eg. `012-subvolume-sync-must-wait`. -* Write a short description of the bug and how it's tested to the comment at the -begining of `test.sh`. +3. Write a short description of the bug and how it's tested to the comment at the +begining of `test.sh`. You don't need to add the file to git yet. -* Write the test commands, comment anything that's not obvious. +4. Write the test commands, comment anything that's not obvious. -* Test your test. Use the `TEST` variable to jump right to your test: +5. Test your test. Use the `TEST` variable to jump right to your test: ```shell $ make TEST=012\* tests-misc # from top directory $ TEST=012\* ./misc-tests.sh # from tests/ ``` -* The commit changelog should reference a commit that either introduced or +6. The commit changelog should reference a commit that either introduced or fixed the bug (or both). Subject line of the shall mention the name of the new directory for ease of search, eg. `btrfs-progs: tests: add 012-subvolume-sync-must-wait` -- cgit v1.2.3 From 670b73fe0a40fc0b353fce64000c059ccd46a631 Mon Sep 17 00:00:00 2001 From: David Sterba Date: Wed, 22 Jun 2016 15:50:17 +0200 Subject: btrfs-progs: tests: add 005-delete-all-rollback Test if a rollback works after deleing all files from btrfs. Signed-off-by: David Sterba --- .../convert-tests/005-delete-all-rollback/test.sh | 61 ++++++++++++++++++++++ 1 file changed, 61 insertions(+) create mode 100755 tests/convert-tests/005-delete-all-rollback/test.sh (limited to 'tests') diff --git a/tests/convert-tests/005-delete-all-rollback/test.sh b/tests/convert-tests/005-delete-all-rollback/test.sh new file mode 100755 index 00000000..d498e5f8 --- /dev/null +++ b/tests/convert-tests/005-delete-all-rollback/test.sh @@ -0,0 +1,61 @@ +#!/bin/bash +# create a base image, convert to btrfs, remove all files, rollback the ext4 image +# note: ext4 only + +source $TOP/tests/common +source $TOP/tests/common.convert + +setup_root_helper +prepare_test_dev 512M +check_prereq btrfs-convert + +# simple wrapper for a convert test +# $1: btrfs features, argument to -O +# $2: message +# $3: nodesize value +# $4 + rest: command to create the ext2 image +do_test() { + local features + local msg + local nodesize + local CHECKSUMTMP + local here + + features="$1" + msg="$2" + nodesize="$3" + shift 3 + convert_test_preamble "$features" "$msg" "$nodesize" "$@" + convert_test_prep_fs "$@" + populate_fs + CHECKSUMTMP=$(mktemp --tmpdir btrfs-progs-convert.XXXXXXXXXX) + convert_test_gen_checksums "$CHECKSUMTMP" + + run_check_umount_test_dev + + convert_test_do_convert "$features" "$nodesize" + convert_test_post_check "$CHECKSUMTMP" + + run_check_mount_test_dev + here=$(pwd) + cd "$TEST_MNT" || _fail "cannot cd to TEST_MNT" + # ext2_saved/image must not be deleted + run_mayfail $SUDO_HELPER find "$TEST_MNT"/ -mindepth 1 -path '*ext2_saved' -prune -o -exec rm -vrf "{}" \; + cd "$here" + run_check $TOP/btrfs filesystem sync "$TEST_MNT" + run_check_umount_test_dev + convert_test_post_rollback + convert_test_post_check "$CHECKSUMTMP" + + # mount again and verify checksums + convert_test_post_check "$CHECKSUMTMP" + rm "$CHECKSUMTMP" +} + +for feature in '' 'extref' 'skinny-metadata' 'no-holes'; do + do_test "$feature" "ext4 4k nodesize" 4096 mke2fs -t ext4 -b 4096 + do_test "$feature" "ext4 8k nodesize" 8192 mke2fs -t ext4 -b 4096 + do_test "$feature" "ext4 16k nodesize" 16384 mke2fs -t ext4 -b 4096 + do_test "$feature" "ext4 32k nodesize" 32768 mke2fs -t ext4 -b 4096 + do_test "$feature" "ext4 64k nodesize" 65536 mke2fs -t ext4 -b 4096 +done -- cgit v1.2.3 From cd9b35c37ae03d8ea7cc35c4ffe501925e75e629 Mon Sep 17 00:00:00 2001 From: David Sterba Date: Wed, 22 Jun 2016 15:52:17 +0200 Subject: btrfs-progs: tests: fix filesytem type creation for convert tests The extN filesystem type was lost when the separate tests were created and we've been testing only ext2. The tests pass for ext3 and ext4 though. Signed-off-by: David Sterba --- tests/convert-tests/002-ext3-basic/test.sh | 10 +++++----- tests/convert-tests/003-ext4-basic/test.sh | 10 +++++----- 2 files changed, 10 insertions(+), 10 deletions(-) (limited to 'tests') diff --git a/tests/convert-tests/002-ext3-basic/test.sh b/tests/convert-tests/002-ext3-basic/test.sh index 64356307..aeb111eb 100755 --- a/tests/convert-tests/002-ext3-basic/test.sh +++ b/tests/convert-tests/002-ext3-basic/test.sh @@ -8,9 +8,9 @@ prepare_test_dev 512M check_prereq btrfs-convert for feature in '' 'extref' 'skinny-metadata' 'no-holes'; do - convert_test "$feature" "ext3 4k nodesize" 4096 mke2fs -b 4096 - convert_test "$feature" "ext3 8k nodesize" 8192 mke2fs -b 4096 - convert_test "$feature" "ext3 16k nodesize" 16384 mke2fs -b 4096 - convert_test "$feature" "ext3 32k nodesize" 32768 mke2fs -b 4096 - convert_test "$feature" "ext3 64k nodesize" 65536 mke2fs -b 4096 + convert_test "$feature" "ext3 4k nodesize" 4096 mke2fs -j -b 4096 + convert_test "$feature" "ext3 8k nodesize" 8192 mke2fs -j -b 4096 + convert_test "$feature" "ext3 16k nodesize" 16384 mke2fs -j -b 4096 + convert_test "$feature" "ext3 32k nodesize" 32768 mke2fs -j -b 4096 + convert_test "$feature" "ext3 64k nodesize" 65536 mke2fs -j -b 4096 done diff --git a/tests/convert-tests/003-ext4-basic/test.sh b/tests/convert-tests/003-ext4-basic/test.sh index 9a81a473..531c81bd 100755 --- a/tests/convert-tests/003-ext4-basic/test.sh +++ b/tests/convert-tests/003-ext4-basic/test.sh @@ -8,9 +8,9 @@ prepare_test_dev 512M check_prereq btrfs-convert for feature in '' 'extref' 'skinny-metadata' 'no-holes'; do - convert_test "$feature" "ext4 4k nodesize" 4096 mke2fs -b 4096 - convert_test "$feature" "ext4 8k nodesize" 8192 mke2fs -b 4096 - convert_test "$feature" "ext4 16k nodesize" 16384 mke2fs -b 4096 - convert_test "$feature" "ext4 32k nodesize" 32768 mke2fs -b 4096 - convert_test "$feature" "ext4 64k nodesize" 65536 mke2fs -b 4096 + convert_test "$feature" "ext4 4k nodesize" 4096 mke2fs -t ext4 -b 4096 + convert_test "$feature" "ext4 8k nodesize" 8192 mke2fs -t ext4 -b 4096 + convert_test "$feature" "ext4 16k nodesize" 16384 mke2fs -t ext4 -b 4096 + convert_test "$feature" "ext4 32k nodesize" 32768 mke2fs -t ext4 -b 4096 + convert_test "$feature" "ext4 64k nodesize" 65536 mke2fs -t ext4 -b 4096 done -- cgit v1.2.3 From 82aaf603e0e3e2d4302616c0b5c6e45246deca71 Mon Sep 17 00:00:00 2001 From: Luis Henriques Date: Sat, 25 Jun 2016 00:47:29 +0100 Subject: btrfs-progs: tests: 001-simple-unmounted: fix test failure due to bashism The usage of 'source' is a bashism, and '.' should be used instead. This is causing fuzz-tests/001-simple-unmounted to fail in systems where /bin/sh isn't bash: [TEST/fuzz] 001-simple-unmounted ./test.sh: 5: ./test.sh: source: not found ./test.sh: 7: ./test.sh: setup_root_helper: not found ./test.sh: 8: ./test.sh: check_prereq: not found ./test.sh: 18: ./test.sh: check_all_images: not found Since most (all?) tests actually use /bin/bash, change this test to use bash too. Signed-off-by: Luis Henriques Signed-off-by: David Sterba --- tests/fuzz-tests/001-simple-unmounted/test.sh | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) (limited to 'tests') diff --git a/tests/fuzz-tests/001-simple-unmounted/test.sh b/tests/fuzz-tests/001-simple-unmounted/test.sh index bf01a3a4..98fe7b0c 100755 --- a/tests/fuzz-tests/001-simple-unmounted/test.sh +++ b/tests/fuzz-tests/001-simple-unmounted/test.sh @@ -1,4 +1,4 @@ -#!/bin/sh +#!/bin/bash # iterate over all fuzzed images and run 'btrfs check' -- cgit v1.2.3 From 2e58edbdf45b901558dffe98933d19bdb510b35b Mon Sep 17 00:00:00 2001 From: Qu Wenruo Date: Mon, 27 Jun 2016 15:50:11 +0800 Subject: btrfs-progs: convert-test: Add test case for discontinuous hole extent For ext* fs containing a large hole(larger than 128M), btrfs-convert will only insert one 128M hole extent and skip the remaining. This leads to discontinuous file extents. Add test case for it, and since it's a pinpoint regression test case, no combination of convert options nor checksum verification. Signed-off-by: Qu Wenruo Signed-off-by: David Sterba --- tests/convert-tests/006-large-hole-extent/test.sh | 23 +++++++++++++++++++++++ 1 file changed, 23 insertions(+) create mode 100755 tests/convert-tests/006-large-hole-extent/test.sh (limited to 'tests') diff --git a/tests/convert-tests/006-large-hole-extent/test.sh b/tests/convert-tests/006-large-hole-extent/test.sh new file mode 100755 index 00000000..d3bc093c --- /dev/null +++ b/tests/convert-tests/006-large-hole-extent/test.sh @@ -0,0 +1,23 @@ +#!/bin/bash +# Create a base image with large hole extent, then convert to btrfs, +# check the converted image. +# Check if btrfs-convert can handle such large hole. +# Fast pinpoint regression test. No options combination nor checksum +# verification + +source $TOP/tests/common +source $TOP/tests/common.convert + +setup_root_helper +prepare_test_dev 512M +check_prereq btrfs-convert + +default_mke2fs="mke2fs -t ext4 -b 4096" +convert_test_preamble '' 'large hole extent test' 16k "$default_mke2fs" +convert_test_prep_fs $default_mke2fs + +run_check $SUDO_HELPER dd if=/dev/zero of=$TEST_MNT/file bs=1M \ + count=1 seek=1024 > /dev/null 2>&1 + +run_check_umount_test_dev +convert_test_do_convert -- cgit v1.2.3 From 52fda816e88b2b521c2eaa8e416176d3a8d7a6fa Mon Sep 17 00:00:00 2001 From: David Sterba Date: Mon, 4 Jul 2016 13:45:15 +0200 Subject: btrfs-progs: tests: use /bin/bash for scripts Since we use 'source' in scripts, let's use bash everywhere. Signed-off-by: David Sterba --- tests/clean-tests.sh | 2 +- tests/test-console.sh | 2 +- 2 files changed, 2 insertions(+), 2 deletions(-) (limited to 'tests') diff --git a/tests/clean-tests.sh b/tests/clean-tests.sh index f7fefdda..7f18e6f0 100755 --- a/tests/clean-tests.sh +++ b/tests/clean-tests.sh @@ -1,4 +1,4 @@ -#!/bin/sh +#!/bin/bash # remove all intermediate files from tests SCRIPT_DIR=$(dirname $(readlink -f $0)) diff --git a/tests/test-console.sh b/tests/test-console.sh index cc1cdf3c..365cc971 100755 --- a/tests/test-console.sh +++ b/tests/test-console.sh @@ -1,4 +1,4 @@ -#!/bin/sh +#!/bin/bash # a shell with test environment set up, logged commands and output LANG=C -- cgit v1.2.3 From 08c70e18defee0eed543f5a2ee88beed7a710d5f Mon Sep 17 00:00:00 2001 From: Luis Henriques Date: Mon, 4 Jul 2016 23:48:47 +0100 Subject: btrfs-progs: tests: 006-image-on-missing-device: fix btrfs tool path If btrfs isn't in the path, this test will fail with: [TEST/misc] 006-image-on-missing-device failed: btrfs fi show /dev/loop0 test failed for case 006-image-on-missing-device Makefile:226: recipe for target 'test-misc' failed make: *** [test-misc] Error 1 Fix the test script by adding $TOP to the path. Signed-off-by: Luis Henriques [ updated to full command names ] Signed-off-by: David Sterba --- tests/misc-tests/006-image-on-missing-device/test.sh | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) (limited to 'tests') diff --git a/tests/misc-tests/006-image-on-missing-device/test.sh b/tests/misc-tests/006-image-on-missing-device/test.sh index 8680a707..b22a95d7 100755 --- a/tests/misc-tests/006-image-on-missing-device/test.sh +++ b/tests/misc-tests/006-image-on-missing-device/test.sh @@ -61,12 +61,12 @@ test_run() run_check $SUDO_HELPER umount $TEST_MNT test_image_dump - run_check btrfs fi show $dev1 + run_check $TOP/btrfs filesystem show $dev1 # create a degraded raid1 filesystem, check must succeed # btrfs-image must not loop run_mayfail wipefs -a $dev2 run_check $SUDO_HELPER losetup -d $dev2 - run_check btrfs fi show $dev1 + run_check $TOP/btrfs filesystem show $dev1 test_image_dump } -- cgit v1.2.3 From ebbddd7fd4307a692355490494ebc53ef0689f39 Mon Sep 17 00:00:00 2001 From: David Sterba Date: Fri, 15 Jul 2016 01:25:12 +0200 Subject: btrfs-progs: tests: add 007-unsupported-block-sizes Check if block sizes smaller than 4k expectedly fail to convert. Signed-off-by: David Sterba --- .../007-unsupported-block-sizes/test.sh | 21 +++++++++++++++++++++ 1 file changed, 21 insertions(+) create mode 100755 tests/convert-tests/007-unsupported-block-sizes/test.sh (limited to 'tests') diff --git a/tests/convert-tests/007-unsupported-block-sizes/test.sh b/tests/convert-tests/007-unsupported-block-sizes/test.sh new file mode 100755 index 00000000..9ba17751 --- /dev/null +++ b/tests/convert-tests/007-unsupported-block-sizes/test.sh @@ -0,0 +1,21 @@ +#!/bin/bash +# Check if block sizes smaller than 4k expectedly fail to convert + +source $TOP/tests/common +source $TOP/tests/common.convert + +setup_root_helper +prepare_test_dev 512M +check_prereq btrfs-convert + +for bs in 1024 2048; do + default_mke2fs="mke2fs -t ext4 -b $bs" + convert_test_preamble '' "unsupported block size $bs" 16k "$default_mke2fs" + convert_test_prep_fs $default_mke2fs + + run_check $SUDO_HELPER dd if=/dev/zero of=$TEST_MNT/file bs=1M \ + count=1 seek=1024 > /dev/null 2>&1 + + run_check_umount_test_dev + run_mustfail "$bs block converted" $TOP/btrfs-convert $TEST_DEV +done -- cgit v1.2.3 From 4f3ccdd518cbea2a34f5a62099bb1ca2881fae9c Mon Sep 17 00:00:00 2001 From: Qu Wenruo Date: Fri, 19 Aug 2016 16:13:06 +0800 Subject: btrfs-progs: convert-test: Check if the ext2_save/image is read only Old convert codes uses both 0400 permission and INODE_READONLY flag to make the converted ext2 image readonly. While new convert treat the inode just as normal inode, with no special inode flag and uses 0600 permission. This makes user able to modify converted image unintentionally and make rollback fails. This test case will test the regression. Signed-off-by: Qu Wenruo Signed-off-by: David Sterba --- tests/convert-tests/008-readonly-image/test.sh | 26 ++++++++++++++++++++++++++ 1 file changed, 26 insertions(+) create mode 100755 tests/convert-tests/008-readonly-image/test.sh (limited to 'tests') diff --git a/tests/convert-tests/008-readonly-image/test.sh b/tests/convert-tests/008-readonly-image/test.sh new file mode 100755 index 00000000..4e422378 --- /dev/null +++ b/tests/convert-tests/008-readonly-image/test.sh @@ -0,0 +1,26 @@ +#!/bin/bash +# Check if the converted ext2 image is readonly + +source $TOP/tests/common +source $TOP/tests/common.convert + +setup_root_helper +prepare_test_dev 512M +check_prereq btrfs-convert + +default_mke2fs="mke2fs -t ext4 -b 4096" +convert_test_preamble '' 'readonly image test' 16k "$default_mke2fs" +convert_test_prep_fs $default_mke2fs +run_check_umount_test_dev +convert_test_do_convert +run_check_mount_test_dev + +# It's expected to fail +$SUDO_HELPER dd if=/dev/zero of=$TEST_MNT/ext2_save/image bs=1M count=1 \ + &> /dev/null +if [ $? -ne 1 ]; then + echo "after convert ext2_save/image is not read-only" + exit 1 +fi +run_check_umount_test_dev +convert_test_post_rollback -- cgit v1.2.3 From 767ae9e348a667fa4e05e3b1a01630ecaff1f27d Mon Sep 17 00:00:00 2001 From: Qu Wenruo Date: Tue, 30 Aug 2016 10:15:50 +0800 Subject: btrfs-progs: fuzz-test: Add image for wrong chunk item in root tree Reported by Lukas and the same image from him. DATA_RELOC tree's key type is modifed to CHUNK_ITEM, causing btrfsck interpret it as CHUNK_ITEM and cause 0 num_stripes. Add the image to fuzz-test. Reported-by: Lukas Lueg Signed-off-by: Qu Wenruo [ added bko-NNN- prefix to the files ] Signed-off-by: David Sterba --- ...ko-155201-wrong-chunk-item-in-root-tree.raw.txt | 35 +++++++++++++++++++++ ...bko-155201-wrong-chunk-item-in-root-tree.raw.xz | Bin 0 -> 3696 bytes 2 files changed, 35 insertions(+) create mode 100644 tests/fuzz-tests/images/bko-155201-wrong-chunk-item-in-root-tree.raw.txt create mode 100644 tests/fuzz-tests/images/bko-155201-wrong-chunk-item-in-root-tree.raw.xz (limited to 'tests') diff --git a/tests/fuzz-tests/images/bko-155201-wrong-chunk-item-in-root-tree.raw.txt b/tests/fuzz-tests/images/bko-155201-wrong-chunk-item-in-root-tree.raw.txt new file mode 100644 index 00000000..9097e49d --- /dev/null +++ b/tests/fuzz-tests/images/bko-155201-wrong-chunk-item-in-root-tree.raw.txt @@ -0,0 +1,35 @@ +URL: https://bugzilla.kernel.org/show_bug.cgi?id=155201 +Lukas Lueg 2016-08-28 19:15:53 UTC + +Created attachment 230921 [details] +Image causing SIGFPE in btrfsck + +News from the fuzzer. See the attached image to reproduce using btrfs-progs +v4.7-42-g56e9586. + + +[Thread debugging using libthread_db enabled] +Using host libthread_db library "/lib64/libthread_db.so.1". +checking extents +Chunk[0, 4194304] existed. +Chunk[18446744073709551607, 228, 0]: length(1), offset(0), type(4160) mismatch +with block group[0, 192, 4194304]: offset(4194304), objectid(0), flags(2) + +Program received signal SIGFPE, Arithmetic exception. +0x000000000042b178 in calc_stripe_length (type=4160, length=1, num_stripes=0) +at cmds-check.c:8018 +8018 stripe_size /= num_stripes; +#0 0x000000000042b178 in calc_stripe_length (type=4160, length=1, +num_stripes=0) at cmds-check.c:8018 +#1 0x000000000042b56d in check_chunk_refs (silent=0, +dev_extent_cache=0x7fffffffdd30, block_group_cache=0x7fffffffdd60, +chunk_rec=0x6b92c0) at cmds-check.c:8101 +#2 check_chunks (chunk_cache=chunk_cache@entry=0x7fffffffdd80, +block_group_cache=block_group_cache@entry=0x7fffffffdd60, +dev_extent_cache=dev_extent_cache@entry=0x7fffffffdd30, good=good@entry=0x0, +bad=bad@entry=0x0, rebuild=rebuild@entry=0x0, silent=0) at cmds-check.c:8165 +#3 0x000000000042bbdd in check_chunks_and_extents (root=root@entry=0x6b2cf0) +at cmds-check.c:8524 +#4 0x000000000042e3cb in cmd_check (argc=, argv=) at cmds-check.c:11430 +#5 0x000000000040a416 in main (argc=2, argv=0x7fffffffe218) at btrfs.c:243 diff --git a/tests/fuzz-tests/images/bko-155201-wrong-chunk-item-in-root-tree.raw.xz b/tests/fuzz-tests/images/bko-155201-wrong-chunk-item-in-root-tree.raw.xz new file mode 100644 index 00000000..5bc2d3b9 Binary files /dev/null and b/tests/fuzz-tests/images/bko-155201-wrong-chunk-item-in-root-tree.raw.xz differ -- cgit v1.2.3 From ba23b7679fb85e55cb28239e65a58a4f47e9f739 Mon Sep 17 00:00:00 2001 From: Qu Wenruo Date: Tue, 30 Aug 2016 11:29:33 +0800 Subject: btrfs-progs: fuzz-test: Add image for unaligned tree block ptr Add test case image for unaligned tree block ptr. It should lead to BUG_ON in free_extent_buffer(). Reported-by: Lukas Lueg Signed-off-by: Qu Wenruo [ added bko-NNN- prefix to the files ] Signed-off-by: David Sterba --- .../bko-153641-unaligned-tree-block-bytenr.raw.txt | 33 +++++++++++++++++++++ .../bko-153641-unaligned-tree-block-bytenr.raw.xz | Bin 0 -> 3852 bytes 2 files changed, 33 insertions(+) create mode 100644 tests/fuzz-tests/images/bko-153641-unaligned-tree-block-bytenr.raw.txt create mode 100644 tests/fuzz-tests/images/bko-153641-unaligned-tree-block-bytenr.raw.xz (limited to 'tests') diff --git a/tests/fuzz-tests/images/bko-153641-unaligned-tree-block-bytenr.raw.txt b/tests/fuzz-tests/images/bko-153641-unaligned-tree-block-bytenr.raw.txt new file mode 100644 index 00000000..05cf3928 --- /dev/null +++ b/tests/fuzz-tests/images/bko-153641-unaligned-tree-block-bytenr.raw.txt @@ -0,0 +1,33 @@ +URL: https://bugzilla.kernel.org/show_bug.cgi?id=153641 +Lukas Lueg 2016-08-23 19:54:45 UTC + +Created attachment 229941 [details] +Image triggering btrfsck into asan error + +The filesystem-image attached to this bug drives btrfsck from btrfs-progs +v4.7-42-g56e9586 into a heap-use-after-free. The src was from kdave's mirror, +devel branch. CFLAGS='-DNDEBUG -O1 -g -fsanitize=address +-fno-omit-frame-pointer -fno-optimize-sibling-calls' + + +The juicy parts: +==32639==ERROR: AddressSanitizer: heap-use-after-free on address +0x621000019170 at pc 0x0000005c046e bp 0x7fff631e48d0 sp 0x7fff631e48c8 +READ of size 4 at 0x621000019170 thread T0 + #0 0x5c046d in free_extent_buffer +/home/lukas/dev/btrfsprogs_fuzz/src/extent_io.c:579:10 + #1 0x59356c in btrfs_release_all_roots +/home/lukas/dev/btrfsprogs_fuzz/src/disk-io.c:1084:3 + #2 0x5949a7 in __open_ctree_fd +/home/lukas/dev/btrfsprogs_fuzz/src/disk-io.c:1325:2 + #3 0x594325 in open_ctree_fs_info +/home/lukas/dev/btrfsprogs_fuzz/src/disk-io.c:1363:9 + #4 0x51e717 in cmd_check +/home/lukas/dev/btrfsprogs_fuzz/src/cmds-check.c:11320:9 + #5 0x4f0f81 in main /home/lukas/dev/btrfsprogs_fuzz/src/btrfs.c:243:8 + #6 0x7f5ce75ee730 in __libc_start_main (/lib64/libc.so.6+0x20730) + #7 0x4213f8 in _start (/home/lukas/dev/btrfsfuzz/bin/bin/btrfs+0x4213f8) + + +Note that the bug happens within core itself. The kernel may be vulnerable as +well, I didn't check, though. diff --git a/tests/fuzz-tests/images/bko-153641-unaligned-tree-block-bytenr.raw.xz b/tests/fuzz-tests/images/bko-153641-unaligned-tree-block-bytenr.raw.xz new file mode 100644 index 00000000..d37b1a2d Binary files /dev/null and b/tests/fuzz-tests/images/bko-153641-unaligned-tree-block-bytenr.raw.xz differ -- cgit v1.2.3 From f51a34696bff9c60bc03d6a9c2934121d9423061 Mon Sep 17 00:00:00 2001 From: Qu Wenruo Date: Tue, 30 Aug 2016 15:22:14 +0800 Subject: btrfs-progs: fuzz-test: Add test case for invalid drop level Reported-by: Lukas Lueg Signed-off-by: Qu Wenruo [ added bko-NNN- prefix to the files ] Signed-off-by: David Sterba --- .../images/bko-154021-invalid-drop-level.raw.txt | 30 +++++++++++++++++++++ .../images/bko-154021-invalid-drop-level.raw.xz | Bin 0 -> 3788 bytes 2 files changed, 30 insertions(+) create mode 100644 tests/fuzz-tests/images/bko-154021-invalid-drop-level.raw.txt create mode 100644 tests/fuzz-tests/images/bko-154021-invalid-drop-level.raw.xz (limited to 'tests') diff --git a/tests/fuzz-tests/images/bko-154021-invalid-drop-level.raw.txt b/tests/fuzz-tests/images/bko-154021-invalid-drop-level.raw.txt new file mode 100644 index 00000000..dab91dcc --- /dev/null +++ b/tests/fuzz-tests/images/bko-154021-invalid-drop-level.raw.txt @@ -0,0 +1,30 @@ +URL: https://bugzilla.kernel.org/show_bug.cgi?id=154021 +Lukas Lueg 2016-08-26 22:53:42 UTC + +Created attachment 230361 [details] +Image triggering btrfsck to segv + +The fuzzer hit again: + +==32522==ERROR: AddressSanitizer: SEGV on unknown address 0x00027fff801c (pc +0x0000004a952e bp 0x7fff5222ce70 sp 0x7fff5222c600 T0) + #0 0x4a952d in __asan_memcpy +(/home/lukas/dev/btrfsfuzz/bin-asan/bin/btrfs+0x4a952d) + #1 0x66a323 in read_extent_buffer +/home/lukas/dev/btrfsfuzz/src-asan/extent_io.c:867:2 + #2 0x55ad25 in btrfs_node_key +/home/lukas/dev/btrfsfuzz/src-asan/./ctree.h:1668:2 + #3 0x58573b in check_fs_root +/home/lukas/dev/btrfsfuzz/src-asan/cmds-check.c:3748:3 + #4 0x544136 in check_fs_roots +/home/lukas/dev/btrfsfuzz/src-asan/cmds-check.c:3896:10 + #5 0x53d8c5 in cmd_check +/home/lukas/dev/btrfsfuzz/src-asan/cmds-check.c:11470:8 + #6 0x4f105f in main /home/lukas/dev/btrfsfuzz/src-asan/btrfs.c:243:8 + #7 0x7fea1bcb7730 in __libc_start_main (/lib64/libc.so.6+0x20730) + #8 0x421238 in _start +(/home/lukas/dev/btrfsfuzz/bin-asan/bin/btrfs+0x421238) + + +See the attached image to reproduce using btrfs-progs btrfs-progs +v4.7-42-g56e9586. diff --git a/tests/fuzz-tests/images/bko-154021-invalid-drop-level.raw.xz b/tests/fuzz-tests/images/bko-154021-invalid-drop-level.raw.xz new file mode 100644 index 00000000..76c58dce Binary files /dev/null and b/tests/fuzz-tests/images/bko-154021-invalid-drop-level.raw.xz differ -- cgit v1.2.3 From 8607100a9b5c99736fa1fce3e0c6c624c189f4ec Mon Sep 17 00:00:00 2001 From: Qu Wenruo Date: Tue, 30 Aug 2016 15:22:17 +0800 Subject: btrfs-progs: fuzz-test: Add test case for unaligned extent item Reported-by: Lukas Lueg Signed-off-by: Qu Wenruo [ added bko-NNN- prefix to the files ] Signed-off-by: David Sterba --- .../images/bko-155181-unaligned-extent-item.raw.txt | 8 ++++++++ .../images/bko-155181-unaligned-extent-item.raw.xz | Bin 0 -> 3684 bytes 2 files changed, 8 insertions(+) create mode 100644 tests/fuzz-tests/images/bko-155181-unaligned-extent-item.raw.txt create mode 100644 tests/fuzz-tests/images/bko-155181-unaligned-extent-item.raw.xz (limited to 'tests') diff --git a/tests/fuzz-tests/images/bko-155181-unaligned-extent-item.raw.txt b/tests/fuzz-tests/images/bko-155181-unaligned-extent-item.raw.txt new file mode 100644 index 00000000..7f0b8045 --- /dev/null +++ b/tests/fuzz-tests/images/bko-155181-unaligned-extent-item.raw.txt @@ -0,0 +1,8 @@ +URL: https://bugzilla.kernel.org/show_bug.cgi?id=155181 +Lukas Lueg 2016-08-28 10:52:32 UTC + +Created attachment 230891 [details] +BTRFS-image that reaches abort() in btrfsck + +More news from the fuzzer. The attached image causes btrfsck to reach abort() +in in cmds-check.c:add_tree_backref(); using btrfs-progs v4.7-42-g56e9586. diff --git a/tests/fuzz-tests/images/bko-155181-unaligned-extent-item.raw.xz b/tests/fuzz-tests/images/bko-155181-unaligned-extent-item.raw.xz new file mode 100644 index 00000000..c401f2e5 Binary files /dev/null and b/tests/fuzz-tests/images/bko-155181-unaligned-extent-item.raw.xz differ -- cgit v1.2.3 From aa6baa178dd9215ef3aeaaf7deac1090bfa76743 Mon Sep 17 00:00:00 2001 From: David Sterba Date: Tue, 30 Aug 2016 17:09:10 +0200 Subject: btrfs-progs: tests README: fuzzed images Signed-off-by: David Sterba --- tests/README.md | 11 +++++++++++ 1 file changed, 11 insertions(+) (limited to 'tests') diff --git a/tests/README.md b/tests/README.md index 6bb3de49..ca45cf6f 100644 --- a/tests/README.md +++ b/tests/README.md @@ -159,3 +159,14 @@ $ TEST=012\* ./misc-tests.sh # from tests/ 6. The commit changelog should reference a commit that either introduced or fixed the bug (or both). Subject line of the shall mention the name of the new directory for ease of search, eg. `btrfs-progs: tests: add 012-subvolume-sync-must-wait` + +### Crafted/fuzzed images + +Images that are create by fuzzing or specially crafted to trigger some error +conditions should be added to the directory *fuzz-tests/images*, accompanied by +a textual description of the source (bugzilla, mail), the reporter, brief +description of the problem or the stack trace. + +If you have a fix for the problem, please submit it prior to the test image, so +the fuzz tests always succeed when run on random checked out. This helps +bisectability. -- cgit v1.2.3 From f919530b3a1d5876d3ce6213dbb0b65b853f2ba8 Mon Sep 17 00:00:00 2001 From: David Sterba Date: Thu, 1 Sep 2016 20:05:20 +0200 Subject: btrfs-progs: tests: add 015-dump-super-garbage Signed-off-by: David Sterba --- tests/misc-tests/015-dump-super-garbage/test.sh | 17 +++++++++++++++++ 1 file changed, 17 insertions(+) create mode 100755 tests/misc-tests/015-dump-super-garbage/test.sh (limited to 'tests') diff --git a/tests/misc-tests/015-dump-super-garbage/test.sh b/tests/misc-tests/015-dump-super-garbage/test.sh new file mode 100755 index 00000000..33fc8332 --- /dev/null +++ b/tests/misc-tests/015-dump-super-garbage/test.sh @@ -0,0 +1,17 @@ +#!/bin/bash +# +# let dump-super dump random data, must not crash + +source $TOP/tests/common + +check_prereq btrfs + +run_check $TOP/btrfs inspect-internal dump-super /dev/urandom +run_check $TOP/btrfs inspect-internal dump-super -a /dev/urandom +run_check $TOP/btrfs inspect-internal dump-super -fa /dev/urandom +run_check $TOP/btrfs inspect-internal dump-super -Ffa /dev/urandom +run_check $TOP/btrfs inspect-internal dump-super -Ffa /dev/urandom +run_check $TOP/btrfs inspect-internal dump-super -Ffa /dev/urandom +run_check $TOP/btrfs inspect-internal dump-super -Ffa /dev/urandom +run_check $TOP/btrfs inspect-internal dump-super -Ffa /dev/urandom +run_check $TOP/btrfs inspect-internal dump-super -Ffa /dev/urandom -- cgit v1.2.3 From 1e4ef75053e05cef19f3ba41eef80d2dabbb49ce Mon Sep 17 00:00:00 2001 From: David Sterba Date: Sat, 3 Sep 2016 20:47:21 +0200 Subject: btrfs-progs: tests: add fuzzed image for invalid sub_stripe value Reported-by: Lukas Lueg Signed-off-by: David Sterba --- .../bko-97041-invalid-sub-stripes-zero-FPE.raw.txt | 50 +++++++++++++++++++++ .../bko-97041-invalid-sub-stripes-zero-FPE.raw.xz | Bin 0 -> 6476 bytes 2 files changed, 50 insertions(+) create mode 100644 tests/fuzz-tests/images/bko-97041-invalid-sub-stripes-zero-FPE.raw.txt create mode 100644 tests/fuzz-tests/images/bko-97041-invalid-sub-stripes-zero-FPE.raw.xz (limited to 'tests') diff --git a/tests/fuzz-tests/images/bko-97041-invalid-sub-stripes-zero-FPE.raw.txt b/tests/fuzz-tests/images/bko-97041-invalid-sub-stripes-zero-FPE.raw.txt new file mode 100644 index 00000000..5f631646 --- /dev/null +++ b/tests/fuzz-tests/images/bko-97041-invalid-sub-stripes-zero-FPE.raw.txt @@ -0,0 +1,50 @@ +URL: https://bugzilla.kernel.org/show_bug.cgi?id=97041 + Lukas Lueg 2015-04-21 21:53:14 UTC + +The btrfs-image attached to this bug causes the userland tools v3.19.1 to +crash with a SIGFPE. The problem is that map->sub_stripes in +__btrfs_map_block() is allowed to be 0 before entering a division. + +The userland tool crashes. The kernel reports a "divide error: 0000 ..." +with a traceback from __btrfs_map_block() + + +(gdb) run check btrfs_fukked_sigfpe_volumes:1404.bin +Starting program: /usr/sbin/btrfs check btrfs_fukked_sigfpe_volumes:1404.bin +[Thread debugging using libthread_db enabled] +Using host libthread_db library "/lib64/libthread_db.so.1". + +Program received signal SIGFPE, Arithmetic exception. +0x000000000044d7b6 in __btrfs_map_block (map_tree=map_tree@entry=0x88c170, + rw=rw@entry=0, logical=, length=length@entry=0x7fffffffd8f0, + type=type@entry=0x0, multi_ret=multi_ret@entry=0x7fffffffd8e8, mirror_num=0, + raid_map_ret=0x0) at volumes.c:1404 +1404 int factor = map->num_stripes / map->sub_stripes; +(gdb) bt +#0 0x000000000044d7b6 in __btrfs_map_block (map_tree=map_tree@entry=0x88c170, + rw=rw@entry=0, logical=, length=length@entry=0x7fffffffd8f0, + type=type@entry=0x0, multi_ret=multi_ret@entry=0x7fffffffd8e8, mirror_num=0, + raid_map_ret=0x0) at volumes.c:1404 +#1 0x000000000044db45 in btrfs_map_block (map_tree=map_tree@entry=0x88c170, + rw=rw@entry=0, logical=, length=length@entry=0x7fffffffd8f0, + multi_ret=multi_ret@entry=0x7fffffffd8e8, mirror_num=mirror_num@entry=0, + raid_map_ret=0x0) at volumes.c:1291 +#2 0x000000000043b22d in read_whole_eb (info=0x88c010, eb=eb@entry=0x88f400, + mirror=mirror@entry=0) at disk-io.c:232 +#3 0x000000000043caa2 in read_tree_block (root=root@entry=0x88c710, + bytenr=, blocksize=, parent_transid=5) + at disk-io.c:295 +#4 0x000000000043d5df in btrfs_setup_chunk_tree_and_device_map ( + fs_info=fs_info@entry=0x88c010) at disk-io.c:1106 +#5 0x000000000043d7d1 in __open_ctree_fd (fp=fp@entry=3, + path=path@entry=0x7fffffffe1fa "btrfs_fukked_sigfpe_volumes:1404.bin", + sb_bytenr=65536, sb_bytenr@entry=0, root_tree_bytenr=root_tree_bytenr@entry=0, + flags=flags@entry=OPEN_CTREE_EXCLUSIVE) at disk-io.c:1190 +#6 0x000000000043d965 in open_ctree_fs_info ( + filename=0x7fffffffe1fa "btrfs_fukked_sigfpe_volumes:1404.bin", + sb_bytenr=sb_bytenr@entry=0, root_tree_bytenr=root_tree_bytenr@entry=0, + flags=flags@entry=OPEN_CTREE_EXCLUSIVE) at disk-io.c:1231 +#7 0x0000000000427bf5 in cmd_check (argc=1, argv=0x7fffffffde90) at cmds-check.c:9326 +#8 0x000000000040e5a2 in main (argc=2, argv=0x7fffffffde90) at btrfs.c:245 +(gdb) p map->sub_stripes +$1 = 0 diff --git a/tests/fuzz-tests/images/bko-97041-invalid-sub-stripes-zero-FPE.raw.xz b/tests/fuzz-tests/images/bko-97041-invalid-sub-stripes-zero-FPE.raw.xz new file mode 100644 index 00000000..b8e23eb7 Binary files /dev/null and b/tests/fuzz-tests/images/bko-97041-invalid-sub-stripes-zero-FPE.raw.xz differ -- cgit v1.2.3 From 083721de5c0c056a1699a70ec7a75a4e17d748ee Mon Sep 17 00:00:00 2001 From: David Sterba Date: Sat, 3 Sep 2016 20:52:18 +0200 Subject: btrfs-progs: tests: add fuzzed image for invalid sys_array and stripe_len Reported-by: Lukas Lueg Signed-off-by: David Sterba --- .../bko-97031-invalid-stripe-len-sys-array.raw.txt | 58 +++++++++++++++++++++ .../bko-97031-invalid-stripe-len-sys-array.raw.xz | Bin 0 -> 7128 bytes 2 files changed, 58 insertions(+) create mode 100644 tests/fuzz-tests/images/bko-97031-invalid-stripe-len-sys-array.raw.txt create mode 100644 tests/fuzz-tests/images/bko-97031-invalid-stripe-len-sys-array.raw.xz (limited to 'tests') diff --git a/tests/fuzz-tests/images/bko-97031-invalid-stripe-len-sys-array.raw.txt b/tests/fuzz-tests/images/bko-97031-invalid-stripe-len-sys-array.raw.txt new file mode 100644 index 00000000..2dc51b21 --- /dev/null +++ b/tests/fuzz-tests/images/bko-97031-invalid-stripe-len-sys-array.raw.txt @@ -0,0 +1,58 @@ +URL: https://bugzilla.kernel.org/show_bug.cgi?id=97031 +Lukas Lueg 2015-04-21 21:47:18 UTC + +The btrfs-image attached to this bug causes the userland tools v3.19.1 to crash +with a SIGFPE. The problem is that map->stripe_len in __btrfs_map_block() is +allowed to be 0 before entering a division. + +The userland tool crashes. +The kernel fails to mount with +> BTRFS: failed to read the system array on loop0 +> BTRFS: open_ctree_failed + + + +(gdb) run check btrfs_fukked_sigfpe_volumes:1372.bin +.... +warning, device 0 is missing +warning, device 4294967295 is missing +warning, device 0 is missing +warning, device 0 is missing +warning, device 0 is missing +warning, device 0 is missing +warning, device 4294967295 is missing + +Program received signal SIGFPE, Arithmetic exception. +0x000000000044d56f in __btrfs_map_block (map_tree=map_tree@entry=0x88c170, + rw=rw@entry=0, logical=, length=length@entry=0x7fffffffd8f0, + type=type@entry=0x0, multi_ret=multi_ret@entry=0x7fffffffd8e8, mirror_num=0, + raid_map_ret=0x0) at volumes.c:1372 +1372 stripe_nr = stripe_nr / map->stripe_len; +(gdb) bt +#0 0x000000000044d56f in __btrfs_map_block (map_tree=map_tree@entry=0x88c170, + rw=rw@entry=0, logical=, length=length@entry=0x7fffffffd8f0, + type=type@entry=0x0, multi_ret=multi_ret@entry=0x7fffffffd8e8, mirror_num=0, + raid_map_ret=0x0) at volumes.c:1372 +#1 0x000000000044db45 in btrfs_map_block (map_tree=map_tree@entry=0x88c170, + rw=rw@entry=0, logical=, length=length@entry=0x7fffffffd8f0, + multi_ret=multi_ret@entry=0x7fffffffd8e8, mirror_num=mirror_num@entry=0, + raid_map_ret=0x0) at volumes.c:1291 +#2 0x000000000043b22d in read_whole_eb (info=0x88c010, eb=eb@entry=0x88f400, + mirror=mirror@entry=0) at disk-io.c:232 +#3 0x000000000043caa2 in read_tree_block (root=root@entry=0x88c710, + bytenr=, blocksize=, parent_transid=5) + at disk-io.c:295 +#4 0x000000000043d5df in btrfs_setup_chunk_tree_and_device_map ( + fs_info=fs_info@entry=0x88c010) at disk-io.c:1106 +#5 0x000000000043d7d1 in __open_ctree_fd (fp=fp@entry=3, + path=path@entry=0x7fffffffe1fa "btrfs_fukked_sigfpe_volumes:1372.bin", + sb_bytenr=65536, sb_bytenr@entry=0, root_tree_bytenr=root_tree_bytenr@entry=0, + flags=flags@entry=OPEN_CTREE_EXCLUSIVE) at disk-io.c:1190 +#6 0x000000000043d965 in open_ctree_fs_info ( + filename=0x7fffffffe1fa "btrfs_fukked_sigfpe_volumes:1372.bin", + sb_bytenr=sb_bytenr@entry=0, root_tree_bytenr=root_tree_bytenr@entry=0, + flags=flags@entry=OPEN_CTREE_EXCLUSIVE) at disk-io.c:1231 +#7 0x0000000000427bf5 in cmd_check (argc=1, argv=0x7fffffffde90) at cmds-check.c:9326 +#8 0x000000000040e5a2 in main (argc=2, argv=0x7fffffffde90) at btrfs.c:245 +(gdb) p map->stripe_len +$1 = 0 diff --git a/tests/fuzz-tests/images/bko-97031-invalid-stripe-len-sys-array.raw.xz b/tests/fuzz-tests/images/bko-97031-invalid-stripe-len-sys-array.raw.xz new file mode 100644 index 00000000..8680fa34 Binary files /dev/null and b/tests/fuzz-tests/images/bko-97031-invalid-stripe-len-sys-array.raw.xz differ -- cgit v1.2.3 From 386cdcd741d1e0f64754eee5c246bb03842d017e Mon Sep 17 00:00:00 2001 From: David Sterba Date: Sat, 3 Sep 2016 20:52:18 +0200 Subject: btrfs-progs: tests: add fuzzed image for invalid chunk sectorsize Reported-by: Lukas Lueg Signed-off-by: David Sterba --- .../bko-97021-invalid-chunk-sectorsize.raw.txt | 41 +++++++++++++++++++++ .../bko-97021-invalid-chunk-sectorsize.raw.xz | Bin 0 -> 6472 bytes 2 files changed, 41 insertions(+) create mode 100644 tests/fuzz-tests/images/bko-97021-invalid-chunk-sectorsize.raw.txt create mode 100644 tests/fuzz-tests/images/bko-97021-invalid-chunk-sectorsize.raw.xz (limited to 'tests') diff --git a/tests/fuzz-tests/images/bko-97021-invalid-chunk-sectorsize.raw.txt b/tests/fuzz-tests/images/bko-97021-invalid-chunk-sectorsize.raw.txt new file mode 100644 index 00000000..fb098411 --- /dev/null +++ b/tests/fuzz-tests/images/bko-97021-invalid-chunk-sectorsize.raw.txt @@ -0,0 +1,41 @@ +URL: https://bugzilla.kernel.org/show_bug.cgi?id=97021 +Lukas Lueg 2015-04-21 21:36:31 UTC + +The btrfs-image attached to this bug causes the userland tools v3.19.1 to crash +by reaching a call to abort(). + +(gdb) run check btrfs_fukked_abort_cmds-check:5919.bin +Starting program: /usr/sbin/btrfs check btrfs_fukked_abort_cmds-check:5919.bin +[Thread debugging using libthread_db enabled] +Using host libthread_db library "/lib64/libthread_db.so.1". +Checking filesystem on btrfs_fukked_abort_cmds-check:5919.bin +UUID: cdd8684f-9eb1-40a4-91ec-1ed7c3cb444c +checking extents + +Program received signal SIGABRT, Aborted. +0x00000032626348d7 in __GI_raise (sig=sig@entry=6) + at ../sysdeps/unix/sysv/linux/raise.c:55 +55 return INLINE_SYSCALL (tgkill, 3, pid, selftid, sig); +(gdb) bt +#0 0x00000032626348d7 in __GI_raise (sig=sig@entry=6) + at ../sysdeps/unix/sysv/linux/raise.c:55 +#1 0x000000326263653a in __GI_abort () at abort.c:89 +#2 0x0000000000425038 in run_next_block (root=root@entry=0x894b20, + bits=bits@entry=0x896960, last=last@entry=0x7fffffffd470, + pending=pending@entry=0x7fffffffd5f0, seen=seen@entry=0x7fffffffd5e0, + reada=reada@entry=0x7fffffffd600, nodes=0x7fffffffd610, + extent_cache=0x7fffffffd5d0, chunk_cache=0x7fffffffd5c0, dev_cache=0x7fffffffd5b0, + block_group_cache=0x7fffffffd6a0, dev_extent_cache=0x7fffffffd6c0, ri=0x894e20, + bits_nr=1024) at cmds-check.c:5908 +#3 0x000000000042523d in deal_root_from_list (list=list@entry=0x7fffffffd640, + root=root@entry=0x894b20, bits=bits@entry=0x896960, + pending=pending@entry=0x7fffffffd5f0, seen=seen@entry=0x7fffffffd5e0, + reada=reada@entry=0x7fffffffd600, nodes=0x7fffffffd610, + extent_cache=0x7fffffffd5d0, chunk_cache=0x7fffffffd5c0, dev_cache=0x7fffffffd5b0, + block_group_cache=0x7fffffffd6a0, dev_extent_cache=0x7fffffffd6c0, bits_nr=1024) + at cmds-check.c:7838 +#4 0x0000000000425f3d in check_chunks_and_extents (root=root@entry=0x894b20) + at cmds-check.c:8000 +#5 0x0000000000428144 in cmd_check (argc=, argv=) + at cmds-check.c:9431 +#6 0x000000000040e5a2 in main (argc=2, argv=0x7fffffffde90) at btrfs.c:245 diff --git a/tests/fuzz-tests/images/bko-97021-invalid-chunk-sectorsize.raw.xz b/tests/fuzz-tests/images/bko-97021-invalid-chunk-sectorsize.raw.xz new file mode 100644 index 00000000..4e9ff538 Binary files /dev/null and b/tests/fuzz-tests/images/bko-97021-invalid-chunk-sectorsize.raw.xz differ -- cgit v1.2.3 From 7d6307dcf3dbbb5bd9a9aafad77b8393c73b2618 Mon Sep 17 00:00:00 2001 From: David Sterba Date: Sat, 3 Sep 2016 20:52:18 +0200 Subject: btrfs-progs: tests: add fuzzed image for heap overflow while checking chunk items Reported-by: Lukas Lueg Signed-off-by: David Sterba --- .../bko-154961-heap-overflow-chunk-items.raw.txt | 21 +++++++++++++++++++++ .../bko-154961-heap-overflow-chunk-items.raw.xz | Bin 0 -> 3692 bytes 2 files changed, 21 insertions(+) create mode 100644 tests/fuzz-tests/images/bko-154961-heap-overflow-chunk-items.raw.txt create mode 100644 tests/fuzz-tests/images/bko-154961-heap-overflow-chunk-items.raw.xz (limited to 'tests') diff --git a/tests/fuzz-tests/images/bko-154961-heap-overflow-chunk-items.raw.txt b/tests/fuzz-tests/images/bko-154961-heap-overflow-chunk-items.raw.txt new file mode 100644 index 00000000..f41eac60 --- /dev/null +++ b/tests/fuzz-tests/images/bko-154961-heap-overflow-chunk-items.raw.txt @@ -0,0 +1,21 @@ +URL: https://bugzilla.kernel.org/show_bug.cgi?id=154961 +Lukas Lueg 2016-08-27 17:29:35 UTC + +More news from the fuzzer. See the attached image to reproduce using +btrfs-progs btrfs-progs v4.7-42-g56e9586. You may need to compile with ASAN, +could not reproduce without... + + +==2572==ERROR: AddressSanitizer: heap-buffer-overflow on address 0x621000018d86 at pc 0x000000547c3c bp 0x7ffd60ec5ef0 sp 0x7ffd60ec5ee8 +READ of size 8 at 0x621000018d86 thread T0 + #0 0x547c3b in btrfs_stripe_offset /home/lukas/dev/btrfsfuzz/src-asan/./ctree.h:1357:1 + #1 0x5391f7 in btrfs_stripe_offset_nr /home/lukas/dev/btrfsfuzz/src-asan/./ctree.h:1399:9 + #2 0x538790 in btrfs_new_chunk_record /home/lukas/dev/btrfsfuzz/src-asan/cmds-check.c:5209:4 + #3 0x56c55d in process_chunk_item /home/lukas/dev/btrfsfuzz/src-asan/cmds-check.c:5225:8 + #4 0x5634e7 in run_next_block /home/lukas/dev/btrfsfuzz/src-asan/cmds-check.c:6290:5 + #5 0x55c489 in deal_root_from_list /home/lukas/dev/btrfsfuzz/src-asan/cmds-check.c:8338:10 + #6 0x541d53 in check_chunks_and_extents /home/lukas/dev/btrfsfuzz/src-asan/cmds-check.c:8505:8 + #7 0x53d565 in cmd_check /home/lukas/dev/btrfsfuzz/src-asan/cmds-check.c:11430:9 + #8 0x4f105f in main /home/lukas/dev/btrfsfuzz/src-asan/btrfs.c:243:8 + #9 0x7f40dcd8b730 in __libc_start_main (/lib64/libc.so.6+0x20730) + #10 0x421238 in _start (/home/lukas/dev/btrfsfuzz/bin-asan/bin/btrfs+0x421238) diff --git a/tests/fuzz-tests/images/bko-154961-heap-overflow-chunk-items.raw.xz b/tests/fuzz-tests/images/bko-154961-heap-overflow-chunk-items.raw.xz new file mode 100644 index 00000000..dfd01ca2 Binary files /dev/null and b/tests/fuzz-tests/images/bko-154961-heap-overflow-chunk-items.raw.xz differ -- cgit v1.2.3 From c2f3212502210427c5f17e66fbb30ad89826fbd7 Mon Sep 17 00:00:00 2001 From: "Lakshmipathi.G" Date: Mon, 5 Sep 2016 21:27:36 +0200 Subject: btrfs-progs: tests: post btrfs-convert verify permissions and ACLs Signed-off-by: Lakshmipathi.G Signed-off-by: David Sterba --- tests/common.convert | 95 +++++++++++++++++++++++++++++++++++++++++++++++++++- 1 file changed, 94 insertions(+), 1 deletion(-) (limited to 'tests') diff --git a/tests/common.convert b/tests/common.convert index 4e3d49c9..1e00d389 100644 --- a/tests/common.convert +++ b/tests/common.convert @@ -123,6 +123,38 @@ convert_test_gen_checksums() { count=1 >/dev/null 2>&1 run_check_stdout $SUDO_HELPER find $TEST_MNT -type f ! -name 'image' -exec md5sum {} \+ > "$CHECKSUMTMP" } +# list $TEST_MNT data set file permissions. +# $1: path where the permissions will be stored +convert_test_perm() { + local PERMTMP + PERMTMP="$1" + FILES_LIST=$(mktemp --tmpdir btrfs-progs-convert.fileslistXXXXXX) + + run_check $SUDO_HELPER dd if=/dev/zero of=$TEST_MNT/test bs=$nodesize \ + count=1 >/dev/null 2>&1 + run_check_stdout $SUDO_HELPER find $TEST_MNT -type f ! -name 'image' -fprint $FILES_LIST + # Fix directory entries order + sort $FILES_LIST -o $FILES_LIST + for file in `cat $FILES_LIST` ;do + run_check_stdout $SUDO_HELPER getfacl --absolute-names $file >> "$PERMTMP" + done + rm -- $FILES_LIST +} +# list acls of files on $TEST_MNT +# $1: path where the acls will be stored +convert_test_acl() { + local ACLSTMP + ACLTMP="$1" + FILES_LIST=$(mktemp --tmpdir btrfs-progs-convert.fileslistXXXXXX) + + run_check_stdout $SUDO_HELPER find $TEST_MNT/acls -type f -fprint $FILES_LIST + # Fix directory entries order + sort $FILES_LIST -o $FILES_LIST + for file in `cat $FILES_LIST`;do + run_check_stdout $SUDO_HELPER getfattr --absolute-names -d $file >> "$ACLTMP" + done + rm -- $FILES_LIST +} # do conversion with given features and nodesize, fsck afterwards # $1: features, argument of -O, can be empty @@ -133,15 +165,68 @@ convert_test_do_convert() { run_check $TOP/btrfs-show-super -Ffa $TEST_DEV } +# post conversion check, verify file permissions. +# $1: file with ext permissions. +convert_test_post_check_permissions() { + local EXT_PERMTMP + local BTRFS_PERMTMP + + EXT_PERMTMP="$1" + BTRFS_PERMTMP=$(mktemp --tmpdir btrfs-progs-convert.permXXXXXX) + convert_test_perm "$BTRFS_PERMTMP" + + btrfs_perm=`md5sum $BTRFS_PERMTMP | cut -f1 -d' '` + ext_perm=`md5sum $EXT_PERMTMP | cut -f1 -d' '` + + if [ "$btrfs_perm" != "$ext_perm" ]; + then + btrfs_perm_file=`md5sum $BTRFS_PERMTMP | cut -f2 -d' '` + ext_perm_file=`md5sum $EXT_PERMTMP | cut -f2 -d' '` + _fail "file permission failed. Mismatched BTRFS:$btrfs_perm_file:$btrfs_perm EXT:$ext_perm_file:$ext_perm" + fi + + rm -- $BTRFS_PERMTMP +} +# post conversion check, compare BTRFS file acls against EXT. +# $1: file with ext acls. +convert_test_post_check_acl() { + local EXT_ACLTMP + local BTRFS_ACLTMP + + EXT_ACLTMP="$1" + BTRFS_ACLTMP=$(mktemp --tmpdir btrfs-progs-convert.aclsXXXXXXX) + convert_test_acl "$BTRFS_ACLTMP" + + btrfs_acl=`md5sum $BTRFS_ACLTMP | cut -f1 -d' '` + ext_acl=`md5sum $EXT_ACLTMP | cut -f1 -d' '` + + if [ "$btrfs_acl" != "$ext_acl" ] + then + btrfs_acl_file=`md5sum $BTRFS_ACLTMP | cut -f2 -d' '` + ext_acl_file=`md5sum $EXT_ACLTMP | cut -f2 -d' '` + _fail "file acl failed. Mismatched BTRFS:$btrfs_acl_file:$btrfs_acl EXT:$ext_acl_file:$ext_acl" + fi + + rm -- $BTRFS_ACLTMP +} # post conversion checks, verify md5sums # $1: file with checksums +# $2: file with permissions. +# $3: file with acl entries. convert_test_post_check() { local CHECKSUMTMP + local EXT_PERMTMP + local EXT_ACLTMP + CHECKSUMTMP="$1" + EXT_PERMTMP="$2" + EXT_ACLTMP="$3" run_check_mount_test_dev run_check_stdout $SUDO_HELPER md5sum -c "$CHECKSUMTMP" | grep -q 'FAILED' && _fail "file validation failed" + convert_test_post_check_permissions "$EXT_PERMTMP" + convert_test_post_check_acl "$EXT_ACLTMP" run_check_umount_test_dev } @@ -161,6 +246,8 @@ convert_test() { local nodesize local msg local CHECKSUMTMP + local EXT_PERMTMP + local EXT_ACLTMP features="$1" msg="$2" @@ -170,13 +257,19 @@ convert_test() { convert_test_prep_fs "$@" populate_fs CHECKSUMTMP=$(mktemp --tmpdir btrfs-progs-convert.XXXXXXXXXX) + EXT_PERMTMP=$(mktemp --tmpdir btrfs-progs-convert.permXXXXXX) + EXT_ACLTMP=$(mktemp --tmpdir btrfs-progs-convert.aclsXXXXXXX) convert_test_gen_checksums "$CHECKSUMTMP" + convert_test_perm "$EXT_PERMTMP" + convert_test_acl "$EXT_ACLTMP" run_check_umount_test_dev convert_test_do_convert "$features" "$nodesize" - convert_test_post_check "$CHECKSUMTMP" + convert_test_post_check "$CHECKSUMTMP" "$EXT_PERMTMP" "$EXT_ACLTMP" rm $CHECKSUMTMP + rm $EXT_PERMTMP + rm $EXT_ACLTMP convert_test_post_rollback } -- cgit v1.2.3 From 05b6d8b187dba66d92d2d7d7f48ca26090c1aac8 Mon Sep 17 00:00:00 2001 From: David Sterba Date: Thu, 8 Sep 2016 14:12:25 +0200 Subject: btrfs-progs: tests: add fuzzed image for a bad backref Reported-by: Lukas Lueg Signed-off-by: David Sterba --- .../images/bko-155181-bad-backref.raw.txt | 22 +++++++++++++++++++++ .../images/bko-155181-bad-backref.raw.xz | Bin 0 -> 3684 bytes 2 files changed, 22 insertions(+) create mode 100644 tests/fuzz-tests/images/bko-155181-bad-backref.raw.txt create mode 100644 tests/fuzz-tests/images/bko-155181-bad-backref.raw.xz (limited to 'tests') diff --git a/tests/fuzz-tests/images/bko-155181-bad-backref.raw.txt b/tests/fuzz-tests/images/bko-155181-bad-backref.raw.txt new file mode 100644 index 00000000..440641e9 --- /dev/null +++ b/tests/fuzz-tests/images/bko-155181-bad-backref.raw.txt @@ -0,0 +1,22 @@ +ULR: https://bugzilla.kernel.org/show_bug.cgi?id=155181 +Lukas Lueg 2016-08-28 10:52:32 UTC + +More news from the fuzzer. The attached image causes btrfsck to reach abort() +in in cmds-check.c:add_tree_backref(); using btrfs-progs v4.7-42-g56e9586. + +[Thread debugging using libthread_db enabled] +Using host libthread_db library "/lib64/libthread_db.so.1". +Checking filesystem on crash2.bin +UUID: 5cb33553-6f6d-4ce8-83fd-20af5a2f8181 + +Program received signal SIGABRT, Aborted. +0x00007ffff6fae6f5 in raise () from /lib64/libc.so.6 +#0 0x00007ffff6fae6f5 in raise () from /lib64/libc.so.6 +#1 0x00007ffff6fb02fa in abort () from /lib64/libc.so.6 +#2 0x000000000041fbe1 in add_tree_backref (extent_cache=extent_cache@entry=0x7fffffffdd20, bytenr=bytenr@entry=131200, parent=parent@entry=0, root=3, found_ref=found_ref@entry=0) at cmds-check.c:4869 +#3 0x0000000000423538 in process_extent_item (root=root@entry=0x6b2cf0, extent_cache=extent_cache@entry=0x7fffffffdd20, eb=eb@entry=0x6af7c0, slot=slot@entry=1) at cmds-check.c:5452 +#4 0x000000000042a605 in run_next_block (root=root@entry=0x6b2cf0, bits=bits@entry=0x6b4ff0, bits_nr=bits_nr@entry=1024, last=last@entry=0x7fffffffd878, pending=pending@entry=0x7fffffffdd00, seen=seen@entry=0x7fffffffdd10, reada=0x7fffffffdcf0, nodes=0x7fffffffdce0, extent_cache=0x7fffffffdd20, chunk_cache=0x7fffffffdd80, dev_cache=0x7fffffffdd90, block_group_cache=0x7fffffffdd60, dev_extent_cache=0x7fffffffdd30, ri=0x6b9000) at cmds-check.c:6280 +#5 0x000000000042afb6 in deal_root_from_list (list=list@entry=0x7fffffffda10, root=root@entry=0x6b2cf0, bits=bits@entry=0x6b4ff0, bits_nr=bits_nr@entry=1024, pending=pending@entry=0x7fffffffdd00, seen=seen@entry=0x7fffffffdd10, reada=0x7fffffffdcf0, nodes=0x7fffffffdce0, extent_cache=0x7fffffffdd20, chunk_cache=0x7fffffffdd80, dev_cache=0x7fffffffdd90, block_group_cache=0x7fffffffdd60, dev_extent_cache=0x7fffffffdd30) at cmds-check.c:8338 +#6 0x000000000042bb15 in check_chunks_and_extents (root=root@entry=0x6b2cf0) at cmds-check.c:8505 +#7 0x000000000042e3cb in cmd_check (argc=, argv=) at cmds-check.c:11430 +#8 0x000000000040a416 in main (argc=2, argv=0x7fffffffe218) at btrfs.c:243 diff --git a/tests/fuzz-tests/images/bko-155181-bad-backref.raw.xz b/tests/fuzz-tests/images/bko-155181-bad-backref.raw.xz new file mode 100644 index 00000000..ff5fe859 Binary files /dev/null and b/tests/fuzz-tests/images/bko-155181-bad-backref.raw.xz differ -- cgit v1.2.3 From 9fc5aefe458d2a5ad2f24759d094228aee40e27a Mon Sep 17 00:00:00 2001 From: David Sterba Date: Thu, 8 Sep 2016 17:57:02 +0200 Subject: btrfs-progs: tests: rename test 001 to mention check Make it more clear that the test does 'btrfs check'. Signed-off-by: David Sterba --- tests/fuzz-tests/001-simple-check-unmounted/test.sh | 20 ++++++++++++++++++++ tests/fuzz-tests/001-simple-unmounted/test.sh | 20 -------------------- 2 files changed, 20 insertions(+), 20 deletions(-) create mode 100755 tests/fuzz-tests/001-simple-check-unmounted/test.sh delete mode 100755 tests/fuzz-tests/001-simple-unmounted/test.sh (limited to 'tests') diff --git a/tests/fuzz-tests/001-simple-check-unmounted/test.sh b/tests/fuzz-tests/001-simple-check-unmounted/test.sh new file mode 100755 index 00000000..98fe7b0c --- /dev/null +++ b/tests/fuzz-tests/001-simple-check-unmounted/test.sh @@ -0,0 +1,20 @@ +#!/bin/bash + +# iterate over all fuzzed images and run 'btrfs check' + +source $TOP/tests/common + +setup_root_helper +check_prereq btrfs + +# redefine the one provided by common +check_image() { + local image + + image=$1 + run_mayfail $TOP/btrfs check "$image" +} + +check_all_images $TOP/tests/fuzz-tests/images + +exit 0 diff --git a/tests/fuzz-tests/001-simple-unmounted/test.sh b/tests/fuzz-tests/001-simple-unmounted/test.sh deleted file mode 100755 index 98fe7b0c..00000000 --- a/tests/fuzz-tests/001-simple-unmounted/test.sh +++ /dev/null @@ -1,20 +0,0 @@ -#!/bin/bash - -# iterate over all fuzzed images and run 'btrfs check' - -source $TOP/tests/common - -setup_root_helper -check_prereq btrfs - -# redefine the one provided by common -check_image() { - local image - - image=$1 - run_mayfail $TOP/btrfs check "$image" -} - -check_all_images $TOP/tests/fuzz-tests/images - -exit 0 -- cgit v1.2.3 From faaeee5bf3d260b2c011c42a208cffea2e2e1ea5 Mon Sep 17 00:00:00 2001 From: David Sterba Date: Thu, 8 Sep 2016 18:06:44 +0200 Subject: btrfs-progs: tests: add fuzz test to try btrfs-image on all images Signed-off-by: David Sterba --- tests/fuzz-tests/002-simple-image/test.sh | 24 ++++++++++++++++++++++++ 1 file changed, 24 insertions(+) create mode 100755 tests/fuzz-tests/002-simple-image/test.sh (limited to 'tests') diff --git a/tests/fuzz-tests/002-simple-image/test.sh b/tests/fuzz-tests/002-simple-image/test.sh new file mode 100755 index 00000000..42470ecc --- /dev/null +++ b/tests/fuzz-tests/002-simple-image/test.sh @@ -0,0 +1,24 @@ +#!/bin/bash + +# iterate over all fuzzed images and run 'btrfs-image' + +source $TOP/tests/common + +setup_root_helper +check_prereq btrfs-image + +# redefine the one provided by common +check_image() { + local image + + image=$1 + truncate -s0 target + run_mayfail $TOP/btrfs-image "$image" target + truncate -s0 target +} + +check_all_images $TOP/tests/fuzz-tests/images + +rm -- target + +exit 0 -- cgit v1.2.3 From 5150103fcf97d14ecfd132fc257d2acea5eb12f3 Mon Sep 17 00:00:00 2001 From: David Sterba Date: Thu, 8 Sep 2016 18:17:48 +0200 Subject: btrfs-progs: tests: run check with various options on the fuzzed images Signed-off-by: David Sterba --- tests/fuzz-tests/003-multi-check-unmounted/test.sh | 26 ++++++++++++++++++++++ 1 file changed, 26 insertions(+) create mode 100755 tests/fuzz-tests/003-multi-check-unmounted/test.sh (limited to 'tests') diff --git a/tests/fuzz-tests/003-multi-check-unmounted/test.sh b/tests/fuzz-tests/003-multi-check-unmounted/test.sh new file mode 100755 index 00000000..9fd7b8aa --- /dev/null +++ b/tests/fuzz-tests/003-multi-check-unmounted/test.sh @@ -0,0 +1,26 @@ +#!/bin/bash + +# iterate over all fuzzed images and run 'btrfs check', try various options to +# get more code coverage + +source $TOP/tests/common + +setup_root_helper +check_prereq btrfs + +# redefine the one provided by common +check_image() { + local image + + image=$1 + run_mayfail $TOP/btrfs check -s 1 "$image" + run_mayfail $TOP/btrfs check --init-csum-tree "$image" + run_mayfail $TOP/btrfs check --init-extent-tree "$image" + run_mayfail $TOP/btrfs check --check-data-csum "$image" + run_mayfail $TOP/btrfs check --subvol-extents "$image" + run_mayfail $TOP/btrfs check --repair "$image" +} + +check_all_images $TOP/tests/fuzz-tests/images + +exit 0 -- cgit v1.2.3 From 2125a655332990ce8c3b9c9e17a71b3830d771cb Mon Sep 17 00:00:00 2001 From: David Sterba Date: Fri, 9 Sep 2016 15:33:20 +0200 Subject: btrfs-progs: tests: add fuzzed images for bad block group offset Reported-by: Lukas Lueg Signed-off-by: David Sterba --- .../bko-155151-bad-block-group-offset.raw.txt | 5 +++++ .../bko-155151-bad-block-group-offset.raw.xz | Bin 0 -> 3676 bytes .../bko-155621-bad-block-group-offset.raw.txt | 25 +++++++++++++++++++++ .../bko-155621-bad-block-group-offset.raw.xz | Bin 0 -> 3712 bytes 4 files changed, 30 insertions(+) create mode 100644 tests/fuzz-tests/images/bko-155151-bad-block-group-offset.raw.txt create mode 100644 tests/fuzz-tests/images/bko-155151-bad-block-group-offset.raw.xz create mode 100644 tests/fuzz-tests/images/bko-155621-bad-block-group-offset.raw.txt create mode 100644 tests/fuzz-tests/images/bko-155621-bad-block-group-offset.raw.xz (limited to 'tests') diff --git a/tests/fuzz-tests/images/bko-155151-bad-block-group-offset.raw.txt b/tests/fuzz-tests/images/bko-155151-bad-block-group-offset.raw.txt new file mode 100644 index 00000000..4971f13e --- /dev/null +++ b/tests/fuzz-tests/images/bko-155151-bad-block-group-offset.raw.txt @@ -0,0 +1,5 @@ +URL: https://bugzilla.kernel.org/show_bug.cgi?id=155151 +Lukas Lueg 2016-08-27 20:19:24 UTC + +More news from the fuzzer. The attached image causes btrfsck to enter what +seems to be an endless loop; using btrfs-progs v4.7-42-g56e9586. diff --git a/tests/fuzz-tests/images/bko-155151-bad-block-group-offset.raw.xz b/tests/fuzz-tests/images/bko-155151-bad-block-group-offset.raw.xz new file mode 100644 index 00000000..377b4d80 Binary files /dev/null and b/tests/fuzz-tests/images/bko-155151-bad-block-group-offset.raw.xz differ diff --git a/tests/fuzz-tests/images/bko-155621-bad-block-group-offset.raw.txt b/tests/fuzz-tests/images/bko-155621-bad-block-group-offset.raw.txt new file mode 100644 index 00000000..e28d73fc --- /dev/null +++ b/tests/fuzz-tests/images/bko-155621-bad-block-group-offset.raw.txt @@ -0,0 +1,25 @@ +URL: https://bugzilla.kernel.org/show_bug.cgi?id=155621 +Lukas Lueg 2016-08-30 16:07:36 UTC + +More news from the fuzzer. The attached image causes btrfsck to enter what +seems to be an endless loop; using btrfs-progs v4.7-42-g56e9586. + +Starting program: /home/lukas/dev/btrfsfuzz/bin/bin/btrfsck hang17.img +[Thread debugging using libthread_db enabled] +Using host libthread_db library "/lib64/libthread_db.so.1". + +Program received signal SIGINT, Interrupt. +__find_space_info (info=info@entry=0x6ab3a0, flags=0, flags@entry=8589934592) at extent-tree.c:1796 +1796 list_for_each_entry(found, &info->space_info, list) { +#0 __find_space_info (info=info@entry=0x6ab3a0, flags=0, flags@entry=8589934592) at extent-tree.c:1796 +#1 0x000000000044c66d in update_space_info (info=info@entry=0x6ab3a0, flags=8589934592, total_bytes=total_bytes@entry=0, bytes_used=17592186044416, space_info=space_info@entry=0x7fffffffdbd8) + at extent-tree.c:1835 +#2 0x0000000000451622 in btrfs_read_block_groups (root=0x6ab850) at extent-tree.c:3278 +#3 0x000000000044b157 in btrfs_setup_all_roots (fs_info=fs_info@entry=0x6ab3a0, root_tree_bytenr=, root_tree_bytenr@entry=0, flags=flags@entry=64) at disk-io.c:1055 +#4 0x000000000044b484 in __open_ctree_fd (fp=fp@entry=3, path=path@entry=0x7fffffffe4eb "hang17.img", sb_bytenr=65536, sb_bytenr@entry=0, root_tree_bytenr=root_tree_bytenr@entry=0, + chunk_root_bytenr=chunk_root_bytenr@entry=0, flags=flags@entry=64) at disk-io.c:1317 +#5 0x000000000044b611 in open_ctree_fs_info (filename=0x7fffffffe4eb "hang17.img", sb_bytenr=sb_bytenr@entry=0, root_tree_bytenr=root_tree_bytenr@entry=0, chunk_root_bytenr=chunk_root_bytenr@entry=0, + flags=64) at disk-io.c:1363 +#6 0x000000000042deca in cmd_check (argc=, argv=0x7fffffffe218) at cmds-check.c:11320 +#7 0x000000000040a416 in main (argc=2, argv=0x7fffffffe218) at btrfs.c:243 +quit diff --git a/tests/fuzz-tests/images/bko-155621-bad-block-group-offset.raw.xz b/tests/fuzz-tests/images/bko-155621-bad-block-group-offset.raw.xz new file mode 100644 index 00000000..2456780d Binary files /dev/null and b/tests/fuzz-tests/images/bko-155621-bad-block-group-offset.raw.xz differ -- cgit v1.2.3 From f9309584bf9c58054d588077ba51d8123df54571 Mon Sep 17 00:00:00 2001 From: Wang Xiaoguang Date: Thu, 25 Aug 2016 13:21:01 +0800 Subject: btrfs-progs: tests: add 021-partially-dropped-snapshot-case Signed-off-by: Wang Xiaoguang Signed-off-by: David Sterba --- .../dropped-snapshot.img | Bin 0 -> 24576 bytes .../021-partially-dropped-snapshot-case/test.sh | 18 ++++++++++++++++++ 2 files changed, 18 insertions(+) create mode 100644 tests/fsck-tests/021-partially-dropped-snapshot-case/dropped-snapshot.img create mode 100755 tests/fsck-tests/021-partially-dropped-snapshot-case/test.sh (limited to 'tests') diff --git a/tests/fsck-tests/021-partially-dropped-snapshot-case/dropped-snapshot.img b/tests/fsck-tests/021-partially-dropped-snapshot-case/dropped-snapshot.img new file mode 100644 index 00000000..345ef419 Binary files /dev/null and b/tests/fsck-tests/021-partially-dropped-snapshot-case/dropped-snapshot.img differ diff --git a/tests/fsck-tests/021-partially-dropped-snapshot-case/test.sh b/tests/fsck-tests/021-partially-dropped-snapshot-case/test.sh new file mode 100755 index 00000000..eb8d8849 --- /dev/null +++ b/tests/fsck-tests/021-partially-dropped-snapshot-case/test.sh @@ -0,0 +1,18 @@ +#!/bin/bash +# confirm whether btrfsck supports to check a partially dropped snapshot + +source $TOP/tests/common + +check_prereq btrfs + +for img in *.img +do + image=$(extract_image $img) + run_check_stdout $TOP/btrfs check "$image" 2>&1 | + grep -q "Errors found in extent allocation tree or chunk allocation" + if [ $? -eq 0 ]; then + rm -f "$image" + _fail "unexpected error occurred when checking $img" + fi + rm -f "$image" +done -- cgit v1.2.3 From da64ae3a0f7498e356a72e7f1b65a704ddfbb6bc Mon Sep 17 00:00:00 2001 From: David Sterba Date: Mon, 12 Sep 2016 11:13:24 +0200 Subject: btrfs-progs: reorganize extent_buffer and fix alignment of data Reported by UBSAN, the checksum code tries to access unaligned data that come from the extent_buffer. struct extent_buffer { struct cache_extent cache_node; /* 0 48 */ u64 start; /* 48 8 */ u64 dev_bytenr; /* 56 8 */ /* --- cacheline 1 boundary (64 bytes) --- */ u32 len; /* 64 4 */ /* XXX 4 bytes hole, try to pack */ struct extent_io_tree * tree; /* 72 8 */ struct list_head lru; /* 80 16 */ struct list_head recow; /* 96 16 */ int refs; /* 112 4 */ u32 flags; /* 116 4 */ int fd; /* 120 4 */ char data[0]; /* 124 0 */ /* size: 128, cachelines: 2, members: 11 */ /* sum members: 120, holes: 1, sum holes: 4 */ /* padding: 4 */ }; Add explicit alignment to data. Reported-by: Lukas Lueg Bugzilla: https://bugzilla.kernel.org/show_bug.cgi?id=156471 Signed-off-by: David Sterba --- ...o-156471-ubsan-trigger-crc32c-unaligned.raw.txt | 62 +++++++++++++++++++++ ...ko-156471-ubsan-trigger-crc32c-unaligned.raw.xz | Bin 0 -> 3764 bytes 2 files changed, 62 insertions(+) create mode 100644 tests/fuzz-tests/images/bko-156471-ubsan-trigger-crc32c-unaligned.raw.txt create mode 100644 tests/fuzz-tests/images/bko-156471-ubsan-trigger-crc32c-unaligned.raw.xz (limited to 'tests') diff --git a/tests/fuzz-tests/images/bko-156471-ubsan-trigger-crc32c-unaligned.raw.txt b/tests/fuzz-tests/images/bko-156471-ubsan-trigger-crc32c-unaligned.raw.txt new file mode 100644 index 00000000..c8279633 --- /dev/null +++ b/tests/fuzz-tests/images/bko-156471-ubsan-trigger-crc32c-unaligned.raw.txt @@ -0,0 +1,62 @@ +URL: https://bugzilla.kernel.org/show_bug.cgi?id=156471 +Lukas Lueg 2016-09-09 18:58:27 UTC + +More news from the fuzzer and (up to now) the only news from UBSAN using +btrfs-progs v4.7-42-g56e9586. The attached image causes btrfsck to trigger +undefined behavior by dereferencing a ptr to a long unsigned int that was cast +from an uchar with no alignment guarantees. + +UBSAN complains: +crc32c.c:75:19: runtime error: load of misaligned address 0x000001b3736c for +type 'long unsigned int', which requires 8 byte alignment + +I've attached an image and a log, the behavior is triggered all the time and +unspecific, though. + +AFAIC the problem is that *ptmp is cast from *data. This may actually not cause +the CPU to fault due to how *data is de-facto aligned by it's callers. The code +may still cause nose demons as the pure act of having *ptmp is undefined +behavior. + +crc32c.c:75:19: runtime error: load of misaligned address 0x000001b3736c for type 'long unsigned int', which requires 8 byte alignment +0x000001b3736c: note: pointer points here + 00 00 00 00 b7 0e 65 6c 64 61 40 4b a5 0d 0f ba 33 0c 75 27 00 00 02 00 00 00 00 00 01 00 00 00 + ^ + #0 0x4f4308 in crc32c_intel /home/lukas/dev/btrfsfuzz/src-ubsan/crc32c.c:75 + #1 0x4f43f3 in crc32c_le /home/lukas/dev/btrfsfuzz/src-ubsan/crc32c.c:221 + #2 0x486c39 in __csum_tree_block_size /home/lukas/dev/btrfsfuzz/src-ubsan/disk-io.c:139 + #3 0x486c39 in csum_tree_block_size /home/lukas/dev/btrfsfuzz/src-ubsan/disk-io.c:159 + #4 0x486d48 in csum_tree_block_fs_info /home/lukas/dev/btrfsfuzz/src-ubsan/disk-io.c:174 + #5 0x48ba29 in read_tree_block_fs_info /home/lukas/dev/btrfsfuzz/src-ubsan/disk-io.c:348 + #6 0x48d48d in read_tree_block /home/lukas/dev/btrfsfuzz/src-ubsan/disk-io.h:112 + #7 0x48d48d in btrfs_setup_chunk_tree_and_device_map /home/lukas/dev/btrfsfuzz/src-ubsan/disk-io.c:1210 + #8 0x48d95b in __open_ctree_fd /home/lukas/dev/btrfsfuzz/src-ubsan/disk-io.c:1322 + #9 0x48dd80 in open_ctree_fs_info /home/lukas/dev/btrfsfuzz/src-ubsan/disk-io.c:1381 + #10 0x45011a in cmd_check /home/lukas/dev/btrfsfuzz/src-ubsan/cmds-check.c:11449 + #11 0x40a799 in main /home/lukas/dev/btrfsfuzz/src-ubsan/btrfs.c:243 + #12 0x7fdf11c96730 in __libc_start_main (/lib64/libc.so.6+0x20730) + #13 0x40a1e8 in _start (/home/lukas/dev/btrfsfuzz/bin-ubsan/bin/btrfs+0x40a1e8) + +key (3472328296227680304 INODE_EXTREF 3472328296227680304)slot end outside of leaf 12360 > 3995 +parent transid verify failed on 4227072 wanted 3472328296227680304 found 4 +Ignoring transid failure +checking extents +Checking filesystem on ubsan_logs/id:000990,src:000816,op:flip1,pos:3845.img +UUID: b70e656c-6461-404b-a50d-0fba330c7527 +key (3472328296227680304 INODE_EXTREF 3472328296227680304)slot end outside of leaf 12360 > 3995 +Invalid key type(ROOT_ITEM) found in root(3472328296227680304) +ignoring invalid key +Invalid key type(ROOT_ITEM) found in root(3472328296227680304) +ignoring invalid key +Invalid key type(ROOT_ITEM) found in root(3472328296227680304) +ignoring invalid key +Invalid key type(ROOT_ITEM) found in root(3472328296227680304) +ignoring invalid key +key (3472328296227680304 INODE_EXTREF 3472328296227680304)slot end outside of leaf 12360 > 3995 +key (3472328296227680304 INODE_EXTREF 3472328296227680304)slot end outside of leaf 12360 > 3995 +key (3472328296227680304 INODE_EXTREF 3472328296227680304)slot end outside of leaf 12360 > 3995 +key (3472328296227680304 INODE_EXTREF 3472328296227680304)slot end outside of leaf 12360 > 3995 +key (3472328296227680304 INODE_EXTREF 3472328296227680304)slot end outside of leaf 12360 > 3995 +bad block 4202496 +Errors found in extent allocation tree or chunk allocation +key (3472328296227680304 INODE_EXTREF 3472328296227680304)slot end outside of leaf 12360 > 3995 diff --git a/tests/fuzz-tests/images/bko-156471-ubsan-trigger-crc32c-unaligned.raw.xz b/tests/fuzz-tests/images/bko-156471-ubsan-trigger-crc32c-unaligned.raw.xz new file mode 100644 index 00000000..ee5778a5 Binary files /dev/null and b/tests/fuzz-tests/images/bko-156471-ubsan-trigger-crc32c-unaligned.raw.xz differ -- cgit v1.2.3 From 5a38a52194221743e071d819ea3c026f2c7de4b8 Mon Sep 17 00:00:00 2001 From: David Sterba Date: Fri, 23 Sep 2016 15:38:04 +0200 Subject: btrfs-progs: tests: iterate over fuzzed images and test various tools Signed-off-by: David Sterba --- tests/fuzz-tests/004-misc-dumps/test.sh | 31 +++++++++++++++++++++++++++++++ 1 file changed, 31 insertions(+) create mode 100755 tests/fuzz-tests/004-misc-dumps/test.sh (limited to 'tests') diff --git a/tests/fuzz-tests/004-misc-dumps/test.sh b/tests/fuzz-tests/004-misc-dumps/test.sh new file mode 100755 index 00000000..3fae2f65 --- /dev/null +++ b/tests/fuzz-tests/004-misc-dumps/test.sh @@ -0,0 +1,31 @@ +#!/bin/bash + +# iterate over all fuzzed images and run various tools, do not expect to repair +# or dump succesfully, must not crash at least + +source $TOP/tests/common + +setup_root_helper +check_prereq btrfs + +# redefine the one provided by common +check_image() { + local image + + image=$1 + run_mayfail $TOP/btrfs inspect-internal dump-tree "$image" + run_mayfail $TOP/btrfs inspect-internal dump-super "$image" + run_mayfail $TOP/btrfs inspect-internal dump-super -Ffa "$image" + run_mayfail $TOP/btrfs inspect-internal tree-stats "$image" + run_check cp "$image" "$image".scratch + run_mayfail $TOP/btrfs rescue super-recover -y -v "$image".scratch + run_check cp "$image" "$image".scratch + run_mayfail $TOP/btrfs rescue chunk-recover -y -v "$image".scratch + run_check cp "$image" "$image".scratch + run_mayfail $TOP/btrfs rescue zero-log "$image".scratch + rm -- "$image".scratch +} + +check_all_images $TOP/tests/fuzz-tests/images + +exit 0 -- cgit v1.2.3 From 8d8de7c2e59e31def84e04d49e2ec09aeb1f07cd Mon Sep 17 00:00:00 2001 From: David Sterba Date: Fri, 23 Sep 2016 15:51:28 +0200 Subject: btrfs-progs: tests: add script to scan results for some known runtime errors Signed-off-by: David Sterba --- tests/scan-results.sh | 16 ++++++++++++++++ 1 file changed, 16 insertions(+) create mode 100755 tests/scan-results.sh (limited to 'tests') diff --git a/tests/scan-results.sh b/tests/scan-results.sh new file mode 100755 index 00000000..743b968b --- /dev/null +++ b/tests/scan-results.sh @@ -0,0 +1,16 @@ +#!/bin/sh + +# look for some error messages in all test logs + +for i in *.txt; do + echo "Scanning $i" + last= + while read line; do + case "$line" in + ===\ Entering*) last="$line" ;; + *Assertion*failed*) echo "ASSERTION FAILED: $last" ;; + *runtime\ error*) echo "RUNTIME ERROR (sanitizer): $last" ;; + *) : ;; + esac + done < "$i" +done -- cgit v1.2.3 From 801f15bdf1598a75f20d1c07d3e0640d37499165 Mon Sep 17 00:00:00 2001 From: David Sterba Date: Fri, 30 Sep 2016 16:23:05 +0200 Subject: btrfs-progs: tests: add fuzzed images with bad blocksize/lengh of eb Signed-off-by: David Sterba --- .../images/bko-166361-blocksize-zero.raw.txt | 93 +++++++++++++++ .../images/bko-166361-blocksize-zero.raw.xz | Bin 0 -> 3840 bytes ...bko-169311-blocksize-zero-qgroup-verify.raw.txt | 126 +++++++++++++++++++++ .../bko-169311-blocksize-zero-qgroup-verify.raw.xz | Bin 0 -> 3800 bytes 4 files changed, 219 insertions(+) create mode 100644 tests/fuzz-tests/images/bko-166361-blocksize-zero.raw.txt create mode 100644 tests/fuzz-tests/images/bko-166361-blocksize-zero.raw.xz create mode 100644 tests/fuzz-tests/images/bko-169311-blocksize-zero-qgroup-verify.raw.txt create mode 100644 tests/fuzz-tests/images/bko-169311-blocksize-zero-qgroup-verify.raw.xz (limited to 'tests') diff --git a/tests/fuzz-tests/images/bko-166361-blocksize-zero.raw.txt b/tests/fuzz-tests/images/bko-166361-blocksize-zero.raw.txt new file mode 100644 index 00000000..bca52969 --- /dev/null +++ b/tests/fuzz-tests/images/bko-166361-blocksize-zero.raw.txt @@ -0,0 +1,93 @@ +URL: https://bugzilla.kernel.org/show_bug.cgi?id=166361 +Lukas Lueg 2016-09-17 16:45:53 UTC + +More news from the fuzzer. The attached image causes a segmentation fault when +running btrfsck over it; using btrfs-progs v4.7.1-17-g2076992 + +The juicy parts: + +==30530==ERROR: AddressSanitizer: SEGV on unknown address 0x62103031ae21 (pc 0x0000005f19b9 bp 0x7ffd4aa30a90 sp 0x7ffd4aa30a90 T0) + #0 0x5f19b8 in btrfs_qgroup_status_flags /home/lukas/dev/btrfsfuzz/src-asan/./ctree.h:2136:1 + #1 0x5f16f5 in read_qgroup_status /home/lukas/dev/btrfsfuzz/src-asan/qgroup-verify.c:885:10 + #2 0x5ef38a in load_quota_info /home/lukas/dev/btrfsfuzz/src-asan/qgroup-verify.c:949:5 + #3 0x5eeefc in qgroup_verify_all /home/lukas/dev/btrfsfuzz/src-asan/qgroup-verify.c:1351:8 + #4 0x51f08f in cmd_check /home/lukas/dev/btrfsfuzz/src-asan/cmds-check.c:11637:9 + #5 0x4f0f81 in main /home/lukas/dev/btrfsfuzz/src-asan/btrfs.c:243:8 + #6 0x7f7eb11aa730 in __libc_start_main (/lib64/libc.so.6+0x20730) + #7 0x4213f8 in _start (/home/lukas/dev/btrfsfuzz/bin-asan/bin/btrfs+0x4213f8) + +parent transid verify failed on 4198400 wanted 4 found 5 +Ignoring transid failure +parent transid verify failed on 0 wanted 3472328296227680304 found 0 +parent transid verify failed on 0 wanted 3472328296227680304 found 0 +Ignoring transid failure +parent transid verify failed on 4198400 wanted 26388280060160 found 5 +Ignoring transid failure +parent transid verify failed on 0 wanted 3472328296227680304 found 0 +Ignoring transid failure +checking extents +parent transid verify failed on 0 wanted 3472328296227680304 found 0 +Ignoring transid failure +parent transid verify failed on 0 wanted 3472328296227680304 found 0 +Ignoring transid failure +parent transid verify failed on 0 wanted 3472328296227680304 found 0 +Ignoring transid failure +parent transid verify failed on 0 wanted 3472328296227680304 found 0 +Ignoring transid failure +parent transid verify failed on 0 wanted 3472328296227680304 found 0 +Ignoring transid failure +parent transid verify failed on 0 wanted 3472328296227680304 found 0 +Ignoring transid failure +parent transid verify failed on 0 wanted 3472328296227680304 found 0 +Ignoring transid failure +parent transid verify failed on 0 wanted 3472328296227680304 found 0 +Ignoring transid failure +Chunk[256, 228, 0]: length(4194304), offset(0), type(2) is not found in block group +Chunk[256, 228, 0] stripe[1, 0] is not found in dev extent +Chunk[256, 228, 4194304]: length(1638400), offset(4194304), type(5) is not found in block group +Chunk[256, 228, 4194304] stripe[1, 4194304] is not found in dev extent +Chunk[256, 228, 5832704]: length(1638400), offset(5832704), type(5) is not found in block group +Chunk[256, 228, 5832704] stripe[1, 5832704] is not found in dev extent +ref mismatch on [0 4096] extent item 0, found 1 +Backref 0 parent 0 root 0 not found in extent tree +backpointer mismatch on [0 4096] +ref mismatch on [131072 4096] extent item 0, found 1 +Backref 131072 parent 3 root 3 not found in extent tree +backpointer mismatch on [131072 4096] +ref mismatch on [4198400 4096] extent item 0, found 1 +Backref 4198400 parent 1 root 1 not found in extent tree +backpointer mismatch on [4198400 4096] +ref mismatch on [4231168 4096] extent item 0, found 1 +Backref 4231168 parent 7 root 7 not found in extent tree +backpointer mismatch on [4231168 4096] +ref mismatch on [3472328296227680304 3472328296227680304] extent item 0, found 1 +Backref 3472328296227680304 root 1 owner 2 offset 0 num_refs 0 not found in extent tree +Incorrect local backref count on 3472328296227680304 root 1 owner 2 offset 0 found 1 wanted 0 back 0x60800000bda0 +backpointer mismatch on [3472328296227680304 3472328296227680304] +Dev extent's total-byte(0) is not equal to byte-used(7471104) in dev[1, 216, 1] +Errors found in extent allocation tree or chunk allocation +parent transid verify failed on 0 wanted 3472328296227680304 found 0 +Ignoring transid failure +parent transid verify failed on 4198400 wanted 26388280060160 found 5 +Ignoring transid failure +checking free space cache +checking fs roots +root 5 root dir 3472328296227680304 not found +checking csums +checking root refs +checking quota groups +ASAN:DEADLYSIGNAL +================================================================= +==30530==ERROR: AddressSanitizer: SEGV on unknown address 0x62103031ae21 (pc 0x0000005f19b9 bp 0x7ffd4aa30a90 sp 0x7ffd4aa30a90 T0) + #0 0x5f19b8 in btrfs_qgroup_status_flags /home/lukas/dev/btrfsfuzz/src-asan/./ctree.h:2136:1 + #1 0x5f16f5 in read_qgroup_status /home/lukas/dev/btrfsfuzz/src-asan/qgroup-verify.c:885:10 + #2 0x5ef38a in load_quota_info /home/lukas/dev/btrfsfuzz/src-asan/qgroup-verify.c:949:5 + #3 0x5eeefc in qgroup_verify_all /home/lukas/dev/btrfsfuzz/src-asan/qgroup-verify.c:1351:8 + #4 0x51f08f in cmd_check /home/lukas/dev/btrfsfuzz/src-asan/cmds-check.c:11637:9 + #5 0x4f0f81 in main /home/lukas/dev/btrfsfuzz/src-asan/btrfs.c:243:8 + #6 0x7f7eb11aa730 in __libc_start_main (/lib64/libc.so.6+0x20730) + #7 0x4213f8 in _start (/home/lukas/dev/btrfsfuzz/bin-asan/bin/btrfs+0x4213f8) + +AddressSanitizer can not provide additional info. +SUMMARY: AddressSanitizer: SEGV /home/lukas/dev/btrfsfuzz/src-asan/./ctree.h:2136:1 in btrfs_qgroup_status_flags +==30530==ABORTING diff --git a/tests/fuzz-tests/images/bko-166361-blocksize-zero.raw.xz b/tests/fuzz-tests/images/bko-166361-blocksize-zero.raw.xz new file mode 100644 index 00000000..2b3c6741 Binary files /dev/null and b/tests/fuzz-tests/images/bko-166361-blocksize-zero.raw.xz differ diff --git a/tests/fuzz-tests/images/bko-169311-blocksize-zero-qgroup-verify.raw.txt b/tests/fuzz-tests/images/bko-169311-blocksize-zero-qgroup-verify.raw.txt new file mode 100644 index 00000000..c3d491be --- /dev/null +++ b/tests/fuzz-tests/images/bko-169311-blocksize-zero-qgroup-verify.raw.txt @@ -0,0 +1,126 @@ +URL: https://bugzilla.kernel.org/show_bug.cgi?id=169311 +Lukas Lueg 2016-09-18 09:23:44 UTC + +More news from the fuzzer. The attached image causes a heap-buffer-overflow +when running btrfsck with ASAN over it; using btrfs-prog s v4.7.2-56-ge8c2013 + + +==32491==ERROR: AddressSanitizer: heap-buffer-overflow on address 0x60c00000bf5c at pc 0x000000614b63 bp 0x7ffeacb5c3b0 sp 0x7ffeacb +5c3a8 +READ of size 8 at 0x60c00000bf5c thread T0 + #0 0x614b62 in crc32c_intel /home/lukas/dev/btrfsfuzz/src-asan/crc32c.c:75:19 + #1 0x614c09 in crc32c_le /home/lukas/dev/btrfsfuzz/src-asan/crc32c.c:221:9 + #2 0x58de58 in __csum_tree_block_size /home/lukas/dev/btrfsfuzz/src-asan/disk-io.c:139:8 + #3 0x58dd88 in csum_tree_block_size /home/lukas/dev/btrfsfuzz/src-asan/disk-io.c:159:9 + #4 0x58dfa1 in csum_tree_block_fs_info /home/lukas/dev/btrfsfuzz/src-asan/disk-io.c:174:9 + #5 0x58eb64 in read_tree_block_fs_info /home/lukas/dev/btrfsfuzz/src-asan/disk-io.c:348:19 + #6 0x5f2f84 in read_tree_block /home/lukas/dev/btrfsfuzz/src-asan/./disk-io.h:112:9 + #7 0x5f2d62 in travel_tree /home/lukas/dev/btrfsfuzz/src-asan/qgroup-verify.c:692:7 + #8 0x5f2bab in add_refs_for_implied /home/lukas/dev/btrfsfuzz/src-asan/qgroup-verify.c:748:8 + #9 0x5eff59 in map_implied_refs /home/lukas/dev/btrfsfuzz/src-asan/qgroup-verify.c:766:9 + #10 0x5eefa9 in qgroup_verify_all /home/lukas/dev/btrfsfuzz/src-asan/qgroup-verify.c:1366:8 + #11 0x51f08f in cmd_check /home/lukas/dev/btrfsfuzz/src-asan/cmds-check.c:11637:9 + #12 0x4f0f81 in main /home/lukas/dev/btrfsfuzz/src-asan/btrfs.c:243:8 + #13 0x7fbf35742730 in __libc_start_main (/lib64/libc.so.6+0x20730) + #14 0x4213f8 in _start (/home/lukas/dev/btrfsfuzz/bin-asan/bin/btrfs+0x4213f8) + +checking extents +Chunk[256, 228, 0]: length(4194304), offset(0), type(2) is not found in block group +Chunk[256, 228, 0] stripe[1, 0] is not found in dev extent +Chunk[256, 228, 4194304]: length(1638400), offset(4194304), type(5) is not found in block group +Chunk[256, 228, 4194304] stripe[1, 4194304] is not found in dev extent +Chunk[256, 228, 5832704]: length(1638400), offset(5832704), type(5) is not found in block group +Chunk[256, 228, 5832704] stripe[1, 5832704] is not found in dev extent +ref mismatch on [131072 4096] extent item 0, found 1 +Backref 131072 parent 3 root 3 not found in extent tree +backpointer mismatch on [131072 4096] +ref mismatch on [4194304 4096] extent item 0, found 1 +Backref 4194304 parent 5 root 5 not found in extent tree +backpointer mismatch on [4194304 4096] +ref mismatch on [4198400 4096] extent item 0, found 1 +Backref 4198400 parent 1 root 1 not found in extent tree +backpointer mismatch on [4198400 4096] +ref mismatch on [4231168 4096] extent item 0, found 1 +Backref 4231168 parent 7 root 7 not found in extent tree +backpointer mismatch on [4231168 4096] +ref mismatch on [3472328296227680304 3472328296227680304] extent item 0, found 1 +Backref 3472328296227680304 root 1 owner 2 offset 0 num_refs 0 not found in extent tree +Incorrect local backref count on 3472328296227680304 root 1 owner 2 offset 0 found 1 wanted 0 back 0x60800000bc20 +backpointer mismatch on [3472328296227680304 3472328296227680304] +Dev extent's total-byte(0) is not equal to byte-used(7471104) in dev[1, 216, 1] +Errors found in extent allocation tree or chunk allocation +checking free space cache +checking fs roots +checking csums +checking root refs +checking quota groups +================================================================= +==32491==ERROR: AddressSanitizer: heap-buffer-overflow on address 0x60c00000bf5c at pc 0x000000614b63 bp 0x7ffeacb5c3b0 sp 0x7ffeacb5c3a8 +READ of size 8 at 0x60c00000bf5c thread T0 + #0 0x614b62 in crc32c_intel /home/lukas/dev/btrfsfuzz/src-asan/crc32c.c:75:19 + #1 0x614c09 in crc32c_le /home/lukas/dev/btrfsfuzz/src-asan/crc32c.c:221:9 + #2 0x58de58 in __csum_tree_block_size /home/lukas/dev/btrfsfuzz/src-asan/disk-io.c:139:8 + #3 0x58dd88 in csum_tree_block_size /home/lukas/dev/btrfsfuzz/src-asan/disk-io.c:159:9 + #4 0x58dfa1 in csum_tree_block_fs_info /home/lukas/dev/btrfsfuzz/src-asan/disk-io.c:174:9 + #5 0x58eb64 in read_tree_block_fs_info /home/lukas/dev/btrfsfuzz/src-asan/disk-io.c:348:19 + #6 0x5f2f84 in read_tree_block /home/lukas/dev/btrfsfuzz/src-asan/./disk-io.h:112:9 + #7 0x5f2d62 in travel_tree /home/lukas/dev/btrfsfuzz/src-asan/qgroup-verify.c:692:7 + #8 0x5f2bab in add_refs_for_implied /home/lukas/dev/btrfsfuzz/src-asan/qgroup-verify.c:748:8 + #9 0x5eff59 in map_implied_refs /home/lukas/dev/btrfsfuzz/src-asan/qgroup-verify.c:766:9 + #10 0x5eefa9 in qgroup_verify_all /home/lukas/dev/btrfsfuzz/src-asan/qgroup-verify.c:1366:8 + #11 0x51f08f in cmd_check /home/lukas/dev/btrfsfuzz/src-asan/cmds-check.c:11637:9 + #12 0x4f0f81 in main /home/lukas/dev/btrfsfuzz/src-asan/btrfs.c:243:8 + #13 0x7fbf35742730 in __libc_start_main (/lib64/libc.so.6+0x20730) + #14 0x4213f8 in _start (/home/lukas/dev/btrfsfuzz/bin-asan/bin/btrfs+0x4213f8) + +0x60c00000bf5c is located 28 bytes to the right of 128-byte region [0x60c00000bec0,0x60c00000bf40) +allocated by thread T0 here: + #0 0x4bfd40 in calloc (/home/lukas/dev/btrfsfuzz/bin-asan/bin/btrfs+0x4bfd40) + #1 0x5c181a in __alloc_extent_buffer /home/lukas/dev/btrfsfuzz/src-asan/extent_io.c:542:7 + #2 0x5c1c76 in alloc_extent_buffer /home/lukas/dev/btrfsfuzz/src-asan/extent_io.c:646:8 + #3 0x58e01c in btrfs_find_create_tree_block /home/lukas/dev/btrfsfuzz/src-asan/disk-io.c:193:9 + #4 0x58ea90 in read_tree_block_fs_info /home/lukas/dev/btrfsfuzz/src-asan/disk-io.c:339:7 + #5 0x5f2f84 in read_tree_block /home/lukas/dev/btrfsfuzz/src-asan/./disk-io.h:112:9 + #6 0x5f2d62 in travel_tree /home/lukas/dev/btrfsfuzz/src-asan/qgroup-verify.c:692:7 + #7 0x5f2bab in add_refs_for_implied /home/lukas/dev/btrfsfuzz/src-asan/qgroup-verify.c:748:8 + #8 0x5eff59 in map_implied_refs /home/lukas/dev/btrfsfuzz/src-asan/qgroup-verify.c:766:9 + #9 0x5eefa9 in qgroup_verify_all /home/lukas/dev/btrfsfuzz/src-asan/qgroup-verify.c:1366:8 + #10 0x51f08f in cmd_check /home/lukas/dev/btrfsfuzz/src-asan/cmds-check.c:11637:9 + #11 0x4f0f81 in main /home/lukas/dev/btrfsfuzz/src-asan/btrfs.c:243:8 + #12 0x7fbf35742730 in __libc_start_main (/lib64/libc.so.6+0x20730) + +SUMMARY: AddressSanitizer: heap-buffer-overflow /home/lukas/dev/btrfsfuzz/src-asan/crc32c.c:75:19 in crc32c_intel +Shadow bytes around the buggy address: + 0x0c187fff9790: fa fa fa fa fa fa fa fa fa fa fa fa fa fa fa fa + 0x0c187fff97a0: fa fa fa fa fa fa fa fa fa fa fa fa fa fa fa fa + 0x0c187fff97b0: fa fa fa fa fa fa fa fa fa fa fa fa fa fa fa fa + 0x0c187fff97c0: fa fa fa fa fa fa fa fa fa fa fa fa fa fa fa fa + 0x0c187fff97d0: fa fa fa fa fa fa fa fa 00 00 00 00 00 00 00 00 +=>0x0c187fff97e0: 00 00 00 00 00 00 00 00 fa fa fa[fa]fa fa fa fa + 0x0c187fff97f0: fd fd fd fd fd fd fd fd fd fd fd fd fd fd fd fa + 0x0c187fff9800: fa fa fa fa fa fa fa fa fa fa fa fa fa fa fa fa + 0x0c187fff9810: fa fa fa fa fa fa fa fa fa fa fa fa fa fa fa fa + 0x0c187fff9820: fa fa fa fa fa fa fa fa fa fa fa fa fa fa fa fa + 0x0c187fff9830: fa fa fa fa fa fa fa fa fa fa fa fa fa fa fa fa +Shadow byte legend (one shadow byte represents 8 application bytes): + Addressable: 00 + Partially addressable: 01 02 03 04 05 06 07 + Heap left redzone: fa + Heap right redzone: fb + Freed heap region: fd + Stack left redzone: f1 + Stack mid redzone: f2 + Stack right redzone: f3 + Stack partial redzone: f4 + Stack after return: f5 + Stack use after scope: f8 + Global redzone: f9 + Global init order: f6 + Poisoned by user: f7 + Container overflow: fc + Array cookie: ac + Intra object redzone: bb + ASan internal: fe + Left alloca redzone: ca + Right alloca redzone: cb +==32491==ABORTING diff --git a/tests/fuzz-tests/images/bko-169311-blocksize-zero-qgroup-verify.raw.xz b/tests/fuzz-tests/images/bko-169311-blocksize-zero-qgroup-verify.raw.xz new file mode 100644 index 00000000..c506d1bc Binary files /dev/null and b/tests/fuzz-tests/images/bko-169311-blocksize-zero-qgroup-verify.raw.xz differ -- cgit v1.2.3 From 35d0588b641b227f6560f8c7240e0b2c43afae14 Mon Sep 17 00:00:00 2001 From: David Sterba Date: Fri, 30 Sep 2016 18:59:44 +0200 Subject: btrfs-progs: tests: add fuzzed image with bad parent refs, qgroup-verify Signed-off-by: David Sterba --- ...bko-156811-bad-parent-ref-qgroup-verify.raw.txt | 94 +++++++++++++++++++++ .../bko-156811-bad-parent-ref-qgroup-verify.raw.xz | Bin 0 -> 3832 bytes 2 files changed, 94 insertions(+) create mode 100644 tests/fuzz-tests/images/bko-156811-bad-parent-ref-qgroup-verify.raw.txt create mode 100644 tests/fuzz-tests/images/bko-156811-bad-parent-ref-qgroup-verify.raw.xz (limited to 'tests') diff --git a/tests/fuzz-tests/images/bko-156811-bad-parent-ref-qgroup-verify.raw.txt b/tests/fuzz-tests/images/bko-156811-bad-parent-ref-qgroup-verify.raw.txt new file mode 100644 index 00000000..6e4a5418 --- /dev/null +++ b/tests/fuzz-tests/images/bko-156811-bad-parent-ref-qgroup-verify.raw.txt @@ -0,0 +1,94 @@ +URL: https://bugzilla.kernel.org/show_bug.cgi?id=156811 +Lukas Lueg 2016-09-14 19:19:46 UTC + +More news from the fuzzer. The attached image causes btrfsck to engage in +undefined behavior; using btrfs-progs v4.7-42-g56e9586. You need to compile +with UBSAN in order to reproduce. + +The juicy parts: + +qgroup-verify.c:333:15: runtime error: member access within null pointer of type 'struct ref' + #0 0x88684f in find_parent_roots /home/lukas/dev/btrfsfuzz/src-ubsan/qgroup-verify.c:333:15 + #1 0x877a71 in account_all_refs /home/lukas/dev/btrfsfuzz/src-ubsan/qgroup-verify.c:525:11 + #2 0x87513b in qgroup_verify_all /home/lukas/dev/btrfsfuzz/src-ubsan/qgroup-verify.c:1372:8 + #3 0x536d3a in cmd_check /home/lukas/dev/btrfsfuzz/src-ubsan/cmds-check.c:11637:9 + #4 0x490560 in main /home/lukas/dev/btrfsfuzz/src-ubsan/btrfs.c:243:8 + #5 0x7f35b46ab730 in __libc_start_main (/lib64/libc.so.6+0x20730) + #6 0x422188 in _start (/home/lukas/dev/btrfsfuzz/bin-ubsan/bin/btrfs+0x422188) + + +We don't strictly need UBSAN as the error can be spotted by naked eye in +find_parent_root(): The line "node = &ref->bytenr_node" gets a reference to a +member of a NULL pointer before the pointer is checked against being NULL on +the next line. It should be the other way around... + +crc32c.c:75:19: runtime error: load of misaligned address 0x74200001cc9c for type 'unsigned long', which requires 8 byte alignment +0x74200001cc9c: note: pointer points here + 00 00 00 00 b7 0e 65 6c 64 61 40 4b a5 0d 0f ba 33 0c 75 27 00 00 02 00 00 00 00 00 01 00 00 00 + ^ + #0 0x907c52 in crc32c_intel /home/lukas/dev/btrfsfuzz/src-ubsan/crc32c.c:75:19 + #1 0x6f9845 in __csum_tree_block_size /home/lukas/dev/btrfsfuzz/src-ubsan/disk-io.c:139:8 + #2 0x6f96b8 in csum_tree_block_size /home/lukas/dev/btrfsfuzz/src-ubsan/disk-io.c:159:9 + #3 0x6fda28 in read_tree_block_fs_info /home/lukas/dev/btrfsfuzz/src-ubsan/disk-io.c:348:19 + #4 0x71669f in btrfs_setup_chunk_tree_and_device_map /home/lukas/dev/btrfsfuzz/src-ubsan/disk-io.c:1210:30 + #5 0x7187e4 in __open_ctree_fd /home/lukas/dev/btrfsfuzz/src-ubsan/disk-io.c:1322:8 + #6 0x717a6d in open_ctree_fs_info /home/lukas/dev/btrfsfuzz/src-ubsan/disk-io.c:1381:9 + #7 0x533791 in cmd_check /home/lukas/dev/btrfsfuzz/src-ubsan/cmds-check.c:11449:9 + #8 0x490560 in main /home/lukas/dev/btrfsfuzz/src-ubsan/btrfs.c:243:8 + #9 0x7f35b46ab730 in __libc_start_main (/lib64/libc.so.6+0x20730) + #10 0x422188 in _start (/home/lukas/dev/btrfsfuzz/bin-ubsan/bin/btrfs+0x422188) + +SUMMARY: MemorySanitizer: undefined-behavior crc32c.c:75:19 in +checking extents +Chunk[256, 228, 0]: length(4194304), offset(0), type(2) is not found in block group +Chunk[256, 228, 0] stripe[1, 0] is not found in dev extent +Chunk[256, 228, 4194304]: length(1638400), offset(4194304), type(5) is not found in block group +Chunk[256, 228, 4194304] stripe[1, 4194304] is not found in dev extent +Chunk[256, 228, 5832704]: length(1638400), offset(5832704), type(5) is not found in block group +Chunk[256, 228, 5832704] stripe[1, 5832704] is not found in dev extent +ref mismatch on [131072 4096] extent item 0, found 1 +Backref 131072 parent 3 root 3 not found in extent tree +backpointer mismatch on [131072 4096] +ref mismatch on [4194304 4096] extent item 0, found 1 +Backref 4194304 parent 5 root 5 not found in extent tree +backpointer mismatch on [4194304 4096] +ref mismatch on [4198400 4096] extent item 0, found 1 +Backref 4198400 parent 1 root 1 not found in extent tree +backpointer mismatch on [4198400 4096] +ref mismatch on [4231168 4096] extent item 0, found 1 +Backref 4231168 parent 7 root 7 not found in extent tree +backpointer mismatch on [4231168 4096] +ref mismatch on [3472328296227680304 3472328296227680304] extent item 0, found 1 +Backref 3472328296227680304 root 1 owner 2 offset 0 num_refs 0 not found in extent tree +Incorrect local backref count on 3472328296227680304 root 1 owner 2 offset 0 found 1 wanted 0 back 0x70c00000ed00 +backpointer mismatch on [3472328296227680304 3472328296227680304] +Dev extent's total-byte(0) is not equal to byte-used(7471104) in dev[1, 216, 1] +Errors found in extent allocation tree or chunk allocation +checking free space cache +checking fs roots +checking csums +checking root refs +checking quota groups +qgroup-verify.c:333:15: runtime error: member access within null pointer of type 'struct ref' + #0 0x88684f in find_parent_roots /home/lukas/dev/btrfsfuzz/src-ubsan/qgroup-verify.c:333:15 + #1 0x877a71 in account_all_refs /home/lukas/dev/btrfsfuzz/src-ubsan/qgroup-verify.c:525:11 + #2 0x87513b in qgroup_verify_all /home/lukas/dev/btrfsfuzz/src-ubsan/qgroup-verify.c:1372:8 + #3 0x536d3a in cmd_check /home/lukas/dev/btrfsfuzz/src-ubsan/cmds-check.c:11637:9 + #4 0x490560 in main /home/lukas/dev/btrfsfuzz/src-ubsan/btrfs.c:243:8 + #5 0x7f35b46ab730 in __libc_start_main (/lib64/libc.so.6+0x20730) + #6 0x422188 in _start (/home/lukas/dev/btrfsfuzz/bin-ubsan/bin/btrfs+0x422188) + +SUMMARY: MemorySanitizer: undefined-behavior qgroup-verify.c:333:15 in +qgroup-verify.c:334: find_parent_roots: Assertion `ref == NULL` failed. +btrfs check(backtrace+0x51)[0x43f6d1] +btrfs check[0x883611] +btrfs check[0x880ce9] +btrfs check[0x8868b1] +btrfs check[0x877a72] +btrfs check(qgroup_verify_all+0x26c)[0x87513c] +btrfs check(cmd_check+0x457b)[0x536d3b] +btrfs check(main+0x6a1)[0x490561] +/lib64/libc.so.6(__libc_start_main+0xf1)[0x7f35b46ab731] +btrfs check(_start+0x29)[0x422189] +Checking filesystem on ubsan_logs/id:002289,src:001702+002037,op:splice,rep:4.img +UUID: b70e656c-6461-404b-a50d-0fba330c7527 diff --git a/tests/fuzz-tests/images/bko-156811-bad-parent-ref-qgroup-verify.raw.xz b/tests/fuzz-tests/images/bko-156811-bad-parent-ref-qgroup-verify.raw.xz new file mode 100644 index 00000000..7e499f77 Binary files /dev/null and b/tests/fuzz-tests/images/bko-156811-bad-parent-ref-qgroup-verify.raw.xz differ -- cgit v1.2.3 From a5ac95415366113462ff68cdff9ac9047159c3c7 Mon Sep 17 00:00:00 2001 From: David Sterba Date: Mon, 3 Oct 2016 17:54:05 +0200 Subject: btrfs-progs: tests: split test 004 to separate tests Makes testing specific tool easier. Signed-off-by: David Sterba --- tests/fuzz-tests/004-misc-dumps/test.sh | 31 ----------------------- tests/fuzz-tests/004-simple-dump-tree/test.sh | 18 +++++++++++++ tests/fuzz-tests/005-simple-dump-super/test.sh | 19 ++++++++++++++ tests/fuzz-tests/006-simple-tree-stats/test.sh | 18 +++++++++++++ tests/fuzz-tests/007-simple-super-recover/test.sh | 20 +++++++++++++++ tests/fuzz-tests/008-simple-chunk-recover/test.sh | 20 +++++++++++++++ tests/fuzz-tests/009-simple-zero-log/test.sh | 20 +++++++++++++++ 7 files changed, 115 insertions(+), 31 deletions(-) delete mode 100755 tests/fuzz-tests/004-misc-dumps/test.sh create mode 100755 tests/fuzz-tests/004-simple-dump-tree/test.sh create mode 100755 tests/fuzz-tests/005-simple-dump-super/test.sh create mode 100755 tests/fuzz-tests/006-simple-tree-stats/test.sh create mode 100755 tests/fuzz-tests/007-simple-super-recover/test.sh create mode 100755 tests/fuzz-tests/008-simple-chunk-recover/test.sh create mode 100755 tests/fuzz-tests/009-simple-zero-log/test.sh (limited to 'tests') diff --git a/tests/fuzz-tests/004-misc-dumps/test.sh b/tests/fuzz-tests/004-misc-dumps/test.sh deleted file mode 100755 index 3fae2f65..00000000 --- a/tests/fuzz-tests/004-misc-dumps/test.sh +++ /dev/null @@ -1,31 +0,0 @@ -#!/bin/bash - -# iterate over all fuzzed images and run various tools, do not expect to repair -# or dump succesfully, must not crash at least - -source $TOP/tests/common - -setup_root_helper -check_prereq btrfs - -# redefine the one provided by common -check_image() { - local image - - image=$1 - run_mayfail $TOP/btrfs inspect-internal dump-tree "$image" - run_mayfail $TOP/btrfs inspect-internal dump-super "$image" - run_mayfail $TOP/btrfs inspect-internal dump-super -Ffa "$image" - run_mayfail $TOP/btrfs inspect-internal tree-stats "$image" - run_check cp "$image" "$image".scratch - run_mayfail $TOP/btrfs rescue super-recover -y -v "$image".scratch - run_check cp "$image" "$image".scratch - run_mayfail $TOP/btrfs rescue chunk-recover -y -v "$image".scratch - run_check cp "$image" "$image".scratch - run_mayfail $TOP/btrfs rescue zero-log "$image".scratch - rm -- "$image".scratch -} - -check_all_images $TOP/tests/fuzz-tests/images - -exit 0 diff --git a/tests/fuzz-tests/004-simple-dump-tree/test.sh b/tests/fuzz-tests/004-simple-dump-tree/test.sh new file mode 100755 index 00000000..89ff214c --- /dev/null +++ b/tests/fuzz-tests/004-simple-dump-tree/test.sh @@ -0,0 +1,18 @@ +#!/bin/bash + +source $TOP/tests/common + +setup_root_helper +check_prereq btrfs + +# redefine the one provided by common +check_image() { + local image + + image=$1 + run_mayfail $TOP/btrfs inspect-internal dump-tree "$image" +} + +check_all_images $TOP/tests/fuzz-tests/images + +exit 0 diff --git a/tests/fuzz-tests/005-simple-dump-super/test.sh b/tests/fuzz-tests/005-simple-dump-super/test.sh new file mode 100755 index 00000000..fbce3d9f --- /dev/null +++ b/tests/fuzz-tests/005-simple-dump-super/test.sh @@ -0,0 +1,19 @@ +#!/bin/bash + +source $TOP/tests/common + +setup_root_helper +check_prereq btrfs + +# redefine the one provided by common +check_image() { + local image + + image=$1 + run_mayfail $TOP/btrfs inspect-internal dump-super "$image" + run_mayfail $TOP/btrfs inspect-internal dump-super -Ffa "$image" +} + +check_all_images $TOP/tests/fuzz-tests/images + +exit 0 diff --git a/tests/fuzz-tests/006-simple-tree-stats/test.sh b/tests/fuzz-tests/006-simple-tree-stats/test.sh new file mode 100755 index 00000000..c3410b06 --- /dev/null +++ b/tests/fuzz-tests/006-simple-tree-stats/test.sh @@ -0,0 +1,18 @@ +#!/bin/bash + +source $TOP/tests/common + +setup_root_helper +check_prereq btrfs + +# redefine the one provided by common +check_image() { + local image + + image=$1 + run_mayfail $TOP/btrfs inspect-internal tree-stats "$image" +} + +check_all_images $TOP/tests/fuzz-tests/images + +exit 0 diff --git a/tests/fuzz-tests/007-simple-super-recover/test.sh b/tests/fuzz-tests/007-simple-super-recover/test.sh new file mode 100755 index 00000000..885cb352 --- /dev/null +++ b/tests/fuzz-tests/007-simple-super-recover/test.sh @@ -0,0 +1,20 @@ +#!/bin/bash + +source $TOP/tests/common + +setup_root_helper +check_prereq btrfs + +# redefine the one provided by common +check_image() { + local image + + image=$1 + run_check cp "$image" "$image".scratch + run_mayfail $TOP/btrfs rescue super-recover -y -v "$image".scratch + rm -- "$image".scratch +} + +check_all_images $TOP/tests/fuzz-tests/images + +exit 0 diff --git a/tests/fuzz-tests/008-simple-chunk-recover/test.sh b/tests/fuzz-tests/008-simple-chunk-recover/test.sh new file mode 100755 index 00000000..d53453f6 --- /dev/null +++ b/tests/fuzz-tests/008-simple-chunk-recover/test.sh @@ -0,0 +1,20 @@ +#!/bin/bash + +source $TOP/tests/common + +setup_root_helper +check_prereq btrfs + +# redefine the one provided by common +check_image() { + local image + + image=$1 + run_check cp "$image" "$image".scratch + run_mayfail $TOP/btrfs rescue chunk-recover -y -v "$image".scratch + rm -- "$image".scratch +} + +check_all_images $TOP/tests/fuzz-tests/images + +exit 0 diff --git a/tests/fuzz-tests/009-simple-zero-log/test.sh b/tests/fuzz-tests/009-simple-zero-log/test.sh new file mode 100755 index 00000000..393db3f6 --- /dev/null +++ b/tests/fuzz-tests/009-simple-zero-log/test.sh @@ -0,0 +1,20 @@ +#!/bin/bash + +source $TOP/tests/common + +setup_root_helper +check_prereq btrfs + +# redefine the one provided by common +check_image() { + local image + + image=$1 + run_check cp "$image" "$image".scratch + run_mayfail $TOP/btrfs rescue zero-log "$image".scratch + rm -- "$image".scratch +} + +check_all_images $TOP/tests/fuzz-tests/images + +exit 0 -- cgit v1.2.3 From b6bf79eb962247ecabdd079cf266ec7173a6345a Mon Sep 17 00:00:00 2001 From: David Sterba Date: Mon, 3 Oct 2016 17:55:49 +0200 Subject: btrfs-progs: tests: don't treat segfault as ignorable error Some fuzzed images cause various tools to crash but the mayfail helper would not recognize that. We don't mind if the utility failes but it must not crash. Signed-off-by: David Sterba --- tests/common | 12 +++++++++--- 1 file changed, 9 insertions(+), 3 deletions(-) (limited to 'tests') diff --git a/tests/common b/tests/common index c50b661f..d965c12c 100644 --- a/tests/common +++ b/tests/common @@ -48,6 +48,8 @@ run_check_stdout() # same as run_check but does not fail the test, output is logged run_mayfail() { + local ret + echo "############### $@" >> $RESULTS 2>&1 if [ "$TEST_LOG" = 'tty' ]; then echo "CMD(mayfail): $@" > /dev/tty; fi if [ "$1" = 'root_helper' ]; then @@ -55,9 +57,13 @@ run_mayfail() else $INSTRUMENT "$@" >> $RESULTS 2>&1 fi - if [ $? != 0 ]; then - echo "failed (ignored): $@" >> $RESULTS - return 1 + ret=$? + if [ $ret != 0 ]; then + echo "failed (ignored, ret=$ret): $@" >> $RESULTS + if [ $ret == 139 ]; then + _fail "mayfail: returned code 139 (SEGFAULT), not ignored" + fi + return $ret fi } -- cgit v1.2.3 From a08ca376f7746b4ec5839bacc4d7d7468a271dac Mon Sep 17 00:00:00 2001 From: David Sterba Date: Tue, 4 Oct 2016 18:53:38 +0200 Subject: btrfs-progs: tests: teach run_mayfail about sigabrt Mayfail helper should stop when we encoutner an abort. Signed-off-by: David Sterba --- tests/common | 2 ++ 1 file changed, 2 insertions(+) (limited to 'tests') diff --git a/tests/common b/tests/common index d965c12c..264424d3 100644 --- a/tests/common +++ b/tests/common @@ -62,6 +62,8 @@ run_mayfail() echo "failed (ignored, ret=$ret): $@" >> $RESULTS if [ $ret == 139 ]; then _fail "mayfail: returned code 139 (SEGFAULT), not ignored" + elif [ $ret == 134 ]; then + _fail "mayfail: returned code 134 (SIGABRT), not ignored" fi return $ret fi -- cgit v1.2.3 From ba253d4ea58a618acc6e2f65446cfd3d20652234 Mon Sep 17 00:00:00 2001 From: David Sterba Date: Thu, 6 Oct 2016 17:35:33 +0200 Subject: btrfs-progs: tests: add script to help build coverage Signed-off-by: David Sterba --- tests/build-tests.sh | 88 ++++++++++++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 88 insertions(+) create mode 100755 tests/build-tests.sh (limited to 'tests') diff --git a/tests/build-tests.sh b/tests/build-tests.sh new file mode 100755 index 00000000..04e3fd19 --- /dev/null +++ b/tests/build-tests.sh @@ -0,0 +1,88 @@ +#!/bin/sh +# test various compilation options +# - 32bit, 64bit +# - dynamic, static +# - various configure options +# +# Arguments: anything will be passed to 'make', eg. define CC, D, V +# +# Requirements for full coverage: +# - static version of all libs +# - 32bit/64bit libraries, also the static variants + +make=make +opts="-j16 $@" + +conf= +target= + +function die() { + echo "ERROR: $@" + exit 1 +} + +function check_result() { + local ret + local str + + ret=$1 + + str="RESULT of target($target) conf($conf): " + case $ret in + 0) str="$str OK";; + *) str="$str FAIL";; + esac + echo "$str" + verdict="$verdict +$str" +} + +function buildme() { + make clean-all + + ./autogen.sh && configure "$conf" || die "configure not working with: $@" + $make clean + $make $opts $target + check_result "$?" + echo "VERDICT: $verdict" +} + +function build_make_targets() { + # defaults + target= + buildme + # defaults, static + target=static + buildme + # defaults, 32bit + target="EXTRA_CFLAGS=-m32" + buildme + # defaults, 64bit + target="EXTRA_CFLAGS=-m64" + buildme + # defaults, library + target="library-test" + buildme +} + +# main() +if ! [ -f configure.ac ]; then + echo "Please run me from the top directory" + exit 1 +fi + +verdict= +conf= +build_make_targets + +conf='--disable-documentation' +build_make_targets + +conf='--disable-backtrace' +build_make_targets + +conf='--disable-convert' +build_make_targets + +echo "---------------------------------------------------" +echo "$verdict" -- cgit v1.2.3 From 0ec02b118da84e4dfbbb532b9e9f7c59df4e5dbe Mon Sep 17 00:00:00 2001 From: "Lakshmipathi.G" Date: Sun, 9 Oct 2016 17:08:12 +0200 Subject: btrfs-progs: Add fast,slow symlinks, fifo types to convert test Signed-off-by: Lakshmipathi.G [ fix root helper use in fast_symlink ] Signed-off-by: David Sterba --- tests/common.convert | 20 +++++++++++++++++--- 1 file changed, 17 insertions(+), 3 deletions(-) (limited to 'tests') diff --git a/tests/common.convert b/tests/common.convert index 1e00d389..a80948d7 100644 --- a/tests/common.convert +++ b/tests/common.convert @@ -25,10 +25,10 @@ generate_dataset() { done ;; - symlink) + fast_symlink) for num in $(seq 1 $DATASET_SIZE); do run_check $SUDO_HELPER touch $dirpath/$dataset_type.$num - run_check $SUDO_HELPER ln -s $dirpath/$dataset_type.$num $dirpath/slink.$num + run_check cd $dirpath && $SUDO_HELPER ln -s $dataset_type.$num $dirpath/slink.$num && cd / done ;; @@ -71,12 +71,26 @@ generate_dataset() { run_check $SUDO_HELPER setfattr -n user.foo -v bar$num $dirpath/$dataset_type.$num done ;; + + fifo) + for num in $(seq 1 $DATASET_SIZE); do + run_check $SUDO_HELPER mkfifo $dirpath/$dataset_type.$num + done + ;; + + slow_symlink) + long_filename=`date +%s | sha256sum | cut -f1 -d'-'` + run_check $SUDO_HELPER touch $dirpath/$long_filename + for num in $(seq 1 $DATASET_SIZE); do + run_check $SUDO_HELPER ln -s $dirpath/$long_filename $dirpath/slow_slink.$num + done + ;; esac } populate_fs() { - for dataset_type in 'small' 'hardlink' 'symlink' 'brokenlink' 'perm' 'sparse' 'acls'; do + for dataset_type in 'small' 'hardlink' 'fast_symlink' 'brokenlink' 'perm' 'sparse' 'acls' 'fifo' 'slow_symlink'; do generate_dataset "$dataset_type" done } -- cgit v1.2.3 From 8c663f9f3616e0de56e77ac4a91ef3db2d99bf34 Mon Sep 17 00:00:00 2001 From: Qu Wenruo Date: Mon, 10 Oct 2016 11:00:13 +0800 Subject: btrfs-progs: convert-test: Add test case for common inode flags Add a new test case to check if btrfs-convert copies common inode flags like append(a), immutable(i). Signed-off-by: Qu Wenruo [ minor fixes ] Signed-off-by: David Sterba --- tests/convert-tests/009-common-inode-flags/test.sh | 34 ++++++++++++++++++++++ 1 file changed, 34 insertions(+) create mode 100755 tests/convert-tests/009-common-inode-flags/test.sh (limited to 'tests') diff --git a/tests/convert-tests/009-common-inode-flags/test.sh b/tests/convert-tests/009-common-inode-flags/test.sh new file mode 100755 index 00000000..6f26d187 --- /dev/null +++ b/tests/convert-tests/009-common-inode-flags/test.sh @@ -0,0 +1,34 @@ +#!/bin/bash +# Check if btrfs-convert can copy common inode flags like SYNC/IMMUTABLE + +source $TOP/tests/common +source $TOP/tests/common.convert + +setup_root_helper +prepare_test_dev 512M +check_prereq btrfs-convert + +fail=0 +default_mke2fs="mke2fs -t ext4 -b 4096" +convert_test_preamble '' 'common inode flags test' 16k "$default_mke2fs" +convert_test_prep_fs $default_mke2fs + +# create file with specific flags +run_check $SUDO_HELPER touch $TEST_MNT/flag_test +run_check $SUDO_HELPER chattr +aAdSi $TEST_MNT/flag_test + +run_check_umount_test_dev +convert_test_do_convert +run_check_mount_test_dev + +# Log the status +run_check lsattr $TEST_MNT/flag_test +# Above flags should be copied to btrfs flags, and lsattr should get them +run_check_stdout lsattr $TEST_MNT/flag_test | cut -f1 -d\ | grep "[aAdiS]" -q +if [ $? -ne 0 ]; then + rm tmp_output + _fail "no common inode flags are copied after convert" +fi + +run_check_umount_test_dev +convert_test_post_rollback -- cgit v1.2.3 From 9119319ef99ffd742349f4b91aa8caab02d38fc9 Mon Sep 17 00:00:00 2001 From: Qu Wenruo Date: Fri, 7 Oct 2016 15:22:59 +0800 Subject: btrfs-progs: test: Add test image for btrfsck qgroup rescan detection Fixed by commit 7c646c538e74 btrfs-progs: qgroup: Fix regression leads to corrupted qgroup status. Add minimal test image for that fix. Signed-off-by: Qu Wenruo [ minor cleanups in test.sh ] Signed-off-by: David Sterba --- .../qgroup_rescan_halfway.raw.xz | Bin 0 -> 59360 bytes tests/fsck-tests/022-qgroup-rescan-halfway/test.sh | 19 +++++++++++++++++++ 2 files changed, 19 insertions(+) create mode 100644 tests/fsck-tests/022-qgroup-rescan-halfway/qgroup_rescan_halfway.raw.xz create mode 100755 tests/fsck-tests/022-qgroup-rescan-halfway/test.sh (limited to 'tests') diff --git a/tests/fsck-tests/022-qgroup-rescan-halfway/qgroup_rescan_halfway.raw.xz b/tests/fsck-tests/022-qgroup-rescan-halfway/qgroup_rescan_halfway.raw.xz new file mode 100644 index 00000000..8cb620f7 Binary files /dev/null and b/tests/fsck-tests/022-qgroup-rescan-halfway/qgroup_rescan_halfway.raw.xz differ diff --git a/tests/fsck-tests/022-qgroup-rescan-halfway/test.sh b/tests/fsck-tests/022-qgroup-rescan-halfway/test.sh new file mode 100755 index 00000000..5b114eeb --- /dev/null +++ b/tests/fsck-tests/022-qgroup-rescan-halfway/test.sh @@ -0,0 +1,19 @@ +#!/bin/bash +# check whether btrfsck can detect running qgroup rescan + +source $TOP/tests/common + +check_prereq btrfs + +check_image() { + local image + + image=$1 + run_check_stdout $TOP/btrfs check "$image" 2>&1 | \ + grep -q "Counts for qgroup id" + if [ $? -eq 0 ]; then + _fail "Btrfs check doesn't detect rescan correctly" + fi +} + +check_all_images "." -- cgit v1.2.3 From 112514568fbe266943d7dd5ed3d2a6a8ab01a1de Mon Sep 17 00:00:00 2001 From: Qu Wenruo Date: Fri, 7 Oct 2016 15:23:00 +0800 Subject: btrfs-progs: test: Add image for quota verify stack overflow For image with tree reloc tree, if its height is over level 2, the root node's backref will point to itself. It's valid for kernel, but quota verify code can't handle it and cause a infinite call, overflowing the stack. Add minimal image to reproduce the bug, as regression test. Signed-off-by: Qu Wenruo [ minor cleanups in test.sh ] Signed-off-by: David Sterba --- .../quota_balance_loop_backref.raw.xz | Bin 0 -> 55708 bytes tests/fsck-tests/023-qgroup-stack-overflow/test.sh | 17 +++++++++++++++++ 2 files changed, 17 insertions(+) create mode 100644 tests/fsck-tests/023-qgroup-stack-overflow/quota_balance_loop_backref.raw.xz create mode 100755 tests/fsck-tests/023-qgroup-stack-overflow/test.sh (limited to 'tests') diff --git a/tests/fsck-tests/023-qgroup-stack-overflow/quota_balance_loop_backref.raw.xz b/tests/fsck-tests/023-qgroup-stack-overflow/quota_balance_loop_backref.raw.xz new file mode 100644 index 00000000..a0759739 Binary files /dev/null and b/tests/fsck-tests/023-qgroup-stack-overflow/quota_balance_loop_backref.raw.xz differ diff --git a/tests/fsck-tests/023-qgroup-stack-overflow/test.sh b/tests/fsck-tests/023-qgroup-stack-overflow/test.sh new file mode 100755 index 00000000..e8bf3fae --- /dev/null +++ b/tests/fsck-tests/023-qgroup-stack-overflow/test.sh @@ -0,0 +1,17 @@ +#!/bin/bash +# +# Check whether btrfs check quota verify will cause stack overflow. +# This is caused by lack of handling of tree reloc tree. +# Fixed by patch: +# btrfs-progs: Fix stack overflow for checking qgroup on tree reloc tree + +source $TOP/tests/common + +check_prereq btrfs + +check_image() +{ + run_check $TOP/btrfs check "$1" +} + +check_all_images "." -- cgit v1.2.3 From 40de2f62793ad54a91755edb301f2609121137e4 Mon Sep 17 00:00:00 2001 From: Qu Wenruo Date: Thu, 13 Oct 2016 17:22:27 +0800 Subject: btrfs-progs: fsck-tests: Check if clear space cache works Add test case to check the basic function of --clear-space-cache. Signed-off-by: Qu Wenruo Signed-off-by: David Sterba --- tests/fsck-tests/024-clear-space-cache/test.sh | 48 ++++++++++++++++++++++++++ 1 file changed, 48 insertions(+) create mode 100755 tests/fsck-tests/024-clear-space-cache/test.sh (limited to 'tests') diff --git a/tests/fsck-tests/024-clear-space-cache/test.sh b/tests/fsck-tests/024-clear-space-cache/test.sh new file mode 100755 index 00000000..2945ae87 --- /dev/null +++ b/tests/fsck-tests/024-clear-space-cache/test.sh @@ -0,0 +1,48 @@ +#!/bin/bash +# confirm that clearing space cache works + +source $TOP/tests/common + +check_prereq btrfs +check_prereq mkfs.btrfs + +setup_root_helper +prepare_test_dev 1G + +run_check $SUDO_HELPER $TOP/mkfs.btrfs -f $TEST_DEV +run_check_mount_test_dev + +# Create files that takes at least 3 data chunks, while +# can still be removed to create free space inside one chunk. + +for i in $(seq 0 6); do + run_check $SUDO_HELPER dd if=/dev/zero of=$TEST_MNT/file_${i} bs=1M \ + count=64 > /dev/null 2>&1 +done +sync + +# Remove file 1 3 5 to create holes +for i in 1 3 5; do + run_check $SUDO_HELPER rm $TEST_MNT/file_${i} +done + +sync + +run_check_umount_test_dev + +# Clear space cache and re-check fs +run_check $TOP/btrfs check --clear-space-cache v1 $TEST_DEV +run_check $TOP/btrfs check $TEST_DEV + +# Manually recheck space cache and super space cache generation +run_check_stdout $TOP/btrfs inspect-internal dump-tree -t root $TEST_DEV | \ + grep -q FREE_SPACE +if [ $? -eq 0 ]; then + _fail "clear space cache doesn't clear all space cache" +fi + +run_check_stdout $TOP/btrfs inspect-internal dump-super $TEST_DEV | + grep -q 'cache_generation.*18446744073709551615' +if [ $? -ne 0 ]; then + _fail "clear space cache doesn't set cache_generation correctly" +fi -- cgit v1.2.3 From c8d1c4c7920efea969fedfd6d7b0669832161d22 Mon Sep 17 00:00:00 2001 From: David Sterba Date: Wed, 26 Oct 2016 16:41:32 +0200 Subject: btrfs-progs: tests: switch to dump- commands from inspect The dump-super and debug-tree commands are replacements for the standalone tools. Signed-off-by: David Sterba --- tests/common.convert | 2 +- .../convert-tests/004-ext2-backup-superblock-ranges/test.sh | 3 +-- tests/fsck-tests/013-extent-tree-rebuild/test.sh | 3 +-- tests/misc-tests/001-btrfstune-features/test.sh | 8 +++----- tests/misc-tests/002-uuid-rewrite/test.sh | 12 +++++------- tests/misc-tests/003-zero-log/test.sh | 9 ++++----- tests/misc-tests/006-image-on-missing-device/test.sh | 1 - tests/misc-tests/010-convert-delete-ext2-subvol/test.sh | 5 ++--- tests/misc-tests/011-delete-missing-device/test.sh | 3 +-- tests/mkfs-tests/001-basic-profiles/test.sh | 3 +-- tests/mkfs-tests/005-long-device-name-for-ssd/test.sh | 3 +-- tests/mkfs-tests/006-partitioned-loopdev/test.sh | 3 +-- tests/mkfs-tests/007-mix-nodesize-sectorsize/test.sh | 3 +-- 13 files changed, 22 insertions(+), 36 deletions(-) (limited to 'tests') diff --git a/tests/common.convert b/tests/common.convert index a80948d7..dcf0868c 100644 --- a/tests/common.convert +++ b/tests/common.convert @@ -176,7 +176,7 @@ convert_test_acl() { convert_test_do_convert() { run_check $TOP/btrfs-convert ${1:+-O "$1"} ${2:+-N "$2"} $TEST_DEV run_check $TOP/btrfs check $TEST_DEV - run_check $TOP/btrfs-show-super -Ffa $TEST_DEV + run_check $TOP/btrfs inspect-internal dump-super -Ffa $TEST_DEV } # post conversion check, verify file permissions. diff --git a/tests/convert-tests/004-ext2-backup-superblock-ranges/test.sh b/tests/convert-tests/004-ext2-backup-superblock-ranges/test.sh index d85e4de4..c56650b2 100755 --- a/tests/convert-tests/004-ext2-backup-superblock-ranges/test.sh +++ b/tests/convert-tests/004-ext2-backup-superblock-ranges/test.sh @@ -14,7 +14,6 @@ source $TOP/tests/common check_prereq btrfs-convert check_prereq btrfs -check_prereq btrfs-show-super check_global_prereq e2fsck check_global_prereq xzcat @@ -27,7 +26,7 @@ function check_image() { run_check e2fsck -n -f $TEST_DEV run_check $TOP/btrfs-convert $TEST_DEV run_check $TOP/btrfs check $TEST_DEV - run_check $TOP/btrfs-show-super $TEST_DEV + run_check $TOP/btrfs inspect-internal dump-super $TEST_DEV run_check_mount_test_dev run_check $SUDO_HELPER e2fsck -n -f $TEST_MNT/ext2_saved/image diff --git a/tests/fsck-tests/013-extent-tree-rebuild/test.sh b/tests/fsck-tests/013-extent-tree-rebuild/test.sh index ff7d28e5..f678e29b 100755 --- a/tests/fsck-tests/013-extent-tree-rebuild/test.sh +++ b/tests/fsck-tests/013-extent-tree-rebuild/test.sh @@ -3,7 +3,6 @@ source $TOP/tests/common check_prereq btrfs-corrupt-block -check_prereq btrfs-debug-tree check_prereq mkfs.btrfs check_prereq btrfs @@ -25,7 +24,7 @@ test_extent_tree_rebuild() run_check_umount_test_dev # get extent root bytenr - extent_root_bytenr=`$SUDO_HELPER $TOP/btrfs-debug-tree -r $TEST_DEV | \ + extent_root_bytenr=`$SUDO_HELPER $TOP/btrfs inspect-internal dump-tree -r $TEST_DEV | \ grep extent | awk '{print $7}'` if [ -z $extent_root_bytenr ];then _fail "fail to get extent root bytenr" diff --git a/tests/misc-tests/001-btrfstune-features/test.sh b/tests/misc-tests/001-btrfstune-features/test.sh index c858d701..bfa7f43e 100755 --- a/tests/misc-tests/001-btrfstune-features/test.sh +++ b/tests/misc-tests/001-btrfstune-features/test.sh @@ -3,8 +3,6 @@ source $TOP/tests/common -check_prereq btrfs-debug-tree -check_prereq btrfs-show-super check_prereq mkfs.btrfs check_prereq btrfstune check_prereq btrfs @@ -16,7 +14,7 @@ prepare_test_dev # parameters: # - option for mkfs.btrfs -O, empty for defaults # - option for btrfstune -# - string representing the feature in btrfs-show-super dump +# - string representing the feature in dump-super output test_feature() { local mkfsfeatures @@ -28,12 +26,12 @@ test_feature() sbflag="$3" run_check $SUDO_HELPER $TOP/mkfs.btrfs -f $mkfsfeatures $TEST_DEV - if run_check_stdout $TOP/btrfs-show-super $TEST_DEV | \ + if run_check_stdout $TOP/btrfs inspect-internal dump-super $TEST_DEV | \ grep -q "$sbflag"; then _fail "FAIL: feature $sbflag must not be set on the base image" fi run_check $TOP/btrfstune $tuneopt $TEST_DEV - if ! run_check_stdout $TOP/btrfs-show-super $TEST_DEV | \ + if ! run_check_stdout $TOP/btrfs inspect-internal dump-super $TEST_DEV | \ grep -q "$sbflag"; then _fail "FAIL: feature $sbflag not set" fi diff --git a/tests/misc-tests/002-uuid-rewrite/test.sh b/tests/misc-tests/002-uuid-rewrite/test.sh index d84ec6ca..fd100fb3 100755 --- a/tests/misc-tests/002-uuid-rewrite/test.sh +++ b/tests/misc-tests/002-uuid-rewrite/test.sh @@ -3,8 +3,6 @@ source $TOP/tests/common -check_prereq btrfs-debug-tree -check_prereq btrfs-show-super check_prereq mkfs.btrfs check_prereq btrfstune check_prereq btrfs @@ -15,7 +13,7 @@ get_fs_uuid() { local image image="$1" - run_check_stdout $TOP/btrfs-show-super "$image" | \ + run_check_stdout $TOP/btrfs inspect-internal dump-super "$image" | \ grep '^fsid' | awk '{print $2}' } @@ -29,13 +27,13 @@ test_uuid_random() --uuid $origuuid \ --rootdir $TOP/Documentation \ $TEST_DEV - run_check $TOP/btrfs-show-super "$TEST_DEV" + run_check $TOP/btrfs inspect-internal dump-super "$TEST_DEV" currentfsid=$(run_check_stdout $TOP/btrfstune -f -u $TEST_DEV | \ grep -i 'current fsid:' | awk '{print $3}') if ! [ $currentfsid = $origuuid ]; then _fail "FAIL: current UUID mismatch" fi - run_check $TOP/btrfs-show-super "$TEST_DEV" + run_check $TOP/btrfs inspect-internal dump-super "$TEST_DEV" run_check $SUDO_HELPER $TOP/btrfs check $TEST_DEV } @@ -51,10 +49,10 @@ test_uuid_user() --uuid $origuuid \ --rootdir $TOP/Documentation \ $TEST_DEV - run_check $TOP/btrfs-show-super "$TEST_DEV" + run_check $TOP/btrfs inspect-internal dump-super "$TEST_DEV" run_check $TOP/btrfstune -f -U $newuuid \ $TEST_DEV - # btrfs-show-super is called within get_fs_uuid + # btrfs inspect-internal dump-super is called within get_fs_uuid fsid=$(get_fs_uuid $TEST_DEV) if ! [ $fsid = $newuuid ]; then _fail "FAIL: UUID not rewritten" diff --git a/tests/misc-tests/003-zero-log/test.sh b/tests/misc-tests/003-zero-log/test.sh index b650930e..e7c5c806 100755 --- a/tests/misc-tests/003-zero-log/test.sh +++ b/tests/misc-tests/003-zero-log/test.sh @@ -3,7 +3,6 @@ source $TOP/tests/common -check_prereq btrfs-show-super check_prereq mkfs.btrfs check_prereq btrfs prepare_test_dev @@ -13,14 +12,14 @@ get_log_root() local image image="$1" - $TOP/btrfs-show-super "$image" | \ + $TOP/btrfs inspect-internal dump-super "$image" | \ grep '^log_root\>' | awk '{print $2}' } get_log_root_level() { local image image="$1" - $TOP/btrfs-show-super "$image" | \ + $TOP/btrfs inspect-internal dump-super "$image" | \ grep '^log_root_level' | awk '{print $2}' } @@ -30,7 +29,7 @@ test_zero_log() run_check $SUDO_HELPER $TOP/mkfs.btrfs -f \ --rootdir $TOP/Documentation \ $TEST_DEV - run_check $TOP/btrfs-show-super $TEST_DEV + run_check $TOP/btrfs inspect-internal dump-super $TEST_DEV if [ "$1" = 'standalone' ]; then run_check $TOP/btrfs rescue zero-log $TEST_DEV else @@ -44,7 +43,7 @@ test_zero_log() if [ "$log_root_level" != 0 ]; then _fail "FAIL: log_root_level not reset" fi - run_check $TOP/btrfs-show-super $TEST_DEV + run_check $TOP/btrfs inspect-internal dump-super $TEST_DEV run_check $SUDO_HELPER $TOP/btrfs check $TEST_DEV } diff --git a/tests/misc-tests/006-image-on-missing-device/test.sh b/tests/misc-tests/006-image-on-missing-device/test.sh index b22a95d7..83a6a056 100755 --- a/tests/misc-tests/006-image-on-missing-device/test.sh +++ b/tests/misc-tests/006-image-on-missing-device/test.sh @@ -6,7 +6,6 @@ source $TOP/tests/common -check_prereq btrfs-show-super check_prereq btrfs-image check_prereq mkfs.btrfs check_prereq btrfs diff --git a/tests/misc-tests/010-convert-delete-ext2-subvol/test.sh b/tests/misc-tests/010-convert-delete-ext2-subvol/test.sh index 451e453a..7bf7be34 100755 --- a/tests/misc-tests/010-convert-delete-ext2-subvol/test.sh +++ b/tests/misc-tests/010-convert-delete-ext2-subvol/test.sh @@ -6,7 +6,6 @@ source $TOP/tests/common check_prereq btrfs-convert -check_prereq btrfs-debug-tree check_prereq btrfs setup_root_helper @@ -15,11 +14,11 @@ prepare_test_dev run_check truncate -s 2G "$TEST_DEV" run_check mkfs.ext4 -F "$TEST_DEV" run_check $TOP/btrfs-convert "$TEST_DEV" -run_check $TOP/btrfs-debug-tree "$TEST_DEV" +run_check $TOP/btrfs inspect-internal dump-tree "$TEST_DEV" run_check_mount_test_dev run_check $SUDO_HELPER $TOP/btrfs subvolume delete -c "$TEST_MNT/ext2_saved" run_check_umount_test_dev -run_check $TOP/btrfs-debug-tree "$TEST_DEV" +run_check $TOP/btrfs inspect-internal dump-tree "$TEST_DEV" run_check_stdout $TOP/btrfs-convert --rollback "$TEST_DEV" | grep -q 'is it deleted' || _fail "unexpected rollback" diff --git a/tests/misc-tests/011-delete-missing-device/test.sh b/tests/misc-tests/011-delete-missing-device/test.sh index 26645f10..57e88745 100755 --- a/tests/misc-tests/011-delete-missing-device/test.sh +++ b/tests/misc-tests/011-delete-missing-device/test.sh @@ -3,7 +3,6 @@ source $TOP/tests/common -check_prereq btrfs-show-super check_prereq mkfs.btrfs check_prereq btrfs @@ -39,7 +38,7 @@ cleanup_devices() test_do_mkfs() { run_check $SUDO_HELPER $TOP/mkfs.btrfs -f $@ ${devs[@]} - run_check $TOP/btrfs-show-super $dev1 + run_check $TOP/btrfs inspect-internal dump-super $dev1 run_check $SUDO_HELPER $TOP/btrfs check $dev1 run_check $TOP/btrfs filesystem show } diff --git a/tests/mkfs-tests/001-basic-profiles/test.sh b/tests/mkfs-tests/001-basic-profiles/test.sh index a6769214..e893887f 100755 --- a/tests/mkfs-tests/001-basic-profiles/test.sh +++ b/tests/mkfs-tests/001-basic-profiles/test.sh @@ -4,7 +4,6 @@ source $TOP/tests/common -check_prereq btrfs-show-super check_prereq mkfs.btrfs check_prereq btrfs @@ -38,7 +37,7 @@ cleanup_devices() test_get_info() { - run_check $TOP/btrfs-show-super $dev1 + run_check $TOP/btrfs inspect-internal dump-super $dev1 run_check $SUDO_HELPER $TOP/btrfs check $dev1 run_check $SUDO_HELPER mount $dev1 $TEST_MNT run_check $TOP/btrfs filesystem df $TEST_MNT diff --git a/tests/mkfs-tests/005-long-device-name-for-ssd/test.sh b/tests/mkfs-tests/005-long-device-name-for-ssd/test.sh index cff495e6..20387b83 100755 --- a/tests/mkfs-tests/005-long-device-name-for-ssd/test.sh +++ b/tests/mkfs-tests/005-long-device-name-for-ssd/test.sh @@ -4,7 +4,6 @@ source $TOP/tests/common check_prereq mkfs.btrfs -check_prereq btrfs-show-super setup_root_helper prepare_test_dev @@ -33,7 +32,7 @@ run_check cat $rot # test run_check_stdout $SUDO_HELPER $TOP/mkfs.btrfs -f $@ $dmdev | grep -q 'SSD detected:.*yes' || _fail 'SSD not detected' -run_check $TOP/btrfs-show-super $dmdev +run_check $TOP/btrfs inspect-internal dump-super $dmdev # cleanup run_check $SUDO_HELPER dmsetup remove $dmname diff --git a/tests/mkfs-tests/006-partitioned-loopdev/test.sh b/tests/mkfs-tests/006-partitioned-loopdev/test.sh index 7c9fb829..e40dc675 100755 --- a/tests/mkfs-tests/006-partitioned-loopdev/test.sh +++ b/tests/mkfs-tests/006-partitioned-loopdev/test.sh @@ -4,7 +4,6 @@ source $TOP/tests/common check_prereq mkfs.btrfs -check_prereq btrfs-show-super setup_root_helper @@ -19,7 +18,7 @@ base=$(basename $loopdev) # expect partitions named like loop0p1 etc for looppart in $(ls /dev/$base?*); do run_check $SUDO_HELPER $TOP/mkfs.btrfs -f $looppart - run_check $TOP/btrfs-show-super $looppart + run_check $TOP/btrfs inspect-internal dump-super $looppart done # cleanup diff --git a/tests/mkfs-tests/007-mix-nodesize-sectorsize/test.sh b/tests/mkfs-tests/007-mix-nodesize-sectorsize/test.sh index d5374cbd..29d9be14 100755 --- a/tests/mkfs-tests/007-mix-nodesize-sectorsize/test.sh +++ b/tests/mkfs-tests/007-mix-nodesize-sectorsize/test.sh @@ -3,7 +3,6 @@ source $TOP/tests/common -check_prereq btrfs-show-super check_prereq mkfs.btrfs check_prereq btrfs @@ -13,7 +12,7 @@ prepare_test_dev test_mkfs_single() { run_check $SUDO_HELPER $TOP/mkfs.btrfs -f "$@" $TEST_DEV - run_check $TOP/btrfs-show-super $TEST_DEV + run_check $TOP/btrfs inspect-internal dump-super $TEST_DEV run_check $SUDO_HELPER $TOP/btrfs check $TEST_DEV } -- cgit v1.2.3 From 29a1a78aaacbd02e59f61b25bd2b25244e948d5d Mon Sep 17 00:00:00 2001 From: David Sterba Date: Wed, 2 Nov 2016 13:07:15 +0100 Subject: btrfs-progs: tests: add test for multi-subvolume send from parent Fixed by "btrfs-progs: send: fix handling of multiple snapshots (-p option)". Signed-off-by: David Sterba --- .../cli-tests/004-send-parent-multi-subvol/test.sh | 34 ++++++++++++++++++++++ 1 file changed, 34 insertions(+) create mode 100755 tests/cli-tests/004-send-parent-multi-subvol/test.sh (limited to 'tests') diff --git a/tests/cli-tests/004-send-parent-multi-subvol/test.sh b/tests/cli-tests/004-send-parent-multi-subvol/test.sh new file mode 100755 index 00000000..e9ccf225 --- /dev/null +++ b/tests/cli-tests/004-send-parent-multi-subvol/test.sh @@ -0,0 +1,34 @@ +#!/bin/bash +# +# minimal test for the following syntax: btrfs send -p parent subvol1 subvol2 + +source $TOP/tests/common + +check_prereq mkfs.btrfs +check_prereq btrfs + +setup_root_helper +prepare_test_dev 2g + +run_check $TOP/mkfs.btrfs -f $IMAGE +run_check_mount_test_dev + +here=`pwd` +cd "$TEST_MNT" || _fail "cannot chdir to TEST_MNT" + +run_check $SUDO_HELPER btrfs subvolume create subv-parent +run_check $SUDO_HELPER dd if=/dev/urandom of=subv-parent/file bs=1M count=10 +run_check $SUDO_HELPER btrfs subvolume snapshot -r subv-parent subv-snap1 +run_check $SUDO_HELPER dd if=/dev/urandom of=subv-parent/file bs=1M count=10 +run_check $SUDO_HELPER btrfs subvolume snapshot -r subv-parent subv-snap2 +run_check $SUDO_HELPER dd if=/dev/urandom of=subv-parent/file bs=1M count=10 +run_check $SUDO_HELPER btrfs subvolume snapshot -r subv-parent subv-snap3 + +run_check truncate -s0 "$here"/send.stream +run_check chmod a+w "$here"/send.stream +run_check $SUDO_HELPER $TOP/btrfs send -f "$here"/send.stream -p subv-snap1 subv-snap2 subv-snap3 + +cd "$here" || _fail "cannot chdir back to test directory" +rm send.stream + +run_check_umount_test_dev -- cgit v1.2.3 From 0bd0d9c062d1b02978161c356057122c865f5ad0 Mon Sep 17 00:00:00 2001 From: David Sterba Date: Mon, 7 Nov 2016 13:21:34 +0100 Subject: btrfs-progs: tests: teach scan-results about more errors ASAN detects use after free. Signed-off-by: David Sterba --- tests/scan-results.sh | 2 ++ 1 file changed, 2 insertions(+) (limited to 'tests') diff --git a/tests/scan-results.sh b/tests/scan-results.sh index 743b968b..f3ebcbc4 100755 --- a/tests/scan-results.sh +++ b/tests/scan-results.sh @@ -10,6 +10,8 @@ for i in *.txt; do ===\ Entering*) last="$line" ;; *Assertion*failed*) echo "ASSERTION FAILED: $last" ;; *runtime\ error*) echo "RUNTIME ERROR (sanitizer): $last" ;; + *AddressSanitizer*heap-use-after-free*) echo "RUNTIME ERROR (use after free): $last" ;; + *Warning:\ assertion*failed*) echo "ASSERTION WARNING: $last" ;; *) : ;; esac done < "$i" -- cgit v1.2.3 From 45827710e2b9ce7351b2959efcced922752d2e3c Mon Sep 17 00:00:00 2001 From: David Sterba Date: Wed, 9 Nov 2016 11:39:02 +0100 Subject: btrfs-progs: tests: teach extract_image about packed streams Packed streams for testing purposes should be packed with 'xz -9' and use suffix .stream.xz . Signed-off-by: David Sterba --- tests/common | 7 +++++++ 1 file changed, 7 insertions(+) (limited to 'tests') diff --git a/tests/common b/tests/common index 264424d3..420286d6 100644 --- a/tests/common +++ b/tests/common @@ -128,6 +128,7 @@ check_image() # - dtto compressed by XZ, suffix .raw.xz # - meta-dump images with suffix .img # - dtto compressed by XZ, suffix .img.xz +# - compressed send stream, .stream.xz extract_image() { local image @@ -154,6 +155,12 @@ extract_image() image=${image%%.xz} mv "$image" "$image".restored ;; + *.stream.xz) + xz --decompress --keep "$image" || \ + _fail "failed to decompress file $image" >&2 + image=${image%%.xz} + mv "$image" "$image".restored + ;; esac if ! [ -f $image.restored ]; then -- cgit v1.2.3 From f529d6472e09066ab8a2fd8e730f1e8c2acf04d8 Mon Sep 17 00:00:00 2001 From: Tsutomu Itoh Date: Wed, 9 Nov 2016 13:44:15 +0900 Subject: btrfs-progs: tests: add checking of send multiple clone source option Sending stream size of clone-src(-c) option is checked. Fixed by "btrfs-progs: send: fix handling of -c option". Signed-off-by: Tsutomu Itoh Signed-off-by: David Sterba --- .../multi-clone-src-v4.8.2.stream.xz | Bin 0 -> 2688 bytes tests/misc-tests/016-send-clone-src/test.sh | 50 +++++++++++++++++++++ 2 files changed, 50 insertions(+) create mode 100644 tests/misc-tests/016-send-clone-src/multi-clone-src-v4.8.2.stream.xz create mode 100755 tests/misc-tests/016-send-clone-src/test.sh (limited to 'tests') diff --git a/tests/misc-tests/016-send-clone-src/multi-clone-src-v4.8.2.stream.xz b/tests/misc-tests/016-send-clone-src/multi-clone-src-v4.8.2.stream.xz new file mode 100644 index 00000000..34c14ed5 Binary files /dev/null and b/tests/misc-tests/016-send-clone-src/multi-clone-src-v4.8.2.stream.xz differ diff --git a/tests/misc-tests/016-send-clone-src/test.sh b/tests/misc-tests/016-send-clone-src/test.sh new file mode 100755 index 00000000..e256eef9 --- /dev/null +++ b/tests/misc-tests/016-send-clone-src/test.sh @@ -0,0 +1,50 @@ +#!/bin/bash +# +# test for sending stream size of clone-src option, compare against a send +# stream generated by buggy version + +source $TOP/tests/common + +check_prereq mkfs.btrfs +check_prereq btrfs + +setup_root_helper +prepare_test_dev 1g + +run_check $TOP/mkfs.btrfs -f $IMAGE +run_check_mount_test_dev + +here=`pwd` +cd "$TEST_MNT" || _fail "cannot chdir to TEST_MNT" + +run_check $SUDO_HELPER $TOP/btrfs subvolume create subv-parent1 +for i in 1 2 3; do + run_check $SUDO_HELPER dd if=/dev/zero of=subv-parent1/file1_$i bs=1M count=1 + run_check $SUDO_HELPER $TOP/btrfs subvolume snapshot -r subv-parent1 subv-snap1_$i +done + +run_check $SUDO_HELPER $TOP/btrfs subvolume create subv-parent2 +for i in 1 2 3; do + run_check $SUDO_HELPER dd if=/dev/zero of=subv-parent2/file2_$i bs=1M count=1 + run_check $SUDO_HELPER $TOP/btrfs subvolume snapshot -r subv-parent2 subv-snap2_$i +done + +truncate -s0 "$here"/send-stream.img +chmod a+w "$here"/send-stream.img +run_check $SUDO_HELPER $TOP/btrfs send -f "$here"/send-stream.img \ + -c subv-snap1_1 -c subv-snap2_1 subv-snap1_[23] subv-snap2_[23] + +image=$(extract_image "$here"/multi-clone-src-v4.8.2.stream.xz) +old_stream_size=`stat --format=%s "$image"` +stream_size=`stat --format=%s "$here"/send-stream.img` + +if [ $old_stream_size -lt $stream_size ]; then + run_check ls -l "$image" "$here"/send-stream.img + _fail "sending stream size is bigger than old stream" +fi + +run_check rm -f -- "$image" "$here"/send-stream.img + +cd "$here" || _fail "cannot chdir back to test directory" + +run_check_umount_test_dev -- cgit v1.2.3 From 4ad7a967d1bcbb77b12b610b9db3ee07518ddb83 Mon Sep 17 00:00:00 2001 From: David Sterba Date: Thu, 10 Nov 2016 18:57:38 +0100 Subject: btrfs-progs: tests: check if kernel has btrfs support Add some sanity checks, reported among other issues via bugzilla. References: https://bugzilla.kernel.org/show_bug.cgi?id=177141 Signed-off-by: David Sterba --- tests/cli-tests.sh | 1 + tests/common | 10 ++++++++++ tests/convert-tests.sh | 2 ++ tests/fsck-tests.sh | 1 + tests/misc-tests.sh | 1 + tests/mkfs-tests.sh | 1 + 6 files changed, 16 insertions(+) (limited to 'tests') diff --git a/tests/cli-tests.sh b/tests/cli-tests.sh index 72f7865a..86dda87b 100755 --- a/tests/cli-tests.sh +++ b/tests/cli-tests.sh @@ -20,6 +20,7 @@ export TEST_DEV rm -f $RESULTS check_prereq btrfs +check_kernel_support # The tests are driven by their custom script called 'test.sh' diff --git a/tests/common b/tests/common index 420286d6..c20fec88 100644 --- a/tests/common +++ b/tests/common @@ -280,10 +280,20 @@ run_check_umount_test_dev() run_check $SUDO_HELPER umount "$@" "$TEST_DEV" } +check_kernel_support() +{ + if ! grep -iq 'btrfs' /proc/filesystems; then + echo "WARNING: btrfs filesystem not listed in /proc/filesystems, some tests might fail" + return 1 + fi + return 0 +} + init_env() { TEST_MNT="${TEST_MNT:-$TOP/tests/mnt}" export TEST_MNT mkdir -p "$TEST_MNT" || { echo "Failed mkdir -p $TEST_MNT"; exit 1; } + } init_env diff --git a/tests/convert-tests.sh b/tests/convert-tests.sh index 0e025f99..db149724 100755 --- a/tests/convert-tests.sh +++ b/tests/convert-tests.sh @@ -21,6 +21,8 @@ export TEST_DEV rm -f $RESULTS +check_kernel_support + run_one_test() { local testdir local testname diff --git a/tests/fsck-tests.sh b/tests/fsck-tests.sh index d1cd7329..69ec57a0 100755 --- a/tests/fsck-tests.sh +++ b/tests/fsck-tests.sh @@ -23,6 +23,7 @@ rm -f $RESULTS check_prereq btrfs-corrupt-block check_prereq btrfs-image check_prereq btrfs +check_kernel_support run_one_test() { local testname diff --git a/tests/misc-tests.sh b/tests/misc-tests.sh index eefe8a81..fd19c2f9 100755 --- a/tests/misc-tests.sh +++ b/tests/misc-tests.sh @@ -24,6 +24,7 @@ check_prereq btrfs-corrupt-block check_prereq btrfs-image check_prereq btrfstune check_prereq btrfs +check_kernel_support # The tests are driven by their custom script called 'test.sh' diff --git a/tests/mkfs-tests.sh b/tests/mkfs-tests.sh index 1afc0282..3c5465fa 100755 --- a/tests/mkfs-tests.sh +++ b/tests/mkfs-tests.sh @@ -21,6 +21,7 @@ rm -f $RESULTS check_prereq mkfs.btrfs check_prereq btrfs +check_kernel_support # The tests are driven by their custom script called 'test.sh' -- cgit v1.2.3 From 66b9b36805d7a932001983903ae2f7f5ce0c6107 Mon Sep 17 00:00:00 2001 From: David Sterba Date: Fri, 11 Nov 2016 01:27:39 +0100 Subject: btrfs-progs: tests: refactor post-convert check helpers Separate checksum test from convert_test_post_check and use it to fix the broken test 005 as reported. References: https://bugzilla.kernel.org/show_bug.cgi?id=177141 Signed-off-by: David Sterba --- tests/common.convert | 18 +++++++++++++----- tests/convert-tests/005-delete-all-rollback/test.sh | 13 ++++++++++--- 2 files changed, 23 insertions(+), 8 deletions(-) (limited to 'tests') diff --git a/tests/common.convert b/tests/common.convert index dcf0868c..1b5217c3 100644 --- a/tests/common.convert +++ b/tests/common.convert @@ -223,11 +223,21 @@ convert_test_post_check_acl() { rm -- $BTRFS_ACLTMP } + # post conversion checks, verify md5sums +convert_test_post_check_checksums() { + local CHECKSUMTMP + + CHECKSUMTMP="$1" + run_check_stdout $SUDO_HELPER md5sum -c "$CHECKSUMTMP" | + grep -q 'FAILED' && _fail "file validation failed" +} + +# post conversion checks, all three in one call, on an unmounted image # $1: file with checksums # $2: file with permissions. # $3: file with acl entries. -convert_test_post_check() { +convert_test_post_checks_all() { local CHECKSUMTMP local EXT_PERMTMP local EXT_ACLTMP @@ -235,10 +245,8 @@ convert_test_post_check() { CHECKSUMTMP="$1" EXT_PERMTMP="$2" EXT_ACLTMP="$3" - run_check_mount_test_dev - run_check_stdout $SUDO_HELPER md5sum -c "$CHECKSUMTMP" | - grep -q 'FAILED' && _fail "file validation failed" + convert_test_post_check_checksums "$CHECKSUMTMP" convert_test_post_check_permissions "$EXT_PERMTMP" convert_test_post_check_acl "$EXT_ACLTMP" run_check_umount_test_dev @@ -280,7 +288,7 @@ convert_test() { run_check_umount_test_dev convert_test_do_convert "$features" "$nodesize" - convert_test_post_check "$CHECKSUMTMP" "$EXT_PERMTMP" "$EXT_ACLTMP" + convert_test_post_checks_all "$CHECKSUMTMP" "$EXT_PERMTMP" "$EXT_ACLTMP" rm $CHECKSUMTMP rm $EXT_PERMTMP rm $EXT_ACLTMP diff --git a/tests/convert-tests/005-delete-all-rollback/test.sh b/tests/convert-tests/005-delete-all-rollback/test.sh index d498e5f8..cf576e70 100755 --- a/tests/convert-tests/005-delete-all-rollback/test.sh +++ b/tests/convert-tests/005-delete-all-rollback/test.sh @@ -34,9 +34,10 @@ do_test() { run_check_umount_test_dev convert_test_do_convert "$features" "$nodesize" - convert_test_post_check "$CHECKSUMTMP" run_check_mount_test_dev + convert_test_post_check_checksums "$CHECKSUMTMP" + here=$(pwd) cd "$TEST_MNT" || _fail "cannot cd to TEST_MNT" # ext2_saved/image must not be deleted @@ -45,10 +46,16 @@ do_test() { run_check $TOP/btrfs filesystem sync "$TEST_MNT" run_check_umount_test_dev convert_test_post_rollback - convert_test_post_check "$CHECKSUMTMP" + + run_check_mount_test_dev + convert_test_post_check_checksums "$CHECKSUMTMP" + run_check_umount_test_dev # mount again and verify checksums - convert_test_post_check "$CHECKSUMTMP" + run_check_mount_test_dev + convert_test_post_check_checksums "$CHECKSUMTMP" + run_check_umount_test_dev + rm "$CHECKSUMTMP" } -- cgit v1.2.3 From 8a44fd062ab24155e9438f72de75cd5eb2e3af58 Mon Sep 17 00:00:00 2001 From: David Sterba Date: Fri, 11 Nov 2016 01:18:49 +0100 Subject: btrfs-progs: tests: add assertion helper Helper to extend sanity checks in various functions. Signed-off-by: David Sterba --- tests/common | 18 ++++++++++++++++++ 1 file changed, 18 insertions(+) (limited to 'tests') diff --git a/tests/common b/tests/common index c20fec88..320b023f 100644 --- a/tests/common +++ b/tests/common @@ -3,6 +3,24 @@ # Common routines for all tests # +# assert that argument is not empty and is an existing path (file or directory) +_assert_path() +{ + local path + + path="$1" + if [ -z "$path" ]; then + echo "ASSERTION FAIL: $path is not valid" + exit 1 + fi + + if [ -f "$path" -o -d "$path" -o -b "$path" ]; then + return 0 + fi + echo "ASSERTION FAIL: $path is not valid" + exit 1 +} + _fail() { echo "$*" | tee -a $RESULTS -- cgit v1.2.3 From 747146e23748095e46e2f3f023afc6310fb91c83 Mon Sep 17 00:00:00 2001 From: David Sterba Date: Fri, 11 Nov 2016 08:40:21 +0100 Subject: btrfs-progs: tests: add path assertions to post-checks Signed-off-by: David Sterba --- tests/common.convert | 30 ++++++++++++++---------------- 1 file changed, 14 insertions(+), 16 deletions(-) (limited to 'tests') diff --git a/tests/common.convert b/tests/common.convert index 1b5217c3..0d22949c 100644 --- a/tests/common.convert +++ b/tests/common.convert @@ -130,17 +130,18 @@ convert_test_prep_fs() { # generate md5 checksums of files on $TEST_MNT # $1: path where the checksums will be stored convert_test_gen_checksums() { - local CHECKSUMTMP - CHECKSUMTMP="$1" + _assert_path "$1" run_check $SUDO_HELPER dd if=/dev/zero of=$TEST_MNT/test bs=$nodesize \ count=1 >/dev/null 2>&1 - run_check_stdout $SUDO_HELPER find $TEST_MNT -type f ! -name 'image' -exec md5sum {} \+ > "$CHECKSUMTMP" + run_check_stdout $SUDO_HELPER find $TEST_MNT -type f ! -name 'image' -exec md5sum {} \+ > "$1" } # list $TEST_MNT data set file permissions. # $1: path where the permissions will be stored convert_test_perm() { local PERMTMP + + _assert_path "$1" PERMTMP="$1" FILES_LIST=$(mktemp --tmpdir btrfs-progs-convert.fileslistXXXXXX) @@ -185,6 +186,7 @@ convert_test_post_check_permissions() { local EXT_PERMTMP local BTRFS_PERMTMP + _assert_path "$1" EXT_PERMTMP="$1" BTRFS_PERMTMP=$(mktemp --tmpdir btrfs-progs-convert.permXXXXXX) convert_test_perm "$BTRFS_PERMTMP" @@ -207,6 +209,7 @@ convert_test_post_check_acl() { local EXT_ACLTMP local BTRFS_ACLTMP + _assert_path "$1" EXT_ACLTMP="$1" BTRFS_ACLTMP=$(mktemp --tmpdir btrfs-progs-convert.aclsXXXXXXX) convert_test_acl "$BTRFS_ACLTMP" @@ -226,10 +229,8 @@ convert_test_post_check_acl() { # post conversion checks, verify md5sums convert_test_post_check_checksums() { - local CHECKSUMTMP - - CHECKSUMTMP="$1" - run_check_stdout $SUDO_HELPER md5sum -c "$CHECKSUMTMP" | + _assert_path "$1" + run_check_stdout $SUDO_HELPER md5sum -c "$1" | grep -q 'FAILED' && _fail "file validation failed" } @@ -238,17 +239,14 @@ convert_test_post_check_checksums() { # $2: file with permissions. # $3: file with acl entries. convert_test_post_checks_all() { - local CHECKSUMTMP - local EXT_PERMTMP - local EXT_ACLTMP + _assert_path "$1" + _assert_path "$2" + _assert_path "$3" - CHECKSUMTMP="$1" - EXT_PERMTMP="$2" - EXT_ACLTMP="$3" run_check_mount_test_dev - convert_test_post_check_checksums "$CHECKSUMTMP" - convert_test_post_check_permissions "$EXT_PERMTMP" - convert_test_post_check_acl "$EXT_ACLTMP" + convert_test_post_check_checksums "$1" + convert_test_post_check_permissions "$2" + convert_test_post_check_acl "$3" run_check_umount_test_dev } -- cgit v1.2.3 From cc0d3d3198e969692826a3bd5935e966acb15d16 Mon Sep 17 00:00:00 2001 From: David Sterba Date: Fri, 11 Nov 2016 10:04:26 +0100 Subject: btrfs-progs: tests: add quotes around variables in common Signed-off-by: David Sterba --- tests/common | 64 ++++++++++++++++++++++++++++++------------------------------ 1 file changed, 32 insertions(+), 32 deletions(-) (limited to 'tests') diff --git a/tests/common b/tests/common index 320b023f..c8ac0c15 100644 --- a/tests/common +++ b/tests/common @@ -23,14 +23,14 @@ _assert_path() _fail() { - echo "$*" | tee -a $RESULTS + echo "$*" | tee -a "$RESULTS" exit 1 } # log a message to the results file _log() { - echo "$*" | tee -a $RESULTS + echo "$*" | tee -a "$RESULTS" } _not_run() @@ -41,12 +41,12 @@ _not_run() run_check() { - echo "############### $@" >> $RESULTS 2>&1 + echo "############### $@" >> "$RESULTS" 2>&1 if [ "$TEST_LOG" = 'tty' ]; then echo "CMD: $@" > /dev/tty; fi if [ "$1" = 'root_helper' ]; then - "$@" >> $RESULTS 2>&1 || _fail "failed: $@" + "$@" >> "$RESULTS" 2>&1 || _fail "failed: $@" else - $INSTRUMENT "$@" >> $RESULTS 2>&1 || _fail "failed: $@" + $INSTRUMENT "$@" >> "$RESULTS" 2>&1 || _fail "failed: $@" fi } @@ -54,12 +54,12 @@ run_check() # can be processed further run_check_stdout() { - echo "############### $@" >> $RESULTS 2>&1 + echo "############### $@" >> "$RESULTS" 2>&1 if [ "$TEST_LOG" = 'tty' ]; then echo "CMD(stdout): $@" > /dev/tty; fi if [ "$1" = 'root_helper' ]; then - "$@" 2>&1 | tee -a $RESULTS || _fail "failed: $@" + "$@" 2>&1 | tee -a "$RESULTS" || _fail "failed: $@" else - $INSTRUMENT "$@" 2>&1 | tee -a $RESULTS || _fail "failed: $@" + $INSTRUMENT "$@" 2>&1 | tee -a "$RESULTS" || _fail "failed: $@" fi } @@ -68,16 +68,16 @@ run_mayfail() { local ret - echo "############### $@" >> $RESULTS 2>&1 + echo "############### $@" >> "$RESULTS" 2>&1 if [ "$TEST_LOG" = 'tty' ]; then echo "CMD(mayfail): $@" > /dev/tty; fi if [ "$1" = 'root_helper' ]; then "$@" >> $RESULTS 2>&1 else - $INSTRUMENT "$@" >> $RESULTS 2>&1 + $INSTRUMENT "$@" >> "$RESULTS" 2>&1 fi ret=$? if [ $ret != 0 ]; then - echo "failed (ignored, ret=$ret): $@" >> $RESULTS + echo "failed (ignored, ret=$ret): $@" >> "$RESULTS" if [ $ret == 139 ]; then _fail "mayfail: returned code 139 (SEGFAULT), not ignored" elif [ $ret == 134 ]; then @@ -96,18 +96,18 @@ run_mustfail() msg="$1" shift - echo "############### $@" >> $RESULTS 2>&1 + echo "############### $@" >> "$RESULTS" 2>&1 if [ "$TEST_LOG" = 'tty' ]; then echo "CMD(mustfail): $@" > /dev/tty; fi if [ "$1" = 'root_helper' ]; then - "$@" >> $RESULTS 2>&1 + "$@" >> "$RESULTS" 2>&1 else - $INSTRUMENT "$@" >> $RESULTS 2>&1 + $INSTRUMENT "$@" >> "$RESULTS" 2>&1 fi if [ $? != 0 ]; then - echo "failed (expected): $@" >> $RESULTS + echo "failed (expected): $@" >> "$RESULTS" return 0 else - echo "succeeded (unexpected!): $@" >> $RESULTS + echo "succeeded (unexpected!): $@" >> "$RESULTS" _fail "unexpected success: $msg" return 1 fi @@ -115,7 +115,7 @@ run_mustfail() check_prereq() { - if ! [ -f $TOP/$1 ]; then + if ! [ -f "$TOP/$1" ]; then _fail "Failed prerequisites: $1"; fi } @@ -133,12 +133,12 @@ check_image() local image image=$1 - echo "testing image $(basename $image)" >> $RESULTS - $TOP/btrfs check $image >> $RESULTS 2>&1 + echo "testing image $(basename $image)" >> "$RESULTS" + $TOP/btrfs check "$image" >> "$RESULTS" 2>&1 [ $? -eq 0 ] && _fail "btrfs check should have detected corruption" - run_check $TOP/btrfs check --repair $image - run_check $TOP/btrfs check $image + run_check $TOP/btrfs check --repair "$image" + run_check $TOP/btrfs check "$image" } # Extract a usable image from packed formats @@ -155,36 +155,36 @@ extract_image() image="$1" case "$image" in *.img) - rm -f $image.restored + rm -f "$image.restored" : ;; *.img.xz) xz --decompress --keep "$image" || \ _fail "failed to decompress image $image" >&2 image=${image%%.xz} - rm -f $image.restored + rm -f "$image.restored" cleanme=$image ;; *.raw) - cp --sparse=auto $image $image.restored + cp --sparse=auto "$image" "$image.restored" ;; *.raw.xz) xz --decompress --keep "$image" || \ _fail "failed to decompress image $image" >&2 image=${image%%.xz} - mv "$image" "$image".restored + mv "$image" "$image.restored" ;; *.stream.xz) xz --decompress --keep "$image" || \ _fail "failed to decompress file $image" >&2 image=${image%%.xz} - mv "$image" "$image".restored + mv "$image" "$image.restored" ;; esac - if ! [ -f $image.restored ]; then - echo "restoring image $(basename $image)" >> $RESULTS - $TOP/btrfs-image -r $image $image.restored \ - &>> $RESULTS \ + if ! [ -f "$image.restored" ]; then + echo "restoring image $(basename $image)" >> "$RESULTS" + "$TOP/btrfs-image" -r "$image" "$image.restored" \ + &>> "$RESULTS" \ || _fail "failed to restore image $image" >&2 fi @@ -200,7 +200,7 @@ check_all_images() local extracted dir="$1" - for image in $(find $dir \( -iname '*.img' -o \ + for image in $(find "$dir" \( -iname '*.img' -o \ -iname '*.img.xz' -o \ -iname '*.raw' -o \ -iname '*.raw.xz' \) | sort) @@ -266,7 +266,7 @@ prepare_test_dev() [[ "$size" ]] || size='2G' echo "\$TEST_DEV not given, use $TOP/test/test.img as fallback" >> \ - $RESULTS + "$RESULTS" TEST_DEV="$TOP/tests/test.img" truncate -s "$size" "$TEST_DEV" || _not_run "create file for loop device failed" -- cgit v1.2.3 From 8dc653f00338527b230617defd4e5971009d0e36 Mon Sep 17 00:00:00 2001 From: David Sterba Date: Fri, 11 Nov 2016 10:12:05 +0100 Subject: btrfs-progs: tests: add quotation around variables in common.convert Signed-off-by: David Sterba --- tests/common.convert | 124 ++++++++++++++++++++++++++------------------------- 1 file changed, 63 insertions(+), 61 deletions(-) (limited to 'tests') diff --git a/tests/common.convert b/tests/common.convert index 0d22949c..375d4b55 100644 --- a/tests/common.convert +++ b/tests/common.convert @@ -8,33 +8,35 @@ generate_dataset() { dataset_type="$1" dirpath=$TEST_MNT/$dataset_type - run_check $SUDO_HELPER mkdir -p $dirpath + run_check $SUDO_HELPER mkdir -p "$dirpath" case $dataset_type in small) - for num in $(seq 1 $DATASET_SIZE); do - run_check $SUDO_HELPER dd if=/dev/urandom of=$dirpath/$dataset_type.$num bs=10K \ + for num in $(seq 1 "$DATASET_SIZE"); do + run_check $SUDO_HELPER dd if=/dev/urandom of="$dirpath/$dataset_type.$num" bs=10K \ count=1 >/dev/null 2>&1 done ;; hardlink) - for num in $(seq 1 $DATASET_SIZE); do + for num in $(seq 1 "$DATASET_SIZE"); do run_check $SUDO_HELPER touch $dirpath/$dataset_type.$num - run_check $SUDO_HELPER ln $dirpath/$dataset_type.$num $dirpath/hlink.$num + run_check $SUDO_HELPER ln "$dirpath/$dataset_type.$num" "$dirpath/hlink.$num" done ;; fast_symlink) - for num in $(seq 1 $DATASET_SIZE); do + for num in $(seq 1 "$DATASET_SIZE"); do run_check $SUDO_HELPER touch $dirpath/$dataset_type.$num - run_check cd $dirpath && $SUDO_HELPER ln -s $dataset_type.$num $dirpath/slink.$num && cd / + run_check cd "$dirpath" && \ + $SUDO_HELPER ln -s "$dataset_type.$num" "$dirpath/slink.$num" && \ + cd / done ;; brokenlink) - for num in $(seq 1 $DATASET_SIZE); do - run_check $SUDO_HELPER ln -s $dirpath/$dataset_type.$num $dirpath/blink.$num + for num in $(seq 1 "$DATASET_SIZE"); do + run_check $SUDO_HELPER ln -s "$dirpath/$dataset_type.$num" "$dirpath/blink.$num" done ;; @@ -47,42 +49,42 @@ generate_dataset() { then continue; else - run_check $SUDO_HELPER touch $dirpath/$dataset_type.$modes - run_check $SUDO_HELPER chmod $modes $dirpath/$dataset_type.$modes + run_check $SUDO_HELPER touch "$dirpath/$dataset_type.$modes" + run_check $SUDO_HELPER chmod "$modes" "$dirpath/$dataset_type.$modes" fi done ;; sparse) - for num in $(seq 1 $DATASET_SIZE); do - run_check $SUDO_HELPER dd if=/dev/urandom of=$dirpath/$dataset_type.$num bs=10K \ + for num in $(seq 1 "$DATASET_SIZE"); do + run_check $SUDO_HELPER dd if=/dev/urandom of="$dirpath/$dataset_type.$num" bs=10K \ count=1 >/dev/null 2>&1 - run_check $SUDO_HELPER truncate -s 500K $dirpath/$dataset_type.$num - run_check $SUDO_HELPER dd if=/dev/urandom of=$dirpath/$dataset_type.$num bs=10K \ + run_check $SUDO_HELPER truncate -s 500K "$dirpath/$dataset_type.$num" + run_check $SUDO_HELPER dd if=/dev/urandom of="$dirpath/$dataset_type.$num" bs=10K \ oflag=append conv=notrunc count=1 >/dev/null 2>&1 - run_check $SUDO_HELPER truncate -s 800K $dirpath/$dataset_type.$num + run_check $SUDO_HELPER truncate -s 800K "$dirpath/$dataset_type.$num" done ;; acls) - for num in $(seq 1 $DATASET_SIZE); do - run_check $SUDO_HELPER touch $dirpath/$dataset_type.$num - run_check $SUDO_HELPER setfacl -m "u:root:x" $dirpath/$dataset_type.$num - run_check $SUDO_HELPER setfattr -n user.foo -v bar$num $dirpath/$dataset_type.$num + for num in $(seq 1 "$DATASET_SIZE"); do + run_check $SUDO_HELPER touch "$dirpath/$dataset_type.$num" + run_check $SUDO_HELPER setfacl -m "u:root:x" "$dirpath/$dataset_type.$num" + run_check $SUDO_HELPER setfattr -n user.foo -v "bar$num" "$dirpath/$dataset_type.$num" done ;; fifo) - for num in $(seq 1 $DATASET_SIZE); do - run_check $SUDO_HELPER mkfifo $dirpath/$dataset_type.$num + for num in $(seq 1 "$DATASET_SIZE"); do + run_check $SUDO_HELPER mkfifo "$dirpath/$dataset_type.$num" done ;; slow_symlink) long_filename=`date +%s | sha256sum | cut -f1 -d'-'` - run_check $SUDO_HELPER touch $dirpath/$long_filename - for num in $(seq 1 $DATASET_SIZE); do - run_check $SUDO_HELPER ln -s $dirpath/$long_filename $dirpath/slow_slink.$num + run_check $SUDO_HELPER touch "$dirpath/$long_filename" + for num in $(seq 1 "$DATASET_SIZE"); do + run_check $SUDO_HELPER ln -s "$dirpath/$long_filename" "$dirpath/slow_slink.$num" done ;; esac @@ -104,7 +106,7 @@ convert_test_preamble() { msg="$2" shift 3 echo " [TEST/conv] $msg, btrfs" "${features:-defaults}" - echo "creating ext image with: $@" >> $RESULTS + echo "creating ext image with: $@" >> "$RESULTS" } # prepare TEST_DEV before conversion, create filesystem and mount it, image @@ -113,10 +115,10 @@ convert_test_preamble() { convert_test_prep_fs() { # TEST_DEV not removed as the file might have special permissions, eg. # when test image is on NFS and would not be writable for root - run_check truncate -s 0 $TEST_DEV + run_check truncate -s 0 "$TEST_DEV" # 256MB is the smallest acceptable btrfs image. - run_check truncate -s 512M $TEST_DEV - run_check "$@" -F $TEST_DEV + run_check truncate -s 512M "$TEST_DEV" + run_check "$@" -F "$TEST_DEV" # create a file to check btrfs-convert can convert regular file correct run_check_mount_test_dev @@ -124,7 +126,7 @@ convert_test_prep_fs() { # create a file inside the fs before convert, to make sure there is # data covering btrfs backup superblock range (64M) run_check $SUDO_HELPER dd if=/dev/zero bs=1M count=64 \ - of=$TEST_MNT/convert_space_holder + of="$TEST_MNT/convert_space_holder" } # generate md5 checksums of files on $TEST_MNT @@ -132,9 +134,9 @@ convert_test_prep_fs() { convert_test_gen_checksums() { _assert_path "$1" - run_check $SUDO_HELPER dd if=/dev/zero of=$TEST_MNT/test bs=$nodesize \ + run_check $SUDO_HELPER dd if=/dev/zero of="$TEST_MNT/test" "bs=$nodesize" \ count=1 >/dev/null 2>&1 - run_check_stdout $SUDO_HELPER find $TEST_MNT -type f ! -name 'image' -exec md5sum {} \+ > "$1" + run_check_stdout $SUDO_HELPER find "$TEST_MNT" -type f ! -name 'image' -exec md5sum {} \+ > "$1" } # list $TEST_MNT data set file permissions. # $1: path where the permissions will be stored @@ -145,15 +147,15 @@ convert_test_perm() { PERMTMP="$1" FILES_LIST=$(mktemp --tmpdir btrfs-progs-convert.fileslistXXXXXX) - run_check $SUDO_HELPER dd if=/dev/zero of=$TEST_MNT/test bs=$nodesize \ + run_check $SUDO_HELPER dd if=/dev/zero of="$TEST_MNT/test" "bs=$nodesize" \ count=1 >/dev/null 2>&1 - run_check_stdout $SUDO_HELPER find $TEST_MNT -type f ! -name 'image' -fprint $FILES_LIST + run_check_stdout $SUDO_HELPER find "$TEST_MNT" -type f ! -name 'image' -fprint "$FILES_LIST" # Fix directory entries order - sort $FILES_LIST -o $FILES_LIST - for file in `cat $FILES_LIST` ;do - run_check_stdout $SUDO_HELPER getfacl --absolute-names $file >> "$PERMTMP" + sort "$FILES_LIST" -o "$FILES_LIST" + for file in `cat "$FILES_LIST"` ;do + run_check_stdout $SUDO_HELPER getfacl --absolute-names "$file" >> "$PERMTMP" done - rm -- $FILES_LIST + rm -- "$FILES_LIST" } # list acls of files on $TEST_MNT # $1: path where the acls will be stored @@ -162,22 +164,22 @@ convert_test_acl() { ACLTMP="$1" FILES_LIST=$(mktemp --tmpdir btrfs-progs-convert.fileslistXXXXXX) - run_check_stdout $SUDO_HELPER find $TEST_MNT/acls -type f -fprint $FILES_LIST + run_check_stdout $SUDO_HELPER find "$TEST_MNT/acls" -type f -fprint "$FILES_LIST" # Fix directory entries order - sort $FILES_LIST -o $FILES_LIST - for file in `cat $FILES_LIST`;do - run_check_stdout $SUDO_HELPER getfattr --absolute-names -d $file >> "$ACLTMP" + sort "$FILES_LIST" -o "$FILES_LIST" + for file in `cat "$FILES_LIST"`;do + run_check_stdout $SUDO_HELPER getfattr --absolute-names -d "$file" >> "$ACLTMP" done - rm -- $FILES_LIST + rm -- "$FILES_LIST" } # do conversion with given features and nodesize, fsck afterwards # $1: features, argument of -O, can be empty # $2: nodesize, argument of -N, can be empty convert_test_do_convert() { - run_check $TOP/btrfs-convert ${1:+-O "$1"} ${2:+-N "$2"} $TEST_DEV - run_check $TOP/btrfs check $TEST_DEV - run_check $TOP/btrfs inspect-internal dump-super -Ffa $TEST_DEV + run_check "$TOP/btrfs-convert" ${1:+-O "$1"} ${2:+-N "$2"} "$TEST_DEV" + run_check "$TOP/btrfs" check $TEST_DEV + run_check "$TOP/btrfs" inspect-internal dump-super -Ffa "$TEST_DEV" } # post conversion check, verify file permissions. @@ -191,17 +193,17 @@ convert_test_post_check_permissions() { BTRFS_PERMTMP=$(mktemp --tmpdir btrfs-progs-convert.permXXXXXX) convert_test_perm "$BTRFS_PERMTMP" - btrfs_perm=`md5sum $BTRFS_PERMTMP | cut -f1 -d' '` - ext_perm=`md5sum $EXT_PERMTMP | cut -f1 -d' '` + btrfs_perm=`md5sum "$BTRFS_PERMTMP" | cut -f1 -d' '` + ext_perm=`md5sum "$EXT_PERMTMP" | cut -f1 -d' '` if [ "$btrfs_perm" != "$ext_perm" ]; then - btrfs_perm_file=`md5sum $BTRFS_PERMTMP | cut -f2 -d' '` - ext_perm_file=`md5sum $EXT_PERMTMP | cut -f2 -d' '` + btrfs_perm_file=`md5sum "$BTRFS_PERMTMP" | cut -f2 -d' '` + ext_perm_file=`md5sum "$EXT_PERMTMP" | cut -f2 -d' '` _fail "file permission failed. Mismatched BTRFS:$btrfs_perm_file:$btrfs_perm EXT:$ext_perm_file:$ext_perm" fi - rm -- $BTRFS_PERMTMP + rm -- "$BTRFS_PERMTMP" } # post conversion check, compare BTRFS file acls against EXT. # $1: file with ext acls. @@ -214,17 +216,17 @@ convert_test_post_check_acl() { BTRFS_ACLTMP=$(mktemp --tmpdir btrfs-progs-convert.aclsXXXXXXX) convert_test_acl "$BTRFS_ACLTMP" - btrfs_acl=`md5sum $BTRFS_ACLTMP | cut -f1 -d' '` - ext_acl=`md5sum $EXT_ACLTMP | cut -f1 -d' '` + btrfs_acl=`md5sum "$BTRFS_ACLTMP" | cut -f1 -d' '` + ext_acl=`md5sum "$EXT_ACLTMP" | cut -f1 -d' '` if [ "$btrfs_acl" != "$ext_acl" ] then - btrfs_acl_file=`md5sum $BTRFS_ACLTMP | cut -f2 -d' '` - ext_acl_file=`md5sum $EXT_ACLTMP | cut -f2 -d' '` + btrfs_acl_file=`md5sum "$BTRFS_ACLTMP" | cut -f2 -d' '` + ext_acl_file=`md5sum "$EXT_ACLTMP" | cut -f2 -d' '` _fail "file acl failed. Mismatched BTRFS:$btrfs_acl_file:$btrfs_acl EXT:$ext_acl_file:$ext_acl" fi - rm -- $BTRFS_ACLTMP + rm -- "$BTRFS_ACLTMP" } # post conversion checks, verify md5sums @@ -252,8 +254,8 @@ convert_test_post_checks_all() { # do rollback and fsck convert_test_post_rollback() { - run_check $TOP/btrfs-convert --rollback $TEST_DEV - run_check fsck -n -t ext2,ext3,ext4 $TEST_DEV + run_check "$TOP/btrfs-convert" --rollback "$TEST_DEV" + run_check fsck -n -t ext2,ext3,ext4 "$TEST_DEV" } # simple wrapper for a convert test @@ -287,9 +289,9 @@ convert_test() { convert_test_do_convert "$features" "$nodesize" convert_test_post_checks_all "$CHECKSUMTMP" "$EXT_PERMTMP" "$EXT_ACLTMP" - rm $CHECKSUMTMP - rm $EXT_PERMTMP - rm $EXT_ACLTMP + rm -- "$CHECKSUMTMP" + rm -- "$EXT_PERMTMP" + rm -- "$EXT_ACLTMP" convert_test_post_rollback } -- cgit v1.2.3 From 7dbb17dbb2ea65d22b573641c20c09eceabc652c Mon Sep 17 00:00:00 2001 From: David Sterba Date: Fri, 11 Nov 2016 10:12:05 +0100 Subject: btrfs-progs: tests: add quotation around variables in support scripts Signed-off-by: David Sterba --- tests/clean-tests.sh | 8 ++++---- tests/cli-tests.sh | 18 +++++++++--------- tests/convert-tests.sh | 14 +++++++------- tests/fsck-tests.sh | 16 ++++++++-------- tests/fuzz-tests.sh | 16 ++++++++-------- tests/misc-tests.sh | 16 ++++++++-------- tests/mkfs-tests.sh | 16 ++++++++-------- tests/test-console.sh | 4 ++-- 8 files changed, 54 insertions(+), 54 deletions(-) (limited to 'tests') diff --git a/tests/clean-tests.sh b/tests/clean-tests.sh index 7f18e6f0..61baa069 100755 --- a/tests/clean-tests.sh +++ b/tests/clean-tests.sh @@ -1,9 +1,9 @@ #!/bin/bash # remove all intermediate files from tests -SCRIPT_DIR=$(dirname $(readlink -f $0)) -TOP=$(readlink -f $SCRIPT_DIR/../) -source $TOP/tests/common +SCRIPT_DIR=$(dirname $(readlink -f "$0")) +TOP=$(readlink -f "$SCRIPT_DIR/../") +source "$TOP/tests/common" setup_root_helper @@ -13,7 +13,7 @@ fi $SUDO_HELPER umount "$TEST_MNT" &>/dev/null -if ! cd $TOP/tests; then +if ! cd "$TOP/tests"; then echo "ERROR: cannot cd to $TOP/tests" exit 1 fi diff --git a/tests/cli-tests.sh b/tests/cli-tests.sh index 86dda87b..bc1a1e2c 100755 --- a/tests/cli-tests.sh +++ b/tests/cli-tests.sh @@ -3,13 +3,13 @@ # command line interface coverage tests LANG=C -SCRIPT_DIR=$(dirname $(readlink -f $0)) -TOP=$(readlink -f $SCRIPT_DIR/../) +SCRIPT_DIR=$(dirname $(readlink -f "$0")) +TOP=$(readlink -f "$SCRIPT_DIR/../") TEST_DEV=${TEST_DEV:-} RESULTS="$TOP/tests/cli-tests-results.txt" IMAGE="$TOP/tests/test.img" -source $TOP/tests/common +source "$TOP/tests/common" export TOP export RESULTS @@ -17,25 +17,25 @@ export LANG export IMAGE export TEST_DEV -rm -f $RESULTS +rm -f "$RESULTS" check_prereq btrfs check_kernel_support # The tests are driven by their custom script called 'test.sh' -for i in $(find $TOP/tests/cli-tests -maxdepth 1 -mindepth 1 -type d \ +for i in $(find "$TOP/tests/cli-tests" -maxdepth 1 -mindepth 1 -type d \ ${TEST:+-name "$TEST"} | sort) do - name=$(basename $i) - cd $i + name=$(basename "$i") + cd "$i" if [ -x test.sh ]; then - echo "=== Entering $i" >> $RESULTS + echo "=== Entering $i" >> "$RESULTS" echo " [TEST/cli] $name" ./test.sh if [ $? -ne 0 ]; then _fail "test failed for case $(basename $i)" fi fi - cd $TOP + cd "$TOP" done diff --git a/tests/convert-tests.sh b/tests/convert-tests.sh index db149724..5fa88a12 100755 --- a/tests/convert-tests.sh +++ b/tests/convert-tests.sh @@ -4,14 +4,14 @@ # clean. LANG=C -SCRIPT_DIR=$(dirname $(readlink -f $0)) -TOP=$(readlink -f $SCRIPT_DIR/../) +SCRIPT_DIR=$(dirname $(readlink -f "$0")) +TOP=$(readlink -f "$SCRIPT_DIR/../") TEST_DEV=${TEST_DEV:-} RESULTS="$TOP/tests/convert-tests-results.txt" IMAGE="$TOP/tests/test.img" -source $TOP/tests/common -source $TOP/tests/common.convert +source "$TOP/tests/common" +source "$TOP/tests/common.convert" export TOP export RESULTS @@ -19,7 +19,7 @@ export LANG export IMAGE export TEST_DEV -rm -f $RESULTS +rm -f "$RESULTS" check_kernel_support @@ -31,7 +31,7 @@ run_one_test() { testname=$(basename "$testdir") echo " [TEST/conv] $testname" cd "$testdir" - echo "=== Entering $testname" >> $RESULTS + echo "=== Entering $testname" >> "$RESULTS" if [ -x test.sh ]; then # Only support custom test scripts ./test.sh @@ -44,7 +44,7 @@ run_one_test() { } # Test special images -for i in $(find $TOP/tests/convert-tests -maxdepth 1 -mindepth 1 -type d \ +for i in $(find "$TOP/tests/convert-tests" -maxdepth 1 -mindepth 1 -type d \ ${TEST:+-name "$TEST"} | sort) do run_one_test "$i" diff --git a/tests/fsck-tests.sh b/tests/fsck-tests.sh index 69ec57a0..e71b7119 100755 --- a/tests/fsck-tests.sh +++ b/tests/fsck-tests.sh @@ -3,13 +3,13 @@ # loop through all of our bad images and make sure fsck repairs them properly LANG=C -SCRIPT_DIR=$(dirname $(readlink -f $0)) -TOP=$(readlink -f $SCRIPT_DIR/../) +SCRIPT_DIR=$(dirname $(readlink -f "$0")) +TOP=$(readlink -f "$SCRIPT_DIR/../") TEST_DEV=${TEST_DEV:-} RESULTS="$TOP/tests/fsck-tests-results.txt" IMAGE="$TOP/tests/test.img" -source $TOP/tests/common +source "$TOP/tests/common" export TOP export RESULTS @@ -17,7 +17,7 @@ export LANG export IMAGE export TEST_DEV -rm -f $RESULTS +rm -f "$RESULTS" # test rely on corrupting blocks tool check_prereq btrfs-corrupt-block @@ -30,8 +30,8 @@ run_one_test() { testname="$1" echo " [TEST/fsck] $(basename $testname)" - cd $testname - echo "=== Entering $testname" >> $RESULTS + cd "$testname" + echo "=== Entering $testname" >> "$RESULTS" if [ -x test.sh ]; then # Type 2 ./test.sh @@ -42,7 +42,7 @@ run_one_test() { # Type 1 check_all_images `pwd` fi - cd $TOP + cd "$TOP" } # Each dir contains one type of error for btrfsck test. @@ -58,7 +58,7 @@ run_one_test() { # This is for case btrfs-image can't dump or case needs extra # check/verify -for i in $(find $TOP/tests/fsck-tests -maxdepth 1 -mindepth 1 -type d \ +for i in $(find "$TOP/tests/fsck-tests" -maxdepth 1 -mindepth 1 -type d \ ${TEST:+-name "$TEST"} | sort) do run_one_test "$i" diff --git a/tests/fuzz-tests.sh b/tests/fuzz-tests.sh index 29691cae..9b88aa10 100755 --- a/tests/fuzz-tests.sh +++ b/tests/fuzz-tests.sh @@ -3,13 +3,13 @@ # misc tests on fuzzed or crafted images LANG=C -SCRIPT_DIR=$(dirname $(readlink -f $0)) -TOP=$(readlink -f $SCRIPT_DIR/../) +SCRIPT_DIR=$(dirname $(readlink -f "$0")) +TOP=$(readlink -f "$SCRIPT_DIR/../") TEST_DEV=${TEST_DEV:-} RESULTS="$TOP/tests/fuzz-tests-results.txt" IMAGE="$TOP/tests/test.img" -source $TOP/tests/common +source "$TOP/tests/common" export TOP export RESULTS @@ -17,24 +17,24 @@ export LANG export IMAGE export TEST_DEV -rm -f $RESULTS +rm -f "$RESULTS" check_prereq btrfs # The tests are driven by their custom script called 'test.sh' -for i in $(find $TOP/tests/fuzz-tests -maxdepth 1 -mindepth 1 -type d \ +for i in $(find "$TOP/tests/fuzz-tests" -maxdepth 1 -mindepth 1 -type d \ ${TEST:+-name "$TEST"} | sort) do - name=$(basename $i) + name=$(basename "$i") cd $i if [ -x test.sh ]; then - echo "=== Entering $i" >> $RESULTS + echo "=== Entering $i" >> "$RESULTS" echo " [TEST/fuzz] $name" ./test.sh if [ $? -ne 0 ]; then _fail "test failed for case $(basename $i)" fi fi - cd $TOP + cd "$TOP" done diff --git a/tests/misc-tests.sh b/tests/misc-tests.sh index fd19c2f9..40e1cba1 100755 --- a/tests/misc-tests.sh +++ b/tests/misc-tests.sh @@ -3,13 +3,13 @@ # Misc tests LANG=C -SCRIPT_DIR=$(dirname $(readlink -f $0)) -TOP=$(readlink -f $SCRIPT_DIR/../) +SCRIPT_DIR=$(dirname $(readlink -f "$0")) +TOP=$(readlink -f "$SCRIPT_DIR/../") TEST_DEV=${TEST_DEV:-} RESULTS="$TOP/tests/misc-tests-results.txt" IMAGE="$TOP/tests/test.img" -source $TOP/tests/common +source "$TOP/tests/common" export TOP export RESULTS @@ -17,7 +17,7 @@ export LANG export TEST_DEV export IMAGE -rm -f $RESULTS +rm -f "$RESULTS" # test rely on corrupting blocks tool check_prereq btrfs-corrupt-block @@ -28,17 +28,17 @@ check_kernel_support # The tests are driven by their custom script called 'test.sh' -for i in $(find $TOP/tests/misc-tests -maxdepth 1 -mindepth 1 -type d \ +for i in $(find "$TOP/tests/misc-tests" -maxdepth 1 -mindepth 1 -type d \ ${TEST:+-name "$TEST"} | sort) do echo " [TEST/misc] $(basename $i)" - cd $i - echo "=== Entering $i" >> $RESULTS + cd "$i" + echo "=== Entering $i" >> "$RESULTS" if [ -x test.sh ]; then ./test.sh if [ $? -ne 0 ]; then _fail "test failed for case $(basename $i)" fi fi - cd $TOP + cd "$TOP" done diff --git a/tests/mkfs-tests.sh b/tests/mkfs-tests.sh index 3c5465fa..c130520d 100755 --- a/tests/mkfs-tests.sh +++ b/tests/mkfs-tests.sh @@ -3,13 +3,13 @@ # mkfs.btrfs tests LANG=C -SCRIPT_DIR=$(dirname $(readlink -f $0)) -TOP=$(readlink -f $SCRIPT_DIR/../) +SCRIPT_DIR=$(dirname $(readlink -f "$0")) +TOP=$(readlink -f "$SCRIPT_DIR/../") TEST_DEV=${TEST_DEV:-} RESULTS="$TOP/tests/mkfs-tests-results.txt" IMAGE="$TOP/tests/test.img" -source $TOP/tests/common +source "$TOP/tests/common" export TOP export RESULTS @@ -17,7 +17,7 @@ export LANG export IMAGE export TEST_DEV -rm -f $RESULTS +rm -f "$RESULTS" check_prereq mkfs.btrfs check_prereq btrfs @@ -25,17 +25,17 @@ check_kernel_support # The tests are driven by their custom script called 'test.sh' -for i in $(find $TOP/tests/mkfs-tests -maxdepth 1 -mindepth 1 -type d \ +for i in $(find "$TOP/tests/mkfs-tests" -maxdepth 1 -mindepth 1 -type d \ ${TEST:+-name "$TEST"} | sort) do echo " [TEST/mkfs] $(basename $i)" - cd $i - echo "=== Entering $i" >> $RESULTS + cd "$i" + echo "=== Entering $i" >> "$RESULTS" if [ -x test.sh ]; then ./test.sh if [ $? -ne 0 ]; then _fail "test failed for case $(basename $i)" fi fi - cd $TOP + cd "$TOP" done diff --git a/tests/test-console.sh b/tests/test-console.sh index 365cc971..779e541f 100755 --- a/tests/test-console.sh +++ b/tests/test-console.sh @@ -2,8 +2,8 @@ # a shell with test environment set up, logged commands and output LANG=C -SCRIPT_DIR=$(dirname $(readlink -f $0)) -TOP=$(readlink -f $SCRIPT_DIR/../) +SCRIPT_DIR=$(dirname $(readlink -f "$0")) +TOP=$(readlink -f "$SCRIPT_DIR/../") TEST_DEV=${TEST_DEV:-} RESULTS="$TOP/tests/test-console.txt" IMAGE="$TOP/tests/test.img" -- cgit v1.2.3 From 9d0e6a67f9d884bca99e9ca1fff0118dc310384f Mon Sep 17 00:00:00 2001 From: David Sterba Date: Fri, 11 Nov 2016 13:36:27 +0100 Subject: btrfs-progs: tests: enhance run_mayfail description comment Signed-off-by: David Sterba --- tests/common | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-) (limited to 'tests') diff --git a/tests/common b/tests/common index c8ac0c15..c61962da 100644 --- a/tests/common +++ b/tests/common @@ -63,7 +63,9 @@ run_check_stdout() fi } -# same as run_check but does not fail the test, output is logged +# same as run_check but does not fail the test if it's handled gracefully by +# the tool, unexpected failure like segfault or abor will exit forcibly +# output is logged run_mayfail() { local ret -- cgit v1.2.3 From 5ee216a86f054844f52285cc22736cd249904e52 Mon Sep 17 00:00:00 2001 From: David Sterba Date: Mon, 14 Nov 2016 19:06:40 +0100 Subject: btrfs-progs: tests: add more fuzzed images from bugzilla Fixing the problems by one does not scale now. Add more images despite the fuzz tests will fail. They have been for some time already. Reported-by: Lukas Lueg Signed-off-by: David Sterba --- tests/fuzz-tests/images/bko-156731.raw.txt | 83 ++++++ tests/fuzz-tests/images/bko-156731.raw.xz | Bin 0 -> 3824 bytes tests/fuzz-tests/images/bko-156741.raw.txt | 131 +++++++++ tests/fuzz-tests/images/bko-156741.raw.xz | Bin 0 -> 3796 bytes tests/fuzz-tests/images/bko-161811.raw.txt | 81 ++++++ tests/fuzz-tests/images/bko-161811.raw.xz | Bin 0 -> 10960 bytes tests/fuzz-tests/images/bko-161821.raw.txt | 42 +++ tests/fuzz-tests/images/bko-161821.raw.xz | Bin 0 -> 10596 bytes tests/fuzz-tests/images/bko-167551.raw.txt | 29 ++ tests/fuzz-tests/images/bko-167551.raw.xz | Bin 0 -> 10808 bytes tests/fuzz-tests/images/bko-167781.raw.txt | 297 +++++++++++++++++++++ tests/fuzz-tests/images/bko-167781.raw.xz | Bin 0 -> 3856 bytes tests/fuzz-tests/images/bko-167921.raw.txt | 55 ++++ tests/fuzz-tests/images/bko-167921.raw.xz | Bin 0 -> 10956 bytes tests/fuzz-tests/images/bko-168301.raw.txt | 51 ++++ tests/fuzz-tests/images/bko-168301.raw.xz | Bin 0 -> 11008 bytes .../images/bko-169301-1-blocksize-zero.raw.txt | 134 ++++++++++ .../images/bko-169301-1-blocksize-zero.raw.xz | Bin 0 -> 3828 bytes .../images/bko-169301-2-blocksize-zero.raw.txt | 185 +++++++++++++ .../images/bko-169301-2-blocksize-zero.raw.xz | Bin 0 -> 3836 bytes tests/fuzz-tests/images/bko-172811.raw.txt | 55 ++++ tests/fuzz-tests/images/bko-172811.raw.xz | Bin 0 -> 10900 bytes tests/fuzz-tests/images/bko-172861.raw.txt | 68 +++++ tests/fuzz-tests/images/bko-172861.raw.xz | Bin 0 -> 10828 bytes 24 files changed, 1211 insertions(+) create mode 100644 tests/fuzz-tests/images/bko-156731.raw.txt create mode 100644 tests/fuzz-tests/images/bko-156731.raw.xz create mode 100644 tests/fuzz-tests/images/bko-156741.raw.txt create mode 100644 tests/fuzz-tests/images/bko-156741.raw.xz create mode 100644 tests/fuzz-tests/images/bko-161811.raw.txt create mode 100644 tests/fuzz-tests/images/bko-161811.raw.xz create mode 100644 tests/fuzz-tests/images/bko-161821.raw.txt create mode 100644 tests/fuzz-tests/images/bko-161821.raw.xz create mode 100644 tests/fuzz-tests/images/bko-167551.raw.txt create mode 100644 tests/fuzz-tests/images/bko-167551.raw.xz create mode 100644 tests/fuzz-tests/images/bko-167781.raw.txt create mode 100644 tests/fuzz-tests/images/bko-167781.raw.xz create mode 100644 tests/fuzz-tests/images/bko-167921.raw.txt create mode 100644 tests/fuzz-tests/images/bko-167921.raw.xz create mode 100644 tests/fuzz-tests/images/bko-168301.raw.txt create mode 100644 tests/fuzz-tests/images/bko-168301.raw.xz create mode 100644 tests/fuzz-tests/images/bko-169301-1-blocksize-zero.raw.txt create mode 100644 tests/fuzz-tests/images/bko-169301-1-blocksize-zero.raw.xz create mode 100644 tests/fuzz-tests/images/bko-169301-2-blocksize-zero.raw.txt create mode 100644 tests/fuzz-tests/images/bko-169301-2-blocksize-zero.raw.xz create mode 100644 tests/fuzz-tests/images/bko-172811.raw.txt create mode 100644 tests/fuzz-tests/images/bko-172811.raw.xz create mode 100644 tests/fuzz-tests/images/bko-172861.raw.txt create mode 100644 tests/fuzz-tests/images/bko-172861.raw.xz (limited to 'tests') diff --git a/tests/fuzz-tests/images/bko-156731.raw.txt b/tests/fuzz-tests/images/bko-156731.raw.txt new file mode 100644 index 00000000..aea35f1f --- /dev/null +++ b/tests/fuzz-tests/images/bko-156731.raw.txt @@ -0,0 +1,83 @@ +URL: https://bugzilla.kernel.org/show_bug.cgi?id=156731 +Lukas Lueg 2016-09-13 19:53:59 UTC + +More news from the fuzzer. The attached image causes btrfsck to +buffer-overflow. Using btrfs-progs v4.7-42-g56e9586, compiled with ASAN +(doesn't crash without) + +==17647==ERROR: AddressSanitizer: heap-buffer-overflow on address 0x621000017980 at pc 0x00000052dde3 bp 0x7ffecc974fe0 sp 0x7ffecc974fd8 +READ of size 4 at 0x621000017980 thread T0 + #0 0x52dde2 in btrfs_extent_data_ref_count /home/lukas/dev/btrfsfuzz/src-asan/./ctree.h:1582:1 + #1 0x5329ae in run_next_block /home/lukas/dev/btrfsfuzz/src-asan/cmds-check.c:6380:6 + #2 0x52f584 in deal_root_from_list /home/lukas/dev/btrfsfuzz/src-asan/cmds-check.c:8391:10 + #3 0x520f81 in check_chunks_and_extents /home/lukas/dev/btrfsfuzz/src-asan/cmds-check.c:8558:8 + #4 0x51e5a9 in cmd_check /home/lukas/dev/btrfsfuzz/src-asan/cmds-check.c:11493:9 + #5 0x4f0ee1 in main /home/lukas/dev/btrfsfuzz/src-asan/btrfs.c:243:8 + #6 0x7faced2c8730 in __libc_start_main (/lib64/libc.so.6+0x20730) + #7 0x421358 in _start (/home/lukas/dev/btrfsfuzz/bin-asan/bin/btrfs+0x421358) + +cat crashing_images/id:000047,sig:11,src:000343+000051,op:splice,rep:4.log +================================================================= +==17647==ERROR: AddressSanitizer: heap-buffer-overflow on address 0x621000017980 at pc 0x00000052dde3 bp 0x7ffecc974fe0 sp 0x7ffecc974fd8 +READ of size 4 at 0x621000017980 thread T0 + #0 0x52dde2 in btrfs_extent_data_ref_count /home/lukas/dev/btrfsfuzz/src-asan/./ctree.h:1582:1 + #1 0x5329ae in run_next_block /home/lukas/dev/btrfsfuzz/src-asan/cmds-check.c:6380:6 + #2 0x52f584 in deal_root_from_list /home/lukas/dev/btrfsfuzz/src-asan/cmds-check.c:8391:10 + #3 0x520f81 in check_chunks_and_extents /home/lukas/dev/btrfsfuzz/src-asan/cmds-check.c:8558:8 + #4 0x51e5a9 in cmd_check /home/lukas/dev/btrfsfuzz/src-asan/cmds-check.c:11493:9 + #5 0x4f0ee1 in main /home/lukas/dev/btrfsfuzz/src-asan/btrfs.c:243:8 + #6 0x7faced2c8730 in __libc_start_main (/lib64/libc.so.6+0x20730) + #7 0x421358 in _start (/home/lukas/dev/btrfsfuzz/bin-asan/bin/btrfs+0x421358) + +0x621000017980 is located 0 bytes to the right of 4224-byte region [0x621000016900,0x621000017980) +allocated by thread T0 here: + #0 0x4bfca0 in calloc (/home/lukas/dev/btrfsfuzz/bin-asan/bin/btrfs+0x4bfca0) + #1 0x5c16ca in __alloc_extent_buffer /home/lukas/dev/btrfsfuzz/src-asan/extent_io.c:542:7 + #2 0x5c1b26 in alloc_extent_buffer /home/lukas/dev/btrfsfuzz/src-asan/extent_io.c:646:8 + #3 0x58de0c in btrfs_find_create_tree_block /home/lukas/dev/btrfsfuzz/src-asan/disk-io.c:193:9 + #4 0x58e880 in read_tree_block_fs_info /home/lukas/dev/btrfsfuzz/src-asan/disk-io.c:339:7 + #5 0x5918a2 in read_tree_block /home/lukas/dev/btrfsfuzz/src-asan/./disk-io.h:112:9 + #6 0x591712 in find_and_setup_root /home/lukas/dev/btrfsfuzz/src-asan/disk-io.c:647:15 + #7 0x593243 in setup_root_or_create_block /home/lukas/dev/btrfsfuzz/src-asan/disk-io.c:966:8 + #8 0x592850 in btrfs_setup_all_roots /home/lukas/dev/btrfsfuzz/src-asan/disk-io.c:1031:8 + #9 0x5948fe in __open_ctree_fd /home/lukas/dev/btrfsfuzz/src-asan/disk-io.c:1341:8 + #10 0x5942b5 in open_ctree_fs_info /home/lukas/dev/btrfsfuzz/src-asan/disk-io.c:1387:9 + #11 0x51dff2 in cmd_check /home/lukas/dev/btrfsfuzz/src-asan/cmds-check.c:11382:9 + #12 0x4f0ee1 in main /home/lukas/dev/btrfsfuzz/src-asan/btrfs.c:243:8 + #13 0x7faced2c8730 in __libc_start_main (/lib64/libc.so.6+0x20730) + +SUMMARY: AddressSanitizer: heap-buffer-overflow /home/lukas/dev/btrfsfuzz/src-asan/./ctree.h:1582:1 in btrfs_extent_data_ref_count +Shadow bytes around the buggy address: + 0x0c427fffaee0: 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 + 0x0c427fffaef0: 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 + 0x0c427fffaf00: 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 + 0x0c427fffaf10: 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 + 0x0c427fffaf20: 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 +=>0x0c427fffaf30:[fa]fa fa fa fa fa fa fa fa fa fa fa fa fa fa fa + 0x0c427fffaf40: fa fa fa fa fa fa fa fa fa fa fa fa fa fa fa fa + 0x0c427fffaf50: fa fa fa fa fa fa fa fa fa fa fa fa fa fa fa fa + 0x0c427fffaf60: fa fa fa fa fa fa fa fa fa fa fa fa fa fa fa fa + 0x0c427fffaf70: fa fa fa fa fa fa fa fa fa fa fa fa fa fa fa fa + 0x0c427fffaf80: fa fa fa fa fa fa fa fa fa fa fa fa fa fa fa fa +Shadow byte legend (one shadow byte represents 8 application bytes): + Addressable: 00 + Partially addressable: 01 02 03 04 05 06 07 + Heap left redzone: fa + Heap right redzone: fb + Freed heap region: fd + Stack left redzone: f1 + Stack mid redzone: f2 + Stack right redzone: f3 + Stack partial redzone: f4 + Stack after return: f5 + Stack use after scope: f8 + Global redzone: f9 + Global init order: f6 + Poisoned by user: f7 + Container overflow: fc + Array cookie: ac + Intra object redzone: bb + ASan internal: fe + Left alloca redzone: ca + Right alloca redzone: cb +==17647==ABORTING diff --git a/tests/fuzz-tests/images/bko-156731.raw.xz b/tests/fuzz-tests/images/bko-156731.raw.xz new file mode 100644 index 00000000..74a5c2a9 Binary files /dev/null and b/tests/fuzz-tests/images/bko-156731.raw.xz differ diff --git a/tests/fuzz-tests/images/bko-156741.raw.txt b/tests/fuzz-tests/images/bko-156741.raw.txt new file mode 100644 index 00000000..ca52677a --- /dev/null +++ b/tests/fuzz-tests/images/bko-156741.raw.txt @@ -0,0 +1,131 @@ +URL: https://bugzilla.kernel.org/show_bug.cgi?id=156741 +Lukas Lueg 2016-09-13 19:56:16 UTC + +More news from the fuzzer. The attached image causes btrfsck to +buffer-overflow. Using btrfs-progs v4.7-42-g56e9586, compiled with ASAN +(doesn't crash without). + +==23161==ERROR: AddressSanitizer: heap-buffer-overflow on address 0x621000017980 at pc 0x0000005299d3 bp 0x7fff110ce980 sp 0x7fff110ce978 +READ of size 1 at 0x621000017980 thread T0 + #0 0x5299d2 in btrfs_extent_inline_ref_type /home/lukas/dev/btrfsfuzz/src-asan/./ctree.h:1588:1 + #1 0x540f54 in build_roots_info_cache /home/lukas/dev/btrfsfuzz/src-asan/cmds-check.c:10965:10 + #2 0x52163e in repair_root_items /home/lukas/dev/btrfsfuzz/src-asan/cmds-check.c:11108:8 + #3 0x51e5c3 in cmd_check /home/lukas/dev/btrfsfuzz/src-asan/cmds-check.c:11497:8 + #4 0x4f0ee1 in main /home/lukas/dev/btrfsfuzz/src-asan/btrfs.c:243:8 + #5 0x7f067cc9f730 in __libc_start_main (/lib64/libc.so.6+0x20730) + #6 0x421358 in _start (/home/lukas/dev/btrfsfuzz/bin-asan/bin/btrfs+0x421358) + +cat crashing_images/id:000073,sig:11,src:000504+000275,op:splice,rep:4.log +parent transid verify failed on 1122304 wanted 3472328296227680304 found 1 +parent transid verify failed on 1122304 wanted 3472328296227680304 found 1 +Ignoring transid failure +Chunk[256, 228, 0]: length(4194304), offset(0), type(2) is not found in block group +Chunk[256, 228, 4194304]: length(1638400), offset(4194304), type(5) is not found in block group +Chunk[256, 228, 5832704]: length(1638400), offset(5832704), type(5) is not found in block group +ref mismatch on [131072 4096] extent item 0, found 1 +Backref 131072 parent 3 root 3 not found in extent tree +backpointer mismatch on [131072 4096] +ref mismatch on [1118208 4096] extent item 1, found 0 +Backref 1118208 root 1 not referenced back 0x60300000ee00 +Incorrect global backref count on 1118208 found 1 wanted 0 +backpointer mismatch on [1118208 4096] +owner ref check failed [1118208 4096] +ref mismatch on [1126400 4096] extent item 1, found 0 +Backref 1126400 root 3 not referenced back 0x60300000edd0 +Incorrect global backref count on 1126400 found 1 wanted 0 +backpointer mismatch on [1126400 4096] +owner ref check failed [1126400 4096] +ref mismatch on [1130496 4096] extent item 1, found 0 +Backref 1130496 root 4 not referenced back 0x60300000eda0 +Incorrect global backref count on 1130496 found 1 wanted 0 +backpointer mismatch on [1130496 4096] +owner ref check failed [1130496 4096] +ref mismatch on [1134592 4096] extent item 1, found 0 +Backref 1134592 root 5 not referenced back 0x60300000ed70 +Incorrect global backref count on 1134592 found 1 wanted 0 +backpointer mismatch on [1134592 4096] +owner ref check failed [1134592 4096] +ref mismatch on [1138688 4096] extent item 1, found 0 +Backref 1138688 root 7 not referenced back 0x60300000ed40 +Incorrect global backref count on 1138688 found 1 wanted 0 +backpointer mismatch on [1138688 4096] +owner ref check failed [1138688 4096] +ref mismatch on [4194304 4096] extent item 0, found 1 +Backref 4194304 parent 5 root 5 not found in extent tree +backpointer mismatch on [4194304 4096] +ref mismatch on [4198400 4096] extent item 0, found 1 +Backref 4198400 parent 1 root 1 not found in extent tree +backpointer mismatch on [4198400 4096] +ref mismatch on [4227072 4096] extent item 0, found 1 +Backref 4227072 parent 4 root 4 not found in extent tree +backpointer mismatch on [4227072 4096] +ref mismatch on [4231168 4096] extent item 0, found 1 +Backref 4231168 parent 7 root 7 not found in extent tree +backpointer mismatch on [4231168 4096] +ref mismatch on [3472328296227680304 3472328296227680304] extent item 0, found 1 +Backref 3472328296227680304 root 1 owner 6 offset 0 num_refs 0 not found in extent tree +Incorrect local backref count on 3472328296227680304 root 1 owner 6 offset 0 found 1 wanted 0 back 0x60700000dca0 +backpointer mismatch on [3472328296227680304 3472328296227680304] +================================================================= +==23161==ERROR: AddressSanitizer: heap-buffer-overflow on address 0x621000017980 at pc 0x0000005299d3 bp 0x7fff110ce980 sp 0x7fff110ce978 +READ of size 1 at 0x621000017980 thread T0 + #0 0x5299d2 in btrfs_extent_inline_ref_type /home/lukas/dev/btrfsfuzz/src-asan/./ctree.h:1588:1 + #1 0x540f54 in build_roots_info_cache /home/lukas/dev/btrfsfuzz/src-asan/cmds-check.c:10965:10 + #2 0x52163e in repair_root_items /home/lukas/dev/btrfsfuzz/src-asan/cmds-check.c:11108:8 + #3 0x51e5c3 in cmd_check /home/lukas/dev/btrfsfuzz/src-asan/cmds-check.c:11497:8 + #4 0x4f0ee1 in main /home/lukas/dev/btrfsfuzz/src-asan/btrfs.c:243:8 + #5 0x7f067cc9f730 in __libc_start_main (/lib64/libc.so.6+0x20730) + #6 0x421358 in _start (/home/lukas/dev/btrfsfuzz/bin-asan/bin/btrfs+0x421358) + +0x621000017980 is located 0 bytes to the right of 4224-byte region [0x621000016900,0x621000017980) +allocated by thread T0 here: + #0 0x4bfca0 in calloc (/home/lukas/dev/btrfsfuzz/bin-asan/bin/btrfs+0x4bfca0) + #1 0x5c16ca in __alloc_extent_buffer /home/lukas/dev/btrfsfuzz/src-asan/extent_io.c:542:7 + #2 0x5c1b26 in alloc_extent_buffer /home/lukas/dev/btrfsfuzz/src-asan/extent_io.c:646:8 + #3 0x58de0c in btrfs_find_create_tree_block /home/lukas/dev/btrfsfuzz/src-asan/disk-io.c:193:9 + #4 0x58e880 in read_tree_block_fs_info /home/lukas/dev/btrfsfuzz/src-asan/disk-io.c:339:7 + #5 0x5918a2 in read_tree_block /home/lukas/dev/btrfsfuzz/src-asan/./disk-io.h:112:9 + #6 0x591712 in find_and_setup_root /home/lukas/dev/btrfsfuzz/src-asan/disk-io.c:647:15 + #7 0x593243 in setup_root_or_create_block /home/lukas/dev/btrfsfuzz/src-asan/disk-io.c:966:8 + #8 0x592850 in btrfs_setup_all_roots /home/lukas/dev/btrfsfuzz/src-asan/disk-io.c:1031:8 + #9 0x5948fe in __open_ctree_fd /home/lukas/dev/btrfsfuzz/src-asan/disk-io.c:1341:8 + #10 0x5942b5 in open_ctree_fs_info /home/lukas/dev/btrfsfuzz/src-asan/disk-io.c:1387:9 + #11 0x51dff2 in cmd_check /home/lukas/dev/btrfsfuzz/src-asan/cmds-check.c:11382:9 + #12 0x4f0ee1 in main /home/lukas/dev/btrfsfuzz/src-asan/btrfs.c:243:8 + #13 0x7f067cc9f730 in __libc_start_main (/lib64/libc.so.6+0x20730) + +SUMMARY: AddressSanitizer: heap-buffer-overflow /home/lukas/dev/btrfsfuzz/src-asan/./ctree.h:1588:1 in btrfs_extent_inline_ref_type +Shadow bytes around the buggy address: + 0x0c427fffaee0: 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 + 0x0c427fffaef0: 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 + 0x0c427fffaf00: 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 + 0x0c427fffaf10: 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 + 0x0c427fffaf20: 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 +=>0x0c427fffaf30:[fa]fa fa fa fa fa fa fa fa fa fa fa fa fa fa fa + 0x0c427fffaf40: fa fa fa fa fa fa fa fa fa fa fa fa fa fa fa fa + 0x0c427fffaf50: fa fa fa fa fa fa fa fa fa fa fa fa fa fa fa fa + 0x0c427fffaf60: fa fa fa fa fa fa fa fa fa fa fa fa fa fa fa fa + 0x0c427fffaf70: fa fa fa fa fa fa fa fa fa fa fa fa fa fa fa fa + 0x0c427fffaf80: fa fa fa fa fa fa fa fa fa fa fa fa fa fa fa fa +Shadow byte legend (one shadow byte represents 8 application bytes): + Addressable: 00 + Partially addressable: 01 02 03 04 05 06 07 + Heap left redzone: fa + Heap right redzone: fb + Freed heap region: fd + Stack left redzone: f1 + Stack mid redzone: f2 + Stack right redzone: f3 + Stack partial redzone: f4 + Stack after return: f5 + Stack use after scope: f8 + Global redzone: f9 + Global init order: f6 + Poisoned by user: f7 + Container overflow: fc + Array cookie: ac + Intra object redzone: bb + ASan internal: fe + Left alloca redzone: ca + Right alloca redzone: cb +==23161==ABORTING diff --git a/tests/fuzz-tests/images/bko-156741.raw.xz b/tests/fuzz-tests/images/bko-156741.raw.xz new file mode 100644 index 00000000..af4de268 Binary files /dev/null and b/tests/fuzz-tests/images/bko-156741.raw.xz differ diff --git a/tests/fuzz-tests/images/bko-161811.raw.txt b/tests/fuzz-tests/images/bko-161811.raw.txt new file mode 100644 index 00000000..93374e98 --- /dev/null +++ b/tests/fuzz-tests/images/bko-161811.raw.txt @@ -0,0 +1,81 @@ +URL: https://bugzilla.kernel.org/show_bug.cgi?id=161811 +Lukas Lueg 2016-09-16 20:03:35 UTC + +More news from the fuzzer. The attached image causes a global-buffer-overflow +in btrfsck; using btrfs-progs v4.7-42-g56e9586. You need to compile with ASAN +in order to reproduce. + +The juicy parts: + +==16657==ERROR: AddressSanitizer: global-buffer-overflow on address 0x00000064726f at pc 0x00000054eadd bp 0x7ffec6d9b980 sp 0x7ffec6d9b978 +READ of size 1 at 0x00000064726f thread T0 + #0 0x54eadc in imode_to_type /home/lukas/dev/btrfsfuzz/src-asan/cmds-check.c:635:9 + #1 0x54673a in maybe_free_inode_rec /home/lukas/dev/btrfsfuzz/src-asan/cmds-check.c:932:13 + #2 0x54a79a in add_inode_backref /home/lukas/dev/btrfsfuzz/src-asan/cmds-check.c:1104:2 + #3 0x54b6d2 in process_inode_ref /home/lukas/dev/btrfsfuzz/src-asan/cmds-check.c:1549:3 + #4 0x5489e4 in process_one_leaf /home/lukas/dev/btrfsfuzz/src-asan/cmds-check.c:1810:10 + #5 0x54522e in walk_down_tree /home/lukas/dev/btrfsfuzz/src-asan/cmds-check.c:1958:10 + #6 0x54372e in check_fs_root /home/lukas/dev/btrfsfuzz/src-asan/cmds-check.c:3668:10 + #7 0x5224ef in check_fs_roots /home/lukas/dev/btrfsfuzz/src-asan/cmds-check.c:3809:10 + #8 0x51e772 in cmd_check /home/lukas/dev/btrfsfuzz/src-asan/cmds-check.c:11533:8 + #9 0x4f0ee1 in main /home/lukas/dev/btrfsfuzz/src-asan/btrfs.c:243:8 + #10 0x7f4a5c29f730 in __libc_start_main (/lib64/libc.so.6+0x20730) + #11 0x421358 in _start (/home/lukas/dev/btrfsfuzz/bin-asan/bin/btrfs+0x421358) + +bad full backref, on [4198400] +checking free space cache +checking fs roots +================================================================= +==16657==ERROR: AddressSanitizer: global-buffer-overflow on address 0x00000064726f at pc 0x00000054eadd bp 0x7ffec6d9b980 sp 0x7ffec6d9b978 +READ of size 1 at 0x00000064726f thread T0 + #0 0x54eadc in imode_to_type /home/lukas/dev/btrfsfuzz/src-asan/cmds-check.c:635:9 + #1 0x54673a in maybe_free_inode_rec /home/lukas/dev/btrfsfuzz/src-asan/cmds-check.c:932:13 + #2 0x54a79a in add_inode_backref /home/lukas/dev/btrfsfuzz/src-asan/cmds-check.c:1104:2 + #3 0x54b6d2 in process_inode_ref /home/lukas/dev/btrfsfuzz/src-asan/cmds-check.c:1549:3 + #4 0x5489e4 in process_one_leaf /home/lukas/dev/btrfsfuzz/src-asan/cmds-check.c:1810:10 + #5 0x54522e in walk_down_tree /home/lukas/dev/btrfsfuzz/src-asan/cmds-check.c:1958:10 + #6 0x54372e in check_fs_root /home/lukas/dev/btrfsfuzz/src-asan/cmds-check.c:3668:10 + #7 0x5224ef in check_fs_roots /home/lukas/dev/btrfsfuzz/src-asan/cmds-check.c:3809:10 + #8 0x51e772 in cmd_check /home/lukas/dev/btrfsfuzz/src-asan/cmds-check.c:11533:8 + #9 0x4f0ee1 in main /home/lukas/dev/btrfsfuzz/src-asan/btrfs.c:243:8 + #10 0x7f4a5c29f730 in __libc_start_main (/lib64/libc.so.6+0x20730) + #11 0x421358 in _start (/home/lukas/dev/btrfsfuzz/bin-asan/bin/btrfs+0x421358) + +0x00000064726f is located 49 bytes to the left of global variable '' defined in 'cmds-check.c:3051:2' (0x6472a0) of size 17 + '' is ascii string 'check_inode_recs' +0x00000064726f is located 0 bytes to the right of global variable 'btrfs_type_by_mode' defined in 'cmds-check.c:625:23' (0x647260) of size 15 +SUMMARY: AddressSanitizer: global-buffer-overflow /home/lukas/dev/btrfsfuzz/src-asan/cmds-check.c:635:9 in imode_to_type +Shadow bytes around the buggy address: + 0x0000800c0df0: f9 f9 f9 f9 00 00 05 f9 f9 f9 f9 f9 00 00 02 f9 + 0x0000800c0e00: f9 f9 f9 f9 00 00 f9 f9 f9 f9 f9 f9 00 07 f9 f9 + 0x0000800c0e10: f9 f9 f9 f9 00 00 00 00 f9 f9 f9 f9 00 00 00 01 + 0x0000800c0e20: f9 f9 f9 f9 00 00 f9 f9 f9 f9 f9 f9 00 00 01 f9 + 0x0000800c0e30: f9 f9 f9 f9 00 07 f9 f9 f9 f9 f9 f9 00 00 05 f9 +=>0x0000800c0e40: f9 f9 f9 f9 00 00 02 f9 f9 f9 f9 f9 00[07]f9 f9 + 0x0000800c0e50: f9 f9 f9 f9 00 00 01 f9 f9 f9 f9 f9 00 00 00 07 + 0x0000800c0e60: f9 f9 f9 f9 00 00 00 00 00 04 f9 f9 f9 f9 f9 f9 + 0x0000800c0e70: 00 00 00 00 03 f9 f9 f9 f9 f9 f9 f9 00 00 00 00 + 0x0000800c0e80: 00 00 00 00 00 05 f9 f9 f9 f9 f9 f9 00 00 00 00 + 0x0000800c0e90: 00 00 03 f9 f9 f9 f9 f9 00 00 06 f9 f9 f9 f9 f9 +Shadow byte legend (one shadow byte represents 8 application bytes): + Addressable: 00 + Partially addressable: 01 02 03 04 05 06 07 + Heap left redzone: fa + Heap right redzone: fb + Freed heap region: fd + Stack left redzone: f1 + Stack mid redzone: f2 + Stack right redzone: f3 + Stack partial redzone: f4 + Stack after return: f5 + Stack use after scope: f8 + Global redzone: f9 + Global init order: f6 + Poisoned by user: f7 + Container overflow: fc + Array cookie: ac + Intra object redzone: bb + ASan internal: fe + Left alloca redzone: ca + Right alloca redzone: cb +==16657==ABORTING diff --git a/tests/fuzz-tests/images/bko-161811.raw.xz b/tests/fuzz-tests/images/bko-161811.raw.xz new file mode 100644 index 00000000..8ac31951 Binary files /dev/null and b/tests/fuzz-tests/images/bko-161811.raw.xz differ diff --git a/tests/fuzz-tests/images/bko-161821.raw.txt b/tests/fuzz-tests/images/bko-161821.raw.txt new file mode 100644 index 00000000..c06b0ea7 --- /dev/null +++ b/tests/fuzz-tests/images/bko-161821.raw.txt @@ -0,0 +1,42 @@ +URL: https://bugzilla.kernel.org/show_bug.cgi?id=161821 +Lukas Lueg 2016-09-16 20:45:58 UTC + +More news from the fuzzer. The attached image causes a segmentation fault when +running btrfsck over it; using btrfs-progs v4.7.2-55-g2b7c507 + +The juicy parts: + +==29097==ERROR: AddressSanitizer: SEGV on unknown address 0x000000000070 (pc 0x000000581939 bp 0x7fff1f168590 sp 0x7fff1f168590 T0) + #0 0x581938 in extent_buffer_get /home/lukas/dev/btrfsfuzz/src-asan/./extent_io.h:105:10 + #1 0x583daf in btrfs_search_slot /home/lukas/dev/btrfsfuzz/src-asan/ctree.c:1118:2 + #2 0x538652 in check_owner_ref /home/lukas/dev/btrfsfuzz/src-asan/cmds-check.c:4043:8 + #3 0x535ca5 in check_block /home/lukas/dev/btrfsfuzz/src-asan/cmds-check.c:4433:10 + #4 0x532464 in run_next_block /home/lukas/dev/btrfsfuzz/src-asan/cmds-check.c:6292:8 + #5 0x52f584 in deal_root_from_list /home/lukas/dev/btrfsfuzz/src-asan/cmds-check.c:8391:10 + #6 0x520f81 in check_chunks_and_extents /home/lukas/dev/btrfsfuzz/src-asan/cmds-check.c:8558:8 + #7 0x51e5a9 in cmd_check /home/lukas/dev/btrfsfuzz/src-asan/cmds-check.c:11493:9 + #8 0x4f0ee1 in main /home/lukas/dev/btrfsfuzz/src-asan/btrfs.c:243:8 + #9 0x7f42d367b730 in __libc_start_main (/lib64/libc.so.6+0x20730) + #10 0x421358 in _start (/home/lukas/dev/btrfsfuzz/bin-asan/bin/btrfs+0x421358) + +parent transid verify failed on 4198400 wanted 14 found 1114126 +parent transid verify failed on 4198400 wanted 14 found 1114126 +Ignoring transid failure +ASAN:DEADLYSIGNAL +================================================================= +==29097==ERROR: AddressSanitizer: SEGV on unknown address 0x000000000070 (pc 0x000000581939 bp 0x7fff1f168590 sp 0x7fff1f168590 T0) + #0 0x581938 in extent_buffer_get /home/lukas/dev/btrfsfuzz/src-asan/./extent_io.h:105:10 + #1 0x583daf in btrfs_search_slot /home/lukas/dev/btrfsfuzz/src-asan/ctree.c:1118:2 + #2 0x538652 in check_owner_ref /home/lukas/dev/btrfsfuzz/src-asan/cmds-check.c:4043:8 + #3 0x535ca5 in check_block /home/lukas/dev/btrfsfuzz/src-asan/cmds-check.c:4433:10 + #4 0x532464 in run_next_block /home/lukas/dev/btrfsfuzz/src-asan/cmds-check.c:6292:8 + #5 0x52f584 in deal_root_from_list /home/lukas/dev/btrfsfuzz/src-asan/cmds-check.c:8391:10 + #6 0x520f81 in check_chunks_and_extents /home/lukas/dev/btrfsfuzz/src-asan/cmds-check.c:8558:8 + #7 0x51e5a9 in cmd_check /home/lukas/dev/btrfsfuzz/src-asan/cmds-check.c:11493:9 + #8 0x4f0ee1 in main /home/lukas/dev/btrfsfuzz/src-asan/btrfs.c:243:8 + #9 0x7f42d367b730 in __libc_start_main (/lib64/libc.so.6+0x20730) + #10 0x421358 in _start (/home/lukas/dev/btrfsfuzz/bin-asan/bin/btrfs+0x421358) + +AddressSanitizer can not provide additional info. +SUMMARY: AddressSanitizer: SEGV /home/lukas/dev/btrfsfuzz/src-asan/./extent_io.h:105:10 in extent_buffer_get +==29097==ABORTING diff --git a/tests/fuzz-tests/images/bko-161821.raw.xz b/tests/fuzz-tests/images/bko-161821.raw.xz new file mode 100644 index 00000000..6c673ea4 Binary files /dev/null and b/tests/fuzz-tests/images/bko-161821.raw.xz differ diff --git a/tests/fuzz-tests/images/bko-167551.raw.txt b/tests/fuzz-tests/images/bko-167551.raw.txt new file mode 100644 index 00000000..c2ae8548 --- /dev/null +++ b/tests/fuzz-tests/images/bko-167551.raw.txt @@ -0,0 +1,29 @@ +URL: https://bugzilla.kernel.org/show_bug.cgi?id=167551 +Lukas Lueg 2016-09-17 18:32:31 UTC + +More news from the fuzzer. The attached image causes btrfsck to enter what +seems to be an endless loop; using btrfs-progs v4.7.2-55-g2b7c507 + +Starting program: /home/lukas/dev/btrfsfuzz/bin/bin/btrfsck hang000022.img +Missing separate debuginfos, use: dnf debuginfo-install glibc-2.23.1-10.fc24.x86_64 +[Thread debugging using libthread_db enabled] +Using host libthread_db library "/lib64/libthread_db.so.1". + +Program received signal SIGINT, Interrupt. +0x00000000004576b7 in alloc_extent_buffer (tree=0x6b5420, bytenr=4198400, blocksize=4096) at extent_io.c:628 +628 { +Missing separate debuginfos, use: dnf debuginfo-install libblkid-2.28.2-1.fc24.x86_64 libuuid-2.28.2-1.fc24.x86_64 lzo-2.08-8.fc24.x86_64 zlib-1.2.8-10.fc24.x86_64 +#0 0x00000000004576b7 in alloc_extent_buffer (tree=0x6b5420, bytenr=4198400, blocksize=4096) at extent_io.c:628 +#1 0x0000000000444be3 in read_tree_block_fs_info (fs_info=0x6b53a0, bytenr=4198400, blocksize=4096, parent_transid=14) at disk-io.c:339 +#2 0x0000000000440845 in btrfs_search_slot (trans=, root=, key=, p=, + ins_len=, cow=) at ctree.c:1175 +#3 0x000000000044bf8a in find_first_block_group (root=0x6b5850, path=0x6b41d0, key=0x7fffffffde78) at extent-tree.c:3142 +#4 0x000000000044bd3a in btrfs_read_block_groups (root=0x6b5850) at extent-tree.c:3240 +#5 0x00000000004464b3 in btrfs_setup_all_roots (fs_info=0x6b53a0, root_tree_bytenr=4202496, flags=) at disk-io.c:1077 +#6 0x0000000000446fc5 in __open_ctree_fd (fp=, path=, sb_bytenr=65536, root_tree_bytenr=, + chunk_root_bytenr=, flags=) at disk-io.c:1341 +#7 0x0000000000446d65 in open_ctree_fs_info (filename=0x7fffffffe4f5 "hang000022.img", sb_bytenr=0, root_tree_bytenr=0, + chunk_root_bytenr=0, flags=64) at disk-io.c:1387 +#8 0x000000000041bbe2 in cmd_check (argc=, argv=) at cmds-check.c:11382 +#9 0x000000000040a10d in main (argc=, argv=0x7fffffffe218) at btrfs.c:243 +quit diff --git a/tests/fuzz-tests/images/bko-167551.raw.xz b/tests/fuzz-tests/images/bko-167551.raw.xz new file mode 100644 index 00000000..2292fb4b Binary files /dev/null and b/tests/fuzz-tests/images/bko-167551.raw.xz differ diff --git a/tests/fuzz-tests/images/bko-167781.raw.txt b/tests/fuzz-tests/images/bko-167781.raw.txt new file mode 100644 index 00000000..f185fb6f --- /dev/null +++ b/tests/fuzz-tests/images/bko-167781.raw.txt @@ -0,0 +1,297 @@ +URL: https://bugzilla.kernel.org/show_bug.cgi?id=167781 +Lukas Lueg 2016-09-17 19:01:47 UTC + +More news from the fuzzer. The attached image causes btrfsck to overflow it's +stack by what seems to be an infinite (or at least sufficiently deep) recursion +in resolve_one_root(); using btrfs-progs v4.7-42-g56e9586. + + +checking extents +Chunk[256, 228, 0]: length(4194304), offset(0), type(2) is not found in block group +Chunk[256, 228, 0] stripe[1, 0] is not found in dev extent +Chunk[256, 228, 4194304]: length(1638400), offset(4194304), type(5) is not found in block group +Chunk[256, 228, 4194304] stripe[1, 4194304] is not found in dev extent +Chunk[256, 228, 5832704]: length(1638400), offset(5832704), type(5) is not found in block group +Chunk[256, 228, 5832704] stripe[1, 5832704] is not found in dev extent +ref mismatch on [131072 4096] extent item 0, found 1 +Backref 131072 parent 3 root 3 not found in extent tree +backpointer mismatch on [131072 4096] +bad extent [131072, 135168), type mismatch with chunk +ref mismatch on [4194304 4096] extent item 0, found 1 +Backref 4194304 parent 5 root 5 not found in extent tree +backpointer mismatch on [4194304 4096] +ref mismatch on [4198400 4096] extent item 0, found 1 +Backref 4198400 parent 1 root 1 not found in extent tree +backpointer mismatch on [4198400 4096] +ref mismatch on [4231168 4096] extent item 0, found 1 +Backref 4231168 parent 7 root 7 not found in extent tree +backpointer mismatch on [4231168 4096] +ref mismatch on [3472328296227680304 3472328296227680304] extent item 0, found 1 +Backref 3472328296227680304 root 1 owner 2 offset 0 num_refs 0 not found in extent tree +Incorrect local backref count on 3472328296227680304 root 1 owner 2 offset 0 found 1 wanted 0 back 0x60800000bd20 +backpointer mismatch on [3472328296227680304 3472328296227680304] +Dev extent's total-byte(0) is not equal to byte-used(7471104) in dev[1, 216, 1] +Errors found in extent allocation tree or chunk allocation +checking free space cache +checking fs roots +checking csums +checking root refs +checking quota groups +ASAN:DEADLYSIGNAL +================================================================= +==9638==ERROR: AddressSanitizer: stack-overflow on address 0x7ffc0e2d1ff8 (pc 0x0000005f2ed7 bp 0x7ffc0e2d2010 sp 0x7ffc0e2d2000 T0) + #0 0x5f2ed6 in find_ref_bytenr /home/lukas/dev/btrfsfuzz/src-asan/qgroup-verify.c:253:46 + #1 0x5f2cba in resolve_one_root /home/lukas/dev/btrfsfuzz/src-asan/qgroup-verify.c:560:20 + #2 0x5f2d1e in resolve_one_root /home/lukas/dev/btrfsfuzz/src-asan/qgroup-verify.c:566:9 + #3 0x5f2d1e in resolve_one_root /home/lukas/dev/btrfsfuzz/src-asan/qgroup-verify.c:566:9 + #4 0x5f2d1e in resolve_one_root /home/lukas/dev/btrfsfuzz/src-asan/qgroup-verify.c:566:9 + #5 0x5f2d1e in resolve_one_root /home/lukas/dev/btrfsfuzz/src-asan/qgroup-verify.c:566:9 + #6 0x5f2d1e in resolve_one_root /home/lukas/dev/btrfsfuzz/src-asan/qgroup-verify.c:566:9 + #7 0x5f2d1e in resolve_one_root /home/lukas/dev/btrfsfuzz/src-asan/qgroup-verify.c:566:9 + #8 0x5f2d1e in resolve_one_root /home/lukas/dev/btrfsfuzz/src-asan/qgroup-verify.c:566:9 + #9 0x5f2d1e in resolve_one_root /home/lukas/dev/btrfsfuzz/src-asan/qgroup-verify.c:566:9 + #10 0x5f2d1e in resolve_one_root /home/lukas/dev/btrfsfuzz/src-asan/qgroup-verify.c:566:9 + #11 0x5f2d1e in resolve_one_root /home/lukas/dev/btrfsfuzz/src-asan/qgroup-verify.c:566:9 + #12 0x5f2d1e in resolve_one_root /home/lukas/dev/btrfsfuzz/src-asan/qgroup-verify.c:566:9 + #13 0x5f2d1e in resolve_one_root /home/lukas/dev/btrfsfuzz/src-asan/qgroup-verify.c:566:9 + #14 0x5f2d1e in resolve_one_root /home/lukas/dev/btrfsfuzz/src-asan/qgroup-verify.c:566:9 + #15 0x5f2d1e in resolve_one_root /home/lukas/dev/btrfsfuzz/src-asan/qgroup-verify.c:566:9 + #16 0x5f2d1e in resolve_one_root /home/lukas/dev/btrfsfuzz/src-asan/qgroup-verify.c:566:9 + #17 0x5f2d1e in resolve_one_root /home/lukas/dev/btrfsfuzz/src-asan/qgroup-verify.c:566:9 + #18 0x5f2d1e in resolve_one_root /home/lukas/dev/btrfsfuzz/src-asan/qgroup-verify.c:566:9 + #19 0x5f2d1e in resolve_one_root /home/lukas/dev/btrfsfuzz/src-asan/qgroup-verify.c:566:9 + #20 0x5f2d1e in resolve_one_root /home/lukas/dev/btrfsfuzz/src-asan/qgroup-verify.c:566:9 + #21 0x5f2d1e in resolve_one_root /home/lukas/dev/btrfsfuzz/src-asan/qgroup-verify.c:566:9 + #22 0x5f2d1e in resolve_one_root /home/lukas/dev/btrfsfuzz/src-asan/qgroup-verify.c:566:9 + #23 0x5f2d1e in resolve_one_root /home/lukas/dev/btrfsfuzz/src-asan/qgroup-verify.c:566:9 + #24 0x5f2d1e in resolve_one_root /home/lukas/dev/btrfsfuzz/src-asan/qgroup-verify.c:566:9 + #25 0x5f2d1e in resolve_one_root /home/lukas/dev/btrfsfuzz/src-asan/qgroup-verify.c:566:9 + #26 0x5f2d1e in resolve_one_root /home/lukas/dev/btrfsfuzz/src-asan/qgroup-verify.c:566:9 + #27 0x5f2d1e in resolve_one_root /home/lukas/dev/btrfsfuzz/src-asan/qgroup-verify.c:566:9 + #28 0x5f2d1e in resolve_one_root /home/lukas/dev/btrfsfuzz/src-asan/qgroup-verify.c:566:9 + #29 0x5f2d1e in resolve_one_root /home/lukas/dev/btrfsfuzz/src-asan/qgroup-verify.c:566:9 + #30 0x5f2d1e in resolve_one_root /home/lukas/dev/btrfsfuzz/src-asan/qgroup-verify.c:566:9 + #31 0x5f2d1e in resolve_one_root /home/lukas/dev/btrfsfuzz/src-asan/qgroup-verify.c:566:9 + #32 0x5f2d1e in resolve_one_root /home/lukas/dev/btrfsfuzz/src-asan/qgroup-verify.c:566:9 + #33 0x5f2d1e in resolve_one_root /home/lukas/dev/btrfsfuzz/src-asan/qgroup-verify.c:566:9 + #34 0x5f2d1e in resolve_one_root /home/lukas/dev/btrfsfuzz/src-asan/qgroup-verify.c:566:9 + #35 0x5f2d1e in resolve_one_root /home/lukas/dev/btrfsfuzz/src-asan/qgroup-verify.c:566:9 + #36 0x5f2d1e in resolve_one_root /home/lukas/dev/btrfsfuzz/src-asan/qgroup-verify.c:566:9 + #37 0x5f2d1e in resolve_one_root /home/lukas/dev/btrfsfuzz/src-asan/qgroup-verify.c:566:9 + #38 0x5f2d1e in resolve_one_root /home/lukas/dev/btrfsfuzz/src-asan/qgroup-verify.c:566:9 + #39 0x5f2d1e in resolve_one_root /home/lukas/dev/btrfsfuzz/src-asan/qgroup-verify.c:566:9 + #40 0x5f2d1e in resolve_one_root /home/lukas/dev/btrfsfuzz/src-asan/qgroup-verify.c:566:9 + #41 0x5f2d1e in resolve_one_root /home/lukas/dev/btrfsfuzz/src-asan/qgroup-verify.c:566:9 + #42 0x5f2d1e in resolve_one_root /home/lukas/dev/btrfsfuzz/src-asan/qgroup-verify.c:566:9 + #43 0x5f2d1e in resolve_one_root /home/lukas/dev/btrfsfuzz/src-asan/qgroup-verify.c:566:9 + #44 0x5f2d1e in resolve_one_root /home/lukas/dev/btrfsfuzz/src-asan/qgroup-verify.c:566:9 + #45 0x5f2d1e in resolve_one_root /home/lukas/dev/btrfsfuzz/src-asan/qgroup-verify.c:566:9 + #46 0x5f2d1e in resolve_one_root /home/lukas/dev/btrfsfuzz/src-asan/qgroup-verify.c:566:9 + #47 0x5f2d1e in resolve_one_root /home/lukas/dev/btrfsfuzz/src-asan/qgroup-verify.c:566:9 + #48 0x5f2d1e in resolve_one_root /home/lukas/dev/btrfsfuzz/src-asan/qgroup-verify.c:566:9 + #49 0x5f2d1e in resolve_one_root /home/lukas/dev/btrfsfuzz/src-asan/qgroup-verify.c:566:9 + #50 0x5f2d1e in resolve_one_root /home/lukas/dev/btrfsfuzz/src-asan/qgroup-verify.c:566:9 + #51 0x5f2d1e in resolve_one_root /home/lukas/dev/btrfsfuzz/src-asan/qgroup-verify.c:566:9 + #52 0x5f2d1e in resolve_one_root /home/lukas/dev/btrfsfuzz/src-asan/qgroup-verify.c:566:9 + #53 0x5f2d1e in resolve_one_root /home/lukas/dev/btrfsfuzz/src-asan/qgroup-verify.c:566:9 + #54 0x5f2d1e in resolve_one_root /home/lukas/dev/btrfsfuzz/src-asan/qgroup-verify.c:566:9 + #55 0x5f2d1e in resolve_one_root /home/lukas/dev/btrfsfuzz/src-asan/qgroup-verify.c:566:9 + #56 0x5f2d1e in resolve_one_root /home/lukas/dev/btrfsfuzz/src-asan/qgroup-verify.c:566:9 + #57 0x5f2d1e in resolve_one_root /home/lukas/dev/btrfsfuzz/src-asan/qgroup-verify.c:566:9 + #58 0x5f2d1e in resolve_one_root /home/lukas/dev/btrfsfuzz/src-asan/qgroup-verify.c:566:9 + #59 0x5f2d1e in resolve_one_root /home/lukas/dev/btrfsfuzz/src-asan/qgroup-verify.c:566:9 + #60 0x5f2d1e in resolve_one_root /home/lukas/dev/btrfsfuzz/src-asan/qgroup-verify.c:566:9 + #61 0x5f2d1e in resolve_one_root /home/lukas/dev/btrfsfuzz/src-asan/qgroup-verify.c:566:9 + #62 0x5f2d1e in resolve_one_root /home/lukas/dev/btrfsfuzz/src-asan/qgroup-verify.c:566:9 + #63 0x5f2d1e in resolve_one_root /home/lukas/dev/btrfsfuzz/src-asan/qgroup-verify.c:566:9 + #64 0x5f2d1e in resolve_one_root /home/lukas/dev/btrfsfuzz/src-asan/qgroup-verify.c:566:9 + #65 0x5f2d1e in resolve_one_root /home/lukas/dev/btrfsfuzz/src-asan/qgroup-verify.c:566:9 + #66 0x5f2d1e in resolve_one_root /home/lukas/dev/btrfsfuzz/src-asan/qgroup-verify.c:566:9 + #67 0x5f2d1e in resolve_one_root /home/lukas/dev/btrfsfuzz/src-asan/qgroup-verify.c:566:9 + #68 0x5f2d1e in resolve_one_root /home/lukas/dev/btrfsfuzz/src-asan/qgroup-verify.c:566:9 + #69 0x5f2d1e in resolve_one_root /home/lukas/dev/btrfsfuzz/src-asan/qgroup-verify.c:566:9 + #70 0x5f2d1e in resolve_one_root /home/lukas/dev/btrfsfuzz/src-asan/qgroup-verify.c:566:9 + #71 0x5f2d1e in resolve_one_root /home/lukas/dev/btrfsfuzz/src-asan/qgroup-verify.c:566:9 + #72 0x5f2d1e in resolve_one_root /home/lukas/dev/btrfsfuzz/src-asan/qgroup-verify.c:566:9 + #73 0x5f2d1e in resolve_one_root /home/lukas/dev/btrfsfuzz/src-asan/qgroup-verify.c:566:9 + #74 0x5f2d1e in resolve_one_root /home/lukas/dev/btrfsfuzz/src-asan/qgroup-verify.c:566:9 + #75 0x5f2d1e in resolve_one_root /home/lukas/dev/btrfsfuzz/src-asan/qgroup-verify.c:566:9 + #76 0x5f2d1e in resolve_one_root /home/lukas/dev/btrfsfuzz/src-asan/qgroup-verify.c:566:9 + #77 0x5f2d1e in resolve_one_root /home/lukas/dev/btrfsfuzz/src-asan/qgroup-verify.c:566:9 + #78 0x5f2d1e in resolve_one_root /home/lukas/dev/btrfsfuzz/src-asan/qgroup-verify.c:566:9 + #79 0x5f2d1e in resolve_one_root /home/lukas/dev/btrfsfuzz/src-asan/qgroup-verify.c:566:9 + #80 0x5f2d1e in resolve_one_root /home/lukas/dev/btrfsfuzz/src-asan/qgroup-verify.c:566:9 + #81 0x5f2d1e in resolve_one_root /home/lukas/dev/btrfsfuzz/src-asan/qgroup-verify.c:566:9 + #82 0x5f2d1e in resolve_one_root /home/lukas/dev/btrfsfuzz/src-asan/qgroup-verify.c:566:9 + #83 0x5f2d1e in resolve_one_root /home/lukas/dev/btrfsfuzz/src-asan/qgroup-verify.c:566:9 + #84 0x5f2d1e in resolve_one_root /home/lukas/dev/btrfsfuzz/src-asan/qgroup-verify.c:566:9 + #85 0x5f2d1e in resolve_one_root /home/lukas/dev/btrfsfuzz/src-asan/qgroup-verify.c:566:9 + #86 0x5f2d1e in resolve_one_root /home/lukas/dev/btrfsfuzz/src-asan/qgroup-verify.c:566:9 + #87 0x5f2d1e in resolve_one_root /home/lukas/dev/btrfsfuzz/src-asan/qgroup-verify.c:566:9 + #88 0x5f2d1e in resolve_one_root /home/lukas/dev/btrfsfuzz/src-asan/qgroup-verify.c:566:9 + #89 0x5f2d1e in resolve_one_root /home/lukas/dev/btrfsfuzz/src-asan/qgroup-verify.c:566:9 + #90 0x5f2d1e in resolve_one_root /home/lukas/dev/btrfsfuzz/src-asan/qgroup-verify.c:566:9 + #91 0x5f2d1e in resolve_one_root /home/lukas/dev/btrfsfuzz/src-asan/qgroup-verify.c:566:9 + #92 0x5f2d1e in resolve_one_root /home/lukas/dev/btrfsfuzz/src-asan/qgroup-verify.c:566:9 + #93 0x5f2d1e in resolve_one_root /home/lukas/dev/btrfsfuzz/src-asan/qgroup-verify.c:566:9 + #94 0x5f2d1e in resolve_one_root /home/lukas/dev/btrfsfuzz/src-asan/qgroup-verify.c:566:9 + #95 0x5f2d1e in resolve_one_root /home/lukas/dev/btrfsfuzz/src-asan/qgroup-verify.c:566:9 + #96 0x5f2d1e in resolve_one_root /home/lukas/dev/btrfsfuzz/src-asan/qgroup-verify.c:566:9 + #97 0x5f2d1e in resolve_one_root /home/lukas/dev/btrfsfuzz/src-asan/qgroup-verify.c:566:9 + #98 0x5f2d1e in resolve_one_root /home/lukas/dev/btrfsfuzz/src-asan/qgroup-verify.c:566:9 + #99 0x5f2d1e in resolve_one_root /home/lukas/dev/btrfsfuzz/src-asan/qgroup-verify.c:566:9 + #100 0x5f2d1e in resolve_one_root /home/lukas/dev/btrfsfuzz/src-asan/qgroup-verify.c:566:9 + #101 0x5f2d1e in resolve_one_root /home/lukas/dev/btrfsfuzz/src-asan/qgroup-verify.c:566:9 + #102 0x5f2d1e in resolve_one_root /home/lukas/dev/btrfsfuzz/src-asan/qgroup-verify.c:566:9 + #103 0x5f2d1e in resolve_one_root /home/lukas/dev/btrfsfuzz/src-asan/qgroup-verify.c:566:9 + #104 0x5f2d1e in resolve_one_root /home/lukas/dev/btrfsfuzz/src-asan/qgroup-verify.c:566:9 + #105 0x5f2d1e in resolve_one_root /home/lukas/dev/btrfsfuzz/src-asan/qgroup-verify.c:566:9 + #106 0x5f2d1e in resolve_one_root /home/lukas/dev/btrfsfuzz/src-asan/qgroup-verify.c:566:9 + #107 0x5f2d1e in resolve_one_root /home/lukas/dev/btrfsfuzz/src-asan/qgroup-verify.c:566:9 + #108 0x5f2d1e in resolve_one_root /home/lukas/dev/btrfsfuzz/src-asan/qgroup-verify.c:566:9 + #109 0x5f2d1e in resolve_one_root /home/lukas/dev/btrfsfuzz/src-asan/qgroup-verify.c:566:9 + #110 0x5f2d1e in resolve_one_root /home/lukas/dev/btrfsfuzz/src-asan/qgroup-verify.c:566:9 + #111 0x5f2d1e in resolve_one_root /home/lukas/dev/btrfsfuzz/src-asan/qgroup-verify.c:566:9 + #112 0x5f2d1e in resolve_one_root /home/lukas/dev/btrfsfuzz/src-asan/qgroup-verify.c:566:9 + #113 0x5f2d1e in resolve_one_root /home/lukas/dev/btrfsfuzz/src-asan/qgroup-verify.c:566:9 + #114 0x5f2d1e in resolve_one_root /home/lukas/dev/btrfsfuzz/src-asan/qgroup-verify.c:566:9 + #115 0x5f2d1e in resolve_one_root /home/lukas/dev/btrfsfuzz/src-asan/qgroup-verify.c:566:9 + #116 0x5f2d1e in resolve_one_root /home/lukas/dev/btrfsfuzz/src-asan/qgroup-verify.c:566:9 + #117 0x5f2d1e in resolve_one_root /home/lukas/dev/btrfsfuzz/src-asan/qgroup-verify.c:566:9 + #118 0x5f2d1e in resolve_one_root /home/lukas/dev/btrfsfuzz/src-asan/qgroup-verify.c:566:9 + #119 0x5f2d1e in resolve_one_root /home/lukas/dev/btrfsfuzz/src-asan/qgroup-verify.c:566:9 + #120 0x5f2d1e in resolve_one_root /home/lukas/dev/btrfsfuzz/src-asan/qgroup-verify.c:566:9 + #121 0x5f2d1e in resolve_one_root /home/lukas/dev/btrfsfuzz/src-asan/qgroup-verify.c:566:9 + #122 0x5f2d1e in resolve_one_root /home/lukas/dev/btrfsfuzz/src-asan/qgroup-verify.c:566:9 + #123 0x5f2d1e in resolve_one_root /home/lukas/dev/btrfsfuzz/src-asan/qgroup-verify.c:566:9 + #124 0x5f2d1e in resolve_one_root /home/lukas/dev/btrfsfuzz/src-asan/qgroup-verify.c:566:9 + #125 0x5f2d1e in resolve_one_root /home/lukas/dev/btrfsfuzz/src-asan/qgroup-verify.c:566:9 + #126 0x5f2d1e in resolve_one_root /home/lukas/dev/btrfsfuzz/src-asan/qgroup-verify.c:566:9 + #127 0x5f2d1e in resolve_one_root /home/lukas/dev/btrfsfuzz/src-asan/qgroup-verify.c:566:9 + #128 0x5f2d1e in resolve_one_root /home/lukas/dev/btrfsfuzz/src-asan/qgroup-verify.c:566:9 + #129 0x5f2d1e in resolve_one_root /home/lukas/dev/btrfsfuzz/src-asan/qgroup-verify.c:566:9 + #130 0x5f2d1e in resolve_one_root /home/lukas/dev/btrfsfuzz/src-asan/qgroup-verify.c:566:9 + #131 0x5f2d1e in resolve_one_root /home/lukas/dev/btrfsfuzz/src-asan/qgroup-verify.c:566:9 + #132 0x5f2d1e in resolve_one_root /home/lukas/dev/btrfsfuzz/src-asan/qgroup-verify.c:566:9 + #133 0x5f2d1e in resolve_one_root /home/lukas/dev/btrfsfuzz/src-asan/qgroup-verify.c:566:9 + #134 0x5f2d1e in resolve_one_root /home/lukas/dev/btrfsfuzz/src-asan/qgroup-verify.c:566:9 + #135 0x5f2d1e in resolve_one_root /home/lukas/dev/btrfsfuzz/src-asan/qgroup-verify.c:566:9 + #136 0x5f2d1e in resolve_one_root /home/lukas/dev/btrfsfuzz/src-asan/qgroup-verify.c:566:9 + #137 0x5f2d1e in resolve_one_root /home/lukas/dev/btrfsfuzz/src-asan/qgroup-verify.c:566:9 + #138 0x5f2d1e in resolve_one_root /home/lukas/dev/btrfsfuzz/src-asan/qgroup-verify.c:566:9 + #139 0x5f2d1e in resolve_one_root /home/lukas/dev/btrfsfuzz/src-asan/qgroup-verify.c:566:9 + #140 0x5f2d1e in resolve_one_root /home/lukas/dev/btrfsfuzz/src-asan/qgroup-verify.c:566:9 + #141 0x5f2d1e in resolve_one_root /home/lukas/dev/btrfsfuzz/src-asan/qgroup-verify.c:566:9 + #142 0x5f2d1e in resolve_one_root /home/lukas/dev/btrfsfuzz/src-asan/qgroup-verify.c:566:9 + #143 0x5f2d1e in resolve_one_root /home/lukas/dev/btrfsfuzz/src-asan/qgroup-verify.c:566:9 + #144 0x5f2d1e in resolve_one_root /home/lukas/dev/btrfsfuzz/src-asan/qgroup-verify.c:566:9 + #145 0x5f2d1e in resolve_one_root /home/lukas/dev/btrfsfuzz/src-asan/qgroup-verify.c:566:9 + #146 0x5f2d1e in resolve_one_root /home/lukas/dev/btrfsfuzz/src-asan/qgroup-verify.c:566:9 + #147 0x5f2d1e in resolve_one_root /home/lukas/dev/btrfsfuzz/src-asan/qgroup-verify.c:566:9 + #148 0x5f2d1e in resolve_one_root /home/lukas/dev/btrfsfuzz/src-asan/qgroup-verify.c:566:9 + #149 0x5f2d1e in resolve_one_root /home/lukas/dev/btrfsfuzz/src-asan/qgroup-verify.c:566:9 + #150 0x5f2d1e in resolve_one_root /home/lukas/dev/btrfsfuzz/src-asan/qgroup-verify.c:566:9 + #151 0x5f2d1e in resolve_one_root /home/lukas/dev/btrfsfuzz/src-asan/qgroup-verify.c:566:9 + #152 0x5f2d1e in resolve_one_root /home/lukas/dev/btrfsfuzz/src-asan/qgroup-verify.c:566:9 + #153 0x5f2d1e in resolve_one_root /home/lukas/dev/btrfsfuzz/src-asan/qgroup-verify.c:566:9 + #154 0x5f2d1e in resolve_one_root /home/lukas/dev/btrfsfuzz/src-asan/qgroup-verify.c:566:9 + #155 0x5f2d1e in resolve_one_root /home/lukas/dev/btrfsfuzz/src-asan/qgroup-verify.c:566:9 + #156 0x5f2d1e in resolve_one_root /home/lukas/dev/btrfsfuzz/src-asan/qgroup-verify.c:566:9 + #157 0x5f2d1e in resolve_one_root /home/lukas/dev/btrfsfuzz/src-asan/qgroup-verify.c:566:9 + #158 0x5f2d1e in resolve_one_root /home/lukas/dev/btrfsfuzz/src-asan/qgroup-verify.c:566:9 + #159 0x5f2d1e in resolve_one_root /home/lukas/dev/btrfsfuzz/src-asan/qgroup-verify.c:566:9 + #160 0x5f2d1e in resolve_one_root /home/lukas/dev/btrfsfuzz/src-asan/qgroup-verify.c:566:9 + #161 0x5f2d1e in resolve_one_root /home/lukas/dev/btrfsfuzz/src-asan/qgroup-verify.c:566:9 + #162 0x5f2d1e in resolve_one_root /home/lukas/dev/btrfsfuzz/src-asan/qgroup-verify.c:566:9 + #163 0x5f2d1e in resolve_one_root /home/lukas/dev/btrfsfuzz/src-asan/qgroup-verify.c:566:9 + #164 0x5f2d1e in resolve_one_root /home/lukas/dev/btrfsfuzz/src-asan/qgroup-verify.c:566:9 + #165 0x5f2d1e in resolve_one_root /home/lukas/dev/btrfsfuzz/src-asan/qgroup-verify.c:566:9 + #166 0x5f2d1e in resolve_one_root /home/lukas/dev/btrfsfuzz/src-asan/qgroup-verify.c:566:9 + #167 0x5f2d1e in resolve_one_root /home/lukas/dev/btrfsfuzz/src-asan/qgroup-verify.c:566:9 + #168 0x5f2d1e in resolve_one_root /home/lukas/dev/btrfsfuzz/src-asan/qgroup-verify.c:566:9 + #169 0x5f2d1e in resolve_one_root /home/lukas/dev/btrfsfuzz/src-asan/qgroup-verify.c:566:9 + #170 0x5f2d1e in resolve_one_root /home/lukas/dev/btrfsfuzz/src-asan/qgroup-verify.c:566:9 + #171 0x5f2d1e in resolve_one_root /home/lukas/dev/btrfsfuzz/src-asan/qgroup-verify.c:566:9 + #172 0x5f2d1e in resolve_one_root /home/lukas/dev/btrfsfuzz/src-asan/qgroup-verify.c:566:9 + #173 0x5f2d1e in resolve_one_root /home/lukas/dev/btrfsfuzz/src-asan/qgroup-verify.c:566:9 + #174 0x5f2d1e in resolve_one_root /home/lukas/dev/btrfsfuzz/src-asan/qgroup-verify.c:566:9 + #175 0x5f2d1e in resolve_one_root /home/lukas/dev/btrfsfuzz/src-asan/qgroup-verify.c:566:9 + #176 0x5f2d1e in resolve_one_root /home/lukas/dev/btrfsfuzz/src-asan/qgroup-verify.c:566:9 + #177 0x5f2d1e in resolve_one_root /home/lukas/dev/btrfsfuzz/src-asan/qgroup-verify.c:566:9 + #178 0x5f2d1e in resolve_one_root /home/lukas/dev/btrfsfuzz/src-asan/qgroup-verify.c:566:9 + #179 0x5f2d1e in resolve_one_root /home/lukas/dev/btrfsfuzz/src-asan/qgroup-verify.c:566:9 + #180 0x5f2d1e in resolve_one_root /home/lukas/dev/btrfsfuzz/src-asan/qgroup-verify.c:566:9 + #181 0x5f2d1e in resolve_one_root /home/lukas/dev/btrfsfuzz/src-asan/qgroup-verify.c:566:9 + #182 0x5f2d1e in resolve_one_root /home/lukas/dev/btrfsfuzz/src-asan/qgroup-verify.c:566:9 + #183 0x5f2d1e in resolve_one_root /home/lukas/dev/btrfsfuzz/src-asan/qgroup-verify.c:566:9 + #184 0x5f2d1e in resolve_one_root /home/lukas/dev/btrfsfuzz/src-asan/qgroup-verify.c:566:9 + #185 0x5f2d1e in resolve_one_root /home/lukas/dev/btrfsfuzz/src-asan/qgroup-verify.c:566:9 + #186 0x5f2d1e in resolve_one_root /home/lukas/dev/btrfsfuzz/src-asan/qgroup-verify.c:566:9 + #187 0x5f2d1e in resolve_one_root /home/lukas/dev/btrfsfuzz/src-asan/qgroup-verify.c:566:9 + #188 0x5f2d1e in resolve_one_root /home/lukas/dev/btrfsfuzz/src-asan/qgroup-verify.c:566:9 + #189 0x5f2d1e in resolve_one_root /home/lukas/dev/btrfsfuzz/src-asan/qgroup-verify.c:566:9 + #190 0x5f2d1e in resolve_one_root /home/lukas/dev/btrfsfuzz/src-asan/qgroup-verify.c:566:9 + #191 0x5f2d1e in resolve_one_root /home/lukas/dev/btrfsfuzz/src-asan/qgroup-verify.c:566:9 + #192 0x5f2d1e in resolve_one_root /home/lukas/dev/btrfsfuzz/src-asan/qgroup-verify.c:566:9 + #193 0x5f2d1e in resolve_one_root /home/lukas/dev/btrfsfuzz/src-asan/qgroup-verify.c:566:9 + #194 0x5f2d1e in resolve_one_root /home/lukas/dev/btrfsfuzz/src-asan/qgroup-verify.c:566:9 + #195 0x5f2d1e in resolve_one_root /home/lukas/dev/btrfsfuzz/src-asan/qgroup-verify.c:566:9 + #196 0x5f2d1e in resolve_one_root /home/lukas/dev/btrfsfuzz/src-asan/qgroup-verify.c:566:9 + #197 0x5f2d1e in resolve_one_root /home/lukas/dev/btrfsfuzz/src-asan/qgroup-verify.c:566:9 + #198 0x5f2d1e in resolve_one_root /home/lukas/dev/btrfsfuzz/src-asan/qgroup-verify.c:566:9 + #199 0x5f2d1e in resolve_one_root /home/lukas/dev/btrfsfuzz/src-asan/qgroup-verify.c:566:9 + #200 0x5f2d1e in resolve_one_root /home/lukas/dev/btrfsfuzz/src-asan/qgroup-verify.c:566:9 + #201 0x5f2d1e in resolve_one_root /home/lukas/dev/btrfsfuzz/src-asan/qgroup-verify.c:566:9 + #202 0x5f2d1e in resolve_one_root /home/lukas/dev/btrfsfuzz/src-asan/qgroup-verify.c:566:9 + #203 0x5f2d1e in resolve_one_root /home/lukas/dev/btrfsfuzz/src-asan/qgroup-verify.c:566:9 + #204 0x5f2d1e in resolve_one_root /home/lukas/dev/btrfsfuzz/src-asan/qgroup-verify.c:566:9 + #205 0x5f2d1e in resolve_one_root /home/lukas/dev/btrfsfuzz/src-asan/qgroup-verify.c:566:9 + #206 0x5f2d1e in resolve_one_root /home/lukas/dev/btrfsfuzz/src-asan/qgroup-verify.c:566:9 + #207 0x5f2d1e in resolve_one_root /home/lukas/dev/btrfsfuzz/src-asan/qgroup-verify.c:566:9 + #208 0x5f2d1e in resolve_one_root /home/lukas/dev/btrfsfuzz/src-asan/qgroup-verify.c:566:9 + #209 0x5f2d1e in resolve_one_root /home/lukas/dev/btrfsfuzz/src-asan/qgroup-verify.c:566:9 + #210 0x5f2d1e in resolve_one_root /home/lukas/dev/btrfsfuzz/src-asan/qgroup-verify.c:566:9 + #211 0x5f2d1e in resolve_one_root /home/lukas/dev/btrfsfuzz/src-asan/qgroup-verify.c:566:9 + #212 0x5f2d1e in resolve_one_root /home/lukas/dev/btrfsfuzz/src-asan/qgroup-verify.c:566:9 + #213 0x5f2d1e in resolve_one_root /home/lukas/dev/btrfsfuzz/src-asan/qgroup-verify.c:566:9 + #214 0x5f2d1e in resolve_one_root /home/lukas/dev/btrfsfuzz/src-asan/qgroup-verify.c:566:9 + #215 0x5f2d1e in resolve_one_root /home/lukas/dev/btrfsfuzz/src-asan/qgroup-verify.c:566:9 + #216 0x5f2d1e in resolve_one_root /home/lukas/dev/btrfsfuzz/src-asan/qgroup-verify.c:566:9 + #217 0x5f2d1e in resolve_one_root /home/lukas/dev/btrfsfuzz/src-asan/qgroup-verify.c:566:9 + #218 0x5f2d1e in resolve_one_root /home/lukas/dev/btrfsfuzz/src-asan/qgroup-verify.c:566:9 + #219 0x5f2d1e in resolve_one_root /home/lukas/dev/btrfsfuzz/src-asan/qgroup-verify.c:566:9 + #220 0x5f2d1e in resolve_one_root /home/lukas/dev/btrfsfuzz/src-asan/qgroup-verify.c:566:9 + #221 0x5f2d1e in resolve_one_root /home/lukas/dev/btrfsfuzz/src-asan/qgroup-verify.c:566:9 + #222 0x5f2d1e in resolve_one_root /home/lukas/dev/btrfsfuzz/src-asan/qgroup-verify.c:566:9 + #223 0x5f2d1e in resolve_one_root /home/lukas/dev/btrfsfuzz/src-asan/qgroup-verify.c:566:9 + #224 0x5f2d1e in resolve_one_root /home/lukas/dev/btrfsfuzz/src-asan/qgroup-verify.c:566:9 + #225 0x5f2d1e in resolve_one_root /home/lukas/dev/btrfsfuzz/src-asan/qgroup-verify.c:566:9 + #226 0x5f2d1e in resolve_one_root /home/lukas/dev/btrfsfuzz/src-asan/qgroup-verify.c:566:9 + #227 0x5f2d1e in resolve_one_root /home/lukas/dev/btrfsfuzz/src-asan/qgroup-verify.c:566:9 + #228 0x5f2d1e in resolve_one_root /home/lukas/dev/btrfsfuzz/src-asan/qgroup-verify.c:566:9 + #229 0x5f2d1e in resolve_one_root /home/lukas/dev/btrfsfuzz/src-asan/qgroup-verify.c:566:9 + #230 0x5f2d1e in resolve_one_root /home/lukas/dev/btrfsfuzz/src-asan/qgroup-verify.c:566:9 + #231 0x5f2d1e in resolve_one_root /home/lukas/dev/btrfsfuzz/src-asan/qgroup-verify.c:566:9 + #232 0x5f2d1e in resolve_one_root /home/lukas/dev/btrfsfuzz/src-asan/qgroup-verify.c:566:9 + #233 0x5f2d1e in resolve_one_root /home/lukas/dev/btrfsfuzz/src-asan/qgroup-verify.c:566:9 + #234 0x5f2d1e in resolve_one_root /home/lukas/dev/btrfsfuzz/src-asan/qgroup-verify.c:566:9 + #235 0x5f2d1e in resolve_one_root /home/lukas/dev/btrfsfuzz/src-asan/qgroup-verify.c:566:9 + #236 0x5f2d1e in resolve_one_root /home/lukas/dev/btrfsfuzz/src-asan/qgroup-verify.c:566:9 + #237 0x5f2d1e in resolve_one_root /home/lukas/dev/btrfsfuzz/src-asan/qgroup-verify.c:566:9 + #238 0x5f2d1e in resolve_one_root /home/lukas/dev/btrfsfuzz/src-asan/qgroup-verify.c:566:9 + #239 0x5f2d1e in resolve_one_root /home/lukas/dev/btrfsfuzz/src-asan/qgroup-verify.c:566:9 + #240 0x5f2d1e in resolve_one_root /home/lukas/dev/btrfsfuzz/src-asan/qgroup-verify.c:566:9 + #241 0x5f2d1e in resolve_one_root /home/lukas/dev/btrfsfuzz/src-asan/qgroup-verify.c:566:9 + #242 0x5f2d1e in resolve_one_root /home/lukas/dev/btrfsfuzz/src-asan/qgroup-verify.c:566:9 + #243 0x5f2d1e in resolve_one_root /home/lukas/dev/btrfsfuzz/src-asan/qgroup-verify.c:566:9 + #244 0x5f2d1e in resolve_one_root /home/lukas/dev/btrfsfuzz/src-asan/qgroup-verify.c:566:9 + #245 0x5f2d1e in resolve_one_root /home/lukas/dev/btrfsfuzz/src-asan/qgroup-verify.c:566:9 + #246 0x5f2d1e in resolve_one_root /home/lukas/dev/btrfsfuzz/src-asan/qgroup-verify.c:566:9 + #247 0x5f2d1e in resolve_one_root /home/lukas/dev/btrfsfuzz/src-asan/qgroup-verify.c:566:9 + #248 0x5f2d1e in resolve_one_root /home/lukas/dev/btrfsfuzz/src-asan/qgroup-verify.c:566:9 + #249 0x5f2d1e in resolve_one_root /home/lukas/dev/btrfsfuzz/src-asan/qgroup-verify.c:566:9 + #250 0x5f2d1e in resolve_one_root /home/lukas/dev/btrfsfuzz/src-asan/qgroup-verify.c:566:9 + #251 0x5f2d1e in resolve_one_root /home/lukas/dev/btrfsfuzz/src-asan/qgroup-verify.c:566:9 + +SUMMARY: AddressSanitizer: stack-overflow /home/lukas/dev/btrfsfuzz/src-asan/qgroup-verify.c:253:46 in find_ref_bytenr +==9638==ABORTING diff --git a/tests/fuzz-tests/images/bko-167781.raw.xz b/tests/fuzz-tests/images/bko-167781.raw.xz new file mode 100644 index 00000000..a4bd1de5 Binary files /dev/null and b/tests/fuzz-tests/images/bko-167781.raw.xz differ diff --git a/tests/fuzz-tests/images/bko-167921.raw.txt b/tests/fuzz-tests/images/bko-167921.raw.txt new file mode 100644 index 00000000..04ae8a19 --- /dev/null +++ b/tests/fuzz-tests/images/bko-167921.raw.txt @@ -0,0 +1,55 @@ +URL: https://bugzilla.kernel.org/show_bug.cgi?id=167921 +Lukas Lueg 2016-09-17 19:16:19 UTC + +More news from the fuzzer. The attached image causes a call to abort() when +running btrfsck over it; using btrfs-progs v4.7.2-55-g2b7c507 + +Program received signal SIGABRT, Aborted. +0x00007ffff6fae6f5 in raise () from /lib64/libc.so.6 +#0 0x00007ffff6fae6f5 in raise () from /lib64/libc.so.6 +#1 0x00007ffff6fb02fa in abort () from /lib64/libc.so.6 +#2 0x000000000042390b in run_next_block (root=, bits=, bits_nr=1024, last=, + pending=, seen=, reada=, nodes=, extent_cache=, + chunk_cache=, dev_cache=, block_group_cache=, dev_extent_cache=, + ri=) at cmds-check.c:6424 +#3 0x0000000000421d9b in deal_root_from_list (list=, root=, bits=, bits_nr=1024, + pending=, seen=, reada=, nodes=, extent_cache=, + chunk_cache=, dev_cache=, block_group_cache=, dev_extent_cache=) + at cmds-check.c:8391 +#4 0x000000000041d1d2 in check_chunks_and_extents (root=) at cmds-check.c:8567 +#5 0x000000000041bf0b in cmd_check (argc=, argv=) at cmds-check.c:11493 +#6 0x000000000040a10d in main (argc=, argv=0x7fffffffe218) at btrfs.c:243 + +parent transid verify failed on 4194304 wanted 65305493131755520 found 14 +parent transid verify failed on 4194304 wanted 65305493131755520 found 14 +Ignoring transid failure +Checking filesystem on crashing_images/id:000162,sig:06,src:000059+001444,op:splice,rep:2.img +UUID: 056b0872-c0a7-4121-8ac9-2263ffbee306 +checking extents/bin/sh: line 3: 3091 Aborted LD_LIBRARY_PATH=/home/lukas/dev/btrfsfuzz/bin-asan/lib LD_PRELOAD=/home/lukas/dev/afl_git/libdislocator/libdislocator.so ASAN_OPTIONS=detect_leaks=0 /home/lukas/dev/btrfsfuzz/bin-asan/bin/btrfsck crashing_images/id:000162,sig:06,src:000059+001444,op:splice,rep:2.img +Starting program: /home/lukas/dev/btrfsfuzz/bin/bin/btrfsck crash000160.img +Missing separate debuginfos, use: dnf debuginfo-install glibc-2.23.1-10.fc24.x86_64 +[Thread debugging using libthread_db enabled] +Using host libthread_db library "/lib64/libthread_db.so.1". +[Inferior 1 (process 21730) exited with code 0376] +Missing separate debuginfos, use: dnf debuginfo-install libblkid-2.28.2-1.fc24.x86_64 libuuid-2.28.2-1.fc24.x86_64 lzo-2.08-8.fc24.x86_64 zlib-1.2.8-10.fc24.x86_64 +No stack. +Starting program: /home/lukas/dev/btrfsfuzz/bin/bin/btrfsck crash000162.img +[Thread debugging using libthread_db enabled] +Using host libthread_db library "/lib64/libthread_db.so.1". + +Program received signal SIGABRT, Aborted. +0x00007ffff6fae6f5 in raise () from /lib64/libc.so.6 +#0 0x00007ffff6fae6f5 in raise () from /lib64/libc.so.6 +#1 0x00007ffff6fb02fa in abort () from /lib64/libc.so.6 +#2 0x000000000042390b in run_next_block (root=, bits=, bits_nr=1024, last=, + pending=, seen=, reada=, nodes=, extent_cache=, + chunk_cache=, dev_cache=, block_group_cache=, dev_extent_cache=, + ri=) at cmds-check.c:6424 +#3 0x0000000000421d9b in deal_root_from_list (list=, root=, bits=, bits_nr=1024, + pending=, seen=, reada=, nodes=, extent_cache=, + chunk_cache=, dev_cache=, block_group_cache=, dev_extent_cache=) + at cmds-check.c:8391 +#4 0x000000000041d1d2 in check_chunks_and_extents (root=) at cmds-check.c:8567 +#5 0x000000000041bf0b in cmd_check (argc=, argv=) at cmds-check.c:11493 +#6 0x000000000040a10d in main (argc=, argv=0x7fffffffe218) at btrfs.c:243 +quit diff --git a/tests/fuzz-tests/images/bko-167921.raw.xz b/tests/fuzz-tests/images/bko-167921.raw.xz new file mode 100644 index 00000000..41d7157e Binary files /dev/null and b/tests/fuzz-tests/images/bko-167921.raw.xz differ diff --git a/tests/fuzz-tests/images/bko-168301.raw.txt b/tests/fuzz-tests/images/bko-168301.raw.txt new file mode 100644 index 00000000..9f3bab87 --- /dev/null +++ b/tests/fuzz-tests/images/bko-168301.raw.txt @@ -0,0 +1,51 @@ +URL: https://bugzilla.kernel.org/show_bug.cgi?id=168301 +Lukas Lueg 2016-09-17 20:00:11 UTC + +More news from the fuzzer. The attached image causes a call to abort() when +running btrfsck over it; using btrfs-progs v4.7.2-55-g2b7c507 + +Program received signal SIGABRT, Aborted. +0x00007ffff6fae6f5 in raise () from /lib64/libc.so.6 +#0 0x00007ffff6fae6f5 in raise () from /lib64/libc.so.6 +#1 0x00007ffff6fb02fa in abort () from /lib64/libc.so.6 +#2 0x0000000000424fc7 in add_data_backref (extent_cache=0x7fffffffdfe0, bytenr=18446744073709551615, parent=, + root=, owner=, offset=, num_refs=, found_ref=, + max_size=4096) at cmds-check.c:4856 +#3 0x00000000004234bd in run_next_block (root=, bits=, bits_nr=1024, last=, + pending=, seen=, reada=, nodes=, extent_cache=, + chunk_cache=, dev_cache=, block_group_cache=, dev_extent_cache=, + ri=) at cmds-check.c:6388 +#4 0x0000000000421d9b in deal_root_from_list (list=, root=, bits=, bits_nr=1024, + pending=, seen=, reada=, nodes=, extent_cache=, + chunk_cache=, dev_cache=, block_group_cache=, dev_extent_cache=) + at cmds-check.c:8391 +#5 0x000000000041d160 in check_chunks_and_extents (root=) at cmds-check.c:8558 +#6 0x000000000041bf0b in cmd_check (argc=, argv=) at cmds-check.c:11493 +#7 0x000000000040a10d in main (argc=, argv=0x7fffffffe218) at btrfs.c:243 + +Checking filesystem on crashing_images/id:000170,sig:06,src:001268,op:havoc,rep:8.img +UUID: 056b0872-c0a7-4121-8ac9-2263ffbee306 +checking extents/bin/sh: line 3: 4644 Aborted LD_LIBRARY_PATH=/home/lukas/dev/btrfsfuzz/bin-asan/lib LD_PRELOAD=/home/lukas/dev/afl_git/libdislocator/libdislocator.so ASAN_OPTIONS=detect_leaks=0 /home/lukas/dev/btrfsfuzz/bin-asan/bin/btrfsck crashing_images/id:000170,sig:06,src:001268,op:havoc,rep:8.img +Starting program: /home/lukas/dev/btrfsfuzz/bin/bin/btrfsck crash000170.img +[Thread debugging using libthread_db enabled] +Using host libthread_db library "/lib64/libthread_db.so.1". + +Program received signal SIGABRT, Aborted. +0x00007ffff6fae6f5 in raise () from /lib64/libc.so.6 +#0 0x00007ffff6fae6f5 in raise () from /lib64/libc.so.6 +#1 0x00007ffff6fb02fa in abort () from /lib64/libc.so.6 +#2 0x0000000000424fc7 in add_data_backref (extent_cache=0x7fffffffdfe0, bytenr=18446744073709551615, parent=, + root=, owner=, offset=, num_refs=, found_ref=, + max_size=4096) at cmds-check.c:4856 +#3 0x00000000004234bd in run_next_block (root=, bits=, bits_nr=1024, last=, + pending=, seen=, reada=, nodes=, extent_cache=, + chunk_cache=, dev_cache=, block_group_cache=, dev_extent_cache=, + ri=) at cmds-check.c:6388 +#4 0x0000000000421d9b in deal_root_from_list (list=, root=, bits=, bits_nr=1024, + pending=, seen=, reada=, nodes=, extent_cache=, + chunk_cache=, dev_cache=, block_group_cache=, dev_extent_cache=) + at cmds-check.c:8391 +#5 0x000000000041d160 in check_chunks_and_extents (root=) at cmds-check.c:8558 +#6 0x000000000041bf0b in cmd_check (argc=, argv=) at cmds-check.c:11493 +#7 0x000000000040a10d in main (argc=, argv=0x7fffffffe218) at btrfs.c:243 +quit diff --git a/tests/fuzz-tests/images/bko-168301.raw.xz b/tests/fuzz-tests/images/bko-168301.raw.xz new file mode 100644 index 00000000..4c7f4623 Binary files /dev/null and b/tests/fuzz-tests/images/bko-168301.raw.xz differ diff --git a/tests/fuzz-tests/images/bko-169301-1-blocksize-zero.raw.txt b/tests/fuzz-tests/images/bko-169301-1-blocksize-zero.raw.txt new file mode 100644 index 00000000..c5ec8ee1 --- /dev/null +++ b/tests/fuzz-tests/images/bko-169301-1-blocksize-zero.raw.txt @@ -0,0 +1,134 @@ +URL: https://bugzilla.kernel.org/show_bug.cgi?id=169301 +Lukas Lueg 2016-09-18 09:07:55 UTC + +More news from the fuzzer. The attached image causes a heap-use-after-free +when running btrfsck with ASAN over it; using btrfs-progs v4.7.2-56-ge8c2013 + +==3439==ERROR: AddressSanitizer: heap-use-after-free on address 0x621000014170 at pc 0x0000005c05ae bp 0x7ffe84ef8d00 sp 0x7ffe84ef8cf8 +READ of size 4 at 0x621000014170 thread T0 + #0 0x5c05ad in free_extent_buffer /home/slave/dev/btrfsfuzz/src-asan/extent_io.c:579:10 + #1 0x59360c in btrfs_release_all_roots /home/slave/dev/btrfsfuzz/src-asan/disk-io.c:1096:3 + #2 0x5961bb in close_ctree_fs_info /home/slave/dev/btrfsfuzz/src-asan/disk-io.c:1805:2 + #3 0x5246e7 in close_ctree /home/slave/dev/btrfsfuzz/src-asan/./disk-io.h:155:9 + #4 0x51e334 in cmd_check /home/slave/dev/btrfsfuzz/src-asan/cmds-check.c:11618:2 + #5 0x4f0ee1 in main /home/slave/dev/btrfsfuzz/src-asan/btrfs.c:243:8 + #6 0x7f792c60e730 in __libc_start_main (/lib64/libc.so.6+0x20730) + #7 0x421358 in _start (/home/slave/dev/btrfsfuzz/bin-asan/bin/btrfs+0x421358) + +Probably somewhat related to this: The image crash000255.img causes btrfsck to +try to allocate around 3.5gb of memory in one chunk, sending ASAN into a death +spiral. On systems with sufficient memory, the heap-use-after-free turns up. + +parent transid verify failed on 0 wanted 3472328296227680304 found 0 +parent transid verify failed on 0 wanted 3472328296227680304 found 0 +Ignoring transid failure +Chunk[256, 228, 0]: length(4194304), offset(0), type(2) is not found in block group +Chunk[256, 228, 0] stripe[1, 0] is not found in dev extent +Chunk[256, 228, 4194304]: length(1638400), offset(4194304), type(5) is not found in block group +Chunk[256, 228, 4194304] stripe[1, 4194304] is not found in dev extent +Chunk[256, 228, 5832704]: length(1638400), offset(5832704), type(5) is not found in block group +Chunk[256, 228, 5832704] stripe[1, 5832704] is not found in dev extent +ref mismatch on [0 4096] extent item 0, found 1 +Backref 0 parent 0 root 0 not found in extent tree +backpointer mismatch on [0 4096] +bad extent [0, 4096), type mismatch with chunk +ref mismatch on [131072 4096] extent item 0, found 1 +Backref 131072 parent 3 root 3 not found in extent tree +backpointer mismatch on [131072 4096] +ref mismatch on [4198400 4096] extent item 0, found 1 +Backref 4198400 parent 1 root 1 not found in extent tree +backpointer mismatch on [4198400 4096] +ref mismatch on [4231168 4096] extent item 0, found 1 +Backref 4231168 parent 7 root 7 not found in extent tree +backpointer mismatch on [4231168 4096] +ref mismatch on [3472328296227680304 3472328296227680304] extent item 0, found 1 +Backref 3472328296227680304 root 1 owner 2 offset 0 num_refs 0 not found in extent tree +Incorrect local backref count on 3472328296227680304 root 1 owner 2 offset 0 found 1 wanted 0 back 0x60700000ddf0 +backpointer mismatch on [3472328296227680304 3472328296227680304] +Dev extent's total-byte(0) is not equal to byte-used(7471104) in dev[1, 216, 1] +checking free space cache +checking fs roots +root 5 root dir 3472328296227680304 not found +checking csums +checking root refs +checking quota groups +ERROR: while mapping refs: -5 +================================================================= +==3439==ERROR: AddressSanitizer: heap-use-after-free on address 0x621000014170 at pc 0x0000005c05ae bp 0x7ffe84ef8d00 sp 0x7ffe84ef8cf8 +READ of size 4 at 0x621000014170 thread T0 + #0 0x5c05ad in free_extent_buffer /home/slave/dev/btrfsfuzz/src-asan/extent_io.c:579:10 + #1 0x59360c in btrfs_release_all_roots /home/slave/dev/btrfsfuzz/src-asan/disk-io.c:1096:3 + #2 0x5961bb in close_ctree_fs_info /home/slave/dev/btrfsfuzz/src-asan/disk-io.c:1805:2 + #3 0x5246e7 in close_ctree /home/slave/dev/btrfsfuzz/src-asan/./disk-io.h:155:9 + #4 0x51e334 in cmd_check /home/slave/dev/btrfsfuzz/src-asan/cmds-check.c:11618:2 + #5 0x4f0ee1 in main /home/slave/dev/btrfsfuzz/src-asan/btrfs.c:243:8 + #6 0x7f792c60e730 in __libc_start_main (/lib64/libc.so.6+0x20730) + #7 0x421358 in _start (/home/slave/dev/btrfsfuzz/bin-asan/bin/btrfs+0x421358) + +0x621000014170 is located 112 bytes inside of 4224-byte region [0x621000014100,0x621000015180) +freed by thread T0 here: + #0 0x4bf990 in __interceptor_cfree.localalias.1 (/home/slave/dev/btrfsfuzz/bin-asan/bin/btrfs+0x4bf990) + #1 0x5c0582 in free_extent_buffer /home/slave/dev/btrfsfuzz/src-asan/extent_io.c:591:3 + #2 0x5c1b18 in alloc_extent_buffer /home/slave/dev/btrfsfuzz/src-asan/extent_io.c:644:4 + #3 0x58de0c in btrfs_find_create_tree_block /home/slave/dev/btrfsfuzz/src-asan/disk-io.c:193:9 + #4 0x58e880 in read_tree_block_fs_info /home/slave/dev/btrfsfuzz/src-asan/disk-io.c:339:7 + #5 0x5f2d74 in read_tree_block /home/slave/dev/btrfsfuzz/src-asan/./disk-io.h:112:9 + #6 0x5f2b52 in travel_tree /home/slave/dev/btrfsfuzz/src-asan/qgroup-verify.c:692:7 + #7 0x5f299b in add_refs_for_implied /home/slave/dev/btrfsfuzz/src-asan/qgroup-verify.c:748:8 + #8 0x5efd39 in map_implied_refs /home/slave/dev/btrfsfuzz/src-asan/qgroup-verify.c:766:9 + #9 0x5eed89 in qgroup_verify_all /home/slave/dev/btrfsfuzz/src-asan/qgroup-verify.c:1366:8 + #10 0x51ea14 in cmd_check /home/slave/dev/btrfsfuzz/src-asan/cmds-check.c:11571:9 + #11 0x4f0ee1 in main /home/slave/dev/btrfsfuzz/src-asan/btrfs.c:243:8 + #12 0x7f792c60e730 in __libc_start_main (/lib64/libc.so.6+0x20730) + +previously allocated by thread T0 here: + #0 0x4bfca0 in calloc (/home/slave/dev/btrfsfuzz/bin-asan/bin/btrfs+0x4bfca0) + #1 0x5c16ca in __alloc_extent_buffer /home/slave/dev/btrfsfuzz/src-asan/extent_io.c:542:7 + #2 0x5c1b26 in alloc_extent_buffer /home/slave/dev/btrfsfuzz/src-asan/extent_io.c:646:8 + #3 0x58de0c in btrfs_find_create_tree_block /home/slave/dev/btrfsfuzz/src-asan/disk-io.c:193:9 + #4 0x58e880 in read_tree_block_fs_info /home/slave/dev/btrfsfuzz/src-asan/disk-io.c:339:7 + #5 0x5918a2 in read_tree_block /home/slave/dev/btrfsfuzz/src-asan/./disk-io.h:112:9 + #6 0x591712 in find_and_setup_root /home/slave/dev/btrfsfuzz/src-asan/disk-io.c:647:15 + #7 0x593243 in setup_root_or_create_block /home/slave/dev/btrfsfuzz/src-asan/disk-io.c:966:8 + #8 0x592a06 in btrfs_setup_all_roots /home/slave/dev/btrfsfuzz/src-asan/disk-io.c:1045:8 + #9 0x5948fe in __open_ctree_fd /home/slave/dev/btrfsfuzz/src-asan/disk-io.c:1341:8 + #10 0x5942b5 in open_ctree_fs_info /home/slave/dev/btrfsfuzz/src-asan/disk-io.c:1387:9 + #11 0x51dff2 in cmd_check /home/slave/dev/btrfsfuzz/src-asan/cmds-check.c:11382:9 + #12 0x4f0ee1 in main /home/slave/dev/btrfsfuzz/src-asan/btrfs.c:243:8 + #13 0x7f792c60e730 in __libc_start_main (/lib64/libc.so.6+0x20730) + +SUMMARY: AddressSanitizer: heap-use-after-free /home/slave/dev/btrfsfuzz/src-asan/extent_io.c:579:10 in free_extent_buffer +Shadow bytes around the buggy address: + 0x0c427fffa7d0: fa fa fa fa fa fa fa fa fa fa fa fa fa fa fa fa + 0x0c427fffa7e0: fa fa fa fa fa fa fa fa fa fa fa fa fa fa fa fa + 0x0c427fffa7f0: fa fa fa fa fa fa fa fa fa fa fa fa fa fa fa fa + 0x0c427fffa800: fa fa fa fa fa fa fa fa fa fa fa fa fa fa fa fa + 0x0c427fffa810: fa fa fa fa fa fa fa fa fa fa fa fa fa fa fa fa +=>0x0c427fffa820: fd fd fd fd fd fd fd fd fd fd fd fd fd fd[fd]fd + 0x0c427fffa830: fd fd fd fd fd fd fd fd fd fd fd fd fd fd fd fd + 0x0c427fffa840: fd fd fd fd fd fd fd fd fd fd fd fd fd fd fd fd + 0x0c427fffa850: fd fd fd fd fd fd fd fd fd fd fd fd fd fd fd fd + 0x0c427fffa860: fd fd fd fd fd fd fd fd fd fd fd fd fd fd fd fd + 0x0c427fffa870: fd fd fd fd fd fd fd fd fd fd fd fd fd fd fd fd +Shadow byte legend (one shadow byte represents 8 application bytes): + Addressable: 00 + Partially addressable: 01 02 03 04 05 06 07 + Heap left redzone: fa + Heap right redzone: fb + Freed heap region: fd + Stack left redzone: f1 + Stack mid redzone: f2 + Stack right redzone: f3 + Stack partial redzone: f4 + Stack after return: f5 + Stack use after scope: f8 + Global redzone: f9 + Global init order: f6 + Poisoned by user: f7 + Container overflow: fc + Array cookie: ac + Intra object redzone: bb + ASan internal: fe + Left alloca redzone: ca + Right alloca redzone: cb +==3439==ABORTING diff --git a/tests/fuzz-tests/images/bko-169301-1-blocksize-zero.raw.xz b/tests/fuzz-tests/images/bko-169301-1-blocksize-zero.raw.xz new file mode 100644 index 00000000..70c2b22f Binary files /dev/null and b/tests/fuzz-tests/images/bko-169301-1-blocksize-zero.raw.xz differ diff --git a/tests/fuzz-tests/images/bko-169301-2-blocksize-zero.raw.txt b/tests/fuzz-tests/images/bko-169301-2-blocksize-zero.raw.txt new file mode 100644 index 00000000..0af00ec6 --- /dev/null +++ b/tests/fuzz-tests/images/bko-169301-2-blocksize-zero.raw.txt @@ -0,0 +1,185 @@ +URL: https://bugzilla.kernel.org/show_bug.cgi?id=169301 +Lukas Lueg 2016-09-18 09:07:55 UTC + +parent transid verify failed on 4231168 wanted 274877906948 found 4 +Ignoring transid failure +parent transid verify failed on 4222976 wanted 3472328296227680304 found 4 +parent transid verify failed on 4222976 wanted 3472328296227680304 found 4 +Ignoring transid failure +checking extents +Chunk[256, 228, 0]: length(4194304), offset(0), type(2) is not found in block group +Chunk[256, 228, 0] stripe[1, 0] is not found in dev extent +Chunk[256, 228, 4194304]: length(1638400), offset(4194304), type(5) is not found in block group +Chunk[256, 228, 4194304] stripe[1, 4194304] is not found in dev extent +Chunk[256, 228, 5832704]: length(1638400), offset(5832704), type(5) is not found in block group +Chunk[256, 228, 5832704] stripe[1, 5832704] is not found in dev extent +ref mismatch on [131072 4096] extent item 0, found 1 +Backref 131072 parent 3 root 3 not found in extent tree +backpointer mismatch on [131072 4096] +ref mismatch on [4194304 4096] extent item 0, found 1 +Backref 4194304 parent 5 root 5 not found in extent tree +backpointer mismatch on [4194304 4096] +ref mismatch on [4198400 4096] extent item 0, found 1 +Backref 4198400 parent 1 root 1 not found in extent tree +backpointer mismatch on [4198400 4096] +ref mismatch on [4231168 4096] extent item 0, found 1 +Backref 4231168 parent 7 root 7 not found in extent tree +backpointer mismatch on [4231168 4096] +ref mismatch on [3472328296227680304 3472328296227680304] extent item 0, found 1 +Backref 3472328296227680304 root 1 owner 2 offset 0 num_refs 0 not found in extent tree +Incorrect local backref count on 3472328296227680304 root 1 owner 2 offset 0 found 1 wanted 0 back 0x60800000bc20 +backpointer mismatch on [3472328296227680304 3472328296227680304] +Dev extent's total-byte(0) is not equal to byte-used(7471104) in dev[1, 216, 1] +Errors found in extent allocation tree or chunk allocation +checking free space cache +checking fs roots +checking csums +checking root refs +checking quota groups +==23294==ERROR: AddressSanitizer failed to allocate 0xe4ff4000 (3841933312) bytes of LargeMmapAllocator (error code: 12) +==23294==Process memory map follows: + 0x000000400000-0x0000006a6000 /home/lukas/dev/btrfsfuzz/bin-asan/bin/btrfs + 0x0000008a6000-0x0000008b9000 /home/lukas/dev/btrfsfuzz/bin-asan/bin/btrfs + 0x0000008b9000-0x0000008ef000 /home/lukas/dev/btrfsfuzz/bin-asan/bin/btrfs + 0x0000008ef000-0x000001567000 + 0x00007fff7000-0x00008fff7000 + 0x00008fff7000-0x02008fff7000 + 0x02008fff7000-0x10007fff8000 + 0x600000000000-0x602000000000 + 0x602000000000-0x602000010000 + 0x602000010000-0x603000000000 + 0x603000000000-0x603000010000 + 0x603000010000-0x604000000000 + 0x604000000000-0x604000010000 + 0x604000010000-0x606000000000 + 0x606000000000-0x606000010000 + 0x606000010000-0x607000000000 + 0x607000000000-0x607000010000 + 0x607000010000-0x608000000000 + 0x608000000000-0x608000010000 + 0x608000010000-0x60c000000000 + 0x60c000000000-0x60c000010000 + 0x60c000010000-0x60d000000000 + 0x60d000000000-0x60d000010000 + 0x60d000010000-0x60e000000000 + 0x60e000000000-0x60e000010000 + 0x60e000010000-0x611000000000 + 0x611000000000-0x611000010000 + 0x611000010000-0x616000000000 + 0x616000000000-0x616000020000 + 0x616000020000-0x619000000000 + 0x619000000000-0x619000020000 + 0x619000020000-0x621000000000 + 0x621000000000-0x621000020000 + 0x621000020000-0x624000000000 + 0x624000000000-0x624000020000 + 0x624000020000-0x629000000000 + 0x629000000000-0x629000010000 + 0x629000010000-0x640000000000 + 0x640000000000-0x640000003000 + 0x7f62fb97e000-0x7f62fdcd0000 + 0x7f62fdcd0000-0x7f62fde89000 /usr/lib64/libc-2.23.so + 0x7f62fde89000-0x7f62fe088000 /usr/lib64/libc-2.23.so + 0x7f62fe088000-0x7f62fe08c000 /usr/lib64/libc-2.23.so + 0x7f62fe08c000-0x7f62fe08e000 /usr/lib64/libc-2.23.so + 0x7f62fe08e000-0x7f62fe092000 + 0x7f62fe092000-0x7f62fe0a8000 /usr/lib64/libgcc_s-6.1.1-20160621.so.1 + 0x7f62fe0a8000-0x7f62fe2a7000 /usr/lib64/libgcc_s-6.1.1-20160621.so.1 + 0x7f62fe2a7000-0x7f62fe2a8000 /usr/lib64/libgcc_s-6.1.1-20160621.so.1 + 0x7f62fe2a8000-0x7f62fe2a9000 /usr/lib64/libgcc_s-6.1.1-20160621.so.1 + 0x7f62fe2a9000-0x7f62fe2ac000 /usr/lib64/libdl-2.23.so + 0x7f62fe2ac000-0x7f62fe4ab000 /usr/lib64/libdl-2.23.so + 0x7f62fe4ab000-0x7f62fe4ac000 /usr/lib64/libdl-2.23.so + 0x7f62fe4ac000-0x7f62fe4ad000 /usr/lib64/libdl-2.23.so + 0x7f62fe4ad000-0x7f62fe5b5000 /usr/lib64/libm-2.23.so + 0x7f62fe5b5000-0x7f62fe7b4000 /usr/lib64/libm-2.23.so + 0x7f62fe7b4000-0x7f62fe7b5000 /usr/lib64/libm-2.23.so + 0x7f62fe7b5000-0x7f62fe7b6000 /usr/lib64/libm-2.23.so + 0x7f62fe7b6000-0x7f62fe7bd000 /usr/lib64/librt-2.23.so + 0x7f62fe7bd000-0x7f62fe9bc000 /usr/lib64/librt-2.23.so + 0x7f62fe9bc000-0x7f62fe9bd000 /usr/lib64/librt-2.23.so + 0x7f62fe9bd000-0x7f62fe9be000 /usr/lib64/librt-2.23.so + 0x7f62fe9be000-0x7f62fe9d5000 /usr/lib64/libpthread-2.23.so + 0x7f62fe9d5000-0x7f62febd4000 /usr/lib64/libpthread-2.23.so + 0x7f62febd4000-0x7f62febd5000 /usr/lib64/libpthread-2.23.so + 0x7f62febd5000-0x7f62febd6000 /usr/lib64/libpthread-2.23.so + 0x7f62febd6000-0x7f62febda000 + 0x7f62febda000-0x7f62febfc000 /usr/lib64/liblzo2.so.2.0.0 + 0x7f62febfc000-0x7f62fedfb000 /usr/lib64/liblzo2.so.2.0.0 + 0x7f62fedfb000-0x7f62fedfc000 /usr/lib64/liblzo2.so.2.0.0 + 0x7f62fedfc000-0x7f62fedfd000 + 0x7f62fedfd000-0x7f62fee12000 /usr/lib64/libz.so.1.2.8 + 0x7f62fee12000-0x7f62ff011000 /usr/lib64/libz.so.1.2.8 + 0x7f62ff011000-0x7f62ff012000 /usr/lib64/libz.so.1.2.8 + 0x7f62ff012000-0x7f62ff013000 /usr/lib64/libz.so.1.2.8 + 0x7f62ff013000-0x7f62ff050000 /usr/lib64/libblkid.so.1.1.0 + 0x7f62ff050000-0x7f62ff250000 /usr/lib64/libblkid.so.1.1.0 + 0x7f62ff250000-0x7f62ff254000 /usr/lib64/libblkid.so.1.1.0 + 0x7f62ff254000-0x7f62ff255000 /usr/lib64/libblkid.so.1.1.0 + 0x7f62ff255000-0x7f62ff256000 + 0x7f62ff256000-0x7f62ff25a000 /usr/lib64/libuuid.so.1.3.0 + 0x7f62ff25a000-0x7f62ff459000 /usr/lib64/libuuid.so.1.3.0 + 0x7f62ff459000-0x7f62ff45a000 /usr/lib64/libuuid.so.1.3.0 + 0x7f62ff45a000-0x7f62ff45b000 + 0x7f62ff45b000-0x7f62ff45d000 /home/lukas/dev/afl_git/libdislocator/libdislocator.so + 0x7f62ff45d000-0x7f62ff65c000 /home/lukas/dev/afl_git/libdislocator/libdislocator.so + 0x7f62ff65c000-0x7f62ff65d000 /home/lukas/dev/afl_git/libdislocator/libdislocator.so + 0x7f62ff65d000-0x7f62ff65e000 /home/lukas/dev/afl_git/libdislocator/libdislocator.so + 0x7f62ff65e000-0x7f62ff682000 /usr/lib64/ld-2.23.so + 0x7f62ff810000-0x7f62ff879000 + 0x7f62ff879000-0x7f62ff881000 + 0x7f62ff881000-0x7f62ff882000 /usr/lib64/ld-2.23.so + 0x7f62ff882000-0x7f62ff883000 /usr/lib64/ld-2.23.so + 0x7f62ff883000-0x7f62ff884000 + 0x7fff5a065000-0x7fff5a086000 [stack] + 0x7fff5a0c7000-0x7fff5a0ca000 [vvar] + 0x7fff5a0ca000-0x7fff5a0cc000 [vdso] + 0xffffffffff600000-0xffffffffff601000 [vsyscall] +==23294==End of process memory map. +==23294==AddressSanitizer CHECK failed: /builddir/build/BUILD/compiler-rt-3.8.0.src/lib/sanitizer_common/sanitizer_common.cc:183 "((0 && "unable to mmap")) != (0)" (0x0, 0x0) + #0 0x4c90cd in __asan::AsanCheckFailed(char const*, int, char const*, unsigned long long, unsigned long long) (/home/lukas/dev/btrfsfuzz/bin-asan/bin/btrfs+0x4c90cd) + #1 0x4cfa73 in __sanitizer::CheckFailed(char const*, int, char const*, unsigned long long, unsigned long long) (/home/lukas/dev/btrfsfuzz/bin-asan/bin/btrfs+0x4cfa73) + #2 0x4cfc61 in __sanitizer::ReportMmapFailureAndDie(unsigned long, char const*, char const*, int, bool) (/home/lukas/dev/btrfsfuzz/bin-asan/bin/btrfs+0x4cfc61) + #3 0x4d8922 in __sanitizer::MmapOrDie(unsigned long, char const*, bool) (/home/lukas/dev/btrfsfuzz/bin-asan/bin/btrfs+0x4d8922) + #4 0x42dbab in __asan::Allocator::Allocate(unsigned long, unsigned long, __sanitizer::BufferedStackTrace*, __asan::AllocType, bool) (/home/lukas/dev/btrfsfuzz/bin-asan/bin/btrfs+0x42dbab) + #5 0x4259fb in __asan::asan_calloc(unsigned long, unsigned long, __sanitizer::BufferedStackTrace*) (/home/lukas/dev/btrfsfuzz/bin-asan/bin/btrfs+0x4259fb) + #6 0x4bfd1a in calloc (/home/lukas/dev/btrfsfuzz/bin-asan/bin/btrfs+0x4bfd1a) + #7 0x5c181a in __alloc_extent_buffer /home/lukas/dev/btrfsfuzz/src-asan/extent_io.c:542:7 + #8 0x5c1c76 in alloc_extent_buffer /home/lukas/dev/btrfsfuzz/src-asan/extent_io.c:646:8 + #9 0x58e01c in btrfs_find_create_tree_block /home/lukas/dev/btrfsfuzz/src-asan/disk-io.c:193:9 + #10 0x58ea90 in read_tree_block_fs_info /home/lukas/dev/btrfsfuzz/src-asan/disk-io.c:339:7 + #11 0x5f2f84 in read_tree_block /home/lukas/dev/btrfsfuzz/src-asan/./disk-io.h:112:9 + #12 0x5f2d62 in travel_tree /home/lukas/dev/btrfsfuzz/src-asan/qgroup-verify.c:692:7 + #13 0x5f2bab in add_refs_for_implied /home/lukas/dev/btrfsfuzz/src-asan/qgroup-verify.c:748:8 + #14 0x5eff59 in map_implied_refs /home/lukas/dev/btrfsfuzz/src-asan/qgroup-verify.c:766:9 + #15 0x5eefa9 in qgroup_verify_all /home/lukas/dev/btrfsfuzz/src-asan/qgroup-verify.c:1366:8 + #16 0x51f08f in cmd_check /home/lukas/dev/btrfsfuzz/src-asan/cmds-check.c:11637:9 + #17 0x4f0f81 in main /home/lukas/dev/btrfsfuzz/src-asan/btrfs.c:243:8 + #18 0x7f62fdcf0730 in __libc_start_main (/lib64/libc.so.6+0x20730) + #19 0x4213f8 in _start (/home/lukas/dev/btrfsfuzz/bin-asan/bin/btrfs+0x4213f8) + +checking free space cache +checking fs roots +checking csums +checking root refs +checking quota groups +ERROR: while mapping refs: -5 +checking extentsErrors found in extent allocation tree or chunk allocationfound 3472328296227696688 bytes used err is 0 +total csum bytes: 0 +total tree bytes: 16384 +total fs tree bytes: 4096 +total extent tree bytes: 0 +btree space waste bytes: 12674 +file data blocks allocated: 3472328296227680304 + referenced 3472328296227680304 +extent_io.c:580: free_extent_buffer: Assertion `eb->refs < 0` failed. +../btrfs[0x47a4a3] +../btrfs[0x47a550] +../btrfs(free_extent_buffer+0x6e)[0x47b73c] +../btrfs(btrfs_release_all_roots+0x8c)[0x461cdf] +../btrfs(close_ctree_fs_info+0x1f3)[0x46391a] +../btrfs[0x424043] +../btrfs(cmd_check+0xe1a)[0x43f352] +../btrfs(main+0x12b)[0x40b581] +/lib64/libc.so.6(__libc_start_main+0xf1)[0x7f970daf3291] +../btrfs(_start+0x2a)[0x40afba] diff --git a/tests/fuzz-tests/images/bko-169301-2-blocksize-zero.raw.xz b/tests/fuzz-tests/images/bko-169301-2-blocksize-zero.raw.xz new file mode 100644 index 00000000..68f7ffd4 Binary files /dev/null and b/tests/fuzz-tests/images/bko-169301-2-blocksize-zero.raw.xz differ diff --git a/tests/fuzz-tests/images/bko-172811.raw.txt b/tests/fuzz-tests/images/bko-172811.raw.txt new file mode 100644 index 00000000..bbdf99b5 --- /dev/null +++ b/tests/fuzz-tests/images/bko-172811.raw.txt @@ -0,0 +1,55 @@ +URL: https://bugzilla.kernel.org/show_bug.cgi?id=172811 +Lukas Lueg 2016-09-23 18:34:15 UTC + +More news from the fuzzer. The attached image causes a segmentation fault when +running btrfsck over it; using btrfs-progs v4.7.2-55-g2b7c507 + +This may be the same cause as 156721, the call-tree is different, though. + +The juicy parts: + +==19342==ERROR: AddressSanitizer: SEGV on unknown address 0x0000000000e5 (pc 0x7f3b12e1df50 bp 0x7ffeb50b4260 sp 0x7ffeb50b39e8 T0) + #0 0x7f3b12e1df4f in __memmove_avx_unaligned (/lib64/libc.so.6+0x149f4f) + #1 0x4a982c in __asan_memcpy (/home/lukas/dev/btrfsfuzz/bin-asan/bin/btrfs+0x4a982c) + #2 0x5c2d59 in read_extent_buffer /home/lukas/dev/btrfsfuzz/src-asan/extent_io.c:867:2 + #3 0x52eaa6 in btrfs_node_key /home/lukas/dev/btrfsfuzz/src-asan/./ctree.h:1667:2 + #4 0x5436c7 in check_fs_root /home/lukas/dev/btrfsfuzz/src-asan/cmds-check.c:3661:3 + #5 0x5224ef in check_fs_roots /home/lukas/dev/btrfsfuzz/src-asan/cmds-check.c:3809:10 + #6 0x51e772 in cmd_check /home/lukas/dev/btrfsfuzz/src-asan/cmds-check.c:11533:8 + #7 0x4f0ee1 in main /home/lukas/dev/btrfsfuzz/src-asan/btrfs.c:243:8 + #8 0x7f3b12cf4730 in __libc_start_main (/lib64/libc.so.6+0x20730) + #9 0x421358 in _start (/home/lukas/dev/btrfsfuzz/bin-asan/bin/btrfs+0x421358) + +parent transid verify failed on 4198400 wanted 65305493131755520 found 14 +parent transid verify failed on 4198400 wanted 65305493131755520 found 14 +Ignoring transid failure +ERROR: add_tree_backref failed: File exists +ERROR: add_tree_backref failed: File exists +parent transid verify failed on 131072 wanted 36283884678912 found 4 +parent transid verify failed on 131072 wanted 36283884678912 found 4 +Ignoring transid failure +ERROR: tree block bytenr 1280 is not aligned to sectorsize 4096 +checking free space cache +checking fs roots +root 5 root dir 41471 not found +parent transid verify failed on 4198400 wanted 4 found 14 +Ignoring transid failure +parent transid verify failed on 131072 wanted 36283884678912 found 4 +Ignoring transid failure +ASAN:DEADLYSIGNAL +================================================================= +==19342==ERROR: AddressSanitizer: SEGV on unknown address 0x0000000000e5 (pc 0x7f3b12e1df50 bp 0x7ffeb50b4260 sp 0x7ffeb50b39e8 T0) + #0 0x7f3b12e1df4f in __memmove_avx_unaligned (/lib64/libc.so.6+0x149f4f) + #1 0x4a982c in __asan_memcpy (/home/lukas/dev/btrfsfuzz/bin-asan/bin/btrfs+0x4a982c) + #2 0x5c2d59 in read_extent_buffer /home/lukas/dev/btrfsfuzz/src-asan/extent_io.c:867:2 + #3 0x52eaa6 in btrfs_node_key /home/lukas/dev/btrfsfuzz/src-asan/./ctree.h:1667:2 + #4 0x5436c7 in check_fs_root /home/lukas/dev/btrfsfuzz/src-asan/cmds-check.c:3661:3 + #5 0x5224ef in check_fs_roots /home/lukas/dev/btrfsfuzz/src-asan/cmds-check.c:3809:10 + #6 0x51e772 in cmd_check /home/lukas/dev/btrfsfuzz/src-asan/cmds-check.c:11533:8 + #7 0x4f0ee1 in main /home/lukas/dev/btrfsfuzz/src-asan/btrfs.c:243:8 + #8 0x7f3b12cf4730 in __libc_start_main (/lib64/libc.so.6+0x20730) + #9 0x421358 in _start (/home/lukas/dev/btrfsfuzz/bin-asan/bin/btrfs+0x421358) + +AddressSanitizer can not provide additional info. +SUMMARY: AddressSanitizer: SEGV (/lib64/libc.so.6+0x149f4f) in __memmove_avx_unaligned +==19342==ABORTING diff --git a/tests/fuzz-tests/images/bko-172811.raw.xz b/tests/fuzz-tests/images/bko-172811.raw.xz new file mode 100644 index 00000000..08546c2b Binary files /dev/null and b/tests/fuzz-tests/images/bko-172811.raw.xz differ diff --git a/tests/fuzz-tests/images/bko-172861.raw.txt b/tests/fuzz-tests/images/bko-172861.raw.txt new file mode 100644 index 00000000..f395333f --- /dev/null +++ b/tests/fuzz-tests/images/bko-172861.raw.txt @@ -0,0 +1,68 @@ +URL: https://bugzilla.kernel.org/show_bug.cgi?id=172861 +Lukas Lueg 2016-09-24 15:40:54 UTC + +More news from the fuzzer. The attached image causes a segmentation fault when +running btrfsck over it; using btrfs-progs v4.7.2-55-g2b7c507 + +The juicy parts: + +==12279==ERROR: AddressSanitizer: SEGV on unknown address 0x6210010719f9 (pc 0x0000005f30bd bp 0x7ffcf39cc670 sp 0x7ffcf39cc670 T0) + #0 0x5f30bc in btrfs_file_extent_type /home/lukas/dev/btrfsfuzz/src-asan/./ctree.h:2083:1 + #1 0x5f2f49 in add_refs_for_leaf_items /home/lukas/dev/btrfsfuzz/src-asan/qgroup-verify.c:664:17 + #2 0x5f2ba9 in travel_tree /home/lukas/dev/btrfsfuzz/src-asan/qgroup-verify.c:704:9 + #3 0x5f2c0a in travel_tree /home/lukas/dev/btrfsfuzz/src-asan/qgroup-verify.c:719:9 + #4 0x5f299b in add_refs_for_implied /home/lukas/dev/btrfsfuzz/src-asan/qgroup-verify.c:748:8 + #5 0x5efd39 in map_implied_refs /home/lukas/dev/btrfsfuzz/src-asan/qgroup-verify.c:766:9 + #6 0x5eed89 in qgroup_verify_all /home/lukas/dev/btrfsfuzz/src-asan/qgroup-verify.c:1366:8 + #7 0x51ea14 in cmd_check /home/lukas/dev/btrfsfuzz/src-asan/cmds-check.c:11571:9 + #8 0x4f0ee1 in main /home/lukas/dev/btrfsfuzz/src-asan/btrfs.c:243:8 + #9 0x7f811e227730 in __libc_start_main (/lib64/libc.so.6+0x20730) + #10 0x421358 in _start (/home/lukas/dev/btrfsfuzz/bin-asan/bin/btrfs+0x421358) + +Extent back ref already exists for 0 parent 0 root 0 +Extent back ref already exists for 0 parent 0 root 0 +Extent back ref already exists for 0 parent 0 root 0 +Chunk[256, 228, 0]: length(4194304), offset(0), type(2) is not found in block group +Chunk[256, 228, 0] stripe[1, 0] is not found in dev extent +Chunk[256, 228, 4194304]: length(1638400), offset(4194304), type(5) is not found in block group +Chunk[256, 228, 4194304] stripe[1, 4194304] is not found in dev extent +Chunk[256, 228, 5832704]: length(1638400), offset(5832704), type(5) is not found in block group +Chunk[256, 228, 5832704] stripe[1, 5832704] is not found in dev extent +Chunk[256, 228, 7471104]: length(9306112), offset(7471104), type(5) is not found in block group +Chunk[256, 228, 7471104] stripe[1, 7471104] is not found in dev extent +ref mismatch on [0 4096] extent item 0, found 4 +Backref 0 parent 0 root 0 not found in extent tree +Incorrect global backref count on 0 found 1 wanted 4 +backpointer mismatch on [0 4096] +bad extent [0, 4096), type mismatch with chunk +ref mismatch on [135168 4096] extent item 0, found 1 +Backref 135168 parent 3 root 3 not found in extent tree +backpointer mismatch on [135168 4096] +ref mismatch on [4202496 4096] extent item 0, found 1 +Backref 4202496 parent 1 root 1 not found in extent tree +backpointer mismatch on [4202496 4096] +Dev extent's total-byte(0) is not equal to byte-used(16777216) in dev[1, 216, 1] +checking free space cache +checking fs roots +root 5 root dir 0 not found +checking csums +checking root refs +checking quota groups +ASAN:DEADLYSIGNAL +================================================================= +==12279==ERROR: AddressSanitizer: SEGV on unknown address 0x6210010719f9 (pc 0x0000005f30bd bp 0x7ffcf39cc670 sp 0x7ffcf39cc670 T0) + #0 0x5f30bc in btrfs_file_extent_type /home/lukas/dev/btrfsfuzz/src-asan/./ctree.h:2083:1 + #1 0x5f2f49 in add_refs_for_leaf_items /home/lukas/dev/btrfsfuzz/src-asan/qgroup-verify.c:664:17 + #2 0x5f2ba9 in travel_tree /home/lukas/dev/btrfsfuzz/src-asan/qgroup-verify.c:704:9 + #3 0x5f2c0a in travel_tree /home/lukas/dev/btrfsfuzz/src-asan/qgroup-verify.c:719:9 + #4 0x5f299b in add_refs_for_implied /home/lukas/dev/btrfsfuzz/src-asan/qgroup-verify.c:748:8 + #5 0x5efd39 in map_implied_refs /home/lukas/dev/btrfsfuzz/src-asan/qgroup-verify.c:766:9 + #6 0x5eed89 in qgroup_verify_all /home/lukas/dev/btrfsfuzz/src-asan/qgroup-verify.c:1366:8 + #7 0x51ea14 in cmd_check /home/lukas/dev/btrfsfuzz/src-asan/cmds-check.c:11571:9 + #8 0x4f0ee1 in main /home/lukas/dev/btrfsfuzz/src-asan/btrfs.c:243:8 + #9 0x7f811e227730 in __libc_start_main (/lib64/libc.so.6+0x20730) + #10 0x421358 in _start (/home/lukas/dev/btrfsfuzz/bin-asan/bin/btrfs+0x421358) + +AddressSanitizer can not provide additional info. +SUMMARY: AddressSanitizer: SEGV /home/lukas/dev/btrfsfuzz/src-asan/./ctree.h:2083:1 in btrfs_file_extent_type +==12279==ABORTING diff --git a/tests/fuzz-tests/images/bko-172861.raw.xz b/tests/fuzz-tests/images/bko-172861.raw.xz new file mode 100644 index 00000000..c57661d9 Binary files /dev/null and b/tests/fuzz-tests/images/bko-172861.raw.xz differ -- cgit v1.2.3 From 691d1ac8fa0830d04d9bce1cbbb81cad2dbe600d Mon Sep 17 00:00:00 2001 From: David Sterba Date: Tue, 15 Nov 2016 15:34:03 +0100 Subject: btrfs-progs: tests: add basic checks for bad stream on the receive side Signed-off-by: David Sterba --- .../017-recv-stream-malformatted/test.sh | 25 ++++++++++++++++++++++ 1 file changed, 25 insertions(+) create mode 100755 tests/misc-tests/017-recv-stream-malformatted/test.sh (limited to 'tests') diff --git a/tests/misc-tests/017-recv-stream-malformatted/test.sh b/tests/misc-tests/017-recv-stream-malformatted/test.sh new file mode 100755 index 00000000..884b7d42 --- /dev/null +++ b/tests/misc-tests/017-recv-stream-malformatted/test.sh @@ -0,0 +1,25 @@ +#!/bin/bash +# +# test receiving stream that's not valid, simple cases + +source $TOP/tests/common + +check_prereq mkfs.btrfs +check_prereq btrfs + +setup_root_helper +prepare_test_dev 1g + +run_check $TOP/mkfs.btrfs -f $IMAGE +run_check_mount_test_dev + +echo -n '' | run_mayfail $SUDO_HELPER "$TOP/btrfs" receive "$TEST_MNT" && + _fail "unexpected: received empty stream" + +echo -n '1' | run_mayfail $SUDO_HELPER "$TOP/btrfs" receive "$TEST_MNT" && + _fail "unexpected: received stream with shrot and corrupted header" + +echo -n '12345678901234567' | run_mayfail $SUDO_HELPER "$TOP/btrfs" receive "$TEST_MNT" && + _fail "unexpected: received stream with corrupted header" + +run_check_umount_test_dev -- cgit v1.2.3 From 6572f884ba0958af7591947028cec5adcbf21193 Mon Sep 17 00:00:00 2001 From: David Sterba Date: Fri, 18 Nov 2016 15:02:50 +0100 Subject: btrfs-progs: tests: use the root helper for various info retrieval commands The current user might not be able to peek into the loop files directly, use the helper. Discovered by running tests in travis. Signed-off-by: David Sterba --- tests/misc-tests/006-image-on-missing-device/test.sh | 4 ++-- tests/misc-tests/010-convert-delete-ext2-subvol/test.sh | 4 ++-- tests/misc-tests/011-delete-missing-device/test.sh | 8 ++++---- tests/mkfs-tests/001-basic-profiles/test.sh | 2 +- tests/mkfs-tests/005-long-device-name-for-ssd/test.sh | 2 +- tests/mkfs-tests/006-partitioned-loopdev/test.sh | 2 +- tests/mkfs-tests/007-mix-nodesize-sectorsize/test.sh | 2 +- 7 files changed, 12 insertions(+), 12 deletions(-) (limited to 'tests') diff --git a/tests/misc-tests/006-image-on-missing-device/test.sh b/tests/misc-tests/006-image-on-missing-device/test.sh index 83a6a056..8133d2b1 100755 --- a/tests/misc-tests/006-image-on-missing-device/test.sh +++ b/tests/misc-tests/006-image-on-missing-device/test.sh @@ -60,12 +60,12 @@ test_run() run_check $SUDO_HELPER umount $TEST_MNT test_image_dump - run_check $TOP/btrfs filesystem show $dev1 + run_check $SUDO_HELPER $TOP/btrfs filesystem show $dev1 # create a degraded raid1 filesystem, check must succeed # btrfs-image must not loop run_mayfail wipefs -a $dev2 run_check $SUDO_HELPER losetup -d $dev2 - run_check $TOP/btrfs filesystem show $dev1 + run_check $SUDO_HELPER $TOP/btrfs filesystem show $dev1 test_image_dump } diff --git a/tests/misc-tests/010-convert-delete-ext2-subvol/test.sh b/tests/misc-tests/010-convert-delete-ext2-subvol/test.sh index 7bf7be34..7915867c 100755 --- a/tests/misc-tests/010-convert-delete-ext2-subvol/test.sh +++ b/tests/misc-tests/010-convert-delete-ext2-subvol/test.sh @@ -14,11 +14,11 @@ prepare_test_dev run_check truncate -s 2G "$TEST_DEV" run_check mkfs.ext4 -F "$TEST_DEV" run_check $TOP/btrfs-convert "$TEST_DEV" -run_check $TOP/btrfs inspect-internal dump-tree "$TEST_DEV" +run_check $SUDO_HELPER $TOP/btrfs inspect-internal dump-tree "$TEST_DEV" run_check_mount_test_dev run_check $SUDO_HELPER $TOP/btrfs subvolume delete -c "$TEST_MNT/ext2_saved" run_check_umount_test_dev -run_check $TOP/btrfs inspect-internal dump-tree "$TEST_DEV" +run_check $SUDO_HELPER $TOP/btrfs inspect-internal dump-tree "$TEST_DEV" run_check_stdout $TOP/btrfs-convert --rollback "$TEST_DEV" | grep -q 'is it deleted' || _fail "unexpected rollback" diff --git a/tests/misc-tests/011-delete-missing-device/test.sh b/tests/misc-tests/011-delete-missing-device/test.sh index 57e88745..0222b6f8 100755 --- a/tests/misc-tests/011-delete-missing-device/test.sh +++ b/tests/misc-tests/011-delete-missing-device/test.sh @@ -38,16 +38,16 @@ cleanup_devices() test_do_mkfs() { run_check $SUDO_HELPER $TOP/mkfs.btrfs -f $@ ${devs[@]} - run_check $TOP/btrfs inspect-internal dump-super $dev1 + run_check $SUDO_HELPER $TOP/btrfs inspect-internal dump-super $dev1 run_check $SUDO_HELPER $TOP/btrfs check $dev1 - run_check $TOP/btrfs filesystem show + run_check $SUDO_HELPER $TOP/btrfs filesystem show } test_wipefs() { - run_check wipefs -a $devtodel + run_check $SUDO_HELPER wipefs -a $devtodel run_check $SUDO_HELPER losetup -d $devtodel - run_check losetup -a + run_check $SUDO_HELPER losetup --all run_check $TOP/btrfs filesystem show } test_delete_missing() diff --git a/tests/mkfs-tests/001-basic-profiles/test.sh b/tests/mkfs-tests/001-basic-profiles/test.sh index e893887f..eb55148d 100755 --- a/tests/mkfs-tests/001-basic-profiles/test.sh +++ b/tests/mkfs-tests/001-basic-profiles/test.sh @@ -37,7 +37,7 @@ cleanup_devices() test_get_info() { - run_check $TOP/btrfs inspect-internal dump-super $dev1 + run_check $SUDO_HELPER $TOP/btrfs inspect-internal dump-super $dev1 run_check $SUDO_HELPER $TOP/btrfs check $dev1 run_check $SUDO_HELPER mount $dev1 $TEST_MNT run_check $TOP/btrfs filesystem df $TEST_MNT diff --git a/tests/mkfs-tests/005-long-device-name-for-ssd/test.sh b/tests/mkfs-tests/005-long-device-name-for-ssd/test.sh index 20387b83..63fb1785 100755 --- a/tests/mkfs-tests/005-long-device-name-for-ssd/test.sh +++ b/tests/mkfs-tests/005-long-device-name-for-ssd/test.sh @@ -32,7 +32,7 @@ run_check cat $rot # test run_check_stdout $SUDO_HELPER $TOP/mkfs.btrfs -f $@ $dmdev | grep -q 'SSD detected:.*yes' || _fail 'SSD not detected' -run_check $TOP/btrfs inspect-internal dump-super $dmdev +run_check $SUDO_HELPER $TOP/btrfs inspect-internal dump-super $dmdev # cleanup run_check $SUDO_HELPER dmsetup remove $dmname diff --git a/tests/mkfs-tests/006-partitioned-loopdev/test.sh b/tests/mkfs-tests/006-partitioned-loopdev/test.sh index e40dc675..4415b468 100755 --- a/tests/mkfs-tests/006-partitioned-loopdev/test.sh +++ b/tests/mkfs-tests/006-partitioned-loopdev/test.sh @@ -18,7 +18,7 @@ base=$(basename $loopdev) # expect partitions named like loop0p1 etc for looppart in $(ls /dev/$base?*); do run_check $SUDO_HELPER $TOP/mkfs.btrfs -f $looppart - run_check $TOP/btrfs inspect-internal dump-super $looppart + run_check $SUDO_HELPER $TOP/btrfs inspect-internal dump-super $looppart done # cleanup diff --git a/tests/mkfs-tests/007-mix-nodesize-sectorsize/test.sh b/tests/mkfs-tests/007-mix-nodesize-sectorsize/test.sh index 29d9be14..3980414f 100755 --- a/tests/mkfs-tests/007-mix-nodesize-sectorsize/test.sh +++ b/tests/mkfs-tests/007-mix-nodesize-sectorsize/test.sh @@ -12,7 +12,7 @@ prepare_test_dev test_mkfs_single() { run_check $SUDO_HELPER $TOP/mkfs.btrfs -f "$@" $TEST_DEV - run_check $TOP/btrfs inspect-internal dump-super $TEST_DEV + run_check $SUDO_HELPER $TOP/btrfs inspect-internal dump-super $TEST_DEV run_check $SUDO_HELPER $TOP/btrfs check $TEST_DEV } -- cgit v1.2.3 From 9da3ce40f54340d5a660233ae1fb040d724757f8 Mon Sep 17 00:00:00 2001 From: David Sterba Date: Fri, 18 Nov 2016 15:06:13 +0100 Subject: btrfs-progs: tests: change options to list all loop devices The option --list might not be available on older versions, the equvalent is --all. Discovered via failed travis build. Signed-off-by: David Sterba --- tests/misc-tests/006-image-on-missing-device/test.sh | 2 +- tests/misc-tests/011-delete-missing-device/test.sh | 2 +- tests/mkfs-tests/001-basic-profiles/test.sh | 2 +- 3 files changed, 3 insertions(+), 3 deletions(-) (limited to 'tests') diff --git a/tests/misc-tests/006-image-on-missing-device/test.sh b/tests/misc-tests/006-image-on-missing-device/test.sh index 8133d2b1..5b6fe065 100755 --- a/tests/misc-tests/006-image-on-missing-device/test.sh +++ b/tests/misc-tests/006-image-on-missing-device/test.sh @@ -39,7 +39,7 @@ cleanup_devices() for i in `seq $ndevs`; do truncate -s0 img$i done - run_check $SUDO_HELPER losetup --list + run_check $SUDO_HELPER losetup --all } test_image_dump() diff --git a/tests/misc-tests/011-delete-missing-device/test.sh b/tests/misc-tests/011-delete-missing-device/test.sh index 0222b6f8..5b5f9786 100755 --- a/tests/misc-tests/011-delete-missing-device/test.sh +++ b/tests/misc-tests/011-delete-missing-device/test.sh @@ -32,7 +32,7 @@ cleanup_devices() for i in `seq $ndevs`; do truncate -s0 img$i done - run_check $SUDO_HELPER losetup --list + run_check $SUDO_HELPER losetup --all } test_do_mkfs() diff --git a/tests/mkfs-tests/001-basic-profiles/test.sh b/tests/mkfs-tests/001-basic-profiles/test.sh index eb55148d..0dc9a2bd 100755 --- a/tests/mkfs-tests/001-basic-profiles/test.sh +++ b/tests/mkfs-tests/001-basic-profiles/test.sh @@ -32,7 +32,7 @@ cleanup_devices() for i in `seq $ndevs`; do truncate -s0 img$i done - run_check $SUDO_HELPER losetup --list + run_check $SUDO_HELPER losetup --all } test_get_info() -- cgit v1.2.3 From 7cd40e125b42831f1cda999a5d206739853120fd Mon Sep 17 00:00:00 2001 From: David Sterba Date: Fri, 18 Nov 2016 15:09:50 +0100 Subject: btrfs-progs: tests: check for TEST_LOG values by a regex The set of possible values will be extended so check for existence of the keyword. Signed-off-by: David Sterba --- tests/common | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-) (limited to 'tests') diff --git a/tests/common b/tests/common index c61962da..e653d4c6 100644 --- a/tests/common +++ b/tests/common @@ -42,7 +42,7 @@ _not_run() run_check() { echo "############### $@" >> "$RESULTS" 2>&1 - if [ "$TEST_LOG" = 'tty' ]; then echo "CMD: $@" > /dev/tty; fi + if [[ $TEST_LOG =~ tty ]]; then echo "CMD: $@" > /dev/tty; fi if [ "$1" = 'root_helper' ]; then "$@" >> "$RESULTS" 2>&1 || _fail "failed: $@" else @@ -55,7 +55,7 @@ run_check() run_check_stdout() { echo "############### $@" >> "$RESULTS" 2>&1 - if [ "$TEST_LOG" = 'tty' ]; then echo "CMD(stdout): $@" > /dev/tty; fi + if [[ $TEST_LOG =~ tty ]]; then echo "CMD(stdout): $@" > /dev/tty; fi if [ "$1" = 'root_helper' ]; then "$@" 2>&1 | tee -a "$RESULTS" || _fail "failed: $@" else @@ -71,7 +71,7 @@ run_mayfail() local ret echo "############### $@" >> "$RESULTS" 2>&1 - if [ "$TEST_LOG" = 'tty' ]; then echo "CMD(mayfail): $@" > /dev/tty; fi + if [[ $TEST_LOG =~ tty ]]; then echo "CMD(mayfail): $@" > /dev/tty; fi if [ "$1" = 'root_helper' ]; then "$@" >> $RESULTS 2>&1 else @@ -99,7 +99,7 @@ run_mustfail() shift echo "############### $@" >> "$RESULTS" 2>&1 - if [ "$TEST_LOG" = 'tty' ]; then echo "CMD(mustfail): $@" > /dev/tty; fi + if [[ $TEST_LOG =~ tty ]]; then echo "CMD(mustfail): $@" > /dev/tty; fi if [ "$1" = 'root_helper' ]; then "$@" >> "$RESULTS" 2>&1 else -- cgit v1.2.3 From 4884ae2f5e87e1cfbf7cc1d5624e0600b1fa46b3 Mon Sep 17 00:00:00 2001 From: David Sterba Date: Fri, 18 Nov 2016 15:18:02 +0100 Subject: btrfs-progs: tests: enhance TEST_LOG features Add new keyword to dump the log file after any test fails. Can be useful for remote analysis of test failures. Signed-off-by: David Sterba --- tests/README.md | 10 +++++++--- tests/cli-tests.sh | 3 +++ tests/convert-tests.sh | 3 +++ tests/fsck-tests.sh | 3 +++ tests/fuzz-tests.sh | 3 +++ tests/misc-tests.sh | 3 +++ tests/mkfs-tests.sh | 3 +++ 7 files changed, 25 insertions(+), 3 deletions(-) (limited to 'tests') diff --git a/tests/README.md b/tests/README.md index ca45cf6f..f0d54d5e 100644 --- a/tests/README.md +++ b/tests/README.md @@ -108,9 +108,13 @@ the root helper). ### Verbosity -Setting the variable `TEST_LOG=tty` will print all commands executed by some of -the wrappers (`run_check` etc), other commands are not printed to the terminal -(but the full output is in the log). +* `TEST_LOG=tty` -- setting the variable will print all commands executed by + some of the wrappers (`run_check` etc), other commands are not printed to the + terminal (but the full output is in the log) + +* `TEST_LOG=dump` -- dump the entire testing log when a test fails + +Multiple values can be separated by `,`. ### Permissions diff --git a/tests/cli-tests.sh b/tests/cli-tests.sh index bc1a1e2c..16d6afcf 100755 --- a/tests/cli-tests.sh +++ b/tests/cli-tests.sh @@ -34,6 +34,9 @@ do echo " [TEST/cli] $name" ./test.sh if [ $? -ne 0 ]; then + if [[ $TEST_LOG =~ dump ]]; then + cat "$RESULTS" + fi _fail "test failed for case $(basename $i)" fi fi diff --git a/tests/convert-tests.sh b/tests/convert-tests.sh index 5fa88a12..c5663367 100755 --- a/tests/convert-tests.sh +++ b/tests/convert-tests.sh @@ -37,6 +37,9 @@ run_one_test() { ./test.sh if [ $? -ne 0 ]; then _fail "test failed for case $testname" + if [[ $TEST_LOG =~ dump ]]; then + cat "$RESULTS" + fi fi else _fail "custom test script not found" diff --git a/tests/fsck-tests.sh b/tests/fsck-tests.sh index e71b7119..d5fc3d14 100755 --- a/tests/fsck-tests.sh +++ b/tests/fsck-tests.sh @@ -36,6 +36,9 @@ run_one_test() { # Type 2 ./test.sh if [ $? -ne 0 ]; then + if [[ $TEST_LOG =~ dump ]]; then + cat "$RESULTS" + fi _fail "test failed for case $(basename $testname)" fi else diff --git a/tests/fuzz-tests.sh b/tests/fuzz-tests.sh index 9b88aa10..f72385e5 100755 --- a/tests/fuzz-tests.sh +++ b/tests/fuzz-tests.sh @@ -33,6 +33,9 @@ do echo " [TEST/fuzz] $name" ./test.sh if [ $? -ne 0 ]; then + if [[ $TEST_LOG =~ dump ]]; then + cat "$RESULTS" + fi _fail "test failed for case $(basename $i)" fi fi diff --git a/tests/misc-tests.sh b/tests/misc-tests.sh index 40e1cba1..1c645c9b 100755 --- a/tests/misc-tests.sh +++ b/tests/misc-tests.sh @@ -37,6 +37,9 @@ do if [ -x test.sh ]; then ./test.sh if [ $? -ne 0 ]; then + if [[ $TEST_LOG =~ dump ]]; then + cat "$RESULTS" + fi _fail "test failed for case $(basename $i)" fi fi diff --git a/tests/mkfs-tests.sh b/tests/mkfs-tests.sh index c130520d..c8ff8c83 100755 --- a/tests/mkfs-tests.sh +++ b/tests/mkfs-tests.sh @@ -34,6 +34,9 @@ do if [ -x test.sh ]; then ./test.sh if [ $? -ne 0 ]; then + if [[ $TEST_LOG =~ dump ]]; then + cat "$RESULTS" + fi _fail "test failed for case $(basename $i)" fi fi -- cgit v1.2.3 From d4ce61f7a2905c914e00ff764ecfa2554d1726b7 Mon Sep 17 00:00:00 2001 From: David Sterba Date: Fri, 18 Nov 2016 19:21:02 +0100 Subject: btrfs-progs: tests: add fallback to current directory for check_all_images Reported-by: Tsutomu Itoh Signed-off-by: David Sterba --- tests/common | 4 ++++ tests/fsck-tests.sh | 2 +- tests/fsck-tests/022-qgroup-rescan-halfway/test.sh | 2 +- tests/fsck-tests/023-qgroup-stack-overflow/test.sh | 2 +- 4 files changed, 7 insertions(+), 3 deletions(-) (limited to 'tests') diff --git a/tests/common b/tests/common index e653d4c6..5430f822 100644 --- a/tests/common +++ b/tests/common @@ -202,6 +202,10 @@ check_all_images() local extracted dir="$1" + if [ -z "$dir" ]; then + dir=. + fi + _assert_path "$dir" for image in $(find "$dir" \( -iname '*.img' -o \ -iname '*.img.xz' -o \ -iname '*.raw' -o \ diff --git a/tests/fsck-tests.sh b/tests/fsck-tests.sh index d5fc3d14..44cca1b8 100755 --- a/tests/fsck-tests.sh +++ b/tests/fsck-tests.sh @@ -43,7 +43,7 @@ run_one_test() { fi else # Type 1 - check_all_images `pwd` + check_all_images fi cd "$TOP" } diff --git a/tests/fsck-tests/022-qgroup-rescan-halfway/test.sh b/tests/fsck-tests/022-qgroup-rescan-halfway/test.sh index 5b114eeb..1dc8f8fc 100755 --- a/tests/fsck-tests/022-qgroup-rescan-halfway/test.sh +++ b/tests/fsck-tests/022-qgroup-rescan-halfway/test.sh @@ -16,4 +16,4 @@ check_image() { fi } -check_all_images "." +check_all_images diff --git a/tests/fsck-tests/023-qgroup-stack-overflow/test.sh b/tests/fsck-tests/023-qgroup-stack-overflow/test.sh index e8bf3fae..a304eac5 100755 --- a/tests/fsck-tests/023-qgroup-stack-overflow/test.sh +++ b/tests/fsck-tests/023-qgroup-stack-overflow/test.sh @@ -14,4 +14,4 @@ check_image() run_check $TOP/btrfs check "$1" } -check_all_images "." +check_all_images -- cgit v1.2.3 From d8f93ce802c31dde2b936d0626b636dc070e118b Mon Sep 17 00:00:00 2001 From: David Sterba Date: Thu, 10 Nov 2016 18:31:53 +0100 Subject: btrfs-progs: Update README and other docs Signed-off-by: David Sterba --- tests/README.md | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) (limited to 'tests') diff --git a/tests/README.md b/tests/README.md index f0d54d5e..48664471 100644 --- a/tests/README.md +++ b/tests/README.md @@ -1,7 +1,8 @@ # Btrfs-progs tests A testsuite covering functionality of btrfs-progs, ie. the checker, image, mkfs -and similar tools. There are no special requirements on kernel features, the +and similar tools. There are no additional requirements on kernel features +(other than `CONFIG_BTRFS_FS` built-in or module), the tests build on top of the core functionality like snapshots and device management. In some cases optional features are turned on by mkfs and the filesystem image could be mounted, such tests might fail if there's lack of -- cgit v1.2.3 From b0d89755826d4e643c5aec8d1e8df1cbe2a587bc Mon Sep 17 00:00:00 2001 From: Tsutomu Itoh Date: Mon, 21 Nov 2016 14:10:41 +0900 Subject: btrfs-progs: test: fix how to make test files in fsck-tests 013 In my test environment, following error was occurred because the size of /lib/modules/`uname -r`/* is larger than 1GB. # make test-fsck [TEST] fsck-tests.sh [TEST/fsck] 013-extent-tree-rebuild failed: cp -aR /lib/modules/4.9.0-rc5/ /test/btrfs-progs/tests/mnt test failed for case 013-extent-tree-rebuild Makefile:272: recipe for target 'test-fsck' failed make: *** [test-fsck] Error 1 # In this test case, 'generate_dataset small' is enough for making the test files, so I will use 'generate_dataset' instead of 'cp'. For this, move 'generate_dataset()' from 'common.convert' to 'common'. Signed-off-by: Tsutomu Itoh Signed-off-by: David Sterba --- tests/common | 89 ++++++++++++++++++++++++ tests/common.convert | 89 ------------------------ tests/fsck-tests/013-extent-tree-rebuild/test.sh | 2 +- 3 files changed, 90 insertions(+), 90 deletions(-) (limited to 'tests') diff --git a/tests/common b/tests/common index 5430f822..71806c24 100644 --- a/tests/common +++ b/tests/common @@ -313,6 +313,95 @@ check_kernel_support() return 0 } +# how many files to create. +DATASET_SIZE=50 + +generate_dataset() { + + dataset_type="$1" + dirpath=$TEST_MNT/$dataset_type + run_check $SUDO_HELPER mkdir -p "$dirpath" + + case $dataset_type in + small) + for num in $(seq 1 "$DATASET_SIZE"); do + run_check $SUDO_HELPER dd if=/dev/urandom of="$dirpath/$dataset_type.$num" bs=10K \ + count=1 >/dev/null 2>&1 + done + ;; + + hardlink) + for num in $(seq 1 "$DATASET_SIZE"); do + run_check $SUDO_HELPER touch $dirpath/$dataset_type.$num + run_check $SUDO_HELPER ln "$dirpath/$dataset_type.$num" "$dirpath/hlink.$num" + done + ;; + + fast_symlink) + for num in $(seq 1 "$DATASET_SIZE"); do + run_check $SUDO_HELPER touch $dirpath/$dataset_type.$num + run_check cd "$dirpath" && \ + $SUDO_HELPER ln -s "$dataset_type.$num" "$dirpath/slink.$num" && \ + cd / + done + ;; + + brokenlink) + for num in $(seq 1 "$DATASET_SIZE"); do + run_check $SUDO_HELPER ln -s "$dirpath/$dataset_type.$num" "$dirpath/blink.$num" + done + ;; + + perm) + for modes in 777 775 755 750 700 666 664 644 640 600 444 440 400 000 \ + 1777 1775 1755 1750 1700 1666 1664 1644 1640 1600 1444 1440 1400 1000 \ + 2777 2775 2755 2750 2700 2666 2664 2644 2640 2600 2444 2440 2400 2000 \ + 4777 4775 4755 4750 4700 4666 4664 4644 4640 4600 4444 4440 4400 4000; do + if [[ "$modes" == *9* ]] || [[ "$modes" == *8* ]] + then + continue; + else + run_check $SUDO_HELPER touch "$dirpath/$dataset_type.$modes" + run_check $SUDO_HELPER chmod "$modes" "$dirpath/$dataset_type.$modes" + fi + done + ;; + + sparse) + for num in $(seq 1 "$DATASET_SIZE"); do + run_check $SUDO_HELPER dd if=/dev/urandom of="$dirpath/$dataset_type.$num" bs=10K \ + count=1 >/dev/null 2>&1 + run_check $SUDO_HELPER truncate -s 500K "$dirpath/$dataset_type.$num" + run_check $SUDO_HELPER dd if=/dev/urandom of="$dirpath/$dataset_type.$num" bs=10K \ + oflag=append conv=notrunc count=1 >/dev/null 2>&1 + run_check $SUDO_HELPER truncate -s 800K "$dirpath/$dataset_type.$num" + done + ;; + + acls) + for num in $(seq 1 "$DATASET_SIZE"); do + run_check $SUDO_HELPER touch "$dirpath/$dataset_type.$num" + run_check $SUDO_HELPER setfacl -m "u:root:x" "$dirpath/$dataset_type.$num" + run_check $SUDO_HELPER setfattr -n user.foo -v "bar$num" "$dirpath/$dataset_type.$num" + done + ;; + + fifo) + for num in $(seq 1 "$DATASET_SIZE"); do + run_check $SUDO_HELPER mkfifo "$dirpath/$dataset_type.$num" + done + ;; + + slow_symlink) + long_filename=`date +%s | sha256sum | cut -f1 -d'-'` + run_check $SUDO_HELPER touch "$dirpath/$long_filename" + for num in $(seq 1 "$DATASET_SIZE"); do + run_check $SUDO_HELPER ln -s "$dirpath/$long_filename" "$dirpath/slow_slink.$num" + done + ;; + esac +} + init_env() { TEST_MNT="${TEST_MNT:-$TOP/tests/mnt}" diff --git a/tests/common.convert b/tests/common.convert index 375d4b55..3481c4db 100644 --- a/tests/common.convert +++ b/tests/common.convert @@ -1,95 +1,6 @@ #!/bin/bash # helpers for btrfs-convert tests -# how many files to create. -DATASET_SIZE=50 - -generate_dataset() { - - dataset_type="$1" - dirpath=$TEST_MNT/$dataset_type - run_check $SUDO_HELPER mkdir -p "$dirpath" - - case $dataset_type in - small) - for num in $(seq 1 "$DATASET_SIZE"); do - run_check $SUDO_HELPER dd if=/dev/urandom of="$dirpath/$dataset_type.$num" bs=10K \ - count=1 >/dev/null 2>&1 - done - ;; - - hardlink) - for num in $(seq 1 "$DATASET_SIZE"); do - run_check $SUDO_HELPER touch $dirpath/$dataset_type.$num - run_check $SUDO_HELPER ln "$dirpath/$dataset_type.$num" "$dirpath/hlink.$num" - done - ;; - - fast_symlink) - for num in $(seq 1 "$DATASET_SIZE"); do - run_check $SUDO_HELPER touch $dirpath/$dataset_type.$num - run_check cd "$dirpath" && \ - $SUDO_HELPER ln -s "$dataset_type.$num" "$dirpath/slink.$num" && \ - cd / - done - ;; - - brokenlink) - for num in $(seq 1 "$DATASET_SIZE"); do - run_check $SUDO_HELPER ln -s "$dirpath/$dataset_type.$num" "$dirpath/blink.$num" - done - ;; - - perm) - for modes in 777 775 755 750 700 666 664 644 640 600 444 440 400 000 \ - 1777 1775 1755 1750 1700 1666 1664 1644 1640 1600 1444 1440 1400 1000 \ - 2777 2775 2755 2750 2700 2666 2664 2644 2640 2600 2444 2440 2400 2000 \ - 4777 4775 4755 4750 4700 4666 4664 4644 4640 4600 4444 4440 4400 4000; do - if [[ "$modes" == *9* ]] || [[ "$modes" == *8* ]] - then - continue; - else - run_check $SUDO_HELPER touch "$dirpath/$dataset_type.$modes" - run_check $SUDO_HELPER chmod "$modes" "$dirpath/$dataset_type.$modes" - fi - done - ;; - - sparse) - for num in $(seq 1 "$DATASET_SIZE"); do - run_check $SUDO_HELPER dd if=/dev/urandom of="$dirpath/$dataset_type.$num" bs=10K \ - count=1 >/dev/null 2>&1 - run_check $SUDO_HELPER truncate -s 500K "$dirpath/$dataset_type.$num" - run_check $SUDO_HELPER dd if=/dev/urandom of="$dirpath/$dataset_type.$num" bs=10K \ - oflag=append conv=notrunc count=1 >/dev/null 2>&1 - run_check $SUDO_HELPER truncate -s 800K "$dirpath/$dataset_type.$num" - done - ;; - - acls) - for num in $(seq 1 "$DATASET_SIZE"); do - run_check $SUDO_HELPER touch "$dirpath/$dataset_type.$num" - run_check $SUDO_HELPER setfacl -m "u:root:x" "$dirpath/$dataset_type.$num" - run_check $SUDO_HELPER setfattr -n user.foo -v "bar$num" "$dirpath/$dataset_type.$num" - done - ;; - - fifo) - for num in $(seq 1 "$DATASET_SIZE"); do - run_check $SUDO_HELPER mkfifo "$dirpath/$dataset_type.$num" - done - ;; - - slow_symlink) - long_filename=`date +%s | sha256sum | cut -f1 -d'-'` - run_check $SUDO_HELPER touch "$dirpath/$long_filename" - for num in $(seq 1 "$DATASET_SIZE"); do - run_check $SUDO_HELPER ln -s "$dirpath/$long_filename" "$dirpath/slow_slink.$num" - done - ;; - esac -} - populate_fs() { for dataset_type in 'small' 'hardlink' 'fast_symlink' 'brokenlink' 'perm' 'sparse' 'acls' 'fifo' 'slow_symlink'; do diff --git a/tests/fsck-tests/013-extent-tree-rebuild/test.sh b/tests/fsck-tests/013-extent-tree-rebuild/test.sh index f678e29b..37bdcd9c 100755 --- a/tests/fsck-tests/013-extent-tree-rebuild/test.sh +++ b/tests/fsck-tests/013-extent-tree-rebuild/test.sh @@ -15,7 +15,7 @@ test_extent_tree_rebuild() run_check $SUDO_HELPER $TOP/mkfs.btrfs -f $TEST_DEV run_check_mount_test_dev - run_check $SUDO_HELPER cp -aR /lib/modules/`uname -r`/ $TEST_MNT + generate_dataset small for i in `seq 1 100`;do run_check $SUDO_HELPER $TOP/btrfs sub snapshot $TEST_MNT \ -- cgit v1.2.3 From c1d714f944ee334a58ebf0adb19420bcf5d62d84 Mon Sep 17 00:00:00 2001 From: David Sterba Date: Mon, 21 Nov 2016 14:44:06 +0100 Subject: btrfs-progs: tests: drop redundant test for rwx number validity The list of rwx permissions is now hardcoded but used to begenerated and the invalid numbers filtered out. Not necessary anymore. Signed-off-by: David Sterba --- tests/common | 9 ++------- 1 file changed, 2 insertions(+), 7 deletions(-) (limited to 'tests') diff --git a/tests/common b/tests/common index 71806c24..d9dec0c3 100644 --- a/tests/common +++ b/tests/common @@ -357,13 +357,8 @@ generate_dataset() { 1777 1775 1755 1750 1700 1666 1664 1644 1640 1600 1444 1440 1400 1000 \ 2777 2775 2755 2750 2700 2666 2664 2644 2640 2600 2444 2440 2400 2000 \ 4777 4775 4755 4750 4700 4666 4664 4644 4640 4600 4444 4440 4400 4000; do - if [[ "$modes" == *9* ]] || [[ "$modes" == *8* ]] - then - continue; - else - run_check $SUDO_HELPER touch "$dirpath/$dataset_type.$modes" - run_check $SUDO_HELPER chmod "$modes" "$dirpath/$dataset_type.$modes" - fi + run_check $SUDO_HELPER touch "$dirpath/$dataset_type.$modes" + run_check $SUDO_HELPER chmod "$modes" "$dirpath/$dataset_type.$modes" done ;; -- cgit v1.2.3 From 55db7bf0598ab782d64cd1605a3c9a7162997a54 Mon Sep 17 00:00:00 2001 From: David Sterba Date: Mon, 21 Nov 2016 14:51:40 +0100 Subject: btrfs-progs: tests: more variable quoting in common scripts Signed-off-by: David Sterba --- tests/common | 14 +++++++------- tests/common.convert | 2 +- 2 files changed, 8 insertions(+), 8 deletions(-) (limited to 'tests') diff --git a/tests/common b/tests/common index d9dec0c3..98ef0292 100644 --- a/tests/common +++ b/tests/common @@ -73,7 +73,7 @@ run_mayfail() echo "############### $@" >> "$RESULTS" 2>&1 if [[ $TEST_LOG =~ tty ]]; then echo "CMD(mayfail): $@" > /dev/tty; fi if [ "$1" = 'root_helper' ]; then - "$@" >> $RESULTS 2>&1 + "$@" >> "$RESULTS" 2>&1 else $INSTRUMENT "$@" >> "$RESULTS" 2>&1 fi @@ -136,11 +136,11 @@ check_image() image=$1 echo "testing image $(basename $image)" >> "$RESULTS" - $TOP/btrfs check "$image" >> "$RESULTS" 2>&1 + "$TOP/btrfs" check "$image" >> "$RESULTS" 2>&1 [ $? -eq 0 ] && _fail "btrfs check should have detected corruption" - run_check $TOP/btrfs check --repair "$image" - run_check $TOP/btrfs check "$image" + run_check "$TOP/btrfs" check --repair "$image" + run_check "$TOP/btrfs" check "$image" } # Extract a usable image from packed formats @@ -322,7 +322,7 @@ generate_dataset() { dirpath=$TEST_MNT/$dataset_type run_check $SUDO_HELPER mkdir -p "$dirpath" - case $dataset_type in + case "$dataset_type" in small) for num in $(seq 1 "$DATASET_SIZE"); do run_check $SUDO_HELPER dd if=/dev/urandom of="$dirpath/$dataset_type.$num" bs=10K \ @@ -332,14 +332,14 @@ generate_dataset() { hardlink) for num in $(seq 1 "$DATASET_SIZE"); do - run_check $SUDO_HELPER touch $dirpath/$dataset_type.$num + run_check $SUDO_HELPER touch "$dirpath/$dataset_type.$num" run_check $SUDO_HELPER ln "$dirpath/$dataset_type.$num" "$dirpath/hlink.$num" done ;; fast_symlink) for num in $(seq 1 "$DATASET_SIZE"); do - run_check $SUDO_HELPER touch $dirpath/$dataset_type.$num + run_check $SUDO_HELPER touch "$dirpath/$dataset_type.$num" run_check cd "$dirpath" && \ $SUDO_HELPER ln -s "$dataset_type.$num" "$dirpath/slink.$num" && \ cd / diff --git a/tests/common.convert b/tests/common.convert index 3481c4db..a2d31524 100644 --- a/tests/common.convert +++ b/tests/common.convert @@ -89,7 +89,7 @@ convert_test_acl() { # $2: nodesize, argument of -N, can be empty convert_test_do_convert() { run_check "$TOP/btrfs-convert" ${1:+-O "$1"} ${2:+-N "$2"} "$TEST_DEV" - run_check "$TOP/btrfs" check $TEST_DEV + run_check "$TOP/btrfs" check "$TEST_DEV" run_check "$TOP/btrfs" inspect-internal dump-super -Ffa "$TEST_DEV" } -- cgit v1.2.3 From 50e742a6b096116b0a0117127127775f8e03bff6 Mon Sep 17 00:00:00 2001 From: David Sterba Date: Tue, 22 Nov 2016 13:32:18 +0100 Subject: btrfs-progs: tests: add support for additional command arguments Add convenient support for extending command arguments, now implemented for 'btrfs check' to cover the low-memory mode. If defined, arguments are inserted to any 'btrfs check' command in tests. Exceptions could be defined in common.local. Signed-off-by: David Sterba --- tests/README.md | 9 ++++- tests/common | 98 ++++++++++++++++++++++++++++++++++++++++++++++++++++++ tests/common.local | 25 ++++++++++++++ 3 files changed, 131 insertions(+), 1 deletion(-) create mode 100644 tests/common.local (limited to 'tests') diff --git a/tests/README.md b/tests/README.md index 48664471..bb2846a1 100644 --- a/tests/README.md +++ b/tests/README.md @@ -107,7 +107,7 @@ are possible. Note: instrumentation is not applied to privileged commands (anything that uses the root helper). -### Verbosity +### Verbosity, test tuning * `TEST_LOG=tty` -- setting the variable will print all commands executed by some of the wrappers (`run_check` etc), other commands are not printed to the @@ -115,6 +115,13 @@ the root helper). * `TEST_LOG=dump` -- dump the entire testing log when a test fails +* `TEST_ENABLE_OVERRIDE` -- defined either as make arguments or via + `tests/common.local` to enable additional arguments to some commands, using + the variable(s) below (default: false, enable by setting to 'true') + +* `TEST_ARGS_CHECK` -- user-defined arguments to `btrfs check`, before the + test-specific arguments + Multiple values can be separated by `,`. ### Permissions diff --git a/tests/common b/tests/common index 98ef0292..571118a1 100644 --- a/tests/common +++ b/tests/common @@ -39,8 +39,75 @@ _not_run() exit 0 } +# debugging helper +_dump_args() +{ + local i + + i=1 + echo "DUMP args for ${FUNCNAME[1]}:" + while [ $# -gt 0 ]; do + echo "ARG[$i]: $1" + i=$(($i+1)) + shift + done +} + +# read arguments, look if we're calling btrfs and if there's a known +# subcommand, return argument index to insert, taking root helper into +# consideration, returns 2 for unknown subcommand +_get_spec_ins() +{ + if [ "$1" = 'root_helper' ]; then + if [[ $2 =~ /btrfs$ ]]; then + echo -n 4 + return + fi + else + if [[ $1 =~ /btrfs$ ]]; then + echo -n 3 + return + fi + fi + echo -n 2 +} + +# return command-specific arguments if enabled +_cmd_spec() +{ + if [ "$TEST_ENABLE_OVERRIDE" = 'true' ]; then + # if defined via common.local, use it, otherwise pass make + # arguments + if [ "$(type -t _skip_spec)" = 'function' ]; then + if _skip_spec "$@"; then + return + fi + fi + case "$1" in + check) echo -n "$TEST_ARGS_CHECK" ;; + esac + fi +} + +# Argument passing magic: +# the command passed to run_* helpers is inspected, if there's 'btrfs command' +# found and there are defined additional arguments, they're inserted just after +# the command name, ie. any arguments in the test could override them. +# +# The root helper is recognized. Unrecognized subcommands or external tools +# are not affected. + run_check() { + local spec + local ins + local cmd + + ins=$(_get_spec_ins "$@") + spec=$(($ins-1)) + cmd=$(eval echo "\${$spec}") + spec=$(_cmd_spec "$cmd") + set -- "${@:1:$(($ins-1))}" $spec "${@: $ins}" echo "############### $@" >> "$RESULTS" 2>&1 if [[ $TEST_LOG =~ tty ]]; then echo "CMD: $@" > /dev/tty; fi if [ "$1" = 'root_helper' ]; then @@ -54,6 +121,15 @@ run_check() # can be processed further run_check_stdout() { + local spec + local ins + local cmd + + ins=$(_get_spec_ins "$@") + spec=$(($ins-1)) + cmd=$(eval echo "\${$spec}") + spec=$(_cmd_spec "$cmd") + set -- "${@:1:$(($ins-1))}" $spec "${@: $ins}" echo "############### $@" >> "$RESULTS" 2>&1 if [[ $TEST_LOG =~ tty ]]; then echo "CMD(stdout): $@" > /dev/tty; fi if [ "$1" = 'root_helper' ]; then @@ -68,8 +144,16 @@ run_check_stdout() # output is logged run_mayfail() { + local spec + local ins + local cmd local ret + ins=$(_get_spec_ins "$@") + spec=$(($ins-1)) + cmd=$(eval echo "\${$spec}") + spec=$(_cmd_spec "$cmd") + set -- "${@:1:$(($ins-1))}" $spec "${@: $ins}" echo "############### $@" >> "$RESULTS" 2>&1 if [[ $TEST_LOG =~ tty ]]; then echo "CMD(mayfail): $@" > /dev/tty; fi if [ "$1" = 'root_helper' ]; then @@ -93,11 +177,19 @@ run_mayfail() # same as run_check but expects the command to fail, output is logged run_mustfail() { + local spec + local ins + local cmd local msg msg="$1" shift + ins=$(_get_spec_ins "$@") + spec=$(($ins-1)) + cmd=$(eval echo "\${$spec}") + spec=$(_cmd_spec "$cmd") + set -- "${@:1:$(($ins-1))}" $spec "${@: $ins}" echo "############### $@" >> "$RESULTS" 2>&1 if [[ $TEST_LOG =~ tty ]]; then echo "CMD(mustfail): $@" > /dev/tty; fi if [ "$1" = 'root_helper' ]; then @@ -403,5 +495,11 @@ init_env() export TEST_MNT mkdir -p "$TEST_MNT" || { echo "Failed mkdir -p $TEST_MNT"; exit 1; } + source $TOP/tests/common.local + + if [ "$TEST_ENABLE_OVERRIDE" = 'true' -a -n "$RESULTS" ]; then + echo "INCLUDE common.local" >> "$RESULTS" + echo " check: $TEST_ARGS_CHECK" >> "$RESULTS" + fi } init_env diff --git a/tests/common.local b/tests/common.local new file mode 100644 index 00000000..9f567c27 --- /dev/null +++ b/tests/common.local @@ -0,0 +1,25 @@ +#!/bin/bash +# +# additional arguments to various commands + +# already defined, eg. via make argument +if [ -n "$TEST_ENABLE_OVERRIDE" ]; then + return +fi + +# set to 'true' +TEST_ENABLE_OVERRIDE=false + +TEST_ARGS_CHECK=--mode=lowmem + +# gets arguments of a current command and can decide if the argument insertion +# should happen, eg. if some option combination does not make sense or would +# break tests +_skip_spec() +{ + if echo "$TEST_CHECK" | grep -q 'mode=lowmem' && + echo "$@" | grep -q -- '--repair'; then + return 0 + fi + return 1 +} -- cgit v1.2.3 From 9d133083aade130f34f6ebde4252d1b7c0b86a6e Mon Sep 17 00:00:00 2001 From: David Sterba Date: Tue, 29 Nov 2016 16:12:15 +0100 Subject: btrfs-progs: tests: end of stream conditions Signed-off-by: David Sterba --- tests/misc-tests/018-recv-end-of-stream/test.sh | 149 ++++++++++++++++++++++++ 1 file changed, 149 insertions(+) create mode 100755 tests/misc-tests/018-recv-end-of-stream/test.sh (limited to 'tests') diff --git a/tests/misc-tests/018-recv-end-of-stream/test.sh b/tests/misc-tests/018-recv-end-of-stream/test.sh new file mode 100755 index 00000000..d39683e9 --- /dev/null +++ b/tests/misc-tests/018-recv-end-of-stream/test.sh @@ -0,0 +1,149 @@ +#!/bin/bash +# +# end of stream conditions: test that no instructions in a stream are still +# received, at least the header must be present + +source $TOP/tests/common + +check_prereq mkfs.btrfs +check_prereq btrfs + +setup_root_helper +prepare_test_dev 1g + +here=`pwd` + +test_full_empty_stream() { + local str + + str="$here/stream-full-empty.stream" + run_check $TOP/mkfs.btrfs -f $TEST_DEV + run_check_mount_test_dev + + cd "$TEST_MNT" || _fail "cannot chdir to TEST_MNT" + + run_check $SUDO_HELPER $TOP/btrfs subvolume create subv1 + run_check $SUDO_HELPER $TOP/btrfs subvolume snapshot -r subv1 subv1-snap + + truncate -s0 "$str" + chmod a+w "$str" + run_check $SUDO_HELPER $TOP/btrfs send -f "$str" subv1-snap + + cd "$here" || _fail "cannot chdir back to test directory" + run_check_umount_test_dev + + run_check $TOP/mkfs.btrfs -f $TEST_DEV + run_check_mount_test_dev + run_check $SUDO_HELPER $TOP/btrfs receive -v -f "$str" "$TEST_MNT" + run_check_umount_test_dev + + run_check rm -f -- "$str" +} + +test_full_simple_stream() { + local str + + str="$here/stream-full-simple.stream" + run_check $TOP/mkfs.btrfs -f $TEST_DEV + run_check_mount_test_dev + + cd "$TEST_MNT" || _fail "cannot chdir to TEST_MNT" + + run_check $SUDO_HELPER $TOP/btrfs subvolume create subv1 + for i in 1 2 3; do + run_check $SUDO_HELPER dd if=/dev/zero of=subv1/file1_$i bs=1M count=1 + done + + run_check $SUDO_HELPER $TOP/btrfs subvolume snapshot -r subv1 subv1-snap + + truncate -s0 "$str" + chmod a+w "$str" + run_check $SUDO_HELPER $TOP/btrfs send -f "$str" subv1-snap + + cd "$here" || _fail "cannot chdir back to test directory" + run_check_umount_test_dev + + run_check $TOP/mkfs.btrfs -f $TEST_DEV + run_check_mount_test_dev + run_check $SUDO_HELPER $TOP/btrfs receive -v -f "$str" "$TEST_MNT" + run_check_umount_test_dev + + run_check rm -f -- "$str" +} + +test_incr_empty_stream() { + local fstr + local istr + + fstr="$here/stream-full-empty.stream" + istr="$here/stream-incr-empty.stream" + run_check $TOP/mkfs.btrfs -f $TEST_DEV + run_check_mount_test_dev + + cd "$TEST_MNT" || _fail "cannot chdir to TEST_MNT" + + run_check $SUDO_HELPER $TOP/btrfs subvolume create subv1 + run_check $SUDO_HELPER $TOP/btrfs subvolume snapshot -r subv1 subv1-snap + run_check $SUDO_HELPER $TOP/btrfs subvolume snapshot -r subv1 subv2-snap + + truncate -s0 "$fstr" "$istr" + chmod a+w "$fstr" "$istr" + run_check $SUDO_HELPER $TOP/btrfs send -f "$fstr" subv1-snap + run_check $SUDO_HELPER $TOP/btrfs send -p subv1-snap -f "$istr" subv2-snap + + cd "$here" || _fail "cannot chdir back to test directory" + run_check_umount_test_dev + + run_check $TOP/mkfs.btrfs -f $TEST_DEV + run_check_mount_test_dev + run_check $SUDO_HELPER $TOP/btrfs receive -v -f "$fstr" "$TEST_MNT" + run_check $SUDO_HELPER $TOP/btrfs receive -v -f "$istr" "$TEST_MNT" + run_check_umount_test_dev + + run_check rm -f -- "$fstr" "$istr" +} + +test_incr_simple_stream() { + local str + + fstr="$here/stream-full-simple.stream" + istr="$here/stream-incr-simple.stream" + run_check $TOP/mkfs.btrfs -f $TEST_DEV + run_check_mount_test_dev + + cd "$TEST_MNT" || _fail "cannot chdir to TEST_MNT" + + run_check $SUDO_HELPER $TOP/btrfs subvolume create subv1 + for i in 1 2 3; do + run_check $SUDO_HELPER dd if=/dev/zero of=subv1/file1_$i bs=1M count=1 + done + + run_check $SUDO_HELPER $TOP/btrfs subvolume snapshot -r subv1 subv1-snap + + for i in 1 2 3; do + run_check $SUDO_HELPER dd if=/dev/urandom of=subv1/file1_$i bs=1M count=1 + done + + run_check $SUDO_HELPER $TOP/btrfs subvolume snapshot -r subv1 subv2-snap + + truncate -s0 "$fstr" "$istr" + chmod a+w "$fstr" "$istr" + run_check $SUDO_HELPER $TOP/btrfs send -f "$fstr" subv1-snap + run_check $SUDO_HELPER $TOP/btrfs send -p subv1-snap -f "$istr" subv2-snap + + cd "$here" || _fail "cannot chdir back to test directory" + run_check_umount_test_dev + + run_check $TOP/mkfs.btrfs -f $TEST_DEV + run_check_mount_test_dev + run_check $SUDO_HELPER $TOP/btrfs receive -v -f "$fstr" "$TEST_MNT" + run_check $SUDO_HELPER $TOP/btrfs receive -v -f "$istr" "$TEST_MNT" + run_check_umount_test_dev + + run_check rm -f -- "$fstr" "$istr" +} + +test_full_empty_stream +test_full_simple_stream +test_incr_empty_stream +test_incr_simple_stream -- cgit v1.2.3 From 26ad474e16637e34a91aec8cf9df206d51a0865a Mon Sep 17 00:00:00 2001 From: David Sterba Date: Mon, 21 Nov 2016 14:55:11 +0100 Subject: btrfs-progs: tests: add more gobal option to test 001-btrfs Signed-off-by: David Sterba --- tests/cli-tests/001-btrfs/test.sh | 3 +++ 1 file changed, 3 insertions(+) (limited to 'tests') diff --git a/tests/cli-tests/001-btrfs/test.sh b/tests/cli-tests/001-btrfs/test.sh index 1de2f6f2..560e4890 100755 --- a/tests/cli-tests/001-btrfs/test.sh +++ b/tests/cli-tests/001-btrfs/test.sh @@ -11,5 +11,8 @@ run_check $TOP/btrfs version run_check $TOP/btrfs version -- run_check $TOP/btrfs help run_check $TOP/btrfs help -- +run_check $TOP/btrfs help --full run_check $TOP/btrfs --help run_check $TOP/btrfs --help --full +run_check $TOP/btrfs --version +run_check $TOP/btrfs --version --help -- cgit v1.2.3 From 8fe3a7bfd0d045ec68882d0299e3ce1944ee1ed6 Mon Sep 17 00:00:00 2001 From: David Sterba Date: Wed, 30 Nov 2016 16:49:18 +0100 Subject: btrfs-progs: tests: check for partscan support in misc/006-partitioned-loopdev The travis CI does not have losetup with --partscan, skip the check in that case so we can still run the mkfs testsuite. Signed-off-by: David Sterba --- tests/mkfs-tests/006-partitioned-loopdev/test.sh | 5 +++++ 1 file changed, 5 insertions(+) (limited to 'tests') diff --git a/tests/mkfs-tests/006-partitioned-loopdev/test.sh b/tests/mkfs-tests/006-partitioned-loopdev/test.sh index 4415b468..12f37842 100755 --- a/tests/mkfs-tests/006-partitioned-loopdev/test.sh +++ b/tests/mkfs-tests/006-partitioned-loopdev/test.sh @@ -3,6 +3,11 @@ source $TOP/tests/common +if ! losetup --help | grep -q 'partscan'; then + _not_run "losetup --partscan not available" + exit 0 +fi + check_prereq mkfs.btrfs setup_root_helper -- cgit v1.2.3 From 46b8ea0e9928500c3fa12c65bf9049c0ac45fec8 Mon Sep 17 00:00:00 2001 From: Qu Wenruo Date: Mon, 19 Dec 2016 14:56:42 +0800 Subject: btrfs-progs: convert-test: trigger chunk allocation after convert Populate fs after convert so we can trigger data chunk allocation. This can expose too restrict old rollback condition Reported-by: Chandan Rajendra Signed-off-by: Qu Wenruo Signed-off-by: David Sterba --- tests/common | 4 ++++ tests/common.convert | 3 +++ 2 files changed, 7 insertions(+) (limited to 'tests') diff --git a/tests/common b/tests/common index 571118a1..51c2e267 100644 --- a/tests/common +++ b/tests/common @@ -486,6 +486,10 @@ generate_dataset() { run_check $SUDO_HELPER ln -s "$dirpath/$long_filename" "$dirpath/slow_slink.$num" done ;; + large) + run_check $SUDO_HELPER dd if=/dev/urandom bs=32M count=1 \ + of="$dirpath/$dataset_type" >/dev/null 2>&1 + ;; esac } diff --git a/tests/common.convert b/tests/common.convert index a2d31524..8c9242e5 100644 --- a/tests/common.convert +++ b/tests/common.convert @@ -160,6 +160,9 @@ convert_test_post_checks_all() { convert_test_post_check_checksums "$1" convert_test_post_check_permissions "$2" convert_test_post_check_acl "$3" + + # Create a large file to trigger data chunk allocation + generate_dataset "large" run_check_umount_test_dev } -- cgit v1.2.3 From 0e95fff4fff4688c82c150833a021a9399da094c Mon Sep 17 00:00:00 2001 From: David Sterba Date: Fri, 20 Jan 2017 17:54:04 +0100 Subject: btrfs-progs: tests: 005-qgroup-show Signed-off-by: David Sterba --- tests/cli-tests/005-qgroup-show/test.sh | 21 +++++++++++++++++++++ 1 file changed, 21 insertions(+) create mode 100755 tests/cli-tests/005-qgroup-show/test.sh (limited to 'tests') diff --git a/tests/cli-tests/005-qgroup-show/test.sh b/tests/cli-tests/005-qgroup-show/test.sh new file mode 100755 index 00000000..28c22c61 --- /dev/null +++ b/tests/cli-tests/005-qgroup-show/test.sh @@ -0,0 +1,21 @@ +#!/bin/bash +# +# qgroup show behaviour when quotas are not enabled + +source $TOP/tests/common + +check_prereq mkfs.btrfs +check_prereq btrfs + +setup_root_helper +prepare_test_dev 2g + +run_check $TOP/mkfs.btrfs -f $IMAGE +run_check_mount_test_dev +run_mayfail $TOP/btrfs qgroup show "$TEST_MNT" +run_mayfail $SUDO_HELPER $TOP/btrfs qgroup show "$TEST_MNT" +run_check $SUDO_HELPER $TOP/btrfs quota enable "$TEST_MNT" +run_mayfail $TOP/btrfs qgroup show "$TEST_MNT" +run_check $SUDO_HELPER $TOP/btrfs qgroup show "$TEST_MNT" +run_check $SUDO_HELPER $TOP/btrfs quota disable "$TEST_MNT" +run_check_umount_test_dev -- cgit v1.2.3 From 55e3a601951302641c4fd5e148f46449acc449c2 Mon Sep 17 00:00:00 2001 From: Tsutomu Itoh Date: Thu, 15 Dec 2016 13:33:05 +0900 Subject: btrfs-progs: tests: add test for --sync option of qgroup show Simple test script for the following patch. btrfs-progs: qgroup: add sync option to 'qgroup show' Signed-off-by: Tsutomu Itoh Signed-off-by: David Sterba --- tests/cli-tests/006-qgroup-show-sync/test.sh | 30 ++++++++++++++++++++++++++++ 1 file changed, 30 insertions(+) create mode 100755 tests/cli-tests/006-qgroup-show-sync/test.sh (limited to 'tests') diff --git a/tests/cli-tests/006-qgroup-show-sync/test.sh b/tests/cli-tests/006-qgroup-show-sync/test.sh new file mode 100755 index 00000000..30d0a9a1 --- /dev/null +++ b/tests/cli-tests/006-qgroup-show-sync/test.sh @@ -0,0 +1,30 @@ +#!/bin/bash +# +# simple test of qgroup show --sync option + +source "$TOP/tests/common" + +check_prereq mkfs.btrfs +check_prereq btrfs + +setup_root_helper +prepare_test_dev 1g + +run_check "$TOP/mkfs.btrfs" -f "$IMAGE" +run_check_mount_test_dev + +run_check $SUDO_HELPER "$TOP/btrfs" subvolume create "$TEST_MNT/Sub" +run_check $SUDO_HELPER "$TOP/btrfs" quota enable "$TEST_MNT/Sub" + +for opt in '' '--' '--sync'; do + run_check $SUDO_HELPER "$TOP/btrfs" qgroup limit 300M "$TEST_MNT/Sub" + run_check $SUDO_HELPER dd if=/dev/zero of="$TEST_MNT/Sub/file" bs=1M count=200 + + run_check $SUDO_HELPER "$TOP/btrfs" qgroup show -re $opt "$TEST_MNT/Sub" + + run_check $SUDO_HELPER "$TOP/btrfs" qgroup limit none "$TEST_MNT/Sub" + run_check $SUDO_HELPER rm -f "$TEST_MNT/Sub/file" + run_check "$TOP/btrfs" filesystem sync "$TEST_MNT/Sub" +done + +run_check_umount_test_dev -- cgit v1.2.3 From 21821424715214a6252708f2322e2f4882c967ab Mon Sep 17 00:00:00 2001 From: David Sterba Date: Tue, 24 Jan 2017 17:59:47 +0100 Subject: btrfs-progs: tests: add variable quotation to cli-tests Signed-off-by: David Sterba --- tests/cli-tests/001-btrfs/test.sh | 20 +++++++------- .../cli-tests/002-balance-full-no-filters/test.sh | 12 ++++---- tests/cli-tests/003-fi-resize-args/test.sh | 32 +++++++++++----------- .../cli-tests/004-send-parent-multi-subvol/test.sh | 6 ++-- tests/cli-tests/005-qgroup-show/test.sh | 16 +++++------ 5 files changed, 43 insertions(+), 43 deletions(-) (limited to 'tests') diff --git a/tests/cli-tests/001-btrfs/test.sh b/tests/cli-tests/001-btrfs/test.sh index 560e4890..c680604b 100755 --- a/tests/cli-tests/001-btrfs/test.sh +++ b/tests/cli-tests/001-btrfs/test.sh @@ -1,18 +1,18 @@ #!/bin/bash # test commands of btrfs -source $TOP/tests/common +source "$TOP/tests/common" check_prereq btrfs # returns 1 run_mayfail $TOP/btrfs || true -run_check $TOP/btrfs version -run_check $TOP/btrfs version -- -run_check $TOP/btrfs help -run_check $TOP/btrfs help -- -run_check $TOP/btrfs help --full -run_check $TOP/btrfs --help -run_check $TOP/btrfs --help --full -run_check $TOP/btrfs --version -run_check $TOP/btrfs --version --help +run_check "$TOP/btrfs" version +run_check "$TOP/btrfs" version -- +run_check "$TOP/btrfs" help +run_check "$TOP/btrfs" help -- +run_check "$TOP/btrfs" help --full +run_check "$TOP/btrfs" --help +run_check "$TOP/btrfs" --help --full +run_check "$TOP/btrfs" --version +run_check "$TOP/btrfs" --version --help diff --git a/tests/cli-tests/002-balance-full-no-filters/test.sh b/tests/cli-tests/002-balance-full-no-filters/test.sh index c2757f24..81a719eb 100755 --- a/tests/cli-tests/002-balance-full-no-filters/test.sh +++ b/tests/cli-tests/002-balance-full-no-filters/test.sh @@ -2,7 +2,7 @@ # # coverage of balance --full-balance -source $TOP/tests/common +source "$TOP/tests/common" check_prereq mkfs.btrfs check_prereq btrfs @@ -10,12 +10,12 @@ check_prereq btrfs setup_root_helper prepare_test_dev 2g -run_check $TOP/mkfs.btrfs -f $IMAGE +run_check "$TOP/mkfs.btrfs" -f "$IMAGE" run_check_mount_test_dev -run_check $SUDO_HELPER $TOP/btrfs balance start --full-balance $TEST_MNT -run_check $SUDO_HELPER $TOP/btrfs balance start $TEST_MNT -run_check $SUDO_HELPER $TOP/btrfs balance --full-balance $TEST_MNT -run_check $SUDO_HELPER $TOP/btrfs balance $TEST_MNT +run_check $SUDO_HELPER "$TOP/btrfs" balance start --full-balance "$TEST_MNT" +run_check $SUDO_HELPER "$TOP/btrfs" balance start "$TEST_MNT" +run_check $SUDO_HELPER "$TOP/btrfs" balance --full-balance "$TEST_MNT" +run_check $SUDO_HELPER "$TOP/btrfs" balance "$TEST_MNT" run_check_umount_test_dev diff --git a/tests/cli-tests/003-fi-resize-args/test.sh b/tests/cli-tests/003-fi-resize-args/test.sh index 2f136fa2..b835e078 100755 --- a/tests/cli-tests/003-fi-resize-args/test.sh +++ b/tests/cli-tests/003-fi-resize-args/test.sh @@ -2,7 +2,7 @@ # # test parsing of various resize arguments -source $TOP/tests/common +source "$TOP/tests/common" check_prereq mkfs.btrfs check_prereq btrfs @@ -10,37 +10,37 @@ check_prereq btrfs setup_root_helper prepare_test_dev 2g -run_check $TOP/mkfs.btrfs -f $IMAGE +run_check "$TOP/mkfs.btrfs" -f "$IMAGE" run_check_mount_test_dev # missing the one of the required arguments for sep in '' '--'; do - run_check_stdout $TOP/btrfs filesystem resize $sep | + run_check_stdout "$TOP/btrfs" filesystem resize $sep | grep -q "btrfs filesystem resize: too few arguments" - run_check_stdout $TOP/btrfs filesystem resize $sep $TEST_MNT | + run_check_stdout "$TOP/btrfs" filesystem resize $sep "$TEST_MNT" | grep -q "btrfs filesystem resize: too few arguments" - run_check_stdout $TOP/btrfs filesystem resize $sep -128M | + run_check_stdout "$TOP/btrfs" filesystem resize $sep -128M | grep -q "btrfs filesystem resize: too few arguments" - run_check_stdout $TOP/btrfs filesystem resize $sep +128M | + run_check_stdout "$TOP/btrfs" filesystem resize $sep +128M | grep -q "btrfs filesystem resize: too few arguments" - run_check_stdout $TOP/btrfs filesystem resize $sep 512M | + run_check_stdout "$TOP/btrfs" filesystem resize $sep 512M | grep -q "btrfs filesystem resize: too few arguments" - run_check_stdout $TOP/btrfs filesystem resize $sep 1:-128M | + run_check_stdout "$TOP/btrfs" filesystem resize $sep 1:-128M | grep -q "btrfs filesystem resize: too few arguments" - run_check_stdout $TOP/btrfs filesystem resize $sep 1:512M | + run_check_stdout "$TOP/btrfs" filesystem resize $sep 1:512M | grep -q "btrfs filesystem resize: too few arguments" - run_check_stdout $TOP/btrfs filesystem resize $sep 1:+128M | + run_check_stdout "$TOP/btrfs" filesystem resize $sep 1:+128M | grep -q "btrfs filesystem resize: too few arguments" done # valid resize for sep in '' '--'; do - run_check $SUDO_HELPER $TOP/btrfs filesystem resize $sep -128M $TEST_MNT - run_check $SUDO_HELPER $TOP/btrfs filesystem resize $sep +128M $TEST_MNT - run_check $SUDO_HELPER $TOP/btrfs filesystem resize $sep 512M $TEST_MNT - run_check $SUDO_HELPER $TOP/btrfs filesystem resize $sep 1:-128M $TEST_MNT - run_check $SUDO_HELPER $TOP/btrfs filesystem resize $sep 1:512M $TEST_MNT - run_check $SUDO_HELPER $TOP/btrfs filesystem resize $sep 1:+128M $TEST_MNT + run_check $SUDO_HELPER "$TOP/btrfs" filesystem resize $sep -128M "$TEST_MNT" + run_check $SUDO_HELPER "$TOP/btrfs" filesystem resize $sep +128M "$TEST_MNT" + run_check $SUDO_HELPER "$TOP/btrfs" filesystem resize $sep 512M "$TEST_MNT" + run_check $SUDO_HELPER "$TOP/btrfs" filesystem resize $sep 1:-128M "$TEST_MNT" + run_check $SUDO_HELPER "$TOP/btrfs" filesystem resize $sep 1:512M "$TEST_MNT" + run_check $SUDO_HELPER "$TOP/btrfs" filesystem resize $sep 1:+128M "$TEST_MNT" done run_check_umount_test_dev diff --git a/tests/cli-tests/004-send-parent-multi-subvol/test.sh b/tests/cli-tests/004-send-parent-multi-subvol/test.sh index e9ccf225..860f657a 100755 --- a/tests/cli-tests/004-send-parent-multi-subvol/test.sh +++ b/tests/cli-tests/004-send-parent-multi-subvol/test.sh @@ -2,7 +2,7 @@ # # minimal test for the following syntax: btrfs send -p parent subvol1 subvol2 -source $TOP/tests/common +source "$TOP/tests/common" check_prereq mkfs.btrfs check_prereq btrfs @@ -10,7 +10,7 @@ check_prereq btrfs setup_root_helper prepare_test_dev 2g -run_check $TOP/mkfs.btrfs -f $IMAGE +run_check "$TOP/mkfs.btrfs" -f "$IMAGE" run_check_mount_test_dev here=`pwd` @@ -26,7 +26,7 @@ run_check $SUDO_HELPER btrfs subvolume snapshot -r subv-parent subv-snap3 run_check truncate -s0 "$here"/send.stream run_check chmod a+w "$here"/send.stream -run_check $SUDO_HELPER $TOP/btrfs send -f "$here"/send.stream -p subv-snap1 subv-snap2 subv-snap3 +run_check $SUDO_HELPER "$TOP/btrfs" send -f "$here"/send.stream -p subv-snap1 subv-snap2 subv-snap3 cd "$here" || _fail "cannot chdir back to test directory" rm send.stream diff --git a/tests/cli-tests/005-qgroup-show/test.sh b/tests/cli-tests/005-qgroup-show/test.sh index 28c22c61..46d3c3a7 100755 --- a/tests/cli-tests/005-qgroup-show/test.sh +++ b/tests/cli-tests/005-qgroup-show/test.sh @@ -2,7 +2,7 @@ # # qgroup show behaviour when quotas are not enabled -source $TOP/tests/common +source "$TOP/tests/common" check_prereq mkfs.btrfs check_prereq btrfs @@ -10,12 +10,12 @@ check_prereq btrfs setup_root_helper prepare_test_dev 2g -run_check $TOP/mkfs.btrfs -f $IMAGE +run_check "$TOP/mkfs.btrfs" -f "$IMAGE" run_check_mount_test_dev -run_mayfail $TOP/btrfs qgroup show "$TEST_MNT" -run_mayfail $SUDO_HELPER $TOP/btrfs qgroup show "$TEST_MNT" -run_check $SUDO_HELPER $TOP/btrfs quota enable "$TEST_MNT" -run_mayfail $TOP/btrfs qgroup show "$TEST_MNT" -run_check $SUDO_HELPER $TOP/btrfs qgroup show "$TEST_MNT" -run_check $SUDO_HELPER $TOP/btrfs quota disable "$TEST_MNT" +run_mayfail "$TOP/btrfs" qgroup show "$TEST_MNT" +run_mayfail $SUDO_HELPER "$TOP/btrfs" qgroup show "$TEST_MNT" +run_check $SUDO_HELPER "$TOP/btrfs" quota enable "$TEST_MNT" +run_mayfail "$TOP/btrfs" qgroup show "$TEST_MNT" +run_check $SUDO_HELPER "$TOP/btrfs" qgroup show "$TEST_MNT" +run_check $SUDO_HELPER "$TOP/btrfs" quota disable "$TEST_MNT" run_check_umount_test_dev -- cgit v1.2.3 From 78e1787c55a28f496d210b2805d84539d86552a1 Mon Sep 17 00:00:00 2001 From: David Sterba Date: Tue, 24 Jan 2017 18:19:27 +0100 Subject: btrfs-progs: tests: use built binaries for 004-send-parent-multi-subvol Signed-off-by: David Sterba --- tests/cli-tests/004-send-parent-multi-subvol/test.sh | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-) (limited to 'tests') diff --git a/tests/cli-tests/004-send-parent-multi-subvol/test.sh b/tests/cli-tests/004-send-parent-multi-subvol/test.sh index 860f657a..72a9eb36 100755 --- a/tests/cli-tests/004-send-parent-multi-subvol/test.sh +++ b/tests/cli-tests/004-send-parent-multi-subvol/test.sh @@ -16,13 +16,13 @@ run_check_mount_test_dev here=`pwd` cd "$TEST_MNT" || _fail "cannot chdir to TEST_MNT" -run_check $SUDO_HELPER btrfs subvolume create subv-parent +run_check $SUDO_HELPER "$TOP/btrfs" subvolume create subv-parent run_check $SUDO_HELPER dd if=/dev/urandom of=subv-parent/file bs=1M count=10 -run_check $SUDO_HELPER btrfs subvolume snapshot -r subv-parent subv-snap1 +run_check $SUDO_HELPER "$TOP/btrfs" subvolume snapshot -r subv-parent subv-snap1 run_check $SUDO_HELPER dd if=/dev/urandom of=subv-parent/file bs=1M count=10 -run_check $SUDO_HELPER btrfs subvolume snapshot -r subv-parent subv-snap2 +run_check $SUDO_HELPER "$TOP/btrfs" subvolume snapshot -r subv-parent subv-snap2 run_check $SUDO_HELPER dd if=/dev/urandom of=subv-parent/file bs=1M count=10 -run_check $SUDO_HELPER btrfs subvolume snapshot -r subv-parent subv-snap3 +run_check $SUDO_HELPER "$TOP/btrfs" subvolume snapshot -r subv-parent subv-snap3 run_check truncate -s0 "$here"/send.stream run_check chmod a+w "$here"/send.stream -- cgit v1.2.3 From fa77a1b5a36347d95e230807195b76e3d2ee2743 Mon Sep 17 00:00:00 2001 From: Qu Wenruo Date: Tue, 21 Feb 2017 16:34:33 +0800 Subject: btrfs-progs: tests: Move fsck-tests/015 to fuzz tests The test case fsck-tests/015-check-bad-memory-access can't be repair by btrfs check, and it's a fortunate bug makes original mode to forget the error code from extent tree, making original mode pass it. So fuzz-tests is more suitable for it. Signed-off-by: Qu Wenruo Signed-off-by: David Sterba --- .../bko-97171-btrfs-image.raw.txt | 254 --------------------- .../bko-97171-btrfs-image.raw.xz | Bin 6748 -> 0 bytes .../images/bko-97171-btrfs-image.raw.txt | 254 +++++++++++++++++++++ .../fuzz-tests/images/bko-97171-btrfs-image.raw.xz | Bin 0 -> 6748 bytes 4 files changed, 254 insertions(+), 254 deletions(-) delete mode 100644 tests/fsck-tests/015-check-bad-memory-access/bko-97171-btrfs-image.raw.txt delete mode 100644 tests/fsck-tests/015-check-bad-memory-access/bko-97171-btrfs-image.raw.xz create mode 100644 tests/fuzz-tests/images/bko-97171-btrfs-image.raw.txt create mode 100644 tests/fuzz-tests/images/bko-97171-btrfs-image.raw.xz (limited to 'tests') diff --git a/tests/fsck-tests/015-check-bad-memory-access/bko-97171-btrfs-image.raw.txt b/tests/fsck-tests/015-check-bad-memory-access/bko-97171-btrfs-image.raw.txt deleted file mode 100644 index 9685ed46..00000000 --- a/tests/fsck-tests/015-check-bad-memory-access/bko-97171-btrfs-image.raw.txt +++ /dev/null @@ -1,254 +0,0 @@ -URL: https://bugzilla.kernel.org/show_bug.cgi?id=97171 - -The btrfs-image attached to this bug causes the btrfs-userland tool to use -uninitialized memory and ultimately overwrite what seems to be arbitrary memory -locations, dying in the process. Reproduced on x86-64 and i686. - -The kernel seems to be less affected and fails to mount the image. If -/usr/sbin/btrfs is not setuid (which it probably never is), things should be -safe. I didn't investigate further though. - -gdb output: - -GNU gdb (GDB) Fedora 7.8.2-38.fc21 -[... lots of other errors...] -Ignoring transid failure -root 5 inode 260 errors 1000, some csum missing - unresolved ref dir 256 index 7 namelen 5 name b.bin filetype 1 errors 2, no dir index - unresolved ref dir 256 index 7 namelen 5 name b.fin filetype 1 errors 5, no dir item, no inode ref -root 5 inode 261 errors 200, dir isize wrong - -Program received signal SIGSEGV, Segmentation fault. -0x000000000089bb70 in ?? () -(gdb) bt -#0 0x000000000089bb70 in ?? () -#1 0x00007fffffffdb50 in ?? () -#2 0x0000000000894b20 in ?? () -#3 0x00000032629b88e0 in _IO_2_1_stdout_ () from /lib64/libc.so.6 -#4 0x000000000088c010 in ?? () -#5 0x0000000000000000 in ?? () - - -valgrind output: - -[...lots of errors...] -==12638== Conditional jump or move depends on uninitialised value(s) -==12638== at 0x436E77: check_block.part.14 (ctree.c:548) -==12638== by 0x438954: UnknownInlinedFun (kerncompat.h:91) -==12638== by 0x438954: btrfs_search_slot (ctree.c:1120) -==12638== by 0x40DD1F: count_csum_range (cmds-check.c:1419) -==12638== by 0x40DD1F: process_file_extent (cmds-check.c:1551) -==12638== by 0x40DD1F: process_one_leaf (cmds-check.c:1617) -==12638== by 0x40DD1F: walk_down_tree (cmds-check.c:1742) -==12638== by 0x40DD1F: check_fs_root (cmds-check.c:3380) -==12638== by 0x40DD1F: check_fs_roots.isra.51 (cmds-check.c:3516) -==12638== by 0x4C64B0F: ??? -==12638== by 0x4C30A2F: ??? -==12638== by 0x4C468CF: ??? -==12638== by 0x32629B88DF: ??? (in /usr/lib64/libc-2.20.so) -==12638== by 0x4C3657F: ??? -==12638== -==12638== Conditional jump or move depends on uninitialised value(s) -==12638== at 0x4A0B0E7: memcpy@@GLIBC_2.14 (in /usr/lib64/valgrind/vgpreload_memcheck-amd64-linux.so) -==12638== by 0x436E99: UnknownInlinedFun (ctree.h:1613) -==12638== by 0x436E99: check_block.part.14 (ctree.c:550) -==12638== by 0x438954: UnknownInlinedFun (kerncompat.h:91) -==12638== by 0x438954: btrfs_search_slot (ctree.c:1120) -==12638== by 0x40DD1F: count_csum_range (cmds-check.c:1419) -==12638== by 0x40DD1F: process_file_extent (cmds-check.c:1551) -==12638== by 0x40DD1F: process_one_leaf (cmds-check.c:1617) -==12638== by 0x40DD1F: walk_down_tree (cmds-check.c:1742) -==12638== by 0x40DD1F: check_fs_root (cmds-check.c:3380) -==12638== by 0x40DD1F: check_fs_roots.isra.51 (cmds-check.c:3516) -==12638== by 0x4C64B0F: ??? -==12638== by 0x4C30A2F: ??? -==12638== by 0x4C468CF: ??? -==12638== by 0x32629B88DF: ??? (in /usr/lib64/libc-2.20.so) -==12638== by 0x4C3657F: ??? -==12638== -==12638== Conditional jump or move depends on uninitialised value(s) -==12638== at 0x4A0B2AC: memcpy@@GLIBC_2.14 (in /usr/lib64/valgrind/vgpreload_memcheck-amd64-linux.so) -==12638== by 0x436E99: UnknownInlinedFun (ctree.h:1613) -==12638== by 0x436E99: check_block.part.14 (ctree.c:550) -==12638== by 0x438954: UnknownInlinedFun (kerncompat.h:91) -==12638== by 0x438954: btrfs_search_slot (ctree.c:1120) -==12638== by 0x40DD1F: count_csum_range (cmds-check.c:1419) -==12638== by 0x40DD1F: process_file_extent (cmds-check.c:1551) -==12638== by 0x40DD1F: process_one_leaf (cmds-check.c:1617) -==12638== by 0x40DD1F: walk_down_tree (cmds-check.c:1742) -==12638== by 0x40DD1F: check_fs_root (cmds-check.c:3380) -==12638== by 0x40DD1F: check_fs_roots.isra.51 (cmds-check.c:3516) -==12638== by 0x4C64B0F: ??? -==12638== by 0x4C30A2F: ??? -==12638== by 0x4C468CF: ??? -==12638== by 0x32629B88DF: ??? (in /usr/lib64/libc-2.20.so) -==12638== by 0x4C3657F: ??? -==12638== -==12638== Conditional jump or move depends on uninitialised value(s) -==12638== at 0x4A0B151: memcpy@@GLIBC_2.14 (in /usr/lib64/valgrind/vgpreload_memcheck-amd64-linux.so) -==12638== by 0x436E99: UnknownInlinedFun (ctree.h:1613) -==12638== by 0x436E99: check_block.part.14 (ctree.c:550) -==12638== by 0x438954: UnknownInlinedFun (kerncompat.h:91) -==12638== by 0x438954: btrfs_search_slot (ctree.c:1120) -==12638== by 0x40DD1F: count_csum_range (cmds-check.c:1419) -==12638== by 0x40DD1F: process_file_extent (cmds-check.c:1551) -==12638== by 0x40DD1F: process_one_leaf (cmds-check.c:1617) -==12638== by 0x40DD1F: walk_down_tree (cmds-check.c:1742) -==12638== by 0x40DD1F: check_fs_root (cmds-check.c:3380) -==12638== by 0x40DD1F: check_fs_roots.isra.51 (cmds-check.c:3516) -==12638== by 0x4C64B0F: ??? -==12638== by 0x4C30A2F: ??? -==12638== by 0x4C468CF: ??? -==12638== by 0x32629B88DF: ??? (in /usr/lib64/libc-2.20.so) -==12638== by 0x4C3657F: ??? -==12638== -==12638== Conditional jump or move depends on uninitialised value(s) -==12638== at 0x4A0B162: memcpy@@GLIBC_2.14 (in /usr/lib64/valgrind/vgpreload_memcheck-amd64-linux.so) -==12638== by 0x436E99: UnknownInlinedFun (ctree.h:1613) -==12638== by 0x436E99: check_block.part.14 (ctree.c:550) -==12638== by 0x438954: UnknownInlinedFun (kerncompat.h:91) -==12638== by 0x438954: btrfs_search_slot (ctree.c:1120) -==12638== by 0x40DD1F: count_csum_range (cmds-check.c:1419) -==12638== by 0x40DD1F: process_file_extent (cmds-check.c:1551) -==12638== by 0x40DD1F: process_one_leaf (cmds-check.c:1617) -==12638== by 0x40DD1F: walk_down_tree (cmds-check.c:1742) -==12638== by 0x40DD1F: check_fs_root (cmds-check.c:3380) -==12638== by 0x40DD1F: check_fs_roots.isra.51 (cmds-check.c:3516) -==12638== by 0x4C64B0F: ??? -==12638== by 0x4C30A2F: ??? -==12638== by 0x4C468CF: ??? -==12638== by 0x32629B88DF: ??? (in /usr/lib64/libc-2.20.so) -==12638== by 0x4C3657F: ??? -==12638== -==12638== Conditional jump or move depends on uninitialised value(s) -==12638== at 0x4A0B176: memcpy@@GLIBC_2.14 (in /usr/lib64/valgrind/vgpreload_memcheck-amd64-linux.so) -==12638== by 0x436E99: UnknownInlinedFun (ctree.h:1613) -==12638== by 0x436E99: check_block.part.14 (ctree.c:550) -==12638== by 0x438954: UnknownInlinedFun (kerncompat.h:91) -==12638== by 0x438954: btrfs_search_slot (ctree.c:1120) -==12638== by 0x40DD1F: count_csum_range (cmds-check.c:1419) -==12638== by 0x40DD1F: process_file_extent (cmds-check.c:1551) -==12638== by 0x40DD1F: process_one_leaf (cmds-check.c:1617) -==12638== by 0x40DD1F: walk_down_tree (cmds-check.c:1742) -==12638== by 0x40DD1F: check_fs_root (cmds-check.c:3380) -==12638== by 0x40DD1F: check_fs_roots.isra.51 (cmds-check.c:3516) -==12638== by 0x4C64B0F: ??? -==12638== by 0x4C30A2F: ??? -==12638== by 0x4C468CF: ??? -==12638== by 0x32629B88DF: ??? (in /usr/lib64/libc-2.20.so) -==12638== by 0x4C3657F: ??? -==12638== -==12638== Conditional jump or move depends on uninitialised value(s) -==12638== at 0x4A0B2CE: memcpy@@GLIBC_2.14 (in /usr/lib64/valgrind/vgpreload_memcheck-amd64-linux.so) -==12638== by 0x436E99: UnknownInlinedFun (ctree.h:1613) -==12638== by 0x436E99: check_block.part.14 (ctree.c:550) -==12638== by 0x438954: UnknownInlinedFun (kerncompat.h:91) -==12638== by 0x438954: btrfs_search_slot (ctree.c:1120) -==12638== by 0x40DD1F: count_csum_range (cmds-check.c:1419) -==12638== by 0x40DD1F: process_file_extent (cmds-check.c:1551) -==12638== by 0x40DD1F: process_one_leaf (cmds-check.c:1617) -==12638== by 0x40DD1F: walk_down_tree (cmds-check.c:1742) -==12638== by 0x40DD1F: check_fs_root (cmds-check.c:3380) -==12638== by 0x40DD1F: check_fs_roots.isra.51 (cmds-check.c:3516) -==12638== by 0x4C64B0F: ??? -==12638== by 0x4C30A2F: ??? -==12638== by 0x4C468CF: ??? -==12638== by 0x32629B88DF: ??? (in /usr/lib64/libc-2.20.so) -==12638== by 0x4C3657F: ??? -==12638== -==12638== Conditional jump or move depends on uninitialised value(s) -==12638== at 0x4A0B34A: memcpy@@GLIBC_2.14 (in /usr/lib64/valgrind/vgpreload_memcheck-amd64-linux.so) -==12638== by 0x436E99: UnknownInlinedFun (ctree.h:1613) -==12638== by 0x436E99: check_block.part.14 (ctree.c:550) -==12638== by 0x438954: UnknownInlinedFun (kerncompat.h:91) -==12638== by 0x438954: btrfs_search_slot (ctree.c:1120) -==12638== by 0x40DD1F: count_csum_range (cmds-check.c:1419) -==12638== by 0x40DD1F: process_file_extent (cmds-check.c:1551) -==12638== by 0x40DD1F: process_one_leaf (cmds-check.c:1617) -==12638== by 0x40DD1F: walk_down_tree (cmds-check.c:1742) -==12638== by 0x40DD1F: check_fs_root (cmds-check.c:3380) -==12638== by 0x40DD1F: check_fs_roots.isra.51 (cmds-check.c:3516) -==12638== by 0x4C64B0F: ??? -==12638== by 0x4C30A2F: ??? -==12638== by 0x4C468CF: ??? -==12638== by 0x32629B88DF: ??? (in /usr/lib64/libc-2.20.so) -==12638== by 0x4C3657F: ??? -==12638== -==12638== Use of uninitialised value of size 8 -==12638== at 0x4A0B3A0: memcpy@@GLIBC_2.14 (in /usr/lib64/valgrind/vgpreload_memcheck-amd64-linux.so) -==12638== by 0x436E99: UnknownInlinedFun (ctree.h:1613) -==12638== by 0x436E99: check_block.part.14 (ctree.c:550) -==12638== by 0x438954: UnknownInlinedFun (kerncompat.h:91) -==12638== by 0x438954: btrfs_search_slot (ctree.c:1120) -==12638== by 0x40DD1F: count_csum_range (cmds-check.c:1419) -==12638== by 0x40DD1F: process_file_extent (cmds-check.c:1551) -==12638== by 0x40DD1F: process_one_leaf (cmds-check.c:1617) -==12638== by 0x40DD1F: walk_down_tree (cmds-check.c:1742) -==12638== by 0x40DD1F: check_fs_root (cmds-check.c:3380) -==12638== by 0x40DD1F: check_fs_roots.isra.51 (cmds-check.c:3516) -==12638== by 0x4C64B0F: ??? -==12638== by 0x4C30A2F: ??? -==12638== by 0x4C468CF: ??? -==12638== by 0x32629B88DF: ??? (in /usr/lib64/libc-2.20.so) -==12638== by 0x4C3657F: ??? -==12638== -==12638== Invalid read of size 1 -==12638== at 0x4A0B3A0: memcpy@@GLIBC_2.14 (in /usr/lib64/valgrind/vgpreload_memcheck-amd64-linux.so) -==12638== by 0x436E99: UnknownInlinedFun (ctree.h:1613) -==12638== by 0x436E99: check_block.part.14 (ctree.c:550) -==12638== by 0x438954: UnknownInlinedFun (kerncompat.h:91) -==12638== by 0x438954: btrfs_search_slot (ctree.c:1120) -==12638== by 0x40DD1F: count_csum_range (cmds-check.c:1419) -==12638== by 0x40DD1F: process_file_extent (cmds-check.c:1551) -==12638== by 0x40DD1F: process_one_leaf (cmds-check.c:1617) -==12638== by 0x40DD1F: walk_down_tree (cmds-check.c:1742) -==12638== by 0x40DD1F: check_fs_root (cmds-check.c:3380) -==12638== by 0x40DD1F: check_fs_roots.isra.51 (cmds-check.c:3516) -==12638== by 0x4C64B0F: ??? -==12638== by 0x4C30A2F: ??? -==12638== by 0x4C468CF: ??? -==12638== by 0x32629B88DF: ??? (in /usr/lib64/libc-2.20.so) -==12638== by 0x4C3657F: ??? -==12638== Address 0xa25c9de9 is not stack'd, malloc'd or (recently) free'd -==12638== -==12638== -==12638== Process terminating with default action of signal 11 (SIGSEGV) -==12638== Access not within mapped region at address 0xA25C9DE9 -==12638== at 0x4A0B3A0: memcpy@@GLIBC_2.14 (in /usr/lib64/valgrind/vgpreload_memcheck-amd64-linux.so) -==12638== by 0x436E99: UnknownInlinedFun (ctree.h:1613) -==12638== by 0x436E99: check_block.part.14 (ctree.c:550) -==12638== by 0x438954: UnknownInlinedFun (kerncompat.h:91) -==12638== by 0x438954: btrfs_search_slot (ctree.c:1120) -==12638== by 0x40DD1F: count_csum_range (cmds-check.c:1419) -==12638== by 0x40DD1F: process_file_extent (cmds-check.c:1551) -==12638== by 0x40DD1F: process_one_leaf (cmds-check.c:1617) -==12638== by 0x40DD1F: walk_down_tree (cmds-check.c:1742) -==12638== by 0x40DD1F: check_fs_root (cmds-check.c:3380) -==12638== by 0x40DD1F: check_fs_roots.isra.51 (cmds-check.c:3516) -==12638== by 0x4C64B0F: ??? -==12638== by 0x4C30A2F: ??? -==12638== by 0x4C468CF: ??? -==12638== by 0x32629B88DF: ??? (in /usr/lib64/libc-2.20.so) -==12638== by 0x4C3657F: ??? -==12638== If you believe this happened as a result of a stack -==12638== overflow in your program's main thread (unlikely but -==12638== possible), you can try to increase the size of the -==12638== main thread stack using the --main-stacksize= flag. -==12638== The main thread stack size used in this run was 8388608. -==12638== -==12638== HEAP SUMMARY: -==12638== in use at exit: 46,260 bytes in 56 blocks -==12638== total heap usage: 380 allocs, 324 frees, 218,054 bytes allocated -==12638== -==12638== LEAK SUMMARY: -==12638== definitely lost: 272 bytes in 2 blocks -==12638== indirectly lost: 800 bytes in 8 blocks -==12638== possibly lost: 88 bytes in 1 blocks -==12638== still reachable: 45,100 bytes in 45 blocks -==12638== suppressed: 0 bytes in 0 blocks -==12638== Rerun with --leak-check=full to see details of leaked memory -==12638== -==12638== For counts of detected and suppressed errors, rerun with: -v -==12638== Use --track-origins=yes to see where uninitialised values come from -==12638== ERROR SUMMARY: 10 errors from 10 contexts (suppressed: 0 from 0) -[1] 12638 segmentation fault valgrind btrfs check btrfs_fukked_memorycorruption.bin diff --git a/tests/fsck-tests/015-check-bad-memory-access/bko-97171-btrfs-image.raw.xz b/tests/fsck-tests/015-check-bad-memory-access/bko-97171-btrfs-image.raw.xz deleted file mode 100644 index f3f0944d..00000000 Binary files a/tests/fsck-tests/015-check-bad-memory-access/bko-97171-btrfs-image.raw.xz and /dev/null differ diff --git a/tests/fuzz-tests/images/bko-97171-btrfs-image.raw.txt b/tests/fuzz-tests/images/bko-97171-btrfs-image.raw.txt new file mode 100644 index 00000000..9685ed46 --- /dev/null +++ b/tests/fuzz-tests/images/bko-97171-btrfs-image.raw.txt @@ -0,0 +1,254 @@ +URL: https://bugzilla.kernel.org/show_bug.cgi?id=97171 + +The btrfs-image attached to this bug causes the btrfs-userland tool to use +uninitialized memory and ultimately overwrite what seems to be arbitrary memory +locations, dying in the process. Reproduced on x86-64 and i686. + +The kernel seems to be less affected and fails to mount the image. If +/usr/sbin/btrfs is not setuid (which it probably never is), things should be +safe. I didn't investigate further though. + +gdb output: + +GNU gdb (GDB) Fedora 7.8.2-38.fc21 +[... lots of other errors...] +Ignoring transid failure +root 5 inode 260 errors 1000, some csum missing + unresolved ref dir 256 index 7 namelen 5 name b.bin filetype 1 errors 2, no dir index + unresolved ref dir 256 index 7 namelen 5 name b.fin filetype 1 errors 5, no dir item, no inode ref +root 5 inode 261 errors 200, dir isize wrong + +Program received signal SIGSEGV, Segmentation fault. +0x000000000089bb70 in ?? () +(gdb) bt +#0 0x000000000089bb70 in ?? () +#1 0x00007fffffffdb50 in ?? () +#2 0x0000000000894b20 in ?? () +#3 0x00000032629b88e0 in _IO_2_1_stdout_ () from /lib64/libc.so.6 +#4 0x000000000088c010 in ?? () +#5 0x0000000000000000 in ?? () + + +valgrind output: + +[...lots of errors...] +==12638== Conditional jump or move depends on uninitialised value(s) +==12638== at 0x436E77: check_block.part.14 (ctree.c:548) +==12638== by 0x438954: UnknownInlinedFun (kerncompat.h:91) +==12638== by 0x438954: btrfs_search_slot (ctree.c:1120) +==12638== by 0x40DD1F: count_csum_range (cmds-check.c:1419) +==12638== by 0x40DD1F: process_file_extent (cmds-check.c:1551) +==12638== by 0x40DD1F: process_one_leaf (cmds-check.c:1617) +==12638== by 0x40DD1F: walk_down_tree (cmds-check.c:1742) +==12638== by 0x40DD1F: check_fs_root (cmds-check.c:3380) +==12638== by 0x40DD1F: check_fs_roots.isra.51 (cmds-check.c:3516) +==12638== by 0x4C64B0F: ??? +==12638== by 0x4C30A2F: ??? +==12638== by 0x4C468CF: ??? +==12638== by 0x32629B88DF: ??? (in /usr/lib64/libc-2.20.so) +==12638== by 0x4C3657F: ??? +==12638== +==12638== Conditional jump or move depends on uninitialised value(s) +==12638== at 0x4A0B0E7: memcpy@@GLIBC_2.14 (in /usr/lib64/valgrind/vgpreload_memcheck-amd64-linux.so) +==12638== by 0x436E99: UnknownInlinedFun (ctree.h:1613) +==12638== by 0x436E99: check_block.part.14 (ctree.c:550) +==12638== by 0x438954: UnknownInlinedFun (kerncompat.h:91) +==12638== by 0x438954: btrfs_search_slot (ctree.c:1120) +==12638== by 0x40DD1F: count_csum_range (cmds-check.c:1419) +==12638== by 0x40DD1F: process_file_extent (cmds-check.c:1551) +==12638== by 0x40DD1F: process_one_leaf (cmds-check.c:1617) +==12638== by 0x40DD1F: walk_down_tree (cmds-check.c:1742) +==12638== by 0x40DD1F: check_fs_root (cmds-check.c:3380) +==12638== by 0x40DD1F: check_fs_roots.isra.51 (cmds-check.c:3516) +==12638== by 0x4C64B0F: ??? +==12638== by 0x4C30A2F: ??? +==12638== by 0x4C468CF: ??? +==12638== by 0x32629B88DF: ??? (in /usr/lib64/libc-2.20.so) +==12638== by 0x4C3657F: ??? +==12638== +==12638== Conditional jump or move depends on uninitialised value(s) +==12638== at 0x4A0B2AC: memcpy@@GLIBC_2.14 (in /usr/lib64/valgrind/vgpreload_memcheck-amd64-linux.so) +==12638== by 0x436E99: UnknownInlinedFun (ctree.h:1613) +==12638== by 0x436E99: check_block.part.14 (ctree.c:550) +==12638== by 0x438954: UnknownInlinedFun (kerncompat.h:91) +==12638== by 0x438954: btrfs_search_slot (ctree.c:1120) +==12638== by 0x40DD1F: count_csum_range (cmds-check.c:1419) +==12638== by 0x40DD1F: process_file_extent (cmds-check.c:1551) +==12638== by 0x40DD1F: process_one_leaf (cmds-check.c:1617) +==12638== by 0x40DD1F: walk_down_tree (cmds-check.c:1742) +==12638== by 0x40DD1F: check_fs_root (cmds-check.c:3380) +==12638== by 0x40DD1F: check_fs_roots.isra.51 (cmds-check.c:3516) +==12638== by 0x4C64B0F: ??? +==12638== by 0x4C30A2F: ??? +==12638== by 0x4C468CF: ??? +==12638== by 0x32629B88DF: ??? (in /usr/lib64/libc-2.20.so) +==12638== by 0x4C3657F: ??? +==12638== +==12638== Conditional jump or move depends on uninitialised value(s) +==12638== at 0x4A0B151: memcpy@@GLIBC_2.14 (in /usr/lib64/valgrind/vgpreload_memcheck-amd64-linux.so) +==12638== by 0x436E99: UnknownInlinedFun (ctree.h:1613) +==12638== by 0x436E99: check_block.part.14 (ctree.c:550) +==12638== by 0x438954: UnknownInlinedFun (kerncompat.h:91) +==12638== by 0x438954: btrfs_search_slot (ctree.c:1120) +==12638== by 0x40DD1F: count_csum_range (cmds-check.c:1419) +==12638== by 0x40DD1F: process_file_extent (cmds-check.c:1551) +==12638== by 0x40DD1F: process_one_leaf (cmds-check.c:1617) +==12638== by 0x40DD1F: walk_down_tree (cmds-check.c:1742) +==12638== by 0x40DD1F: check_fs_root (cmds-check.c:3380) +==12638== by 0x40DD1F: check_fs_roots.isra.51 (cmds-check.c:3516) +==12638== by 0x4C64B0F: ??? +==12638== by 0x4C30A2F: ??? +==12638== by 0x4C468CF: ??? +==12638== by 0x32629B88DF: ??? (in /usr/lib64/libc-2.20.so) +==12638== by 0x4C3657F: ??? +==12638== +==12638== Conditional jump or move depends on uninitialised value(s) +==12638== at 0x4A0B162: memcpy@@GLIBC_2.14 (in /usr/lib64/valgrind/vgpreload_memcheck-amd64-linux.so) +==12638== by 0x436E99: UnknownInlinedFun (ctree.h:1613) +==12638== by 0x436E99: check_block.part.14 (ctree.c:550) +==12638== by 0x438954: UnknownInlinedFun (kerncompat.h:91) +==12638== by 0x438954: btrfs_search_slot (ctree.c:1120) +==12638== by 0x40DD1F: count_csum_range (cmds-check.c:1419) +==12638== by 0x40DD1F: process_file_extent (cmds-check.c:1551) +==12638== by 0x40DD1F: process_one_leaf (cmds-check.c:1617) +==12638== by 0x40DD1F: walk_down_tree (cmds-check.c:1742) +==12638== by 0x40DD1F: check_fs_root (cmds-check.c:3380) +==12638== by 0x40DD1F: check_fs_roots.isra.51 (cmds-check.c:3516) +==12638== by 0x4C64B0F: ??? +==12638== by 0x4C30A2F: ??? +==12638== by 0x4C468CF: ??? +==12638== by 0x32629B88DF: ??? (in /usr/lib64/libc-2.20.so) +==12638== by 0x4C3657F: ??? +==12638== +==12638== Conditional jump or move depends on uninitialised value(s) +==12638== at 0x4A0B176: memcpy@@GLIBC_2.14 (in /usr/lib64/valgrind/vgpreload_memcheck-amd64-linux.so) +==12638== by 0x436E99: UnknownInlinedFun (ctree.h:1613) +==12638== by 0x436E99: check_block.part.14 (ctree.c:550) +==12638== by 0x438954: UnknownInlinedFun (kerncompat.h:91) +==12638== by 0x438954: btrfs_search_slot (ctree.c:1120) +==12638== by 0x40DD1F: count_csum_range (cmds-check.c:1419) +==12638== by 0x40DD1F: process_file_extent (cmds-check.c:1551) +==12638== by 0x40DD1F: process_one_leaf (cmds-check.c:1617) +==12638== by 0x40DD1F: walk_down_tree (cmds-check.c:1742) +==12638== by 0x40DD1F: check_fs_root (cmds-check.c:3380) +==12638== by 0x40DD1F: check_fs_roots.isra.51 (cmds-check.c:3516) +==12638== by 0x4C64B0F: ??? +==12638== by 0x4C30A2F: ??? +==12638== by 0x4C468CF: ??? +==12638== by 0x32629B88DF: ??? (in /usr/lib64/libc-2.20.so) +==12638== by 0x4C3657F: ??? +==12638== +==12638== Conditional jump or move depends on uninitialised value(s) +==12638== at 0x4A0B2CE: memcpy@@GLIBC_2.14 (in /usr/lib64/valgrind/vgpreload_memcheck-amd64-linux.so) +==12638== by 0x436E99: UnknownInlinedFun (ctree.h:1613) +==12638== by 0x436E99: check_block.part.14 (ctree.c:550) +==12638== by 0x438954: UnknownInlinedFun (kerncompat.h:91) +==12638== by 0x438954: btrfs_search_slot (ctree.c:1120) +==12638== by 0x40DD1F: count_csum_range (cmds-check.c:1419) +==12638== by 0x40DD1F: process_file_extent (cmds-check.c:1551) +==12638== by 0x40DD1F: process_one_leaf (cmds-check.c:1617) +==12638== by 0x40DD1F: walk_down_tree (cmds-check.c:1742) +==12638== by 0x40DD1F: check_fs_root (cmds-check.c:3380) +==12638== by 0x40DD1F: check_fs_roots.isra.51 (cmds-check.c:3516) +==12638== by 0x4C64B0F: ??? +==12638== by 0x4C30A2F: ??? +==12638== by 0x4C468CF: ??? +==12638== by 0x32629B88DF: ??? (in /usr/lib64/libc-2.20.so) +==12638== by 0x4C3657F: ??? +==12638== +==12638== Conditional jump or move depends on uninitialised value(s) +==12638== at 0x4A0B34A: memcpy@@GLIBC_2.14 (in /usr/lib64/valgrind/vgpreload_memcheck-amd64-linux.so) +==12638== by 0x436E99: UnknownInlinedFun (ctree.h:1613) +==12638== by 0x436E99: check_block.part.14 (ctree.c:550) +==12638== by 0x438954: UnknownInlinedFun (kerncompat.h:91) +==12638== by 0x438954: btrfs_search_slot (ctree.c:1120) +==12638== by 0x40DD1F: count_csum_range (cmds-check.c:1419) +==12638== by 0x40DD1F: process_file_extent (cmds-check.c:1551) +==12638== by 0x40DD1F: process_one_leaf (cmds-check.c:1617) +==12638== by 0x40DD1F: walk_down_tree (cmds-check.c:1742) +==12638== by 0x40DD1F: check_fs_root (cmds-check.c:3380) +==12638== by 0x40DD1F: check_fs_roots.isra.51 (cmds-check.c:3516) +==12638== by 0x4C64B0F: ??? +==12638== by 0x4C30A2F: ??? +==12638== by 0x4C468CF: ??? +==12638== by 0x32629B88DF: ??? (in /usr/lib64/libc-2.20.so) +==12638== by 0x4C3657F: ??? +==12638== +==12638== Use of uninitialised value of size 8 +==12638== at 0x4A0B3A0: memcpy@@GLIBC_2.14 (in /usr/lib64/valgrind/vgpreload_memcheck-amd64-linux.so) +==12638== by 0x436E99: UnknownInlinedFun (ctree.h:1613) +==12638== by 0x436E99: check_block.part.14 (ctree.c:550) +==12638== by 0x438954: UnknownInlinedFun (kerncompat.h:91) +==12638== by 0x438954: btrfs_search_slot (ctree.c:1120) +==12638== by 0x40DD1F: count_csum_range (cmds-check.c:1419) +==12638== by 0x40DD1F: process_file_extent (cmds-check.c:1551) +==12638== by 0x40DD1F: process_one_leaf (cmds-check.c:1617) +==12638== by 0x40DD1F: walk_down_tree (cmds-check.c:1742) +==12638== by 0x40DD1F: check_fs_root (cmds-check.c:3380) +==12638== by 0x40DD1F: check_fs_roots.isra.51 (cmds-check.c:3516) +==12638== by 0x4C64B0F: ??? +==12638== by 0x4C30A2F: ??? +==12638== by 0x4C468CF: ??? +==12638== by 0x32629B88DF: ??? (in /usr/lib64/libc-2.20.so) +==12638== by 0x4C3657F: ??? +==12638== +==12638== Invalid read of size 1 +==12638== at 0x4A0B3A0: memcpy@@GLIBC_2.14 (in /usr/lib64/valgrind/vgpreload_memcheck-amd64-linux.so) +==12638== by 0x436E99: UnknownInlinedFun (ctree.h:1613) +==12638== by 0x436E99: check_block.part.14 (ctree.c:550) +==12638== by 0x438954: UnknownInlinedFun (kerncompat.h:91) +==12638== by 0x438954: btrfs_search_slot (ctree.c:1120) +==12638== by 0x40DD1F: count_csum_range (cmds-check.c:1419) +==12638== by 0x40DD1F: process_file_extent (cmds-check.c:1551) +==12638== by 0x40DD1F: process_one_leaf (cmds-check.c:1617) +==12638== by 0x40DD1F: walk_down_tree (cmds-check.c:1742) +==12638== by 0x40DD1F: check_fs_root (cmds-check.c:3380) +==12638== by 0x40DD1F: check_fs_roots.isra.51 (cmds-check.c:3516) +==12638== by 0x4C64B0F: ??? +==12638== by 0x4C30A2F: ??? +==12638== by 0x4C468CF: ??? +==12638== by 0x32629B88DF: ??? (in /usr/lib64/libc-2.20.so) +==12638== by 0x4C3657F: ??? +==12638== Address 0xa25c9de9 is not stack'd, malloc'd or (recently) free'd +==12638== +==12638== +==12638== Process terminating with default action of signal 11 (SIGSEGV) +==12638== Access not within mapped region at address 0xA25C9DE9 +==12638== at 0x4A0B3A0: memcpy@@GLIBC_2.14 (in /usr/lib64/valgrind/vgpreload_memcheck-amd64-linux.so) +==12638== by 0x436E99: UnknownInlinedFun (ctree.h:1613) +==12638== by 0x436E99: check_block.part.14 (ctree.c:550) +==12638== by 0x438954: UnknownInlinedFun (kerncompat.h:91) +==12638== by 0x438954: btrfs_search_slot (ctree.c:1120) +==12638== by 0x40DD1F: count_csum_range (cmds-check.c:1419) +==12638== by 0x40DD1F: process_file_extent (cmds-check.c:1551) +==12638== by 0x40DD1F: process_one_leaf (cmds-check.c:1617) +==12638== by 0x40DD1F: walk_down_tree (cmds-check.c:1742) +==12638== by 0x40DD1F: check_fs_root (cmds-check.c:3380) +==12638== by 0x40DD1F: check_fs_roots.isra.51 (cmds-check.c:3516) +==12638== by 0x4C64B0F: ??? +==12638== by 0x4C30A2F: ??? +==12638== by 0x4C468CF: ??? +==12638== by 0x32629B88DF: ??? (in /usr/lib64/libc-2.20.so) +==12638== by 0x4C3657F: ??? +==12638== If you believe this happened as a result of a stack +==12638== overflow in your program's main thread (unlikely but +==12638== possible), you can try to increase the size of the +==12638== main thread stack using the --main-stacksize= flag. +==12638== The main thread stack size used in this run was 8388608. +==12638== +==12638== HEAP SUMMARY: +==12638== in use at exit: 46,260 bytes in 56 blocks +==12638== total heap usage: 380 allocs, 324 frees, 218,054 bytes allocated +==12638== +==12638== LEAK SUMMARY: +==12638== definitely lost: 272 bytes in 2 blocks +==12638== indirectly lost: 800 bytes in 8 blocks +==12638== possibly lost: 88 bytes in 1 blocks +==12638== still reachable: 45,100 bytes in 45 blocks +==12638== suppressed: 0 bytes in 0 blocks +==12638== Rerun with --leak-check=full to see details of leaked memory +==12638== +==12638== For counts of detected and suppressed errors, rerun with: -v +==12638== Use --track-origins=yes to see where uninitialised values come from +==12638== ERROR SUMMARY: 10 errors from 10 contexts (suppressed: 0 from 0) +[1] 12638 segmentation fault valgrind btrfs check btrfs_fukked_memorycorruption.bin diff --git a/tests/fuzz-tests/images/bko-97171-btrfs-image.raw.xz b/tests/fuzz-tests/images/bko-97171-btrfs-image.raw.xz new file mode 100644 index 00000000..f3f0944d Binary files /dev/null and b/tests/fuzz-tests/images/bko-97171-btrfs-image.raw.xz differ -- cgit v1.2.3 From 6203e63672ab34f401083957f580f5e9dce6a792 Mon Sep 17 00:00:00 2001 From: Qu Wenruo Date: Tue, 21 Feb 2017 16:34:34 +0800 Subject: btrfs-progs: tests: Add test image for lowmem mode block group false alert Add a minimal image which can reproduce the block group used space false alert for lowmem mode fsck. Reported-by: Christoph Anton Mitterer Signed-off-by: Qu Wenruo Signed-off-by: David Sterba --- .../block_group_item_false_alert.raw.xz | Bin 0 -> 47792 bytes tests/fsck-tests/020-extent-ref-cases/test.sh | 15 +++++++++++---- 2 files changed, 11 insertions(+), 4 deletions(-) create mode 100644 tests/fsck-tests/020-extent-ref-cases/block_group_item_false_alert.raw.xz (limited to 'tests') diff --git a/tests/fsck-tests/020-extent-ref-cases/block_group_item_false_alert.raw.xz b/tests/fsck-tests/020-extent-ref-cases/block_group_item_false_alert.raw.xz new file mode 100644 index 00000000..559c3fa9 Binary files /dev/null and b/tests/fsck-tests/020-extent-ref-cases/block_group_item_false_alert.raw.xz differ diff --git a/tests/fsck-tests/020-extent-ref-cases/test.sh b/tests/fsck-tests/020-extent-ref-cases/test.sh index c2b6a006..5dc5e55d 100755 --- a/tests/fsck-tests/020-extent-ref-cases/test.sh +++ b/tests/fsck-tests/020-extent-ref-cases/test.sh @@ -8,16 +8,23 @@ # * shared_data_ref # * no_inline_ref (a extent item without inline ref) # * no_skinny_ref +# +# Special check for lowmem regression +# * block_group_item_false_alert +# Containing a block group and its first extent at +# the beginning of leaf. +# Which caused false alert for lowmem mode. source $TOP/tests/common check_prereq btrfs -for img in *.img +for img in *.img *.raw.xz do image=$(extract_image $img) - run_check_stdout $TOP/btrfs check "$image" 2>&1 | - grep -q "Errors found in extent allocation tree or chunk allocation" && - _fail "unexpected error occurred when checking $img" + + # Since the return value bug is already fixed, we don't need + # the old grep hack to detect bug. + run_check $TOP/btrfs check "$image" rm -f "$image" done -- cgit v1.2.3 From 381b43a0201e78049f11e8ededd251a930cbaeb8 Mon Sep 17 00:00:00 2001 From: Qu Wenruo Date: Tue, 21 Feb 2017 16:34:35 +0800 Subject: btrfs-progs: tests: Make fsck-test/013 compatible with lowmem mode fsck-tests/013-extent-tree-rebuild uses "--init-extent-tree", which implies "--repair". But the test script doesn't specify "--repair" for lowmem mode test to detect it. Add it so lowmem mode test can be happy with it. Signed-off-by: Qu Wenruo Signed-off-by: David Sterba --- tests/fsck-tests/013-extent-tree-rebuild/test.sh | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) (limited to 'tests') diff --git a/tests/fsck-tests/013-extent-tree-rebuild/test.sh b/tests/fsck-tests/013-extent-tree-rebuild/test.sh index 37bdcd9c..08c1e50e 100755 --- a/tests/fsck-tests/013-extent-tree-rebuild/test.sh +++ b/tests/fsck-tests/013-extent-tree-rebuild/test.sh @@ -36,7 +36,7 @@ test_extent_tree_rebuild() $SUDO_HELPER $TOP/btrfs check $TEST_DEV >& /dev/null && \ _fail "btrfs check should detect failure" - run_check $SUDO_HELPER $TOP/btrfs check --init-extent-tree $TEST_DEV + run_check $SUDO_HELPER $TOP/btrfs check --repair --init-extent-tree $TEST_DEV run_check $SUDO_HELPER $TOP/btrfs check $TEST_DEV } -- cgit v1.2.3 From cbaa289d3d1350a7aad8f3f96df2b66ffeaa9155 Mon Sep 17 00:00:00 2001 From: Qu Wenruo Date: Tue, 21 Feb 2017 16:34:36 +0800 Subject: btrfs-progs: tests: Add new test case for file extent false alerts Lowmem mode exposed several false alerts, all related to file extents check. 1) Partly written prealloc extent Cause lowmem mode to report missing csum or prealloc extent should not have csum 2) Compressed inline extent Cause lowmem mode to find mismatch on inline len and item len. While no error message is output but exit silently. Reported-by: Chris Murphy Reported-by: Christoph Anton Mitterer Signed-off-by: Qu Wenruo Signed-off-by: David Sterba --- tests/fsck-tests/025-file-extents/test.sh | 42 +++++++++++++++++++++++++++++++ 1 file changed, 42 insertions(+) create mode 100755 tests/fsck-tests/025-file-extents/test.sh (limited to 'tests') diff --git a/tests/fsck-tests/025-file-extents/test.sh b/tests/fsck-tests/025-file-extents/test.sh new file mode 100755 index 00000000..cb64c500 --- /dev/null +++ b/tests/fsck-tests/025-file-extents/test.sh @@ -0,0 +1,42 @@ +#!/bin/bash +# Confirm btrfs check can check file extents without causing false alert + +source $TOP/tests/common + +check_prereq btrfs +check_prereq mkfs.btrfs +check_global_prereq xfs_io +check_global_prereq fallocate + +setup_root_helper +prepare_test_dev 128M + +# Do some write into a large prealloc range +# Lowmem mode can report missing csum due to wrong csum range +test_paritical_write_into_prealloc() +{ + run_check $SUDO_HELPER "$TOP/mkfs.btrfs" -f "$TEST_DEV" + run_check_mount_test_dev + + run_check fallocate -l 128K "$TEST_MNT/file" + sync + run_check xfs_io -c "pwrite 0 64K" "$TEST_MNT/file" + run_check_umount_test_dev + run_check "$TOP/btrfs" check "$TEST_DEV" +} + +# Inline compressed file extent +# Lowmem mode can cause silent error without any error message +# due to too restrict check on inline extent size +test_compressed_inline_extent() +{ + run_check $SUDO_HELPER "$TOP/mkfs.btrfs" -f "$TEST_DEV" + run_check_mount_test_dev -o compress=lzo,max_inline=2048 + + run_check xfs_io -f -c "pwrite 0 1K" "$TEST_MNT/file" + run_check_umount_test_dev + run_check "$TOP/btrfs" check "$TEST_DEV" +} + +test_paritical_write_into_prealloc +test_compressed_inline_extent -- cgit v1.2.3 From a0e44021abd7fa612f3060d6b9fe7a50211aafcf Mon Sep 17 00:00:00 2001 From: Lu Fengqi Date: Tue, 21 Feb 2017 16:34:37 +0800 Subject: btrfs-progs: check: Fix lowmem mode override to allow it skip repair work Current common.local doesn't handle lowmem mode well. It passes "--mode=lowmem" alone with "--repair", making it unable to check lowmem mode. It's caused by the following bugs: 1) Wrong variable in test/common.local We should check TEST_ARGS_CHECK, not TEST_CHECK, which is not defined so we never return 1. 2) Wrong parameter passed to _cmd_spec() in test/common This prevents us from grepping the correct parameters. Fix it. Signed-off-by: Lu Fengqi Signed-off-by: David Sterba --- tests/common | 8 ++++---- tests/common.local | 2 +- 2 files changed, 5 insertions(+), 5 deletions(-) (limited to 'tests') diff --git a/tests/common b/tests/common index 51c2e267..7ad436e3 100644 --- a/tests/common +++ b/tests/common @@ -106,7 +106,7 @@ run_check() ins=$(_get_spec_ins "$@") spec=$(($ins-1)) cmd=$(eval echo "\${$spec}") - spec=$(_cmd_spec "$cmd") + spec=$(_cmd_spec "${@:$spec}") set -- "${@:1:$(($ins-1))}" $spec "${@: $ins}" echo "############### $@" >> "$RESULTS" 2>&1 if [[ $TEST_LOG =~ tty ]]; then echo "CMD: $@" > /dev/tty; fi @@ -128,7 +128,7 @@ run_check_stdout() ins=$(_get_spec_ins "$@") spec=$(($ins-1)) cmd=$(eval echo "\${$spec}") - spec=$(_cmd_spec "$cmd") + spec=$(_cmd_spec "${@:$spec}") set -- "${@:1:$(($ins-1))}" $spec "${@: $ins}" echo "############### $@" >> "$RESULTS" 2>&1 if [[ $TEST_LOG =~ tty ]]; then echo "CMD(stdout): $@" > /dev/tty; fi @@ -152,7 +152,7 @@ run_mayfail() ins=$(_get_spec_ins "$@") spec=$(($ins-1)) cmd=$(eval echo "\${$spec}") - spec=$(_cmd_spec "$cmd") + spec=$(_cmd_spec "${@:$spec}") set -- "${@:1:$(($ins-1))}" $spec "${@: $ins}" echo "############### $@" >> "$RESULTS" 2>&1 if [[ $TEST_LOG =~ tty ]]; then echo "CMD(mayfail): $@" > /dev/tty; fi @@ -188,7 +188,7 @@ run_mustfail() ins=$(_get_spec_ins "$@") spec=$(($ins-1)) cmd=$(eval echo "\${$spec}") - spec=$(_cmd_spec "$cmd") + spec=$(_cmd_spec "${@:$spec}") set -- "${@:1:$(($ins-1))}" $spec "${@: $ins}" echo "############### $@" >> "$RESULTS" 2>&1 if [[ $TEST_LOG =~ tty ]]; then echo "CMD(mustfail): $@" > /dev/tty; fi diff --git a/tests/common.local b/tests/common.local index 9f567c27..4f56bb08 100644 --- a/tests/common.local +++ b/tests/common.local @@ -17,7 +17,7 @@ TEST_ARGS_CHECK=--mode=lowmem # break tests _skip_spec() { - if echo "$TEST_CHECK" | grep -q 'mode=lowmem' && + if echo "$TEST_ARGS_CHECK" | grep -q 'mode=lowmem' && echo "$@" | grep -q -- '--repair'; then return 0 fi -- cgit v1.2.3 From 62d4aa5fbabaa2068d2c25802c480070ac05aa26 Mon Sep 17 00:00:00 2001 From: David Sterba Date: Wed, 1 Mar 2017 17:10:44 +0100 Subject: btrfs-progs: tests: fix permissions of temporary files in 025-file-extents If the tests are started from non-root user, the fallocate and xfs_io fail. Use the root helper as a workaround, we'd should fix the perms instead. Signed-off-by: David Sterba --- tests/fsck-tests/025-file-extents/test.sh | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) (limited to 'tests') diff --git a/tests/fsck-tests/025-file-extents/test.sh b/tests/fsck-tests/025-file-extents/test.sh index cb64c500..37173ebd 100755 --- a/tests/fsck-tests/025-file-extents/test.sh +++ b/tests/fsck-tests/025-file-extents/test.sh @@ -18,9 +18,9 @@ test_paritical_write_into_prealloc() run_check $SUDO_HELPER "$TOP/mkfs.btrfs" -f "$TEST_DEV" run_check_mount_test_dev - run_check fallocate -l 128K "$TEST_MNT/file" + run_check $SUDO_HELPER fallocate -l 128K "$TEST_MNT/file" sync - run_check xfs_io -c "pwrite 0 64K" "$TEST_MNT/file" + run_check $SUDO_HELPER xfs_io -c "pwrite 0 64K" "$TEST_MNT/file" run_check_umount_test_dev run_check "$TOP/btrfs" check "$TEST_DEV" } @@ -33,7 +33,7 @@ test_compressed_inline_extent() run_check $SUDO_HELPER "$TOP/mkfs.btrfs" -f "$TEST_DEV" run_check_mount_test_dev -o compress=lzo,max_inline=2048 - run_check xfs_io -f -c "pwrite 0 1K" "$TEST_MNT/file" + run_check $SUDO_HELPER xfs_io -f -c "pwrite 0 1K" "$TEST_MNT/file" run_check_umount_test_dev run_check "$TOP/btrfs" check "$TEST_DEV" } -- cgit v1.2.3 From 839de9c033f3f6ecda2f61fcbcd1dfafc0e68125 Mon Sep 17 00:00:00 2001 From: David Sterba Date: Wed, 1 Mar 2017 17:16:46 +0100 Subject: btrfs-progs: tests: use dd in 025-file-extents for creating files Drop the dependency on xfs_io as it's not a standard tool, though it provides convenience. We use a simple write here so dd can manage. Signed-off-by: David Sterba --- tests/fsck-tests/025-file-extents/test.sh | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) (limited to 'tests') diff --git a/tests/fsck-tests/025-file-extents/test.sh b/tests/fsck-tests/025-file-extents/test.sh index 37173ebd..290464e0 100755 --- a/tests/fsck-tests/025-file-extents/test.sh +++ b/tests/fsck-tests/025-file-extents/test.sh @@ -5,7 +5,7 @@ source $TOP/tests/common check_prereq btrfs check_prereq mkfs.btrfs -check_global_prereq xfs_io +check_global_prereq dd check_global_prereq fallocate setup_root_helper @@ -20,7 +20,7 @@ test_paritical_write_into_prealloc() run_check $SUDO_HELPER fallocate -l 128K "$TEST_MNT/file" sync - run_check $SUDO_HELPER xfs_io -c "pwrite 0 64K" "$TEST_MNT/file" + run_check $SUDO_HELPER dd conv=notrunc if=/dev/zero of="$TEST_MNT/file" bs=1K count=64 run_check_umount_test_dev run_check "$TOP/btrfs" check "$TEST_DEV" } @@ -33,7 +33,7 @@ test_compressed_inline_extent() run_check $SUDO_HELPER "$TOP/mkfs.btrfs" -f "$TEST_DEV" run_check_mount_test_dev -o compress=lzo,max_inline=2048 - run_check $SUDO_HELPER xfs_io -f -c "pwrite 0 1K" "$TEST_MNT/file" + run_check $SUDO_HELPER dd conv=notrunc if=/dev/null of="$TEST_MNT/file" bs=1K count=1 run_check_umount_test_dev run_check "$TOP/btrfs" check "$TEST_DEV" } -- cgit v1.2.3 From 8eaf63bc9a7b957c566be23df7c6701a9a5b22a2 Mon Sep 17 00:00:00 2001 From: Benedikt Morbach Date: Thu, 23 Feb 2017 00:07:35 +0100 Subject: btrfs-progs: tests: correctly receive clones to mounted subvol clone needs to resolve the paths of the involved subvolumes in the target fs from their UUIDs. When doing so it might need to strip the prefix that is mounted as the root of the fs from those paths. It didn't do so correctly when processing the source of "clone" commands This is a regression test for btrfs-progs: receive: handle root subvol path in clone Signed-off-by: Benedikt Morbach [ copied the fstests version, will be updated later ] Signed-off-by: David Sterba --- .../019-receive-clones-on-munted-subvol/test.sh | 179 +++++++++++++++++++++ 1 file changed, 179 insertions(+) create mode 100755 tests/misc-tests/019-receive-clones-on-munted-subvol/test.sh (limited to 'tests') diff --git a/tests/misc-tests/019-receive-clones-on-munted-subvol/test.sh b/tests/misc-tests/019-receive-clones-on-munted-subvol/test.sh new file mode 100755 index 00000000..b32a59a2 --- /dev/null +++ b/tests/misc-tests/019-receive-clones-on-munted-subvol/test.sh @@ -0,0 +1,179 @@ +#! /bin/bash +# +# Test that an incremental send operation works when in both snapshots there are +# two directory inodes that have the same number but different generations and +# have an entry with the same name that corresponds to different inodes in each +# snapshot. + +# temporary, until the test gets adapted +exit 0 + +seq=`basename $0` +seqres=$RESULT_DIR/$seq +echo "QA output created by $seq" + +tmp=/tmp/$$ +status=1 # failure is the default! +trap "_cleanup; exit \$status" 0 1 2 3 15 + +_cleanup() +{ + cd / + rm -fr $send_files_dir + rm -f $tmp.* +} + +# get standard environment, filters and checks +. ./common/rc +. ./common/filter + +# real QA test starts here +_supported_fs btrfs +_supported_os Linux +_require_test +_require_scratch +_require_cloner +_require_fssum + +send_files_dir=$TEST_DIR/btrfs-test-$seq + +rm -f $seqres.full +rm -fr $send_files_dir +mkdir $send_files_dir + +_scratch_mkfs >>$seqres.full 2>&1 +_scratch_mount + +BLOCK_SIZE=$(_get_block_size $SCRATCH_MNT) + +# create source fs + +$BTRFS_UTIL_PROG subvolume create $SCRATCH_MNT/foo | _filter_scratch +$BTRFS_UTIL_PROG subvolume create $SCRATCH_MNT/bar | _filter_scratch +$BTRFS_UTIL_PROG subvolume create $SCRATCH_MNT/baz | _filter_scratch +$BTRFS_UTIL_PROG subvolume create $SCRATCH_MNT/snap | _filter_scratch + +$XFS_IO_PROG -s -f -c "pwrite -S 0xaa -b $((32 * $BLOCK_SIZE)) 0 $((32 * $BLOCK_SIZE))" \ + $SCRATCH_MNT/foo/file_a | _filter_xfs_io_blocks_modified +$XFS_IO_PROG -s -f -c "pwrite -S 0xbb -b $((32 * $BLOCK_SIZE)) 0 $((32 * $BLOCK_SIZE))" \ + $SCRATCH_MNT/bar/file_b | _filter_xfs_io_blocks_modified + +$CLONER_PROG $SCRATCH_MNT/{foo/file_a,baz/file_a} +$CLONER_PROG $SCRATCH_MNT/{bar/file_b,baz/file_b} + +# Filesystem looks like: +# +# . +# |--- foo/ +# | |--- file_a +# |--- bar/ +# | |--- file_b +# |--- baz/ +# | |--- file_a (clone of "foo/file_a") +# | |--- file_b (clone of "bar/file_b") +# |--- snap/ +# + +# create snapshots and send streams + +$BTRFS_UTIL_PROG subvolume snapshot -r $SCRATCH_MNT/foo \ + $SCRATCH_MNT/snap/foo.0 > /dev/null + +$BTRFS_UTIL_PROG send $SCRATCH_MNT/snap/foo.0 \ + -f $send_files_dir/foo.0.snap \ + 2>&1 1>/dev/null | _filter_scratch + +$BTRFS_UTIL_PROG subvolume snapshot -r \ + $SCRATCH_MNT/bar $SCRATCH_MNT/snap/bar.0 \ + > /dev/null + +$BTRFS_UTIL_PROG send $SCRATCH_MNT/snap/bar.0 \ + -f $send_files_dir/bar.0.snap \ + 2>&1 1>/dev/null | _filter_scratch + +$CLONER_PROG $SCRATCH_MNT/foo/file_a{,.clone} +rm $SCRATCH_MNT/foo/file_a + +$BTRFS_UTIL_PROG subvolume snapshot -r \ + $SCRATCH_MNT/foo $SCRATCH_MNT/snap/foo.1 \ + > /dev/null + +$BTRFS_UTIL_PROG send \ + -p $SCRATCH_MNT/snap/foo.0 \ + -f $send_files_dir/foo.1.snap \ + $SCRATCH_MNT/snap/foo.1 \ + 2>&1 1>/dev/null | _filter_scratch + +$BTRFS_UTIL_PROG subvolume snapshot -r \ + $SCRATCH_MNT/baz $SCRATCH_MNT/snap/baz.0 \ + > /dev/null + +$BTRFS_UTIL_PROG send \ + -p $SCRATCH_MNT/snap/foo.1 \ + -c $SCRATCH_MNT/snap/bar.0 \ + -f $send_files_dir/baz.0.snap \ + $SCRATCH_MNT/snap/baz.0 \ + 2>&1 1>/dev/null | _filter_scratch + +# Filesystem looks like: +# +# . +# |--- foo/ +# | |--- file_a.clone (clone of "foo/file_a") +# |--- bar/ +# | |--- file_b +# |--- baz/ +# | |--- file_a (clone of "foo/file_a") +# | |--- file_b (clone of "bar/file_b") +# |--- snap/ +# |--- bar.0/ (snapshot of "bar") +# | |--- file_b +# |--- foo.0/ (snapshot of "foo") +# | |--- file_a +# |--- foo.1/ (snapshot of "foo") +# | |--- file_a.clone +# |--- baz.0/ (snapshot of "baz") +# | |--- file_a +# | |--- file_b + +run_check $FSSUM_PROG -A -f -w $send_files_dir/foo.0.fssum $SCRATCH_MNT/snap/foo.0 +run_check $FSSUM_PROG -A -f -w $send_files_dir/foo.1.fssum $SCRATCH_MNT/snap/foo.1 +run_check $FSSUM_PROG -A -f -w $send_files_dir/bar.0.fssum $SCRATCH_MNT/snap/bar.0 +run_check $FSSUM_PROG -A -f -w $send_files_dir/baz.0.fssum $SCRATCH_MNT/snap/baz.0 + +_scratch_unmount +_scratch_mkfs >>$seqres.full 2>&1 +_scratch_mount +$BTRFS_UTIL_PROG subvolume create $SCRATCH_MNT/dest | _filter_scratch +_scratch_unmount +_scratch_mount -o subvol=/dest + +$BTRFS_UTIL_PROG receive \ + -f $send_files_dir/foo.0.snap \ + $SCRATCH_MNT \ + 2>&1 | _filter_scratch +$BTRFS_UTIL_PROG receive \ + -f $send_files_dir/bar.0.snap \ + $SCRATCH_MNT \ + 2>&1 | _filter_scratch + +# if "dest/" is not correctly stripped from the beginning of the path to "foo.0" in the target fs, +# we would get an error here because the clone source "foo.0/file_a" for "foo.1/file_a.clone" can't be found. +$BTRFS_UTIL_PROG receive \ + -f $send_files_dir/foo.1.snap \ + $SCRATCH_MNT \ + 2>&1 | _filter_scratch + +# same here, but with send -c instead of -p +$BTRFS_UTIL_PROG receive \ + -f $send_files_dir/baz.0.snap \ + $SCRATCH_MNT \ + 2>&1 | _filter_scratch + +run_check $FSSUM_PROG -r $send_files_dir/foo.0.fssum $SCRATCH_MNT/foo.0 +run_check $FSSUM_PROG -r $send_files_dir/foo.1.fssum $SCRATCH_MNT/foo.1 +run_check $FSSUM_PROG -r $send_files_dir/bar.0.fssum $SCRATCH_MNT/bar.0 +run_check $FSSUM_PROG -r $send_files_dir/baz.0.fssum $SCRATCH_MNT/baz.0 + +status=0 +exit -- cgit v1.2.3 From 21e8582d32cfbbfd54ab550b4c9d31ff479931ad Mon Sep 17 00:00:00 2001 From: David Sterba Date: Wed, 8 Mar 2017 15:51:57 +0100 Subject: btrfs-progs: tests: port 019-receive-clones-on-munted-subvol Port from fstests. Signed-off-by: David Sterba --- .../019-receive-clones-on-munted-subvol/test.sh | 183 ++++++++------------- 1 file changed, 65 insertions(+), 118 deletions(-) (limited to 'tests') diff --git a/tests/misc-tests/019-receive-clones-on-munted-subvol/test.sh b/tests/misc-tests/019-receive-clones-on-munted-subvol/test.sh index b32a59a2..5735ecb0 100755 --- a/tests/misc-tests/019-receive-clones-on-munted-subvol/test.sh +++ b/tests/misc-tests/019-receive-clones-on-munted-subvol/test.sh @@ -6,60 +6,38 @@ # snapshot. # temporary, until the test gets adapted -exit 0 +FSSUM_PROG=/bin/true -seq=`basename $0` -seqres=$RESULT_DIR/$seq -echo "QA output created by $seq" +source $TOP/tests/common -tmp=/tmp/$$ -status=1 # failure is the default! -trap "_cleanup; exit \$status" 0 1 2 3 15 +check_prereq mkfs.btrfs +check_prereq btrfs -_cleanup() -{ - cd / - rm -fr $send_files_dir - rm -f $tmp.* -} +setup_root_helper +prepare_test_dev -# get standard environment, filters and checks -. ./common/rc -. ./common/filter +srcdir=./send-test-dir +rm -rf "$srcdir" +mkdir -p "$srcdir" +run_check chmod a+rw "$srcdir" -# real QA test starts here -_supported_fs btrfs -_supported_os Linux -_require_test -_require_scratch -_require_cloner -_require_fssum +run_check "$TOP/mkfs.btrfs" -f "$TEST_DEV" +run_check_mount_test_dev -send_files_dir=$TEST_DIR/btrfs-test-$seq +BLOCK_SIZE=$(stat -f -c %S "$TEST_MNT") -rm -f $seqres.full -rm -fr $send_files_dir -mkdir $send_files_dir +run_check $SUDO_HELPER "$TOP/btrfs" subvolume create "$TEST_MNT/foo" +run_check $SUDO_HELPER "$TOP/btrfs" subvolume create "$TEST_MNT/bar" +run_check $SUDO_HELPER "$TOP/btrfs" subvolume create "$TEST_MNT/baz" +run_check $SUDO_HELPER "$TOP/btrfs" subvolume create "$TEST_MNT/snap" -_scratch_mkfs >>$seqres.full 2>&1 -_scratch_mount +tr '\000' 'A' < /dev/null | + run_check $SUDO_HELPER dd of=$TEST_MNT/foo/file_a bs=$BLOCK_SIZE count=32 +tr '\000' 'B' < /dev/null | + run_check $SUDO_HELPER dd of=$TEST_MNT/bar/file_b bs=$BLOCK_SIZE count=32 -BLOCK_SIZE=$(_get_block_size $SCRATCH_MNT) - -# create source fs - -$BTRFS_UTIL_PROG subvolume create $SCRATCH_MNT/foo | _filter_scratch -$BTRFS_UTIL_PROG subvolume create $SCRATCH_MNT/bar | _filter_scratch -$BTRFS_UTIL_PROG subvolume create $SCRATCH_MNT/baz | _filter_scratch -$BTRFS_UTIL_PROG subvolume create $SCRATCH_MNT/snap | _filter_scratch - -$XFS_IO_PROG -s -f -c "pwrite -S 0xaa -b $((32 * $BLOCK_SIZE)) 0 $((32 * $BLOCK_SIZE))" \ - $SCRATCH_MNT/foo/file_a | _filter_xfs_io_blocks_modified -$XFS_IO_PROG -s -f -c "pwrite -S 0xbb -b $((32 * $BLOCK_SIZE)) 0 $((32 * $BLOCK_SIZE))" \ - $SCRATCH_MNT/bar/file_b | _filter_xfs_io_blocks_modified - -$CLONER_PROG $SCRATCH_MNT/{foo/file_a,baz/file_a} -$CLONER_PROG $SCRATCH_MNT/{bar/file_b,baz/file_b} +run_check $SUDO_HELPER cp --reflink=always "$TEST_MNT/foo/file_a" "$TEST_MNT/baz/file_a" +run_check $SUDO_HELPER cp --reflink=always "$TEST_MNT/bar/file_b" "$TEST_MNT/baz/file_b" # Filesystem looks like: # @@ -76,44 +54,25 @@ $CLONER_PROG $SCRATCH_MNT/{bar/file_b,baz/file_b} # create snapshots and send streams -$BTRFS_UTIL_PROG subvolume snapshot -r $SCRATCH_MNT/foo \ - $SCRATCH_MNT/snap/foo.0 > /dev/null - -$BTRFS_UTIL_PROG send $SCRATCH_MNT/snap/foo.0 \ - -f $send_files_dir/foo.0.snap \ - 2>&1 1>/dev/null | _filter_scratch - -$BTRFS_UTIL_PROG subvolume snapshot -r \ - $SCRATCH_MNT/bar $SCRATCH_MNT/snap/bar.0 \ - > /dev/null - -$BTRFS_UTIL_PROG send $SCRATCH_MNT/snap/bar.0 \ - -f $send_files_dir/bar.0.snap \ - 2>&1 1>/dev/null | _filter_scratch +run_check $SUDO_HELPER "$TOP/btrfs" subvolume snapshot -r "$TEST_MNT/foo" "$TEST_MNT/snap/foo.0" +run_check $SUDO_HELPER "$TOP/btrfs" send -f "$srcdir/foo.0.snap" "$TEST_MNT/snap/foo.0" -$CLONER_PROG $SCRATCH_MNT/foo/file_a{,.clone} -rm $SCRATCH_MNT/foo/file_a +run_check $SUDO_HELPER "$TOP/btrfs" subvolume snapshot -r "$TEST_MNT/bar" "$TEST_MNT/snap/bar.0" +run_check $SUDO_HELPER "$TOP/btrfs" send -f "$srcdir/bar.0.snap" "$TEST_MNT/snap/bar.0" -$BTRFS_UTIL_PROG subvolume snapshot -r \ - $SCRATCH_MNT/foo $SCRATCH_MNT/snap/foo.1 \ - > /dev/null +run_check $SUDO_HELPER cp --reflink=always "$TEST_MNT/foo/file_a" "$TEST_MNT/foo/file_a.clone" +run_check $SUDO_HELPER rm -f -- "$TEST_MNT/foo/file_a" -$BTRFS_UTIL_PROG send \ - -p $SCRATCH_MNT/snap/foo.0 \ - -f $send_files_dir/foo.1.snap \ - $SCRATCH_MNT/snap/foo.1 \ - 2>&1 1>/dev/null | _filter_scratch +run_check $SUDO_HELPER "$TOP/btrfs" subvolume snapshot -r "$TEST_MNT/foo" \ + "$TEST_MNT/snap/foo.1" +run_check $SUDO_HELPER "$TOP/btrfs" send -p "$TEST_MNT/snap/foo.0" -f "$srcdir/foo.1.snap" \ + "$TEST_MNT/snap/foo.1" -$BTRFS_UTIL_PROG subvolume snapshot -r \ - $SCRATCH_MNT/baz $SCRATCH_MNT/snap/baz.0 \ - > /dev/null - -$BTRFS_UTIL_PROG send \ - -p $SCRATCH_MNT/snap/foo.1 \ - -c $SCRATCH_MNT/snap/bar.0 \ - -f $send_files_dir/baz.0.snap \ - $SCRATCH_MNT/snap/baz.0 \ - 2>&1 1>/dev/null | _filter_scratch +run_check $SUDO_HELPER "$TOP/btrfs" subvolume snapshot -r "$TEST_MNT/baz" \ + "$TEST_MNT/snap/baz.0" +run_check $SUDO_HELPER "$TOP/btrfs" send -p "$TEST_MNT/snap/foo.1" \ + -c "$TEST_MNT/snap/bar.0" -f "$srcdir/baz.0.snap" \ + "$TEST_MNT/snap/baz.0" # Filesystem looks like: # @@ -136,44 +95,32 @@ $BTRFS_UTIL_PROG send \ # | |--- file_a # | |--- file_b -run_check $FSSUM_PROG -A -f -w $send_files_dir/foo.0.fssum $SCRATCH_MNT/snap/foo.0 -run_check $FSSUM_PROG -A -f -w $send_files_dir/foo.1.fssum $SCRATCH_MNT/snap/foo.1 -run_check $FSSUM_PROG -A -f -w $send_files_dir/bar.0.fssum $SCRATCH_MNT/snap/bar.0 -run_check $FSSUM_PROG -A -f -w $send_files_dir/baz.0.fssum $SCRATCH_MNT/snap/baz.0 - -_scratch_unmount -_scratch_mkfs >>$seqres.full 2>&1 -_scratch_mount -$BTRFS_UTIL_PROG subvolume create $SCRATCH_MNT/dest | _filter_scratch -_scratch_unmount -_scratch_mount -o subvol=/dest - -$BTRFS_UTIL_PROG receive \ - -f $send_files_dir/foo.0.snap \ - $SCRATCH_MNT \ - 2>&1 | _filter_scratch -$BTRFS_UTIL_PROG receive \ - -f $send_files_dir/bar.0.snap \ - $SCRATCH_MNT \ - 2>&1 | _filter_scratch - -# if "dest/" is not correctly stripped from the beginning of the path to "foo.0" in the target fs, -# we would get an error here because the clone source "foo.0/file_a" for "foo.1/file_a.clone" can't be found. -$BTRFS_UTIL_PROG receive \ - -f $send_files_dir/foo.1.snap \ - $SCRATCH_MNT \ - 2>&1 | _filter_scratch +run_check $FSSUM_PROG -A -f -w "$srcdir/foo.0.fssum" "$TEST_MNT/snap/foo.0" +run_check $FSSUM_PROG -A -f -w "$srcdir/foo.1.fssum" "$TEST_MNT/snap/foo.1" +run_check $FSSUM_PROG -A -f -w "$srcdir/bar.0.fssum" "$TEST_MNT/snap/bar.0" +run_check $FSSUM_PROG -A -f -w "$srcdir/baz.0.fssum" "$TEST_MNT/snap/baz.0" + +run_check_umount_test_dev +run_check "$TOP/mkfs.btrfs" -f "$TEST_DEV" +run_check_mount_test_dev +run_check $SUDO_HELPER "$TOP/btrfs" subvolume create "$TEST_MNT/dest" +run_check_umount_test_dev +run_check_mount_test_dev -o subvol=/dest + +run_check $SUDO_HELPER "$TOP/btrfs" receive -f "$srcdir/foo.0.snap" "$TEST_MNT" +run_check $SUDO_HELPER "$TOP/btrfs" receive -f "$srcdir/bar.0.snap" "$TEST_MNT" + +# if "dest/" is not correctly stripped from the beginning of the path to +# "foo.0" in the target fs, we would get an error here because the clone source +# "foo.0/file_a" for "foo.1/file_a.clone" can't be found. +run_check $SUDO_HELPER "$TOP/btrfs" receive -f "$srcdir/foo.1.snap" "$TEST_MNT" # same here, but with send -c instead of -p -$BTRFS_UTIL_PROG receive \ - -f $send_files_dir/baz.0.snap \ - $SCRATCH_MNT \ - 2>&1 | _filter_scratch - -run_check $FSSUM_PROG -r $send_files_dir/foo.0.fssum $SCRATCH_MNT/foo.0 -run_check $FSSUM_PROG -r $send_files_dir/foo.1.fssum $SCRATCH_MNT/foo.1 -run_check $FSSUM_PROG -r $send_files_dir/bar.0.fssum $SCRATCH_MNT/bar.0 -run_check $FSSUM_PROG -r $send_files_dir/baz.0.fssum $SCRATCH_MNT/baz.0 - -status=0 -exit +run_check $SUDO_HELPER "$TOP/btrfs" receive -f "$srcdir/baz.0.snap" "$TEST_MNT" + +run_check $FSSUM_PROG -r "$srcdir/foo.0.fssum" "$TEST_MNT/foo.0" +run_check $FSSUM_PROG -r "$srcdir/foo.1.fssum" "$TEST_MNT/foo.1" +run_check $FSSUM_PROG -r "$srcdir/bar.0.fssum" "$TEST_MNT/bar.0" +run_check $FSSUM_PROG -r "$srcdir/baz.0.fssum" "$TEST_MNT/baz.0" + +rm -rf -- "$srcdir" -- cgit v1.2.3 From ea3d522cc633aa2cfe5675d34674f1c779f84cfb Mon Sep 17 00:00:00 2001 From: David Sterba Date: Mon, 13 Mar 2017 17:15:24 +0100 Subject: btrfs-progs: tests: do test build of library-test.static Signed-off-by: David Sterba --- tests/build-tests.sh | 3 +++ 1 file changed, 3 insertions(+) (limited to 'tests') diff --git a/tests/build-tests.sh b/tests/build-tests.sh index 04e3fd19..4dc8744e 100755 --- a/tests/build-tests.sh +++ b/tests/build-tests.sh @@ -63,6 +63,9 @@ function build_make_targets() { # defaults, library target="library-test" buildme + # defaults, static library + target="library-test.static" + buildme } # main() -- cgit v1.2.3 From 3727d89b41c9901871605bf1d772e866656e1d19 Mon Sep 17 00:00:00 2001 From: David Sterba Date: Mon, 13 Mar 2017 17:43:05 +0100 Subject: btrfs-progs: docs: add preliminary do's & dont's for tests Signed-off-by: David Sterba --- tests/README.md | 34 ++++++++++++++++++++++++++++++++++ 1 file changed, 34 insertions(+) (limited to 'tests') diff --git a/tests/README.md b/tests/README.md index bb2846a1..a8d3a2ba 100644 --- a/tests/README.md +++ b/tests/README.md @@ -182,3 +182,37 @@ description of the problem or the stack trace. If you have a fix for the problem, please submit it prior to the test image, so the fuzz tests always succeed when run on random checked out. This helps bisectability. + + +# Coding style, best practices + +## do + +* quote all variables by default, any path, even the TOP could need that, and + we use it everywhere + * there are exceptions: + * `$SUDO_HELPER` as it might be intentionally unset + * the variable is obviously set to a value that does not require it +* use `#!/bin/bash` explicitly +* check for all external dependencies (`check_prereq_global`) +* check for internal dependencies (`check_prereq`), though the basic set is + always built when the tests are started through make +* use functions instead of repeating code + * generic helpers could be factored to the `common` script +* cleanup after successful test +* use common helpers and variables + +## do not + +* pull external dependencies if we can find a way to replace them: example is + `xfs_io` that's conveniently used in fstests but we'd require `xfsprogs`, + so use `dd` instead +* throw away (redirect to */dev/null*) output of commands unless it's justified + (ie. really too much text, unnecessary slowdown) -- the test output log is + regenerated all the time and we need to be able to analyze test failures or + just observe how the tests progress +* cleanup after failed test -- the testsuite stops on first failure and the + developer can eg. access the environment that the test created and do further + debugging + * this might change in the future so the tests cover as much as possible, but + this would require to enhance all tests with a cleanup phase -- cgit v1.2.3 From b7eb8f7650c6707dc3a45835955db4a770d90b68 Mon Sep 17 00:00:00 2001 From: David Sterba Date: Mon, 13 Mar 2017 17:48:55 +0100 Subject: btrfs-progs: tests: use TEST_DEV in cli-tests IMAGE points to the fallback image, tests should use TEST_DEV. Signed-off-by: David Sterba --- tests/cli-tests/002-balance-full-no-filters/test.sh | 2 +- tests/cli-tests/003-fi-resize-args/test.sh | 2 +- tests/cli-tests/004-send-parent-multi-subvol/test.sh | 2 +- tests/cli-tests/005-qgroup-show/test.sh | 2 +- tests/cli-tests/006-qgroup-show-sync/test.sh | 2 +- 5 files changed, 5 insertions(+), 5 deletions(-) (limited to 'tests') diff --git a/tests/cli-tests/002-balance-full-no-filters/test.sh b/tests/cli-tests/002-balance-full-no-filters/test.sh index 81a719eb..0501aad2 100755 --- a/tests/cli-tests/002-balance-full-no-filters/test.sh +++ b/tests/cli-tests/002-balance-full-no-filters/test.sh @@ -10,7 +10,7 @@ check_prereq btrfs setup_root_helper prepare_test_dev 2g -run_check "$TOP/mkfs.btrfs" -f "$IMAGE" +run_check "$TOP/mkfs.btrfs" -f "$TEST_DEV" run_check_mount_test_dev run_check $SUDO_HELPER "$TOP/btrfs" balance start --full-balance "$TEST_MNT" diff --git a/tests/cli-tests/003-fi-resize-args/test.sh b/tests/cli-tests/003-fi-resize-args/test.sh index b835e078..e4f262b6 100755 --- a/tests/cli-tests/003-fi-resize-args/test.sh +++ b/tests/cli-tests/003-fi-resize-args/test.sh @@ -10,7 +10,7 @@ check_prereq btrfs setup_root_helper prepare_test_dev 2g -run_check "$TOP/mkfs.btrfs" -f "$IMAGE" +run_check "$TOP/mkfs.btrfs" -f "$TEST_DEV" run_check_mount_test_dev # missing the one of the required arguments diff --git a/tests/cli-tests/004-send-parent-multi-subvol/test.sh b/tests/cli-tests/004-send-parent-multi-subvol/test.sh index 72a9eb36..49226f9b 100755 --- a/tests/cli-tests/004-send-parent-multi-subvol/test.sh +++ b/tests/cli-tests/004-send-parent-multi-subvol/test.sh @@ -10,7 +10,7 @@ check_prereq btrfs setup_root_helper prepare_test_dev 2g -run_check "$TOP/mkfs.btrfs" -f "$IMAGE" +run_check "$TOP/mkfs.btrfs" -f "$TEST_DEV" run_check_mount_test_dev here=`pwd` diff --git a/tests/cli-tests/005-qgroup-show/test.sh b/tests/cli-tests/005-qgroup-show/test.sh index 46d3c3a7..2af13033 100755 --- a/tests/cli-tests/005-qgroup-show/test.sh +++ b/tests/cli-tests/005-qgroup-show/test.sh @@ -10,7 +10,7 @@ check_prereq btrfs setup_root_helper prepare_test_dev 2g -run_check "$TOP/mkfs.btrfs" -f "$IMAGE" +run_check "$TOP/mkfs.btrfs" -f "$TEST_DEV" run_check_mount_test_dev run_mayfail "$TOP/btrfs" qgroup show "$TEST_MNT" run_mayfail $SUDO_HELPER "$TOP/btrfs" qgroup show "$TEST_MNT" diff --git a/tests/cli-tests/006-qgroup-show-sync/test.sh b/tests/cli-tests/006-qgroup-show-sync/test.sh index 30d0a9a1..d552b8b9 100755 --- a/tests/cli-tests/006-qgroup-show-sync/test.sh +++ b/tests/cli-tests/006-qgroup-show-sync/test.sh @@ -10,7 +10,7 @@ check_prereq btrfs setup_root_helper prepare_test_dev 1g -run_check "$TOP/mkfs.btrfs" -f "$IMAGE" +run_check "$TOP/mkfs.btrfs" -f "$TEST_DEV" run_check_mount_test_dev run_check $SUDO_HELPER "$TOP/btrfs" subvolume create "$TEST_MNT/Sub" -- cgit v1.2.3 From d4eb5a77d7a29419f625d4ed0b4c828bb49eba57 Mon Sep 17 00:00:00 2001 From: David Sterba Date: Mon, 13 Mar 2017 17:52:20 +0100 Subject: btrfs-progs: tests: mkfs/002 and 003: use TEST_DEV instead of IMAGE As we don't know what's the TEST_DEV like, use the explicit mkfs limit. Signed-off-by: David Sterba --- tests/mkfs-tests/002-no-force-mixed-on-small-volume/test.sh | 3 +-- tests/mkfs-tests/003-mixed-with-wrong-nodesize/test.sh | 3 +-- 2 files changed, 2 insertions(+), 4 deletions(-) (limited to 'tests') diff --git a/tests/mkfs-tests/002-no-force-mixed-on-small-volume/test.sh b/tests/mkfs-tests/002-no-force-mixed-on-small-volume/test.sh index 855fbd18..37846234 100755 --- a/tests/mkfs-tests/002-no-force-mixed-on-small-volume/test.sh +++ b/tests/mkfs-tests/002-no-force-mixed-on-small-volume/test.sh @@ -8,6 +8,5 @@ check_prereq mkfs.btrfs setup_root_helper -run_check truncate -s 512M $IMAGE -mixed=$(run_check_stdout $TOP/mkfs.btrfs -n 64k -f $IMAGE | egrep 'Data|Metadata') +mixed=$(run_check_stdout "$TOP/mkfs.btrfs" -b 512M -n 64k -f "$TEST_DEV" | egrep 'Data|Metadata') echo "$mixed" | grep -q -v 'Data+Metadata:' || _fail "unexpected: created a mixed-bg filesystem" diff --git a/tests/mkfs-tests/003-mixed-with-wrong-nodesize/test.sh b/tests/mkfs-tests/003-mixed-with-wrong-nodesize/test.sh index 289d5ff0..074fc22e 100755 --- a/tests/mkfs-tests/003-mixed-with-wrong-nodesize/test.sh +++ b/tests/mkfs-tests/003-mixed-with-wrong-nodesize/test.sh @@ -6,7 +6,6 @@ source $TOP/tests/common check_prereq mkfs.btrfs -run_check truncate -s 512M $IMAGE -run_mayfail $TOP/mkfs.btrfs -f -M -s 4096 -n 16384 "$IMAGE" && _fail +run_mayfail "$TOP/mkfs.btrfs" -b 512M -f -M -s 4096 -n 16384 "$TEST_DEV" && _fail exit 0 -- cgit v1.2.3 From c2d3f549960e3a21196dc535e123b709abd55f34 Mon Sep 17 00:00:00 2001 From: David Sterba Date: Mon, 13 Mar 2017 18:07:28 +0100 Subject: btrfs-progs: tests: cleanup use of IMAGE and replace by helpers Nearly each use of IMAGE can be replaced by common helpers as there are no specific requirements on the testing filesystem. There are still a few left that need to be evaluated and converted eventually. Signed-off-by: David Sterba --- tests/misc-tests/009-subvolume-sync-must-wait/test.sh | 8 ++++---- tests/misc-tests/013-subvolume-sync-crash/test.sh | 8 ++++---- tests/misc-tests/014-filesystem-label/test.sh | 8 ++++---- tests/misc-tests/016-send-clone-src/test.sh | 4 ++-- tests/misc-tests/017-recv-stream-malformatted/test.sh | 4 ++-- 5 files changed, 16 insertions(+), 16 deletions(-) (limited to 'tests') diff --git a/tests/misc-tests/009-subvolume-sync-must-wait/test.sh b/tests/misc-tests/009-subvolume-sync-must-wait/test.sh index 92c896f9..fa3f09ab 100755 --- a/tests/misc-tests/009-subvolume-sync-must-wait/test.sh +++ b/tests/misc-tests/009-subvolume-sync-must-wait/test.sh @@ -9,9 +9,9 @@ check_prereq btrfs setup_root_helper -run_check truncate -s 2G $IMAGE -run_check $TOP/mkfs.btrfs -f $IMAGE -run_check $SUDO_HELPER mount $IMAGE $TEST_MNT +prepare_test_dev +run_check $TOP/mkfs.btrfs -f "$TEST_DEV" +run_check_mount_test_dev run_check $SUDO_HELPER chmod a+rw $TEST_MNT cd $TEST_MNT @@ -49,4 +49,4 @@ run_check $SUDO_HELPER $TOP/btrfs subvolume list -d . wait cd .. -run_check $SUDO_HELPER umount $TEST_MNT +run_check_umount_test_dev diff --git a/tests/misc-tests/013-subvolume-sync-crash/test.sh b/tests/misc-tests/013-subvolume-sync-crash/test.sh index 4cb1b4e7..cd445961 100755 --- a/tests/misc-tests/013-subvolume-sync-crash/test.sh +++ b/tests/misc-tests/013-subvolume-sync-crash/test.sh @@ -10,9 +10,9 @@ check_prereq btrfs setup_root_helper -run_check truncate -s 2G $IMAGE -run_check $TOP/mkfs.btrfs -f $IMAGE -run_check $SUDO_HELPER mount $IMAGE $TEST_MNT +prepare_test_dev +run_check "$TOP/mkfs.btrfs" -f "$TEST_DEV" +run_check_mount_test_dev run_check $SUDO_HELPER chmod a+rw $TEST_MNT cd $TEST_MNT @@ -46,4 +46,4 @@ run_check $SUDO_HELPER $TOP/btrfs subvolume list -d . wait cd .. -run_check $SUDO_HELPER umount $TEST_MNT +run_check_umount_test_dev diff --git a/tests/misc-tests/014-filesystem-label/test.sh b/tests/misc-tests/014-filesystem-label/test.sh index a5e08ccc..753aa9ea 100755 --- a/tests/misc-tests/014-filesystem-label/test.sh +++ b/tests/misc-tests/014-filesystem-label/test.sh @@ -9,9 +9,9 @@ check_prereq btrfs setup_root_helper -run_check truncate -s 2G $IMAGE -run_check $TOP/mkfs.btrfs -L BTRFS-TEST-LABEL -f $IMAGE -run_check $SUDO_HELPER mount $IMAGE $TEST_MNT +prepare_test_dev +run_check "$TOP/mkfs.btrfs" -L BTRFS-TEST-LABEL -f "$TEST_DEV" +run_check_mount_test_dev run_check $SUDO_HELPER chmod a+rw $TEST_MNT cd $TEST_MNT @@ -66,4 +66,4 @@ run_check $SUDO_HELPER $TOP/btrfs filesystem label $TEST_MNT cd .. -run_check $SUDO_HELPER umount $TEST_MNT +run_check_umount_test_dev diff --git a/tests/misc-tests/016-send-clone-src/test.sh b/tests/misc-tests/016-send-clone-src/test.sh index e256eef9..479da677 100755 --- a/tests/misc-tests/016-send-clone-src/test.sh +++ b/tests/misc-tests/016-send-clone-src/test.sh @@ -9,9 +9,9 @@ check_prereq mkfs.btrfs check_prereq btrfs setup_root_helper -prepare_test_dev 1g -run_check $TOP/mkfs.btrfs -f $IMAGE +prepare_test_dev 1g +run_check "$TOP/mkfs.btrfs" -f "$TEST_DEV" run_check_mount_test_dev here=`pwd` diff --git a/tests/misc-tests/017-recv-stream-malformatted/test.sh b/tests/misc-tests/017-recv-stream-malformatted/test.sh index 884b7d42..3756be27 100755 --- a/tests/misc-tests/017-recv-stream-malformatted/test.sh +++ b/tests/misc-tests/017-recv-stream-malformatted/test.sh @@ -8,9 +8,9 @@ check_prereq mkfs.btrfs check_prereq btrfs setup_root_helper -prepare_test_dev 1g -run_check $TOP/mkfs.btrfs -f $IMAGE +prepare_test_dev 1g +run_check "$TOP/mkfs.btrfs" -f "$TEST_DEV" run_check_mount_test_dev echo -n '' | run_mayfail $SUDO_HELPER "$TOP/btrfs" receive "$TEST_MNT" && -- cgit v1.2.3 From 9a98589f00f8e8def668f9e3f76a0d44e525cff7 Mon Sep 17 00:00:00 2001 From: David Sterba Date: Tue, 14 Mar 2017 18:53:29 +0100 Subject: btrfs-progs: tests: add fssum utility Copy from fstests, originally from git://git.kernel.org/pub/scm/linux/kernel/git/arne/far-progs.git Needs libcrypto to link but this check is now missing in configure. Signed-off-by: Jan Schmidt Signed-off-by: David Sterba --- tests/fssum.c | 830 ++++++++++++++++++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 830 insertions(+) create mode 100644 tests/fssum.c (limited to 'tests') diff --git a/tests/fssum.c b/tests/fssum.c new file mode 100644 index 00000000..c26d32b9 --- /dev/null +++ b/tests/fssum.c @@ -0,0 +1,830 @@ +/* + * Copyright (C) 2012 STRATO AG. All rights reserved. + * + * This program is free software; you can redistribute it and/or + * modify it under the terms of the GNU General Public + * License v2 as published by the Free Software Foundation. + * + * This program is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU + * General Public License for more details. + * + * You should have received a copy of the GNU General Public + * License along with this program; if not, write to the + * Free Software Foundation, Inc., 59 Temple Place - Suite 330, + * Boston, MA 021110-1307, USA. + */ +#ifdef __LINUX__ +#define _BSD_SOURCE +#define _LARGEFILE64_SOURCE +#ifndef _GNU_SOURCE +#define _GNU_SOURCE +#endif +#endif +#include +#include +#include +#include +#include +#include +#include +#include +#include +#ifdef __SOLARIS__ +#include +#endif +#include +#include +#include +#include + +#define CS_SIZE 16 +#define CHUNKS 128 + +#ifdef __LINUX__ +#ifndef SEEK_DATA +#define SEEK_DATA 3 +#define SEEK_HOLE 4 +#endif + +#if __BYTE_ORDER == __LITTLE_ENDIAN +#define htonll(x) __bswap_64 (x) +#else +#define htonll(x) (x) +#endif +#endif + +/* TODO: add hardlink recognition */ +/* TODO: add xattr/acl */ + +struct excludes { + char *path; + int len; +}; + +typedef struct _sum { + MD5_CTX md5; + unsigned char out[16]; +} sum_t; + +typedef int (*sum_file_data_t)(int fd, sum_t *dst); + +int gen_manifest = 0; +int in_manifest = 0; +char *checksum = NULL; +struct excludes *excludes; +int n_excludes = 0; +int verbose = 0; +FILE *out_fp; +FILE *in_fp; + +enum _flags { + FLAG_UID, + FLAG_GID, + FLAG_MODE, + FLAG_ATIME, + FLAG_MTIME, + FLAG_CTIME, + FLAG_DATA, + FLAG_OPEN_ERROR, + FLAG_STRUCTURE, + NUM_FLAGS +}; + +const char flchar[] = "ugoamcdes"; +char line[65536]; + +int flags[NUM_FLAGS] = {1, 1, 1, 1, 1, 0, 1, 0, 0}; + +char * +getln(char *buf, int size, FILE *fp) +{ + char *p; + int l; + + p = fgets(buf, size, fp); + if (!p) + return NULL; + + l = strlen(p); + while(l > 0 && (p[l - 1] == '\n' || p[l - 1] == '\r')) + p[--l] = 0; + + return p; +} + +void +parse_flag(int c) +{ + int i; + int is_upper = 0; + + if (c >= 'A' && c <= 'Z') { + is_upper = 1; + c += 'a' - 'A'; + } + for (i = 0; flchar[i]; ++i) { + if (flchar[i] == c) { + flags[i] = is_upper ? 0 : 1; + return; + } + } + fprintf(stderr, "unrecognized flag %c\n", c); + exit(-1); +} + +void +parse_flags(char *p) +{ + while (*p) + parse_flag(*p++); +} + +void +usage(void) +{ + fprintf(stderr, "usage: fssum \n"); + fprintf(stderr, " options:\n"); + fprintf(stderr, " -f : write out a full manifest file\n"); + fprintf(stderr, " -w : send output to file\n"); + fprintf(stderr, " -v : verbose mode (debugging only)\n"); + fprintf(stderr, + " -r : read checksum or manifest from file\n"); + fprintf(stderr, " -[ugoamcde] : specify which fields to include in checksum calculation.\n"); + fprintf(stderr, " u : include uid\n"); + fprintf(stderr, " g : include gid\n"); + fprintf(stderr, " o : include mode\n"); + fprintf(stderr, " m : include mtime\n"); + fprintf(stderr, " a : include atime\n"); + fprintf(stderr, " c : include ctime\n"); + fprintf(stderr, " d : include file data\n"); + fprintf(stderr, " e : include open errors (aborts otherwise)\n"); + fprintf(stderr, " s : include block structure (holes)\n"); + fprintf(stderr, " -[UGOAMCDES]: exclude respective field from calculation\n"); + fprintf(stderr, " -n : reset all flags\n"); + fprintf(stderr, " -N : set all flags\n"); + fprintf(stderr, " -x path : exclude path when building checksum (multiple ok)\n"); + fprintf(stderr, " -h : this help\n\n"); + fprintf(stderr, "The default field mask is ugoamCdES. If the checksum/manifest is read from a\n"); + fprintf(stderr, "file, the mask is taken from there and the values given on the command line\n"); + fprintf(stderr, "are ignored.\n"); + exit(-1); +} + +static char buf[65536]; + +void * +alloc(size_t sz) +{ + void *p = malloc(sz); + + if (!p) { + fprintf(stderr, "malloc failed\n"); + exit(-1); + } + + return p; +} + +void +sum_init(sum_t *cs) +{ + MD5_Init(&cs->md5); +} + +void +sum_fini(sum_t *cs) +{ + MD5_Final(cs->out, &cs->md5); +} + +void +sum_add(sum_t *cs, void *buf, int size) +{ + MD5_Update(&cs->md5, buf, size); +} + +void +sum_add_sum(sum_t *dst, sum_t *src) +{ + sum_add(dst, src->out, sizeof(src->out)); +} + +void +sum_add_u64(sum_t *dst, uint64_t val) +{ + uint64_t v = htonll(val); + sum_add(dst, &v, sizeof(v)); +} + +void +sum_add_time(sum_t *dst, time_t t) +{ + sum_add_u64(dst, t); +} + +char * +sum_to_string(sum_t *dst) +{ + int i; + char *s = alloc(CS_SIZE * 2 + 1); + + for (i = 0; i < CS_SIZE; ++i) + sprintf(s + i * 2, "%02x", dst->out[i]); + + return s; +} + +int +sum_file_data_permissive(int fd, sum_t *dst) +{ + int ret; + off_t pos; + off_t old; + int i; + uint64_t zeros = 0; + + pos = lseek(fd, 0, SEEK_CUR); + if (pos == (off_t)-1) + return errno == ENXIO ? 0 : -2; + + while (1) { + old = pos; + pos = lseek(fd, pos, SEEK_DATA); + if (pos == (off_t)-1) { + if (errno == ENXIO) { + ret = 0; + pos = lseek(fd, 0, SEEK_END); + if (pos != (off_t)-1) + zeros += pos - old; + } else { + ret = -2; + } + break; + } + ret = read(fd, buf, sizeof(buf)); + assert(ret); /* eof found by lseek */ + if (ret <= 0) + break; + if (old < pos) /* hole */ + zeros += pos - old; + for (i = 0; i < ret; ++i) { + for (old = i; buf[i] == 0 && i < ret; ++i) + ; + if (old < i) /* code like a hole */ + zeros += i - old; + if (i == ret) + break; + if (zeros) { + if (verbose >= 2) + fprintf(stderr, + "adding %llu zeros to sum\n", + (unsigned long long)zeros); + sum_add_u64(dst, 0); + sum_add_u64(dst, zeros); + zeros = 0; + } + for (old = i; buf[i] != 0 && i < ret; ++i) + ; + if (verbose >= 2) + fprintf(stderr, "adding %u non-zeros to sum\n", + i - (int)old); + sum_add(dst, buf + old, i - old); + } + pos += ret; + } + + if (zeros) { + if (verbose >= 2) + fprintf(stderr, + "adding %llu zeros to sum (finishing)\n", + (unsigned long long)zeros); + sum_add_u64(dst, 0); + sum_add_u64(dst, zeros); + } + + return ret; +} + +int +sum_file_data_strict(int fd, sum_t *dst) +{ + int ret; + off_t pos; + + pos = lseek(fd, 0, SEEK_CUR); + if (pos == (off_t)-1) + return errno == ENXIO ? 0 : -2; + + while (1) { + pos = lseek(fd, pos, SEEK_DATA); + if (pos == (off_t)-1) + return errno == ENXIO ? 0 : -2; + ret = read(fd, buf, sizeof(buf)); + assert(ret); /* eof found by lseek */ + if (ret <= 0) + return ret; + if (verbose >= 2) + fprintf(stderr, + "adding to sum at file offset %llu, %d bytes\n", + (unsigned long long)pos, ret); + sum_add_u64(dst, (uint64_t)pos); + sum_add(dst, buf, ret); + pos += ret; + } +} + +char * +escape(char *in) +{ + char *out = alloc(strlen(in) * 3 + 1); + char *src = in; + char *dst = out; + + for (; *src; ++src) { + if (*src >= 32 && *src < 127 && *src != '\\') { + *dst++ = *src; + } else { + sprintf(dst, "\\%02x", (unsigned char)*src); + dst += 3; + } + } + *dst = 0; + + return out; +} + +void +excess_file(const char *fn) +{ + printf("only in local fs: %s\n", fn); +} + +void +missing_file(const char *fn) +{ + printf("only in remote fs: %s\n", fn); +} + +int +pathcmp(const char *a, const char *b) +{ + int len_a = strlen(a); + int len_b = strlen(b); + + /* + * as the containing directory is sent after the files, it has to + * come out bigger in the comparison. + */ + if (len_a < len_b && a[len_a - 1] == '/' && strncmp(a, b, len_a) == 0) + return 1; + if (len_a > len_b && b[len_b - 1] == '/' && strncmp(a, b, len_b) == 0) + return -1; + + return strcmp(a, b); +} + +void +check_match(char *fn, char *local_m, char *remote_m, + char *local_c, char *remote_c) +{ + int match_m = !strcmp(local_m, remote_m); + int match_c = !strcmp(local_c, remote_c); + + if (match_m && !match_c) { + printf("data mismatch in %s\n", fn); + } else if (!match_m && match_c) { + printf("metadata mismatch in %s\n", fn); + } else if (!match_m && !match_c) { + printf("metadata and data mismatch in %s\n", fn); + } +} + +char *prev_fn; +char *prev_m; +char *prev_c; +void +check_manifest(char *fn, char *m, char *c, int last_call) +{ + char *rem_m; + char *rem_c; + char *l; + int cmp; + + if (prev_fn) { + if (last_call) + cmp = -1; + else + cmp = pathcmp(prev_fn, fn); + if (cmp > 0) { + excess_file(fn); + return; + } else if (cmp < 0) { + missing_file(prev_fn); + } else { + check_match(fn, m, prev_m, c, prev_c); + } + free(prev_fn); + free(prev_m); + free(prev_c); + prev_fn = NULL; + prev_m = NULL; + prev_c = NULL; + if (cmp == 0) + return; + } + while ((l = getln(line, sizeof(line), in_fp))) { + rem_c = strrchr(l, ' '); + if (!rem_c) { + /* final cs */ + checksum = strdup(l); + break; + } + if (rem_c == l) { +malformed: + fprintf(stderr, "malformed input\n"); + exit(-1); + } + *rem_c++ = 0; + rem_m = strrchr(l, ' '); + if (!rem_m) + goto malformed; + *rem_m++ = 0; + + if (last_call) + cmp = -1; + else + cmp = pathcmp(l, fn); + if (cmp == 0) { + check_match(fn, m, rem_m, c, rem_c); + return; + } else if (cmp > 0) { + excess_file(fn); + prev_fn = strdup(l); + prev_m = strdup(rem_m); + prev_c = strdup(rem_c); + return; + } + missing_file(l); + } + if (!last_call) + excess_file(fn); +} + +int +namecmp(const void *aa, const void *bb) +{ + char * const *a = aa; + char * const *b = bb; + + return strcmp(*a, *b); +} + +void +sum(int dirfd, int level, sum_t *dircs, char *path_prefix, char *path_in) +{ + DIR *d; + struct dirent *de; + char **namelist = NULL; + int alloclen = 0; + int entries = 0; + int i; + int ret; + int fd; + int excl; + sum_file_data_t sum_file_data = flags[FLAG_STRUCTURE] ? + sum_file_data_strict : sum_file_data_permissive; + + d = fdopendir(dirfd); + if (!d) { + perror("opendir"); + exit(-1); + } + while((de = readdir(d))) { + if (!strcmp(de->d_name, ".") || !strcmp(de->d_name, "..")) + continue; + if (entries == alloclen) { + alloclen += CHUNKS; + namelist = realloc(namelist, + alloclen * sizeof(*namelist)); + if (!namelist) { + fprintf(stderr, "malloc failed\n"); + exit(-1); + } + } + namelist[entries] = strdup(de->d_name); + if (!namelist[entries]) { + fprintf(stderr, "malloc failed\n"); + exit(-1); + } + ++entries; + } + qsort(namelist, entries, sizeof(*namelist), namecmp); + for (i = 0; i < entries; ++i) { + struct stat64 st; + sum_t cs; + sum_t meta; + char *path; + + sum_init(&cs); + sum_init(&meta); + path = alloc(strlen(path_in) + strlen(namelist[i]) + 3); + sprintf(path, "%s/%s", path_in, namelist[i]); + for (excl = 0; excl < n_excludes; ++excl) { + if (strncmp(excludes[excl].path, path, + excludes[excl].len) == 0) + goto next; + } + + ret = fchdir(dirfd); + if (ret == -1) { + perror("fchdir"); + exit(-1); + } + ret = lstat64(namelist[i], &st); + if (ret) { + fprintf(stderr, "stat failed for %s/%s: %s\n", + path_prefix, path, strerror(errno)); + exit(-1); + } + sum_add_u64(&meta, level); + sum_add(&meta, namelist[i], strlen(namelist[i])); + if (!S_ISDIR(st.st_mode)) + sum_add_u64(&meta, st.st_nlink); + if (flags[FLAG_UID]) + sum_add_u64(&meta, st.st_uid); + if (flags[FLAG_GID]) + sum_add_u64(&meta, st.st_gid); + if (flags[FLAG_MODE]) + sum_add_u64(&meta, st.st_mode); + if (flags[FLAG_ATIME]) + sum_add_time(&meta, st.st_atime); + if (flags[FLAG_MTIME]) + sum_add_time(&meta, st.st_mtime); + if (flags[FLAG_CTIME]) + sum_add_time(&meta, st.st_ctime); + if (S_ISDIR(st.st_mode)) { + fd = openat(dirfd, namelist[i], 0); + if (fd == -1 && flags[FLAG_OPEN_ERROR]) { + sum_add_u64(&meta, errno); + } else if (fd == -1) { + fprintf(stderr, "open failed for %s/%s: %s\n", + path_prefix, path, strerror(errno)); + exit(-1); + } else { + sum(fd, level + 1, &cs, path_prefix, path); + close(fd); + } + } else if (S_ISREG(st.st_mode)) { + sum_add_u64(&meta, st.st_size); + if (flags[FLAG_DATA]) { + if (verbose) + fprintf(stderr, "file %s\n", + namelist[i]); + fd = openat(dirfd, namelist[i], 0); + if (fd == -1 && flags[FLAG_OPEN_ERROR]) { + sum_add_u64(&meta, errno); + } else if (fd == -1) { + fprintf(stderr, + "open failed for %s/%s: %s\n", + path_prefix, path, + strerror(errno)); + exit(-1); + } + if (fd != -1) { + ret = sum_file_data(fd, &cs); + if (ret < 0) { + fprintf(stderr, + "read failed for " + "%s/%s: %s\n", + path_prefix, path, + strerror(errno)); + exit(-1); + } + close(fd); + } + } + } else if (S_ISLNK(st.st_mode)) { + ret = readlink(namelist[i], buf, sizeof(buf)); + if (ret == -1) { + perror("readlink"); + exit(-1); + } + sum_add(&cs, buf, ret); + } else if (S_ISCHR(st.st_mode) || S_ISBLK(st.st_mode)) { + sum_add_u64(&cs, major(st.st_rdev)); + sum_add_u64(&cs, minor(st.st_rdev)); + } + sum_fini(&cs); + sum_fini(&meta); + if (gen_manifest || in_manifest) { + char *fn; + char *m; + char *c; + + if (S_ISDIR(st.st_mode)) + strcat(path, "/"); + fn = escape(path); + m = sum_to_string(&meta); + c = sum_to_string(&cs); + + if (gen_manifest) + fprintf(out_fp, "%s %s %s\n", fn, m, c); + if (in_manifest) + check_manifest(fn, m, c, 0); + free(c); + free(m); + free(fn); + } + sum_add_sum(dircs, &cs); + sum_add_sum(dircs, &meta); +next: + free(path); + } +} + +int +main(int argc, char *argv[]) +{ + extern char *optarg; + extern int optind; + int c; + char *path; + int fd; + sum_t cs; + char flagstring[sizeof(flchar)]; + int i; + int plen; + int elen; + int n_flags = 0; + const char *allopts = "heEfuUgGoOaAmMcCdDsSnNw:r:vx:"; + + out_fp = stdout; + while ((c = getopt(argc, argv, allopts)) != EOF) { + switch(c) { + case 'f': + gen_manifest = 1; + break; + case 'u': + case 'U': + case 'g': + case 'G': + case 'o': + case 'O': + case 'a': + case 'A': + case 'm': + case 'M': + case 'c': + case 'C': + case 'd': + case 'D': + case 'e': + case 'E': + case 's': + case 'S': + ++n_flags; + parse_flag(c); + break; + case 'n': + for (i = 0; i < NUM_FLAGS; ++i) + flags[i] = 0; + break; + case 'N': + for (i = 0; i < NUM_FLAGS; ++i) + flags[i] = 1; + break; + case 'w': + out_fp = fopen(optarg, "w"); + if (!out_fp) { + fprintf(stderr, + "failed to open output file: %s\n", + strerror(errno)); + exit(-1); + } + break; + case 'r': + in_fp = fopen(optarg, "r"); + if (!in_fp) { + fprintf(stderr, + "failed to open input file: %s\n", + strerror(errno)); + exit(-1); + } + break; + case 'x': + ++n_excludes; + excludes = realloc(excludes, + sizeof(*excludes) * n_excludes); + if (!excludes) { + fprintf(stderr, + "failed to alloc exclude space\n"); + exit(-1); + } + excludes[n_excludes - 1].path = optarg; + break; + case 'v': + ++verbose; + break; + case 'h': + case '?': + usage(); + } + } + + if (optind + 1 != argc) { + fprintf(stderr, "missing path\n"); + usage(); + } + + if (in_fp) { + char *l = getln(line, sizeof(line), in_fp); + char *p; + + if (l == NULL) { + fprintf(stderr, "failed to read line from input\n"); + exit(-1); + } + if (strncmp(l, "Flags: ", 7) == 0) { + l += 7; + in_manifest = 1; + parse_flags(l); + } else if ((p = strchr(l, ':'))) { + *p++ = 0; + parse_flags(l); + checksum = strdup(p); + } else { + fprintf(stderr, "invalid input file format\n"); + exit(-1); + } + if (n_flags) + fprintf(stderr, "warning: " + "command line flags ignored in -r mode\n"); + } + strcpy(flagstring, flchar); + for (i = 0; i < NUM_FLAGS; ++i) { + if (flags[i] == 0) + flagstring[i] -= 'a' - 'A'; + } + + path = argv[optind]; + plen = strlen(path); + if (path[plen - 1] == '/') { + --plen; + path[plen] = '\0'; + } + + for (i = 0; i < n_excludes; ++i) { + if (strncmp(path, excludes[i].path, plen) != 0) + fprintf(stderr, + "warning: exclude %s outside of path %s\n", + excludes[i].path, path); + else + excludes[i].path += plen; + elen = strlen(excludes[i].path); + if (excludes[i].path[elen - 1] == '/') + --elen; + excludes[i].path[elen] = '\0'; + excludes[i].len = elen; + } + + fd = open(path, O_RDONLY); + if (fd == -1) { + fprintf(stderr, "failed to open %s: %s\n", path, + strerror(errno)); + exit(-1); + } + + if (gen_manifest) + fprintf(out_fp, "Flags: %s\n", flagstring); + + sum_init(&cs); + sum(fd, 1, &cs, path, ""); + sum_fini(&cs); + + close(fd); + if (in_manifest) + check_manifest("", "", "", 1); + + if (!checksum) { + if (in_manifest) { + fprintf(stderr, "malformed input\n"); + exit(-1); + } + if (!gen_manifest) + fprintf(out_fp, "%s:", flagstring); + + fprintf(out_fp, "%s\n", sum_to_string(&cs)); + } else { + if (strcmp(checksum, sum_to_string(&cs)) == 0) { + printf("OK\n"); + exit(0); + } else { + printf("FAIL\n"); + exit(1); + } + } + + exit(0); +} -- cgit v1.2.3 From 12cae4c2c6c020cbde440e96a6444ba7dc7ba613 Mon Sep 17 00:00:00 2001 From: David Sterba Date: Tue, 14 Mar 2017 18:56:22 +0100 Subject: btrfs-progs: tests: fssum, drop unnecessray build defines Signed-off-by: David Sterba --- tests/fssum.c | 8 +------- 1 file changed, 1 insertion(+), 7 deletions(-) (limited to 'tests') diff --git a/tests/fssum.c b/tests/fssum.c index c26d32b9..ebfecf53 100644 --- a/tests/fssum.c +++ b/tests/fssum.c @@ -15,13 +15,12 @@ * Free Software Foundation, Inc., 59 Temple Place - Suite 330, * Boston, MA 021110-1307, USA. */ -#ifdef __LINUX__ + #define _BSD_SOURCE #define _LARGEFILE64_SOURCE #ifndef _GNU_SOURCE #define _GNU_SOURCE #endif -#endif #include #include #include @@ -31,9 +30,6 @@ #include #include #include -#ifdef __SOLARIS__ -#include -#endif #include #include #include @@ -42,7 +38,6 @@ #define CS_SIZE 16 #define CHUNKS 128 -#ifdef __LINUX__ #ifndef SEEK_DATA #define SEEK_DATA 3 #define SEEK_HOLE 4 @@ -53,7 +48,6 @@ #else #define htonll(x) (x) #endif -#endif /* TODO: add hardlink recognition */ /* TODO: add xattr/acl */ -- cgit v1.2.3 From 855b4272a4297ee1156304f86a5e9bf81d54a489 Mon Sep 17 00:00:00 2001 From: David Sterba Date: Tue, 14 Mar 2017 19:01:35 +0100 Subject: btrfs-progs: tests: fssum, use our endianity helper The function htonll is not provided by the standard library and we can replace it by our cpu-to-XX helpers. This switches the endianity of the checksummed value to LE, but this is not a problem. Signed-off-by: David Sterba --- tests/fssum.c | 10 +++------- 1 file changed, 3 insertions(+), 7 deletions(-) (limited to 'tests') diff --git a/tests/fssum.c b/tests/fssum.c index ebfecf53..2d62ba66 100644 --- a/tests/fssum.c +++ b/tests/fssum.c @@ -21,6 +21,8 @@ #ifndef _GNU_SOURCE #define _GNU_SOURCE #endif + +#include "kerncompat.h" #include #include #include @@ -43,12 +45,6 @@ #define SEEK_HOLE 4 #endif -#if __BYTE_ORDER == __LITTLE_ENDIAN -#define htonll(x) __bswap_64 (x) -#else -#define htonll(x) (x) -#endif - /* TODO: add hardlink recognition */ /* TODO: add xattr/acl */ @@ -208,7 +204,7 @@ sum_add_sum(sum_t *dst, sum_t *src) void sum_add_u64(sum_t *dst, uint64_t val) { - uint64_t v = htonll(val); + uint64_t v = cpu_to_le64(val); sum_add(dst, &v, sizeof(v)); } -- cgit v1.2.3 From 17b964dc915b26c99ac0df42fe9f05025a34be16 Mon Sep 17 00:00:00 2001 From: David Sterba Date: Tue, 14 Mar 2017 19:04:51 +0100 Subject: btrfs-progs: tests: fssum, drop *_SOURCE defines, already provided via config.h In file included from /usr/include/stdio.h:27:0, from kerncompat.h:22, from tests/fssum.c:25: /usr/include/features.h:148:3: warning: #warning "_BSD_SOURCE and _SVID_SOURCE are deprecated, use _DEFAULT_SOURCE" [-Wcpp] # warning "_BSD_SOURCE and _SVID_SOURCE are deprecated, use _DEFAULT_SOURCE" ^~~~~~~ We've solved that long time ago and config.h now provides the macros. Signed-off-by: David Sterba --- tests/fssum.c | 6 ------ 1 file changed, 6 deletions(-) (limited to 'tests') diff --git a/tests/fssum.c b/tests/fssum.c index 2d62ba66..f5f83f9d 100644 --- a/tests/fssum.c +++ b/tests/fssum.c @@ -16,12 +16,6 @@ * Boston, MA 021110-1307, USA. */ -#define _BSD_SOURCE -#define _LARGEFILE64_SOURCE -#ifndef _GNU_SOURCE -#define _GNU_SOURCE -#endif - #include "kerncompat.h" #include #include -- cgit v1.2.3 From 1d684ec0e0c3663a140e362f5c7397134c4030f7 Mon Sep 17 00:00:00 2001 From: David Sterba Date: Tue, 14 Mar 2017 19:09:29 +0100 Subject: btrfs-progs: tests: fssum, update includes Remove unneeded and add headers that define time_te and int types. Signed-off-by: David Sterba --- tests/fssum.c | 5 ++--- 1 file changed, 2 insertions(+), 3 deletions(-) (limited to 'tests') diff --git a/tests/fssum.c b/tests/fssum.c index f5f83f9d..a69f80f2 100644 --- a/tests/fssum.c +++ b/tests/fssum.c @@ -24,12 +24,11 @@ #include #include #include -#include #include #include -#include -#include #include +#include +#include #define CS_SIZE 16 #define CHUNKS 128 -- cgit v1.2.3 From 4ddd6055c333932b561046ad1d41234d773246d2 Mon Sep 17 00:00:00 2001 From: David Sterba Date: Tue, 14 Mar 2017 19:30:47 +0100 Subject: btrfs-progs: tests: add SHA256 In order to drop dependency on SSL library to compute MD5 in fssum, we'll use the reference implementation from RFC 6234. The checksum is not in a cryptographically sensitive context, but we're going to skip MD5 and SHA-1 anyway. Signed-off-by: David Sterba --- tests/sha-private.h | 28 +++ tests/sha.h | 356 +++++++++++++++++++++++++++++++ tests/sha224-256.c | 601 ++++++++++++++++++++++++++++++++++++++++++++++++++++ 3 files changed, 985 insertions(+) create mode 100644 tests/sha-private.h create mode 100644 tests/sha.h create mode 100644 tests/sha224-256.c (limited to 'tests') diff --git a/tests/sha-private.h b/tests/sha-private.h new file mode 100644 index 00000000..6e9c4520 --- /dev/null +++ b/tests/sha-private.h @@ -0,0 +1,28 @@ +/************************ sha-private.h ************************/ +/***************** See RFC 6234 for details. *******************/ +#ifndef _SHA_PRIVATE__H +#define _SHA_PRIVATE__H +/* + * These definitions are defined in FIPS 180-3, section 4.1. + * Ch() and Maj() are defined identically in sections 4.1.1, + * 4.1.2, and 4.1.3. + * + * The definitions used in FIPS 180-3 are as follows: + */ + +#ifndef USE_MODIFIED_MACROS +#define SHA_Ch(x,y,z) (((x) & (y)) ^ ((~(x)) & (z))) +#define SHA_Maj(x,y,z) (((x) & (y)) ^ ((x) & (z)) ^ ((y) & (z))) +#else /* USE_MODIFIED_MACROS */ +/* + * The following definitions are equivalent and potentially faster. + */ + +#define SHA_Ch(x, y, z) (((x) & ((y) ^ (z))) ^ (z)) +#define SHA_Maj(x, y, z) (((x) & ((y) | (z))) | ((y) & (z))) + +#endif /* USE_MODIFIED_MACROS */ + +#define SHA_Parity(x, y, z) ((x) ^ (y) ^ (z)) + +#endif /* _SHA_PRIVATE__H */ diff --git a/tests/sha.h b/tests/sha.h new file mode 100644 index 00000000..1ffd6880 --- /dev/null +++ b/tests/sha.h @@ -0,0 +1,356 @@ +/**************************** sha.h ****************************/ +/***************** See RFC 6234 for details. *******************/ +/* + Copyright (c) 2011 IETF Trust and the persons identified as + authors of the code. All rights reserved. + + Redistribution and use in source and binary forms, with or + without modification, are permitted provided that the following + conditions are met: + + - Redistributions of source code must retain the above + copyright notice, this list of conditions and + the following disclaimer. + + - Redistributions in binary form must reproduce the above + copyright notice, this list of conditions and the following + disclaimer in the documentation and/or other materials provided + with the distribution. + + - Neither the name of Internet Society, IETF or IETF Trust, nor + the names of specific contributors, may be used to endorse or + promote products derived from this software without specific + prior written permission. + + THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND + CONTRIBUTORS "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, + INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF + MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE + DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR + CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, + SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT + NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; + LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) + HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN + CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR + OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, + EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. +*/ +#ifndef _SHA_H_ +#define _SHA_H_ + +/* + * Description: + * This file implements the Secure Hash Algorithms + * as defined in the U.S. National Institute of Standards + * and Technology Federal Information Processing Standards + * Publication (FIPS PUB) 180-3 published in October 2008 + * and formerly defined in its predecessors, FIPS PUB 180-1 + * and FIP PUB 180-2. + * + * A combined document showing all algorithms is available at + * http://csrc.nist.gov/publications/fips/ + * fips180-3/fips180-3_final.pdf + * + * The five hashes are defined in these sizes: + * SHA-1 20 byte / 160 bit + * SHA-224 28 byte / 224 bit + * SHA-256 32 byte / 256 bit + * SHA-384 48 byte / 384 bit + * SHA-512 64 byte / 512 bit + * + * Compilation Note: + * These files may be compiled with two options: + * USE_32BIT_ONLY - use 32-bit arithmetic only, for systems + * without 64-bit integers + * + * USE_MODIFIED_MACROS - use alternate form of the SHA_Ch() + * and SHA_Maj() macros that are equivalent + * and potentially faster on many systems + * + */ + +#include +/* + * If you do not have the ISO standard stdint.h header file, then you + * must typedef the following: + * name meaning + * uint64_t unsigned 64-bit integer + * uint32_t unsigned 32-bit integer + * uint8_t unsigned 8-bit integer (i.e., unsigned char) + * int_least16_t integer of >= 16 bits + * + * See stdint-example.h + */ + +#ifndef _SHA_enum_ +#define _SHA_enum_ +/* + * All SHA functions return one of these values. + */ +enum { + shaSuccess = 0, + shaNull, /* Null pointer parameter */ + shaInputTooLong, /* input data too long */ + shaStateError, /* called Input after FinalBits or Result */ + shaBadParam /* passed a bad parameter */ +}; +#endif /* _SHA_enum_ */ + +/* + * These constants hold size information for each of the SHA + * hashing operations + */ +enum { + SHA1_Message_Block_Size = 64, SHA224_Message_Block_Size = 64, + SHA256_Message_Block_Size = 64, SHA384_Message_Block_Size = 128, + SHA512_Message_Block_Size = 128, + USHA_Max_Message_Block_Size = SHA512_Message_Block_Size, + + SHA1HashSize = 20, SHA224HashSize = 28, SHA256HashSize = 32, + SHA384HashSize = 48, SHA512HashSize = 64, + USHAMaxHashSize = SHA512HashSize, + + SHA1HashSizeBits = 160, SHA224HashSizeBits = 224, + SHA256HashSizeBits = 256, SHA384HashSizeBits = 384, + SHA512HashSizeBits = 512, USHAMaxHashSizeBits = SHA512HashSizeBits +}; + +/* + * These constants are used in the USHA (Unified SHA) functions. + */ +typedef enum SHAversion { + SHA1, SHA224, SHA256, SHA384, SHA512 +} SHAversion; + +/* + * This structure will hold context information for the SHA-1 + * hashing operation. + */ +typedef struct SHA1Context { + uint32_t Intermediate_Hash[SHA1HashSize/4]; /* Message Digest */ + + uint32_t Length_High; /* Message length in bits */ + uint32_t Length_Low; /* Message length in bits */ + + int_least16_t Message_Block_Index; /* Message_Block array index */ + /* 512-bit message blocks */ + uint8_t Message_Block[SHA1_Message_Block_Size]; + + int Computed; /* Is the hash computed? */ + int Corrupted; /* Cumulative corruption code */ +} SHA1Context; + +/* + * This structure will hold context information for the SHA-256 + * hashing operation. + */ +typedef struct SHA256Context { + uint32_t Intermediate_Hash[SHA256HashSize/4]; /* Message Digest */ + + uint32_t Length_High; /* Message length in bits */ + uint32_t Length_Low; /* Message length in bits */ + + int_least16_t Message_Block_Index; /* Message_Block array index */ + /* 512-bit message blocks */ + uint8_t Message_Block[SHA256_Message_Block_Size]; + + int Computed; /* Is the hash computed? */ + int Corrupted; /* Cumulative corruption code */ +} SHA256Context; + +/* + * This structure will hold context information for the SHA-512 + * hashing operation. + */ +typedef struct SHA512Context { +#ifdef USE_32BIT_ONLY + uint32_t Intermediate_Hash[SHA512HashSize/4]; /* Message Digest */ + uint32_t Length[4]; /* Message length in bits */ +#else /* !USE_32BIT_ONLY */ + uint64_t Intermediate_Hash[SHA512HashSize/8]; /* Message Digest */ + uint64_t Length_High, Length_Low; /* Message length in bits */ +#endif /* USE_32BIT_ONLY */ + + int_least16_t Message_Block_Index; /* Message_Block array index */ + /* 1024-bit message blocks */ + uint8_t Message_Block[SHA512_Message_Block_Size]; + + int Computed; /* Is the hash computed?*/ + int Corrupted; /* Cumulative corruption code */ +} SHA512Context; + +/* + * This structure will hold context information for the SHA-224 + * hashing operation. It uses the SHA-256 structure for computation. + */ +typedef struct SHA256Context SHA224Context; + +/* + * This structure will hold context information for the SHA-384 + * hashing operation. It uses the SHA-512 structure for computation. + */ +typedef struct SHA512Context SHA384Context; + +/* + * This structure holds context information for all SHA + * hashing operations. + */ +typedef struct USHAContext { + int whichSha; /* which SHA is being used */ + union { + SHA1Context sha1Context; + SHA224Context sha224Context; SHA256Context sha256Context; + SHA384Context sha384Context; SHA512Context sha512Context; + } ctx; +} USHAContext; + +/* + * This structure will hold context information for the HMAC + * keyed-hashing operation. + */ +typedef struct HMACContext { + int whichSha; /* which SHA is being used */ + int hashSize; /* hash size of SHA being used */ + int blockSize; /* block size of SHA being used */ + USHAContext shaContext; /* SHA context */ + unsigned char k_opad[USHA_Max_Message_Block_Size]; + /* outer padding - key XORd with opad */ + int Computed; /* Is the MAC computed? */ + int Corrupted; /* Cumulative corruption code */ + +} HMACContext; + +/* + * This structure will hold context information for the HKDF + * extract-and-expand Key Derivation Functions. + */ +typedef struct HKDFContext { + int whichSha; /* which SHA is being used */ + HMACContext hmacContext; + int hashSize; /* hash size of SHA being used */ + unsigned char prk[USHAMaxHashSize]; + /* pseudo-random key - output of hkdfInput */ + int Computed; /* Is the key material computed? */ + int Corrupted; /* Cumulative corruption code */ +} HKDFContext; + +/* + * Function Prototypes + */ + +/* SHA-1 */ +extern int SHA1Reset(SHA1Context *); +extern int SHA1Input(SHA1Context *, const uint8_t *bytes, + unsigned int bytecount); +extern int SHA1FinalBits(SHA1Context *, uint8_t bits, + unsigned int bit_count); +extern int SHA1Result(SHA1Context *, + uint8_t Message_Digest[SHA1HashSize]); + +/* SHA-224 */ +extern int SHA224Reset(SHA224Context *); +extern int SHA224Input(SHA224Context *, const uint8_t *bytes, + unsigned int bytecount); +extern int SHA224FinalBits(SHA224Context *, uint8_t bits, + unsigned int bit_count); +extern int SHA224Result(SHA224Context *, + uint8_t Message_Digest[SHA224HashSize]); + +/* SHA-256 */ +extern int SHA256Reset(SHA256Context *); +extern int SHA256Input(SHA256Context *, const uint8_t *bytes, + unsigned int bytecount); +extern int SHA256FinalBits(SHA256Context *, uint8_t bits, + unsigned int bit_count); +extern int SHA256Result(SHA256Context *, + uint8_t Message_Digest[SHA256HashSize]); + +/* SHA-384 */ +extern int SHA384Reset(SHA384Context *); +extern int SHA384Input(SHA384Context *, const uint8_t *bytes, + unsigned int bytecount); +extern int SHA384FinalBits(SHA384Context *, uint8_t bits, + unsigned int bit_count); +extern int SHA384Result(SHA384Context *, + uint8_t Message_Digest[SHA384HashSize]); + +/* SHA-512 */ +extern int SHA512Reset(SHA512Context *); +extern int SHA512Input(SHA512Context *, const uint8_t *bytes, + unsigned int bytecount); +extern int SHA512FinalBits(SHA512Context *, uint8_t bits, + unsigned int bit_count); +extern int SHA512Result(SHA512Context *, + uint8_t Message_Digest[SHA512HashSize]); + +/* Unified SHA functions, chosen by whichSha */ +extern int USHAReset(USHAContext *context, SHAversion whichSha); +extern int USHAInput(USHAContext *context, + const uint8_t *bytes, unsigned int bytecount); +extern int USHAFinalBits(USHAContext *context, + uint8_t bits, unsigned int bit_count); +extern int USHAResult(USHAContext *context, + uint8_t Message_Digest[USHAMaxHashSize]); +extern int USHABlockSize(enum SHAversion whichSha); +extern int USHAHashSize(enum SHAversion whichSha); +extern int USHAHashSizeBits(enum SHAversion whichSha); +extern const char *USHAHashName(enum SHAversion whichSha); + +/* + * HMAC Keyed-Hashing for Message Authentication, RFC 2104, + * for all SHAs. + * This interface allows a fixed-length text input to be used. + */ +extern int hmac(SHAversion whichSha, /* which SHA algorithm to use */ + const unsigned char *text, /* pointer to data stream */ + int text_len, /* length of data stream */ + const unsigned char *key, /* pointer to authentication key */ + int key_len, /* length of authentication key */ + uint8_t digest[USHAMaxHashSize]); /* caller digest to fill in */ + +/* + * HMAC Keyed-Hashing for Message Authentication, RFC 2104, + * for all SHAs. + * This interface allows any length of text input to be used. + */ +extern int hmacReset(HMACContext *context, enum SHAversion whichSha, + const unsigned char *key, int key_len); +extern int hmacInput(HMACContext *context, const unsigned char *text, + int text_len); +extern int hmacFinalBits(HMACContext *context, uint8_t bits, + unsigned int bit_count); +extern int hmacResult(HMACContext *context, + uint8_t digest[USHAMaxHashSize]); + +/* + * HKDF HMAC-based Extract-and-Expand Key Derivation Function, + * RFC 5869, for all SHAs. + */ +extern int hkdf(SHAversion whichSha, const unsigned char *salt, + int salt_len, const unsigned char *ikm, int ikm_len, + const unsigned char *info, int info_len, + uint8_t okm[ ], int okm_len); +extern int hkdfExtract(SHAversion whichSha, const unsigned char *salt, + int salt_len, const unsigned char *ikm, + int ikm_len, uint8_t prk[USHAMaxHashSize]); +extern int hkdfExpand(SHAversion whichSha, const uint8_t prk[ ], + int prk_len, const unsigned char *info, + int info_len, uint8_t okm[ ], int okm_len); + +/* + * HKDF HMAC-based Extract-and-Expand Key Derivation Function, + * RFC 5869, for all SHAs. + * This interface allows any length of text input to be used. + */ +extern int hkdfReset(HKDFContext *context, enum SHAversion whichSha, + const unsigned char *salt, int salt_len); +extern int hkdfInput(HKDFContext *context, const unsigned char *ikm, + int ikm_len); +extern int hkdfFinalBits(HKDFContext *context, uint8_t ikm_bits, + unsigned int ikm_bit_count); +extern int hkdfResult(HKDFContext *context, + uint8_t prk[USHAMaxHashSize], + const unsigned char *info, int info_len, + uint8_t okm[USHAMaxHashSize], int okm_len); +#endif /* _SHA_H_ */ diff --git a/tests/sha224-256.c b/tests/sha224-256.c new file mode 100644 index 00000000..2d963e65 --- /dev/null +++ b/tests/sha224-256.c @@ -0,0 +1,601 @@ +/* +RFC 6234 SHAs, HMAC-SHAs, and HKDF May 2011 + + +Copyright Notice + + Copyright (c) 2011 IETF Trust and the persons identified as the + document authors. All rights reserved. + + This document is subject to BCP 78 and the IETF Trust's Legal + Provisions Relating to IETF Documents + (http://trustee.ietf.org/license-info) in effect on the date of + publication of this document. Please review these documents + carefully, as they describe your rights and restrictions with respect + to this document. Code Components extracted from this document must + include Simplified BSD License text as described in Section 4.e of + the Trust Legal Provisions and are provided without warranty as + described in the Simplified BSD License. +*/ + +/************************* sha224-256.c ************************/ +/***************** See RFC 6234 for details. *******************/ +/* Copyright (c) 2011 IETF Trust and the persons identified as */ +/* authors of the code. All rights reserved. */ +/* See sha.h for terms of use and redistribution. */ + +/* + * Description: + * This file implements the Secure Hash Algorithms SHA-224 and + * SHA-256 as defined in the U.S. National Institute of Standards + * and Technology Federal Information Processing Standards + * Publication (FIPS PUB) 180-3 published in October 2008 + * and formerly defined in its predecessors, FIPS PUB 180-1 + * and FIP PUB 180-2. + * + * A combined document showing all algorithms is available at + * http://csrc.nist.gov/publications/fips/ + * fips180-3/fips180-3_final.pdf + * + * The SHA-224 and SHA-256 algorithms produce 224-bit and 256-bit + * message digests for a given data stream. It should take about + * 2**n steps to find a message with the same digest as a given + * message and 2**(n/2) to find any two messages with the same + * digest, when n is the digest size in bits. Therefore, this + * algorithm can serve as a means of providing a + * "fingerprint" for a message. + * + * Portability Issues: + * SHA-224 and SHA-256 are defined in terms of 32-bit "words". + * This code uses (included via "sha.h") to define 32- + * and 8-bit unsigned integer types. If your C compiler does not + * support 32-bit unsigned integers, this code is not + * appropriate. + * + * Caveats: + * SHA-224 and SHA-256 are designed to work with messages less + * than 2^64 bits long. This implementation uses SHA224/256Input() + * to hash the bits that are a multiple of the size of an 8-bit + * octet, and then optionally uses SHA224/256FinalBits() + * to hash the final few bits of the input. + */ + +#include "tests/sha.h" +#include "tests/sha-private.h" + +/* Define the SHA shift, rotate left, and rotate right macros */ +#define SHA256_SHR(bits,word) ((word) >> (bits)) +#define SHA256_ROTL(bits,word) \ + (((word) << (bits)) | ((word) >> (32-(bits)))) +#define SHA256_ROTR(bits,word) \ + (((word) >> (bits)) | ((word) << (32-(bits)))) + +/* Define the SHA SIGMA and sigma macros */ +#define SHA256_SIGMA0(word) \ + (SHA256_ROTR( 2,word) ^ SHA256_ROTR(13,word) ^ SHA256_ROTR(22,word)) +#define SHA256_SIGMA1(word) \ + (SHA256_ROTR( 6,word) ^ SHA256_ROTR(11,word) ^ SHA256_ROTR(25,word)) +#define SHA256_sigma0(word) \ + (SHA256_ROTR( 7,word) ^ SHA256_ROTR(18,word) ^ SHA256_SHR( 3,word)) +#define SHA256_sigma1(word) \ + (SHA256_ROTR(17,word) ^ SHA256_ROTR(19,word) ^ SHA256_SHR(10,word)) + +/* + * Add "length" to the length. + * Set Corrupted when overflow has occurred. + */ +static uint32_t addTemp; +#define SHA224_256AddLength(context, length) \ + (addTemp = (context)->Length_Low, (context)->Corrupted = \ + (((context)->Length_Low += (length)) < addTemp) && \ + (++(context)->Length_High == 0) ? shaInputTooLong : \ + (context)->Corrupted ) + +/* Local Function Prototypes */ +static int SHA224_256Reset(SHA256Context *context, uint32_t *H0); +static void SHA224_256ProcessMessageBlock(SHA256Context *context); +static void SHA224_256Finalize(SHA256Context *context, + uint8_t Pad_Byte); +static void SHA224_256PadMessage(SHA256Context *context, + uint8_t Pad_Byte); +static int SHA224_256ResultN(SHA256Context *context, + uint8_t Message_Digest[ ], int HashSize); + +/* Initial Hash Values: FIPS 180-3 section 5.3.2 */ +static uint32_t SHA224_H0[SHA256HashSize/4] = { + 0xC1059ED8, 0x367CD507, 0x3070DD17, 0xF70E5939, + 0xFFC00B31, 0x68581511, 0x64F98FA7, 0xBEFA4FA4 +}; + +/* Initial Hash Values: FIPS 180-3 section 5.3.3 */ +static uint32_t SHA256_H0[SHA256HashSize/4] = { + 0x6A09E667, 0xBB67AE85, 0x3C6EF372, 0xA54FF53A, + 0x510E527F, 0x9B05688C, 0x1F83D9AB, 0x5BE0CD19 +}; + +/* + * SHA224Reset + * + * Description: + * This function will initialize the SHA224Context in preparation + * for computing a new SHA224 message digest. + * + * Parameters: + * context: [in/out] + * The context to reset. + * + * Returns: + * sha Error Code. + */ +int SHA224Reset(SHA224Context *context) +{ + return SHA224_256Reset(context, SHA224_H0); +} + +/* + * SHA224Input + * + * Description: + * This function accepts an array of octets as the next portion + * of the message. + * + * Parameters: + * context: [in/out] + * The SHA context to update. + * message_array[ ]: [in] + * An array of octets representing the next portion of + * the message. + * length: [in] + * The length of the message in message_array. + * + * Returns: + * sha Error Code. + * + */ +int SHA224Input(SHA224Context *context, const uint8_t *message_array, + unsigned int length) +{ + return SHA256Input(context, message_array, length); +} + +/* + * SHA224FinalBits + * + * Description: + * This function will add in any final bits of the message. + * + * Parameters: + * context: [in/out] + * The SHA context to update. + * message_bits: [in] + * The final bits of the message, in the upper portion of the + * byte. (Use 0b###00000 instead of 0b00000### to input the + * three bits ###.) + * length: [in] + * The number of bits in message_bits, between 1 and 7. + * + * Returns: + * sha Error Code. + */ +int SHA224FinalBits(SHA224Context *context, + uint8_t message_bits, unsigned int length) +{ + return SHA256FinalBits(context, message_bits, length); +} + +/* + * SHA224Result + * + * Description: + * This function will return the 224-bit message digest + * into the Message_Digest array provided by the caller. + * NOTE: + * The first octet of hash is stored in the element with index 0, + * the last octet of hash in the element with index 27. + * + * Parameters: + * context: [in/out] + * The context to use to calculate the SHA hash. + * Message_Digest[ ]: [out] + * Where the digest is returned. + * + * Returns: + * sha Error Code. + */ +int SHA224Result(SHA224Context *context, + uint8_t Message_Digest[SHA224HashSize]) +{ + return SHA224_256ResultN(context, Message_Digest, SHA224HashSize); +} + +/* + * SHA256Reset + * + * Description: + * This function will initialize the SHA256Context in preparation + * for computing a new SHA256 message digest. + * + * Parameters: + * context: [in/out] + * The context to reset. + * + * Returns: + * sha Error Code. + */ +int SHA256Reset(SHA256Context *context) +{ + return SHA224_256Reset(context, SHA256_H0); +} + +/* + * SHA256Input + * + * Description: + * This function accepts an array of octets as the next portion + * of the message. + * + * Parameters: + * context: [in/out] + * The SHA context to update. + * message_array[ ]: [in] + * An array of octets representing the next portion of + * the message. + * length: [in] + * The length of the message in message_array. + * + * Returns: + * sha Error Code. + */ +int SHA256Input(SHA256Context *context, const uint8_t *message_array, + unsigned int length) +{ + if (!context) return shaNull; + if (!length) return shaSuccess; + if (!message_array) return shaNull; + if (context->Computed) return context->Corrupted = shaStateError; + if (context->Corrupted) return context->Corrupted; + + while (length--) { + context->Message_Block[context->Message_Block_Index++] = + *message_array; + + if ((SHA224_256AddLength(context, 8) == shaSuccess) && + (context->Message_Block_Index == SHA256_Message_Block_Size)) + SHA224_256ProcessMessageBlock(context); + + message_array++; + } + + return context->Corrupted; + +} + +/* + * SHA256FinalBits + * + * Description: + * This function will add in any final bits of the message. + * + * Parameters: + * context: [in/out] + * The SHA context to update. + * message_bits: [in] + * The final bits of the message, in the upper portion of the + * byte. (Use 0b###00000 instead of 0b00000### to input the + * three bits ###.) + * length: [in] + * The number of bits in message_bits, between 1 and 7. + * + * Returns: + * sha Error Code. + */ +int SHA256FinalBits(SHA256Context *context, + uint8_t message_bits, unsigned int length) +{ + static uint8_t masks[8] = { + /* 0 0b00000000 */ 0x00, /* 1 0b10000000 */ 0x80, + /* 2 0b11000000 */ 0xC0, /* 3 0b11100000 */ 0xE0, + /* 4 0b11110000 */ 0xF0, /* 5 0b11111000 */ 0xF8, + /* 6 0b11111100 */ 0xFC, /* 7 0b11111110 */ 0xFE + }; + static uint8_t markbit[8] = { + /* 0 0b10000000 */ 0x80, /* 1 0b01000000 */ 0x40, + /* 2 0b00100000 */ 0x20, /* 3 0b00010000 */ 0x10, + /* 4 0b00001000 */ 0x08, /* 5 0b00000100 */ 0x04, + /* 6 0b00000010 */ 0x02, /* 7 0b00000001 */ 0x01 + }; + + if (!context) return shaNull; + if (!length) return shaSuccess; + if (context->Corrupted) return context->Corrupted; + if (context->Computed) return context->Corrupted = shaStateError; + if (length >= 8) return context->Corrupted = shaBadParam; + + SHA224_256AddLength(context, length); + SHA224_256Finalize(context, (uint8_t) + ((message_bits & masks[length]) | markbit[length])); + + return context->Corrupted; +} + +/* + * SHA256Result + * + * Description: + * This function will return the 256-bit message digest + * into the Message_Digest array provided by the caller. + * NOTE: + * The first octet of hash is stored in the element with index 0, + * the last octet of hash in the element with index 31. + * + * Parameters: + * context: [in/out] + * The context to use to calculate the SHA hash. + * Message_Digest[ ]: [out] + * Where the digest is returned. + * + * Returns: + * sha Error Code. + */ +int SHA256Result(SHA256Context *context, + uint8_t Message_Digest[SHA256HashSize]) +{ + return SHA224_256ResultN(context, Message_Digest, SHA256HashSize); +} + +/* + * SHA224_256Reset + * + * Description: + * This helper function will initialize the SHA256Context in + * preparation for computing a new SHA-224 or SHA-256 message digest. + * + * Parameters: + * context: [in/out] + * The context to reset. + * H0[ ]: [in] + * The initial hash value array to use. + * + * Returns: + * sha Error Code. + */ +static int SHA224_256Reset(SHA256Context *context, uint32_t *H0) +{ + if (!context) return shaNull; + + context->Length_High = context->Length_Low = 0; + context->Message_Block_Index = 0; + + context->Intermediate_Hash[0] = H0[0]; + context->Intermediate_Hash[1] = H0[1]; + context->Intermediate_Hash[2] = H0[2]; + context->Intermediate_Hash[3] = H0[3]; + context->Intermediate_Hash[4] = H0[4]; + context->Intermediate_Hash[5] = H0[5]; + context->Intermediate_Hash[6] = H0[6]; + context->Intermediate_Hash[7] = H0[7]; + + context->Computed = 0; + context->Corrupted = shaSuccess; + + return shaSuccess; +} + +/* + * SHA224_256ProcessMessageBlock + * + * Description: + * This helper function will process the next 512 bits of the + * message stored in the Message_Block array. + * + * Parameters: + * context: [in/out] + * The SHA context to update. + * + * Returns: + * Nothing. + * + * Comments: + * Many of the variable names in this code, especially the + * single character names, were used because those were the + * names used in the Secure Hash Standard. + */ +static void SHA224_256ProcessMessageBlock(SHA256Context *context) +{ + /* Constants defined in FIPS 180-3, section 4.2.2 */ + static const uint32_t K[64] = { + 0x428a2f98, 0x71374491, 0xb5c0fbcf, 0xe9b5dba5, 0x3956c25b, + 0x59f111f1, 0x923f82a4, 0xab1c5ed5, 0xd807aa98, 0x12835b01, + 0x243185be, 0x550c7dc3, 0x72be5d74, 0x80deb1fe, 0x9bdc06a7, + 0xc19bf174, 0xe49b69c1, 0xefbe4786, 0x0fc19dc6, 0x240ca1cc, + 0x2de92c6f, 0x4a7484aa, 0x5cb0a9dc, 0x76f988da, 0x983e5152, + 0xa831c66d, 0xb00327c8, 0xbf597fc7, 0xc6e00bf3, 0xd5a79147, + 0x06ca6351, 0x14292967, 0x27b70a85, 0x2e1b2138, 0x4d2c6dfc, + 0x53380d13, 0x650a7354, 0x766a0abb, 0x81c2c92e, 0x92722c85, + 0xa2bfe8a1, 0xa81a664b, 0xc24b8b70, 0xc76c51a3, 0xd192e819, + 0xd6990624, 0xf40e3585, 0x106aa070, 0x19a4c116, 0x1e376c08, + 0x2748774c, 0x34b0bcb5, 0x391c0cb3, 0x4ed8aa4a, 0x5b9cca4f, + 0x682e6ff3, 0x748f82ee, 0x78a5636f, 0x84c87814, 0x8cc70208, + 0x90befffa, 0xa4506ceb, 0xbef9a3f7, 0xc67178f2 + }; + int t, t4; /* Loop counter */ + uint32_t temp1, temp2; /* Temporary word value */ + uint32_t W[64]; /* Word sequence */ + uint32_t A, B, C, D, E, F, G, H; /* Word buffers */ + + /* + * Initialize the first 16 words in the array W + */ + for (t = t4 = 0; t < 16; t++, t4 += 4) + W[t] = (((uint32_t)context->Message_Block[t4]) << 24) | + (((uint32_t)context->Message_Block[t4 + 1]) << 16) | + (((uint32_t)context->Message_Block[t4 + 2]) << 8) | + (((uint32_t)context->Message_Block[t4 + 3])); + + for (t = 16; t < 64; t++) + W[t] = SHA256_sigma1(W[t-2]) + W[t-7] + + SHA256_sigma0(W[t-15]) + W[t-16]; + + A = context->Intermediate_Hash[0]; + B = context->Intermediate_Hash[1]; + C = context->Intermediate_Hash[2]; + D = context->Intermediate_Hash[3]; + E = context->Intermediate_Hash[4]; + F = context->Intermediate_Hash[5]; + G = context->Intermediate_Hash[6]; + H = context->Intermediate_Hash[7]; + + for (t = 0; t < 64; t++) { + temp1 = H + SHA256_SIGMA1(E) + SHA_Ch(E,F,G) + K[t] + W[t]; + temp2 = SHA256_SIGMA0(A) + SHA_Maj(A,B,C); + H = G; + G = F; + F = E; + E = D + temp1; + D = C; + C = B; + B = A; + A = temp1 + temp2; + } + + context->Intermediate_Hash[0] += A; + context->Intermediate_Hash[1] += B; + context->Intermediate_Hash[2] += C; + context->Intermediate_Hash[3] += D; + context->Intermediate_Hash[4] += E; + context->Intermediate_Hash[5] += F; + context->Intermediate_Hash[6] += G; + context->Intermediate_Hash[7] += H; + + context->Message_Block_Index = 0; +} + +/* + * SHA224_256Finalize + * + * Description: + * This helper function finishes off the digest calculations. + * + * Parameters: + * context: [in/out] + * The SHA context to update. + * Pad_Byte: [in] + * The last byte to add to the message block before the 0-padding + * and length. This will contain the last bits of the message + * followed by another single bit. If the message was an + * exact multiple of 8-bits long, Pad_Byte will be 0x80. + * + * Returns: + * sha Error Code. + */ +static void SHA224_256Finalize(SHA256Context *context, + uint8_t Pad_Byte) +{ + int i; + SHA224_256PadMessage(context, Pad_Byte); + /* message may be sensitive, so clear it out */ + for (i = 0; i < SHA256_Message_Block_Size; ++i) + context->Message_Block[i] = 0; + context->Length_High = 0; /* and clear length */ + context->Length_Low = 0; + context->Computed = 1; +} + +/* + * SHA224_256PadMessage + * + * Description: + * According to the standard, the message must be padded to the next + * even multiple of 512 bits. The first padding bit must be a '1'. + * The last 64 bits represent the length of the original message. + * All bits in between should be 0. This helper function will pad + * the message according to those rules by filling the + * Message_Block array accordingly. When it returns, it can be + * assumed that the message digest has been computed. + * + * Parameters: + * context: [in/out] + * The context to pad. + * Pad_Byte: [in] + * The last byte to add to the message block before the 0-padding + * and length. This will contain the last bits of the message + * followed by another single bit. If the message was an + * exact multiple of 8-bits long, Pad_Byte will be 0x80. + * + * Returns: + * Nothing. + */ +static void SHA224_256PadMessage(SHA256Context *context, + uint8_t Pad_Byte) +{ + /* + * Check to see if the current message block is too small to hold + * the initial padding bits and length. If so, we will pad the + * block, process it, and then continue padding into a second + * block. + */ + if (context->Message_Block_Index >= (SHA256_Message_Block_Size-8)) { + context->Message_Block[context->Message_Block_Index++] = Pad_Byte; + while (context->Message_Block_Index < SHA256_Message_Block_Size) + context->Message_Block[context->Message_Block_Index++] = 0; + SHA224_256ProcessMessageBlock(context); + } else + context->Message_Block[context->Message_Block_Index++] = Pad_Byte; + + while (context->Message_Block_Index < (SHA256_Message_Block_Size-8)) + context->Message_Block[context->Message_Block_Index++] = 0; + + /* + * Store the message length as the last 8 octets + */ + context->Message_Block[56] = (uint8_t)(context->Length_High >> 24); + context->Message_Block[57] = (uint8_t)(context->Length_High >> 16); + context->Message_Block[58] = (uint8_t)(context->Length_High >> 8); + context->Message_Block[59] = (uint8_t)(context->Length_High); + context->Message_Block[60] = (uint8_t)(context->Length_Low >> 24); + context->Message_Block[61] = (uint8_t)(context->Length_Low >> 16); + context->Message_Block[62] = (uint8_t)(context->Length_Low >> 8); + context->Message_Block[63] = (uint8_t)(context->Length_Low); + + SHA224_256ProcessMessageBlock(context); +} + +/* + * SHA224_256ResultN + * + * Description: + * This helper function will return the 224-bit or 256-bit message + * digest into the Message_Digest array provided by the caller. + * NOTE: + * The first octet of hash is stored in the element with index 0, + * the last octet of hash in the element with index 27/31. + * + * Parameters: + * context: [in/out] + * The context to use to calculate the SHA hash. + * Message_Digest[ ]: [out] + * Where the digest is returned. + * HashSize: [in] + * The size of the hash, either 28 or 32. + * + * Returns: + * sha Error Code. + */ +static int SHA224_256ResultN(SHA256Context *context, + uint8_t Message_Digest[ ], int HashSize) +{ + int i; + + if (!context) return shaNull; + if (!Message_Digest) return shaNull; + if (context->Corrupted) return context->Corrupted; + + if (!context->Computed) + SHA224_256Finalize(context, 0x80); + + for (i = 0; i < HashSize; ++i) + Message_Digest[i] = (uint8_t) + (context->Intermediate_Hash[i>>2] >> 8 * ( 3 - ( i & 0x03 ) )); + + return shaSuccess; +} -- cgit v1.2.3 From b5d4b3cef3504b1ca6734ca8fd56b8d6a1c304ac Mon Sep 17 00:00:00 2001 From: David Sterba Date: Wed, 15 Mar 2017 12:21:50 +0100 Subject: btrfs-progs: tests: fssum, switch from MD5 to SHA256 Signed-off-by: David Sterba --- tests/fssum.c | 14 +++++++------- 1 file changed, 7 insertions(+), 7 deletions(-) (limited to 'tests') diff --git a/tests/fssum.c b/tests/fssum.c index a69f80f2..83bd4106 100644 --- a/tests/fssum.c +++ b/tests/fssum.c @@ -25,12 +25,12 @@ #include #include #include -#include #include #include #include +#include "tests/sha.h" -#define CS_SIZE 16 +#define CS_SIZE 32 #define CHUNKS 128 #ifndef SEEK_DATA @@ -47,8 +47,8 @@ struct excludes { }; typedef struct _sum { - MD5_CTX md5; - unsigned char out[16]; + SHA256Context sha; + unsigned char out[CS_SIZE]; } sum_t; typedef int (*sum_file_data_t)(int fd, sum_t *dst); @@ -173,19 +173,19 @@ alloc(size_t sz) void sum_init(sum_t *cs) { - MD5_Init(&cs->md5); + SHA256Reset(&cs->sha); } void sum_fini(sum_t *cs) { - MD5_Final(cs->out, &cs->md5); + SHA256Result(&cs->sha, cs->out); } void sum_add(sum_t *cs, void *buf, int size) { - MD5_Update(&cs->md5, buf, size); + SHA256Input(&cs->sha, buf, size); } void -- cgit v1.2.3 From 02947f410591dca68ca3b3c5ea4e78d899aedcf1 Mon Sep 17 00:00:00 2001 From: David Sterba Date: Wed, 15 Mar 2017 12:28:16 +0100 Subject: btrfs-progs: tests: misc/019, use fssum The fssum utility is now ready to use, test still passes. Signed-off-by: David Sterba --- tests/misc-tests/019-receive-clones-on-munted-subvol/test.sh | 5 ++--- 1 file changed, 2 insertions(+), 3 deletions(-) (limited to 'tests') diff --git a/tests/misc-tests/019-receive-clones-on-munted-subvol/test.sh b/tests/misc-tests/019-receive-clones-on-munted-subvol/test.sh index 5735ecb0..3a572439 100755 --- a/tests/misc-tests/019-receive-clones-on-munted-subvol/test.sh +++ b/tests/misc-tests/019-receive-clones-on-munted-subvol/test.sh @@ -5,17 +5,16 @@ # have an entry with the same name that corresponds to different inodes in each # snapshot. -# temporary, until the test gets adapted -FSSUM_PROG=/bin/true - source $TOP/tests/common check_prereq mkfs.btrfs check_prereq btrfs +check_prereq fssum setup_root_helper prepare_test_dev +FSSUM_PROG="$TOP/fssum" srcdir=./send-test-dir rm -rf "$srcdir" mkdir -p "$srcdir" -- cgit v1.2.3 From 583cab2e2c7c09cc0d6896e67c7c1f53c8f98484 Mon Sep 17 00:00:00 2001 From: Qu Wenruo Date: Fri, 17 Mar 2017 10:06:34 +0800 Subject: btrfs-progs: tests: Add SHARED_DATA_REF test image for check lowmem mode Introduce a new image, which contains external SHARED_DATA_REF items to trigger a lowmem mode false alert. The image only contains external SHARED_DATA_REF and no inlined data backref. Before the image, we only have inlined shared data ref, which is not enough to trigger lowmem mode false alert. Signed-off-by: Qu Wenruo Signed-off-by: David Sterba --- .../020-extent-ref-cases/shared_data_ref_only.img | Bin 0 -> 7168 bytes 1 file changed, 0 insertions(+), 0 deletions(-) create mode 100644 tests/fsck-tests/020-extent-ref-cases/shared_data_ref_only.img (limited to 'tests') diff --git a/tests/fsck-tests/020-extent-ref-cases/shared_data_ref_only.img b/tests/fsck-tests/020-extent-ref-cases/shared_data_ref_only.img new file mode 100644 index 00000000..6d2b95e4 Binary files /dev/null and b/tests/fsck-tests/020-extent-ref-cases/shared_data_ref_only.img differ -- cgit v1.2.3 From 27c5e540be8d79e8b610e91dfee381e46b4a94c8 Mon Sep 17 00:00:00 2001 From: Christian Brauner Date: Mon, 3 Apr 2017 22:21:08 +0200 Subject: btrfs-progs: tests: misc/018-receive use receive -e to terminate on end marker Signed-off-by: Christian Brauner [ enhance tests to take extra options and use for -e ] Signed-off-by: David Sterba --- tests/misc-tests/018-recv-end-of-stream/test.sh | 20 ++++++++++++++------ 1 file changed, 14 insertions(+), 6 deletions(-) (limited to 'tests') diff --git a/tests/misc-tests/018-recv-end-of-stream/test.sh b/tests/misc-tests/018-recv-end-of-stream/test.sh index d39683e9..3b8a0319 100755 --- a/tests/misc-tests/018-recv-end-of-stream/test.sh +++ b/tests/misc-tests/018-recv-end-of-stream/test.sh @@ -13,6 +13,8 @@ prepare_test_dev 1g here=`pwd` +# All helpers can exercise various options passed to 'btrfs receive' + test_full_empty_stream() { local str @@ -34,7 +36,7 @@ test_full_empty_stream() { run_check $TOP/mkfs.btrfs -f $TEST_DEV run_check_mount_test_dev - run_check $SUDO_HELPER $TOP/btrfs receive -v -f "$str" "$TEST_MNT" + run_check $SUDO_HELPER $TOP/btrfs receive "$@" -v -f "$str" "$TEST_MNT" run_check_umount_test_dev run_check rm -f -- "$str" @@ -65,7 +67,7 @@ test_full_simple_stream() { run_check $TOP/mkfs.btrfs -f $TEST_DEV run_check_mount_test_dev - run_check $SUDO_HELPER $TOP/btrfs receive -v -f "$str" "$TEST_MNT" + run_check $SUDO_HELPER $TOP/btrfs receive "$@" -v -f "$str" "$TEST_MNT" run_check_umount_test_dev run_check rm -f -- "$str" @@ -96,8 +98,8 @@ test_incr_empty_stream() { run_check $TOP/mkfs.btrfs -f $TEST_DEV run_check_mount_test_dev - run_check $SUDO_HELPER $TOP/btrfs receive -v -f "$fstr" "$TEST_MNT" - run_check $SUDO_HELPER $TOP/btrfs receive -v -f "$istr" "$TEST_MNT" + run_check $SUDO_HELPER $TOP/btrfs receive "$@" -v -f "$fstr" "$TEST_MNT" + run_check $SUDO_HELPER $TOP/btrfs receive "$@" -v -f "$istr" "$TEST_MNT" run_check_umount_test_dev run_check rm -f -- "$fstr" "$istr" @@ -136,8 +138,8 @@ test_incr_simple_stream() { run_check $TOP/mkfs.btrfs -f $TEST_DEV run_check_mount_test_dev - run_check $SUDO_HELPER $TOP/btrfs receive -v -f "$fstr" "$TEST_MNT" - run_check $SUDO_HELPER $TOP/btrfs receive -v -f "$istr" "$TEST_MNT" + run_check $SUDO_HELPER $TOP/btrfs receive "$@" -v -f "$fstr" "$TEST_MNT" + run_check $SUDO_HELPER $TOP/btrfs receive "$@" -v -f "$istr" "$TEST_MNT" run_check_umount_test_dev run_check rm -f -- "$fstr" "$istr" @@ -147,3 +149,9 @@ test_full_empty_stream test_full_simple_stream test_incr_empty_stream test_incr_simple_stream + +extra_opt=-e +test_full_empty_stream $extra_opt +test_full_simple_stream $extra_opt +test_incr_empty_stream $extra_opt +test_incr_simple_stream $extra_opt -- cgit v1.2.3 From 57909d702c4d636a5f733309202c36fe006d84e9 Mon Sep 17 00:00:00 2001 From: "Lakshmipathi.G" Date: Sat, 15 Apr 2017 15:43:08 +0530 Subject: btrfs-progs: misc-tests: Superblock corruption and recovery using backup Signed-off-by: Lakshmipathi.G Signed-off-by: David Sterba --- .../020-fix-superblock-corruption/test.sh | 34 ++++++++++++++++++++++ 1 file changed, 34 insertions(+) create mode 100755 tests/misc-tests/020-fix-superblock-corruption/test.sh (limited to 'tests') diff --git a/tests/misc-tests/020-fix-superblock-corruption/test.sh b/tests/misc-tests/020-fix-superblock-corruption/test.sh new file mode 100755 index 00000000..77c1a5aa --- /dev/null +++ b/tests/misc-tests/020-fix-superblock-corruption/test.sh @@ -0,0 +1,34 @@ +#!/bin/bash +# +# Corrupt primary superblock and restore it using backup superblock. + +source "$TOP/tests/common" + +check_prereq btrfs-select-super +check_prereq btrfs + +setup_root_helper +prepare_test_dev + +FIRST_SUPERBLOCK_OFFSET=65536 + +test_superblock_restore() +{ + run_check $SUDO_HELPER "$TOP/mkfs.btrfs" -f "$TEST_DEV" + + # Corrupt superblock checksum + run_check $SUDO_HELPER dd if=/dev/zero of="$TEST_DEV" \ + seek="$FIRST_SUPERBLOCK_OFFSET" bs=1 count=4 conv=notrunc + + # Run btrfs check to detect corruption + run_mayfail "$TOP/btrfs" check "$TEST_DEV" && \ + _fail "btrfs check should detect corruption" + + # Copy backup superblock to primary + run_check "$TOP/btrfs-select-super" -s 1 "$TEST_DEV" + + # Perform btrfs check + run_check "$TOP/btrfs" check "$TEST_DEV" +} + +test_superblock_restore -- cgit v1.2.3 From 467b49ccbbb132d4d2ff4fe43d9581b89f349cea Mon Sep 17 00:00:00 2001 From: "Lakshmipathi.G" Date: Mon, 24 Apr 2017 18:59:40 +0530 Subject: btrfs-progs: tests: add variable quotation to fsck-tests Signed-off-by: Lakshmipathi.G Signed-off-by: David Sterba --- tests/fsck-tests/006-bad-root-items/test.sh | 6 +++--- tests/fsck-tests/012-leaf-corruption/test.sh | 24 +++++++++++----------- tests/fsck-tests/013-extent-tree-rebuild/test.sh | 22 ++++++++++---------- tests/fsck-tests/018-leaf-crossing-stripes/test.sh | 4 ++-- .../fsck-tests/019-non-skinny-false-alert/test.sh | 4 ++-- tests/fsck-tests/020-extent-ref-cases/test.sh | 6 +++--- .../021-partially-dropped-snapshot-case/test.sh | 6 +++--- tests/fsck-tests/022-qgroup-rescan-halfway/test.sh | 4 ++-- tests/fsck-tests/023-qgroup-stack-overflow/test.sh | 4 ++-- tests/fsck-tests/024-clear-space-cache/test.sh | 16 +++++++-------- tests/fsck-tests/025-file-extents/test.sh | 2 +- 11 files changed, 49 insertions(+), 49 deletions(-) (limited to 'tests') diff --git a/tests/fsck-tests/006-bad-root-items/test.sh b/tests/fsck-tests/006-bad-root-items/test.sh index 84332348..bf3ef781 100755 --- a/tests/fsck-tests/006-bad-root-items/test.sh +++ b/tests/fsck-tests/006-bad-root-items/test.sh @@ -1,15 +1,15 @@ #!/bin/bash -source $TOP/tests/common +source "$TOP/tests/common" check_prereq btrfs -echo "extracting image default_case.tar.xz" >> $RESULTS +echo "extracting image default_case.tar.xz" >> "$RESULTS" tar --no-same-owner -xJf default_case.tar.xz || \ _fail "failed to extract default_case.tar.xz" check_image test.img -echo "extracting image skinny_case.tar.xz" >> $RESULTS +echo "extracting image skinny_case.tar.xz" >> "$RESULTS" tar --no-same-owner -xJf skinny_case.tar.xz || \ _fail "failed to extract skinny_case.tar.xz" check_image test.img diff --git a/tests/fsck-tests/012-leaf-corruption/test.sh b/tests/fsck-tests/012-leaf-corruption/test.sh index a308727d..43b0e6de 100755 --- a/tests/fsck-tests/012-leaf-corruption/test.sh +++ b/tests/fsck-tests/012-leaf-corruption/test.sh @@ -1,6 +1,6 @@ #!/bin/bash -source $TOP/tests/common +source "$TOP/tests/common" check_prereq btrfs-image @@ -37,16 +37,16 @@ leaf_no_data_ext_list=( generate_leaf_corrupt_no_data_ext() { dest=$1 - echo "generating leaf_corrupt_no_data_ext.btrfs-image" >> $RESULTS + echo "generating leaf_corrupt_no_data_ext.btrfs-image" >> "$RESULTS" tar --no-same-owner -xJf ./no_data_extent.tar.xz || \ _fail "failed to extract leaf_corrupt_no_data_ext.btrfs-image" - $TOP/btrfs-image -r test.img.btrfs-image $dest || \ + "$TOP/btrfs-image" -r test.img.btrfs-image "$dest" || \ _fail "failed to extract leaf_corrupt_no_data_ext.btrfs-image" # leaf at 4206592 and 20905984 contains no regular data # extent, clear its csum to corrupt the leaf. for x in 4206592 20905984; do - dd if=/dev/zero of=$dest bs=1 count=32 conv=notrunc seek=$x \ + dd if=/dev/zero of="$dest" bs=1 count=32 conv=notrunc seek="$x" \ 1>/dev/null 2>&1 done } @@ -60,21 +60,21 @@ check_inode() name=$5 # Check whether the inode exists - exists=$($SUDO_HELPER find $path -inum $ino) + exists=$($SUDO_HELPER find "$path" -inum "$ino") if [ -z "$exists" ]; then _fail "inode $ino not recovered correctly" fi # Check inode type - found_mode=$(printf "%o" 0x$($SUDO_HELPER stat $exists -c %f)) - if [ $found_mode -ne $mode ]; then + found_mode=$(printf "%o" 0x$($SUDO_HELPER stat "$exists" -c %f)) + if [ "$found_mode" -ne "$mode" ]; then echo "$found_mode" _fail "inode $ino modes not recovered" fi # Check inode size - found_size=$($SUDO_HELPER stat $exists -c %s) - if [ $mode -ne 41700 -a $found_size -ne $size ]; then + found_size=$($SUDO_HELPER stat "$exists" -c %s) + if [ $mode -ne 41700 -a "$found_size" -ne "$size" ]; then _fail "inode $ino size not recovered correctly" fi @@ -90,11 +90,11 @@ check_inode() check_leaf_corrupt_no_data_ext() { image=$1 - $SUDO_HELPER mount -o loop $image -o ro $TEST_MNT + $SUDO_HELPER mount -o loop "$image" -o ro "$TEST_MNT" i=0 while [ $i -lt ${#leaf_no_data_ext_list[@]} ]; do - check_inode $TEST_MNT/lost+found \ + check_inode "$TEST_MNT/lost+found" \ ${leaf_no_data_ext_list[i]} \ ${leaf_no_data_ext_list[i + 1]} \ ${leaf_no_data_ext_list[i + 2]} \ @@ -102,7 +102,7 @@ check_leaf_corrupt_no_data_ext() ${leaf_no_data_ext_list[i + 4]} ((i+=4)) done - $SUDO_HELPER umount $TEST_MNT + $SUDO_HELPER umount "$TEST_MNT" } setup_root_helper diff --git a/tests/fsck-tests/013-extent-tree-rebuild/test.sh b/tests/fsck-tests/013-extent-tree-rebuild/test.sh index 08c1e50e..90fe2e83 100755 --- a/tests/fsck-tests/013-extent-tree-rebuild/test.sh +++ b/tests/fsck-tests/013-extent-tree-rebuild/test.sh @@ -1,6 +1,6 @@ #!/bin/bash -source $TOP/tests/common +source "$TOP/tests/common" check_prereq btrfs-corrupt-block check_prereq mkfs.btrfs @@ -12,32 +12,32 @@ prepare_test_dev 1G # test whether fsck can rebuild a corrupted extent tree test_extent_tree_rebuild() { - run_check $SUDO_HELPER $TOP/mkfs.btrfs -f $TEST_DEV + run_check $SUDO_HELPER "$TOP/mkfs.btrfs" -f "$TEST_DEV" run_check_mount_test_dev generate_dataset small for i in `seq 1 100`;do - run_check $SUDO_HELPER $TOP/btrfs sub snapshot $TEST_MNT \ - $TEST_MNT/snapaaaaaaa_$i + run_check $SUDO_HELPER "$TOP/btrfs" sub snapshot "$TEST_MNT" \ + "$TEST_MNT/snapaaaaaaa_$i" done run_check_umount_test_dev # get extent root bytenr - extent_root_bytenr=`$SUDO_HELPER $TOP/btrfs inspect-internal dump-tree -r $TEST_DEV | \ + extent_root_bytenr=`$SUDO_HELPER "$TOP/btrfs" inspect-internal dump-tree -r "$TEST_DEV" | \ grep extent | awk '{print $7}'` - if [ -z $extent_root_bytenr ];then + if [ -z "$extent_root_bytenr" ];then _fail "fail to get extent root bytenr" fi # corrupt extent root node block - run_check $SUDO_HELPER $TOP/btrfs-corrupt-block -l $extent_root_bytenr \ - -b 4096 $TEST_DEV + run_check $SUDO_HELPER "$TOP/btrfs-corrupt-block" -l "$extent_root_bytenr" \ + -b 4096 "$TEST_DEV" - $SUDO_HELPER $TOP/btrfs check $TEST_DEV >& /dev/null && \ + $SUDO_HELPER "$TOP/btrfs" check "$TEST_DEV" >& /dev/null && \ _fail "btrfs check should detect failure" - run_check $SUDO_HELPER $TOP/btrfs check --repair --init-extent-tree $TEST_DEV - run_check $SUDO_HELPER $TOP/btrfs check $TEST_DEV + run_check $SUDO_HELPER "$TOP/btrfs" check --repair --init-extent-tree "$TEST_DEV" + run_check $SUDO_HELPER "$TOP/btrfs" check "$TEST_DEV" } test_extent_tree_rebuild diff --git a/tests/fsck-tests/018-leaf-crossing-stripes/test.sh b/tests/fsck-tests/018-leaf-crossing-stripes/test.sh index c453ab5c..29eb20b5 100755 --- a/tests/fsck-tests/018-leaf-crossing-stripes/test.sh +++ b/tests/fsck-tests/018-leaf-crossing-stripes/test.sh @@ -1,11 +1,11 @@ #!/bin/bash -source $TOP/tests/common +source "$TOP/tests/common" check_prereq btrfs image=$(extract_image "./default_case.raw.xz") -run_check_stdout $TOP/btrfs check "$image" 2>&1 | +run_check_stdout "$TOP/btrfs" check "$image" 2>&1 | grep -q "crossing stripe boundary" || _fail "no expected error message in the output" diff --git a/tests/fsck-tests/019-non-skinny-false-alert/test.sh b/tests/fsck-tests/019-non-skinny-false-alert/test.sh index a7f8e862..550f2947 100755 --- a/tests/fsck-tests/019-non-skinny-false-alert/test.sh +++ b/tests/fsck-tests/019-non-skinny-false-alert/test.sh @@ -11,12 +11,12 @@ # # a buggy check leads to the above messages -source $TOP/tests/common +source "$TOP/tests/common" check_prereq btrfs image=$(extract_image "./default_case.img.xz") -run_check_stdout $TOP/btrfs check "$image" 2>&1 | +run_check_stdout "$TOP/btrfs" check "$image" 2>&1 | grep -q "type mismatch with chunk" && _fail "unexpected error message in the output" diff --git a/tests/fsck-tests/020-extent-ref-cases/test.sh b/tests/fsck-tests/020-extent-ref-cases/test.sh index 5dc5e55d..1e1e4e23 100755 --- a/tests/fsck-tests/020-extent-ref-cases/test.sh +++ b/tests/fsck-tests/020-extent-ref-cases/test.sh @@ -15,16 +15,16 @@ # the beginning of leaf. # Which caused false alert for lowmem mode. -source $TOP/tests/common +source "$TOP/tests/common" check_prereq btrfs for img in *.img *.raw.xz do - image=$(extract_image $img) + image=$(extract_image "$img") # Since the return value bug is already fixed, we don't need # the old grep hack to detect bug. - run_check $TOP/btrfs check "$image" + run_check "$TOP/btrfs" check "$image" rm -f "$image" done diff --git a/tests/fsck-tests/021-partially-dropped-snapshot-case/test.sh b/tests/fsck-tests/021-partially-dropped-snapshot-case/test.sh index eb8d8849..44a33a63 100755 --- a/tests/fsck-tests/021-partially-dropped-snapshot-case/test.sh +++ b/tests/fsck-tests/021-partially-dropped-snapshot-case/test.sh @@ -1,14 +1,14 @@ #!/bin/bash # confirm whether btrfsck supports to check a partially dropped snapshot -source $TOP/tests/common +source "$TOP/tests/common" check_prereq btrfs for img in *.img do - image=$(extract_image $img) - run_check_stdout $TOP/btrfs check "$image" 2>&1 | + image=$(extract_image "$img") + run_check_stdout "$TOP/btrfs" check "$image" 2>&1 | grep -q "Errors found in extent allocation tree or chunk allocation" if [ $? -eq 0 ]; then rm -f "$image" diff --git a/tests/fsck-tests/022-qgroup-rescan-halfway/test.sh b/tests/fsck-tests/022-qgroup-rescan-halfway/test.sh index 1dc8f8fc..dcdc1b42 100755 --- a/tests/fsck-tests/022-qgroup-rescan-halfway/test.sh +++ b/tests/fsck-tests/022-qgroup-rescan-halfway/test.sh @@ -1,7 +1,7 @@ #!/bin/bash # check whether btrfsck can detect running qgroup rescan -source $TOP/tests/common +source "$TOP/tests/common" check_prereq btrfs @@ -9,7 +9,7 @@ check_image() { local image image=$1 - run_check_stdout $TOP/btrfs check "$image" 2>&1 | \ + run_check_stdout "$TOP/btrfs" check "$image" 2>&1 | \ grep -q "Counts for qgroup id" if [ $? -eq 0 ]; then _fail "Btrfs check doesn't detect rescan correctly" diff --git a/tests/fsck-tests/023-qgroup-stack-overflow/test.sh b/tests/fsck-tests/023-qgroup-stack-overflow/test.sh index a304eac5..ebb07f36 100755 --- a/tests/fsck-tests/023-qgroup-stack-overflow/test.sh +++ b/tests/fsck-tests/023-qgroup-stack-overflow/test.sh @@ -5,13 +5,13 @@ # Fixed by patch: # btrfs-progs: Fix stack overflow for checking qgroup on tree reloc tree -source $TOP/tests/common +source "$TOP/tests/common" check_prereq btrfs check_image() { - run_check $TOP/btrfs check "$1" + run_check "$TOP/btrfs" check "$1" } check_all_images diff --git a/tests/fsck-tests/024-clear-space-cache/test.sh b/tests/fsck-tests/024-clear-space-cache/test.sh index 2945ae87..6cf8440b 100755 --- a/tests/fsck-tests/024-clear-space-cache/test.sh +++ b/tests/fsck-tests/024-clear-space-cache/test.sh @@ -1,7 +1,7 @@ #!/bin/bash # confirm that clearing space cache works -source $TOP/tests/common +source "$TOP/tests/common" check_prereq btrfs check_prereq mkfs.btrfs @@ -9,21 +9,21 @@ check_prereq mkfs.btrfs setup_root_helper prepare_test_dev 1G -run_check $SUDO_HELPER $TOP/mkfs.btrfs -f $TEST_DEV +run_check $SUDO_HELPER "$TOP/mkfs.btrfs" -f "$TEST_DEV" run_check_mount_test_dev # Create files that takes at least 3 data chunks, while # can still be removed to create free space inside one chunk. for i in $(seq 0 6); do - run_check $SUDO_HELPER dd if=/dev/zero of=$TEST_MNT/file_${i} bs=1M \ + run_check $SUDO_HELPER dd if=/dev/zero of="$TEST_MNT/file_${i}" bs=1M \ count=64 > /dev/null 2>&1 done sync # Remove file 1 3 5 to create holes for i in 1 3 5; do - run_check $SUDO_HELPER rm $TEST_MNT/file_${i} + run_check $SUDO_HELPER rm "$TEST_MNT/file_${i}" done sync @@ -31,17 +31,17 @@ sync run_check_umount_test_dev # Clear space cache and re-check fs -run_check $TOP/btrfs check --clear-space-cache v1 $TEST_DEV -run_check $TOP/btrfs check $TEST_DEV +run_check "$TOP/btrfs" check --clear-space-cache v1 "$TEST_DEV" +run_check "$TOP/btrfs" check "$TEST_DEV" # Manually recheck space cache and super space cache generation -run_check_stdout $TOP/btrfs inspect-internal dump-tree -t root $TEST_DEV | \ +run_check_stdout "$TOP/btrfs" inspect-internal dump-tree -t root "$TEST_DEV" | \ grep -q FREE_SPACE if [ $? -eq 0 ]; then _fail "clear space cache doesn't clear all space cache" fi -run_check_stdout $TOP/btrfs inspect-internal dump-super $TEST_DEV | +run_check_stdout $TOP/btrfs inspect-internal dump-super "$TEST_DEV" | grep -q 'cache_generation.*18446744073709551615' if [ $? -ne 0 ]; then _fail "clear space cache doesn't set cache_generation correctly" diff --git a/tests/fsck-tests/025-file-extents/test.sh b/tests/fsck-tests/025-file-extents/test.sh index 290464e0..e4bc4247 100755 --- a/tests/fsck-tests/025-file-extents/test.sh +++ b/tests/fsck-tests/025-file-extents/test.sh @@ -1,7 +1,7 @@ #!/bin/bash # Confirm btrfs check can check file extents without causing false alert -source $TOP/tests/common +source "$TOP/tests/common" check_prereq btrfs check_prereq mkfs.btrfs -- cgit v1.2.3 From fd4526fe686421b8844089ed058167d0724a36c0 Mon Sep 17 00:00:00 2001 From: Lu Fengqi Date: Wed, 26 Apr 2017 09:22:41 +0800 Subject: btrfs-progs: tests: fssum, fix memory leak Free the alloced memory and close dir before exit. Signed-off-by: Lu Fengqi Signed-off-by: David Sterba --- tests/fssum.c | 35 ++++++++++++++++++++++++++++++----- 1 file changed, 30 insertions(+), 5 deletions(-) (limited to 'tests') diff --git a/tests/fssum.c b/tests/fssum.c index 83bd4106..8be44547 100644 --- a/tests/fssum.c +++ b/tests/fssum.c @@ -420,6 +420,9 @@ check_manifest(char *fn, char *m, char *c, int last_call) while ((l = getln(line, sizeof(line), in_fp))) { rem_c = strrchr(l, ' '); if (!rem_c) { + if (checksum) + free(checksum); + /* final cs */ checksum = strdup(l); break; @@ -503,6 +506,7 @@ sum(int dirfd, int level, sum_t *dircs, char *path_prefix, char *path_in) } ++entries; } + qsort(namelist, entries, sizeof(*namelist), namecmp); for (i = 0; i < entries; ++i) { struct stat64 st; @@ -624,7 +628,11 @@ sum(int dirfd, int level, sum_t *dircs, char *path_prefix, char *path_in) sum_add_sum(dircs, &meta); next: free(path); + free(namelist[i]); } + + free(namelist); + closedir(d); } int @@ -636,7 +644,9 @@ main(int argc, char *argv[]) char *path; int fd; sum_t cs; + char *sumstring; char flagstring[sizeof(flchar)]; + int ret = 0; int i; int plen; int elen; @@ -736,6 +746,9 @@ main(int argc, char *argv[]) } else if ((p = strchr(l, ':'))) { *p++ = 0; parse_flags(l); + + if (checksum) + free(checksum); checksum = strdup(p); } else { fprintf(stderr, "invalid input file format\n"); @@ -798,16 +811,28 @@ main(int argc, char *argv[]) if (!gen_manifest) fprintf(out_fp, "%s:", flagstring); - fprintf(out_fp, "%s\n", sum_to_string(&cs)); + sumstring = sum_to_string(&cs); + fprintf(out_fp, "%s\n", sumstring); + free(sumstring); } else { - if (strcmp(checksum, sum_to_string(&cs)) == 0) { + sumstring = sum_to_string(&cs); + if (strcmp(checksum, sumstring) == 0) { printf("OK\n"); - exit(0); + ret = 0; } else { printf("FAIL\n"); - exit(1); + ret = 1; } + + free(checksum); + free(sumstring); } - exit(0); + if (in_fp) + fclose(in_fp); + + if (out_fp != stdout) + fclose(out_fp); + + exit(ret); } -- cgit v1.2.3 From b75c0720a41b95e0a2e37aa3bc5591454ded65b8 Mon Sep 17 00:00:00 2001 From: David Sterba Date: Tue, 2 May 2017 16:23:54 +0200 Subject: btrfs-progs: fssum: fix warning, include correct header for major() tests/fssum.c:599:13: warning: In the GNU C Library, "major" is defined by . For historical compatibility, it is currently defined by as well, but we plan to remove this soon. To use "major", include directly. If you did not intend to use a system-defined macro "major", you should undefine it after including . sum_add_u64(&cs, major(st.st_rdev)); Signed-off-by: David Sterba --- tests/fssum.c | 1 + 1 file changed, 1 insertion(+) (limited to 'tests') diff --git a/tests/fssum.c b/tests/fssum.c index 8be44547..5dde9984 100644 --- a/tests/fssum.c +++ b/tests/fssum.c @@ -24,6 +24,7 @@ #include #include #include +#include #include #include #include -- cgit v1.2.3 From ca1be56db5b6ec8ccad36c3bc4bf215757350e92 Mon Sep 17 00:00:00 2001 From: "Lakshmipathi.G" Date: Mon, 24 Apr 2017 00:30:00 +0530 Subject: btrfs-progs: tests: add variable quotation to convert-tests Signed-off-by: Lakshmipathi.G Signed-off-by: David Sterba --- tests/convert-tests/001-ext2-basic/test.sh | 4 ++-- tests/convert-tests/002-ext3-basic/test.sh | 4 ++-- tests/convert-tests/003-ext4-basic/test.sh | 4 ++-- .../004-ext2-backup-superblock-ranges/test.sh | 22 +++++++++++----------- .../convert-tests/005-delete-all-rollback/test.sh | 6 +++--- tests/convert-tests/006-large-hole-extent/test.sh | 6 +++--- .../007-unsupported-block-sizes/test.sh | 8 ++++---- tests/convert-tests/008-readonly-image/test.sh | 8 ++++---- tests/convert-tests/009-common-inode-flags/test.sh | 14 +++++++------- 9 files changed, 38 insertions(+), 38 deletions(-) (limited to 'tests') diff --git a/tests/convert-tests/001-ext2-basic/test.sh b/tests/convert-tests/001-ext2-basic/test.sh index 8f4f935d..07f1d6e8 100755 --- a/tests/convert-tests/001-ext2-basic/test.sh +++ b/tests/convert-tests/001-ext2-basic/test.sh @@ -1,7 +1,7 @@ #!/bin/bash -source $TOP/tests/common -source $TOP/tests/common.convert +source "$TOP/tests/common" +source "$TOP/tests/common.convert" setup_root_helper prepare_test_dev 512M diff --git a/tests/convert-tests/002-ext3-basic/test.sh b/tests/convert-tests/002-ext3-basic/test.sh index aeb111eb..be8a9291 100755 --- a/tests/convert-tests/002-ext3-basic/test.sh +++ b/tests/convert-tests/002-ext3-basic/test.sh @@ -1,7 +1,7 @@ #!/bin/bash -source $TOP/tests/common -source $TOP/tests/common.convert +source "$TOP/tests/common" +source "$TOP/tests/common.convert" setup_root_helper prepare_test_dev 512M diff --git a/tests/convert-tests/003-ext4-basic/test.sh b/tests/convert-tests/003-ext4-basic/test.sh index 531c81bd..44ee592d 100755 --- a/tests/convert-tests/003-ext4-basic/test.sh +++ b/tests/convert-tests/003-ext4-basic/test.sh @@ -1,7 +1,7 @@ #!/bin/bash -source $TOP/tests/common -source $TOP/tests/common.convert +source "$TOP/tests/common" +source "$TOP/tests/common.convert" setup_root_helper prepare_test_dev 512M diff --git a/tests/convert-tests/004-ext2-backup-superblock-ranges/test.sh b/tests/convert-tests/004-ext2-backup-superblock-ranges/test.sh index c56650b2..0ce62f78 100755 --- a/tests/convert-tests/004-ext2-backup-superblock-ranges/test.sh +++ b/tests/convert-tests/004-ext2-backup-superblock-ranges/test.sh @@ -10,7 +10,7 @@ # 4) Overlap file extents # 5) Unable to rollback -source $TOP/tests/common +source "$TOP/tests/common" check_prereq btrfs-convert check_prereq btrfs @@ -23,20 +23,20 @@ prepare_test_dev 512M # override common function function check_image() { TEST_DEV="$1" - run_check e2fsck -n -f $TEST_DEV - run_check $TOP/btrfs-convert $TEST_DEV - run_check $TOP/btrfs check $TEST_DEV - run_check $TOP/btrfs inspect-internal dump-super $TEST_DEV + run_check e2fsck -n -f "$TEST_DEV" + run_check "$TOP/btrfs-convert" "$TEST_DEV" + run_check "$TOP/btrfs" check "$TEST_DEV" + run_check "$TOP/btrfs" inspect-internal dump-super "$TEST_DEV" run_check_mount_test_dev - run_check $SUDO_HELPER e2fsck -n -f $TEST_MNT/ext2_saved/image - run_check $SUDO_HELPER umount $TEST_MNT + run_check $SUDO_HELPER e2fsck -n -f "$TEST_MNT/ext2_saved/image" + run_check $SUDO_HELPER umount "$TEST_MNT" - run_check $TOP/btrfs check $TEST_DEV - run_check $TOP/btrfs-convert -r $TEST_DEV - run_check e2fsck -n -f $TEST_DEV + run_check "$TOP/btrfs" check "$TEST_DEV" + run_check "$TOP/btrfs-convert" -r "$TEST_DEV" + run_check e2fsck -n -f "$TEST_DEV" - rm -f $TEST_DEV + rm -f "$TEST_DEV" } check_all_images diff --git a/tests/convert-tests/005-delete-all-rollback/test.sh b/tests/convert-tests/005-delete-all-rollback/test.sh index cf576e70..c6f7466a 100755 --- a/tests/convert-tests/005-delete-all-rollback/test.sh +++ b/tests/convert-tests/005-delete-all-rollback/test.sh @@ -2,8 +2,8 @@ # create a base image, convert to btrfs, remove all files, rollback the ext4 image # note: ext4 only -source $TOP/tests/common -source $TOP/tests/common.convert +source "$TOP/tests/common" +source "$TOP/tests/common.convert" setup_root_helper prepare_test_dev 512M @@ -43,7 +43,7 @@ do_test() { # ext2_saved/image must not be deleted run_mayfail $SUDO_HELPER find "$TEST_MNT"/ -mindepth 1 -path '*ext2_saved' -prune -o -exec rm -vrf "{}" \; cd "$here" - run_check $TOP/btrfs filesystem sync "$TEST_MNT" + run_check "$TOP/btrfs" filesystem sync "$TEST_MNT" run_check_umount_test_dev convert_test_post_rollback diff --git a/tests/convert-tests/006-large-hole-extent/test.sh b/tests/convert-tests/006-large-hole-extent/test.sh index d3bc093c..e99741cc 100755 --- a/tests/convert-tests/006-large-hole-extent/test.sh +++ b/tests/convert-tests/006-large-hole-extent/test.sh @@ -5,8 +5,8 @@ # Fast pinpoint regression test. No options combination nor checksum # verification -source $TOP/tests/common -source $TOP/tests/common.convert +source "$TOP/tests/common" +source "$TOP/tests/common.convert" setup_root_helper prepare_test_dev 512M @@ -16,7 +16,7 @@ default_mke2fs="mke2fs -t ext4 -b 4096" convert_test_preamble '' 'large hole extent test' 16k "$default_mke2fs" convert_test_prep_fs $default_mke2fs -run_check $SUDO_HELPER dd if=/dev/zero of=$TEST_MNT/file bs=1M \ +run_check $SUDO_HELPER dd if=/dev/zero of="$TEST_MNT/file" bs=1M \ count=1 seek=1024 > /dev/null 2>&1 run_check_umount_test_dev diff --git a/tests/convert-tests/007-unsupported-block-sizes/test.sh b/tests/convert-tests/007-unsupported-block-sizes/test.sh index 9ba17751..a7488407 100755 --- a/tests/convert-tests/007-unsupported-block-sizes/test.sh +++ b/tests/convert-tests/007-unsupported-block-sizes/test.sh @@ -1,8 +1,8 @@ #!/bin/bash # Check if block sizes smaller than 4k expectedly fail to convert -source $TOP/tests/common -source $TOP/tests/common.convert +source "$TOP/tests/common" +source "$TOP/tests/common.convert" setup_root_helper prepare_test_dev 512M @@ -13,9 +13,9 @@ for bs in 1024 2048; do convert_test_preamble '' "unsupported block size $bs" 16k "$default_mke2fs" convert_test_prep_fs $default_mke2fs - run_check $SUDO_HELPER dd if=/dev/zero of=$TEST_MNT/file bs=1M \ + run_check $SUDO_HELPER dd if=/dev/zero of="$TEST_MNT/file" bs=1M \ count=1 seek=1024 > /dev/null 2>&1 run_check_umount_test_dev - run_mustfail "$bs block converted" $TOP/btrfs-convert $TEST_DEV + run_mustfail "$bs block converted" "$TOP/btrfs-convert" "$TEST_DEV" done diff --git a/tests/convert-tests/008-readonly-image/test.sh b/tests/convert-tests/008-readonly-image/test.sh index 4e422378..b2f1ae37 100755 --- a/tests/convert-tests/008-readonly-image/test.sh +++ b/tests/convert-tests/008-readonly-image/test.sh @@ -1,8 +1,8 @@ #!/bin/bash # Check if the converted ext2 image is readonly -source $TOP/tests/common -source $TOP/tests/common.convert +source "$TOP/tests/common" +source "$TOP/tests/common.convert" setup_root_helper prepare_test_dev 512M @@ -10,13 +10,13 @@ check_prereq btrfs-convert default_mke2fs="mke2fs -t ext4 -b 4096" convert_test_preamble '' 'readonly image test' 16k "$default_mke2fs" -convert_test_prep_fs $default_mke2fs +convert_test_prep_fs "$default_mke2fs" run_check_umount_test_dev convert_test_do_convert run_check_mount_test_dev # It's expected to fail -$SUDO_HELPER dd if=/dev/zero of=$TEST_MNT/ext2_save/image bs=1M count=1 \ +$SUDO_HELPER dd if=/dev/zero of="$TEST_MNT/ext2_save/image" bs=1M count=1 \ &> /dev/null if [ $? -ne 1 ]; then echo "after convert ext2_save/image is not read-only" diff --git a/tests/convert-tests/009-common-inode-flags/test.sh b/tests/convert-tests/009-common-inode-flags/test.sh index 6f26d187..a5828790 100755 --- a/tests/convert-tests/009-common-inode-flags/test.sh +++ b/tests/convert-tests/009-common-inode-flags/test.sh @@ -1,8 +1,8 @@ #!/bin/bash # Check if btrfs-convert can copy common inode flags like SYNC/IMMUTABLE -source $TOP/tests/common -source $TOP/tests/common.convert +source "$TOP/tests/common" +source "$TOP/tests/common.convert" setup_root_helper prepare_test_dev 512M @@ -11,20 +11,20 @@ check_prereq btrfs-convert fail=0 default_mke2fs="mke2fs -t ext4 -b 4096" convert_test_preamble '' 'common inode flags test' 16k "$default_mke2fs" -convert_test_prep_fs $default_mke2fs +convert_test_prep_fs "$default_mke2fs" # create file with specific flags -run_check $SUDO_HELPER touch $TEST_MNT/flag_test -run_check $SUDO_HELPER chattr +aAdSi $TEST_MNT/flag_test +run_check $SUDO_HELPER touch "$TEST_MNT/flag_test" +run_check $SUDO_HELPER chattr +aAdSi "$TEST_MNT/flag_test" run_check_umount_test_dev convert_test_do_convert run_check_mount_test_dev # Log the status -run_check lsattr $TEST_MNT/flag_test +run_check lsattr "$TEST_MNT/flag_test" # Above flags should be copied to btrfs flags, and lsattr should get them -run_check_stdout lsattr $TEST_MNT/flag_test | cut -f1 -d\ | grep "[aAdiS]" -q +run_check_stdout lsattr "$TEST_MNT/flag_test" | cut -f1 -d\ | grep "[aAdiS]" -q if [ $? -ne 0 ]; then rm tmp_output _fail "no common inode flags are copied after convert" -- cgit v1.2.3 From 68d303bdbb919a52e715c6f7f8c8378473600572 Mon Sep 17 00:00:00 2001 From: David Sterba Date: Mon, 15 May 2017 16:34:31 +0200 Subject: btrfs-progs: tests: fix misc/019-receive-clones-on-munted-subvol Patches "btrfs-progs: tests: correctly receive clones to mounted subvol" (8eaf63bc9a7b957c566be23df7c6701a9a5b22a2) and followup are missing last unmount which leads to failure of misc/020. Signed-off-by: David Sterba --- tests/misc-tests/019-receive-clones-on-munted-subvol/test.sh | 2 ++ 1 file changed, 2 insertions(+) (limited to 'tests') diff --git a/tests/misc-tests/019-receive-clones-on-munted-subvol/test.sh b/tests/misc-tests/019-receive-clones-on-munted-subvol/test.sh index 3a572439..182b0cf9 100755 --- a/tests/misc-tests/019-receive-clones-on-munted-subvol/test.sh +++ b/tests/misc-tests/019-receive-clones-on-munted-subvol/test.sh @@ -122,4 +122,6 @@ run_check $FSSUM_PROG -r "$srcdir/foo.1.fssum" "$TEST_MNT/foo.1" run_check $FSSUM_PROG -r "$srcdir/bar.0.fssum" "$TEST_MNT/bar.0" run_check $FSSUM_PROG -r "$srcdir/baz.0.fssum" "$TEST_MNT/baz.0" +run_check_umount_test_dev + rm -rf -- "$srcdir" -- cgit v1.2.3 From 8dcc1b6f6526638eeae0f3121deb1a630ad4a400 Mon Sep 17 00:00:00 2001 From: Tsutomu Itoh Date: Tue, 16 May 2017 12:01:53 +0900 Subject: btrfs-progs: tests: remove variable quotation from convert-tests In btrfs-progs-v4.11-rc1, the following convert-tests failed. [TEST/conv] 008-readonly-image [TEST/conv] readonly image test, btrfs defaults failed: mke2fs -t ext4 -b 4096 -F /Build/btrfs-progs-v4.11-rc1/tests/test.img test failed for case 008-readonly-image Makefile:271: recipe for target 'test-convert' failed make: *** [test-convert] Error 1 [TEST/conv] 009-common-inode-flags [TEST/conv] common inode flags test, btrfs defaults failed: mke2fs -t ext4 -b 4096 -F /Build/btrfs-progs-v4.11-rc1/tests/test.img test failed for case 009-common-inode-flags Makefile:271: recipe for target 'test-convert' failed make: *** [test-convert] Error 1 So, remove quotes from $default_mke2fs. Signed-off-by: Tsutomu Itoh Signed-off-by: David Sterba --- tests/convert-tests/008-readonly-image/test.sh | 2 +- tests/convert-tests/009-common-inode-flags/test.sh | 2 +- 2 files changed, 2 insertions(+), 2 deletions(-) (limited to 'tests') diff --git a/tests/convert-tests/008-readonly-image/test.sh b/tests/convert-tests/008-readonly-image/test.sh index b2f1ae37..27c9373e 100755 --- a/tests/convert-tests/008-readonly-image/test.sh +++ b/tests/convert-tests/008-readonly-image/test.sh @@ -10,7 +10,7 @@ check_prereq btrfs-convert default_mke2fs="mke2fs -t ext4 -b 4096" convert_test_preamble '' 'readonly image test' 16k "$default_mke2fs" -convert_test_prep_fs "$default_mke2fs" +convert_test_prep_fs $default_mke2fs run_check_umount_test_dev convert_test_do_convert run_check_mount_test_dev diff --git a/tests/convert-tests/009-common-inode-flags/test.sh b/tests/convert-tests/009-common-inode-flags/test.sh index a5828790..02823e14 100755 --- a/tests/convert-tests/009-common-inode-flags/test.sh +++ b/tests/convert-tests/009-common-inode-flags/test.sh @@ -11,7 +11,7 @@ check_prereq btrfs-convert fail=0 default_mke2fs="mke2fs -t ext4 -b 4096" convert_test_preamble '' 'common inode flags test' 16k "$default_mke2fs" -convert_test_prep_fs "$default_mke2fs" +convert_test_prep_fs $default_mke2fs # create file with specific flags run_check $SUDO_HELPER touch "$TEST_MNT/flag_test" -- cgit v1.2.3 From c1c987503412a8e98e40da2548c6b78888535641 Mon Sep 17 00:00:00 2001 From: Filipe Manana Date: Wed, 17 May 2017 02:41:31 +0100 Subject: btrfs-progs: test for restoring multiple devices fs into a single device Test that we are able to create an image from a multiple devices fs, that we are able to restore that image into a single device and finally that we are able to mount it. Signed-off-by: Filipe Manana Reviewed-by: Liu Bo [ added shell quotation and chmod a+w so testsuite on NFS works ] Signed-off-by: David Sterba --- tests/misc-tests/021-image-multi-devices/test.sh | 50 ++++++++++++++++++++++++ 1 file changed, 50 insertions(+) create mode 100755 tests/misc-tests/021-image-multi-devices/test.sh (limited to 'tests') diff --git a/tests/misc-tests/021-image-multi-devices/test.sh b/tests/misc-tests/021-image-multi-devices/test.sh new file mode 100755 index 00000000..abf67f90 --- /dev/null +++ b/tests/misc-tests/021-image-multi-devices/test.sh @@ -0,0 +1,50 @@ +#!/bin/bash +# Test btrfs-image with multiple devices filesystem and verify that restoring +# the created image works against a single device. + +source "$TOP/tests/common" + +check_prereq btrfs-image +check_prereq mkfs.btrfs +check_prereq btrfs + +setup_root_helper + +rm -f dev1 dev2 +run_check truncate -s 2G dev1 +run_check truncate -s 2G dev2 +chmod a+w dev1 dev2 + +loop1=$(run_check_stdout $SUDO_HELPER losetup --find --show dev1) +loop2=$(run_check_stdout $SUDO_HELPER losetup --find --show dev2) + +# Create the test file system. + +run_check $SUDO_HELPER "$TOP/mkfs.btrfs" -f $loop1 $loop2 +run_check $SUDO_HELPER mount $loop1 "$TEST_MNT" +run_check $SUDO_HELPER dd bs=1M count=1 if=/dev/zero "of=$TEST_MNT/foobar" +orig_md5=$(run_check_stdout md5sum "$TEST_MNT/foobar" | cut -d ' ' -f 1) +run_check $SUDO_HELPER umount "$TEST_MNT" + +# Create the image to restore later. +run_check $SUDO_HELPER "$TOP/btrfs-image" $loop1 "$IMAGE" + +# Wipe out the filesystem from the devices, restore the image on a single +# device, check everything works and file foobar is there and with 1Mb of +# zeroes. +run_check $SUDO_HELPER wipefs -a $loop1 +run_check $SUDO_HELPER wipefs -a $loop2 + +run_check $SUDO_HELPER $TOP/btrfs-image -r "$IMAGE" $loop1 + +run_check $SUDO_HELPER mount $loop1 "$TEST_MNT" +new_md5=$(run_check_stdout md5sum "$TEST_MNT/foobar" | cut -d ' ' -f 1) +run_check $SUDO_HELPER umount "$TEST_MNT" + +# Cleanup loop devices. +run_check $SUDO_HELPER losetup -d $loop1 +run_check $SUDO_HELPER losetup -d $loop2 +rm -f dev1 dev2 + +# Compare the file digests. +[ $orig_md5 == $new_md5 ] || _fail "File digests do not match" -- cgit v1.2.3 From bb305ae832c4864af85339a3d4947394d4edfb1d Mon Sep 17 00:00:00 2001 From: Qu Wenruo Date: Fri, 16 Jun 2017 09:43:23 +0800 Subject: btrfs-progs: tests: Add test case to check file hole extents with NO_HOLES flag Add test case which we have NO_HOLES incompat flag while still have hole file extent. This can be created by enabling NO_HOLES feature on an existing filesystem, which lowmem mode would cause false alert for it. Signed-off-by: Qu Wenruo [ minor adjustments ] Signed-off-by: David Sterba --- tests/fsck-tests/025-file-extents/test.sh | 18 ++++++++++++++++++ 1 file changed, 18 insertions(+) (limited to 'tests') diff --git a/tests/fsck-tests/025-file-extents/test.sh b/tests/fsck-tests/025-file-extents/test.sh index e4bc4247..ebe8a305 100755 --- a/tests/fsck-tests/025-file-extents/test.sh +++ b/tests/fsck-tests/025-file-extents/test.sh @@ -5,8 +5,10 @@ source "$TOP/tests/common" check_prereq btrfs check_prereq mkfs.btrfs +check_prereq btrfstune check_global_prereq dd check_global_prereq fallocate +check_global_prereq truncate setup_root_helper prepare_test_dev 128M @@ -38,5 +40,21 @@ test_compressed_inline_extent() run_check "$TOP/btrfs" check "$TEST_DEV" } +# File extent hole with NO_HOLES incompat feature set. +# Lowmem mode will cause a false alert as it doesn't allow any file hole +# extents, while we can set NO_HOLES at anytime we want, it's definitely a +# false alert +test_hole_extent_with_no_holes_flag() +{ + run_check $SUDO_HELPER "$TOP/mkfs.btrfs" -f "$TEST_DEV" + run_check_mount_test_dev + + run_check $SUDO_HELPER truncate -s 16K "$TEST_MNT/tmp" + run_check_umount_test_dev + run_check $SUDO_HELPER "$TOP/btrfstune" -n "$TEST_DEV" + run_check "$TOP/btrfs" check "$TEST_DEV" +} + test_paritical_write_into_prealloc test_compressed_inline_extent +test_hole_extent_with_no_holes_flag -- cgit v1.2.3 From 50d037b4590ea8eea376d19ad89c152776b4225c Mon Sep 17 00:00:00 2001 From: Adam Buchbinder Date: Mon, 10 Jul 2017 14:29:08 -0700 Subject: btrfs-progs: tests: Fix missing internal deps in check and misc tests Doing a straight 'make test' would fail because some misc and fsck tests require particular tools to already be built. Add dependencies at the Makefile and shell-script level. Signed-off-by: Adam Buchbinder Signed-off-by: David Sterba --- tests/fsck-tests.sh | 1 + tests/misc-tests.sh | 3 +++ 2 files changed, 4 insertions(+) (limited to 'tests') diff --git a/tests/fsck-tests.sh b/tests/fsck-tests.sh index 44cca1b8..15d26c70 100755 --- a/tests/fsck-tests.sh +++ b/tests/fsck-tests.sh @@ -23,6 +23,7 @@ rm -f "$RESULTS" check_prereq btrfs-corrupt-block check_prereq btrfs-image check_prereq btrfs +check_prereq btrfstune check_kernel_support run_one_test() { diff --git a/tests/misc-tests.sh b/tests/misc-tests.sh index 1c645c9b..08988016 100755 --- a/tests/misc-tests.sh +++ b/tests/misc-tests.sh @@ -24,6 +24,9 @@ check_prereq btrfs-corrupt-block check_prereq btrfs-image check_prereq btrfstune check_prereq btrfs +check_prereq btrfs-zero-log +check_prereq btrfs-find-root +check_prereq btrfs-select-super check_kernel_support # The tests are driven by their custom script called 'test.sh' -- cgit v1.2.3 From 46809a7287eb41ff2fdb83f742bd5250b820145a Mon Sep 17 00:00:00 2001 From: David Sterba Date: Thu, 20 Jul 2017 17:53:56 +0200 Subject: btrfs-progs: tests: enhance API to request type of the converted filesystem We'll use mount -t $fstype later on, extend the API so we don't have to parse the type from other parameters. Signed-off-by: David Sterba --- tests/common.convert | 28 ++++++++++++++-------- tests/convert-tests/001-ext2-basic/test.sh | 10 ++++---- tests/convert-tests/002-ext3-basic/test.sh | 10 ++++---- tests/convert-tests/003-ext4-basic/test.sh | 10 ++++---- .../convert-tests/005-delete-all-rollback/test.sh | 2 +- tests/convert-tests/006-large-hole-extent/test.sh | 2 +- .../007-unsupported-block-sizes/test.sh | 2 +- tests/convert-tests/008-readonly-image/test.sh | 2 +- tests/convert-tests/009-common-inode-flags/test.sh | 2 +- 9 files changed, 38 insertions(+), 30 deletions(-) (limited to 'tests') diff --git a/tests/common.convert b/tests/common.convert index 8c9242e5..12ad3a82 100644 --- a/tests/common.convert +++ b/tests/common.convert @@ -22,8 +22,13 @@ convert_test_preamble() { # prepare TEST_DEV before conversion, create filesystem and mount it, image # size is 512MB -# $@: free form, command to create the filesystem, with appended -F +# $1: type of the filesystem +# $2+: free form, command to create the filesystem, with appended -F convert_test_prep_fs() { + local fstype + + fstype="$1" + shift # TEST_DEV not removed as the file might have special permissions, eg. # when test image is on NFS and would not be writable for root run_check truncate -s 0 "$TEST_DEV" @@ -173,11 +178,13 @@ convert_test_post_rollback() { } # simple wrapper for a convert test -# $1: btrfs features, argument to -O -# $2: description of the test "ext2 8k nodesize" -# $3: nodesize value -# $4 + rest: command to create the ext2 image +# $1: type of the converted filesystem +# $2: btrfs features, argument to -O +# $3: description of the test "ext2 8k nodesize" +# $4: nodesize value +# $5 + rest: command to create the ext2 image convert_test() { + local fstype local features local nodesize local msg @@ -185,12 +192,13 @@ convert_test() { local EXT_PERMTMP local EXT_ACLTMP - features="$1" - msg="$2" - nodesize="$3" - shift 3 + fstype="$1" + features="$2" + msg="$3" + nodesize="$4" + shift 4 convert_test_preamble "$features" "$msg" "$nodesize" "$@" - convert_test_prep_fs "$@" + convert_test_prep_fs "$fstype" "$@" populate_fs CHECKSUMTMP=$(mktemp --tmpdir btrfs-progs-convert.XXXXXXXXXX) EXT_PERMTMP=$(mktemp --tmpdir btrfs-progs-convert.permXXXXXX) diff --git a/tests/convert-tests/001-ext2-basic/test.sh b/tests/convert-tests/001-ext2-basic/test.sh index 07f1d6e8..7d8e87d8 100755 --- a/tests/convert-tests/001-ext2-basic/test.sh +++ b/tests/convert-tests/001-ext2-basic/test.sh @@ -8,9 +8,9 @@ prepare_test_dev 512M check_prereq btrfs-convert for feature in '' 'extref' 'skinny-metadata' 'no-holes'; do - convert_test "$feature" "ext2 4k nodesize" 4096 mke2fs -b 4096 - convert_test "$feature" "ext2 8k nodesize" 8192 mke2fs -b 4096 - convert_test "$feature" "ext2 16k nodesize" 16384 mke2fs -b 4096 - convert_test "$feature" "ext2 32k nodesize" 32768 mke2fs -b 4096 - convert_test "$feature" "ext2 64k nodesize" 65536 mke2fs -b 4096 + convert_test ext2 "$feature" "ext2 4k nodesize" 4096 mke2fs -b 4096 + convert_test ext2 "$feature" "ext2 8k nodesize" 8192 mke2fs -b 4096 + convert_test ext2 "$feature" "ext2 16k nodesize" 16384 mke2fs -b 4096 + convert_test ext2 "$feature" "ext2 32k nodesize" 32768 mke2fs -b 4096 + convert_test ext2 "$feature" "ext2 64k nodesize" 65536 mke2fs -b 4096 done diff --git a/tests/convert-tests/002-ext3-basic/test.sh b/tests/convert-tests/002-ext3-basic/test.sh index be8a9291..5a33c2ca 100755 --- a/tests/convert-tests/002-ext3-basic/test.sh +++ b/tests/convert-tests/002-ext3-basic/test.sh @@ -8,9 +8,9 @@ prepare_test_dev 512M check_prereq btrfs-convert for feature in '' 'extref' 'skinny-metadata' 'no-holes'; do - convert_test "$feature" "ext3 4k nodesize" 4096 mke2fs -j -b 4096 - convert_test "$feature" "ext3 8k nodesize" 8192 mke2fs -j -b 4096 - convert_test "$feature" "ext3 16k nodesize" 16384 mke2fs -j -b 4096 - convert_test "$feature" "ext3 32k nodesize" 32768 mke2fs -j -b 4096 - convert_test "$feature" "ext3 64k nodesize" 65536 mke2fs -j -b 4096 + convert_test ext3 "$feature" "ext3 4k nodesize" 4096 mke2fs -j -b 4096 + convert_test ext3 "$feature" "ext3 8k nodesize" 8192 mke2fs -j -b 4096 + convert_test ext3 "$feature" "ext3 16k nodesize" 16384 mke2fs -j -b 4096 + convert_test ext3 "$feature" "ext3 32k nodesize" 32768 mke2fs -j -b 4096 + convert_test ext3 "$feature" "ext3 64k nodesize" 65536 mke2fs -j -b 4096 done diff --git a/tests/convert-tests/003-ext4-basic/test.sh b/tests/convert-tests/003-ext4-basic/test.sh index 44ee592d..df8bec28 100755 --- a/tests/convert-tests/003-ext4-basic/test.sh +++ b/tests/convert-tests/003-ext4-basic/test.sh @@ -8,9 +8,9 @@ prepare_test_dev 512M check_prereq btrfs-convert for feature in '' 'extref' 'skinny-metadata' 'no-holes'; do - convert_test "$feature" "ext4 4k nodesize" 4096 mke2fs -t ext4 -b 4096 - convert_test "$feature" "ext4 8k nodesize" 8192 mke2fs -t ext4 -b 4096 - convert_test "$feature" "ext4 16k nodesize" 16384 mke2fs -t ext4 -b 4096 - convert_test "$feature" "ext4 32k nodesize" 32768 mke2fs -t ext4 -b 4096 - convert_test "$feature" "ext4 64k nodesize" 65536 mke2fs -t ext4 -b 4096 + convert_test ext4 "$feature" "ext4 4k nodesize" 4096 mke2fs -t ext4 -b 4096 + convert_test ext4 "$feature" "ext4 8k nodesize" 8192 mke2fs -t ext4 -b 4096 + convert_test ext4 "$feature" "ext4 16k nodesize" 16384 mke2fs -t ext4 -b 4096 + convert_test ext4 "$feature" "ext4 32k nodesize" 32768 mke2fs -t ext4 -b 4096 + convert_test ext4 "$feature" "ext4 64k nodesize" 65536 mke2fs -t ext4 -b 4096 done diff --git a/tests/convert-tests/005-delete-all-rollback/test.sh b/tests/convert-tests/005-delete-all-rollback/test.sh index c6f7466a..6871939e 100755 --- a/tests/convert-tests/005-delete-all-rollback/test.sh +++ b/tests/convert-tests/005-delete-all-rollback/test.sh @@ -26,7 +26,7 @@ do_test() { nodesize="$3" shift 3 convert_test_preamble "$features" "$msg" "$nodesize" "$@" - convert_test_prep_fs "$@" + convert_test_prep_fs ext4 "$@" populate_fs CHECKSUMTMP=$(mktemp --tmpdir btrfs-progs-convert.XXXXXXXXXX) convert_test_gen_checksums "$CHECKSUMTMP" diff --git a/tests/convert-tests/006-large-hole-extent/test.sh b/tests/convert-tests/006-large-hole-extent/test.sh index e99741cc..f63a1186 100755 --- a/tests/convert-tests/006-large-hole-extent/test.sh +++ b/tests/convert-tests/006-large-hole-extent/test.sh @@ -14,7 +14,7 @@ check_prereq btrfs-convert default_mke2fs="mke2fs -t ext4 -b 4096" convert_test_preamble '' 'large hole extent test' 16k "$default_mke2fs" -convert_test_prep_fs $default_mke2fs +convert_test_prep_fs ext4 $default_mke2fs run_check $SUDO_HELPER dd if=/dev/zero of="$TEST_MNT/file" bs=1M \ count=1 seek=1024 > /dev/null 2>&1 diff --git a/tests/convert-tests/007-unsupported-block-sizes/test.sh b/tests/convert-tests/007-unsupported-block-sizes/test.sh index a7488407..af8ec357 100755 --- a/tests/convert-tests/007-unsupported-block-sizes/test.sh +++ b/tests/convert-tests/007-unsupported-block-sizes/test.sh @@ -11,7 +11,7 @@ check_prereq btrfs-convert for bs in 1024 2048; do default_mke2fs="mke2fs -t ext4 -b $bs" convert_test_preamble '' "unsupported block size $bs" 16k "$default_mke2fs" - convert_test_prep_fs $default_mke2fs + convert_test_prep_fs ext4 $default_mke2fs run_check $SUDO_HELPER dd if=/dev/zero of="$TEST_MNT/file" bs=1M \ count=1 seek=1024 > /dev/null 2>&1 diff --git a/tests/convert-tests/008-readonly-image/test.sh b/tests/convert-tests/008-readonly-image/test.sh index 27c9373e..4d5e629f 100755 --- a/tests/convert-tests/008-readonly-image/test.sh +++ b/tests/convert-tests/008-readonly-image/test.sh @@ -10,7 +10,7 @@ check_prereq btrfs-convert default_mke2fs="mke2fs -t ext4 -b 4096" convert_test_preamble '' 'readonly image test' 16k "$default_mke2fs" -convert_test_prep_fs $default_mke2fs +convert_test_prep_fs ext4 $default_mke2fs run_check_umount_test_dev convert_test_do_convert run_check_mount_test_dev diff --git a/tests/convert-tests/009-common-inode-flags/test.sh b/tests/convert-tests/009-common-inode-flags/test.sh index 02823e14..f42fb681 100755 --- a/tests/convert-tests/009-common-inode-flags/test.sh +++ b/tests/convert-tests/009-common-inode-flags/test.sh @@ -11,7 +11,7 @@ check_prereq btrfs-convert fail=0 default_mke2fs="mke2fs -t ext4 -b 4096" convert_test_preamble '' 'common inode flags test' 16k "$default_mke2fs" -convert_test_prep_fs $default_mke2fs +convert_test_prep_fs ext4 $default_mke2fs # create file with specific flags run_check $SUDO_HELPER touch "$TEST_MNT/flag_test" -- cgit v1.2.3 From 18b519e694a6ef559d85072f86898ab5a61f6a05 Mon Sep 17 00:00:00 2001 From: David Sterba Date: Thu, 20 Jul 2017 18:44:49 +0200 Subject: btrfs-progs: tests: use separate helper for mounting convert filesystems We'll enforce the btrfs type for mount everwhere so we must provide a way to mount converted filesystems. Add a new helper that will try to mount the given type. Signed-off-by: David Sterba --- tests/common.convert | 35 +++++++++++++++++++++- .../convert-tests/005-delete-all-rollback/test.sh | 4 +-- 2 files changed, 36 insertions(+), 3 deletions(-) (limited to 'tests') diff --git a/tests/common.convert b/tests/common.convert index 12ad3a82..2c19a4be 100644 --- a/tests/common.convert +++ b/tests/common.convert @@ -1,6 +1,39 @@ #!/bin/bash # helpers for btrfs-convert tests +# mount image of converted filesystem of a given type +# $1: type of the filesystem +run_check_mount_convert_dev() +{ + local fstype + local loop_opt + + setup_root_helper + + fstype="$1" + shift + if [ -z "$fstype" ]; then + _fail "Missing source filesystem type" + fi + if [ "$fstype" = 'btrfs' ]; then + _fail "Incorrect type for converted filesystem: btrfs" + fi + + if [[ -b "$TEST_DEV" ]]; then + loop_opt="" + elif [[ -f "$TEST_DEV" ]]; then + loop_opt="-o loop" + else + _fail "Invalid \$TEST_DEV: $TEST_DEV" + fi + + [[ -d "$TEST_MNT" ]] || { + _fail "Invalid \$TEST_MNT: $TEST_MNT" + } + + run_check $SUDO_HELPER mount $loop_opt -t "$fstype" "$@" "$TEST_DEV" "$TEST_MNT" +} + populate_fs() { for dataset_type in 'small' 'hardlink' 'fast_symlink' 'brokenlink' 'perm' 'sparse' 'acls' 'fifo' 'slow_symlink'; do @@ -37,7 +70,7 @@ convert_test_prep_fs() { run_check "$@" -F "$TEST_DEV" # create a file to check btrfs-convert can convert regular file correct - run_check_mount_test_dev + run_check_mount_convert_dev "$fstype" # create a file inside the fs before convert, to make sure there is # data covering btrfs backup superblock range (64M) diff --git a/tests/convert-tests/005-delete-all-rollback/test.sh b/tests/convert-tests/005-delete-all-rollback/test.sh index 6871939e..337413bb 100755 --- a/tests/convert-tests/005-delete-all-rollback/test.sh +++ b/tests/convert-tests/005-delete-all-rollback/test.sh @@ -47,12 +47,12 @@ do_test() { run_check_umount_test_dev convert_test_post_rollback - run_check_mount_test_dev + run_check_mount_convert_dev ext4 convert_test_post_check_checksums "$CHECKSUMTMP" run_check_umount_test_dev # mount again and verify checksums - run_check_mount_test_dev + run_check_mount_convert_dev ext4 convert_test_post_check_checksums "$CHECKSUMTMP" run_check_umount_test_dev -- cgit v1.2.3 From 5c2cf48a4cc3f2aab5a478059d3e5f593554a738 Mon Sep 17 00:00:00 2001 From: Adam Buchbinder Date: Wed, 12 Jul 2017 13:05:22 -0700 Subject: btrfs-progs: tests: Use '-t btrfs' mount option in tests Without it, mount (at least from util-linux 2.20.1) tries (and fails) to mount some filesystems as NTFS. Signed-off-by: Adam Buchbinder Signed-off-by: David Sterba --- tests/common | 2 +- tests/fsck-tests/012-leaf-corruption/test.sh | 2 +- 2 files changed, 2 insertions(+), 2 deletions(-) (limited to 'tests') diff --git a/tests/common b/tests/common index 7ad436e3..bed60094 100644 --- a/tests/common +++ b/tests/common @@ -387,7 +387,7 @@ run_check_mount_test_dev() _fail "Invalid \$TEST_MNT: $TEST_MNT" } - run_check $SUDO_HELPER mount $loop_opt "$@" "$TEST_DEV" "$TEST_MNT" + run_check $SUDO_HELPER mount -t btrfs $loop_opt "$@" "$TEST_DEV" "$TEST_MNT" } run_check_umount_test_dev() diff --git a/tests/fsck-tests/012-leaf-corruption/test.sh b/tests/fsck-tests/012-leaf-corruption/test.sh index 43b0e6de..fc10a4ff 100755 --- a/tests/fsck-tests/012-leaf-corruption/test.sh +++ b/tests/fsck-tests/012-leaf-corruption/test.sh @@ -90,7 +90,7 @@ check_inode() check_leaf_corrupt_no_data_ext() { image=$1 - $SUDO_HELPER mount -o loop "$image" -o ro "$TEST_MNT" + $SUDO_HELPER mount -o loop -t btrfs "$image" -o ro "$TEST_MNT" i=0 while [ $i -lt ${#leaf_no_data_ext_list[@]} ]; do -- cgit v1.2.3 From 0cd4485178dcf97f2ed58a59f5d3ade56aa11eb3 Mon Sep 17 00:00:00 2001 From: Jeff Mahoney Date: Tue, 22 Aug 2017 19:44:44 +0200 Subject: btrfs-progs: tests: fix typo in convert-tests/008-readonly-image The dd in convert-tests/008-readonly-image is expected to fail, so there being a typo in the file name has gone unnoticed. Signed-off-by: Jeff Mahoney Signed-off-by: David Sterba --- tests/convert-tests/008-readonly-image/test.sh | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) (limited to 'tests') diff --git a/tests/convert-tests/008-readonly-image/test.sh b/tests/convert-tests/008-readonly-image/test.sh index 4d5e629f..dd954181 100755 --- a/tests/convert-tests/008-readonly-image/test.sh +++ b/tests/convert-tests/008-readonly-image/test.sh @@ -16,10 +16,10 @@ convert_test_do_convert run_check_mount_test_dev # It's expected to fail -$SUDO_HELPER dd if=/dev/zero of="$TEST_MNT/ext2_save/image" bs=1M count=1 \ +$SUDO_HELPER dd if=/dev/zero of="$TEST_MNT/ext2_saved/image" bs=1M count=1 \ &> /dev/null if [ $? -ne 1 ]; then - echo "after convert ext2_save/image is not read-only" + echo "after convert ext2_saved/image is not read-only" exit 1 fi run_check_umount_test_dev -- cgit v1.2.3 From 515ea7dc2f28794b03b64bc962da79935a29b457 Mon Sep 17 00:00:00 2001 From: Su Yue Date: Fri, 14 Jul 2017 15:47:46 +0800 Subject: btrfs-progs: fsck-test: case for corrupted dir item name In this test case, all name in dir_item, dir_index, inode_ref are corrupted to another one. btrfs check should report errors about the corrupted dir_item but btrfs can't repair the case now. Signed-off-by: Su Yue Signed-off-by: David Sterba --- .../fsck-tests/026-bad-dir-item-name/default_case.img.xz | Bin 0 -> 1924 bytes tests/fsck-tests/026-bad-dir-item-name/test.sh | 13 +++++++++++++ 2 files changed, 13 insertions(+) create mode 100644 tests/fsck-tests/026-bad-dir-item-name/default_case.img.xz create mode 100755 tests/fsck-tests/026-bad-dir-item-name/test.sh (limited to 'tests') diff --git a/tests/fsck-tests/026-bad-dir-item-name/default_case.img.xz b/tests/fsck-tests/026-bad-dir-item-name/default_case.img.xz new file mode 100644 index 00000000..27e8553f Binary files /dev/null and b/tests/fsck-tests/026-bad-dir-item-name/default_case.img.xz differ diff --git a/tests/fsck-tests/026-bad-dir-item-name/test.sh b/tests/fsck-tests/026-bad-dir-item-name/test.sh new file mode 100755 index 00000000..a1077a8d --- /dev/null +++ b/tests/fsck-tests/026-bad-dir-item-name/test.sh @@ -0,0 +1,13 @@ +#!/bin/bash +# +# confirm whether check detects name and hash mismatch in dir_item + +source "$TOP/tests/common" + +check_prereq btrfs + +image=$(extract_image "./default_case.img.xz") + +run_mustfail "dir_item hash mismatch not found" "$TOP/btrfs" check "$image" + +rm -f "$image" -- cgit v1.2.3 From f0c7703671996ed078462f41bb52490d7774aea3 Mon Sep 17 00:00:00 2001 From: David Sterba Date: Wed, 23 Aug 2017 19:19:47 +0200 Subject: btrfs-progs: tests: scan results for commands not found In case of typos or messed up command execution, we'd like to be able to catch that. Signed-off-by: David Sterba --- tests/scan-results.sh | 1 + 1 file changed, 1 insertion(+) (limited to 'tests') diff --git a/tests/scan-results.sh b/tests/scan-results.sh index f3ebcbc4..89e34dd2 100755 --- a/tests/scan-results.sh +++ b/tests/scan-results.sh @@ -12,6 +12,7 @@ for i in *.txt; do *runtime\ error*) echo "RUNTIME ERROR (sanitizer): $last" ;; *AddressSanitizer*heap-use-after-free*) echo "RUNTIME ERROR (use after free): $last" ;; *Warning:\ assertion*failed*) echo "ASSERTION WARNING: $last" ;; + *command\ not\ found*) echo "COMMAND NOT FOUND: $last" ;; *) : ;; esac done < "$i" -- cgit v1.2.3 From d7dd9d00e944ee2308ee23f7881fb1b58edf7214 Mon Sep 17 00:00:00 2001 From: David Sterba Date: Wed, 23 Aug 2017 19:26:42 +0200 Subject: btrfs-progs: tests: catch bad usage of run_mustfail This function has an extra argument and can get forgotten, add a sanity check so the bad usage can be caught during development. Signed-off-by: David Sterba --- tests/common | 25 +++++++++++++++++++++++++ 1 file changed, 25 insertions(+) (limited to 'tests') diff --git a/tests/common b/tests/common index bed60094..a1ab3e03 100644 --- a/tests/common +++ b/tests/common @@ -21,6 +21,26 @@ _assert_path() exit 1 } +# $1: this string gets matched to files, absolute or relative path, or a +# systemwide command available via $PATH +_is_file_or_command() +{ + local msg + + msg="$1" + if [ -z "$msg" ]; then + return 1 + fi + + if [ -f "$msg" -o -d "$msg" -o -b "$msg" ]; then + return 0 + fi + if [ -f $(type -p "$msg") ]; then + return 0 + fi + return 1 +} + _fail() { echo "$*" | tee -a "$RESULTS" @@ -185,6 +205,11 @@ run_mustfail() msg="$1" shift + if _is_file_or_command "$msg"; then + echo "ASSERTION FAIL: 1st argument of run_mustfail must be a message" + exit 1 + fi + ins=$(_get_spec_ins "$@") spec=$(($ins-1)) cmd=$(eval echo "\${$spec}") -- cgit v1.2.3 From fb0d53a9377351d2875bde422e11b1213caf0b48 Mon Sep 17 00:00:00 2001 From: David Sterba Date: Fri, 25 Aug 2017 15:44:24 +0200 Subject: btrfs-progs: tests: fix _is_file_or_command detection type -p returns an empty string for nonexistent commands, but the -f test on an empty string does not behave the same on all shells. To be safe, use the quoted value. Signed-off-by: David Sterba --- tests/common | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) (limited to 'tests') diff --git a/tests/common b/tests/common index a1ab3e03..d0324a62 100644 --- a/tests/common +++ b/tests/common @@ -35,7 +35,8 @@ _is_file_or_command() if [ -f "$msg" -o -d "$msg" -o -b "$msg" ]; then return 0 fi - if [ -f $(type -p "$msg") ]; then + msg=$(type -p "$msg") + if [ -f "$msg" ]; then return 0 fi return 1 -- cgit v1.2.3 From e75f466ddd8138093b5355af9fda24ca204bce58 Mon Sep 17 00:00:00 2001 From: Jeff Mahoney Date: Tue, 22 Aug 2017 18:32:57 +0200 Subject: btrfs-progs: tests: add support for converting reiserfs Many of the test cases for convert apply regardless of what the source file system is and using ext4 is sufficient. I've included several test cases that are reiserfs-specific. Signed-off-by: Jeff Mahoney [ patch split from the previous one, minor cleanups in common.convert ] Signed-off-by: David Sterba --- tests/common.convert | 19 +++++- tests/convert-tests/010-reiserfs-basic/test.sh | 16 +++++ .../011-reiserfs-delete-all-rollback/test.sh | 67 ++++++++++++++++++++ .../012-reiserfs-large-hole-extent/test.sh | 23 +++++++ .../013-reiserfs-common-inode-flags/test.sh | 35 +++++++++++ .../014-reiserfs-tail-handling/test.sh | 73 ++++++++++++++++++++++ 6 files changed, 230 insertions(+), 3 deletions(-) create mode 100755 tests/convert-tests/010-reiserfs-basic/test.sh create mode 100755 tests/convert-tests/011-reiserfs-delete-all-rollback/test.sh create mode 100755 tests/convert-tests/012-reiserfs-large-hole-extent/test.sh create mode 100755 tests/convert-tests/013-reiserfs-common-inode-flags/test.sh create mode 100755 tests/convert-tests/014-reiserfs-tail-handling/test.sh (limited to 'tests') diff --git a/tests/common.convert b/tests/common.convert index 2c19a4be..1d98cda1 100644 --- a/tests/common.convert +++ b/tests/common.convert @@ -50,7 +50,7 @@ convert_test_preamble() { msg="$2" shift 3 echo " [TEST/conv] $msg, btrfs" "${features:-defaults}" - echo "creating ext image with: $@" >> "$RESULTS" + echo "creating test image with: $@" >> "$RESULTS" } # prepare TEST_DEV before conversion, create filesystem and mount it, image @@ -59,6 +59,8 @@ convert_test_preamble() { # $2+: free form, command to create the filesystem, with appended -F convert_test_prep_fs() { local fstype + local force + local mountopts fstype="$1" shift @@ -67,10 +69,21 @@ convert_test_prep_fs() { run_check truncate -s 0 "$TEST_DEV" # 256MB is the smallest acceptable btrfs image. run_check truncate -s 512M "$TEST_DEV" - run_check "$@" -F "$TEST_DEV" + force= + mountopts= + case "$fstype" in + ext[234]) + force=-F ;; + reiserfs) + force=-ff + mountopts="-o acl,user_xattr,attrs" ;; + *) + _fail "unknown filesystem to convert: $fstype" + esac + run_check "$@" $force "$TEST_DEV" # create a file to check btrfs-convert can convert regular file correct - run_check_mount_convert_dev "$fstype" + run_check_mount_convert_dev "$fstype" $mountopts # create a file inside the fs before convert, to make sure there is # data covering btrfs backup superblock range (64M) diff --git a/tests/convert-tests/010-reiserfs-basic/test.sh b/tests/convert-tests/010-reiserfs-basic/test.sh new file mode 100755 index 00000000..f469aff2 --- /dev/null +++ b/tests/convert-tests/010-reiserfs-basic/test.sh @@ -0,0 +1,16 @@ +#!/bin/bash + +source "$TOP/tests/common" +source "$TOP/tests/common.convert" + +setup_root_helper +prepare_test_dev 512M +check_prereq btrfs-convert + +for feature in '' 'extref' 'skinny-metadata' 'no-holes'; do + convert_test reiserfs "$feature" "reiserfs 4k nodesize" 4096 mkreiserfs -b 4096 + convert_test reiserfs "$feature" "reiserfs 8k nodesize" 8192 mkreiserfs -b 4096 + convert_test reiserfs "$feature" "reiserfs 16k nodesize" 16384 mkreiserfs -b 4096 + convert_test reiserfs "$feature" "reiserfs 32k nodesize" 32768 mkreiserfs -b 4096 + convert_test reiserfs "$feature" "reiserfs 64k nodesize" 65536 mkreiserfs -b 4096 +done diff --git a/tests/convert-tests/011-reiserfs-delete-all-rollback/test.sh b/tests/convert-tests/011-reiserfs-delete-all-rollback/test.sh new file mode 100755 index 00000000..b905db89 --- /dev/null +++ b/tests/convert-tests/011-reiserfs-delete-all-rollback/test.sh @@ -0,0 +1,67 @@ +#!/bin/bash +# create a base image, convert to btrfs, remove all files, rollback the reiserfs image + +source "$TOP/tests/common" +source "$TOP/tests/common.convert" + +setup_root_helper +prepare_test_dev 512M +check_prereq btrfs-convert + +# simple wrapper for a convert test +# $1: btrfs features, argument to -O +# $2: message +# $3: nodesize value +# $4 + rest: command to create the reiserfs image +do_test() { + local features + local msg + local nodesize + local CHECKSUMTMP + local here + + features="$1" + msg="$2" + nodesize="$3" + shift 3 + convert_test_preamble "$features" "$msg" "$nodesize" "$@" + convert_test_prep_fs reiserfs "$@" + populate_fs + CHECKSUMTMP=$(mktemp --tmpdir btrfs-progs-convert.XXXXXXXXXX) + convert_test_gen_checksums "$CHECKSUMTMP" + + run_check_umount_test_dev + + convert_test_do_convert "$features" "$nodesize" + + run_check_mount_test_dev + convert_test_post_check_checksums "$CHECKSUMTMP" + + here=$(pwd) + cd "$TEST_MNT" || _fail "cannot cd to TEST_MNT" + # reiserfs_saved/image must not be deleted + run_mayfail $SUDO_HELPER find "$TEST_MNT"/ -mindepth 1 -path '*reiserfs_saved' -prune -o -exec rm -vrf "{}" \; + cd "$here" + run_check "$TOP/btrfs" filesystem sync "$TEST_MNT" + run_check_umount_test_dev + convert_test_post_rollback + + run_check_mount_convert_dev reiserfs + convert_test_post_check_checksums "$CHECKSUMTMP" + run_check_umount_test_dev + + # mount again and verify checksums + run_check_mount_convert_dev reiserfs + convert_test_post_check_checksums "$CHECKSUMTMP" + run_check_umount_test_dev + + rm "$CHECKSUMTMP" +} + +for feature in '' 'extref' 'skinny-metadata' 'no-holes'; do + do_test "$feature" "reiserfs 4k nodesize" 4096 mkreiserfs -b 4096 + do_test "$feature" "reiserfs 8k nodesize" 8192 mkreiserfs -b 4096 + do_test "$feature" "reiserfs 16k nodesize" 16384 mkreiserfs -b 4096 + do_test "$feature" "reiserfs 32k nodesize" 32768 mkreiserfs -b 4096 + do_test "$feature" "reiserfs 64k nodesize" 65536 mkreiserfs -b 4096 +done diff --git a/tests/convert-tests/012-reiserfs-large-hole-extent/test.sh b/tests/convert-tests/012-reiserfs-large-hole-extent/test.sh new file mode 100755 index 00000000..19acbbd1 --- /dev/null +++ b/tests/convert-tests/012-reiserfs-large-hole-extent/test.sh @@ -0,0 +1,23 @@ +#!/bin/bash +# Create a base image with large hole extent, then convert to btrfs, +# check the converted image. +# Check if btrfs-convert can handle such large hole. +# Fast pinpoint regression test. No options combination nor checksum +# verification + +source "$TOP/tests/common" +source "$TOP/tests/common.convert" + +setup_root_helper +prepare_test_dev 512M +check_prereq btrfs-convert + +default_mkfs="mkreiserfs -b 4096" +convert_test_preamble '' 'large hole extent test' 16k "$default_mkfs" +convert_test_prep_fs reiserfs $default_mkfs + +run_check $SUDO_HELPER dd if=/dev/zero of="$TEST_MNT/file" bs=1M \ + count=1 seek=1024 > /dev/null 2>&1 + +run_check_umount_test_dev +convert_test_do_convert diff --git a/tests/convert-tests/013-reiserfs-common-inode-flags/test.sh b/tests/convert-tests/013-reiserfs-common-inode-flags/test.sh new file mode 100755 index 00000000..850ecb9a --- /dev/null +++ b/tests/convert-tests/013-reiserfs-common-inode-flags/test.sh @@ -0,0 +1,35 @@ +#!/bin/bash +# Check if btrfs-convert can copy common inode flags like SYNC/IMMUTABLE + +source "$TOP/tests/common" +source "$TOP/tests/common.convert" + +setup_root_helper +prepare_test_dev 512M +check_prereq btrfs-convert + +fail=0 +default_mkfs="mkreiserfs -b 4096" +convert_test_preamble '' 'common inode flags test' 16k "$default_mkfs" +convert_test_prep_fs reiserfs $default_mkfs + +# create file with specific flags +run_check $SUDO_HELPER touch "$TEST_MNT/flag_test" +run_check $SUDO_HELPER chattr +aAdSi "$TEST_MNT/flag_test" +run_check lsattr "$TEST_MNT/flag_test" + +run_check_umount_test_dev +convert_test_do_convert +run_check_mount_test_dev + +# Log the status +run_check lsattr "$TEST_MNT/flag_test" +# Above flags should be copied to btrfs flags, and lsattr should get them +run_check_stdout lsattr "$TEST_MNT/flag_test" | cut -f1 -d\ | grep "[aAdiS]" -q +if [ $? -ne 0 ]; then + rm tmp_output + _fail "no common inode flags are copied after convert" +fi + +run_check_umount_test_dev +convert_test_post_rollback diff --git a/tests/convert-tests/014-reiserfs-tail-handling/test.sh b/tests/convert-tests/014-reiserfs-tail-handling/test.sh new file mode 100755 index 00000000..58cfaa4b --- /dev/null +++ b/tests/convert-tests/014-reiserfs-tail-handling/test.sh @@ -0,0 +1,73 @@ +#!/bin/bash +# Check the various combinations of real blocks, holes, and tails +# Since it's possible to have a valid extent layout that check will +# happily accept AND have garbage in the output, compare the results +# as well. +# We use separate inputs for tails and real blocks so we can determine +# if there was a failure in copying either. + +source "$TOP/tests/common" +source "$TOP/tests/common.convert" + +setup_root_helper +prepare_test_dev 512M +check_prereq btrfs-convert +check_global_prereq md5sum + +perl -e "print 'a'x8192;" > input +perl -e "print 'b'x8192;" > input2 + +default_mkfs="mkreiserfs -b 4096" +convert_test_preamble '' 'tail conversion test' 16k "$default_mkfs" +convert_test_prep_fs reiserfs $default_mkfs + +# Hole alone +run_check $SUDO_HELPER truncate -s 81920 "$TEST_MNT/hole" + +# Tail alone +run_check $SUDO_HELPER dd if=input of="$TEST_MNT/1k" bs=1k count=1 \ + > /dev/null 2>&1 + +# Single indirect block +run_check $SUDO_HELPER dd if=input of="$TEST_MNT/4k" bs=1k count=4 \ + > /dev/null 2>&1 + +# Indirect block + tail +run_check $SUDO_HELPER dd if=input of="$TEST_MNT/5k" bs=1k count=4 \ + > /dev/null 2>&1 +run_check $SUDO_HELPER dd if=input2 of="$TEST_MNT/5k" bs=1k count=1 \ + seek=4 > /dev/null 2>&1 + +# Hole followed by tail +run_check $SUDO_HELPER dd if=input of="$TEST_MNT/hole-1k" bs=1k count=1 \ + seek=4 > /dev/null 2>&1 + +# Indirect block followed by hole +run_check $SUDO_HELPER dd if=input of="$TEST_MNT/4k-hole" bs=1k count=4 \ + > /dev/null 2>&1 +run_check $SUDO_HELPER truncate -s 81920 "$TEST_MNT/4k-hole" + +# Indirect block followed by hole followed by tail +run_check $SUDO_HELPER dd if=input of="$TEST_MNT/4k-hole-1k" bs=1k count=4 \ + > /dev/null 2>&1 +run_check $SUDO_HELPER truncate -s 8192 "$TEST_MNT/4k-hole-1k" +run_check $SUDO_HELPER dd if=input2 of="$TEST_MNT/4k-hole-1k" bs=1k count=1 \ + seek=8 > /dev/null 2>&1 + +rm -f input input2 + +declare -A SUMS +for file in "$TEST_MNT"/*; do + SUM=$(md5sum "$file") + SUMS["$file"]=$SUM +done + +run_check_umount_test_dev +convert_test_do_convert + +run_check_mount_test_dev +for file in "${!SUMS[@]}"; do + SUM=$(md5sum "$file") + run_check test "$SUM" = "${SUMS[$file]}" +done +run_check_umount_test_dev -- cgit v1.2.3 From 092698b40ac77d181c51d6aa020a03f9b164069b Mon Sep 17 00:00:00 2001 From: David Sterba Date: Fri, 25 Aug 2017 19:21:01 +0200 Subject: btrfs-progs: tests: add more fuzzed images from bugzilla Signed-off-by: David Sterba --- .../images/bko-155551-unaligned-tree-block.raw.txt | 49 +++++++++++++++++++++ .../images/bko-155551-unaligned-tree-block.raw.xz | Bin 0 -> 3692 bytes 2 files changed, 49 insertions(+) create mode 100644 tests/fuzz-tests/images/bko-155551-unaligned-tree-block.raw.txt create mode 100644 tests/fuzz-tests/images/bko-155551-unaligned-tree-block.raw.xz (limited to 'tests') diff --git a/tests/fuzz-tests/images/bko-155551-unaligned-tree-block.raw.txt b/tests/fuzz-tests/images/bko-155551-unaligned-tree-block.raw.txt new file mode 100644 index 00000000..498896c1 --- /dev/null +++ b/tests/fuzz-tests/images/bko-155551-unaligned-tree-block.raw.txt @@ -0,0 +1,49 @@ +URL: https://bugzilla.kernel.org/show_bug.cgi?id=155551 +Lukas Lueg 2016-08-29 20:44:04 UTC + +More news from the fuzzer. The attached image causes btrfsck to enter what +seems to be an endless loop; using btrfs-progs v4.7-42-g56e9586. + +Couldn't map the block 18446744073709551607 +No mapping for 18446744073709551607-4087 +Couldn't map the block 18446744073709551607 +bytenr mismatch, want=18446744073709551607, have=0 +checking extents +parent transid verify failed on 4194304 wanted 169 found 4 +Ignoring transid failure +parent transid verify failed on 4194304 wanted 169 found 4 +Ignoring transid failure +parent transid verify failed on 4194304 wanted 169 found 4 +Ignoring transid failure +parent transid verify failed on 4194304 wanted 169 found 4 +Ignoring transid failure +parent transid verify failed on 4194304 wanted 169 found 4 +Ignoring transid failure +parent transid verify failed on 4194304 wanted 169 found 4 +Ignoring transid failure +parent transid verify failed on 4194304 wanted 169 found 4 +Ignoring transid failure +parent transid verify failed on 4194304 wanted 169 found 4 +Ignoring transid failure +parent transid verify failed on 4194304 wanted 169 found 4 +Ignoring transid failure +Couldn't map the block 419430592 +No mapping for 419430592-419434688 +Couldn't map the block 419430592 +bytenr mismatch, want=419430592, have=0 +Couldn't map the block 36283884701696 +No mapping for 36283884701696-36283884705792 +Couldn't map the block 36283884701696 +bytenr mismatch, want=36283884701696, have=0 +Couldn't map the block 18446744073709551607 +No mapping for 18446744073709551607-4087 +Couldn't map the block 18446744073709551607 +bytenr mismatch, want=18446744073709551607, have=0 +Couldn't map the block 18446744073709551607 +No mapping for 18446744073709551607-4087 +Couldn't map the block 18446744073709551607 +bytenr mismatch, want=18446744073709551607, have=0 +Couldn't map the block 18446744073709551607 +No mapping for 18446744073709551607-4087 +Couldn't map the block 18446744073709551607 +bytenr mismatch, want=18446744073709551607, have=0 diff --git a/tests/fuzz-tests/images/bko-155551-unaligned-tree-block.raw.xz b/tests/fuzz-tests/images/bko-155551-unaligned-tree-block.raw.xz new file mode 100644 index 00000000..f60271e2 Binary files /dev/null and b/tests/fuzz-tests/images/bko-155551-unaligned-tree-block.raw.xz differ -- cgit v1.2.3 From ee3725211533ed5592af79f2e6cb4524ed089047 Mon Sep 17 00:00:00 2001 From: David Sterba Date: Mon, 28 Aug 2017 13:54:02 +0200 Subject: btrfs-progs: tests: add build checks for sanitization features Signed-off-by: David Sterba --- tests/build-tests.sh | 13 +++++++++++++ 1 file changed, 13 insertions(+) (limited to 'tests') diff --git a/tests/build-tests.sh b/tests/build-tests.sh index 4dc8744e..4df29331 100755 --- a/tests/build-tests.sh +++ b/tests/build-tests.sh @@ -87,5 +87,18 @@ build_make_targets conf='--disable-convert' build_make_targets +# debugging builds, just the default targets +target='D=1' +buildme + +target='D=asan' +buildme + +target='D=tsan' +buildme + +target='D=ubsan' +buildme + echo "---------------------------------------------------" echo "$verdict" -- cgit v1.2.3 From 847ff667ce673f553ef777593b70c2beb2032e15 Mon Sep 17 00:00:00 2001 From: David Sterba Date: Tue, 29 Aug 2017 16:35:01 +0200 Subject: btrfs-progs: tests: add more checks for tools used in convert tests Tools that may not be present in common installations should be checked in the tests. Signed-off-by: David Sterba --- tests/convert-tests.sh | 4 ++++ tests/convert-tests/001-ext2-basic/test.sh | 1 + tests/convert-tests/002-ext3-basic/test.sh | 1 + tests/convert-tests/003-ext4-basic/test.sh | 1 + tests/convert-tests/005-delete-all-rollback/test.sh | 1 + tests/convert-tests/006-large-hole-extent/test.sh | 1 + tests/convert-tests/007-unsupported-block-sizes/test.sh | 1 + tests/convert-tests/008-readonly-image/test.sh | 1 + tests/convert-tests/009-common-inode-flags/test.sh | 3 +++ tests/convert-tests/010-reiserfs-basic/test.sh | 1 + tests/convert-tests/011-reiserfs-delete-all-rollback/test.sh | 1 + tests/convert-tests/012-reiserfs-large-hole-extent/test.sh | 1 + tests/convert-tests/013-reiserfs-common-inode-flags/test.sh | 3 +++ tests/convert-tests/014-reiserfs-tail-handling/test.sh | 2 ++ 14 files changed, 22 insertions(+) (limited to 'tests') diff --git a/tests/convert-tests.sh b/tests/convert-tests.sh index c5663367..42479df9 100755 --- a/tests/convert-tests.sh +++ b/tests/convert-tests.sh @@ -22,6 +22,10 @@ export TEST_DEV rm -f "$RESULTS" check_kernel_support +# anything expected by common.convert +check_global_prereq getfacl +check_global_prereq setfacl +check_global_prereq md5sum run_one_test() { local testdir diff --git a/tests/convert-tests/001-ext2-basic/test.sh b/tests/convert-tests/001-ext2-basic/test.sh index 7d8e87d8..d94bf0b6 100755 --- a/tests/convert-tests/001-ext2-basic/test.sh +++ b/tests/convert-tests/001-ext2-basic/test.sh @@ -6,6 +6,7 @@ source "$TOP/tests/common.convert" setup_root_helper prepare_test_dev 512M check_prereq btrfs-convert +check_global_prereq mke2fs for feature in '' 'extref' 'skinny-metadata' 'no-holes'; do convert_test ext2 "$feature" "ext2 4k nodesize" 4096 mke2fs -b 4096 diff --git a/tests/convert-tests/002-ext3-basic/test.sh b/tests/convert-tests/002-ext3-basic/test.sh index 5a33c2ca..f00e0e82 100755 --- a/tests/convert-tests/002-ext3-basic/test.sh +++ b/tests/convert-tests/002-ext3-basic/test.sh @@ -6,6 +6,7 @@ source "$TOP/tests/common.convert" setup_root_helper prepare_test_dev 512M check_prereq btrfs-convert +check_global_prereq mke2fs for feature in '' 'extref' 'skinny-metadata' 'no-holes'; do convert_test ext3 "$feature" "ext3 4k nodesize" 4096 mke2fs -j -b 4096 diff --git a/tests/convert-tests/003-ext4-basic/test.sh b/tests/convert-tests/003-ext4-basic/test.sh index df8bec28..d33f1d9a 100755 --- a/tests/convert-tests/003-ext4-basic/test.sh +++ b/tests/convert-tests/003-ext4-basic/test.sh @@ -6,6 +6,7 @@ source "$TOP/tests/common.convert" setup_root_helper prepare_test_dev 512M check_prereq btrfs-convert +check_global_prereq mke2fs for feature in '' 'extref' 'skinny-metadata' 'no-holes'; do convert_test ext4 "$feature" "ext4 4k nodesize" 4096 mke2fs -t ext4 -b 4096 diff --git a/tests/convert-tests/005-delete-all-rollback/test.sh b/tests/convert-tests/005-delete-all-rollback/test.sh index 337413bb..316d57a0 100755 --- a/tests/convert-tests/005-delete-all-rollback/test.sh +++ b/tests/convert-tests/005-delete-all-rollback/test.sh @@ -8,6 +8,7 @@ source "$TOP/tests/common.convert" setup_root_helper prepare_test_dev 512M check_prereq btrfs-convert +check_global_prereq mke2fs # simple wrapper for a convert test # $1: btrfs features, argument to -O diff --git a/tests/convert-tests/006-large-hole-extent/test.sh b/tests/convert-tests/006-large-hole-extent/test.sh index f63a1186..0edb6280 100755 --- a/tests/convert-tests/006-large-hole-extent/test.sh +++ b/tests/convert-tests/006-large-hole-extent/test.sh @@ -11,6 +11,7 @@ source "$TOP/tests/common.convert" setup_root_helper prepare_test_dev 512M check_prereq btrfs-convert +check_global_prereq mke2fs default_mke2fs="mke2fs -t ext4 -b 4096" convert_test_preamble '' 'large hole extent test' 16k "$default_mke2fs" diff --git a/tests/convert-tests/007-unsupported-block-sizes/test.sh b/tests/convert-tests/007-unsupported-block-sizes/test.sh index af8ec357..f1b29726 100755 --- a/tests/convert-tests/007-unsupported-block-sizes/test.sh +++ b/tests/convert-tests/007-unsupported-block-sizes/test.sh @@ -7,6 +7,7 @@ source "$TOP/tests/common.convert" setup_root_helper prepare_test_dev 512M check_prereq btrfs-convert +check_global_prereq mke2fs for bs in 1024 2048; do default_mke2fs="mke2fs -t ext4 -b $bs" diff --git a/tests/convert-tests/008-readonly-image/test.sh b/tests/convert-tests/008-readonly-image/test.sh index dd954181..73c9eff2 100755 --- a/tests/convert-tests/008-readonly-image/test.sh +++ b/tests/convert-tests/008-readonly-image/test.sh @@ -7,6 +7,7 @@ source "$TOP/tests/common.convert" setup_root_helper prepare_test_dev 512M check_prereq btrfs-convert +check_global_prereq mke2fs default_mke2fs="mke2fs -t ext4 -b 4096" convert_test_preamble '' 'readonly image test' 16k "$default_mke2fs" diff --git a/tests/convert-tests/009-common-inode-flags/test.sh b/tests/convert-tests/009-common-inode-flags/test.sh index f42fb681..1f3106b4 100755 --- a/tests/convert-tests/009-common-inode-flags/test.sh +++ b/tests/convert-tests/009-common-inode-flags/test.sh @@ -7,6 +7,9 @@ source "$TOP/tests/common.convert" setup_root_helper prepare_test_dev 512M check_prereq btrfs-convert +check_global_prereq mke2fs +check_global_prereq lsattr +check_global_prereq chattr fail=0 default_mke2fs="mke2fs -t ext4 -b 4096" diff --git a/tests/convert-tests/010-reiserfs-basic/test.sh b/tests/convert-tests/010-reiserfs-basic/test.sh index f469aff2..32e15deb 100755 --- a/tests/convert-tests/010-reiserfs-basic/test.sh +++ b/tests/convert-tests/010-reiserfs-basic/test.sh @@ -6,6 +6,7 @@ source "$TOP/tests/common.convert" setup_root_helper prepare_test_dev 512M check_prereq btrfs-convert +check_global_prereq mkreiserfs for feature in '' 'extref' 'skinny-metadata' 'no-holes'; do convert_test reiserfs "$feature" "reiserfs 4k nodesize" 4096 mkreiserfs -b 4096 diff --git a/tests/convert-tests/011-reiserfs-delete-all-rollback/test.sh b/tests/convert-tests/011-reiserfs-delete-all-rollback/test.sh index b905db89..8c1b8057 100755 --- a/tests/convert-tests/011-reiserfs-delete-all-rollback/test.sh +++ b/tests/convert-tests/011-reiserfs-delete-all-rollback/test.sh @@ -7,6 +7,7 @@ source "$TOP/tests/common.convert" setup_root_helper prepare_test_dev 512M check_prereq btrfs-convert +check_global_prereq mkreiserfs # simple wrapper for a convert test # $1: btrfs features, argument to -O diff --git a/tests/convert-tests/012-reiserfs-large-hole-extent/test.sh b/tests/convert-tests/012-reiserfs-large-hole-extent/test.sh index 19acbbd1..d9abbd8a 100755 --- a/tests/convert-tests/012-reiserfs-large-hole-extent/test.sh +++ b/tests/convert-tests/012-reiserfs-large-hole-extent/test.sh @@ -11,6 +11,7 @@ source "$TOP/tests/common.convert" setup_root_helper prepare_test_dev 512M check_prereq btrfs-convert +check_global_prereq mkreiserfs default_mkfs="mkreiserfs -b 4096" convert_test_preamble '' 'large hole extent test' 16k "$default_mkfs" diff --git a/tests/convert-tests/013-reiserfs-common-inode-flags/test.sh b/tests/convert-tests/013-reiserfs-common-inode-flags/test.sh index 850ecb9a..ba160262 100755 --- a/tests/convert-tests/013-reiserfs-common-inode-flags/test.sh +++ b/tests/convert-tests/013-reiserfs-common-inode-flags/test.sh @@ -7,6 +7,9 @@ source "$TOP/tests/common.convert" setup_root_helper prepare_test_dev 512M check_prereq btrfs-convert +check_global_prereq mkreiserfs +check_global_prereq chattr +check_global_prereq lsattr fail=0 default_mkfs="mkreiserfs -b 4096" diff --git a/tests/convert-tests/014-reiserfs-tail-handling/test.sh b/tests/convert-tests/014-reiserfs-tail-handling/test.sh index 58cfaa4b..aba5337b 100755 --- a/tests/convert-tests/014-reiserfs-tail-handling/test.sh +++ b/tests/convert-tests/014-reiserfs-tail-handling/test.sh @@ -13,6 +13,8 @@ setup_root_helper prepare_test_dev 512M check_prereq btrfs-convert check_global_prereq md5sum +check_global_prereq mkreiserfs +check_global_prereq perl perl -e "print 'a'x8192;" > input perl -e "print 'b'x8192;" > input2 -- cgit v1.2.3 From c4dd5fef8a97543630fe945e5d5a365e40cb17f0 Mon Sep 17 00:00:00 2001 From: David Sterba Date: Tue, 29 Aug 2017 17:07:15 +0200 Subject: btrfs-progs: tests: update README Wording, runtime dependencies. Signed-off-by: David Sterba --- tests/README.md | 15 +++++++++++---- 1 file changed, 11 insertions(+), 4 deletions(-) (limited to 'tests') diff --git a/tests/README.md b/tests/README.md index a8d3a2ba..04d2ce2a 100644 --- a/tests/README.md +++ b/tests/README.md @@ -30,7 +30,7 @@ category, eg. `fsck-tests-results.txt`. ## Selective testing -The test are prefixed by a number for ordering and uniqueness. To run a +The tests are prefixed by a number for ordering and uniqueness. To run a particular test use: ```shell @@ -76,8 +76,7 @@ will run the first test in fsck-tests subdirectory. * anything that does not fit to the above, the test driver script will only execute `./test.sh` in the test directory -*tests/common:* -*tests/common.convert:* +*tests/common, tests/common.convert:* * script with shell helpers, separated by functionality @@ -146,6 +145,13 @@ the loop devices as they are managed on a per-test basis. There's a script `test-console.sh` that will run shell commands in a loop and logs the output with the testing environment set up. +### Runtime dependencies + +The tests use some common system utilities like `find`, `rm`, `dd`. Additionally, +specific tests need the following packages installed: `acl`, `attr`, +`e2fsprogs`, `reiserfsprogs` + + ## New test 1. Pick the category for the new test or fallback to `misc-tests` if not sure. For @@ -162,7 +168,7 @@ begining of `test.sh`. You don't need to add the file to git yet. 4. Write the test commands, comment anything that's not obvious. -5. Test your test. Use the `TEST` variable to jump right to your test: +5. **Test your test.** Use the `TEST` variable to jump right to your test: ```shell $ make TEST=012\* tests-misc # from top directory $ TEST=012\* ./misc-tests.sh # from tests/ @@ -172,6 +178,7 @@ $ TEST=012\* ./misc-tests.sh # from tests/ fixed the bug (or both). Subject line of the shall mention the name of the new directory for ease of search, eg. `btrfs-progs: tests: add 012-subvolume-sync-must-wait` + ### Crafted/fuzzed images Images that are create by fuzzing or specially crafted to trigger some error -- cgit v1.2.3 From eae83c46f79020f93cc85d3497951ea8db1cdd13 Mon Sep 17 00:00:00 2001 From: David Sterba Date: Tue, 29 Aug 2017 17:42:28 +0200 Subject: btrfs-progs: tests: fix TEST_LOG=dump in convert tests Test failure in convert tests with log dump does not happen because _fail is called before that and exits. Other test types are ok. Signed-off-by: David Sterba --- tests/convert-tests.sh | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) (limited to 'tests') diff --git a/tests/convert-tests.sh b/tests/convert-tests.sh index 42479df9..57fd9252 100755 --- a/tests/convert-tests.sh +++ b/tests/convert-tests.sh @@ -40,10 +40,10 @@ run_one_test() { # Only support custom test scripts ./test.sh if [ $? -ne 0 ]; then - _fail "test failed for case $testname" if [[ $TEST_LOG =~ dump ]]; then cat "$RESULTS" fi + _fail "test failed for case $testname" fi else _fail "custom test script not found" -- cgit v1.2.3 From c9141313ecdf06fb2eec107330dfeaa28e8edf6f Mon Sep 17 00:00:00 2001 From: David Sterba Date: Tue, 29 Aug 2017 18:41:30 +0200 Subject: btrfs-progs: tests: limit size of log dump from conver tests The convert tests generate lots of log material, travis CI has limit 4MB so we don't see anything useful when a late test fails. Signed-off-by: David Sterba --- tests/convert-tests.sh | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-) (limited to 'tests') diff --git a/tests/convert-tests.sh b/tests/convert-tests.sh index 57fd9252..8e97b225 100755 --- a/tests/convert-tests.sh +++ b/tests/convert-tests.sh @@ -41,7 +41,9 @@ run_one_test() { ./test.sh if [ $? -ne 0 ]; then if [[ $TEST_LOG =~ dump ]]; then - cat "$RESULTS" + # the logs can be large and may exceed the + # limits, use 4MB for now + tail -c 3900000 "$RESULTS" fi _fail "test failed for case $testname" fi -- cgit v1.2.3 From 4851de27f1b61a2e22adeb1f3d5a03c5560554b5 Mon Sep 17 00:00:00 2001 From: David Sterba Date: Wed, 30 Aug 2017 16:56:23 +0200 Subject: btrfs-progs: tests: add more sanitizer message patterns to log scanner Signed-off-by: David Sterba --- tests/scan-results.sh | 1 + 1 file changed, 1 insertion(+) (limited to 'tests') diff --git a/tests/scan-results.sh b/tests/scan-results.sh index 89e34dd2..f935b1cd 100755 --- a/tests/scan-results.sh +++ b/tests/scan-results.sh @@ -11,6 +11,7 @@ for i in *.txt; do *Assertion*failed*) echo "ASSERTION FAILED: $last" ;; *runtime\ error*) echo "RUNTIME ERROR (sanitizer): $last" ;; *AddressSanitizer*heap-use-after-free*) echo "RUNTIME ERROR (use after free): $last" ;; + *LeakSanitizer:*leak*) echo "SANITIZER REPORT: memory leak: $last" ;; *Warning:\ assertion*failed*) echo "ASSERTION WARNING: $last" ;; *command\ not\ found*) echo "COMMAND NOT FOUND: $last" ;; *) : ;; -- cgit v1.2.3 From a36d92cb8b52be7d9aa5c38cb42f7ebb56f289c2 Mon Sep 17 00:00:00 2001 From: David Sterba Date: Thu, 31 Aug 2017 18:49:38 +0200 Subject: btrfs-progs: tests: add test for check --force Basic test of the --force functionality, on an empty filesystem. Signed-off-by: David Sterba --- tests/cli-tests/007-check-force/test.sh | 21 +++++++++++++++++++++ 1 file changed, 21 insertions(+) create mode 100755 tests/cli-tests/007-check-force/test.sh (limited to 'tests') diff --git a/tests/cli-tests/007-check-force/test.sh b/tests/cli-tests/007-check-force/test.sh new file mode 100755 index 00000000..ecee0166 --- /dev/null +++ b/tests/cli-tests/007-check-force/test.sh @@ -0,0 +1,21 @@ +#!/bin/bash +# +# test 'btrfs check --force' on a mounted filesystem + +source "$TOP/tests/common" + +check_prereq mkfs.btrfs +check_prereq btrfs + +setup_root_helper +prepare_test_dev + +run_check "$TOP/mkfs.btrfs" -f "$TEST_DEV" +run_check_mount_test_dev +run_mustfail $SUDO_HELPER "$TOP/btrfs" check "$TEST_DEV" +run_check $SUDO_HELPER "$TOP/btrfs" check --force "$TEST_DEV" +run_mustfail $SUDO_HELPER "$TOP/btrfs" check --force --repair "$TEST_DEV" +run_check_umount_test_dev +run_check $SUDO_HELPER "$TOP/btrfs" check "$TEST_DEV" +run_check $SUDO_HELPER "$TOP/btrfs" check --force "$TEST_DEV" +run_mustfail $SUDO_HELPER "$TOP/btrfs" check --force --repair "$TEST_DEV" -- cgit v1.2.3 From 872837ebbfb186e2e2cdf39daac98257fcd18392 Mon Sep 17 00:00:00 2001 From: David Sterba Date: Fri, 1 Sep 2017 16:45:34 +0200 Subject: btrfs-progs: tests: add testcase for 'fi du' and empty subvol Signed-off-by: David Sterba --- .../022-filesystem-du-on-empty-subvol/test.sh | 26 ++++++++++++++++++++++ 1 file changed, 26 insertions(+) create mode 100755 tests/misc-tests/022-filesystem-du-on-empty-subvol/test.sh (limited to 'tests') diff --git a/tests/misc-tests/022-filesystem-du-on-empty-subvol/test.sh b/tests/misc-tests/022-filesystem-du-on-empty-subvol/test.sh new file mode 100755 index 00000000..72cf076f --- /dev/null +++ b/tests/misc-tests/022-filesystem-du-on-empty-subvol/test.sh @@ -0,0 +1,26 @@ +#!/bin/bash +# +# btrfs fi du should handle empty subvolumes (with ino == 2) + +source "$TOP/tests/common" + +check_prereq mkfs.btrfs +check_prereq btrfs +setup_root_helper +prepare_test_dev + +run_check "$TOP/mkfs.btrfs" -f "$TEST_DEV" +run_check_mount_test_dev + +cd "$TEST_MNT" + +run_check $SUDO_HELPER "$TOP/btrfs" subvolume create test1 +run_check $SUDO_HELPER "$TOP/btrfs" subvolume create test1/test2 +run_check $SUDO_HELPER "$TOP/btrfs" subvolume snapshot test1 test1-snap +run_check $SUDO_HELPER "$TOP/btrfs" filesystem du -s test1 +run_check_stdout $SUDO_HELPER "$TOP/btrfs" filesystem du -s test1-snap | \ + grep -q "ERROR:.*ioctl" && _fail "empty subvolume not handled" + +cd .. + +run_check_umount_test_dev -- cgit v1.2.3 From 3a6895b823cfe950eda2b1866227a68edb050fab Mon Sep 17 00:00:00 2001 From: David Sterba Date: Fri, 1 Sep 2017 19:32:16 +0200 Subject: btrfs-progs: tests: cleanup loop device helpers Make the loop device helpers a bit more generic before moving them to the common helpers. Signed-off-by: David Sterba --- tests/mkfs-tests/001-basic-profiles/test.sh | 46 +++++++++++++++++------------ 1 file changed, 27 insertions(+), 19 deletions(-) (limited to 'tests') diff --git a/tests/mkfs-tests/001-basic-profiles/test.sh b/tests/mkfs-tests/001-basic-profiles/test.sh index 0dc9a2bd..216ad5fb 100755 --- a/tests/mkfs-tests/001-basic-profiles/test.sh +++ b/tests/mkfs-tests/001-basic-profiles/test.sh @@ -7,30 +7,37 @@ source $TOP/tests/common check_prereq mkfs.btrfs check_prereq btrfs -ndevs=4 -declare -a devs -dev1= - setup_root_helper -prepare_devices() +setup_loopdevs() +{ + if [ -z "$1" ]; then + _fail "setup_loopdevs needs a number" + fi + nloopdevs="$1" + loopdev_prefix=img + declare -a loopdevs + +} + +prepare_loopdevs() { - for i in `seq $ndevs`; do - touch img$i - chmod a+rw img$i - truncate -s0 img$i - truncate -s2g img$i - devs[$i]=`run_check_stdout $SUDO_HELPER losetup --find --show img$i` + for i in `seq $nloopdevs`; do + touch $loopdev_prefix$i + chmod a+rw $loopdev_prefix$i + truncate -s0 $loopdev_prefix$i + truncate -s2g $loopdev_prefix$i + loopdevs[$i]=`run_check_stdout $SUDO_HELPER losetup --find --show $loopdev_prefix$i` done } -cleanup_devices() +cleanup_loopdevs() { - for dev in ${devs[@]}; do + for dev in ${loopdevs[@]}; do run_check $SUDO_HELPER losetup -d $dev done - for i in `seq $ndevs`; do - truncate -s0 img$i + for i in `seq $nloopdevs`; do + truncate -s0 $loopdev_prefix$i done run_check $SUDO_HELPER losetup --all } @@ -58,12 +65,13 @@ test_mkfs_single() } test_mkfs_multi() { - test_do_mkfs $@ ${devs[@]} + test_do_mkfs $@ ${loopdevs[@]} test_get_info } -prepare_devices -dev1=${devs[1]} +setup_loopdevs 4 +prepare_loopdevs +dev1=${loopdevs[1]} test_mkfs_single test_mkfs_single -d single -m single @@ -89,4 +97,4 @@ test_mkfs_multi -d raid6 -m raid6 --mixed test_mkfs_multi -d dup -m dup test_mkfs_multi -d dup -m dup --mixed -cleanup_devices +cleanup_loopdevs -- cgit v1.2.3 From 528a5bf6ad1f90366c6422a2d1488f88a5df4abb Mon Sep 17 00:00:00 2001 From: David Sterba Date: Fri, 1 Sep 2017 20:14:03 +0200 Subject: btrfs-progs: tests: move loopdev helpers out of the testcase to common Signed-off-by: David Sterba --- tests/common | 41 +++++++++++++++++++++++++++++ tests/mkfs-tests/001-basic-profiles/test.sh | 33 ----------------------- 2 files changed, 41 insertions(+), 33 deletions(-) (limited to 'tests') diff --git a/tests/common b/tests/common index d0324a62..ebd41ba9 100644 --- a/tests/common +++ b/tests/common @@ -519,6 +519,47 @@ generate_dataset() { esac } +# prepare environment for loop devices, set up the following variables +# - nloopdevs -- number of desired devices +# - loopdevs -- array containing paths to all devices (after prepare is called) +# - loopdev_prefix -- file backed images starting with this string, 'img' by default +# +# $1: number of loop devices to be set up +setup_loopdevs() +{ + if [ -z "$1" ]; then + _fail "setup_loopdevs needs a number" + fi + nloopdevs="$1" + loopdev_prefix=img + declare -a loopdevs + +} + +# create all loop devices from a given loopdev environment +prepare_loopdevs() +{ + for i in `seq $nloopdevs`; do + touch $loopdev_prefix$i + chmod a+rw $loopdev_prefix$i + truncate -s0 $loopdev_prefix$i + truncate -s2g $loopdev_prefix$i + loopdevs[$i]=`run_check_stdout $SUDO_HELPER losetup --find --show $loopdev_prefix$i` + done +} + +# detach loop devices and reset their size to 0, does not delete the files +cleanup_loopdevs() +{ + for dev in ${loopdevs[@]}; do + run_check $SUDO_HELPER losetup -d $dev + done + for i in `seq $nloopdevs`; do + truncate -s0 $loopdev_prefix$i + done + run_check $SUDO_HELPER losetup --all +} + init_env() { TEST_MNT="${TEST_MNT:-$TOP/tests/mnt}" diff --git a/tests/mkfs-tests/001-basic-profiles/test.sh b/tests/mkfs-tests/001-basic-profiles/test.sh index 216ad5fb..854ee007 100755 --- a/tests/mkfs-tests/001-basic-profiles/test.sh +++ b/tests/mkfs-tests/001-basic-profiles/test.sh @@ -9,39 +9,6 @@ check_prereq btrfs setup_root_helper -setup_loopdevs() -{ - if [ -z "$1" ]; then - _fail "setup_loopdevs needs a number" - fi - nloopdevs="$1" - loopdev_prefix=img - declare -a loopdevs - -} - -prepare_loopdevs() -{ - for i in `seq $nloopdevs`; do - touch $loopdev_prefix$i - chmod a+rw $loopdev_prefix$i - truncate -s0 $loopdev_prefix$i - truncate -s2g $loopdev_prefix$i - loopdevs[$i]=`run_check_stdout $SUDO_HELPER losetup --find --show $loopdev_prefix$i` - done -} - -cleanup_loopdevs() -{ - for dev in ${loopdevs[@]}; do - run_check $SUDO_HELPER losetup -d $dev - done - for i in `seq $nloopdevs`; do - truncate -s0 $loopdev_prefix$i - done - run_check $SUDO_HELPER losetup --all -} - test_get_info() { run_check $SUDO_HELPER $TOP/btrfs inspect-internal dump-super $dev1 -- cgit v1.2.3 From 83fe48c54b3e4853b2b9502ed737683346b59e96 Mon Sep 17 00:00:00 2001 From: David Sterba Date: Fri, 1 Sep 2017 20:14:55 +0200 Subject: btrfs-progs: tests: convert misc/006-image-on-missing-device to loopdevs Signed-off-by: David Sterba --- .../misc-tests/006-image-on-missing-device/test.sh | 40 ++++------------------ 1 file changed, 6 insertions(+), 34 deletions(-) (limited to 'tests') diff --git a/tests/misc-tests/006-image-on-missing-device/test.sh b/tests/misc-tests/006-image-on-missing-device/test.sh index 5b6fe065..2766fb17 100755 --- a/tests/misc-tests/006-image-on-missing-device/test.sh +++ b/tests/misc-tests/006-image-on-missing-device/test.sh @@ -10,38 +10,8 @@ check_prereq btrfs-image check_prereq mkfs.btrfs check_prereq btrfs -ndevs=2 -declare -a devs -dev1= -dev2= - setup_root_helper - -# TODO: move the helpers to common - -prepare_devices() -{ - for i in `seq $ndevs`; do - touch img$i - chmod a+rw img$i - truncate -s0 img$i - truncate -s2g img$i - devs[$i]=`run_check_stdout $SUDO_HELPER losetup --find --show img$i` - done -} - -cleanup_devices() -{ - for dev in ${devs[@]}; do - run_mayfail $SUDO_HELPER losetup -d $dev - done - for i in `seq $ndevs`; do - truncate -s0 img$i - done - run_check $SUDO_HELPER losetup --all -} - test_image_dump() { run_check $SUDO_HELPER $TOP/btrfs check $dev1 @@ -65,13 +35,15 @@ test_run() # btrfs-image must not loop run_mayfail wipefs -a $dev2 run_check $SUDO_HELPER losetup -d $dev2 + unset loopdevs[2] run_check $SUDO_HELPER $TOP/btrfs filesystem show $dev1 test_image_dump } -prepare_devices -dev1=${devs[1]} -dev2=${devs[2]} +setup_loopdevs 2 +prepare_loopdevs +dev1=${loopdevs[1]} +dev2=${loopdevs[2]} test_run -cleanup_devices +cleanup_loopdevs -- cgit v1.2.3 From f47587d83db2fd7beaf1ceb9feb8c3e16e2b352c Mon Sep 17 00:00:00 2001 From: David Sterba Date: Fri, 1 Sep 2017 20:18:20 +0200 Subject: btrfs-progs: tests: convert misc/011-delete-missing-device to loopdevs Signed-off-by: David Sterba --- tests/misc-tests/011-delete-missing-device/test.sh | 39 ++++------------------ 1 file changed, 7 insertions(+), 32 deletions(-) (limited to 'tests') diff --git a/tests/misc-tests/011-delete-missing-device/test.sh b/tests/misc-tests/011-delete-missing-device/test.sh index 5b5f9786..e817d907 100755 --- a/tests/misc-tests/011-delete-missing-device/test.sh +++ b/tests/misc-tests/011-delete-missing-device/test.sh @@ -6,38 +6,11 @@ source $TOP/tests/common check_prereq mkfs.btrfs check_prereq btrfs -ndevs=4 -declare -a devs -dev1= -devtodel= - setup_root_helper -prepare_devices() -{ - for i in `seq $ndevs`; do - touch img$i - chmod a+rw img$i - truncate -s0 img$i - truncate -s2g img$i - devs[$i]=`run_check_stdout $SUDO_HELPER losetup --find --show img$i` - done -} - -cleanup_devices() -{ - for dev in ${devs[@]}; do - run_mayfail $SUDO_HELPER losetup -d $dev - done - for i in `seq $ndevs`; do - truncate -s0 img$i - done - run_check $SUDO_HELPER losetup --all -} - test_do_mkfs() { - run_check $SUDO_HELPER $TOP/mkfs.btrfs -f $@ ${devs[@]} + run_check $SUDO_HELPER $TOP/mkfs.btrfs -f $@ ${loopdevs[@]} run_check $SUDO_HELPER $TOP/btrfs inspect-internal dump-super $dev1 run_check $SUDO_HELPER $TOP/btrfs check $dev1 run_check $SUDO_HELPER $TOP/btrfs filesystem show @@ -47,6 +20,7 @@ test_wipefs() { run_check $SUDO_HELPER wipefs -a $devtodel run_check $SUDO_HELPER losetup -d $devtodel + unset loopdevs[3] run_check $SUDO_HELPER losetup --all run_check $TOP/btrfs filesystem show } @@ -70,13 +44,14 @@ test_delete_missing() run_check_umount_test_dev } -prepare_devices -dev1=${devs[1]} -devtodel=${devs[3]} +setup_loopdevs 4 +prepare_loopdevs +dev1=${loopdevs[1]} +devtodel=${loopdevs[3]} TEST_DEV=$dev1 test_do_mkfs test_wipefs test_delete_missing -cleanup_devices +cleanup_loopdevs -- cgit v1.2.3 From df4a04484aeffa5e88488a42307af4d60a4f3e62 Mon Sep 17 00:00:00 2001 From: David Sterba Date: Mon, 4 Sep 2017 18:33:48 +0200 Subject: btrfs-progs: tests: missing device and slack space report Verify that a missing device will not result in reporting a negative value interpreted as 16EiB. Signed-off-by: David Sterba --- .../023-device-usage-with-missing-device/test.sh | 40 ++++++++++++++++++++++ 1 file changed, 40 insertions(+) create mode 100755 tests/misc-tests/023-device-usage-with-missing-device/test.sh (limited to 'tests') diff --git a/tests/misc-tests/023-device-usage-with-missing-device/test.sh b/tests/misc-tests/023-device-usage-with-missing-device/test.sh new file mode 100755 index 00000000..3c8ba85c --- /dev/null +++ b/tests/misc-tests/023-device-usage-with-missing-device/test.sh @@ -0,0 +1,40 @@ +#!/bin/bash +# check if 'device slack' is reported as zero when a device is missing + +source "$TOP/tests/common" + +check_prereq btrfs-image +check_prereq mkfs.btrfs +check_prereq btrfs + +setup_root_helper + +test_run() +{ + # empty filesystem, with enough redundancy so degraded mount works + run_check $SUDO_HELPER "$TOP/mkfs.btrfs" -f -d raid1 -m raid1 $dev1 $dev2 + + TEST_DEV="$dev1" + run_check_mount_test_dev + run_check $SUDO_HELPER "$TOP/btrfs" filesystem usage "$TEST_MNT" + run_check_stdout $SUDO_HELPER "$TOP/btrfs" device usage "$TEST_MNT" | \ + grep -q "slack.*16\\.00EiB" && _fail + run_check_umount_test_dev + + run_mayfail wipefs -a $dev2 + run_check $SUDO_HELPER losetup -d $dev2 + unset loopdevs[2] + + run_check_mount_test_dev -o degraded,ro + run_check $SUDO_HELPER "$TOP/btrfs" filesystem usage "$TEST_MNT" + run_check_stdout $SUDO_HELPER "$TOP/btrfs" device usage "$TEST_MNT" | \ + grep -q "slack.*16\\.00EiB" && _fail + run_check_umount_test_dev +} + +setup_loopdevs 2 +prepare_loopdevs +dev1=${loopdevs[1]} +dev2=${loopdevs[2]} +test_run +cleanup_loopdevs -- cgit v1.2.3 From dbe96ecd3f38d37ee0793297e7dbfb699b4a5aec Mon Sep 17 00:00:00 2001 From: Qu Wenruo Date: Tue, 5 Sep 2017 10:24:15 +0900 Subject: btrfs-progs: tests: Add test case for mkfs --rootdir parameter Add test case which checks if -r|--rootdir mkfs option can handle symlink/char/block/fifo files. Signed-off-by: Qu Wenruo Signed-off-by: David Sterba --- .../009-special-files-for-rootdir/test.sh | 36 ++++++++++++++++++++++ 1 file changed, 36 insertions(+) create mode 100755 tests/mkfs-tests/009-special-files-for-rootdir/test.sh (limited to 'tests') diff --git a/tests/mkfs-tests/009-special-files-for-rootdir/test.sh b/tests/mkfs-tests/009-special-files-for-rootdir/test.sh new file mode 100755 index 00000000..d327a0d9 --- /dev/null +++ b/tests/mkfs-tests/009-special-files-for-rootdir/test.sh @@ -0,0 +1,36 @@ +#!/bin/bash +# Check if --rootdir can handle special files (socket/fifo/char/block) correctly +# +# --rootdir had a problem of filling dir items/indexes with wrong type +# and caused btrfs check to report such error +# +# Note: sock type is skipped in this test + +source "$TOP/tests/common" + +check_prereq mkfs.btrfs +check_prereq btrfs + +setup_root_helper # For mknod +prepare_test_dev + +# mknod can create FIFO/CHAR/BLOCK file but not SOCK. +# No neat tool to create socket file, unless using python or similar. +# So no SOCK is tested here +check_global_prereq mknod +check_global_prereq dd + +tmp=$(mktemp -d --tmpdir btrfs-progs-mkfs.rootdirXXXXXXX) + +run_check mkdir "$tmp/dir" +run_check mkdir -p "$tmp/dir/in/dir" +run_check mknod "$tmp/fifo" p +run_check $SUDO_HELPER mknod "$tmp/char" c 1 1 +run_check $SUDO_HELPER mknod "$tmp/block" b 1 1 +run_check dd if=/dev/zero bs=1M count=1 of="$tmp/regular" + +run_check $SUDO_HELPER "$TOP/mkfs.btrfs" -f -r "$tmp" "$TEST_DEV" + +rm -rf -- "$tmp" + +run_check $SUDO_HELPER "$TOP/btrfs" check "$TEST_DEV" -- cgit v1.2.3 From 02e9bb9f236e28801a7a2cb66c82ea9d04260018 Mon Sep 17 00:00:00 2001 From: "Misono, Tomohiro" Date: Tue, 5 Sep 2017 14:49:02 +0900 Subject: btrfs-progs: test: fix run_check_stdout() call _fail() run_check_stdout() uses "... | tee ... || _fail". However, since tee won't fail, _fail() is not called even if first command fails. Fix this by checking PIPESTATUS in the end. Signed-off-by: Tomohiro Misono Signed-off-by: David Sterba --- tests/common | 7 +++++-- 1 file changed, 5 insertions(+), 2 deletions(-) (limited to 'tests') diff --git a/tests/common b/tests/common index ebd41ba9..d450c2c8 100644 --- a/tests/common +++ b/tests/common @@ -154,9 +154,12 @@ run_check_stdout() echo "############### $@" >> "$RESULTS" 2>&1 if [[ $TEST_LOG =~ tty ]]; then echo "CMD(stdout): $@" > /dev/tty; fi if [ "$1" = 'root_helper' ]; then - "$@" 2>&1 | tee -a "$RESULTS" || _fail "failed: $@" + "$@" 2>&1 | tee -a "$RESULTS" else - $INSTRUMENT "$@" 2>&1 | tee -a "$RESULTS" || _fail "failed: $@" + $INSTRUMENT "$@" 2>&1 | tee -a "$RESULTS" + fi + if [ ${PIPESTATUS[0]} -ne 0 ]; then + _fail "failed: $@" fi } -- cgit v1.2.3 From cb39164f9d87e6309e315929a3b6a6791c5ee8f6 Mon Sep 17 00:00:00 2001 From: "Misono, Tomohiro" Date: Tue, 5 Sep 2017 14:50:03 +0900 Subject: btrfs-progs: test: fix name generation not to contain trailing spaces First patch causes test-convert fails. This is because generate_dataset() creates a name containing trailing spaces for "slow_symlink" type, and cause getfacl error in convert_test_perm(). (This is not noticed since original run_check_stdout() throws away the error.) Fix this by use space for delimiter for cut. Signed-off-by: Tomohiro Misono Signed-off-by: David Sterba --- tests/common | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) (limited to 'tests') diff --git a/tests/common b/tests/common index d450c2c8..08a25918 100644 --- a/tests/common +++ b/tests/common @@ -509,7 +509,7 @@ generate_dataset() { ;; slow_symlink) - long_filename=`date +%s | sha256sum | cut -f1 -d'-'` + long_filename=`date +%s | sha256sum | cut -f1 -d ' '` run_check $SUDO_HELPER touch "$dirpath/$long_filename" for num in $(seq 1 "$DATASET_SIZE"); do run_check $SUDO_HELPER ln -s "$dirpath/$long_filename" "$dirpath/slow_slink.$num" -- cgit v1.2.3 From 7299e0d294c0846da0af46775713f3697bfc3bcf Mon Sep 17 00:00:00 2001 From: David Sterba Date: Thu, 7 Sep 2017 14:44:45 +0200 Subject: btrfs-progs: tests: enhance post-rollback fsck tests The post-rollback helper still assumes just extN, we need an extra argument that'll get passed to fsck. Change all callsites at once so the tests do not fail temporarily. Signed-off-by: David Sterba --- tests/common.convert | 16 ++++++++++++++-- tests/convert-tests/005-delete-all-rollback/test.sh | 2 +- tests/convert-tests/008-readonly-image/test.sh | 2 +- tests/convert-tests/009-common-inode-flags/test.sh | 2 +- .../011-reiserfs-delete-all-rollback/test.sh | 2 +- .../013-reiserfs-common-inode-flags/test.sh | 2 +- 6 files changed, 19 insertions(+), 7 deletions(-) (limited to 'tests') diff --git a/tests/common.convert b/tests/common.convert index 1d98cda1..7d9a5be1 100644 --- a/tests/common.convert +++ b/tests/common.convert @@ -218,9 +218,21 @@ convert_test_post_checks_all() { } # do rollback and fsck +# $1: filesystem name or alias (ext2 includes ext3 and ext4), convert_test_post_rollback() { + local types + run_check "$TOP/btrfs-convert" --rollback "$TEST_DEV" - run_check fsck -n -t ext2,ext3,ext4 "$TEST_DEV" + if [ -z "$1" ]; then + _fail "missing filesystem type to check" + fi + case "$1" in + ext[234]) types=ext2,ext3,ext4 ;; + reiserfs) types=reiserfs ;; + *) _fail "unknown filesystem type to check: $1" ;; + esac + + run_check fsck -n -t "$types" "$TEST_DEV" } # simple wrapper for a convert test @@ -261,5 +273,5 @@ convert_test() { rm -- "$EXT_PERMTMP" rm -- "$EXT_ACLTMP" - convert_test_post_rollback + convert_test_post_rollback "$fstype" } diff --git a/tests/convert-tests/005-delete-all-rollback/test.sh b/tests/convert-tests/005-delete-all-rollback/test.sh index 316d57a0..19aa76d4 100755 --- a/tests/convert-tests/005-delete-all-rollback/test.sh +++ b/tests/convert-tests/005-delete-all-rollback/test.sh @@ -46,7 +46,7 @@ do_test() { cd "$here" run_check "$TOP/btrfs" filesystem sync "$TEST_MNT" run_check_umount_test_dev - convert_test_post_rollback + convert_test_post_rollback ext4 run_check_mount_convert_dev ext4 convert_test_post_check_checksums "$CHECKSUMTMP" diff --git a/tests/convert-tests/008-readonly-image/test.sh b/tests/convert-tests/008-readonly-image/test.sh index 73c9eff2..8551fb9b 100755 --- a/tests/convert-tests/008-readonly-image/test.sh +++ b/tests/convert-tests/008-readonly-image/test.sh @@ -24,4 +24,4 @@ if [ $? -ne 1 ]; then exit 1 fi run_check_umount_test_dev -convert_test_post_rollback +convert_test_post_rollback ext4 diff --git a/tests/convert-tests/009-common-inode-flags/test.sh b/tests/convert-tests/009-common-inode-flags/test.sh index 1f3106b4..cd7b5111 100755 --- a/tests/convert-tests/009-common-inode-flags/test.sh +++ b/tests/convert-tests/009-common-inode-flags/test.sh @@ -34,4 +34,4 @@ if [ $? -ne 0 ]; then fi run_check_umount_test_dev -convert_test_post_rollback +convert_test_post_rollback ext4 diff --git a/tests/convert-tests/011-reiserfs-delete-all-rollback/test.sh b/tests/convert-tests/011-reiserfs-delete-all-rollback/test.sh index 8c1b8057..98dc5d69 100755 --- a/tests/convert-tests/011-reiserfs-delete-all-rollback/test.sh +++ b/tests/convert-tests/011-reiserfs-delete-all-rollback/test.sh @@ -45,7 +45,7 @@ do_test() { cd "$here" run_check "$TOP/btrfs" filesystem sync "$TEST_MNT" run_check_umount_test_dev - convert_test_post_rollback + convert_test_post_rollback reiserfs run_check_mount_convert_dev reiserfs convert_test_post_check_checksums "$CHECKSUMTMP" diff --git a/tests/convert-tests/013-reiserfs-common-inode-flags/test.sh b/tests/convert-tests/013-reiserfs-common-inode-flags/test.sh index ba160262..d620a055 100755 --- a/tests/convert-tests/013-reiserfs-common-inode-flags/test.sh +++ b/tests/convert-tests/013-reiserfs-common-inode-flags/test.sh @@ -35,4 +35,4 @@ if [ $? -ne 0 ]; then fi run_check_umount_test_dev -convert_test_post_rollback +convert_test_post_rollback reiserfs -- cgit v1.2.3 From 6fb88e28596a6fc8802640197428fd4c9244703b Mon Sep 17 00:00:00 2001 From: David Sterba Date: Thu, 7 Sep 2017 17:29:51 +0200 Subject: btrfs-progs: tests: check for kernel support for reiserfs Signed-off-by: David Sterba --- tests/common.convert | 14 ++++++++++++++ tests/convert-tests.sh | 1 + tests/convert-tests/010-reiserfs-basic/test.sh | 4 ++++ .../convert-tests/011-reiserfs-delete-all-rollback/test.sh | 4 ++++ tests/convert-tests/012-reiserfs-large-hole-extent/test.sh | 4 ++++ .../convert-tests/013-reiserfs-common-inode-flags/test.sh | 4 ++++ tests/convert-tests/014-reiserfs-tail-handling/test.sh | 4 ++++ 7 files changed, 35 insertions(+) (limited to 'tests') diff --git a/tests/common.convert b/tests/common.convert index 7d9a5be1..1be804cf 100644 --- a/tests/common.convert +++ b/tests/common.convert @@ -275,3 +275,17 @@ convert_test() { convert_test_post_rollback "$fstype" } + +load_module_reiserfs() +{ + $SUDO_HELPER modprobe reiserfs +} + +check_kernel_support_reiserfs() +{ + if ! grep -iq 'reiserfs' /proc/filesystems; then + echo "WARNING: reiserfs filesystem not listed in /proc/filesystems, some tests might be skipped" + return 1 + fi + return 0 +} diff --git a/tests/convert-tests.sh b/tests/convert-tests.sh index 8e97b225..2a92a58b 100755 --- a/tests/convert-tests.sh +++ b/tests/convert-tests.sh @@ -22,6 +22,7 @@ export TEST_DEV rm -f "$RESULTS" check_kernel_support +check_kernel_support_reiserfs # anything expected by common.convert check_global_prereq getfacl check_global_prereq setfacl diff --git a/tests/convert-tests/010-reiserfs-basic/test.sh b/tests/convert-tests/010-reiserfs-basic/test.sh index 32e15deb..261f8704 100755 --- a/tests/convert-tests/010-reiserfs-basic/test.sh +++ b/tests/convert-tests/010-reiserfs-basic/test.sh @@ -3,6 +3,10 @@ source "$TOP/tests/common" source "$TOP/tests/common.convert" +if ! check_kernel_support_reiserfs >/dev/null; then + _not_run "no reiserfs support" +fi + setup_root_helper prepare_test_dev 512M check_prereq btrfs-convert diff --git a/tests/convert-tests/011-reiserfs-delete-all-rollback/test.sh b/tests/convert-tests/011-reiserfs-delete-all-rollback/test.sh index 98dc5d69..c6c3119e 100755 --- a/tests/convert-tests/011-reiserfs-delete-all-rollback/test.sh +++ b/tests/convert-tests/011-reiserfs-delete-all-rollback/test.sh @@ -4,6 +4,10 @@ source "$TOP/tests/common" source "$TOP/tests/common.convert" +if ! check_kernel_support_reiserfs >/dev/null; then + _not_run "no reiserfs support" +fi + setup_root_helper prepare_test_dev 512M check_prereq btrfs-convert diff --git a/tests/convert-tests/012-reiserfs-large-hole-extent/test.sh b/tests/convert-tests/012-reiserfs-large-hole-extent/test.sh index d9abbd8a..7a8d4972 100755 --- a/tests/convert-tests/012-reiserfs-large-hole-extent/test.sh +++ b/tests/convert-tests/012-reiserfs-large-hole-extent/test.sh @@ -8,6 +8,10 @@ source "$TOP/tests/common" source "$TOP/tests/common.convert" +if ! check_kernel_support_reiserfs >/dev/null; then + _not_run "no reiserfs support" +fi + setup_root_helper prepare_test_dev 512M check_prereq btrfs-convert diff --git a/tests/convert-tests/013-reiserfs-common-inode-flags/test.sh b/tests/convert-tests/013-reiserfs-common-inode-flags/test.sh index d620a055..e242a3b0 100755 --- a/tests/convert-tests/013-reiserfs-common-inode-flags/test.sh +++ b/tests/convert-tests/013-reiserfs-common-inode-flags/test.sh @@ -4,6 +4,10 @@ source "$TOP/tests/common" source "$TOP/tests/common.convert" +if ! check_kernel_support_reiserfs >/dev/null; then + _not_run "no reiserfs support" +fi + setup_root_helper prepare_test_dev 512M check_prereq btrfs-convert diff --git a/tests/convert-tests/014-reiserfs-tail-handling/test.sh b/tests/convert-tests/014-reiserfs-tail-handling/test.sh index aba5337b..f6131d96 100755 --- a/tests/convert-tests/014-reiserfs-tail-handling/test.sh +++ b/tests/convert-tests/014-reiserfs-tail-handling/test.sh @@ -9,6 +9,10 @@ source "$TOP/tests/common" source "$TOP/tests/common.convert" +if ! check_kernel_support_reiserfs >/dev/null; then + _not_run "no reiserfs support" +fi + setup_root_helper prepare_test_dev 512M check_prereq btrfs-convert -- cgit v1.2.3 From a351dd847873e2605e5796de94db235575304f72 Mon Sep 17 00:00:00 2001 From: "Misono, Tomohiro" Date: Thu, 7 Sep 2017 10:48:27 +0900 Subject: btrfs-progs: test: add new test for inspect-internal rootid This new test checks inspect-internal rootid - handle path to subvolume/directory/file as an argument - get different id for each subvolume - get the expected id for each file/directory (i.e. the same as containing subvolume) Signed-off-by: Tomohiro Misono Signed-off-by: David Sterba --- .../misc-tests/024-inspect-internal-rootid/test.sh | 57 ++++++++++++++++++++++ 1 file changed, 57 insertions(+) create mode 100755 tests/misc-tests/024-inspect-internal-rootid/test.sh (limited to 'tests') diff --git a/tests/misc-tests/024-inspect-internal-rootid/test.sh b/tests/misc-tests/024-inspect-internal-rootid/test.sh new file mode 100755 index 00000000..40e382bb --- /dev/null +++ b/tests/misc-tests/024-inspect-internal-rootid/test.sh @@ -0,0 +1,57 @@ +#!/bin/bash +# +# test commands of inspect-internal rootid + +source "$TOP/tests/common" + +check_prereq mkfs.btrfs +check_prereq btrfs + +prepare_test_dev + +run_check "$TOP/mkfs.btrfs" -f "$TEST_DEV" +run_check_mount_test_dev +run_check $SUDO_HELPER chmod a+rw "$TEST_MNT" +cd "$TEST_MNT" + +run_check "$TOP/btrfs" subvolume create sub +run_check "$TOP/btrfs" subvolume create sub/subsub +run_check mkdir dir +run_check touch file1 +run_check touch dir/file2 +run_check touch sub/file3 + +id1=$(run_check_stdout "$TOP/btrfs" inspect-internal rootid .) \ + || { echo $id1; exit 1; } +id2=$(run_check_stdout "$TOP/btrfs" inspect-internal rootid sub) \ + || { echo $id2; exit 1; } +id3=$(run_check_stdout "$TOP/btrfs" inspect-internal rootid sub/subsub) \ + || { echo $id3; exit 1; } +id4=$(run_check_stdout "$TOP/btrfs" inspect-internal rootid dir) \ + || { echo $id4; exit 1; } +id5=$(run_check_stdout "$TOP/btrfs" inspect-internal rootid file1) \ + || { echo $id5; exit 1; } +id6=$(run_check_stdout "$TOP/btrfs" inspect-internal rootid dir/file2) \ + || { echo $id6; exit 1; } +id7=$(run_check_stdout "$TOP/btrfs" inspect-internal rootid sub/file3) \ + || { echo $id7; exit 1; } + +if ! ([ $id1 -ne $id2 ] && [ $id1 -ne $id3 ] && [ $id2 -ne $id3 ]); then + _fail "inspect-internal rootid: each subvolume must have different id" +fi + +if ! ([ $id1 -eq $id4 ] && [ $id1 -eq $id5 ] && [ $id1 -eq $id6 ]); then + _fail "inspect-internal rootid: rootid mismatch found" +fi + +if ! ([ $id2 -eq $id7 ]); then + _fail "inspect-internal rootid: rootid mismatch found" +fi + +run_mustfail "should fail for non existent file" \ + "$TOP/btrfs" inspect-internal rootid no_such_file +run_mustfail "should fail for non-btrfs filesystem" \ + "$TOP/btrfs" inspect-internal rootid /dev/null + +cd .. +run_check_umount_test_dev -- cgit v1.2.3 From 67b7b4bc4090e83059384b8c870ed09ab410ad5b Mon Sep 17 00:00:00 2001 From: David Sterba Date: Mon, 11 Sep 2017 17:29:03 +0200 Subject: btrfs-progs: tests: fix run_mustfail in cli-tests/007-check-force The sanity check in run_mustfail does not work as expected and allowed the command to continue without the missing parameter Bugzilla: https://bugzilla.kernel.org/show_bug.cgi?id=196893 Signed-off-by: David Sterba --- tests/cli-tests/007-check-force/test.sh | 9 ++++++--- 1 file changed, 6 insertions(+), 3 deletions(-) (limited to 'tests') diff --git a/tests/cli-tests/007-check-force/test.sh b/tests/cli-tests/007-check-force/test.sh index ecee0166..8b60033f 100755 --- a/tests/cli-tests/007-check-force/test.sh +++ b/tests/cli-tests/007-check-force/test.sh @@ -12,10 +12,13 @@ prepare_test_dev run_check "$TOP/mkfs.btrfs" -f "$TEST_DEV" run_check_mount_test_dev -run_mustfail $SUDO_HELPER "$TOP/btrfs" check "$TEST_DEV" +run_mustfail "checking mounted filesystem without --force" \ + $SUDO_HELPER "$TOP/btrfs" check "$TEST_DEV" run_check $SUDO_HELPER "$TOP/btrfs" check --force "$TEST_DEV" -run_mustfail $SUDO_HELPER "$TOP/btrfs" check --force --repair "$TEST_DEV" +run_mustfail "checking mounted filesystem with --force --repair" \ + $SUDO_HELPER "$TOP/btrfs" check --force --repair "$TEST_DEV" run_check_umount_test_dev run_check $SUDO_HELPER "$TOP/btrfs" check "$TEST_DEV" run_check $SUDO_HELPER "$TOP/btrfs" check --force "$TEST_DEV" -run_mustfail $SUDO_HELPER "$TOP/btrfs" check --force --repair "$TEST_DEV" +run_mustfail "--force --repair on unmounted filesystem" \ + $SUDO_HELPER "$TOP/btrfs" check --force --repair "$TEST_DEV" -- cgit v1.2.3 From 0766330f8504dfa876894795fecf8feaff8c1e9c Mon Sep 17 00:00:00 2001 From: Nick Terrell Date: Mon, 11 Sep 2017 21:27:52 +0200 Subject: btrfs-progs: tests: add testing image for zstd for btrfs-restore Adds tests for the new features based on a prebuilt btrfs image with a zstd compressed file. Split from the previous patch. Signed-off-by: Nick Terrell [ with some cleanups ] Signed-off-by: David Sterba --- .../025-zstd-compression/compress.raw.xz | Bin 0 -> 18220 bytes tests/misc-tests/025-zstd-compression/test.sh | 56 +++++++++++++++++++++ 2 files changed, 56 insertions(+) create mode 100644 tests/misc-tests/025-zstd-compression/compress.raw.xz create mode 100755 tests/misc-tests/025-zstd-compression/test.sh (limited to 'tests') diff --git a/tests/misc-tests/025-zstd-compression/compress.raw.xz b/tests/misc-tests/025-zstd-compression/compress.raw.xz new file mode 100644 index 00000000..67aaf17f Binary files /dev/null and b/tests/misc-tests/025-zstd-compression/compress.raw.xz differ diff --git a/tests/misc-tests/025-zstd-compression/test.sh b/tests/misc-tests/025-zstd-compression/test.sh new file mode 100755 index 00000000..e95dcb36 --- /dev/null +++ b/tests/misc-tests/025-zstd-compression/test.sh @@ -0,0 +1,56 @@ +#!/bin/bash +# Test zstd compression support on a prebuilt btrfs image + +source "$TOP/tests/common" + +check_prereq btrfs +check_global_prereq md5sum + +# Extract the test image +image=$(extract_image compress.raw.xz) + +check_dump_tree() { + local image=$1 + local string=$2 + + run_check_stdout "$TOP/btrfs" inspect-internal dump-tree "$image" \ + | grep -q "$string" \ + || _fail "btrfs inspect-internal dump-tree didn't print $string" +} + +# Check that there are blocks of each compression type +check_dump_tree "$image" "extent compression 1 (zlib)" +check_dump_tree "$image" "extent compression 2 (lzo)" +check_dump_tree "$image" "extent compression 3 (zstd)" + +# Check that the filesystem has incompat COMPRESS_ZSTD +run_check_stdout "$TOP/btrfs" inspect-internal dump-super -f "$image" \ + | grep -q COMPRESS_ZSTD \ + || _fail "btrfs inspect-internal dump-super no incompat COMPRESS_ZSTD" + +# Create a temporary directory and restore the filesystem +restore_tmp=$(mktemp --tmpdir -d btrfs-progs-022-zstd-compression.XXXXXXXXXX) +run_check "$TOP/btrfs" restore "$image" "$restore_tmp" + +# Expect 3 files +num_files=$(ls -1 "$restore_tmp" | wc -l) +[ "$num_files" == 3 ] || _fail "number of files does not match" + +check_md5() { + local file="$1" + local expect_md5="$2" + + md5=$(run_check_stdout md5sum "$file" | cut -d ' ' -f 1) + [ "$md5" == "$expect_md5" ] \ + || _fail "$file digest $md5 does not match $expect_md5" +} + +# Each should be 200K of zeros +expect_md5=$(dd if=/dev/zero bs=1K count=200 status=none | md5sum | cut -d ' ' -f 1) +check_md5 "$restore_tmp/zlib" "$expect_md5" +check_md5 "$restore_tmp/lzo" "$expect_md5" +check_md5 "$restore_tmp/zstd" "$expect_md5" + +# Clean up +rm -r -- "$restore_tmp" +rm -- "$image" -- cgit v1.2.3 From 03fb34b6b46ebc54a98d3d0e264e60432e68bb8d Mon Sep 17 00:00:00 2001 From: David Sterba Date: Tue, 12 Sep 2017 18:17:51 +0200 Subject: btrfs-progs: tests: remove temporary loopdev files Remove files for testing loop devices when using the helper. Signed-off-by: David Sterba --- tests/common | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) (limited to 'tests') diff --git a/tests/common b/tests/common index 08a25918..1c098e8e 100644 --- a/tests/common +++ b/tests/common @@ -551,7 +551,7 @@ prepare_loopdevs() done } -# detach loop devices and reset their size to 0, does not delete the files +# detach loop devices and reset their size to 0, delete the files afterwards cleanup_loopdevs() { for dev in ${loopdevs[@]}; do @@ -559,6 +559,7 @@ cleanup_loopdevs() done for i in `seq $nloopdevs`; do truncate -s0 $loopdev_prefix$i + rm -- "$loopdev_prefix$i" done run_check $SUDO_HELPER losetup --all } -- cgit v1.2.3 From 01bcf68cf52286f47302f59cd13ffd56bb5cc996 Mon Sep 17 00:00:00 2001 From: David Sterba Date: Tue, 12 Sep 2017 18:22:24 +0200 Subject: btrfs-progs: tests: remove temporary images in mkfs/005 and mkfs/006 Signed-off-by: David Sterba --- tests/mkfs-tests/005-long-device-name-for-ssd/test.sh | 1 + tests/mkfs-tests/006-partitioned-loopdev/test.sh | 1 + 2 files changed, 2 insertions(+) (limited to 'tests') diff --git a/tests/mkfs-tests/005-long-device-name-for-ssd/test.sh b/tests/mkfs-tests/005-long-device-name-for-ssd/test.sh index 63fb1785..5bdf50e0 100755 --- a/tests/mkfs-tests/005-long-device-name-for-ssd/test.sh +++ b/tests/mkfs-tests/005-long-device-name-for-ssd/test.sh @@ -38,3 +38,4 @@ run_check $SUDO_HELPER $TOP/btrfs inspect-internal dump-super $dmdev run_check $SUDO_HELPER dmsetup remove $dmname run_mayfail $SUDO_HELPER losetup -d $loopdev run_check truncate -s0 img +rm img diff --git a/tests/mkfs-tests/006-partitioned-loopdev/test.sh b/tests/mkfs-tests/006-partitioned-loopdev/test.sh index 12f37842..0c77e5cd 100755 --- a/tests/mkfs-tests/006-partitioned-loopdev/test.sh +++ b/tests/mkfs-tests/006-partitioned-loopdev/test.sh @@ -29,3 +29,4 @@ done # cleanup run_check $SUDO_HELPER losetup -d $loopdev run_check truncate -s0 img +rm img -- cgit v1.2.3 From 509af95c9281549cc93805aca19ed6e7f8de024a Mon Sep 17 00:00:00 2001 From: David Sterba Date: Fri, 15 Sep 2017 16:18:00 +0200 Subject: btrfs-progs: tests: make sure _is_file_or_command does not get confused The test cli/007-check-force reports something like: $ type -p '--string that starts with dashes' bash: type: --: invalid option Add the option/argument separator. Signed-off-by: David Sterba --- tests/common | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) (limited to 'tests') diff --git a/tests/common b/tests/common index 1c098e8e..eb525a4d 100644 --- a/tests/common +++ b/tests/common @@ -35,7 +35,7 @@ _is_file_or_command() if [ -f "$msg" -o -d "$msg" -o -b "$msg" ]; then return 0 fi - msg=$(type -p "$msg") + msg=$(type -p -- "$msg") if [ -f "$msg" ]; then return 0 fi -- cgit v1.2.3 From ac717518287eca607eb9f53465d752c2ea18c9e9 Mon Sep 17 00:00:00 2001 From: Nicholas D Steeves Date: Sun, 17 Sep 2017 19:52:26 -0400 Subject: btrfs-progs: tests: Add required IETF Trust copyright to SHA implementation Signed-off-by: Nicholas D Steeves Signed-off-by: David Sterba --- tests/sha-private.h | 4 ++++ 1 file changed, 4 insertions(+) (limited to 'tests') diff --git a/tests/sha-private.h b/tests/sha-private.h index 6e9c4520..d94d4374 100644 --- a/tests/sha-private.h +++ b/tests/sha-private.h @@ -1,5 +1,9 @@ /************************ sha-private.h ************************/ /***************** See RFC 6234 for details. *******************/ +/* Copyright (c) 2011 IETF Trust and the persons identified as */ +/* authors of the code. All rights reserved. */ +/* See sha.h for terms of use and redistribution. */ + #ifndef _SHA_PRIVATE__H #define _SHA_PRIVATE__H /* -- cgit v1.2.3 From 5b2fbc6f4e93286273f9e7a67834a02004f3f875 Mon Sep 17 00:00:00 2001 From: Nicholas D Steeves Date: Sun, 17 Sep 2017 19:52:27 -0400 Subject: btrfs-progs: tests: Remove misleading BCP 78 boilerplate from SHA implementation BCP 78 applies to RFC 6234, but sha224-256.c is Simplified BSD. This causes the following lintian error when building on Debian and Debian derivatives: E: btrfs-progs source: license-problem-non-free-RFC-BCP78 tests/sha224-256.c Please consult the following email from debian-legal@lists.debian.org for more information: https://lists.debian.org/debian-legal/2017/08/msg00004.html Signed-off-by: Nicholas D Steeves [ I've copied too much from the RFC that's not related to the code, covered by the explicit copyright notice in the file ] Signed-off-by: David Sterba --- tests/sha224-256.c | 20 -------------------- 1 file changed, 20 deletions(-) (limited to 'tests') diff --git a/tests/sha224-256.c b/tests/sha224-256.c index 2d963e65..82124a03 100644 --- a/tests/sha224-256.c +++ b/tests/sha224-256.c @@ -1,23 +1,3 @@ -/* -RFC 6234 SHAs, HMAC-SHAs, and HKDF May 2011 - - -Copyright Notice - - Copyright (c) 2011 IETF Trust and the persons identified as the - document authors. All rights reserved. - - This document is subject to BCP 78 and the IETF Trust's Legal - Provisions Relating to IETF Documents - (http://trustee.ietf.org/license-info) in effect on the date of - publication of this document. Please review these documents - carefully, as they describe your rights and restrictions with respect - to this document. Code Components extracted from this document must - include Simplified BSD License text as described in Section 4.e of - the Trust Legal Provisions and are provided without warranty as - described in the Simplified BSD License. -*/ - /************************* sha224-256.c ************************/ /***************** See RFC 6234 for details. *******************/ /* Copyright (c) 2011 IETF Trust and the persons identified as */ -- cgit v1.2.3 From 5faec9843985b9e9324a2c562d22e111bcdd668a Mon Sep 17 00:00:00 2001 From: David Sterba Date: Mon, 25 Sep 2017 15:09:21 +0200 Subject: btrfs-progs: tests: check there are no unprintable characters in btrfs-image -ss output Signed-off-by: David Sterba --- .../026-image-non-printable-chars/test.sh | 30 ++++++++++++++++++++++ 1 file changed, 30 insertions(+) create mode 100755 tests/misc-tests/026-image-non-printable-chars/test.sh (limited to 'tests') diff --git a/tests/misc-tests/026-image-non-printable-chars/test.sh b/tests/misc-tests/026-image-non-printable-chars/test.sh new file mode 100755 index 00000000..8018586f --- /dev/null +++ b/tests/misc-tests/026-image-non-printable-chars/test.sh @@ -0,0 +1,30 @@ +#!/bin/bash +# check that sanitized names with matching crc do not contain unprintable +# characters, namely 0x7f + +source "$TOP/tests/common" + +check_prereq mkfs.btrfs +check_prereq btrfs + +prepare_test_dev + +run_check "$TOP/mkfs.btrfs" -f "$TEST_DEV" +run_check_mount_test_dev +run_check $SUDO_HELPER chmod a+rw "$TEST_MNT" + +# known to produce char 0x7f == 127 +touch "$TEST_MNT/|5gp!" + +run_check_umount_test_dev + +run_check $SUDO_HELPER "$TOP/btrfs-image" -ss "$TEST_DEV" img +run_check $SUDO_HELPER "$TOP/btrfs-image" -r img img.restored +run_check_stdout $SUDO_HELPER "$TOP/btrfs" inspect-internal dump-tree img.restored > img.dump + +ch7f=$(echo -en '\x7f') +if grep -q "$ch7f" img.dump; then + _fail "found char 0x7f in the sanitized names" +fi + +rm -f -- img img.restored img.dump -- cgit v1.2.3 From fa5b3a7fe246ff5e3291a9fbd200eaf35104254b Mon Sep 17 00:00:00 2001 From: "Misono, Tomohiro" Date: Tue, 3 Oct 2017 15:47:26 +0900 Subject: btrfs-progs: misc-test: use raid1 for data to enable mount with -o degraded kernel 4.14 introduces new function for checking if all chunks is ok for mount with -o degraded option. commit 21634a19f646 ("btrfs: Introduce a function to check if all chunks a OK for degraded rw mount") As a result, raid0 profile cannot be mounted with -o degraded on 4.14. This causes failure of the misc-test 011 "delete missing device". Fix this by using raid1 profile for both data and metadata. This also should work for kernel before 4.13. Signed-off-by: Tomohiro Misono Signed-off-by: David Sterba --- tests/misc-tests/011-delete-missing-device/test.sh | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) (limited to 'tests') diff --git a/tests/misc-tests/011-delete-missing-device/test.sh b/tests/misc-tests/011-delete-missing-device/test.sh index e817d907..8a1b14b1 100755 --- a/tests/misc-tests/011-delete-missing-device/test.sh +++ b/tests/misc-tests/011-delete-missing-device/test.sh @@ -50,7 +50,7 @@ dev1=${loopdevs[1]} devtodel=${loopdevs[3]} TEST_DEV=$dev1 -test_do_mkfs +test_do_mkfs -m raid1 -d raid1 test_wipefs test_delete_missing -- cgit v1.2.3 From 1d4224e4aab14f4967e54f96860f544072cb0442 Mon Sep 17 00:00:00 2001 From: David Sterba Date: Thu, 5 Oct 2017 16:25:21 +0200 Subject: btrfs-progs: tests: don't list toplevel subvolme in 'subvol list' Signed-off-by: David Sterba --- .../027-subvol-list-deleted-toplevel/test.sh | 18 ++++++++++++++++++ 1 file changed, 18 insertions(+) create mode 100755 tests/misc-tests/027-subvol-list-deleted-toplevel/test.sh (limited to 'tests') diff --git a/tests/misc-tests/027-subvol-list-deleted-toplevel/test.sh b/tests/misc-tests/027-subvol-list-deleted-toplevel/test.sh new file mode 100755 index 00000000..ee41d71f --- /dev/null +++ b/tests/misc-tests/027-subvol-list-deleted-toplevel/test.sh @@ -0,0 +1,18 @@ +#!/bin/bash +# check that the toplevel subvolume is not listed as regular or deleted + +source "$TOP/tests/common" + +check_prereq mkfs.btrfs +check_prereq btrfs + +prepare_test_dev + +run_check "$TOP/mkfs.btrfs" -f "$TEST_DEV" +run_check_mount_test_dev +run_check_stdout $SUDO_HELPER "$TOP/btrfs" subvolume list "$TEST_MNT" | + grep -i -q "id 5" && _fail "found toplevel among regular" +run_check_stdout $SUDO_HELPER "$TOP/btrfs" subvolume list -d "$TEST_MNT" | + grep -i -q "id 5.*DELETED" && _fail "found toplevel among deleted" + +run_check_umount_test_dev -- cgit v1.2.3 From 7dbd7f21d5167952085aea0222522f7a809e111c Mon Sep 17 00:00:00 2001 From: Su Yue Date: Thu, 28 Sep 2017 15:29:19 +0800 Subject: btrfs-progs: tests: arg override in command line Lowmem mode only repairs few cases which has a beacon file ".lowmem_repairable" in the case' directory. However, defining TEST_ENABLE_OVERRIDE=true in command line does work in above strategy. Because _skip_spec() in tests/common.local isn't interpreted by shell in that case. Solve it by making _skip_spec() always be defined in common.local. Reported-by: David Sterba Signed-off-by: Su Yue [ keep the _skip_spec check ] Signed-off-by: David Sterba --- tests/common.local | 11 +++++------ 1 file changed, 5 insertions(+), 6 deletions(-) (limited to 'tests') diff --git a/tests/common.local b/tests/common.local index 4f56bb08..d2b8d073 100644 --- a/tests/common.local +++ b/tests/common.local @@ -3,14 +3,13 @@ # additional arguments to various commands # already defined, eg. via make argument -if [ -n "$TEST_ENABLE_OVERRIDE" ]; then - return -fi +if [ -z "$TEST_ENABLE_OVERRIDE" ]; then + # set to 'true' + TEST_ENABLE_OVERRIDE=false -# set to 'true' -TEST_ENABLE_OVERRIDE=false + TEST_ARGS_CHECK=--mode=lowmem +fi -TEST_ARGS_CHECK=--mode=lowmem # gets arguments of a current command and can decide if the argument insertion # should happen, eg. if some option combination does not make sense or would -- cgit v1.2.3 From a69c1917c255c453cecf8d693471324a77d8a1aa Mon Sep 17 00:00:00 2001 From: David Sterba Date: Tue, 10 Oct 2017 14:57:26 +0200 Subject: btrfs-progs: tests: fsck/007 fix so check --force works Signed-off-by: David Sterba --- tests/cli-tests/007-check-force/test.sh | 12 ++++++++++-- 1 file changed, 10 insertions(+), 2 deletions(-) (limited to 'tests') diff --git a/tests/cli-tests/007-check-force/test.sh b/tests/cli-tests/007-check-force/test.sh index 8b60033f..12b30205 100755 --- a/tests/cli-tests/007-check-force/test.sh +++ b/tests/cli-tests/007-check-force/test.sh @@ -8,9 +8,15 @@ check_prereq mkfs.btrfs check_prereq btrfs setup_root_helper -prepare_test_dev -run_check "$TOP/mkfs.btrfs" -f "$TEST_DEV" +# we need to use a real block device, because the check opens the device in +# exclusive mode, that unfortunatelly behaves differently for direct file +# access and for the real /dev/loop0 device +setup_loopdevs 1 +prepare_loopdevs +TEST_DEV=${loopdevs[1]} + +run_check $SUDO_HELPER "$TOP/mkfs.btrfs" -f "$TEST_DEV" run_check_mount_test_dev run_mustfail "checking mounted filesystem without --force" \ $SUDO_HELPER "$TOP/btrfs" check "$TEST_DEV" @@ -22,3 +28,5 @@ run_check $SUDO_HELPER "$TOP/btrfs" check "$TEST_DEV" run_check $SUDO_HELPER "$TOP/btrfs" check --force "$TEST_DEV" run_mustfail "--force --repair on unmounted filesystem" \ $SUDO_HELPER "$TOP/btrfs" check --force --repair "$TEST_DEV" + +cleanup_loopdevs -- cgit v1.2.3 From 5286ec58f54eb9c51f960ede71238938068836ed Mon Sep 17 00:00:00 2001 From: David Sterba Date: Thu, 12 Oct 2017 14:29:27 +0200 Subject: btrfs-progs: tests: add more configure option coverage * test convert spec string * explicitly ask for zstd, as it is now autodetected Signed-off-by: David Sterba --- tests/build-tests.sh | 9 +++++++++ 1 file changed, 9 insertions(+) (limited to 'tests') diff --git a/tests/build-tests.sh b/tests/build-tests.sh index 4df29331..15db42af 100755 --- a/tests/build-tests.sh +++ b/tests/build-tests.sh @@ -87,6 +87,15 @@ build_make_targets conf='--disable-convert' build_make_targets +conf='--with-convert=ext2' +build_make_targets + +conf='--with-convert=ext2,reiserfs' +build_make_targets + +conf='--enable-zstd' +build_make_targets + # debugging builds, just the default targets target='D=1' buildme -- cgit v1.2.3 From eca65a8977aba6f02dad820a88aacbb9120421ca Mon Sep 17 00:00:00 2001 From: Qu Wenruo Date: Wed, 1 Mar 2017 09:21:51 +0800 Subject: btrfs-progs: tests: Allow check test to repair in lowmem mode for certain errors Since lowmem mode can repair certain corruptions (mostly in fs tree), insert a beacon into each fsck test cases to allow some of them be tested in lowmem mode. With this patch, fsck option override will check the beacon file ".lowmem_repairable" in the same directory of the test image, and if the beacon exists, then it will also run lowmem mode repair to repair the image. Signed-off-by: Qu Wenruo Signed-off-by: David Sterba --- tests/common.local | 15 ++++++++++++++- tests/fsck-tests/004-no-dir-index/.lowmem_repairable | 0 .../009-no-dir-item-or-index/.lowmem_repairable | 0 .../010-no-rootdir-inode-item/.lowmem_repairable | 0 tests/fsck-tests/011-no-inode-item/.lowmem_repairable | 0 .../fsck-tests/016-wrong-inode-nbytes/.lowmem_repairable | 0 .../017-missing-all-file-extent/.lowmem_repairable | 0 7 files changed, 14 insertions(+), 1 deletion(-) create mode 100644 tests/fsck-tests/004-no-dir-index/.lowmem_repairable create mode 100644 tests/fsck-tests/009-no-dir-item-or-index/.lowmem_repairable create mode 100644 tests/fsck-tests/010-no-rootdir-inode-item/.lowmem_repairable create mode 100644 tests/fsck-tests/011-no-inode-item/.lowmem_repairable create mode 100644 tests/fsck-tests/016-wrong-inode-nbytes/.lowmem_repairable create mode 100644 tests/fsck-tests/017-missing-all-file-extent/.lowmem_repairable (limited to 'tests') diff --git a/tests/common.local b/tests/common.local index d2b8d073..f5e96f5b 100644 --- a/tests/common.local +++ b/tests/common.local @@ -14,11 +14,24 @@ fi # gets arguments of a current command and can decide if the argument insertion # should happen, eg. if some option combination does not make sense or would # break tests +# +# Return 0 if we need to skip option override +# Return 1 if we don't need to skip option override _skip_spec() { + local beacon + + beacon=.lowmem_repairable + + # For lowmem repair, only support fs tree repair for now + # So we place lowmem repair beacon in the same dir of the test case if echo "$TEST_ARGS_CHECK" | grep -q 'mode=lowmem' && echo "$@" | grep -q -- '--repair'; then - return 0 + dir="$(dirname ${@: -1})" + if [ -f ${dir}/${beacon} ]; then + return 1; + fi + return 0; fi return 1 } diff --git a/tests/fsck-tests/004-no-dir-index/.lowmem_repairable b/tests/fsck-tests/004-no-dir-index/.lowmem_repairable new file mode 100644 index 00000000..e69de29b diff --git a/tests/fsck-tests/009-no-dir-item-or-index/.lowmem_repairable b/tests/fsck-tests/009-no-dir-item-or-index/.lowmem_repairable new file mode 100644 index 00000000..e69de29b diff --git a/tests/fsck-tests/010-no-rootdir-inode-item/.lowmem_repairable b/tests/fsck-tests/010-no-rootdir-inode-item/.lowmem_repairable new file mode 100644 index 00000000..e69de29b diff --git a/tests/fsck-tests/011-no-inode-item/.lowmem_repairable b/tests/fsck-tests/011-no-inode-item/.lowmem_repairable new file mode 100644 index 00000000..e69de29b diff --git a/tests/fsck-tests/016-wrong-inode-nbytes/.lowmem_repairable b/tests/fsck-tests/016-wrong-inode-nbytes/.lowmem_repairable new file mode 100644 index 00000000..e69de29b diff --git a/tests/fsck-tests/017-missing-all-file-extent/.lowmem_repairable b/tests/fsck-tests/017-missing-all-file-extent/.lowmem_repairable new file mode 100644 index 00000000..e69de29b -- cgit v1.2.3 From 59e067ada7e8af5894a9f865a2c8d65be57746c3 Mon Sep 17 00:00:00 2001 From: Su Yue Date: Wed, 27 Sep 2017 14:34:40 +0800 Subject: btrfs-progs: fsck-tests: 027/bad_extent_inline_ref_type This case is for avoiding crash in lowmem check mode. Field type of extent_inline_ref in an extent is corrupted. Signed-off-by: Su Yue Signed-off-by: David Sterba --- .../bad-extent-inline-ref-type.raw.xz | Bin 0 -> 17144 bytes 1 file changed, 0 insertions(+), 0 deletions(-) create mode 100644 tests/fsck-tests/027-bad-extent-inline-ref-type/bad-extent-inline-ref-type.raw.xz (limited to 'tests') diff --git a/tests/fsck-tests/027-bad-extent-inline-ref-type/bad-extent-inline-ref-type.raw.xz b/tests/fsck-tests/027-bad-extent-inline-ref-type/bad-extent-inline-ref-type.raw.xz new file mode 100644 index 00000000..09d82019 Binary files /dev/null and b/tests/fsck-tests/027-bad-extent-inline-ref-type/bad-extent-inline-ref-type.raw.xz differ -- cgit v1.2.3 From 9896b43f70df300feb792487f92b1b1ed87a49ce Mon Sep 17 00:00:00 2001 From: "Misono, Tomohiro" Date: Wed, 18 Oct 2017 11:00:43 +0900 Subject: btrfs-progs: test: add new cli-test for subvol get/set-default Add new test to check functionality of subvol get/set-default. Signed-off-by: Tomohiro Misono [ fix style issues, add missing SUDO_HELPER ] Signed-off-by: David Sterba --- .../008-subvolume-get-set-default/test.sh | 47 ++++++++++++++++++++++ 1 file changed, 47 insertions(+) create mode 100755 tests/cli-tests/008-subvolume-get-set-default/test.sh (limited to 'tests') diff --git a/tests/cli-tests/008-subvolume-get-set-default/test.sh b/tests/cli-tests/008-subvolume-get-set-default/test.sh new file mode 100755 index 00000000..9318002e --- /dev/null +++ b/tests/cli-tests/008-subvolume-get-set-default/test.sh @@ -0,0 +1,47 @@ +#!/bin/bash +# test for "subvolume get-default/set-default" + +check_default_id() +{ + id=$(run_check_stdout $SUDO_HELPER "$TOP/btrfs" subvolume get-default .) \ + || { echo "$id"; exit 1; } + if $(echo "$id" | grep -vq "ID $1"); then + _fail "subvolume get-default: default id is not $1, but $id" + fi +} + +source "$TOP/tests/common" + +check_prereq mkfs.btrfs +check_prereq btrfs + +setup_root_helper +prepare_test_dev + +run_check "$TOP/mkfs.btrfs" -f "$TEST_DEV" +run_check_mount_test_dev +cd "$TEST_MNT" + +check_default_id 5 + +# check "subvol set-default " +run_check $SUDO_HELPER "$TOP/btrfs" subvolume create sub +id=$(run_check_stdout "$TOP/btrfs" inspect-internal rootid sub) +run_check $SUDO_HELPER "$TOP/btrfs" subvolume set-default "$id" . +check_default_id "$id" + +run_mustfail "set-default to non existent id" \ + $SUDO_HELPER "$TOP/btrfs" subvolume set-default 100 . + +# check "subvol set-default " +run_check $SUDO_HELPER "$TOP/btrfs" subvolume create sub2 +id=$(run_check_stdout "$TOP/btrfs" inspect-internal rootid sub2) +run_check $SUDO_HELPER "$TOP/btrfs" subvolume set-default ./sub2 +check_default_id "$id" + +run_check $SUDO_HELPER mkdir sub2/dir +run_mustfail "set-default to normal directory" \ + $SUDO_HELPER "$TOP/btrfs" subvolume set-default ./sub2/dir + +cd .. +run_check_umount_test_dev -- cgit v1.2.3 From a6e5cdef437ca9f47e70f928fa8c4338d2037ad5 Mon Sep 17 00:00:00 2001 From: David Sterba Date: Fri, 27 Oct 2017 15:50:34 +0200 Subject: btrfs-progs: tests: don't pass size to prepare_test_dev if not necessary Most tests don't need a specific size of the test device, the default 2GiB should be fine. Signed-off-by: David Sterba --- tests/cli-tests/002-balance-full-no-filters/test.sh | 2 +- tests/cli-tests/004-send-parent-multi-subvol/test.sh | 2 +- tests/cli-tests/005-qgroup-show/test.sh | 2 +- tests/convert-tests/001-ext2-basic/test.sh | 2 +- tests/convert-tests/002-ext3-basic/test.sh | 2 +- tests/convert-tests/003-ext4-basic/test.sh | 2 +- tests/convert-tests/004-ext2-backup-superblock-ranges/test.sh | 2 +- tests/convert-tests/005-delete-all-rollback/test.sh | 2 +- tests/convert-tests/006-large-hole-extent/test.sh | 2 +- tests/convert-tests/007-unsupported-block-sizes/test.sh | 2 +- tests/convert-tests/008-readonly-image/test.sh | 2 +- tests/convert-tests/009-common-inode-flags/test.sh | 2 +- tests/convert-tests/010-reiserfs-basic/test.sh | 2 +- tests/convert-tests/011-reiserfs-delete-all-rollback/test.sh | 2 +- tests/convert-tests/012-reiserfs-large-hole-extent/test.sh | 2 +- tests/convert-tests/013-reiserfs-common-inode-flags/test.sh | 2 +- tests/convert-tests/014-reiserfs-tail-handling/test.sh | 2 +- tests/fsck-tests/013-extent-tree-rebuild/test.sh | 2 +- tests/fsck-tests/024-clear-space-cache/test.sh | 2 +- tests/misc-tests/005-convert-progress-thread-crash/test.sh | 2 +- tests/misc-tests/016-send-clone-src/test.sh | 2 +- tests/misc-tests/017-recv-stream-malformatted/test.sh | 2 +- tests/misc-tests/018-recv-end-of-stream/test.sh | 2 +- 23 files changed, 23 insertions(+), 23 deletions(-) (limited to 'tests') diff --git a/tests/cli-tests/002-balance-full-no-filters/test.sh b/tests/cli-tests/002-balance-full-no-filters/test.sh index 0501aad2..0475ea73 100755 --- a/tests/cli-tests/002-balance-full-no-filters/test.sh +++ b/tests/cli-tests/002-balance-full-no-filters/test.sh @@ -8,7 +8,7 @@ check_prereq mkfs.btrfs check_prereq btrfs setup_root_helper -prepare_test_dev 2g +prepare_test_dev run_check "$TOP/mkfs.btrfs" -f "$TEST_DEV" run_check_mount_test_dev diff --git a/tests/cli-tests/004-send-parent-multi-subvol/test.sh b/tests/cli-tests/004-send-parent-multi-subvol/test.sh index 49226f9b..c1348b50 100755 --- a/tests/cli-tests/004-send-parent-multi-subvol/test.sh +++ b/tests/cli-tests/004-send-parent-multi-subvol/test.sh @@ -8,7 +8,7 @@ check_prereq mkfs.btrfs check_prereq btrfs setup_root_helper -prepare_test_dev 2g +prepare_test_dev run_check "$TOP/mkfs.btrfs" -f "$TEST_DEV" run_check_mount_test_dev diff --git a/tests/cli-tests/005-qgroup-show/test.sh b/tests/cli-tests/005-qgroup-show/test.sh index 2af13033..d9a91831 100755 --- a/tests/cli-tests/005-qgroup-show/test.sh +++ b/tests/cli-tests/005-qgroup-show/test.sh @@ -8,7 +8,7 @@ check_prereq mkfs.btrfs check_prereq btrfs setup_root_helper -prepare_test_dev 2g +prepare_test_dev run_check "$TOP/mkfs.btrfs" -f "$TEST_DEV" run_check_mount_test_dev diff --git a/tests/convert-tests/001-ext2-basic/test.sh b/tests/convert-tests/001-ext2-basic/test.sh index d94bf0b6..af75d948 100755 --- a/tests/convert-tests/001-ext2-basic/test.sh +++ b/tests/convert-tests/001-ext2-basic/test.sh @@ -4,7 +4,7 @@ source "$TOP/tests/common" source "$TOP/tests/common.convert" setup_root_helper -prepare_test_dev 512M +prepare_test_dev check_prereq btrfs-convert check_global_prereq mke2fs diff --git a/tests/convert-tests/002-ext3-basic/test.sh b/tests/convert-tests/002-ext3-basic/test.sh index f00e0e82..233e2d94 100755 --- a/tests/convert-tests/002-ext3-basic/test.sh +++ b/tests/convert-tests/002-ext3-basic/test.sh @@ -4,7 +4,7 @@ source "$TOP/tests/common" source "$TOP/tests/common.convert" setup_root_helper -prepare_test_dev 512M +prepare_test_dev check_prereq btrfs-convert check_global_prereq mke2fs diff --git a/tests/convert-tests/003-ext4-basic/test.sh b/tests/convert-tests/003-ext4-basic/test.sh index d33f1d9a..baf6115c 100755 --- a/tests/convert-tests/003-ext4-basic/test.sh +++ b/tests/convert-tests/003-ext4-basic/test.sh @@ -4,7 +4,7 @@ source "$TOP/tests/common" source "$TOP/tests/common.convert" setup_root_helper -prepare_test_dev 512M +prepare_test_dev check_prereq btrfs-convert check_global_prereq mke2fs diff --git a/tests/convert-tests/004-ext2-backup-superblock-ranges/test.sh b/tests/convert-tests/004-ext2-backup-superblock-ranges/test.sh index 0ce62f78..cf354d40 100755 --- a/tests/convert-tests/004-ext2-backup-superblock-ranges/test.sh +++ b/tests/convert-tests/004-ext2-backup-superblock-ranges/test.sh @@ -18,7 +18,7 @@ check_global_prereq e2fsck check_global_prereq xzcat setup_root_helper -prepare_test_dev 512M +prepare_test_dev # override common function function check_image() { diff --git a/tests/convert-tests/005-delete-all-rollback/test.sh b/tests/convert-tests/005-delete-all-rollback/test.sh index 19aa76d4..31fa2c4b 100755 --- a/tests/convert-tests/005-delete-all-rollback/test.sh +++ b/tests/convert-tests/005-delete-all-rollback/test.sh @@ -6,7 +6,7 @@ source "$TOP/tests/common" source "$TOP/tests/common.convert" setup_root_helper -prepare_test_dev 512M +prepare_test_dev check_prereq btrfs-convert check_global_prereq mke2fs diff --git a/tests/convert-tests/006-large-hole-extent/test.sh b/tests/convert-tests/006-large-hole-extent/test.sh index 0edb6280..38e97055 100755 --- a/tests/convert-tests/006-large-hole-extent/test.sh +++ b/tests/convert-tests/006-large-hole-extent/test.sh @@ -9,7 +9,7 @@ source "$TOP/tests/common" source "$TOP/tests/common.convert" setup_root_helper -prepare_test_dev 512M +prepare_test_dev check_prereq btrfs-convert check_global_prereq mke2fs diff --git a/tests/convert-tests/007-unsupported-block-sizes/test.sh b/tests/convert-tests/007-unsupported-block-sizes/test.sh index f1b29726..ef010202 100755 --- a/tests/convert-tests/007-unsupported-block-sizes/test.sh +++ b/tests/convert-tests/007-unsupported-block-sizes/test.sh @@ -5,7 +5,7 @@ source "$TOP/tests/common" source "$TOP/tests/common.convert" setup_root_helper -prepare_test_dev 512M +prepare_test_dev check_prereq btrfs-convert check_global_prereq mke2fs diff --git a/tests/convert-tests/008-readonly-image/test.sh b/tests/convert-tests/008-readonly-image/test.sh index 8551fb9b..064bc271 100755 --- a/tests/convert-tests/008-readonly-image/test.sh +++ b/tests/convert-tests/008-readonly-image/test.sh @@ -5,7 +5,7 @@ source "$TOP/tests/common" source "$TOP/tests/common.convert" setup_root_helper -prepare_test_dev 512M +prepare_test_dev check_prereq btrfs-convert check_global_prereq mke2fs diff --git a/tests/convert-tests/009-common-inode-flags/test.sh b/tests/convert-tests/009-common-inode-flags/test.sh index cd7b5111..6d159993 100755 --- a/tests/convert-tests/009-common-inode-flags/test.sh +++ b/tests/convert-tests/009-common-inode-flags/test.sh @@ -5,7 +5,7 @@ source "$TOP/tests/common" source "$TOP/tests/common.convert" setup_root_helper -prepare_test_dev 512M +prepare_test_dev check_prereq btrfs-convert check_global_prereq mke2fs check_global_prereq lsattr diff --git a/tests/convert-tests/010-reiserfs-basic/test.sh b/tests/convert-tests/010-reiserfs-basic/test.sh index 261f8704..87008f15 100755 --- a/tests/convert-tests/010-reiserfs-basic/test.sh +++ b/tests/convert-tests/010-reiserfs-basic/test.sh @@ -8,7 +8,7 @@ if ! check_kernel_support_reiserfs >/dev/null; then fi setup_root_helper -prepare_test_dev 512M +prepare_test_dev check_prereq btrfs-convert check_global_prereq mkreiserfs diff --git a/tests/convert-tests/011-reiserfs-delete-all-rollback/test.sh b/tests/convert-tests/011-reiserfs-delete-all-rollback/test.sh index c6c3119e..0b8366c8 100755 --- a/tests/convert-tests/011-reiserfs-delete-all-rollback/test.sh +++ b/tests/convert-tests/011-reiserfs-delete-all-rollback/test.sh @@ -9,7 +9,7 @@ if ! check_kernel_support_reiserfs >/dev/null; then fi setup_root_helper -prepare_test_dev 512M +prepare_test_dev check_prereq btrfs-convert check_global_prereq mkreiserfs diff --git a/tests/convert-tests/012-reiserfs-large-hole-extent/test.sh b/tests/convert-tests/012-reiserfs-large-hole-extent/test.sh index 7a8d4972..dde1b3eb 100755 --- a/tests/convert-tests/012-reiserfs-large-hole-extent/test.sh +++ b/tests/convert-tests/012-reiserfs-large-hole-extent/test.sh @@ -13,7 +13,7 @@ if ! check_kernel_support_reiserfs >/dev/null; then fi setup_root_helper -prepare_test_dev 512M +prepare_test_dev check_prereq btrfs-convert check_global_prereq mkreiserfs diff --git a/tests/convert-tests/013-reiserfs-common-inode-flags/test.sh b/tests/convert-tests/013-reiserfs-common-inode-flags/test.sh index e242a3b0..a15240ce 100755 --- a/tests/convert-tests/013-reiserfs-common-inode-flags/test.sh +++ b/tests/convert-tests/013-reiserfs-common-inode-flags/test.sh @@ -9,7 +9,7 @@ if ! check_kernel_support_reiserfs >/dev/null; then fi setup_root_helper -prepare_test_dev 512M +prepare_test_dev check_prereq btrfs-convert check_global_prereq mkreiserfs check_global_prereq chattr diff --git a/tests/convert-tests/014-reiserfs-tail-handling/test.sh b/tests/convert-tests/014-reiserfs-tail-handling/test.sh index f6131d96..335c0091 100755 --- a/tests/convert-tests/014-reiserfs-tail-handling/test.sh +++ b/tests/convert-tests/014-reiserfs-tail-handling/test.sh @@ -14,7 +14,7 @@ if ! check_kernel_support_reiserfs >/dev/null; then fi setup_root_helper -prepare_test_dev 512M +prepare_test_dev check_prereq btrfs-convert check_global_prereq md5sum check_global_prereq mkreiserfs diff --git a/tests/fsck-tests/013-extent-tree-rebuild/test.sh b/tests/fsck-tests/013-extent-tree-rebuild/test.sh index 90fe2e83..d71c1b2e 100755 --- a/tests/fsck-tests/013-extent-tree-rebuild/test.sh +++ b/tests/fsck-tests/013-extent-tree-rebuild/test.sh @@ -7,7 +7,7 @@ check_prereq mkfs.btrfs check_prereq btrfs setup_root_helper -prepare_test_dev 1G +prepare_test_dev # test whether fsck can rebuild a corrupted extent tree test_extent_tree_rebuild() diff --git a/tests/fsck-tests/024-clear-space-cache/test.sh b/tests/fsck-tests/024-clear-space-cache/test.sh index 6cf8440b..76ebcb6b 100755 --- a/tests/fsck-tests/024-clear-space-cache/test.sh +++ b/tests/fsck-tests/024-clear-space-cache/test.sh @@ -7,7 +7,7 @@ check_prereq btrfs check_prereq mkfs.btrfs setup_root_helper -prepare_test_dev 1G +prepare_test_dev run_check $SUDO_HELPER "$TOP/mkfs.btrfs" -f "$TEST_DEV" run_check_mount_test_dev diff --git a/tests/misc-tests/005-convert-progress-thread-crash/test.sh b/tests/misc-tests/005-convert-progress-thread-crash/test.sh index 054069c2..bc71e1fd 100755 --- a/tests/misc-tests/005-convert-progress-thread-crash/test.sh +++ b/tests/misc-tests/005-convert-progress-thread-crash/test.sh @@ -6,7 +6,7 @@ source $TOP/tests/common check_prereq btrfs-convert mkfs.ext4 -V &>/dev/null || _not_run "mkfs.ext4 not found" -prepare_test_dev 1G +prepare_test_dev for ((i = 0; i < 20; i++)); do echo "loop $i" >>$RESULTS diff --git a/tests/misc-tests/016-send-clone-src/test.sh b/tests/misc-tests/016-send-clone-src/test.sh index 479da677..2780ebbd 100755 --- a/tests/misc-tests/016-send-clone-src/test.sh +++ b/tests/misc-tests/016-send-clone-src/test.sh @@ -10,7 +10,7 @@ check_prereq btrfs setup_root_helper -prepare_test_dev 1g +prepare_test_dev run_check "$TOP/mkfs.btrfs" -f "$TEST_DEV" run_check_mount_test_dev diff --git a/tests/misc-tests/017-recv-stream-malformatted/test.sh b/tests/misc-tests/017-recv-stream-malformatted/test.sh index 3756be27..d199a72e 100755 --- a/tests/misc-tests/017-recv-stream-malformatted/test.sh +++ b/tests/misc-tests/017-recv-stream-malformatted/test.sh @@ -9,7 +9,7 @@ check_prereq btrfs setup_root_helper -prepare_test_dev 1g +prepare_test_dev run_check "$TOP/mkfs.btrfs" -f "$TEST_DEV" run_check_mount_test_dev diff --git a/tests/misc-tests/018-recv-end-of-stream/test.sh b/tests/misc-tests/018-recv-end-of-stream/test.sh index 3b8a0319..9ca035f7 100755 --- a/tests/misc-tests/018-recv-end-of-stream/test.sh +++ b/tests/misc-tests/018-recv-end-of-stream/test.sh @@ -9,7 +9,7 @@ check_prereq mkfs.btrfs check_prereq btrfs setup_root_helper -prepare_test_dev 1g +prepare_test_dev here=`pwd` -- cgit v1.2.3 From 7a060ea02662a3cbf4b2707de830c835f43658ef Mon Sep 17 00:00:00 2001 From: "Lakshmipathi.G" Date: Fri, 27 Oct 2017 11:30:24 +0530 Subject: btrfs-progs: tests/common: Display warning only after searching for btrfs kernel module Signed-off-by: Lakshmipathi.G Signed-off-by: David Sterba --- tests/common | 8 ++++++-- 1 file changed, 6 insertions(+), 2 deletions(-) (limited to 'tests') diff --git a/tests/common b/tests/common index eb525a4d..dec090fe 100644 --- a/tests/common +++ b/tests/common @@ -428,8 +428,12 @@ run_check_umount_test_dev() check_kernel_support() { if ! grep -iq 'btrfs' /proc/filesystems; then - echo "WARNING: btrfs filesystem not listed in /proc/filesystems, some tests might fail" - return 1 + run_check $SUDO_HELPER modprobe btrfs + if ! grep -iq 'btrfs' /proc/filesystems; then + echo \ +"WARNING: btrfs filesystem not found in /proc/filesystems, some tests might fail" + return 1 + fi fi return 0 } -- cgit v1.2.3 From 5a78f577a3d46b5fc75d88db600a97e32a3f4a26 Mon Sep 17 00:00:00 2001 From: Qu Wenruo Date: Tue, 10 Oct 2017 15:32:28 +0800 Subject: btrfs-progs: tests/fsck: Add test case image for 'rescue fix-dev-size' The image has 2 problems mixed: 1) Too small super total_bytes This super total_bytes is manually modified to create such problem. 2) Unaligned dev item total_bytes This is created by v4.12 kernel, with 128M + 2K device added, and original device removed. Then we can create such image with unaligned dev item total_bytes. Signed-off-by: Qu Wenruo Reviewed-by: Nikolay Borisov Signed-off-by: David Sterba --- .../dev_and_super_mismatch_unaligned.raw.xz | Bin 0 -> 21536 bytes 1 file changed, 0 insertions(+), 0 deletions(-) create mode 100644 tests/fsck-tests/028-unaligned-super-dev-sizes/dev_and_super_mismatch_unaligned.raw.xz (limited to 'tests') diff --git a/tests/fsck-tests/028-unaligned-super-dev-sizes/dev_and_super_mismatch_unaligned.raw.xz b/tests/fsck-tests/028-unaligned-super-dev-sizes/dev_and_super_mismatch_unaligned.raw.xz new file mode 100644 index 00000000..153e514a Binary files /dev/null and b/tests/fsck-tests/028-unaligned-super-dev-sizes/dev_and_super_mismatch_unaligned.raw.xz differ -- cgit v1.2.3 From f49e2bc3dcef87b58472801d6f4de694c3158c36 Mon Sep 17 00:00:00 2001 From: David Sterba Date: Fri, 27 Oct 2017 18:03:42 +0200 Subject: btrfs-progs: tests: extend fsck/028 to test fix-device-size and mount Signed-off-by: David Sterba --- .../028-unaligned-super-dev-sizes/test.sh | 26 ++++++++++++++++++++++ 1 file changed, 26 insertions(+) create mode 100755 tests/fsck-tests/028-unaligned-super-dev-sizes/test.sh (limited to 'tests') diff --git a/tests/fsck-tests/028-unaligned-super-dev-sizes/test.sh b/tests/fsck-tests/028-unaligned-super-dev-sizes/test.sh new file mode 100755 index 00000000..6f315fae --- /dev/null +++ b/tests/fsck-tests/028-unaligned-super-dev-sizes/test.sh @@ -0,0 +1,26 @@ +#!/bin/bash +# +# An image with mis-aligned superblock total_bytes, that will be found and +# fixed by 'check' or fixed by 'rescue fix-device-size' + +source "$TOP/tests/common" + +check_prereq btrfs +prepare_test_dev +setup_root_helper + +check_all_images + +image=$(extract_image "./dev_and_super_mismatch_unaligned.raw.xz") + +# detect and fix +run_check "$TOP/btrfs" rescue fix-device-size "$image" +# no problem found +run_check "$TOP/btrfs" rescue fix-device-size "$image" +# check if fix-device-size worked +run_check "$TOP/btrfs" check "$image" +# mount test +run_check_mount_test_dev +run_check_umount_test_dev + +rm -f "$image" -- cgit v1.2.3 From 752f42d2c044b3ff47391bef81395bd1a2245eb8 Mon Sep 17 00:00:00 2001 From: Lu Fengqi Date: Fri, 3 Nov 2017 16:28:03 +0800 Subject: btrfs-progs: test: Add test image for lowmem mode file extent interrupt Add a image that the inlined extent coexist with the regular extent. Reported-by: Marc MERLIN Signed-off-by: Lu Fengqi Signed-off-by: David Sterba --- .../020-extent-ref-cases/inline_regular_coexist.img | Bin 0 -> 4096 bytes 1 file changed, 0 insertions(+), 0 deletions(-) create mode 100644 tests/fsck-tests/020-extent-ref-cases/inline_regular_coexist.img (limited to 'tests') diff --git a/tests/fsck-tests/020-extent-ref-cases/inline_regular_coexist.img b/tests/fsck-tests/020-extent-ref-cases/inline_regular_coexist.img new file mode 100644 index 00000000..cf15cc14 Binary files /dev/null and b/tests/fsck-tests/020-extent-ref-cases/inline_regular_coexist.img differ -- cgit v1.2.3 From febfb10263a31558ad5bbffd8bf11c51b4395812 Mon Sep 17 00:00:00 2001 From: Lu Fengqi Date: Fri, 3 Nov 2017 16:28:06 +0800 Subject: btrfs-progs: test: Add test image for lowmem mode referencer count mismatch false alert Add a image which can reproduce the extent item referencer count mismatch false alert for lowmem mode. Reported-by: Marc MERLIN Signed-off-by: Lu Fengqi Signed-off-by: David Sterba --- .../ref_count_mismatch_false_alert.img | Bin 0 -> 4096 bytes 1 file changed, 0 insertions(+), 0 deletions(-) create mode 100644 tests/fsck-tests/020-extent-ref-cases/ref_count_mismatch_false_alert.img (limited to 'tests') diff --git a/tests/fsck-tests/020-extent-ref-cases/ref_count_mismatch_false_alert.img b/tests/fsck-tests/020-extent-ref-cases/ref_count_mismatch_false_alert.img new file mode 100644 index 00000000..85110a81 Binary files /dev/null and b/tests/fsck-tests/020-extent-ref-cases/ref_count_mismatch_false_alert.img differ -- cgit v1.2.3 From fe23461921f9c218045a41922272debf4f1e6106 Mon Sep 17 00:00:00 2001 From: Qu Wenruo Date: Wed, 22 Nov 2017 17:03:19 +0800 Subject: btrfs-progs: fsck-test: Introduce test case for false data extent backref lost Introduce a new test image, which has an extent item with no inlined extent data ref, but all keyed extent data ref. Only in this case we can trigger fase data extent backref lost bug in lowmem mode. Signed-off-by: Qu Wenruo Signed-off-by: David Sterba --- .../020-extent-ref-cases/keyed_data_ref_only.img | Bin 0 -> 4096 bytes 1 file changed, 0 insertions(+), 0 deletions(-) create mode 100644 tests/fsck-tests/020-extent-ref-cases/keyed_data_ref_only.img (limited to 'tests') diff --git a/tests/fsck-tests/020-extent-ref-cases/keyed_data_ref_only.img b/tests/fsck-tests/020-extent-ref-cases/keyed_data_ref_only.img new file mode 100644 index 00000000..668589f4 Binary files /dev/null and b/tests/fsck-tests/020-extent-ref-cases/keyed_data_ref_only.img differ -- cgit v1.2.3 From 95dd77e2d50f214a9e2d5ec09fb9db64e9d69818 Mon Sep 17 00:00:00 2001 From: Qu Wenruo Date: Wed, 22 Nov 2017 17:03:23 +0800 Subject: btrfs-progs: fsck-test: Add new image with shared block ref only metadata backref The image is dumped by modifying kernel to sleep long enough before merging relocation trees, so we can just copy the whole image to other place before kernel begins to merge reloc trees. And the base image is created by the following script to bump metadata size: ------ dev=~/test.img mnt=/mnt/btrfs umount $mnt &> /dev/null fallocate -l 128M $dev mkfs.btrfs -f -n 4k -m single -d single $dev mount $dev $mnt -o nospace_cache,max_inline=2048 btrfs subvolume create $mnt/src for i in $(seq -w 0 128); do xfs_io -f -c "pwrite 0 2k" $mnt/src/file_$i > /dev/null done for i in $(seq -w 0 64); do btrfs subvolume snapshot $mnt/src/ $mnt/snapshot_$i touch $mnt/snapshot_$i/new done sync ------ The image triggers several corner cases that the old lowmem mode didn't consider. Like metadata backref with FULL_BACKREF flag and only SHARED_BLOCK_REF backrefs for metadata. And several tree reloc trees with shared leaves/nodes to confuse old lowmem mode. Signed-off-by: Qu Wenruo Signed-off-by: David Sterba --- .../020-extent-ref-cases/shared_block_ref_only.raw.xz | Bin 0 -> 217204 bytes 1 file changed, 0 insertions(+), 0 deletions(-) create mode 100644 tests/fsck-tests/020-extent-ref-cases/shared_block_ref_only.raw.xz (limited to 'tests') diff --git a/tests/fsck-tests/020-extent-ref-cases/shared_block_ref_only.raw.xz b/tests/fsck-tests/020-extent-ref-cases/shared_block_ref_only.raw.xz new file mode 100644 index 00000000..538fb4f2 Binary files /dev/null and b/tests/fsck-tests/020-extent-ref-cases/shared_block_ref_only.raw.xz differ -- cgit v1.2.3 From 263184c7d286efe5200939686818400d0e3afa5d Mon Sep 17 00:00:00 2001 From: Qu Wenruo Date: Wed, 22 Nov 2017 17:03:25 +0800 Subject: btrfs-progs: fsck-tests: Introduce test case with keyed data backref with shared tree blocks For snapshot shared tree blocks with source subvolume, the keyed backref counter only counts the exclusive owned references. In the following case, 258 is a snapshot of 257, which inherits all the reference to this data extent. ------ item 4 key (12582912 EXTENT_ITEM 524288) itemoff 3741 itemsize 140 refs 179 gen 9 flags DATA extent data backref root 257 objectid 258 offset 0 count 49 extent data backref root 257 objectid 257 offset 0 count 1 extent data backref root 256 objectid 258 offset 0 count 128 extent data backref root 256 objectid 257 offset 0 count 1 ------ However lowmem mode used to iterate the whole inode to find all references, and doesn't care if a reference is already counted by the shared tree block. Add the test case to check it. Signed-off-by: Qu Wenruo Signed-off-by: David Sterba --- .../keyed_data_ref_with_shared_leaf.img | Bin 0 -> 19456 bytes 1 file changed, 0 insertions(+), 0 deletions(-) create mode 100644 tests/fsck-tests/020-extent-ref-cases/keyed_data_ref_with_shared_leaf.img (limited to 'tests') diff --git a/tests/fsck-tests/020-extent-ref-cases/keyed_data_ref_with_shared_leaf.img b/tests/fsck-tests/020-extent-ref-cases/keyed_data_ref_with_shared_leaf.img new file mode 100644 index 00000000..2ce5068f Binary files /dev/null and b/tests/fsck-tests/020-extent-ref-cases/keyed_data_ref_with_shared_leaf.img differ -- cgit v1.2.3 From 4e4c5d354912b2e8adaf4c64bfee00b1bdc420af Mon Sep 17 00:00:00 2001 From: Qu Wenruo Date: Fri, 10 Nov 2017 09:34:17 +0800 Subject: btrfs-progs: test/fsck: Introduce test images containing tree reloc tree Reloc tree is a special tree with very short life span. It acts as a special snapshot for any tree, with related nodes/leaves or EXTENT_DATA modified to point to new position. Considering the short life span and its special purpose, it should be quite reasonable to keep them as both corner case for fsck and educational dump for anyone interested in relocation. Signed-off-by: Qu Wenruo Signed-off-by: David Sterba --- tests/fsck-tests/027-tree-reloc-tree/test.sh | 19 +++++++++++++++++++ .../tree_reloc_for_data_reloc.img.xz | Bin 0 -> 2112 bytes .../tree_reloc_for_fs_tree.img.xz | Bin 0 -> 2424 bytes 3 files changed, 19 insertions(+) create mode 100755 tests/fsck-tests/027-tree-reloc-tree/test.sh create mode 100644 tests/fsck-tests/027-tree-reloc-tree/tree_reloc_for_data_reloc.img.xz create mode 100644 tests/fsck-tests/027-tree-reloc-tree/tree_reloc_for_fs_tree.img.xz (limited to 'tests') diff --git a/tests/fsck-tests/027-tree-reloc-tree/test.sh b/tests/fsck-tests/027-tree-reloc-tree/test.sh new file mode 100755 index 00000000..afad1e8d --- /dev/null +++ b/tests/fsck-tests/027-tree-reloc-tree/test.sh @@ -0,0 +1,19 @@ +#!/bin/bash +# Make sure btrfs check won't report any false alerts for valid image with +# reloc tree. +# +# Also due to the short life span of reloc tree, save the as dump example for +# later usage. + +source "$TOP/tests/common" + +check_prereq btrfs + +check_image() { + local image + + image=$1 + run_check "$TOP/btrfs" check "$image" +} + +check_all_images diff --git a/tests/fsck-tests/027-tree-reloc-tree/tree_reloc_for_data_reloc.img.xz b/tests/fsck-tests/027-tree-reloc-tree/tree_reloc_for_data_reloc.img.xz new file mode 100644 index 00000000..66d8bde6 Binary files /dev/null and b/tests/fsck-tests/027-tree-reloc-tree/tree_reloc_for_data_reloc.img.xz differ diff --git a/tests/fsck-tests/027-tree-reloc-tree/tree_reloc_for_fs_tree.img.xz b/tests/fsck-tests/027-tree-reloc-tree/tree_reloc_for_fs_tree.img.xz new file mode 100644 index 00000000..22af324b Binary files /dev/null and b/tests/fsck-tests/027-tree-reloc-tree/tree_reloc_for_fs_tree.img.xz differ -- cgit v1.2.3 From 17538334e17f9f84faf458157c12c3b548738492 Mon Sep 17 00:00:00 2001 From: Qu Wenruo Date: Fri, 10 Nov 2017 09:34:18 +0800 Subject: btrfs-progs: test/fsck/020: Cleanup custom check function by overriding check_image function Signed-off-by: Qu Wenruo Signed-off-by: David Sterba --- tests/fsck-tests/020-extent-ref-cases/test.sh | 17 ++++++++--------- 1 file changed, 8 insertions(+), 9 deletions(-) (limited to 'tests') diff --git a/tests/fsck-tests/020-extent-ref-cases/test.sh b/tests/fsck-tests/020-extent-ref-cases/test.sh index 1e1e4e23..0c4f7848 100755 --- a/tests/fsck-tests/020-extent-ref-cases/test.sh +++ b/tests/fsck-tests/020-extent-ref-cases/test.sh @@ -1,6 +1,6 @@ #!/bin/bash -# In order to confirm that btrfsck supports to check a variety of refs, add the -# following cases: +# In order to confirm that 'btrfs check' supports checking a variety of refs, +# add the following cases: # # * keyed_block_ref # * keyed_data_ref @@ -19,12 +19,11 @@ source "$TOP/tests/common" check_prereq btrfs -for img in *.img *.raw.xz -do - image=$(extract_image "$img") +check_image() { + local image - # Since the return value bug is already fixed, we don't need - # the old grep hack to detect bug. + image=$1 run_check "$TOP/btrfs" check "$image" - rm -f "$image" -done +} + +check_all_images -- cgit v1.2.3 From 37c737d7cbb3d03be26b1d000c186dac4b73e00e Mon Sep 17 00:00:00 2001 From: Qu Wenruo Date: Fri, 10 Nov 2017 09:34:19 +0800 Subject: btrfs-progs: test/fsck/021: Cleanup custom check by overriding check_image Signed-off-by: Qu Wenruo [ update comment ] Signed-off-by: David Sterba --- .../021-partially-dropped-snapshot-case/test.sh | 16 ++++++++++------ 1 file changed, 10 insertions(+), 6 deletions(-) (limited to 'tests') diff --git a/tests/fsck-tests/021-partially-dropped-snapshot-case/test.sh b/tests/fsck-tests/021-partially-dropped-snapshot-case/test.sh index 44a33a63..5d997e24 100755 --- a/tests/fsck-tests/021-partially-dropped-snapshot-case/test.sh +++ b/tests/fsck-tests/021-partially-dropped-snapshot-case/test.sh @@ -1,18 +1,22 @@ #!/bin/bash -# confirm whether btrfsck supports to check a partially dropped snapshot +# confirm whether 'btrfs check' supports check ing of a partially dropped +# snapshot source "$TOP/tests/common" check_prereq btrfs -for img in *.img -do - image=$(extract_image "$img") +check_image() +{ + local image + + image=$1 run_check_stdout "$TOP/btrfs" check "$image" 2>&1 | grep -q "Errors found in extent allocation tree or chunk allocation" if [ $? -eq 0 ]; then rm -f "$image" _fail "unexpected error occurred when checking $img" fi - rm -f "$image" -done +} + +check_all_images -- cgit v1.2.3 From dc06cda3d6afb4fad5ddfd1508a33f79c2e68efb Mon Sep 17 00:00:00 2001 From: David Sterba Date: Mon, 27 Nov 2017 23:50:45 +0100 Subject: btrfs-progs: tests: mkfs/008 mkfs with force With extended tests in the following patch a file based filesystem image also needs -f, otherwise it will fail. Signed-off-by: David Sterba --- tests/mkfs-tests/008-secorsize-nodesize-combination/test.sh | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) (limited to 'tests') diff --git a/tests/mkfs-tests/008-secorsize-nodesize-combination/test.sh b/tests/mkfs-tests/008-secorsize-nodesize-combination/test.sh index 151e7b77..955cd2b1 100755 --- a/tests/mkfs-tests/008-secorsize-nodesize-combination/test.sh +++ b/tests/mkfs-tests/008-secorsize-nodesize-combination/test.sh @@ -19,7 +19,7 @@ do_test() { sectorsize=$1 nodesize=$2 - run_mayfail $TOP/mkfs.btrfs -O $features -n $nodesize -s $sectorsize \ + run_mayfail $TOP/mkfs.btrfs -f -O $features -n $nodesize -s $sectorsize \ $TEST_DEV ret=$? if [ $ret == 0 ]; then -- cgit v1.2.3 From c12a6e4dca5e5b388124b81c3ea02e2835822924 Mon Sep 17 00:00:00 2001 From: David Sterba Date: Mon, 27 Nov 2017 23:58:23 +0100 Subject: btrfs-progs: tests: fix typos in test names Signed-off-by: David Sterba --- .../019-receive-clones-on-mounted-subvol/test.sh | 127 +++++++++++++++++++++ .../019-receive-clones-on-munted-subvol/test.sh | 127 --------------------- .../008-secorsize-nodesize-combination/test.sh | 50 -------- .../008-sectorsize-nodesize-combination/test.sh | 50 ++++++++ 4 files changed, 177 insertions(+), 177 deletions(-) create mode 100755 tests/misc-tests/019-receive-clones-on-mounted-subvol/test.sh delete mode 100755 tests/misc-tests/019-receive-clones-on-munted-subvol/test.sh delete mode 100755 tests/mkfs-tests/008-secorsize-nodesize-combination/test.sh create mode 100755 tests/mkfs-tests/008-sectorsize-nodesize-combination/test.sh (limited to 'tests') diff --git a/tests/misc-tests/019-receive-clones-on-mounted-subvol/test.sh b/tests/misc-tests/019-receive-clones-on-mounted-subvol/test.sh new file mode 100755 index 00000000..182b0cf9 --- /dev/null +++ b/tests/misc-tests/019-receive-clones-on-mounted-subvol/test.sh @@ -0,0 +1,127 @@ +#! /bin/bash +# +# Test that an incremental send operation works when in both snapshots there are +# two directory inodes that have the same number but different generations and +# have an entry with the same name that corresponds to different inodes in each +# snapshot. + +source $TOP/tests/common + +check_prereq mkfs.btrfs +check_prereq btrfs +check_prereq fssum + +setup_root_helper +prepare_test_dev + +FSSUM_PROG="$TOP/fssum" +srcdir=./send-test-dir +rm -rf "$srcdir" +mkdir -p "$srcdir" +run_check chmod a+rw "$srcdir" + +run_check "$TOP/mkfs.btrfs" -f "$TEST_DEV" +run_check_mount_test_dev + +BLOCK_SIZE=$(stat -f -c %S "$TEST_MNT") + +run_check $SUDO_HELPER "$TOP/btrfs" subvolume create "$TEST_MNT/foo" +run_check $SUDO_HELPER "$TOP/btrfs" subvolume create "$TEST_MNT/bar" +run_check $SUDO_HELPER "$TOP/btrfs" subvolume create "$TEST_MNT/baz" +run_check $SUDO_HELPER "$TOP/btrfs" subvolume create "$TEST_MNT/snap" + +tr '\000' 'A' < /dev/null | + run_check $SUDO_HELPER dd of=$TEST_MNT/foo/file_a bs=$BLOCK_SIZE count=32 +tr '\000' 'B' < /dev/null | + run_check $SUDO_HELPER dd of=$TEST_MNT/bar/file_b bs=$BLOCK_SIZE count=32 + +run_check $SUDO_HELPER cp --reflink=always "$TEST_MNT/foo/file_a" "$TEST_MNT/baz/file_a" +run_check $SUDO_HELPER cp --reflink=always "$TEST_MNT/bar/file_b" "$TEST_MNT/baz/file_b" + +# Filesystem looks like: +# +# . +# |--- foo/ +# | |--- file_a +# |--- bar/ +# | |--- file_b +# |--- baz/ +# | |--- file_a (clone of "foo/file_a") +# | |--- file_b (clone of "bar/file_b") +# |--- snap/ +# + +# create snapshots and send streams + +run_check $SUDO_HELPER "$TOP/btrfs" subvolume snapshot -r "$TEST_MNT/foo" "$TEST_MNT/snap/foo.0" +run_check $SUDO_HELPER "$TOP/btrfs" send -f "$srcdir/foo.0.snap" "$TEST_MNT/snap/foo.0" + +run_check $SUDO_HELPER "$TOP/btrfs" subvolume snapshot -r "$TEST_MNT/bar" "$TEST_MNT/snap/bar.0" +run_check $SUDO_HELPER "$TOP/btrfs" send -f "$srcdir/bar.0.snap" "$TEST_MNT/snap/bar.0" + +run_check $SUDO_HELPER cp --reflink=always "$TEST_MNT/foo/file_a" "$TEST_MNT/foo/file_a.clone" +run_check $SUDO_HELPER rm -f -- "$TEST_MNT/foo/file_a" + +run_check $SUDO_HELPER "$TOP/btrfs" subvolume snapshot -r "$TEST_MNT/foo" \ + "$TEST_MNT/snap/foo.1" +run_check $SUDO_HELPER "$TOP/btrfs" send -p "$TEST_MNT/snap/foo.0" -f "$srcdir/foo.1.snap" \ + "$TEST_MNT/snap/foo.1" + +run_check $SUDO_HELPER "$TOP/btrfs" subvolume snapshot -r "$TEST_MNT/baz" \ + "$TEST_MNT/snap/baz.0" +run_check $SUDO_HELPER "$TOP/btrfs" send -p "$TEST_MNT/snap/foo.1" \ + -c "$TEST_MNT/snap/bar.0" -f "$srcdir/baz.0.snap" \ + "$TEST_MNT/snap/baz.0" + +# Filesystem looks like: +# +# . +# |--- foo/ +# | |--- file_a.clone (clone of "foo/file_a") +# |--- bar/ +# | |--- file_b +# |--- baz/ +# | |--- file_a (clone of "foo/file_a") +# | |--- file_b (clone of "bar/file_b") +# |--- snap/ +# |--- bar.0/ (snapshot of "bar") +# | |--- file_b +# |--- foo.0/ (snapshot of "foo") +# | |--- file_a +# |--- foo.1/ (snapshot of "foo") +# | |--- file_a.clone +# |--- baz.0/ (snapshot of "baz") +# | |--- file_a +# | |--- file_b + +run_check $FSSUM_PROG -A -f -w "$srcdir/foo.0.fssum" "$TEST_MNT/snap/foo.0" +run_check $FSSUM_PROG -A -f -w "$srcdir/foo.1.fssum" "$TEST_MNT/snap/foo.1" +run_check $FSSUM_PROG -A -f -w "$srcdir/bar.0.fssum" "$TEST_MNT/snap/bar.0" +run_check $FSSUM_PROG -A -f -w "$srcdir/baz.0.fssum" "$TEST_MNT/snap/baz.0" + +run_check_umount_test_dev +run_check "$TOP/mkfs.btrfs" -f "$TEST_DEV" +run_check_mount_test_dev +run_check $SUDO_HELPER "$TOP/btrfs" subvolume create "$TEST_MNT/dest" +run_check_umount_test_dev +run_check_mount_test_dev -o subvol=/dest + +run_check $SUDO_HELPER "$TOP/btrfs" receive -f "$srcdir/foo.0.snap" "$TEST_MNT" +run_check $SUDO_HELPER "$TOP/btrfs" receive -f "$srcdir/bar.0.snap" "$TEST_MNT" + +# if "dest/" is not correctly stripped from the beginning of the path to +# "foo.0" in the target fs, we would get an error here because the clone source +# "foo.0/file_a" for "foo.1/file_a.clone" can't be found. +run_check $SUDO_HELPER "$TOP/btrfs" receive -f "$srcdir/foo.1.snap" "$TEST_MNT" + +# same here, but with send -c instead of -p +run_check $SUDO_HELPER "$TOP/btrfs" receive -f "$srcdir/baz.0.snap" "$TEST_MNT" + +run_check $FSSUM_PROG -r "$srcdir/foo.0.fssum" "$TEST_MNT/foo.0" +run_check $FSSUM_PROG -r "$srcdir/foo.1.fssum" "$TEST_MNT/foo.1" +run_check $FSSUM_PROG -r "$srcdir/bar.0.fssum" "$TEST_MNT/bar.0" +run_check $FSSUM_PROG -r "$srcdir/baz.0.fssum" "$TEST_MNT/baz.0" + +run_check_umount_test_dev + +rm -rf -- "$srcdir" diff --git a/tests/misc-tests/019-receive-clones-on-munted-subvol/test.sh b/tests/misc-tests/019-receive-clones-on-munted-subvol/test.sh deleted file mode 100755 index 182b0cf9..00000000 --- a/tests/misc-tests/019-receive-clones-on-munted-subvol/test.sh +++ /dev/null @@ -1,127 +0,0 @@ -#! /bin/bash -# -# Test that an incremental send operation works when in both snapshots there are -# two directory inodes that have the same number but different generations and -# have an entry with the same name that corresponds to different inodes in each -# snapshot. - -source $TOP/tests/common - -check_prereq mkfs.btrfs -check_prereq btrfs -check_prereq fssum - -setup_root_helper -prepare_test_dev - -FSSUM_PROG="$TOP/fssum" -srcdir=./send-test-dir -rm -rf "$srcdir" -mkdir -p "$srcdir" -run_check chmod a+rw "$srcdir" - -run_check "$TOP/mkfs.btrfs" -f "$TEST_DEV" -run_check_mount_test_dev - -BLOCK_SIZE=$(stat -f -c %S "$TEST_MNT") - -run_check $SUDO_HELPER "$TOP/btrfs" subvolume create "$TEST_MNT/foo" -run_check $SUDO_HELPER "$TOP/btrfs" subvolume create "$TEST_MNT/bar" -run_check $SUDO_HELPER "$TOP/btrfs" subvolume create "$TEST_MNT/baz" -run_check $SUDO_HELPER "$TOP/btrfs" subvolume create "$TEST_MNT/snap" - -tr '\000' 'A' < /dev/null | - run_check $SUDO_HELPER dd of=$TEST_MNT/foo/file_a bs=$BLOCK_SIZE count=32 -tr '\000' 'B' < /dev/null | - run_check $SUDO_HELPER dd of=$TEST_MNT/bar/file_b bs=$BLOCK_SIZE count=32 - -run_check $SUDO_HELPER cp --reflink=always "$TEST_MNT/foo/file_a" "$TEST_MNT/baz/file_a" -run_check $SUDO_HELPER cp --reflink=always "$TEST_MNT/bar/file_b" "$TEST_MNT/baz/file_b" - -# Filesystem looks like: -# -# . -# |--- foo/ -# | |--- file_a -# |--- bar/ -# | |--- file_b -# |--- baz/ -# | |--- file_a (clone of "foo/file_a") -# | |--- file_b (clone of "bar/file_b") -# |--- snap/ -# - -# create snapshots and send streams - -run_check $SUDO_HELPER "$TOP/btrfs" subvolume snapshot -r "$TEST_MNT/foo" "$TEST_MNT/snap/foo.0" -run_check $SUDO_HELPER "$TOP/btrfs" send -f "$srcdir/foo.0.snap" "$TEST_MNT/snap/foo.0" - -run_check $SUDO_HELPER "$TOP/btrfs" subvolume snapshot -r "$TEST_MNT/bar" "$TEST_MNT/snap/bar.0" -run_check $SUDO_HELPER "$TOP/btrfs" send -f "$srcdir/bar.0.snap" "$TEST_MNT/snap/bar.0" - -run_check $SUDO_HELPER cp --reflink=always "$TEST_MNT/foo/file_a" "$TEST_MNT/foo/file_a.clone" -run_check $SUDO_HELPER rm -f -- "$TEST_MNT/foo/file_a" - -run_check $SUDO_HELPER "$TOP/btrfs" subvolume snapshot -r "$TEST_MNT/foo" \ - "$TEST_MNT/snap/foo.1" -run_check $SUDO_HELPER "$TOP/btrfs" send -p "$TEST_MNT/snap/foo.0" -f "$srcdir/foo.1.snap" \ - "$TEST_MNT/snap/foo.1" - -run_check $SUDO_HELPER "$TOP/btrfs" subvolume snapshot -r "$TEST_MNT/baz" \ - "$TEST_MNT/snap/baz.0" -run_check $SUDO_HELPER "$TOP/btrfs" send -p "$TEST_MNT/snap/foo.1" \ - -c "$TEST_MNT/snap/bar.0" -f "$srcdir/baz.0.snap" \ - "$TEST_MNT/snap/baz.0" - -# Filesystem looks like: -# -# . -# |--- foo/ -# | |--- file_a.clone (clone of "foo/file_a") -# |--- bar/ -# | |--- file_b -# |--- baz/ -# | |--- file_a (clone of "foo/file_a") -# | |--- file_b (clone of "bar/file_b") -# |--- snap/ -# |--- bar.0/ (snapshot of "bar") -# | |--- file_b -# |--- foo.0/ (snapshot of "foo") -# | |--- file_a -# |--- foo.1/ (snapshot of "foo") -# | |--- file_a.clone -# |--- baz.0/ (snapshot of "baz") -# | |--- file_a -# | |--- file_b - -run_check $FSSUM_PROG -A -f -w "$srcdir/foo.0.fssum" "$TEST_MNT/snap/foo.0" -run_check $FSSUM_PROG -A -f -w "$srcdir/foo.1.fssum" "$TEST_MNT/snap/foo.1" -run_check $FSSUM_PROG -A -f -w "$srcdir/bar.0.fssum" "$TEST_MNT/snap/bar.0" -run_check $FSSUM_PROG -A -f -w "$srcdir/baz.0.fssum" "$TEST_MNT/snap/baz.0" - -run_check_umount_test_dev -run_check "$TOP/mkfs.btrfs" -f "$TEST_DEV" -run_check_mount_test_dev -run_check $SUDO_HELPER "$TOP/btrfs" subvolume create "$TEST_MNT/dest" -run_check_umount_test_dev -run_check_mount_test_dev -o subvol=/dest - -run_check $SUDO_HELPER "$TOP/btrfs" receive -f "$srcdir/foo.0.snap" "$TEST_MNT" -run_check $SUDO_HELPER "$TOP/btrfs" receive -f "$srcdir/bar.0.snap" "$TEST_MNT" - -# if "dest/" is not correctly stripped from the beginning of the path to -# "foo.0" in the target fs, we would get an error here because the clone source -# "foo.0/file_a" for "foo.1/file_a.clone" can't be found. -run_check $SUDO_HELPER "$TOP/btrfs" receive -f "$srcdir/foo.1.snap" "$TEST_MNT" - -# same here, but with send -c instead of -p -run_check $SUDO_HELPER "$TOP/btrfs" receive -f "$srcdir/baz.0.snap" "$TEST_MNT" - -run_check $FSSUM_PROG -r "$srcdir/foo.0.fssum" "$TEST_MNT/foo.0" -run_check $FSSUM_PROG -r "$srcdir/foo.1.fssum" "$TEST_MNT/foo.1" -run_check $FSSUM_PROG -r "$srcdir/bar.0.fssum" "$TEST_MNT/bar.0" -run_check $FSSUM_PROG -r "$srcdir/baz.0.fssum" "$TEST_MNT/baz.0" - -run_check_umount_test_dev - -rm -rf -- "$srcdir" diff --git a/tests/mkfs-tests/008-secorsize-nodesize-combination/test.sh b/tests/mkfs-tests/008-secorsize-nodesize-combination/test.sh deleted file mode 100755 index 955cd2b1..00000000 --- a/tests/mkfs-tests/008-secorsize-nodesize-combination/test.sh +++ /dev/null @@ -1,50 +0,0 @@ -#!/bin/bash -# test various sectorsize and node size combinations -# including valid and invalid ones -# only do mkfs and fsck check, no mounting as -# sub/multi-pagesize is not supported yet - -source $TOP/tests/common - -check_prereq mkfs.btrfs -check_prereq btrfs - -prepare_test_dev - -# disable mixed bg to avoid sectorsize == nodesize check -features="^mixed-bg" - -# caller need to check whether the combination is valid -do_test() -{ - sectorsize=$1 - nodesize=$2 - run_mayfail $TOP/mkfs.btrfs -f -O $features -n $nodesize -s $sectorsize \ - $TEST_DEV - ret=$? - if [ $ret == 0 ]; then - run_check $TOP/btrfs check $TEST_DEV - fi - return $ret -} - -# Invalid: Unaligned sectorsize and nodesize -do_test 8191 8191 && _fail - -# Invalid: Aligned sectorsize with unaligned nodesize -do_test 4k 16385 && _fail - -# Invalid: Unaligned sectorsize with aligned nodesize -do_test 8191 16k && _fail - -# Valid: Aligned sectorsize and nodesize -do_test 4k 16k || _fail - -# Invalid: Sectorsize larger than nodesize -do_test 8k 4k && _fail - -# Invalid: too large nodesize -do_test 16k 128k && _fail - -# Valid: large sectorsize -do_test 64k 64k || _fail diff --git a/tests/mkfs-tests/008-sectorsize-nodesize-combination/test.sh b/tests/mkfs-tests/008-sectorsize-nodesize-combination/test.sh new file mode 100755 index 00000000..955cd2b1 --- /dev/null +++ b/tests/mkfs-tests/008-sectorsize-nodesize-combination/test.sh @@ -0,0 +1,50 @@ +#!/bin/bash +# test various sectorsize and node size combinations +# including valid and invalid ones +# only do mkfs and fsck check, no mounting as +# sub/multi-pagesize is not supported yet + +source $TOP/tests/common + +check_prereq mkfs.btrfs +check_prereq btrfs + +prepare_test_dev + +# disable mixed bg to avoid sectorsize == nodesize check +features="^mixed-bg" + +# caller need to check whether the combination is valid +do_test() +{ + sectorsize=$1 + nodesize=$2 + run_mayfail $TOP/mkfs.btrfs -f -O $features -n $nodesize -s $sectorsize \ + $TEST_DEV + ret=$? + if [ $ret == 0 ]; then + run_check $TOP/btrfs check $TEST_DEV + fi + return $ret +} + +# Invalid: Unaligned sectorsize and nodesize +do_test 8191 8191 && _fail + +# Invalid: Aligned sectorsize with unaligned nodesize +do_test 4k 16385 && _fail + +# Invalid: Unaligned sectorsize with aligned nodesize +do_test 8191 16k && _fail + +# Valid: Aligned sectorsize and nodesize +do_test 4k 16k || _fail + +# Invalid: Sectorsize larger than nodesize +do_test 8k 4k && _fail + +# Invalid: too large nodesize +do_test 16k 128k && _fail + +# Valid: large sectorsize +do_test 64k 64k || _fail -- cgit v1.2.3 From 2bf30fb3b1e420e3f737eb9c2acc2fc96f7467dd Mon Sep 17 00:00:00 2001 From: Qu Wenruo Date: Wed, 1 Nov 2017 09:30:41 +0800 Subject: btrfs-progs: test/common: Introduce run_mustfail_stdout For later test case which needs info from stderr. Signed-off-by: Qu Wenruo Signed-off-by: David Sterba --- tests/common | 52 ++++++++++++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 52 insertions(+) (limited to 'tests') diff --git a/tests/common b/tests/common index dec090fe..3ce99090 100644 --- a/tests/common +++ b/tests/common @@ -236,6 +236,58 @@ run_mustfail() fi } +# The first parameter is error message to print if it fails, just like +# run_must_fail(). +# NOTE: we don't use pipefail to avoid disturbing other script, so here we +# use a temporary output file. +# So it doesn't support pipeline in the @cmd +run_mustfail_stdout() +{ + local spec + local ins + local cmd + local msg + local ret + local tmp_output + + tmp_output=$(mktemp --tmpdir btrfs-progs-test--mustfail-stdtout.XXXXXX) + + msg="$1" + shift + + if _is_file_or_command "$msg"; then + echo "ASSERTION FAIL: 1st argument of run_mustfail_stdout must be a message" + exit 1 + fi + + ins=$(_get_spec_ins "$@") + spec=$(($ins-1)) + cmd=$(eval echo "\${$spec}") + spec=$(_cmd_spec "${@:$spec}") + set -- "${@:1:$(($ins-1))}" $spec "${@: $ins}" + echo "############### $@" >> "$RESULTS" 2>&1 + if [[ $TEST_LOG =~ tty ]]; then echo "CMD(mustfail): $@" > /dev/tty; fi + if [ "$1" = 'root_helper' ]; then + "$@" 2>&1 > "$tmp_output" + else + $INSTRUMENT "$@" 2>&1 > "$tmp_output" + fi + ret=$? + + cat "$tmp_output" >> "$RESULTS" + cat "$tmp_output" + rm "$tmp_output" + + if [ "$ret" != 0 ]; then + echo "failed (expected): $@" >> "$RESULTS" + return 0 + else + echo "succeeded (unexpected!): $@" >> "$RESULTS" + _fail "unexpected success: $msg" + return 1 + fi +} + check_prereq() { if ! [ -f "$TOP/$1" ]; then -- cgit v1.2.3 From 2c2db167c79bee6c0ce88f55f964135908654f74 Mon Sep 17 00:00:00 2001 From: Qu Wenruo Date: Wed, 1 Nov 2017 09:30:42 +0800 Subject: btrfs-progs: test/common: Enhance prepare_test_dev to reset device size So prepare_test_dev() can be called several times in one test case, to test different device sizes. Signed-off-by: Qu Wenruo [ switch to [ ] ] Signed-off-by: David Sterba --- tests/common | 6 +++++- 1 file changed, 5 insertions(+), 1 deletion(-) (limited to 'tests') diff --git a/tests/common b/tests/common index 3ce99090..734cd171 100644 --- a/tests/common +++ b/tests/common @@ -441,8 +441,12 @@ prepare_test_dev() # num[K/M/G/T...] local size="$1" - [[ "$TEST_DEV" ]] && return [[ "$size" ]] || size='2G' + # Still truncate it to new size + if [ -n "$TEST_DEV" ]; then + truncate -s "$size" "$TEST_DEV" + return; + fi echo "\$TEST_DEV not given, use $TOP/test/test.img as fallback" >> \ "$RESULTS" -- cgit v1.2.3 From 1f360220714ba3516c262287d1f6453a10308834 Mon Sep 17 00:00:00 2001 From: Qu Wenruo Date: Wed, 29 Nov 2017 21:48:06 +0800 Subject: btrfs-progs: tests/convert: ensure btrfs-convert won't rollback the filesystem after balance Signed-off-by: Qu Wenruo [ add shell quotes, rename test ] Signed-off-by: David Sterba --- .../015-no-rollback-after-balance/test.sh | 33 ++++++++++++++++++++++ 1 file changed, 33 insertions(+) create mode 100755 tests/convert-tests/015-no-rollback-after-balance/test.sh (limited to 'tests') diff --git a/tests/convert-tests/015-no-rollback-after-balance/test.sh b/tests/convert-tests/015-no-rollback-after-balance/test.sh new file mode 100755 index 00000000..47c9c6fa --- /dev/null +++ b/tests/convert-tests/015-no-rollback-after-balance/test.sh @@ -0,0 +1,33 @@ +#!/bin/bash +# Check if btrfs-convert refuses to rollback the filesystem, and leave the fs +# and the convert image untouched + +source "$TOP/tests/common" +source "$TOP/tests/common.convert" + +setup_root_helper +prepare_test_dev +check_prereq btrfs-convert +check_global_prereq mke2fs + +# convert_test_prep_fs() will create large enough file inside the test device, +# that's good enough for us to test rollback failure. +convert_test_prep_fs ext4 mke2fs -t ext4 -b 4096 +run_check_umount_test_dev +convert_test_do_convert "" 4096 + +run_check_mount_test_dev + +# Now the fs is converted, balance it so later rollback should fail +run_check $SUDO_HELPER "$TOP/btrfs" balance start --full-balance "$TEST_MNT" +run_check_umount_test_dev + +# rollback should fail +run_mustfail "rollback fs after balance" "$TOP/btrfs-convert" -r "$TEST_DEV" + +# Ensure the fs and convert image can pass the check +run_check "$TOP/btrfs" check "$TEST_DEV" + +run_check_mount_test_dev +run_check $SUDO_HELPER e2fsck -fn "$TEST_MNT/ext2_saved/image" +run_check_umount_test_dev -- cgit v1.2.3 From 5d0783ad1430c9fa4621537224073b680d6ad6af Mon Sep 17 00:00:00 2001 From: Qu Wenruo Date: Thu, 12 Oct 2017 15:11:33 +0800 Subject: btrfs-progs: test/mkfs: Test if the minimal device size is valid New test case to test if the minimal device size given by "mkfs.btrfs" failure case is valid. Signed-off-by: Qu Wenruo [ renamed script ] Signed-off-by: David Sterba --- tests/mkfs-tests/010-minimal-size/test.sh | 49 +++++++++++++++++++++++++++++++ 1 file changed, 49 insertions(+) create mode 100755 tests/mkfs-tests/010-minimal-size/test.sh (limited to 'tests') diff --git a/tests/mkfs-tests/010-minimal-size/test.sh b/tests/mkfs-tests/010-minimal-size/test.sh new file mode 100755 index 00000000..f75a22d8 --- /dev/null +++ b/tests/mkfs-tests/010-minimal-size/test.sh @@ -0,0 +1,49 @@ +#!/bin/bash +# test if the reported minimal size of mkfs.btrfs is valid + +source "$TOP/tests/common" + +check_prereq mkfs.btrfs +check_prereq btrfs + +setup_root_helper + +do_test() +{ + # 1M should be small enough to reliably fail, we use the output to get + # the minimal device size for the given option combination + prepare_test_dev 1M + output=$(run_mustfail_stdout "mkfs.btrfs for small image" \ + "$TOP/mkfs.btrfs" -f $@ "$TEST_DEV") + good_size=$(echo "$output" | grep -oP "(?<=is )\d+") + + prepare_test_dev "$good_size" + run_check $TOP/mkfs.btrfs -f $@ "$TEST_DEV" + run_check_mount_test_dev + run_check_umount_test_dev +} + +do_test -n 4k -m single -d single +do_test -n 4k -m single -d dup +do_test -n 4k -m dup -d single +do_test -n 4k -m dup -d dup + +do_test -n 8k -m single -d single +do_test -n 8k -m single -d dup +do_test -n 8k -m dup -d single +do_test -n 8k -m dup -d dup + +do_test -n 16k -m single -d single +do_test -n 16k -m single -d dup +do_test -n 16k -m dup -d single +do_test -n 16k -m dup -d dup + +do_test -n 32k -m single -d single +do_test -n 32k -m single -d dup +do_test -n 32k -m dup -d single +do_test -n 32k -m dup -d dup + +do_test -n 64k -m single -d single +do_test -n 64k -m single -d dup +do_test -n 64k -m dup -d single +do_test -n 64k -m dup -d dup -- cgit v1.2.3 From 0ca2f5a7241373c660946802b0d7f8305234c286 Mon Sep 17 00:00:00 2001 From: Qu Wenruo Date: Wed, 29 Nov 2017 16:26:02 +0800 Subject: btrfs-progs: tests/mkfs: Introduce test case to check if mkfs rootdir can create a new file To test regression 460e93f25754 ("btrfs-progs: mkfs: check the status of file at mkfs"). Signed-off-by: Qu Wenruo [ update test to create a out of /tmp ] Signed-off-by: David Sterba --- tests/mkfs-tests/011-rootdir-create-file/test.sh | 15 +++++++++++++++ 1 file changed, 15 insertions(+) create mode 100755 tests/mkfs-tests/011-rootdir-create-file/test.sh (limited to 'tests') diff --git a/tests/mkfs-tests/011-rootdir-create-file/test.sh b/tests/mkfs-tests/011-rootdir-create-file/test.sh new file mode 100755 index 00000000..c04f711d --- /dev/null +++ b/tests/mkfs-tests/011-rootdir-create-file/test.sh @@ -0,0 +1,15 @@ +#!/bin/bash +# Regression test for mkfs.btrfs --rootdir on non-existent file. +# Expected behavior: it should create a new file if destination doesn't exist +# Regression 460e93f25754 ("btrfs-progs: mkfs: check the status of file at mkfs") + +source "$TOP/tests/common" + +check_prereq mkfs.btrfs + +tmp=$(mktemp -d --tmpdir btrfs-progs-mkfs.rootdirXXXXXXX) +# we can't use TEST_DEV, a file is needed +img=$(mktemp btrfs-progs-mkfs.rootdirXXXXXXX) +run_check "$TOP/mkfs.btrfs" -f --rootdir "$TOP/Documentation/" "$img" + +rm -rf -- "$img" -- cgit v1.2.3 From 0ba347f315435f8dd6d3158ac82ec104cff443a2 Mon Sep 17 00:00:00 2001 From: Qu Wenruo Date: Wed, 29 Nov 2017 16:58:43 +0800 Subject: btrfs-progs: tests/mkfs: verify that mkfs.btrfs rootdir+shrink behaves correctly Signed-off-by: Qu Wenruo Signed-off-by: David Sterba --- tests/mkfs-tests/012-rootdir-no-shrink/test.sh | 39 ++++++++++++++++++++++++++ 1 file changed, 39 insertions(+) create mode 100755 tests/mkfs-tests/012-rootdir-no-shrink/test.sh (limited to 'tests') diff --git a/tests/mkfs-tests/012-rootdir-no-shrink/test.sh b/tests/mkfs-tests/012-rootdir-no-shrink/test.sh new file mode 100755 index 00000000..c1cb04f5 --- /dev/null +++ b/tests/mkfs-tests/012-rootdir-no-shrink/test.sh @@ -0,0 +1,39 @@ +#!/bin/bash +# Test if mkfs.btrfs --rootdir will skip shrinking correctly + +source "$TOP/tests/common" + +check_prereq mkfs.btrfs + +setup_root_helper + +fs_size=$((512 * 1024 * 1024)) +bs=$((1024 * 1024)) +tmp=$(mktemp -d --tmpdir btrfs-progs-mkfs.rootdirXXXXXXX) + +prepare_test_dev $fs_size + +# No shrink case + +run_check "$TOP/mkfs.btrfs" -f --rootdir "$tmp" "$TEST_DEV" +run_check_mount_test_dev + +# We should be able to write at least half of the fs size data since the fs is +# not shrunk +run_check $SUDO_HELPER dd if=/dev/zero bs=$bs count=$(($fs_size / $bs / 2)) \ + of="$TEST_MNT/file" + +run_check_umount_test_dev + +# Shrink case + +run_check "$TOP/mkfs.btrfs" -f --rootdir "$tmp" --shrink "$TEST_DEV" +run_check_mount_test_dev + +run_mustfail "mkfs.btrfs for shrink rootdir" \ + $SUDO_HELPER dd if=/dev/zero bs=$bs count=$(($fs_size / $bs / 2)) \ + of="$TEST_MNT/file" + +run_check_umount_test_dev + +rm -rf -- "$tmp" -- cgit v1.2.3 From 6e8571e2df5b33e601123c686bdc0de7a3542959 Mon Sep 17 00:00:00 2001 From: David Sterba Date: Mon, 8 Jan 2018 19:48:51 +0100 Subject: btrfs-progs: tests: fix typo in error message Signed-off-by: David Sterba --- tests/common | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) (limited to 'tests') diff --git a/tests/common b/tests/common index 734cd171..a2e2f50d 100644 --- a/tests/common +++ b/tests/common @@ -448,7 +448,7 @@ prepare_test_dev() return; fi - echo "\$TEST_DEV not given, use $TOP/test/test.img as fallback" >> \ + echo "\$TEST_DEV not given, using $TOP/tests/test.img as fallback" >> \ "$RESULTS" TEST_DEV="$TOP/tests/test.img" -- cgit v1.2.3 From 058fad5b921db273cf56bb34c4482ba99359ef59 Mon Sep 17 00:00:00 2001 From: Nikolay Borisov Date: Tue, 5 Dec 2017 10:39:43 +0200 Subject: btrfs-progs: tests: Explictly state test.sh must be executable Signed-off-by: Nikolay Borisov Reviewed-by: Signed-off-by: David Sterba --- tests/README.md | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-) (limited to 'tests') diff --git a/tests/README.md b/tests/README.md index 04d2ce2a..c4560185 100644 --- a/tests/README.md +++ b/tests/README.md @@ -164,7 +164,9 @@ how to do mkfs, mount, unmount, check, etc. and join by dashes `-`. This will become the directory name, eg. `012-subvolume-sync-must-wait`. 3. Write a short description of the bug and how it's tested to the comment at the -begining of `test.sh`. You don't need to add the file to git yet. +begining of `test.sh`. You don't need to add the file to git yet. Don't forget +to make the file executable, otherwise it's not going to be executed by the +infrastructure. 4. Write the test commands, comment anything that's not obvious. -- cgit v1.2.3 From e764625f90f947f927f78b4166a34d9d5755ef63 Mon Sep 17 00:00:00 2001 From: Nikolay Borisov Date: Tue, 5 Dec 2017 10:39:48 +0200 Subject: btrfs-progs: tests: Add test for super block recovery This functionality regressed some time ago and it was never caught. Seems no one complained of that, but to be sure add a regression test to prevent future regressions. Signed-off-by: Nikolay Borisov Signed-off-by: David Sterba --- tests/fsck-tests/029-superblock-recovery/test.sh | 64 ++++++++++++++++++++++++ 1 file changed, 64 insertions(+) create mode 100755 tests/fsck-tests/029-superblock-recovery/test.sh (limited to 'tests') diff --git a/tests/fsck-tests/029-superblock-recovery/test.sh b/tests/fsck-tests/029-superblock-recovery/test.sh new file mode 100755 index 00000000..c1dfe7f5 --- /dev/null +++ b/tests/fsck-tests/029-superblock-recovery/test.sh @@ -0,0 +1,64 @@ +#!/bin/bash +# Test that any superblock is correctly detected +# and fixed by btrfs rescue + +source "$TOP/tests/common" + +check_prereq btrfs +check_prereq mkfs.btrfs +check_prereq btrfs-select-super + +setup_root_helper + +rm -f dev1 +run_check truncate -s 260G dev1 +loop=$(run_check_stdout $SUDO_HELPER losetup --find --show dev1) + +# Create the test file system. +run_check $SUDO_HELPER "$TOP"/mkfs.btrfs -f "$loop" + +function check_corruption { + local sb_offset=$1 + local source_sb=$2 + + + # First we ensure we can mount it successfully + run_check $SUDO_HELPER mount $loop "$TEST_MNT" + run_check $SUDO_HELPER umount "$TEST_MNT" + + # Now corrupt 1k of the superblock at sb_offset + run_check $SUDO_HELPER dd bs=1K count=1 seek=$(($sb_offset + 1)) if=/dev/zero of="$loop" + + #if corrupting one of the sb copies, copy it over the initial superblock + if [ ! -z $source_sb ]; then + local shift_val=$((16 << $source_sb * 12 )) + run_check $SUDO_HELPER dd bs=1K count=4 seek=64 skip=$shift_val if="$loop" of="$loop" + fi + + run_mustfail "Mounted fs with corrupted superblock" \ + $SUDO_HELPER mount $loop "$TEST_MNT" + + # Now run btrfs rescue which should fix the superblock. It uses 2 + # to signal success of recovery use mayfail to ignore that retval + # but still log the output of the command + run_mayfail $SUDO_HELPER "$TOP"/btrfs rescue super-recover -yv "$loop" + if [ $? != 2 ]; then + _fail "couldn't rescue super" + fi + + run_check $SUDO_HELPER mount $loop "$TEST_MNT" + run_check $SUDO_HELPER umount "$TEST_MNT" +} + +_log "Corrupting first superblock" +check_corruption 64 + +_log "Corrupting second superblock" +check_corruption 65536 1 + +_log "Corrupting third superblock" +check_corruption 268435456 2 + +# Cleanup +run_check $SUDO_HELPER losetup -d "$loop" +rm -f dev1 -- cgit v1.2.3 From de802a47e0d7474bd446c5eb6974a33dacca5100 Mon Sep 17 00:00:00 2001 From: David Sterba Date: Tue, 23 Jan 2018 16:25:11 +0100 Subject: btrfs-progs: tests: 029-super-recovery: cleanup the test Transform the test to the common helpers and don't manage the loop devices here. The test category changes from check to misc. Signed-off-by: David Sterba --- tests/fsck-tests/029-superblock-recovery/test.sh | 64 ------------------------ tests/misc-tests/028-superblock-recover/test.sh | 57 +++++++++++++++++++++ 2 files changed, 57 insertions(+), 64 deletions(-) delete mode 100755 tests/fsck-tests/029-superblock-recovery/test.sh create mode 100755 tests/misc-tests/028-superblock-recover/test.sh (limited to 'tests') diff --git a/tests/fsck-tests/029-superblock-recovery/test.sh b/tests/fsck-tests/029-superblock-recovery/test.sh deleted file mode 100755 index c1dfe7f5..00000000 --- a/tests/fsck-tests/029-superblock-recovery/test.sh +++ /dev/null @@ -1,64 +0,0 @@ -#!/bin/bash -# Test that any superblock is correctly detected -# and fixed by btrfs rescue - -source "$TOP/tests/common" - -check_prereq btrfs -check_prereq mkfs.btrfs -check_prereq btrfs-select-super - -setup_root_helper - -rm -f dev1 -run_check truncate -s 260G dev1 -loop=$(run_check_stdout $SUDO_HELPER losetup --find --show dev1) - -# Create the test file system. -run_check $SUDO_HELPER "$TOP"/mkfs.btrfs -f "$loop" - -function check_corruption { - local sb_offset=$1 - local source_sb=$2 - - - # First we ensure we can mount it successfully - run_check $SUDO_HELPER mount $loop "$TEST_MNT" - run_check $SUDO_HELPER umount "$TEST_MNT" - - # Now corrupt 1k of the superblock at sb_offset - run_check $SUDO_HELPER dd bs=1K count=1 seek=$(($sb_offset + 1)) if=/dev/zero of="$loop" - - #if corrupting one of the sb copies, copy it over the initial superblock - if [ ! -z $source_sb ]; then - local shift_val=$((16 << $source_sb * 12 )) - run_check $SUDO_HELPER dd bs=1K count=4 seek=64 skip=$shift_val if="$loop" of="$loop" - fi - - run_mustfail "Mounted fs with corrupted superblock" \ - $SUDO_HELPER mount $loop "$TEST_MNT" - - # Now run btrfs rescue which should fix the superblock. It uses 2 - # to signal success of recovery use mayfail to ignore that retval - # but still log the output of the command - run_mayfail $SUDO_HELPER "$TOP"/btrfs rescue super-recover -yv "$loop" - if [ $? != 2 ]; then - _fail "couldn't rescue super" - fi - - run_check $SUDO_HELPER mount $loop "$TEST_MNT" - run_check $SUDO_HELPER umount "$TEST_MNT" -} - -_log "Corrupting first superblock" -check_corruption 64 - -_log "Corrupting second superblock" -check_corruption 65536 1 - -_log "Corrupting third superblock" -check_corruption 268435456 2 - -# Cleanup -run_check $SUDO_HELPER losetup -d "$loop" -rm -f dev1 diff --git a/tests/misc-tests/028-superblock-recover/test.sh b/tests/misc-tests/028-superblock-recover/test.sh new file mode 100755 index 00000000..1175e480 --- /dev/null +++ b/tests/misc-tests/028-superblock-recover/test.sh @@ -0,0 +1,57 @@ +#!/bin/bash +# Test that any superblock is correctly detected and fixed by btrfs rescue + +source "$TOP/tests/common" + +check_prereq btrfs +check_prereq mkfs.btrfs +check_prereq btrfs-select-super + +setup_root_helper +prepare_test_dev 260G + +# Create the test file system. +run_check $SUDO_HELPER "$TOP"/mkfs.btrfs -f "$TEST_DEV" + +function check_corruption { + local sb_offset=$1 + local source_sb=$2 + + # First we ensure we can mount it successfully + run_check_mount_test_dev + run_check_umount_test_dev + + # Now corrupt 1k of the superblock at sb_offset + run_check $SUDO_HELPER dd bs=1K count=1 seek=$(($sb_offset + 1)) if=/dev/zero of="$TEST_DEV" conv=notrunc + + # if corrupting one of the sb copies, copy it over the initial superblock + if [ ! -z $source_sb ]; then + local shift_val=$((16 << $source_sb * 12 )) + run_check $SUDO_HELPER dd bs=1K count=4 seek=64 skip=$shift_val if="$TEST_DEV" of="$TEST_DEV" conv=notrunc + fi + + # we can't use our mount helper, the following works for file image and + # block device as TEST_DEV + run_mustfail "mounted fs with corrupted superblock" \ + $SUDO_HELPER mount "$TEST_DEV" "$TEST_MNT" + + # Now run btrfs rescue which should fix the superblock. It uses 2 + # to signal success of recovery use mayfail to ignore that retval + # but still log the output of the command + run_mayfail $SUDO_HELPER "$TOP"/btrfs rescue super-recover -yv "$TEST_DEV" + if [ $? != 2 ]; then + _fail "couldn't rescue super" + fi + + run_check_mount_test_dev + run_check_umount_test_dev +} + +# Corrupting first superblock +check_corruption 64 + +# Corrupting second superblock +check_corruption 65536 1 + +# Corrupting third superblock +check_corruption 268435456 2 -- cgit v1.2.3 From e0d081b69357574d095f5de314154debc95de162 Mon Sep 17 00:00:00 2001 From: Qu Wenruo Date: Wed, 24 Jan 2018 10:38:30 +0800 Subject: btrfs-progs: tests:mkfs/010: Output minimal device size To make debugging a little easier. Signed-off-by: Qu Wenruo Signed-off-by: David Sterba --- tests/mkfs-tests/010-minimal-size/test.sh | 1 + 1 file changed, 1 insertion(+) (limited to 'tests') diff --git a/tests/mkfs-tests/010-minimal-size/test.sh b/tests/mkfs-tests/010-minimal-size/test.sh index f75a22d8..f33b8aa3 100755 --- a/tests/mkfs-tests/010-minimal-size/test.sh +++ b/tests/mkfs-tests/010-minimal-size/test.sh @@ -18,6 +18,7 @@ do_test() good_size=$(echo "$output" | grep -oP "(?<=is )\d+") prepare_test_dev "$good_size" + echo "Minimal device size is $good_size" >> "$RESULTS" run_check $TOP/mkfs.btrfs -f $@ "$TEST_DEV" run_check_mount_test_dev run_check_umount_test_dev -- cgit v1.2.3 From 510b140955cc8ae1f8676e2b07468200cffd0c98 Mon Sep 17 00:00:00 2001 From: Qu Wenruo Date: Wed, 10 Jan 2018 12:56:48 +0800 Subject: btrfs-progs: tests: mkfs: don't overwrite first 1M for single Add test case to check if the first device extent is occupying reserved 0~1M range. Signed-off-by: Qu Wenruo Reviewed-by: Nikolay Borisov Signed-off-by: David Sterba --- .../mkfs-tests/013-reserved-1M-for-single/test.sh | 38 ++++++++++++++++++++++ 1 file changed, 38 insertions(+) create mode 100755 tests/mkfs-tests/013-reserved-1M-for-single/test.sh (limited to 'tests') diff --git a/tests/mkfs-tests/013-reserved-1M-for-single/test.sh b/tests/mkfs-tests/013-reserved-1M-for-single/test.sh new file mode 100755 index 00000000..775573e0 --- /dev/null +++ b/tests/mkfs-tests/013-reserved-1M-for-single/test.sh @@ -0,0 +1,38 @@ +#!/bin/bash +# Test if "-m single" or "--mixed" can cause dev extent to use the reserved 1M +# range +# +# Other profiles will cause mkfs.btrfs to allocate new meta/sys chunks +# using btrfs_alloc_chunk() which won't use the 0~1M range, so other profiles +# are safe. + +source "$TOP/tests/common" + +check_prereq mkfs.btrfs +check_prereq btrfs + +prepare_test_dev + +do_one_test () +{ + run_check "$TOP/mkfs.btrfs" -f "$@" "$TEST_DEV" + + # Use dev-extent tree to find first device extent + first_dev_extent=$(run_check_stdout "$TOP/btrfs" inspect-internal \ + dump-tree -t device "$TEST_DEV" | \ + grep -oP '(?<=DEV_EXTENT )[[:digit:]]*' | head -n1) + + if [ -z $first_dev_extent ]; then + _fail "failed to get first device extent" + fi + + echo "first dev extent starts at $first_dev_extent" >> "$RESULTS" + echo "reserved range is [0, $(( 1024 * 1024)))" >> "$RESULTS" + # First device extent should not start below 1M + if [ $first_dev_extent -lt $(( 1024 * 1024 )) ]; then + _fail "first device extent occupies reserved 0~1M range" + fi +} + +do_one_test --mixed +do_one_test -m single -- cgit v1.2.3 From 07eafd93b27051f75a51cff634f8ed23858f6fa7 Mon Sep 17 00:00:00 2001 From: David Sterba Date: Tue, 23 Jan 2018 16:57:57 +0100 Subject: btrfs-progs: tests: add more coverage to mkfs-tests/013-reserved-1M-for-single Though the newly added mkfs profiles should not be affected, let's add the remaining valid single device profiles for better coverage. Signed-off-by: David Sterba --- tests/mkfs-tests/013-reserved-1M-for-single/test.sh | 8 +++++++- 1 file changed, 7 insertions(+), 1 deletion(-) (limited to 'tests') diff --git a/tests/mkfs-tests/013-reserved-1M-for-single/test.sh b/tests/mkfs-tests/013-reserved-1M-for-single/test.sh index 775573e0..1490df2c 100755 --- a/tests/mkfs-tests/013-reserved-1M-for-single/test.sh +++ b/tests/mkfs-tests/013-reserved-1M-for-single/test.sh @@ -4,7 +4,7 @@ # # Other profiles will cause mkfs.btrfs to allocate new meta/sys chunks # using btrfs_alloc_chunk() which won't use the 0~1M range, so other profiles -# are safe. +# are safe, but we test them nevertheless. source "$TOP/tests/common" @@ -36,3 +36,9 @@ do_one_test () do_one_test --mixed do_one_test -m single + +do_one_test +do_one_test -m dup +do_one_test -d dup +do_one_test -m dup -d dup +do_one_test --mixed -m dup -d dup -- cgit v1.2.3 From 81dd246d953585c08984aa4b059d8c1ee1c8e715 Mon Sep 17 00:00:00 2001 From: David Sterba Date: Tue, 23 Jan 2018 17:22:30 +0100 Subject: btrfs-progs: tests: truncate test image to 0 first We use the prepare_test_dev helper to make sure the image has at least this size. The "at least" part is not desired by some tests as the device might be larger than the test expects. Signed-off-by: David Sterba --- tests/common | 2 ++ 1 file changed, 2 insertions(+) (limited to 'tests') diff --git a/tests/common b/tests/common index a2e2f50d..2fac202a 100644 --- a/tests/common +++ b/tests/common @@ -444,6 +444,7 @@ prepare_test_dev() [[ "$size" ]] || size='2G' # Still truncate it to new size if [ -n "$TEST_DEV" ]; then + truncate -s 0 "$TEST_DEV" truncate -s "$size" "$TEST_DEV" return; fi @@ -452,6 +453,7 @@ prepare_test_dev() "$RESULTS" TEST_DEV="$TOP/tests/test.img" + truncate -s 0 "$TEST_DEV" truncate -s "$size" "$TEST_DEV" || _not_run "create file for loop device failed" } -- cgit v1.2.3 From e4df433b8a2d5ef944ab4764a5ad237bcdbd1fdc Mon Sep 17 00:00:00 2001 From: Rosen Penev Date: Sun, 7 Jan 2018 13:54:21 -0800 Subject: btrfs-progs: treewide: Replace strerror(errno) with %m. As btrfs is specific to Linux, %m can be used instead of strerror(errno) in format strings. This has some size reduction benefits for embedded systems. glibc, musl, and uclibc-ng all support %m as a modifier to printf. A quick glance at the BIONIC libc source indicates that it has support for %m as well. BSDs and Windows do not but I do believe them to be beyond the scope of btrfs-progs. Compiled sizes on Ubuntu 16.04: Before: 3916512 btrfs 233688 libbtrfs.so.0.1 4899 bcp 2367672 btrfs-convert 2208488 btrfs-corrupt-block 13302 btrfs-debugfs 2152160 btrfs-debug-tree 2136024 btrfs-find-root 2287592 btrfs-image 2144600 btrfs-map-logical 2130760 btrfs-select-super 2152608 btrfstune 2131760 btrfs-zero-log 2277752 mkfs.btrfs 9166 show-blocks After: 3908744 btrfs 233256 libbtrfs.so.0.1 4899 bcp 2366560 btrfs-convert 2207432 btrfs-corrupt-block 13302 btrfs-debugfs 2151104 btrfs-debug-tree 2134968 btrfs-find-root 2281864 btrfs-image 2143536 btrfs-map-logical 2129704 btrfs-select-super 2151552 btrfstune 2130696 btrfs-zero-log 2276272 mkfs.btrfs 9166 show-blocks Total savings: 23928 (24 kilo)bytes Signed-off-by: Rosen Penev Signed-off-by: David Sterba --- tests/fssum.c | 27 +++++++++++---------------- 1 file changed, 11 insertions(+), 16 deletions(-) (limited to 'tests') diff --git a/tests/fssum.c b/tests/fssum.c index 5dde9984..2bda5df8 100644 --- a/tests/fssum.c +++ b/tests/fssum.c @@ -532,8 +532,8 @@ sum(int dirfd, int level, sum_t *dircs, char *path_prefix, char *path_in) } ret = lstat64(namelist[i], &st); if (ret) { - fprintf(stderr, "stat failed for %s/%s: %s\n", - path_prefix, path, strerror(errno)); + fprintf(stderr, "stat failed for %s/%s: %m\n", + path_prefix, path); exit(-1); } sum_add_u64(&meta, level); @@ -557,8 +557,8 @@ sum(int dirfd, int level, sum_t *dircs, char *path_prefix, char *path_in) if (fd == -1 && flags[FLAG_OPEN_ERROR]) { sum_add_u64(&meta, errno); } else if (fd == -1) { - fprintf(stderr, "open failed for %s/%s: %s\n", - path_prefix, path, strerror(errno)); + fprintf(stderr, "open failed for %s/%s: %m\n", + path_prefix, path); exit(-1); } else { sum(fd, level + 1, &cs, path_prefix, path); @@ -575,9 +575,8 @@ sum(int dirfd, int level, sum_t *dircs, char *path_prefix, char *path_in) sum_add_u64(&meta, errno); } else if (fd == -1) { fprintf(stderr, - "open failed for %s/%s: %s\n", - path_prefix, path, - strerror(errno)); + "open failed for %s/%s: %m\n", + path_prefix, path); exit(-1); } if (fd != -1) { @@ -585,9 +584,8 @@ sum(int dirfd, int level, sum_t *dircs, char *path_prefix, char *path_in) if (ret < 0) { fprintf(stderr, "read failed for " - "%s/%s: %s\n", - path_prefix, path, - strerror(errno)); + "%s/%s: %m\n", + path_prefix, path); exit(-1); } close(fd); @@ -693,8 +691,7 @@ main(int argc, char *argv[]) out_fp = fopen(optarg, "w"); if (!out_fp) { fprintf(stderr, - "failed to open output file: %s\n", - strerror(errno)); + "failed to open output file: %m\n"); exit(-1); } break; @@ -702,8 +699,7 @@ main(int argc, char *argv[]) in_fp = fopen(optarg, "r"); if (!in_fp) { fprintf(stderr, - "failed to open input file: %s\n", - strerror(errno)); + "failed to open input file: %m\n"); exit(-1); } break; @@ -788,8 +784,7 @@ main(int argc, char *argv[]) fd = open(path, O_RDONLY); if (fd == -1) { - fprintf(stderr, "failed to open %s: %s\n", path, - strerror(errno)); + fprintf(stderr, "failed to open %s: %m\n", path); exit(-1); } -- cgit v1.2.3 From cda595afa3cfabae2be30af9b8b08f2af3c31437 Mon Sep 17 00:00:00 2001 From: David Sterba Date: Tue, 30 Jan 2018 15:46:05 +0100 Subject: btrfs-progs: tests: disable some mkfs/010 testcases inside travis Node sizes larger than 16k will fail due to enospc in the mount test. This is likely caused by the kernel. Keep the condition only local to travis so any other testing environment could see the failure eventually. Signed-off-by: David Sterba --- tests/mkfs-tests/010-minimal-size/test.sh | 13 +++++++++++++ 1 file changed, 13 insertions(+) (limited to 'tests') diff --git a/tests/mkfs-tests/010-minimal-size/test.sh b/tests/mkfs-tests/010-minimal-size/test.sh index f33b8aa3..62f8e16a 100755 --- a/tests/mkfs-tests/010-minimal-size/test.sh +++ b/tests/mkfs-tests/010-minimal-size/test.sh @@ -39,6 +39,19 @@ do_test -n 16k -m single -d dup do_test -n 16k -m dup -d single do_test -n 16k -m dup -d dup +# Temporary: disable the following tests as they fail inside travis but run +# fine otherwise. This is probably caused by kernel version, 4.4 fails and 4.14 +# is ok. +# +# root_helper mount -t btrfs -o loop /home/travis/build/kdave/btrfs-progs/tests/test.img /home/travis/build/kdave/btrfs-progs/tests/mnt +# mount: No space left on device +# failed: root_helper mount -t btrfs -o loop /home/travis/build/kdave/btrfs-progs/tests/test.img /home/travis/build/kdave/btrfs-progs/tests/mnt +# test failed for case 010-minimal-size +# +if [ "$TRAVIS" = true ]; then + exit 0 +fi + do_test -n 32k -m single -d single do_test -n 32k -m single -d dup do_test -n 32k -m dup -d single -- cgit v1.2.3 From 7de5fafc646514c3b72e9baacf2de9180e7f392e Mon Sep 17 00:00:00 2001 From: David Sterba Date: Tue, 30 Jan 2018 18:51:25 +0100 Subject: btrfs-progs: tests: enhance common umount helper to take optional paths The run_check_umount_test_dev umounts the TEST_DEV and also optionally uses the arguments but this would not work as expected if the TEST_DEV is not a vald path for umount (eg. a restored image). Update the helper so it tries to umount all paths, or fallback to TEST_DEV to keep the current behaviour. Signed-off-by: David Sterba --- tests/common | 6 +++++- 1 file changed, 5 insertions(+), 1 deletion(-) (limited to 'tests') diff --git a/tests/common b/tests/common index 2fac202a..8e5d0cde 100644 --- a/tests/common +++ b/tests/common @@ -477,10 +477,14 @@ run_check_mount_test_dev() run_check $SUDO_HELPER mount -t btrfs $loop_opt "$@" "$TEST_DEV" "$TEST_MNT" } +# $1-$n: optional paths to unmount, otherwise fallback to TEST_DEV run_check_umount_test_dev() { setup_root_helper - run_check $SUDO_HELPER umount "$@" "$TEST_DEV" + if [ "$#" = 0 ]; then + set -- "$TEST_DEV" + fi + run_check $SUDO_HELPER umount "$@" } check_kernel_support() -- cgit v1.2.3 From 811303eab26961edab3de4ab4434080a798ce2df Mon Sep 17 00:00:00 2001 From: David Sterba Date: Tue, 30 Jan 2018 18:26:46 +0100 Subject: btrfs-progs: tests: fixup mount tests of fsck/028-unaligned-super-dev-sizes This test was broken because it tried to mount a different image than what it had repaired. Signed-off-by: David Sterba --- tests/fsck-tests/028-unaligned-super-dev-sizes/test.sh | 13 +++++-------- 1 file changed, 5 insertions(+), 8 deletions(-) (limited to 'tests') diff --git a/tests/fsck-tests/028-unaligned-super-dev-sizes/test.sh b/tests/fsck-tests/028-unaligned-super-dev-sizes/test.sh index 6f315fae..3928f548 100755 --- a/tests/fsck-tests/028-unaligned-super-dev-sizes/test.sh +++ b/tests/fsck-tests/028-unaligned-super-dev-sizes/test.sh @@ -6,21 +6,18 @@ source "$TOP/tests/common" check_prereq btrfs -prepare_test_dev setup_root_helper check_all_images -image=$(extract_image "./dev_and_super_mismatch_unaligned.raw.xz") +TEST_DEV=$(extract_image "./dev_and_super_mismatch_unaligned.raw.xz") # detect and fix -run_check "$TOP/btrfs" rescue fix-device-size "$image" +run_check "$TOP/btrfs" rescue fix-device-size "$TEST_DEV" # no problem found -run_check "$TOP/btrfs" rescue fix-device-size "$image" +run_check "$TOP/btrfs" rescue fix-device-size "$TEST_DEV" # check if fix-device-size worked -run_check "$TOP/btrfs" check "$image" +run_check "$TOP/btrfs" check "$TEST_DEV" # mount test run_check_mount_test_dev -run_check_umount_test_dev - -rm -f "$image" +run_check_umount_test_dev "$TEST_MNT" -- cgit v1.2.3 From 53b8ae14369c5df86c5a45af70e84b58895315c6 Mon Sep 17 00:00:00 2001 From: Qu Wenruo Date: Wed, 31 Jan 2018 10:40:36 +0800 Subject: btrfs-progs: tests: chang tree-reloc-tree test number from 027 to 015 There are 2 fsck tests with the same number 027: tree-reloc-tree bad-extent-inline-ref-type And we also have a hole in 015, so just rename tree-reloc-tree to 015, to get rid of the duplicated test number and fill in the hole. Signed-off-by: Qu Wenruo Signed-off-by: David Sterba --- tests/fsck-tests/015-tree-reloc-tree/test.sh | 19 +++++++++++++++++++ .../tree_reloc_for_data_reloc.img.xz | Bin 0 -> 2112 bytes .../tree_reloc_for_fs_tree.img.xz | Bin 0 -> 2424 bytes tests/fsck-tests/027-tree-reloc-tree/test.sh | 19 ------------------- .../tree_reloc_for_data_reloc.img.xz | Bin 2112 -> 0 bytes .../tree_reloc_for_fs_tree.img.xz | Bin 2424 -> 0 bytes 6 files changed, 19 insertions(+), 19 deletions(-) create mode 100755 tests/fsck-tests/015-tree-reloc-tree/test.sh create mode 100644 tests/fsck-tests/015-tree-reloc-tree/tree_reloc_for_data_reloc.img.xz create mode 100644 tests/fsck-tests/015-tree-reloc-tree/tree_reloc_for_fs_tree.img.xz delete mode 100755 tests/fsck-tests/027-tree-reloc-tree/test.sh delete mode 100644 tests/fsck-tests/027-tree-reloc-tree/tree_reloc_for_data_reloc.img.xz delete mode 100644 tests/fsck-tests/027-tree-reloc-tree/tree_reloc_for_fs_tree.img.xz (limited to 'tests') diff --git a/tests/fsck-tests/015-tree-reloc-tree/test.sh b/tests/fsck-tests/015-tree-reloc-tree/test.sh new file mode 100755 index 00000000..afad1e8d --- /dev/null +++ b/tests/fsck-tests/015-tree-reloc-tree/test.sh @@ -0,0 +1,19 @@ +#!/bin/bash +# Make sure btrfs check won't report any false alerts for valid image with +# reloc tree. +# +# Also due to the short life span of reloc tree, save the as dump example for +# later usage. + +source "$TOP/tests/common" + +check_prereq btrfs + +check_image() { + local image + + image=$1 + run_check "$TOP/btrfs" check "$image" +} + +check_all_images diff --git a/tests/fsck-tests/015-tree-reloc-tree/tree_reloc_for_data_reloc.img.xz b/tests/fsck-tests/015-tree-reloc-tree/tree_reloc_for_data_reloc.img.xz new file mode 100644 index 00000000..66d8bde6 Binary files /dev/null and b/tests/fsck-tests/015-tree-reloc-tree/tree_reloc_for_data_reloc.img.xz differ diff --git a/tests/fsck-tests/015-tree-reloc-tree/tree_reloc_for_fs_tree.img.xz b/tests/fsck-tests/015-tree-reloc-tree/tree_reloc_for_fs_tree.img.xz new file mode 100644 index 00000000..22af324b Binary files /dev/null and b/tests/fsck-tests/015-tree-reloc-tree/tree_reloc_for_fs_tree.img.xz differ diff --git a/tests/fsck-tests/027-tree-reloc-tree/test.sh b/tests/fsck-tests/027-tree-reloc-tree/test.sh deleted file mode 100755 index afad1e8d..00000000 --- a/tests/fsck-tests/027-tree-reloc-tree/test.sh +++ /dev/null @@ -1,19 +0,0 @@ -#!/bin/bash -# Make sure btrfs check won't report any false alerts for valid image with -# reloc tree. -# -# Also due to the short life span of reloc tree, save the as dump example for -# later usage. - -source "$TOP/tests/common" - -check_prereq btrfs - -check_image() { - local image - - image=$1 - run_check "$TOP/btrfs" check "$image" -} - -check_all_images diff --git a/tests/fsck-tests/027-tree-reloc-tree/tree_reloc_for_data_reloc.img.xz b/tests/fsck-tests/027-tree-reloc-tree/tree_reloc_for_data_reloc.img.xz deleted file mode 100644 index 66d8bde6..00000000 Binary files a/tests/fsck-tests/027-tree-reloc-tree/tree_reloc_for_data_reloc.img.xz and /dev/null differ diff --git a/tests/fsck-tests/027-tree-reloc-tree/tree_reloc_for_fs_tree.img.xz b/tests/fsck-tests/027-tree-reloc-tree/tree_reloc_for_fs_tree.img.xz deleted file mode 100644 index 22af324b..00000000 Binary files a/tests/fsck-tests/027-tree-reloc-tree/tree_reloc_for_fs_tree.img.xz and /dev/null differ -- cgit v1.2.3 From c38425344e229deba47f1ac41755618d86521d01 Mon Sep 17 00:00:00 2001 From: Qu Wenruo Date: Tue, 6 Feb 2018 15:31:42 +0800 Subject: btrfs-progs: fsck-tests: Cleanup the restored image for 028 Signed-off-by: Qu Wenruo Signed-off-by: David Sterba --- tests/fsck-tests/028-unaligned-super-dev-sizes/test.sh | 2 ++ 1 file changed, 2 insertions(+) (limited to 'tests') diff --git a/tests/fsck-tests/028-unaligned-super-dev-sizes/test.sh b/tests/fsck-tests/028-unaligned-super-dev-sizes/test.sh index 3928f548..2c72c7ef 100755 --- a/tests/fsck-tests/028-unaligned-super-dev-sizes/test.sh +++ b/tests/fsck-tests/028-unaligned-super-dev-sizes/test.sh @@ -21,3 +21,5 @@ run_check "$TOP/btrfs" check "$TEST_DEV" # mount test run_check_mount_test_dev run_check_umount_test_dev "$TEST_MNT" +# remove restored image +rm -- "$TEST_DEV" -- cgit v1.2.3 From 03401ccd7c4385185ee217a62663035653e880af Mon Sep 17 00:00:00 2001 From: Su Yue Date: Wed, 7 Feb 2018 17:57:43 +0800 Subject: btrfs-progs: tests common: remove meaningless colon in extract_image() The colon is meaningless so remove it. Signed-off-by: Su Yue Signed-off-by: David Sterba --- tests/common | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) (limited to 'tests') diff --git a/tests/common b/tests/common index 8e5d0cde..7f641a00 100644 --- a/tests/common +++ b/tests/common @@ -331,7 +331,7 @@ extract_image() case "$image" in *.img) rm -f "$image.restored" - : ;; + ;; *.img.xz) xz --decompress --keep "$image" || \ _fail "failed to decompress image $image" >&2 -- cgit v1.2.3 From eb2fe7d1c476ebfa434ec2cf8afd1b52cce0f28e Mon Sep 17 00:00:00 2001 From: Gu Jinxiang Date: Thu, 8 Feb 2018 14:34:18 +0800 Subject: btrfs-progs: Add make testsuite command for export tests Export the testsuite files to a separate tar. Since fsck tests depend on btrfs-corrupt-block, and misc tests depends on both btrfs-corrupt-block and fssum, so set it as prerequisites for package commad. Because, althougth fssum can be generated by source that are all in tests directory, and has no rely on the btrfs's structure. But btrfs-corrupt-block deeply relys on btrfs's structure. For consistency, at the present stage, generete the two when create test tar. Signed-off-by: Gu Jinxiang [ applied without changes, the generated tarball will be different from the one after the follow up commits ] Signed-off-by: David Sterba --- tests/export-tests.sh | 37 +++++++++++++++++++++++++++++++++++++ 1 file changed, 37 insertions(+) create mode 100755 tests/export-tests.sh (limited to 'tests') diff --git a/tests/export-tests.sh b/tests/export-tests.sh new file mode 100755 index 00000000..0ed7dd99 --- /dev/null +++ b/tests/export-tests.sh @@ -0,0 +1,37 @@ +#!/bin/bash +# export the testsuite files to a separate tar + +TESTSUITES_LIST_FILE=$PWD/testsuites-list +if ! [ -f $TESTSUITES_LIST_FILE ];then + echo "testsuites list file is not exsit." + exit 1 +fi + +TESTSUITES_LIST=$(cat $TESTSUITES_LIST_FILE) +if [ -z "$TESTSUITES_LIST" ]; then + echo "no file be list in testsuites-list" + exit 1 +fi + +DEST="btrfs-progs-tests.tar.gz" +if [ -f $DEST ];then + echo "remove exsit package: " $DEST + rm $DEST +fi + +TEST_ID=$PWD/testsuites-id +if [ -f $TEST_ID ];then + rm $TEST_ID +fi +VERSION=`./version.sh` +TIMESTAMP=`date -u "+%Y-%m-%d %T %Z"` + +echo "git version: " $VERSION > $TEST_ID +echo "this tar is created in: " $TIMESTAMP >> $TEST_ID + +echo "begin create tar: " $DEST +tar --exclude-vcs-ignores -zScf $DEST -C ../ $TESTSUITES_LIST +if [ $? -eq 0 ]; then + echo "create tar successfully." +fi +rm $TEST_ID -- cgit v1.2.3 From 04cd2c0bcac7129026c80661933b4ab97d4ab9ca Mon Sep 17 00:00:00 2001 From: David Sterba Date: Thu, 8 Feb 2018 15:34:04 +0100 Subject: btrfs-progs: rework testsuite export Move the testsuite to tests/ and make the tarball generation more deterministic. As there could be many random temporary files left in the test directories, we can't just copy them. Use 'git ls-tree' to filter just what we want, this needs a slight extension of the file list specification. Signed-off-by: David Sterba --- tests/export-tests.sh | 37 ------------------------------- tests/export-testsuite.sh | 55 +++++++++++++++++++++++++++++++++++++++++++++++ tests/testsuite-files | 22 +++++++++++++++++++ 3 files changed, 77 insertions(+), 37 deletions(-) delete mode 100755 tests/export-tests.sh create mode 100755 tests/export-testsuite.sh create mode 100644 tests/testsuite-files (limited to 'tests') diff --git a/tests/export-tests.sh b/tests/export-tests.sh deleted file mode 100755 index 0ed7dd99..00000000 --- a/tests/export-tests.sh +++ /dev/null @@ -1,37 +0,0 @@ -#!/bin/bash -# export the testsuite files to a separate tar - -TESTSUITES_LIST_FILE=$PWD/testsuites-list -if ! [ -f $TESTSUITES_LIST_FILE ];then - echo "testsuites list file is not exsit." - exit 1 -fi - -TESTSUITES_LIST=$(cat $TESTSUITES_LIST_FILE) -if [ -z "$TESTSUITES_LIST" ]; then - echo "no file be list in testsuites-list" - exit 1 -fi - -DEST="btrfs-progs-tests.tar.gz" -if [ -f $DEST ];then - echo "remove exsit package: " $DEST - rm $DEST -fi - -TEST_ID=$PWD/testsuites-id -if [ -f $TEST_ID ];then - rm $TEST_ID -fi -VERSION=`./version.sh` -TIMESTAMP=`date -u "+%Y-%m-%d %T %Z"` - -echo "git version: " $VERSION > $TEST_ID -echo "this tar is created in: " $TIMESTAMP >> $TEST_ID - -echo "begin create tar: " $DEST -tar --exclude-vcs-ignores -zScf $DEST -C ../ $TESTSUITES_LIST -if [ $? -eq 0 ]; then - echo "create tar successfully." -fi -rm $TEST_ID diff --git a/tests/export-testsuite.sh b/tests/export-testsuite.sh new file mode 100755 index 00000000..31b6ecf4 --- /dev/null +++ b/tests/export-testsuite.sh @@ -0,0 +1,55 @@ +#!/bin/bash +# export the testsuite files to a separate tar + +if ! [ -f testsuite-files ]; then + echo "ERROR: cannot find testsuite-files" + exit 1 +fi + +set -e + +TESTSUITE_TAR="btrfs-progs-tests.tar.gz" +rm -f "$TESTSUITE_TAR" + +TIMESTAMP=`date -u "+%Y-%m-%d %T %Z"` + +{ + echo "VERSION=`cat ../VERSION`" + echo "GIT_VERSION=`git describe`" + echo "TIMESTAMP='$TIMESTAMP'" +} > testsuite-id + +# Due to potentially unwanted files in the testsuite (restored images or other +# temporary files) we can't simply copy everything so the tar +# +# The testsuite-files specifier: +# F file +# - directly copy the file from the given path, may be a git tracked file or +# a built binary +# G path +# - a path relative to the top of git, recursively traversed; path +# postprocessing is needed so the tar gets it relative to tests/ +while read t f; do + case "$t" in + F) echo "$f";; + G) + here=`pwd` + cd .. + git ls-tree -r --name-only --full-name HEAD "$f" | + sed -e 's#^tests/##' | + sed -e 's#^Documentation#../Documentation#' + cd "$here" + ;; + esac +done < testsuite-files > testsuite-files-all + +echo "create tar: $TESTSUITE_TAR" +tar cz --sparse -f "$TESTSUITE_TAR" -T testsuite-files-all +if [ $? -eq 0 ]; then + echo "tar created successfully" + cat testsuite-id + rm -f testsuite-files-all + rm -f testsuite-id +else + exit $? +fi diff --git a/tests/testsuite-files b/tests/testsuite-files new file mode 100644 index 00000000..d75e2356 --- /dev/null +++ b/tests/testsuite-files @@ -0,0 +1,22 @@ +F README.md +G Documentation/ +F testsuite-id +F ../fssum +F ../btrfs-corrupt-block +F common +F common.convert +F common.local +G tests/cli-tests/ +F cli-tests.sh +G tests/convert-tests/ +F convert-tests.sh +G tests/fsck-tests/ +F fsck-tests.sh +G tests/fuzz-tests/ +F fuzz-tests.sh +G tests/misc-tests/ +F misc-tests.sh +G tests/mkfs-tests/ +F mkfs-tests.sh +F scan-results.sh +F test-console.sh -- cgit v1.2.3 From cebf3b37228cbde730a5448ad2dfb044600d5e03 Mon Sep 17 00:00:00 2001 From: Gu Jinxiang Date: Thu, 8 Feb 2018 14:34:19 +0800 Subject: btrfs-progs: introduce TEST_TOP and INTERNAL_BIN for tests Use TEST_TOP as base for tests to reference any files, this will be used for git and external testsuite. INTERNAL_BIN is needed for referencing binaries that could reside in different paths in git vs external testsuite. Signed-off-by: Gu Jinxiang [ add quotes around sourced files, update changelog ] Signed-off-by: David Sterba --- tests/cli-tests.sh | 15 ++++++++++----- tests/cli-tests/001-btrfs/test.sh | 2 +- tests/cli-tests/002-balance-full-no-filters/test.sh | 2 +- tests/cli-tests/003-fi-resize-args/test.sh | 2 +- tests/cli-tests/004-send-parent-multi-subvol/test.sh | 2 +- tests/cli-tests/005-qgroup-show/test.sh | 2 +- tests/cli-tests/006-qgroup-show-sync/test.sh | 2 +- tests/cli-tests/007-check-force/test.sh | 2 +- tests/cli-tests/008-subvolume-get-set-default/test.sh | 2 +- tests/common | 16 ++++++++++------ tests/convert-tests.sh | 15 ++++++++++----- tests/convert-tests/001-ext2-basic/test.sh | 4 ++-- tests/convert-tests/002-ext3-basic/test.sh | 4 ++-- tests/convert-tests/003-ext4-basic/test.sh | 4 ++-- .../004-ext2-backup-superblock-ranges/test.sh | 2 +- tests/convert-tests/005-delete-all-rollback/test.sh | 4 ++-- tests/convert-tests/006-large-hole-extent/test.sh | 4 ++-- tests/convert-tests/007-unsupported-block-sizes/test.sh | 4 ++-- tests/convert-tests/008-readonly-image/test.sh | 4 ++-- tests/convert-tests/009-common-inode-flags/test.sh | 4 ++-- tests/convert-tests/010-reiserfs-basic/test.sh | 4 ++-- .../011-reiserfs-delete-all-rollback/test.sh | 4 ++-- .../012-reiserfs-large-hole-extent/test.sh | 4 ++-- .../013-reiserfs-common-inode-flags/test.sh | 4 ++-- tests/convert-tests/014-reiserfs-tail-handling/test.sh | 4 ++-- .../convert-tests/015-no-rollback-after-balance/test.sh | 4 ++-- tests/fsck-tests.sh | 17 ++++++++++++----- tests/fsck-tests/006-bad-root-items/test.sh | 2 +- tests/fsck-tests/012-leaf-corruption/test.sh | 2 +- tests/fsck-tests/013-extent-tree-rebuild/test.sh | 4 ++-- tests/fsck-tests/018-leaf-crossing-stripes/test.sh | 2 +- tests/fsck-tests/019-non-skinny-false-alert/test.sh | 2 +- tests/fsck-tests/020-extent-ref-cases/test.sh | 2 +- .../021-partially-dropped-snapshot-case/test.sh | 2 +- tests/fsck-tests/022-qgroup-rescan-halfway/test.sh | 2 +- tests/fsck-tests/023-qgroup-stack-overflow/test.sh | 2 +- tests/fsck-tests/024-clear-space-cache/test.sh | 2 +- tests/fsck-tests/025-file-extents/test.sh | 2 +- tests/fsck-tests/026-bad-dir-item-name/test.sh | 2 +- tests/fsck-tests/028-unaligned-super-dev-sizes/test.sh | 2 +- tests/fuzz-tests.sh | 15 ++++++++++----- tests/fuzz-tests/001-simple-check-unmounted/test.sh | 4 ++-- tests/fuzz-tests/002-simple-image/test.sh | 4 ++-- tests/fuzz-tests/003-multi-check-unmounted/test.sh | 4 ++-- tests/fuzz-tests/004-simple-dump-tree/test.sh | 4 ++-- tests/fuzz-tests/005-simple-dump-super/test.sh | 4 ++-- tests/fuzz-tests/006-simple-tree-stats/test.sh | 4 ++-- tests/fuzz-tests/007-simple-super-recover/test.sh | 4 ++-- tests/fuzz-tests/008-simple-chunk-recover/test.sh | 4 ++-- tests/fuzz-tests/009-simple-zero-log/test.sh | 4 ++-- tests/misc-tests.sh | 17 ++++++++++++----- tests/misc-tests/001-btrfstune-features/test.sh | 2 +- tests/misc-tests/002-uuid-rewrite/test.sh | 6 +++--- tests/misc-tests/003-zero-log/test.sh | 4 ++-- tests/misc-tests/004-shrink-fs/test.sh | 2 +- .../005-convert-progress-thread-crash/test.sh | 2 +- tests/misc-tests/006-image-on-missing-device/test.sh | 2 +- tests/misc-tests/007-subvolume-sync/test.sh | 2 +- tests/misc-tests/008-leaf-crossing-stripes/test.sh | 2 +- tests/misc-tests/009-subvolume-sync-must-wait/test.sh | 2 +- tests/misc-tests/010-convert-delete-ext2-subvol/test.sh | 2 +- tests/misc-tests/011-delete-missing-device/test.sh | 2 +- tests/misc-tests/012-find-root-no-result/test.sh | 2 +- tests/misc-tests/013-subvolume-sync-crash/test.sh | 2 +- tests/misc-tests/014-filesystem-label/test.sh | 2 +- tests/misc-tests/015-dump-super-garbage/test.sh | 2 +- tests/misc-tests/016-send-clone-src/test.sh | 2 +- tests/misc-tests/017-recv-stream-malformatted/test.sh | 2 +- tests/misc-tests/018-recv-end-of-stream/test.sh | 2 +- .../019-receive-clones-on-mounted-subvol/test.sh | 4 ++-- tests/misc-tests/020-fix-superblock-corruption/test.sh | 2 +- tests/misc-tests/021-image-multi-devices/test.sh | 2 +- .../022-filesystem-du-on-empty-subvol/test.sh | 2 +- .../023-device-usage-with-missing-device/test.sh | 2 +- tests/misc-tests/024-inspect-internal-rootid/test.sh | 2 +- tests/misc-tests/025-zstd-compression/test.sh | 2 +- tests/misc-tests/026-image-non-printable-chars/test.sh | 2 +- .../misc-tests/027-subvol-list-deleted-toplevel/test.sh | 2 +- tests/mkfs-tests.sh | 17 ++++++++++++----- tests/mkfs-tests/001-basic-profiles/test.sh | 2 +- .../002-no-force-mixed-on-small-volume/test.sh | 2 +- tests/mkfs-tests/003-mixed-with-wrong-nodesize/test.sh | 2 +- tests/mkfs-tests/004-rootdir-keeps-size/test.sh | 4 ++-- tests/mkfs-tests/005-long-device-name-for-ssd/test.sh | 2 +- tests/mkfs-tests/006-partitioned-loopdev/test.sh | 2 +- tests/mkfs-tests/007-mix-nodesize-sectorsize/test.sh | 2 +- .../008-sectorsize-nodesize-combination/test.sh | 2 +- tests/mkfs-tests/009-special-files-for-rootdir/test.sh | 2 +- 88 files changed, 186 insertions(+), 146 deletions(-) (limited to 'tests') diff --git a/tests/cli-tests.sh b/tests/cli-tests.sh index 16d6afcf..b981f833 100755 --- a/tests/cli-tests.sh +++ b/tests/cli-tests.sh @@ -4,13 +4,18 @@ LANG=C SCRIPT_DIR=$(dirname $(readlink -f "$0")) +TEST_TOP=$(readlink -f "$SCRIPT_DIR/../tests/") TOP=$(readlink -f "$SCRIPT_DIR/../") +if ! [ -f "$TOP/btrfs" ];then + TOP=$(dirname `which btrfs`) +fi TEST_DEV=${TEST_DEV:-} -RESULTS="$TOP/tests/cli-tests-results.txt" -IMAGE="$TOP/tests/test.img" +RESULTS="$TEST_TOP/cli-tests-results.txt" +IMAGE="$TEST_TOP/test.img" -source "$TOP/tests/common" +source "$TEST_TOP/common" +export TEST_TOP export TOP export RESULTS export LANG @@ -24,7 +29,7 @@ check_kernel_support # The tests are driven by their custom script called 'test.sh' -for i in $(find "$TOP/tests/cli-tests" -maxdepth 1 -mindepth 1 -type d \ +for i in $(find "$TEST_TOP/cli-tests" -maxdepth 1 -mindepth 1 -type d \ ${TEST:+-name "$TEST"} | sort) do name=$(basename "$i") @@ -40,5 +45,5 @@ do _fail "test failed for case $(basename $i)" fi fi - cd "$TOP" + cd "$TEST_TOP" done diff --git a/tests/cli-tests/001-btrfs/test.sh b/tests/cli-tests/001-btrfs/test.sh index c680604b..55ab0ad5 100755 --- a/tests/cli-tests/001-btrfs/test.sh +++ b/tests/cli-tests/001-btrfs/test.sh @@ -1,7 +1,7 @@ #!/bin/bash # test commands of btrfs -source "$TOP/tests/common" +source "$TEST_TOP/common" check_prereq btrfs diff --git a/tests/cli-tests/002-balance-full-no-filters/test.sh b/tests/cli-tests/002-balance-full-no-filters/test.sh index 0475ea73..3403b700 100755 --- a/tests/cli-tests/002-balance-full-no-filters/test.sh +++ b/tests/cli-tests/002-balance-full-no-filters/test.sh @@ -2,7 +2,7 @@ # # coverage of balance --full-balance -source "$TOP/tests/common" +source "$TEST_TOP/common" check_prereq mkfs.btrfs check_prereq btrfs diff --git a/tests/cli-tests/003-fi-resize-args/test.sh b/tests/cli-tests/003-fi-resize-args/test.sh index e4f262b6..f6f598f2 100755 --- a/tests/cli-tests/003-fi-resize-args/test.sh +++ b/tests/cli-tests/003-fi-resize-args/test.sh @@ -2,7 +2,7 @@ # # test parsing of various resize arguments -source "$TOP/tests/common" +source "$TEST_TOP/common" check_prereq mkfs.btrfs check_prereq btrfs diff --git a/tests/cli-tests/004-send-parent-multi-subvol/test.sh b/tests/cli-tests/004-send-parent-multi-subvol/test.sh index c1348b50..165ef4a6 100755 --- a/tests/cli-tests/004-send-parent-multi-subvol/test.sh +++ b/tests/cli-tests/004-send-parent-multi-subvol/test.sh @@ -2,7 +2,7 @@ # # minimal test for the following syntax: btrfs send -p parent subvol1 subvol2 -source "$TOP/tests/common" +source "$TEST_TOP/common" check_prereq mkfs.btrfs check_prereq btrfs diff --git a/tests/cli-tests/005-qgroup-show/test.sh b/tests/cli-tests/005-qgroup-show/test.sh index d9a91831..10521039 100755 --- a/tests/cli-tests/005-qgroup-show/test.sh +++ b/tests/cli-tests/005-qgroup-show/test.sh @@ -2,7 +2,7 @@ # # qgroup show behaviour when quotas are not enabled -source "$TOP/tests/common" +source "$TEST_TOP/common" check_prereq mkfs.btrfs check_prereq btrfs diff --git a/tests/cli-tests/006-qgroup-show-sync/test.sh b/tests/cli-tests/006-qgroup-show-sync/test.sh index d552b8b9..aec7a4ba 100755 --- a/tests/cli-tests/006-qgroup-show-sync/test.sh +++ b/tests/cli-tests/006-qgroup-show-sync/test.sh @@ -2,7 +2,7 @@ # # simple test of qgroup show --sync option -source "$TOP/tests/common" +source "$TEST_TOP/common" check_prereq mkfs.btrfs check_prereq btrfs diff --git a/tests/cli-tests/007-check-force/test.sh b/tests/cli-tests/007-check-force/test.sh index 12b30205..597f2d60 100755 --- a/tests/cli-tests/007-check-force/test.sh +++ b/tests/cli-tests/007-check-force/test.sh @@ -2,7 +2,7 @@ # # test 'btrfs check --force' on a mounted filesystem -source "$TOP/tests/common" +source "$TEST_TOP/common" check_prereq mkfs.btrfs check_prereq btrfs diff --git a/tests/cli-tests/008-subvolume-get-set-default/test.sh b/tests/cli-tests/008-subvolume-get-set-default/test.sh index 9318002e..706ee8c5 100755 --- a/tests/cli-tests/008-subvolume-get-set-default/test.sh +++ b/tests/cli-tests/008-subvolume-get-set-default/test.sh @@ -10,7 +10,7 @@ check_default_id() fi } -source "$TOP/tests/common" +source "$TEST_TOP/common" check_prereq mkfs.btrfs check_prereq btrfs diff --git a/tests/common b/tests/common index 7f641a00..fae30f1d 100644 --- a/tests/common +++ b/tests/common @@ -290,8 +290,12 @@ run_mustfail_stdout() check_prereq() { - if ! [ -f "$TOP/$1" ]; then - _fail "Failed prerequisites: $1"; + if [ "$1" = "btrfs-corrupt-block" -o "$1" = "fssum" ]; then + if ! [ -f "$INTERNAL_BIN/$1" ]; then + _fail "Failed prerequisites: $INTERNAL_BIN/$1"; + fi + elif ! [ -f "$TOP/$1" ]; then + _fail "Failed prerequisites: $TOP/$1"; fi } @@ -449,9 +453,9 @@ prepare_test_dev() return; fi - echo "\$TEST_DEV not given, using $TOP/tests/test.img as fallback" >> \ + echo "\$TEST_DEV not given, using $TEST_TOP/test.img as fallback" >> \ "$RESULTS" - TEST_DEV="$TOP/tests/test.img" + TEST_DEV="$TEST_TOP/test.img" truncate -s 0 "$TEST_DEV" truncate -s "$size" "$TEST_DEV" || _not_run "create file for loop device failed" @@ -632,11 +636,11 @@ cleanup_loopdevs() init_env() { - TEST_MNT="${TEST_MNT:-$TOP/tests/mnt}" + TEST_MNT="${TEST_MNT:-$TEST_TOP/mnt}" export TEST_MNT mkdir -p "$TEST_MNT" || { echo "Failed mkdir -p $TEST_MNT"; exit 1; } - source $TOP/tests/common.local + source $TEST_TOP/common.local if [ "$TEST_ENABLE_OVERRIDE" = 'true' -a -n "$RESULTS" ]; then echo "INCLUDE common.local" >> "$RESULTS" diff --git a/tests/convert-tests.sh b/tests/convert-tests.sh index 2a92a58b..52c59d4d 100755 --- a/tests/convert-tests.sh +++ b/tests/convert-tests.sh @@ -5,14 +5,19 @@ LANG=C SCRIPT_DIR=$(dirname $(readlink -f "$0")) +TEST_TOP=$(readlink -f "$SCRIPT_DIR/../tests/") TOP=$(readlink -f "$SCRIPT_DIR/../") +if ! [ -f "$TOP/btrfs" ];then + TOP=$(dirname `which btrfs`) +fi TEST_DEV=${TEST_DEV:-} -RESULTS="$TOP/tests/convert-tests-results.txt" -IMAGE="$TOP/tests/test.img" +RESULTS="$TEST_TOP/convert-tests-results.txt" +IMAGE="$TEST_TOP/test.img" -source "$TOP/tests/common" -source "$TOP/tests/common.convert" +source "$TEST_TOP/common" +source "$TEST_TOP/common.convert" +export TEST_TOP export TOP export RESULTS export LANG @@ -54,7 +59,7 @@ run_one_test() { } # Test special images -for i in $(find "$TOP/tests/convert-tests" -maxdepth 1 -mindepth 1 -type d \ +for i in $(find "$TEST_TOP/convert-tests" -maxdepth 1 -mindepth 1 -type d \ ${TEST:+-name "$TEST"} | sort) do run_one_test "$i" diff --git a/tests/convert-tests/001-ext2-basic/test.sh b/tests/convert-tests/001-ext2-basic/test.sh index af75d948..74cc74e8 100755 --- a/tests/convert-tests/001-ext2-basic/test.sh +++ b/tests/convert-tests/001-ext2-basic/test.sh @@ -1,7 +1,7 @@ #!/bin/bash -source "$TOP/tests/common" -source "$TOP/tests/common.convert" +source "$TEST_TOP/common" +source "$TEST_TOP/common.convert" setup_root_helper prepare_test_dev diff --git a/tests/convert-tests/002-ext3-basic/test.sh b/tests/convert-tests/002-ext3-basic/test.sh index 233e2d94..f0869897 100755 --- a/tests/convert-tests/002-ext3-basic/test.sh +++ b/tests/convert-tests/002-ext3-basic/test.sh @@ -1,7 +1,7 @@ #!/bin/bash -source "$TOP/tests/common" -source "$TOP/tests/common.convert" +source "$TEST_TOP/common" +source "$TEST_TOP/common.convert" setup_root_helper prepare_test_dev diff --git a/tests/convert-tests/003-ext4-basic/test.sh b/tests/convert-tests/003-ext4-basic/test.sh index baf6115c..c5caf67c 100755 --- a/tests/convert-tests/003-ext4-basic/test.sh +++ b/tests/convert-tests/003-ext4-basic/test.sh @@ -1,7 +1,7 @@ #!/bin/bash -source "$TOP/tests/common" -source "$TOP/tests/common.convert" +source "$TEST_TOP/common" +source "$TEST_TOP/common.convert" setup_root_helper prepare_test_dev diff --git a/tests/convert-tests/004-ext2-backup-superblock-ranges/test.sh b/tests/convert-tests/004-ext2-backup-superblock-ranges/test.sh index cf354d40..dcb9772b 100755 --- a/tests/convert-tests/004-ext2-backup-superblock-ranges/test.sh +++ b/tests/convert-tests/004-ext2-backup-superblock-ranges/test.sh @@ -10,7 +10,7 @@ # 4) Overlap file extents # 5) Unable to rollback -source "$TOP/tests/common" +source "$TEST_TOP/common" check_prereq btrfs-convert check_prereq btrfs diff --git a/tests/convert-tests/005-delete-all-rollback/test.sh b/tests/convert-tests/005-delete-all-rollback/test.sh index 31fa2c4b..a5f9d594 100755 --- a/tests/convert-tests/005-delete-all-rollback/test.sh +++ b/tests/convert-tests/005-delete-all-rollback/test.sh @@ -2,8 +2,8 @@ # create a base image, convert to btrfs, remove all files, rollback the ext4 image # note: ext4 only -source "$TOP/tests/common" -source "$TOP/tests/common.convert" +source "$TEST_TOP/common" +source "$TEST_TOP/common.convert" setup_root_helper prepare_test_dev diff --git a/tests/convert-tests/006-large-hole-extent/test.sh b/tests/convert-tests/006-large-hole-extent/test.sh index 38e97055..a37fcbdc 100755 --- a/tests/convert-tests/006-large-hole-extent/test.sh +++ b/tests/convert-tests/006-large-hole-extent/test.sh @@ -5,8 +5,8 @@ # Fast pinpoint regression test. No options combination nor checksum # verification -source "$TOP/tests/common" -source "$TOP/tests/common.convert" +source "$TEST_TOP/common" +source "$TEST_TOP/common.convert" setup_root_helper prepare_test_dev diff --git a/tests/convert-tests/007-unsupported-block-sizes/test.sh b/tests/convert-tests/007-unsupported-block-sizes/test.sh index ef010202..9fda5add 100755 --- a/tests/convert-tests/007-unsupported-block-sizes/test.sh +++ b/tests/convert-tests/007-unsupported-block-sizes/test.sh @@ -1,8 +1,8 @@ #!/bin/bash # Check if block sizes smaller than 4k expectedly fail to convert -source "$TOP/tests/common" -source "$TOP/tests/common.convert" +source "$TEST_TOP/common" +source "$TEST_TOP/common.convert" setup_root_helper prepare_test_dev diff --git a/tests/convert-tests/008-readonly-image/test.sh b/tests/convert-tests/008-readonly-image/test.sh index 064bc271..1a65ea6b 100755 --- a/tests/convert-tests/008-readonly-image/test.sh +++ b/tests/convert-tests/008-readonly-image/test.sh @@ -1,8 +1,8 @@ #!/bin/bash # Check if the converted ext2 image is readonly -source "$TOP/tests/common" -source "$TOP/tests/common.convert" +source "$TEST_TOP/common" +source "$TEST_TOP/common.convert" setup_root_helper prepare_test_dev diff --git a/tests/convert-tests/009-common-inode-flags/test.sh b/tests/convert-tests/009-common-inode-flags/test.sh index 6d159993..428213bf 100755 --- a/tests/convert-tests/009-common-inode-flags/test.sh +++ b/tests/convert-tests/009-common-inode-flags/test.sh @@ -1,8 +1,8 @@ #!/bin/bash # Check if btrfs-convert can copy common inode flags like SYNC/IMMUTABLE -source "$TOP/tests/common" -source "$TOP/tests/common.convert" +source "$TEST_TOP/common" +source "$TEST_TOP/common.convert" setup_root_helper prepare_test_dev diff --git a/tests/convert-tests/010-reiserfs-basic/test.sh b/tests/convert-tests/010-reiserfs-basic/test.sh index 87008f15..73652991 100755 --- a/tests/convert-tests/010-reiserfs-basic/test.sh +++ b/tests/convert-tests/010-reiserfs-basic/test.sh @@ -1,7 +1,7 @@ #!/bin/bash -source "$TOP/tests/common" -source "$TOP/tests/common.convert" +source "$TEST_TOP/common" +source "$TEST_TOP/common.convert" if ! check_kernel_support_reiserfs >/dev/null; then _not_run "no reiserfs support" diff --git a/tests/convert-tests/011-reiserfs-delete-all-rollback/test.sh b/tests/convert-tests/011-reiserfs-delete-all-rollback/test.sh index 0b8366c8..28877e14 100755 --- a/tests/convert-tests/011-reiserfs-delete-all-rollback/test.sh +++ b/tests/convert-tests/011-reiserfs-delete-all-rollback/test.sh @@ -1,8 +1,8 @@ #!/bin/bash # create a base image, convert to btrfs, remove all files, rollback the reiserfs image -source "$TOP/tests/common" -source "$TOP/tests/common.convert" +source "$TEST_TOP/common" +source "$TEST_TOP/common.convert" if ! check_kernel_support_reiserfs >/dev/null; then _not_run "no reiserfs support" diff --git a/tests/convert-tests/012-reiserfs-large-hole-extent/test.sh b/tests/convert-tests/012-reiserfs-large-hole-extent/test.sh index dde1b3eb..d492779a 100755 --- a/tests/convert-tests/012-reiserfs-large-hole-extent/test.sh +++ b/tests/convert-tests/012-reiserfs-large-hole-extent/test.sh @@ -5,8 +5,8 @@ # Fast pinpoint regression test. No options combination nor checksum # verification -source "$TOP/tests/common" -source "$TOP/tests/common.convert" +source "$TEST_TOP/common" +source "$TEST_TOP/common.convert" if ! check_kernel_support_reiserfs >/dev/null; then _not_run "no reiserfs support" diff --git a/tests/convert-tests/013-reiserfs-common-inode-flags/test.sh b/tests/convert-tests/013-reiserfs-common-inode-flags/test.sh index a15240ce..521e8bd4 100755 --- a/tests/convert-tests/013-reiserfs-common-inode-flags/test.sh +++ b/tests/convert-tests/013-reiserfs-common-inode-flags/test.sh @@ -1,8 +1,8 @@ #!/bin/bash # Check if btrfs-convert can copy common inode flags like SYNC/IMMUTABLE -source "$TOP/tests/common" -source "$TOP/tests/common.convert" +source "$TEST_TOP/common" +source "$TEST_TOP/common.convert" if ! check_kernel_support_reiserfs >/dev/null; then _not_run "no reiserfs support" diff --git a/tests/convert-tests/014-reiserfs-tail-handling/test.sh b/tests/convert-tests/014-reiserfs-tail-handling/test.sh index 335c0091..5714dc6c 100755 --- a/tests/convert-tests/014-reiserfs-tail-handling/test.sh +++ b/tests/convert-tests/014-reiserfs-tail-handling/test.sh @@ -6,8 +6,8 @@ # We use separate inputs for tails and real blocks so we can determine # if there was a failure in copying either. -source "$TOP/tests/common" -source "$TOP/tests/common.convert" +source "$TEST_TOP/common" +source "$TEST_TOP/common.convert" if ! check_kernel_support_reiserfs >/dev/null; then _not_run "no reiserfs support" diff --git a/tests/convert-tests/015-no-rollback-after-balance/test.sh b/tests/convert-tests/015-no-rollback-after-balance/test.sh index 47c9c6fa..2f6407f3 100755 --- a/tests/convert-tests/015-no-rollback-after-balance/test.sh +++ b/tests/convert-tests/015-no-rollback-after-balance/test.sh @@ -2,8 +2,8 @@ # Check if btrfs-convert refuses to rollback the filesystem, and leave the fs # and the convert image untouched -source "$TOP/tests/common" -source "$TOP/tests/common.convert" +source "$TEST_TOP/common" +source "$TEST_TOP/common.convert" setup_root_helper prepare_test_dev diff --git a/tests/fsck-tests.sh b/tests/fsck-tests.sh index 15d26c70..f97ae986 100755 --- a/tests/fsck-tests.sh +++ b/tests/fsck-tests.sh @@ -4,13 +4,20 @@ LANG=C SCRIPT_DIR=$(dirname $(readlink -f "$0")) +INTERNAL_BIN=$(readlink -f "$SCRIPT_DIR/../") +TEST_TOP=$(readlink -f "$SCRIPT_DIR/../tests/") TOP=$(readlink -f "$SCRIPT_DIR/../") +if ! [ -f "$TOP/btrfs" ];then + TOP=$(dirname `which btrfs`) +fi TEST_DEV=${TEST_DEV:-} -RESULTS="$TOP/tests/fsck-tests-results.txt" -IMAGE="$TOP/tests/test.img" +RESULTS="$TEST_TOP/fsck-tests-results.txt" +IMAGE="$TEST_TOP/test.img" -source "$TOP/tests/common" +source "$TEST_TOP/common" +export INTERNAL_BIN +export TEST_TOP export TOP export RESULTS export LANG @@ -46,7 +53,7 @@ run_one_test() { # Type 1 check_all_images fi - cd "$TOP" + cd "$TEST_TOP" } # Each dir contains one type of error for btrfsck test. @@ -62,7 +69,7 @@ run_one_test() { # This is for case btrfs-image can't dump or case needs extra # check/verify -for i in $(find "$TOP/tests/fsck-tests" -maxdepth 1 -mindepth 1 -type d \ +for i in $(find "$TEST_TOP/fsck-tests" -maxdepth 1 -mindepth 1 -type d \ ${TEST:+-name "$TEST"} | sort) do run_one_test "$i" diff --git a/tests/fsck-tests/006-bad-root-items/test.sh b/tests/fsck-tests/006-bad-root-items/test.sh index bf3ef781..2cbf67a8 100755 --- a/tests/fsck-tests/006-bad-root-items/test.sh +++ b/tests/fsck-tests/006-bad-root-items/test.sh @@ -1,6 +1,6 @@ #!/bin/bash -source "$TOP/tests/common" +source "$TEST_TOP/common" check_prereq btrfs diff --git a/tests/fsck-tests/012-leaf-corruption/test.sh b/tests/fsck-tests/012-leaf-corruption/test.sh index fc10a4ff..68d9f695 100755 --- a/tests/fsck-tests/012-leaf-corruption/test.sh +++ b/tests/fsck-tests/012-leaf-corruption/test.sh @@ -1,6 +1,6 @@ #!/bin/bash -source "$TOP/tests/common" +source "$TEST_TOP/common" check_prereq btrfs-image diff --git a/tests/fsck-tests/013-extent-tree-rebuild/test.sh b/tests/fsck-tests/013-extent-tree-rebuild/test.sh index d71c1b2e..02afdda1 100755 --- a/tests/fsck-tests/013-extent-tree-rebuild/test.sh +++ b/tests/fsck-tests/013-extent-tree-rebuild/test.sh @@ -1,6 +1,6 @@ #!/bin/bash -source "$TOP/tests/common" +source "$TEST_TOP/common" check_prereq btrfs-corrupt-block check_prereq mkfs.btrfs @@ -31,7 +31,7 @@ test_extent_tree_rebuild() fi # corrupt extent root node block - run_check $SUDO_HELPER "$TOP/btrfs-corrupt-block" -l "$extent_root_bytenr" \ + run_check $SUDO_HELPER "$INTERNAL_BIN/btrfs-corrupt-block" -l "$extent_root_bytenr" \ -b 4096 "$TEST_DEV" $SUDO_HELPER "$TOP/btrfs" check "$TEST_DEV" >& /dev/null && \ diff --git a/tests/fsck-tests/018-leaf-crossing-stripes/test.sh b/tests/fsck-tests/018-leaf-crossing-stripes/test.sh index 29eb20b5..2a3f6379 100755 --- a/tests/fsck-tests/018-leaf-crossing-stripes/test.sh +++ b/tests/fsck-tests/018-leaf-crossing-stripes/test.sh @@ -1,6 +1,6 @@ #!/bin/bash -source "$TOP/tests/common" +source "$TEST_TOP/common" check_prereq btrfs diff --git a/tests/fsck-tests/019-non-skinny-false-alert/test.sh b/tests/fsck-tests/019-non-skinny-false-alert/test.sh index 550f2947..32f595da 100755 --- a/tests/fsck-tests/019-non-skinny-false-alert/test.sh +++ b/tests/fsck-tests/019-non-skinny-false-alert/test.sh @@ -11,7 +11,7 @@ # # a buggy check leads to the above messages -source "$TOP/tests/common" +source "$TEST_TOP/common" check_prereq btrfs diff --git a/tests/fsck-tests/020-extent-ref-cases/test.sh b/tests/fsck-tests/020-extent-ref-cases/test.sh index 0c4f7848..9cf99a51 100755 --- a/tests/fsck-tests/020-extent-ref-cases/test.sh +++ b/tests/fsck-tests/020-extent-ref-cases/test.sh @@ -15,7 +15,7 @@ # the beginning of leaf. # Which caused false alert for lowmem mode. -source "$TOP/tests/common" +source "$TEST_TOP/common" check_prereq btrfs diff --git a/tests/fsck-tests/021-partially-dropped-snapshot-case/test.sh b/tests/fsck-tests/021-partially-dropped-snapshot-case/test.sh index 5d997e24..e6379f97 100755 --- a/tests/fsck-tests/021-partially-dropped-snapshot-case/test.sh +++ b/tests/fsck-tests/021-partially-dropped-snapshot-case/test.sh @@ -2,7 +2,7 @@ # confirm whether 'btrfs check' supports check ing of a partially dropped # snapshot -source "$TOP/tests/common" +source "$TEST_TOP/common" check_prereq btrfs diff --git a/tests/fsck-tests/022-qgroup-rescan-halfway/test.sh b/tests/fsck-tests/022-qgroup-rescan-halfway/test.sh index dcdc1b42..615f003d 100755 --- a/tests/fsck-tests/022-qgroup-rescan-halfway/test.sh +++ b/tests/fsck-tests/022-qgroup-rescan-halfway/test.sh @@ -1,7 +1,7 @@ #!/bin/bash # check whether btrfsck can detect running qgroup rescan -source "$TOP/tests/common" +source "$TEST_TOP/common" check_prereq btrfs diff --git a/tests/fsck-tests/023-qgroup-stack-overflow/test.sh b/tests/fsck-tests/023-qgroup-stack-overflow/test.sh index ebb07f36..d7b85f07 100755 --- a/tests/fsck-tests/023-qgroup-stack-overflow/test.sh +++ b/tests/fsck-tests/023-qgroup-stack-overflow/test.sh @@ -5,7 +5,7 @@ # Fixed by patch: # btrfs-progs: Fix stack overflow for checking qgroup on tree reloc tree -source "$TOP/tests/common" +source "$TEST_TOP/common" check_prereq btrfs diff --git a/tests/fsck-tests/024-clear-space-cache/test.sh b/tests/fsck-tests/024-clear-space-cache/test.sh index 76ebcb6b..6a3a31ec 100755 --- a/tests/fsck-tests/024-clear-space-cache/test.sh +++ b/tests/fsck-tests/024-clear-space-cache/test.sh @@ -1,7 +1,7 @@ #!/bin/bash # confirm that clearing space cache works -source "$TOP/tests/common" +source "$TEST_TOP/common" check_prereq btrfs check_prereq mkfs.btrfs diff --git a/tests/fsck-tests/025-file-extents/test.sh b/tests/fsck-tests/025-file-extents/test.sh index ebe8a305..95707596 100755 --- a/tests/fsck-tests/025-file-extents/test.sh +++ b/tests/fsck-tests/025-file-extents/test.sh @@ -1,7 +1,7 @@ #!/bin/bash # Confirm btrfs check can check file extents without causing false alert -source "$TOP/tests/common" +source "$TEST_TOP/common" check_prereq btrfs check_prereq mkfs.btrfs diff --git a/tests/fsck-tests/026-bad-dir-item-name/test.sh b/tests/fsck-tests/026-bad-dir-item-name/test.sh index a1077a8d..a38bf045 100755 --- a/tests/fsck-tests/026-bad-dir-item-name/test.sh +++ b/tests/fsck-tests/026-bad-dir-item-name/test.sh @@ -2,7 +2,7 @@ # # confirm whether check detects name and hash mismatch in dir_item -source "$TOP/tests/common" +source "$TEST_TOP/common" check_prereq btrfs diff --git a/tests/fsck-tests/028-unaligned-super-dev-sizes/test.sh b/tests/fsck-tests/028-unaligned-super-dev-sizes/test.sh index 2c72c7ef..4015df2d 100755 --- a/tests/fsck-tests/028-unaligned-super-dev-sizes/test.sh +++ b/tests/fsck-tests/028-unaligned-super-dev-sizes/test.sh @@ -3,7 +3,7 @@ # An image with mis-aligned superblock total_bytes, that will be found and # fixed by 'check' or fixed by 'rescue fix-device-size' -source "$TOP/tests/common" +source "$TEST_TOP/common" check_prereq btrfs setup_root_helper diff --git a/tests/fuzz-tests.sh b/tests/fuzz-tests.sh index f72385e5..dca84f10 100755 --- a/tests/fuzz-tests.sh +++ b/tests/fuzz-tests.sh @@ -4,13 +4,18 @@ LANG=C SCRIPT_DIR=$(dirname $(readlink -f "$0")) +TEST_TOP=$(readlink -f "$SCRIPT_DIR/../tests/") TOP=$(readlink -f "$SCRIPT_DIR/../") +if ! [ -f "$TOP/btrfs" ];then + TOP=$(dirname `which btrfs`) +fi TEST_DEV=${TEST_DEV:-} -RESULTS="$TOP/tests/fuzz-tests-results.txt" -IMAGE="$TOP/tests/test.img" +RESULTS="$TEST_TOP/fuzz-tests-results.txt" +IMAGE="$TEST_TOP/test.img" -source "$TOP/tests/common" +source "$TEST_TOP/common" +export TEST_TOP export TOP export RESULTS export LANG @@ -23,7 +28,7 @@ check_prereq btrfs # The tests are driven by their custom script called 'test.sh' -for i in $(find "$TOP/tests/fuzz-tests" -maxdepth 1 -mindepth 1 -type d \ +for i in $(find "$TEST_TOP/fuzz-tests" -maxdepth 1 -mindepth 1 -type d \ ${TEST:+-name "$TEST"} | sort) do name=$(basename "$i") @@ -39,5 +44,5 @@ do _fail "test failed for case $(basename $i)" fi fi - cd "$TOP" + cd "$TEST_TOP" done diff --git a/tests/fuzz-tests/001-simple-check-unmounted/test.sh b/tests/fuzz-tests/001-simple-check-unmounted/test.sh index 98fe7b0c..905d37b7 100755 --- a/tests/fuzz-tests/001-simple-check-unmounted/test.sh +++ b/tests/fuzz-tests/001-simple-check-unmounted/test.sh @@ -2,7 +2,7 @@ # iterate over all fuzzed images and run 'btrfs check' -source $TOP/tests/common +source "$TEST_TOP/common" setup_root_helper check_prereq btrfs @@ -15,6 +15,6 @@ check_image() { run_mayfail $TOP/btrfs check "$image" } -check_all_images $TOP/tests/fuzz-tests/images +check_all_images $TEST_TOP/fuzz-tests/images exit 0 diff --git a/tests/fuzz-tests/002-simple-image/test.sh b/tests/fuzz-tests/002-simple-image/test.sh index 42470ecc..034fcf46 100755 --- a/tests/fuzz-tests/002-simple-image/test.sh +++ b/tests/fuzz-tests/002-simple-image/test.sh @@ -2,7 +2,7 @@ # iterate over all fuzzed images and run 'btrfs-image' -source $TOP/tests/common +source "$TEST_TOP/common" setup_root_helper check_prereq btrfs-image @@ -17,7 +17,7 @@ check_image() { truncate -s0 target } -check_all_images $TOP/tests/fuzz-tests/images +check_all_images $TEST_TOP/fuzz-tests/images rm -- target diff --git a/tests/fuzz-tests/003-multi-check-unmounted/test.sh b/tests/fuzz-tests/003-multi-check-unmounted/test.sh index 9fd7b8aa..35dfe4fc 100755 --- a/tests/fuzz-tests/003-multi-check-unmounted/test.sh +++ b/tests/fuzz-tests/003-multi-check-unmounted/test.sh @@ -3,7 +3,7 @@ # iterate over all fuzzed images and run 'btrfs check', try various options to # get more code coverage -source $TOP/tests/common +source "$TEST_TOP/common" setup_root_helper check_prereq btrfs @@ -21,6 +21,6 @@ check_image() { run_mayfail $TOP/btrfs check --repair "$image" } -check_all_images $TOP/tests/fuzz-tests/images +check_all_images $TEST_TOP/fuzz-tests/images exit 0 diff --git a/tests/fuzz-tests/004-simple-dump-tree/test.sh b/tests/fuzz-tests/004-simple-dump-tree/test.sh index 89ff214c..6c9e8c45 100755 --- a/tests/fuzz-tests/004-simple-dump-tree/test.sh +++ b/tests/fuzz-tests/004-simple-dump-tree/test.sh @@ -1,6 +1,6 @@ #!/bin/bash -source $TOP/tests/common +source "$TEST_TOP/common" setup_root_helper check_prereq btrfs @@ -13,6 +13,6 @@ check_image() { run_mayfail $TOP/btrfs inspect-internal dump-tree "$image" } -check_all_images $TOP/tests/fuzz-tests/images +check_all_images $TEST_TOP/fuzz-tests/images exit 0 diff --git a/tests/fuzz-tests/005-simple-dump-super/test.sh b/tests/fuzz-tests/005-simple-dump-super/test.sh index fbce3d9f..01c7b628 100755 --- a/tests/fuzz-tests/005-simple-dump-super/test.sh +++ b/tests/fuzz-tests/005-simple-dump-super/test.sh @@ -1,6 +1,6 @@ #!/bin/bash -source $TOP/tests/common +source "$TEST_TOP/common" setup_root_helper check_prereq btrfs @@ -14,6 +14,6 @@ check_image() { run_mayfail $TOP/btrfs inspect-internal dump-super -Ffa "$image" } -check_all_images $TOP/tests/fuzz-tests/images +check_all_images $TEST_TOP/fuzz-tests/images exit 0 diff --git a/tests/fuzz-tests/006-simple-tree-stats/test.sh b/tests/fuzz-tests/006-simple-tree-stats/test.sh index c3410b06..dbed471a 100755 --- a/tests/fuzz-tests/006-simple-tree-stats/test.sh +++ b/tests/fuzz-tests/006-simple-tree-stats/test.sh @@ -1,6 +1,6 @@ #!/bin/bash -source $TOP/tests/common +source "$TEST_TOP/common" setup_root_helper check_prereq btrfs @@ -13,6 +13,6 @@ check_image() { run_mayfail $TOP/btrfs inspect-internal tree-stats "$image" } -check_all_images $TOP/tests/fuzz-tests/images +check_all_images $TEST_TOP/fuzz-tests/images exit 0 diff --git a/tests/fuzz-tests/007-simple-super-recover/test.sh b/tests/fuzz-tests/007-simple-super-recover/test.sh index 885cb352..ceb16348 100755 --- a/tests/fuzz-tests/007-simple-super-recover/test.sh +++ b/tests/fuzz-tests/007-simple-super-recover/test.sh @@ -1,6 +1,6 @@ #!/bin/bash -source $TOP/tests/common +source "$TEST_TOP/common" setup_root_helper check_prereq btrfs @@ -15,6 +15,6 @@ check_image() { rm -- "$image".scratch } -check_all_images $TOP/tests/fuzz-tests/images +check_all_images $TEST_TOP/fuzz-tests/images exit 0 diff --git a/tests/fuzz-tests/008-simple-chunk-recover/test.sh b/tests/fuzz-tests/008-simple-chunk-recover/test.sh index d53453f6..198f88e2 100755 --- a/tests/fuzz-tests/008-simple-chunk-recover/test.sh +++ b/tests/fuzz-tests/008-simple-chunk-recover/test.sh @@ -1,6 +1,6 @@ #!/bin/bash -source $TOP/tests/common +source "$TEST_TOP/common" setup_root_helper check_prereq btrfs @@ -15,6 +15,6 @@ check_image() { rm -- "$image".scratch } -check_all_images $TOP/tests/fuzz-tests/images +check_all_images $TEST_TOP/fuzz-tests/images exit 0 diff --git a/tests/fuzz-tests/009-simple-zero-log/test.sh b/tests/fuzz-tests/009-simple-zero-log/test.sh index 393db3f6..928c66b1 100755 --- a/tests/fuzz-tests/009-simple-zero-log/test.sh +++ b/tests/fuzz-tests/009-simple-zero-log/test.sh @@ -1,6 +1,6 @@ #!/bin/bash -source $TOP/tests/common +source "$TEST_TOP/common" setup_root_helper check_prereq btrfs @@ -15,6 +15,6 @@ check_image() { rm -- "$image".scratch } -check_all_images $TOP/tests/fuzz-tests/images +check_all_images $TEST_TOP/fuzz-tests/images exit 0 diff --git a/tests/misc-tests.sh b/tests/misc-tests.sh index 08988016..fed1b36c 100755 --- a/tests/misc-tests.sh +++ b/tests/misc-tests.sh @@ -4,13 +4,20 @@ LANG=C SCRIPT_DIR=$(dirname $(readlink -f "$0")) +TEST_TOP=$(readlink -f "$SCRIPT_DIR/../tests/") +INTERNAL_BIN=$(readlink -f "$SCRIPT_DIR/../") TOP=$(readlink -f "$SCRIPT_DIR/../") +if ! [ -f "$TOP/btrfs" ];then + TOP=$(dirname `which btrfs`) +fi TEST_DEV=${TEST_DEV:-} -RESULTS="$TOP/tests/misc-tests-results.txt" -IMAGE="$TOP/tests/test.img" +RESULTS="$TEST_TOP/misc-tests-results.txt" +IMAGE="$TEST_TOP/test.img" -source "$TOP/tests/common" +source "$TEST_TOP/common" +export INTERNAL_BIN +export TEST_TOP export TOP export RESULTS export LANG @@ -31,7 +38,7 @@ check_kernel_support # The tests are driven by their custom script called 'test.sh' -for i in $(find "$TOP/tests/misc-tests" -maxdepth 1 -mindepth 1 -type d \ +for i in $(find "$TEST_TOP/misc-tests" -maxdepth 1 -mindepth 1 -type d \ ${TEST:+-name "$TEST"} | sort) do echo " [TEST/misc] $(basename $i)" @@ -46,5 +53,5 @@ do _fail "test failed for case $(basename $i)" fi fi - cd "$TOP" + cd "$TEST_TOP" done diff --git a/tests/misc-tests/001-btrfstune-features/test.sh b/tests/misc-tests/001-btrfstune-features/test.sh index bfa7f43e..718e4b08 100755 --- a/tests/misc-tests/001-btrfstune-features/test.sh +++ b/tests/misc-tests/001-btrfstune-features/test.sh @@ -1,7 +1,7 @@ #!/bin/bash # test btrfstune options that enable filesystem features -source $TOP/tests/common +source "$TEST_TOP/common" check_prereq mkfs.btrfs check_prereq btrfstune diff --git a/tests/misc-tests/002-uuid-rewrite/test.sh b/tests/misc-tests/002-uuid-rewrite/test.sh index fd100fb3..e32aff0c 100755 --- a/tests/misc-tests/002-uuid-rewrite/test.sh +++ b/tests/misc-tests/002-uuid-rewrite/test.sh @@ -1,7 +1,7 @@ #!/bin/bash # test btrfstune uuid rewriting options -source $TOP/tests/common +source "$TEST_TOP/common" check_prereq mkfs.btrfs check_prereq btrfstune @@ -25,7 +25,7 @@ test_uuid_random() run_check $SUDO_HELPER $TOP/mkfs.btrfs -f \ --uuid $origuuid \ - --rootdir $TOP/Documentation \ + --rootdir $INTERNAL_BIN/Documentation \ $TEST_DEV run_check $TOP/btrfs inspect-internal dump-super "$TEST_DEV" currentfsid=$(run_check_stdout $TOP/btrfstune -f -u $TEST_DEV | \ @@ -47,7 +47,7 @@ test_uuid_user() run_check $SUDO_HELPER $TOP/mkfs.btrfs -f \ --uuid $origuuid \ - --rootdir $TOP/Documentation \ + --rootdir $INTERNAL_BIN/Documentation \ $TEST_DEV run_check $TOP/btrfs inspect-internal dump-super "$TEST_DEV" run_check $TOP/btrfstune -f -U $newuuid \ diff --git a/tests/misc-tests/003-zero-log/test.sh b/tests/misc-tests/003-zero-log/test.sh index e7c5c806..9d2940f5 100755 --- a/tests/misc-tests/003-zero-log/test.sh +++ b/tests/misc-tests/003-zero-log/test.sh @@ -1,7 +1,7 @@ #!/bin/bash # test zero-log -source $TOP/tests/common +source "$TEST_TOP/common" check_prereq mkfs.btrfs check_prereq btrfs @@ -27,7 +27,7 @@ test_zero_log() { # FIXME: we need an image with existing log_root run_check $SUDO_HELPER $TOP/mkfs.btrfs -f \ - --rootdir $TOP/Documentation \ + --rootdir $INTERNAL_BIN/Documentation \ $TEST_DEV run_check $TOP/btrfs inspect-internal dump-super $TEST_DEV if [ "$1" = 'standalone' ]; then diff --git a/tests/misc-tests/004-shrink-fs/test.sh b/tests/misc-tests/004-shrink-fs/test.sh index 88740358..2f08b0b0 100755 --- a/tests/misc-tests/004-shrink-fs/test.sh +++ b/tests/misc-tests/004-shrink-fs/test.sh @@ -4,7 +4,7 @@ # are able to resize (shrink) it to that size. # -source $TOP/tests/common +source "$TEST_TOP/common" check_prereq mkfs.btrfs check_prereq btrfs diff --git a/tests/misc-tests/005-convert-progress-thread-crash/test.sh b/tests/misc-tests/005-convert-progress-thread-crash/test.sh index bc71e1fd..b8012c9f 100755 --- a/tests/misc-tests/005-convert-progress-thread-crash/test.sh +++ b/tests/misc-tests/005-convert-progress-thread-crash/test.sh @@ -1,7 +1,7 @@ #!/bin/bash # test convert-thread-conflict -source $TOP/tests/common +source "$TEST_TOP/common" check_prereq btrfs-convert diff --git a/tests/misc-tests/006-image-on-missing-device/test.sh b/tests/misc-tests/006-image-on-missing-device/test.sh index 2766fb17..d8b1cef2 100755 --- a/tests/misc-tests/006-image-on-missing-device/test.sh +++ b/tests/misc-tests/006-image-on-missing-device/test.sh @@ -4,7 +4,7 @@ # - btrfs-image must not loop indefinetelly # - btrfs-image will expectedly fail to produce the dump -source $TOP/tests/common +source "$TEST_TOP/common" check_prereq btrfs-image check_prereq mkfs.btrfs diff --git a/tests/misc-tests/007-subvolume-sync/test.sh b/tests/misc-tests/007-subvolume-sync/test.sh index 243bb8cc..ef03d16b 100755 --- a/tests/misc-tests/007-subvolume-sync/test.sh +++ b/tests/misc-tests/007-subvolume-sync/test.sh @@ -4,7 +4,7 @@ # - btrfs subvolume must not loop indefinitely # - btrfs subvolume return 0 in normal case -source $TOP/tests/common +source "$TEST_TOP/common" check_prereq mkfs.btrfs check_prereq btrfs diff --git a/tests/misc-tests/008-leaf-crossing-stripes/test.sh b/tests/misc-tests/008-leaf-crossing-stripes/test.sh index 03818062..517bd667 100755 --- a/tests/misc-tests/008-leaf-crossing-stripes/test.sh +++ b/tests/misc-tests/008-leaf-crossing-stripes/test.sh @@ -1,7 +1,7 @@ #!/bin/bash # test if btrfs-convert creates a filesystem without leaf crossing stripes -source $TOP/tests/common +source "$TEST_TOP/common" check_prereq btrfs-convert check_prereq btrfs diff --git a/tests/misc-tests/009-subvolume-sync-must-wait/test.sh b/tests/misc-tests/009-subvolume-sync-must-wait/test.sh index fa3f09ab..15de3355 100755 --- a/tests/misc-tests/009-subvolume-sync-must-wait/test.sh +++ b/tests/misc-tests/009-subvolume-sync-must-wait/test.sh @@ -2,7 +2,7 @@ # # Verify that subvolume sync waits until the subvolume is cleaned -source $TOP/tests/common +source "$TEST_TOP/common" check_prereq mkfs.btrfs check_prereq btrfs diff --git a/tests/misc-tests/010-convert-delete-ext2-subvol/test.sh b/tests/misc-tests/010-convert-delete-ext2-subvol/test.sh index 7915867c..6d510fea 100755 --- a/tests/misc-tests/010-convert-delete-ext2-subvol/test.sh +++ b/tests/misc-tests/010-convert-delete-ext2-subvol/test.sh @@ -3,7 +3,7 @@ # verify that convert rollback finds the ext2_subvolume intact and fails if it # was partially deleted -source $TOP/tests/common +source "$TEST_TOP/common" check_prereq btrfs-convert check_prereq btrfs diff --git a/tests/misc-tests/011-delete-missing-device/test.sh b/tests/misc-tests/011-delete-missing-device/test.sh index 8a1b14b1..469c3be9 100755 --- a/tests/misc-tests/011-delete-missing-device/test.sh +++ b/tests/misc-tests/011-delete-missing-device/test.sh @@ -1,7 +1,7 @@ #!/bin/bash # make sure that 'missing' is accepted for device deletion -source $TOP/tests/common +source "$TEST_TOP/common" check_prereq mkfs.btrfs check_prereq btrfs diff --git a/tests/misc-tests/012-find-root-no-result/test.sh b/tests/misc-tests/012-find-root-no-result/test.sh index 983a8a1e..f4a57e76 100755 --- a/tests/misc-tests/012-find-root-no-result/test.sh +++ b/tests/misc-tests/012-find-root-no-result/test.sh @@ -3,7 +3,7 @@ # recent fs or balanced fs, whose metadata chunk is the first chunk # and the only metadata chunk -source $TOP/tests/common +source "$TEST_TOP/common" check_prereq btrfs-find-root check_prereq btrfs-image diff --git a/tests/misc-tests/013-subvolume-sync-crash/test.sh b/tests/misc-tests/013-subvolume-sync-crash/test.sh index cd445961..051b457a 100755 --- a/tests/misc-tests/013-subvolume-sync-crash/test.sh +++ b/tests/misc-tests/013-subvolume-sync-crash/test.sh @@ -3,7 +3,7 @@ # Verify that subvolume sync waits until the subvolume is cleaned and does not # crash at the end -source $TOP/tests/common +source "$TEST_TOP/common" check_prereq mkfs.btrfs check_prereq btrfs diff --git a/tests/misc-tests/014-filesystem-label/test.sh b/tests/misc-tests/014-filesystem-label/test.sh index 753aa9ea..bd6773cb 100755 --- a/tests/misc-tests/014-filesystem-label/test.sh +++ b/tests/misc-tests/014-filesystem-label/test.sh @@ -2,7 +2,7 @@ # # test label settings -source $TOP/tests/common +source "$TEST_TOP/common" check_prereq mkfs.btrfs check_prereq btrfs diff --git a/tests/misc-tests/015-dump-super-garbage/test.sh b/tests/misc-tests/015-dump-super-garbage/test.sh index 33fc8332..10d8d5b6 100755 --- a/tests/misc-tests/015-dump-super-garbage/test.sh +++ b/tests/misc-tests/015-dump-super-garbage/test.sh @@ -2,7 +2,7 @@ # # let dump-super dump random data, must not crash -source $TOP/tests/common +source "$TEST_TOP/common" check_prereq btrfs diff --git a/tests/misc-tests/016-send-clone-src/test.sh b/tests/misc-tests/016-send-clone-src/test.sh index 2780ebbd..e4fa16a7 100755 --- a/tests/misc-tests/016-send-clone-src/test.sh +++ b/tests/misc-tests/016-send-clone-src/test.sh @@ -3,7 +3,7 @@ # test for sending stream size of clone-src option, compare against a send # stream generated by buggy version -source $TOP/tests/common +source "$TEST_TOP/common" check_prereq mkfs.btrfs check_prereq btrfs diff --git a/tests/misc-tests/017-recv-stream-malformatted/test.sh b/tests/misc-tests/017-recv-stream-malformatted/test.sh index d199a72e..991f2569 100755 --- a/tests/misc-tests/017-recv-stream-malformatted/test.sh +++ b/tests/misc-tests/017-recv-stream-malformatted/test.sh @@ -2,7 +2,7 @@ # # test receiving stream that's not valid, simple cases -source $TOP/tests/common +source "$TEST_TOP/common" check_prereq mkfs.btrfs check_prereq btrfs diff --git a/tests/misc-tests/018-recv-end-of-stream/test.sh b/tests/misc-tests/018-recv-end-of-stream/test.sh index 9ca035f7..79e735ea 100755 --- a/tests/misc-tests/018-recv-end-of-stream/test.sh +++ b/tests/misc-tests/018-recv-end-of-stream/test.sh @@ -3,7 +3,7 @@ # end of stream conditions: test that no instructions in a stream are still # received, at least the header must be present -source $TOP/tests/common +source "$TEST_TOP/common" check_prereq mkfs.btrfs check_prereq btrfs diff --git a/tests/misc-tests/019-receive-clones-on-mounted-subvol/test.sh b/tests/misc-tests/019-receive-clones-on-mounted-subvol/test.sh index 182b0cf9..60ec5cf9 100755 --- a/tests/misc-tests/019-receive-clones-on-mounted-subvol/test.sh +++ b/tests/misc-tests/019-receive-clones-on-mounted-subvol/test.sh @@ -5,7 +5,7 @@ # have an entry with the same name that corresponds to different inodes in each # snapshot. -source $TOP/tests/common +source "$TEST_TOP/common" check_prereq mkfs.btrfs check_prereq btrfs @@ -14,7 +14,7 @@ check_prereq fssum setup_root_helper prepare_test_dev -FSSUM_PROG="$TOP/fssum" +FSSUM_PROG="$INTERNAL_BIN/fssum" srcdir=./send-test-dir rm -rf "$srcdir" mkdir -p "$srcdir" diff --git a/tests/misc-tests/020-fix-superblock-corruption/test.sh b/tests/misc-tests/020-fix-superblock-corruption/test.sh index 77c1a5aa..8f3d20fe 100755 --- a/tests/misc-tests/020-fix-superblock-corruption/test.sh +++ b/tests/misc-tests/020-fix-superblock-corruption/test.sh @@ -2,7 +2,7 @@ # # Corrupt primary superblock and restore it using backup superblock. -source "$TOP/tests/common" +source "$TEST_TOP/common" check_prereq btrfs-select-super check_prereq btrfs diff --git a/tests/misc-tests/021-image-multi-devices/test.sh b/tests/misc-tests/021-image-multi-devices/test.sh index abf67f90..d78c44fb 100755 --- a/tests/misc-tests/021-image-multi-devices/test.sh +++ b/tests/misc-tests/021-image-multi-devices/test.sh @@ -2,7 +2,7 @@ # Test btrfs-image with multiple devices filesystem and verify that restoring # the created image works against a single device. -source "$TOP/tests/common" +source "$TEST_TOP/common" check_prereq btrfs-image check_prereq mkfs.btrfs diff --git a/tests/misc-tests/022-filesystem-du-on-empty-subvol/test.sh b/tests/misc-tests/022-filesystem-du-on-empty-subvol/test.sh index 72cf076f..54365289 100755 --- a/tests/misc-tests/022-filesystem-du-on-empty-subvol/test.sh +++ b/tests/misc-tests/022-filesystem-du-on-empty-subvol/test.sh @@ -2,7 +2,7 @@ # # btrfs fi du should handle empty subvolumes (with ino == 2) -source "$TOP/tests/common" +source "$TEST_TOP/common" check_prereq mkfs.btrfs check_prereq btrfs diff --git a/tests/misc-tests/023-device-usage-with-missing-device/test.sh b/tests/misc-tests/023-device-usage-with-missing-device/test.sh index 3c8ba85c..05894cfe 100755 --- a/tests/misc-tests/023-device-usage-with-missing-device/test.sh +++ b/tests/misc-tests/023-device-usage-with-missing-device/test.sh @@ -1,7 +1,7 @@ #!/bin/bash # check if 'device slack' is reported as zero when a device is missing -source "$TOP/tests/common" +source "$TEST_TOP/common" check_prereq btrfs-image check_prereq mkfs.btrfs diff --git a/tests/misc-tests/024-inspect-internal-rootid/test.sh b/tests/misc-tests/024-inspect-internal-rootid/test.sh index 40e382bb..71e19044 100755 --- a/tests/misc-tests/024-inspect-internal-rootid/test.sh +++ b/tests/misc-tests/024-inspect-internal-rootid/test.sh @@ -2,7 +2,7 @@ # # test commands of inspect-internal rootid -source "$TOP/tests/common" +source "$TEST_TOP/common" check_prereq mkfs.btrfs check_prereq btrfs diff --git a/tests/misc-tests/025-zstd-compression/test.sh b/tests/misc-tests/025-zstd-compression/test.sh index e95dcb36..22795d27 100755 --- a/tests/misc-tests/025-zstd-compression/test.sh +++ b/tests/misc-tests/025-zstd-compression/test.sh @@ -1,7 +1,7 @@ #!/bin/bash # Test zstd compression support on a prebuilt btrfs image -source "$TOP/tests/common" +source "$TEST_TOP/common" check_prereq btrfs check_global_prereq md5sum diff --git a/tests/misc-tests/026-image-non-printable-chars/test.sh b/tests/misc-tests/026-image-non-printable-chars/test.sh index 8018586f..50441a21 100755 --- a/tests/misc-tests/026-image-non-printable-chars/test.sh +++ b/tests/misc-tests/026-image-non-printable-chars/test.sh @@ -2,7 +2,7 @@ # check that sanitized names with matching crc do not contain unprintable # characters, namely 0x7f -source "$TOP/tests/common" +source "$TEST_TOP/common" check_prereq mkfs.btrfs check_prereq btrfs diff --git a/tests/misc-tests/027-subvol-list-deleted-toplevel/test.sh b/tests/misc-tests/027-subvol-list-deleted-toplevel/test.sh index ee41d71f..3b73dd36 100755 --- a/tests/misc-tests/027-subvol-list-deleted-toplevel/test.sh +++ b/tests/misc-tests/027-subvol-list-deleted-toplevel/test.sh @@ -1,7 +1,7 @@ #!/bin/bash # check that the toplevel subvolume is not listed as regular or deleted -source "$TOP/tests/common" +source "$TEST_TOP/common" check_prereq mkfs.btrfs check_prereq btrfs diff --git a/tests/mkfs-tests.sh b/tests/mkfs-tests.sh index c8ff8c83..1a84b37c 100755 --- a/tests/mkfs-tests.sh +++ b/tests/mkfs-tests.sh @@ -4,13 +4,20 @@ LANG=C SCRIPT_DIR=$(dirname $(readlink -f "$0")) +INTERNAL_BIN=$(readlink -f "$SCRIPT_DIR/../") +TEST_TOP=$(readlink -f "$SCRIPT_DIR/../tests/") TOP=$(readlink -f "$SCRIPT_DIR/../") +if ! [ -f "$TOP/btrfs" ];then + TOP=$(dirname `which btrfs`) +fi TEST_DEV=${TEST_DEV:-} -RESULTS="$TOP/tests/mkfs-tests-results.txt" -IMAGE="$TOP/tests/test.img" +RESULTS="$TEST_TOP/mkfs-tests-results.txt" +IMAGE="$TEST_TOP/test.img" -source "$TOP/tests/common" +source "$TEST_TOP/common" +export INTERNAL_BIN +export TEST_TOP export TOP export RESULTS export LANG @@ -25,7 +32,7 @@ check_kernel_support # The tests are driven by their custom script called 'test.sh' -for i in $(find "$TOP/tests/mkfs-tests" -maxdepth 1 -mindepth 1 -type d \ +for i in $(find "$TEST_TOP/mkfs-tests" -maxdepth 1 -mindepth 1 -type d \ ${TEST:+-name "$TEST"} | sort) do echo " [TEST/mkfs] $(basename $i)" @@ -40,5 +47,5 @@ do _fail "test failed for case $(basename $i)" fi fi - cd "$TOP" + cd "$TEST_TOP" done diff --git a/tests/mkfs-tests/001-basic-profiles/test.sh b/tests/mkfs-tests/001-basic-profiles/test.sh index 854ee007..b84016f7 100755 --- a/tests/mkfs-tests/001-basic-profiles/test.sh +++ b/tests/mkfs-tests/001-basic-profiles/test.sh @@ -2,7 +2,7 @@ # test various blockgroup profile combinations, use loop devices as block # devices -source $TOP/tests/common +source "$TEST_TOP/common" check_prereq mkfs.btrfs check_prereq btrfs diff --git a/tests/mkfs-tests/002-no-force-mixed-on-small-volume/test.sh b/tests/mkfs-tests/002-no-force-mixed-on-small-volume/test.sh index 37846234..4bc9c262 100755 --- a/tests/mkfs-tests/002-no-force-mixed-on-small-volume/test.sh +++ b/tests/mkfs-tests/002-no-force-mixed-on-small-volume/test.sh @@ -2,7 +2,7 @@ # # Verify that we do not force mixed block groups on small volumes anymore -source $TOP/tests/common +source "$TEST_TOP/common" check_prereq mkfs.btrfs diff --git a/tests/mkfs-tests/003-mixed-with-wrong-nodesize/test.sh b/tests/mkfs-tests/003-mixed-with-wrong-nodesize/test.sh index 074fc22e..f5327338 100755 --- a/tests/mkfs-tests/003-mixed-with-wrong-nodesize/test.sh +++ b/tests/mkfs-tests/003-mixed-with-wrong-nodesize/test.sh @@ -2,7 +2,7 @@ # # Mixed mode needs equal sectorsize and nodesize -source $TOP/tests/common +source "$TEST_TOP/common" check_prereq mkfs.btrfs diff --git a/tests/mkfs-tests/004-rootdir-keeps-size/test.sh b/tests/mkfs-tests/004-rootdir-keeps-size/test.sh index 7038c8ea..4a84e6db 100755 --- a/tests/mkfs-tests/004-rootdir-keeps-size/test.sh +++ b/tests/mkfs-tests/004-rootdir-keeps-size/test.sh @@ -1,7 +1,7 @@ #!/bin/bash # make sure that mkfs.btrfs --rootsize does not change size of the image -source $TOP/tests/common +source "$TEST_TOP/common" check_prereq mkfs.btrfs @@ -16,7 +16,7 @@ test_mkfs_with_size() { run_check truncate -s$size $TEST_DEV imgsize=$(run_check_stdout stat --format=%s $TEST_DEV) run_check $SUDO_HELPER $TOP/mkfs.btrfs -f \ - --rootdir $TOP/Documentation \ + --rootdir $INTERNAL_BIN/Documentation \ $TEST_DEV tmp=$(run_check_stdout stat --format=%s $TEST_DEV) if ! [ "$imgsize" = "$tmp" ]; then diff --git a/tests/mkfs-tests/005-long-device-name-for-ssd/test.sh b/tests/mkfs-tests/005-long-device-name-for-ssd/test.sh index 5bdf50e0..55ce676e 100755 --- a/tests/mkfs-tests/005-long-device-name-for-ssd/test.sh +++ b/tests/mkfs-tests/005-long-device-name-for-ssd/test.sh @@ -1,7 +1,7 @@ #!/bin/bash # a long device name must pass the SSD test -source $TOP/tests/common +source "$TEST_TOP/common" check_prereq mkfs.btrfs diff --git a/tests/mkfs-tests/006-partitioned-loopdev/test.sh b/tests/mkfs-tests/006-partitioned-loopdev/test.sh index 0c77e5cd..06c254fd 100755 --- a/tests/mkfs-tests/006-partitioned-loopdev/test.sh +++ b/tests/mkfs-tests/006-partitioned-loopdev/test.sh @@ -1,7 +1,7 @@ #!/bin/bash # recognize partitioned loop devices -source $TOP/tests/common +source "$TEST_TOP/common" if ! losetup --help | grep -q 'partscan'; then _not_run "losetup --partscan not available" diff --git a/tests/mkfs-tests/007-mix-nodesize-sectorsize/test.sh b/tests/mkfs-tests/007-mix-nodesize-sectorsize/test.sh index 3980414f..f7e88c9a 100755 --- a/tests/mkfs-tests/007-mix-nodesize-sectorsize/test.sh +++ b/tests/mkfs-tests/007-mix-nodesize-sectorsize/test.sh @@ -1,7 +1,7 @@ #!/bin/bash # iterate over nodesize and sectorsize combinations -source $TOP/tests/common +source "$TEST_TOP/common" check_prereq mkfs.btrfs check_prereq btrfs diff --git a/tests/mkfs-tests/008-sectorsize-nodesize-combination/test.sh b/tests/mkfs-tests/008-sectorsize-nodesize-combination/test.sh index 955cd2b1..9cc2f9e0 100755 --- a/tests/mkfs-tests/008-sectorsize-nodesize-combination/test.sh +++ b/tests/mkfs-tests/008-sectorsize-nodesize-combination/test.sh @@ -4,7 +4,7 @@ # only do mkfs and fsck check, no mounting as # sub/multi-pagesize is not supported yet -source $TOP/tests/common +source "$TEST_TOP/common" check_prereq mkfs.btrfs check_prereq btrfs diff --git a/tests/mkfs-tests/009-special-files-for-rootdir/test.sh b/tests/mkfs-tests/009-special-files-for-rootdir/test.sh index d327a0d9..a94d5209 100755 --- a/tests/mkfs-tests/009-special-files-for-rootdir/test.sh +++ b/tests/mkfs-tests/009-special-files-for-rootdir/test.sh @@ -6,7 +6,7 @@ # # Note: sock type is skipped in this test -source "$TOP/tests/common" +source "$TEST_TOP/common" check_prereq mkfs.btrfs check_prereq btrfs -- cgit v1.2.3 From dd11901dae6c11387ffce0c769718b22ca8128f0 Mon Sep 17 00:00:00 2001 From: David Sterba Date: Thu, 8 Feb 2018 17:40:34 +0100 Subject: btrfs-progs: tests: update README.md Irregular proofreading with adjustments and enhancements. Signed-off-by: David Sterba --- tests/README.md | 57 +++++++++++++++++++++++++++++++++------------------------ 1 file changed, 33 insertions(+), 24 deletions(-) (limited to 'tests') diff --git a/tests/README.md b/tests/README.md index c4560185..c6d89a5c 100644 --- a/tests/README.md +++ b/tests/README.md @@ -45,46 +45,51 @@ $ make TEST=001\* test-fsck $ TEST=001\* ./fsck-tests.sh ``` -will run the first test in fsck-tests subdirectory. +will run the first test in fsck-tests subdirectory. If the test directories +follow a good naming scheme, it's possible to select a subset eg. like the +convert tests for ext[234] filesystems. ## Test structure -*tests/fsck-tests/:* +*tests/fsck-tests/* - * tests targeted at bugs that are fixable by fsck + * tests targeted at bugs that are fixable by fsck, the test directory can + contain images that will get fixed, or a custom script `./test.sh` that + will be run if present -*tests/convert-tests/:* +*tests/convert-tests/* - * coverage tests of ext2/3/4 and btrfs-convert options + * coverage tests of ext2/3/4 or reiserfs and btrfs-convert options -*tests/fuzz-tests/:* +*tests/fuzz-tests/* * collection of fuzzed or crafted images * tests that are supposed to run various utilities on the images and not crash -*tests/cli-tests/:* +*tests/cli-tests/* * tests for command line interface, option coverage, weird option combinations that should not work * not necessary to do any functional testing, could be rather lightweight * functional tests should go to to other test dirs * the driver script will only execute `./test.sh` in the test directory -*tests/misc-tests/:* +*tests/misc-tests/* * anything that does not fit to the above, the test driver script will only execute `./test.sh` in the test directory -*tests/common, tests/common.convert:* +*tests/common, tests/common.convert* - * script with shell helpers, separated by functionality + * scripts with shell helpers, separated by functionality -*tests/test.img:* +*tests/test.img* - * default testing image, the file is never deleted by the scripts but - truncated to 0 bytes, so it keeps it's permissions. It's eg. possible to - host it on NFS, make it `chmod a+w` for root. + * default testing image, available as `TEST_DEV` variable, the file is never + deleted by the scripts but truncated to 0 bytes, so it keeps it's + permissions. It's eg. possible to host it on NFS, make it `chmod a+w` for + root. ## Other tuning, environment variables @@ -125,10 +130,10 @@ Multiple values can be separated by `,`. ### Permissions -Some commands require root privileges (to mount/umount, access loop devices). -It is assumed that `sudo` will work in some way (no password, password asked -and cached). Note that instrumentation is not applied in this case, for safety -reasons. You need to modify the test script instead. +Some commands require root privileges (to mount/umount, access loop devices or +call privileged ioctls). It is assumed that `sudo` will work in some way (no +password, password asked and cached). Note that instrumentation is not applied +in this case, for safety reasons. You need to modify the test script instead. ### Cleanup @@ -143,13 +148,14 @@ the loop devices as they are managed on a per-test basis. ### Prototyping tests, quick tests There's a script `test-console.sh` that will run shell commands in a loop and -logs the output with the testing environment set up. +logs the output with the testing environment set up. It sources the common +helper scripts so the shell functions are available. ### Runtime dependencies The tests use some common system utilities like `find`, `rm`, `dd`. Additionally, specific tests need the following packages installed: `acl`, `attr`, -`e2fsprogs`, `reiserfsprogs` +`e2fsprogs`, `reiserfsprogs`. ## New test @@ -158,7 +164,7 @@ specific tests need the following packages installed: `acl`, `attr`, an easy start copy an existing `test.sh` script from some test that might be close to the purpose of your new test. The environment setup includes the common scripts and/or prepares the test devices. Other scripts contain examples -how to do mkfs, mount, unmount, check, etc. +how to do mkfs, mount, unmount, check, loop device management etc. 2. Use the highest unused number in the sequence, write a short descriptive title and join by dashes `-`. This will become the directory name, eg. `012-subvolume-sync-must-wait`. @@ -180,10 +186,12 @@ $ TEST=012\* ./misc-tests.sh # from tests/ fixed the bug (or both). Subject line of the shall mention the name of the new directory for ease of search, eg. `btrfs-progs: tests: add 012-subvolume-sync-must-wait` +7. A commit that fixes a bug should be applied before the test that verifies + the fix. This is to keep the git history bisectable. ### Crafted/fuzzed images -Images that are create by fuzzing or specially crafted to trigger some error +Images that are created by fuzzing or specially crafted to trigger some error conditions should be added to the directory *fuzz-tests/images*, accompanied by a textual description of the source (bugzilla, mail), the reporter, brief description of the problem or the stack trace. @@ -208,8 +216,9 @@ bisectability. always built when the tests are started through make * use functions instead of repeating code * generic helpers could be factored to the `common` script -* cleanup after successful test -* use common helpers and variables +* cleanup files an intermediate state (mount, loop devices, device mapper + devices) a after successful test +* use common helpers and variables where possible ## do not -- cgit v1.2.3 From e44f595dd7dd2372954595cb9231c36e04cafc73 Mon Sep 17 00:00:00 2001 From: David Sterba Date: Thu, 8 Feb 2018 18:34:40 +0100 Subject: btrfs-progs: tests: unify test drivers, make ready for extenral testsuite Make the TOP variable more configurable, allow to set it to any path where to find binaries when the testsuite is exported, or fallback to system binaries. There's now more code duplication, the logic is now more complex so it's left open coded for clarity. Further cleanups are possible. Signed-off-by: David Sterba --- tests/clean-tests.sh | 29 +++++++++++++++++++++++++++-- tests/cli-tests.sh | 25 +++++++++++++++++++++---- tests/convert-tests.sh | 25 +++++++++++++++++++++---- tests/fsck-tests.sh | 25 ++++++++++++++++++++----- tests/fuzz-tests.sh | 25 +++++++++++++++++++++---- tests/misc-tests.sh | 27 +++++++++++++++++++++------ tests/mkfs-tests.sh | 25 ++++++++++++++++++++----- 7 files changed, 151 insertions(+), 30 deletions(-) (limited to 'tests') diff --git a/tests/clean-tests.sh b/tests/clean-tests.sh index 61baa069..f5f63092 100755 --- a/tests/clean-tests.sh +++ b/tests/clean-tests.sh @@ -1,9 +1,34 @@ #!/bin/bash # remove all intermediate files from tests +LANG=C SCRIPT_DIR=$(dirname $(readlink -f "$0")) -TOP=$(readlink -f "$SCRIPT_DIR/../") -source "$TOP/tests/common" +if [ -z "$TOP" ]; then + TOP=$(readlink -f "$SCRIPT_DIR/../") + if [ -f "$TOP/configure.ac" ]; then + # inside git + TEST_TOP="$TOP/tests/" + INTERNAL_BIN="$TOP" + else + # external, defaults to system binaries + TOP=$(dirname `which btrfs`) + TEST_TOP="$SCRIPT_DIR" + INTERNAL_BIN="$TEST_TOP" + fi +else + # assume external, TOP set from commandline + TEST_TOP="$SCRIPT_DIR" + INTERNAL_BIN="$TEST_TOP" +fi +if ! [ -x "$TOP/btrfs" ]; then + echo "ERROR: cannot execute btrfs from TOP=$TOP" + exit 1 +fi +TEST_DEV=${TEST_DEV:-} +RESULTS="$TEST_TOP/cli-tests-results.txt" +IMAGE="$TEST_TOP/test.img" + +source "$TEST_TOP/tests/common" setup_root_helper diff --git a/tests/cli-tests.sh b/tests/cli-tests.sh index b981f833..9e0fbae4 100755 --- a/tests/cli-tests.sh +++ b/tests/cli-tests.sh @@ -4,10 +4,26 @@ LANG=C SCRIPT_DIR=$(dirname $(readlink -f "$0")) -TEST_TOP=$(readlink -f "$SCRIPT_DIR/../tests/") -TOP=$(readlink -f "$SCRIPT_DIR/../") -if ! [ -f "$TOP/btrfs" ];then - TOP=$(dirname `which btrfs`) +if [ -z "$TOP" ]; then + TOP=$(readlink -f "$SCRIPT_DIR/../") + if [ -f "$TOP/configure.ac" ]; then + # inside git + TEST_TOP="$TOP/tests/" + INTERNAL_BIN="$TOP" + else + # external, defaults to system binaries + TOP=$(dirname `which btrfs`) + TEST_TOP="$SCRIPT_DIR" + INTERNAL_BIN="$TEST_TOP" + fi +else + # assume external, TOP set from commandline + TEST_TOP="$SCRIPT_DIR" + INTERNAL_BIN="$TEST_TOP" +fi +if ! [ -x "$TOP/btrfs" ]; then + echo "ERROR: cannot execute btrfs from TOP=$TOP" + exit 1 fi TEST_DEV=${TEST_DEV:-} RESULTS="$TEST_TOP/cli-tests-results.txt" @@ -15,6 +31,7 @@ IMAGE="$TEST_TOP/test.img" source "$TEST_TOP/common" +export INTERNAL_BIN export TEST_TOP export TOP export RESULTS diff --git a/tests/convert-tests.sh b/tests/convert-tests.sh index 52c59d4d..4bc915db 100755 --- a/tests/convert-tests.sh +++ b/tests/convert-tests.sh @@ -5,10 +5,26 @@ LANG=C SCRIPT_DIR=$(dirname $(readlink -f "$0")) -TEST_TOP=$(readlink -f "$SCRIPT_DIR/../tests/") -TOP=$(readlink -f "$SCRIPT_DIR/../") -if ! [ -f "$TOP/btrfs" ];then - TOP=$(dirname `which btrfs`) +if [ -z "$TOP" ]; then + TOP=$(readlink -f "$SCRIPT_DIR/../") + if [ -f "$TOP/configure.ac" ]; then + # inside git + TEST_TOP="$TOP/tests/" + INTERNAL_BIN="$TOP" + else + # external, defaults to system binaries + TOP=$(dirname `which btrfs`) + TEST_TOP="$SCRIPT_DIR" + INTERNAL_BIN="$TEST_TOP" + fi +else + # assume external, TOP set from commandline + TEST_TOP="$SCRIPT_DIR" + INTERNAL_BIN="$TEST_TOP" +fi +if ! [ -x "$TOP/btrfs" ]; then + echo "ERROR: cannot execute btrfs from TOP=$TOP" + exit 1 fi TEST_DEV=${TEST_DEV:-} RESULTS="$TEST_TOP/convert-tests-results.txt" @@ -17,6 +33,7 @@ IMAGE="$TEST_TOP/test.img" source "$TEST_TOP/common" source "$TEST_TOP/common.convert" +export INTERNAL_BIN export TEST_TOP export TOP export RESULTS diff --git a/tests/fsck-tests.sh b/tests/fsck-tests.sh index f97ae986..14287bbe 100755 --- a/tests/fsck-tests.sh +++ b/tests/fsck-tests.sh @@ -4,11 +4,26 @@ LANG=C SCRIPT_DIR=$(dirname $(readlink -f "$0")) -INTERNAL_BIN=$(readlink -f "$SCRIPT_DIR/../") -TEST_TOP=$(readlink -f "$SCRIPT_DIR/../tests/") -TOP=$(readlink -f "$SCRIPT_DIR/../") -if ! [ -f "$TOP/btrfs" ];then - TOP=$(dirname `which btrfs`) +if [ -z "$TOP" ]; then + TOP=$(readlink -f "$SCRIPT_DIR/../") + if [ -f "$TOP/configure.ac" ]; then + # inside git + TEST_TOP="$TOP/tests/" + INTERNAL_BIN="$TOP" + else + # external, defaults to system binaries + TOP=$(dirname `which btrfs`) + TEST_TOP="$SCRIPT_DIR" + INTERNAL_BIN="$TEST_TOP" + fi +else + # assume external, TOP set from commandline + TEST_TOP="$SCRIPT_DIR" + INTERNAL_BIN="$TEST_TOP" +fi +if ! [ -x "$TOP/btrfs" ]; then + echo "ERROR: cannot execute btrfs from TOP=$TOP" + exit 1 fi TEST_DEV=${TEST_DEV:-} RESULTS="$TEST_TOP/fsck-tests-results.txt" diff --git a/tests/fuzz-tests.sh b/tests/fuzz-tests.sh index dca84f10..7bc620f0 100755 --- a/tests/fuzz-tests.sh +++ b/tests/fuzz-tests.sh @@ -4,10 +4,26 @@ LANG=C SCRIPT_DIR=$(dirname $(readlink -f "$0")) -TEST_TOP=$(readlink -f "$SCRIPT_DIR/../tests/") -TOP=$(readlink -f "$SCRIPT_DIR/../") -if ! [ -f "$TOP/btrfs" ];then - TOP=$(dirname `which btrfs`) +if [ -z "$TOP" ]; then + TOP=$(readlink -f "$SCRIPT_DIR/../") + if [ -f "$TOP/configure.ac" ]; then + # inside git + TEST_TOP="$TOP/tests/" + INTERNAL_BIN="$TOP" + else + # external, defaults to system binaries + TOP=$(dirname `which btrfs`) + TEST_TOP="$SCRIPT_DIR" + INTERNAL_BIN="$TEST_TOP" + fi +else + # assume external, TOP set from commandline + TEST_TOP="$SCRIPT_DIR" + INTERNAL_BIN="$TEST_TOP" +fi +if ! [ -x "$TOP/btrfs" ]; then + echo "ERROR: cannot execute btrfs from TOP=$TOP" + exit 1 fi TEST_DEV=${TEST_DEV:-} RESULTS="$TEST_TOP/fuzz-tests-results.txt" @@ -15,6 +31,7 @@ IMAGE="$TEST_TOP/test.img" source "$TEST_TOP/common" +export INTERNAL_BIN export TEST_TOP export TOP export RESULTS diff --git a/tests/misc-tests.sh b/tests/misc-tests.sh index fed1b36c..94703a3e 100755 --- a/tests/misc-tests.sh +++ b/tests/misc-tests.sh @@ -4,11 +4,26 @@ LANG=C SCRIPT_DIR=$(dirname $(readlink -f "$0")) -TEST_TOP=$(readlink -f "$SCRIPT_DIR/../tests/") -INTERNAL_BIN=$(readlink -f "$SCRIPT_DIR/../") -TOP=$(readlink -f "$SCRIPT_DIR/../") -if ! [ -f "$TOP/btrfs" ];then - TOP=$(dirname `which btrfs`) +if [ -z "$TOP" ]; then + TOP=$(readlink -f "$SCRIPT_DIR/../") + if [ -f "$TOP/configure.ac" ]; then + # inside git + TEST_TOP="$TOP/tests/" + INTERNAL_BIN="$TOP" + else + # external, defaults to system binaries + TOP=$(dirname `which btrfs`) + TEST_TOP="$SCRIPT_DIR" + INTERNAL_BIN="$TEST_TOP" + fi +else + # assume external, TOP set from commandline + TEST_TOP="$SCRIPT_DIR" + INTERNAL_BIN="$TEST_TOP" +fi +if ! [ -x "$TOP/btrfs" ]; then + echo "ERROR: cannot execute btrfs from TOP=$TOP" + exit 1 fi TEST_DEV=${TEST_DEV:-} RESULTS="$TEST_TOP/misc-tests-results.txt" @@ -21,8 +36,8 @@ export TEST_TOP export TOP export RESULTS export LANG -export TEST_DEV export IMAGE +export TEST_DEV rm -f "$RESULTS" diff --git a/tests/mkfs-tests.sh b/tests/mkfs-tests.sh index 1a84b37c..2ced4ac9 100755 --- a/tests/mkfs-tests.sh +++ b/tests/mkfs-tests.sh @@ -4,11 +4,26 @@ LANG=C SCRIPT_DIR=$(dirname $(readlink -f "$0")) -INTERNAL_BIN=$(readlink -f "$SCRIPT_DIR/../") -TEST_TOP=$(readlink -f "$SCRIPT_DIR/../tests/") -TOP=$(readlink -f "$SCRIPT_DIR/../") -if ! [ -f "$TOP/btrfs" ];then - TOP=$(dirname `which btrfs`) +if [ -z "$TOP" ]; then + TOP=$(readlink -f "$SCRIPT_DIR/../") + if [ -f "$TOP/configure.ac" ]; then + # inside git + TEST_TOP="$TOP/tests/" + INTERNAL_BIN="$TOP" + else + # external, defaults to system binaries + TOP=$(dirname `which btrfs`) + TEST_TOP="$SCRIPT_DIR" + INTERNAL_BIN="$TEST_TOP" + fi +else + # assume external, TOP set from commandline + TEST_TOP="$SCRIPT_DIR" + INTERNAL_BIN="$TEST_TOP" +fi +if ! [ -x "$TOP/btrfs" ]; then + echo "ERROR: cannot execute btrfs from TOP=$TOP" + exit 1 fi TEST_DEV=${TEST_DEV:-} RESULTS="$TEST_TOP/mkfs-tests-results.txt" -- cgit v1.2.3 From dbb8c9d19e465e09603386c51b2bb32b72a1b009 Mon Sep 17 00:00:00 2001 From: David Sterba Date: Tue, 13 Feb 2018 16:21:20 +0100 Subject: btrfs-progs: test: update clean-test.sh after the TEST_TOP update Signed-off-by: David Sterba --- tests/clean-tests.sh | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) (limited to 'tests') diff --git a/tests/clean-tests.sh b/tests/clean-tests.sh index f5f63092..342616f7 100755 --- a/tests/clean-tests.sh +++ b/tests/clean-tests.sh @@ -28,7 +28,7 @@ TEST_DEV=${TEST_DEV:-} RESULTS="$TEST_TOP/cli-tests-results.txt" IMAGE="$TEST_TOP/test.img" -source "$TEST_TOP/tests/common" +source "$TEST_TOP/common" setup_root_helper @@ -38,8 +38,8 @@ fi $SUDO_HELPER umount "$TEST_MNT" &>/dev/null -if ! cd "$TOP/tests"; then - echo "ERROR: cannot cd to $TOP/tests" +if ! cd "$TEST_TOP"; then + echo "ERROR: cannot cd to $TEST_TOP" exit 1 fi -- cgit v1.2.3 From 9aa0c422b82c15fee1ac5cd3b0fae2ebe358d64a Mon Sep 17 00:00:00 2001 From: David Sterba Date: Thu, 8 Feb 2018 18:44:41 +0100 Subject: btrfs-progs: tests: document exported testsuite Signed-off-by: David Sterba --- tests/README.md | 25 +++++++++++++++++++++++++ 1 file changed, 25 insertions(+) (limited to 'tests') diff --git a/tests/README.md b/tests/README.md index c6d89a5c..d4b80da1 100644 --- a/tests/README.md +++ b/tests/README.md @@ -201,6 +201,31 @@ the fuzz tests always succeed when run on random checked out. This helps bisectability. +# Exported testsuite + +The tests are typically run from git on binaries built from the git sources. It +is possible to extract only the testsuite files and run it independently. Use + +```shell +$ make testsuite +``` + +This will gather scripts and generate `tests/btrfs-progs-tests.tar.gz`. The +files inside the tar are in the top level directory, make sure you extract +the contents to an empty directory. From there you can start the tests as +described above (the non-make variant). + +By default the binaries found in `$PATH` are used, this will normally mean the +system binaries. You can also override the `$TOP` shell variable and this +path will be used as prefix for all btrfs binaries inside the tests. + +There are some utilities that are not distributed but are necessary for the +tests. They are in the top level directory of the testsuite and their path +cannot be set. + +The tests assume write acesss to their directories. + + # Coding style, best practices ## do -- cgit v1.2.3 From ea0956bb2a26ca0deb1bcba186a0e53ab07164a5 Mon Sep 17 00:00:00 2001 From: David Sterba Date: Mon, 19 Feb 2018 19:07:32 +0100 Subject: btrfs-progs: tests: add test for send -p on 2 mont points Add testcase from issue, use reproducer from Axel Burri. Issue: #96 Signed-off-by: David Sterba --- .../029-send-p-different-mountpoints/test.sh | 51 ++++++++++++++++++++++ 1 file changed, 51 insertions(+) create mode 100755 tests/misc-tests/029-send-p-different-mountpoints/test.sh (limited to 'tests') diff --git a/tests/misc-tests/029-send-p-different-mountpoints/test.sh b/tests/misc-tests/029-send-p-different-mountpoints/test.sh new file mode 100755 index 00000000..64048334 --- /dev/null +++ b/tests/misc-tests/029-send-p-different-mountpoints/test.sh @@ -0,0 +1,51 @@ +#!/bin/bash +# test that send -p does not corrupt paths when send is using 2 different mount +# points + +source "$TOP/tests/common" + +check_prereq btrfs +check_prereq mkfs.btrfs + +setup_root_helper +prepare_test_dev + +# we need two mount points, cannot nest the subvoolume under TEST_MNT +SUBVOL_MNT="$TEST_MNT/subvol" +TOPLEVEL_MNT="$TEST_MNT/toplevel" +TEST_MNT="$TOPLEVEL_MNT" +mkdir -p "$TOPLEVEL_MNT" "$SUBVOL_MNT" + +run_check $SUDO_HELPER "$TOP/mkfs.btrfs" -f "$TEST_DEV" +run_check_mount_test_dev + +run_check $SUDO_HELPER "$TOP/btrfs" subvolume create "$TOPLEVEL_MNT/subv1" +run_check $SUDO_HELPER mount -t btrfs -o subvol=subv1 "$TEST_DEV" "$SUBVOL_MNT" + +run_check $SUDO_HELPER "$TOP/btrfs" subvolume create "$TOPLEVEL_MNT/test-subvol" +run_check $SUDO_HELPER "$TOP/btrfs" subvolume snapshot -r \ + "$TOPLEVEL_MNT/test-subvol" "$SUBVOL_MNT/test-subvol-mnt-subvol" +run_check $SUDO_HELPER "$TOP/btrfs" subvolume snapshot -r \ + "$TOPLEVEL_MNT/test-subvol" "$TOPLEVEL_MNT/test-subvol-mnt-root" + +run_mustfail_stdout "send -p on 2 mount points" \ + $SUDO_HELPER "$TOP/btrfs" send -f /dev/null -p \ + "$SUBVOL_MNT/test-subvol-mnt-subvol" "$TOPLEVEL_MNT/test-subvol-mnt-root" \ + | tee -a "$RESULTS" \ + | grep -q "not on mount point.*/toplevel" \ + || _fail "expected output not found, please check the logs" + +# without a fix, this leads to a corrupted path, with something like: +# +# ERROR: open st-subvol-mnt-subvol failed. No such file or directory +# ^^^^^^^^^^^^^^^^^^^^ +# ERROR: could not resolve rootid for .../tests/mnt/subvol/test-subvol-mnt-subvol + +# expected output: +# ERROR: not on mount point: .../tests/mnt/toplevel + +run_check_umount_test_dev "$SUBVOL_MNT" +run_check_umount_test_dev "$TOPLEVEL_MNT" + +rmdir "$SUBVOL_MNT" +rmdir "$TOPLEVEL_MNT" -- cgit v1.2.3 From 510bb4ccc4258567e731b81c4722a6adc7faec8b Mon Sep 17 00:00:00 2001 From: David Sterba Date: Mon, 19 Feb 2018 19:24:07 +0100 Subject: btrfs-progs: tests: add helper to log pipe stdout Signed-off-by: David Sterba --- tests/common | 7 +++++++ tests/misc-tests/029-send-p-different-mountpoints/test.sh | 2 +- 2 files changed, 8 insertions(+), 1 deletion(-) (limited to 'tests') diff --git a/tests/common b/tests/common index fae30f1d..4b266c5b 100644 --- a/tests/common +++ b/tests/common @@ -54,6 +54,13 @@ _log() echo "$*" | tee -a "$RESULTS" } +# copy stdout to log and pass to stdout, eg. another stdout consumer, commands +# should redirect stderr to stdout if this is consmed by further commands +_log_stdout() +{ + tee -a "$RESULTS" +} + _not_run() { echo " [NOTRUN] $*" diff --git a/tests/misc-tests/029-send-p-different-mountpoints/test.sh b/tests/misc-tests/029-send-p-different-mountpoints/test.sh index 64048334..6a380158 100755 --- a/tests/misc-tests/029-send-p-different-mountpoints/test.sh +++ b/tests/misc-tests/029-send-p-different-mountpoints/test.sh @@ -31,7 +31,7 @@ run_check $SUDO_HELPER "$TOP/btrfs" subvolume snapshot -r \ run_mustfail_stdout "send -p on 2 mount points" \ $SUDO_HELPER "$TOP/btrfs" send -f /dev/null -p \ "$SUBVOL_MNT/test-subvol-mnt-subvol" "$TOPLEVEL_MNT/test-subvol-mnt-root" \ - | tee -a "$RESULTS" \ + | _log_stdout \ | grep -q "not on mount point.*/toplevel" \ || _fail "expected output not found, please check the logs" -- cgit v1.2.3 From 0155481cc91285c75992603dfa6204a4fb6b698d Mon Sep 17 00:00:00 2001 From: Lu Fengqi Date: Wed, 28 Feb 2018 18:13:23 +0800 Subject: btrfs-progs: fsck-tests: Introduce test case with keyed data backref with the extent offset Add the testcase for false alert of data extent backref lost with the extent offset. The image can be reproduced by the following commands: ------ dev=~/test.img mnt=/mnt/btrfs umount $mnt &> /dev/null fallocate -l 128M $dev mkfs.btrfs $dev mount $dev $mnt for i in `seq 1 10`; do xfs_io -f -c "pwrite 0 2K" $mnt/file$i done xfs_io -f -c "falloc 0 64K" $mnt/file11 for i in `seq 1 32`; do xfs_io -f -c "reflink $mnt/file11 0 $(($i * 64))K 64K" $mnt/file11 done xfs_io -f -c "reflink $mnt/file11 32K $((33 * 64))K 32K" $mnt/file11 btrfs subvolume snapshot $mnt $mnt/snap1 umount $mnt btrfs-image -c9 $dev extent_data_ref.img ------ Signed-off-by: Lu Fengqi Signed-off-by: David Sterba --- .../fsck-tests/020-extent-ref-cases/extent_data_ref.img | Bin 0 -> 6144 bytes 1 file changed, 0 insertions(+), 0 deletions(-) create mode 100644 tests/fsck-tests/020-extent-ref-cases/extent_data_ref.img (limited to 'tests') diff --git a/tests/fsck-tests/020-extent-ref-cases/extent_data_ref.img b/tests/fsck-tests/020-extent-ref-cases/extent_data_ref.img new file mode 100644 index 00000000..3ab2396b Binary files /dev/null and b/tests/fsck-tests/020-extent-ref-cases/extent_data_ref.img differ -- cgit v1.2.3 From 546cea6f364cb5d51e589186503764595543123a Mon Sep 17 00:00:00 2001 From: Qu Wenruo Date: Mon, 5 Feb 2018 14:47:12 +0800 Subject: btrfs-progs: tests: Add test case with valid orphan inode Regression test for false alerts in lowmem mode. Signed-off-by: Qu Wenruo [ update test ] Signed-off-by: David Sterba --- .../fsck-tests/029-valid-orphan-item/orphan_inode.img.xz | Bin 0 -> 1620 bytes tests/fsck-tests/029-valid-orphan-item/test.sh | 15 +++++++++++++++ 2 files changed, 15 insertions(+) create mode 100644 tests/fsck-tests/029-valid-orphan-item/orphan_inode.img.xz create mode 100755 tests/fsck-tests/029-valid-orphan-item/test.sh (limited to 'tests') diff --git a/tests/fsck-tests/029-valid-orphan-item/orphan_inode.img.xz b/tests/fsck-tests/029-valid-orphan-item/orphan_inode.img.xz new file mode 100644 index 00000000..26e4cf8a Binary files /dev/null and b/tests/fsck-tests/029-valid-orphan-item/orphan_inode.img.xz differ diff --git a/tests/fsck-tests/029-valid-orphan-item/test.sh b/tests/fsck-tests/029-valid-orphan-item/test.sh new file mode 100755 index 00000000..d8068f63 --- /dev/null +++ b/tests/fsck-tests/029-valid-orphan-item/test.sh @@ -0,0 +1,15 @@ +#!/bin/bash +# To check if btrfs check can handle valid orphan items. +# Orphan item is a marker for deleted inodes that were open at the time of +# deletion. # Orphan inode/root will is not referenced and will have an orphan +# item, which should not be reported as error. + +source "$TEST_TOP/common" + +check_prereq btrfs + +check_image() { + run_check "$TOP/btrfs" check "$1" +} + +check_all_images -- cgit v1.2.3 From e875cd98e38f9fdc7f812a7575a3a2afd6b6094b Mon Sep 17 00:00:00 2001 From: David Sterba Date: Mon, 12 Mar 2018 19:17:49 +0100 Subject: btrfs-progs: tests: fix source path for testsuite The commit cebf3b37228cbde730a5 ("btrfs-progs: introduce TEST_TOP and INTERNAL_BIN for tests") did not convert all test paths. This would break the exported testsutie. Signed-off-by: David Sterba --- tests/fsck-tests/015-tree-reloc-tree/test.sh | 2 +- tests/misc-tests/028-superblock-recover/test.sh | 2 +- tests/misc-tests/029-send-p-different-mountpoints/test.sh | 2 +- tests/mkfs-tests/010-minimal-size/test.sh | 2 +- tests/mkfs-tests/011-rootdir-create-file/test.sh | 2 +- tests/mkfs-tests/012-rootdir-no-shrink/test.sh | 2 +- tests/mkfs-tests/013-reserved-1M-for-single/test.sh | 2 +- 7 files changed, 7 insertions(+), 7 deletions(-) (limited to 'tests') diff --git a/tests/fsck-tests/015-tree-reloc-tree/test.sh b/tests/fsck-tests/015-tree-reloc-tree/test.sh index afad1e8d..21987b0c 100755 --- a/tests/fsck-tests/015-tree-reloc-tree/test.sh +++ b/tests/fsck-tests/015-tree-reloc-tree/test.sh @@ -5,7 +5,7 @@ # Also due to the short life span of reloc tree, save the as dump example for # later usage. -source "$TOP/tests/common" +source "$TEST_TOP/common" check_prereq btrfs diff --git a/tests/misc-tests/028-superblock-recover/test.sh b/tests/misc-tests/028-superblock-recover/test.sh index 1175e480..a177e1e1 100755 --- a/tests/misc-tests/028-superblock-recover/test.sh +++ b/tests/misc-tests/028-superblock-recover/test.sh @@ -1,7 +1,7 @@ #!/bin/bash # Test that any superblock is correctly detected and fixed by btrfs rescue -source "$TOP/tests/common" +source "$TEST_TOP/common" check_prereq btrfs check_prereq mkfs.btrfs diff --git a/tests/misc-tests/029-send-p-different-mountpoints/test.sh b/tests/misc-tests/029-send-p-different-mountpoints/test.sh index 6a380158..0b42b772 100755 --- a/tests/misc-tests/029-send-p-different-mountpoints/test.sh +++ b/tests/misc-tests/029-send-p-different-mountpoints/test.sh @@ -2,7 +2,7 @@ # test that send -p does not corrupt paths when send is using 2 different mount # points -source "$TOP/tests/common" +source "$TEST_TOP/common" check_prereq btrfs check_prereq mkfs.btrfs diff --git a/tests/mkfs-tests/010-minimal-size/test.sh b/tests/mkfs-tests/010-minimal-size/test.sh index 62f8e16a..582533c3 100755 --- a/tests/mkfs-tests/010-minimal-size/test.sh +++ b/tests/mkfs-tests/010-minimal-size/test.sh @@ -1,7 +1,7 @@ #!/bin/bash # test if the reported minimal size of mkfs.btrfs is valid -source "$TOP/tests/common" +source "$TEST_TOP/common" check_prereq mkfs.btrfs check_prereq btrfs diff --git a/tests/mkfs-tests/011-rootdir-create-file/test.sh b/tests/mkfs-tests/011-rootdir-create-file/test.sh index c04f711d..20f7c4ce 100755 --- a/tests/mkfs-tests/011-rootdir-create-file/test.sh +++ b/tests/mkfs-tests/011-rootdir-create-file/test.sh @@ -3,7 +3,7 @@ # Expected behavior: it should create a new file if destination doesn't exist # Regression 460e93f25754 ("btrfs-progs: mkfs: check the status of file at mkfs") -source "$TOP/tests/common" +source "$TEST_TOP/common" check_prereq mkfs.btrfs diff --git a/tests/mkfs-tests/012-rootdir-no-shrink/test.sh b/tests/mkfs-tests/012-rootdir-no-shrink/test.sh index c1cb04f5..045906ae 100755 --- a/tests/mkfs-tests/012-rootdir-no-shrink/test.sh +++ b/tests/mkfs-tests/012-rootdir-no-shrink/test.sh @@ -1,7 +1,7 @@ #!/bin/bash # Test if mkfs.btrfs --rootdir will skip shrinking correctly -source "$TOP/tests/common" +source "$TEST_TOP/common" check_prereq mkfs.btrfs diff --git a/tests/mkfs-tests/013-reserved-1M-for-single/test.sh b/tests/mkfs-tests/013-reserved-1M-for-single/test.sh index 1490df2c..caeb7d59 100755 --- a/tests/mkfs-tests/013-reserved-1M-for-single/test.sh +++ b/tests/mkfs-tests/013-reserved-1M-for-single/test.sh @@ -6,7 +6,7 @@ # using btrfs_alloc_chunk() which won't use the 0~1M range, so other profiles # are safe, but we test them nevertheless. -source "$TOP/tests/common" +source "$TEST_TOP/common" check_prereq mkfs.btrfs check_prereq btrfs -- cgit v1.2.3 From 7a8d5d50145e6f3898bb382360857dcc080a4a78 Mon Sep 17 00:00:00 2001 From: Filipe Manana Date: Wed, 14 Mar 2018 20:11:18 +0000 Subject: Btrfs-progs: add fsck test for filesystem with shared prealloc extents Verify that a filesystem check operation (fsck) does not report the following scenario as an error: An extent is shared between two inodes, as a result of clone/reflink operation, and for one of the inodes, lets call it inode A, the extent is referenced through a file extent item as a prealloc extent, while for the other inode, call it inode B, the extent is referenced through a regular file extent item, that is, it was written to. The goal of this test is to make sure a filesystem check operation will not report "odd csum items" errors for the prealloc extent at inode A, because this scenario is valid since the extent was written through inode B and therefore it is expected to have checksum items in the filesystem's checksum btree for that shared extent. Such scenario can be created with the following steps for example: mkfs.btrfs -f /dev/sdb mount /dev/sdb /mnt touch /mnt/foo xfs_io -c "falloc 0 256K" /mnt/foo sync xfs_io -c "pwrite -S 0xab 0 256K" /mnt/foo touch /mnt/bar xfs_io -c "reflink /mnt/foo 0 0 256K" /mnt/bar xfs_io -c "fsync" /mnt/bar mount /dev/sdb /mnt umount /mnt This scenario is fixed by the following patch for the filesystem checker: "Btrfs-progs: check, fix false error reports for shared prealloc extents" Signed-off-by: Filipe Manana Reviewed-by: Qu Wenruo Signed-off-by: David Sterba --- .../reflinked-prealloc-extents.img.xz | Bin 0 -> 3244 bytes .../030-reflinked-prealloc-extents/test.sh | 42 +++++++++++++++++++++ 2 files changed, 42 insertions(+) create mode 100644 tests/fsck-tests/030-reflinked-prealloc-extents/reflinked-prealloc-extents.img.xz create mode 100755 tests/fsck-tests/030-reflinked-prealloc-extents/test.sh (limited to 'tests') diff --git a/tests/fsck-tests/030-reflinked-prealloc-extents/reflinked-prealloc-extents.img.xz b/tests/fsck-tests/030-reflinked-prealloc-extents/reflinked-prealloc-extents.img.xz new file mode 100644 index 00000000..8adf0071 Binary files /dev/null and b/tests/fsck-tests/030-reflinked-prealloc-extents/reflinked-prealloc-extents.img.xz differ diff --git a/tests/fsck-tests/030-reflinked-prealloc-extents/test.sh b/tests/fsck-tests/030-reflinked-prealloc-extents/test.sh new file mode 100755 index 00000000..63f692bc --- /dev/null +++ b/tests/fsck-tests/030-reflinked-prealloc-extents/test.sh @@ -0,0 +1,42 @@ +#!/bin/bash +# +# Verify that a filesystem check operation (fsck) does not report the following +# scenario as an error: +# +# An extent is shared between two inodes, as a result of clone/reflink operation, +# and for one of the inodes, lets call it inode A, the extent is referenced +# through a file extent item as a prealloc extent, while for the other inode, +# call it inode B, the extent is referenced through a regular file extent item, +# that is, it was written to. The goal of this test is to make sure a filesystem +# check operation will not report "odd csum items" errors for the prealloc +# extent at inode A, because this scenario is valid since the extent was written +# through inode B and therefore it is expected to have checksum items in the +# filesystem's checksum btree for that shared extent. +# +# Such scenario can be created with the following steps for example: +# +# mkfs.btrfs -f /dev/sdb +# mount /dev/sdb /mnt +# +# touch /mnt/foo +# xfs_io -c "falloc 0 256K" /mnt/foo +# sync +# +# xfs_io -c "pwrite -S 0xab 0 256K" /mnt/foo +# touch /mnt/bar +# xfs_io -c "reflink /mnt/foo 0 0 256K" /mnt/bar +# xfs_io -c "fsync" /mnt/bar +# +# +# mount /dev/sdb /mnt +# umount /mnt + +source "$TEST_TOP/common" + +check_prereq btrfs + +check_image() { + run_check "$TOP/btrfs" check "$1" +} + +check_all_images -- cgit v1.2.3 From b79681fe6d651e2646f7b4168e5a6b4cbac108b8 Mon Sep 17 00:00:00 2001 From: Qu Wenruo Date: Tue, 20 Mar 2018 14:42:28 +0800 Subject: btrfs-progs: test/convert: Add test case for invalid large inline data extent Signed-off-by: Qu Wenruo Signed-off-by: David Sterba --- .../016-invalid-large-inline-extent/test.sh | 22 ++++++++++++++++++++++ 1 file changed, 22 insertions(+) create mode 100755 tests/convert-tests/016-invalid-large-inline-extent/test.sh (limited to 'tests') diff --git a/tests/convert-tests/016-invalid-large-inline-extent/test.sh b/tests/convert-tests/016-invalid-large-inline-extent/test.sh new file mode 100755 index 00000000..f37c7c09 --- /dev/null +++ b/tests/convert-tests/016-invalid-large-inline-extent/test.sh @@ -0,0 +1,22 @@ +#!/bin/bash +# Check if btrfs-convert refuses to rollback the filesystem, and leave the fs +# and the convert image untouched + +source "$TEST_TOP/common" +source "$TEST_TOP/common.convert" + +setup_root_helper +prepare_test_dev +check_prereq btrfs-convert +check_global_prereq mke2fs + +convert_test_prep_fs ext4 mke2fs -t ext4 -b 4096 + +# Create a 6K file, which should not be inlined +run_check $SUDO_HELPER dd if=/dev/zero bs=2k count=3 of="$TEST_MNT/file1" + +run_check_umount_test_dev + +# convert_test_do_convert() will call btrfs check, which should expose any +# invalid inline extent with too large size +convert_test_do_convert -- cgit v1.2.3 From 7edeb29c34704475889852d21ddfa6c1eaa60e24 Mon Sep 17 00:00:00 2001 From: Qu Wenruo Date: Tue, 20 Mar 2018 14:42:29 +0800 Subject: btrfs-progs: tests: Add testcase for rootdir inline extent size Add a test case for mkfs --rootdir, using files with different file sizes to check if invalid large inline extent could exist. Signed-off-by: Qu Wenruo Signed-off-by: David Sterba --- tests/mkfs-tests/014-rootdir-inline-extent/test.sh | 47 ++++++++++++++++++++++ 1 file changed, 47 insertions(+) create mode 100755 tests/mkfs-tests/014-rootdir-inline-extent/test.sh (limited to 'tests') diff --git a/tests/mkfs-tests/014-rootdir-inline-extent/test.sh b/tests/mkfs-tests/014-rootdir-inline-extent/test.sh new file mode 100755 index 00000000..167ced1e --- /dev/null +++ b/tests/mkfs-tests/014-rootdir-inline-extent/test.sh @@ -0,0 +1,47 @@ +#!/bin/bash +# Regression test for mkfs.btrfs --rootdir with inline file extents +# For any large inline file extent, btrfs check could already report it + +source "$TEST_TOP/common" + +check_global_prereq fallocate +check_prereq mkfs.btrfs + +prepare_test_dev + +tmp=$(mktemp -d --tmpdir btrfs-progs-mkfs.rootdirXXXXXXX) + +pagesize=$(getconf PAGESIZE) +create_file() +{ + local size=$1 + # Reuse size as filename + run_check fallocate -l $size "$tmp/$size" +} + +test_mkfs_rootdir() +{ + nodesize=$1 + run_check "$TOP/mkfs.btrfs" --nodesize $nodesize -f --rootdir "$tmp" \ + "$TEST_DEV" + run_check $SUDO_HELPER "$TOP/btrfs" check "$TEST_DEV" +} + +# Use power of 2 from 512 to 64K (maximum node size) as base file size +for i in 512 1024 2048 4096 8192 16384 32768; do + create_file $(($i - 102)) + # 101 is the overhead size for max inline extent + create_file $(($i - 101)) + create_file $(($i - 100)) + + create_file $(($i - 1)) + create_file $i + create_file $(($i + 1)) +done + +for nodesize in 4096 8192 16384 32768 65536; do + if [ $nodesize -ge $pagesize ]; then + test_mkfs_rootdir $nodesize + fi +done +rm -rf -- "$tmp" -- cgit v1.2.3 From 82a1442e9cd025436be8ae65e684fd6b2701efbb Mon Sep 17 00:00:00 2001 From: David Sterba Date: Wed, 21 Mar 2018 16:42:28 +0100 Subject: btrfs-progs: tests: don't use fallocate in mkfs/014-rootdir-inline-extent If fallocate is not supported, this test fails. Use a shell trick to fill with given number of bytes. Signed-off-by: David Sterba --- tests/mkfs-tests/014-rootdir-inline-extent/test.sh | 3 +-- 1 file changed, 1 insertion(+), 2 deletions(-) (limited to 'tests') diff --git a/tests/mkfs-tests/014-rootdir-inline-extent/test.sh b/tests/mkfs-tests/014-rootdir-inline-extent/test.sh index 167ced1e..b337e493 100755 --- a/tests/mkfs-tests/014-rootdir-inline-extent/test.sh +++ b/tests/mkfs-tests/014-rootdir-inline-extent/test.sh @@ -4,7 +4,6 @@ source "$TEST_TOP/common" -check_global_prereq fallocate check_prereq mkfs.btrfs prepare_test_dev @@ -16,7 +15,7 @@ create_file() { local size=$1 # Reuse size as filename - run_check fallocate -l $size "$tmp/$size" + eval printf "%0.sx" {1..$size} > "$tmp/$size" } test_mkfs_rootdir() -- cgit v1.2.3 From f3219ad42fc3608aee629065c5a33863b5d7082b Mon Sep 17 00:00:00 2001 From: David Sterba Date: Wed, 21 Mar 2018 19:36:49 +0100 Subject: btrfs-progs: tests: mkfs fills uuid and otime for FS_TREE Signed-off-by: David Sterba --- tests/mkfs-tests/015-fstree-uuid-otime/test.sh | 35 ++++++++++++++++++++++++++ 1 file changed, 35 insertions(+) create mode 100755 tests/mkfs-tests/015-fstree-uuid-otime/test.sh (limited to 'tests') diff --git a/tests/mkfs-tests/015-fstree-uuid-otime/test.sh b/tests/mkfs-tests/015-fstree-uuid-otime/test.sh new file mode 100755 index 00000000..a2e04a3f --- /dev/null +++ b/tests/mkfs-tests/015-fstree-uuid-otime/test.sh @@ -0,0 +1,35 @@ +#!/bin/bash +# verify that mkfs fills the uuid and otime for FS_TREE + +source "$TEST_TOP/common" + +check_prereq mkfs.btrfs +check_prereq btrfs + +setup_root_helper +prepare_test_dev + +# item 3 key (FS_TREE ROOT_ITEM 0) itemoff 14949 itemsize 439 +# generation 4 root_dirid 256 bytenr 30408704 level 0 refs 1 +# lastsnap 0 byte_limit 0 bytes_used 16384 flags 0x0(none) +# uuid 322826f3-817a-4111-89ff-5481bfd516e2 +# ctime 1521656113.0 (2018-03-21 19:15:13) +# otime 1521656113.0 (2018-03-21 19:15:13) +# drop key (0 UNKNOWN.0 0) level 0 + +run_check $SUDO_HELPER "$TOP/mkfs.btrfs" -f "$@" "$TEST_DEV" +# match not-all-zeros in the first part +uuid=$(run_check_stdout $SUDO_HELPER "$TOP/btrfs" inspect-internal dump-tree -t root "$TEST_DEV" | \ + grep -A 3 "FS_TREE ROOT_ITEM 0" | grep 'uuid ') + +if [ $? != 0 ]; then + _fail "uuid for FS_TREE not found" +fi + +if [ "$uuid" = '00000000-0000-0000-0000-000000000000' ]; then + _fail "uuid for FS_TREE is null" +fi + +run_check_stdout $SUDO_HELPER "$TOP/btrfs" inspect-internal dump-tree -t root "$TEST_DEV" | \ + grep -A 5 "FS_TREE ROOT_ITEM 0" | grep -q 'otime ' || \ + _fail "otime for FS_TREE not found" -- cgit v1.2.3 From acd4df738165e1e4b16e199ee70b77d3e64a260a Mon Sep 17 00:00:00 2001 From: David Sterba Date: Fri, 23 Mar 2018 15:29:41 +0100 Subject: btrfs-progs: tests: update README, images, coding style Signed-off-by: David Sterba --- tests/README.md | 24 +++++++++++++++++++++++- 1 file changed, 23 insertions(+), 1 deletion(-) (limited to 'tests') diff --git a/tests/README.md b/tests/README.md index d4b80da1..d14d727c 100644 --- a/tests/README.md +++ b/tests/README.md @@ -189,6 +189,27 @@ $ TEST=012\* ./misc-tests.sh # from tests/ 7. A commit that fixes a bug should be applied before the test that verifies the fix. This is to keep the git history bisectable. + +### Test images + +Most tests should be able to create the test images from scratch, using regular +commands and file operation. The commands also document the testcase and use +the teste code and kernel of the environment. + +In other cases, a pre-created image may be the right way if the above does not +work (eg. comparing output, requesting an exact layout or some intermediate +state that would be hard to achieve otherwise). + +* images that don't need data and valid checksums can be created by + `btrfs-image`, the image can be compressed by the tool itself (file extension + `.img`) or compressed externally (recognized is `.img.xz`) + +* raw images that are binary dump of an existing image, created eg. from a + sparse file (`.raw` or `.raw.xz`) + +Use `xz --best` and try to get the smallest size as the file is stored in git. + + ### Crafted/fuzzed images Images that are created by fuzzing or specially crafted to trigger some error @@ -232,9 +253,10 @@ The tests assume write acesss to their directories. * quote all variables by default, any path, even the TOP could need that, and we use it everywhere + * even if the variable is safe, use quotes for consistency and to ease + reading the code * there are exceptions: * `$SUDO_HELPER` as it might be intentionally unset - * the variable is obviously set to a value that does not require it * use `#!/bin/bash` explicitly * check for all external dependencies (`check_prereq_global`) * check for internal dependencies (`check_prereq`), though the basic set is -- cgit v1.2.3 From a7e56ef21b666b26e9668094d4c171788a914840 Mon Sep 17 00:00:00 2001 From: David Sterba Date: Fri, 23 Mar 2018 16:03:14 +0100 Subject: btrfs-progs: tests: convert/014 use shell builtin for generating content We can remove dependency on perl and use shell builtin go generate sequence of bytes. Signed-off-by: David Sterba --- tests/convert-tests/014-reiserfs-tail-handling/test.sh | 5 ++--- 1 file changed, 2 insertions(+), 3 deletions(-) (limited to 'tests') diff --git a/tests/convert-tests/014-reiserfs-tail-handling/test.sh b/tests/convert-tests/014-reiserfs-tail-handling/test.sh index 5714dc6c..3be2ed5b 100755 --- a/tests/convert-tests/014-reiserfs-tail-handling/test.sh +++ b/tests/convert-tests/014-reiserfs-tail-handling/test.sh @@ -18,10 +18,9 @@ prepare_test_dev check_prereq btrfs-convert check_global_prereq md5sum check_global_prereq mkreiserfs -check_global_prereq perl -perl -e "print 'a'x8192;" > input -perl -e "print 'b'x8192;" > input2 +printf "%0.sa" {1..8192} > input +printf "%0.sb" {1..8192} > input2 default_mkfs="mkreiserfs -b 4096" convert_test_preamble '' 'tail conversion test' 16k "$default_mkfs" -- cgit v1.2.3 From a1e21ec5a880044f44a9109633c7503bce02cb5e Mon Sep 17 00:00:00 2001 From: David Sterba Date: Fri, 23 Mar 2018 16:11:41 +0100 Subject: btrfs-progs: tests: add shell quoting to fuzz test scripts Signed-off-by: David Sterba --- tests/fuzz-tests/001-simple-check-unmounted/test.sh | 4 ++-- tests/fuzz-tests/002-simple-image/test.sh | 4 ++-- tests/fuzz-tests/003-multi-check-unmounted/test.sh | 2 +- tests/fuzz-tests/004-simple-dump-tree/test.sh | 4 ++-- tests/fuzz-tests/005-simple-dump-super/test.sh | 6 +++--- tests/fuzz-tests/006-simple-tree-stats/test.sh | 4 ++-- tests/fuzz-tests/008-simple-chunk-recover/test.sh | 4 ++-- tests/fuzz-tests/009-simple-zero-log/test.sh | 4 ++-- 8 files changed, 16 insertions(+), 16 deletions(-) (limited to 'tests') diff --git a/tests/fuzz-tests/001-simple-check-unmounted/test.sh b/tests/fuzz-tests/001-simple-check-unmounted/test.sh index 905d37b7..84d7ed83 100755 --- a/tests/fuzz-tests/001-simple-check-unmounted/test.sh +++ b/tests/fuzz-tests/001-simple-check-unmounted/test.sh @@ -12,9 +12,9 @@ check_image() { local image image=$1 - run_mayfail $TOP/btrfs check "$image" + run_mayfail "$TOP/btrfs" check "$image" } -check_all_images $TEST_TOP/fuzz-tests/images +check_all_images "$TEST_TOP/fuzz-tests/images" exit 0 diff --git a/tests/fuzz-tests/002-simple-image/test.sh b/tests/fuzz-tests/002-simple-image/test.sh index 034fcf46..0db61908 100755 --- a/tests/fuzz-tests/002-simple-image/test.sh +++ b/tests/fuzz-tests/002-simple-image/test.sh @@ -13,11 +13,11 @@ check_image() { image=$1 truncate -s0 target - run_mayfail $TOP/btrfs-image "$image" target + run_mayfail "$TOP/btrfs-image" "$image" target truncate -s0 target } -check_all_images $TEST_TOP/fuzz-tests/images +check_all_images "$TEST_TOP/fuzz-tests/images" rm -- target diff --git a/tests/fuzz-tests/003-multi-check-unmounted/test.sh b/tests/fuzz-tests/003-multi-check-unmounted/test.sh index 35dfe4fc..3021c3a8 100755 --- a/tests/fuzz-tests/003-multi-check-unmounted/test.sh +++ b/tests/fuzz-tests/003-multi-check-unmounted/test.sh @@ -21,6 +21,6 @@ check_image() { run_mayfail $TOP/btrfs check --repair "$image" } -check_all_images $TEST_TOP/fuzz-tests/images +check_all_images "$TEST_TOP/fuzz-tests/images" exit 0 diff --git a/tests/fuzz-tests/004-simple-dump-tree/test.sh b/tests/fuzz-tests/004-simple-dump-tree/test.sh index 6c9e8c45..857c742a 100755 --- a/tests/fuzz-tests/004-simple-dump-tree/test.sh +++ b/tests/fuzz-tests/004-simple-dump-tree/test.sh @@ -10,9 +10,9 @@ check_image() { local image image=$1 - run_mayfail $TOP/btrfs inspect-internal dump-tree "$image" + run_mayfail "$TOP/btrfs" inspect-internal dump-tree "$image" } -check_all_images $TEST_TOP/fuzz-tests/images +check_all_images "$TEST_TOP/fuzz-tests/images" exit 0 diff --git a/tests/fuzz-tests/005-simple-dump-super/test.sh b/tests/fuzz-tests/005-simple-dump-super/test.sh index 01c7b628..18f71a48 100755 --- a/tests/fuzz-tests/005-simple-dump-super/test.sh +++ b/tests/fuzz-tests/005-simple-dump-super/test.sh @@ -10,10 +10,10 @@ check_image() { local image image=$1 - run_mayfail $TOP/btrfs inspect-internal dump-super "$image" - run_mayfail $TOP/btrfs inspect-internal dump-super -Ffa "$image" + run_mayfail "$TOP/btrfs" inspect-internal dump-super "$image" + run_mayfail "$TOP/btrfs" inspect-internal dump-super -Ffa "$image" } -check_all_images $TEST_TOP/fuzz-tests/images +check_all_images "$TEST_TOP/fuzz-tests/images" exit 0 diff --git a/tests/fuzz-tests/006-simple-tree-stats/test.sh b/tests/fuzz-tests/006-simple-tree-stats/test.sh index dbed471a..cb82e2cf 100755 --- a/tests/fuzz-tests/006-simple-tree-stats/test.sh +++ b/tests/fuzz-tests/006-simple-tree-stats/test.sh @@ -10,9 +10,9 @@ check_image() { local image image=$1 - run_mayfail $TOP/btrfs inspect-internal tree-stats "$image" + run_mayfail "$TOP/btrfs" inspect-internal tree-stats "$image" } -check_all_images $TEST_TOP/fuzz-tests/images +check_all_images "$TEST_TOP/fuzz-tests/images" exit 0 diff --git a/tests/fuzz-tests/008-simple-chunk-recover/test.sh b/tests/fuzz-tests/008-simple-chunk-recover/test.sh index 198f88e2..4b27de0c 100755 --- a/tests/fuzz-tests/008-simple-chunk-recover/test.sh +++ b/tests/fuzz-tests/008-simple-chunk-recover/test.sh @@ -11,10 +11,10 @@ check_image() { image=$1 run_check cp "$image" "$image".scratch - run_mayfail $TOP/btrfs rescue chunk-recover -y -v "$image".scratch + run_mayfail "$TOP/btrfs" rescue chunk-recover -y -v "$image".scratch rm -- "$image".scratch } -check_all_images $TEST_TOP/fuzz-tests/images +check_all_images "$TEST_TOP/fuzz-tests/images" exit 0 diff --git a/tests/fuzz-tests/009-simple-zero-log/test.sh b/tests/fuzz-tests/009-simple-zero-log/test.sh index 928c66b1..f78e5b50 100755 --- a/tests/fuzz-tests/009-simple-zero-log/test.sh +++ b/tests/fuzz-tests/009-simple-zero-log/test.sh @@ -11,10 +11,10 @@ check_image() { image=$1 run_check cp "$image" "$image".scratch - run_mayfail $TOP/btrfs rescue zero-log "$image".scratch + run_mayfail "$TOP/btrfs" rescue zero-log "$image".scratch rm -- "$image".scratch } -check_all_images $TEST_TOP/fuzz-tests/images +check_all_images "$TEST_TOP/fuzz-tests/images" exit 0 -- cgit v1.2.3 From a855717a87a8da78b62148e8bf0a629695596097 Mon Sep 17 00:00:00 2001 From: David Sterba Date: Fri, 23 Mar 2018 16:21:37 +0100 Subject: btrfs-progs: tests: remove trivial use of local variables No need to use a temporary variable if the parameter usage is obvious from the context. Signed-off-by: David Sterba --- tests/fsck-tests/015-tree-reloc-tree/test.sh | 5 +---- tests/fsck-tests/020-extent-ref-cases/test.sh | 5 +---- tests/fuzz-tests/001-simple-check-unmounted/test.sh | 5 +---- tests/fuzz-tests/002-simple-image/test.sh | 5 +---- tests/fuzz-tests/004-simple-dump-tree/test.sh | 5 +---- tests/fuzz-tests/006-simple-tree-stats/test.sh | 5 +---- tests/misc-tests/002-uuid-rewrite/test.sh | 5 +---- tests/misc-tests/003-zero-log/test.sh | 10 ++-------- 8 files changed, 9 insertions(+), 36 deletions(-) (limited to 'tests') diff --git a/tests/fsck-tests/015-tree-reloc-tree/test.sh b/tests/fsck-tests/015-tree-reloc-tree/test.sh index 21987b0c..5d9d5122 100755 --- a/tests/fsck-tests/015-tree-reloc-tree/test.sh +++ b/tests/fsck-tests/015-tree-reloc-tree/test.sh @@ -10,10 +10,7 @@ source "$TEST_TOP/common" check_prereq btrfs check_image() { - local image - - image=$1 - run_check "$TOP/btrfs" check "$image" + run_check "$TOP/btrfs" check "$1" } check_all_images diff --git a/tests/fsck-tests/020-extent-ref-cases/test.sh b/tests/fsck-tests/020-extent-ref-cases/test.sh index 9cf99a51..a1bf75b1 100755 --- a/tests/fsck-tests/020-extent-ref-cases/test.sh +++ b/tests/fsck-tests/020-extent-ref-cases/test.sh @@ -20,10 +20,7 @@ source "$TEST_TOP/common" check_prereq btrfs check_image() { - local image - - image=$1 - run_check "$TOP/btrfs" check "$image" + run_check "$TOP/btrfs" check "$1" } check_all_images diff --git a/tests/fuzz-tests/001-simple-check-unmounted/test.sh b/tests/fuzz-tests/001-simple-check-unmounted/test.sh index 84d7ed83..87a63944 100755 --- a/tests/fuzz-tests/001-simple-check-unmounted/test.sh +++ b/tests/fuzz-tests/001-simple-check-unmounted/test.sh @@ -9,10 +9,7 @@ check_prereq btrfs # redefine the one provided by common check_image() { - local image - - image=$1 - run_mayfail "$TOP/btrfs" check "$image" + run_mayfail "$TOP/btrfs" check "$1" } check_all_images "$TEST_TOP/fuzz-tests/images" diff --git a/tests/fuzz-tests/002-simple-image/test.sh b/tests/fuzz-tests/002-simple-image/test.sh index 0db61908..5dddc9e1 100755 --- a/tests/fuzz-tests/002-simple-image/test.sh +++ b/tests/fuzz-tests/002-simple-image/test.sh @@ -9,11 +9,8 @@ check_prereq btrfs-image # redefine the one provided by common check_image() { - local image - - image=$1 truncate -s0 target - run_mayfail "$TOP/btrfs-image" "$image" target + run_mayfail "$TOP/btrfs-image" "$1" target truncate -s0 target } diff --git a/tests/fuzz-tests/004-simple-dump-tree/test.sh b/tests/fuzz-tests/004-simple-dump-tree/test.sh index 857c742a..c09b8478 100755 --- a/tests/fuzz-tests/004-simple-dump-tree/test.sh +++ b/tests/fuzz-tests/004-simple-dump-tree/test.sh @@ -7,10 +7,7 @@ check_prereq btrfs # redefine the one provided by common check_image() { - local image - - image=$1 - run_mayfail "$TOP/btrfs" inspect-internal dump-tree "$image" + run_mayfail "$TOP/btrfs" inspect-internal dump-tree "$1" } check_all_images "$TEST_TOP/fuzz-tests/images" diff --git a/tests/fuzz-tests/006-simple-tree-stats/test.sh b/tests/fuzz-tests/006-simple-tree-stats/test.sh index cb82e2cf..146afa93 100755 --- a/tests/fuzz-tests/006-simple-tree-stats/test.sh +++ b/tests/fuzz-tests/006-simple-tree-stats/test.sh @@ -7,10 +7,7 @@ check_prereq btrfs # redefine the one provided by common check_image() { - local image - - image=$1 - run_mayfail "$TOP/btrfs" inspect-internal tree-stats "$image" + run_mayfail "$TOP/btrfs" inspect-internal tree-stats "$1" } check_all_images "$TEST_TOP/fuzz-tests/images" diff --git a/tests/misc-tests/002-uuid-rewrite/test.sh b/tests/misc-tests/002-uuid-rewrite/test.sh index e32aff0c..8e7011a8 100755 --- a/tests/misc-tests/002-uuid-rewrite/test.sh +++ b/tests/misc-tests/002-uuid-rewrite/test.sh @@ -10,10 +10,7 @@ check_prereq btrfs prepare_test_dev get_fs_uuid() { - local image - - image="$1" - run_check_stdout $TOP/btrfs inspect-internal dump-super "$image" | \ + run_check_stdout $TOP/btrfs inspect-internal dump-super "$1" | \ grep '^fsid' | awk '{print $2}' } diff --git a/tests/misc-tests/003-zero-log/test.sh b/tests/misc-tests/003-zero-log/test.sh index 9d2940f5..51cf6ae4 100755 --- a/tests/misc-tests/003-zero-log/test.sh +++ b/tests/misc-tests/003-zero-log/test.sh @@ -9,17 +9,11 @@ prepare_test_dev get_log_root() { - local image - - image="$1" - $TOP/btrfs inspect-internal dump-super "$image" | \ + $TOP/btrfs inspect-internal dump-super "$1" | \ grep '^log_root\>' | awk '{print $2}' } get_log_root_level() { - local image - - image="$1" - $TOP/btrfs inspect-internal dump-super "$image" | \ + $TOP/btrfs inspect-internal dump-super "$1" | \ grep '^log_root_level' | awk '{print $2}' } -- cgit v1.2.3 From 3ccad2a6443fcae0fee2cd94132580d2d06268dd Mon Sep 17 00:00:00 2001 From: David Sterba Date: Fri, 23 Mar 2018 16:34:30 +0100 Subject: btrfs-progs: tests: add shell quotes to mkfs test scripts Signed-off-by: David Sterba --- tests/mkfs-tests/001-basic-profiles/test.sh | 19 +++++++++---------- tests/mkfs-tests/004-rootdir-keeps-size/test.sh | 12 ++++++------ .../mkfs-tests/005-long-device-name-for-ssd/test.sh | 20 ++++++++++---------- tests/mkfs-tests/006-partitioned-loopdev/test.sh | 10 +++++----- tests/mkfs-tests/007-mix-nodesize-sectorsize/test.sh | 16 ++++++++-------- .../008-sectorsize-nodesize-combination/test.sh | 10 +++++----- tests/mkfs-tests/010-minimal-size/test.sh | 4 ++-- tests/mkfs-tests/012-rootdir-no-shrink/test.sh | 6 +++--- tests/mkfs-tests/013-reserved-1M-for-single/test.sh | 4 ++-- tests/mkfs-tests/014-rootdir-inline-extent/test.sh | 6 +++--- 10 files changed, 53 insertions(+), 54 deletions(-) (limited to 'tests') diff --git a/tests/mkfs-tests/001-basic-profiles/test.sh b/tests/mkfs-tests/001-basic-profiles/test.sh index b84016f7..6e295274 100755 --- a/tests/mkfs-tests/001-basic-profiles/test.sh +++ b/tests/mkfs-tests/001-basic-profiles/test.sh @@ -11,28 +11,27 @@ setup_root_helper test_get_info() { - run_check $SUDO_HELPER $TOP/btrfs inspect-internal dump-super $dev1 - run_check $SUDO_HELPER $TOP/btrfs check $dev1 - run_check $SUDO_HELPER mount $dev1 $TEST_MNT - run_check $TOP/btrfs filesystem df $TEST_MNT - run_check $SUDO_HELPER $TOP/btrfs filesystem usage $TEST_MNT - run_check $SUDO_HELPER $TOP/btrfs device usage $TEST_MNT + run_check $SUDO_HELPER "$TOP/btrfs" inspect-internal dump-super "$dev1" + run_check $SUDO_HELPER "$TOP/btrfs" check "$dev1" + run_check $SUDO_HELPER mount "$dev1" "$TEST_MNT" + run_check "$TOP/btrfs" filesystem df "$TEST_MNT" + run_check $SUDO_HELPER "$TOP/btrfs" filesystem usage "$TEST_MNT" + run_check $SUDO_HELPER "$TOP/btrfs" device usage "$TEST_MNT" run_check $SUDO_HELPER umount "$TEST_MNT" } test_do_mkfs() { - run_check $SUDO_HELPER $TOP/mkfs.btrfs -f \ - $@ + run_check $SUDO_HELPER "$TOP/mkfs.btrfs" -f "$@" } test_mkfs_single() { - test_do_mkfs $@ $dev1 + test_do_mkfs "$@" "$dev1" test_get_info } test_mkfs_multi() { - test_do_mkfs $@ ${loopdevs[@]} + test_do_mkfs "$@" ${loopdevs[@]} test_get_info } diff --git a/tests/mkfs-tests/004-rootdir-keeps-size/test.sh b/tests/mkfs-tests/004-rootdir-keeps-size/test.sh index 4a84e6db..635a5137 100755 --- a/tests/mkfs-tests/004-rootdir-keeps-size/test.sh +++ b/tests/mkfs-tests/004-rootdir-keeps-size/test.sh @@ -13,12 +13,12 @@ test_mkfs_with_size() { local tmp size="$1" - run_check truncate -s$size $TEST_DEV - imgsize=$(run_check_stdout stat --format=%s $TEST_DEV) - run_check $SUDO_HELPER $TOP/mkfs.btrfs -f \ - --rootdir $INTERNAL_BIN/Documentation \ - $TEST_DEV - tmp=$(run_check_stdout stat --format=%s $TEST_DEV) + run_check truncate -s"$size" "$TEST_DEV" + imgsize=$(run_check_stdout stat --format=%s "$TEST_DEV") + run_check $SUDO_HELPER "$TOP/mkfs.btrfs" -f \ + --rootdir "$INTERNAL_BIN/Documentation" \ + "$TEST_DEV" + tmp=$(run_check_stdout stat --format=%s "$TEST_DEV") if ! [ "$imgsize" = "$tmp" ]; then _fail "image size changed from $imgsize to $tmp" fi diff --git a/tests/mkfs-tests/005-long-device-name-for-ssd/test.sh b/tests/mkfs-tests/005-long-device-name-for-ssd/test.sh index 55ce676e..b7c76b18 100755 --- a/tests/mkfs-tests/005-long-device-name-for-ssd/test.sh +++ b/tests/mkfs-tests/005-long-device-name-for-ssd/test.sh @@ -11,31 +11,31 @@ prepare_test_dev # prep device dmname=\ btrfs-test-with-very-long-name-AAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAA -dmdev=/dev/mapper/$dmname +dmdev="/dev/mapper/$dmname" run_check truncate -s0 img chmod a+w img run_check truncate -s2g img loopdev=`run_check_stdout $SUDO_HELPER losetup --find --show img` -run_check $SUDO_HELPER dmsetup create $dmname --table "0 1048576 linear $loopdev 0" +run_check $SUDO_HELPER dmsetup create "$dmname" --table "0 1048576 linear $loopdev 0" -dmbase=`readlink -f $dmdev` +dmbase=`readlink -f "$dmdev"` base=`basename "$dmbase"` -rot=/sys/class/block/$base/queue/rotational +rot="/sys/class/block/$base/queue/rotational" # switch rotational run_check cat $rot -echo 0 | run_check $SUDO_HELPER tee $rot -run_check cat $rot +echo 0 | run_check $SUDO_HELPER tee "$rot" +run_check cat "$rot" # test -run_check_stdout $SUDO_HELPER $TOP/mkfs.btrfs -f $@ $dmdev | +run_check_stdout $SUDO_HELPER "$TOP/mkfs.btrfs" -f "$@" "$dmdev" | grep -q 'SSD detected:.*yes' || _fail 'SSD not detected' -run_check $SUDO_HELPER $TOP/btrfs inspect-internal dump-super $dmdev +run_check $SUDO_HELPER "$TOP/btrfs" inspect-internal dump-super "$dmdev" # cleanup -run_check $SUDO_HELPER dmsetup remove $dmname -run_mayfail $SUDO_HELPER losetup -d $loopdev +run_check $SUDO_HELPER dmsetup remove "$dmname" +run_mayfail $SUDO_HELPER losetup -d "$loopdev" run_check truncate -s0 img rm img diff --git a/tests/mkfs-tests/006-partitioned-loopdev/test.sh b/tests/mkfs-tests/006-partitioned-loopdev/test.sh index 06c254fd..5d972a78 100755 --- a/tests/mkfs-tests/006-partitioned-loopdev/test.sh +++ b/tests/mkfs-tests/006-partitioned-loopdev/test.sh @@ -18,15 +18,15 @@ cp partition-1g-1g img run_check truncate -s2g img loopdev=$(run_check_stdout $SUDO_HELPER losetup --partscan --find --show img) -base=$(basename $loopdev) +base=$(basename "$loopdev") # expect partitions named like loop0p1 etc -for looppart in $(ls /dev/$base?*); do - run_check $SUDO_HELPER $TOP/mkfs.btrfs -f $looppart - run_check $SUDO_HELPER $TOP/btrfs inspect-internal dump-super $looppart +for looppart in $(ls /dev/"$base"?*); do + run_check $SUDO_HELPER "$TOP/mkfs.btrfs" -f "$looppart" + run_check $SUDO_HELPER "$TOP/btrfs" inspect-internal dump-super "$looppart" done # cleanup -run_check $SUDO_HELPER losetup -d $loopdev +run_check $SUDO_HELPER losetup -d "$loopdev" run_check truncate -s0 img rm img diff --git a/tests/mkfs-tests/007-mix-nodesize-sectorsize/test.sh b/tests/mkfs-tests/007-mix-nodesize-sectorsize/test.sh index f7e88c9a..31f44f33 100755 --- a/tests/mkfs-tests/007-mix-nodesize-sectorsize/test.sh +++ b/tests/mkfs-tests/007-mix-nodesize-sectorsize/test.sh @@ -11,9 +11,9 @@ prepare_test_dev test_mkfs_single() { - run_check $SUDO_HELPER $TOP/mkfs.btrfs -f "$@" $TEST_DEV - run_check $SUDO_HELPER $TOP/btrfs inspect-internal dump-super $TEST_DEV - run_check $SUDO_HELPER $TOP/btrfs check $TEST_DEV + run_check $SUDO_HELPER "$TOP/mkfs.btrfs" -f "$@" "$TEST_DEV" + run_check $SUDO_HELPER "$TOP/btrfs" inspect-internal dump-super "$TEST_DEV" + run_check $SUDO_HELPER "$TOP/btrfs" check "$TEST_DEV" } # default @@ -22,14 +22,14 @@ test_mkfs_single # nodesize >= sectorsize for nodesize in 4096 8192 16384 32768 65536; do for sectorsize in 4096 8192 16384 32768 65536; do - [ $nodesize -lt $sectorsize ] && continue - test_mkfs_single -n $nodesize -s $sectorsize -d single -m single - test_mkfs_single -n $nodesize -s $sectorsize -d single -m dup + [ "$nodesize" -lt "$sectorsize" ] && continue + test_mkfs_single -n "$nodesize" -s "$sectorsize" -d single -m single + test_mkfs_single -n "$nodesize" -s "$sectorsize" -d single -m dup done done # nodesize, mixed mode for nodesize in 4k 8k 16k 32k 64k; do - test_mkfs_single -n $nodesize -s $nodesize -d single -m single --mixed - test_mkfs_single -n $nodesize -s $nodesize -d dup -m dup --mixed + test_mkfs_single -n "$nodesize" -s "$nodesize" -d single -m single --mixed + test_mkfs_single -n "$nodesize" -s "$nodesize" -d dup -m dup --mixed done diff --git a/tests/mkfs-tests/008-sectorsize-nodesize-combination/test.sh b/tests/mkfs-tests/008-sectorsize-nodesize-combination/test.sh index 9cc2f9e0..345d81de 100755 --- a/tests/mkfs-tests/008-sectorsize-nodesize-combination/test.sh +++ b/tests/mkfs-tests/008-sectorsize-nodesize-combination/test.sh @@ -19,13 +19,13 @@ do_test() { sectorsize=$1 nodesize=$2 - run_mayfail $TOP/mkfs.btrfs -f -O $features -n $nodesize -s $sectorsize \ - $TEST_DEV + run_mayfail "$TOP/mkfs.btrfs" -f -O "$features" -n "$nodesize" -s "$sectorsize" \ + "$TEST_DEV" ret=$? - if [ $ret == 0 ]; then - run_check $TOP/btrfs check $TEST_DEV + if [ "$ret" == 0 ]; then + run_check "$TOP/btrfs" check "$TEST_DEV" fi - return $ret + return "$ret" } # Invalid: Unaligned sectorsize and nodesize diff --git a/tests/mkfs-tests/010-minimal-size/test.sh b/tests/mkfs-tests/010-minimal-size/test.sh index 582533c3..0ebe0995 100755 --- a/tests/mkfs-tests/010-minimal-size/test.sh +++ b/tests/mkfs-tests/010-minimal-size/test.sh @@ -14,12 +14,12 @@ do_test() # the minimal device size for the given option combination prepare_test_dev 1M output=$(run_mustfail_stdout "mkfs.btrfs for small image" \ - "$TOP/mkfs.btrfs" -f $@ "$TEST_DEV") + "$TOP/mkfs.btrfs" -f "$@" "$TEST_DEV") good_size=$(echo "$output" | grep -oP "(?<=is )\d+") prepare_test_dev "$good_size" echo "Minimal device size is $good_size" >> "$RESULTS" - run_check $TOP/mkfs.btrfs -f $@ "$TEST_DEV" + run_check $TOP/mkfs.btrfs -f "$@" "$TEST_DEV" run_check_mount_test_dev run_check_umount_test_dev } diff --git a/tests/mkfs-tests/012-rootdir-no-shrink/test.sh b/tests/mkfs-tests/012-rootdir-no-shrink/test.sh index 045906ae..765f8cdd 100755 --- a/tests/mkfs-tests/012-rootdir-no-shrink/test.sh +++ b/tests/mkfs-tests/012-rootdir-no-shrink/test.sh @@ -11,7 +11,7 @@ fs_size=$((512 * 1024 * 1024)) bs=$((1024 * 1024)) tmp=$(mktemp -d --tmpdir btrfs-progs-mkfs.rootdirXXXXXXX) -prepare_test_dev $fs_size +prepare_test_dev "$fs_size" # No shrink case @@ -20,7 +20,7 @@ run_check_mount_test_dev # We should be able to write at least half of the fs size data since the fs is # not shrunk -run_check $SUDO_HELPER dd if=/dev/zero bs=$bs count=$(($fs_size / $bs / 2)) \ +run_check $SUDO_HELPER dd if=/dev/zero bs="$bs" count=$(($fs_size / $bs / 2)) \ of="$TEST_MNT/file" run_check_umount_test_dev @@ -31,7 +31,7 @@ run_check "$TOP/mkfs.btrfs" -f --rootdir "$tmp" --shrink "$TEST_DEV" run_check_mount_test_dev run_mustfail "mkfs.btrfs for shrink rootdir" \ - $SUDO_HELPER dd if=/dev/zero bs=$bs count=$(($fs_size / $bs / 2)) \ + $SUDO_HELPER dd if=/dev/zero bs="$bs" count=$(($fs_size / $bs / 2)) \ of="$TEST_MNT/file" run_check_umount_test_dev diff --git a/tests/mkfs-tests/013-reserved-1M-for-single/test.sh b/tests/mkfs-tests/013-reserved-1M-for-single/test.sh index caeb7d59..1944ad93 100755 --- a/tests/mkfs-tests/013-reserved-1M-for-single/test.sh +++ b/tests/mkfs-tests/013-reserved-1M-for-single/test.sh @@ -22,14 +22,14 @@ do_one_test () dump-tree -t device "$TEST_DEV" | \ grep -oP '(?<=DEV_EXTENT )[[:digit:]]*' | head -n1) - if [ -z $first_dev_extent ]; then + if [ -z "$first_dev_extent" ]; then _fail "failed to get first device extent" fi echo "first dev extent starts at $first_dev_extent" >> "$RESULTS" echo "reserved range is [0, $(( 1024 * 1024)))" >> "$RESULTS" # First device extent should not start below 1M - if [ $first_dev_extent -lt $(( 1024 * 1024 )) ]; then + if [ "$first_dev_extent" -lt $(( 1024 * 1024 )) ]; then _fail "first device extent occupies reserved 0~1M range" fi } diff --git a/tests/mkfs-tests/014-rootdir-inline-extent/test.sh b/tests/mkfs-tests/014-rootdir-inline-extent/test.sh index b337e493..09a96004 100755 --- a/tests/mkfs-tests/014-rootdir-inline-extent/test.sh +++ b/tests/mkfs-tests/014-rootdir-inline-extent/test.sh @@ -21,7 +21,7 @@ create_file() test_mkfs_rootdir() { nodesize=$1 - run_check "$TOP/mkfs.btrfs" --nodesize $nodesize -f --rootdir "$tmp" \ + run_check "$TOP/mkfs.btrfs" --nodesize "$nodesize" -f --rootdir "$tmp" \ "$TEST_DEV" run_check $SUDO_HELPER "$TOP/btrfs" check "$TEST_DEV" } @@ -39,8 +39,8 @@ for i in 512 1024 2048 4096 8192 16384 32768; do done for nodesize in 4096 8192 16384 32768 65536; do - if [ $nodesize -ge $pagesize ]; then - test_mkfs_rootdir $nodesize + if [ "$nodesize" -ge "$pagesize" ]; then + test_mkfs_rootdir "$nodesize" fi done rm -rf -- "$tmp" -- cgit v1.2.3 From dcb174ce2e2c9be1eaad73757d0312246560ba3d Mon Sep 17 00:00:00 2001 From: David Sterba Date: Fri, 23 Mar 2018 16:34:30 +0100 Subject: btrfs-progs: tests: add shell quotes to misc test scripts Signed-off-by: David Sterba --- tests/misc-tests/001-btrfstune-features/test.sh | 13 +++-- tests/misc-tests/002-uuid-rewrite/test.sh | 40 ++++++------- tests/misc-tests/003-zero-log/test.sh | 24 ++++---- tests/misc-tests/004-shrink-fs/test.sh | 36 ++++++------ .../005-convert-progress-thread-crash/test.sh | 6 +- .../misc-tests/006-image-on-missing-device/test.sh | 22 +++---- tests/misc-tests/007-subvolume-sync/test.sh | 18 +++--- tests/misc-tests/008-leaf-crossing-stripes/test.sh | 4 +- .../009-subvolume-sync-must-wait/test.sh | 28 ++++----- .../010-convert-delete-ext2-subvol/test.sh | 10 ++-- tests/misc-tests/011-delete-missing-device/test.sh | 22 +++---- tests/misc-tests/012-find-root-no-result/test.sh | 4 +- tests/misc-tests/013-subvolume-sync-crash/test.sh | 24 ++++---- tests/misc-tests/014-filesystem-label/test.sh | 24 ++++---- tests/misc-tests/015-dump-super-garbage/test.sh | 18 +++--- tests/misc-tests/016-send-clone-src/test.sh | 12 ++-- tests/misc-tests/018-recv-end-of-stream/test.sh | 68 +++++++++++----------- .../019-receive-clones-on-mounted-subvol/test.sh | 4 +- tests/misc-tests/021-image-multi-devices/test.sh | 22 +++---- .../023-device-usage-with-missing-device/test.sh | 6 +- .../misc-tests/024-inspect-internal-rootid/test.sh | 6 +- tests/misc-tests/028-superblock-recover/test.sh | 4 +- 22 files changed, 208 insertions(+), 207 deletions(-) (limited to 'tests') diff --git a/tests/misc-tests/001-btrfstune-features/test.sh b/tests/misc-tests/001-btrfstune-features/test.sh index 718e4b08..e3da3949 100755 --- a/tests/misc-tests/001-btrfstune-features/test.sh +++ b/tests/misc-tests/001-btrfstune-features/test.sh @@ -21,21 +21,22 @@ test_feature() local tuneopt local sbflag - mkfsfeatures=${1:+-O ^$1} + mkfsfeatures=$1 tuneopt="$2" sbflag="$3" - run_check $SUDO_HELPER $TOP/mkfs.btrfs -f $mkfsfeatures $TEST_DEV - if run_check_stdout $TOP/btrfs inspect-internal dump-super $TEST_DEV | \ + run_check $SUDO_HELPER "$TOP/mkfs.btrfs" -f \ + ${mkfsfeatures:+-O ^"$mkfsfeatures"} "$TEST_DEV" + if run_check_stdout "$TOP/btrfs" inspect-internal dump-super "$TEST_DEV" | \ grep -q "$sbflag"; then _fail "FAIL: feature $sbflag must not be set on the base image" fi - run_check $TOP/btrfstune $tuneopt $TEST_DEV - if ! run_check_stdout $TOP/btrfs inspect-internal dump-super $TEST_DEV | \ + run_check "$TOP/btrfstune" "$tuneopt" "$TEST_DEV" + if ! run_check_stdout "$TOP/btrfs" inspect-internal dump-super "$TEST_DEV" | \ grep -q "$sbflag"; then _fail "FAIL: feature $sbflag not set" fi - run_check $SUDO_HELPER $TOP/btrfs check $TEST_DEV + run_check $SUDO_HELPER "$TOP/btrfs" check "$TEST_DEV" } test_feature extref -r EXTENDED_IREF diff --git a/tests/misc-tests/002-uuid-rewrite/test.sh b/tests/misc-tests/002-uuid-rewrite/test.sh index 8e7011a8..0191bd5c 100755 --- a/tests/misc-tests/002-uuid-rewrite/test.sh +++ b/tests/misc-tests/002-uuid-rewrite/test.sh @@ -10,7 +10,7 @@ check_prereq btrfs prepare_test_dev get_fs_uuid() { - run_check_stdout $TOP/btrfs inspect-internal dump-super "$1" | \ + run_check_stdout "$TOP/btrfs" inspect-internal dump-super "$1" | \ grep '^fsid' | awk '{print $2}' } @@ -20,18 +20,18 @@ test_uuid_random() origuuid=11111111-a101-4031-b29a-379d4f8b7a2d - run_check $SUDO_HELPER $TOP/mkfs.btrfs -f \ - --uuid $origuuid \ - --rootdir $INTERNAL_BIN/Documentation \ - $TEST_DEV - run_check $TOP/btrfs inspect-internal dump-super "$TEST_DEV" - currentfsid=$(run_check_stdout $TOP/btrfstune -f -u $TEST_DEV | \ + run_check $SUDO_HELPER "$TOP/mkfs.btrfs" -f \ + --uuid "$origuuid" \ + --rootdir "$INTERNAL_BIN/Documentation" \ + "$TEST_DEV" + run_check "$TOP/btrfs" inspect-internal dump-super "$TEST_DEV" + currentfsid=$(run_check_stdout "$TOP/btrfstune" -f -u "$TEST_DEV" | \ grep -i 'current fsid:' | awk '{print $3}') - if ! [ $currentfsid = $origuuid ]; then + if ! [ "$currentfsid" = "$origuuid" ]; then _fail "FAIL: current UUID mismatch" fi - run_check $TOP/btrfs inspect-internal dump-super "$TEST_DEV" - run_check $SUDO_HELPER $TOP/btrfs check $TEST_DEV + run_check "$TOP/btrfs" inspect-internal dump-super "$TEST_DEV" + run_check $SUDO_HELPER "$TOP/btrfs" check "$TEST_DEV" } test_uuid_user() @@ -42,19 +42,19 @@ test_uuid_user() origuuid=22222222-d324-4f92-80e9-7658bf3b845f newuuid=33333333-bfc9-4045-9399-a396dc6893b3 - run_check $SUDO_HELPER $TOP/mkfs.btrfs -f \ - --uuid $origuuid \ - --rootdir $INTERNAL_BIN/Documentation \ - $TEST_DEV - run_check $TOP/btrfs inspect-internal dump-super "$TEST_DEV" - run_check $TOP/btrfstune -f -U $newuuid \ - $TEST_DEV + run_check $SUDO_HELPER "$TOP/mkfs.btrfs" -f \ + --uuid "$origuuid" \ + --rootdir "$INTERNAL_BIN/Documentation" \ + "$TEST_DEV" + run_check "$TOP/btrfs" inspect-internal dump-super "$TEST_DEV" + run_check "$TOP/btrfstune" -f -U "$newuuid" \ + "$TEST_DEV" # btrfs inspect-internal dump-super is called within get_fs_uuid - fsid=$(get_fs_uuid $TEST_DEV) - if ! [ $fsid = $newuuid ]; then + fsid=$(get_fs_uuid "$TEST_DEV") + if ! [ "$fsid" = "$newuuid" ]; then _fail "FAIL: UUID not rewritten" fi - run_check $SUDO_HELPER $TOP/btrfs check $TEST_DEV + run_check $SUDO_HELPER "$TOP/btrfs" check "$TEST_DEV" } test_uuid_random diff --git a/tests/misc-tests/003-zero-log/test.sh b/tests/misc-tests/003-zero-log/test.sh index 51cf6ae4..b24616a9 100755 --- a/tests/misc-tests/003-zero-log/test.sh +++ b/tests/misc-tests/003-zero-log/test.sh @@ -9,36 +9,36 @@ prepare_test_dev get_log_root() { - $TOP/btrfs inspect-internal dump-super "$1" | \ + "$TOP/btrfs" inspect-internal dump-super "$1" | \ grep '^log_root\>' | awk '{print $2}' } get_log_root_level() { - $TOP/btrfs inspect-internal dump-super "$1" | \ + "$TOP/btrfs" inspect-internal dump-super "$1" | \ grep '^log_root_level' | awk '{print $2}' } test_zero_log() { # FIXME: we need an image with existing log_root - run_check $SUDO_HELPER $TOP/mkfs.btrfs -f \ - --rootdir $INTERNAL_BIN/Documentation \ - $TEST_DEV - run_check $TOP/btrfs inspect-internal dump-super $TEST_DEV + run_check $SUDO_HELPER "$TOP/mkfs.btrfs" -f \ + --rootdir "$INTERNAL_BIN/Documentation" \ + "$TEST_DEV" + run_check "$TOP/btrfs" inspect-internal dump-super "$TEST_DEV" if [ "$1" = 'standalone' ]; then - run_check $TOP/btrfs rescue zero-log $TEST_DEV + run_check "$TOP/btrfs" rescue zero-log "$TEST_DEV" else - run_check $TOP/btrfs-zero-log $TEST_DEV + run_check "$TOP/btrfs-zero-log" "$TEST_DEV" fi - log_root=$(get_log_root $TEST_DEV) - log_root_level=$(get_log_root $TEST_DEV) + log_root=$(get_log_root "$TEST_DEV") + log_root_level=$(get_log_root "$TEST_DEV") if [ "$log_root" != 0 ]; then _fail "FAIL: log_root not reset" fi if [ "$log_root_level" != 0 ]; then _fail "FAIL: log_root_level not reset" fi - run_check $TOP/btrfs inspect-internal dump-super $TEST_DEV - run_check $SUDO_HELPER $TOP/btrfs check $TEST_DEV + run_check "$TOP/btrfs" inspect-internal dump-super "$TEST_DEV" + run_check $SUDO_HELPER "$TOP/btrfs" check "$TEST_DEV" } test_zero_log standalone diff --git a/tests/misc-tests/004-shrink-fs/test.sh b/tests/misc-tests/004-shrink-fs/test.sh index 2f08b0b0..4117f037 100755 --- a/tests/misc-tests/004-shrink-fs/test.sh +++ b/tests/misc-tests/004-shrink-fs/test.sh @@ -14,45 +14,45 @@ setup_root_helper # Optionally take id of the device to shrink shrink_test() { - min_size=$(run_check_stdout $SUDO_HELPER $TOP/btrfs inspect-internal min-dev-size ${1:+--id $1} $TEST_MNT) - min_size=$(echo $min_size | cut -d ' ' -f 1) - echo "min size = ${min_size}" >> $RESULTS + min_size=$(run_check_stdout $SUDO_HELPER "$TOP/btrfs" inspect-internal min-dev-size ${1:+--id "$1"} "$TEST_MNT") + min_size=$(echo "$min_size" | cut -d ' ' -f 1) + echo "min size = ${min_size}" >> "$RESULTS" if [ -z "$min_size" ]; then _fail "Failed to parse minimum size" fi - run_check $SUDO_HELPER $TOP/btrfs filesystem resize $min_size $TEST_MNT + run_check $SUDO_HELPER "$TOP/btrfs" filesystem resize "$min_size" "$TEST_MNT" } -run_check truncate -s 20G $IMAGE -run_check $TOP/mkfs.btrfs -f $IMAGE -run_check $SUDO_HELPER mount $IMAGE $TEST_MNT -run_check $SUDO_HELPER chmod a+rw $TEST_MNT +run_check truncate -s 20G "$IMAGE" +run_check "$TOP/mkfs.btrfs" -f "$IMAGE" +run_check $SUDO_HELPER mount "$IMAGE" "$TEST_MNT" +run_check $SUDO_HELPER chmod a+rw "$TEST_MNT" # Create 7 data block groups, each with a size of 1Gb. for ((i = 1; i <= 7; i++)); do - run_check fallocate -l 1G $TEST_MNT/foo$i + run_check fallocate -l 1G "$TEST_MNT/foo$i" done # Make sure they are persisted (all the chunk, device and block group items # added to the chunk/dev/extent trees). -run_check $TOP/btrfs filesystem sync $TEST_MNT +run_check "$TOP/btrfs" filesystem sync "$TEST_MNT" # Now remove 3 of those 1G files. This will result in 3 block groups becoming # unused, which will be automatically deleted by the cleaner kthread, and this # will result in 3 holes (unallocated space) in the device (each with a size # of 1Gb). -run_check rm -f $TEST_MNT/foo2 -run_check rm -f $TEST_MNT/foo4 -run_check rm -f $TEST_MNT/foo6 +run_check rm -f "$TEST_MNT/foo2" +run_check rm -f "$TEST_MNT/foo4" +run_check rm -f "$TEST_MNT/foo6" # Sync once to wake up the cleaner kthread which will delete the unused block # groups - it could have been sleeping when they became unused. Then wait a bit # to allow the cleaner kthread to delete them and then finally ensure the # transaction started by the cleaner kthread is committed. -run_check $TOP/btrfs filesystem sync $TEST_MNT +run_check "$TOP/btrfs" filesystem sync "$TEST_MNT" sleep 3 -run_check $TOP/btrfs filesystem sync $TEST_MNT +run_check "$TOP/btrfs" filesystem sync "$TEST_MNT" # Now attempt to get the minimum size we can resize the filesystem to and verify # the resize operation succeeds. This size closely matches the sum of the size @@ -63,10 +63,10 @@ done # Now convert metadata and system chunks to the single profile and check we are # still able to get a correct minimum size and shrink to that size. -run_check $SUDO_HELPER $TOP/btrfs balance start -mconvert=single \ - -sconvert=single -f $TEST_MNT +run_check $SUDO_HELPER "$TOP/btrfs" balance start -mconvert=single \ + -sconvert=single -f "$TEST_MNT" for ((i = 1; i <= 3; i++)); do shrink_test 1 done -run_check $SUDO_HELPER umount $TEST_MNT +run_check $SUDO_HELPER umount "$TEST_MNT" diff --git a/tests/misc-tests/005-convert-progress-thread-crash/test.sh b/tests/misc-tests/005-convert-progress-thread-crash/test.sh index b8012c9f..dcd6fd26 100755 --- a/tests/misc-tests/005-convert-progress-thread-crash/test.sh +++ b/tests/misc-tests/005-convert-progress-thread-crash/test.sh @@ -9,7 +9,7 @@ mkfs.ext4 -V &>/dev/null || _not_run "mkfs.ext4 not found" prepare_test_dev for ((i = 0; i < 20; i++)); do - echo "loop $i" >>$RESULTS - mkfs.ext4 -F "$TEST_DEV" &>>$RESULTS || _not_run "mkfs.ext4 failed" - run_check $TOP/btrfs-convert "$TEST_DEV" + echo "loop $i" >> "$RESULTS" + mkfs.ext4 -F "$TEST_DEV" &>>"$RESULTS" || _not_run "mkfs.ext4 failed" + run_check "$TOP/btrfs-convert" "$TEST_DEV" done diff --git a/tests/misc-tests/006-image-on-missing-device/test.sh b/tests/misc-tests/006-image-on-missing-device/test.sh index d8b1cef2..2b222340 100755 --- a/tests/misc-tests/006-image-on-missing-device/test.sh +++ b/tests/misc-tests/006-image-on-missing-device/test.sh @@ -14,29 +14,29 @@ setup_root_helper test_image_dump() { - run_check $SUDO_HELPER $TOP/btrfs check $dev1 + run_check $SUDO_HELPER "$TOP/btrfs" check "$dev1" # the output file will be deleted - run_mayfail $SUDO_HELPER $TOP/btrfs-image $dev1 /tmp/test-img.dump + run_mayfail $SUDO_HELPER "$TOP/btrfs-image" "$dev1" /tmp/test-img.dump } test_run() { - run_check $SUDO_HELPER $TOP/mkfs.btrfs -f -d raid1 -m raid1 $dev1 $dev2 + run_check $SUDO_HELPER "$TOP/mkfs.btrfs" -f -d raid1 -m raid1 "$dev1" "$dev2" # we need extents to trigger reading from all devices - run_check $SUDO_HELPER mount $dev1 $TEST_MNT - run_check $SUDO_HELPER dd if=/dev/zero of=$TEST_MNT/a bs=1M count=10 - run_check $SUDO_HELPER dd if=/dev/zero of=$TEST_MNT/b bs=4k count=1000 conv=sync - run_check $SUDO_HELPER umount $TEST_MNT + run_check $SUDO_HELPER mount "$dev1" "$TEST_MNT" + run_check $SUDO_HELPER dd if=/dev/zero of="$TEST_MNT/a" bs=1M count=10 + run_check $SUDO_HELPER dd if=/dev/zero of="$TEST_MNT/b" bs=4k count=1000 conv=sync + run_check $SUDO_HELPER umount "$TEST_MNT" test_image_dump - run_check $SUDO_HELPER $TOP/btrfs filesystem show $dev1 + run_check $SUDO_HELPER "$TOP/btrfs" filesystem show "$dev1" # create a degraded raid1 filesystem, check must succeed # btrfs-image must not loop - run_mayfail wipefs -a $dev2 - run_check $SUDO_HELPER losetup -d $dev2 + run_mayfail wipefs -a "$dev2" + run_check $SUDO_HELPER losetup -d "$dev2" unset loopdevs[2] - run_check $SUDO_HELPER $TOP/btrfs filesystem show $dev1 + run_check $SUDO_HELPER "$TOP/btrfs" filesystem show "$dev1" test_image_dump } diff --git a/tests/misc-tests/007-subvolume-sync/test.sh b/tests/misc-tests/007-subvolume-sync/test.sh index ef03d16b..104b50ea 100755 --- a/tests/misc-tests/007-subvolume-sync/test.sh +++ b/tests/misc-tests/007-subvolume-sync/test.sh @@ -12,21 +12,21 @@ check_prereq btrfs setup_root_helper prepare_test_dev -run_check $SUDO_HELPER $TOP/mkfs.btrfs -f "$TEST_DEV" +run_check $SUDO_HELPER "$TOP/mkfs.btrfs" -f "$TEST_DEV" run_check_mount_test_dev # to check following thing in both 1 and multiple subvolume case: # 1: is subvolume sync loop indefinitely # 2: is return value right # -run_check $SUDO_HELPER $TOP/btrfs subvolume create "$TEST_MNT"/mysubvol1 -run_check $SUDO_HELPER $TOP/btrfs subvolume create "$TEST_MNT"/mysubvol2 -run_check $SUDO_HELPER $TOP/btrfs subvolume delete "$TEST_MNT"/mysubvol1 -run_check $SUDO_HELPER $TOP/btrfs subvolume delete "$TEST_MNT"/mysubvol2 -run_check $SUDO_HELPER $TOP/btrfs subvolume sync "$TEST_MNT" +run_check $SUDO_HELPER "$TOP/btrfs" subvolume create "$TEST_MNT"/mysubvol1 +run_check $SUDO_HELPER "$TOP/btrfs" subvolume create "$TEST_MNT"/mysubvol2 +run_check $SUDO_HELPER "$TOP/btrfs" subvolume delete "$TEST_MNT"/mysubvol1 +run_check $SUDO_HELPER "$TOP/btrfs" subvolume delete "$TEST_MNT"/mysubvol2 +run_check $SUDO_HELPER "$TOP/btrfs" subvolume sync "$TEST_MNT" -run_check $SUDO_HELPER $TOP/btrfs subvolume create "$TEST_MNT"/mysubvol -run_check $SUDO_HELPER $TOP/btrfs subvolume delete "$TEST_MNT"/mysubvol -run_check $SUDO_HELPER $TOP/btrfs subvolume sync "$TEST_MNT" +run_check $SUDO_HELPER "$TOP/btrfs" subvolume create "$TEST_MNT"/mysubvol +run_check $SUDO_HELPER "$TOP/btrfs" subvolume delete "$TEST_MNT"/mysubvol +run_check $SUDO_HELPER "$TOP/btrfs" subvolume sync "$TEST_MNT" run_check_umount_test_dev diff --git a/tests/misc-tests/008-leaf-crossing-stripes/test.sh b/tests/misc-tests/008-leaf-crossing-stripes/test.sh index 517bd667..41825439 100755 --- a/tests/misc-tests/008-leaf-crossing-stripes/test.sh +++ b/tests/misc-tests/008-leaf-crossing-stripes/test.sh @@ -15,8 +15,8 @@ A_PRIME_NUM=17 for ((size = SIZE_FROM; size <= SIZE_END; size += A_PRIME_NUM)); do run_check truncate -s "$size"M "$IMAGE" run_check mkfs.ext4 -F "$IMAGE" - run_check $TOP/btrfs-convert "$IMAGE" - run_check_stdout $TOP/btrfs check "$IMAGE" 2>&1 | + run_check "$TOP/btrfs-convert" "$IMAGE" + run_check_stdout "$TOP/btrfs" check "$IMAGE" 2>&1 | grep -q "crossing stripe boundary" && _fail "leaf crossing stripes after btrfs-convert" done diff --git a/tests/misc-tests/009-subvolume-sync-must-wait/test.sh b/tests/misc-tests/009-subvolume-sync-must-wait/test.sh index 15de3355..62190e14 100755 --- a/tests/misc-tests/009-subvolume-sync-must-wait/test.sh +++ b/tests/misc-tests/009-subvolume-sync-must-wait/test.sh @@ -10,41 +10,41 @@ check_prereq btrfs setup_root_helper prepare_test_dev -run_check $TOP/mkfs.btrfs -f "$TEST_DEV" +run_check "$TOP/mkfs.btrfs" -f "$TEST_DEV" run_check_mount_test_dev -run_check $SUDO_HELPER chmod a+rw $TEST_MNT +run_check $SUDO_HELPER chmod a+rw "$TEST_MNT" -cd $TEST_MNT +cd "$TEST_MNT" for i in `seq 5`; do run_check dd if=/dev/zero of=file$i bs=1M count=10 done for sn in `seq 4`;do - run_check $SUDO_HELPER $TOP/btrfs subvolume snapshot . snap$sn + run_check $SUDO_HELPER "$TOP/btrfs" subvolume snapshot . snap$sn for i in `seq 10`; do - run_check dd if=/dev/zero of=snap$sn/file$i bs=1M count=10 + run_check dd if=/dev/zero of="snap$sn/file$i" bs=1M count=10 done done -run_check $SUDO_HELPER $TOP/btrfs subvolume list . -run_check $SUDO_HELPER $TOP/btrfs subvolume list -d . +run_check $SUDO_HELPER "$TOP/btrfs" subvolume list . +run_check $SUDO_HELPER "$TOP/btrfs" subvolume list -d . -idtodel=`run_check_stdout $SUDO_HELPER $TOP/btrfs inspect-internal rootid snap3` +idtodel=`run_check_stdout $SUDO_HELPER "$TOP/btrfs" inspect-internal rootid snap3` # delete, sync after some time -run_check $SUDO_HELPER $TOP/btrfs subvolume delete -c snap3 -{ sleep 5; run_check $TOP/btrfs filesystem sync $TEST_MNT; } & +run_check $SUDO_HELPER "$TOP/btrfs" subvolume delete -c snap3 +{ sleep 5; run_check "$TOP/btrfs" filesystem sync "$TEST_MNT"; } & -run_check $SUDO_HELPER $TOP/btrfs subvolume sync . $idtodel +run_check $SUDO_HELPER "$TOP/btrfs" subvolume sync . "$idtodel" -if run_check_stdout $SUDO_HELPER $TOP/btrfs subvolume list -d . | +if run_check_stdout $SUDO_HELPER "$TOP/btrfs" subvolume list -d . | grep -q "ID $idtodel.*DELETED"; then _fail "sync did not wait for the subvolume cleanup" fi -run_check $TOP/btrfs filesystem sync $TEST_MNT -run_check $SUDO_HELPER $TOP/btrfs subvolume list -d . +run_check "$TOP/btrfs" filesystem sync "$TEST_MNT" +run_check $SUDO_HELPER "$TOP/btrfs" subvolume list -d . wait cd .. diff --git a/tests/misc-tests/010-convert-delete-ext2-subvol/test.sh b/tests/misc-tests/010-convert-delete-ext2-subvol/test.sh index 6d510fea..5f441a7f 100755 --- a/tests/misc-tests/010-convert-delete-ext2-subvol/test.sh +++ b/tests/misc-tests/010-convert-delete-ext2-subvol/test.sh @@ -13,13 +13,13 @@ prepare_test_dev run_check truncate -s 2G "$TEST_DEV" run_check mkfs.ext4 -F "$TEST_DEV" -run_check $TOP/btrfs-convert "$TEST_DEV" -run_check $SUDO_HELPER $TOP/btrfs inspect-internal dump-tree "$TEST_DEV" +run_check "$TOP/btrfs-convert" "$TEST_DEV" +run_check $SUDO_HELPER "$TOP/btrfs" inspect-internal dump-tree "$TEST_DEV" run_check_mount_test_dev -run_check $SUDO_HELPER $TOP/btrfs subvolume delete -c "$TEST_MNT/ext2_saved" +run_check $SUDO_HELPER "$TOP/btrfs" subvolume delete -c "$TEST_MNT/ext2_saved" run_check_umount_test_dev -run_check $SUDO_HELPER $TOP/btrfs inspect-internal dump-tree "$TEST_DEV" -run_check_stdout $TOP/btrfs-convert --rollback "$TEST_DEV" | +run_check $SUDO_HELPER "$TOP/btrfs" inspect-internal dump-tree "$TEST_DEV" +run_check_stdout "$TOP/btrfs-convert" --rollback "$TEST_DEV" | grep -q 'is it deleted' || _fail "unexpected rollback" exit 0 diff --git a/tests/misc-tests/011-delete-missing-device/test.sh b/tests/misc-tests/011-delete-missing-device/test.sh index 469c3be9..4c976421 100755 --- a/tests/misc-tests/011-delete-missing-device/test.sh +++ b/tests/misc-tests/011-delete-missing-device/test.sh @@ -10,31 +10,31 @@ setup_root_helper test_do_mkfs() { - run_check $SUDO_HELPER $TOP/mkfs.btrfs -f $@ ${loopdevs[@]} - run_check $SUDO_HELPER $TOP/btrfs inspect-internal dump-super $dev1 - run_check $SUDO_HELPER $TOP/btrfs check $dev1 - run_check $SUDO_HELPER $TOP/btrfs filesystem show + run_check $SUDO_HELPER "$TOP/mkfs.btrfs" -f "$@" ${loopdevs[@]} + run_check $SUDO_HELPER "$TOP/btrfs" inspect-internal dump-super "$dev1" + run_check $SUDO_HELPER "$TOP/btrfs" check "$dev1" + run_check $SUDO_HELPER "$TOP/btrfs" filesystem show } test_wipefs() { - run_check $SUDO_HELPER wipefs -a $devtodel - run_check $SUDO_HELPER losetup -d $devtodel + run_check $SUDO_HELPER wipefs -a "$devtodel" + run_check $SUDO_HELPER losetup -d "$devtodel" unset loopdevs[3] run_check $SUDO_HELPER losetup --all - run_check $TOP/btrfs filesystem show + run_check "$TOP/btrfs" filesystem show } test_delete_missing() { run_check_mount_test_dev -o degraded - run_check $SUDO_HELPER $TOP/btrfs filesystem show $TEST_MNT - run_check $SUDO_HELPER $TOP/btrfs device delete missing $TEST_MNT - run_check $SUDO_HELPER $TOP/btrfs filesystem show $TEST_MNT + run_check $SUDO_HELPER "$TOP/btrfs" filesystem show "$TEST_MNT" + run_check $SUDO_HELPER "$TOP/btrfs" device delete missing "$TEST_MNT" + run_check $SUDO_HELPER "$TOP/btrfs" filesystem show "$TEST_MNT" run_check_umount_test_dev run_check_mount_test_dev local out - out="$(run_check_stdout $SUDO_HELPER $TOP/btrfs filesystem show $TEST_MNT)" + out=$(run_check_stdout $SUDO_HELPER "$TOP/btrfs" filesystem show "$TEST_MNT") if echo "$out" | grep -q -- "$devtodel"; then _fail "device $devtodel not deleted" fi diff --git a/tests/misc-tests/012-find-root-no-result/test.sh b/tests/misc-tests/012-find-root-no-result/test.sh index f4a57e76..6dd447f3 100755 --- a/tests/misc-tests/012-find-root-no-result/test.sh +++ b/tests/misc-tests/012-find-root-no-result/test.sh @@ -8,10 +8,10 @@ source "$TEST_TOP/common" check_prereq btrfs-find-root check_prereq btrfs-image -run_check $TOP/btrfs-image -r first_meta_chunk.btrfs-image test.img || \ +run_check "$TOP/btrfs-image" -r first_meta_chunk.btrfs-image test.img || \ _fail "failed to extract first_meta_chunk.btrfs-image" -result=$(run_check_stdout $TOP/btrfs-find-root test.img | sed '/^Superblock/d') +result=$(run_check_stdout "$TOP/btrfs-find-root" test.img | sed '/^Superblock/d') if [ -z "$result" ]; then _fail "btrfs-find-root failed to find tree root" diff --git a/tests/misc-tests/013-subvolume-sync-crash/test.sh b/tests/misc-tests/013-subvolume-sync-crash/test.sh index 051b457a..c348ba5d 100755 --- a/tests/misc-tests/013-subvolume-sync-crash/test.sh +++ b/tests/misc-tests/013-subvolume-sync-crash/test.sh @@ -13,9 +13,9 @@ setup_root_helper prepare_test_dev run_check "$TOP/mkfs.btrfs" -f "$TEST_DEV" run_check_mount_test_dev -run_check $SUDO_HELPER chmod a+rw $TEST_MNT +run_check $SUDO_HELPER chmod a+rw "$TEST_MNT" -cd $TEST_MNT +cd "$TEST_MNT" for i in `seq 5`; do run_check dd if=/dev/zero of=file$i bs=1M count=10 @@ -23,25 +23,25 @@ done # 128 is minimum for sn in `seq 130`;do - run_check $SUDO_HELPER $TOP/btrfs subvolume snapshot . snap$sn + run_check $SUDO_HELPER "$TOP/btrfs" subvolume snapshot . snap$sn for i in `seq 10`; do - run_check dd if=/dev/zero of=snap$sn/file$i bs=1M count=1 + run_check dd if=/dev/zero of="snap$sn/file$i" bs=1M count=1 done done -run_check $SUDO_HELPER $TOP/btrfs subvolume list . -run_check $SUDO_HELPER $TOP/btrfs subvolume list -d . +run_check $SUDO_HELPER "$TOP/btrfs" subvolume list . +run_check $SUDO_HELPER "$TOP/btrfs" subvolume list -d . -idtodel=`run_check_stdout $SUDO_HELPER $TOP/btrfs inspect-internal rootid snap3` +idtodel=`run_check_stdout $SUDO_HELPER "$TOP/btrfs" inspect-internal rootid snap3` # delete, sync after some time -run_check $SUDO_HELPER $TOP/btrfs subvolume delete -c snap* -{ sleep 5; run_check $TOP/btrfs filesystem sync $TEST_MNT; } & +run_check $SUDO_HELPER "$TOP/btrfs" subvolume delete -c snap* +{ sleep 5; run_check "$TOP/btrfs" filesystem sync "$TEST_MNT"; } & -run_check $SUDO_HELPER $TOP/btrfs subvolume sync . +run_check $SUDO_HELPER "$TOP/btrfs" subvolume sync . -run_check $TOP/btrfs filesystem sync $TEST_MNT -run_check $SUDO_HELPER $TOP/btrfs subvolume list -d . +run_check "$TOP/btrfs" filesystem sync "$TEST_MNT" +run_check $SUDO_HELPER "$TOP/btrfs" subvolume list -d . wait cd .. diff --git a/tests/misc-tests/014-filesystem-label/test.sh b/tests/misc-tests/014-filesystem-label/test.sh index bd6773cb..4756e764 100755 --- a/tests/misc-tests/014-filesystem-label/test.sh +++ b/tests/misc-tests/014-filesystem-label/test.sh @@ -12,14 +12,14 @@ setup_root_helper prepare_test_dev run_check "$TOP/mkfs.btrfs" -L BTRFS-TEST-LABEL -f "$TEST_DEV" run_check_mount_test_dev -run_check $SUDO_HELPER chmod a+rw $TEST_MNT +run_check $SUDO_HELPER chmod a+rw "$TEST_MNT" -cd $TEST_MNT -run_check $SUDO_HELPER $TOP/btrfs filesystem label $TEST_MNT +cd "$TEST_MNT" +run_check $SUDO_HELPER "$TOP/btrfs" filesystem label "$TEST_MNT" # shortest label -run_check $SUDO_HELPER $TOP/btrfs filesystem label $TEST_MNT a -run_check $SUDO_HELPER $TOP/btrfs filesystem label $TEST_MNT -run_check $SUDO_HELPER $TOP/btrfs filesystem label $TEST_MNT '' +run_check $SUDO_HELPER "$TOP/btrfs" filesystem label "$TEST_MNT" a +run_check $SUDO_HELPER "$TOP/btrfs" filesystem label "$TEST_MNT" +run_check $SUDO_HELPER "$TOP/btrfs" filesystem label "$TEST_MNT" '' longlabel=\ 0123456789\ @@ -54,15 +54,15 @@ longlabel=\ \ 01234 -run_check $SUDO_HELPER $TOP/btrfs filesystem label $TEST_MNT "$longlabel" -run_check $SUDO_HELPER $TOP/btrfs filesystem label $TEST_MNT +run_check $SUDO_HELPER "$TOP/btrfs" filesystem label "$TEST_MNT" "$longlabel" +run_check $SUDO_HELPER "$TOP/btrfs" filesystem label "$TEST_MNT" # 256, must fail run_mustfail "label 256 bytes long succeeded" \ - $SUDO_HELPER $TOP/btrfs filesystem label $TEST_MNT "$longlabel"5 -run_check $SUDO_HELPER $TOP/btrfs filesystem label $TEST_MNT + $SUDO_HELPER "$TOP/btrfs" filesystem label "$TEST_MNT" "$longlabel"5 +run_check $SUDO_HELPER "$TOP/btrfs" filesystem label "$TEST_MNT" run_mustfail "label 2 * 255 bytes long succeeded" \ - $SUDO_HELPER $TOP/btrfs filesystem label $TEST_MNT "$longlabel$longlabel" -run_check $SUDO_HELPER $TOP/btrfs filesystem label $TEST_MNT + $SUDO_HELPER "$TOP/btrfs" filesystem label "$TEST_MNT" "$longlabel$longlabel" +run_check $SUDO_HELPER "$TOP/btrfs" filesystem label "$TEST_MNT" cd .. diff --git a/tests/misc-tests/015-dump-super-garbage/test.sh b/tests/misc-tests/015-dump-super-garbage/test.sh index 10d8d5b6..b3469459 100755 --- a/tests/misc-tests/015-dump-super-garbage/test.sh +++ b/tests/misc-tests/015-dump-super-garbage/test.sh @@ -6,12 +6,12 @@ source "$TEST_TOP/common" check_prereq btrfs -run_check $TOP/btrfs inspect-internal dump-super /dev/urandom -run_check $TOP/btrfs inspect-internal dump-super -a /dev/urandom -run_check $TOP/btrfs inspect-internal dump-super -fa /dev/urandom -run_check $TOP/btrfs inspect-internal dump-super -Ffa /dev/urandom -run_check $TOP/btrfs inspect-internal dump-super -Ffa /dev/urandom -run_check $TOP/btrfs inspect-internal dump-super -Ffa /dev/urandom -run_check $TOP/btrfs inspect-internal dump-super -Ffa /dev/urandom -run_check $TOP/btrfs inspect-internal dump-super -Ffa /dev/urandom -run_check $TOP/btrfs inspect-internal dump-super -Ffa /dev/urandom +run_check "$TOP/btrfs" inspect-internal dump-super /dev/urandom +run_check "$TOP/btrfs" inspect-internal dump-super -a /dev/urandom +run_check "$TOP/btrfs" inspect-internal dump-super -fa /dev/urandom +run_check "$TOP/btrfs" inspect-internal dump-super -Ffa /dev/urandom +run_check "$TOP/btrfs" inspect-internal dump-super -Ffa /dev/urandom +run_check "$TOP/btrfs" inspect-internal dump-super -Ffa /dev/urandom +run_check "$TOP/btrfs" inspect-internal dump-super -Ffa /dev/urandom +run_check "$TOP/btrfs" inspect-internal dump-super -Ffa /dev/urandom +run_check "$TOP/btrfs" inspect-internal dump-super -Ffa /dev/urandom diff --git a/tests/misc-tests/016-send-clone-src/test.sh b/tests/misc-tests/016-send-clone-src/test.sh index e4fa16a7..c993095e 100755 --- a/tests/misc-tests/016-send-clone-src/test.sh +++ b/tests/misc-tests/016-send-clone-src/test.sh @@ -17,28 +17,28 @@ run_check_mount_test_dev here=`pwd` cd "$TEST_MNT" || _fail "cannot chdir to TEST_MNT" -run_check $SUDO_HELPER $TOP/btrfs subvolume create subv-parent1 +run_check $SUDO_HELPER "$TOP/btrfs" subvolume create subv-parent1 for i in 1 2 3; do run_check $SUDO_HELPER dd if=/dev/zero of=subv-parent1/file1_$i bs=1M count=1 - run_check $SUDO_HELPER $TOP/btrfs subvolume snapshot -r subv-parent1 subv-snap1_$i + run_check $SUDO_HELPER "$TOP/btrfs" subvolume snapshot -r subv-parent1 subv-snap1_$i done -run_check $SUDO_HELPER $TOP/btrfs subvolume create subv-parent2 +run_check $SUDO_HELPER "$TOP/btrfs" subvolume create subv-parent2 for i in 1 2 3; do run_check $SUDO_HELPER dd if=/dev/zero of=subv-parent2/file2_$i bs=1M count=1 - run_check $SUDO_HELPER $TOP/btrfs subvolume snapshot -r subv-parent2 subv-snap2_$i + run_check $SUDO_HELPER "$TOP/btrfs" subvolume snapshot -r subv-parent2 subv-snap2_$i done truncate -s0 "$here"/send-stream.img chmod a+w "$here"/send-stream.img -run_check $SUDO_HELPER $TOP/btrfs send -f "$here"/send-stream.img \ +run_check $SUDO_HELPER "$TOP/btrfs" send -f "$here"/send-stream.img \ -c subv-snap1_1 -c subv-snap2_1 subv-snap1_[23] subv-snap2_[23] image=$(extract_image "$here"/multi-clone-src-v4.8.2.stream.xz) old_stream_size=`stat --format=%s "$image"` stream_size=`stat --format=%s "$here"/send-stream.img` -if [ $old_stream_size -lt $stream_size ]; then +if [ "$old_stream_size" -lt "$stream_size" ]; then run_check ls -l "$image" "$here"/send-stream.img _fail "sending stream size is bigger than old stream" fi diff --git a/tests/misc-tests/018-recv-end-of-stream/test.sh b/tests/misc-tests/018-recv-end-of-stream/test.sh index 79e735ea..0de7d3b6 100755 --- a/tests/misc-tests/018-recv-end-of-stream/test.sh +++ b/tests/misc-tests/018-recv-end-of-stream/test.sh @@ -19,24 +19,24 @@ test_full_empty_stream() { local str str="$here/stream-full-empty.stream" - run_check $TOP/mkfs.btrfs -f $TEST_DEV + run_check "$TOP/mkfs.btrfs" -f "$TEST_DEV" run_check_mount_test_dev cd "$TEST_MNT" || _fail "cannot chdir to TEST_MNT" - run_check $SUDO_HELPER $TOP/btrfs subvolume create subv1 - run_check $SUDO_HELPER $TOP/btrfs subvolume snapshot -r subv1 subv1-snap + run_check $SUDO_HELPER "$TOP/btrfs" subvolume create subv1 + run_check $SUDO_HELPER "$TOP/btrfs" subvolume snapshot -r subv1 subv1-snap truncate -s0 "$str" chmod a+w "$str" - run_check $SUDO_HELPER $TOP/btrfs send -f "$str" subv1-snap + run_check $SUDO_HELPER "$TOP/btrfs" send -f "$str" subv1-snap cd "$here" || _fail "cannot chdir back to test directory" run_check_umount_test_dev - run_check $TOP/mkfs.btrfs -f $TEST_DEV + run_check "$TOP/mkfs.btrfs" -f "$TEST_DEV" run_check_mount_test_dev - run_check $SUDO_HELPER $TOP/btrfs receive "$@" -v -f "$str" "$TEST_MNT" + run_check $SUDO_HELPER "$TOP/btrfs" receive "$@" -v -f "$str" "$TEST_MNT" run_check_umount_test_dev run_check rm -f -- "$str" @@ -46,28 +46,28 @@ test_full_simple_stream() { local str str="$here/stream-full-simple.stream" - run_check $TOP/mkfs.btrfs -f $TEST_DEV + run_check "$TOP/mkfs.btrfs" -f $TEST_DEV run_check_mount_test_dev cd "$TEST_MNT" || _fail "cannot chdir to TEST_MNT" - run_check $SUDO_HELPER $TOP/btrfs subvolume create subv1 + run_check $SUDO_HELPER "$TOP/btrfs" subvolume create subv1 for i in 1 2 3; do run_check $SUDO_HELPER dd if=/dev/zero of=subv1/file1_$i bs=1M count=1 done - run_check $SUDO_HELPER $TOP/btrfs subvolume snapshot -r subv1 subv1-snap + run_check $SUDO_HELPER "$TOP/btrfs" subvolume snapshot -r subv1 subv1-snap truncate -s0 "$str" chmod a+w "$str" - run_check $SUDO_HELPER $TOP/btrfs send -f "$str" subv1-snap + run_check $SUDO_HELPER "$TOP/btrfs" send -f "$str" subv1-snap cd "$here" || _fail "cannot chdir back to test directory" run_check_umount_test_dev - run_check $TOP/mkfs.btrfs -f $TEST_DEV + run_check "$TOP/mkfs.btrfs" -f "$TEST_DEV" run_check_mount_test_dev - run_check $SUDO_HELPER $TOP/btrfs receive "$@" -v -f "$str" "$TEST_MNT" + run_check $SUDO_HELPER "$TOP/btrfs" receive "$@" -v -f "$str" "$TEST_MNT" run_check_umount_test_dev run_check rm -f -- "$str" @@ -79,27 +79,27 @@ test_incr_empty_stream() { fstr="$here/stream-full-empty.stream" istr="$here/stream-incr-empty.stream" - run_check $TOP/mkfs.btrfs -f $TEST_DEV + run_check "$TOP/mkfs.btrfs" -f "$TEST_DEV" run_check_mount_test_dev cd "$TEST_MNT" || _fail "cannot chdir to TEST_MNT" - run_check $SUDO_HELPER $TOP/btrfs subvolume create subv1 - run_check $SUDO_HELPER $TOP/btrfs subvolume snapshot -r subv1 subv1-snap - run_check $SUDO_HELPER $TOP/btrfs subvolume snapshot -r subv1 subv2-snap + run_check $SUDO_HELPER "$TOP/btrfs" subvolume create subv1 + run_check $SUDO_HELPER "$TOP/btrfs" subvolume snapshot -r subv1 subv1-snap + run_check $SUDO_HELPER "$TOP/btrfs" subvolume snapshot -r subv1 subv2-snap truncate -s0 "$fstr" "$istr" chmod a+w "$fstr" "$istr" - run_check $SUDO_HELPER $TOP/btrfs send -f "$fstr" subv1-snap - run_check $SUDO_HELPER $TOP/btrfs send -p subv1-snap -f "$istr" subv2-snap + run_check $SUDO_HELPER "$TOP/btrfs" send -f "$fstr" subv1-snap + run_check $SUDO_HELPER "$TOP/btrfs" send -p subv1-snap -f "$istr" subv2-snap cd "$here" || _fail "cannot chdir back to test directory" run_check_umount_test_dev - run_check $TOP/mkfs.btrfs -f $TEST_DEV + run_check "$TOP/mkfs.btrfs" -f "$TEST_DEV" run_check_mount_test_dev - run_check $SUDO_HELPER $TOP/btrfs receive "$@" -v -f "$fstr" "$TEST_MNT" - run_check $SUDO_HELPER $TOP/btrfs receive "$@" -v -f "$istr" "$TEST_MNT" + run_check $SUDO_HELPER "$TOP/btrfs" receive "$@" -v -f "$fstr" "$TEST_MNT" + run_check $SUDO_HELPER "$TOP/btrfs" receive "$@" -v -f "$istr" "$TEST_MNT" run_check_umount_test_dev run_check rm -f -- "$fstr" "$istr" @@ -110,36 +110,36 @@ test_incr_simple_stream() { fstr="$here/stream-full-simple.stream" istr="$here/stream-incr-simple.stream" - run_check $TOP/mkfs.btrfs -f $TEST_DEV + run_check "$TOP/mkfs.btrfs" -f "$TEST_DEV" run_check_mount_test_dev cd "$TEST_MNT" || _fail "cannot chdir to TEST_MNT" - run_check $SUDO_HELPER $TOP/btrfs subvolume create subv1 + run_check $SUDO_HELPER "$TOP/btrfs" subvolume create subv1 for i in 1 2 3; do run_check $SUDO_HELPER dd if=/dev/zero of=subv1/file1_$i bs=1M count=1 done - run_check $SUDO_HELPER $TOP/btrfs subvolume snapshot -r subv1 subv1-snap + run_check $SUDO_HELPER "$TOP/btrfs" subvolume snapshot -r subv1 subv1-snap for i in 1 2 3; do run_check $SUDO_HELPER dd if=/dev/urandom of=subv1/file1_$i bs=1M count=1 done - run_check $SUDO_HELPER $TOP/btrfs subvolume snapshot -r subv1 subv2-snap + run_check $SUDO_HELPER "$TOP/btrfs" subvolume snapshot -r subv1 subv2-snap truncate -s0 "$fstr" "$istr" chmod a+w "$fstr" "$istr" - run_check $SUDO_HELPER $TOP/btrfs send -f "$fstr" subv1-snap - run_check $SUDO_HELPER $TOP/btrfs send -p subv1-snap -f "$istr" subv2-snap + run_check $SUDO_HELPER "$TOP/btrfs" send -f "$fstr" subv1-snap + run_check $SUDO_HELPER "$TOP/btrfs" send -p subv1-snap -f "$istr" subv2-snap cd "$here" || _fail "cannot chdir back to test directory" run_check_umount_test_dev - run_check $TOP/mkfs.btrfs -f $TEST_DEV + run_check "$TOP/mkfs.btrfs" -f "$TEST_DEV" run_check_mount_test_dev - run_check $SUDO_HELPER $TOP/btrfs receive "$@" -v -f "$fstr" "$TEST_MNT" - run_check $SUDO_HELPER $TOP/btrfs receive "$@" -v -f "$istr" "$TEST_MNT" + run_check $SUDO_HELPER "$TOP/btrfs" receive "$@" -v -f "$fstr" "$TEST_MNT" + run_check $SUDO_HELPER "$TOP/btrfs" receive "$@" -v -f "$istr" "$TEST_MNT" run_check_umount_test_dev run_check rm -f -- "$fstr" "$istr" @@ -151,7 +151,7 @@ test_incr_empty_stream test_incr_simple_stream extra_opt=-e -test_full_empty_stream $extra_opt -test_full_simple_stream $extra_opt -test_incr_empty_stream $extra_opt -test_incr_simple_stream $extra_opt +test_full_empty_stream "$extra_opt" +test_full_simple_stream "$extra_opt" +test_incr_empty_stream "$extra_opt" +test_incr_simple_stream "$extra_opt" diff --git a/tests/misc-tests/019-receive-clones-on-mounted-subvol/test.sh b/tests/misc-tests/019-receive-clones-on-mounted-subvol/test.sh index 60ec5cf9..6937163a 100755 --- a/tests/misc-tests/019-receive-clones-on-mounted-subvol/test.sh +++ b/tests/misc-tests/019-receive-clones-on-mounted-subvol/test.sh @@ -31,9 +31,9 @@ run_check $SUDO_HELPER "$TOP/btrfs" subvolume create "$TEST_MNT/baz" run_check $SUDO_HELPER "$TOP/btrfs" subvolume create "$TEST_MNT/snap" tr '\000' 'A' < /dev/null | - run_check $SUDO_HELPER dd of=$TEST_MNT/foo/file_a bs=$BLOCK_SIZE count=32 + run_check $SUDO_HELPER dd of="$TEST_MNT/foo/file_a" bs="$BLOCK_SIZE" count=32 tr '\000' 'B' < /dev/null | - run_check $SUDO_HELPER dd of=$TEST_MNT/bar/file_b bs=$BLOCK_SIZE count=32 + run_check $SUDO_HELPER dd of="$TEST_MNT/bar/file_b" bs="$BLOCK_SIZE" count=32 run_check $SUDO_HELPER cp --reflink=always "$TEST_MNT/foo/file_a" "$TEST_MNT/baz/file_a" run_check $SUDO_HELPER cp --reflink=always "$TEST_MNT/bar/file_b" "$TEST_MNT/baz/file_b" diff --git a/tests/misc-tests/021-image-multi-devices/test.sh b/tests/misc-tests/021-image-multi-devices/test.sh index d78c44fb..5430847f 100755 --- a/tests/misc-tests/021-image-multi-devices/test.sh +++ b/tests/misc-tests/021-image-multi-devices/test.sh @@ -20,31 +20,31 @@ loop2=$(run_check_stdout $SUDO_HELPER losetup --find --show dev2) # Create the test file system. -run_check $SUDO_HELPER "$TOP/mkfs.btrfs" -f $loop1 $loop2 -run_check $SUDO_HELPER mount $loop1 "$TEST_MNT" -run_check $SUDO_HELPER dd bs=1M count=1 if=/dev/zero "of=$TEST_MNT/foobar" +run_check $SUDO_HELPER "$TOP/mkfs.btrfs" -f "$loop1" "$loop2" +run_check $SUDO_HELPER mount "$loop1" "$TEST_MNT" +run_check $SUDO_HELPER dd bs=1M count=1 if=/dev/zero of="$TEST_MNT/foobar" orig_md5=$(run_check_stdout md5sum "$TEST_MNT/foobar" | cut -d ' ' -f 1) run_check $SUDO_HELPER umount "$TEST_MNT" # Create the image to restore later. -run_check $SUDO_HELPER "$TOP/btrfs-image" $loop1 "$IMAGE" +run_check $SUDO_HELPER "$TOP/btrfs-image" "$loop1" "$IMAGE" # Wipe out the filesystem from the devices, restore the image on a single # device, check everything works and file foobar is there and with 1Mb of # zeroes. -run_check $SUDO_HELPER wipefs -a $loop1 -run_check $SUDO_HELPER wipefs -a $loop2 +run_check $SUDO_HELPER wipefs -a "$loop1" +run_check $SUDO_HELPER wipefs -a "$loop2" -run_check $SUDO_HELPER $TOP/btrfs-image -r "$IMAGE" $loop1 +run_check $SUDO_HELPER "$TOP/btrfs-image" -r "$IMAGE" "$loop1" -run_check $SUDO_HELPER mount $loop1 "$TEST_MNT" +run_check $SUDO_HELPER mount "$loop1" "$TEST_MNT" new_md5=$(run_check_stdout md5sum "$TEST_MNT/foobar" | cut -d ' ' -f 1) run_check $SUDO_HELPER umount "$TEST_MNT" # Cleanup loop devices. -run_check $SUDO_HELPER losetup -d $loop1 -run_check $SUDO_HELPER losetup -d $loop2 +run_check $SUDO_HELPER losetup -d "$loop1" +run_check $SUDO_HELPER losetup -d "$loop2" rm -f dev1 dev2 # Compare the file digests. -[ $orig_md5 == $new_md5 ] || _fail "File digests do not match" +[ "$orig_md5" == "$new_md5" ] || _fail "File digests do not match" diff --git a/tests/misc-tests/023-device-usage-with-missing-device/test.sh b/tests/misc-tests/023-device-usage-with-missing-device/test.sh index 05894cfe..57b500c9 100755 --- a/tests/misc-tests/023-device-usage-with-missing-device/test.sh +++ b/tests/misc-tests/023-device-usage-with-missing-device/test.sh @@ -12,7 +12,7 @@ setup_root_helper test_run() { # empty filesystem, with enough redundancy so degraded mount works - run_check $SUDO_HELPER "$TOP/mkfs.btrfs" -f -d raid1 -m raid1 $dev1 $dev2 + run_check $SUDO_HELPER "$TOP/mkfs.btrfs" -f -d raid1 -m raid1 "$dev1" "$dev2" TEST_DEV="$dev1" run_check_mount_test_dev @@ -21,8 +21,8 @@ test_run() grep -q "slack.*16\\.00EiB" && _fail run_check_umount_test_dev - run_mayfail wipefs -a $dev2 - run_check $SUDO_HELPER losetup -d $dev2 + run_mayfail wipefs -a "$dev2" + run_check $SUDO_HELPER losetup -d "$dev2" unset loopdevs[2] run_check_mount_test_dev -o degraded,ro diff --git a/tests/misc-tests/024-inspect-internal-rootid/test.sh b/tests/misc-tests/024-inspect-internal-rootid/test.sh index 71e19044..ea0c6298 100755 --- a/tests/misc-tests/024-inspect-internal-rootid/test.sh +++ b/tests/misc-tests/024-inspect-internal-rootid/test.sh @@ -36,15 +36,15 @@ id6=$(run_check_stdout "$TOP/btrfs" inspect-internal rootid dir/file2) \ id7=$(run_check_stdout "$TOP/btrfs" inspect-internal rootid sub/file3) \ || { echo $id7; exit 1; } -if ! ([ $id1 -ne $id2 ] && [ $id1 -ne $id3 ] && [ $id2 -ne $id3 ]); then +if ! ([ "$id1" -ne "$id2" ] && [ "$id1" -ne "$id3" ] && [ "$id2" -ne "$id3" ]); then _fail "inspect-internal rootid: each subvolume must have different id" fi -if ! ([ $id1 -eq $id4 ] && [ $id1 -eq $id5 ] && [ $id1 -eq $id6 ]); then +if ! ([ "$id1" -eq "$id4" ] && [ "$id1" -eq "$id5" ] && [ "$id1" -eq "$id6" ]); then _fail "inspect-internal rootid: rootid mismatch found" fi -if ! ([ $id2 -eq $id7 ]); then +if ! ([ "$id2" -eq "$id7" ]); then _fail "inspect-internal rootid: rootid mismatch found" fi diff --git a/tests/misc-tests/028-superblock-recover/test.sh b/tests/misc-tests/028-superblock-recover/test.sh index a177e1e1..ee117d0f 100755 --- a/tests/misc-tests/028-superblock-recover/test.sh +++ b/tests/misc-tests/028-superblock-recover/test.sh @@ -25,9 +25,9 @@ function check_corruption { run_check $SUDO_HELPER dd bs=1K count=1 seek=$(($sb_offset + 1)) if=/dev/zero of="$TEST_DEV" conv=notrunc # if corrupting one of the sb copies, copy it over the initial superblock - if [ ! -z $source_sb ]; then + if [ ! -z "$source_sb" ]; then local shift_val=$((16 << $source_sb * 12 )) - run_check $SUDO_HELPER dd bs=1K count=4 seek=64 skip=$shift_val if="$TEST_DEV" of="$TEST_DEV" conv=notrunc + run_check $SUDO_HELPER dd bs=1K count=4 seek=64 skip="$shift_val" if="$TEST_DEV" of="$TEST_DEV" conv=notrunc fi # we can't use our mount helper, the following works for file image and -- cgit v1.2.3 From 3f42d56fcbc6420cf47bed601542a776b1bc7ca2 Mon Sep 17 00:00:00 2001 From: Qu Wenruo Date: Thu, 29 Mar 2018 09:26:44 +0800 Subject: btrfs-progs: tests: Test if mkfs.btrfs --rootdir can handle ng symlink Signed-off-by: Qu Wenruo Signed-off-by: David Sterba --- .../016-rootdir-bad-symbolic-link/test.sh | 26 ++++++++++++++++++++++ 1 file changed, 26 insertions(+) create mode 100755 tests/mkfs-tests/016-rootdir-bad-symbolic-link/test.sh (limited to 'tests') diff --git a/tests/mkfs-tests/016-rootdir-bad-symbolic-link/test.sh b/tests/mkfs-tests/016-rootdir-bad-symbolic-link/test.sh new file mode 100755 index 00000000..39387ec7 --- /dev/null +++ b/tests/mkfs-tests/016-rootdir-bad-symbolic-link/test.sh @@ -0,0 +1,26 @@ +#!/bin/bash +# Regression test for mkfs.btrfs --rootdir with dangling symlink (points to +# non-existing location) +# +# Since mkfs.btrfs --rootdir will just create symbolic link rather than +# follow it, we shouldn't hit any problem + +source "$TEST_TOP/common" + +check_prereq mkfs.btrfs +prepare_test_dev + +tmp=$(mktemp -d --tmpdir btrfs-progs-mkfs.rootdirXXXXXXX) + +non_existing="/no/such/file$RANDOM$RANDOM" + +if [ -f "$non_existing" ]; then + _not_run "Some one created $non_existing, which is not expect to exist" +fi + +run_check ln -sf "$non_existing" "$tmp/foobar" + +run_check "$TOP/mkfs.btrfs" -f --rootdir "$tmp" "$TEST_DEV" +run_check "$TOP/btrfs" check "$TEST_DEV" + +rm -rf -- "$tmp" -- cgit v1.2.3 From a4cd4ae0b38a79fdc61aebf81267d5e10bb39d8f Mon Sep 17 00:00:00 2001 From: Qu Wenruo Date: Fri, 30 Mar 2018 15:35:28 +0800 Subject: btrfs-progs: tests: Test if btrfs-image can handle RAID1 missing device Signed-off-by: Qu Wenruo Signed-off-by: David Sterba --- tests/misc-tests/030-missing-device-image/test.sh | 58 +++++++++++++++++++++++ 1 file changed, 58 insertions(+) create mode 100755 tests/misc-tests/030-missing-device-image/test.sh (limited to 'tests') diff --git a/tests/misc-tests/030-missing-device-image/test.sh b/tests/misc-tests/030-missing-device-image/test.sh new file mode 100755 index 00000000..a04efe8f --- /dev/null +++ b/tests/misc-tests/030-missing-device-image/test.sh @@ -0,0 +1,58 @@ +#!/bin/bash +# Test that btrfs-image can dump image correctly for a missing device (RAID1) +# +# At least for RAID1, btrfs-image should be able to handle one missing device +# without any problem + +source "$TEST_TOP/common" + +check_prereq btrfs-image +check_prereq mkfs.btrfs +check_prereq btrfs + +setup_root_helper +setup_loopdevs 2 +prepare_loopdevs +dev1=${loopdevs[1]} +dev2=${loopdevs[2]} + +# $1: device number to remove (either 1 or 2) +test_missing() +{ + local bad_num + local bad_dev + local good_num + local good_dev + + bad_num=$1 + bad_dev=${loopdevs[$bad_num]} + good_num=$((3 - $bad_num)) + good_dev=${loopdevs[$good_num]} + + run_check $SUDO_HELPER "$TOP/mkfs.btrfs" -f -d raid1 -m raid1 "$dev1" "$dev2" + + # fill the fs with some data, we could create space cache + run_check $SUDO_HELPER mount "$dev1" "$TEST_MNT" + run_check $SUDO_HELPER dd if=/dev/zero of="$TEST_MNT/a" bs=1M count=10 + run_check $SUDO_HELPER dd if=/dev/zero of="$TEST_MNT/b" bs=4k count=1000 conv=sync + run_check $SUDO_HELPER umount "$TEST_MNT" + + # make sure we have space cache + if ! run_check_stdout "$TOP/btrfs" inspect dump-tree -t root "$dev1" | + grep -q "EXTENT_DATA"; then + # Normally the above operation should create the space cache. + # If not, it may mean we have migrated to v2 cache by default + _not_run "unable to create v1 space cache" + fi + + # now wipe the device + run_check wipefs -fa "$bad_dev" + + # we don't care about the image but btrfs-image must not fail + run_check "$TOP/btrfs-image" "$good_dev" /dev/null +} + +# Test with either device missing, so we're ensured to hit missing device +test_missing 1 +test_missing 2 +cleanup_loopdevs -- cgit v1.2.3 From df9158f20d8950b996a3e9b5a4ac0f9b2ea034d3 Mon Sep 17 00:00:00 2001 From: Nikolay Borisov Date: Tue, 27 Mar 2018 10:45:44 +0300 Subject: btrfs-progs: Remove deprecated btrfs-zero-log standalone tool Its function has been subsumed by "btrfs rescue zero-log". Remove its source file and adjust make/tests soruces accordingly. Deprecated since 4.0. Issue: #97 Signed-off-by: Nikolay Borisov Signed-off-by: David Sterba --- tests/misc-tests.sh | 1 - tests/misc-tests/003-zero-log/test.sh | 6 +----- 2 files changed, 1 insertion(+), 6 deletions(-) (limited to 'tests') diff --git a/tests/misc-tests.sh b/tests/misc-tests.sh index 94703a3e..dad397ec 100755 --- a/tests/misc-tests.sh +++ b/tests/misc-tests.sh @@ -46,7 +46,6 @@ check_prereq btrfs-corrupt-block check_prereq btrfs-image check_prereq btrfstune check_prereq btrfs -check_prereq btrfs-zero-log check_prereq btrfs-find-root check_prereq btrfs-select-super check_kernel_support diff --git a/tests/misc-tests/003-zero-log/test.sh b/tests/misc-tests/003-zero-log/test.sh index b24616a9..c6742bf3 100755 --- a/tests/misc-tests/003-zero-log/test.sh +++ b/tests/misc-tests/003-zero-log/test.sh @@ -24,11 +24,7 @@ test_zero_log() --rootdir "$INTERNAL_BIN/Documentation" \ "$TEST_DEV" run_check "$TOP/btrfs" inspect-internal dump-super "$TEST_DEV" - if [ "$1" = 'standalone' ]; then - run_check "$TOP/btrfs" rescue zero-log "$TEST_DEV" - else - run_check "$TOP/btrfs-zero-log" "$TEST_DEV" - fi + run_check "$TOP/btrfs" rescue zero-log "$TEST_DEV" log_root=$(get_log_root "$TEST_DEV") log_root_level=$(get_log_root "$TEST_DEV") if [ "$log_root" != 0 ]; then -- cgit v1.2.3 From 5f53c23e7676e9fafb78fa166e3f00e143b5a2c5 Mon Sep 17 00:00:00 2001 From: Qu Wenruo Date: Tue, 3 Apr 2018 13:39:47 +0800 Subject: btrfs-progs: tests/fsck: Add test case to check if btrfs check can skip data csum verfication for metadata dump Signed-off-by: Qu Wenruo Signed-off-by: David Sterba --- .../031-metadatadump-check-data-csum/test.sh | 30 ++++++++++++++++++++++ 1 file changed, 30 insertions(+) create mode 100755 tests/fsck-tests/031-metadatadump-check-data-csum/test.sh (limited to 'tests') diff --git a/tests/fsck-tests/031-metadatadump-check-data-csum/test.sh b/tests/fsck-tests/031-metadatadump-check-data-csum/test.sh new file mode 100755 index 00000000..30b0b7a3 --- /dev/null +++ b/tests/fsck-tests/031-metadatadump-check-data-csum/test.sh @@ -0,0 +1,30 @@ +#!/bin/bash +# To check if "btrfs check" can detect metadata dump (restored by btrfs-iamge) +# and ignore --check-data-csum option + +source "$TEST_TOP/common" + +check_prereq btrfs +check_prereq mkfs.btrfs +check_prereq btrfs-image +setup_root_helper +prepare_test_dev + +run_check $SUDO_HELPER "$TOP/mkfs.btrfs" -f "$TEST_DEV" +run_check_mount_test_dev + +run_check $SUDO_HELPER dd if=/dev/urandom of="$TEST_MNT/file" bs=4k count=16 +run_check_umount_test_dev + +run_check $SUDO_HELPER "$TOP/btrfs-image" "$TEST_DEV" "restored_image" + +# use prepare_test_dev() to wipe all existing data on $TEST_DEV +# so there is no way that restored image could have mathcing data csum +prepare_test_dev + +run_check $SUDO_HELPER "$TOP/btrfs-image" -r "restored_image" "$TEST_DEV" + +# Should not report any error +run_check "$TOP/btrfs" check --check-data-csum "$TEST_DEV" + +rm -rf -- "restored_image*" -- cgit v1.2.3 From bd52df0502f1cd48a9469692684f396bc782d4e1 Mon Sep 17 00:00:00 2001 From: Su Yue Date: Tue, 8 May 2018 16:30:12 +0800 Subject: btrfs-progs: tests: add image with no extent with normal device size This new image misses one extent which leads lowmem mode to allocate new chunks in repair. Rename original image to no_extent_bad_dev.img. Because of its bad used bytes, it should let lowmem mode exclude blocks in repair. Due to problems of btrfs-image, choose xz as compression tool. Signed-off-by: Su Yue Signed-off-by: David Sterba --- tests/fsck-tests/014-no-extent-info/.lowmem_repairable | 0 tests/fsck-tests/014-no-extent-info/default_case.img | Bin 4096 -> 0 bytes tests/fsck-tests/014-no-extent-info/no_extent.raw.xz | Bin 0 -> 28084 bytes .../fsck-tests/014-no-extent-info/no_extent_bad_dev.img | Bin 0 -> 4096 bytes 4 files changed, 0 insertions(+), 0 deletions(-) create mode 100644 tests/fsck-tests/014-no-extent-info/.lowmem_repairable delete mode 100644 tests/fsck-tests/014-no-extent-info/default_case.img create mode 100644 tests/fsck-tests/014-no-extent-info/no_extent.raw.xz create mode 100644 tests/fsck-tests/014-no-extent-info/no_extent_bad_dev.img (limited to 'tests') diff --git a/tests/fsck-tests/014-no-extent-info/.lowmem_repairable b/tests/fsck-tests/014-no-extent-info/.lowmem_repairable new file mode 100644 index 00000000..e69de29b diff --git a/tests/fsck-tests/014-no-extent-info/default_case.img b/tests/fsck-tests/014-no-extent-info/default_case.img deleted file mode 100644 index 1ff27434..00000000 Binary files a/tests/fsck-tests/014-no-extent-info/default_case.img and /dev/null differ diff --git a/tests/fsck-tests/014-no-extent-info/no_extent.raw.xz b/tests/fsck-tests/014-no-extent-info/no_extent.raw.xz new file mode 100644 index 00000000..6e568a9c Binary files /dev/null and b/tests/fsck-tests/014-no-extent-info/no_extent.raw.xz differ diff --git a/tests/fsck-tests/014-no-extent-info/no_extent_bad_dev.img b/tests/fsck-tests/014-no-extent-info/no_extent_bad_dev.img new file mode 100644 index 00000000..1ff27434 Binary files /dev/null and b/tests/fsck-tests/014-no-extent-info/no_extent_bad_dev.img differ -- cgit v1.2.3 From 402ac7a14083130b5cae6a93ab2c80eddd5871a5 Mon Sep 17 00:00:00 2001 From: David Sterba Date: Tue, 8 May 2018 19:04:41 +0200 Subject: btrfs-progs: tests: update log markers Use visual markers that separate tests and individual commands run via the run_* helpers. Signed-off-by: David Sterba --- tests/cli-tests.sh | 2 +- tests/common | 10 +++++----- tests/convert-tests.sh | 2 +- tests/fsck-tests.sh | 2 +- tests/fuzz-tests.sh | 2 +- tests/misc-tests.sh | 2 +- tests/mkfs-tests.sh | 2 +- 7 files changed, 11 insertions(+), 11 deletions(-) (limited to 'tests') diff --git a/tests/cli-tests.sh b/tests/cli-tests.sh index 9e0fbae4..d302a93e 100755 --- a/tests/cli-tests.sh +++ b/tests/cli-tests.sh @@ -52,7 +52,7 @@ do name=$(basename "$i") cd "$i" if [ -x test.sh ]; then - echo "=== Entering $i" >> "$RESULTS" + echo "=== START TEST $i" >> "$RESULTS" echo " [TEST/cli] $name" ./test.sh if [ $? -ne 0 ]; then diff --git a/tests/common b/tests/common index 4b266c5b..7e4e09df 100644 --- a/tests/common +++ b/tests/common @@ -136,7 +136,7 @@ run_check() cmd=$(eval echo "\${$spec}") spec=$(_cmd_spec "${@:$spec}") set -- "${@:1:$(($ins-1))}" $spec "${@: $ins}" - echo "############### $@" >> "$RESULTS" 2>&1 + echo "====== RUN CHECK $@" >> "$RESULTS" 2>&1 if [[ $TEST_LOG =~ tty ]]; then echo "CMD: $@" > /dev/tty; fi if [ "$1" = 'root_helper' ]; then "$@" >> "$RESULTS" 2>&1 || _fail "failed: $@" @@ -158,7 +158,7 @@ run_check_stdout() cmd=$(eval echo "\${$spec}") spec=$(_cmd_spec "${@:$spec}") set -- "${@:1:$(($ins-1))}" $spec "${@: $ins}" - echo "############### $@" >> "$RESULTS" 2>&1 + echo "====== RUN CHECK $@" >> "$RESULTS" 2>&1 if [[ $TEST_LOG =~ tty ]]; then echo "CMD(stdout): $@" > /dev/tty; fi if [ "$1" = 'root_helper' ]; then "$@" 2>&1 | tee -a "$RESULTS" @@ -185,7 +185,7 @@ run_mayfail() cmd=$(eval echo "\${$spec}") spec=$(_cmd_spec "${@:$spec}") set -- "${@:1:$(($ins-1))}" $spec "${@: $ins}" - echo "############### $@" >> "$RESULTS" 2>&1 + echo "====== RUN MAYFAIL $@" >> "$RESULTS" 2>&1 if [[ $TEST_LOG =~ tty ]]; then echo "CMD(mayfail): $@" > /dev/tty; fi if [ "$1" = 'root_helper' ]; then "$@" >> "$RESULTS" 2>&1 @@ -226,7 +226,7 @@ run_mustfail() cmd=$(eval echo "\${$spec}") spec=$(_cmd_spec "${@:$spec}") set -- "${@:1:$(($ins-1))}" $spec "${@: $ins}" - echo "############### $@" >> "$RESULTS" 2>&1 + echo "====== RUN MUSTFAIL $@" >> "$RESULTS" 2>&1 if [[ $TEST_LOG =~ tty ]]; then echo "CMD(mustfail): $@" > /dev/tty; fi if [ "$1" = 'root_helper' ]; then "$@" >> "$RESULTS" 2>&1 @@ -272,7 +272,7 @@ run_mustfail_stdout() cmd=$(eval echo "\${$spec}") spec=$(_cmd_spec "${@:$spec}") set -- "${@:1:$(($ins-1))}" $spec "${@: $ins}" - echo "############### $@" >> "$RESULTS" 2>&1 + echo "====== RUN MUSTFAIL $@" >> "$RESULTS" 2>&1 if [[ $TEST_LOG =~ tty ]]; then echo "CMD(mustfail): $@" > /dev/tty; fi if [ "$1" = 'root_helper' ]; then "$@" 2>&1 > "$tmp_output" diff --git a/tests/convert-tests.sh b/tests/convert-tests.sh index 4bc915db..f6c94043 100755 --- a/tests/convert-tests.sh +++ b/tests/convert-tests.sh @@ -58,7 +58,7 @@ run_one_test() { testname=$(basename "$testdir") echo " [TEST/conv] $testname" cd "$testdir" - echo "=== Entering $testname" >> "$RESULTS" + echo "=== START TEST $testname" >> "$RESULTS" if [ -x test.sh ]; then # Only support custom test scripts ./test.sh diff --git a/tests/fsck-tests.sh b/tests/fsck-tests.sh index 14287bbe..8fbc2b4b 100755 --- a/tests/fsck-tests.sh +++ b/tests/fsck-tests.sh @@ -54,7 +54,7 @@ run_one_test() { testname="$1" echo " [TEST/fsck] $(basename $testname)" cd "$testname" - echo "=== Entering $testname" >> "$RESULTS" + echo "=== START TEST $testname" >> "$RESULTS" if [ -x test.sh ]; then # Type 2 ./test.sh diff --git a/tests/fuzz-tests.sh b/tests/fuzz-tests.sh index 7bc620f0..ae738710 100755 --- a/tests/fuzz-tests.sh +++ b/tests/fuzz-tests.sh @@ -51,7 +51,7 @@ do name=$(basename "$i") cd $i if [ -x test.sh ]; then - echo "=== Entering $i" >> "$RESULTS" + echo "=== START TEST $i" >> "$RESULTS" echo " [TEST/fuzz] $name" ./test.sh if [ $? -ne 0 ]; then diff --git a/tests/misc-tests.sh b/tests/misc-tests.sh index dad397ec..3e7b9e9b 100755 --- a/tests/misc-tests.sh +++ b/tests/misc-tests.sh @@ -57,7 +57,7 @@ for i in $(find "$TEST_TOP/misc-tests" -maxdepth 1 -mindepth 1 -type d \ do echo " [TEST/misc] $(basename $i)" cd "$i" - echo "=== Entering $i" >> "$RESULTS" + echo "=== START TEST $i" >> "$RESULTS" if [ -x test.sh ]; then ./test.sh if [ $? -ne 0 ]; then diff --git a/tests/mkfs-tests.sh b/tests/mkfs-tests.sh index 2ced4ac9..e76a805b 100755 --- a/tests/mkfs-tests.sh +++ b/tests/mkfs-tests.sh @@ -52,7 +52,7 @@ for i in $(find "$TEST_TOP/mkfs-tests" -maxdepth 1 -mindepth 1 -type d \ do echo " [TEST/mkfs] $(basename $i)" cd "$i" - echo "=== Entering $i" >> "$RESULTS" + echo "=== START TEST $i" >> "$RESULTS" if [ -x test.sh ]; then ./test.sh if [ $? -ne 0 ]; then -- cgit v1.2.3 From 0ef679720532fe97588c9d77f5a5f981b0150fe3 Mon Sep 17 00:00:00 2001 From: Qu Wenruo Date: Mon, 7 May 2018 15:46:28 +0800 Subject: btrfs-progs: tests: Add test case for dump-tree on heavily corrupted leaf Signed-off-by: Qu Wenruo Signed-off-by: David Sterba --- tests/misc-tests/032-bad-item-ptr/bad_item_ptr.raw.xz | Bin 0 -> 21964 bytes tests/misc-tests/032-bad-item-ptr/test.sh | 17 +++++++++++++++++ 2 files changed, 17 insertions(+) create mode 100644 tests/misc-tests/032-bad-item-ptr/bad_item_ptr.raw.xz create mode 100755 tests/misc-tests/032-bad-item-ptr/test.sh (limited to 'tests') diff --git a/tests/misc-tests/032-bad-item-ptr/bad_item_ptr.raw.xz b/tests/misc-tests/032-bad-item-ptr/bad_item_ptr.raw.xz new file mode 100644 index 00000000..7cf2e89f Binary files /dev/null and b/tests/misc-tests/032-bad-item-ptr/bad_item_ptr.raw.xz differ diff --git a/tests/misc-tests/032-bad-item-ptr/test.sh b/tests/misc-tests/032-bad-item-ptr/test.sh new file mode 100755 index 00000000..cfbfe1a5 --- /dev/null +++ b/tests/misc-tests/032-bad-item-ptr/test.sh @@ -0,0 +1,17 @@ +#!/bin/bash +# +# Verify that btrfs inspect dump-tree won't segfault on heavily corrupted +# tree leaf +# Issue: #128 + +source "$TEST_TOP/common" + +check_prereq btrfs + +check_image() { + run_check "$TOP/btrfs" inspect-internal dump-tree "$1" + run_mustfail "btrfs check failed to detect such corruption" \ + "$TOP/btrfs" check "$1" +} + +check_all_images -- cgit v1.2.3 From f841497b6085748262f10a96585836cd69070ba7 Mon Sep 17 00:00:00 2001 From: Lu Fengqi Date: Tue, 8 May 2018 13:48:03 +0800 Subject: btrfs-progs: tests: check btrfs qgroup parent-child relation output Since commit aaf2dac5ef37 ("btrfs-progs: qgroup: split update_qgroup to reduce arguments") cause qgroup show to output the wrong qgroup parent-child relationship, in addition to fixing the problem, a test case is needed to prevent the similar problem in the future. Signed-off-by: Lu Fengqi Reviewed-by: Qu Wenruo Signed-off-by: David Sterba --- .../031-qgroup-parent-child-relation/test.sh | 27 ++++++++++++++++++++++ 1 file changed, 27 insertions(+) create mode 100755 tests/misc-tests/031-qgroup-parent-child-relation/test.sh (limited to 'tests') diff --git a/tests/misc-tests/031-qgroup-parent-child-relation/test.sh b/tests/misc-tests/031-qgroup-parent-child-relation/test.sh new file mode 100755 index 00000000..2d66fd60 --- /dev/null +++ b/tests/misc-tests/031-qgroup-parent-child-relation/test.sh @@ -0,0 +1,27 @@ +#!/bin/bash +# Test that btrfs 'qgroup show' outputs the correct parent-child qgroup relation + +source "$TEST_TOP/common" + +check_prereq mkfs.btrfs +check_prereq btrfs + +setup_root_helper +prepare_test_dev + +run_check $SUDO_HELPER "$TOP/mkfs.btrfs" -f "$TEST_DEV" +run_check_mount_test_dev + +run_check $SUDO_HELPER "$TOP/btrfs" quota enable "$TEST_MNT" +run_check $SUDO_HELPER "$TOP/btrfs" qgroup create 1/0 "$TEST_MNT" +run_check $SUDO_HELPER "$TOP/btrfs" qgroup assign 0/5 1/0 "$TEST_MNT" +run_check $SUDO_HELPER "$TOP/btrfs" quota rescan -w "$TEST_MNT" + +run_check_stdout $SUDO_HELPER "$TOP/btrfs" qgroup show --sort=-qgroupid \ + -p "$TEST_MNT" | tail -n 1 | grep -q "1/0" \ + || _fail "parent qgroup check failed, please check the log" +run_check_stdout $SUDO_HELPER "$TOP/btrfs" qgroup show --sort=qgroupid \ + -c "$TEST_MNT" | tail -n 1 | grep -q "0/5" \ + || _fail "child qgroup check failed, please check the log" + +run_check_umount_test_dev "$TEST_MNT" -- cgit v1.2.3 From 7e0ae73fb4dcbb8b3b76a47e708661ef9c4aea73 Mon Sep 17 00:00:00 2001 From: Qu Wenruo Date: Mon, 30 Apr 2018 14:17:00 +0800 Subject: btrfs-progs: tests: Add test case to ensure btrfs check returns error for corrupted qgroups Since the test case uses run_mustfail(), which is pretty easy pass due to other unexpected problems, so here an extra run_check() is added to ensure we don't only report qgroup error, but also fix it without problem. Signed-off-by: Qu Wenruo Signed-off-by: David Sterba --- .../032-corrupted-qgroup/qgroup_corrupted.img | Bin 0 -> 3072 bytes tests/fsck-tests/032-corrupted-qgroup/test.sh | 19 +++++++++++++++++++ 2 files changed, 19 insertions(+) create mode 100644 tests/fsck-tests/032-corrupted-qgroup/qgroup_corrupted.img create mode 100755 tests/fsck-tests/032-corrupted-qgroup/test.sh (limited to 'tests') diff --git a/tests/fsck-tests/032-corrupted-qgroup/qgroup_corrupted.img b/tests/fsck-tests/032-corrupted-qgroup/qgroup_corrupted.img new file mode 100644 index 00000000..a19a3035 Binary files /dev/null and b/tests/fsck-tests/032-corrupted-qgroup/qgroup_corrupted.img differ diff --git a/tests/fsck-tests/032-corrupted-qgroup/test.sh b/tests/fsck-tests/032-corrupted-qgroup/test.sh new file mode 100755 index 00000000..4bfa3601 --- /dev/null +++ b/tests/fsck-tests/032-corrupted-qgroup/test.sh @@ -0,0 +1,19 @@ +#!/bin/bash +# Check if btrfs check can handle valid orphan items. +# Orphan item is a marker for deleted inodes that were open at the time of +# deletion. Orphan inode/root is not referenced and will have an orphan +# item, which should not be reported as error. + +source "$TEST_TOP/common" + +check_prereq btrfs + +check_image() { + run_mustfail "btrfs check failed to detect qgroup corruption" \ + "$TOP/btrfs" check "$1" + # Above command can fail due to other bugs, so add extra check to + # ensure we can fix qgroup without problems. + run_check "$TOP/btrfs" check --repair "$1" +} + +check_all_images -- cgit v1.2.3 From e889fd7c1172ab5ef304dbbf5b003c0331e6ac9d Mon Sep 17 00:00:00 2001 From: Nikolay Borisov Date: Mon, 26 Mar 2018 16:59:34 +0300 Subject: btrfs-progs: tests: Add test for collision DIR_ITEM handling Verify that if we have an otherwise clean filesystem, containging collided DIR_ITEM, btrfs check lowmem's mode can correctly handle those and not produce any false positives. This if fixed by commit titled: "btrfs-progs: check: fix DIR_ITEM checking in lowmem" Signed-off-by: Nikolay Borisov Reviewed-by: Qu Wenruo Signed-off-by: David Sterba --- .../033-lowmem-collission-dir-items/test.sh | 24 ++++++++++++++++++++++ 1 file changed, 24 insertions(+) create mode 100755 tests/fsck-tests/033-lowmem-collission-dir-items/test.sh (limited to 'tests') diff --git a/tests/fsck-tests/033-lowmem-collission-dir-items/test.sh b/tests/fsck-tests/033-lowmem-collission-dir-items/test.sh new file mode 100755 index 00000000..60f34b25 --- /dev/null +++ b/tests/fsck-tests/033-lowmem-collission-dir-items/test.sh @@ -0,0 +1,24 @@ +#!/bin/bash +# Ensure that running btrfs check on a fs which has name collisions of files +# doesn't result in false positives. This test is specifically targeted at +# lowmem mode. + +source "$TEST_TOP/common" + +check_prereq btrfs +check_prereq mkfs.btrfs + +setup_root_helper +prepare_test_dev + +run_check $SUDO_HELPER "$TOP/mkfs.btrfs" -f "$TEST_DEV" +run_check_mount_test_dev + +# Create 2 files whose names collide +run_check $SUDO_HELPER touch "$TEST_MNT/5ab4e206~~~~~~~~XVT1U3ZF647YS2PD4AKAG826" +run_check $SUDO_HELPER touch "$TEST_MNT/5ab4e26a~~~~~~~~AP1C3VQBE79IJOTVOEZIR9YU" + +run_check_umount_test_dev + +# The fs is clean so lowmem shouldn't produce any warnings +run_check "$TOP/btrfs" check --readonly "$TEST_DEV" -- cgit v1.2.3 From e2eb6dc4d405e21a7ded3c2a2508f6979a5d39c9 Mon Sep 17 00:00:00 2001 From: Su Yue Date: Thu, 12 Apr 2018 09:10:28 +0800 Subject: btrfs-progs: tests: test mkfs.btrfs fails on small backing size thin provision device This tests is most similar to xfstests generic/405. It calls device mapper to create a thin provision device with small backing size and big virtual size. mkfs.btrfs should fail on such devices. This test should pass after commit e805b143a4fe ("btrfs-progs: mkfs: return nozero value on thin provisioned device"). Signed-off-by: Su Yue Signed-off-by: David Sterba --- .../test.sh | 98 ++++++++++++++++++++++ 1 file changed, 98 insertions(+) create mode 100755 tests/mkfs-tests/017-small-backing-size-thin-provision-device/test.sh (limited to 'tests') diff --git a/tests/mkfs-tests/017-small-backing-size-thin-provision-device/test.sh b/tests/mkfs-tests/017-small-backing-size-thin-provision-device/test.sh new file mode 100755 index 00000000..32640ce5 --- /dev/null +++ b/tests/mkfs-tests/017-small-backing-size-thin-provision-device/test.sh @@ -0,0 +1,98 @@ +#!/bin/bash +# mkfs.btrfs must fail on a thin provision device with very small backing size +# and big virtual size. + +source "$TEST_TOP/common" + +check_prereq mkfs.btrfs +check_global_prereq udevadm +check_global_prereq dmsetup + +setup_root_helper +prepare_test_dev + +# Backing data dev +DMTHIN_DATA_NAME="btrfs-progs-thin-data" +DMTHIN_DATA_DEV="/dev/mapper/$DMTHIN_DATA_NAME" +# Backing metadata dev +DMTHIN_META_NAME="btrfs-progs-thin-meta" +DMTHIN_META_DEV="/dev/mapper/$DMTHIN_META_NAME" +# Backing pool dev (combination of above) +DMTHIN_POOL_NAME="btrfs-progs-thin-pool" +DMTHIN_POOL_DEV="/dev/mapper/$DMTHIN_POOL_NAME" +# Thin volume +DMTHIN_VOL_NAME="btrfs-progs-thin-vol" +DMTHIN_VOL_DEV="/dev/mapper/$DMTHIN_VOL_NAME" + +dmthin_cleanup() +{ + # wait for device to be fully settled + run_check $SUDO_HELPER udevadm settle + run_check $SUDO_HELPER dmsetup remove "$DMTHIN_VOL_NAME" + run_check $SUDO_HELPER dmsetup remove "$DMTHIN_POOL_NAME" + run_check $SUDO_HELPER dmsetup remove "$DMTHIN_META_NAME" + run_check $SUDO_HELPER dmsetup remove "$DMTHIN_DATA_NAME" +} + +sector_size=512 # in bytes +data_dev_size=$((1 * 1024 * 1024 / $sector_size)) # 1M +virtual_size=$((1 * 1024 * 1024 * 1024 * 1024 / $sector_size)) # 1T +cluster_size=1024 # 512k in sectors +low_water=$((104857600 / $cluster_size/ $sector_size)) # 100M / $cluster_size, in sectors + +# Need to make linear metadata and data devs. From kernel docs: +# As a guide, we suggest you calculate the number of bytes to use in the +# metadata device as 48 * $data_dev_size / $data_block_size but round it up +# to 2MB (4096 sectors) if the answer is smaller. +# So do that: +meta_dev_size=$((48 * $data_dev_size / $cluster_size)) +if [ "$meta_dev_size" -lt "4096" ]; then + meta_dev_size=4096 # 2MB +fi + +meta_dev_offset=0 +total_data_dev_size=$(($meta_dev_offset + $meta_dev_size + $data_dev_size)) + +run_check truncate -s0 img +chmod a+w img +run_check truncate -s"$(($total_data_dev_size * $sector_size))" img + +dm_backing_dev=`run_check_stdout $SUDO_HELPER losetup --find --show img` + +if ! [ -b "$dm_backing_dev" ]; then + _fail "cannot create backing device" +fi + +# Metadata device +DMTHIN_META_TABLE="0 $meta_dev_size linear $dm_backing_dev $meta_dev_offset" +run_check $SUDO_HELPER dmsetup create "$DMTHIN_META_NAME" --table "$DMTHIN_META_TABLE" + +# Data device +data_dev_offset=$((meta_dev_offset + $meta_dev_size)) +DMTHIN_DATA_TABLE="0 $data_dev_size linear $dm_backing_dev $data_dev_offset" +run_check $SUDO_HELPER dmsetup create "$DMTHIN_DATA_NAME" --table "$DMTHIN_DATA_TABLE" + +# Zap the pool metadata dev +run_check $SUDO_HELPER dd if=/dev/zero of="$DMTHIN_META_DEV" bs=4096 count=1 + +# Thin pool +# "start length thin-pool metadata_dev data_dev data_block_size low_water_mark" +DMTHIN_POOL_TABLE="0 $data_dev_size thin-pool $DMTHIN_META_DEV $DMTHIN_DATA_DEV $cluster_size $low_water" +run_check $SUDO_HELPER dmsetup create "$DMTHIN_POOL_NAME" --table "$DMTHIN_POOL_TABLE" + +# Thin volume +pool_id=$RANDOM +run_check $SUDO_HELPER dmsetup message "$DMTHIN_POOL_DEV" 0 "create_thin $pool_id" + +# start length thin pool_dev dev_id [external_origin_dev] +DMTHIN_VOL_TABLE="0 $virtual_size thin $DMTHIN_POOL_DEV $pool_id" +run_check $SUDO_HELPER dmsetup create "$DMTHIN_VOL_NAME" --table "$DMTHIN_VOL_TABLE" + +# mkfs.btrfs should fail due to the small backing device, the initial discard +# is disabled +run_mustfail "should fail for small backing size thin provision device" \ + $SUDO_HELPER "$TOP/mkfs.btrfs" -K -f "$DMTHIN_VOL_DEV" + +dmthin_cleanup +run_mayfail $SUDO_HELPER losetup -d "$dm_backing_dev" +rm -- img -- cgit v1.2.3 From 6386ae4d8c6644630ab3f9aa1c92d8aed3b81aea Mon Sep 17 00:00:00 2001 From: Su Yue Date: Tue, 15 May 2018 09:33:24 +0800 Subject: btrfs-progs: fsck-tests: add test case to check symlinks with bad flags There are two bad symlinks in the test case. One is with immutable attribute. Another one is with append attribute. Signed-off-by: Su Yue Signed-off-by: David Sterba --- tests/fsck-tests/034-bad-inode-flags/default_case.img | Bin 0 -> 4096 bytes tests/fsck-tests/034-bad-inode-flags/test.sh | 15 +++++++++++++++ 2 files changed, 15 insertions(+) create mode 100644 tests/fsck-tests/034-bad-inode-flags/default_case.img create mode 100755 tests/fsck-tests/034-bad-inode-flags/test.sh (limited to 'tests') diff --git a/tests/fsck-tests/034-bad-inode-flags/default_case.img b/tests/fsck-tests/034-bad-inode-flags/default_case.img new file mode 100644 index 00000000..43a2a6f6 Binary files /dev/null and b/tests/fsck-tests/034-bad-inode-flags/default_case.img differ diff --git a/tests/fsck-tests/034-bad-inode-flags/test.sh b/tests/fsck-tests/034-bad-inode-flags/test.sh new file mode 100755 index 00000000..4bdc2bf0 --- /dev/null +++ b/tests/fsck-tests/034-bad-inode-flags/test.sh @@ -0,0 +1,15 @@ +#!/bin/bash +# In order to confirm that 'btrfs check' supports checking symlinks +# with immutable/append attributes that are not possible to set by standard +# syscall or ioctl so they're handled as corruption + +source "$TEST_TOP/common" + +check_prereq btrfs + +check_image() { + run_mustfail "check should report errors about inode flags" \ + $SUDO_HELPER "$TOP/btrfs" check "$1" +} + +check_all_images -- cgit v1.2.3 From 686dc0864ea913d694182b40e9841baa825ba10c Mon Sep 17 00:00:00 2001 From: David Sterba Date: Thu, 7 Jun 2018 15:18:50 +0200 Subject: btrfs-progs: tests: fix fsck-tests/031 when on NFS The restore target file does not exist and creating by root does not work on NFS, so precreating will make that work. Also fix the image name to be deleted. Signed-off-by: David Sterba --- tests/fsck-tests/031-metadatadump-check-data-csum/test.sh | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-) (limited to 'tests') diff --git a/tests/fsck-tests/031-metadatadump-check-data-csum/test.sh b/tests/fsck-tests/031-metadatadump-check-data-csum/test.sh index 30b0b7a3..e9b2d5c6 100755 --- a/tests/fsck-tests/031-metadatadump-check-data-csum/test.sh +++ b/tests/fsck-tests/031-metadatadump-check-data-csum/test.sh @@ -16,6 +16,8 @@ run_check_mount_test_dev run_check $SUDO_HELPER dd if=/dev/urandom of="$TEST_MNT/file" bs=4k count=16 run_check_umount_test_dev +touch restored_image +chmod a+w restored_image run_check $SUDO_HELPER "$TOP/btrfs-image" "$TEST_DEV" "restored_image" # use prepare_test_dev() to wipe all existing data on $TEST_DEV @@ -27,4 +29,4 @@ run_check $SUDO_HELPER "$TOP/btrfs-image" -r "restored_image" "$TEST_DEV" # Should not report any error run_check "$TOP/btrfs" check --check-data-csum "$TEST_DEV" -rm -rf -- "restored_image*" +rm -rf -- "restored_image" -- cgit v1.2.3 From 8aee4b000d4fdf30cab167d5cf78b413af155098 Mon Sep 17 00:00:00 2001 From: David Sterba Date: Mon, 2 Jul 2018 17:54:36 +0200 Subject: btrfs-progs: tests: add fuzzed image that triggers crash in reloc setup on mount Reported-by: Wen Xu Signed-off-by: David Sterba --- .../images/bko-199833-reloc-recovery-crash.raw.xz | Bin 0 -> 23428 bytes .../images/bko-199833-reloc-recovery-crash.txt | 113 +++++++++++++++++++++ 2 files changed, 113 insertions(+) create mode 100644 tests/fuzz-tests/images/bko-199833-reloc-recovery-crash.raw.xz create mode 100644 tests/fuzz-tests/images/bko-199833-reloc-recovery-crash.txt (limited to 'tests') diff --git a/tests/fuzz-tests/images/bko-199833-reloc-recovery-crash.raw.xz b/tests/fuzz-tests/images/bko-199833-reloc-recovery-crash.raw.xz new file mode 100644 index 00000000..7d291041 Binary files /dev/null and b/tests/fuzz-tests/images/bko-199833-reloc-recovery-crash.raw.xz differ diff --git a/tests/fuzz-tests/images/bko-199833-reloc-recovery-crash.txt b/tests/fuzz-tests/images/bko-199833-reloc-recovery-crash.txt new file mode 100644 index 00000000..a54992ee --- /dev/null +++ b/tests/fuzz-tests/images/bko-199833-reloc-recovery-crash.txt @@ -0,0 +1,113 @@ +URL: https://bugzilla.kernel.org/show_bug.cgi?id=199833 +Wen Xu 2018-05-26 02:27:26 UTC + +The (compressed) crafted image which causes crash + +- Overview +Invalid pointer dereference in __del_reloc_root() when mounting a crafted btrfs image + +- Reproduce +# mkdir mnt +# mount -t btrfs 82.img mnt +(Reproduced on Linux 4.17-rc5) + +- Comment +https://elixir.bootlin.com/linux/v4.17-rc5/source/fs/btrfs/relocation.c#L1324 + +static void __del_reloc_root(struct btrfs_root *root) +{ + struct btrfs_fs_info *fs_info = root->fs_info; + struct rb_node *rb_node; + struct mapping_node *node = NULL; + struct reloc_control *rc = fs_info->reloc_ctl; + + spin_lock(&rc->reloc_root_tree.lock); + +rc can be NULL, which means that reloc_ctl may be not initialized + +- Kernel message +[ 208.623313] BUG: unable to handle kernel NULL pointer dereference at 0000000000000570 +[ 208.624890] PGD 80000001e9495067 P4D 80000001e9495067 PUD 1f0d81067 PMD 0 +[ 208.626285] Oops: 0002 [#1] SMP KASAN PTI +[ 208.632054] BTRFS info (device loop0): delayed_refs has NO entry +[ 208.636502] CPU: 1 PID: 1330 Comm: mount Tainted: G B W 4.17.0-rc5+ #6 +[ 208.639306] Hardware name: QEMU Standard PC (i440FX + PIIX, 1996), BIOS Ubuntu-1.8.2-1ubuntu1 04/01/2014 +[ 208.641177] RIP: 0010:_raw_spin_lock+0x1e/0x40 +[ 208.642200] RSP: 0018:ffff8801df437338 EFLAGS: 00010246 +[ 208.643240] RAX: 0000000000000000 RBX: 0000000000000570 RCX: 0000000000000000 +[ 208.644643] RDX: 0000000000000001 RSI: 0000000000000297 RDI: 0000000000000297 +[ 208.646058] RBP: ffff8801df437340 R08: ffffed003ee23ebb R09: ffffed003ee23ebb +[ 208.647464] R10: 0000000000000001 R11: ffffed003ee23eba R12: ffff8801f2e8c400 +[ 208.648870] R13: 0000000000000000 R14: ffff8801e3a28000 R15: 0000000000000568 +[ 208.650286] FS: 00007fd41a0a7840(0000) GS:ffff8801f7100000(0000) knlGS:0000000000000000 +[ 208.651872] CS: 0010 DS: 0000 ES: 0000 CR0: 0000000080050033 +[ 208.653006] CR2: 0000000000000570 CR3: 00000001e16e6000 CR4: 00000000000006e0 +[ 208.654449] Call Trace: +[ 208.654961] __del_reloc_root+0x5a/0x190 +[ 208.655755] free_reloc_roots+0x40/0xb0 +[ 208.656531] btrfs_recover_relocation+0x2fa/0x750 +[ 208.657487] ? btrfs_cleanup_fs_roots+0x351/0x3b0 +[ 208.658428] ? btrfs_relocate_block_group+0x370/0x370 +[ 208.659433] ? qgroup_reserve+0x650/0x650 +[ 208.660237] ? migrate_swap_stop+0x2e0/0x2e0 +[ 208.661090] ? btrfs_check_rw_degradable+0xb0/0x240 +[ 208.662077] open_ctree+0x37c4/0x3ce9 +[ 208.662822] ? close_ctree+0x4a0/0x4a0 +[ 208.663580] ? bdi_register_va+0x44/0x50 +[ 208.664371] ? super_setup_bdi_name+0x11b/0x1a0 +[ 208.665302] ? kill_block_super+0x80/0x80 +[ 208.666111] ? snprintf+0x96/0xd0 +[ 208.666787] btrfs_mount_root+0xae6/0xc60 +[ 208.667596] ? btrfs_mount_root+0xae6/0xc60 +[ 208.668449] ? pcpu_block_update_hint_alloc+0x1f5/0x2a0 +[ 208.669505] ? btrfs_decode_error+0x40/0x40 +[ 208.670345] ? find_next_bit+0x57/0x90 +[ 208.671101] ? cpumask_next+0x1a/0x20 +[ 208.671837] ? pcpu_alloc+0x449/0x8c0 +[ 208.672577] ? pcpu_free_area+0x410/0x410 +[ 208.673393] ? memcg_kmem_put_cache+0x1b/0xa0 +[ 208.674267] ? memcpy+0x45/0x50 +[ 208.674905] mount_fs+0x60/0x1a0 +[ 208.675562] ? btrfs_decode_error+0x40/0x40 +[ 208.676399] ? mount_fs+0x60/0x1a0 +[ 208.677088] ? alloc_vfsmnt+0x309/0x360 +[ 208.677880] vfs_kern_mount+0x6b/0x1a0 +[ 208.678634] ? entry_SYSCALL_64_after_hwframe+0x44/0xa9 +[ 208.679671] btrfs_mount+0x209/0xb71 +[ 208.680390] ? pcpu_block_update_hint_alloc+0x1f5/0x2a0 +[ 208.681442] ? btrfs_remount+0x8e0/0x8e0 +[ 208.682247] ? find_next_zero_bit+0x2c/0xa0 +[ 208.683119] ? find_next_bit+0x57/0x90 +[ 208.683876] ? cpumask_next+0x1a/0x20 +[ 208.684619] ? pcpu_alloc+0x449/0x8c0 +[ 208.685371] ? pcpu_free_area+0x410/0x410 +[ 208.686177] ? memcg_kmem_put_cache+0x1b/0xa0 +[ 208.687046] ? memcpy+0x45/0x50 +[ 208.687685] mount_fs+0x60/0x1a0 +[ 208.688337] ? btrfs_remount+0x8e0/0x8e0 +[ 208.689121] ? mount_fs+0x60/0x1a0 +[ 208.689828] ? alloc_vfsmnt+0x309/0x360 +[ 208.690599] vfs_kern_mount+0x6b/0x1a0 +[ 208.691352] do_mount+0x34a/0x18a0 +[ 208.692039] ? lockref_put_or_lock+0xcf/0x160 +[ 208.692909] ? copy_mount_string+0x20/0x20 +[ 208.693742] ? memcg_kmem_put_cache+0x1b/0xa0 +[ 208.694615] ? kasan_check_write+0x14/0x20 +[ 208.695437] ? _copy_from_user+0x6a/0x90 +[ 208.696226] ? memdup_user+0x42/0x60 +[ 208.696948] ksys_mount+0x83/0xd0 +[ 208.697631] __x64_sys_mount+0x67/0x80 +[ 208.698385] do_syscall_64+0x78/0x170 +[ 208.699122] entry_SYSCALL_64_after_hwframe+0x44/0xa9 +[ 208.700124] RIP: 0033:0x7fd419987b9a +[ 208.700842] RSP: 002b:00007fff30668b88 EFLAGS: 00000206 ORIG_RAX: 00000000000000a5 +[ 208.702345] RAX: ffffffffffffffda RBX: 0000000001829030 RCX: 00007fd419987b9a +[ 208.703742] RDX: 0000000001829210 RSI: 000000000182af30 RDI: 0000000001831ec0 +[ 208.705134] RBP: 0000000000000000 R08: 0000000000000000 R09: 0000000000000014 +[ 208.706533] R10: 00000000c0ed0000 R11: 0000000000000206 R12: 0000000001831ec0 +[ 208.707931] R13: 0000000001829210 R14: 0000000000000000 R15: 0000000000000003 +[ 208.713050] RIP: _raw_spin_lock+0x1e/0x40 RSP: ffff8801df437338 +[ 208.714238] CR2: 0000000000000570 +[ 208.714985] ---[ end trace be56bf4112c4e5e3 ]--- + +Found by Wen Xu and Po-Ning Tseng from SSLab, Gatech. -- cgit v1.2.3 From 014a0db6cbc09b720e832e9e069028b52dd0bc11 Mon Sep 17 00:00:00 2001 From: Qu Wenruo Date: Wed, 20 Jun 2018 08:38:39 +0800 Subject: btrfs-progs: misc-tests: Fix 029 test cases for sudo test environment Test misc/029 only works if the test case is executed as root, while for sudo usage, it doesn't work as initial mkdir and final cleanup doesn't use $SUDO_HELPER. Add "run_check $SUDO_HELPER" for such cases to allow it works under sudo usage. Signed-off-by: Qu Wenruo Reviewed-by: Nikolay Borisov Signed-off-by: David Sterba --- tests/misc-tests/029-send-p-different-mountpoints/test.sh | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) (limited to 'tests') diff --git a/tests/misc-tests/029-send-p-different-mountpoints/test.sh b/tests/misc-tests/029-send-p-different-mountpoints/test.sh index 0b42b772..90465e1d 100755 --- a/tests/misc-tests/029-send-p-different-mountpoints/test.sh +++ b/tests/misc-tests/029-send-p-different-mountpoints/test.sh @@ -14,7 +14,7 @@ prepare_test_dev SUBVOL_MNT="$TEST_MNT/subvol" TOPLEVEL_MNT="$TEST_MNT/toplevel" TEST_MNT="$TOPLEVEL_MNT" -mkdir -p "$TOPLEVEL_MNT" "$SUBVOL_MNT" +run_check $SUDO_HELPER mkdir -p "$TOPLEVEL_MNT" "$SUBVOL_MNT" run_check $SUDO_HELPER "$TOP/mkfs.btrfs" -f "$TEST_DEV" run_check_mount_test_dev @@ -47,5 +47,5 @@ run_mustfail_stdout "send -p on 2 mount points" \ run_check_umount_test_dev "$SUBVOL_MNT" run_check_umount_test_dev "$TOPLEVEL_MNT" -rmdir "$SUBVOL_MNT" -rmdir "$TOPLEVEL_MNT" +run_check $SUDO_HELPER rmdir "$SUBVOL_MNT" +run_check $SUDO_HELPER rmdir "$TOPLEVEL_MNT" -- cgit v1.2.3 From 866740418ccf881fcc64a4633978e3621ed4a7fc Mon Sep 17 00:00:00 2001 From: Qu Wenruo Date: Wed, 6 Jun 2018 15:27:17 +0800 Subject: btrfs-progs: fsck-tests: Add test case for corrupted inline ram_bytes Signed-off-by: Qu Wenruo Signed-off-by: David Sterba --- .../035-inline-bad-ram-bytes/offset_by_one.img | Bin 0 -> 3072 bytes tests/fsck-tests/035-inline-bad-ram-bytes/test.sh | 11 +++++++++++ 2 files changed, 11 insertions(+) create mode 100644 tests/fsck-tests/035-inline-bad-ram-bytes/offset_by_one.img create mode 100755 tests/fsck-tests/035-inline-bad-ram-bytes/test.sh (limited to 'tests') diff --git a/tests/fsck-tests/035-inline-bad-ram-bytes/offset_by_one.img b/tests/fsck-tests/035-inline-bad-ram-bytes/offset_by_one.img new file mode 100644 index 00000000..2f58208e Binary files /dev/null and b/tests/fsck-tests/035-inline-bad-ram-bytes/offset_by_one.img differ diff --git a/tests/fsck-tests/035-inline-bad-ram-bytes/test.sh b/tests/fsck-tests/035-inline-bad-ram-bytes/test.sh new file mode 100755 index 00000000..6f6e2a5e --- /dev/null +++ b/tests/fsck-tests/035-inline-bad-ram-bytes/test.sh @@ -0,0 +1,11 @@ +#!/bin/bash +# Around 2014, btrfs kernel has a regression that create inline extent +# with ram_bytes offset by one. +# This old regression could be caught by tree-check code. +# This test case will check if btrfs check could detect and repair it. + +source "$TEST_TOP/common" + +check_prereq btrfs + +check_all_images -- cgit v1.2.3 From beb3ede39a21f61bd559f589a067d2847ce2c6d0 Mon Sep 17 00:00:00 2001 From: Qu Wenruo Date: Mon, 9 Jul 2018 14:50:54 +0800 Subject: btrfs-progs: tests/fuzz: Add image for bko-200409 Reported-by: Xu Wen Link: https://bugzilla.kernel.org/show_bug.cgi?id=200409 Signed-off-by: Qu Wenruo Signed-off-by: David Sterba --- tests/fuzz-tests/images/bko-200409.raw.txt | 125 +++++++++++++++++++++++++++++ tests/fuzz-tests/images/bko-200409.raw.xz | Bin 0 -> 24480 bytes 2 files changed, 125 insertions(+) create mode 100644 tests/fuzz-tests/images/bko-200409.raw.txt create mode 100644 tests/fuzz-tests/images/bko-200409.raw.xz (limited to 'tests') diff --git a/tests/fuzz-tests/images/bko-200409.raw.txt b/tests/fuzz-tests/images/bko-200409.raw.txt new file mode 100644 index 00000000..7df79243 --- /dev/null +++ b/tests/fuzz-tests/images/bko-200409.raw.txt @@ -0,0 +1,125 @@ +Link: https://bugzilla.kernel.org/show_bug.cgi?id=200409 +Wen Xu 2018-07-04 17:47:09 UTC + +Created attachment 277173 [details] +The (compressed) crafted image which causes crash + +- Reproduce +# mkdir mnt +# mount -t btrfs 5.img mnt + +- Kernel message +[ 333.770743] BTRFS: device fsid 3381d111-94a3-4ac7-8f39-611bbbdab7e6 devid 1 transid 8 /dev/loop0 +[ 333.779221] BTRFS info (device loop0): disk space caching is enabled +[ 333.779234] BTRFS info (device loop0): has skinny extents +[ 333.798081] ------------[ cut here ]------------ +[ 333.798090] kernel BUG at fs/btrfs/volumes.c:6564! +[ 333.799293] invalid opcode: 0000 [#1] SMP KASAN PTI +[ 333.800355] CPU: 0 PID: 1353 Comm: mount Not tainted 4.18.0-rc1+ #8 +[ 333.801652] Hardware name: QEMU Standard PC (i440FX + PIIX, 1996), BIOS Ubuntu-1.8.2-1ubuntu1 04/01/2014 +[ 333.803658] RIP: 0010:read_one_chunk+0x77c/0x880 +[ 333.804630] Code: e8 a9 82 fd ff 48 8b 95 70 ff ff ff 48 8b bd 60 ff ff ff b9 01 00 00 00 4c 89 f6 e8 2e 14 ff ff b8 fe ff ff ff e9 cb fe ff ff <0f> 0b 48 8b bd 38 ff ff ff e8 76 82 fd ff e9 35 ff ff ff 48 8b 95 +[ 333.808462] RSP: 0018:ffff8801eedf7230 EFLAGS: 00010282 +[ 333.809542] RAX: ffff8801f2df2100 RBX: 00000000ffffffef RCX: ffffffffa5839143 +[ 333.810991] RDX: 1ffff1003e5be444 RSI: e300000001c00000 RDI: ffff8801f2df2220 +[ 333.812451] RBP: ffff8801eedf7310 R08: ffffed003e5be445 R09: ffffed003e5be445 +[ 333.813905] R10: 0000000000000001 R11: ffffed003e5be444 R12: ffff8801e6788158 +[ 333.815357] R13: 0000000000000001 R14: 0000000000000001 R15: ffff8801f2df2220 +[ 333.846990] FS: 00007f2013519840(0000) GS:ffff8801f6e00000(0000) knlGS:0000000000000000 +[ 333.848645] CS: 0010 DS: 0000 ES: 0000 CR0: 0000000080050033 +[ 333.849816] CR2: 00007f88a3c6b760 CR3: 00000001e655e000 CR4: 00000000000006f0 +[ 333.851304] Call Trace: +[ 333.851864] ? add_missing_dev+0xc0/0xc0 +[ 333.852715] ? read_extent_buffer+0xe9/0x130 +[ 333.853604] btrfs_read_chunk_tree+0x957/0xd20 +[ 333.854551] ? free_root_pointers+0xb0/0xb0 +[ 333.855435] ? btrfs_check_rw_degradable+0x240/0x240 +[ 333.856491] ? btree_read_extent_buffer_pages+0x1e0/0x3b0 +[ 333.857617] ? run_one_async_done+0xb0/0xb0 +[ 333.858498] ? cache_state.part.32+0x10/0x40 +[ 333.859430] ? unlock_page+0x16/0x40 +[ 333.860202] ? alloc_extent_buffer+0x4a1/0x4e0 +[ 333.861149] ? memcpy+0x45/0x50 +[ 333.861818] ? read_extent_buffer+0xe9/0x130 +[ 333.862711] open_ctree+0x246c/0x35c6 +[ 333.863488] ? close_ctree+0x460/0x460 +[ 333.864302] ? bdi_register_va+0x44/0x50 +[ 333.865142] ? super_setup_bdi_name+0x11b/0x1a0 +[ 333.866089] ? kill_block_super+0x80/0x80 +[ 333.866970] ? snprintf+0x96/0xd0 +[ 333.867704] btrfs_mount_root+0xae6/0xc60 +[ 333.868550] ? btrfs_mount_root+0xae6/0xc60 +[ 333.869419] ? pcpu_block_update_hint_alloc+0x1d2/0x2a0 +[ 333.870492] ? btrfs_decode_error+0x40/0x40 +[ 333.871389] ? find_next_bit+0x57/0x90 +[ 333.872206] ? cpumask_next+0x1a/0x20 +[ 333.872986] ? pcpu_alloc+0x449/0x8c0 +[ 333.873761] ? pcpu_free_area+0x410/0x410 +[ 333.874614] ? memcg_kmem_put_cache+0x1b/0xa0 +[ 333.875531] ? memcpy+0x45/0x50 +[ 333.876209] mount_fs+0x60/0x1a0 +[ 333.876892] ? btrfs_decode_error+0x40/0x40 +[ 333.877763] ? mount_fs+0x60/0x1a0 +[ 333.878492] ? alloc_vfsmnt+0x309/0x360 +[ 333.879303] vfs_kern_mount+0x6b/0x1a0 +[ 333.880121] ? entry_SYSCALL_64_after_hwframe+0x44/0xa9 +[ 333.881209] btrfs_mount+0x209/0xb71 +[ 333.881962] ? pcpu_block_update_hint_alloc+0x1d2/0x2a0 +[ 333.883044] ? btrfs_remount+0x8e0/0x8e0 +[ 333.883878] ? find_next_zero_bit+0x2c/0xa0 +[ 333.884753] ? find_next_bit+0x57/0x90 +[ 333.885538] ? cpumask_next+0x1a/0x20 +[ 333.886307] ? pcpu_alloc+0x449/0x8c0 +[ 333.887078] ? pcpu_free_area+0x410/0x410 +[ 333.887930] ? memcg_kmem_put_cache+0x1b/0xa0 +[ 333.888836] ? memcpy+0x45/0x50 +[ 333.889500] mount_fs+0x60/0x1a0 +[ 333.890182] ? btrfs_remount+0x8e0/0x8e0 +[ 333.891001] ? mount_fs+0x60/0x1a0 +[ 333.891728] ? alloc_vfsmnt+0x309/0x360 +[ 333.892533] vfs_kern_mount+0x6b/0x1a0 +[ 333.893323] do_mount+0x34a/0x18c0 +[ 333.894042] ? copy_mount_string+0x20/0x20 +[ 333.894898] ? memcg_kmem_put_cache+0x1b/0xa0 +[ 333.895832] ? kasan_check_write+0x14/0x20 +[ 333.896704] ? _copy_from_user+0x6a/0x90 +[ 333.897542] ? memdup_user+0x42/0x60 +[ 333.898300] ksys_mount+0x83/0xd0 +[ 333.899003] __x64_sys_mount+0x67/0x80 +[ 333.899831] do_syscall_64+0x78/0x170 +[ 333.900610] entry_SYSCALL_64_after_hwframe+0x44/0xa9 +[ 333.901682] RIP: 0033:0x7f2012df9b9a +[ 333.902430] Code: 48 8b 0d 01 c3 2b 00 f7 d8 64 89 01 48 83 c8 ff c3 66 2e 0f 1f 84 00 00 00 00 00 0f 1f 44 00 00 49 89 ca b8 a5 00 00 00 0f 05 <48> 3d 01 f0 ff ff 73 01 c3 48 8b 0d ce c2 2b 00 f7 d8 64 89 01 48 +[ 333.906311] RSP: 002b:00007ffd77e261b8 EFLAGS: 00000206 ORIG_RAX: 00000000000000a5 +[ 333.907874] RAX: ffffffffffffffda RBX: 00000000019e7030 RCX: 00007f2012df9b9a +[ 333.909341] RDX: 00000000019e7210 RSI: 00000000019e8f30 RDI: 00000000019efec0 +[ 333.910804] RBP: 0000000000000000 R08: 0000000000000000 R09: 0000000000000014 +[ 333.912281] R10: 00000000c0ed0000 R11: 0000000000000206 R12: 00000000019efec0 +[ 333.913747] R13: 00000000019e7210 R14: 0000000000000000 R15: 0000000000000003 +[ 333.915224] Modules linked in: snd_hda_codec_generic snd_hda_intel snd_hda_codec snd_hwdep snd_hda_core snd_pcm snd_timer snd mac_hid i2c_piix4 soundcore ib_iser rdma_cm iw_cm ib_cm ib_core iscsi_tcp libiscsi_tcp libiscsi scsi_transport_iscsi raid10 raid456 async_raid6_recov async_memcpy async_pq async_xor async_tx raid1 raid0 multipath linear 8139too qxl drm_kms_helper crct10dif_pclmul syscopyarea sysfillrect sysimgblt fb_sys_fops ttm crc32_pclmul aesni_intel drm aes_x86_64 crypto_simd cryptd glue_helper 8139cp mii pata_acpi floppy +[ 333.932460] ---[ end trace 2e85051acb5f6dc1 ]--- +[ 333.933448] RIP: 0010:read_one_chunk+0x77c/0x880 +[ 333.934397] Code: e8 a9 82 fd ff 48 8b 95 70 ff ff ff 48 8b bd 60 ff ff ff b9 01 00 00 00 4c 89 f6 e8 2e 14 ff ff b8 fe ff ff ff e9 cb fe ff ff <0f> 0b 48 8b bd 38 ff ff ff e8 76 82 fd ff e9 35 ff ff ff 48 8b 95 +[ 333.938283] RSP: 0018:ffff8801eedf7230 EFLAGS: 00010282 +[ 333.939361] RAX: ffff8801f2df2100 RBX: 00000000ffffffef RCX: ffffffffa5839143 +[ 333.940846] RDX: 1ffff1003e5be444 RSI: e300000001c00000 RDI: ffff8801f2df2220 +[ 333.942318] RBP: ffff8801eedf7310 R08: ffffed003e5be445 R09: ffffed003e5be445 +[ 333.943878] R10: 0000000000000001 R11: ffffed003e5be444 R12: ffff8801e6788158 +[ 333.945371] R13: 0000000000000001 R14: 0000000000000001 R15: ffff8801f2df2220 +[ 333.946839] FS: 00007f2013519840(0000) GS:ffff8801f6e00000(0000) knlGS:0000000000000000 +[ 333.948526] CS: 0010 DS: 0000 ES: 0000 CR0: 0000000080050033 +[ 333.949711] CR2: 00007f88a3c6b760 CR3: 00000001e655e000 CR4: 00000000000006f0 + +- Location +https://elixir.bootlin.com/linux/v4.18-rc3/source/fs/btrfs/volumes.c#L6564 + write_lock(&map_tree->map_tree.lock); + ret = add_extent_mapping(&map_tree->map_tree, em, 0); + write_unlock(&map_tree->map_tree.lock); + BUG_ON(ret); /* Tree corruption */ <--- + free_extent_map(em); + +Found by Wen Xu and Po-Ning Tseng from SSLab at Gatech. + +====== Extra info for btrfs-progs ====== +Btrfs-progs has the exact BUG_ON() in read_one_chunk(). +Fixed by "btrfs-progs: Exit gracefully when overlap chunks are detected". diff --git a/tests/fuzz-tests/images/bko-200409.raw.xz b/tests/fuzz-tests/images/bko-200409.raw.xz new file mode 100644 index 00000000..8ec29cfd Binary files /dev/null and b/tests/fuzz-tests/images/bko-200409.raw.xz differ -- cgit v1.2.3 From 3fcef5090633111219696b2d5a769829c366234b Mon Sep 17 00:00:00 2001 From: Qu Wenruo Date: Thu, 5 Jul 2018 15:45:57 +0800 Subject: btrfs-progs: tests/fuzz: Add fuzzed test image for btrfs check BUG_ON This fuzzed image will not only cause kernel BUG_ON(), but also btrfs check BUG_ON() for original mode. Checking filesystem on /home/adam/btrfs/crafted_images/runtime/0.img UUID: 3381d111-94a3-4ac7-8f39-611bbbdab7e6 checking extents check/main.c:3677: check_owner_ref: BUG_ON `rec->is_root` triggered, value 1 btrfs(+0x572c2)[0x562d65da72c2] btrfs(+0x6098d)[0x562d65db098d] btrfs(+0x60bb6)[0x562d65db0bb6] btrfs(+0x6179b)[0x562d65db179b] btrfs(cmd_check+0x1199)[0x562d65db5589] btrfs(main+0x88)[0x562d65d62768] /usr/lib/libc.so.6(__libc_start_main+0xeb)[0x7f4fcbb1b06b] btrfs(_start+0x2a)[0x562d65d6288a] Link: https://bugzilla.kernel.org/show_bug.cgi?id=200403 Signed-off-by: Qu Wenruo Signed-off-by: David Sterba --- tests/fuzz-tests/images/bko-200403.raw.txt | 93 +++++++++++++++++++++++++++++ tests/fuzz-tests/images/bko-200403.raw.xz | Bin 0 -> 23252 bytes 2 files changed, 93 insertions(+) create mode 100644 tests/fuzz-tests/images/bko-200403.raw.txt create mode 100644 tests/fuzz-tests/images/bko-200403.raw.xz (limited to 'tests') diff --git a/tests/fuzz-tests/images/bko-200403.raw.txt b/tests/fuzz-tests/images/bko-200403.raw.txt new file mode 100644 index 00000000..aae8ea48 --- /dev/null +++ b/tests/fuzz-tests/images/bko-200403.raw.txt @@ -0,0 +1,93 @@ +Link: https://bugzilla.kernel.org/show_bug.cgi?id=200403 +Wen Xu 2018-07-04 17:21:58 UTC + +Created attachment 277167 [details] +The (compressed) crafted image which causes crash + +- Reproduce +# mkdir mnt +# mount -t btrfs 0.img mnt +# gcc -o poc poc.c +# ./poc ./mnt +# umount mnt + +- Kernel message +[ 230.611533] BTRFS: device fsid 3381d111-94a3-4ac7-8f39-611bbbdab7e6 devid 1 transid 8 /dev/loop0 +[ 230.632922] BTRFS info (device loop0): disk space caching is enabled +[ 230.632935] BTRFS info (device loop0): has skinny extents +[ 230.647496] BTRFS info (device loop0): creating UUID tree +[ 237.692643] ------------[ cut here ]------------ +[ 237.692654] kernel BUG at fs/btrfs/volumes.c:1625! +[ 237.693822] invalid opcode: 0000 [#1] SMP KASAN PTI +[ 237.694867] CPU: 1 PID: 1387 Comm: umount Not tainted 4.18.0-rc1+ #8 +[ 237.696177] Hardware name: QEMU Standard PC (i440FX + PIIX, 1996), BIOS Ubuntu-1.8.2-1ubuntu1 04/01/2014 +[ 237.698177] RIP: 0010:btrfs_remove_chunk+0x37a/0xd60 +[ 237.699209] Code: e0 48 39 85 28 ff ff ff 77 20 0f b6 85 27 ff ff ff 4d 89 6f 80 4c 89 f7 4d 89 67 89 41 88 47 88 e8 0b 01 f7 ff e9 f5 fe ff ff <0f> 0b 0f 85 5c 08 00 00 4d 8d 66 40 4c 89 f7 e8 42 f9 b6 ff 4c 89 +[ 237.703034] RSP: 0018:ffff8801f0b0fad8 EFLAGS: 00010206 +[ 237.704122] RAX: 0000000008000000 RBX: ffff8801ef4d7c38 RCX: 0000000000000000 +[ 237.705572] RDX: ffffed003e161f30 RSI: 0000000000000e70 RDI: ffff8801f2a6ae70 +[ 237.707035] RBP: ffff8801f0b0fc38 R08: ffff8801f0b0f9e0 R09: ffff8801f0b0fa20 +[ 237.708485] R10: 0000000000000003 R11: ffffed003e161f7c R12: 0000000007400000 +[ 237.709929] R13: 0000000000000001 R14: ffff8801f2bf0a50 R15: ffff8801f0b0fc10 +[ 237.711391] FS: 00007f691b770840(0000) GS:ffff8801f6f00000(0000) knlGS:0000000000000000 +[ 237.713034] CS: 0010 DS: 0000 ES: 0000 CR0: 0000000080050033 +[ 237.714206] CR2: 0000000000cb0348 CR3: 00000001f26f8000 CR4: 00000000000006e0 +[ 237.719741] Call Trace: +[ 237.720274] ? btrfs_grow_device+0x240/0x240 +[ 237.721193] ? kasan_check_read+0x11/0x20 +[ 237.722080] ? mutex_lock+0x99/0xf0 +[ 237.722854] btrfs_delete_unused_bgs+0x4b6/0x5c0 +[ 237.723836] close_ctree+0x40a/0x460 +[ 237.724586] ? transaction_kthread+0x250/0x250 +[ 237.725523] ? dispose_list+0xa0/0xa0 +[ 237.726303] btrfs_put_super+0x25/0x30 +[ 237.727110] generic_shutdown_super+0xb9/0x1c0 +[ 237.728032] kill_anon_super+0x24/0x40 +[ 237.728814] btrfs_kill_super+0x31/0x220 +[ 237.729630] deactivate_locked_super+0x6f/0xa0 +[ 237.730548] deactivate_super+0x5e/0x80 +[ 237.731352] cleanup_mnt+0x61/0xa0 +[ 237.732060] __cleanup_mnt+0x12/0x20 +[ 237.732835] task_work_run+0xc8/0xf0 +[ 237.733605] exit_to_usermode_loop+0x125/0x130 +[ 237.734530] do_syscall_64+0x138/0x170 +[ 237.735331] entry_SYSCALL_64_after_hwframe+0x44/0xa9 +[ 237.736676] RIP: 0033:0x7f691b050487 +[ 237.737457] Code: 83 c8 ff c3 66 2e 0f 1f 84 00 00 00 00 00 0f 1f 44 00 00 31 f6 e9 09 00 00 00 66 0f 1f 84 00 00 00 00 00 b8 a6 00 00 00 0f 05 <48> 3d 01 f0 ff ff 73 01 c3 48 8b 0d e1 c9 2b 00 f7 d8 64 89 01 48 +[ 237.741327] RSP: 002b:00007ffdf3a06d98 EFLAGS: 00000246 ORIG_RAX: 00000000000000a6 +[ 237.742889] RAX: 0000000000000000 RBX: 0000000000ca7030 RCX: 00007f691b050487 +[ 237.744351] RDX: 0000000000000001 RSI: 0000000000000000 RDI: 0000000000cae1e0 +[ 237.745814] RBP: 0000000000cae1e0 R08: 0000000000000000 R09: 0000000000000015 +[ 237.747289] R10: 00000000000006b2 R11: 0000000000000246 R12: 00007f691b55983c +[ 237.748750] R13: 0000000000000000 R14: 0000000000ca7210 R15: 00007ffdf3a07020 +[ 237.750224] Modules linked in: snd_hda_codec_generic snd_hda_intel snd_hda_codec snd_hwdep snd_hda_core snd_pcm snd_timer snd mac_hid i2c_piix4 soundcore ib_iser rdma_cm iw_cm ib_cm ib_core iscsi_tcp libiscsi_tcp libiscsi scsi_transport_iscsi raid10 raid456 async_raid6_recov async_memcpy async_pq async_xor async_tx raid1 raid0 multipath linear 8139too qxl drm_kms_helper crct10dif_pclmul syscopyarea sysfillrect sysimgblt fb_sys_fops ttm crc32_pclmul aesni_intel drm aes_x86_64 crypto_simd cryptd glue_helper 8139cp mii pata_acpi floppy +[ 237.760666] ---[ end trace 2e85051acb5f6dc1 ]--- +[ 237.761718] RIP: 0010:btrfs_remove_chunk+0x37a/0xd60 +[ 237.762827] Code: e0 48 39 85 28 ff ff ff 77 20 0f b6 85 27 ff ff ff 4d 89 6f 80 4c 89 f7 4d 89 67 89 41 88 47 88 e8 0b 01 f7 ff e9 f5 fe ff ff <0f> 0b 0f 85 5c 08 00 00 4d 8d 66 40 4c 89 f7 e8 42 f9 b6 ff 4c 89 +[ 237.766977] RSP: 0018:ffff8801f0b0fad8 EFLAGS: 00010206 +[ 237.768157] RAX: 0000000008000000 RBX: ffff8801ef4d7c38 RCX: 0000000000000000 +[ 237.769672] RDX: ffffed003e161f30 RSI: 0000000000000e70 RDI: ffff8801f2a6ae70 +[ 237.771147] RBP: ffff8801f0b0fc38 R08: ffff8801f0b0f9e0 R09: ffff8801f0b0fa20 +[ 237.772650] R10: 0000000000000003 R11: ffffed003e161f7c R12: 0000000007400000 +[ 237.774119] R13: 0000000000000001 R14: ffff8801f2bf0a50 R15: ffff8801f0b0fc10 +[ 237.775598] FS: 00007f691b770840(0000) GS:ffff8801f6f00000(0000) knlGS:0000000000000000 +[ 237.777297] CS: 0010 DS: 0000 ES: 0000 CR0: 0000000080050033 +[ 237.778496] CR2: 0000000000cb0348 CR3: 00000001f26f8000 CR4: 00000000000006e0 + + +===== Extra info for btrfs-progs ====== +It has one corrupted root item, (41 ROOT_ITEM 0) referring tree block +29364224, which is also UUID tree root. +It would cause original mode to hit BUG_ON(). +Checking filesystem on /home/adam/btrfs/crafted_images/runtime/0.img +UUID: 3381d111-94a3-4ac7-8f39-611bbbdab7e6 +checking extents +check/main.c:3677: check_owner_ref: BUG_ON `rec->is_root` triggered, value 1 +btrfs(+0x572c2)[0x562d65da72c2] +btrfs(+0x6098d)[0x562d65db098d] +btrfs(+0x60bb6)[0x562d65db0bb6] +btrfs(+0x6179b)[0x562d65db179b] +btrfs(cmd_check+0x1199)[0x562d65db5589] +btrfs(main+0x88)[0x562d65d62768] +/usr/lib/libc.so.6(__libc_start_main+0xeb)[0x7f4fcbb1b06b] +btrfs(_start+0x2a)[0x562d65d6288a] diff --git a/tests/fuzz-tests/images/bko-200403.raw.xz b/tests/fuzz-tests/images/bko-200403.raw.xz new file mode 100644 index 00000000..56959457 Binary files /dev/null and b/tests/fuzz-tests/images/bko-200403.raw.xz differ -- cgit v1.2.3 From d6f5504239b097a3904df88982882825cc32a178 Mon Sep 17 00:00:00 2001 From: Qu Wenruo Date: Thu, 5 Jul 2018 15:45:58 +0800 Subject: btrfs-progs: test/fuzz: Add image for BUG_ON() when opening the fs by btrfs check Link: https://bugzilla.kernel.org/show_bug.cgi?id=199839 Signed-off-by: Qu Wenruo Signed-off-by: David Sterba --- tests/fuzz-tests/images/bko-199839.raw.txt | 198 +++++++++++++++++++++++++++++ tests/fuzz-tests/images/bko-199839.raw.xz | Bin 0 -> 24400 bytes 2 files changed, 198 insertions(+) create mode 100644 tests/fuzz-tests/images/bko-199839.raw.txt create mode 100644 tests/fuzz-tests/images/bko-199839.raw.xz (limited to 'tests') diff --git a/tests/fuzz-tests/images/bko-199839.raw.txt b/tests/fuzz-tests/images/bko-199839.raw.txt new file mode 100644 index 00000000..3e4b273d --- /dev/null +++ b/tests/fuzz-tests/images/bko-199839.raw.txt @@ -0,0 +1,198 @@ +URL: https://bugzilla.kernel.org/show_bug.cgi?id=199839 +Wen Xu 2018-05-26 04:18:45 UTC + +Created attachment 276197 [details] +The (compressed) crafted image which causes crash + +- Overview +use-after-free in try_merge_free_space() when mounting a crafted btrfs image + +- Reproduce (4.17 KASAN build) +# mkdir mnt +# mount -t btrfs 8.img mnt + +- Kernel Message +[ 449.751861] BTRFS: device fsid 12b338de-a2e9-40fa-a4b0-90e53b7c5773 devid 1 transid 8 /dev/loop0 +[ 449.757216] BTRFS info (device loop0): disk space caching is enabled +[ 449.757221] BTRFS info (device loop0): has skinny extents +[ 449.785096] BTRFS error (device loop0): bad tree block start 0 29396992 +[ 449.788629] BTRFS info (device loop0): read error corrected: ino 0 off 29396992 (dev /dev/loop0 sector 73800) +[ 449.792965] BTRFS error (device loop0): bad fsid on block 29409280 +[ 449.795193] BTRFS info (device loop0): read error corrected: ino 0 off 29409280 (dev /dev/loop0 sector 73824) +[ 449.795401] BTRFS info (device loop0): creating UUID tree +[ 449.883426] ================================================================== +[ 449.886228] BUG: KASAN: use-after-free in try_merge_free_space+0xc0/0x2e0 +[ 449.888344] Read of size 8 at addr ffff8801ed10f030 by task mount/1291 + +[ 449.889947] CPU: 1 PID: 1291 Comm: mount Not tainted 4.17.0-rc5+ #6 +[ 449.889951] Hardware name: QEMU Standard PC (i440FX + PIIX, 1996), BIOS Ubuntu-1.8.2-1ubuntu1 04/01/2014 +[ 449.889953] Call Trace: +[ 449.889976] dump_stack+0x7b/0xb5 +[ 449.890274] print_address_description+0x70/0x290 +[ 449.890286] kasan_report+0x291/0x390 +[ 449.890296] ? try_merge_free_space+0xc0/0x2e0 +[ 449.890303] __asan_load8+0x54/0x90 +[ 449.890310] try_merge_free_space+0xc0/0x2e0 +[ 449.890318] __btrfs_add_free_space+0x96/0x5e0 +[ 449.890324] ? kasan_check_write+0x14/0x20 +[ 449.890331] ? btrfs_get_block_group+0x1e/0x30 +[ 449.890337] ? block_group_cache_tree_search+0xef/0x150 +[ 449.890343] unpin_extent_range+0x376/0x670 +[ 449.890350] ? __exclude_logged_extent+0x160/0x160 +[ 449.890358] btrfs_finish_extent_commit+0x15b/0x490 +[ 449.890371] ? __find_get_block+0x106/0x400 +[ 449.890378] ? btrfs_prepare_extent_commit+0x1a0/0x1a0 +[ 449.890384] ? write_all_supers+0x714/0x1420 +[ 449.890394] btrfs_commit_transaction+0xaf4/0xfa0 +[ 449.890402] ? btrfs_apply_pending_changes+0xa0/0xa0 +[ 449.890407] ? start_transaction+0x153/0x640 +[ 449.890414] btrfs_create_uuid_tree+0x6a/0x170 +[ 449.890419] open_ctree+0x3b26/0x3ce9 +[ 449.890429] ? close_ctree+0x4a0/0x4a0 +[ 449.890441] ? bdi_register_va+0x44/0x50 +[ 449.890451] ? super_setup_bdi_name+0x11b/0x1a0 +[ 449.890457] ? kill_block_super+0x80/0x80 +[ 449.890468] ? snprintf+0x96/0xd0 +[ 449.890479] btrfs_mount_root+0xae6/0xc60 +[ 449.890485] ? btrfs_mount_root+0xae6/0xc60 +[ 449.890491] ? pcpu_block_update_hint_alloc+0x1f5/0x2a0 +[ 449.890498] ? btrfs_decode_error+0x40/0x40 +[ 449.890510] ? find_next_bit+0x57/0x90 +[ 449.890517] ? cpumask_next+0x1a/0x20 +[ 449.890522] ? pcpu_alloc+0x449/0x8c0 +[ 449.890528] ? pcpu_free_area+0x410/0x410 +[ 449.890534] ? memcg_kmem_put_cache+0x1b/0xa0 +[ 449.890540] ? memcpy+0x45/0x50 +[ 449.890547] mount_fs+0x60/0x1a0 +[ 449.890553] ? btrfs_decode_error+0x40/0x40 +[ 449.890558] ? mount_fs+0x60/0x1a0 +[ 449.890565] ? alloc_vfsmnt+0x309/0x360 +[ 449.890570] vfs_kern_mount+0x6b/0x1a0 +[ 449.890576] ? entry_SYSCALL_64_after_hwframe+0x44/0xa9 +[ 449.890583] btrfs_mount+0x209/0xb71 +[ 449.890589] ? pcpu_block_update_hint_alloc+0x1f5/0x2a0 +[ 449.890595] ? btrfs_remount+0x8e0/0x8e0 +[ 449.890601] ? find_next_zero_bit+0x2c/0xa0 +[ 449.890608] ? find_next_bit+0x57/0x90 +[ 449.890613] ? cpumask_next+0x1a/0x20 +[ 449.890617] ? pcpu_alloc+0x449/0x8c0 +[ 449.890624] ? pcpu_free_area+0x410/0x410 +[ 449.890629] ? memcg_kmem_put_cache+0x1b/0xa0 +[ 449.890634] ? memcpy+0x45/0x50 +[ 449.890641] mount_fs+0x60/0x1a0 +[ 449.890646] ? btrfs_remount+0x8e0/0x8e0 +[ 449.890652] ? mount_fs+0x60/0x1a0 +[ 449.890656] ? alloc_vfsmnt+0x309/0x360 +[ 449.890662] vfs_kern_mount+0x6b/0x1a0 +[ 449.890668] do_mount+0x34a/0x18a0 +[ 449.890673] ? lockref_put_or_lock+0xcf/0x160 +[ 449.890680] ? copy_mount_string+0x20/0x20 +[ 449.890685] ? memcg_kmem_put_cache+0x1b/0xa0 +[ 449.890691] ? kasan_check_write+0x14/0x20 +[ 449.890696] ? _copy_from_user+0x6a/0x90 +[ 449.890702] ? memdup_user+0x42/0x60 +[ 449.890708] ksys_mount+0x83/0xd0 +[ 449.890714] __x64_sys_mount+0x67/0x80 +[ 449.890723] do_syscall_64+0x78/0x170 +[ 449.890729] entry_SYSCALL_64_after_hwframe+0x44/0xa9 +[ 449.890734] RIP: 0033:0x7fc36964fb9a +[ 449.890737] RSP: 002b:00007ffd268892f8 EFLAGS: 00000202 ORIG_RAX: 00000000000000a5 +[ 449.890744] RAX: ffffffffffffffda RBX: 0000000000e7f030 RCX: 00007fc36964fb9a +[ 449.890747] RDX: 0000000000e7f210 RSI: 0000000000e80f30 RDI: 0000000000e87ec0 +[ 449.890750] RBP: 0000000000000000 R08: 0000000000000000 R09: 0000000000000014 +[ 449.890753] R10: 00000000c0ed0000 R11: 0000000000000202 R12: 0000000000e87ec0 +[ 449.890756] R13: 0000000000e7f210 R14: 0000000000000000 R15: 0000000000000003 + +[ 449.891109] Allocated by task 1291: +[ 449.891832] save_stack+0x46/0xd0 +[ 449.891838] kasan_kmalloc+0xad/0xe0 +[ 449.891843] kasan_slab_alloc+0x11/0x20 +[ 449.891848] kmem_cache_alloc+0xd1/0x1e0 +[ 449.891854] __btrfs_add_free_space+0x43/0x5e0 +[ 449.891859] add_new_free_space+0x22b/0x240 +[ 449.891864] btrfs_read_block_groups+0xae3/0xc60 +[ 449.891868] open_ctree+0x2cfc/0x3ce9 +[ 449.891873] btrfs_mount_root+0xae6/0xc60 +[ 449.891878] mount_fs+0x60/0x1a0 +[ 449.891883] vfs_kern_mount+0x6b/0x1a0 +[ 449.891888] btrfs_mount+0x209/0xb71 +[ 449.891893] mount_fs+0x60/0x1a0 +[ 449.891897] vfs_kern_mount+0x6b/0x1a0 +[ 449.891902] do_mount+0x34a/0x18a0 +[ 449.891906] ksys_mount+0x83/0xd0 +[ 449.891911] __x64_sys_mount+0x67/0x80 +[ 449.891916] do_syscall_64+0x78/0x170 +[ 449.891921] entry_SYSCALL_64_after_hwframe+0x44/0xa9 + +[ 449.892235] Freed by task 1291: +[ 449.892866] save_stack+0x46/0xd0 +[ 449.892872] __kasan_slab_free+0x13c/0x1a0 +[ 449.892877] kasan_slab_free+0xe/0x10 +[ 449.892882] kmem_cache_free+0x89/0x1e0 +[ 449.892888] try_merge_free_space+0x274/0x2e0 +[ 449.892894] __btrfs_add_free_space+0x96/0x5e0 +[ 449.892898] unpin_extent_range+0x376/0x670 +[ 449.892904] btrfs_finish_extent_commit+0x15b/0x490 +[ 449.892909] btrfs_commit_transaction+0xaf4/0xfa0 +[ 449.892913] btrfs_create_uuid_tree+0x6a/0x170 +[ 449.892917] open_ctree+0x3b26/0x3ce9 +[ 449.892922] btrfs_mount_root+0xae6/0xc60 +[ 449.892927] mount_fs+0x60/0x1a0 +[ 449.892932] vfs_kern_mount+0x6b/0x1a0 +[ 449.892937] btrfs_mount+0x209/0xb71 +[ 449.892942] mount_fs+0x60/0x1a0 +[ 449.892946] vfs_kern_mount+0x6b/0x1a0 +[ 449.892951] do_mount+0x34a/0x18a0 +[ 449.892955] ksys_mount+0x83/0xd0 +[ 449.892960] __x64_sys_mount+0x67/0x80 +[ 449.892965] do_syscall_64+0x78/0x170 +[ 449.892970] entry_SYSCALL_64_after_hwframe+0x44/0xa9 + +[ 449.893286] The buggy address belongs to the object at ffff8801ed10f000 + which belongs to the cache btrfs_free_space of size 72 +[ 449.895793] The buggy address is located 48 bytes inside of + 72-byte region [ffff8801ed10f000, ffff8801ed10f048) +[ 449.898035] The buggy address belongs to the page: +[ 449.898979] page:ffffea0007b443c0 count:1 mapcount:0 mapping:0000000000000000 index:0x0 +[ 449.900562] flags: 0x2ffff0000000100(slab) +[ 449.901379] raw: 02ffff0000000100 0000000000000000 0000000000000000 0000000180270027 +[ 449.902881] raw: dead000000000100 dead000000000200 ffff8801e0a676c0 0000000000000000 +[ 449.904396] page dumped because: kasan: bad access detected + +[ 449.905800] Memory state around the buggy address: +[ 449.906748] ffff8801ed10ef00: 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 +[ 449.908165] ffff8801ed10ef80: 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 +[ 449.909577] >ffff8801ed10f000: fb fb fb fb fb fb fb fb fb fc fc fc fc fc fc fc +[ 449.910969] ^ +[ 449.911933] ffff8801ed10f080: fc fc fc fc fc fc fc fc fc fc fc fc fc fc fc fc +[ 449.913328] ffff8801ed10f100: fc fc fc fc fc fc fc fc fc fc fc fc fc fc fc fc +[ 449.914720] ================================================================== +[ 449.916119] Disabling lock debugging due to kernel taint + +No kernel crash on plain kernel. + +- Reason +https://elixir.bootlin.com/linux/v4.17-rc5/source/fs/btrfs/free-space-cache.c#L2161 + + if (left_info && !left_info->bitmap && + left_info->offset + left_info->bytes == offset) { + if (update_stat) + unlink_free_space(ctl, left_info); + else + __unlink_free_space(ctl, left_info); + info->offset = left_info->offset; + info->bytes += left_info->bytes; + kmem_cache_free(btrfs_free_space_cachep, left_info); + merged = true; + } + + return merged; + +Regarding KASAN report, left_info is already freed but referenced (->bitmap). It is in fact freed just several lines after, namely kmem_cache_free(btrfs_free_space_cachep, left_info); + +Found by Wen Xu and Po-Ning Tseng from SSLab, Gatech. + +===== Extra info for btrfs-progs ===== +This image could cause btrfs-progs to BUG_ON() when opening the image. +Fixed by "btrfs-progs: Don't BUG_ON() if we failed to load one device or one +chunk". diff --git a/tests/fuzz-tests/images/bko-199839.raw.xz b/tests/fuzz-tests/images/bko-199839.raw.xz new file mode 100644 index 00000000..c06d9540 Binary files /dev/null and b/tests/fuzz-tests/images/bko-199839.raw.xz differ -- cgit v1.2.3 From e6203e6ff9fc0ee2f15dd06b4db61b89eaace982 Mon Sep 17 00:00:00 2001 From: Su Yue Date: Tue, 3 Jul 2018 15:58:51 +0800 Subject: btrfs-progs: fsck-tests: add test case with keyed data backref with reloc tree blocks For trees have been balanced, leaves are with flag BTRFS_HEADER_FLAG_RELOC and extent data backrefs are shared. Like: ===================== item 0 key (11927552 EXTENT_ITEM 524288) itemoff 3932 itemsize 63 refs 129 gen 7 flags DATA shared data backref parent 35897344 count 41 shared data backref parent 35426304 count 37 shared data backref parent 35422208 count 51 ===================== Then make the leaf which owns the extent data cowed. The shared data backref was to transferred to keyed data ref, but remaining backrefs are still shared. Like: ===================== item 0 key (11927552 EXTENT_ITEM 524288) itemoff 3887 itemsize 108 refs 129 gen 7 flags DATA extent data backref root 5 objectid 258 offset 0 count 40 extent data backref root 5 objectid 257 offset 0 count 1 shared data backref parent 35426304 count 37 shared data backref parent 35422208 count 51 ===================== However lowmem mode used to iterate the whole inode to find all references, and doesn't care if a reference is already counted by the shared tree block. Add the test case to check it. Signed-off-by: Su Yue Signed-off-by: David Sterba --- .../keyed_data_ref_with_reloc_leaf.img | Bin 0 -> 16384 bytes 1 file changed, 0 insertions(+), 0 deletions(-) create mode 100644 tests/fsck-tests/020-extent-ref-cases/keyed_data_ref_with_reloc_leaf.img (limited to 'tests') diff --git a/tests/fsck-tests/020-extent-ref-cases/keyed_data_ref_with_reloc_leaf.img b/tests/fsck-tests/020-extent-ref-cases/keyed_data_ref_with_reloc_leaf.img new file mode 100644 index 00000000..80345cf9 Binary files /dev/null and b/tests/fsck-tests/020-extent-ref-cases/keyed_data_ref_with_reloc_leaf.img differ -- cgit v1.2.3 From d99615284a83452c019f5bed05a882f93a4ef19a Mon Sep 17 00:00:00 2001 From: Qu Wenruo Date: Thu, 26 Jul 2018 14:39:01 +0800 Subject: btrfs-progs: fsck-tests: Add test image to check if btrfs check reports uninitialized rescan as error Signed-off-by: Qu Wenruo Signed-off-by: David Sterba --- .../035-rescan-not-kicked-in/no_rescan_kicked_in.img | Bin 0 -> 3072 bytes tests/fsck-tests/035-rescan-not-kicked-in/test.sh | 17 +++++++++++++++++ 2 files changed, 17 insertions(+) create mode 100644 tests/fsck-tests/035-rescan-not-kicked-in/no_rescan_kicked_in.img create mode 100755 tests/fsck-tests/035-rescan-not-kicked-in/test.sh (limited to 'tests') diff --git a/tests/fsck-tests/035-rescan-not-kicked-in/no_rescan_kicked_in.img b/tests/fsck-tests/035-rescan-not-kicked-in/no_rescan_kicked_in.img new file mode 100644 index 00000000..b855a72f Binary files /dev/null and b/tests/fsck-tests/035-rescan-not-kicked-in/no_rescan_kicked_in.img differ diff --git a/tests/fsck-tests/035-rescan-not-kicked-in/test.sh b/tests/fsck-tests/035-rescan-not-kicked-in/test.sh new file mode 100755 index 00000000..82fa978e --- /dev/null +++ b/tests/fsck-tests/035-rescan-not-kicked-in/test.sh @@ -0,0 +1,17 @@ +#!/bin/bash +# Under certain power loss case, btrfs quota tree can be initialized but +# rescan not kicked in. Can be also reproduced by fstests/btrfs/166 but with +# low probability. +# +# This test case verifies a special case when 'btrfs check' does not report +# qgroup accounting differece as an error, thus no false alert for btrfs/166. + +source "$TEST_TOP/common" + +check_prereq btrfs + +check_image() { + run_check "$TOP/btrfs" check "$1" +} + +check_all_images -- cgit v1.2.3 From b3b0c404657bcdca6d837f10d972d8237d2b49a3 Mon Sep 17 00:00:00 2001 From: David Sterba Date: Fri, 24 Aug 2018 13:15:03 +0200 Subject: btrfs-progs: tests: renumber last fsck test to 036-rescan-not-kicked-in The commit d99615284a83452c019f5bed05a882f93a4ef19a ("btrfs-progs: fsck-tests: Add test image to check if btrfs check reports uninitialized rescan as error") added test 035, should have been 036. Signed-off-by: David Sterba --- .../035-rescan-not-kicked-in/no_rescan_kicked_in.img | Bin 3072 -> 0 bytes tests/fsck-tests/035-rescan-not-kicked-in/test.sh | 17 ----------------- .../036-rescan-not-kicked-in/no_rescan_kicked_in.img | Bin 0 -> 3072 bytes tests/fsck-tests/036-rescan-not-kicked-in/test.sh | 17 +++++++++++++++++ 4 files changed, 17 insertions(+), 17 deletions(-) delete mode 100644 tests/fsck-tests/035-rescan-not-kicked-in/no_rescan_kicked_in.img delete mode 100755 tests/fsck-tests/035-rescan-not-kicked-in/test.sh create mode 100644 tests/fsck-tests/036-rescan-not-kicked-in/no_rescan_kicked_in.img create mode 100755 tests/fsck-tests/036-rescan-not-kicked-in/test.sh (limited to 'tests') diff --git a/tests/fsck-tests/035-rescan-not-kicked-in/no_rescan_kicked_in.img b/tests/fsck-tests/035-rescan-not-kicked-in/no_rescan_kicked_in.img deleted file mode 100644 index b855a72f..00000000 Binary files a/tests/fsck-tests/035-rescan-not-kicked-in/no_rescan_kicked_in.img and /dev/null differ diff --git a/tests/fsck-tests/035-rescan-not-kicked-in/test.sh b/tests/fsck-tests/035-rescan-not-kicked-in/test.sh deleted file mode 100755 index 82fa978e..00000000 --- a/tests/fsck-tests/035-rescan-not-kicked-in/test.sh +++ /dev/null @@ -1,17 +0,0 @@ -#!/bin/bash -# Under certain power loss case, btrfs quota tree can be initialized but -# rescan not kicked in. Can be also reproduced by fstests/btrfs/166 but with -# low probability. -# -# This test case verifies a special case when 'btrfs check' does not report -# qgroup accounting differece as an error, thus no false alert for btrfs/166. - -source "$TEST_TOP/common" - -check_prereq btrfs - -check_image() { - run_check "$TOP/btrfs" check "$1" -} - -check_all_images diff --git a/tests/fsck-tests/036-rescan-not-kicked-in/no_rescan_kicked_in.img b/tests/fsck-tests/036-rescan-not-kicked-in/no_rescan_kicked_in.img new file mode 100644 index 00000000..b855a72f Binary files /dev/null and b/tests/fsck-tests/036-rescan-not-kicked-in/no_rescan_kicked_in.img differ diff --git a/tests/fsck-tests/036-rescan-not-kicked-in/test.sh b/tests/fsck-tests/036-rescan-not-kicked-in/test.sh new file mode 100755 index 00000000..82fa978e --- /dev/null +++ b/tests/fsck-tests/036-rescan-not-kicked-in/test.sh @@ -0,0 +1,17 @@ +#!/bin/bash +# Under certain power loss case, btrfs quota tree can be initialized but +# rescan not kicked in. Can be also reproduced by fstests/btrfs/166 but with +# low probability. +# +# This test case verifies a special case when 'btrfs check' does not report +# qgroup accounting differece as an error, thus no false alert for btrfs/166. + +source "$TEST_TOP/common" + +check_prereq btrfs + +check_image() { + run_check "$TOP/btrfs" check "$1" +} + +check_all_images -- cgit v1.2.3 From 5950bcd1214e91af3fdb618a65e34d7d5360a188 Mon Sep 17 00:00:00 2001 From: Nikolay Borisov Date: Mon, 3 Sep 2018 13:02:57 +0300 Subject: btrfs-progs: tests: add test for missing device delete error value Add a test which ensures the kernel returns the correct error value when missing device removal is requested. This test verifies that kernel refactoring didn't break the return value. Signed-off-by: Nikolay Borisov Signed-off-by: David Sterba --- tests/misc-tests/011-delete-missing-device/test.sh | 17 +++++++++++++++++ 1 file changed, 17 insertions(+) (limited to 'tests') diff --git a/tests/misc-tests/011-delete-missing-device/test.sh b/tests/misc-tests/011-delete-missing-device/test.sh index 4c976421..a6b2e29c 100755 --- a/tests/misc-tests/011-delete-missing-device/test.sh +++ b/tests/misc-tests/011-delete-missing-device/test.sh @@ -44,6 +44,22 @@ test_delete_missing() run_check_umount_test_dev } +test_missing_error() +{ + local out + + run_check $SUDO_HELPER "$TOP/mkfs.btrfs" -f "$TEST_DEV" + run_check_mount_test_dev + out=$(run_mustfail_stdout "device remove succeeded" \ + $SUDO_HELPER "$TOP/btrfs" device remove missing "$TEST_MNT") + + if ! echo "$out" | grep -q "no missing devices found to remove"; then + _fail "IOCTL returned unexpected error value" + fi + + run_check_umount_test_dev +} + setup_loopdevs 4 prepare_loopdevs dev1=${loopdevs[1]} @@ -53,5 +69,6 @@ TEST_DEV=$dev1 test_do_mkfs -m raid1 -d raid1 test_wipefs test_delete_missing +test_missing_error cleanup_loopdevs -- cgit v1.2.3 From 1cf5833aa671f935eb3372e13c4eb039ee81d53e Mon Sep 17 00:00:00 2001 From: Nikolay Borisov Date: Mon, 1 Oct 2018 17:46:20 +0300 Subject: btrfs-progs: tests: Test for FST corruption detection/repair Simple test case which preps a filesystem, then corrupts the FST and finally repairs it. Tests both extent based and bitmap based FSTs. Signed-off-by: Nikolay Borisov Signed-off-by: David Sterba --- tests/fsck-tests/037-freespacetree-repair/test.sh | 76 +++++++++++++++++++++++ 1 file changed, 76 insertions(+) create mode 100755 tests/fsck-tests/037-freespacetree-repair/test.sh (limited to 'tests') diff --git a/tests/fsck-tests/037-freespacetree-repair/test.sh b/tests/fsck-tests/037-freespacetree-repair/test.sh new file mode 100755 index 00000000..c38a4c85 --- /dev/null +++ b/tests/fsck-tests/037-freespacetree-repair/test.sh @@ -0,0 +1,76 @@ +#!/bin/bash +# Corrupt a filesystem that is using freespace tree and then ensure that +# btrfs check is able to repair it. This tests correct detection/repair of +# both a FREE_SPACE_EXTENT based FST and a FREE_SPACE_BITMAP based FST. + +source "$TEST_TOP/common" + +setup_root_helper +prepare_test_dev 256M + +check_prereq btrfs +check_prereq mkfs.btrfs +check_global_prereq grep +check_global_prereq tail +check_global_prereq head +check_global_prereq cut + +# wrapper for btrfs-corrupt-item +# $1: Type of item we want to corrupt - extent or bitmap +corrupt_fst_item() +{ + local type + local objectid + local offset + type="$1" + + if [[ $type == "bitmap" ]]; then + type=200 + objectid=$("$TOP/btrfs" inspect-internal dump-tree -t 10 "$TEST_DEV" | \ + grep -o "[[:digit:]]* FREE_SPACE_BITMAP [[:digit:]]*" | \ + cut -d' ' -f1 | tail -2 | head -1) + offset=$("$TOP/btrfs" inspect-internal dump-tree -t 10 "$TEST_DEV" | \ + grep -o "[[:digit:]]* FREE_SPACE_BITMAP [[:digit:]]*" | \ + cut -d' ' -f3 | tail -2 | head -1) + echo "Corrupting $objectid,FREE_SPACE_BITMAP,$offset" >> "$RESULTS" + elif [[ $type == "extent" ]]; then + type=199 + objectid=$("$TOP/btrfs" inspect-internal dump-tree -t 10 "$TEST_DEV" | \ + grep -o "[[:digit:]]* FREE_SPACE_EXTENT [[:digit:]]*" | \ + cut -d' ' -f1 | tail -2 | head -1) + offset=$("$TOP/btrfs" inspect-internal dump-tree -t 10 "$TEST_DEV" | \ + grep -o "[[:digit:]]* FREE_SPACE_EXTENT [[:digit:]]*" | \ + cut -d' ' -f3 | tail -2 | head -1) + echo "Corrupting $objectid,FREE_SPACE_EXTENT,$offset" >> "$RESULTS" + else + _fail "Unknown item type for corruption" + fi + + run_check "$TOP/btrfs-corrupt-block" -r 10 -K "$objectid,$type,$offset" \ + -f offset "$TEST_DEV" +} + +run_check "$TOP/mkfs.btrfs" -n 4k -f "$TEST_DEV" +run_check_mount_test_dev -oclear_cache,space_cache=v2 + +# create files which will populate the FST +for i in {1..3000}; do + run_check $SUDO_HELPER fallocate -l 4k "$TEST_MNT/file.$i" +done + +run_check_umount_test_dev + +# now corrupt one of the bitmap items +corrupt_fst_item "bitmap" +check_image "$TEST_DEV" + +# change the freespace such that we now have at least one free_space_extent +# object +run_check_mount_test_dev +rm -rf "$TEST_MNT/file.*" +run_check $SUDO_HELPER fallocate -l 50m "$TEST_MNT/file" +run_check_umount_test_dev + +# now corrupt an extent +corrupt_fst_item "extent" +check_image "$TEST_DEV" -- cgit v1.2.3 From 9d3303fa1b5d8e797a63c588934d0f7a6c84fa1c Mon Sep 17 00:00:00 2001 From: David Sterba Date: Tue, 23 Oct 2018 16:57:48 +0200 Subject: btrfs-progs: tests: add runtime check for free-space-tree The CI hosts have old kernel that does not support the FST, make the test fail gracefully. Signed-off-by: David Sterba --- tests/fsck-tests/037-freespacetree-repair/test.sh | 5 +++++ 1 file changed, 5 insertions(+) (limited to 'tests') diff --git a/tests/fsck-tests/037-freespacetree-repair/test.sh b/tests/fsck-tests/037-freespacetree-repair/test.sh index c38a4c85..261d7ccb 100755 --- a/tests/fsck-tests/037-freespacetree-repair/test.sh +++ b/tests/fsck-tests/037-freespacetree-repair/test.sh @@ -50,6 +50,11 @@ corrupt_fst_item() -f offset "$TEST_DEV" } +if ! [ -f "/sys/fs/btrfs/features/free_space_tree" ]; then + _not_run "kernel does not support free-space-tree feature" + exit +fi + run_check "$TOP/mkfs.btrfs" -n 4k -f "$TEST_DEV" run_check_mount_test_dev -oclear_cache,space_cache=v2 -- cgit v1.2.3 From b4843d366906cdb5b1198c0206b720ba28ee66f6 Mon Sep 17 00:00:00 2001 From: Su Yanjun Date: Tue, 18 Sep 2018 16:44:48 +0800 Subject: btrfs-progs: tests: Add the testcase for subvolume name length limit test Total of three conditions are tested. One for short name, one with name length 255, the last one with more than 255. This case should pass after commit 'btrfs-progs: change filename limit to 255 when creating subvolume'. Signed-off-by: Su Yanjun Signed-off-by: David Sterba --- tests/misc-tests/033-filename-length-limit/test.sh | 82 ++++++++++++++++++++++ 1 file changed, 82 insertions(+) create mode 100755 tests/misc-tests/033-filename-length-limit/test.sh (limited to 'tests') diff --git a/tests/misc-tests/033-filename-length-limit/test.sh b/tests/misc-tests/033-filename-length-limit/test.sh new file mode 100755 index 00000000..673138e2 --- /dev/null +++ b/tests/misc-tests/033-filename-length-limit/test.sh @@ -0,0 +1,82 @@ +#!/bin/bash +# +# test file name length limits for subvolumes + +source "$TEST_TOP/common" + +check_prereq mkfs.btrfs +check_prereq btrfs + +setup_root_helper +prepare_test_dev + +run_check "$TOP/mkfs.btrfs" -f "$TEST_DEV" +run_check_mount_test_dev +run_check $SUDO_HELPER chmod a+rw "$TEST_MNT" + +cd "$TEST_MNT" + +longname=\ +0123456789\ +0123456789\ +0123456789\ +0123456789\ +0123456789\ +\ +0123456789\ +0123456789\ +0123456789\ +0123456789\ +0123456789\ +\ +0123456789\ +0123456789\ +0123456789\ +0123456789\ +0123456789\ +\ +0123456789\ +0123456789\ +0123456789\ +0123456789\ +0123456789\ +\ +0123456789\ +0123456789\ +0123456789\ +0123456789\ +0123456789\ +\ +01234 + +# subvolume name length limit test + +# short name test +run_check $SUDO_HELPER "$TOP/btrfs" subvolume create subvol +# 255 +run_check $SUDO_HELPER "$TOP/btrfs" subvolume create "$longname" +# 256, must fail +run_mustfail "subvolume with name 256 bytes long succeeded" \ + $SUDO_HELPER "$TOP/btrfs" subvolume create "$longname"5 +# 255*2, must fail +run_mustfail "subvolume with name 2 * 255 bytes long succeeded" \ + $SUDO_HELPER "$TOP/btrfs" subvolume create "$longname$longname" + +# snapshot name length limit test + +run_check $SUDO_HELPER mkdir snaps + +# short name test +run_check $SUDO_HELPER "$TOP/btrfs" subvolume snapshot subvol snaps/snap +# 255 +run_check $SUDO_HELPER "$TOP/btrfs" subvolume snapshot subvol snaps/"$longname" +# 256, must fail +run_mustfail "snapshot with name 256 bytes long succeeded" \ + $SUDO_HELPER "$TOP/btrfs" subvolume snapshot subvol snaps/"$longname"5 +# 255*2, must fail +run_mustfail "subvolume with name 2 * 255 bytes long succeeded" \ + $SUDO_HELPER "$TOP/btrfs" subvolume snapshot subvol snaps/"$longname$longname" + +cd .. + +run_check_umount_test_dev -- cgit v1.2.3 From 2e67bf0ed69d0a07a0d6bee628301e0da7c6e973 Mon Sep 17 00:00:00 2001 From: Josh Soref Date: Mon, 26 Nov 2018 17:47:22 +0100 Subject: btrfs-progs: docs: fix typos in READMEs, INSTALL and CHANGES Generated by https://github.com/jsoref/spelling Issue: #154 Author: Josh Soref Signed-off-by: David Sterba --- tests/README.md | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) (limited to 'tests') diff --git a/tests/README.md b/tests/README.md index d14d727c..94c5533d 100644 --- a/tests/README.md +++ b/tests/README.md @@ -170,7 +170,7 @@ how to do mkfs, mount, unmount, check, loop device management etc. and join by dashes `-`. This will become the directory name, eg. `012-subvolume-sync-must-wait`. 3. Write a short description of the bug and how it's tested to the comment at the -begining of `test.sh`. You don't need to add the file to git yet. Don't forget +beginning of `test.sh`. You don't need to add the file to git yet. Don't forget to make the file executable, otherwise it's not going to be executed by the infrastructure. @@ -194,7 +194,7 @@ $ TEST=012\* ./misc-tests.sh # from tests/ Most tests should be able to create the test images from scratch, using regular commands and file operation. The commands also document the testcase and use -the teste code and kernel of the environment. +the test code and kernel of the environment. In other cases, a pre-created image may be the right way if the above does not work (eg. comparing output, requesting an exact layout or some intermediate @@ -244,7 +244,7 @@ There are some utilities that are not distributed but are necessary for the tests. They are in the top level directory of the testsuite and their path cannot be set. -The tests assume write acesss to their directories. +The tests assume write access to their directories. # Coding style, best practices -- cgit v1.2.3 From 0509c05ae6bd7461964d3e483246aa07a63ee6d0 Mon Sep 17 00:00:00 2001 From: Josh Soref Date: Mon, 26 Nov 2018 17:53:43 +0100 Subject: btrfs-progs: tests: fix typos in test comments Generated by https://github.com/jsoref/spelling Issue: #154 Author: Josh Soref Signed-off-by: David Sterba --- tests/cli-tests/007-check-force/test.sh | 2 +- tests/common | 2 +- tests/fsck-tests/031-metadatadump-check-data-csum/test.sh | 4 ++-- tests/fsck-tests/036-rescan-not-kicked-in/test.sh | 2 +- tests/misc-tests/006-image-on-missing-device/test.sh | 2 +- tests/misc-tests/029-send-p-different-mountpoints/test.sh | 2 +- 6 files changed, 7 insertions(+), 7 deletions(-) (limited to 'tests') diff --git a/tests/cli-tests/007-check-force/test.sh b/tests/cli-tests/007-check-force/test.sh index 597f2d60..deee96c8 100755 --- a/tests/cli-tests/007-check-force/test.sh +++ b/tests/cli-tests/007-check-force/test.sh @@ -10,7 +10,7 @@ check_prereq btrfs setup_root_helper # we need to use a real block device, because the check opens the device in -# exclusive mode, that unfortunatelly behaves differently for direct file +# exclusive mode, that unfortunately behaves differently for direct file # access and for the real /dev/loop0 device setup_loopdevs 1 prepare_loopdevs diff --git a/tests/common b/tests/common index 7e4e09df..1575ae38 100644 --- a/tests/common +++ b/tests/common @@ -171,7 +171,7 @@ run_check_stdout() } # same as run_check but does not fail the test if it's handled gracefully by -# the tool, unexpected failure like segfault or abor will exit forcibly +# the tool, unexpected failure like segfault or abort will exit forcibly # output is logged run_mayfail() { diff --git a/tests/fsck-tests/031-metadatadump-check-data-csum/test.sh b/tests/fsck-tests/031-metadatadump-check-data-csum/test.sh index e9b2d5c6..7f3872e6 100755 --- a/tests/fsck-tests/031-metadatadump-check-data-csum/test.sh +++ b/tests/fsck-tests/031-metadatadump-check-data-csum/test.sh @@ -1,5 +1,5 @@ #!/bin/bash -# To check if "btrfs check" can detect metadata dump (restored by btrfs-iamge) +# To check if "btrfs check" can detect metadata dump (restored by btrfs-image) # and ignore --check-data-csum option source "$TEST_TOP/common" @@ -21,7 +21,7 @@ chmod a+w restored_image run_check $SUDO_HELPER "$TOP/btrfs-image" "$TEST_DEV" "restored_image" # use prepare_test_dev() to wipe all existing data on $TEST_DEV -# so there is no way that restored image could have mathcing data csum +# so there is no way that restored image could have matching data csum prepare_test_dev run_check $SUDO_HELPER "$TOP/btrfs-image" -r "restored_image" "$TEST_DEV" diff --git a/tests/fsck-tests/036-rescan-not-kicked-in/test.sh b/tests/fsck-tests/036-rescan-not-kicked-in/test.sh index 82fa978e..eafd599d 100755 --- a/tests/fsck-tests/036-rescan-not-kicked-in/test.sh +++ b/tests/fsck-tests/036-rescan-not-kicked-in/test.sh @@ -4,7 +4,7 @@ # low probability. # # This test case verifies a special case when 'btrfs check' does not report -# qgroup accounting differece as an error, thus no false alert for btrfs/166. +# qgroup accounting difference as an error, thus no false alert for btrfs/166. source "$TEST_TOP/common" diff --git a/tests/misc-tests/006-image-on-missing-device/test.sh b/tests/misc-tests/006-image-on-missing-device/test.sh index 2b222340..8c81e6fb 100755 --- a/tests/misc-tests/006-image-on-missing-device/test.sh +++ b/tests/misc-tests/006-image-on-missing-device/test.sh @@ -1,7 +1,7 @@ #!/bin/bash # test btrfs-image with a missing device (uses loop devices) # -# - btrfs-image must not loop indefinetelly +# - btrfs-image must not loop indefinitely # - btrfs-image will expectedly fail to produce the dump source "$TEST_TOP/common" diff --git a/tests/misc-tests/029-send-p-different-mountpoints/test.sh b/tests/misc-tests/029-send-p-different-mountpoints/test.sh index 90465e1d..a59a585e 100755 --- a/tests/misc-tests/029-send-p-different-mountpoints/test.sh +++ b/tests/misc-tests/029-send-p-different-mountpoints/test.sh @@ -10,7 +10,7 @@ check_prereq mkfs.btrfs setup_root_helper prepare_test_dev -# we need two mount points, cannot nest the subvoolume under TEST_MNT +# we need two mount points, cannot nest the subvolume under TEST_MNT SUBVOL_MNT="$TEST_MNT/subvol" TOPLEVEL_MNT="$TEST_MNT/toplevel" TEST_MNT="$TOPLEVEL_MNT" -- cgit v1.2.3 From 584749488a71149ee038c71e1d48dd3d04d009d4 Mon Sep 17 00:00:00 2001 From: Josh Soref Date: Mon, 26 Nov 2018 17:54:19 +0100 Subject: btrfs-progs: tests: fsck/025, fix typo in helpre name Generated by https://github.com/jsoref/spelling Issue: #154 Author: Josh Soref Signed-off-by: David Sterba --- tests/fsck-tests/025-file-extents/test.sh | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) (limited to 'tests') diff --git a/tests/fsck-tests/025-file-extents/test.sh b/tests/fsck-tests/025-file-extents/test.sh index 95707596..db066ee1 100755 --- a/tests/fsck-tests/025-file-extents/test.sh +++ b/tests/fsck-tests/025-file-extents/test.sh @@ -15,7 +15,7 @@ prepare_test_dev 128M # Do some write into a large prealloc range # Lowmem mode can report missing csum due to wrong csum range -test_paritical_write_into_prealloc() +test_partial_write_into_prealloc() { run_check $SUDO_HELPER "$TOP/mkfs.btrfs" -f "$TEST_DEV" run_check_mount_test_dev @@ -55,6 +55,6 @@ test_hole_extent_with_no_holes_flag() run_check "$TOP/btrfs" check "$TEST_DEV" } -test_paritical_write_into_prealloc +test_partial_write_into_prealloc test_compressed_inline_extent test_hole_extent_with_no_holes_flag -- cgit v1.2.3