]> CyberLeo.Net >> Repos - FreeBSD/FreeBSD.git/blob - tests/sys/cddl/zfs/tests/zinject/zinject_001_pos.ksh
MFV r344878:
[FreeBSD/FreeBSD.git] / tests / sys / cddl / zfs / tests / zinject / zinject_001_pos.ksh
1 #!/usr/local/bin/ksh93 -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 # $FreeBSD$
24
25 #
26 # Copyright 2009 Sun Microsystems, Inc.  All rights reserved.
27 # Use is subject to license terms.
28 #
29 # ident "@(#)zinject_001_pos.ksh        1.3     09/06/22 SMI"
30 #
31
32 ###############################################################################
33 #
34 # __stc_assertion_start
35 #
36 # ID: zinject_001_pos
37 #
38 # DESCRIPTION:
39 #
40 # Inject an error into the plain file contents of a file.
41 # Verify fmdump will get the expect ereport
42 #
43 # STRATEGY:
44 # 1) Populate ZFS file system
45 # 2) Inject an error into the plain file contents of a file.
46 # 3) Verify fmdump get the ereport as expect.
47 #       <Errno>         <Expect ereport>                <Comments>      
48 #       io              ereport.fs.zfs.io
49 #                       ereport.fs.zfs.data
50 #       checksum        ereport.fs.zfs.checksum         Non-stripe pool
51 #                       ereport.fs.zfs.data
52 #       checksum        ereport.fs.zfs.data             Stripe pool only
53 #
54 # TESTABILITY: explicit
55 #
56 # TEST_AUTOMATION_LEVEL: automated
57 #
58 # CODING_STATUS: COMPLETED (2007-02-01)
59 #
60 # __stc_assertion_end
61 #
62 ################################################################################
63
64 . $STF_SUITE/tests/zinject/zinject.kshlib
65
66 verify_runnable "global"
67
68 log_assert "Verify fault inject handle content error successfully."
69 log_onexit cleanup_env
70
71 set -A types "" "mirror" "raidz" "raidz2"
72
73 typeset -i maxnumber=300
74
75 function test_zinject_unit
76 {
77         typeset etype=$1
78         typeset object=$2
79         typeset errno=$3
80         typeset ereport=$4
81         typeset now
82
83         typeset otype="file"
84         [[ -d $object ]] && otype="dir"
85
86         now=`date '+%m/%d/%y %H:%M:%S'`
87         inject_fault $etype $object $errno
88
89         trigger_inject $etype $object $otype
90
91         log_must check_ereport "$now" $ereport
92
93         log_must check_status $TESTPOOL $object
94
95         inject_clear
96 }
97
98 function test_zinject
99 {
100         typeset basedir=$1
101         typeset pooltype=$2
102         typeset -i i=0
103         typeset etype="data"
104
105         set -A errset "io" "ereport.fs.zfs.io ereport.fs.zfs.data"
106
107         ((i=${#errset[*]}))
108         if [[ -n $pooltype ]] ; then
109                 errset[i]="checksum"
110                 errset[((i+1))]="ereport.fs.zfs.checksum ereport.fs.zfs.data"
111         else
112                 errset[i]="checksum"
113                 errset[((i+1))]="ereport.fs.zfs.data"
114         fi
115                 
116         i=0
117         while ((i < ${#errset[*]} )); do
118
119                 for object in $basedir/testfile.$maxnumber \
120                         $basedir/testdir.$maxnumber ; do
121                 
122                         test_zinject_unit $etype $object \
123                                 ${errset[i]} "${errset[((i+1))]}"
124                 done
125
126                 (( i = i + 2 ))
127         done
128 }
129
130 inject_clear
131 for type in "${types[@]}"; do 
132         create_pool $TESTPOOL $type $pooldevs spare $sparedevs
133
134         log_must $ZPOOL add -f $TESTPOOL log $logdevs
135         log_must $ZPOOL add -f $TESTPOOL cache $cachedevs
136
137         log_must $ZPOOL replace $TESTPOOL $VDEV0 $sparedevs
138         log_must $ZFS create $TESTPOOL/$TESTFS
139         log_must $ZFS set mountpoint=$TESTDIR $TESTPOOL/$TESTFS
140         
141         populate_test_env $TESTDIR $maxnumber
142         test_zinject $TESTDIR $type
143
144         cleanup_env
145 done
146
147 log_pass "Fault inject handle content error successfully."