diff options
author | Tavian Barnes <tavianator@tavianator.com> | 2022-05-12 15:26:43 -0400 |
---|---|---|
committer | Tavian Barnes <tavianator@tavianator.com> | 2022-05-12 16:55:42 -0400 |
commit | 5101665a31b03a7fe14b832658cf80427ac8ba21 (patch) | |
tree | d852a3de225de8fef4e590ad79ca11ed21bfd212 | |
parent | 956895430edd4a4ea2963798c3485ab227ea525c (diff) | |
download | bfs-5101665a31b03a7fe14b832658cf80427ac8ba21.tar.xz |
tests: Use skip_if for sudo tests
This lets us categorize the sudo tests properly, which fixes e.g.
$ ./tests.sh --posix --sudo
-rw-r--r-- | .github/workflows/ci.yml | 2 | ||||
-rw-r--r-- | Makefile | 7 | ||||
-rwxr-xr-x | tests.sh | 106 | ||||
-rw-r--r-- | tests/test_inum_automount.out (renamed from tests/test_automount.out) | 0 |
4 files changed, 66 insertions, 49 deletions
diff --git a/.github/workflows/ci.yml b/.github/workflows/ci.yml index b0a2f49..81b7f77 100644 --- a/.github/workflows/ci.yml +++ b/.github/workflows/ci.yml @@ -84,4 +84,4 @@ jobs: run: | muon=$(tailscale ip -6 muon) rsync -rl --delete . "[$muon]:bfs" - ssh "$muon" 'gmake -C bfs -j$(sysctl -n hw.ncpu) distcheck' + ssh "$muon" 'gmake -C bfs -j$(sysctl -n hw.ncpu) distcheck DISTCHECK_FLAGS=TEST_FLAGS=--verbose' @@ -119,10 +119,6 @@ endif LOCAL_LDFLAGS += -Wl,--as-needed LOCAL_LDLIBS += -lrt - -DISTCHECK_FLAGS := TEST_FLAGS="--verbose --all --sudo" -else # Linux -DISTCHECK_FLAGS := TEST_FLAGS="--verbose" endif ifeq ($(OS),NetBSD) @@ -193,6 +189,9 @@ STRATEGY_CHECKS := $(STRATEGIES:%=check-%) # All the different checks we run CHECKS := $(STRATEGY_CHECKS) check-trie check-xtimegm +# Custom test flags for distcheck +DISTCHECK_FLAGS := TEST_FLAGS="--sudo --verbose" + default: bfs .PHONY: default @@ -92,7 +92,7 @@ Usage: ${GRN}$0${RST} [${BLU}--bfs${RST}=${MAG}path/to/bfs${RST}] [${BLU}--posix Choose which test cases to run (default: ${BLU}--all${RST}) ${BLU}--sudo${RST} - Run tests that require root (not included in ${BLU}--all${RST}) + Run tests that require root ${BLU}--noclean${RST} Keep the test directories around after the run @@ -151,7 +151,6 @@ for arg; do ALL=yes ;; --sudo) - DEFAULT= SUDO=yes ;; --noclean) @@ -169,6 +168,7 @@ for arg; do ;; test_*) EXPLICIT=yes + SUDO=yes enabled_tests+=("$arg") ;; *) @@ -282,11 +282,15 @@ posix_tests=( test_type_l test_H_type_l test_L_type_l + test_type_bind_mount test_user_name test_user_id test_user_nouser + test_xdev + test_L_xdev + # Closed file descriptors test_closed_stdin test_closed_stdout @@ -375,6 +379,8 @@ bsd_tests=( test_iname test_inum + test_inum_mount + test_inum_bind_mount test_ipath @@ -393,6 +399,9 @@ bsd_tests=( test_mnewer test_H_mnewer + test_mount + test_L_mount + test_msince test_mtime_units @@ -447,6 +456,12 @@ bsd_tests=( test_uid_name + test_xattr + test_L_xattr + + test_xattrname + test_L_xattrname + # Optimizer tests test_data_flow_sparse ) @@ -557,6 +572,9 @@ gnu_tests=( test_iname test_inum + test_inum_mount + test_inum_bind_mount + test_inum_automount test_ipath @@ -574,6 +592,9 @@ gnu_tests=( test_mindepth + test_mount + test_L_mount + test_name_slash test_name_slashes @@ -666,6 +687,7 @@ gnu_tests=( test_xtype_f test_L_xtype_l test_L_xtype_f + test_xtype_bind_mount # Optimizer tests test_and_purity @@ -713,6 +735,9 @@ bfs_tests=( # Primaries + test_capable + test_L_capable + test_color test_color_L test_color_rs_lc_rc_ec @@ -814,44 +839,6 @@ bfs_tests=( test_stderr_fails_loudly ) -sudo_tests=( - test_capable - test_L_capable - - test_mount - test_L_mount - test_xdev - test_L_xdev - - test_inum_mount - test_inum_bind_mount - test_type_bind_mount - test_xtype_bind_mount - - test_automount -) - -case "$UNAME" in - Darwin|FreeBSD) - bsd_tests+=( - test_xattr - test_L_xattr - - test_xattrname - test_L_xattrname - ) - ;; - *) - sudo_tests+=( - test_xattr - test_L_xattr - - test_xattrname - test_L_xattrname - ) - ;; -esac - if [ "$DEFAULT" ]; then POSIX=yes BSD=yes @@ -864,7 +851,6 @@ if [ ! "$EXPLICIT" ]; then [ "$BSD" ] && enabled_tests+=("${bsd_tests[@]}") [ "$GNU" ] && enabled_tests+=("${gnu_tests[@]}") [ "$ALL" ] && enabled_tests+=("${bfs_tests[@]}") - [ "$SUDO" ] && enabled_tests+=("${sudo_tests[@]}") fi eval "enabled_tests=($(printf '%q\n' "${enabled_tests[@]}" | sort -u))" @@ -2917,6 +2903,9 @@ function test_L_unique_depth() { } function test_mount() { + skip_if test ! "$SUDO" + skip_if test "$UNAME" = "Darwin" + rm -rf scratch/* mkdir scratch/{foo,mnt} sudo mount -t tmpfs tmpfs scratch/mnt @@ -2930,6 +2919,9 @@ function test_mount() { } function test_L_mount() { + skip_if test ! "$SUDO" + skip_if test "$UNAME" = "Darwin" + rm -rf scratch/* mkdir scratch/{foo,mnt} sudo mount -t tmpfs tmpfs scratch/mnt @@ -2945,6 +2937,9 @@ function test_L_mount() { } function test_xdev() { + skip_if test ! "$SUDO" + skip_if test "$UNAME" = "Darwin" + rm -rf scratch/* mkdir scratch/{foo,mnt} sudo mount -t tmpfs tmpfs scratch/mnt @@ -2958,6 +2953,9 @@ function test_xdev() { } function test_L_xdev() { + skip_if test ! "$SUDO" + skip_if test "$UNAME" = "Darwin" + rm -rf scratch/* mkdir scratch/{foo,mnt} sudo mount -t tmpfs tmpfs scratch/mnt @@ -2973,6 +2971,9 @@ function test_L_xdev() { } function test_inum_mount() { + skip_if test ! "$SUDO" + skip_if test "$UNAME" = "Darwin" + rm -rf scratch/* mkdir scratch/{foo,mnt} sudo mount -t tmpfs tmpfs scratch/mnt @@ -2985,6 +2986,9 @@ function test_inum_mount() { } function test_inum_bind_mount() { + skip_if test ! "$SUDO" + skip_if test "$UNAME" != "Linux" + rm -rf scratch/* $TOUCH scratch/{foo,bar} sudo mount --bind scratch/{foo,bar} @@ -2997,6 +3001,9 @@ function test_inum_bind_mount() { } function test_type_bind_mount() { + skip_if test ! "$SUDO" + skip_if test "$UNAME" != "Linux" + rm -rf scratch/* $TOUCH scratch/{file,null} sudo mount --bind /dev/null scratch/null @@ -3009,6 +3016,9 @@ function test_type_bind_mount() { } function test_xtype_bind_mount() { + skip_if test ! "$SUDO" + skip_if test "$UNAME" != "Linux" + rm -rf scratch/* $TOUCH scratch/{file,null} sudo mount --bind /dev/null scratch/null @@ -3021,14 +3031,15 @@ function test_xtype_bind_mount() { return $ret } -function test_automount() { +function test_inum_automount() { # bfs shouldn't trigger automounts unless it descends into them + skip_if test ! "$SUDO" skip_if fail command -v systemd-mount &>/dev/null rm -rf scratch/* mkdir scratch/{foo,mnt} - quiet sudo systemd-mount -A -o bind basic scratch/mnt + skip_if fail quiet sudo systemd-mount -A -o bind basic scratch/mnt local before=$(inum scratch/mnt) bfs_diff scratch -inum "$before" -prune @@ -3083,6 +3094,9 @@ function test_L_acl() { } function test_capable() { + skip_if test ! "$SUDO" + skip_if test "$UNAME" != "Linux" + rm -rf scratch/* skip_if fail quiet invoke_bfs scratch -quit -capable @@ -3095,6 +3109,9 @@ function test_capable() { } function test_L_capable() { + skip_if test ! "$SUDO" + skip_if test "$UNAME" != "Linux" + rm -rf scratch/* skip_if fail quiet invoke_bfs scratch -quit -capable @@ -3127,7 +3144,8 @@ 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 setfattr -n security.bfs_test scratch/xattr \ + [ "$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 ;; diff --git a/tests/test_automount.out b/tests/test_inum_automount.out index 99c7511..99c7511 100644 --- a/tests/test_automount.out +++ b/tests/test_inum_automount.out |