File: test.sh

package info (click to toggle)
btrfs-progs 6.2-1%2Bdeb12u1
  • links: PTS, VCS
  • area: main
  • in suites: bookworm
  • size: 17,244 kB
  • sloc: ansic: 114,376; sh: 9,576; python: 1,242; makefile: 820
file content (126 lines) | stat: -rwxr-xr-x 2,773 bytes parent folder | download
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
#!/bin/bash
#
# test that we can send and receive encoded writes for three modes of
# transparent compression: zlib, lzo, and zstd.

source "$TEST_TOP/common"

check_prereq mkfs.btrfs
check_prereq btrfs

setup_root_helper
prepare_test_dev

if ! [ -f "/sys/fs/btrfs/features/send_stream_version" ] ||
   grep -s '1$' "/sys/fs/btrfs/features/send_stream_version"; then
	_not_run "kernel does not support send stream >1"
	exit
fi

here=`pwd`

# assumes the filesystem exists, and does mount, write, snapshot, send, unmount
# for the specified encoding option
send_one() {
	local str
	local subv
	local snap

	algorithm="$1"
	shift
	file="$1"
	shift

	subv="subv-$algorithm"
	snap="snap-$algorithm"

	run_check_mount_test_dev "-o" "compress-force=$algorithm"
	cd "$TEST_MNT" || _fail "cannot chdir to TEST_MNT"

	_mktemp_local "$file"

	run_check $SUDO_HELPER "$TOP/btrfs" subvolume create "$subv"
	run_check $SUDO_HELPER dd if=/dev/zero of="$subv/file1" bs=1M count=1
	run_check $SUDO_HELPER dd if=/dev/zero of="$subv/file2" bs=500K count=1
	run_check $SUDO_HELPER "$TOP/btrfs" subvolume snapshot -r "$subv" "$snap"
	run_check $SUDO_HELPER "$TOP/btrfs" send -f "$file" "$snap" "$@"

	cd "$here" || _fail "cannot chdir back to test directory"
	run_check_umount_test_dev
}

receive_one() {
	local str

	str="$1"
	shift

	run_check_mkfs_test_dev
	run_check_mount_test_dev
	run_check $SUDO_HELPER "$TOP/btrfs" receive "$@" -v -f "$str" "$TEST_MNT"
	run_check_umount_test_dev
	run_check rm -f -- "$str"
}

test_one_write_encoded() {
	local str
	local algorithm

	algorithm="$1"
	shift
	str="$here/stream-$algorithm.stream"

	run_check_mkfs_test_dev
	send_one "$algorithm" "$str" --compressed-data
	receive_one "$str" "$@"
}

test_one_stream_v1() {
	local str
	local algorithm

	algorithm="$1"
	shift
	str="$here/stream-$algorithm.stream"

	run_check_mkfs_test_dev
	send_one "$algorithm" "$str" --proto 1
	receive_one "$str" "$@"
}

test_mix_write_encoded() {
	local strzlib
	local strlzo
	local strzstd

	strzlib="$here/stream-zlib.stream"
	strlzo="$here/stream-lzo.stream"
	strzstd="$here/stream-zstd.stream"

	run_check_mkfs_test_dev

	send_one "zlib" "$strzlib" --compressed-data
	send_one "lzo" "$strlzo" --compressed-data
	send_one "zstd" "$strzstd" --compressed-data

	receive_one "$strzlib"
	receive_one "$strlzo"
	receive_one "$strzstd"
}

test_one_write_encoded "zlib"
test_one_write_encoded "lzo"
test_one_write_encoded "zstd"

# with decompression forced
test_one_write_encoded "zlib" "--force-decompress"
test_one_write_encoded "lzo" "--force-decompress"
test_one_write_encoded "zstd" "--force-decompress"

# send stream v1
test_one_stream_v1 "zlib"
test_one_stream_v1 "lzo"
test_one_stream_v1 "zstd"

# files use a mix of compression algorithms
test_mix_write_encoded