]>
Commit | Line | Data |
---|---|---|
3c67d83a TH |
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 | ||
70621ff2 | 23 | # |
b63e2d88 | 24 | # Copyright (c) 2018, 2019 by Delphix. All rights reserved. |
70621ff2 JWK |
25 | # |
26 | ||
3c67d83a TH |
27 | . $STF_SUITE/include/libtest.shlib |
28 | . $STF_SUITE/include/properties.shlib | |
e4a3297a | 29 | . $STF_SUITE/tests/functional/checksum/default.cfg |
3c67d83a TH |
30 | |
31 | # DESCRIPTION: | |
32 | # Sanity test to make sure checksum algorithms work. | |
33 | # For each checksum, create a file in the pool using that checksum. Verify | |
34 | # that there are no checksum errors. Next, for each checksum, create a single | |
b63e2d88 JWK |
35 | # file in the pool using that checksum, corrupt the file, and verify that we |
36 | # correctly catch the checksum errors. | |
3c67d83a TH |
37 | # |
38 | # STRATEGY: | |
39 | # Test 1 | |
40 | # 1. Create a mirrored pool | |
41 | # 2. Create a file using each checksum | |
42 | # 3. Export/import/scrub the pool | |
43 | # 4. Verify there's no checksum errors. | |
44 | # 5. Clear the pool | |
45 | # | |
46 | # Test 2 | |
47 | # 6. For each checksum: | |
48 | # 7. Create a file using the checksum | |
b63e2d88 JWK |
49 | # 8. Corrupt all level 0 blocks in the file |
50 | # 9. Scrub the pool | |
51 | # 10. Verify that there are checksum errors | |
3c67d83a TH |
52 | |
53 | verify_runnable "both" | |
54 | ||
55 | function cleanup | |
56 | { | |
c1d9abf9 | 57 | echo cleanup |
3c67d83a | 58 | [[ -e $TESTDIR ]] && \ |
c1d9abf9 | 59 | log_must rm -rf $TESTDIR/* > /dev/null 2>&1 |
3c67d83a TH |
60 | } |
61 | ||
62 | log_assert "Create and read back files with using different checksum algorithms" | |
63 | ||
64 | log_onexit cleanup | |
65 | ||
3c67d83a | 66 | WRITESZ=1048576 |
3c67d83a TH |
67 | |
68 | # Get a list of vdevs in our pool | |
69 | set -A array $(get_disklist_fullpath) | |
70 | ||
71 | # Get the first vdev, since we will corrupt it later | |
72 | firstvdev=${array[0]} | |
73 | ||
e4a3297a BB |
74 | # Test each checksum by writing a file using it, confirm there are no errors. |
75 | typeset -i i=1 | |
76 | while [[ $i -lt ${#CHECKSUM_TYPES[*]} ]]; do | |
77 | type=${CHECKSUM_TYPES[i]} | |
7839c4b5 MM |
78 | # edonr not supported on FreeBSD |
79 | if is_freebsd && [[ "$type" == "edonr" ]] ; then | |
80 | (( i = i + 1 )) | |
81 | continue | |
82 | fi | |
e4a3297a BB |
83 | log_must zfs set checksum=$type $TESTPOOL |
84 | log_must file_write -o overwrite -f $TESTDIR/test_$type \ | |
85 | -b $WRITESZ -c 5 -d R | |
86 | (( i = i + 1 )) | |
3c67d83a | 87 | done |
e4a3297a BB |
88 | |
89 | log_must zpool export $TESTPOOL | |
90 | log_must zpool import $TESTPOOL | |
91 | log_must zpool scrub $TESTPOOL | |
92 | log_must wait_scrubbed $TESTPOOL | |
93 | ||
70621ff2 | 94 | cksum=$(zpool status -P -v $TESTPOOL | grep "$firstvdev" | awk '{print $5}') |
7d75815d | 95 | log_assert "Normal file write test saw $cksum checksum errors" |
3c67d83a TH |
96 | log_must [ $cksum -eq 0 ] |
97 | ||
98 | rm -fr $TESTDIR/* | |
99 | ||
b63e2d88 | 100 | log_assert "Test corrupting the files and seeing checksum errors" |
e4a3297a BB |
101 | typeset -i j=1 |
102 | while [[ $j -lt ${#CHECKSUM_TYPES[*]} ]]; do | |
103 | type=${CHECKSUM_TYPES[$j]} | |
7839c4b5 MM |
104 | # edonr not supported on FreeBSD |
105 | if is_freebsd && [[ "$type" == "edonr" ]] ; then | |
106 | (( j = j + 1 )) | |
107 | continue | |
108 | fi | |
e4a3297a BB |
109 | log_must zfs set checksum=$type $TESTPOOL |
110 | log_must file_write -o overwrite -f $TESTDIR/test_$type \ | |
111 | -b $WRITESZ -c 5 -d R | |
3c67d83a | 112 | |
b63e2d88 JWK |
113 | # Corrupt the level 0 blocks of this file |
114 | corrupt_blocks_at_level $TESTDIR/test_$type | |
3c67d83a | 115 | |
e4a3297a BB |
116 | log_must zpool scrub $TESTPOOL |
117 | log_must wait_scrubbed $TESTPOOL | |
3c67d83a | 118 | |
70621ff2 JWK |
119 | cksum=$(zpool status -P -v $TESTPOOL | grep "$firstvdev" | \ |
120 | awk '{print $5}') | |
3c67d83a | 121 | |
e4a3297a | 122 | log_assert "Checksum '$type' caught $cksum checksum errors" |
3c67d83a TH |
123 | log_must [ $cksum -ne 0 ] |
124 | ||
e4a3297a BB |
125 | rm -f $TESTDIR/test_$type |
126 | log_must zpool clear $TESTPOOL | |
127 | ||
128 | (( j = j + 1 )) | |
3c67d83a | 129 | done |