1# $NetBSD: t_raid.sh,v 1.3 2010/12/18 09:26:57 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} 30 31makecfg() 32{ 33 level=${1} 34 ncol=${2} 35 36 printf "START array\n1 ${ncol} 0\nSTART disks\n" > raid.conf 37 diskn=0 38 while [ ${ncol} -gt ${diskn} ] ; do 39 echo "/disk${diskn}" >> raid.conf 40 diskn=$((diskn+1)) 41 done 42 43 printf "START layout\n32 1 1 ${level}\nSTART queue\nfifo 100\n" \ 44 >> raid.conf 45} 46 47atf_test_case smalldisk cleanup 48smalldisk_head() 49{ 50 51 atf_set "descr" "Checks the raidframe works on small disks " \ 52 "(PR kern/44239)" 53} 54 55smalldisk_body() 56{ 57 58 makecfg 1 2 59 export RUMP_SERVER=unix://sock 60 atf_check -s exit:0 rump_allserver \ 61 -d key=/disk0,hostpath=disk0.img,size=1m \ 62 -d key=/disk1,hostpath=disk1.img,size=1m \ 63 ${RUMP_SERVER} 64 65 atf_expect_fail "PR kern/44239" # ADJUST CLEANUP WHEN THIS IS FIXED! 66 atf_check -s exit:0 rump.raidctl -C raid.conf raid0 67} 68 69smalldisk_cleanup() 70{ 71 72 export RUMP_SERVER=unix://sock 73 rump.halt 74 : server dumps currently, so reset error. remove this line when fixed 75} 76 77# make this smaller once 44239 is fixed 78export RAID_MEDIASIZE=32m 79 80atf_test_case raid1_compfail cleanup 81raid1_compfail_head() 82{ 83 84 atf_set "descr" "Checks that RAID1 works after component failure" 85} 86 87raid1_compfail_body() 88{ 89 90 makecfg 1 2 91 export RUMP_SERVER=unix://sock 92 atf_check -s exit:0 rump_allserver \ 93 -d key=/disk0,hostpath=disk0.img,size=${RAID_MEDIASIZE} \ 94 -d key=/disk1,hostpath=disk1.img,size=${RAID_MEDIASIZE} \ 95 ${RUMP_SERVER} 96 97 atf_check -s exit:0 rump.raidctl -C raid.conf raid0 98 atf_check -s exit:0 rump.raidctl -I 12345 raid0 99 atf_check -s exit:0 -o ignore rump.raidctl -iv raid0 100 101 # put some data there 102 atf_check -s exit:0 -e ignore \ 103 dd if=$(atf_get_srcdir)/t_raid of=testfile count=4 104 atf_check -s exit:0 -e ignore dd if=testfile rof=${rawraid} conv=sync 105 106 # restart server with failed component 107 rump.halt 108 rm disk1.img # FAIL 109 atf_check -s exit:0 rump_allserver \ 110 -d key=/disk0,hostpath=disk0.img,size=${RAID_MEDIASIZE} \ 111 -d key=/disk1,hostpath=disk1.img,size=${RAID_MEDIASIZE} \ 112 ${RUMP_SERVER} 113 114 atf_check -s exit:0 rump.raidctl -c raid.conf raid0 115 116 # check if we we get what we wrote 117 atf_check -s exit:0 -o file:testfile -e ignore dd rif=${rawraid} count=4 118} 119 120raid1_compfail_cleanup() 121{ 122 123 export RUMP_SERVER=unix://sock 124 rump.halt 125} 126 127atf_test_case raid5_compfail cleanup 128raid5_compfail_head() 129{ 130 131 atf_set "descr" "Checks that RAID5 works after component failure" 132} 133 134raid5_compfail_body() 135{ 136 137 makecfg 5 3 138 export RUMP_SERVER=unix://sock 139 atf_check -s exit:0 rump_allserver \ 140 -d key=/disk0,hostpath=disk0.img,size=${RAID_MEDIASIZE} \ 141 -d key=/disk1,hostpath=disk1.img,size=${RAID_MEDIASIZE} \ 142 -d key=/disk2,hostpath=disk2.img,size=${RAID_MEDIASIZE} \ 143 ${RUMP_SERVER} 144 145 atf_check -s exit:0 rump.raidctl -C raid.conf raid0 146 atf_check -s exit:0 rump.raidctl -I 12345 raid0 147 atf_check -s exit:0 -o ignore rump.raidctl -iv raid0 148 149 # put some data there 150 atf_check -s exit:0 -e ignore \ 151 dd if=$(atf_get_srcdir)/t_raid of=testfile count=4 152 atf_check -s exit:0 -e ignore dd if=testfile rof=${rawraid} conv=sync 153 154 # restart server with failed component 155 rump.halt 156 rm disk2.img # FAIL 157 atf_check -s exit:0 rump_allserver \ 158 -d key=/disk0,hostpath=disk0.img,size=${RAID_MEDIASIZE} \ 159 -d key=/disk1,hostpath=disk1.img,size=${RAID_MEDIASIZE} \ 160 -d key=/disk2,hostpath=disk2.img,size=${RAID_MEDIASIZE} \ 161 ${RUMP_SERVER} 162 163 atf_check -s exit:0 rump.raidctl -c raid.conf raid0 164 165 # check if we we get what we wrote 166 atf_check -s exit:0 -o file:testfile -e ignore dd rif=${rawraid} count=4 167} 168 169raid5_compfail_cleanup() 170{ 171 172 export RUMP_SERVER=unix://sock 173 rump.halt 174} 175 176atf_init_test_cases() 177{ 178 179 atf_add_test_case smalldisk 180 atf_add_test_case raid1_compfail 181 atf_add_test_case raid5_compfail 182} 183