diff mbox

[1/2] btrfs-progs-tests: Introduce init_env() to initialize common env variant

Message ID faa118527b0436377f6a452948350b0700b73584.1438005660.git.zhaolei@cn.fujitsu.com (mailing list archive)
State New, archived
Headers show

Commit Message

Zhaolei July 27, 2015, 2:01 p.m. UTC
From: Zhao Lei <zhaolei@cn.fujitsu.com>

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 <zhaolei@cn.fujitsu.com>
---
 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(-)
diff mbox

Patch

diff --git a/tests/common b/tests/common
index 2d337b0..ba0b78a 100644
--- a/tests/common
+++ b/tests/common
@@ -158,3 +158,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 efed90b..4e8496a 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 b0ded6a..46dd72d 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 f8701ad..a37ceda 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 88a66cc..b7909d2 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 5bbe914..cabe9c3 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,11 +17,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/misc-tests/001-btrfstune-features/test.sh b/tests/misc-tests/001-btrfstune-features/test.sh
index ea33954..836e8d3 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 bffa9b8..9b103aa 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 edab5db..b650930 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