]> git.ipfire.org Git - thirdparty/systemd.git/commitdiff
test: add test cases for journal corruption on btrfs 31311/head
authorFrantisek Sumsal <frantisek@sumsal.cz>
Sat, 10 Feb 2024 07:24:10 +0000 (16:24 +0900)
committerYu Watanabe <watanabe.yu+github@gmail.com>
Thu, 15 Feb 2024 18:48:18 +0000 (03:48 +0900)
For issue #24150 and #31222.

test/test-functions
test/units/testsuite-04.journal-corrupt.sh [new file with mode: 0755]

index ce7e03d7457ebc80697ec8bf1b2f04debac8f925..abaa86792b897f1a02a4ea3d69c7574379e50391 100644 (file)
@@ -2103,7 +2103,7 @@ install_testuser() {
     # create unprivileged user for user manager tests
     mkdir -p "${initdir:?}/etc/sysusers.d"
     cat >"$initdir/etc/sysusers.d/testuser.conf" <<EOF
-u testuser    4711     "Test User" /home/testuser
+u testuser    4711     "Test User" /home/testuser /bin/bash
 EOF
 
     mkdir -p "$initdir/home/testuser"
diff --git a/test/units/testsuite-04.journal-corrupt.sh b/test/units/testsuite-04.journal-corrupt.sh
new file mode 100755 (executable)
index 0000000..051d0ab
--- /dev/null
@@ -0,0 +1,36 @@
+#!/usr/bin/env bash
+# SPDX-License-Identifier: LGPL-2.1-or-later
+set -eux
+set -o pipefail
+
+journalctl --rotate --vacuum-files=1
+# Nuke all archived journals, so we start with a clean slate
+rm -f "/var/log/journal/$(</etc/machine-id)"/system@*.journal
+rm -f "/var/log/journal/$(</etc/machine-id)"/user-*@*.journal
+journalctl --header | grep path
+
+# Make sure the user instance is active when we rotate journals
+systemd-run --unit user-sleep.service --user -M testuser@ sleep infinity
+
+for _ in {0..9}; do
+    journalctl --rotate
+    journalctl --sync
+    SYSTEMD_LOG_LEVEL=debug journalctl -n1 -q
+    (! journalctl -n0 -q |& grep corrupted)
+done
+
+systemctl stop --user -M testuser@ user-sleep.service
+
+journalctl --sync
+journalctl --rotate --vacuum-files=1
+# Nuke all archived journals, so we start with a clean slate
+rm -f "/var/log/journal/$(</etc/machine-id)"/system@*.journal
+rm -f "/var/log/journal/$(</etc/machine-id)/"user-*@*.journal
+journalctl --header | grep path
+
+for _ in {0..9}; do
+    journalctl --rotate --vacuum-files=1
+    journalctl --sync
+    SYSTEMD_LOG_LEVEL=debug journalctl -n1 -q
+    (! journalctl -n0 -q |& grep corrupted)
+done