From: Cao Ruichuang <create0818@163.com>
To: rostedt@goodmis.org, mhiramat@kernel.org,
mathieu.desnoyers@efficios.com, shuah@kernel.org
Cc: linux-kernel@vger.kernel.org, linux-trace-kernel@vger.kernel.org,
linux-kselftest@vger.kernel.org
Subject: [PATCH 2/2] selftests/ftrace: Check exact trace_marker_raw payload lengths
Date: Wed, 8 Apr 2026 23:32:41 +0800 [thread overview]
Message-ID: <20260408153241.15391-2-create0818@163.com> (raw)
In-Reply-To: <20260408153241.15391-1-create0818@163.com>
trace_marker_raw.tc currently depends on awk strtonum() and assumes
that the printed raw-data byte count is rounded up to four bytes.
Now that TRACE_RAW_DATA records keep the true payload length in the
event itself, update the testcase to validate the exact number of bytes
printed for a short sequence of writes. While doing that, make the test
portable to /bin/sh environments that use mawk by replacing strtonum()
and the lscpu endian probe with od-based checks.
Signed-off-by: Cao Ruichuang <create0818@163.com>
---
.../ftrace/test.d/00basic/trace_marker_raw.tc | 93 ++++++++++++-------
1 file changed, 59 insertions(+), 34 deletions(-)
diff --git a/tools/testing/selftests/ftrace/test.d/00basic/trace_marker_raw.tc b/tools/testing/selftests/ftrace/test.d/00basic/trace_marker_raw.tc
index a2c42e13f..3b37890f8 100644
--- a/tools/testing/selftests/ftrace/test.d/00basic/trace_marker_raw.tc
+++ b/tools/testing/selftests/ftrace/test.d/00basic/trace_marker_raw.tc
@@ -1,11 +1,11 @@
#!/bin/sh
# SPDX-License-Identifier: GPL-2.0
# description: Basic tests on writing to trace_marker_raw
-# requires: trace_marker_raw
+# requires: trace_marker_raw od:program
# flags: instance
is_little_endian() {
- if lscpu | grep -q 'Little Endian'; then
+ if [ "$(printf '\001\000\000\000' | od -An -tu4 | tr -d '[:space:]')" = "1" ]; then
echo 1;
else
echo 0;
@@ -34,7 +34,7 @@ make_str() {
data=`printf -- 'X%.0s' $(seq $cnt)`
- printf "${val}${data}"
+ printf "%b%s" "${val}" "${data}"
}
write_buffer() {
@@ -47,36 +47,68 @@ write_buffer() {
test_multiple_writes() {
+ out_file=$TMPDIR/trace_marker_raw.out
+ match_file=$TMPDIR/trace_marker_raw.lines
+ wait_iter=0
+ pause_on_trace=
+
+ if [ -f options/pause-on-trace ]; then
+ pause_on_trace=`cat options/pause-on-trace`
+ echo 0 > options/pause-on-trace
+ fi
+
+ : > trace
+ cat trace_pipe > $out_file &
+ reader_pid=$!
+ sleep 1
+
+ # Write sizes that cover both the short and long raw-data encodings
+ # without overflowing the trace buffer before we can verify them.
+ for i in `seq 1 12`; do
+ write_buffer 0x12345678 $i
+ done
- # Write a bunch of data where the id is the count of
- # data to write
- for i in `seq 1 10` `seq 101 110` `seq 1001 1010`; do
- write_buffer $i $i
+ while [ "`grep -c ' buf:' $out_file 2> /dev/null || true`" -lt 12 ]; do
+ wait_iter=$((wait_iter + 1))
+ if [ $wait_iter -ge 10 ]; then
+ kill $reader_pid 2> /dev/null || true
+ wait $reader_pid 2> /dev/null || true
+ if [ -n "$pause_on_trace" ]; then
+ echo $pause_on_trace > options/pause-on-trace
+ fi
+ return 1
+ fi
+ sleep 1
done
# add a little buffer
echo stop > trace_marker
+ sleep 1
+ kill $reader_pid 2> /dev/null || true
+ wait $reader_pid 2> /dev/null || true
+ if [ -n "$pause_on_trace" ]; then
+ echo $pause_on_trace > options/pause-on-trace
+ fi
- # Check to make sure the number of entries is the id (rounded up by 4)
- awk '/.*: # [0-9a-f]* / {
- print;
- cnt = -1;
- for (i = 0; i < NF; i++) {
- # The counter is after the "#" marker
- if ( $i == "#" ) {
- i++;
- cnt = strtonum("0x" $i);
- num = NF - (i + 1);
- # The number of items is always rounded up by 4
- cnt2 = int((cnt + 3) / 4) * 4;
- if (cnt2 != num) {
- exit 1;
- }
- break;
- }
- }
- }
- // { if (NR > 30) { exit 0; } } ' trace_pipe;
+ grep ' buf:' $out_file > $match_file || return 1
+ if [ "`wc -l < $match_file`" -ne 12 ]; then
+ cat $match_file
+ return 1
+ fi
+
+ # Check to make sure the number of byte values matches the id exactly.
+ for expected in `seq 1 12`; do
+ line=`sed -n "${expected}p" $match_file`
+ if [ -z "$line" ]; then
+ return 1
+ fi
+ rest=${line#* buf: }
+ set -- $rest
+ if [ "$#" -ne "$expected" ]; then
+ echo "$line"
+ return 1
+ fi
+ done
}
@@ -107,13 +139,6 @@ test_buffer() {
ORIG=`cat buffer_size_kb`
-# test_multiple_writes test needs at least 12KB buffer
-NEW_SIZE=12
-
-if [ ${ORIG} -lt ${NEW_SIZE} ]; then
- echo ${NEW_SIZE} > buffer_size_kb
-fi
-
test_buffer
if ! test_multiple_writes; then
echo ${ORIG} > buffer_size_kb
--
2.39.5 (Apple Git-154)
next prev parent reply other threads:[~2026-04-08 15:33 UTC|newest]
Thread overview: 4+ messages / expand[flat|nested] mbox.gz Atom feed top
2026-04-08 15:32 [PATCH 1/2] tracing: Store trace_marker_raw payload length in events Cao Ruichuang
2026-04-08 15:32 ` Cao Ruichuang [this message]
2026-04-08 17:39 ` Steven Rostedt
2026-04-09 5:12 ` Cao Ruichuang
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=20260408153241.15391-2-create0818@163.com \
--to=create0818@163.com \
--cc=linux-kernel@vger.kernel.org \
--cc=linux-kselftest@vger.kernel.org \
--cc=linux-trace-kernel@vger.kernel.org \
--cc=mathieu.desnoyers@efficios.com \
--cc=mhiramat@kernel.org \
--cc=rostedt@goodmis.org \
--cc=shuah@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 a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox