From bafc3a33f5527f3cdd4f27be17687703256d0914 Mon Sep 17 00:00:00 2001 From: Zhao Lei Date: Mon, 27 Jul 2015 20:24:31 +0800 Subject: 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 ++++++++++++++++ 1 file changed, 16 insertions(+) (limited to 'tests/common') 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" +} + -- cgit v1.2.3