1#! /usr/bin/atf-sh 2# $NetBSD: t_raid.sh,v 1.16 2022/11/30 17:49:09 martin 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 29rawpart=$( 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 shift $( sysctl -n kern.rawpartition ); printf %s "$1" ) 31rawraid=/dev/rraid0${rawpart} 32raidserver="rump_server -lrumpvfs -lrumpdev -lrumpdev_disk -lrumpdev_raidframe" 33 34makecfg() 35{ 36 level=${1} 37 ncol=${2} 38 39 printf "START array\n${ncol} 0\nSTART disks\n" > raid.conf 40 diskn=0 41 while [ ${ncol} -gt ${diskn} ] ; do 42 echo "/disk${diskn}" >> raid.conf 43 diskn=$((diskn+1)) 44 done 45 46 printf "START layout\n32 1 1 ${level}\nSTART queue\nfifo 100\n" \ 47 >> raid.conf 48} 49 50makecfg_old() 51{ 52 level=${1} 53 ncol=${2} 54 55 printf "START array\n1 ${ncol} 0\nSTART disks\n" > raid.conf 56 diskn=0 57 while [ ${ncol} -gt ${diskn} ] ; do 58 echo "/disk${diskn}" >> raid.conf 59 diskn=$((diskn+1)) 60 done 61 62 printf "START layout\n32 1 1 ${level}\nSTART queue\nfifo 100\n" \ 63 >> raid.conf 64} 65 66atf_test_case smalldisk cleanup 67smalldisk_head() 68{ 69 atf_set "descr" "Checks the raidframe works on small disks " \ 70 "(PR kern/44239)" 71 atf_set "require.progs" "rump_server" 72} 73 74smalldisk_body_backend() 75{ 76 export RUMP_SERVER=unix://sock 77 atf_check -s exit:0 ${raidserver} \ 78 -d key=/disk0,hostpath=disk0.img,size=1m \ 79 -d key=/disk1,hostpath=disk1.img,size=1m \ 80 ${RUMP_SERVER} 81 82 atf_check -s exit:0 rump.raidctl -C raid.conf raid0 83} 84 85smalldisk_body() 86{ 87 makecfg 1 2 88 smalldisk_body_backend 89} 90 91smalldisk_cleanup() 92{ 93 export RUMP_SERVER=unix://sock 94 rump.halt 95} 96 97# The old configuration test case uses the smalldisk backend 98atf_test_case old_numrows_config cleanup 99old_numrows_config_head() 100{ 101 atf_set "descr" "Checks the old numRows configuration works" 102 atf_set "require.progs" "rump_server" 103} 104 105old_numrows_config_body() 106{ 107 makecfg_old 1 2 108 smalldisk_body_backend 109} 110 111old_numrows_config_cleanup() 112{ 113 export RUMP_SERVER=unix://sock 114 rump.halt 115} 116 117export RAID_MEDIASIZE=4m 118 119atf_test_case raid1_compfail cleanup 120raid1_compfail_head() 121{ 122 atf_set "descr" "Checks that RAID1 works after component failure" 123 atf_set "require.progs" "rump_server" 124} 125 126raid1_compfail_body() 127{ 128 makecfg 1 2 129 export RUMP_SERVER=unix://sock 130 atf_check -s exit:0 ${raidserver} \ 131 -d key=/disk0,hostpath=disk0.img,size=${RAID_MEDIASIZE} \ 132 -d key=/disk1,hostpath=disk1.img,size=${RAID_MEDIASIZE} \ 133 ${RUMP_SERVER} 134 135 atf_check -s exit:0 rump.raidctl -C raid.conf raid0 136 atf_check -s exit:0 rump.raidctl -I 12345 raid0 137 atf_check -s exit:0 -o ignore rump.raidctl -iv raid0 138 139 # put some data there 140 atf_check -s exit:0 -e ignore \ 141 dd if=$(atf_get_srcdir)/t_raid of=testfile count=4 142 atf_check -s exit:0 -e ignore -x \ 143 "dd if=testfile | rump.dd of=${rawraid} conv=sync" 144 145 # restart server with failed component 146 rump.halt 147 rm disk1.img # FAIL 148 atf_check -s exit:0 ${raidserver} \ 149 -d key=/disk0,hostpath=disk0.img,size=${RAID_MEDIASIZE} \ 150 -d key=/disk1,hostpath=disk1.img,size=${RAID_MEDIASIZE} \ 151 ${RUMP_SERVER} 152 153 atf_check -s exit:0 rump.raidctl -c raid.conf raid0 154 155 # check if we get what we wrote 156 atf_check -s exit:0 -o file:testfile -e ignore \ 157 rump.dd if=${rawraid} count=4 158} 159 160raid1_compfail_cleanup() 161{ 162 export RUMP_SERVER=unix://sock 163 rump.halt 164} 165 166 167 168atf_test_case raid1_comp0fail cleanup 169raid1_comp0fail_head() 170{ 171 atf_set "descr" "Checks configuring RAID1 after component 0 fails" \ 172 "(PR kern/44251)" 173 atf_set "require.progs" "rump_server" 174} 175 176raid1_comp0fail_body() 177{ 178 makecfg 1 2 179 export RUMP_SERVER=unix://sock 180 atf_check -s exit:0 ${raidserver} \ 181 -d key=/disk0,hostpath=disk0.img,size=${RAID_MEDIASIZE} \ 182 -d key=/disk1,hostpath=disk1.img,size=${RAID_MEDIASIZE} \ 183 ${RUMP_SERVER} 184 185 atf_check -s exit:0 rump.raidctl -C raid.conf raid0 186 atf_check -s exit:0 rump.raidctl -I 12345 raid0 187 atf_check -s exit:0 -o ignore rump.raidctl -iv raid0 188 189 # restart server with failed component 190 rump.halt 191 rm disk0.img # FAIL 192 atf_check -s exit:0 ${raidserver} \ 193 -d key=/disk0,hostpath=disk0.img,size=${RAID_MEDIASIZE} \ 194 -d key=/disk1,hostpath=disk1.img,size=${RAID_MEDIASIZE} \ 195 ${RUMP_SERVER} 196 197 atf_check -s exit:0 rump.raidctl -c raid.conf raid0 198} 199 200raid1_comp0fail_cleanup() 201{ 202 export RUMP_SERVER=unix://sock 203 rump.halt 204} 205 206atf_test_case raid1_normal cleanup 207raid1_normal_head() 208{ 209 atf_set "descr" "Checks that RAID1 -c configurations work " \ 210 "in the normal case" 211 atf_set "require.progs" "rump_server" 212} 213 214raid1_normal_body() 215{ 216 makecfg 1 2 217 export RUMP_SERVER=unix://sock 218 atf_check -s exit:0 ${raidserver} \ 219 -d key=/disk0,hostpath=disk0.img,size=${RAID_MEDIASIZE} \ 220 -d key=/disk1,hostpath=disk1.img,size=${RAID_MEDIASIZE} \ 221 ${RUMP_SERVER} 222 223 atf_check -s exit:0 rump.raidctl -C raid.conf raid0 224 atf_check -s exit:0 rump.raidctl -I 12345 raid0 225 atf_check -s exit:0 -o ignore rump.raidctl -iv raid0 226 227 # put some data there 228 atf_check -s exit:0 -e ignore \ 229 dd if=$(atf_get_srcdir)/t_raid of=testfile count=4 230 atf_check -s exit:0 -e ignore -x \ 231 "dd if=testfile | rump.dd of=${rawraid} conv=sync" 232 233 # restart server, disks remain normal 234 rump.halt 235 236 atf_check -s exit:0 ${raidserver} \ 237 -d key=/disk0,hostpath=disk0.img,size=${RAID_MEDIASIZE} \ 238 -d key=/disk1,hostpath=disk1.img,size=${RAID_MEDIASIZE} \ 239 ${RUMP_SERVER} 240 241 atf_check -s exit:0 rump.raidctl -c raid.conf raid0 242 243 # check if we get what we wrote 244 atf_check -s exit:0 -o file:testfile -e ignore \ 245 rump.dd if=${rawraid} count=4 246 247} 248 249raid1_normal_cleanup() 250{ 251 export RUMP_SERVER=unix://sock 252 rump.halt 253} 254 255 256atf_test_case raid5_compfail cleanup 257raid5_compfail_head() 258{ 259 atf_set "descr" "Checks that RAID5 works after component failure" 260 atf_set "require.progs" "rump_server" 261} 262 263raid5_compfail_body() 264{ 265 makecfg 5 3 266 export RUMP_SERVER=unix://sock 267 atf_check -s exit:0 ${raidserver} \ 268 -d key=/disk0,hostpath=disk0.img,size=${RAID_MEDIASIZE} \ 269 -d key=/disk1,hostpath=disk1.img,size=${RAID_MEDIASIZE} \ 270 -d key=/disk2,hostpath=disk2.img,size=${RAID_MEDIASIZE} \ 271 ${RUMP_SERVER} 272 273 atf_check -s exit:0 rump.raidctl -C raid.conf raid0 274 atf_check -s exit:0 rump.raidctl -I 12345 raid0 275 atf_check -s exit:0 -o ignore rump.raidctl -iv raid0 276 277 # put some data there 278 atf_check -s exit:0 -e ignore \ 279 dd if=$(atf_get_srcdir)/t_raid of=testfile count=4 280 atf_check -s exit:0 -e ignore -x \ 281 "dd if=testfile | rump.dd of=${rawraid} conv=sync" 282 283 # restart server with failed component 284 rump.halt 285 rm disk2.img # FAIL 286 atf_check -s exit:0 ${raidserver} \ 287 -d key=/disk0,hostpath=disk0.img,size=${RAID_MEDIASIZE} \ 288 -d key=/disk1,hostpath=disk1.img,size=${RAID_MEDIASIZE} \ 289 -d key=/disk2,hostpath=disk2.img,size=${RAID_MEDIASIZE} \ 290 ${RUMP_SERVER} 291 292 atf_check -s exit:0 rump.raidctl -c raid.conf raid0 293 294 # check if we get what we wrote 295 atf_check -s exit:0 -o file:testfile -e ignore \ 296 rump.dd if=${rawraid} count=4 297} 298 299raid5_compfail_cleanup() 300{ 301 export RUMP_SERVER=unix://sock 302 rump.halt 303} 304 305atf_test_case raid5_normal cleanup 306raid5_normal_head() 307{ 308 atf_set "descr" "Checks that RAID5 works after normal shutdown " \ 309 "and 'raidctl -c' startup" 310 atf_set "require.progs" "rump_server" 311} 312 313raid5_normal_body() 314{ 315 makecfg 5 3 316 export RUMP_SERVER=unix://sock 317 atf_check -s exit:0 ${raidserver} \ 318 -d key=/disk0,hostpath=disk0.img,size=${RAID_MEDIASIZE} \ 319 -d key=/disk1,hostpath=disk1.img,size=${RAID_MEDIASIZE} \ 320 -d key=/disk2,hostpath=disk2.img,size=${RAID_MEDIASIZE} \ 321 ${RUMP_SERVER} 322 323 atf_check -s exit:0 rump.raidctl -C raid.conf raid0 324 atf_check -s exit:0 rump.raidctl -I 12345 raid0 325 atf_check -s exit:0 -o ignore rump.raidctl -iv raid0 326 327 # put some data there 328 atf_check -s exit:0 -e ignore \ 329 dd if=$(atf_get_srcdir)/t_raid of=testfile count=4 330 atf_check -s exit:0 -e ignore -x \ 331 "dd if=testfile | rump.dd of=${rawraid} conv=sync" 332 333 # restart server after normal shutdown 334 rump.halt 335 336 atf_check -s exit:0 ${raidserver} \ 337 -d key=/disk0,hostpath=disk0.img,size=${RAID_MEDIASIZE} \ 338 -d key=/disk1,hostpath=disk1.img,size=${RAID_MEDIASIZE} \ 339 -d key=/disk2,hostpath=disk2.img,size=${RAID_MEDIASIZE} \ 340 ${RUMP_SERVER} 341 342 atf_check -s exit:0 rump.raidctl -c raid.conf raid0 343 344 # check if we get what we wrote 345 atf_check -s exit:0 -o file:testfile -e ignore \ 346 rump.dd if=${rawraid} count=4 347} 348 349raid5_normal_cleanup() 350{ 351 export RUMP_SERVER=unix://sock 352 rump.halt 353} 354 355atf_init_test_cases() 356{ 357 atf_add_test_case smalldisk 358 atf_add_test_case old_numrows_config 359 atf_add_test_case raid1_normal 360 atf_add_test_case raid1_comp0fail 361 atf_add_test_case raid1_compfail 362 atf_add_test_case raid5_normal 363 atf_add_test_case raid5_compfail 364} 365