diff --git a/test/test-functions b/test/test-functions index 3b26b0ca06d..7461703e855 100644 --- a/test/test-functions +++ b/test/test-functions @@ -173,6 +173,7 @@ BASICTOOLS=( getconf getent getfacl + getfattr grep gunzip gzip diff --git a/test/units/testsuite-04.LogFilterPatterns.sh b/test/units/testsuite-04.LogFilterPatterns.sh index 41cf8a1fa1d..d5d610fe02a 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 ffa9af2f6ac..afd3053e4da 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 534232a9fb3..6552643ee96 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 8a01c5c07a9..fee642fa9d8 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 ]] +}