Skip to contentSkip to conversation

btrfs-progs: fix issues in tests

PATCH In review Anand Jain 2 participants 8 messages Apr 3, 2020 – Apr 9, 2020 Btrfs file system

lore
Share & tools
lore

Anand Jain

author
#0 lore raw

v3 cover btrfs-progs: fix issues in tests

Fixes issues found in tests.

path 3/4 canonicalized the TEST_DEV path and affected few test group. Unit tests passed however a complete tests runs is not done.

Anand Jain (4):
btrfs-progs: fix fsck-test/037 skip corrupt FREE_SPACE_BITMAP
btrfs-progs: fix TEST_TOP path drop extra forward slash
btrfs-progs: test clean start after failures
btrfs-progs: fix misc-test/029 provide device for mount

 tests/clean-tests.sh                                      |  2 +-
 tests/cli-tests.sh                                        |  2 +-
 tests/common                                              |  6 ++++++
 tests/convert-tests.sh                                    |  2 +-
 tests/fsck-tests.sh                                       |  2 +-
 tests/fsck-tests/037-freespacetree-repair/test.sh         | 14 ++++++++++----
 tests/fuzz-tests.sh                                       |  2 +-
 tests/misc-tests.sh                                       |  3 ++-
 tests/misc-tests/029-send-p-different-mountpoints/test.sh |  3 ++-
 tests/mkfs-tests.sh                                       |  2 +-
 10 files changed, 26 insertions(+), 12 deletions(-)
Signature · 1 line
1.8.3.1
author
#1 lore raw

PATCH v3 1/4 btrfs-progs: fix fsck-test/037 skip corrupt FREE_SPACE_BITMAP

We don't have the FREE_SPACE_BITMAP in the default filesystem, skip the sub test by checking if the objectid is null for the FREE_SPACE_BITMAP. The null objectid check for the FREE_SPACE_EXTENT is not actually required, it is added to maintain similar flow in the code above it.

---
 tests/fsck-tests/037-freespacetree-repair/test.sh | 14 ++++++++++----
 1 file changed, 10 insertions(+), 4 deletions(-)
tests/fsck-tests/037-freespacetree-repair/test.sh +10 -4
index 49165fcd7390..607a4e9dff9a 100755
@@ -29,6 +29,9 @@ corrupt_fst_item()
 		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)
+		if [[ $objectid == "" ]]; then
+			return 1
+		fi
 		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)
@@ -38,6 +41,9 @@ corrupt_fst_item()
 		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)
+		if [[ $objectid == "" ]]; then
+			return 1
+		fi
 		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)
@@ -48,6 +54,8 @@ corrupt_fst_item()
 
 	run_check "$INTERNAL_BIN/btrfs-corrupt-block" -r 10 -K "$objectid,$type,$offset" \
 		-f offset "$TEST_DEV"
+
+	return 0
 }
 
 if ! [ -f "/sys/fs/btrfs/features/free_space_tree" ]; then
@@ -69,8 +77,7 @@ done
 run_check_umount_test_dev
 
 # now corrupt one of the bitmap items
-corrupt_fst_item "bitmap"
-check_image "$TEST_DEV"
+corrupt_fst_item "bitmap" && check_image "$TEST_DEV"
 
 # change the freespace such that we now have at least one free_space_extent
 # object
@@ -80,5 +87,4 @@ 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"
+corrupt_fst_item "extent" && check_image "$TEST_DEV"
Signature · 1 line
1.8.3.1
author
#2 lore raw

PATCH v3 2/4 btrfs-progs: fix TEST_TOP path drop extra forward slash

In reply to Anand Jain

From
TEST_TOP="$TOP/tests/"
to
TEST_TOP="$TOP/tests"

Affected test cases are:
tests/clean-tests.sh
tests/cli-tests.sh
tests/convert-tests.sh
tests/fsck-tests.sh
tests/fuzz-tests.sh
tests/misc-tests.sh
tests/mkfs-tests.sh

---
 tests/clean-tests.sh   | 2 +-
 tests/cli-tests.sh     | 2 +-
 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, 7 insertions(+), 7 deletions(-)
tests/clean-tests.sh +1 -1
index eda16e329698..d8157ab54ee3 100755
@@ -7,7 +7,7 @@ if [ -z "$TOP" ]; then
 	TOP=$(readlink -f "$SCRIPT_DIR/../")
 	if [ -f "$TOP/configure.ac" ]; then
 		# inside git
-		TEST_TOP="$TOP/tests/"
+		TEST_TOP="$TOP/tests"
 		INTERNAL_BIN="$TOP"
 	else
 		# external, defaults to system binaries
tests/cli-tests.sh +1 -1
index d302a93ea594..d8cd06724701 100755
@@ -8,7 +8,7 @@ if [ -z "$TOP" ]; then
 	TOP=$(readlink -f "$SCRIPT_DIR/../")
 	if [ -f "$TOP/configure.ac" ]; then
 		# inside git
-		TEST_TOP="$TOP/tests/"
+		TEST_TOP="$TOP/tests"
 		INTERNAL_BIN="$TOP"
 	else
 		# external, defaults to system binaries
tests/convert-tests.sh +1 -1
index f6c940437eec..24b3ec0df144 100755
@@ -9,7 +9,7 @@ if [ -z "$TOP" ]; then
 	TOP=$(readlink -f "$SCRIPT_DIR/../")
 	if [ -f "$TOP/configure.ac" ]; then
 		# inside git
-		TEST_TOP="$TOP/tests/"
+		TEST_TOP="$TOP/tests"
 		INTERNAL_BIN="$TOP"
 	else
 		# external, defaults to system binaries
tests/fsck-tests.sh +1 -1
index 8fbc2b4bc40e..15e3d8d5995c 100755
@@ -8,7 +8,7 @@ if [ -z "$TOP" ]; then
 	TOP=$(readlink -f "$SCRIPT_DIR/../")
 	if [ -f "$TOP/configure.ac" ]; then
 		# inside git
-		TEST_TOP="$TOP/tests/"
+		TEST_TOP="$TOP/tests"
 		INTERNAL_BIN="$TOP"
 	else
 		# external, defaults to system binaries
tests/fuzz-tests.sh +1 -1
index ae738710b8bc..0ba8f1e11f70 100755
@@ -8,7 +8,7 @@ if [ -z "$TOP" ]; then
 	TOP=$(readlink -f "$SCRIPT_DIR/../")
 	if [ -f "$TOP/configure.ac" ]; then
 		# inside git
-		TEST_TOP="$TOP/tests/"
+		TEST_TOP="$TOP/tests"
 		INTERNAL_BIN="$TOP"
 	else
 		# external, defaults to system binaries
tests/misc-tests.sh +1 -1
index 3e7b9e9befe6..3b49ab012e78 100755
@@ -8,7 +8,7 @@ if [ -z "$TOP" ]; then
 	TOP=$(readlink -f "$SCRIPT_DIR/../")
 	if [ -f "$TOP/configure.ac" ]; then
 		# inside git
-		TEST_TOP="$TOP/tests/"
+		TEST_TOP="$TOP/tests"
 		INTERNAL_BIN="$TOP"
 	else
 		# external, defaults to system binaries
tests/mkfs-tests.sh +1 -1
index e76a805b4f0b..150f094f2303 100755
@@ -8,7 +8,7 @@ if [ -z "$TOP" ]; then
 	TOP=$(readlink -f "$SCRIPT_DIR/../")
 	if [ -f "$TOP/configure.ac" ]; then
 		# inside git
-		TEST_TOP="$TOP/tests/"
+		TEST_TOP="$TOP/tests"
 		INTERNAL_BIN="$TOP"
 	else
 		# external, defaults to system binaries
Signature · 1 line
1.8.3.1
#3 lore raw

Re: [PATCH 2/4] btrfs-progs: fix TEST_TOP path drop extra forward slash

Quoted 4 lines · Anand Jain

From
TEST_TOP="$TOP/tests/"
to
TEST_TOP="$TOP/tests"

So this basically repeats the diff

Quoted 8 lines

Affected test cases are:
tests/clean-tests.sh
tests/cli-tests.sh
tests/convert-tests.sh
tests/fsck-tests.sh
tests/fuzz-tests.sh
tests/misc-tests.sh
tests/mkfs-tests.sh

And this repeats the diffstat.

The changelog should explain why the change is made, summarize some key points, etc.

I'll apply this patch and write a changelog but please try to improve that. What works is to postpone sending the patches and read them after a day or two, if it still makes sense then send it. Second look reveals all the typos and missing information.

author
#4 lore raw

PATCH v3 3/4 btrfs-progs: test clean start after failures

In reply to Anand Jain

After a failure it fails for a different reason

=== START TEST /btrfs-progs/tests/misc-tests/029-send-p-different-mountpoints $TEST_DEV not given, using /btrfs-progs/tests/test.img as fallback ====== RUN MAYFAIL mkdir -p /btrfs-progs/tests/misc-tests/029-send-p-different-mountpoints/subvol_mnt ====== RUN CHECK /btrfs-progs/mkfs.btrfs -f /btrfs-progs/tests/test.img
ERROR: /btrfs-progs/tests/test.img is mounted <====

Add clean_start() helper to unmount.

---
 tests/common        | 6 ++++++
 tests/misc-tests.sh | 1 +
 2 files changed, 7 insertions(+)
tests/common +6 -0
index 71661e950db0..bf55500e94ec 100644
@@ -788,6 +788,12 @@ cleanup_loopdevs()
 	run_check $SUDO_HELPER losetup --all
 }
 
+# add all the cleanups here
+clean_start()
+{
+	grep -q $TEST_MNT /proc/self/mounts && umount $TEST_MNT
+}
+
 init_env()
 {
 	TEST_MNT="${TEST_MNT:-$TEST_TOP/mnt}"
tests/misc-tests.sh +1 -0
index 3b49ab012e78..3dc96f258540 100755
@@ -40,6 +40,7 @@ export IMAGE
 export TEST_DEV
 
 rm -f "$RESULTS"
+clean_start
 
 # test rely on corrupting blocks tool
 check_prereq btrfs-corrupt-block
Signature · 1 line
1.8.3.1
#5 lore raw

Re: [PATCH 3/4] btrfs-progs: test clean start after failures

Quoted 11 lines · Anand Jain

After a failure it fails for a different reason

=== START TEST /btrfs-progs/tests/misc-tests/029-send-p-different-mountpoints $TEST_DEV not given, using /btrfs-progs/tests/test.img as fallback ====== RUN MAYFAIL mkdir -p /btrfs-progs/tests/misc-tests/029-send-p-different-mountpoints/subvol_mnt ====== RUN CHECK /btrfs-progs/mkfs.btrfs -f /btrfs-progs/tests/test.img
ERROR: /btrfs-progs/tests/test.img is mounted <====

Add clean_start() helper to unmount.

The testsuite is designed to stop on first failure and it's up the user to investigate and clean it up before starting it again. For that there's the test-clean make target. In some cases it might not clean up the environment completely, but that's typically if the test image is not unmoutnable due to some process having the directory open.

Quoted 14 lines
tests/common +6 -0
+# add all the cleanups here
+clean_start()
+{
+	grep -q $TEST_MNT /proc/self/mounts && umount $TEST_MNT
+}
+
 init_env()
 {
 	TEST_MNT="${TEST_MNT:-$TEST_TOP/mnt}"
tests/misc-tests.sh +0 -0
index 3b49ab012e78..3dc96f258540 100755

tests/misc-tests.sh export IMAGE · line 43

Quoted 4 lines
tests/misc-tests.sh +1 -0
@@ -40,6 +40,7 @@ export IMAGE
 export TEST_DEV
 
 rm -f "$RESULTS"
+clean_start

Instead of this I'd rather make it a hard stop if there's some problem with the environment, like the mountpoint still mounted, or more loop devices from the specific tests still set up as loop devices etc.

When I get to this situation I fix it manually (checkint mount output, losetup -D), but it'd be nice to have that automated.

author
#6 lore raw

PATCH v3 4/4 btrfs-progs: fix misc-test/029 provide device for mount

In reply to Anand Jain

The mount fails with 'file exists' error. Fix it by providing the device name.

$ make TEST=029\* test-misc
    [TEST]   misc-tests.sh
    [TEST/misc]   029-send-p-different-mountpoints
failed: mount -t btrfs -o subvol=subv1 /btrfs-progs/tests//test.img /btrfs-progs/tests/misc-tests/029-send-p-different-mountpoints/subvol_mnt
test failed for case 029-send-p-different-mountpoints
make: *** [test-misc] Error 1

====== RUN CHECK mount -t btrfs -o subvol=subv1 /btrfs-progs/tests//test.img /btrfs-progs/tests/misc-tests/029-send-p-different-mountpoints/subvol_mnt
mount: mount /dev/loop1 on /btrfs-progs/tests/misc-tests/029-send-p-different-mountpoints/subvol_mnt
failed: File exists
failed: mount -t btrfs -o subvol=subv1 /btrfs-progs/tests//test.img /btrfs-progs/tests/misc-tests/029-send-p-different-mountpoints/subvol_mnt test failed for case 029-send-p-different-mountpoints

---
v2: use readlink to sanitize the TEST_DEV path
v3: readlink for TEST_DEV is not needed drop it

 tests/misc-tests/029-send-p-different-mountpoints/test.sh | 3 ++-
 1 file changed, 2 insertions(+), 1 deletion(-)
tests/misc-tests/029-send-p-different-mountpoints/test.sh +2 -1
index a478b3d26495..b05e4172ca0f 100755
@@ -20,7 +20,8 @@ run_check_mkfs_test_dev
 run_check_mount_test_dev
 
 run_check $SUDO_HELPER "$TOP/btrfs" subvolume create "$TEST_MNT/subv1"
-run_check $SUDO_HELPER mount -t btrfs -o subvol=subv1 "$TEST_DEV" "$SUBVOL_MNT"
+lodev=$(losetup  | grep ${TEST_DEV} | awk '{print $1}')
+run_check $SUDO_HELPER mount -t btrfs -o subvol=subv1 "$lodev" "$SUBVOL_MNT"
 
 run_check $SUDO_HELPER "$TOP/btrfs" subvolume create "$TEST_MNT/test-subvol"
 run_check $SUDO_HELPER "$TOP/btrfs" subvolume snapshot -r \
Signature · 1 line
1.8.3.1
#7 lore raw

Re: [PATCH v3 4/4] btrfs-progs: fix misc-test/029 provide device for mount

Quoted 33 lines · Anand Jain

The mount fails with 'file exists' error. Fix it by providing the device name.

$ make TEST=029\* test-misc
    [TEST]   misc-tests.sh
    [TEST/misc]   029-send-p-different-mountpoints
failed: mount -t btrfs -o subvol=subv1 /btrfs-progs/tests//test.img /btrfs-progs/tests/misc-tests/029-send-p-different-mountpoints/subvol_mnt
test failed for case 029-send-p-different-mountpoints
make: *** [test-misc] Error 1

====== RUN CHECK mount -t btrfs -o subvol=subv1 /btrfs-progs/tests//test.img /btrfs-progs/tests/misc-tests/029-send-p-different-mountpoints/subvol_mnt
mount: mount /dev/loop1 on /btrfs-progs/tests/misc-tests/029-send-p-different-mountpoints/subvol_mnt
failed: File exists
failed: mount -t btrfs -o subvol=subv1 /btrfs-progs/tests//test.img /btrfs-progs/tests/misc-tests/029-send-p-different-mountpoints/subvol_mnt test failed for case 029-send-p-different-mountpoints

---
v2: use readlink to sanitize the TEST_DEV path
v3: readlink for TEST_DEV is not needed drop it

 tests/misc-tests/029-send-p-different-mountpoints/test.sh | 3 ++-
 1 file changed, 2 insertions(+), 1 deletion(-)
tests/misc-tests/029-send-p-different-mountpoints/test.sh +0 -0
index a478b3d26495..b05e4172ca0f 100755

tests/misc-tests/029-send-p-different-mountpoints/test.sh run_check_mkfs_test_dev · line 24

Quoted 6 lines
tests/misc-tests/029-send-p-different-mountpoints/test.sh +2 -1
@@ -20,7 +20,8 @@ run_check_mkfs_test_dev
 run_check_mount_test_dev
 
 run_check $SUDO_HELPER "$TOP/btrfs" subvolume create "$TEST_MNT/subv1"
-run_check $SUDO_HELPER mount -t btrfs -o subvol=subv1 "$TEST_DEV" "$SUBVOL_MNT"
+lodev=$(losetup  | grep ${TEST_DEV} | awk '{print $1}')
+run_check $SUDO_HELPER mount -t btrfs -o subvol=subv1 "$lodev" "$SUBVOL_MNT"

The test dev is not necessarily a loop device, yes by default it is, but TEST_DEV can be set externally.

I still wonder why the test fails for you because it does not for me and without more information it's not clear what is mount reporting as 'File exists', which is EEXIST.