]>
Commit | Line | Data |
---|---|---|
1c36b4a7 | 1 | #!/bin/bash |
1c36b4a7 EV |
2 | set -x |
3 | set -e | |
4 | set -o pipefail | |
5 | ||
6 | # Test stdout stream | |
7 | ||
8 | # Skip empty lines | |
9 | ID=$(journalctl --new-id128 | sed -n 2p) | |
10 | >/expected | |
11 | printf $'\n\n\n' | systemd-cat -t "$ID" --level-prefix false | |
e8e5a6e2 | 12 | journalctl --sync |
1c36b4a7 EV |
13 | journalctl -b -o cat -t "$ID" >/output |
14 | cmp /expected /output | |
15 | ||
16 | ID=$(journalctl --new-id128 | sed -n 2p) | |
17 | >/expected | |
18 | printf $'<5>\n<6>\n<7>\n' | systemd-cat -t "$ID" --level-prefix true | |
e8e5a6e2 | 19 | journalctl --sync |
1c36b4a7 EV |
20 | journalctl -b -o cat -t "$ID" >/output |
21 | cmp /expected /output | |
22 | ||
45d39b4f EV |
23 | # Remove trailing spaces |
24 | ID=$(journalctl --new-id128 | sed -n 2p) | |
25 | printf "Trailing spaces\n">/expected | |
26 | printf $'<5>Trailing spaces \t \n' | systemd-cat -t "$ID" --level-prefix true | |
e8e5a6e2 | 27 | journalctl --sync |
45d39b4f EV |
28 | journalctl -b -o cat -t "$ID" >/output |
29 | cmp /expected /output | |
30 | ||
31 | ID=$(journalctl --new-id128 | sed -n 2p) | |
32 | printf "Trailing spaces\n">/expected | |
33 | printf $'Trailing spaces \t \n' | systemd-cat -t "$ID" --level-prefix false | |
e8e5a6e2 | 34 | journalctl --sync |
45d39b4f EV |
35 | journalctl -b -o cat -t "$ID" >/output |
36 | cmp /expected /output | |
37 | ||
38 | # Don't remove leading spaces | |
39 | ID=$(journalctl --new-id128 | sed -n 2p) | |
40 | printf $' \t Leading spaces\n'>/expected | |
41 | printf $'<5> \t Leading spaces\n' | systemd-cat -t "$ID" --level-prefix true | |
e8e5a6e2 | 42 | journalctl --sync |
45d39b4f EV |
43 | journalctl -b -o cat -t "$ID" >/output |
44 | cmp /expected /output | |
45 | ||
46 | ID=$(journalctl --new-id128 | sed -n 2p) | |
47 | printf $' \t Leading spaces\n'>/expected | |
48 | printf $' \t Leading spaces\n' | systemd-cat -t "$ID" --level-prefix false | |
e8e5a6e2 | 49 | journalctl --sync |
45d39b4f EV |
50 | journalctl -b -o cat -t "$ID" >/output |
51 | cmp /expected /output | |
52 | ||
cc25a67e LK |
53 | # --output-fields restricts output |
54 | ID=$(journalctl --new-id128 | sed -n 2p) | |
55 | printf $'foo' | systemd-cat -t "$ID" --level-prefix false | |
56 | journalctl --sync | |
57 | journalctl -b -o export --output-fields=MESSAGE,FOO --output-fields=PRIORITY,MESSAGE -t "$ID" >/output | |
58 | [[ `grep -c . /output` -eq 6 ]] | |
59 | grep -q '^__CURSOR=' /output | |
60 | grep -q '^MESSAGE=foo$' /output | |
61 | grep -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) |
66 | journalctl -b -1 -b all -m > /dev/null | |
67 | ||
68 | # -b always behaves like -b0 | |
69 | journalctl -q -b-1 -b0 | head -1 > /expected | |
70 | journalctl -q -b-1 -b | head -1 > /output | |
71 | cmp /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 | |
75 | cmp /expected /output | |
76 | ||
09d0b46a LB |
77 | # https://github.com/systemd/systemd/issues/13708 |
78 | ID=$(systemd-id128 new) | |
79 | systemd-cat -t "$ID" bash -c 'echo parent; (echo child) & wait' & | |
80 | PID=$! | |
81 | wait %% | |
82 | journalctl --sync | |
83 | # We can drop this grep when https://github.com/systemd/systemd/issues/13937 | |
84 | # has a fix. | |
85 | journalctl -b -o export -t "$ID" --output-fields=_PID | grep '^_PID=' >/output | |
86 | [[ `grep -c . /output` -eq 2 ]] | |
87 | grep -q "^_PID=$PID" /output | |
88 | grep -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 |
94 | systemctl start forever-print-hola | |
95 | sleep 3 | |
96 | systemctl restart systemd-journald | |
97 | sleep 3 | |
98 | systemctl stop forever-print-hola | |
99 | [[ ! -f "/i-lose-my-logs" ]] | |
100 | ||
bff653e3 EV |
101 | # https://github.com/systemd/systemd/issues/4408 |
102 | rm -f /i-lose-my-logs | |
103 | systemctl start forever-print-hola | |
104 | sleep 3 | |
105 | systemctl kill --signal=SIGKILL systemd-journald | |
106 | sleep 3 | |
107 | [[ ! -f "/i-lose-my-logs" ]] | |
108 | ||
1c36b4a7 | 109 | touch /testok |