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>
This commit is contained in:
Zhao Lei 2015-08-31 13:04:36 +08:00 committed by David Sterba
parent 665dc49ef6
commit d4d500d341
9 changed files with 7 additions and 28 deletions

View File

@ -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

View File

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

View File

@ -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

View File

@ -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

View File

@ -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()
{

View File

@ -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

View File

@ -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

View File

@ -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

View File

@ -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