btrfs-progs: tests: Move code to create loop device to common

This code block is used several tests, move it to ./common and add a
helper.

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-07-27 20:24:31 +08:00 committed by David Sterba
parent cb3424cd23
commit bafc3a33f5
5 changed files with 20 additions and 40 deletions

View File

@ -142,3 +142,19 @@ setup_root_helper()
fi
SUDO_HELPER=root_helper
}
prepare_test_dev()
{
# num[K/M/G/T...]
local size="$1"
[[ "$TEST_DEV" ]] && return
[[ "$size" ]] || size='1G'
echo "\$TEST_DEV not given, use $TOP/test/test.img as fallback" >> \
$RESULTS
TEST_DEV="$TOP/tests/test.img"
truncate -s "$size" "$TEST_DEV" || _not_run "create file for loop device failed"
}

View File

@ -5,16 +5,7 @@ source $TOP/tests/common
check_prereq btrfs-debug-tree
check_prereq mkfs.btrfs
setup_root_helper
if [ -z $TEST_DEV ]; then
echo "\$TEST_DEV not given, use $TOP/test/test.img as fallback" >> \
$RESULTS
TEST_DEV="$TOP/tests/test.img"
# Need at least 1G to avoid mixed block group, which extent tree
# rebuild doesn't support.
run_check truncate -s 1G $TEST_DEV
fi
prepare_test_dev 1G
if [ -z $TEST_MNT ];then
echo " [NOTRUN] extent tree rebuild, need TEST_MNT variant"

View File

@ -7,16 +7,7 @@ check_prereq btrfs-debug-tree
check_prereq btrfs-show-super
check_prereq mkfs.btrfs
setup_root_helper
if [ -z $TEST_DEV ]; then
echo "\$TEST_DEV not given, use $TOP/test/test.img as fallback" >> \
$RESULTS
TEST_DEV="$TOP/tests/test.img"
# Need at least 1G to avoid mixed block group, which extent tree
# rebuild doesn't support.
run_check truncate -s 1G $TEST_DEV
fi
prepare_test_dev
if [ -z $TEST_MNT ];then
echo " [NOTRUN] extent tree rebuild, need TEST_MNT variant"

View File

@ -7,16 +7,7 @@ check_prereq btrfs-debug-tree
check_prereq btrfs-show-super
check_prereq mkfs.btrfs
check_prereq btrfstune
if [ -z $TEST_DEV ]; then
echo "\$TEST_DEV not given, use $TOP/test/test.img as fallback" >> \
$RESULTS
TEST_DEV="$TOP/tests/test.img"
# Need at least 1G to avoid mixed block group, which extent tree
# rebuild doesn't support.
run_check truncate -s 1G $TEST_DEV
fi
prepare_test_dev
if [ -z $TEST_MNT ];then
echo " [NOTRUN] extent tree rebuild, need TEST_MNT variant"

View File

@ -6,16 +6,7 @@ source $TOP/tests/common
check_prereq btrfs-show-super
check_prereq mkfs.btrfs
check_prereq btrfs
if [ -z $TEST_DEV ]; then
echo "\$TEST_DEV not given, use $TOP/test/test.img as fallback" >> \
$RESULTS
TEST_DEV="$TOP/tests/test.img"
# Need at least 1G to avoid mixed block group, which extent tree
# rebuild doesn't support.
run_check truncate -s 1G $TEST_DEV
fi
prepare_test_dev
if [ -z $TEST_MNT ];then
echo " [NOTRUN] extent tree rebuild, need TEST_MNT variant"