xref: /netbsd-src/tests/dev/raidframe/t_raid.sh (revision 181254a7b1bdde6873432bffef2d2decc4b5c22f)
1#! /usr/bin/atf-sh
2#	$NetBSD: t_raid.sh,v 1.14 2019/07/10 06:10:54 martin 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\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
49makecfg_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
65atf_test_case smalldisk cleanup
66smalldisk_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
73smalldisk_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
84smalldisk_body()
85{
86	makecfg 1 2
87	smalldisk_body_backend
88}
89
90smalldisk_cleanup()
91{
92	export RUMP_SERVER=unix://sock
93	rump.halt
94}
95
96# The old configuration test case uses the smalldisk backend
97atf_test_case old_numrows_config cleanup
98old_numrows_config_head()
99{
100	atf_set "descr" "Checks the old numRows configuration works"
101	atf_set "require.progs" "rump_server"
102}
103
104old_numrows_config_body()
105{
106	makecfg_old 1 2
107	smalldisk_body_backend
108}
109
110old_numrows_config_cleanup()
111{
112	export RUMP_SERVER=unix://sock
113	rump.halt
114}
115
116export RAID_MEDIASIZE=4m
117
118atf_test_case raid1_compfail cleanup
119raid1_compfail_head()
120{
121	atf_set "descr" "Checks that RAID1 works after component failure"
122	atf_set "require.progs" "rump_server"
123}
124
125raid1_compfail_body()
126{
127	makecfg 1 2
128	export RUMP_SERVER=unix://sock
129	atf_check -s exit:0 ${raidserver}				\
130	    -d key=/disk0,hostpath=disk0.img,size=${RAID_MEDIASIZE}	\
131	    -d key=/disk1,hostpath=disk1.img,size=${RAID_MEDIASIZE}	\
132	    ${RUMP_SERVER}
133
134	atf_check -s exit:0 rump.raidctl -C raid.conf raid0
135	atf_check -s exit:0 rump.raidctl -I 12345 raid0
136	atf_check -s exit:0 -o ignore rump.raidctl -iv raid0
137
138	# put some data there
139	atf_check -s exit:0 -e ignore \
140	    dd if=$(atf_get_srcdir)/t_raid of=testfile count=4
141	atf_check -s exit:0 -e ignore -x \
142	    "dd if=testfile | rump.dd of=${rawraid} conv=sync"
143
144	# restart server with failed component
145	rump.halt
146	rm disk1.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_check -s exit:0 rump.raidctl -c raid.conf raid0
153
154	# check if we we get what we wrote
155	atf_check -s exit:0 -o file:testfile -e ignore \
156	    rump.dd if=${rawraid} count=4
157}
158
159raid1_compfail_cleanup()
160{
161	export RUMP_SERVER=unix://sock
162	rump.halt
163}
164
165
166
167atf_test_case raid1_comp0fail cleanup
168raid1_comp0fail_head()
169{
170	atf_set "descr" "Checks configuring RAID1 after component 0 fails" \
171		"(PR kern/44251)"
172	atf_set "require.progs" "rump_server"
173}
174
175raid1_comp0fail_body()
176{
177	makecfg 1 2
178	export RUMP_SERVER=unix://sock
179	atf_check -s exit:0 ${raidserver}				\
180	    -d key=/disk0,hostpath=disk0.img,size=${RAID_MEDIASIZE}	\
181	    -d key=/disk1,hostpath=disk1.img,size=${RAID_MEDIASIZE}	\
182	    ${RUMP_SERVER}
183
184	atf_check -s exit:0 rump.raidctl -C raid.conf raid0
185	atf_check -s exit:0 rump.raidctl -I 12345 raid0
186	atf_check -s exit:0 -o ignore rump.raidctl -iv raid0
187
188	# restart server with failed component
189	rump.halt
190	rm disk0.img # FAIL
191	atf_check -s exit:0 ${raidserver} 				\
192	    -d key=/disk0,hostpath=disk0.img,size=${RAID_MEDIASIZE}	\
193	    -d key=/disk1,hostpath=disk1.img,size=${RAID_MEDIASIZE}	\
194	    ${RUMP_SERVER}
195
196	atf_check -s exit:0 rump.raidctl -c raid.conf raid0
197}
198
199raid1_comp0fail_cleanup()
200{
201	export RUMP_SERVER=unix://sock
202	rump.halt
203}
204
205atf_test_case raid1_normal cleanup
206raid1_normal_head()
207{
208	atf_set "descr" "Checks that RAID1 -c configurations work " \
209		"in the normal case"
210	atf_set "require.progs" "rump_server"
211}
212
213raid1_normal_body()
214{
215	makecfg 1 2
216	export RUMP_SERVER=unix://sock
217        atf_check -s exit:0 ${raidserver}                               \
218            -d key=/disk0,hostpath=disk0.img,size=${RAID_MEDIASIZE}     \
219            -d key=/disk1,hostpath=disk1.img,size=${RAID_MEDIASIZE}     \
220            ${RUMP_SERVER}
221
222        atf_check -s exit:0 rump.raidctl -C raid.conf raid0
223        atf_check -s exit:0 rump.raidctl -I 12345 raid0
224        atf_check -s exit:0 -o ignore rump.raidctl -iv raid0
225
226        # put some data there
227        atf_check -s exit:0 -e ignore \
228            dd if=$(atf_get_srcdir)/t_raid of=testfile count=4
229        atf_check -s exit:0 -e ignore -x \
230            "dd if=testfile | rump.dd of=${rawraid} conv=sync"
231
232        # restart server, disks remain normal
233        rump.halt
234
235        atf_check -s exit:0 ${raidserver}                               \
236            -d key=/disk0,hostpath=disk0.img,size=${RAID_MEDIASIZE}     \
237            -d key=/disk1,hostpath=disk1.img,size=${RAID_MEDIASIZE}     \
238            ${RUMP_SERVER}
239
240        atf_check -s exit:0 rump.raidctl -c raid.conf raid0
241
242        # check if we we get what we wrote
243        atf_check -s exit:0 -o file:testfile -e ignore \
244            rump.dd if=${rawraid} count=4
245
246}
247
248raid1_normal_cleanup()
249{
250        export RUMP_SERVER=unix://sock
251        rump.halt
252}
253
254
255atf_test_case raid5_compfail cleanup
256raid5_compfail_head()
257{
258	atf_set "descr" "Checks that RAID5 works after component failure"
259	atf_set "require.progs" "rump_server"
260}
261
262raid5_compfail_body()
263{
264	makecfg 5 3
265	export RUMP_SERVER=unix://sock
266	atf_check -s exit:0 ${raidserver}				\
267	    -d key=/disk0,hostpath=disk0.img,size=${RAID_MEDIASIZE}	\
268	    -d key=/disk1,hostpath=disk1.img,size=${RAID_MEDIASIZE}	\
269	    -d key=/disk2,hostpath=disk2.img,size=${RAID_MEDIASIZE}	\
270	    ${RUMP_SERVER}
271
272	atf_check -s exit:0 rump.raidctl -C raid.conf raid0
273	atf_check -s exit:0 rump.raidctl -I 12345 raid0
274	atf_check -s exit:0 -o ignore rump.raidctl -iv raid0
275
276	# put some data there
277	atf_check -s exit:0 -e ignore \
278	    dd if=$(atf_get_srcdir)/t_raid of=testfile count=4
279	atf_check -s exit:0 -e ignore -x \
280	    "dd if=testfile | rump.dd of=${rawraid} conv=sync"
281
282	# restart server with failed component
283	rump.halt
284	rm disk2.img # FAIL
285	atf_check -s exit:0 ${raidserver}				\
286	    -d key=/disk0,hostpath=disk0.img,size=${RAID_MEDIASIZE}	\
287	    -d key=/disk1,hostpath=disk1.img,size=${RAID_MEDIASIZE}	\
288	    -d key=/disk2,hostpath=disk2.img,size=${RAID_MEDIASIZE}	\
289	    ${RUMP_SERVER}
290
291	atf_check -s exit:0 rump.raidctl -c raid.conf raid0
292
293	# check if we we get what we wrote
294	atf_check -s exit:0 -o file:testfile -e ignore \
295	    rump.dd if=${rawraid} count=4
296}
297
298raid5_compfail_cleanup()
299{
300	export RUMP_SERVER=unix://sock
301	rump.halt
302}
303
304atf_test_case raid5_normal cleanup
305raid5_normal_head()
306{
307        atf_set "descr" "Checks that RAID5 works after normal shutdown " \
308		"and 'raidctl -c' startup"
309	atf_set "require.progs" "rump_server"
310}
311
312raid5_normal_body()
313{
314        makecfg 5 3
315        export RUMP_SERVER=unix://sock
316        atf_check -s exit:0 ${raidserver}                               \
317            -d key=/disk0,hostpath=disk0.img,size=${RAID_MEDIASIZE}     \
318            -d key=/disk1,hostpath=disk1.img,size=${RAID_MEDIASIZE}     \
319            -d key=/disk2,hostpath=disk2.img,size=${RAID_MEDIASIZE}     \
320            ${RUMP_SERVER}
321
322        atf_check -s exit:0 rump.raidctl -C raid.conf raid0
323        atf_check -s exit:0 rump.raidctl -I 12345 raid0
324        atf_check -s exit:0 -o ignore rump.raidctl -iv raid0
325
326        # put some data there
327        atf_check -s exit:0 -e ignore \
328            dd if=$(atf_get_srcdir)/t_raid of=testfile count=4
329        atf_check -s exit:0 -e ignore -x \
330            "dd if=testfile | rump.dd of=${rawraid} conv=sync"
331
332        # restart server after normal shutdown
333        rump.halt
334
335        atf_check -s exit:0 ${raidserver}                               \
336            -d key=/disk0,hostpath=disk0.img,size=${RAID_MEDIASIZE}     \
337            -d key=/disk1,hostpath=disk1.img,size=${RAID_MEDIASIZE}     \
338            -d key=/disk2,hostpath=disk2.img,size=${RAID_MEDIASIZE}     \
339            ${RUMP_SERVER}
340
341        atf_check -s exit:0 rump.raidctl -c raid.conf raid0
342
343        # check if we we get what we wrote
344        atf_check -s exit:0 -o file:testfile -e ignore \
345            rump.dd if=${rawraid} count=4
346}
347
348raid5_normal_cleanup()
349{
350        export RUMP_SERVER=unix://sock
351        rump.halt
352}
353
354atf_init_test_cases()
355{
356	atf_add_test_case smalldisk
357	atf_add_test_case old_numrows_config
358	atf_add_test_case raid1_normal
359	atf_add_test_case raid1_comp0fail
360	atf_add_test_case raid1_compfail
361	atf_add_test_case raid5_normal
362	atf_add_test_case raid5_compfail
363}
364