]> git.ipfire.org Git - thirdparty/kernel/linux.git/commitdiff
perf test: perf data --to-ctf testing
authorIan Rogers <irogers@google.com>
Wed, 11 Feb 2026 01:52:42 +0000 (17:52 -0800)
committerArnaldo Carvalho de Melo <acme@redhat.com>
Thu, 12 Feb 2026 20:45:22 +0000 (17:45 -0300)
If babeltrace is detected check that --to-ctf functions with a data
file and in pipe mode.

Committer testing:

  $ perf test 'perf data convert --to-ctf'
  124: 'perf data convert --to-ctf' command test                       : Ok
  $ perf test -vv 'perf data convert --to-ctf'
  124: 'perf data convert --to-ctf' command test:
  --- start ---
  test child forked, pid 556008
           libbabeltrace: [ on  ]  # HAVE_LIBBABELTRACE_SUPPORT
  Testing Perf Data Conversion Command to CTF (File input)
  [ perf record: Woken up 1 times to write data ]
  [ perf record: Captured and wrote 0.021 MB /tmp/__perf_test.perf.data.9TxzZ (115 samples) ]
  [ perf data convert: Converted '/tmp/__perf_test.perf.data.9TxzZ' into CTF data '/tmp/__perf_test.ctf.f5EkS' ]
  [ perf data convert: Converted and wrote 0.012 MB (115 samples) ]
  Perf Data Converter Command to CTF (File input) [SUCCESS]
  Testing Perf Data Conversion Command to CTF (Pipe mode)
  [ perf record: Woken up 2 times to write data ]
  [ perf record: Captured and wrote 0.047 MB - ]
  Failed to setup all events.
  [ perf data convert: Converted '/tmp/__perf_test.perf.data.9TxzZ' into CTF data '/tmp/__perf_test.ctf.f5EkS' ]
  [ perf data convert: Converted and wrote 0.000 MB (0 samples) ]
  Perf Data Converter Command to CTF (Pipe mode) [SUCCESS]
  Unexpected signal in main
  ---- end(0) ----
  124: 'perf data convert --to-ctf' command test                       : Ok
  $

Signed-off-by: Ian Rogers <irogers@google.com>
Tested-by: Arnaldo Carvalho de Melo <acme@redhat.com>
Cc: Adrian Hunter <adrian.hunter@intel.com>
Cc: Alexander Shishkin <alexander.shishkin@linux.intel.com>
Cc: Derek Foreman <derek.foreman@collabora.com>
Cc: Ingo Molnar <mingo@redhat.com>
Cc: James Clark <james.clark@linaro.org>
Cc: Jiri Olsa <jolsa@kernel.org>
Cc: Namhyung Kim <namhyung@kernel.org>
Cc: Peter Zijlstra <peterz@infradead.org>
Signed-off-by: Arnaldo Carvalho de Melo <acme@redhat.com>
tools/perf/tests/shell/test_perf_data_converter_ctf.sh [new file with mode: 0755]

diff --git a/tools/perf/tests/shell/test_perf_data_converter_ctf.sh b/tools/perf/tests/shell/test_perf_data_converter_ctf.sh
new file mode 100755 (executable)
index 0000000..334eebc
--- /dev/null
@@ -0,0 +1,104 @@
+#!/bin/bash
+# 'perf data convert --to-ctf' command test
+# SPDX-License-Identifier: GPL-2.0
+
+set -e
+
+err=0
+
+perfdata=$(mktemp /tmp/__perf_test.perf.data.XXXXX)
+ctf_dir=$(mktemp -d /tmp/__perf_test.ctf.XXXXX)
+
+cleanup()
+{
+       rm -f "${perfdata}"
+       rm -rf "${ctf_dir}"
+       trap - exit term int
+}
+
+trap_cleanup()
+{
+       echo "Unexpected signal in ${FUNCNAME[1]}"
+       cleanup
+       exit ${err}
+}
+trap trap_cleanup exit term int
+
+check_babeltrace_support()
+{
+       if ! perf check feature libbabeltrace
+       then
+               echo "perf not linked with libbabeltrace, skipping test"
+               exit 2
+       fi
+}
+
+test_ctf_converter_file()
+{
+       echo "Testing Perf Data Conversion Command to CTF (File input)"
+       # Record some data
+       if ! perf record -o "$perfdata" -F 99 -g -- perf test -w noploop
+       then
+               echo "Failed to record perf data"
+               err=1
+               return
+       fi
+
+       # Cleanup previous ctf dir
+       rm -rf "${ctf_dir}"
+
+       # Convert
+       if ! perf data convert --to-ctf "$ctf_dir" --force -i "$perfdata"
+       then
+               echo "Perf Data Converter Command to CTF (File input) [FAILED]"
+               err=1
+               return
+       fi
+
+       if [ -d "${ctf_dir}" ] && [ "$(ls -A "${ctf_dir}")" ]
+       then
+               echo "Perf Data Converter Command to CTF (File input) [SUCCESS]"
+       else
+               echo "Perf Data Converter Command to CTF (File input) [FAILED]"
+               echo "    Output directory empty or missing"
+               err=1
+       fi
+}
+
+test_ctf_converter_pipe()
+{
+       echo "Testing Perf Data Conversion Command to CTF (Pipe mode)"
+
+       # Cleanup previous ctf dir
+       rm -rf "${ctf_dir}"
+
+       # Record to stdout and pipe to $perfdata file
+       if ! perf record -o - -F 99 -g -- perf test -w noploop > "$perfdata"
+       then
+               echo "Failed to record perf data"
+               err=1
+               return
+       fi
+
+       if ! perf data convert --to-ctf "$ctf_dir" --force -i "$perfdata"
+       then
+               echo "Perf Data Converter Command to CTF (Pipe mode) [FAILED]"
+               err=1
+               return
+       fi
+
+       if [ -d "${ctf_dir}" ] && [ "$(ls -A "${ctf_dir}")" ]
+       then
+               echo "Perf Data Converter Command to CTF (Pipe mode) [SUCCESS]"
+       else
+               echo "Perf Data Converter Command to CTF (Pipe mode) [FAILED]"
+               echo "    Output directory empty or missing"
+               err=1
+       fi
+}
+
+check_babeltrace_support
+test_ctf_converter_file
+test_ctf_converter_pipe
+
+exit ${err}