summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorZhao Lei <zhaolei@cn.fujitsu.com>2015-08-31 13:04:36 +0800
committerDavid Sterba <dsterba@suse.com>2015-09-01 14:02:48 +0200
commitd4d500d341a352c882169a67b1a0c8119ed4257e (patch)
tree47c4fb57894d8f12bc473558752d3ced29bea477
parent665dc49ef6eee19cc5d31270d13531e9b248424a (diff)
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 <zhaolei@cn.fujitsu.com> Signed-off-by: David Sterba <dsterba@suse.com>
-rw-r--r--tests/common7
-rwxr-xr-xtests/convert-tests.sh1
-rwxr-xr-xtests/fsck-tests.sh3
-rwxr-xr-xtests/fsck-tests/012-leaf-corruption/test.sh1
-rwxr-xr-xtests/fsck-tests/013-extent-tree-rebuild/test.sh5
-rwxr-xr-xtests/misc-tests.sh3
-rwxr-xr-xtests/misc-tests/001-btrfstune-features/test.sh5
-rwxr-xr-xtests/misc-tests/002-uuid-rewrite/test.sh5
-rwxr-xr-xtests/misc-tests/003-zero-log/test.sh5
9 files changed, 7 insertions, 28 deletions
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