From 582547cbd38a02289451c1cea36a32f446b66677 Mon Sep 17 00:00:00 2001 From: Frantisek Sumsal Date: Fri, 17 Jun 2022 14:44:49 +0200 Subject: [PATCH 1/7] test: make the busy loop in TEST-02 less verbose as it unnecessarily clogs the logs. --- test/units/testsuite-02.sh | 5 +++++ 1 file changed, 5 insertions(+) diff --git a/test/units/testsuite-02.sh b/test/units/testsuite-02.sh index af6e007825..54927a6377 100755 --- a/test/units/testsuite-02.sh +++ b/test/units/testsuite-02.sh @@ -49,6 +49,7 @@ function report_result() { systemd-cat cat "/$name.log" } +set +x # Associative array for running tasks, where running[test-path]=PID declare -A running=() for task in "${TEST_LIST[@]}"; do @@ -72,6 +73,7 @@ for task in "${TEST_LIST[@]}"; do done if [[ -x $task ]]; then + echo "Executing test '$task'" log_file="/${task##*/}.log" $task &>"$log_file" & running[$task]=$! @@ -80,11 +82,14 @@ done # Wait for remaining running tasks for key in "${!running[@]}"; do + echo "Waiting for test '$key' to finish" wait ${running[$key]} && ec=0 || ec=$? report_result "$key" $ec unset running["$key"] done +set -x + # Test logs are sometimes lost, as the system shuts down immediately after journalctl --sync From 94850fb956458703e0c6e0bee7f482aa41a47e9e Mon Sep 17 00:00:00 2001 From: Frantisek Sumsal Date: Fri, 17 Jun 2022 14:47:10 +0200 Subject: [PATCH 2/7] test: always wrap useradd/userdel when running w/ ASan since they dlopen() PAM modules, including systemd ones. --- test/test-functions | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/test/test-functions b/test/test-functions index 98650a503f..9d369685d9 100644 --- a/test/test-functions +++ b/test/test-functions @@ -2484,9 +2484,9 @@ inst_binary() { # Same as above, but we need to wrap certain libraries unconditionally # - # login - dlopen()s (not only) systemd's PAM modules + # login, useradd, userdel - dlopen()s (not only) systemd's PAM modules # tar - called by machinectl in TEST-25 - if get_bool "$IS_BUILT_WITH_ASAN" && [[ "$bin" =~ /(login|tar)$ ]]; then + if get_bool "$IS_BUILT_WITH_ASAN" && [[ "$bin" =~ /(login|tar|useradd|userdel)$ ]]; then wrap_binary=1 fi From c84d1c9822bd181c37a5bd26b607edd67096839f Mon Sep 17 00:00:00 2001 From: Frantisek Sumsal Date: Fri, 17 Jun 2022 15:06:59 +0200 Subject: [PATCH 3/7] test: don't flush debug logs to the console Let's keep the debug logs in the journal, while logging only testsute-*.sh stdout/stderr to the console (ba7abf7). This should make the test output log a bit more readable and potentially the tests itself a bit faster by avoiding console oversaturation. Also, it should significantly reduce the size of artifacts kept by CIs. --- test/units/testsuite-20.sh | 1 - test/units/testsuite-23.sh | 1 - test/units/testsuite-27.sh | 1 - test/units/testsuite-30.sh | 1 - test/units/testsuite-32.sh | 1 - test/units/testsuite-34.sh | 1 - test/units/testsuite-38.sh | 1 - test/units/testsuite-39.sh | 1 - test/units/testsuite-40.sh | 1 - test/units/testsuite-41.sh | 1 - test/units/testsuite-46.sh | 1 - test/units/testsuite-47.sh | 1 - test/units/testsuite-52.sh | 1 - test/units/testsuite-55.sh | 1 - test/units/testsuite-59.sh | 1 - test/units/testsuite-62.sh | 1 - test/units/testsuite-66.sh | 1 - 17 files changed, 17 deletions(-) diff --git a/test/units/testsuite-20.sh b/test/units/testsuite-20.sh index fc87c18c4c..338769aacc 100755 --- a/test/units/testsuite-20.sh +++ b/test/units/testsuite-20.sh @@ -4,7 +4,6 @@ set -eux set -o pipefail systemd-analyze log-level debug -systemd-analyze log-target console test "$(systemctl show -P MainPID testsuite-20.service)" -eq $$ diff --git a/test/units/testsuite-23.sh b/test/units/testsuite-23.sh index 46e45c8780..e8f99ff60d 100755 --- a/test/units/testsuite-23.sh +++ b/test/units/testsuite-23.sh @@ -4,7 +4,6 @@ set -eux set -o pipefail systemd-analyze log-level debug -systemd-analyze log-target console # Create a binary for which execve() will fail touch /tmp/brokenbinary diff --git a/test/units/testsuite-27.sh b/test/units/testsuite-27.sh index 3b2f925153..c0701f35c3 100755 --- a/test/units/testsuite-27.sh +++ b/test/units/testsuite-27.sh @@ -4,7 +4,6 @@ set -eux set -o pipefail systemd-analyze log-level debug -systemd-analyze log-target console systemd-run --wait --unit=test27-one \ -p StandardOutput=file:/tmp/stdout \ diff --git a/test/units/testsuite-30.sh b/test/units/testsuite-30.sh index 51b9bdd093..57f46669f9 100755 --- a/test/units/testsuite-30.sh +++ b/test/units/testsuite-30.sh @@ -4,7 +4,6 @@ set -eux set -o pipefail systemd-analyze log-level debug -systemd-analyze log-target console systemctl disable --now systemd-timesyncd.service diff --git a/test/units/testsuite-32.sh b/test/units/testsuite-32.sh index 20ab67f6f1..5c289d0abf 100755 --- a/test/units/testsuite-32.sh +++ b/test/units/testsuite-32.sh @@ -11,7 +11,6 @@ set -o pipefail if test -f /sys/fs/cgroup/system.slice/testsuite-32.service/memory.oom.group; then systemd-analyze log-level debug - systemd-analyze log-target console # Run a service that is guaranteed to be the first candidate for OOM killing systemd-run --unit=oomtest.service \ diff --git a/test/units/testsuite-34.sh b/test/units/testsuite-34.sh index 57a7b950a0..e6171beaa6 100755 --- a/test/units/testsuite-34.sh +++ b/test/units/testsuite-34.sh @@ -4,7 +4,6 @@ set -eux set -o pipefail systemd-analyze log-level debug -systemd-analyze log-target console function test_directory() { local directory="$1" diff --git a/test/units/testsuite-38.sh b/test/units/testsuite-38.sh index f2f61b961f..438990d1c5 100755 --- a/test/units/testsuite-38.sh +++ b/test/units/testsuite-38.sh @@ -5,7 +5,6 @@ set -eux set -o pipefail systemd-analyze log-level debug -systemd-analyze log-target console unit=testsuite-38-sleep.service diff --git a/test/units/testsuite-39.sh b/test/units/testsuite-39.sh index 03abf391f1..5b77bbbaf1 100755 --- a/test/units/testsuite-39.sh +++ b/test/units/testsuite-39.sh @@ -4,7 +4,6 @@ set -eux set -o pipefail systemd-analyze log-level debug -systemd-analyze log-target console export SYSTEMD_PAGER= SERVICE_PATH="$(mktemp /etc/systemd/system/execreloadXXX.service)" diff --git a/test/units/testsuite-40.sh b/test/units/testsuite-40.sh index dd54fa174c..cec1fd3a7a 100755 --- a/test/units/testsuite-40.sh +++ b/test/units/testsuite-40.sh @@ -4,7 +4,6 @@ set -eux set -o pipefail systemd-analyze log-level debug -systemd-analyze log-target console declare -A property diff --git a/test/units/testsuite-41.sh b/test/units/testsuite-41.sh index 3b41db03f5..13bc684c2d 100755 --- a/test/units/testsuite-41.sh +++ b/test/units/testsuite-41.sh @@ -7,7 +7,6 @@ set -o pipefail MAX_SECS=60 systemd-analyze log-level debug -systemd-analyze log-target console # test one: Restart=on-failure should restart the service systemd-run --unit=one -p Type=oneshot -p Restart=on-failure /bin/bash -c "exit 1" \ diff --git a/test/units/testsuite-46.sh b/test/units/testsuite-46.sh index 82da3b755c..9d090654bc 100755 --- a/test/units/testsuite-46.sh +++ b/test/units/testsuite-46.sh @@ -34,7 +34,6 @@ wait_for_state() { } systemd-analyze log-level debug -systemd-analyze log-target console systemctl service-log-level systemd-homed debug # Create a tmpfs to use as backing store for the home dir. That way we can enforce a size limit nicely. diff --git a/test/units/testsuite-47.sh b/test/units/testsuite-47.sh index ff10602df7..529e9617a5 100755 --- a/test/units/testsuite-47.sh +++ b/test/units/testsuite-47.sh @@ -4,7 +4,6 @@ set -eux set -o pipefail systemd-analyze log-level debug -systemd-analyze log-target console systemctl start testsuite-47-repro sleep 4 diff --git a/test/units/testsuite-52.sh b/test/units/testsuite-52.sh index 8a76ff6ed6..d78fdd53ba 100755 --- a/test/units/testsuite-52.sh +++ b/test/units/testsuite-52.sh @@ -4,7 +4,6 @@ set -ex set -o pipefail systemd-analyze log-level debug -systemd-analyze log-target console systemctl enable test-honor-first-shutdown.service systemctl start test-honor-first-shutdown.service diff --git a/test/units/testsuite-55.sh b/test/units/testsuite-55.sh index 009933e665..8fa1d01fd0 100755 --- a/test/units/testsuite-55.sh +++ b/test/units/testsuite-55.sh @@ -4,7 +4,6 @@ set -eux set -o pipefail systemd-analyze log-level debug -systemd-analyze log-target console # Loose checks to ensure the environment has the necessary features for systemd-oomd [[ -e /proc/pressure ]] || echo "no PSI" >>/skipped diff --git a/test/units/testsuite-59.sh b/test/units/testsuite-59.sh index 143e44ec63..83db053107 100755 --- a/test/units/testsuite-59.sh +++ b/test/units/testsuite-59.sh @@ -28,7 +28,6 @@ wait_on_state_or_fail () { } systemd-analyze log-level debug -systemd-analyze log-target console cat >/run/systemd/system/testservice-fail-59.service < Date: Fri, 17 Jun 2022 15:28:17 +0200 Subject: [PATCH 4/7] test: fix a couple of issues found by shellcheck --- test/units/testsuite-02.sh | 4 ++-- test/units/testsuite-38.sh | 8 ++++---- 2 files changed, 6 insertions(+), 6 deletions(-) diff --git a/test/units/testsuite-02.sh b/test/units/testsuite-02.sh index 54927a6377..8ebcc575ee 100755 --- a/test/units/testsuite-02.sh +++ b/test/units/testsuite-02.sh @@ -61,7 +61,7 @@ for task in "${TEST_LIST[@]}"; do # Task has finished, report its result and drop it from the queue wait "${running[$key]}" && ec=0 || ec=$? report_result "$key" $ec - unset running["$key"] + unset "running[$key]" # Break from inner for loop and outer while loop to skip # the sleep below when we find a free slot in the queue break 2 @@ -85,7 +85,7 @@ for key in "${!running[@]}"; do echo "Waiting for test '$key' to finish" wait ${running[$key]} && ec=0 || ec=$? report_result "$key" $ec - unset running["$key"] + unset "running[$key]" done set -x diff --git a/test/units/testsuite-38.sh b/test/units/testsuite-38.sh index 438990d1c5..c5f9bcc22c 100755 --- a/test/units/testsuite-38.sh +++ b/test/units/testsuite-38.sh @@ -17,7 +17,7 @@ dbus_freeze() { local name object_path suffix suffix="${1##*.}" - name="${1%.$suffix}" + name="${1%".$suffix"}" object_path="/org/freedesktop/systemd1/unit/${name//-/_2d}_2e${suffix}" busctl call \ @@ -31,7 +31,7 @@ dbus_thaw() { local name object_path suffix suffix="${1##*.}" - name="${1%.$suffix}" + name="${1%".$suffix"}" object_path="/org/freedesktop/systemd1/unit/${name//-/_2d}_2e${suffix}" busctl call \ @@ -65,7 +65,7 @@ dbus_can_freeze() { local name object_path suffix suffix="${1##*.}" - name="${1%.$suffix}" + name="${1%".$suffix"}" object_path="/org/freedesktop/systemd1/unit/${name//-/_2d}_2e${suffix}" busctl get-property \ @@ -79,7 +79,7 @@ check_freezer_state() { local name object_path suffix suffix="${1##*.}" - name="${1%.$suffix}" + name="${1%".$suffix"}" object_path="/org/freedesktop/systemd1/unit/${name//-/_2d}_2e${suffix}" for _ in {0..10}; do From 4b9a0c3aebdcf000f8d7ee569cb8a1806d07c397 Mon Sep 17 00:00:00 2001 From: Frantisek Sumsal Date: Fri, 18 Feb 2022 14:10:15 +0100 Subject: [PATCH 5/7] test: pass the initdir to check_result_{qemu,nspawn} hooks --- test/test-functions | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-) diff --git a/test/test-functions b/test/test-functions index 9d369685d9..d26225913c 100644 --- a/test/test-functions +++ b/test/test-functions @@ -1507,7 +1507,7 @@ check_result_nspawn() { # Run additional test-specific checks if defined by check_result_nspawn_hook() if declare -F check_result_nspawn_hook >/dev/null; then - if ! check_result_nspawn_hook; then + if ! check_result_nspawn_hook "${workspace}"; then derror "check_result_nspawn_hook() returned with EC > 0" ret=4 fi @@ -1526,16 +1526,16 @@ check_result_qemu() { check_result_common "${initdir:?}" ret=$? - _umount_dir "${initdir:?}" - # Run additional test-specific checks if defined by check_result_qemu_hook() if declare -F check_result_qemu_hook >/dev/null; then - if ! check_result_qemu_hook; then + if ! check_result_qemu_hook "${initdir:?}"; then derror "check_result_qemu_hook() returned with EC > 0" ret=4 fi fi + _umount_dir "${initdir:?}" + return $ret } From 35d2d2e61c7695b87a4ee3dc54d065f4de95f260 Mon Sep 17 00:00:00 2001 From: Frantisek Sumsal Date: Fri, 17 Jun 2022 17:28:13 +0200 Subject: [PATCH 6/7] test: run the custom check hooks before common checks since we delete the guest journals as part of the save_journal() step in check_result_common(), making journal inaccessible from the custom check hooks. --- test/test-functions | 16 ++++++++-------- 1 file changed, 8 insertions(+), 8 deletions(-) diff --git a/test/test-functions b/test/test-functions index d26225913c..b3844f246c 100644 --- a/test/test-functions +++ b/test/test-functions @@ -1502,10 +1502,7 @@ check_result_nspawn() { local workspace="${1:?}" local ret - check_result_common "${workspace}" - ret=$? - - # Run additional test-specific checks if defined by check_result_nspawn_hook() + # Run a test-specific checks if defined by check_result_nspawn_hook() if declare -F check_result_nspawn_hook >/dev/null; then if ! check_result_nspawn_hook "${workspace}"; then derror "check_result_nspawn_hook() returned with EC > 0" @@ -1513,6 +1510,9 @@ check_result_nspawn() { fi fi + check_result_common "${workspace}" + ret=$? + _umount_dir "${initdir:?}" return $ret @@ -1523,10 +1523,7 @@ check_result_qemu() { local ret mount_initdir - check_result_common "${initdir:?}" - ret=$? - - # Run additional test-specific checks if defined by check_result_qemu_hook() + # Run a test-specific checks if defined by check_result_qemu_hook() if declare -F check_result_qemu_hook >/dev/null; then if ! check_result_qemu_hook "${initdir:?}"; then derror "check_result_qemu_hook() returned with EC > 0" @@ -1534,6 +1531,9 @@ check_result_qemu() { fi fi + check_result_common "${initdir:?}" + ret=$? + _umount_dir "${initdir:?}" return $ret From 8cda7b91ff267fc21325d4886980e243389a7566 Mon Sep 17 00:00:00 2001 From: Frantisek Sumsal Date: Fri, 17 Jun 2022 17:29:22 +0200 Subject: [PATCH 7/7] test: check journal directly instead of capturing console output --- test/TEST-52-HONORFIRSTSHUTDOWN/test.sh | 13 ++++--------- 1 file changed, 4 insertions(+), 9 deletions(-) diff --git a/test/TEST-52-HONORFIRSTSHUTDOWN/test.sh b/test/TEST-52-HONORFIRSTSHUTDOWN/test.sh index 936e801c51..6a1ec9ca29 100755 --- a/test/TEST-52-HONORFIRSTSHUTDOWN/test.sh +++ b/test/TEST-52-HONORFIRSTSHUTDOWN/test.sh @@ -14,15 +14,10 @@ TEST_NO_QEMU=1 # could turn into a reboot if the test fails. NSPAWN_TIMEOUT=60 -# Remove this file if it exists. This is used along with -# the make target "finish". Since concrete confirmation is -# only found from the console during the poweroff. -rm -f /tmp/honorfirstshutdown.log >/dev/null - check_result_nspawn_hook() { - grep -q "Shutdown is already active. Skipping emergency action request" /tmp/honorfirstshutdown.log + local workspace="${1:?}" + + "${JOURNALCTL:?}" -D "${workspace:?}/var/log/journal" --grep "Shutdown is already active. Skipping emergency action request" --no-pager } -# Note: don't use a pipe in the following expression, as it breaks the trap -# handlers we have defined in test/test-functions. -do_test "$@" > >(tee /tmp/honorfirstshutdown.log) +do_test "$@"