All of lore.kernel.org
 help / color / mirror / Atom feed
From: Marek Pazur <mpazur@redhat.com>
To: Arnaldo Carvalho de Melo <acme@kernel.org>,
	Namhyung Kim <namhyung@kernel.org>
Cc: Jiri Olsa <jolsa@kernel.org>, Ian Rogers <irogers@google.com>,
	Adrian Hunter <adrian.hunter@intel.com>,
	Howard Chu <howardchu95@gmail.com>,
	linux-perf-users@vger.kernel.org, linux-kernel@vger.kernel.org
Subject: [PATCH 1/2] perf test trace_btf_general: Use %s format specifier when printing test output
Date: Wed,  2 Dec 2026 13:16:21 +0100	[thread overview]
Message-ID: <20261202121622.30071-2-mpazur@redhat.com> (raw)
In-Reply-To: <20261202121622.30071-1-mpazur@redhat.com>

The shell tests insert the captured perf trace output directly into
the printf format string as follows:

  printf "Buffer augmentation test failed, output: \n$output\n"

As a result, printf interprets any possible escape sequences
and conversion specifications within the payload. Because perf trace
prints non-printable characters in decimal while printf parses
backslash escapes as octal, a newline character printed by perf
as "\10" (decimal 10) is interpreted by printf as a backspace
(octal 10), corrupting the failure message:

Buffer augmentation test failed, output:
  buffer content
  echo/129407 write(1, buffer conten, 15, 0) = 15

instead of:

  echo/129407 write(1, buffer content\10, 15, 0) = 15

Pass the output as an argument to a "%s" conversion specifier instead
across all failure messages in the test.

Signed-off-by: Marek Pazur <mpazur@redhat.com>
---
 tools/perf/tests/shell/trace_btf_general.sh | 6 +++---
 1 file changed, 3 insertions(+), 3 deletions(-)

diff --git a/tools/perf/tests/shell/trace_btf_general.sh b/tools/perf/tests/shell/trace_btf_general.sh
index d1fa7c846478..0941459a7137 100755
--- a/tools/perf/tests/shell/trace_btf_general.sh
+++ b/tools/perf/tests/shell/trace_btf_general.sh
@@ -22,42 +22,42 @@ check_vmlinux() {
     return 2
   fi
   return 0
 }
 
 trace_test_string() {
   echo "Testing perf trace's string augmentation"
   output="$(perf trace --sort-events -e renameat* -- mv ${file1} ${file2} 2>&1)"
   if ! echo "$output" | grep -q -E "^mv/[0-9]+ renameat(2)?\(.*, \"${file1}\", .*, \"${file2}\", .*\) += +[0-9]+$"
   then
-    printf "String augmentation test failed, output:\n$output\n"
+    printf "String augmentation test failed, output:\n%s\n" "$output"
     err=1
   fi
 }
 
 trace_test_buffer() {
   echo "Testing perf trace's buffer augmentation"
   # echo will insert a newline (\10) at the end of the buffer
   output="$(perf trace --sort-events -e write -- echo "${buffer}" 2>&1)"
   if ! echo "$output" | grep -q -E "^echo/[0-9]+ write\([0-9]+, ${buffer}.*, [0-9]+\) += +[0-9]+$"
   then
-    printf "Buffer augmentation test failed, output:\n$output\n"
+    printf "Buffer augmentation test failed, output:\n%s\n" "$output"
     err=1
   fi
 }
 
 trace_test_struct_btf() {
   echo "Testing perf trace's struct augmentation"
   output="$(perf trace --sort-events -e clock_nanosleep --force-btf -- sleep 1 2>&1)"
   if ! echo "$output" | grep -q -E "^sleep/[0-9]+ clock_nanosleep\(0, 0, \{1,.*\}, 0x[0-9a-f]+\) += +[0-9]+$"
   then
-	printf "BTF struct augmentation test failed, output:\n$output\n"
+	printf "BTF struct augmentation test failed, output:\n%s\n" "$output"
     err=1
   fi
 }
 
 cleanup() {
   rm -rf ${file1} ${file2} ${perf_config_tmp}
 }
 
 trap_cleanup() {
   echo "Unexpected signal in ${FUNCNAME[1]}"
-- 
2.55.0


  reply	other threads:[~2026-12-02 12:16 UTC|newest]

Thread overview: 4+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2026-12-02 12:16 [PATCH 0/2] perf trace: Improve augmented buf output formatting, fix test output Marek Pazur
2026-12-02 12:16 ` Marek Pazur [this message]
2026-12-02 12:16 ` [PATCH 2/2] perf trace: Quote and escape augmented buffer contents Marek Pazur
2026-12-02 12:19 ` [PATCH 0/2] perf trace: Improve augmented buf output formatting, fix test output 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=20261202121622.30071-2-mpazur@redhat.com \
    --to=mpazur@redhat.com \
    --cc=acme@kernel.org \
    --cc=adrian.hunter@intel.com \
    --cc=howardchu95@gmail.com \
    --cc=irogers@google.com \
    --cc=jolsa@kernel.org \
    --cc=linux-kernel@vger.kernel.org \
    --cc=linux-perf-users@vger.kernel.org \
    --cc=namhyung@kernel.org \
    /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 an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.