From 0b189ac84c432a085a1f10139260cec6b5032523 Mon Sep 17 00:00:00 2001 From: Frantisek Sumsal Date: Sat, 25 Mar 2023 12:02:15 +0100 Subject: [PATCH 1/3] test: don't expand the subshell expression prematurely We need to expand the subshell expression during the `bash -c` invocation, not before, to take the desired effect, as now it expands to: timeout 30 bash -c 'while [[ 0 -eq 0 ]]; do sleep 1; done' instead of the expected: timeout 30 bash -c 'while [[ $(coredumpctl list -q --no-legend 770 | wc -l) -eq 0 ]]; do sleep 1; done' Follow-up to aadbd81f7f. --- test/units/testsuite-74.coredump.sh | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/test/units/testsuite-74.coredump.sh b/test/units/testsuite-74.coredump.sh index 6a299ecbfb1..3910abe0ec1 100755 --- a/test/units/testsuite-74.coredump.sh +++ b/test/units/testsuite-74.coredump.sh @@ -59,7 +59,7 @@ printf '[Coredump]\nStorage=external' >/run/systemd/coredump.conf.d/99-external. "$MAKE_DUMP_SCRIPT" "$CORE_TEST_BIN" "SIGABRT" rm -fv /run/systemd/coredump.conf.d/99-external.conf # Wait a bit for the coredumps to get processed -timeout 30 bash -c "while [[ $(coredumpctl list -q --no-legend $CORE_TEST_BIN | wc -l) -lt 4 ]]; do sleep 1; done" +timeout 30 bash -c "while [[ \$(coredumpctl list -q --no-legend $CORE_TEST_BIN | wc -l) -lt 4 ]]; do sleep 1; done" coredumpctl SYSTEMD_LOG_LEVEL=debug coredumpctl @@ -116,7 +116,7 @@ printf '[Coredump]\nStorage=external' >/run/systemd/coredump.conf.d/99-external. "${UNPRIV_CMD[@]}" "$MAKE_DUMP_SCRIPT" "$CORE_TEST_UNPRIV_BIN" "SIGABRT" rm -fv /run/systemd/coredump.conf.d/99-external.conf # Wait a bit for the coredumps to get processed -timeout 30 bash -c "while [[ $(coredumpctl list -q --no-legend $CORE_TEST_UNPRIV_BIN | wc -l) -lt 4 ]]; do sleep 1; done" +timeout 30 bash -c "while [[ \$(coredumpctl list -q --no-legend $CORE_TEST_UNPRIV_BIN | wc -l) -lt 4 ]]; do sleep 1; done" # root should see coredumps from both binaries coredumpctl info "$CORE_TEST_UNPRIV_BIN" @@ -149,7 +149,7 @@ rm -f /tmp/core.{output,redirected} journalctl -b -n 1 --output=export --output-fields=MESSAGE,COREDUMP COREDUMP_EXE="/usr/bin/test-dump" | /usr/lib/systemd/systemd-coredump --backtrace $$ 0 0 6 1679509994 12345 mymachine # Wait a bit for the coredump to get processed -timeout 30 bash -c "while [[ $(coredumpctl list -q --no-legend $$ | wc -l) -eq 0 ]]; do sleep 1; done" +timeout 30 bash -c "while [[ \$(coredumpctl list -q --no-legend $$ | wc -l) -eq 0 ]]; do sleep 1; done" coredumpctl info "$$" coredumpctl info COREDUMP_HOSTNAME="mymachine" From 370fa624f54bb2a5bd52b86d141e3d16c204c0ed Mon Sep 17 00:00:00 2001 From: Frantisek Sumsal Date: Sat, 25 Mar 2023 12:15:33 +0100 Subject: [PATCH 2/3] test: don't touch the /failed marker in the subtest scripts As it is already handled by the "main" script (testsuite-74.sh). --- test/units/testsuite-74.machinectl.sh | 5 ----- 1 file changed, 5 deletions(-) diff --git a/test/units/testsuite-74.machinectl.sh b/test/units/testsuite-74.machinectl.sh index 4adb1cd6373..119c9bdc027 100755 --- a/test/units/testsuite-74.machinectl.sh +++ b/test/units/testsuite-74.machinectl.sh @@ -7,8 +7,6 @@ set -o pipefail # shellcheck source=test/units/assert.sh . "$(dirname "$0")"/assert.sh -: >/failed - at_exit() { if [[ -v NSPAWN_NAME && -e "/var/lib/machines/$NSPAWN_NAME" ]]; then rm -fvr "/var/lib/machines/$NSPAWN_NAME" "/etc/systemd/nspawn/$NSPAWN_NAME" "new" @@ -38,6 +36,3 @@ script -ec 'machinectl cat "$PWD/new"' /dev/null EDITOR='mv new' script -ec 'machinectl edit "$NSPAWN_NAME"' /dev/null printf '%s\n' '[Exec]' 'Boot=false' | cmp - "/etc/systemd/nspawn/$NSPAWN_NAME" - -touch /testok -rm /failed From 91c031f169d0d972417f0f09fde522212e7980ec Mon Sep 17 00:00:00 2001 From: Frantisek Sumsal Date: Sat, 25 Mar 2023 12:17:11 +0100 Subject: [PATCH 3/3] test: drop unnecessary return Return code of the EXIT trap handler is ignored in bash. --- test/units/testsuite-74.machinectl.sh | 2 -- 1 file changed, 2 deletions(-) diff --git a/test/units/testsuite-74.machinectl.sh b/test/units/testsuite-74.machinectl.sh index 119c9bdc027..3d8d07c87da 100755 --- a/test/units/testsuite-74.machinectl.sh +++ b/test/units/testsuite-74.machinectl.sh @@ -11,8 +11,6 @@ at_exit() { if [[ -v NSPAWN_NAME && -e "/var/lib/machines/$NSPAWN_NAME" ]]; then rm -fvr "/var/lib/machines/$NSPAWN_NAME" "/etc/systemd/nspawn/$NSPAWN_NAME" "new" fi - - return 0 } trap at_exit EXIT