xref: /freebsd/contrib/netbsd-tests/dev/raidframe/t_raid.sh (revision 09a53ad8f1318c5daae6cfb19d97f4f6459f0013)
1#! /usr/bin/atf-sh
2#	$NetBSD: t_raid.sh,v 1.12 2013/02/19 21:08:24 joerg 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
29rawpart=`sysctl -n kern.rawpartition | tr '01234' 'abcde'`
30rawraid=/dev/rraid0${rawpart}
31raidserver="rump_server -lrumpvfs -lrumpdev -lrumpdev_disk -lrumpdev_raidframe"
32
33makecfg()
34{
35	level=${1}
36	ncol=${2}
37
38	printf "START array\n1 ${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
49atf_test_case smalldisk cleanup
50smalldisk_head()
51{
52	atf_set "descr" "Checks the raidframe works on small disks " \
53	    "(PR kern/44239)"
54	atf_set "require.progs" "rump_server"
55}
56
57smalldisk_body()
58{
59	makecfg 1 2
60	export RUMP_SERVER=unix://sock
61	atf_check -s exit:0 ${raidserver}			\
62	    -d key=/disk0,hostpath=disk0.img,size=1m		\
63	    -d key=/disk1,hostpath=disk1.img,size=1m		\
64	    ${RUMP_SERVER}
65
66	atf_check -s exit:0 rump.raidctl -C raid.conf raid0
67}
68
69smalldisk_cleanup()
70{
71	export RUMP_SERVER=unix://sock
72	rump.halt
73}
74
75
76# make this smaller once 44239 is fixed
77export RAID_MEDIASIZE=32m
78
79atf_test_case raid1_compfail cleanup
80raid1_compfail_head()
81{
82	atf_set "descr" "Checks that RAID1 works after component failure"
83	atf_set "require.progs" "rump_server"
84}
85
86raid1_compfail_body()
87{
88	makecfg 1 2
89	export RUMP_SERVER=unix://sock
90	atf_check -s exit:0 ${raidserver}				\
91	    -d key=/disk0,hostpath=disk0.img,size=${RAID_MEDIASIZE}	\
92	    -d key=/disk1,hostpath=disk1.img,size=${RAID_MEDIASIZE}	\
93	    ${RUMP_SERVER}
94
95	atf_check -s exit:0 rump.raidctl -C raid.conf raid0
96	atf_check -s exit:0 rump.raidctl -I 12345 raid0
97	atf_check -s exit:0 -o ignore rump.raidctl -iv raid0
98
99	# put some data there
100	atf_check -s exit:0 -e ignore \
101	    dd if=$(atf_get_srcdir)/t_raid of=testfile count=4
102	atf_check -s exit:0 -e ignore -x \
103	    "dd if=testfile | rump.dd of=${rawraid} conv=sync"
104
105	# restart server with failed component
106	rump.halt
107	rm disk1.img # FAIL
108	atf_check -s exit:0 ${raidserver}				\
109	    -d key=/disk0,hostpath=disk0.img,size=${RAID_MEDIASIZE}	\
110	    -d key=/disk1,hostpath=disk1.img,size=${RAID_MEDIASIZE}	\
111	    ${RUMP_SERVER}
112
113	atf_check -s exit:0 rump.raidctl -c raid.conf raid0
114
115	# check if we we get what we wrote
116	atf_check -s exit:0 -o file:testfile -e ignore \
117	    rump.dd if=${rawraid} count=4
118}
119
120raid1_compfail_cleanup()
121{
122	export RUMP_SERVER=unix://sock
123	rump.halt
124}
125
126
127
128atf_test_case raid1_comp0fail cleanup
129raid1_comp0fail_head()
130{
131	atf_set "descr" "Checks configuring RAID1 after component 0 fails" \
132		"(PR kern/44251)"
133	atf_set "require.progs" "rump_server"
134}
135
136raid1_comp0fail_body()
137{
138	makecfg 1 2
139	export RUMP_SERVER=unix://sock
140	atf_check -s exit:0 ${raidserver}				\
141	    -d key=/disk0,hostpath=disk0.img,size=${RAID_MEDIASIZE}	\
142	    -d key=/disk1,hostpath=disk1.img,size=${RAID_MEDIASIZE}	\
143	    ${RUMP_SERVER}
144
145	atf_check -s exit:0 rump.raidctl -C raid.conf raid0
146	atf_check -s exit:0 rump.raidctl -I 12345 raid0
147	atf_check -s exit:0 -o ignore rump.raidctl -iv raid0
148
149	# restart server with failed component
150	rump.halt
151	rm disk0.img # FAIL
152	atf_check -s exit:0 ${raidserver} 				\
153	    -d key=/disk0,hostpath=disk0.img,size=${RAID_MEDIASIZE}	\
154	    -d key=/disk1,hostpath=disk1.img,size=${RAID_MEDIASIZE}	\
155	    ${RUMP_SERVER}
156
157	atf_check -s exit:0 rump.raidctl -c raid.conf raid0
158}
159
160raid1_comp0fail_cleanup()
161{
162	export RUMP_SERVER=unix://sock
163	rump.halt
164}
165
166atf_test_case raid1_normal cleanup
167raid1_normal_head()
168{
169	atf_set "descr" "Checks that RAID1 -c configurations work " \
170		"in the normal case"
171	atf_set "require.progs" "rump_server"
172}
173
174raid1_normal_body()
175{
176	makecfg 1 2
177	export RUMP_SERVER=unix://sock
178        atf_check -s exit:0 ${raidserver}                               \
179            -d key=/disk0,hostpath=disk0.img,size=${RAID_MEDIASIZE}     \
180            -d key=/disk1,hostpath=disk1.img,size=${RAID_MEDIASIZE}     \
181            ${RUMP_SERVER}
182
183        atf_check -s exit:0 rump.raidctl -C raid.conf raid0
184        atf_check -s exit:0 rump.raidctl -I 12345 raid0
185        atf_check -s exit:0 -o ignore rump.raidctl -iv raid0
186
187        # put some data there
188        atf_check -s exit:0 -e ignore \
189            dd if=$(atf_get_srcdir)/t_raid of=testfile count=4
190        atf_check -s exit:0 -e ignore -x \
191            "dd if=testfile | rump.dd of=${rawraid} conv=sync"
192
193        # restart server, disks remain normal
194        rump.halt
195
196        atf_check -s exit:0 ${raidserver}                               \
197            -d key=/disk0,hostpath=disk0.img,size=${RAID_MEDIASIZE}     \
198            -d key=/disk1,hostpath=disk1.img,size=${RAID_MEDIASIZE}     \
199            ${RUMP_SERVER}
200
201        atf_check -s exit:0 rump.raidctl -c raid.conf raid0
202
203        # check if we we get what we wrote
204        atf_check -s exit:0 -o file:testfile -e ignore \
205            rump.dd if=${rawraid} count=4
206
207}
208
209raid1_normal_cleanup()
210{
211        export RUMP_SERVER=unix://sock
212        rump.halt
213}
214
215
216atf_test_case raid5_compfail cleanup
217raid5_compfail_head()
218{
219	atf_set "descr" "Checks that RAID5 works after component failure"
220	atf_set "require.progs" "rump_server"
221}
222
223raid5_compfail_body()
224{
225	makecfg 5 3
226	export RUMP_SERVER=unix://sock
227	atf_check -s exit:0 ${raidserver}				\
228	    -d key=/disk0,hostpath=disk0.img,size=${RAID_MEDIASIZE}	\
229	    -d key=/disk1,hostpath=disk1.img,size=${RAID_MEDIASIZE}	\
230	    -d key=/disk2,hostpath=disk2.img,size=${RAID_MEDIASIZE}	\
231	    ${RUMP_SERVER}
232
233	atf_check -s exit:0 rump.raidctl -C raid.conf raid0
234	atf_check -s exit:0 rump.raidctl -I 12345 raid0
235	atf_check -s exit:0 -o ignore rump.raidctl -iv raid0
236
237	# put some data there
238	atf_check -s exit:0 -e ignore \
239	    dd if=$(atf_get_srcdir)/t_raid of=testfile count=4
240	atf_check -s exit:0 -e ignore -x \
241	    "dd if=testfile | rump.dd of=${rawraid} conv=sync"
242
243	# restart server with failed component
244	rump.halt
245	rm disk2.img # FAIL
246	atf_check -s exit:0 ${raidserver}				\
247	    -d key=/disk0,hostpath=disk0.img,size=${RAID_MEDIASIZE}	\
248	    -d key=/disk1,hostpath=disk1.img,size=${RAID_MEDIASIZE}	\
249	    -d key=/disk2,hostpath=disk2.img,size=${RAID_MEDIASIZE}	\
250	    ${RUMP_SERVER}
251
252	atf_check -s exit:0 rump.raidctl -c raid.conf raid0
253
254	# check if we we get what we wrote
255	atf_check -s exit:0 -o file:testfile -e ignore \
256	    rump.dd if=${rawraid} count=4
257}
258
259raid5_compfail_cleanup()
260{
261	export RUMP_SERVER=unix://sock
262	rump.halt
263}
264
265atf_test_case raid5_normal cleanup
266raid5_normal_head()
267{
268        atf_set "descr" "Checks that RAID5 works after normal shutdown " \
269		"and 'raidctl -c' startup"
270	atf_set "require.progs" "rump_server"
271}
272
273raid5_normal_body()
274{
275        makecfg 5 3
276        export RUMP_SERVER=unix://sock
277        atf_check -s exit:0 ${raidserver}                               \
278            -d key=/disk0,hostpath=disk0.img,size=${RAID_MEDIASIZE}     \
279            -d key=/disk1,hostpath=disk1.img,size=${RAID_MEDIASIZE}     \
280            -d key=/disk2,hostpath=disk2.img,size=${RAID_MEDIASIZE}     \
281            ${RUMP_SERVER}
282
283        atf_check -s exit:0 rump.raidctl -C raid.conf raid0
284        atf_check -s exit:0 rump.raidctl -I 12345 raid0
285        atf_check -s exit:0 -o ignore rump.raidctl -iv raid0
286
287        # put some data there
288        atf_check -s exit:0 -e ignore \
289            dd if=$(atf_get_srcdir)/t_raid of=testfile count=4
290        atf_check -s exit:0 -e ignore -x \
291            "dd if=testfile | rump.dd of=${rawraid} conv=sync"
292
293        # restart server after normal shutdown
294        rump.halt
295
296        atf_check -s exit:0 ${raidserver}                               \
297            -d key=/disk0,hostpath=disk0.img,size=${RAID_MEDIASIZE}     \
298            -d key=/disk1,hostpath=disk1.img,size=${RAID_MEDIASIZE}     \
299            -d key=/disk2,hostpath=disk2.img,size=${RAID_MEDIASIZE}     \
300            ${RUMP_SERVER}
301
302        atf_check -s exit:0 rump.raidctl -c raid.conf raid0
303
304        # check if we we get what we wrote
305        atf_check -s exit:0 -o file:testfile -e ignore \
306            rump.dd if=${rawraid} count=4
307}
308
309raid5_normal_cleanup()
310{
311        export RUMP_SERVER=unix://sock
312        rump.halt
313}
314
315atf_init_test_cases()
316{
317	atf_add_test_case smalldisk
318	atf_add_test_case raid1_normal
319	atf_add_test_case raid1_comp0fail
320	atf_add_test_case raid1_compfail
321	atf_add_test_case raid5_normal
322	atf_add_test_case raid5_compfail
323}
324