[PATCH v4 11/18] perf test test_task_analyzer: Isolate in temporary directory and make non-exclusive

From: Ian Rogers

Date: Fri Sep 18 2026 - 17:21:18 EST


test_task_analyzer.sh writes perf.data and temporary files directly into
the current working directory, causing collisions when running tests in
parallel.

As a temporary measure until `perf script report` supports an input file
option, resolve perfdir to an absolute path, change directory into $tmpdir
for the test duration, and clean up in the exit trap. Remove the
(exclusive) tag so the test runs in parallel.

perfdir is derived from $0, which may be relative, so it has to be
resolved before the cd into $tmpdir, otherwise both PERF_EXEC_PATH and
the cleanup trap point at paths that no longer exist.

Assisted-by: Antigravity:gemini-3.1-pro
Signed-off-by: Ian Rogers <irogers@xxxxxxxxxx>
---
tools/perf/tests/shell/test_task_analyzer.sh | 20 +++++++++++++++-----
1 file changed, 15 insertions(+), 5 deletions(-)

diff --git a/tools/perf/tests/shell/test_task_analyzer.sh b/tools/perf/tests/shell/test_task_analyzer.sh
index 0314412e63b4..443b88957b17 100755
--- a/tools/perf/tests/shell/test_task_analyzer.sh
+++ b/tools/perf/tests/shell/test_task_analyzer.sh
@@ -1,8 +1,18 @@
#!/bin/bash
-# perf script task-analyzer tests (exclusive)
+# perf script task-analyzer tests
# SPDX-License-Identifier: GPL-2.0

-tmpdir=$(mktemp -d /tmp/perf-script-task-analyzer-XXXXX)
+# Resolve the source directory before changing the working directory below,
+# $0 may be a relative path and would no longer resolve from $tmpdir.
+perfdir=$(cd "$(dirname "$0")/../.." && pwd)
+
+tmpdir=$(mktemp -d /tmp/perf-script-task-analyzer-XXXXX) || exit 1
+# The cleanup trap is only installed further down, once the functions it
+# calls have been defined, so tidy up by hand if this cd fails.
+cd "$tmpdir" || {
+ rmdir "$tmpdir"
+ exit 1
+}
# TODO: perf script report only supports input from the CWD perf.data file, make
# it support input from any file.
perfdata="perf.data"
@@ -11,7 +21,6 @@ csvsummary="$tmpdir/csvsummary"
err=0

# set PERF_EXEC_PATH to find scripts in the source directory
-perfdir=$(dirname "$0")/../..
if [ -e "$perfdir/scripts/python/Perf-Trace-Util" ]; then
export PERF_EXEC_PATH=$perfdir
fi
@@ -20,8 +29,9 @@ fi
export ASAN_OPTIONS=detect_leaks=0

cleanup() {
- rm -f "${perfdata}"
- rm -f "${perfdata}".old
+ # Step out of $tmpdir before removing it. The removal uses an absolute
+ # path and works from anywhere, so a failure to cd must not skip it.
+ cd "$perfdir" || cd / || true
rm -rf "$tmpdir"

trap - exit term int
--
2.55.0.1082.g2b9226bbc0-goog