summaryrefslogtreecommitdiffstats
path: root/test/units
diff options
context:
space:
mode:
authorFrantisek Sumsal <frantisek@sumsal.cz>2023-10-19 12:28:37 +0200
committerLuca Boccassi <luca.boccassi@gmail.com>2023-10-19 19:01:07 +0200
commita2dd5920021ab2f7ea41e3d517956524cfbe9c64 (patch)
treed074ebfd236e725e9e3593d4487a4d0200877045 /test/units
parentmeson: generate proper version tag when git fails on permission errors (diff)
downloadsystemd-a2dd5920021ab2f7ea41e3d517956524cfbe9c64.tar.xz
systemd-a2dd5920021ab2f7ea41e3d517956524cfbe9c64.zip
test: unify checking for user xattrs support in cgroupfs
Also, run the coredump forwarding test only if user xattrs are supported.
Diffstat (limited to 'test/units')
-rwxr-xr-xtest/units/testsuite-04.LogFilterPatterns.sh18
-rwxr-xr-xtest/units/testsuite-55.sh5
-rwxr-xr-xtest/units/testsuite-74.coredump.sh21
-rwxr-xr-xtest/units/util.sh11
4 files changed, 32 insertions, 23 deletions
diff --git a/test/units/testsuite-04.LogFilterPatterns.sh b/test/units/testsuite-04.LogFilterPatterns.sh
index 41cf8a1fa1..d5d610fe02 100755
--- a/test/units/testsuite-04.LogFilterPatterns.sh
+++ b/test/units/testsuite-04.LogFilterPatterns.sh
@@ -3,6 +3,9 @@
set -eux
set -o pipefail
+# shellcheck source=test/units/util.sh
+ . "$(dirname "$0")"/util.sh
+
add_logs_filtering_override() {
local unit="${1:?}"
local override_name="${2:?}"
@@ -27,20 +30,7 @@ run_service_and_fetch_logs() {
systemctl stop "$unit"
}
-is_xattr_supported() {
- local start end
-
- start="$(date '+%Y-%m-%d %T.%6N')"
- systemd-run --unit text_xattr --property LogFilterPatterns=log sh -c "sleep .5"
- sleep .5
- journalctl --sync
- end="$(date '+%Y-%m-%d %T.%6N')"
- systemctl stop text_xattr
-
- ! journalctl -q -u "text_xattr" -S "$start" -U "$end" --grep "Failed to set 'user.journald_log_filter_patterns' xattr.*not supported$"
-}
-
-if is_xattr_supported; then
+if cgroupfs_supports_user_xattrs; then
# Accept all log messages
add_logs_filtering_override "logs-filtering.service" "00-reset" ""
[[ -n $(run_service_and_fetch_logs "logs-filtering.service") ]]
diff --git a/test/units/testsuite-55.sh b/test/units/testsuite-55.sh
index ffa9af2f6a..afd3053e4d 100755
--- a/test/units/testsuite-55.sh
+++ b/test/units/testsuite-55.sh
@@ -3,6 +3,9 @@
set -eux
set -o pipefail
+# shellcheck source=test/units/util.sh
+ . "$(dirname "$0")"/util.sh
+
systemd-analyze log-level debug
# Ensure that the init.scope.d drop-in is applied on boot
@@ -149,7 +152,7 @@ if systemctl --machine "testuser@.host" --user status testsuite-55-testbloat.ser
if ! systemctl --machine "testuser@.host" --user status testsuite-55-testchill.service; then exit 24; fi
# only run this portion of the test if we can set xattrs
-if setfattr -n user.xattr_test -v 1 /sys/fs/cgroup/; then
+if cgroupfs_supports_user_xattrs; then
sleep 120 # wait for systemd-oomd kill cool down and elevated memory pressure to come down
mkdir -p /run/systemd/system/testsuite-55-testbloat.service.d/
diff --git a/test/units/testsuite-74.coredump.sh b/test/units/testsuite-74.coredump.sh
index 534232a9fb..6552643ee9 100755
--- a/test/units/testsuite-74.coredump.sh
+++ b/test/units/testsuite-74.coredump.sh
@@ -3,6 +3,9 @@
set -eux
set -o pipefail
+# shellcheck source=test/units/util.sh
+ . "$(dirname "$0")"/util.sh
+
# Make sure the binary name fits into 15 characters
CORE_TEST_BIN="/tmp/test-dump"
CORE_TEST_UNPRIV_BIN="/tmp/test-usr-dump"
@@ -89,15 +92,17 @@ ExecStart=systemd-nspawn --quiet --link-journal=try-guest --keep-unit --machine=
EOF
systemctl daemon-reload
-machinectl start "$CONTAINER"
-timeout 60 bash -xec "until systemd-run -M '$CONTAINER' -q --wait --pipe true; do sleep .5; done"
+if cgroupfs_supports_user_xattrs; then
+ machinectl start "$CONTAINER"
+ timeout 60 bash -xec "until systemd-run -M '$CONTAINER' -q --wait --pipe true; do sleep .5; done"
-[[ "$(systemd-run -M "$CONTAINER" -q --wait --pipe coredumpctl list -q --no-legend /usr/bin/sleep | wc -l)" -eq 0 ]]
-machinectl copy-to "$CONTAINER" "$MAKE_DUMP_SCRIPT"
-systemd-run -M "$CONTAINER" -q --wait --pipe "$MAKE_DUMP_SCRIPT" "/usr/bin/sleep" "SIGABRT"
-systemd-run -M "$CONTAINER" -q --wait --pipe "$MAKE_DUMP_SCRIPT" "/usr/bin/sleep" "SIGTRAP"
-# Wait a bit for the coredumps to get processed
-timeout 30 bash -c "while [[ \$(systemd-run -M $CONTAINER -q --wait --pipe coredumpctl list -q --no-legend /usr/bin/sleep | wc -l) -lt 2 ]]; do sleep 1; done"
+ [[ "$(systemd-run -M "$CONTAINER" -q --wait --pipe coredumpctl list -q --no-legend /usr/bin/sleep | wc -l)" -eq 0 ]]
+ machinectl copy-to "$CONTAINER" "$MAKE_DUMP_SCRIPT"
+ systemd-run -M "$CONTAINER" -q --wait --pipe "$MAKE_DUMP_SCRIPT" "/usr/bin/sleep" "SIGABRT"
+ systemd-run -M "$CONTAINER" -q --wait --pipe "$MAKE_DUMP_SCRIPT" "/usr/bin/sleep" "SIGTRAP"
+ # Wait a bit for the coredumps to get processed
+ timeout 30 bash -c "while [[ \$(systemd-run -M $CONTAINER -q --wait --pipe coredumpctl list -q --no-legend /usr/bin/sleep | wc -l) -lt 2 ]]; do sleep 1; done"
+fi
coredumpctl
SYSTEMD_LOG_LEVEL=debug coredumpctl
diff --git a/test/units/util.sh b/test/units/util.sh
index 8a01c5c07a..fee642fa9d 100755
--- a/test/units/util.sh
+++ b/test/units/util.sh
@@ -171,3 +171,14 @@ systemctl_final() {
systemctl "$@"
}
+
+cgroupfs_supports_user_xattrs() {
+ local xattr
+
+ xattr="user.supported_$RANDOM"
+ # shellcheck disable=SC2064
+ trap "setfattr --remove=$xattr /sys/fs/cgroup || :" RETURN
+
+ setfattr --name="$xattr" --value=254 /sys/fs/cgroup
+ [[ "$(getfattr --name="$xattr" --absolute-names --only-values /sys/fs/cgroup)" -eq 254 ]]
+}