]> git.ipfire.org Git - thirdparty/systemd.git/commitdiff
test: properly preserve journal from sd-bsod tests
authorFrantisek Sumsal <frantisek@sumsal.cz>
Thu, 15 Feb 2024 20:13:07 +0000 (21:13 +0100)
committerFrantisek Sumsal <frantisek@sumsal.cz>
Fri, 16 Feb 2024 09:37:37 +0000 (10:37 +0100)
I (incorrectly) assumed that --relinquish-var does everything --flush
does, including moving already existing stuff from /var/log/journal/ to
/run/log/journal/, but that's not the case. To actually do that we need
to shuffle things manually, so let's do just that.

This should make issues like #31334 easier to debug, since with this
patch we now have a coredump in the test journal as well:

~# make -C test/TEST-04-JOURNAL/ clean setup run TEST_MATCH_SUBTEST=bsod BUILD_DIR=$PWD/build TEST_NO_NSPAWN=1
...
[   12.176089] testsuite-04.sh[712]: + echo 'Subtest /usr/lib/systemd/tests/testdata/units/testsuite-04.bsod.sh failed'
[   12.176089] testsuite-04.sh[712]: Subtest /usr/lib/systemd/tests/testdata/units/testsuite-04.bsod.sh failed
[   12.176089] testsuite-04.sh[712]: + return 1
[   12.177347] systemd[1]: testsuite-04.service: Failed with result 'exit-code'.
[   12.220580] systemd[1]: Failed to start testsuite-04.service.
Spawning getter /home/mrc0mmand/repos/@systemd/systemd/build/journalctl -o export -D /var/tmp/systemd-tests/systemd-test.Qtqmmr/root/var/log/journal...
Finishing after writing 7649 entries
TEST-04-JOURNAL: (failed; see logs)
-rw-r----- 1 root root 16777216 Feb 15 21:13 /var/tmp/systemd-tests/systemd-test.Qtqmmr/system.journal
...

~# coredumpctl --file /var/tmp/systemd-tests/systemd-test.Qtqmmr/system.journal
TIME                        PID UID GID SIG     COREFILE EXE                           SIZE
Thu 2024-02-15 21:13:38 CET 812   0   0 SIGABRT journal  /usr/lib/systemd/systemd-bsod    -

test/units/testsuite-04.bsod.sh

index 30f0cb0bd4813751cc6d903dd7a411e789b88537..36092fe821dae86805bcf9278092cf3d1bbdd8a7 100755 (executable)
@@ -17,8 +17,22 @@ at_exit() {
     fi
 
     if mountpoint -q /var/log/journal; then
+        # In order to preserve the journal from the just run test we need to do a little dance, as
+        # --relinquish-var is not a "true" opposite of --flush, meaning that it won't move the existing
+        # journal(s) from /var/log/ to /run/log/. To do that, let's rotate the journal first, so all
+        # important bits are in the archived journal(s)...
+        journalctl --rotate
+        # ...then instruct sd-journald to write further entries to the runtime journal...
         journalctl --relinquish-var
+        # ...make sure there are no outstanding writes to the persistent journal that might block us from
+        # unmounting the tmpfs...
+        journalctl --sync
+        # ...move the archived journals to the runtime storage...
+        mv -v "/var/log/journal/$(</etc/machine-id)"/system@*.journal "/run/log/journal/$(</etc/machine-id)/"
+        # ...get rid of the tmpfs on /var/log/journal/...
         umount /var/log/journal
+        # ...and finally flush everything to the "real" persistent journal, so we can collect it after the
+        # test finishes.
         journalctl --flush
     fi
 
@@ -88,6 +102,7 @@ systemctl daemon-reload
 systemctl start systemd-bsod
 systemd-cat -p emerg echo "Service emergency message"
 vcs_dump_and_check "Service emergency message"
+systemctl status systemd-bsod
 systemctl stop systemd-bsod
 
 # Wipe the journal