aboutsummaryrefslogtreecommitdiff
path: root/sbin
diff options
context:
space:
mode:
authorOlivier Cochard <olivier@FreeBSD.org>2025-07-31 00:10:56 +0000
committerOlivier Cochard <olivier@FreeBSD.org>2025-07-31 00:23:13 +0000
commita01ce3b87d83d4a2644b0d806318d09442817d3b (patch)
tree198dc2d69a126f0335c36f18c10bae04c09d9618 /sbin
parent6fa24b29d8ff9af93cd249520b648cc745b1ef60 (diff)
Diffstat (limited to 'sbin')
-rwxr-xr-xsbin/swapon/tests/swapon_test.sh60
1 files changed, 52 insertions, 8 deletions
diff --git a/sbin/swapon/tests/swapon_test.sh b/sbin/swapon/tests/swapon_test.sh
index b6d31ecaeed0..a04bb36cc49e 100755
--- a/sbin/swapon/tests/swapon_test.sh
+++ b/sbin/swapon/tests/swapon_test.sh
@@ -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"
}
@@ -167,6 +191,24 @@ attach_dev_md_eli_cleanup()
}
###
+
+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()
{
atf_add_test_case attach_mdX
@@ -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
}