osandov / rpms / btrfs-progs

Forked from rpms/btrfs-progs 2 years ago
Clone
dbfe2d
From 6b974c6b3235cb83eb3e8c30a47706529f88d197 Mon Sep 17 00:00:00 2001
dbfe2d
From: Boris Burkov <boris@bur.io>
dbfe2d
Date: Fri, 21 Aug 2020 00:40:10 -0700
dbfe2d
Subject: [PATCH] btrfs-progs: receive: add tests for basic encoded_write
dbfe2d
 send/receive
dbfe2d
dbfe2d
Adapt the existing send/receive tests by passing '-o compress-force' to
dbfe2d
the mount commands in a new test. After writing a few files in the
dbfe2d
various compression formats, send/receive them with and without
dbfe2d
--force-decompress to test both the encoded_write path and the fallback
dbfe2d
to decode+write.
dbfe2d
dbfe2d
Signed-off-by: Boris Burkov <boris@bur.io>
dbfe2d
---
dbfe2d
 .../052-receive-write-encoded/test.sh         | 114 ++++++++++++++++++
dbfe2d
 1 file changed, 114 insertions(+)
dbfe2d
 create mode 100755 tests/misc-tests/052-receive-write-encoded/test.sh
dbfe2d
dbfe2d
diff --git a/tests/misc-tests/052-receive-write-encoded/test.sh b/tests/misc-tests/052-receive-write-encoded/test.sh
dbfe2d
new file mode 100755
dbfe2d
index 00000000..47330281
dbfe2d
--- /dev/null
dbfe2d
+++ b/tests/misc-tests/052-receive-write-encoded/test.sh
dbfe2d
@@ -0,0 +1,114 @@
dbfe2d
+#!/bin/bash
dbfe2d
+#
dbfe2d
+# test that we can send and receive encoded writes for three modes of
dbfe2d
+# transparent compression: zlib, lzo, and zstd.
dbfe2d
+
dbfe2d
+source "$TEST_TOP/common"
dbfe2d
+
dbfe2d
+check_prereq mkfs.btrfs
dbfe2d
+check_prereq btrfs
dbfe2d
+
dbfe2d
+setup_root_helper
dbfe2d
+prepare_test_dev
dbfe2d
+
dbfe2d
+here=`pwd`
dbfe2d
+
dbfe2d
+# assumes the filesystem exists, and does mount, write, snapshot, send, unmount
dbfe2d
+# for the specified encoding option
dbfe2d
+send_one() {
dbfe2d
+	local str
dbfe2d
+	local subv
dbfe2d
+	local snap
dbfe2d
+
dbfe2d
+	algorithm="$1"
dbfe2d
+	shift
dbfe2d
+	str="$1"
dbfe2d
+	shift
dbfe2d
+
dbfe2d
+	subv="subv-$algorithm"
dbfe2d
+	snap="snap-$algorithm"
dbfe2d
+
dbfe2d
+	run_check_mount_test_dev "-o" "compress-force=$algorithm"
dbfe2d
+	cd "$TEST_MNT" || _fail "cannot chdir to TEST_MNT"
dbfe2d
+
dbfe2d
+	run_check $SUDO_HELPER "$TOP/btrfs" subvolume create "$subv"
dbfe2d
+	run_check $SUDO_HELPER dd if=/dev/zero of="$subv/file1" bs=1M count=1
dbfe2d
+	run_check $SUDO_HELPER dd if=/dev/zero of="$subv/file2" bs=500K count=1
dbfe2d
+	run_check $SUDO_HELPER "$TOP/btrfs" subvolume snapshot -r "$subv" "$snap"
dbfe2d
+	run_check $SUDO_HELPER "$TOP/btrfs" send -f "$str" "$snap" "$@"
dbfe2d
+
dbfe2d
+	cd "$here" || _fail "cannot chdir back to test directory"
dbfe2d
+	run_check_umount_test_dev
dbfe2d
+}
dbfe2d
+
dbfe2d
+receive_one() {
dbfe2d
+	local str
dbfe2d
+	str="$1"
dbfe2d
+	shift
dbfe2d
+
dbfe2d
+	run_check_mkfs_test_dev
dbfe2d
+	run_check_mount_test_dev
dbfe2d
+	run_check $SUDO_HELPER "$TOP/btrfs" receive "$@" -v -f "$str" "$TEST_MNT"
dbfe2d
+	run_check_umount_test_dev
dbfe2d
+	run_check rm -f -- "$str"
dbfe2d
+}
dbfe2d
+
dbfe2d
+test_one_write_encoded() {
dbfe2d
+	local str
dbfe2d
+	local algorithm
dbfe2d
+	algorithm="$1"
dbfe2d
+	shift
dbfe2d
+	str="$here/stream-$algorithm.stream"
dbfe2d
+
dbfe2d
+	run_check_mkfs_test_dev
dbfe2d
+	send_one "$algorithm" "$str" --compressed-data
dbfe2d
+	receive_one "$str" "$@"
dbfe2d
+}
dbfe2d
+
dbfe2d
+test_one_stream_v1() {
dbfe2d
+	local str
dbfe2d
+	local algorithm
dbfe2d
+	algorithm="$1"
dbfe2d
+	shift
dbfe2d
+	str="$here/stream-$algorithm.stream"
dbfe2d
+
dbfe2d
+	run_check_mkfs_test_dev
dbfe2d
+	send_one "$algorithm" "$str" --proto 1
dbfe2d
+	receive_one "$str" "$@"
dbfe2d
+}
dbfe2d
+
dbfe2d
+test_mix_write_encoded() {
dbfe2d
+	local strzlib
dbfe2d
+	local strlzo
dbfe2d
+	local strzstd
dbfe2d
+	strzlib="$here/stream-zlib.stream"
dbfe2d
+	strlzo="$here/stream-lzo.stream"
dbfe2d
+	strzstd="$here/stream-zstd.stream"
dbfe2d
+
dbfe2d
+	run_check_mkfs_test_dev
dbfe2d
+
dbfe2d
+	send_one "zlib" "$strzlib" --compressed-data
dbfe2d
+	send_one "lzo" "$strlzo" --compressed-data
dbfe2d
+	send_one "zstd" "$strzstd" --compressed-data
dbfe2d
+
dbfe2d
+	receive_one "$strzlib"
dbfe2d
+	receive_one "$strlzo"
dbfe2d
+	receive_one "$strzstd"
dbfe2d
+}
dbfe2d
+
dbfe2d
+test_one_write_encoded "zlib"
dbfe2d
+test_one_write_encoded "lzo"
dbfe2d
+test_one_write_encoded "zstd"
dbfe2d
+
dbfe2d
+# with decompression forced
dbfe2d
+test_one_write_encoded "zlib" "--force-decompress"
dbfe2d
+test_one_write_encoded "lzo" "--force-decompress"
dbfe2d
+test_one_write_encoded "zstd" "--force-decompress"
dbfe2d
+
dbfe2d
+# send stream v1
dbfe2d
+test_one_stream_v1 "zlib"
dbfe2d
+test_one_stream_v1 "lzo"
dbfe2d
+test_one_stream_v1 "zstd"
dbfe2d
+
dbfe2d
+# files use a mix of compression algorithms
dbfe2d
+test_mix_write_encoded
dbfe2d
-- 
dbfe2d
2.35.1
dbfe2d