From b926dda2efab4b25e59291545c4ec24b781beaff Mon Sep 17 00:00:00 2001 From: Yu Watanabe Date: Mon, 28 Jul 2025 00:33:28 +0900 Subject: [PATCH] TEST-04-JOURNAL: several cleanups - move scripts from test/units/ to the test specific units directory, - drop meaningless true from silent-success.service, - call journalctl from the same bash invocation of echo. No functional change, just refactoring and preparation for the next commit. --- .../delegated-cgroup-filtering.service | 2 +- .../delegated_cgroup_filtering_payload.sh | 2 +- ...elegated_cgroup_filtering_payload_child.sh | 2 +- .../silent-success.service | 1 - .../verbose-success.service | 5 +- .../TEST-04-JOURNAL.LogFilterPatterns.sh | 105 ++++++++++-------- test/units/TEST-04-JOURNAL.journal.sh | 6 +- 7 files changed, 65 insertions(+), 58 deletions(-) rename test/{units => integration-tests/TEST-04-JOURNAL/TEST-04-JOURNAL.units}/delegated_cgroup_filtering_payload.sh (79%) rename test/{units => integration-tests/TEST-04-JOURNAL/TEST-04-JOURNAL.units}/delegated_cgroup_filtering_payload_child.sh (94%) diff --git a/test/integration-tests/TEST-04-JOURNAL/TEST-04-JOURNAL.units/delegated-cgroup-filtering.service b/test/integration-tests/TEST-04-JOURNAL/TEST-04-JOURNAL.units/delegated-cgroup-filtering.service index 7ecd35816d..f38977c931 100644 --- a/test/integration-tests/TEST-04-JOURNAL/TEST-04-JOURNAL.units/delegated-cgroup-filtering.service +++ b/test/integration-tests/TEST-04-JOURNAL/TEST-04-JOURNAL.units/delegated-cgroup-filtering.service @@ -3,7 +3,7 @@ Description=Test service for delegated logs filtering [Service] Type=oneshot -ExecStart=/usr/lib/systemd/tests/testdata/units/delegated_cgroup_filtering_payload.sh +ExecStart=/usr/lib/systemd/tests/testdata/TEST-04-JOURNAL.units/delegated_cgroup_filtering_payload.sh Delegate=yes SyslogLevel=notice LogLevelMax=info diff --git a/test/units/delegated_cgroup_filtering_payload.sh b/test/integration-tests/TEST-04-JOURNAL/TEST-04-JOURNAL.units/delegated_cgroup_filtering_payload.sh similarity index 79% rename from test/units/delegated_cgroup_filtering_payload.sh rename to test/integration-tests/TEST-04-JOURNAL/TEST-04-JOURNAL.units/delegated_cgroup_filtering_payload.sh index 505dcf0cbe..ea10caf187 100755 --- a/test/units/delegated_cgroup_filtering_payload.sh +++ b/test/integration-tests/TEST-04-JOURNAL/TEST-04-JOURNAL.units/delegated_cgroup_filtering_payload.sh @@ -2,7 +2,7 @@ # SPDX-License-Identifier: LGPL-2.1-or-later mkdir /sys/fs/cgroup/system.slice/delegated-cgroup-filtering.service/the_child -/bin/sh /usr/lib/systemd/tests/testdata/units/delegated_cgroup_filtering_payload_child.sh +/usr/lib/systemd/tests/testdata/TEST-04-JOURNAL.units/delegated_cgroup_filtering_payload_child.sh echo "parent_process: hello, world!" echo "parent_process: hello, people!" diff --git a/test/units/delegated_cgroup_filtering_payload_child.sh b/test/integration-tests/TEST-04-JOURNAL/TEST-04-JOURNAL.units/delegated_cgroup_filtering_payload_child.sh similarity index 94% rename from test/units/delegated_cgroup_filtering_payload_child.sh rename to test/integration-tests/TEST-04-JOURNAL/TEST-04-JOURNAL.units/delegated_cgroup_filtering_payload_child.sh index 94f0d3acef..2d67ad9a38 100755 --- a/test/units/delegated_cgroup_filtering_payload_child.sh +++ b/test/integration-tests/TEST-04-JOURNAL/TEST-04-JOURNAL.units/delegated_cgroup_filtering_payload_child.sh @@ -1,4 +1,4 @@ -#!/bin/sh +#!/bin/bash # SPDX-License-Identifier: LGPL-2.1-or-later echo $$ >/sys/fs/cgroup/system.slice/delegated-cgroup-filtering.service/the_child/cgroup.procs diff --git a/test/integration-tests/TEST-04-JOURNAL/TEST-04-JOURNAL.units/silent-success.service b/test/integration-tests/TEST-04-JOURNAL/TEST-04-JOURNAL.units/silent-success.service index d4541afa88..f80feebcc9 100644 --- a/test/integration-tests/TEST-04-JOURNAL/TEST-04-JOURNAL.units/silent-success.service +++ b/test/integration-tests/TEST-04-JOURNAL/TEST-04-JOURNAL.units/silent-success.service @@ -5,7 +5,6 @@ Description=Silent successful service [Service] Type=oneshot LogLevelMax=notice -ExecStart=/bin/true # If the service finishes extremely fast, journald cannot find the source of the # stream. Hence, we need to call 'journalctl --sync' before service finishes. ExecStart=journalctl --sync diff --git a/test/integration-tests/TEST-04-JOURNAL/TEST-04-JOURNAL.units/verbose-success.service b/test/integration-tests/TEST-04-JOURNAL/TEST-04-JOURNAL.units/verbose-success.service index 004693b282..97b9387594 100644 --- a/test/integration-tests/TEST-04-JOURNAL/TEST-04-JOURNAL.units/verbose-success.service +++ b/test/integration-tests/TEST-04-JOURNAL/TEST-04-JOURNAL.units/verbose-success.service @@ -4,10 +4,7 @@ Description=Verbose successful service [Service] Type=oneshot -ExecStart=echo success # If the service finishes extremely fast, journald cannot find the source of the # stream. Hence, we need to call 'journalctl --sync' before service finishes. -ExecStart=journalctl --sync -# Suppress debugging logs from PID1 or sd-executor. Otherwise, the client context -# may be outdated when the stream from 'echo' command in the above comes. +ExecStart=bash -c 'echo success; journalctl --sync' LogLevelMax=info diff --git a/test/units/TEST-04-JOURNAL.LogFilterPatterns.sh b/test/units/TEST-04-JOURNAL.LogFilterPatterns.sh index 5349f0bd7c..16a94bf934 100755 --- a/test/units/TEST-04-JOURNAL.LogFilterPatterns.sh +++ b/test/units/TEST-04-JOURNAL.LogFilterPatterns.sh @@ -47,67 +47,78 @@ at_exit() { trap at_exit EXIT -# Accept all log messages -add_logs_filtering_override "logs-filtering.service" "00-reset" "" -[[ -n $(run_service_and_fetch_logs "logs-filtering.service") ]] +test_service() { + service="${1:?}" -add_logs_filtering_override "logs-filtering.service" "01-allow-all" ".*" -[[ -n $(run_service_and_fetch_logs "logs-filtering.service") ]] + # Accept all log messages + add_logs_filtering_override "$service" "00-reset" "" + [[ -n $(run_service_and_fetch_logs "$service") ]] -# Discard all log messages -add_logs_filtering_override "logs-filtering.service" "02-discard-all" "~.*" -[[ -z $(run_service_and_fetch_logs "logs-filtering.service") ]] + add_logs_filtering_override "$service" "01-allow-all" ".*" + [[ -n $(run_service_and_fetch_logs "$service") ]] -# Accept all test messages -add_logs_filtering_override "logs-filtering.service" "03-reset" "" -[[ -n $(run_service_and_fetch_logs "logs-filtering.service") ]] + # Discard all log messages + add_logs_filtering_override "$service" "02-discard-all" "~.*" + [[ -z $(run_service_and_fetch_logs "$service") ]] -# Discard all test messages -add_logs_filtering_override "logs-filtering.service" "04-discard-gg" "~.*gg.*" -[[ -z $(run_service_and_fetch_logs "logs-filtering.service") ]] + # Accept all test messages + add_logs_filtering_override "$service" "03-reset" "" + [[ -n $(run_service_and_fetch_logs "$service") ]] -# Deny filter takes precedence -add_logs_filtering_override "logs-filtering.service" "05-allow-all-but-too-late" ".*" -[[ -z $(run_service_and_fetch_logs "logs-filtering.service") ]] + # Discard all test messages + add_logs_filtering_override "$service" "04-discard-gg" "~.*gg.*" + [[ -z $(run_service_and_fetch_logs "$service") ]] -# Use tilde in a deny pattern -add_logs_filtering_override "logs-filtering.service" "06-reset" "" -add_logs_filtering_override "logs-filtering.service" "07-prevent-tilde" "~~more~" -[[ -z $(run_service_and_fetch_logs "logs-filtering.service") ]] + # Deny filter takes precedence + add_logs_filtering_override "$service" "05-allow-all-but-too-late" ".*" + [[ -z $(run_service_and_fetch_logs "$service") ]] -# Only allow a pattern that won't be matched -add_logs_filtering_override "logs-filtering.service" "08-reset" "" -add_logs_filtering_override "logs-filtering.service" "09-allow-only-non-existing" "non-existing string" -[[ -z $(run_service_and_fetch_logs "logs-filtering.service") ]] + # Use tilde in a deny pattern + add_logs_filtering_override "$service" "06-reset" "" + add_logs_filtering_override "$service" "07-prevent-tilde" "~~more~" + [[ -z $(run_service_and_fetch_logs "$service") ]] -# Allow a pattern starting with a tilde -add_logs_filtering_override "logs-filtering.service" "10-allow-with-escape-char" "\\\\x7emore~" -[[ -n $(run_service_and_fetch_logs "logs-filtering.service") ]] + # Only allow a pattern that won't be matched + add_logs_filtering_override "$service" "08-reset" "" + add_logs_filtering_override "$service" "09-allow-only-non-existing" "non-existing string" + [[ -z $(run_service_and_fetch_logs "$service") ]] -add_logs_filtering_override "logs-filtering.service" "11-reset" "" -add_logs_filtering_override "logs-filtering.service" "12-allow-with-spaces" "foo bar" -[[ -n $(run_service_and_fetch_logs "logs-filtering.service") ]] + # Allow a pattern starting with a tilde + add_logs_filtering_override "$service" "10-allow-with-escape-char" "\\\\x7emore~" + [[ -n $(run_service_and_fetch_logs "$service") ]] -add_logs_filtering_override "logs-filtering.service" "13-reset" "" -add_logs_filtering_override "logs-filtering.service" "14-exclude-head" "~^Logging" -[[ -z $(run_service_and_fetch_logs "logs-filtering.service") ]] + add_logs_filtering_override "$service" "11-reset" "" + add_logs_filtering_override "$service" "12-allow-with-spaces" "foo bar" + [[ -n $(run_service_and_fetch_logs "$service") ]] -add_logs_filtering_override "logs-filtering.service" "15-reset" "" -add_logs_filtering_override "logs-filtering.service" "16-exclude-head-no-match" "~^foo" -[[ -n $(run_service_and_fetch_logs "logs-filtering.service") ]] + add_logs_filtering_override "$service" "13-reset" "" + add_logs_filtering_override "$service" "14-exclude-head" "~^Logging" + [[ -z $(run_service_and_fetch_logs "$service") ]] -add_logs_filtering_override "logs-filtering.service" "17-reset" "" -add_logs_filtering_override "logs-filtering.service" "18-include-head" "^Logging" -[[ -n $(run_service_and_fetch_logs "logs-filtering.service") ]] + add_logs_filtering_override "$service" "15-reset" "" + add_logs_filtering_override "$service" "16-exclude-head-no-match" "~^foo" + [[ -n $(run_service_and_fetch_logs "$service") ]] -add_logs_filtering_override "logs-filtering.service" "19-reset" "" -add_logs_filtering_override "logs-filtering.service" "20-include-head-no-match" "^foo" -[[ -z $(run_service_and_fetch_logs "logs-filtering.service") ]] + add_logs_filtering_override "$service" "17-reset" "" + add_logs_filtering_override "$service" "18-include-head" "^Logging" + [[ -n $(run_service_and_fetch_logs "$service") ]] -add_logs_filtering_override "delegated-cgroup-filtering.service" "00-allow-all" ".*" -[[ -n $(run_service_and_fetch_logs "delegated-cgroup-filtering.service") ]] + add_logs_filtering_override "$service" "19-reset" "" + add_logs_filtering_override "$service" "20-include-head-no-match" "^foo" + [[ -z $(run_service_and_fetch_logs "$service") ]] +} -add_logs_filtering_override "delegated-cgroup-filtering.service" "01-discard-hello" "~hello" -[[ -z $(run_service_and_fetch_logs "delegated-cgroup-filtering.service") ]] +test_delegate() { + local service="${1:?}" + + add_logs_filtering_override "$service" "00-allow-all" ".*" + [[ -n $(run_service_and_fetch_logs "$service") ]] + + add_logs_filtering_override "$service" "01-discard-hello" "~hello" + [[ -z $(run_service_and_fetch_logs "$service") ]] +} + +test_service logs-filtering.service +test_delegate delegated-cgroup-filtering.service systemctl log-level "$SAVED_LOG_LEVEL" diff --git a/test/units/TEST-04-JOURNAL.journal.sh b/test/units/TEST-04-JOURNAL.journal.sh index 56b5731788..8834d5ae59 100755 --- a/test/units/TEST-04-JOURNAL.journal.sh +++ b/test/units/TEST-04-JOURNAL.journal.sh @@ -109,10 +109,10 @@ systemctl start silent-success # Test syslog identifiers exclusion systemctl start verbose-success.service [[ -n "$(journalctl -b -q -u verbose-success.service -t systemd)" ]] -[[ -n "$(journalctl -b -q -u verbose-success.service -t echo)" ]] +[[ -n "$(journalctl -b -q -u verbose-success.service -t bash)" ]] [[ -n "$(journalctl -b -q -u verbose-success.service -T systemd)" ]] -[[ -n "$(journalctl -b -q -u verbose-success.service -T echo)" ]] -[[ -z "$(journalctl -b -q -u verbose-success.service -T echo -T '(echo)' -T sleep -T '(sleep)' -T systemd -T '(systemd)' -T systemd-executor)" ]] +[[ -n "$(journalctl -b -q -u verbose-success.service -T bash)" ]] +[[ -z "$(journalctl -b -q -u verbose-success.service -T bash -T '(bash)' -T systemd -T '(systemd)')" ]] # Exercise the matching machinery SYSTEMD_LOG_LEVEL=debug journalctl -b -n 1 /dev/null /dev/zero /dev/null /dev/null /dev/null