mirror of
https://git.freebsd.org/src.git
synced 2026-01-11 19:57:22 +00:00
swapon: Improve tests for non-standard kernel page size and small media
Add a test to verify swapon's behavior when attaching to media that's too small. This also adapts existing tests to accommodate kernel page sizes larger than the default 4KB. Approved by: kib, chs (previous version) Sponsored by: Netflix Differential Revision: https://reviews.freebsd.org/D51641
This commit is contained in:
parent
6fa24b29d8
commit
a01ce3b87d
1 changed files with 52 additions and 8 deletions
|
|
@ -31,7 +31,10 @@ attach_mdX_head()
|
|||
attach_mdX_body()
|
||||
{
|
||||
# if the swapfile is too small (like 1k) then mdconfig hangs looking up the md
|
||||
atf_check -s exit:0 -x "truncate -s 10k swapfile"
|
||||
# but need a swapfile bigger than one page kernel page size
|
||||
pagesize=$(sysctl -n hw.pagesize)
|
||||
minsize=$(( pagesize * 2 ))
|
||||
atf_check -s exit:0 -x "truncate -s $minsize swapfile"
|
||||
atf_check -s exit:0 -o save:fstab.out -x "echo 'md31 none swap sw,file=swapfile 0 0'"
|
||||
atf_check -s exit:0 -o match:"swapon: adding /dev/md31 as swap device" -x "swapon -F fstab.out -a"
|
||||
}
|
||||
|
|
@ -49,7 +52,10 @@ attach_dev_mdX_head()
|
|||
attach_dev_mdX_body()
|
||||
{
|
||||
# if the swapfile is too small (like 1k) then mdconfig hangs looking up the md
|
||||
atf_check -s exit:0 -x "truncate -s 10k swapfile"
|
||||
# but need a swapfile bigger than one page kernel page size
|
||||
pagesize=$(sysctl -n hw.pagesize)
|
||||
minsize=$(( pagesize * 2 ))
|
||||
atf_check -s exit:0 -x "truncate -s $minsize swapfile"
|
||||
atf_check -s exit:0 -o save:fstab.out -x "echo '/dev/md32 none swap sw,file=swapfile 0 0'"
|
||||
atf_check -s exit:0 -o match:"swapon: adding /dev/md32 as swap device" -x "swapon -F fstab.out -a"
|
||||
}
|
||||
|
|
@ -67,7 +73,10 @@ attach_md_head()
|
|||
attach_md_body()
|
||||
{
|
||||
# if the swapfile is too small (like 1k) then mdconfig hangs looking up the md
|
||||
atf_check -s exit:0 -x "truncate -s 10k swapfile"
|
||||
# but need a swapfile bigger than one page kernel page size
|
||||
pagesize=$(sysctl -n hw.pagesize)
|
||||
minsize=$(( pagesize * 2 ))
|
||||
atf_check -s exit:0 -x "truncate -s $minsize swapfile"
|
||||
atf_check -s exit:0 -o save:fstab.out -x "echo 'md none swap sw,file=swapfile 0 0'"
|
||||
atf_check -s exit:0 -o match:"swapon: adding /dev/md[0-9][0-9]* as swap device" -x "swapon -F fstab.out -a"
|
||||
}
|
||||
|
|
@ -85,7 +94,10 @@ attach_dev_md_head()
|
|||
attach_dev_md_body()
|
||||
{
|
||||
# if the swapfile is too small (like 1k) then mdconfig hangs looking up the md
|
||||
atf_check -s exit:0 -x "truncate -s 10k swapfile"
|
||||
# but need a swapfile bigger than one page kernel page size
|
||||
pagesize=$(sysctl -n hw.pagesize)
|
||||
minsize=$(( pagesize * 2 ))
|
||||
atf_check -s exit:0 -x "truncate -s $minsize swapfile"
|
||||
atf_check -s exit:0 -o save:fstab.out -x "echo '/dev/md none swap sw,file=swapfile 0 0'"
|
||||
atf_check -s exit:0 -o match:"swapon: adding /dev/md[0-9][0-9]* as swap device" -x "swapon -F fstab.out -a"
|
||||
}
|
||||
|
|
@ -103,7 +115,10 @@ attach_mdX_eli_head()
|
|||
attach_mdX_eli_body()
|
||||
{
|
||||
# if the swapfile is too small (like 1k) then mdconfig hangs looking up the md
|
||||
atf_check -s exit:0 -x "truncate -s 10k swapfile"
|
||||
# but need a swapfile bigger than one page kernel page size
|
||||
pagesize=$(sysctl -n hw.pagesize)
|
||||
minsize=$(( pagesize * 2 ))
|
||||
atf_check -s exit:0 -x "truncate -s $minsize swapfile"
|
||||
atf_check -s exit:0 -o save:fstab.out -x "echo 'md33.eli none swap sw,file=swapfile 0 0'"
|
||||
atf_check -s exit:0 -o match:"swapon: adding /dev/md33.eli as swap device" -x "swapon -F fstab.out -a"
|
||||
}
|
||||
|
|
@ -121,7 +136,10 @@ attach_dev_mdX_eli_head()
|
|||
attach_dev_mdX_eli_body()
|
||||
{
|
||||
# if the swapfile is too small (like 1k) then mdconfig hangs looking up the md
|
||||
atf_check -s exit:0 -x "truncate -s 10k swapfile"
|
||||
# but need a swapfile bigger than one page kernel page size
|
||||
pagesize=$(sysctl -n hw.pagesize)
|
||||
minsize=$(( pagesize * 2 ))
|
||||
atf_check -s exit:0 -x "truncate -s $minsize swapfile"
|
||||
atf_check -s exit:0 -o save:fstab.out -x "echo '/dev/md34.eli none swap sw,file=swapfile 0 0'"
|
||||
atf_check -s exit:0 -o match:"swapon: adding /dev/md34.eli as swap device" -x "swapon -F fstab.out -a"
|
||||
}
|
||||
|
|
@ -139,7 +157,10 @@ attach_md_eli_head()
|
|||
attach_md_eli_body()
|
||||
{
|
||||
# if the swapfile is too small (like 1k) then mdconfig hangs looking up the md
|
||||
atf_check -s exit:0 -x "truncate -s 10k swapfile"
|
||||
# but need a swapfile bigger than one page kernel page size
|
||||
pagesize=$(sysctl -n hw.pagesize)
|
||||
minsize=$(( pagesize * 2 ))
|
||||
atf_check -s exit:0 -x "truncate -s $minsize swapfile"
|
||||
atf_check -s exit:0 -o save:fstab.out -x "echo 'md.eli none swap sw,file=swapfile 0 0'"
|
||||
atf_check -s exit:0 -o match:"swapon: adding /dev/md[0-9][0-9]*.eli as swap device" -x "swapon -F fstab.out -a"
|
||||
}
|
||||
|
|
@ -157,7 +178,10 @@ attach_dev_md_eli_head()
|
|||
attach_dev_md_eli_body()
|
||||
{
|
||||
# if the swapfile is too small (like 1k) then mdconfig hangs looking up the md
|
||||
atf_check -s exit:0 -x "truncate -s 10k swapfile"
|
||||
# but need a swapfile bigger than one page kernel page size
|
||||
pagesize=$(sysctl -n hw.pagesize)
|
||||
minsize=$(( pagesize * 2 ))
|
||||
atf_check -s exit:0 -x "truncate -s $minsize swapfile"
|
||||
atf_check -s exit:0 -o save:fstab.out -x "echo '/dev/md.eli none swap sw,file=swapfile 0 0'"
|
||||
atf_check -s exit:0 -o match:"swapon: adding /dev/md[0-9][0-9]*.eli as swap device" -x "swapon -F fstab.out -a"
|
||||
}
|
||||
|
|
@ -166,6 +190,24 @@ attach_dev_md_eli_cleanup()
|
|||
swapoff -F fstab.out -a
|
||||
}
|
||||
|
||||
###
|
||||
|
||||
atf_test_case attach_too_small
|
||||
attach_too_small_head()
|
||||
{
|
||||
atf_set "descr" "should refuse to attach if smaller than one kernel page size"
|
||||
}
|
||||
attach_too_small_body()
|
||||
{
|
||||
# Need to use smaller than kernel page size
|
||||
pagesize=$(sysctl -n hw.pagesize)
|
||||
minsize=$(( pagesize / 2 ))
|
||||
atf_check -s exit:0 -x "truncate -s $minsize swapfile"
|
||||
atf_check -s exit:0 -o save:fstab.out -x "echo 'md35 none swap sw,file=swapfile 0 0'"
|
||||
atf_check -s exit:1 -e match:"swapon: /dev/md35: NSWAPDEV limit reached" -x "swapon -F fstab.out -a"
|
||||
atf_check -s exit:0 -x "mdconfig -d -u 35"
|
||||
}
|
||||
|
||||
###
|
||||
atf_init_test_cases()
|
||||
{
|
||||
|
|
@ -178,4 +220,6 @@ atf_init_test_cases()
|
|||
atf_add_test_case attach_dev_mdX_eli
|
||||
atf_add_test_case attach_md_eli
|
||||
atf_add_test_case attach_dev_md_eli
|
||||
|
||||
atf_add_test_case attach_too_small
|
||||
}
|
||||
|
|
|
|||
Loading…
Add table
Reference in a new issue