]> git.ipfire.org Git - thirdparty/util-linux.git/commitdiff
tests: add ts_skip_capability
authorMasatake YAMATO <yamato@redhat.com>
Sun, 4 Jun 2023 07:55:00 +0000 (16:55 +0900)
committerMasatake YAMATO <yamato@redhat.com>
Sun, 4 Jun 2023 08:19:34 +0000 (17:19 +0900)
Signed-off-by: Masatake YAMATO <yamato@redhat.com>
tests/functions.sh

index c27aac09c45188280d4c0fb0a48f1a2b91e1fff3..b953edc94ed699fafcd9c61c230c6c0ab90f17f9 100644 (file)
@@ -163,6 +163,29 @@ function ts_skip_nonroot {
        fi
 }
 
+# Specify the capability needed in your test case like:
+#
+#      ts_skip_capability cap_wake_alarm
+#
+function ts_skip_capability {
+       local self=$$
+       local cap=$1
+
+       # On Fedora, libcap package provides getpcaps command.
+       ts_check_prog "getpcaps"
+
+       local caps=$(getpcaps "$self")
+       if [[ "$caps" == "${self}: =ep" ]]; then
+               return 0
+       fi
+
+       if [[ "$caps" =~ .*${cap}.* ]]; then
+               return 0
+       fi
+
+       ts_skip "no capability: ${cap}"
+}
+
 function ts_skip_qemu_user {
        if [ "$QEMU_USER" == "1" ]; then
                ts_skip "running under qemu-user emulation"