Home | History | Annotate | Line # | Download | only in raidframe
t_raid.sh revision 1.9
      1 #! /usr/bin/atf-sh
      2 #	$NetBSD: t_raid.sh,v 1.9 2011/07/29 19:57:38 oster 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 
     29 rawpart=`sysctl -n kern.rawpartition | tr '01234' 'abcde'`
     30 rawraid=/dev/rraid0${rawpart}
     31 raidserver="rump_server -lrumpvfs -lrumpdev -lrumpdev_disk -lrumpdev_raidframe"
     32 
     33 makecfg()
     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 
     49 atf_test_case smalldisk cleanup
     50 smalldisk_head()
     51 {
     52 	atf_set "descr" "Checks the raidframe works on small disks " \
     53 	    "(PR kern/44239)"
     54 }
     55 
     56 smalldisk_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 
     68 smalldisk_cleanup()
     69 {
     70 	export RUMP_SERVER=unix://sock
     71 	rump.halt
     72 }
     73 
     74 
     75 # make this smaller once 44239 is fixed
     76 export RAID_MEDIASIZE=32m
     77 
     78 atf_test_case raid1_compfail cleanup
     79 raid1_compfail_head()
     80 {
     81 	atf_set "descr" "Checks that RAID1 works after component failure"
     82 }
     83 
     84 raid1_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 
    118 raid1_compfail_cleanup()
    119 {
    120 	export RUMP_SERVER=unix://sock
    121 	rump.halt
    122 }
    123 
    124 
    125 
    126 atf_test_case raid1_comp0fail cleanup
    127 raid1_comp0fail_head()
    128 {
    129 	atf_set "descr" "Checks configuring RAID1 after component 0 fails" \
    130 		"(PR kern/44251)"
    131 }
    132 
    133 raid1_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 
    157 raid1_comp0fail_cleanup()
    158 {
    159 	export RUMP_SERVER=unix://sock
    160 	rump.halt
    161 }
    162 
    163 atf_test_case raid1_normal cleanup
    164 raid1_normal_head()
    165 {
    166 	atf_set "descr" "Checks that RAID1 -c configurations work " \
    167 		"in the normal case"
    168 }
    169 
    170 raid1_normal_body()
    171 {
    172 	makecfg 1 2
    173         atf_check -s exit:0 ${raidserver}                               \
    174             -d key=/disk0,hostpath=disk0.img,size=${RAID_MEDIASIZE}     \
    175             -d key=/disk1,hostpath=disk1.img,size=${RAID_MEDIASIZE}     \
    176             ${RUMP_SERVER}
    177 
    178         atf_check -s exit:0 rump.raidctl -C raid.conf raid0
    179         atf_check -s exit:0 rump.raidctl -I 12345 raid0
    180         atf_check -s exit:0 -o ignore rump.raidctl -iv raid0
    181 
    182         # put some data there
    183         atf_check -s exit:0 -e ignore \
    184             dd if=$(atf_get_srcdir)/t_raid of=testfile count=4
    185         atf_check -s exit:0 -e ignore -x \
    186             "dd if=testfile | rump.dd of=${rawraid} conv=sync"
    187 
    188         # restart server, disks remain normal 
    189         rump.halt
    190 
    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         # check if we we get what we wrote
    199         atf_check -s exit:0 -o file:testfile -e ignore \
    200             rump.dd if=${rawraid} count=4
    201 
    202 }
    203 
    204 raid1_comp0fail_cleanup()
    205 {       
    206         export RUMP_SERVER=unix://sock
    207         rump.halt
    208 }
    209 
    210 
    211 atf_test_case raid5_compfail cleanup
    212 raid5_compfail_head()
    213 {
    214 	atf_set "descr" "Checks that RAID5 works after component failure"
    215 }
    216 
    217 raid5_compfail_body()
    218 {
    219 	makecfg 5 3
    220 	export RUMP_SERVER=unix://sock
    221 	atf_check -s exit:0 ${raidserver}				\
    222 	    -d key=/disk0,hostpath=disk0.img,size=${RAID_MEDIASIZE}	\
    223 	    -d key=/disk1,hostpath=disk1.img,size=${RAID_MEDIASIZE}	\
    224 	    -d key=/disk2,hostpath=disk2.img,size=${RAID_MEDIASIZE}	\
    225 	    ${RUMP_SERVER}
    226 
    227 	atf_check -s exit:0 rump.raidctl -C raid.conf raid0
    228 	atf_check -s exit:0 rump.raidctl -I 12345 raid0
    229 	atf_check -s exit:0 -o ignore rump.raidctl -iv raid0
    230 
    231 	# put some data there
    232 	atf_check -s exit:0 -e ignore \
    233 	    dd if=$(atf_get_srcdir)/t_raid of=testfile count=4
    234 	atf_check -s exit:0 -e ignore -x \
    235 	    "dd if=testfile | rump.dd of=${rawraid} conv=sync"
    236 
    237 	# restart server with failed component
    238 	rump.halt
    239 	rm disk2.img # FAIL
    240 	atf_check -s exit:0 ${raidserver}				\
    241 	    -d key=/disk0,hostpath=disk0.img,size=${RAID_MEDIASIZE}	\
    242 	    -d key=/disk1,hostpath=disk1.img,size=${RAID_MEDIASIZE}	\
    243 	    -d key=/disk2,hostpath=disk2.img,size=${RAID_MEDIASIZE}	\
    244 	    ${RUMP_SERVER}
    245 
    246 	atf_check -s exit:0 rump.raidctl -c raid.conf raid0
    247 
    248 	# check if we we get what we wrote
    249 	atf_check -s exit:0 -o file:testfile -e ignore \
    250 	    rump.dd if=${rawraid} count=4
    251 }
    252 
    253 raid5_compfail_cleanup()
    254 {
    255 	export RUMP_SERVER=unix://sock
    256 	rump.halt
    257 }
    258 
    259 atf_test_case raid5_normal cleanup
    260 raid5_normal_head()
    261 {
    262         atf_set "descr" "Checks that RAID5 works after normal shutdown " \
    263 		"and 'raidctl -c' startup"
    264 }
    265 
    266 raid5_normal_body()
    267 {
    268         makecfg 5 3
    269         export RUMP_SERVER=unix://sock
    270         atf_check -s exit:0 ${raidserver}                               \
    271             -d key=/disk0,hostpath=disk0.img,size=${RAID_MEDIASIZE}     \
    272             -d key=/disk1,hostpath=disk1.img,size=${RAID_MEDIASIZE}     \
    273             -d key=/disk2,hostpath=disk2.img,size=${RAID_MEDIASIZE}     \
    274             ${RUMP_SERVER}
    275 
    276         atf_check -s exit:0 rump.raidctl -C raid.conf raid0
    277         atf_check -s exit:0 rump.raidctl -I 12345 raid0
    278         atf_check -s exit:0 -o ignore rump.raidctl -iv raid0
    279 
    280         # put some data there
    281         atf_check -s exit:0 -e ignore \
    282             dd if=$(atf_get_srcdir)/t_raid of=testfile count=4
    283         atf_check -s exit:0 -e ignore -x \
    284             "dd if=testfile | rump.dd of=${rawraid} conv=sync"
    285 
    286         # restart server after normal shutdown
    287         rump.halt
    288 
    289         atf_check -s exit:0 ${raidserver}                               \
    290             -d key=/disk0,hostpath=disk0.img,size=${RAID_MEDIASIZE}     \
    291             -d key=/disk1,hostpath=disk1.img,size=${RAID_MEDIASIZE}     \
    292             -d key=/disk2,hostpath=disk2.img,size=${RAID_MEDIASIZE}     \
    293             ${RUMP_SERVER}
    294 
    295         atf_check -s exit:0 rump.raidctl -c raid.conf raid0
    296 
    297         # check if we we get what we wrote
    298         atf_check -s exit:0 -o file:testfile -e ignore \
    299             rump.dd if=${rawraid} count=4
    300 }
    301 
    302 raid5_normal_cleanup()
    303 {
    304         export RUMP_SERVER=unix://sock
    305         rump.halt
    306 }
    307 
    308 atf_init_test_cases()
    309 {
    310 	atf_add_test_case smalldisk
    311 	atf_add_test_case raid1_normal
    312 	atf_add_test_case raid1_comp0fail
    313 	atf_add_test_case raid1_compfail
    314 	atf_add_test_case raid5_normal
    315 	atf_add_test_case raid5_compfail
    316 }
    317