summaryrefslogtreecommitdiffstats
path: root/tests/bsd
diff options
context:
space:
mode:
Diffstat (limited to 'tests/bsd')
-rw-r--r--tests/bsd/type_w.sh20
1 files changed, 4 insertions, 16 deletions
diff --git a/tests/bsd/type_w.sh b/tests/bsd/type_w.sh
index d0cb58c..15b4e68 100644
--- a/tests/bsd/type_w.sh
+++ b/tests/bsd/type_w.sh
@@ -2,23 +2,12 @@
command -v mdconfig &>/dev/null || skip
command -v newfs &>/dev/null || skip
-cleanup=()
-do_cleanup() {
- # Run cleanup hooks in reverse order
- while ((${#cleanup[@]} > 0)); do
- cmd="${cleanup[-1]}"
- unset 'cleanup[-1]'
- eval "bfs_sudo $cmd"
- done
-}
-trap do_cleanup EXIT
-
clean_scratch
# Create a ramdisk
truncate -s1M scratch/img
md=$(bfs_sudo mdconfig scratch/img) || skip
-cleanup+=("mdconfig -du $md")
+defer bfs_sudo mdconfig -du "$md"
# Make an ffs filesystem
bfs_sudo newfs -n "/dev/$md" >&2 || skip
@@ -26,7 +15,7 @@ mkdir scratch/mnt
# Mount it
bfs_sudo mount "/dev/$md" scratch/mnt || skip
-cleanup+=("umount scratch/mnt")
+defer bfs_sudo umount scratch/mnt
# Make it owned by us
bfs_sudo chown "$(id -u):$(id -g)" scratch/mnt
@@ -34,7 +23,7 @@ bfs_sudo chown "$(id -u):$(id -g)" scratch/mnt
# Mount a union filesystem within it
bfs_sudo mount -t unionfs -o below scratch/mnt/{lower,upper}
-cleanup+=("umount scratch/mnt/upper")
+defer bfs_sudo umount scratch/mnt/upper
# Create a whiteout
rm scratch/mnt/upper/bar
@@ -53,8 +42,7 @@ munge_ls() {
# So this is not the same as test 1
invoke_bfs scratch/mnt \( -type w -or -not -type w \) -ls | munge_ls 3
# Unmount the unionfs
- bfs_sudo umount scratch/mnt/upper
- unset 'cleanup[-1]'
+ pop_defer
# Now repeat the same tests
invoke_bfs scratch/mnt -ls | munge_ls 4
invoke_bfs scratch/mnt -type w -ls | munge_ls 5