xref: /netbsd-src/tests/dev/raidframe/t_raid.sh (revision 8693f01d5f9719b6598b699b40b32ea0843c479d)
1bfb5c547Soster#! /usr/bin/atf-sh
2*8693f01dSmartin#	$NetBSD: t_raid.sh,v 1.16 2022/11/30 17:49:09 martin Exp $
3a918a746Spooka#
4a918a746Spooka# Copyright (c) 2010 The NetBSD Foundation, Inc.
5a918a746Spooka# All rights reserved.
6a918a746Spooka#
7a918a746Spooka# Redistribution and use in source and binary forms, with or without
8a918a746Spooka# modification, are permitted provided that the following conditions
9a918a746Spooka# are met:
10a918a746Spooka# 1. Redistributions of source code must retain the above copyright
11a918a746Spooka#    notice, this list of conditions and the following disclaimer.
12a918a746Spooka# 2. Redistributions in binary form must reproduce the above copyright
13a918a746Spooka#    notice, this list of conditions and the following disclaimer in the
14a918a746Spooka#    documentation and/or other materials provided with the distribution.
15a918a746Spooka#
16a918a746Spooka# THIS SOFTWARE IS PROVIDED BY THE NETBSD FOUNDATION, INC. AND CONTRIBUTORS
17a918a746Spooka# ``AS IS'' AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED
18a918a746Spooka# TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
19a918a746Spooka# PURPOSE ARE DISCLAIMED.  IN NO EVENT SHALL THE FOUNDATION OR CONTRIBUTORS
20a918a746Spooka# BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
21a918a746Spooka# CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
22a918a746Spooka# SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
23a918a746Spooka# INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
24a918a746Spooka# CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
25a918a746Spooka# ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
26a918a746Spooka# POSSIBILITY OF SUCH DAMAGE.
27a918a746Spooka#
28a918a746Spooka
29*8693f01dSmartinrawpart=$( set -- a b c d e f g h i j k l m n o p q r s t u v w x y z;
30*8693f01dSmartin	shift $( sysctl -n kern.rawpartition ); printf %s "$1" )
31eafb3db9Spookarawraid=/dev/rraid0${rawpart}
32bc1c80f7Spookaraidserver="rump_server -lrumpvfs -lrumpdev -lrumpdev_disk -lrumpdev_raidframe"
33eafb3db9Spooka
34a918a746Spookamakecfg()
35a918a746Spooka{
36a918a746Spooka	level=${1}
37a918a746Spooka	ncol=${2}
38a918a746Spooka
39f2b04ca0Smrg	printf "START array\n${ncol} 0\nSTART disks\n" > raid.conf
40f2b04ca0Smrg	diskn=0
41f2b04ca0Smrg	while [ ${ncol} -gt ${diskn} ] ; do
42f2b04ca0Smrg		echo "/disk${diskn}" >> raid.conf
43f2b04ca0Smrg		diskn=$((diskn+1))
44f2b04ca0Smrg	done
45f2b04ca0Smrg
46f2b04ca0Smrg	printf "START layout\n32 1 1 ${level}\nSTART queue\nfifo 100\n" \
47f2b04ca0Smrg	    >> raid.conf
48f2b04ca0Smrg}
49f2b04ca0Smrg
50f2b04ca0Smrgmakecfg_old()
51f2b04ca0Smrg{
52f2b04ca0Smrg	level=${1}
53f2b04ca0Smrg	ncol=${2}
54f2b04ca0Smrg
55a918a746Spooka	printf "START array\n1 ${ncol} 0\nSTART disks\n" > raid.conf
56a918a746Spooka	diskn=0
57a918a746Spooka	while [ ${ncol} -gt ${diskn} ] ; do
58a918a746Spooka		echo "/disk${diskn}" >> raid.conf
59a918a746Spooka		diskn=$((diskn+1))
60a918a746Spooka	done
61a918a746Spooka
62a918a746Spooka	printf "START layout\n32 1 1 ${level}\nSTART queue\nfifo 100\n" \
63a918a746Spooka	    >> raid.conf
64a918a746Spooka}
65a918a746Spooka
66a918a746Spookaatf_test_case smalldisk cleanup
6734fb222dSpookasmalldisk_head()
68a918a746Spooka{
69eafb3db9Spooka	atf_set "descr" "Checks the raidframe works on small disks " \
70eafb3db9Spooka	    "(PR kern/44239)"
7194bcefa4Sjoerg	atf_set "require.progs" "rump_server"
72a918a746Spooka}
73a918a746Spooka
74f2b04ca0Smrgsmalldisk_body_backend()
75a918a746Spooka{
76a918a746Spooka	export RUMP_SERVER=unix://sock
77bc1c80f7Spooka	atf_check -s exit:0 ${raidserver}			\
78a918a746Spooka	    -d key=/disk0,hostpath=disk0.img,size=1m		\
79a918a746Spooka	    -d key=/disk1,hostpath=disk1.img,size=1m		\
80a918a746Spooka	    ${RUMP_SERVER}
81a918a746Spooka
82a918a746Spooka	atf_check -s exit:0 rump.raidctl -C raid.conf raid0
83a918a746Spooka}
84a918a746Spooka
85f2b04ca0Smrgsmalldisk_body()
86f2b04ca0Smrg{
87f2b04ca0Smrg	makecfg 1 2
88f2b04ca0Smrg	smalldisk_body_backend
89f2b04ca0Smrg}
90f2b04ca0Smrg
91a918a746Spookasmalldisk_cleanup()
92a918a746Spooka{
93a918a746Spooka	export RUMP_SERVER=unix://sock
94a918a746Spooka	rump.halt
95a918a746Spooka}
96a918a746Spooka
97f2b04ca0Smrg# The old configuration test case uses the smalldisk backend
98f2b04ca0Smrgatf_test_case old_numrows_config cleanup
99f2b04ca0Smrgold_numrows_config_head()
100f2b04ca0Smrg{
101f2b04ca0Smrg	atf_set "descr" "Checks the old numRows configuration works"
102f2b04ca0Smrg	atf_set "require.progs" "rump_server"
103f2b04ca0Smrg}
104f2b04ca0Smrg
105f2b04ca0Smrgold_numrows_config_body()
106f2b04ca0Smrg{
107f2b04ca0Smrg	makecfg_old 1 2
108f2b04ca0Smrg	smalldisk_body_backend
109f2b04ca0Smrg}
110f2b04ca0Smrg
111f2b04ca0Smrgold_numrows_config_cleanup()
112f2b04ca0Smrg{
113f2b04ca0Smrg	export RUMP_SERVER=unix://sock
114f2b04ca0Smrg	rump.halt
115f2b04ca0Smrg}
1167e8af327Spooka
11733a5a5b2Smartinexport RAID_MEDIASIZE=4m
118eafb3db9Spooka
119eafb3db9Spookaatf_test_case raid1_compfail cleanup
120eafb3db9Spookaraid1_compfail_head()
121eafb3db9Spooka{
122eafb3db9Spooka	atf_set "descr" "Checks that RAID1 works after component failure"
12394bcefa4Sjoerg	atf_set "require.progs" "rump_server"
124eafb3db9Spooka}
125eafb3db9Spooka
126eafb3db9Spookaraid1_compfail_body()
127eafb3db9Spooka{
128eafb3db9Spooka	makecfg 1 2
129eafb3db9Spooka	export RUMP_SERVER=unix://sock
130bc1c80f7Spooka	atf_check -s exit:0 ${raidserver}				\
131eafb3db9Spooka	    -d key=/disk0,hostpath=disk0.img,size=${RAID_MEDIASIZE}	\
132eafb3db9Spooka	    -d key=/disk1,hostpath=disk1.img,size=${RAID_MEDIASIZE}	\
133eafb3db9Spooka	    ${RUMP_SERVER}
134eafb3db9Spooka
135eafb3db9Spooka	atf_check -s exit:0 rump.raidctl -C raid.conf raid0
136eafb3db9Spooka	atf_check -s exit:0 rump.raidctl -I 12345 raid0
137eafb3db9Spooka	atf_check -s exit:0 -o ignore rump.raidctl -iv raid0
138eafb3db9Spooka
139eafb3db9Spooka	# put some data there
140eafb3db9Spooka	atf_check -s exit:0 -e ignore \
141eafb3db9Spooka	    dd if=$(atf_get_srcdir)/t_raid of=testfile count=4
1429b4c1721Sjmmv	atf_check -s exit:0 -e ignore -x \
143bcbc2496Spooka	    "dd if=testfile | rump.dd of=${rawraid} conv=sync"
144eafb3db9Spooka
145eafb3db9Spooka	# restart server with failed component
146eafb3db9Spooka	rump.halt
147eafb3db9Spooka	rm disk1.img # FAIL
148bc1c80f7Spooka	atf_check -s exit:0 ${raidserver}				\
149eafb3db9Spooka	    -d key=/disk0,hostpath=disk0.img,size=${RAID_MEDIASIZE}	\
150eafb3db9Spooka	    -d key=/disk1,hostpath=disk1.img,size=${RAID_MEDIASIZE}	\
151eafb3db9Spooka	    ${RUMP_SERVER}
152eafb3db9Spooka
153eafb3db9Spooka	atf_check -s exit:0 rump.raidctl -c raid.conf raid0
154eafb3db9Spooka
15548b6679aSmsaitoh	# check if we get what we wrote
156bcbc2496Spooka	atf_check -s exit:0 -o file:testfile -e ignore \
157bcbc2496Spooka	    rump.dd if=${rawraid} count=4
158eafb3db9Spooka}
159eafb3db9Spooka
160eafb3db9Spookaraid1_compfail_cleanup()
161eafb3db9Spooka{
162eafb3db9Spooka	export RUMP_SERVER=unix://sock
163eafb3db9Spooka	rump.halt
164eafb3db9Spooka}
165eafb3db9Spooka
1667e8af327Spooka
1677e8af327Spooka
1687e8af327Spookaatf_test_case raid1_comp0fail cleanup
1697e8af327Spookaraid1_comp0fail_head()
1707e8af327Spooka{
171bfb5c547Soster	atf_set "descr" "Checks configuring RAID1 after component 0 fails" \
172bfb5c547Soster		"(PR kern/44251)"
17394bcefa4Sjoerg	atf_set "require.progs" "rump_server"
1747e8af327Spooka}
1757e8af327Spooka
1767e8af327Spookaraid1_comp0fail_body()
1777e8af327Spooka{
1787e8af327Spooka	makecfg 1 2
1797e8af327Spooka	export RUMP_SERVER=unix://sock
180bc1c80f7Spooka	atf_check -s exit:0 ${raidserver}				\
1817e8af327Spooka	    -d key=/disk0,hostpath=disk0.img,size=${RAID_MEDIASIZE}	\
1827e8af327Spooka	    -d key=/disk1,hostpath=disk1.img,size=${RAID_MEDIASIZE}	\
1837e8af327Spooka	    ${RUMP_SERVER}
1847e8af327Spooka
1857e8af327Spooka	atf_check -s exit:0 rump.raidctl -C raid.conf raid0
1867e8af327Spooka	atf_check -s exit:0 rump.raidctl -I 12345 raid0
1877e8af327Spooka	atf_check -s exit:0 -o ignore rump.raidctl -iv raid0
1887e8af327Spooka
1897e8af327Spooka	# restart server with failed component
1907e8af327Spooka	rump.halt
1917e8af327Spooka	rm disk0.img # FAIL
192bc1c80f7Spooka	atf_check -s exit:0 ${raidserver} 				\
1937e8af327Spooka	    -d key=/disk0,hostpath=disk0.img,size=${RAID_MEDIASIZE}	\
1947e8af327Spooka	    -d key=/disk1,hostpath=disk1.img,size=${RAID_MEDIASIZE}	\
1957e8af327Spooka	    ${RUMP_SERVER}
1967e8af327Spooka
1977e8af327Spooka	atf_check -s exit:0 rump.raidctl -c raid.conf raid0
1987e8af327Spooka}
1997e8af327Spooka
2007e8af327Spookaraid1_comp0fail_cleanup()
2017e8af327Spooka{
2027e8af327Spooka	export RUMP_SERVER=unix://sock
2037e8af327Spooka	rump.halt
2047e8af327Spooka}
2057e8af327Spooka
206bfb5c547Sosteratf_test_case raid1_normal cleanup
207bfb5c547Sosterraid1_normal_head()
208bfb5c547Soster{
209bfb5c547Soster	atf_set "descr" "Checks that RAID1 -c configurations work " \
210bfb5c547Soster		"in the normal case"
21194bcefa4Sjoerg	atf_set "require.progs" "rump_server"
212bfb5c547Soster}
213bfb5c547Soster
214bfb5c547Sosterraid1_normal_body()
215bfb5c547Soster{
216bfb5c547Soster	makecfg 1 2
2172e58500eSmartin	export RUMP_SERVER=unix://sock
218bfb5c547Soster        atf_check -s exit:0 ${raidserver}                               \
219bfb5c547Soster            -d key=/disk0,hostpath=disk0.img,size=${RAID_MEDIASIZE}     \
220bfb5c547Soster            -d key=/disk1,hostpath=disk1.img,size=${RAID_MEDIASIZE}     \
221bfb5c547Soster            ${RUMP_SERVER}
222bfb5c547Soster
223bfb5c547Soster        atf_check -s exit:0 rump.raidctl -C raid.conf raid0
224bfb5c547Soster        atf_check -s exit:0 rump.raidctl -I 12345 raid0
225bfb5c547Soster        atf_check -s exit:0 -o ignore rump.raidctl -iv raid0
226bfb5c547Soster
227bfb5c547Soster        # put some data there
228bfb5c547Soster        atf_check -s exit:0 -e ignore \
229bfb5c547Soster            dd if=$(atf_get_srcdir)/t_raid of=testfile count=4
230bfb5c547Soster        atf_check -s exit:0 -e ignore -x \
231bfb5c547Soster            "dd if=testfile | rump.dd of=${rawraid} conv=sync"
232bfb5c547Soster
233bfb5c547Soster        # restart server, disks remain normal
234bfb5c547Soster        rump.halt
235bfb5c547Soster
236bfb5c547Soster        atf_check -s exit:0 ${raidserver}                               \
237bfb5c547Soster            -d key=/disk0,hostpath=disk0.img,size=${RAID_MEDIASIZE}     \
238bfb5c547Soster            -d key=/disk1,hostpath=disk1.img,size=${RAID_MEDIASIZE}     \
239bfb5c547Soster            ${RUMP_SERVER}
240bfb5c547Soster
241bfb5c547Soster        atf_check -s exit:0 rump.raidctl -c raid.conf raid0
242bfb5c547Soster
24348b6679aSmsaitoh        # check if we get what we wrote
244bfb5c547Soster        atf_check -s exit:0 -o file:testfile -e ignore \
245bfb5c547Soster            rump.dd if=${rawraid} count=4
246bfb5c547Soster
247bfb5c547Soster}
248bfb5c547Soster
2494b516933Sgsonraid1_normal_cleanup()
250bfb5c547Soster{
251bfb5c547Soster        export RUMP_SERVER=unix://sock
252bfb5c547Soster        rump.halt
253bfb5c547Soster}
254bfb5c547Soster
2557e8af327Spooka
256eafb3db9Spookaatf_test_case raid5_compfail cleanup
257eafb3db9Spookaraid5_compfail_head()
258eafb3db9Spooka{
259eafb3db9Spooka	atf_set "descr" "Checks that RAID5 works after component failure"
26094bcefa4Sjoerg	atf_set "require.progs" "rump_server"
261eafb3db9Spooka}
262eafb3db9Spooka
263eafb3db9Spookaraid5_compfail_body()
264eafb3db9Spooka{
265eafb3db9Spooka	makecfg 5 3
266eafb3db9Spooka	export RUMP_SERVER=unix://sock
267bc1c80f7Spooka	atf_check -s exit:0 ${raidserver}				\
268eafb3db9Spooka	    -d key=/disk0,hostpath=disk0.img,size=${RAID_MEDIASIZE}	\
269eafb3db9Spooka	    -d key=/disk1,hostpath=disk1.img,size=${RAID_MEDIASIZE}	\
270eafb3db9Spooka	    -d key=/disk2,hostpath=disk2.img,size=${RAID_MEDIASIZE}	\
271eafb3db9Spooka	    ${RUMP_SERVER}
272eafb3db9Spooka
273eafb3db9Spooka	atf_check -s exit:0 rump.raidctl -C raid.conf raid0
274eafb3db9Spooka	atf_check -s exit:0 rump.raidctl -I 12345 raid0
275eafb3db9Spooka	atf_check -s exit:0 -o ignore rump.raidctl -iv raid0
276eafb3db9Spooka
277eafb3db9Spooka	# put some data there
278eafb3db9Spooka	atf_check -s exit:0 -e ignore \
279eafb3db9Spooka	    dd if=$(atf_get_srcdir)/t_raid of=testfile count=4
2809b4c1721Sjmmv	atf_check -s exit:0 -e ignore -x \
281bcbc2496Spooka	    "dd if=testfile | rump.dd of=${rawraid} conv=sync"
282eafb3db9Spooka
283eafb3db9Spooka	# restart server with failed component
284eafb3db9Spooka	rump.halt
285eafb3db9Spooka	rm disk2.img # FAIL
286bc1c80f7Spooka	atf_check -s exit:0 ${raidserver}				\
287eafb3db9Spooka	    -d key=/disk0,hostpath=disk0.img,size=${RAID_MEDIASIZE}	\
288eafb3db9Spooka	    -d key=/disk1,hostpath=disk1.img,size=${RAID_MEDIASIZE}	\
289eafb3db9Spooka	    -d key=/disk2,hostpath=disk2.img,size=${RAID_MEDIASIZE}	\
290eafb3db9Spooka	    ${RUMP_SERVER}
291eafb3db9Spooka
292eafb3db9Spooka	atf_check -s exit:0 rump.raidctl -c raid.conf raid0
293eafb3db9Spooka
29448b6679aSmsaitoh	# check if we get what we wrote
295bcbc2496Spooka	atf_check -s exit:0 -o file:testfile -e ignore \
296bcbc2496Spooka	    rump.dd if=${rawraid} count=4
297eafb3db9Spooka}
298eafb3db9Spooka
299eafb3db9Spookaraid5_compfail_cleanup()
300eafb3db9Spooka{
301eafb3db9Spooka	export RUMP_SERVER=unix://sock
302eafb3db9Spooka	rump.halt
303eafb3db9Spooka}
304eafb3db9Spooka
305bfb5c547Sosteratf_test_case raid5_normal cleanup
306bfb5c547Sosterraid5_normal_head()
307bfb5c547Soster{
308bfb5c547Soster        atf_set "descr" "Checks that RAID5 works after normal shutdown " \
309bfb5c547Soster		"and 'raidctl -c' startup"
31094bcefa4Sjoerg	atf_set "require.progs" "rump_server"
311bfb5c547Soster}
312bfb5c547Soster
313bfb5c547Sosterraid5_normal_body()
314bfb5c547Soster{
315bfb5c547Soster        makecfg 5 3
316bfb5c547Soster        export RUMP_SERVER=unix://sock
317bfb5c547Soster        atf_check -s exit:0 ${raidserver}                               \
318bfb5c547Soster            -d key=/disk0,hostpath=disk0.img,size=${RAID_MEDIASIZE}     \
319bfb5c547Soster            -d key=/disk1,hostpath=disk1.img,size=${RAID_MEDIASIZE}     \
320bfb5c547Soster            -d key=/disk2,hostpath=disk2.img,size=${RAID_MEDIASIZE}     \
321bfb5c547Soster            ${RUMP_SERVER}
322bfb5c547Soster
323bfb5c547Soster        atf_check -s exit:0 rump.raidctl -C raid.conf raid0
324bfb5c547Soster        atf_check -s exit:0 rump.raidctl -I 12345 raid0
325bfb5c547Soster        atf_check -s exit:0 -o ignore rump.raidctl -iv raid0
326bfb5c547Soster
327bfb5c547Soster        # put some data there
328bfb5c547Soster        atf_check -s exit:0 -e ignore \
329bfb5c547Soster            dd if=$(atf_get_srcdir)/t_raid of=testfile count=4
330bfb5c547Soster        atf_check -s exit:0 -e ignore -x \
331bfb5c547Soster            "dd if=testfile | rump.dd of=${rawraid} conv=sync"
332bfb5c547Soster
333bfb5c547Soster        # restart server after normal shutdown
334bfb5c547Soster        rump.halt
335bfb5c547Soster
336bfb5c547Soster        atf_check -s exit:0 ${raidserver}                               \
337bfb5c547Soster            -d key=/disk0,hostpath=disk0.img,size=${RAID_MEDIASIZE}     \
338bfb5c547Soster            -d key=/disk1,hostpath=disk1.img,size=${RAID_MEDIASIZE}     \
339bfb5c547Soster            -d key=/disk2,hostpath=disk2.img,size=${RAID_MEDIASIZE}     \
340bfb5c547Soster            ${RUMP_SERVER}
341bfb5c547Soster
342bfb5c547Soster        atf_check -s exit:0 rump.raidctl -c raid.conf raid0
343bfb5c547Soster
34448b6679aSmsaitoh        # check if we get what we wrote
345bfb5c547Soster        atf_check -s exit:0 -o file:testfile -e ignore \
346bfb5c547Soster            rump.dd if=${rawraid} count=4
347bfb5c547Soster}
348bfb5c547Soster
349bfb5c547Sosterraid5_normal_cleanup()
350bfb5c547Soster{
351bfb5c547Soster        export RUMP_SERVER=unix://sock
352bfb5c547Soster        rump.halt
353bfb5c547Soster}
3547e8af327Spooka
355a918a746Spookaatf_init_test_cases()
356a918a746Spooka{
357a918a746Spooka	atf_add_test_case smalldisk
358f2b04ca0Smrg	atf_add_test_case old_numrows_config
359bfb5c547Soster	atf_add_test_case raid1_normal
3607e8af327Spooka	atf_add_test_case raid1_comp0fail
361eafb3db9Spooka	atf_add_test_case raid1_compfail
362bfb5c547Soster	atf_add_test_case raid5_normal
363eafb3db9Spooka	atf_add_test_case raid5_compfail
364a918a746Spooka}
365