btrfs-progs: tests: introduce test dev mount helpers
authorZhao Lei <zhaolei@cn.fujitsu.com>
Tue, 1 Sep 2015 12:45:22 +0000 (14:45 +0200)
committerDavid Sterba <dsterba@suse.com>
Tue, 1 Sep 2015 12:53:16 +0000 (14:53 +0200)
mount command in old system can not add "-o loop" option automatically
for a loop device, and make following test 013-extent-tree-rebuild fail.

Considering that $TEST_DEV can be block or loop device, we need to determine
our mount option in a condition for both case.

Introduce a wrapper that will add the loop options if needed.

Signed-off-by: Zhao Lei <zhaolei@cn.fujitsu.com>
Signed-off-by: David Sterba <dsterba@suse.com>
tests/common

index c597915..63b0d9f 100644 (file)
@@ -171,6 +171,32 @@ prepare_test_dev()
        truncate -s "$size" "$TEST_DEV" || _not_run "create file for loop device failed"
 }
 
+run_check_mount_test_dev()
+{
+       setup_root_helper
+
+       local loop_opt
+       if [[ -b "$TEST_DEV" ]]; then
+               loop_opt=""
+       elif [[ -f "$TEST_DEV" ]]; then
+               loop_opt="-o loop"
+       else
+               _fail "Invalid \$TEST_DEV: $TEST_DEV"
+       fi
+
+       [[ -d "$TEST_MNT" ]] || {
+               _fail "Invalid \$TEST_MNT: $TEST_MNT"
+       }
+
+       run_check $SUDO_HELPER mount $loop_opt "$@" "$TEST_DEV" "$TEST_MNT"
+}
+
+run_check_umount_test_dev()
+{
+       setup_root_helper
+       run_check $SUDO_HELPER umount "$@" "$TEST_DEV"
+}
+
 init_env()
 {
        TEST_MNT="${TEST_MNT:-$TOP/tests/mnt}"