Launch something that has multiple child threads, attach to it and make sure that all child threads are present in the samples
This will only work with 1:1 sinks/sources, and looking for TRBE is an easy way to guarantee this. In theory this could also work for ETR sinks, but we'd have to attempt to record and skip if that fails, which would make the test silently skip if the record command started failing on TRBE too.
Signed-off-by: James Clark james.clark@linaro.org --- .../perf/tests/shell/coresight/per-thread-multi.sh | 76 ++++++++++++++++++++++ 1 file changed, 76 insertions(+)
diff --git a/tools/perf/tests/shell/coresight/per-thread-multi.sh b/tools/perf/tests/shell/coresight/per-thread-multi.sh new file mode 100755 index 000000000000..c6bf1ff2e53d --- /dev/null +++ b/tools/perf/tests/shell/coresight/per-thread-multi.sh @@ -0,0 +1,76 @@ +#!/bin/bash -e +# CoreSight per-thread multiple threads (exclusive) + +# SPDX-License-Identifier: GPL-2.0 + +# If CoreSight is not available, skip the test +perf list pmu | grep -q cs_etm || exit 2 + +if ! tmpdir=$(mktemp -d /tmp/perf-cs-per-thread-multi-test.XXXXXX); then + echo "mktemp failed" + exit 1 +fi + +cleanup_files() +{ + if [[ $parent ]]; then + kill -9 $parent + wait $parent || true + fi + if [[ $perf ]]; then + kill -9 $perf + wait $perf || true + fi + rm -rf "$tmpdir" + trap - EXIT TERM INT +} + +trap cleanup_files EXIT +trap 'cleanup_files; exit 1' TERM INT + +# Multiple --per-thread events are only supported with 1:1 sinks/sources +if ! ls /sys/bus/coresight/devices/trbe* > /dev/null 2>&1; then + echo "No TRBE sinks, skipping" + exit 2 +fi + +# Launch 2 threads to run indefinitely +nthreads=2 +perf test -w named_threads $nthreads 0 & +parent=$! + +# While parent still exists, wait for the 2 children to spawn +while kill -0 "$parent" 2>/dev/null; do + threads=(/proc/"$parent"/task/*) + + if (( ${#threads[@]} >= $(($nthreads + 1)))); then + break + fi + + sleep 0.1 +done + +echo "Recording..." +perf record -o "$tmpdir/data" -e cs_etm//u --per-thread -Se -m,64K --pid $parent > /dev/null 2>&1 & +perf=$! + +sleep 1 + +kill $parent +wait $parent || true +unset parent +wait $perf +unset perf + +echo "Decoding..." +perf script -i "$tmpdir/data" > "$tmpdir/script" 2>/dev/null + +# Check all threads were traced and they have the correct thread name and symbol +for i in $(seq 1 $nthreads); do + if ! grep -q "thread${i} .* named_threads_thread${i}" "$tmpdir/script"; then + echo "Error: thread${i} missing" >&2 + exit 1 + fi +done + +exit 0