summaryrefslogtreecommitdiffstats
path: root/contrib/netbsd-tests/dev/raidframe/t_raid.sh
blob: ae21eedf5e340f562df24ac02b967a06ce717ed0 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
#! /usr/bin/atf-sh
#	$NetBSD: t_raid.sh,v 1.12 2013/02/19 21:08:24 joerg Exp $
#
# Copyright (c) 2010 The NetBSD Foundation, Inc.
# All rights reserved.
#
# Redistribution and use in source and binary forms, with or without
# modification, are permitted provided that the following conditions
# are met:
# 1. Redistributions of source code must retain the above copyright
#    notice, this list of conditions and the following disclaimer.
# 2. Redistributions in binary form must reproduce the above copyright
#    notice, this list of conditions and the following disclaimer in the
#    documentation and/or other materials provided with the distribution.
#
# THIS SOFTWARE IS PROVIDED BY THE NETBSD FOUNDATION, INC. AND CONTRIBUTORS
# ``AS IS'' AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED
# TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
# PURPOSE ARE DISCLAIMED.  IN NO EVENT SHALL THE FOUNDATION OR CONTRIBUTORS
# BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
# CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
# SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
# INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
# CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
# ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
# POSSIBILITY OF SUCH DAMAGE.
#

rawpart=`sysctl -n kern.rawpartition | tr '01234' 'abcde'`
rawraid=/dev/rraid0${rawpart}
raidserver="rump_server -lrumpvfs -lrumpdev -lrumpdev_disk -lrumpdev_raidframe"

makecfg()
{
	level=${1}
	ncol=${2}

	printf "START array\n1 ${ncol} 0\nSTART disks\n" > raid.conf
	diskn=0
	while [ ${ncol} -gt ${diskn} ] ; do
		echo "/disk${diskn}" >> raid.conf
		diskn=$((diskn+1))
	done

	printf "START layout\n32 1 1 ${level}\nSTART queue\nfifo 100\n" \
	    >> raid.conf
}

atf_test_case smalldisk cleanup
smalldisk_head()
{
	atf_set "descr" "Checks the raidframe works on small disks " \
	    "(PR kern/44239)"
	atf_set "require.progs" "rump_server"
}

smalldisk_body()
{
	makecfg 1 2
	export RUMP_SERVER=unix://sock
	atf_check -s exit:0 ${raidserver}			\
	    -d key=/disk0,hostpath=disk0.img,size=1m		\
	    -d key=/disk1,hostpath=disk1.img,size=1m		\
	    ${RUMP_SERVER}

	atf_check -s exit:0 rump.raidctl -C raid.conf raid0
}

smalldisk_cleanup()
{
	export RUMP_SERVER=unix://sock
	rump.halt
}


# make this smaller once 44239 is fixed
export RAID_MEDIASIZE=32m

atf_test_case raid1_compfail cleanup
raid1_compfail_head()
{
	atf_set "descr" "Checks that RAID1 works after component failure"
	atf_set "require.progs" "rump_server"
}

raid1_compfail_body()
{
	makecfg 1 2
	export RUMP_SERVER=unix://sock
	atf_check -s exit:0 ${raidserver}				\
	    -d key=/disk0,hostpath=disk0.img,size=${RAID_MEDIASIZE}	\
	    -d key=/disk1,hostpath=disk1.img,size=${RAID_MEDIASIZE}	\
	    ${RUMP_SERVER}

	atf_check -s exit:0 rump.raidctl -C raid.conf raid0
	atf_check -s exit:0 rump.raidctl -I 12345 raid0
	atf_check -s exit:0 -o ignore rump.raidctl -iv raid0

	# put some data there
	atf_check -s exit:0 -e ignore \
	    dd if=$(atf_get_srcdir)/t_raid of=testfile count=4
	atf_check -s exit:0 -e ignore -x \
	    "dd if=testfile | rump.dd of=${rawraid} conv=sync"

	# restart server with failed component
	rump.halt
	rm disk1.img # FAIL
	atf_check -s exit:0 ${raidserver}				\
	    -d key=/disk0,hostpath=disk0.img,size=${RAID_MEDIASIZE}	\
	    -d key=/disk1,hostpath=disk1.img,size=${RAID_MEDIASIZE}	\
	    ${RUMP_SERVER}

	atf_check -s exit:0 rump.raidctl -c raid.conf raid0

	# check if we we get what we wrote
	atf_check -s exit:0 -o file:testfile -e ignore \
	    rump.dd if=${rawraid} count=4
}

raid1_compfail_cleanup()
{
	export RUMP_SERVER=unix://sock
	rump.halt
}



atf_test_case raid1_comp0fail cleanup
raid1_comp0fail_head()
{
	atf_set "descr" "Checks configuring RAID1 after component 0 fails" \
		"(PR kern/44251)"
	atf_set "require.progs" "rump_server"
}

raid1_comp0fail_body()
{
	makecfg 1 2
	export RUMP_SERVER=unix://sock
	atf_check -s exit:0 ${raidserver}				\
	    -d key=/disk0,hostpath=disk0.img,size=${RAID_MEDIASIZE}	\
	    -d key=/disk1,hostpath=disk1.img,size=${RAID_MEDIASIZE}	\
	    ${RUMP_SERVER}

	atf_check -s exit:0 rump.raidctl -C raid.conf raid0
	atf_check -s exit:0 rump.raidctl -I 12345 raid0
	atf_check -s exit:0 -o ignore rump.raidctl -iv raid0

	# restart server with failed component
	rump.halt
	rm disk0.img # FAIL
	atf_check -s exit:0 ${raidserver} 				\
	    -d key=/disk0,hostpath=disk0.img,size=${RAID_MEDIASIZE}	\
	    -d key=/disk1,hostpath=disk1.img,size=${RAID_MEDIASIZE}	\
	    ${RUMP_SERVER}

	atf_check -s exit:0 rump.raidctl -c raid.conf raid0
}

raid1_comp0fail_cleanup()
{
	export RUMP_SERVER=unix://sock
	rump.halt
}

atf_test_case raid1_normal cleanup
raid1_normal_head()
{
	atf_set "descr" "Checks that RAID1 -c configurations work " \
		"in the normal case"
	atf_set "require.progs" "rump_server"
}

raid1_normal_body()
{
	makecfg 1 2
	export RUMP_SERVER=unix://sock
        atf_check -s exit:0 ${raidserver}                               \
            -d key=/disk0,hostpath=disk0.img,size=${RAID_MEDIASIZE}     \
            -d key=/disk1,hostpath=disk1.img,size=${RAID_MEDIASIZE}     \
            ${RUMP_SERVER}

        atf_check -s exit:0 rump.raidctl -C raid.conf raid0
        atf_check -s exit:0 rump.raidctl -I 12345 raid0
        atf_check -s exit:0 -o ignore rump.raidctl -iv raid0

        # put some data there
        atf_check -s exit:0 -e ignore \
            dd if=$(atf_get_srcdir)/t_raid of=testfile count=4
        atf_check -s exit:0 -e ignore -x \
            "dd if=testfile | rump.dd of=${rawraid} conv=sync"

        # restart server, disks remain normal 
        rump.halt

        atf_check -s exit:0 ${raidserver}                               \
            -d key=/disk0,hostpath=disk0.img,size=${RAID_MEDIASIZE}     \
            -d key=/disk1,hostpath=disk1.img,size=${RAID_MEDIASIZE}     \
            ${RUMP_SERVER}

        atf_check -s exit:0 rump.raidctl -c raid.conf raid0

        # check if we we get what we wrote
        atf_check -s exit:0 -o file:testfile -e ignore \
            rump.dd if=${rawraid} count=4

}

raid1_normal_cleanup()
{       
        export RUMP_SERVER=unix://sock
        rump.halt
}


atf_test_case raid5_compfail cleanup
raid5_compfail_head()
{
	atf_set "descr" "Checks that RAID5 works after component failure"
	atf_set "require.progs" "rump_server"
}

raid5_compfail_body()
{
	makecfg 5 3
	export RUMP_SERVER=unix://sock
	atf_check -s exit:0 ${raidserver}				\
	    -d key=/disk0,hostpath=disk0.img,size=${RAID_MEDIASIZE}	\
	    -d key=/disk1,hostpath=disk1.img,size=${RAID_MEDIASIZE}	\
	    -d key=/disk2,hostpath=disk2.img,size=${RAID_MEDIASIZE}	\
	    ${RUMP_SERVER}

	atf_check -s exit:0 rump.raidctl -C raid.conf raid0
	atf_check -s exit:0 rump.raidctl -I 12345 raid0
	atf_check -s exit:0 -o ignore rump.raidctl -iv raid0

	# put some data there
	atf_check -s exit:0 -e ignore \
	    dd if=$(atf_get_srcdir)/t_raid of=testfile count=4
	atf_check -s exit:0 -e ignore -x \
	    "dd if=testfile | rump.dd of=${rawraid} conv=sync"

	# restart server with failed component
	rump.halt
	rm disk2.img # FAIL
	atf_check -s exit:0 ${raidserver}				\
	    -d key=/disk0,hostpath=disk0.img,size=${RAID_MEDIASIZE}	\
	    -d key=/disk1,hostpath=disk1.img,size=${RAID_MEDIASIZE}	\
	    -d key=/disk2,hostpath=disk2.img,size=${RAID_MEDIASIZE}	\
	    ${RUMP_SERVER}

	atf_check -s exit:0 rump.raidctl -c raid.conf raid0

	# check if we we get what we wrote
	atf_check -s exit:0 -o file:testfile -e ignore \
	    rump.dd if=${rawraid} count=4
}

raid5_compfail_cleanup()
{
	export RUMP_SERVER=unix://sock
	rump.halt
}

atf_test_case raid5_normal cleanup
raid5_normal_head()
{
        atf_set "descr" "Checks that RAID5 works after normal shutdown " \
		"and 'raidctl -c' startup"
	atf_set "require.progs" "rump_server"
}

raid5_normal_body()
{
        makecfg 5 3
        export RUMP_SERVER=unix://sock
        atf_check -s exit:0 ${raidserver}                               \
            -d key=/disk0,hostpath=disk0.img,size=${RAID_MEDIASIZE}     \
            -d key=/disk1,hostpath=disk1.img,size=${RAID_MEDIASIZE}     \
            -d key=/disk2,hostpath=disk2.img,size=${RAID_MEDIASIZE}     \
            ${RUMP_SERVER}

        atf_check -s exit:0 rump.raidctl -C raid.conf raid0
        atf_check -s exit:0 rump.raidctl -I 12345 raid0
        atf_check -s exit:0 -o ignore rump.raidctl -iv raid0

        # put some data there
        atf_check -s exit:0 -e ignore \
            dd if=$(atf_get_srcdir)/t_raid of=testfile count=4
        atf_check -s exit:0 -e ignore -x \
            "dd if=testfile | rump.dd of=${rawraid} conv=sync"

        # restart server after normal shutdown
        rump.halt

        atf_check -s exit:0 ${raidserver}                               \
            -d key=/disk0,hostpath=disk0.img,size=${RAID_MEDIASIZE}     \
            -d key=/disk1,hostpath=disk1.img,size=${RAID_MEDIASIZE}     \
            -d key=/disk2,hostpath=disk2.img,size=${RAID_MEDIASIZE}     \
            ${RUMP_SERVER}

        atf_check -s exit:0 rump.raidctl -c raid.conf raid0

        # check if we we get what we wrote
        atf_check -s exit:0 -o file:testfile -e ignore \
            rump.dd if=${rawraid} count=4
}

raid5_normal_cleanup()
{
        export RUMP_SERVER=unix://sock
        rump.halt
}

atf_init_test_cases()
{
	atf_add_test_case smalldisk
	atf_add_test_case raid1_normal
	atf_add_test_case raid1_comp0fail
	atf_add_test_case raid1_compfail
	atf_add_test_case raid5_normal
	atf_add_test_case raid5_compfail
}
OpenPOWER on IntegriCloud