From b6859d7a6f7e0b3a3cb70fa75e7e46998e8f0f03 Mon Sep 17 00:00:00 2001 From: Tavian Barnes Date: Thu, 29 Dec 2022 13:05:06 -0500 Subject: tests: Use bfs_sudo wrapper instead of testing $SUDO --- tests/bfs/L_capable.sh | 3 +-- tests/bfs/capable.sh | 3 +-- tests/common/L_mount.sh | 5 ++--- tests/common/inum_bind_mount.sh | 5 ++--- tests/common/inum_mount.sh | 5 ++--- tests/common/mount.sh | 5 ++--- tests/gnu/fstype_stacked.sh | 9 ++++----- tests/gnu/inum_automount.sh | 5 ++--- tests/gnu/xtype_bind_mount.sh | 5 ++--- tests/posix/L_xdev.sh | 5 ++--- tests/posix/type_bind_mount.sh | 5 ++--- tests/posix/xdev.sh | 5 ++--- tests/tests.sh | 40 +++++++++++++++++++++++++--------------- 13 files changed, 49 insertions(+), 51 deletions(-) (limited to 'tests') diff --git a/tests/bfs/L_capable.sh b/tests/bfs/L_capable.sh index a349677..232d6ac 100644 --- a/tests/bfs/L_capable.sh +++ b/tests/bfs/L_capable.sh @@ -1,4 +1,3 @@ -test "$SUDO" || skip test "$UNAME" = "Linux" || skip clean_scratch @@ -6,7 +5,7 @@ clean_scratch invoke_bfs scratch -quit -capable || skip "$XTOUCH" scratch/{normal,capable} -sudo setcap all+ep scratch/capable +bfs_sudo setcap all+ep scratch/capable || skip ln -s capable scratch/link bfs_diff -L scratch -capable diff --git a/tests/bfs/capable.sh b/tests/bfs/capable.sh index 8b60ea6..e5cad63 100644 --- a/tests/bfs/capable.sh +++ b/tests/bfs/capable.sh @@ -1,4 +1,3 @@ -test "$SUDO" || skip test "$UNAME" = "Linux" || skip clean_scratch @@ -6,7 +5,7 @@ clean_scratch invoke_bfs scratch -quit -capable || skip "$XTOUCH" scratch/{normal,capable} -sudo setcap all+ep scratch/capable +bfs_sudo setcap all+ep scratch/capable || skip ln -s capable scratch/link bfs_diff scratch -capable diff --git a/tests/common/L_mount.sh b/tests/common/L_mount.sh index 9ab785e..b04acd0 100644 --- a/tests/common/L_mount.sh +++ b/tests/common/L_mount.sh @@ -1,11 +1,10 @@ -test "$SUDO" || skip test "$UNAME" = "Darwin" && skip clean_scratch mkdir scratch/{foo,mnt} -sudo mount -t tmpfs tmpfs scratch/mnt -trap "sudo umount scratch/mnt" EXIT +bfs_sudo mount -t tmpfs tmpfs scratch/mnt || skip +trap "bfs_sudo umount scratch/mnt" EXIT ln -s ../mnt scratch/foo/bar "$XTOUCH" scratch/mnt/baz diff --git a/tests/common/inum_bind_mount.sh b/tests/common/inum_bind_mount.sh index 625ee3d..ecb4ec3 100644 --- a/tests/common/inum_bind_mount.sh +++ b/tests/common/inum_bind_mount.sh @@ -1,10 +1,9 @@ -test "$SUDO" || skip test "$UNAME" = "Linux" || skip clean_scratch "$XTOUCH" scratch/{foo,bar} -sudo mount --bind scratch/{foo,bar} -trap "sudo umount scratch/bar" EXIT +bfs_sudo mount --bind scratch/{foo,bar} || skip +trap "bfs_sudo umount scratch/bar" EXIT bfs_diff scratch -inum "$(inum scratch/bar)" diff --git a/tests/common/inum_mount.sh b/tests/common/inum_mount.sh index 91d06e2..a4832e4 100644 --- a/tests/common/inum_mount.sh +++ b/tests/common/inum_mount.sh @@ -1,10 +1,9 @@ -test "$SUDO" || skip test "$UNAME" = "Darwin" && skip clean_scratch mkdir scratch/{foo,mnt} -sudo mount -t tmpfs tmpfs scratch/mnt -trap "sudo umount scratch/mnt" EXIT +bfs_sudo mount -t tmpfs tmpfs scratch/mnt || skip +trap "bfs_sudo umount scratch/mnt" EXIT bfs_diff scratch -inum "$(inum scratch/mnt)" diff --git a/tests/common/mount.sh b/tests/common/mount.sh index 3f3ed38..b13b43c 100644 --- a/tests/common/mount.sh +++ b/tests/common/mount.sh @@ -1,11 +1,10 @@ -test "$SUDO" || skip test "$UNAME" = "Darwin" && skip clean_scratch mkdir scratch/{foo,mnt} -sudo mount -t tmpfs tmpfs scratch/mnt -trap "sudo umount scratch/mnt" EXIT +bfs_sudo mount -t tmpfs tmpfs scratch/mnt || skip +trap "bfs_sudo umount scratch/mnt" EXIT "$XTOUCH" scratch/foo/bar scratch/mnt/baz diff --git a/tests/gnu/fstype_stacked.sh b/tests/gnu/fstype_stacked.sh index 7110402..16f428f 100644 --- a/tests/gnu/fstype_stacked.sh +++ b/tests/gnu/fstype_stacked.sh @@ -1,13 +1,12 @@ -test "$SUDO" || skip test "$UNAME" = "Linux" || skip clean_scratch mkdir scratch/mnt -sudo mount -t tmpfs tmpfs scratch/mnt -trap "sudo umount scratch/mnt" EXIT +bfs_sudo mount -t tmpfs tmpfs scratch/mnt || skip +trap "bfs_sudo umount scratch/mnt" EXIT -sudo mount -t ramfs ramfs scratch/mnt -trap "sudo umount scratch/mnt; sudo umount scratch/mnt" EXIT +bfs_sudo mount -t ramfs ramfs scratch/mnt || skip +trap "bfs_sudo umount scratch/mnt; bfs_sudo umount scratch/mnt" EXIT bfs_diff scratch/mnt -fstype ramfs -print -o -printf '%p: %F\n' diff --git a/tests/gnu/inum_automount.sh b/tests/gnu/inum_automount.sh index da2e3b0..c4450ef 100644 --- a/tests/gnu/inum_automount.sh +++ b/tests/gnu/inum_automount.sh @@ -1,13 +1,12 @@ # bfs shouldn't trigger automounts unless it descends into them -test "$SUDO" || skip command -v systemd-mount &>/dev/null || skip clean_scratch mkdir scratch/{foo,automnt} -sudo systemd-mount -A -o bind basic scratch/automnt || skip -trap "sudo systemd-umount scratch/automnt" EXIT +bfs_sudo systemd-mount -A -o bind basic scratch/automnt || skip +trap "bfs_sudo systemd-umount scratch/automnt" EXIT before=$(inum scratch/automnt) bfs_diff scratch -inum "$before" -prune diff --git a/tests/gnu/xtype_bind_mount.sh b/tests/gnu/xtype_bind_mount.sh index 9babd9d..99a11ab 100644 --- a/tests/gnu/xtype_bind_mount.sh +++ b/tests/gnu/xtype_bind_mount.sh @@ -1,11 +1,10 @@ -test "$SUDO" || skip test "$UNAME" = "Linux" || skip clean_scratch "$XTOUCH" scratch/{file,null} ln -s /dev/null scratch/link -sudo mount --bind /dev/null scratch/null -trap "sudo umount scratch/null" EXIT +bfs_sudo mount --bind /dev/null scratch/null || skip +trap "bfs_sudo umount scratch/null" EXIT bfs_diff -L scratch -type c diff --git a/tests/posix/L_xdev.sh b/tests/posix/L_xdev.sh index 587c8bb..172ea23 100644 --- a/tests/posix/L_xdev.sh +++ b/tests/posix/L_xdev.sh @@ -1,11 +1,10 @@ -test "$SUDO" || skip test "$UNAME" = "Darwin" && skip clean_scratch mkdir scratch/{foo,mnt} -sudo mount -t tmpfs tmpfs scratch/mnt -trap "sudo umount scratch/mnt" EXIT +bfs_sudo mount -t tmpfs tmpfs scratch/mnt || skip +trap "bfs_sudo umount scratch/mnt" EXIT ln -s ../mnt scratch/foo/bar "$XTOUCH" scratch/mnt/baz diff --git a/tests/posix/type_bind_mount.sh b/tests/posix/type_bind_mount.sh index 2d913db..c9a161d 100644 --- a/tests/posix/type_bind_mount.sh +++ b/tests/posix/type_bind_mount.sh @@ -1,10 +1,9 @@ -test "$SUDO" || skip test "$UNAME" = "Linux" || skip clean_scratch "$XTOUCH" scratch/{file,null} -sudo mount --bind /dev/null scratch/null -trap "sudo umount scratch/null" EXIT +bfs_sudo mount --bind /dev/null scratch/null || skip +trap "bfs_sudo umount scratch/null" EXIT bfs_diff scratch -type c diff --git a/tests/posix/xdev.sh b/tests/posix/xdev.sh index 9d21b14..33412bf 100644 --- a/tests/posix/xdev.sh +++ b/tests/posix/xdev.sh @@ -1,11 +1,10 @@ -test "$SUDO" || skip test "$UNAME" = "Darwin" && skip clean_scratch mkdir scratch/{foo,mnt} -sudo mount -t tmpfs tmpfs scratch/mnt -trap "sudo umount scratch/mnt" EXIT +bfs_sudo mount -t tmpfs tmpfs scratch/mnt || skip +trap "bfs_sudo umount scratch/mnt" EXIT "$XTOUCH" scratch/foo/bar scratch/mnt/baz diff --git a/tests/tests.sh b/tests/tests.sh index 962a2cf..e57db4e 100755 --- a/tests/tests.sh +++ b/tests/tests.sh @@ -101,18 +101,15 @@ fi function usage() { local pad=$(printf "%*s" ${#0} "") cat </dev/null; then + if ((${#SUDO[@]})) && command -v mountpoint &>/dev/null; then for path in "$TMP"/scratch/*; do if mountpoint -q "$path"; then sudo umount "$path" @@ -608,10 +619,9 @@ function make_xattrs() { *) # Linux tmpfs doesn't support the user.* namespace, so we use the security.* # namespace, which is writable by root and readable by others - [ "$SUDO" ] \ - && sudo setfattr -n security.bfs_test scratch/xattr \ - && sudo setfattr -n security.bfs_test_2 scratch/xattr_2 \ - && sudo setfattr -h -n security.bfs_test scratch/xattr_link + bfs_sudo setfattr -n security.bfs_test scratch/xattr \ + && bfs_sudo setfattr -n security.bfs_test_2 scratch/xattr_2 \ + && bfs_sudo setfattr -h -n security.bfs_test scratch/xattr_link ;; esac } -- cgit v1.2.3