1# Copyright (c) 2025 Ronald Klop <ronald@FreeBSD.org> 2# 3# Redistribution and use in source and binary forms, with or without 4# modification, are permitted provided that the following conditions 5# are met: 6# 1. Redistributions of source code must retain the above copyright 7# notice, this list of conditions and the following disclaimer. 8# 2. Redistributions in binary form must reproduce the above copyright 9# notice, this list of conditions and the following disclaimer in the 10# documentation and/or other materials provided with the distribution. 11# 12# THIS SOFTWARE IS PROVIDED BY THE AUTHOR AND CONTRIBUTORS ``AS IS'' AND 13# ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE 14# IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE 15# ARE DISCLAIMED. IN NO EVENT SHALL THE AUTHOR OR CONTRIBUTORS BE LIABLE 16# FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL 17# DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS 18# OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) 19# HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT 20# LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY 21# OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF 22# SUCH DAMAGE. 23# 24# 25 26atf_test_case attach_mdX cleanup 27attach_mdX_head() 28{ 29 atf_set "descr" "mdX device should attach" 30} 31attach_mdX_body() 32{ 33 # if the swapfile is too small (like 1k) then mdconfig hangs looking up the md 34 atf_check -s exit:0 -x "truncate -s 10k swapfile" 35 atf_check -s exit:0 -o save:fstab.out -x "echo 'md3 none swap sw,file=swapfile 0 0'" 36 atf_check -s exit:0 -o match:"swapon: adding /dev/md3 as swap device" -x "swapon -F fstab.out -a" 37} 38attach_mdX_cleanup() 39{ 40 swapoff -F fstab.out -a 41} 42 43### 44atf_test_case attach_dev_mdX cleanup 45attach_dev_mdX_head() 46{ 47 atf_set "descr" "/dev/mdX device should attach" 48} 49attach_dev_mdX_body() 50{ 51 # if the swapfile is too small (like 1k) then mdconfig hangs looking up the md 52 atf_check -s exit:0 -x "truncate -s 10k swapfile" 53 atf_check -s exit:0 -o save:fstab.out -x "echo '/dev/md3 none swap sw,file=swapfile 0 0'" 54 atf_check -s exit:0 -o match:"swapon: adding /dev/md3 as swap device" -x "swapon -F fstab.out -a" 55} 56attach_dev_mdX_cleanup() 57{ 58 swapoff -F fstab.out -a 59} 60 61### 62atf_test_case attach_md cleanup 63attach_md_head() 64{ 65 atf_set "descr" "mdX device should attach" 66} 67attach_md_body() 68{ 69 # if the swapfile is too small (like 1k) then mdconfig hangs looking up the md 70 atf_check -s exit:0 -x "truncate -s 10k swapfile" 71 atf_check -s exit:0 -o save:fstab.out -x "echo 'md none swap sw,file=swapfile 0 0'" 72 atf_check -s exit:0 -o match:"swapon: adding /dev/md0 as swap device" -x "swapon -F fstab.out -a" 73} 74attach_md_cleanup() 75{ 76 swapoff -F fstab.out -a 77} 78 79### 80atf_test_case attach_dev_md cleanup 81attach_dev_md_head() 82{ 83 atf_set "descr" "/dev/md device should attach" 84} 85attach_dev_md_body() 86{ 87 # if the swapfile is too small (like 1k) then mdconfig hangs looking up the md 88 atf_check -s exit:0 -x "truncate -s 10k swapfile" 89 atf_check -s exit:0 -o save:fstab.out -x "echo '/dev/md none swap sw,file=swapfile 0 0'" 90 atf_check -s exit:0 -o match:"swapon: adding /dev/md0 as swap device" -x "swapon -F fstab.out -a" 91} 92attach_dev_md_cleanup() 93{ 94 swapoff -F fstab.out -a 95} 96 97### 98atf_test_case attach_mdX_eli cleanup 99attach_mdX_eli_head() 100{ 101 atf_set "descr" "mdX.eli device should attach" 102} 103attach_mdX_eli_body() 104{ 105 # if the swapfile is too small (like 1k) then mdconfig hangs looking up the md 106 atf_check -s exit:0 -x "truncate -s 10k swapfile" 107 atf_check -s exit:0 -o save:fstab.out -x "echo 'md3.eli none swap sw,file=swapfile 0 0'" 108 atf_check -s exit:0 -o match:"swapon: adding /dev/md3.eli as swap device" -x "swapon -F fstab.out -a" 109} 110attach_mdX_eli_cleanup() 111{ 112 swapoff -F fstab.out -a 113} 114 115### 116atf_test_case attach_dev_mdX_eli cleanup 117attach_dev_mdX_eli_head() 118{ 119 atf_set "descr" "/dev/mdX.eli device should attach" 120} 121attach_dev_mdX_eli_body() 122{ 123 # if the swapfile is too small (like 1k) then mdconfig hangs looking up the md 124 atf_check -s exit:0 -x "truncate -s 10k swapfile" 125 atf_check -s exit:0 -o save:fstab.out -x "echo '/dev/md3.eli none swap sw,file=swapfile 0 0'" 126 atf_check -s exit:0 -o match:"swapon: adding /dev/md3.eli as swap device" -x "swapon -F fstab.out -a" 127} 128attach_dev_mdX_eli_cleanup() 129{ 130 swapoff -F fstab.out -a 131} 132 133### 134atf_test_case attach_md_eli cleanup 135attach_md_eli_head() 136{ 137 atf_set "descr" "md.eli device should attach" 138} 139attach_md_eli_body() 140{ 141 # if the swapfile is too small (like 1k) then mdconfig hangs looking up the md 142 atf_check -s exit:0 -x "truncate -s 10k swapfile" 143 atf_check -s exit:0 -o save:fstab.out -x "echo 'md.eli none swap sw,file=swapfile 0 0'" 144 atf_check -s exit:0 -o match:"swapon: adding /dev/md0.eli as swap device" -x "swapon -F fstab.out -a" 145} 146attach_md_eli_cleanup() 147{ 148 swapoff -F fstab.out -a 149} 150 151### 152atf_test_case attach_dev_md_eli cleanup 153attach_dev_md_eli_head() 154{ 155 atf_set "descr" "/dev/md.eli device should attach" 156} 157attach_dev_md_eli_body() 158{ 159 # if the swapfile is too small (like 1k) then mdconfig hangs looking up the md 160 atf_check -s exit:0 -x "truncate -s 10k swapfile" 161 atf_check -s exit:0 -o save:fstab.out -x "echo '/dev/md.eli none swap sw,file=swapfile 0 0'" 162 atf_check -s exit:0 -o match:"swapon: adding /dev/md0.eli as swap device" -x "swapon -F fstab.out -a" 163} 164attach_dev_md_eli_cleanup() 165{ 166 swapoff -F fstab.out -a 167} 168 169### 170atf_init_test_cases() 171{ 172 atf_add_test_case attach_mdX 173 atf_add_test_case attach_dev_mdX 174 atf_add_test_case attach_md 175 atf_add_test_case attach_dev_md 176 177 atf_add_test_case attach_mdX_eli 178 atf_add_test_case attach_dev_mdX_eli 179 atf_add_test_case attach_md_eli 180 atf_add_test_case attach_dev_md_eli 181} 182