]> git.ipfire.org Git - thirdparty/systemd.git/blame - test/TEST-04-JOURNAL/test-journal.sh
test: Disable LUKS devices from initramfs in QEMU tests
[thirdparty/systemd.git] / test / TEST-04-JOURNAL / test-journal.sh
CommitLineData
1c36b4a7 1#!/bin/bash
1c36b4a7
EV
2set -x
3set -e
4set -o pipefail
5
6# Test stdout stream
7
8# Skip empty lines
9ID=$(journalctl --new-id128 | sed -n 2p)
10>/expected
11printf $'\n\n\n' | systemd-cat -t "$ID" --level-prefix false
e8e5a6e2 12journalctl --sync
1c36b4a7
EV
13journalctl -b -o cat -t "$ID" >/output
14cmp /expected /output
15
16ID=$(journalctl --new-id128 | sed -n 2p)
17>/expected
18printf $'<5>\n<6>\n<7>\n' | systemd-cat -t "$ID" --level-prefix true
e8e5a6e2 19journalctl --sync
1c36b4a7
EV
20journalctl -b -o cat -t "$ID" >/output
21cmp /expected /output
22
45d39b4f
EV
23# Remove trailing spaces
24ID=$(journalctl --new-id128 | sed -n 2p)
25printf "Trailing spaces\n">/expected
26printf $'<5>Trailing spaces \t \n' | systemd-cat -t "$ID" --level-prefix true
e8e5a6e2 27journalctl --sync
45d39b4f
EV
28journalctl -b -o cat -t "$ID" >/output
29cmp /expected /output
30
31ID=$(journalctl --new-id128 | sed -n 2p)
32printf "Trailing spaces\n">/expected
33printf $'Trailing spaces \t \n' | systemd-cat -t "$ID" --level-prefix false
e8e5a6e2 34journalctl --sync
45d39b4f
EV
35journalctl -b -o cat -t "$ID" >/output
36cmp /expected /output
37
38# Don't remove leading spaces
39ID=$(journalctl --new-id128 | sed -n 2p)
40printf $' \t Leading spaces\n'>/expected
41printf $'<5> \t Leading spaces\n' | systemd-cat -t "$ID" --level-prefix true
e8e5a6e2 42journalctl --sync
45d39b4f
EV
43journalctl -b -o cat -t "$ID" >/output
44cmp /expected /output
45
46ID=$(journalctl --new-id128 | sed -n 2p)
47printf $' \t Leading spaces\n'>/expected
48printf $' \t Leading spaces\n' | systemd-cat -t "$ID" --level-prefix false
e8e5a6e2 49journalctl --sync
45d39b4f
EV
50journalctl -b -o cat -t "$ID" >/output
51cmp /expected /output
52
cc25a67e
LK
53# --output-fields restricts output
54ID=$(journalctl --new-id128 | sed -n 2p)
55printf $'foo' | systemd-cat -t "$ID" --level-prefix false
56journalctl --sync
57journalctl -b -o export --output-fields=MESSAGE,FOO --output-fields=PRIORITY,MESSAGE -t "$ID" >/output
58[[ `grep -c . /output` -eq 6 ]]
59grep -q '^__CURSOR=' /output
60grep -q '^MESSAGE=foo$' /output
61grep -q '^PRIORITY=6$' /output
62! grep -q '^FOO=' /output
63! grep -q '^SYSLOG_FACILITY=' /output
64
48904825 65# `-b all` negates earlier use of -b (-b and -m are otherwise exclusive)
66journalctl -b -1 -b all -m > /dev/null
67
68# -b always behaves like -b0
69journalctl -q -b-1 -b0 | head -1 > /expected
70journalctl -q -b-1 -b | head -1 > /output
71cmp /expected /output
72# ... even when another option follows (both of these should fail due to -m)
73{ journalctl -ball -b0 -m 2>&1 || :; } | head -1 > /expected
74{ journalctl -ball -b -m 2>&1 || :; } | head -1 > /output
75cmp /expected /output
76
09d0b46a
LB
77# https://github.com/systemd/systemd/issues/13708
78ID=$(systemd-id128 new)
79systemd-cat -t "$ID" bash -c 'echo parent; (echo child) & wait' &
80PID=$!
81wait %%
82journalctl --sync
83# We can drop this grep when https://github.com/systemd/systemd/issues/13937
84# has a fix.
85journalctl -b -o export -t "$ID" --output-fields=_PID | grep '^_PID=' >/output
86[[ `grep -c . /output` -eq 2 ]]
87grep -q "^_PID=$PID" /output
88grep -vq "^_PID=$PID" /output
89
90# Add new tests before here, the journald restarts below
91# may make tests flappy.
92
3889613e
EV
93# Don't lose streams on restart
94systemctl start forever-print-hola
95sleep 3
96systemctl restart systemd-journald
97sleep 3
98systemctl stop forever-print-hola
99[[ ! -f "/i-lose-my-logs" ]]
100
bff653e3
EV
101# https://github.com/systemd/systemd/issues/4408
102rm -f /i-lose-my-logs
103systemctl start forever-print-hola
104sleep 3
105systemctl kill --signal=SIGKILL systemd-journald
106sleep 3
107[[ ! -f "/i-lose-my-logs" ]]
108
1c36b4a7 109touch /testok