[PATCH 1/2] perf test trace_btf_general: Use %s format specifier when printing test output

From: Marek Pazur

Date: Wed Dec 02 2026 - 07:17:00 EST


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@xxxxxxxxxx>
---
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