xref: /linux/tools/perf/tests/shell/coresight/raw_dump_stress.sh (revision efe86f088f48f18c27b648e5724048947f3b7fb4)
1#!/bin/bash -e
2# CoreSight raw dump stress (exclusive)
3
4# SPDX-License-Identifier: GPL-2.0
5
6if [ "$(id -u)" != 0 ]; then
7	# Requires root for larger buffer size
8	echo "[Skip] No root permission"
9	exit 2
10fi
11
12# If CoreSight is not available, skip the test
13perf list pmu | grep -q cs_etm || exit 2
14
15tmpdir=$(mktemp -d /tmp/__perf_test.coresight_raw_dump_stress.XXXXX)
16
17cleanup() {
18	rm -r "${tmpdir}"
19	trap - EXIT TERM INT
20}
21
22trap_cleanup() {
23	cleanup
24	exit 1
25}
26trap trap_cleanup EXIT TERM INT
27
28# Use exit snapshot to record 2M of trace to make about 80MB of raw dump data.
29echo "Recording..."
30perf record -e cs_etm/timestamp=0/u -m,2M -Se -o "$tmpdir/data" -- \
31	perf test -w brstack 20000 > /dev/null 2>&1
32
33# Test raw dump runs to completion but don't decode because that's too slow for
34# a test
35echo "Dumping raw trace..."
36perf report --dump-raw-trace -i "$tmpdir/data" 2>/dev/null > "$tmpdir/rawdump"
37
38# Get the size and offset of the first AUXTRACE buffer and the index of the last
39# packet in the raw dump.
40read -r size offset last_idx <<< "$(awk '
41	found && /PERF_RECORD_/ { exit }
42	/PERF_RECORD_AUXTRACE / { found = 1; size = $7; offset = $9; next }
43	found && /Idx:/ { last_idx = $1; gsub(/Idx:|;/, "", last_idx) }
44	END { if (last_idx) print size, offset, last_idx }
45' "$tmpdir/rawdump")"
46
47# The last Idx minus start offset should equal the size of the buffer if
48# everything was dumped. Allow 48 bytes difference to cover 3 frames: current
49# frame length, a partial frame and a final empty one, all of which aren't
50# dumped.
51#
52# TODO: for a single snapshot, offset should always be zero. However, we
53# currently output AUX records in snapshot mode when we shouldn't, which
54# increments the offset. Allow for that until it's fixed so we can test raw
55# dumping.
56decode_size=$((1 + last_idx - offset))
57if [ "$decode_size" -gt "$((size - 48))" ] && [ "$decode_size" -le "$((size))" ]; then
58	echo "PASS: AUXTRACE buffer length matches dumped packet index"
59	cleanup
60	exit 0
61fi
62
63echo "FAIL: AUXTRACE buffer length mismatch: size=$size offset=$offset last_idx=$last_idx decode_size=$decode_size"
64cleanup
65exit 1
66