1#!/bin/ksh -p
2
3#
4# This file and its contents are supplied under the terms of the
5# Common Development and Distribution License ("CDDL"), version 1.0.
6# You may only use this file in accordance with the terms of version
7# 1.0 of the CDDL.
8#
9# A full copy of the text of the CDDL should have accompanied this
10# source.  A copy of the CDDL is also available via the Internet at
11# http://www.illumos.org/license/CDDL.
12#
13
14#
15# Copyright (c) 2015, Delphix. All rights reserved.
16# Copyright (c) 2019, Kjeld Schouten-Lebbing. All rights reserved.
17#
18
19. $STF_SUITE/tests/functional/rsend/rsend.kshlib
20. $STF_SUITE/include/properties.shlib
21
22#
23# Description:
24# Verify that the amount of data in a send -c stream matches compressratio.
25#
26# Strategy:
27# 1. For random compression types, and compressible / incompressible data:
28# 2. Create a snap with data
29# 3. Compare the size of the stream with the data on the dataset, adjusted
30#    by compressratio for normal send, and compared to used for send -c.
31#
32
33verify_runnable "both"
34
35log_assert "Verify send -c streams are compressed"
36log_onexit cleanup_pool $POOL2
37
38typeset sendfs=$POOL2/$FS
39typeset megs=64
40
41for prop in "${compress_prop_vals[@]}"; do
42	for compressible in 'yes' 'no'; do
43		log_must zfs create -o compress=$prop $sendfs
44
45		if [[ $compressible = 'yes' ]]; then
46			write_compressible $(get_prop mountpoint $sendfs) \
47			    ${megs}m
48		else
49			typeset file="$(get_prop mountpoint $sendfs)/ddfile"
50			log_must dd if=/dev/urandom of=$file bs=1024k count=$megs
51		fi
52
53		log_must zfs snapshot $sendfs@snap
54
55		# Calculate the sizes and verify the compression ratio.
56		log_must eval "zfs send $sendfs@snap >$BACKDIR/uncompressed"
57		verify_stream_size $BACKDIR/uncompressed $sendfs
58
59		log_must eval "zfs send -c $sendfs@snap >$BACKDIR/compressed"
60		verify_stream_size $BACKDIR/compressed $sendfs
61
62		log_must rm $BACKDIR/uncompressed $BACKDIR/compressed
63		log_must_busy zfs destroy -r $sendfs
64	done
65done
66
67log_pass "Verify send -c streams are compressed"
68