* [PATCH] selftests/tracing: Add basic test for trace_marker_raw file
@ 2025-10-14 18:51 Steven Rostedt
2025-10-14 20:14 ` Steven Rostedt
2025-11-04 23:47 ` Masami Hiramatsu
0 siblings, 2 replies; 5+ messages in thread
From: Steven Rostedt @ 2025-10-14 18:51 UTC (permalink / raw)
To: LKML, Linux Trace Kernel, linux-kselftest
Cc: Masami Hiramatsu, Mathieu Desnoyers, Shuah Khan, Linus Torvalds
From: Steven Rostedt <rostedt@goodmis.org>
Commit 64cf7d058a00 ("tracing: Have trace_marker use per-cpu data to read
user space") made an update that fixed both trace_marker and
trace_marker_raw. But the small difference made to trace_marker_raw had a
blatant bug in it that any basic testing would have uncovered.
Unfortunately, the self tests have tests for trace_marker but nothing for
trace_marker_raw which allowed the bug to get upstream.
Add basic selftests to test trace_marker_raw so that this doesn't happen
again.
Signed-off-by: Steven Rostedt (Google) <rostedt@goodmis.org>
---
.../ftrace/test.d/00basic/trace_marker_raw.tc | 107 ++++++++++++++++++
1 file changed, 107 insertions(+)
create mode 100644 tools/testing/selftests/ftrace/test.d/00basic/trace_marker_raw.tc
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
new file mode 100644
index 000000000000..7daf7292209e
--- /dev/null
+++ b/tools/testing/selftests/ftrace/test.d/00basic/trace_marker_raw.tc
@@ -0,0 +1,107 @@
+#!/bin/sh
+# SPDX-License-Identifier: GPL-2.0
+# description: Basic tests on writing to trace_marker_raw
+# requires: trace_marker_raw
+# flags: instance
+
+is_little_endian() {
+ if lscpu | grep -q 'Little Endian'; then
+ echo 1;
+ else
+ echo 0;
+ fi
+}
+
+little=`is_little_endian`
+
+make_str() {
+ id=$1
+ cnt=$2
+
+ if [ $little -eq 1 ]; then
+ val=`printf "\\%03o\\%03o\\%03o\\%03o" \
+ $(($id & 0xff)) \
+ $((($id >> 8) & 0xff)) \
+ $((($id >> 16) & 0xff)) \
+ $((($id >> 24) & 0xff))`
+ else
+ val=`printf "\\%03o\\%03o\\%03o\\%03o" \
+ $((($id >> 24) & 0xff)) \
+ $((($id >> 16) & 0xff)) \
+ $((($id >> 8) & 0xff)) \
+ $(($id & 0xff))`
+ fi
+
+ data=`printf -- 'X%.0s' $(seq $cnt)`
+
+ printf "${val}${data}"
+}
+
+write_buffer() {
+ id=$1
+ size=$2
+
+ # write the string into the raw marker
+ make_str $id $size > trace_marker_raw
+}
+
+
+test_multiple_writes() {
+
+ # 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
+ done
+
+ # add a little buffer
+ echo stop > trace_marker
+
+ # 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;
+}
+
+
+get_buffer_data_size() {
+ sed -ne 's/^.*data.*size:\([0-9][0-9]*\).*/\1/p' events/header_page
+}
+
+test_buffer() {
+
+ # The id must be four bytes, test that 3 bytes fails a write
+ if echo -n abc > ./trace_marker_raw ; then
+ echo "Too small of write expected to fail but did not"
+ exit_fail
+ fi
+
+ size=`get_buffer_data_size`
+ echo size = $size
+
+ # Now add a little more than what it can handle
+
+ if write_buffer 0xdeadbeef $size ; then
+ echo "Too big of write expected to fail but did not"
+ exit_fail
+ fi
+}
+
+test_buffer
+test_multiple_writes
--
2.51.0
^ permalink raw reply related [flat|nested] 5+ messages in thread* Re: [PATCH] selftests/tracing: Add basic test for trace_marker_raw file
2025-10-14 18:51 [PATCH] selftests/tracing: Add basic test for trace_marker_raw file Steven Rostedt
@ 2025-10-14 20:14 ` Steven Rostedt
2025-11-03 17:10 ` Steven Rostedt
2025-11-04 23:47 ` Masami Hiramatsu
1 sibling, 1 reply; 5+ messages in thread
From: Steven Rostedt @ 2025-10-14 20:14 UTC (permalink / raw)
To: Shuah Khan
Cc: LKML, Linux Trace Kernel, linux-kselftest, Masami Hiramatsu,
Mathieu Desnoyers, Linus Torvalds
Shuah,
After Masami gives an ack, could you take this through your tree.
I don't think it's urgent, but I want to make sure it gets upstream.
-- Steve
On Tue, 14 Oct 2025 14:51:49 -0400
Steven Rostedt <rostedt@goodmis.org> wrote:
> From: Steven Rostedt <rostedt@goodmis.org>
>
> Commit 64cf7d058a00 ("tracing: Have trace_marker use per-cpu data to read
> user space") made an update that fixed both trace_marker and
> trace_marker_raw. But the small difference made to trace_marker_raw had a
> blatant bug in it that any basic testing would have uncovered.
> Unfortunately, the self tests have tests for trace_marker but nothing for
> trace_marker_raw which allowed the bug to get upstream.
>
> Add basic selftests to test trace_marker_raw so that this doesn't happen
> again.
>
> Signed-off-by: Steven Rostedt (Google) <rostedt@goodmis.org>
>
^ permalink raw reply [flat|nested] 5+ messages in thread* Re: [PATCH] selftests/tracing: Add basic test for trace_marker_raw file
2025-10-14 20:14 ` Steven Rostedt
@ 2025-11-03 17:10 ` Steven Rostedt
0 siblings, 0 replies; 5+ messages in thread
From: Steven Rostedt @ 2025-11-03 17:10 UTC (permalink / raw)
To: Shuah Khan
Cc: LKML, Linux Trace Kernel, linux-kselftest, Masami Hiramatsu,
Mathieu Desnoyers, Linus Torvalds
Masami,
Ping!
-- Steve
On Tue, 14 Oct 2025 16:14:03 -0400
Steven Rostedt <rostedt@goodmis.org> wrote:
> Shuah,
>
> After Masami gives an ack, could you take this through your tree.
>
> I don't think it's urgent, but I want to make sure it gets upstream.
>
> -- Steve
>
>
> On Tue, 14 Oct 2025 14:51:49 -0400
> Steven Rostedt <rostedt@goodmis.org> wrote:
>
> > From: Steven Rostedt <rostedt@goodmis.org>
> >
> > Commit 64cf7d058a00 ("tracing: Have trace_marker use per-cpu data to read
> > user space") made an update that fixed both trace_marker and
> > trace_marker_raw. But the small difference made to trace_marker_raw had a
> > blatant bug in it that any basic testing would have uncovered.
> > Unfortunately, the self tests have tests for trace_marker but nothing for
> > trace_marker_raw which allowed the bug to get upstream.
> >
> > Add basic selftests to test trace_marker_raw so that this doesn't happen
> > again.
> >
> > Signed-off-by: Steven Rostedt (Google) <rostedt@goodmis.org>
> >
^ permalink raw reply [flat|nested] 5+ messages in thread
* Re: [PATCH] selftests/tracing: Add basic test for trace_marker_raw file
2025-10-14 18:51 [PATCH] selftests/tracing: Add basic test for trace_marker_raw file Steven Rostedt
2025-10-14 20:14 ` Steven Rostedt
@ 2025-11-04 23:47 ` Masami Hiramatsu
2025-11-06 22:25 ` Shuah Khan
1 sibling, 1 reply; 5+ messages in thread
From: Masami Hiramatsu @ 2025-11-04 23:47 UTC (permalink / raw)
To: Steven Rostedt
Cc: LKML, Linux Trace Kernel, linux-kselftest, Masami Hiramatsu,
Mathieu Desnoyers, Shuah Khan, Linus Torvalds
On Tue, 14 Oct 2025 14:51:49 -0400
Steven Rostedt <rostedt@goodmis.org> wrote:
> From: Steven Rostedt <rostedt@goodmis.org>
>
> Commit 64cf7d058a00 ("tracing: Have trace_marker use per-cpu data to read
> user space") made an update that fixed both trace_marker and
> trace_marker_raw. But the small difference made to trace_marker_raw had a
> blatant bug in it that any basic testing would have uncovered.
> Unfortunately, the self tests have tests for trace_marker but nothing for
> trace_marker_raw which allowed the bug to get upstream.
>
> Add basic selftests to test trace_marker_raw so that this doesn't happen
> again.
>
Looks good to me.
Acked-by: Masami Hiramatsu (Google) <mhiramat@kernel.org>
Thanks!
> Signed-off-by: Steven Rostedt (Google) <rostedt@goodmis.org>
> ---
> .../ftrace/test.d/00basic/trace_marker_raw.tc | 107 ++++++++++++++++++
> 1 file changed, 107 insertions(+)
> create mode 100644 tools/testing/selftests/ftrace/test.d/00basic/trace_marker_raw.tc
>
> 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
> new file mode 100644
> index 000000000000..7daf7292209e
> --- /dev/null
> +++ b/tools/testing/selftests/ftrace/test.d/00basic/trace_marker_raw.tc
> @@ -0,0 +1,107 @@
> +#!/bin/sh
> +# SPDX-License-Identifier: GPL-2.0
> +# description: Basic tests on writing to trace_marker_raw
> +# requires: trace_marker_raw
> +# flags: instance
> +
> +is_little_endian() {
> + if lscpu | grep -q 'Little Endian'; then
> + echo 1;
> + else
> + echo 0;
> + fi
> +}
> +
> +little=`is_little_endian`
> +
> +make_str() {
> + id=$1
> + cnt=$2
> +
> + if [ $little -eq 1 ]; then
> + val=`printf "\\%03o\\%03o\\%03o\\%03o" \
> + $(($id & 0xff)) \
> + $((($id >> 8) & 0xff)) \
> + $((($id >> 16) & 0xff)) \
> + $((($id >> 24) & 0xff))`
> + else
> + val=`printf "\\%03o\\%03o\\%03o\\%03o" \
> + $((($id >> 24) & 0xff)) \
> + $((($id >> 16) & 0xff)) \
> + $((($id >> 8) & 0xff)) \
> + $(($id & 0xff))`
> + fi
> +
> + data=`printf -- 'X%.0s' $(seq $cnt)`
> +
> + printf "${val}${data}"
> +}
> +
> +write_buffer() {
> + id=$1
> + size=$2
> +
> + # write the string into the raw marker
> + make_str $id $size > trace_marker_raw
> +}
> +
> +
> +test_multiple_writes() {
> +
> + # 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
> + done
> +
> + # add a little buffer
> + echo stop > trace_marker
> +
> + # 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;
> +}
> +
> +
> +get_buffer_data_size() {
> + sed -ne 's/^.*data.*size:\([0-9][0-9]*\).*/\1/p' events/header_page
> +}
> +
> +test_buffer() {
> +
> + # The id must be four bytes, test that 3 bytes fails a write
> + if echo -n abc > ./trace_marker_raw ; then
> + echo "Too small of write expected to fail but did not"
> + exit_fail
> + fi
> +
> + size=`get_buffer_data_size`
> + echo size = $size
> +
> + # Now add a little more than what it can handle
> +
> + if write_buffer 0xdeadbeef $size ; then
> + echo "Too big of write expected to fail but did not"
> + exit_fail
> + fi
> +}
> +
> +test_buffer
> +test_multiple_writes
> --
> 2.51.0
>
--
Masami Hiramatsu (Google) <mhiramat@kernel.org>
^ permalink raw reply [flat|nested] 5+ messages in thread* Re: [PATCH] selftests/tracing: Add basic test for trace_marker_raw file
2025-11-04 23:47 ` Masami Hiramatsu
@ 2025-11-06 22:25 ` Shuah Khan
0 siblings, 0 replies; 5+ messages in thread
From: Shuah Khan @ 2025-11-06 22:25 UTC (permalink / raw)
To: Masami Hiramatsu (Google), Steven Rostedt
Cc: LKML, Linux Trace Kernel, linux-kselftest, Mathieu Desnoyers,
Linus Torvalds, Shuah Khan
On 11/4/25 16:47, Masami Hiramatsu (Google) wrote:
> On Tue, 14 Oct 2025 14:51:49 -0400
> Steven Rostedt <rostedt@goodmis.org> wrote:
>
>> From: Steven Rostedt <rostedt@goodmis.org>
>>
>> Commit 64cf7d058a00 ("tracing: Have trace_marker use per-cpu data to read
>> user space") made an update that fixed both trace_marker and
>> trace_marker_raw. But the small difference made to trace_marker_raw had a
>> blatant bug in it that any basic testing would have uncovered.
>> Unfortunately, the self tests have tests for trace_marker but nothing for
>> trace_marker_raw which allowed the bug to get upstream.
>>
>> Add basic selftests to test trace_marker_raw so that this doesn't happen
>> again.
>>
>
> Looks good to me.
>
> Acked-by: Masami Hiramatsu (Google) <mhiramat@kernel.org>
>
Thanks. Applied to ksleftest next for 6.19-rc1.
thanks,
-- Shuah
^ permalink raw reply [flat|nested] 5+ messages in thread
end of thread, other threads:[~2025-11-06 22:25 UTC | newest]
Thread overview: 5+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2025-10-14 18:51 [PATCH] selftests/tracing: Add basic test for trace_marker_raw file Steven Rostedt
2025-10-14 20:14 ` Steven Rostedt
2025-11-03 17:10 ` Steven Rostedt
2025-11-04 23:47 ` Masami Hiramatsu
2025-11-06 22:25 ` Shuah Khan
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).