xref: /freebsd/sys/contrib/openzfs/tests/zfs-tests/tests/functional/fault/decompress_fault.ksh (revision 61145dc2b94f12f6a47344fb9aac702321880e43)
1#!/bin/ksh -p
2# SPDX-License-Identifier: CDDL-1.0
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) 2018 by Datto Inc.
16# All rights reserved.
17#
18
19. $STF_SUITE/include/libtest.shlib
20. $STF_SUITE/tests/functional/fault/fault.cfg
21
22#
23# DESCRIPTION:
24# Test that injected decompression errors are handled correctly.
25#
26# STRATEGY:
27# 1. Create an compressed dataset with a test file
28# 2. Inject decompression errors on the file 20% of the time
29# 3. Read the file to confirm that errors are handled correctly
30# 4. Confirm that the decompression injection was added to the ZED logs
31#
32
33log_assert "Testing that injected decompression errors are handled correctly"
34
35function cleanup
36{
37	log_must set_tunable64 COMPRESSED_ARC_ENABLED 1
38	log_must zinject -c all
39	default_cleanup_noexit
40}
41
42log_onexit cleanup
43
44default_mirror_setup_noexit $DISK1 $DISK2
45log_must set_tunable64 COMPRESSED_ARC_ENABLED 0
46log_must zfs create -o compression=on $TESTPOOL/fs
47mntpt=$(get_prop mountpoint $TESTPOOL/fs)
48write_compressible $mntpt 32m 1 1024k "testfile"
49sync_all_pools
50log_must zfs umount $TESTPOOL/fs
51log_must zfs mount $TESTPOOL/fs
52log_must zinject -a -t data -e decompress -f 20 $mntpt/testfile.0
53log_mustnot eval "cat $mntpt/testfile.0 > /dev/null"
54if ! is_freebsd; then
55	# Events are not supported on FreeBSD
56	log_must eval "zpool events $TESTPOOL | grep -q 'data'"
57fi
58
59log_pass "Injected decompression errors are handled correctly"
60