t_raid.sh revision 1.13 1 #! /usr/bin/atf-sh
2 # $NetBSD: t_raid.sh,v 1.13 2018/01/18 00:32:49 mrg Exp $
3 #
4 # Copyright (c) 2010 The NetBSD Foundation, Inc.
5 # All rights reserved.
6 #
7 # Redistribution and use in source and binary forms, with or without
8 # modification, are permitted provided that the following conditions
9 # are met:
10 # 1. Redistributions of source code must retain the above copyright
11 # notice, this list of conditions and the following disclaimer.
12 # 2. Redistributions in binary form must reproduce the above copyright
13 # notice, this list of conditions and the following disclaimer in the
14 # documentation and/or other materials provided with the distribution.
15 #
16 # THIS SOFTWARE IS PROVIDED BY THE NETBSD FOUNDATION, INC. AND CONTRIBUTORS
17 # ``AS IS'' AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED
18 # TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
19 # PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE FOUNDATION OR CONTRIBUTORS
20 # BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
21 # CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
22 # SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
23 # INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
24 # CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
25 # ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
26 # POSSIBILITY OF SUCH DAMAGE.
27 #
28
29 rawpart=`sysctl -n kern.rawpartition | tr '01234' 'abcde'`
30 rawraid=/dev/rraid0${rawpart}
31 raidserver="rump_server -lrumpvfs -lrumpdev -lrumpdev_disk -lrumpdev_raidframe"
32
33 makecfg()
34 {
35 level=${1}
36 ncol=${2}
37
38 printf "START array\n${ncol} 0\nSTART disks\n" > raid.conf
39 diskn=0
40 while [ ${ncol} -gt ${diskn} ] ; do
41 echo "/disk${diskn}" >> raid.conf
42 diskn=$((diskn+1))
43 done
44
45 printf "START layout\n32 1 1 ${level}\nSTART queue\nfifo 100\n" \
46 >> raid.conf
47 }
48
49 makecfg_old()
50 {
51 level=${1}
52 ncol=${2}
53
54 printf "START array\n1 ${ncol} 0\nSTART disks\n" > raid.conf
55 diskn=0
56 while [ ${ncol} -gt ${diskn} ] ; do
57 echo "/disk${diskn}" >> raid.conf
58 diskn=$((diskn+1))
59 done
60
61 printf "START layout\n32 1 1 ${level}\nSTART queue\nfifo 100\n" \
62 >> raid.conf
63 }
64
65 atf_test_case smalldisk cleanup
66 smalldisk_head()
67 {
68 atf_set "descr" "Checks the raidframe works on small disks " \
69 "(PR kern/44239)"
70 atf_set "require.progs" "rump_server"
71 }
72
73 smalldisk_body_backend()
74 {
75 export RUMP_SERVER=unix://sock
76 atf_check -s exit:0 ${raidserver} \
77 -d key=/disk0,hostpath=disk0.img,size=1m \
78 -d key=/disk1,hostpath=disk1.img,size=1m \
79 ${RUMP_SERVER}
80
81 atf_check -s exit:0 rump.raidctl -C raid.conf raid0
82 }
83
84 smalldisk_body()
85 {
86 makecfg 1 2
87 smalldisk_body_backend
88 }
89
90 smalldisk_cleanup()
91 {
92 export RUMP_SERVER=unix://sock
93 rump.halt
94 }
95
96 # The old configuration test case uses the smalldisk backend
97 atf_test_case old_numrows_config cleanup
98 old_numrows_config_head()
99 {
100 atf_set "descr" "Checks the old numRows configuration works"
101 atf_set "require.progs" "rump_server"
102 }
103
104 old_numrows_config_body()
105 {
106 makecfg_old 1 2
107 smalldisk_body_backend
108 }
109
110 old_numrows_config_cleanup()
111 {
112 export RUMP_SERVER=unix://sock
113 rump.halt
114 }
115
116 # make this smaller once 44239 is fixed
117 export RAID_MEDIASIZE=32m
118
119 atf_test_case raid1_compfail cleanup
120 raid1_compfail_head()
121 {
122 atf_set "descr" "Checks that RAID1 works after component failure"
123 atf_set "require.progs" "rump_server"
124 }
125
126 raid1_compfail_body()
127 {
128 makecfg 1 2
129 export RUMP_SERVER=unix://sock
130 atf_check -s exit:0 ${raidserver} \
131 -d key=/disk0,hostpath=disk0.img,size=${RAID_MEDIASIZE} \
132 -d key=/disk1,hostpath=disk1.img,size=${RAID_MEDIASIZE} \
133 ${RUMP_SERVER}
134
135 atf_check -s exit:0 rump.raidctl -C raid.conf raid0
136 atf_check -s exit:0 rump.raidctl -I 12345 raid0
137 atf_check -s exit:0 -o ignore rump.raidctl -iv raid0
138
139 # put some data there
140 atf_check -s exit:0 -e ignore \
141 dd if=$(atf_get_srcdir)/t_raid of=testfile count=4
142 atf_check -s exit:0 -e ignore -x \
143 "dd if=testfile | rump.dd of=${rawraid} conv=sync"
144
145 # restart server with failed component
146 rump.halt
147 rm disk1.img # FAIL
148 atf_check -s exit:0 ${raidserver} \
149 -d key=/disk0,hostpath=disk0.img,size=${RAID_MEDIASIZE} \
150 -d key=/disk1,hostpath=disk1.img,size=${RAID_MEDIASIZE} \
151 ${RUMP_SERVER}
152
153 atf_check -s exit:0 rump.raidctl -c raid.conf raid0
154
155 # check if we we get what we wrote
156 atf_check -s exit:0 -o file:testfile -e ignore \
157 rump.dd if=${rawraid} count=4
158 }
159
160 raid1_compfail_cleanup()
161 {
162 export RUMP_SERVER=unix://sock
163 rump.halt
164 }
165
166
167
168 atf_test_case raid1_comp0fail cleanup
169 raid1_comp0fail_head()
170 {
171 atf_set "descr" "Checks configuring RAID1 after component 0 fails" \
172 "(PR kern/44251)"
173 atf_set "require.progs" "rump_server"
174 }
175
176 raid1_comp0fail_body()
177 {
178 makecfg 1 2
179 export RUMP_SERVER=unix://sock
180 atf_check -s exit:0 ${raidserver} \
181 -d key=/disk0,hostpath=disk0.img,size=${RAID_MEDIASIZE} \
182 -d key=/disk1,hostpath=disk1.img,size=${RAID_MEDIASIZE} \
183 ${RUMP_SERVER}
184
185 atf_check -s exit:0 rump.raidctl -C raid.conf raid0
186 atf_check -s exit:0 rump.raidctl -I 12345 raid0
187 atf_check -s exit:0 -o ignore rump.raidctl -iv raid0
188
189 # restart server with failed component
190 rump.halt
191 rm disk0.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 ${RUMP_SERVER}
196
197 atf_check -s exit:0 rump.raidctl -c raid.conf raid0
198 }
199
200 raid1_comp0fail_cleanup()
201 {
202 export RUMP_SERVER=unix://sock
203 rump.halt
204 }
205
206 atf_test_case raid1_normal cleanup
207 raid1_normal_head()
208 {
209 atf_set "descr" "Checks that RAID1 -c configurations work " \
210 "in the normal case"
211 atf_set "require.progs" "rump_server"
212 }
213
214 raid1_normal_body()
215 {
216 makecfg 1 2
217 export RUMP_SERVER=unix://sock
218 atf_check -s exit:0 ${raidserver} \
219 -d key=/disk0,hostpath=disk0.img,size=${RAID_MEDIASIZE} \
220 -d key=/disk1,hostpath=disk1.img,size=${RAID_MEDIASIZE} \
221 ${RUMP_SERVER}
222
223 atf_check -s exit:0 rump.raidctl -C raid.conf raid0
224 atf_check -s exit:0 rump.raidctl -I 12345 raid0
225 atf_check -s exit:0 -o ignore rump.raidctl -iv raid0
226
227 # put some data there
228 atf_check -s exit:0 -e ignore \
229 dd if=$(atf_get_srcdir)/t_raid of=testfile count=4
230 atf_check -s exit:0 -e ignore -x \
231 "dd if=testfile | rump.dd of=${rawraid} conv=sync"
232
233 # restart server, disks remain normal
234 rump.halt
235
236 atf_check -s exit:0 ${raidserver} \
237 -d key=/disk0,hostpath=disk0.img,size=${RAID_MEDIASIZE} \
238 -d key=/disk1,hostpath=disk1.img,size=${RAID_MEDIASIZE} \
239 ${RUMP_SERVER}
240
241 atf_check -s exit:0 rump.raidctl -c raid.conf raid0
242
243 # check if we we get what we wrote
244 atf_check -s exit:0 -o file:testfile -e ignore \
245 rump.dd if=${rawraid} count=4
246
247 }
248
249 raid1_normal_cleanup()
250 {
251 export RUMP_SERVER=unix://sock
252 rump.halt
253 }
254
255
256 atf_test_case raid5_compfail cleanup
257 raid5_compfail_head()
258 {
259 atf_set "descr" "Checks that RAID5 works after component failure"
260 atf_set "require.progs" "rump_server"
261 }
262
263 raid5_compfail_body()
264 {
265 makecfg 5 3
266 export RUMP_SERVER=unix://sock
267 atf_check -s exit:0 ${raidserver} \
268 -d key=/disk0,hostpath=disk0.img,size=${RAID_MEDIASIZE} \
269 -d key=/disk1,hostpath=disk1.img,size=${RAID_MEDIASIZE} \
270 -d key=/disk2,hostpath=disk2.img,size=${RAID_MEDIASIZE} \
271 ${RUMP_SERVER}
272
273 atf_check -s exit:0 rump.raidctl -C raid.conf raid0
274 atf_check -s exit:0 rump.raidctl -I 12345 raid0
275 atf_check -s exit:0 -o ignore rump.raidctl -iv raid0
276
277 # put some data there
278 atf_check -s exit:0 -e ignore \
279 dd if=$(atf_get_srcdir)/t_raid of=testfile count=4
280 atf_check -s exit:0 -e ignore -x \
281 "dd if=testfile | rump.dd of=${rawraid} conv=sync"
282
283 # restart server with failed component
284 rump.halt
285 rm disk2.img # FAIL
286 atf_check -s exit:0 ${raidserver} \
287 -d key=/disk0,hostpath=disk0.img,size=${RAID_MEDIASIZE} \
288 -d key=/disk1,hostpath=disk1.img,size=${RAID_MEDIASIZE} \
289 -d key=/disk2,hostpath=disk2.img,size=${RAID_MEDIASIZE} \
290 ${RUMP_SERVER}
291
292 atf_check -s exit:0 rump.raidctl -c raid.conf raid0
293
294 # check if we we get what we wrote
295 atf_check -s exit:0 -o file:testfile -e ignore \
296 rump.dd if=${rawraid} count=4
297 }
298
299 raid5_compfail_cleanup()
300 {
301 export RUMP_SERVER=unix://sock
302 rump.halt
303 }
304
305 atf_test_case raid5_normal cleanup
306 raid5_normal_head()
307 {
308 atf_set "descr" "Checks that RAID5 works after normal shutdown " \
309 "and 'raidctl -c' startup"
310 atf_set "require.progs" "rump_server"
311 }
312
313 raid5_normal_body()
314 {
315 makecfg 5 3
316 export RUMP_SERVER=unix://sock
317 atf_check -s exit:0 ${raidserver} \
318 -d key=/disk0,hostpath=disk0.img,size=${RAID_MEDIASIZE} \
319 -d key=/disk1,hostpath=disk1.img,size=${RAID_MEDIASIZE} \
320 -d key=/disk2,hostpath=disk2.img,size=${RAID_MEDIASIZE} \
321 ${RUMP_SERVER}
322
323 atf_check -s exit:0 rump.raidctl -C raid.conf raid0
324 atf_check -s exit:0 rump.raidctl -I 12345 raid0
325 atf_check -s exit:0 -o ignore rump.raidctl -iv raid0
326
327 # put some data there
328 atf_check -s exit:0 -e ignore \
329 dd if=$(atf_get_srcdir)/t_raid of=testfile count=4
330 atf_check -s exit:0 -e ignore -x \
331 "dd if=testfile | rump.dd of=${rawraid} conv=sync"
332
333 # restart server after normal shutdown
334 rump.halt
335
336 atf_check -s exit:0 ${raidserver} \
337 -d key=/disk0,hostpath=disk0.img,size=${RAID_MEDIASIZE} \
338 -d key=/disk1,hostpath=disk1.img,size=${RAID_MEDIASIZE} \
339 -d key=/disk2,hostpath=disk2.img,size=${RAID_MEDIASIZE} \
340 ${RUMP_SERVER}
341
342 atf_check -s exit:0 rump.raidctl -c raid.conf raid0
343
344 # check if we we get what we wrote
345 atf_check -s exit:0 -o file:testfile -e ignore \
346 rump.dd if=${rawraid} count=4
347 }
348
349 raid5_normal_cleanup()
350 {
351 export RUMP_SERVER=unix://sock
352 rump.halt
353 }
354
355 atf_init_test_cases()
356 {
357 atf_add_test_case smalldisk
358 atf_add_test_case old_numrows_config
359 atf_add_test_case raid1_normal
360 atf_add_test_case raid1_comp0fail
361 atf_add_test_case raid1_compfail
362 atf_add_test_case raid5_normal
363 atf_add_test_case raid5_compfail
364 }
365