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