The Linux Kernel Mailing List
 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-kernel@vger.kernel.org, linux-perf-users@vger.kernel.org,
	Arnaldo Carvalho de Melo <acme@redhat.com>
Subject: [PATCH v1 07/17] perf tests diff: Exercise the output options
Date: Tue, 24 Nov 2026 15:45:54 -0300	[thread overview]
Message-ID: <20261124184604.24983-8-acme@kernel.org> (raw)
In-Reply-To: <20261124184604.24983-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 | 191 +++++++++++++++++++++++++++++++--
 1 file changed, 184 insertions(+), 7 deletions(-)

diff --git a/tools/perf/tests/shell/diff.sh b/tools/perf/tests/shell/diff.sh
index 88f37b8ef8936be4..d2fbc8a8c2c3680a 100755
--- a/tools/perf/tests/shell/diff.sh
+++ b/tools/perf/tests/shell/diff.sh
@@ -8,14 +8,18 @@ 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"
+testsym2="noploop"
 
 skip_test_missing_symbol ${testsym}
+skip_test_missing_symbol ${testsym2}
 
 cleanup() {
   rm -rf "${perfdata1}"
@@ -24,6 +28,7 @@ cleanup() {
   rm -rf "${perfdata2}".old
   rm -rf "${perfdata3}"
   rm -rf "${perfdata3}".old
+  rm -f "${diffout}"
 
   trap - EXIT TERM INT
 }
@@ -36,13 +41,15 @@ trap trap_cleanup EXIT TERM INT
 
 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,12 +60,12 @@ make_data() {
 
 test_two_files() {
   echo "Basic two file diff test"
-  err=$(make_data "${perfdata1}")
+  err=$(make_data "${perfdata1}" "${testprog}" "${testsym}")
   if [ "$err" != 0 ]
   then
     return
   fi
-  err=$(make_data "${perfdata2}")
+  err=$(make_data "${perfdata2}" "${testprog}" "${testsym}")
   if [ "$err" != 0 ]
   then
     return
@@ -75,17 +82,20 @@ test_two_files() {
 
 test_three_files() {
   echo "Basic three file diff test"
-  err=$(make_data "${perfdata1}")
+  err=$(make_data "${perfdata1}" "${testprog}" "${testsym}")
   if [ "$err" != 0 ]
   then
     return
   fi
-  err=$(make_data "${perfdata2}")
+  err=$(make_data "${perfdata2}" "${testprog}" "${testsym}")
   if [ "$err" != 0 ]
   then
     return
   fi
-  err=$(make_data "${perfdata3}")
+  # 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.
+  err=$(make_data "${perfdata3}" "${testprog2}" "${testsym2}")
   if [ $err != 0 ]
   then
     return
@@ -100,8 +110,175 @@ 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
+  if perf diff --time 9000000000000000000, "${perfdata1}" "${perfdata2}" | \
+      grep -q "${testsym}"
+  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
+test_options
 
 cleanup
 exit $err
-- 
2.56.0


  parent reply	other threads:[~2026-11-24 18:46 UTC|newest]

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

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=20261124184604.24983-8-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-kernel@vger.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