Linux Perf Users
 help / color / mirror / Atom feed
From: Arnaldo Carvalho de Melo <acme@kernel.org>
To: Namhyung Kim <namhyung@kernel.org>
Cc: Ingo Molnar <mingo@kernel.org>,
	Thomas Gleixner <tglx@linutronix.de>,
	James Clark <james.clark@linaro.org>,
	Jiri Olsa <jolsa@kernel.org>, Ian Rogers <irogers@google.com>,
	Adrian Hunter <adrian.hunter@intel.com>,
	Clark Williams <williams@redhat.com>,
	linux-perf-users@vger.kernel.org,
	Arnaldo Carvalho de Melo <acme@redhat.com>
Subject: [PATCH v2 08/18] perf tests diff: Exercise the output options
Date: Thu, 26 Nov 2026 22:37:51 -0300	[thread overview]
Message-ID: <20261127013801.14841-9-acme@kernel.org> (raw)
In-Reply-To: <20261127013801.14841-1-acme@kernel.org>

From: Arnaldo Carvalho de Melo <acme@redhat.com>

The diff test only diffs files recorded with the same workload.  Add
the compute formulas, each checked by the column it prints, the
formula, period, field separator, sort and raw trace dump options, and
the time window, checked with a window that leaves nothing.

As delta-abs is the default compute, a plain diff prints its column as
well: the default header is pinned before the option runs, and the
delta-abs run then only checks that the option is accepted and that
the column is not dropped.

Record the third file with the noploop workload: with it the
baseline-only and order options can be checked on a second file whose
entries have no match in the baseline.  The --percentage and --verbose
options only change the numbers when entries are filtered in the TUI
and the debug output, they run here as a check that the table is still
printed.

Signed-off-by: Arnaldo Carvalho de Melo <acme@redhat.com>
---
 tools/perf/tests/shell/diff.sh | 232 ++++++++++++++++++++++++++++++---
 1 file changed, 217 insertions(+), 15 deletions(-)

diff --git a/tools/perf/tests/shell/diff.sh b/tools/perf/tests/shell/diff.sh
index 88f37b8ef8936be4..5bddb06166339ce7 100755
--- a/tools/perf/tests/shell/diff.sh
+++ b/tools/perf/tests/shell/diff.sh
@@ -8,14 +8,15 @@ err=0
 perfdata1=$(mktemp /tmp/__perf_test.perf.data.XXXXX)
 perfdata2=$(mktemp /tmp/__perf_test.perf.data.XXXXX)
 perfdata3=$(mktemp /tmp/__perf_test.perf.data.XXXXX)
+diffout=$(mktemp /tmp/__perf_test.perf.diff.out.XXXXX)
 testprog="perf test -w thloop"
+testprog2="perf test -w noploop"
 
 shelldir=$(dirname "$0")
 . "${shelldir}"/lib/perf_has_symbol.sh
 
 testsym="test_loop"
-
-skip_test_missing_symbol ${testsym}
+testsym2="noploop"
 
 cleanup() {
   rm -rf "${perfdata1}"
@@ -24,25 +25,37 @@ cleanup() {
   rm -rf "${perfdata2}".old
   rm -rf "${perfdata3}"
   rm -rf "${perfdata3}".old
+  rm -f "${diffout}"
 
   trap - EXIT TERM INT
 }
 
 trap_cleanup() {
+  local status=$?
   cleanup
-  exit 1
+  if [ "${status}" -eq 0 ]; then
+    status=1
+  fi
+  exit "${status}"
 }
 trap trap_cleanup EXIT TERM INT
 
+# Install the cleanup trap before the symbol skips, which exit 2, so
+# the mktemp files are removed on that path too.
+skip_test_missing_symbol ${testsym}
+skip_test_missing_symbol ${testsym2}
+
 make_data() {
   file="$1"
-  if ! perf record -o "${file}" ${testprog} 2> /dev/null
+  prog="$2"
+  sym="$3"
+  if ! perf record -o "${file}" ${prog} 2> /dev/null
   then
     echo "Workload record [Failed record]" >&2
     echo 1
     return
   fi
-  if ! perf report -i "${file}" -q | grep -q "${testsym}"
+  if ! perf report -i "${file}" -q | grep -q "${sym}"
   then
     echo "Workload record [Failed missing output]" >&2
     echo 1
@@ -53,14 +66,16 @@ make_data() {
 
 test_two_files() {
   echo "Basic two file diff test"
-  err=$(make_data "${perfdata1}")
-  if [ "$err" != 0 ]
+  ret=$(make_data "${perfdata1}" "${testprog}" "${testsym}")
+  if [ "$ret" != 0 ]
   then
+    err=1
     return
   fi
-  err=$(make_data "${perfdata2}")
-  if [ "$err" != 0 ]
+  ret=$(make_data "${perfdata2}" "${testprog}" "${testsym}")
+  if [ "$ret" != 0 ]
   then
+    err=1
     return
   fi
 
@@ -75,19 +90,25 @@ test_two_files() {
 
 test_three_files() {
   echo "Basic three file diff test"
-  err=$(make_data "${perfdata1}")
-  if [ "$err" != 0 ]
+  ret=$(make_data "${perfdata1}" "${testprog}" "${testsym}")
+  if [ "$ret" != 0 ]
   then
+    err=1
     return
   fi
-  err=$(make_data "${perfdata2}")
-  if [ "$err" != 0 ]
+  ret=$(make_data "${perfdata2}" "${testprog}" "${testsym}")
+  if [ "$ret" != 0 ]
   then
+    err=1
     return
   fi
-  err=$(make_data "${perfdata3}")
-  if [ $err != 0 ]
+  # The third file is recorded with another workload, so that the
+  # baseline-only and order option checks below can tell which entries
+  # are shown and in what order.
+  ret=$(make_data "${perfdata3}" "${testprog2}" "${testsym2}")
+  if [ "$ret" != 0 ]
   then
+    err=1
     return
   fi
 
@@ -100,8 +121,189 @@ test_three_files() {
   echo "Basic three file diff test [Success]"
 }
 
+test_options() {
+  echo "Diff options test"
+
+  # delta-abs is the default compute, so a plain diff prints the same
+  # header: pin it here, the option run below then only checks that
+  # --compute delta-abs is accepted and still prints its column
+  if ! perf diff "${perfdata1}" "${perfdata2}" | \
+      grep -qE 'Baseline[[:space:]]+Delta Abs[[:space:]]+Shared Object'
+  then
+    echo "Diff options test [Failed: default compute is not delta-abs]"
+    err=1
+    return
+  fi
+
+  # Every compute formula prints a column of its own
+  for compute in delta delta-abs ratio wdiff:1,2
+  do
+    case "${compute}" in
+      delta) expect='Delta[[:space:]]+Shared Object' ;;
+      delta-abs) expect='Delta Abs' ;;
+      ratio) expect='Ratio' ;;
+      wdiff:1,2) expect='Weighted diff' ;;
+    esac
+    if ! perf diff --compute "${compute}" "${perfdata1}" "${perfdata2}" | \
+        grep -qE "${expect}"
+    then
+      echo "Diff options test [Failed: --compute ${compute}]"
+      err=1
+      return
+    fi
+  done
+
+  if ! perf diff -F "${perfdata1}" "${perfdata2}" | grep -q "Formula"
+  then
+    echo "Diff options test [Failed: --formula]"
+    err=1
+    return
+  fi
+
+  if ! perf diff -p "${perfdata1}" "${perfdata2}" | grep -q "Base period"
+  then
+    echo "Diff options test [Failed: --period]"
+    err=1
+    return
+  fi
+
+  # -b keeps the entries matched in the baseline: with two files of
+  # the same workload the loop entry stays
+  if ! perf diff -b "${perfdata1}" "${perfdata2}" | grep -q "${testsym}"
+  then
+    echo "Diff options test [Failed: --baseline-only drops common entries]"
+    err=1
+    return
+  fi
+
+  # The noploop workload is only in the third file
+  if ! perf diff "${perfdata1}" "${perfdata3}" > "${diffout}" 2> /dev/null
+  then
+    echo "Diff options test [Failed: diff of different workloads]"
+    err=1
+    return
+  fi
+  if ! grep -q "${testsym2}" "${diffout}"
+  then
+    echo "Diff options test [Failed: ${testsym2} missing from the diff]"
+    err=1
+    return
+  fi
+
+  # and with a second file recorded with another workload its entries
+  # have no match in the baseline and disappear
+  if ! perf diff -b "${perfdata1}" "${perfdata3}" > "${diffout}" 2> /dev/null
+  then
+    echo "Diff options test [Failed: --baseline-only]"
+    err=1
+    return
+  fi
+  if grep -q "${testsym2}" "${diffout}"
+  then
+    echo "Diff options test [Failed: --baseline-only shows non-baseline entries]"
+    err=1
+    return
+  fi
+
+  if ! perf diff -t, "${perfdata1}" "${perfdata2}" | grep -q "Baseline,"
+  then
+    echo "Diff options test [Failed: --field-separator]"
+    err=1
+    return
+  fi
+
+  # -o 0 puts the entry with the biggest baseline first, the loop in
+  # the first file, while the default starts with the loop in the
+  # second file
+  if ! perf diff -o 0 "${perfdata1}" "${perfdata3}" > "${diffout}" 2> /dev/null
+  then
+    echo "Diff options test [Failed: --order]"
+    err=1
+    return
+  fi
+  if ! grep -v '^#' "${diffout}" | grep -v '^[[:space:]]*$' | head -1 | \
+      grep -q "${testsym}"
+  then
+    echo "Diff options test [Failed: --order 0 does not sort by the baseline]"
+    err=1
+    return
+  fi
+
+  # A window starting at the beginning of the data shows it all, a
+  # window starting after the last sample shows nothing
+  if ! perf diff --time 0, "${perfdata1}" "${perfdata2}" | grep -q "${testsym}"
+  then
+    echo "Diff options test [Failed: --time]"
+    err=1
+    return
+  fi
+  # 9999999999 is beyond the recording's timestamps and, unlike a
+  # 19-digit value, does not overflow u64 when scaled to nanoseconds.
+  # Capture the output so a failing perf diff cannot masquerade as an
+  # empty window.
+  if ! perf diff --time 9999999999, "${perfdata1}" "${perfdata2}" > "${diffout}" 2> /dev/null
+  then
+    echo "Diff options test [Failed: --time after the last sample]"
+    err=1
+    return
+  fi
+  if grep -q "${testsym}" "${diffout}"
+  then
+    echo "Diff options test [Failed: --time shows samples outside the window]"
+    err=1
+    return
+  fi
+
+  # --percentage only shows up when entries are filtered in the TUI
+  # and --verbose only adds debug output, check the table is printed
+  if ! perf diff --percentage relative "${perfdata1}" "${perfdata2}" | grep -q "${testsym}"
+  then
+    echo "Diff options test [Failed: --percentage relative]"
+    err=1
+    return
+  fi
+
+  if ! perf diff --percentage absolute "${perfdata1}" "${perfdata2}" | grep -q "${testsym}"
+  then
+    echo "Diff options test [Failed: --percentage absolute]"
+    err=1
+    return
+  fi
+
+  if ! perf diff -s comm "${perfdata1}" "${perfdata2}" | grep -q "Command"
+  then
+    echo "Diff options test [Failed: --sort comm]"
+    err=1
+    return
+  fi
+
+  if ! perf diff -v "${perfdata1}" "${perfdata2}" 2> /dev/null | \
+      grep -q "${testsym}"
+  then
+    echo "Diff options test [Failed: --verbose]"
+    err=1
+    return
+  fi
+
+  if ! perf diff --dump-raw-trace "${perfdata1}" "${perfdata2}" 2>&1 | \
+          grep -q "PERF_RECORD_SAMPLE"
+  then
+    echo "Diff options test [Failed: --dump-raw-trace]"
+    err=1
+    return
+  fi
+
+  echo "Diff options test [Success]"
+}
+
 test_two_files
 test_three_files
 
+if [ -s "${perfdata1}" ] && [ -s "${perfdata2}" ] && [ -s "${perfdata3}" ]; then
+  test_options
+else
+  echo "Diff options test [Skipped: recordings incomplete]"
+fi
+
 cleanup
 exit $err
-- 
2.56.0


  parent reply	other threads:[~2026-11-27  1:38 UTC|newest]

Thread overview: 22+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2026-11-27  1:37 [PATCH v2 00/18] perf tests: Add coverage for the untested perf subcommands Arnaldo Carvalho de Melo
2026-11-27  1:37 ` [PATCH v2 01/18] perf kmem: Use the allocation order when matching page frees Arnaldo Carvalho de Melo
2026-11-27  1:53   ` sashiko-bot
2026-11-27  1:37 ` [PATCH v2 02/18] perf tests top: Pin the ring buffer size Arnaldo Carvalho de Melo
2026-11-27  1:37 ` [PATCH v2 03/18] perf tests sched: Exercise the sched views and options Arnaldo Carvalho de Melo
2026-11-27  1:37 ` [PATCH v2 04/18] perf tests help: Add a basic perf help test Arnaldo Carvalho de Melo
2026-11-27  1:37 ` [PATCH v2 05/18] perf tests config: Exercise the config file and list options Arnaldo Carvalho de Melo
2026-11-27  1:37 ` [PATCH v2 06/18] perf tests script: Exercise the list, fields and dump options Arnaldo Carvalho de Melo
2026-11-27  1:37 ` [PATCH v2 07/18] perf tests sort: Exercise the report and diff sort keys Arnaldo Carvalho de Melo
2026-11-27  1:37 ` Arnaldo Carvalho de Melo [this message]
2026-11-27  1:37 ` [PATCH v2 09/18] perf tests annotate: Exercise the output and filter options Arnaldo Carvalho de Melo
2026-11-27  1:37 ` [PATCH v2 10/18] perf tests report: Exercise the output and format options Arnaldo Carvalho de Melo
2026-11-27  1:37 ` [PATCH v2 11/18] perf tests record: Exercise more record options Arnaldo Carvalho de Melo
2026-11-27  1:52   ` sashiko-bot
2026-11-27  1:37 ` [PATCH v2 12/18] perf tests trace: Exercise the tracing options Arnaldo Carvalho de Melo
2026-11-27  1:37 ` [PATCH v2 13/18] perf tests timechart: Exercise the report options Arnaldo Carvalho de Melo
2026-11-27  1:37 ` [PATCH v2 14/18] perf tests kmem: Add a basic perf kmem test Arnaldo Carvalho de Melo
2026-11-27  1:37 ` [PATCH v2 15/18] perf tests bench: Add smoke tests for perf bench Arnaldo Carvalho de Melo
2026-11-27  1:37 ` [PATCH v2 16/18] perf tests lock: Exercise perf lock report and info Arnaldo Carvalho de Melo
2026-11-27  1:38 ` [PATCH v2 17/18] perf tests probe: Exercise the variable and line listing Arnaldo Carvalho de Melo
2026-11-27  1:38 ` [PATCH v2 18/18] perf tests report: Exercise the TUI browsers Arnaldo Carvalho de Melo
2026-11-27  1:53 ` [PATCH v2 00/18] perf tests: Add coverage for the untested perf subcommands sashiko-bot

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=20261127013801.14841-9-acme@kernel.org \
    --to=acme@kernel.org \
    --cc=acme@redhat.com \
    --cc=adrian.hunter@intel.com \
    --cc=irogers@google.com \
    --cc=james.clark@linaro.org \
    --cc=jolsa@kernel.org \
    --cc=linux-perf-users@vger.kernel.org \
    --cc=mingo@kernel.org \
    --cc=namhyung@kernel.org \
    --cc=tglx@linutronix.de \
    --cc=williams@redhat.com \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox