aboutsummaryrefslogtreecommitdiff
path: root/sys/contrib/openzfs/tests/zfs-tests/tests/functional/rsend/send-c_verify_ratio.ksh
blob: b7d978624f2ba5a8d35537636a0fcbdd8a1fa076 (plain) (blame)
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
#!/bin/ksh -p

#
# This file and its contents are supplied under the terms of the
# Common Development and Distribution License ("CDDL"), version 1.0.
# You may only use this file in accordance with the terms of version
# 1.0 of the CDDL.
#
# A full copy of the text of the CDDL should have accompanied this
# source.  A copy of the CDDL is also available via the Internet at
# http://www.illumos.org/license/CDDL.
#

#
# Copyright (c) 2015, Delphix. All rights reserved.
# Copyright (c) 2019, Kjeld Schouten-Lebbing. All rights reserved.
#

. $STF_SUITE/tests/functional/rsend/rsend.kshlib
. $STF_SUITE/include/properties.shlib

#
# Description:
# Verify that the amount of data in a send -c stream matches compressratio.
#
# Strategy:
# 1. For random compression types, and compressible / incompressible data:
# 2. Create a snap with data
# 3. Compare the size of the stream with the data on the dataset, adjusted
#    by compressratio for normal send, and compared to used for send -c.
#

verify_runnable "both"

log_assert "Verify send -c streams are compressed"
log_onexit cleanup_pool $POOL2

typeset sendfs=$POOL2/$FS
typeset megs=128

for prop in "${compress_prop_vals[@]}"; do
	for compressible in 'yes' 'no'; do
		log_must zfs create -o compress=$prop $sendfs

		if [[ $compressible = 'yes' ]]; then
			write_compressible $(get_prop mountpoint $sendfs) \
			    ${megs}m
		else
			typeset file="$(get_prop mountpoint $sendfs)/ddfile"
			log_must dd if=/dev/urandom of=$file bs=1024k count=$megs
		fi

		log_must zfs snapshot $sendfs@snap

		# Calculate the sizes and verify the compression ratio.
		log_must eval "zfs send $sendfs@snap >$BACKDIR/uncompressed"
		verify_stream_size $BACKDIR/uncompressed $sendfs

		log_must eval "zfs send -c $sendfs@snap >$BACKDIR/compressed"
		verify_stream_size $BACKDIR/compressed $sendfs

		log_must rm $BACKDIR/uncompressed $BACKDIR/compressed
		log_must_busy zfs destroy -r $sendfs
	done
done

log_pass "Verify send -c streams are compressed"