Skip to content

Commit 37f4660

Browse files
rostedtshuahkh
authored andcommitted
selftests/tracing: Add basic test for trace_marker_raw file
Commit 64cf7d0 ("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. Link: https://lore.kernel.org/r/20251014145149.3e3c1033@gandalf.local.home Signed-off-by: Steven Rostedt (Google) <rostedt@goodmis.org> Acked-by: Masami Hiramatsu (Google) <mhiramat@kernel.org> Signed-off-by: Shuah Khan <skhan@linuxfoundation.org>
1 parent 3a86608 commit 37f4660

1 file changed

Lines changed: 107 additions & 0 deletions

File tree

Lines changed: 107 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,107 @@
1+
#!/bin/sh
2+
# SPDX-License-Identifier: GPL-2.0
3+
# description: Basic tests on writing to trace_marker_raw
4+
# requires: trace_marker_raw
5+
# flags: instance
6+
7+
is_little_endian() {
8+
if lscpu | grep -q 'Little Endian'; then
9+
echo 1;
10+
else
11+
echo 0;
12+
fi
13+
}
14+
15+
little=`is_little_endian`
16+
17+
make_str() {
18+
id=$1
19+
cnt=$2
20+
21+
if [ $little -eq 1 ]; then
22+
val=`printf "\\%03o\\%03o\\%03o\\%03o" \
23+
$(($id & 0xff)) \
24+
$((($id >> 8) & 0xff)) \
25+
$((($id >> 16) & 0xff)) \
26+
$((($id >> 24) & 0xff))`
27+
else
28+
val=`printf "\\%03o\\%03o\\%03o\\%03o" \
29+
$((($id >> 24) & 0xff)) \
30+
$((($id >> 16) & 0xff)) \
31+
$((($id >> 8) & 0xff)) \
32+
$(($id & 0xff))`
33+
fi
34+
35+
data=`printf -- 'X%.0s' $(seq $cnt)`
36+
37+
printf "${val}${data}"
38+
}
39+
40+
write_buffer() {
41+
id=$1
42+
size=$2
43+
44+
# write the string into the raw marker
45+
make_str $id $size > trace_marker_raw
46+
}
47+
48+
49+
test_multiple_writes() {
50+
51+
# Write a bunch of data where the id is the count of
52+
# data to write
53+
for i in `seq 1 10` `seq 101 110` `seq 1001 1010`; do
54+
write_buffer $i $i
55+
done
56+
57+
# add a little buffer
58+
echo stop > trace_marker
59+
60+
# Check to make sure the number of entries is the id (rounded up by 4)
61+
awk '/.*: # [0-9a-f]* / {
62+
print;
63+
cnt = -1;
64+
for (i = 0; i < NF; i++) {
65+
# The counter is after the "#" marker
66+
if ( $i == "#" ) {
67+
i++;
68+
cnt = strtonum("0x" $i);
69+
num = NF - (i + 1);
70+
# The number of items is always rounded up by 4
71+
cnt2 = int((cnt + 3) / 4) * 4;
72+
if (cnt2 != num) {
73+
exit 1;
74+
}
75+
break;
76+
}
77+
}
78+
}
79+
// { if (NR > 30) { exit 0; } } ' trace_pipe;
80+
}
81+
82+
83+
get_buffer_data_size() {
84+
sed -ne 's/^.*data.*size:\([0-9][0-9]*\).*/\1/p' events/header_page
85+
}
86+
87+
test_buffer() {
88+
89+
# The id must be four bytes, test that 3 bytes fails a write
90+
if echo -n abc > ./trace_marker_raw ; then
91+
echo "Too small of write expected to fail but did not"
92+
exit_fail
93+
fi
94+
95+
size=`get_buffer_data_size`
96+
echo size = $size
97+
98+
# Now add a little more than what it can handle
99+
100+
if write_buffer 0xdeadbeef $size ; then
101+
echo "Too big of write expected to fail but did not"
102+
exit_fail
103+
fi
104+
}
105+
106+
test_buffer
107+
test_multiple_writes

0 commit comments

Comments
 (0)