summaryrefslogtreecommitdiffstats
path: root/test/units/testsuite-09.journal.sh
diff options
context:
space:
mode:
authorDaniel Baumann <daniel.baumann@progress-linux.org>2024-04-10 20:49:52 +0000
committerDaniel Baumann <daniel.baumann@progress-linux.org>2024-04-10 20:49:52 +0000
commit55944e5e40b1be2afc4855d8d2baf4b73d1876b5 (patch)
tree33f869f55a1b149e9b7c2b7e201867ca5dd52992 /test/units/testsuite-09.journal.sh
parentInitial commit. (diff)
downloadsystemd-55944e5e40b1be2afc4855d8d2baf4b73d1876b5.tar.xz
systemd-55944e5e40b1be2afc4855d8d2baf4b73d1876b5.zip
Adding upstream version 255.4.upstream/255.4
Signed-off-by: Daniel Baumann <daniel.baumann@progress-linux.org>
Diffstat (limited to 'test/units/testsuite-09.journal.sh')
-rwxr-xr-xtest/units/testsuite-09.journal.sh72
1 files changed, 72 insertions, 0 deletions
diff --git a/test/units/testsuite-09.journal.sh b/test/units/testsuite-09.journal.sh
new file mode 100755
index 0000000..2ef192c
--- /dev/null
+++ b/test/units/testsuite-09.journal.sh
@@ -0,0 +1,72 @@
+#!/usr/bin/env bash
+# SPDX-License-Identifier: LGPL-2.1-or-later
+set -eux
+set -o pipefail
+
+# shellcheck source=test/units/util.sh
+. "$(dirname "$0")"/util.sh
+
+get_first_boot_id() {
+ journalctl -b "${1:?}" -o json -n +1 | jq -r '._BOOT_ID'
+}
+
+get_last_boot_id() {
+ journalctl -b "${1:?}" -o json -n 1 | jq -r '._BOOT_ID'
+}
+
+get_first_timestamp() {
+ journalctl -b "${1:?}" -o json -n +1 | jq -r '.__REALTIME_TIMESTAMP'
+}
+
+get_last_timestamp() {
+ journalctl -b "${1:?}" -o json -n 1 | jq -r '.__REALTIME_TIMESTAMP'
+}
+
+# Issue: #29275, second part
+# Now let's check if the boot entries are in the correct/expected order
+index=0
+SYSTEMD_LOG_LEVEL=debug journalctl --list-boots
+journalctl --list-boots -o json | jq -r '.[] | [.index, .boot_id, .first_entry, .last_entry] | @tsv' |
+ while read -r offset boot_id first_ts last_ts; do
+ : "Boot #$((++index)) ($offset) with ID $boot_id"
+
+ # Try the "regular" (non-json) variants first, as they provide a helpful
+ # error message if something is not right
+ SYSTEMD_LOG_LEVEL=debug journalctl -q -n 0 -b "$index"
+ SYSTEMD_LOG_LEVEL=debug journalctl -q -n 0 -b "$offset"
+ SYSTEMD_LOG_LEVEL=debug journalctl -q -n 0 -b "$boot_id"
+
+ # Check the boot ID of the first entry
+ entry_boot_id="$(get_first_boot_id "$index")"
+ assert_eq "$entry_boot_id" "$boot_id"
+ entry_boot_id="$(get_first_boot_id "$offset")"
+ assert_eq "$entry_boot_id" "$boot_id"
+ entry_boot_id="$(get_first_boot_id "$boot_id")"
+ assert_eq "$entry_boot_id" "$boot_id"
+
+ # Check the timestamp of the first entry
+ entry_ts="$(get_first_timestamp "$index")"
+ assert_eq "$entry_ts" "$first_ts"
+ entry_ts="$(get_first_timestamp "$offset")"
+ assert_eq "$entry_ts" "$first_ts"
+ entry_ts="$(get_first_timestamp "$boot_id")"
+ assert_eq "$entry_ts" "$first_ts"
+
+ # Check the boot ID of the last entry
+ entry_boot_id="$(get_last_boot_id "$index")"
+ assert_eq "$entry_boot_id" "$boot_id"
+ entry_boot_id="$(get_last_boot_id "$offset")"
+ assert_eq "$entry_boot_id" "$boot_id"
+ entry_boot_id="$(get_last_boot_id "$boot_id")"
+ assert_eq "$entry_boot_id" "$boot_id"
+
+ # Check the timestamp of the last entry
+ if [[ "$offset" != "0" ]]; then
+ entry_ts="$(get_last_timestamp "$index")"
+ assert_eq "$entry_ts" "$last_ts"
+ entry_ts="$(get_last_timestamp "$offset")"
+ assert_eq "$entry_ts" "$last_ts"
+ entry_ts="$(get_last_timestamp "$boot_id")"
+ assert_eq "$entry_ts" "$last_ts"
+ fi
+ done