test: make the multiple-file test more thorough

Let's check if we keep the old records after multiple systemd-pstore
invocations (i.e. simulate a scenario where we get multiple crashes and
multiple machine reboots).
This commit is contained in:
Frantisek Sumsal 2023-06-01 20:02:20 +02:00
parent 45a6a2aace
commit 6178ced491

View file

@ -10,8 +10,8 @@ if systemd-detect-virt -cq; then
exit 0
fi
DUMMY_DMESG_1="$(mktemp)"
cat >"$DUMMY_DMESG_1" <<\EOF
DUMMY_DMESG_0="$(mktemp)"
cat >"$DUMMY_DMESG_0" <<\EOF
6,17159,5340096332127,-;usb 1-4: USB disconnect, device number 124
6,17160,5340109662397,-;input: WH-1000XM3 (AVRCP) as /devices/virtual/input/input293
6,17161,5343126458360,-;loop0: detected capacity change from 0 to 3145728
@ -28,8 +28,8 @@ cat >"$DUMMY_DMESG_1" <<\EOF
6,17172,5343158701120,-; loop0: p1 p2
EOF
DUMMY_DMESG_2="$(mktemp)"
cat >"$DUMMY_DMESG_2" <<\EOF
DUMMY_DMESG_1="$(mktemp)"
cat >"$DUMMY_DMESG_1" <<\EOF
Nechť již hříšné saxofony ďáblů rozezvučí síň úděsnými tóny waltzu, tanga a quickstepu.
Příliš žluťoučký kůň úpěl ďábelské ódy.
Zvlášť zákeřný učeň s ďolíčky běží podél zóny úlů.
@ -108,7 +108,7 @@ prepare_pstore_config() {
rm -fr /sys/fs/pstore/* /var/lib/systemd/pstore/*
mkdir -p /run/systemd/pstore.conf.d
cat >"/run/systemd/pstore.conf.d/99-test.conf" <<EOF
cat >/run/systemd/pstore.conf.d/99-test.conf <<EOF
[PStore]
Storage=$storage
Unlink=$unlink
@ -121,7 +121,7 @@ EOF
start_pstore() {
rm -f /tmp/journal.cursor
journalctl -q -n 0 --cursor-file=/tmp/journal.cursor
systemctl start systemd-pstore
systemctl restart systemd-pstore
journalctl --sync
}
@ -130,12 +130,21 @@ start_pstore() {
PSTORE_DIR="$(mktemp -d)"
mount --bind "${PSTORE_DIR:?}" "/sys/fs/pstore"
# Disable the start limit since we're going to restart the systemd-pstore
# service quite a lot in a short time span
mkdir -p /run/systemd/system/systemd-pstore.service.d
cat >/run/systemd/system/systemd-pstore.service.d/99-StartLimitInterval.conf <<EOF
[Unit]
StartLimitInterval=0
EOF
systemctl daemon-reload
# systemd-pstore is a no-op with Storage=none
for unlink in yes no; do
: "Backend: N/A; Storage: none; Unlink: $unlink"
timestamp="$(random_efi_timestamp)"
prepare_pstore_config "none" "$unlink"
prepare_efi_logs "$DUMMY_DMESG_1" "$timestamp"
prepare_efi_logs "$DUMMY_DMESG_0" "$timestamp"
old_count="$(file_count /sys/fs/pstore/)"
start_pstore
[[ "$(file_count /sys/fs/pstore)" -ge "$old_count" ]]
@ -144,78 +153,95 @@ for unlink in yes no; do
: "Backend: EFI; Storage: external; Unlink: $unlink"
timestamp="$(random_efi_timestamp)"
prepare_pstore_config "external" "$unlink"
prepare_efi_logs "$DUMMY_DMESG_1" "$timestamp"
prepare_efi_logs "$DUMMY_DMESG_0" "$timestamp"
[[ "$unlink" == yes ]] && exp_count=0 || exp_count="$(file_count /sys/fs/pstore/)"
start_pstore
[[ "$(file_count /sys/fs/pstore)" -ge "$exp_count" ]]
[[ "$(file_count /var/lib/systemd/pstore/)" -ne 0 ]]
# We always log to journal
diff "$DUMMY_DMESG_1" <(journalctl -o cat --output-fields=FILE --cursor-file=/tmp/journal.cursor | sed "/^$/d")
filename="$(printf "/var/lib/systemd/pstore/%s/%0.3d/dmesg.txt" "$timestamp" "$(file_size "$DUMMY_DMESG_1")")"
diff "$DUMMY_DMESG_1" "$filename"
diff "$DUMMY_DMESG_0" <(journalctl -o cat --output-fields=FILE --cursor-file=/tmp/journal.cursor | sed "/^$/d")
filename="$(printf "/var/lib/systemd/pstore/%s/%0.3d/dmesg.txt" "$timestamp" "$(file_size "$DUMMY_DMESG_0")")"
diff "$DUMMY_DMESG_0" "$filename"
: "Backend: EFI; Storage: external; Unlink: $unlink; multiple dmesg files"
timestamp_1="$(random_efi_timestamp)"
timestamp_2="$((timestamp_1 + 1))"
timestamps=()
timestamp="$(random_efi_timestamp)"
prepare_pstore_config "external" "$unlink"
prepare_efi_logs "$DUMMY_DMESG_1" "$timestamp_1"
prepare_efi_logs "$DUMMY_DMESG_2" "$timestamp_2"
# Add one "random" (non-dmesg) file as well
echo "hello world" >/sys/fs/pstore/foo.bar
[[ "$unlink" == yes ]] && exp_count=0 || exp_count="$(file_count /sys/fs/pstore/)"
start_pstore
[[ "$(file_count /sys/fs/pstore)" -ge "$exp_count" ]]
[[ "$(file_count /var/lib/systemd/pstore/)" -ne 0 ]]
filename_1="$(printf "/var/lib/systemd/pstore/%s/%0.3d/dmesg.txt" "$timestamp_1" "$(file_size "$DUMMY_DMESG_1")")"
diff "$DUMMY_DMESG_1" "$filename_1"
filename_2="$(printf "/var/lib/systemd/pstore/%s/%0.3d/dmesg.txt" "$timestamp_2" "$(file_size "$DUMMY_DMESG_2")")"
diff "$DUMMY_DMESG_2" "$filename_2"
grep "hello world" "/var/lib/systemd/pstore/foo.bar"
for i in {0..6}; do
timestamp="$((timestamp + (i * 10)))"
timestamps+=("$timestamp")
# Create a name reference to one of the $DUMMY_DMESG_X variables
dmesg="DUMMY_DMESG_$((i % 2))"
prepare_efi_logs "${!dmesg}" "$timestamp"
# Add one "random" (non-dmesg) file as well
echo "hello world" >/sys/fs/pstore/foo.bar
[[ "$unlink" == yes ]] && exp_count=0 || exp_count="$(file_count /sys/fs/pstore/)"
start_pstore
[[ "$(file_count /sys/fs/pstore)" -ge "$exp_count" ]]
[[ "$(file_count /var/lib/systemd/pstore/)" -ne 0 ]]
filename="$(printf "/var/lib/systemd/pstore/%s/%0.3d/dmesg.txt" "$timestamp" "$(file_size "${!dmesg}")")"
diff "${!dmesg}" "$filename"
grep "hello world" "/var/lib/systemd/pstore/foo.bar"
done
# Check that we kept all previous records as well
for timestamp in "${timestamps[@]}"; do
[[ -d "/var/lib/systemd/pstore/$timestamp" ]]
[[ "$(file_count "/var/lib/systemd/pstore/$timestamp/")" -gt 0 ]]
done
: "Backend: EFI; Storage: journal; Unlink: $unlink"
timestamp="$(random_efi_timestamp)"
prepare_pstore_config "journal" "$unlink"
prepare_efi_logs "$DUMMY_DMESG_1" "$timestamp"
prepare_efi_logs "$DUMMY_DMESG_0" "$timestamp"
[[ "$unlink" == yes ]] && exp_count=0 || exp_count="$(file_count /sys/fs/pstore/)"
start_pstore
[[ "$(file_count /sys/fs/pstore)" -ge "$exp_count" ]]
[[ "$(file_count /var/lib/systemd/pstore/)" -eq 0 ]]
diff "$DUMMY_DMESG_1" <(journalctl -o cat --output-fields=FILE --cursor-file=/tmp/journal.cursor | sed "/^$/d")
diff "$DUMMY_DMESG_0" <(journalctl -o cat --output-fields=FILE --cursor-file=/tmp/journal.cursor | sed "/^$/d")
: "Backend: ERST; Storage: external; Unlink: $unlink"
prepare_pstore_config "external" "$unlink"
last_id="$(prepare_erst_logs "$DUMMY_DMESG_1" 0)"
last_id="$(prepare_erst_logs "$DUMMY_DMESG_0" 0)"
[[ "$unlink" == yes ]] && exp_count=0 || exp_count="$(file_count /sys/fs/pstore/)"
start_pstore
[[ "$(file_count /sys/fs/pstore)" -ge "$exp_count" ]]
[[ "$(file_count /var/lib/systemd/pstore/)" -ne 0 ]]
# We always log to journal
diff "$DUMMY_DMESG_1" <(journalctl -o cat --output-fields=FILE --cursor-file=/tmp/journal.cursor | sed "/^$/d")
diff "$DUMMY_DMESG_0" <(journalctl -o cat --output-fields=FILE --cursor-file=/tmp/journal.cursor | sed "/^$/d")
filename="$(printf "/var/lib/systemd/pstore/%0.16d/dmesg.txt" "$last_id")"
diff "$DUMMY_DMESG_1" "$filename"
diff "$DUMMY_DMESG_0" "$filename"
: "Backend: ERST; Storage: external; Unlink: $unlink; multiple dmesg files"
last_ids=()
prepare_pstore_config "external" "$unlink"
last_id_1="$(prepare_erst_logs "$DUMMY_DMESG_1" 0)"
last_id_2="$(prepare_erst_logs "$DUMMY_DMESG_2" "$((last_id_1 + 10))")"
# Add one "random" (non-dmesg) file as well
echo "hello world" >/sys/fs/pstore/foo.bar
[[ "$unlink" == yes ]] && exp_count=0 || exp_count="$(file_count /sys/fs/pstore/)"
start_pstore
[[ "$(file_count /sys/fs/pstore)" -ge "$exp_count" ]]
[[ "$(file_count /var/lib/systemd/pstore/)" -ne 0 ]]
filename_1="$(printf "/var/lib/systemd/pstore/%0.16d/dmesg.txt" "$last_id_1")"
diff "$DUMMY_DMESG_1" "$filename_1"
filename_2="$(printf "/var/lib/systemd/pstore/%0.16d/dmesg.txt" "$last_id_2")"
diff "$DUMMY_DMESG_2" "$filename_2"
grep "hello world" "/var/lib/systemd/pstore/foo.bar"
for i in {0..9}; do
# Create a name reference to one of the $DUMMY_DMESG_X variables
dmesg="DUMMY_DMESG_$((i % 2))"
last_id="$(prepare_erst_logs "${!dmesg}" "$((i * 100))")"
last_ids+=("$last_id")
# Add one "random" (non-dmesg) file as well
echo "hello world" >/sys/fs/pstore/foo.bar
[[ "$unlink" == yes ]] && exp_count=0 || exp_count="$(file_count /sys/fs/pstore/)"
start_pstore
[[ "$(file_count /sys/fs/pstore)" -ge "$exp_count" ]]
[[ "$(file_count /var/lib/systemd/pstore/)" -ne 0 ]]
filename="$(printf "/var/lib/systemd/pstore/%0.16d/dmesg.txt" "$last_id")"
diff "${!dmesg}" "$filename"
grep "hello world" "/var/lib/systemd/pstore/foo.bar"
done
# Check that we kept all previous records as well
for last_id in "${last_ids[@]}"; do
directory="$(printf "/var/lib/systemd/pstore/%0.16d" "$last_id")"
[[ -d "$directory" ]]
[[ "$(file_count "$directory")" -gt 0 ]]
done
: "Backend: ERST; Storage: journal; Unlink: $unlink"
prepare_pstore_config "journal" "$unlink"
last_id="$(prepare_erst_logs "$DUMMY_DMESG_1" 0)"
last_id="$(prepare_erst_logs "$DUMMY_DMESG_0" 0)"
[[ "$unlink" == yes ]] && exp_count=0 || exp_count="$(file_count /sys/fs/pstore/)"
start_pstore
[[ "$(file_count /sys/fs/pstore)" -ge "$exp_count" ]]
[[ "$(file_count /var/lib/systemd/pstore/)" -eq 0 ]]
diff "$DUMMY_DMESG_1" <(journalctl -o cat --output-fields=FILE --cursor-file=/tmp/journal.cursor | sed "/^$/d")
diff "$DUMMY_DMESG_0" <(journalctl -o cat --output-fields=FILE --cursor-file=/tmp/journal.cursor | sed "/^$/d")
done