Skip to contentSkip to conversation

btrfs-progs: tests: umount TEST_MNT in clean-tests.sh

PATCH Applied Zhao Lei 2 participants 9 messages Aug 31, 2015 – Sep 1, 2015 Btrfs file system

lore
Share & tools
lore

Zhao Lei

author
#0 lore raw

v2 cover 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
  #

To solve this problem, I put umount command into test sctipt in v1, but it will change stat of failed-test in next test, and make it hard to debug, noticed by David Sterba <[email protected]>:
My expectation is that the testsuite will not fail and if it does, I wan't to keep the last stat so I can have a look. Would it be acceptable for you to enhance the clean-tests.sh script to unmount the TEST_DEV?

Putting umount command into clean-tests.sh need a global $TEST_MNT, which already done in my previous patch.

This patchset rebase my previous patch of "setting global $TEST_MNT" to git head in [PATCH 1..2/4], and add v2 of "umount TEST_MNT" in [PATCH 3/4].

Thanks
Zhaolei

Zhao Lei (4):
btrfs-progs: tests: Introduce init_env() to initialize common env
variant
btrfs-progs: tests: Fix mount fail of 013-extent-tree-rebuild
btrfs-progs: tests: umount TEST_MNT in clean-tests.sh
btrfs-progs: Use mount_test_dev for misc-tests/007-subvolume-sync

 tests/clean-tests.sh                             |  7 ++++--
 tests/common                                     | 30 ++++++++++++++++++++++++
 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 |  9 ++-----
 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 ----
 tests/misc-tests/007-subvolume-sync/test.sh      |  4 ++--
 11 files changed, 39 insertions(+), 34 deletions(-)
Signature · 1 line
1.8.5.1
author
#1 lore raw

PATCH v2 1/4 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.

---
 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(-)
tests/common +7 -0
index cf463e8..c597915 100644
@@ -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
tests/convert-tests.sh +0 -1
index b395e25..68c03dc 100755
@@ -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"
 
tests/fsck-tests.sh +0 -3
index 73538fe..b910e85 100755
@@ -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
tests/fsck-tests/012-leaf-corruption/test.sh +0 -1
index f8701ad..a37ceda 100755
@@ -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
tests/fsck-tests/013-extent-tree-rebuild/test.sh +0 -5
index 88a66cc..b7909d2 100755
@@ -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()
 {
tests/misc-tests.sh +0 -3
index f9c1152..d04416b 100755
@@ -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"
 
@@ -20,13 +19,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
tests/misc-tests/001-btrfstune-features/test.sh +0 -5
index ea33954..836e8d3 100755
@@ -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
tests/misc-tests/002-uuid-rewrite/test.sh +0 -5
index bffa9b8..9b103aa 100755
@@ -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
 
tests/misc-tests/003-zero-log/test.sh +0 -5
index edab5db..b650930 100755
@@ -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
Signature · 1 line
1.8.5.1
Applied
#2 lore raw

Re: [PATCH v2 1/4] btrfs-progs: tests: Introduce init_env to initialize common env variant

Quoted 14 lines · Zhao Lei

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"
...

Quoted 5 lines

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.

Applied, thanks.

author
#3 lore raw

PATCH v2 2/4 btrfs-progs: tests: Fix mount fail of 013-extent-tree-rebuild

In reply to Zhao Lei

When using loop device for test, fsck-tests/013-extent-tree-rebuild failed with following error message:

  # ./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 make above request to a common function, to solve current problem in 013-extent-tree-rebuild, and support similar request in future.

---
 tests/common                                     | 23 +++++++++++++++++++++++
 tests/fsck-tests/013-extent-tree-rebuild/test.sh |  4 ++--
 2 files changed, 25 insertions(+), 2 deletions(-)
tests/common +23 -0
index c597915..eae6b2b 100644
@@ -178,3 +178,26 @@ init_env()
 	mkdir -p "$TEST_MNT" || { echo "Failed mkdir -p $TEST_MNT"; exit 1; }
 }
 init_env
+
+mount_test_dev()
+{
+	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"
+	}
+
+	mount "${loop_opt[@]}" "$TEST_DEV" "$TEST_MNT" || _fail "mount $TEST_DEV to $TEST_MNT failed"
+}
+
+umount_test_dev()
+{
+	umount "$TEST_DEV"
+}
tests/fsck-tests/013-extent-tree-rebuild/test.sh +2 -2
index b7909d2..ff3c922 100755
@@ -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 $SUDO_HELPER 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 $SUDO_HELPER umount_test_dev
 
 	# get extent root bytenr
 	extent_root_bytenr=`$SUDO_HELPER $TOP/btrfs-debug-tree -r $TEST_DEV | \
Signature · 1 line
1.8.5.1
#4 lore raw

Re: [PATCH v2 2/4] btrfs-progs: tests: Fix mount fail of 013-extent-tree-rebuild

Quoted 6 lines · Zhao Lei
tests/common +6 -0
+mount_test_dev()
+{
+	local loop_opt
+	if [[ -b "$TEST_DEV" ]]; then
+		loop_opt=()
+	elif [[ -f "$TEST_DEV" ]]; then

tests/common init_env() · line 197

Quoted 10 lines
tests/common +10 -0
+		loop_opt=(-o loop)
+	else
+		_fail "Invalid \$TEST_DEV: $TEST_DEV"
+	fi
+
+	[[ -d "$TEST_MNT" ]] || {
+		_fail "Invalid \$TEST_MNT: $TEST_MNT"
+	}
+
+	mount "${loop_opt[@]}" "$TEST_DEV" "$TEST_MNT" || _fail "mount $TEST_DEV to $TEST_MNT failed"

This needs the root helper, besides I don't see a reason why to use the array to pass the loop options.

On newer systems the option 'loop' is not necessary and mount works with that but I don't mind adding support for systems where this does not work. However, this should not break current behaviour.

One thing that I find important is that the full commands are logged via the run_check helpers. So I suggest to add run_check_mount_test_dev helper that would wrapp all the commands. The combination of shell functions does not work in all cases.

author
#5 lore raw

RE: [PATCH v2 2/4] btrfs-progs: tests: Fix mount fail of 013-extent-tree-rebuild

Hi, David Sterba

Thanks for review.

Quoted 27 lines

-----Original Message-----
From: David Sterba [mailto:[email protected]]
Sent: Monday, August 31, 2015 10:48 PM
To: Zhao Lei <[email protected]>
Cc: [email protected]
Subject: Re: [PATCH v2 2/4] btrfs-progs: tests: Fix mount fail of 013-extent-tree-rebuild

Quoted 6 lines · Zhao Lei
tests/common +6 -0
+mount_test_dev()
+{
+	local loop_opt
+	if [[ -b "$TEST_DEV" ]]; then
+		loop_opt=()
+	elif [[ -f "$TEST_DEV" ]]; then

tests/common init_env()

Quoted 10 lines
tests/common +10 -0
+		loop_opt=(-o loop)
+	else
+		_fail "Invalid \$TEST_DEV: $TEST_DEV"
+	fi
+
+	[[ -d "$TEST_MNT" ]] || {
+		_fail "Invalid \$TEST_MNT: $TEST_MNT"
+	}
+
+	mount "${loop_opt[@]}" "$TEST_DEV" "$TEST_MNT" || _fail "mount

$TEST_DEV to $TEST_MNT failed"

Quoted 5 lines

This needs the root helper,

besides I don't see a reason why to use the array to pass the loop options.

Only personal habit, will not use it in v2.

Quoted 2 lines

On newer systems the option 'loop' is not necessary and mount works with that

Glad to hear it.

Quoted 8 lines

but I don't mind adding support for systems where this does not work. However, this should not break current behaviour.

One thing that I find important is that the full commands are logged via the run_check helpers. So I suggest to add run_check_mount_test_dev helper that would wrapp all the commands. The combination of shell functions does not work in all cases.

Ok.

Thanks
Zhaolei

author
#6 lore raw

PATCH v2 3/4 btrfs-progs: tests: umount TEST_MNT in clean-tests.sh

In reply to Zhao Lei

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
  #

Changelog v1->v2:
Put umount command to clean-tests.sh instead of in testscript, to keep failed-test stat until user run clean-tests.sh explicitly, Suggested-by: David Sterba <[email protected]>

---
 tests/clean-tests.sh | 7 +++++--
 1 file changed, 5 insertions(+), 2 deletions(-)
tests/clean-tests.sh +5 -2
index c1dc56a..19d682d 100755
@@ -1,12 +1,15 @@
 #!/bin/sh
 # remove all intermediate files from tests
 
+SCRIPT_DIR=$(dirname $(readlink -f $0))
+TOP=$(readlink -f $SCRIPT_DIR/../)
+source $TOP/tests/common
+
 if [ "$BUILD_VERBOSE" = 1 ]; then
 	verbose=-print
 fi
 
-SCRIPT_DIR=$(dirname $(readlink -f $0))
-TOP=$(readlink -f $SCRIPT_DIR/../)
+umount "$TEST_MNT" &>/dev/null
 
 if ! cd $TOP/tests; then
 	echo "ERROR: cannot cd to $TOP/tests"
Signature · 1 line
1.8.5.1
Applied
#7 lore raw
Quoted 28 lines · Zhao Lei

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
  #
Quoted 7 lines

Changelog v1->v2:
Put umount command to clean-tests.sh instead of in testscript, to keep failed-test stat until user run clean-tests.sh explicitly, Suggested-by: David Sterba <[email protected]>

Applied, thanks.

author
#8 lore raw

PATCH v2 4/4 btrfs-progs: tests: Use mount_test_dev for misc-tests/007-subvolume-sync

In reply to Zhao Lei

So this test can support both block device and loop device simply.

---
 tests/misc-tests/007-subvolume-sync/test.sh | 4 ++--
 1 file changed, 2 insertions(+), 2 deletions(-)
tests/misc-tests/007-subvolume-sync/test.sh +2 -2
index d4019f4..1eea098 100755
@@ -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 $SUDO_HELPER 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 $SUDO_HELPER umount_test_dev
Signature · 1 line
1.8.5.1