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) 2022 by Delphix. All rights reserved.
16#
17
18. $STF_SUITE/tests/functional/rsend/rsend.kshlib
19. $STF_SUITE/include/math.shlib
20
21#
22# Description:
23# Verify compression features show up in zstream dump
24#
25# Strategy:
26# 1. Create a compressed send stream
27# 2. Recompress the stream with a different algorithm
28# 3. Verify it can be received correctly
29# 4. Verify the contents match the original filesystem
30# 5. Create an uncompressed send stream
31# 6. Compress the send stream
32# 7. Verify that the stream is smaller when compressed
33#
34
35verify_runnable "both"
36
37log_assert "Verify zstream recompress correctly modifies send streams."
38log_onexit cleanup_pool $POOL2
39
40typeset sendfs=$POOL2/fs
41typeset recvfs=$POOL2/fs2
42
43log_must zfs create -o compress=lz4 $sendfs
44typeset dir=$(get_prop mountpoint $sendfs)
45write_compressible $dir 16m
46log_must zfs snapshot $sendfs@snap
47
48log_must eval "zfs send -c $sendfs@snap | zstream recompress gzip-1 | zfs recv $recvfs"
49typeset recvdir=$(get_prop mountpoint $recvfs)
50log_must diff -r $dir $recvdir
51
52log_must eval "zfs send $sendfs@snap >$BACKDIR/uncompressed"
53log_must zstream recompress gzip-1 <$BACKDIR/uncompressed >$BACKDIR/compressed
54typeset uncomp_size=$(wc -c $BACKDIR/uncompressed | awk '{print $1}')
55typeset comp_size=$(wc -c $BACKDIR/compressed | awk '{print $1}')
56[[ "$uncomp_size" -gt "$comp_size" ]] || log_fail "recompressed stream was not smaller"
57
58log_pass "zstream recompress correctly modifies send streams."
59