From 63feafbae8f0fa898e439846d8ba88a19497b0e1 Mon Sep 17 00:00:00 2001 From: Masatake YAMATO Date: Sun, 4 Jun 2023 16:55:00 +0900 Subject: [PATCH] tests: add ts_skip_capability Signed-off-by: Masatake YAMATO --- tests/functions.sh | 23 +++++++++++++++++++++++ 1 file changed, 23 insertions(+) diff --git a/tests/functions.sh b/tests/functions.sh index c27aac09c4..b953edc94e 100644 --- a/tests/functions.sh +++ b/tests/functions.sh @@ -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" -- 2.47.2