btrfs-progs: tests: Move code to create loop device to common
authorZhao Lei <zhaolei@cn.fujitsu.com>
Mon, 27 Jul 2015 12:24:31 +0000 (20:24 +0800)
committerDavid Sterba <dsterba@suse.com>
Mon, 31 Aug 2015 17:25:11 +0000 (19:25 +0200)
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>
tests/common
tests/fsck-tests/013-extent-tree-rebuild/test.sh
tests/misc-tests/001-btrfstune-features/test.sh
tests/misc-tests/002-uuid-rewrite/test.sh
tests/misc-tests/003-zero-log/test.sh

index 899ec7b..2d337b0 100644 (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"
+}
+
index 3290cd7..88a66cc 100755 (executable)
@@ -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"
index c9981e6..ea33954 100755 (executable)
@@ -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"
index 6c2a393..bffa9b8 100755 (executable)
@@ -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"
index da5b351..edab5db 100755 (executable)
@@ -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"