From 5dffa6b032168305213e4fb0d72fb02363acfd65 Mon Sep 17 00:00:00 2001 From: Frantisek Sumsal Date: Tue, 21 Jun 2022 10:01:30 +0200 Subject: [PATCH 1/5] test: always force a new image for dfuzzer Otherwise we might end up with an image containing broken service symlinks and other things, which break certain parts of the test. --- test/TEST-21-DFUZZER/test.sh | 2 ++ 1 file changed, 2 insertions(+) diff --git a/test/TEST-21-DFUZZER/test.sh b/test/TEST-21-DFUZZER/test.sh index 42e37c8a9c..7669e4e0ad 100755 --- a/test/TEST-21-DFUZZER/test.sh +++ b/test/TEST-21-DFUZZER/test.sh @@ -6,6 +6,8 @@ TEST_DESCRIPTION="Fuzz our D-Bus interfaces with dfuzzer" TEST_NO_NSPAWN=1 TEST_SUPPORTING_SERVICES_SHOULD_BE_MASKED=0 QEMU_TIMEOUT="${QEMU_TIMEOUT:-1800}" +IMAGE_NAME=dfuzzer +TEST_FORCE_NEWIMAGE=1 # shellcheck source=test/test-functions . "${TEST_BASE_DIR:?}/test-functions" From d3eb4159c9577f0a9ee776d34fcec7ad913d88a5 Mon Sep 17 00:00:00 2001 From: Frantisek Sumsal Date: Tue, 21 Jun 2022 10:04:03 +0200 Subject: [PATCH 2/5] test: make dfuzzer less verbose Otherwise it oversaturates the journal, which in some cases can't keep up with the load of messages (due to the performance penalty caused by sanitizers), and gets killed by a watchdog. --- test/units/testsuite-21.sh | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/test/units/testsuite-21.sh b/test/units/testsuite-21.sh index 43b5fb6f22..604bf145ca 100755 --- a/test/units/testsuite-21.sh +++ b/test/units/testsuite-21.sh @@ -72,7 +72,7 @@ mount -t tmpfs -o size=50M tmpfs /var/lib/machines for bus in "${BUS_LIST[@]}"; do echo "Bus: $bus (system)" systemd-run --pipe --wait \ - -- dfuzzer -v -b "$PAYLOAD_MAX" -n "$bus" + -- dfuzzer -b "$PAYLOAD_MAX" -n "$bus" # Let's reload the systemd daemon to test (de)serialization as well systemctl daemon-reload @@ -83,7 +83,7 @@ umount /var/lib/machines for bus in "${SESSION_BUS_LIST[@]}"; do echo "Bus: $bus (session)" systemd-run --machine 'testuser@.host' --user --pipe --wait \ - -- dfuzzer -v -b "$PAYLOAD_MAX" -n "$bus" + -- dfuzzer -b "$PAYLOAD_MAX" -n "$bus" # Let's reload the systemd user daemon to test (de)serialization as well systemctl --machine 'testuser@.host' --user daemon-reload From 5309b56505dfccf9111cb5fe6461047725429e79 Mon Sep 17 00:00:00 2001 From: Frantisek Sumsal Date: Tue, 21 Jun 2022 10:13:48 +0200 Subject: [PATCH 3/5] test: drop the at_exit() coredump check since we don't truncate the journal anymore. --- test/units/testsuite-21.sh | 12 +----------- 1 file changed, 1 insertion(+), 11 deletions(-) diff --git a/test/units/testsuite-21.sh b/test/units/testsuite-21.sh index 604bf145ca..053d571a90 100755 --- a/test/units/testsuite-21.sh +++ b/test/units/testsuite-21.sh @@ -8,17 +8,7 @@ set -o pipefail systemctl list-jobs | grep -F 'end.service' && SHUTDOWN_AT_EXIT=1 || SHUTDOWN_AT_EXIT=0 at_exit() { - # "Safety net" - check for any coredumps which might have not caused dfuzzer - # to stop & return an error (we need to do this now before truncating the - # journal) - # TODO: check fo ASan/UBSan errors - local found_cd=0 - while read -r exe; do - coredumctl info "$exe" - found_cd=1 - done < <(coredumpctl -F COREDUMP_EXE | sort -u) - [[ $found_cd -eq 0 ]] || exit 1 - + set +e # We have to call the end.service explicitly even if it's specified on # the kernel cmdline via systemd.wants=end.service, since dfuzzer calls # org.freedesktop.systemd1.Manager.ClearJobs() which drops the service From 56e8ee55d58e38d47992ca6b5b6466fdb5be4781 Mon Sep 17 00:00:00 2001 From: Frantisek Sumsal Date: Tue, 21 Jun 2022 10:20:12 +0200 Subject: [PATCH 4/5] test: make the shutdown routine a bit more "robust" Replace the call to the `end.service` with `systemctl poweroff`, since it seems to cause issues no matter what `--job-mode=` is used: ``` [ 129.070993] testsuite-21.sh[380]: ++ systemctl start --job-mode=flush end.service [ 129.154985] testsuite-21.sh[912]: Failed to start end.service: Transaction for end.service/start is destructive (sysinit.target has 'stop' job queued, but 'start' is included in transaction). [ 129.159636] testsuite-21.sh[912]: See system logs and 'systemctl status end.service' for details. ``` Also, add a "safety net" which bypasses the manager and does the poweroff directly, since sometimes the D-Bus call performed by `systemctl` might timeout (as the manager might be still processing data from the fuzzing): ``` [ 115.776778] sh[894]: + systemctl poweroff --no-block [ 166.164242] testsuite-21.sh[893]: Failed to start transient service unit: Connection timed out [ 166.269289] sh[894]: Call to PowerOff failed: Connection timed out ``` --- test/units/testsuite-21.sh | 8 ++++++-- 1 file changed, 6 insertions(+), 2 deletions(-) diff --git a/test/units/testsuite-21.sh b/test/units/testsuite-21.sh index 053d571a90..e9bf18603a 100755 --- a/test/units/testsuite-21.sh +++ b/test/units/testsuite-21.sh @@ -9,11 +9,15 @@ systemctl list-jobs | grep -F 'end.service' && SHUTDOWN_AT_EXIT=1 || SHUTDOWN_AT at_exit() { set +e - # We have to call the end.service explicitly even if it's specified on + # We have to call the end.service/poweroff explicitly even if it's specified on # the kernel cmdline via systemd.wants=end.service, since dfuzzer calls # org.freedesktop.systemd1.Manager.ClearJobs() which drops the service # from the queue - [[ $SHUTDOWN_AT_EXIT -ne 0 ]] && systemctl start --job-mode=flush end.service + if [[ $SHUTDOWN_AT_EXIT -ne 0 ]] && ! systemctl poweroff; then + # PID1 is down let's try to save the journal + journalctl --sync || : # journal can be down as well so let's ignore exit codes here + systemctl -ff poweroff # sync() and reboot(RB_POWER_OFF) + fi } trap at_exit EXIT From dc350e78fe66ae8698574202b2e30e5d650219ec Mon Sep 17 00:00:00 2001 From: Frantisek Sumsal Date: Tue, 21 Jun 2022 12:09:35 +0200 Subject: [PATCH 5/5] test: allow overriding $QEMU_MEM when running w/ ASan --- test/TEST-36-NUMAPOLICY/test.sh | 2 +- test/test-functions | 5 ++--- 2 files changed, 3 insertions(+), 4 deletions(-) diff --git a/test/TEST-36-NUMAPOLICY/test.sh b/test/TEST-36-NUMAPOLICY/test.sh index 5f38bf1009..7909b1dce3 100755 --- a/test/TEST-36-NUMAPOLICY/test.sh +++ b/test/TEST-36-NUMAPOLICY/test.sh @@ -9,7 +9,7 @@ TEST_NO_NSPAWN=1 . "${TEST_BASE_DIR:?}/test-functions" if qemu_min_version "5.2.0"; then - QEMU_OPTIONS="-object memory-backend-ram,id=mem0,size=${QEMU_MEM:?} -numa node,memdev=mem0,nodeid=0" + QEMU_OPTIONS="-object memory-backend-ram,id=mem0,size=${QEMU_MEM:-512M} -numa node,memdev=mem0,nodeid=0" else QEMU_OPTIONS="-numa node,nodeid=0" fi diff --git a/test/test-functions b/test/test-functions index f4dd673522..bc479b3e79 100644 --- a/test/test-functions +++ b/test/test-functions @@ -30,7 +30,6 @@ TIMED_OUT= # will be 1 after run_* if *_TIMEOUT is set and test timed out [[ "$LOOKS_LIKE_SUSE" ]] && FSTYPE="${FSTYPE:-btrfs}" || FSTYPE="${FSTYPE:-ext4}" UNIFIED_CGROUP_HIERARCHY="${UNIFIED_CGROUP_HIERARCHY:-default}" EFI_MOUNT="${EFI_MOUNT:-$(bootctl -x 2>/dev/null || echo /boot)}" -QEMU_MEM="${QEMU_MEM:-512M}" # Note that defining a different IMAGE_NAME in a test setup script will only result # in default.img being copied and renamed. It can then be extended by defining # a test_append_files() function. The $1 parameter will be the root directory. @@ -262,7 +261,7 @@ if get_bool "$IS_BUILT_WITH_ASAN"; then STRIP_BINARIES=no SKIP_INITRD="${SKIP_INITRD:-yes}" PATH_TO_INIT=$ROOTLIBDIR/systemd-under-asan - QEMU_MEM="2048M" + QEMU_MEM="${QEMU_MEM:-2G}" QEMU_SMP="${QEMU_SMP:-4}" # We need to correctly distinguish between gcc's and clang's ASan DSOs. @@ -456,7 +455,7 @@ run_qemu() { qemu_options+=( -smp "$QEMU_SMP" -net none - -m "$QEMU_MEM" + -m "${QEMU_MEM:-512M}" -nographic -kernel "$KERNEL_BIN" -drive "format=raw,cache=unsafe,file=$image"