From bafc3a33f5527f3cdd4f27be17687703256d0914 Mon Sep 17 00:00:00 2001 From: Zhao Lei Date: Mon, 27 Jul 2015 20:24:31 +0800 Subject: [PATCH] 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 Signed-off-by: David Sterba --- tests/common | 16 ++++++++++++++++ tests/fsck-tests/013-extent-tree-rebuild/test.sh | 11 +---------- tests/misc-tests/001-btrfstune-features/test.sh | 11 +---------- tests/misc-tests/002-uuid-rewrite/test.sh | 11 +---------- tests/misc-tests/003-zero-log/test.sh | 11 +---------- 5 files changed, 20 insertions(+), 40 deletions(-) diff --git a/tests/common b/tests/common index 899ec7b1..2d337b0b 100644 --- a/tests/common +++ b/tests/common @@ -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" +} + diff --git a/tests/fsck-tests/013-extent-tree-rebuild/test.sh b/tests/fsck-tests/013-extent-tree-rebuild/test.sh index 3290cd72..88a66cc2 100755 --- a/tests/fsck-tests/013-extent-tree-rebuild/test.sh +++ b/tests/fsck-tests/013-extent-tree-rebuild/test.sh @@ -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" diff --git a/tests/misc-tests/001-btrfstune-features/test.sh b/tests/misc-tests/001-btrfstune-features/test.sh index c9981e6e..ea33954d 100755 --- a/tests/misc-tests/001-btrfstune-features/test.sh +++ b/tests/misc-tests/001-btrfstune-features/test.sh @@ -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" diff --git a/tests/misc-tests/002-uuid-rewrite/test.sh b/tests/misc-tests/002-uuid-rewrite/test.sh index 6c2a3930..bffa9b85 100755 --- a/tests/misc-tests/002-uuid-rewrite/test.sh +++ b/tests/misc-tests/002-uuid-rewrite/test.sh @@ -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" diff --git a/tests/misc-tests/003-zero-log/test.sh b/tests/misc-tests/003-zero-log/test.sh index da5b3510..edab5dbc 100755 --- a/tests/misc-tests/003-zero-log/test.sh +++ b/tests/misc-tests/003-zero-log/test.sh @@ -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"