selftests/ftrace: Add persistent ring buffer testcases

Add test cases for persistent ring buffer (reserve_mem= combined
with trace_instance=) and backup instance (trace_instance=backup=boot_map).

These test cases verify:
 - persistent-01-reserve-mem: Memory reservation via reserve_mem=
   and trace_instance=boot_map@trace. Verifies trace data retention in
   the boot_map instance across guest crash/reboot via sysrq-trigger.
 - persistent-02-backup-instance: Backup instance creation via
   trace_instance=backup=boot_map. Verifies that previous boot trace
   log is preserved in the backup instance on the subsequent boot.

These test cases specify '# REBOOT: 1' to enable multi-boot guest
crash/reboot testing with doubled QEMU timeout.

Link: https://lore.kernel.org/all/178649544683.438282.14573895196260214231.stgit@devnote2/

Assisted-by: LLM
Signed-off-by: Masami Hiramatsu (Google) <mhiramat@kernel.org>
This commit is contained in:
Masami Hiramatsu (Google) 2026-09-30 00:09:41 +09:00
parent 8dd296e4ec
commit 313cb5169f
4 changed files with 70 additions and 0 deletions

View File

@ -0,0 +1 @@
reserve_mem=12M:32M:trace trace_instance=boot_map@trace

View File

@ -0,0 +1 @@
reserve_mem=12M:32M:trace trace_instance=boot_map@trace trace_instance=backup=boot_map

View File

@ -0,0 +1,28 @@
#!/bin/sh
# SPDX-License-Identifier: GPL-2.0
# Copyright (C) 2026, Google LLC.
# Check persistent ring buffer across guest crash/reboot
# REBOOT: 1
TRACEDIR="/sys/kernel/tracing"
if [ ! -f "$TRACEDIR/instances/boot_map/trace" ]; then
echo "FAIL: persistent trace instance boot_map/trace file missing"
exit 1
fi
# Check if Boot 1 marker was already written
if grep -q "BOOT1_MARKER" "$TRACEDIR/instances/boot_map/trace" 2>/dev/null; then
# Second boot: verify persistent ring buffer content from first boot
echo "PASS: persistent-01-reserve-mem"
exit 0
fi
# First boot: write marker to persistent buffer and trigger kernel crash/reboot
echo "BOOT1_MARKER" > "$TRACEDIR/instances/boot_map/trace_marker"
sync
# Trigger reboot to restart into second boot
echo b > /proc/sysrq-trigger 2>/dev/null || echo c > /proc/sysrq-trigger 2>/dev/null || true
sleep 5
echo "FAIL: reboot trigger failed on first boot"
exit 1

View File

@ -0,0 +1,40 @@
#!/bin/sh
# SPDX-License-Identifier: GPL-2.0
# Copyright (C) 2026, Google LLC.
# Check persistent backup instance across guest crash/reboot
# REBOOT: 1
TRACEDIR="/sys/kernel/tracing"
# Ensure both boot_map/trace and backup/trace files exist
if [ ! -f "$TRACEDIR/instances/boot_map/trace" ]; then
echo "FAIL: boot_map/trace file missing"
exit 1
fi
if [ ! -f "$TRACEDIR/instances/backup/trace" ]; then
echo "FAIL: backup/trace file missing"
exit 1
fi
# Check if BOOT1_MARKER is in boot_map/trace (indicates second boot)
if grep -q "BOOT1_MARKER" "$TRACEDIR/instances/boot_map/trace" 2>/dev/null; then
# Second boot: verify BOOT1_MARKER was copied into backup/trace from Boot 1
if grep -q "BOOT1_MARKER" "$TRACEDIR/instances/backup/trace" 2>/dev/null; then
echo "PASS: persistent-02-backup-instance"
exit 0
else
echo "FAIL: BOOT1_MARKER found in boot_map/trace" \
"but missing from backup/trace on second boot"
exit 1
fi
fi
# First boot: write BOOT1_MARKER to boot_map and reboot via sysrq-trigger
echo "BOOT1_MARKER" > "$TRACEDIR/instances/boot_map/trace_marker"
sync
# Trigger reboot to restart into second boot
echo b > /proc/sysrq-trigger 2>/dev/null || echo c > /proc/sysrq-trigger 2>/dev/null || true
sleep 5
echo "FAIL: reboot trigger failed on first boot"
exit 1