]> git.ipfire.org Git - thirdparty/kernel/linux.git/commitdiff
perf tests sched stats: Write output to temp file
authorIan Rogers <irogers@google.com>
Sat, 21 Mar 2026 06:14:48 +0000 (23:14 -0700)
committerNamhyung Kim <namhyung@kernel.org>
Mon, 6 Apr 2026 05:21:42 +0000 (22:21 -0700)
Writing to the perf.data file can fail in various contexts such as
continual test. Other tests write to a mktemp-ed file, make the "perf
sched stats tests" follow this convention.

Signed-off-by: Ian Rogers <irogers@google.com>
Tested-by: Swapnil Sapkal <swapnil.sapkal@amd.com>
Signed-off-by: Namhyung Kim <namhyung@kernel.org>
tools/perf/tests/shell/perf_sched_stats.sh

index 2b1410b050d04737fb3c2cc15c244aed9e7f27a3..bef7714ef37af7b7c8fb2f1ef835611a307e4877 100755 (executable)
@@ -4,10 +4,29 @@
 
 set -e
 
+perfdata=$(mktemp /tmp/__perf_test_sched_stats.perf.data.XXXXX)
+perfdata2=$(mktemp /tmp/__perf_test_sched_stats.perf.data.XXXXX)
+
+cleanup() {
+  rm -f "${perfdata}"
+  rm -f "${perfdata}".old
+  rm -f "${perfdata2}"
+  rm -f "${perfdata2}".old
+
+  trap - EXIT TERM INT
+}
+
+trap_cleanup() {
+  echo "Unexpected signal in ${FUNCNAME[1]}"
+  cleanup
+  exit 1
+}
+trap trap_cleanup EXIT TERM INT
+
 err=0
 test_perf_sched_stats_record() {
   echo "Basic perf sched stats record test"
-  if ! perf sched stats record true 2>&1 | \
+  if ! perf sched stats record -o "${perfdata}" true 2>&1 | \
     grep -E -q "[ perf sched stats: Wrote samples to perf.data ]"
   then
     echo "Basic perf sched stats record test [Failed]"
@@ -19,15 +38,13 @@ test_perf_sched_stats_record() {
 
 test_perf_sched_stats_report() {
   echo "Basic perf sched stats report test"
-  perf sched stats record true > /dev/null
-  if ! perf sched stats report 2>&1 | grep -E -q "Description"
+  perf sched stats record -o "${perfdata}" true > /dev/null
+  if ! perf sched stats report -i "${perfdata}" 2>&1 | grep -E -q "Description"
   then
     echo "Basic perf sched stats report test [Failed]"
     err=1
-    rm perf.data
     return
   fi
-  rm perf.data
   echo "Basic perf sched stats report test [Success]"
 }
 
@@ -44,16 +61,14 @@ test_perf_sched_stats_live() {
 
 test_perf_sched_stats_diff() {
   echo "Basic perf sched stats diff test"
-  perf sched stats record true > /dev/null
-  perf sched stats record true > /dev/null
-  if ! perf sched stats diff > /dev/null
+  perf sched stats record -o "${perfdata}" true > /dev/null
+  perf sched stats record -o "${perfdata2}" true > /dev/null
+  if ! perf sched stats diff "${perfdata}" "${perfdata2}" > /dev/null
   then
     echo "Basic perf sched stats diff test [Failed]"
     err=1
-    rm perf.data.old perf.data
     return
   fi
-  rm perf.data.old perf.data
   echo "Basic perf sched stats diff test [Success]"
 }
 
@@ -61,4 +76,6 @@ test_perf_sched_stats_record
 test_perf_sched_stats_report
 test_perf_sched_stats_live
 test_perf_sched_stats_diff
+
+cleanup
 exit $err