]> CyberLeo.Net >> Repos - FreeBSD/FreeBSD.git/blob - tests/zfs-tests/tests/functional/checksum/filetest_001_pos.ksh
Use 100MB pool for filetest_001_pos.ksh checksum test
[FreeBSD/FreeBSD.git] / tests / zfs-tests / tests / functional / checksum / filetest_001_pos.ksh
1 #! /bin/ksh -p
2 #
3 # CDDL HEADER START
4 #
5 # The contents of this file are subject to the terms of the
6 # Common Development and Distribution License (the "License").
7 # You may not use this file except in compliance with the License.
8 #
9 # You can obtain a copy of the license at usr/src/OPENSOLARIS.LICENSE
10 # or http://www.opensolaris.org/os/licensing.
11 # See the License for the specific language governing permissions
12 # and limitations under the License.
13 #
14 # When distributing Covered Code, include this CDDL HEADER in each
15 # file and include the License file at usr/src/OPENSOLARIS.LICENSE.
16 # If applicable, add the following below this CDDL HEADER, with the
17 # fields enclosed by brackets "[]" replaced with your own identifying
18 # information: Portions Copyright [yyyy] [name of copyright owner]
19 #
20 # CDDL HEADER END
21 #
22
23 . $STF_SUITE/include/libtest.shlib
24 . $STF_SUITE/include/properties.shlib
25
26 # DESCRIPTION:
27 # Sanity test to make sure checksum algorithms work.
28 # For each checksum, create a file in the pool using that checksum.  Verify
29 # that there are no checksum errors.  Next, for each checksum, create a single
30 # file in the pool using that checksum, scramble the underlying vdev, and
31 # verify that we correctly catch the checksum errors.
32 #
33 # STRATEGY:
34 # Test 1
35 # 1. Create a mirrored pool
36 # 2. Create a file using each checksum
37 # 3. Export/import/scrub the pool
38 # 4. Verify there's no checksum errors.
39 # 5. Clear the pool
40 #
41 # Test 2
42 # 6. For each checksum:
43 # 7.    Create a file using the checksum
44 # 8.    Export the pool
45 # 9.    Scramble the data on one of the underlying VDEVs
46 # 10.   Import the pool
47 # 11.   Scrub the pool
48 # 12.   Verify that there are checksum errors
49
50 verify_runnable "both"
51
52 function cleanup
53 {
54         $ECHO cleanup
55         [[ -e $TESTDIR ]] && \
56                 log_must $RM -rf $TESTDIR/* > /dev/null 2>&1
57 }
58
59 log_assert "Create and read back files with using different checksum algorithms"
60
61 log_onexit cleanup
62
63 FSSIZE=$($ZPOOL list -Hp -o size $TESTPOOL)
64 WRITESZ=1048576
65 WRITECNT=$((($FSSIZE) / $WRITESZ ))
66 # Skip the first and last 4MB
67 SKIP=4127518
68 SKIPCNT=$((($SKIP / $WRITESZ )))
69 SKIPCNT=$((($SKIPCNT * 2)))
70 WRITECNT=$((($WRITECNT - $SKIPCNT)))
71
72 # Get a list of vdevs in our pool
73 set -A array $(get_disklist_fullpath)
74
75 # Get the first vdev, since we will corrupt it later
76 firstvdev=${array[0]}
77
78 # First test each checksum by writing a file using it, and confirm there's no
79 # errors.
80 for ((count = 0; count < ${#checksum_props[*]} ; count++)); do
81         i=${checksum_props[$count]}
82         $ZFS set checksum=$i $TESTPOOL
83         $FILE_WRITE -o overwrite -f $TESTDIR/test_$i -b $WRITESZ -c 5 -d R
84 done
85 $ZPOOL export $TESTPOOL
86 $ZPOOL import $TESTPOOL
87 $ZPOOL scrub $TESTPOOL
88 while is_pool_scrubbing $TESTPOOL; do
89         $SLEEP 1
90 done
91 $ZPOOL status -P -v $TESTPOOL | grep $firstvdev | read -r name state rd wr cksum
92 log_assert "Normal file write test saw $cksum checksum errors"
93 log_must [ $cksum -eq 0 ]
94
95 rm -fr $TESTDIR/*
96
97 log_assert "Test scrambling the disk and seeing checksum errors"
98 for ((count = 0; count < ${#checksum_props[*]} ; count++)); do
99         i=${checksum_props[$count]}
100         $ZFS set checksum=$i $TESTPOOL
101         $FILE_WRITE -o overwrite -f $TESTDIR/test_$i -b $WRITESZ -c 5 -d R
102
103         $ZPOOL export $TESTPOOL
104
105         # Scramble the data on the first vdev in our pool.
106         # Skip the first and last 16MB of data, then scramble the rest after that
107         #
108         $FILE_WRITE -o overwrite -f $firstvdev -s $SKIP -c $WRITECNT -b $WRITESZ -d R
109
110         $ZPOOL import $TESTPOOL
111
112         i=${checksum_props[$count]}
113         $ZPOOL scrub $TESTPOOL
114         while is_pool_scrubbing $TESTPOOL; do
115                 $SLEEP 1
116         done
117
118         $ZPOOL status -P -v $TESTPOOL | grep $firstvdev | read -r name state rd wr cksum
119
120         log_assert "Checksum '$i' caught $cksum checksum errors"
121         log_must [ $cksum -ne 0 ]
122
123         rm -f $TESTDIR/test_$i
124         $ZPOOL clear $TESTPOOL
125 done