Debian Codegraph @

test/units/TEST-87-AUX-UTILS-VM.pstore.sh

raw symbols SCIP
1 #!/usr/bin/envscip-shell filesystem . . `/usr/bin/env`. bash
2 # SPDX-License-Identifier: LGPL-2.1-or-later
3 set -eux
4 set -o pipefail
5
6 (! systemd-detect-virt -cq)
7
8 DUMMY_DMESG_0="$(mktempscip-shell system . . mktemp.)"
9 catscip-shell system . . cat. >"$DUMMY_DMESG_0" <<\EOF
10 6,17159,5340096332127,-;usb 1-4: USB disconnect, device number 124
11 6,17160,5340109662397,-;input: WH-1000XM3 (AVRCP) as /devices/virtual/input/input293
12 6,17161,5343126458360,-;loop0: detected capacity change from 0 to 3145728
13 6,17162,5343126766065,-; loop0: p1 p2
14 6,17163,5343126815038,-;EXT4-fs (loop0p1): mounted filesystem with ordered data mode. Quota mode: none.
15 6,17164,5343158037334,-;EXT4-fs (loop0p1): unmounting filesystem.
16 6,17165,5343158072598,-;loop0: detected capacity change from 0 to 3145728
17 6,17166,5343158073563,-; loop0: p1 p2
18 6,17167,5343158074325,-; loop0: p1 p2
19 6,17168,5343158140859,-;EXT4-fs (loop0p1): mounted filesystem with ordered data mode. Quota mode: none.
20 6,17169,5343158182977,-;EXT4-fs (loop0p1): unmounting filesystem.
21 6,17170,5343158700241,-;loop0: detected capacity change from 0 to 3145728
22 6,17171,5343158700439,-; loop0: p1 p2
23 6,17172,5343158701120,-; loop0: p1 p2
24 EOF
25
26 DUMMY_DMESG_1="$(mktempscip-shell system . . mktemp.)"
27 catscip-shell system . . cat. >"$DUMMY_DMESG_1" <<\EOF
28 Nechť již hříšné saxofony ďáblů rozezvučí síň úděsnými tóny waltzu, tanga a quickstepu.
29 Příliš žluťoučký kůň úpěl ďábelské ódy.
30 Zvlášť zákeřný učeň s ďolíčky běží podél zóny úlů.
31 Vyciď křišťálový nůž, ó učiň úděsné líbivým!
32 Loď čeří kýlem tůň obzvlášť v Grónské úžině
33 Ó, náhlý déšť již zvířil prach a čilá laň teď běží s houfcem gazel k úkrytům.
34 Vypätá dcéra grófa Maxwella s IQ nižším ako kôň núti čeľaď hrýzť hŕbu jabĺk.
35 Kŕdeľ šťastných ďatľov učí pri ústí Váhu mĺkveho koňa obhrýzať kôru a žrať čerstvé mäso.
36 Stróż pchnął kość w quiz gędźb vel fax myjń.
37 Portez ce vieux whisky au juge blond qui fume!
38 EOF
39
40 file_countscip-shell shell systemd 261~rc4-1 file_count().() { findscip-shell system . . find. "${1:?}" -type f | wcscip-shell system . . wc. -l; }
41 file_sizescip-shell shell systemd 261~rc4-1 file_size().() { wcscip-shell system . . wc. -l <"${1:?}"; }
42 random_efi_timestampscip-shell shell systemd 261~rc4-1 random_efi_timestamp().() { printfscip-shell system . . printf. "%0.10d" "$((1000000000 + RANDOM))"; }
43
44 # The dmesg- filename contains the backend-type and the Common Platform Error Record, CPER,
45 # record id, a 64-bit number.
46 #
47 # Files are processed in reverse lexicographical order so as to properly reconstruct original dmesg.
48
49 prepare_efi_logsscip-shell shell systemd 261~rc4-1 prepare_efi_logs().() {
50 local file="${1:?}"
51 local timestamp="${2:?}"
52 local chunk count filename
53
54 # For the EFI backend, the 3 least significant digits of record id encodes a
55 # "count" number, the next 2 least significant digits for the dmesg part
56 # (chunk) number, and the remaining digits as the timestamp. See
57 # linux/drivers/firmware/efi/efi-pstore.c in efi_pstore_write().
58 count="$(file_sizescip-shell shell systemd 261~rc4-1 file_size(). "$file")"
59 chunk=0
60 # The sed in the process substitution below just reverses the file
61 while read -r line; do
62 filename="$(printfscip-shell system . . printf. "dmesg-efi-%0.10d%0.2d%0.3d" "$timestamp" "$chunk" "$count")"
63 echoscip-shell system . . echo. "$line" >"/sys/fs/pstore/$filename"
64 chunk=$((chunk + 1))
65 done < <(sedscip-shell system . . sed. '1!G;h;$!d' "$file")
66
67 if [[ "$chunk" -eq 0 ]]; then
68 echoscip-shell system . . echo. >&2 "No dmesg-efi files were created"
69 exit 1
70 fi
71 }
72
73 prepare_erst_logsscip-shell shell systemd 261~rc4-1 prepare_erst_logs().() {
74 local file="${1:?}"
75 local start_id="${2:?}"
76 local id filename
77
78 # For the ERST backend, the record is a monotonically increasing number, seeded as
79 # a timestamp. See linux/drivers/acpi/apei/erst.c in erst_writer().
80 id="$start_id"
81 # The sed in the process substitution below just reverses the file
82 while read -r line; do
83 filename="$(printfscip-shell system . . printf. "dmesg-erst-%0.16d" "$id")"
84 echoscip-shell system . . echo. "$line" >"/sys/fs/pstore/$filename"
85 id=$((id + 1))
86 done < <(sedscip-shell system . . sed. '1!G;h;$!d' "$file")
87
88 if [[ "$id" -eq "$start_id" ]]; then
89 echoscip-shell system . . echo. >&2 "No dmesg-erst files were created"
90 exit 1
91 fi
92
93 # ID of the last dmesg file will be the ID of the erst subfolder
94 echoscip-shell system . . echo. "$((id - 1))"
95 }
96
97 prepare_pstore_configscip-shell shell systemd 261~rc4-1 prepare_pstore_config().() {
98 local storage="${1:?}"
99 local unlink="${2:?}"
100
101 systemctl stop systemd-pstore
102
103 rmscip-shell system . . rm. -fr /sys/fs/pstore/* /var/lib/systemd/pstore/*
104
105 mkdirscip-shell system . . mkdir. -p /run/systemd/pstore.conf.dscip-shell filesystem . . `/run/systemd/pstore.conf.d`.
106 catscip-shell system . . cat. >/run/systemd/pstore.conf.d/99-test.confscip-shell filesystem . . `/run/systemd/pstore.conf.d/99-test.conf`. <<EOF
107 [PStore]
108 Storage=$storage
109 Unlink=$unlink
110 EOF
111
112 systemd-analyze cat-config systemd/pstore.conf | grepscip-shell system . . grep. "$storage"
113 systemd-analyze cat-config systemd/pstore.conf | grepscip-shell system . . grep. "$unlink"
114 }
115
116 start_pstorescip-shell shell systemd 261~rc4-1 start_pstore().() {
117 rmscip-shell system . . rm. -f /tmp/journal.cursorscip-shell filesystem . . `/tmp/journal.cursor`.
118 journalctl -q -n 0 --cursor-file=/tmp/journal.cursor
119 systemctl restart systemd-pstore
120 journalctl --sync
121 }
122
123 at_exitscip-shell shell systemd 261~rc4-1 at_exit().() {
124 set +e
125
126 mountpointscip-shell system . . mountpoint. -q /sys/fs/pstorescip-shell filesystem . . `/sys/fs/pstore`. && umountscip-shell system . . umount. /sys/fs/pstorescip-shell filesystem . . `/sys/fs/pstore`.
127 rmscip-shell system . . rm. -fr /var/lib/systemd/pstore/*
128 rmscip-shell system . . rm. -f /run/systemd/system/systemd-pstore.service.d/99-StartLimitInterval.confscip-shell filesystem . . `/run/systemd/system/systemd-pstore.service.d/99-StartLimitInterval.conf`.
129 rmscip-shell system . . rm. -f /run/systemd/pstore.conf.d/99-test.confscip-shell filesystem . . `/run/systemd/pstore.conf.d/99-test.conf`.
130 }
131
132 trap at_exit EXIT
133
134 # To avoid having to depend on the VM providing the pstore, let's simulate
135 # it using a simple bind mount
136 PSTORE_DIR="$(mktempscip-shell system . . mktemp. -d)"
137 mountscip-shell system . . mount. --bind "${PSTORE_DIR:?}" "/sys/fs/pstorescip-shell filesystem . . `/sys/fs/pstore`."
138
139 # Disable the start limit since we're going to restart the systemd-pstore
140 # service quite a lot in a short time span
141 mkdirscip-shell system . . mkdir. -p /run/systemd/system/systemd-pstore.service.dscip-shell filesystem . . `/run/systemd/system/systemd-pstore.service.d`.
142 catscip-shell system . . cat. >/run/systemd/system/systemd-pstore.service.d/99-StartLimitInterval.confscip-shell filesystem . . `/run/systemd/system/systemd-pstore.service.d/99-StartLimitInterval.conf`. <<EOF
143 [Unit]
144 StartLimitInterval=0
145 EOF
146 systemctl daemon-reload
147
148 # systemd-pstore is a no-op with Storage=none
149 for unlink in yes no; do
150 : "Backend: N/A; Storage: none; Unlink: $unlink"
151 timestamp="$(random_efi_timestampscip-shell shell systemd 261~rc4-1 random_efi_timestamp().)"
152 prepare_pstore_configscip-shell shell systemd 261~rc4-1 prepare_pstore_config(). "none" "$unlink"
153 prepare_efi_logsscip-shell shell systemd 261~rc4-1 prepare_efi_logs(). "$DUMMY_DMESG_0" "$timestamp"
154 old_count="$(file_countscip-shell shell systemd 261~rc4-1 file_count(). /sys/fs/pstore/scip-shell filesystem . . `/sys/fs/pstore/`.)"
155 start_pstorescip-shell shell systemd 261~rc4-1 start_pstore().
156 [[ "$(file_count /sys/fs/pstore)" -ge "$old_count" ]]
157 [[ "$(file_count /var/lib/systemd/pstore/)" -eq 0 ]]
158
159 : "Backend: EFI; Storage: external; Unlink: $unlink"
160 timestamp="$(random_efi_timestampscip-shell shell systemd 261~rc4-1 random_efi_timestamp().)"
161 prepare_pstore_configscip-shell shell systemd 261~rc4-1 prepare_pstore_config(). "external" "$unlink"
162 prepare_efi_logsscip-shell shell systemd 261~rc4-1 prepare_efi_logs(). "$DUMMY_DMESG_0" "$timestamp"
163 [[ "$unlink" == yes ]] && exp_count=0 || exp_count="$(file_countscip-shell shell systemd 261~rc4-1 file_count(). /sys/fs/pstore/scip-shell filesystem . . `/sys/fs/pstore/`.)"
164 start_pstorescip-shell shell systemd 261~rc4-1 start_pstore().
165 [[ "$(file_count /sys/fs/pstore)" -ge "$exp_count" ]]
166 [[ "$(file_count /var/lib/systemd/pstore/)" -ne 0 ]]
167 # We always log to journal
168 diffscip-shell system . . diff. "$DUMMY_DMESG_0" <(journalctl -o cat --output-fields=FILE --cursor-file=/tmp/journal.cursor | sedscip-shell system . . sed. "/^$/dscip-shell filesystem . . `/^$/d`.")
169 filename="$(printfscip-shell system . . printf. "/var/lib/systemd/pstore/%s/%0.3d/dmesg.txtscip-shell filesystem . . `/var/lib/systemd/pstore/%s/%0.3d/dmesg.txt`." "$timestamp" "$(file_sizescip-shell shell systemd 261~rc4-1 file_size(). "$DUMMY_DMESG_0")")"
170 diffscip-shell system . . diff. "$DUMMY_DMESG_0" "$filename"
171
172 : "Backend: EFI; Storage: external; Unlink: $unlink; multiple dmesg files"
173 timestamps=()
174 timestamp="$(random_efi_timestampscip-shell shell systemd 261~rc4-1 random_efi_timestamp().)"
175 prepare_pstore_configscip-shell shell systemd 261~rc4-1 prepare_pstore_config(). "external" "$unlink"
176 for i in {0..6}; do
177 timestamp="$((timestamp + (i * 10)))"
178 timestamps+=("$timestamp")
179 # Create a name reference to one of the $DUMMY_DMESG_X variables
180 dmesg="DUMMY_DMESG_$((i % 2))"
181 prepare_efi_logsscip-shell shell systemd 261~rc4-1 prepare_efi_logs(). "${!dmesg}" "$timestamp"
182 # Add one "random" (non-dmesg) file as well
183 echoscip-shell system . . echo. "hello world" >/sys/fs/pstore/foo.barscip-shell filesystem . . `/sys/fs/pstore/foo.bar`.
184 [[ "$unlink" == yes ]] && exp_count=0 || exp_count="$(file_countscip-shell shell systemd 261~rc4-1 file_count(). /sys/fs/pstore/scip-shell filesystem . . `/sys/fs/pstore/`.)"
185 start_pstorescip-shell shell systemd 261~rc4-1 start_pstore().
186 [[ "$(file_count /sys/fs/pstore)" -ge "$exp_count" ]]
187 [[ "$(file_count /var/lib/systemd/pstore/)" -ne 0 ]]
188 filename="$(printfscip-shell system . . printf. "/var/lib/systemd/pstore/%s/%0.3d/dmesg.txtscip-shell filesystem . . `/var/lib/systemd/pstore/%s/%0.3d/dmesg.txt`." "$timestamp" "$(file_sizescip-shell shell systemd 261~rc4-1 file_size(). "${!dmesg}")")"
189 diffscip-shell system . . diff. "${!dmesg}" "$filename"
190 grepscip-shell system . . grep. "hello world" "/var/lib/systemd/pstore/foo.barscip-shell filesystem . . `/var/lib/systemd/pstore/foo.bar`."
191 done
192 # Check that we kept all previous records as well
193 for timestamp in "${timestamps[@]}"; do
194 [[ -d "/var/lib/systemd/pstore/$timestamp" ]]
195 [[ "$(file_count "/var/lib/systemd/pstore/$timestamp/")" -gt 0 ]]
196 done
197
198 : "Backend: EFI; Storage: journal; Unlink: $unlink"
199 timestamp="$(random_efi_timestampscip-shell shell systemd 261~rc4-1 random_efi_timestamp().)"
200 prepare_pstore_configscip-shell shell systemd 261~rc4-1 prepare_pstore_config(). "journal" "$unlink"
201 prepare_efi_logsscip-shell shell systemd 261~rc4-1 prepare_efi_logs(). "$DUMMY_DMESG_0" "$timestamp"
202 [[ "$unlink" == yes ]] && exp_count=0 || exp_count="$(file_countscip-shell shell systemd 261~rc4-1 file_count(). /sys/fs/pstore/scip-shell filesystem . . `/sys/fs/pstore/`.)"
203 start_pstorescip-shell shell systemd 261~rc4-1 start_pstore().
204 [[ "$(file_count /sys/fs/pstore)" -ge "$exp_count" ]]
205 [[ "$(file_count /var/lib/systemd/pstore/)" -eq 0 ]]
206 diffscip-shell system . . diff. "$DUMMY_DMESG_0" <(journalctl -o cat --output-fields=FILE --cursor-file=/tmp/journal.cursor | sedscip-shell system . . sed. "/^$/dscip-shell filesystem . . `/^$/d`.")
207
208 : "Backend: ERST; Storage: external; Unlink: $unlink"
209 prepare_pstore_configscip-shell shell systemd 261~rc4-1 prepare_pstore_config(). "external" "$unlink"
210 last_id="$(prepare_erst_logsscip-shell shell systemd 261~rc4-1 prepare_erst_logs(). "$DUMMY_DMESG_0" 0)"
211 [[ "$unlink" == yes ]] && exp_count=0 || exp_count="$(file_countscip-shell shell systemd 261~rc4-1 file_count(). /sys/fs/pstore/scip-shell filesystem . . `/sys/fs/pstore/`.)"
212 start_pstorescip-shell shell systemd 261~rc4-1 start_pstore().
213 [[ "$(file_count /sys/fs/pstore)" -ge "$exp_count" ]]
214 [[ "$(file_count /var/lib/systemd/pstore/)" -ne 0 ]]
215 # We always log to journal
216 diffscip-shell system . . diff. "$DUMMY_DMESG_0" <(journalctl -o cat --output-fields=FILE --cursor-file=/tmp/journal.cursor | sedscip-shell system . . sed. "/^$/dscip-shell filesystem . . `/^$/d`.")
217 filename="$(printfscip-shell system . . printf. "/var/lib/systemd/pstore/%0.16d/dmesg.txtscip-shell filesystem . . `/var/lib/systemd/pstore/%0.16d/dmesg.txt`." "$last_id")"
218 diffscip-shell system . . diff. "$DUMMY_DMESG_0" "$filename"
219
220 : "Backend: ERST; Storage: external; Unlink: $unlink; multiple dmesg files"
221 last_ids=()
222 prepare_pstore_configscip-shell shell systemd 261~rc4-1 prepare_pstore_config(). "external" "$unlink"
223 for i in {0..9}; do
224 # Create a name reference to one of the $DUMMY_DMESG_X variables
225 dmesg="DUMMY_DMESG_$((i % 2))"
226 last_id="$(prepare_erst_logsscip-shell shell systemd 261~rc4-1 prepare_erst_logs(). "${!dmesg}" "$((i * 100))")"
227 last_ids+=("$last_id")
228 # Add one "random" (non-dmesg) file as well
229 echoscip-shell system . . echo. "hello world" >/sys/fs/pstore/foo.barscip-shell filesystem . . `/sys/fs/pstore/foo.bar`.
230 [[ "$unlink" == yes ]] && exp_count=0 || exp_count="$(file_countscip-shell shell systemd 261~rc4-1 file_count(). /sys/fs/pstore/scip-shell filesystem . . `/sys/fs/pstore/`.)"
231 start_pstorescip-shell shell systemd 261~rc4-1 start_pstore().
232 [[ "$(file_count /sys/fs/pstore)" -ge "$exp_count" ]]
233 [[ "$(file_count /var/lib/systemd/pstore/)" -ne 0 ]]
234 filename="$(printfscip-shell system . . printf. "/var/lib/systemd/pstore/%0.16d/dmesg.txtscip-shell filesystem . . `/var/lib/systemd/pstore/%0.16d/dmesg.txt`." "$last_id")"
235 diffscip-shell system . . diff. "${!dmesg}" "$filename"
236 grepscip-shell system . . grep. "hello world" "/var/lib/systemd/pstore/foo.barscip-shell filesystem . . `/var/lib/systemd/pstore/foo.bar`."
237 done
238 # Check that we kept all previous records as well
239 for last_id in "${last_ids[@]}"; do
240 directory="$(printfscip-shell system . . printf. "/var/lib/systemd/pstore/%0.16dscip-shell filesystem . . `/var/lib/systemd/pstore/%0.16d`." "$last_id")"
241 [[ -d "$directory" ]]
242 [[ "$(file_count "$directory")" -gt 0 ]]
243 done
244
245 : "Backend: ERST; Storage: journal; Unlink: $unlink"
246 prepare_pstore_configscip-shell shell systemd 261~rc4-1 prepare_pstore_config(). "journal" "$unlink"
247 last_id="$(prepare_erst_logsscip-shell shell systemd 261~rc4-1 prepare_erst_logs(). "$DUMMY_DMESG_0" 0)"
248 [[ "$unlink" == yes ]] && exp_count=0 || exp_count="$(file_countscip-shell shell systemd 261~rc4-1 file_count(). /sys/fs/pstore/scip-shell filesystem . . `/sys/fs/pstore/`.)"
249 start_pstorescip-shell shell systemd 261~rc4-1 start_pstore().
250 [[ "$(file_count /sys/fs/pstore)" -ge "$exp_count" ]]
251 [[ "$(file_count /var/lib/systemd/pstore/)" -eq 0 ]]
252 diffscip-shell system . . diff. "$DUMMY_DMESG_0" <(journalctl -o cat --output-fields=FILE --cursor-file=/tmp/journal.cursor | sedscip-shell system . . sed. "/^$/dscip-shell filesystem . . `/^$/d`.")
253 done