t_raid.sh revision 1.8 1 # $NetBSD: t_raid.sh,v 1.8 2011/05/14 17:42:28 jmmv Exp $
2 #
3 # Copyright (c) 2010 The NetBSD Foundation, Inc.
4 # All rights reserved.
5 #
6 # Redistribution and use in source and binary forms, with or without
7 # modification, are permitted provided that the following conditions
8 # are met:
9 # 1. Redistributions of source code must retain the above copyright
10 # notice, this list of conditions and the following disclaimer.
11 # 2. Redistributions in binary form must reproduce the above copyright
12 # notice, this list of conditions and the following disclaimer in the
13 # documentation and/or other materials provided with the distribution.
14 #
15 # THIS SOFTWARE IS PROVIDED BY THE NETBSD FOUNDATION, INC. AND CONTRIBUTORS
16 # ``AS IS'' AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED
17 # TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
18 # PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE FOUNDATION OR CONTRIBUTORS
19 # BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
20 # CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
21 # SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
22 # INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
23 # CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
24 # ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
25 # POSSIBILITY OF SUCH DAMAGE.
26 #
27
28 rawpart=`sysctl -n kern.rawpartition | tr '01234' 'abcde'`
29 rawraid=/dev/rraid0${rawpart}
30 raidserver="rump_server -lrumpvfs -lrumpdev -lrumpdev_disk -lrumpdev_raidframe"
31
32 makecfg()
33 {
34 level=${1}
35 ncol=${2}
36
37 printf "START array\n1 ${ncol} 0\nSTART disks\n" > raid.conf
38 diskn=0
39 while [ ${ncol} -gt ${diskn} ] ; do
40 echo "/disk${diskn}" >> raid.conf
41 diskn=$((diskn+1))
42 done
43
44 printf "START layout\n32 1 1 ${level}\nSTART queue\nfifo 100\n" \
45 >> raid.conf
46 }
47
48 atf_test_case smalldisk cleanup
49 smalldisk_head()
50 {
51 atf_set "descr" "Checks the raidframe works on small disks " \
52 "(PR kern/44239)"
53 }
54
55 smalldisk_body()
56 {
57 makecfg 1 2
58 export RUMP_SERVER=unix://sock
59 atf_check -s exit:0 ${raidserver} \
60 -d key=/disk0,hostpath=disk0.img,size=1m \
61 -d key=/disk1,hostpath=disk1.img,size=1m \
62 ${RUMP_SERVER}
63
64 atf_check -s exit:0 rump.raidctl -C raid.conf raid0
65 }
66
67 smalldisk_cleanup()
68 {
69 export RUMP_SERVER=unix://sock
70 rump.halt
71 }
72
73
74 # make this smaller once 44239 is fixed
75 export RAID_MEDIASIZE=32m
76
77 atf_test_case raid1_compfail cleanup
78 raid1_compfail_head()
79 {
80 atf_set "descr" "Checks that RAID1 works after component failure"
81 }
82
83 raid1_compfail_body()
84 {
85 makecfg 1 2
86 export RUMP_SERVER=unix://sock
87 atf_check -s exit:0 ${raidserver} \
88 -d key=/disk0,hostpath=disk0.img,size=${RAID_MEDIASIZE} \
89 -d key=/disk1,hostpath=disk1.img,size=${RAID_MEDIASIZE} \
90 ${RUMP_SERVER}
91
92 atf_check -s exit:0 rump.raidctl -C raid.conf raid0
93 atf_check -s exit:0 rump.raidctl -I 12345 raid0
94 atf_check -s exit:0 -o ignore rump.raidctl -iv raid0
95
96 # put some data there
97 atf_check -s exit:0 -e ignore \
98 dd if=$(atf_get_srcdir)/t_raid of=testfile count=4
99 atf_check -s exit:0 -e ignore -x \
100 "dd if=testfile | rump.dd of=${rawraid} conv=sync"
101
102 # restart server with failed component
103 rump.halt
104 rm disk1.img # FAIL
105 atf_check -s exit:0 ${raidserver} \
106 -d key=/disk0,hostpath=disk0.img,size=${RAID_MEDIASIZE} \
107 -d key=/disk1,hostpath=disk1.img,size=${RAID_MEDIASIZE} \
108 ${RUMP_SERVER}
109
110 atf_check -s exit:0 rump.raidctl -c raid.conf raid0
111
112 # check if we we get what we wrote
113 atf_check -s exit:0 -o file:testfile -e ignore \
114 rump.dd if=${rawraid} count=4
115 }
116
117 raid1_compfail_cleanup()
118 {
119 export RUMP_SERVER=unix://sock
120 rump.halt
121 }
122
123
124
125 atf_test_case raid1_comp0fail cleanup
126 raid1_comp0fail_head()
127 {
128 atf_set "descr" "Checks configuring RAID1 after component 0 fails"
129 }
130
131 raid1_comp0fail_body()
132 {
133 makecfg 1 2
134 export RUMP_SERVER=unix://sock
135 atf_check -s exit:0 ${raidserver} \
136 -d key=/disk0,hostpath=disk0.img,size=${RAID_MEDIASIZE} \
137 -d key=/disk1,hostpath=disk1.img,size=${RAID_MEDIASIZE} \
138 ${RUMP_SERVER}
139
140 atf_check -s exit:0 rump.raidctl -C raid.conf raid0
141 atf_check -s exit:0 rump.raidctl -I 12345 raid0
142 atf_check -s exit:0 -o ignore rump.raidctl -iv raid0
143
144 # restart server with failed component
145 rump.halt
146 rm disk0.img # FAIL
147 atf_check -s exit:0 ${raidserver} \
148 -d key=/disk0,hostpath=disk0.img,size=${RAID_MEDIASIZE} \
149 -d key=/disk1,hostpath=disk1.img,size=${RAID_MEDIASIZE} \
150 ${RUMP_SERVER}
151
152 atf_expect_fail "PR kern/44251"
153 atf_check -s exit:0 rump.raidctl -c raid.conf raid0
154 }
155
156 raid1_comp0fail_cleanup()
157 {
158 export RUMP_SERVER=unix://sock
159 rump.halt
160 }
161
162
163 atf_test_case raid5_compfail cleanup
164 raid5_compfail_head()
165 {
166 atf_set "descr" "Checks that RAID5 works after component failure"
167 }
168
169 raid5_compfail_body()
170 {
171 makecfg 5 3
172 export RUMP_SERVER=unix://sock
173 atf_check -s exit:0 ${raidserver} \
174 -d key=/disk0,hostpath=disk0.img,size=${RAID_MEDIASIZE} \
175 -d key=/disk1,hostpath=disk1.img,size=${RAID_MEDIASIZE} \
176 -d key=/disk2,hostpath=disk2.img,size=${RAID_MEDIASIZE} \
177 ${RUMP_SERVER}
178
179 atf_check -s exit:0 rump.raidctl -C raid.conf raid0
180 atf_check -s exit:0 rump.raidctl -I 12345 raid0
181 atf_check -s exit:0 -o ignore rump.raidctl -iv raid0
182
183 # put some data there
184 atf_check -s exit:0 -e ignore \
185 dd if=$(atf_get_srcdir)/t_raid of=testfile count=4
186 atf_check -s exit:0 -e ignore -x \
187 "dd if=testfile | rump.dd of=${rawraid} conv=sync"
188
189 # restart server with failed component
190 rump.halt
191 rm disk2.img # FAIL
192 atf_check -s exit:0 ${raidserver} \
193 -d key=/disk0,hostpath=disk0.img,size=${RAID_MEDIASIZE} \
194 -d key=/disk1,hostpath=disk1.img,size=${RAID_MEDIASIZE} \
195 -d key=/disk2,hostpath=disk2.img,size=${RAID_MEDIASIZE} \
196 ${RUMP_SERVER}
197
198 atf_check -s exit:0 rump.raidctl -c raid.conf raid0
199
200 # check if we we get what we wrote
201 atf_check -s exit:0 -o file:testfile -e ignore \
202 rump.dd if=${rawraid} count=4
203 }
204
205 raid5_compfail_cleanup()
206 {
207 export RUMP_SERVER=unix://sock
208 rump.halt
209 }
210
211
212 atf_init_test_cases()
213 {
214 atf_add_test_case smalldisk
215 atf_add_test_case raid1_comp0fail
216 atf_add_test_case raid1_compfail
217 atf_add_test_case raid5_compfail
218 }
219