1# $NetBSD: t_raid.sh,v 1.6 2011/02/04 19:44:00 pooka Exp $ 2# 3# Copyright (c) 2010 The NetBSD Foundation, Inc. 4# All rights reserved. 5# 6# Redistribution and use in source and binary forms, with or without 7# modification, are permitted provided that the following conditions 8# are met: 9# 1. Redistributions of source code must retain the above copyright 10# notice, this list of conditions and the following disclaimer. 11# 2. Redistributions in binary form must reproduce the above copyright 12# notice, this list of conditions and the following disclaimer in the 13# documentation and/or other materials provided with the distribution. 14# 15# THIS SOFTWARE IS PROVIDED BY THE NETBSD FOUNDATION, INC. AND CONTRIBUTORS 16# ``AS IS'' AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED 17# TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR 18# PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE FOUNDATION OR CONTRIBUTORS 19# BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR 20# CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF 21# SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS 22# INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN 23# CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) 24# ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE 25# POSSIBILITY OF SUCH DAMAGE. 26# 27 28rawpart=`sysctl -n kern.rawpartition | tr '01234' 'abcde'` 29rawraid=/dev/rraid0${rawpart} 30raidserver="rump_server -lrumpvfs -lrumpdev -lrumpdev_disk -lrumpdev_raidframe" 31 32makecfg() 33{ 34 level=${1} 35 ncol=${2} 36 37 printf "START array\n1 ${ncol} 0\nSTART disks\n" > raid.conf 38 diskn=0 39 while [ ${ncol} -gt ${diskn} ] ; do 40 echo "/disk${diskn}" >> raid.conf 41 diskn=$((diskn+1)) 42 done 43 44 printf "START layout\n32 1 1 ${level}\nSTART queue\nfifo 100\n" \ 45 >> raid.conf 46} 47 48atf_test_case smalldisk cleanup 49smalldisk_head() 50{ 51 atf_set "descr" "Checks the raidframe works on small disks " \ 52 "(PR kern/44239)" 53} 54 55smalldisk_body() 56{ 57 makecfg 1 2 58 export RUMP_SERVER=unix://sock 59 atf_check -s exit:0 ${raidserver} \ 60 -d key=/disk0,hostpath=disk0.img,size=1m \ 61 -d key=/disk1,hostpath=disk1.img,size=1m \ 62 ${RUMP_SERVER} 63 64 atf_expect_fail "PR kern/44239" # ADJUST CLEANUP WHEN THIS IS FIXED! 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 : server dumps currently, so reset error. remove this line when fixed 73} 74 75 76# make this smaller once 44239 is fixed 77export RAID_MEDIASIZE=32m 78 79atf_test_case raid1_compfail cleanup 80raid1_compfail_head() 81{ 82 atf_set "descr" "Checks that RAID1 works after component failure" 83} 84 85raid1_compfail_body() 86{ 87 makecfg 1 2 88 export RUMP_SERVER=unix://sock 89 atf_check -s exit:0 ${raidserver} \ 90 -d key=/disk0,hostpath=disk0.img,size=${RAID_MEDIASIZE} \ 91 -d key=/disk1,hostpath=disk1.img,size=${RAID_MEDIASIZE} \ 92 ${RUMP_SERVER} 93 94 atf_check -s exit:0 rump.raidctl -C raid.conf raid0 95 atf_check -s exit:0 rump.raidctl -I 12345 raid0 96 atf_check -s exit:0 -o ignore rump.raidctl -iv raid0 97 98 # put some data there 99 atf_check -s exit:0 -e ignore \ 100 dd if=$(atf_get_srcdir)/t_raid of=testfile count=4 101 atf_check -s exit:0 -e ignore sh -c \ 102 "dd if=testfile | rump.dd of=${rawraid} conv=sync" 103 104 # restart server with failed component 105 rump.halt 106 rm disk1.img # FAIL 107 atf_check -s exit:0 ${raidserver} \ 108 -d key=/disk0,hostpath=disk0.img,size=${RAID_MEDIASIZE} \ 109 -d key=/disk1,hostpath=disk1.img,size=${RAID_MEDIASIZE} \ 110 ${RUMP_SERVER} 111 112 atf_check -s exit:0 rump.raidctl -c raid.conf raid0 113 114 # check if we we get what we wrote 115 atf_check -s exit:0 -o file:testfile -e ignore \ 116 rump.dd if=${rawraid} count=4 117} 118 119raid1_compfail_cleanup() 120{ 121 export RUMP_SERVER=unix://sock 122 rump.halt 123} 124 125 126 127atf_test_case raid1_comp0fail cleanup 128raid1_comp0fail_head() 129{ 130 atf_set "descr" "Checks configuring RAID1 after component 0 fails" 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_expect_fail "PR kern/44251" 155 atf_check -s exit:0 rump.raidctl -c raid.conf raid0 156} 157 158raid1_comp0fail_cleanup() 159{ 160 export RUMP_SERVER=unix://sock 161 rump.halt 162} 163 164 165atf_test_case raid5_compfail cleanup 166raid5_compfail_head() 167{ 168 atf_set "descr" "Checks that RAID5 works after component failure" 169} 170 171raid5_compfail_body() 172{ 173 makecfg 5 3 174 export RUMP_SERVER=unix://sock 175 atf_check -s exit:0 ${raidserver} \ 176 -d key=/disk0,hostpath=disk0.img,size=${RAID_MEDIASIZE} \ 177 -d key=/disk1,hostpath=disk1.img,size=${RAID_MEDIASIZE} \ 178 -d key=/disk2,hostpath=disk2.img,size=${RAID_MEDIASIZE} \ 179 ${RUMP_SERVER} 180 181 atf_check -s exit:0 rump.raidctl -C raid.conf raid0 182 atf_check -s exit:0 rump.raidctl -I 12345 raid0 183 atf_check -s exit:0 -o ignore rump.raidctl -iv raid0 184 185 # put some data there 186 atf_check -s exit:0 -e ignore \ 187 dd if=$(atf_get_srcdir)/t_raid of=testfile count=4 188 atf_check -s exit:0 -e ignore sh -c \ 189 "dd if=testfile | rump.dd of=${rawraid} conv=sync" 190 191 # restart server with failed component 192 rump.halt 193 rm disk2.img # FAIL 194 atf_check -s exit:0 ${raidserver} \ 195 -d key=/disk0,hostpath=disk0.img,size=${RAID_MEDIASIZE} \ 196 -d key=/disk1,hostpath=disk1.img,size=${RAID_MEDIASIZE} \ 197 -d key=/disk2,hostpath=disk2.img,size=${RAID_MEDIASIZE} \ 198 ${RUMP_SERVER} 199 200 atf_check -s exit:0 rump.raidctl -c raid.conf raid0 201 202 # check if we we get what we wrote 203 atf_check -s exit:0 -o file:testfile -e ignore \ 204 rump.dd if=${rawraid} count=4 205} 206 207raid5_compfail_cleanup() 208{ 209 export RUMP_SERVER=unix://sock 210 rump.halt 211} 212 213 214atf_init_test_cases() 215{ 216 atf_add_test_case smalldisk 217 atf_add_test_case raid1_comp0fail 218 atf_add_test_case raid1_compfail 219 atf_add_test_case raid5_compfail 220} 221