diff mbox series

[PATCHv3,3/3] btrfs-progs: tests: misc: Add some replace tests

Message ID 20200416004642.9941-4-marcos@mpdesouza.com (mailing list archive)
State New, archived
Headers show
Series btrfs-progs: Auto resize fs after device replace | expand

Commit Message

Marcos Paulo de Souza April 16, 2020, 12:46 a.m. UTC
From: Marcos Paulo de Souza <mpdesouza@suse.com>

The new test includes a check for the new --autoresize option

Signed-off-by: Marcos Paulo de Souza <mpdesouza@suse.com>
---
 tests/misc-tests/039-replace-device/test.sh | 56 +++++++++++++++++++++
 1 file changed, 56 insertions(+)
 create mode 100755 tests/misc-tests/039-replace-device/test.sh
diff mbox series

Patch

diff --git a/tests/misc-tests/039-replace-device/test.sh b/tests/misc-tests/039-replace-device/test.sh
new file mode 100755
index 00000000..64b80bed
--- /dev/null
+++ b/tests/misc-tests/039-replace-device/test.sh
@@ -0,0 +1,56 @@ 
+#!/bin/bash
+#
+# test the different arguments accepted by "btrfs replace"
+
+source "$TEST_TOP/common"
+
+check_prereq mkfs.btrfs
+check_prereq btrfs
+
+setup_root_helper
+
+setup_loopdevs 2
+prepare_loopdevs
+dev1=${loopdevs[1]}
+dev2=${loopdevs[2]}
+
+# resize only works with disk size bigger than the replaced disk
+run_check_stdout truncate -s3g `pwd`/img3
+dev3=`run_check_stdout $SUDO_HELPER losetup --find --show $(pwd)/img3`
+
+test()
+{
+	local srcdev
+	local final_size
+	local resize_arg
+	srcdev="$1"
+	final_size="$2"
+	resize_arg="$3"
+	args="-B -f"
+
+	if [ -n "$resize_arg" ]; then
+		args="$args --autoresize"
+	fi
+
+	run_check $SUDO_HELPER "$TOP/mkfs.btrfs" -f "$dev1" "$dev2"
+	TEST_DEV="$dev1"
+
+	run_check_mount_test_dev
+	run_check_stdout $SUDO_HELPER "$TOP/btrfs" replace start $args "$srcdev" "$dev3" "$TEST_MNT"
+	run_check_stdout $SUDO_HELPER "$TOP/btrfs" filesystem usage "$TEST_MNT" | head -2 | \
+			grep -q "$final_size\\.00GiB"
+	[ $? -eq 1 ] && _fail "Device size don't match. Expected size: $final_size\\.00GiB"
+	run_check_umount_test_dev
+}
+
+# test replace using devid and path, and also test the final fs size when
+# --autoresize is passed, executing the replace + resize in just one command.
+test 2 4
+test 2 5 true
+test "$dev2" 4
+test "$dev2" 5 true
+
+run_check $SUDO_HELPER losetup -d "$dev3"
+rm `pwd`/img3
+
+cleanup_loopdevs