Skip to content

Commit 2488655

Browse files
committed
Merge tag 'linux_kselftest-next-6.19-rc1' of git://git.kernel.org/pub/scm/linux/kernel/git/shuah/linux-kselftest
Pull kselftest updates from Shuah Khan: - Add basic test for trace_marker_raw file to tracing selftest - Fix invalid array access in printf dma_map_benchmark selftest - Add tprobe enable/disable testcase to tracing selftest - Update fprobe selftest for ftrace based fprobe * tag 'linux_kselftest-next-6.19-rc1' of git://git.kernel.org/pub/scm/linux/kernel/git/shuah/linux-kselftest: selftests: tracing: Update fprobe selftest for ftrace based fprobe selftests: tracing: Add tprobe enable/disable testcase selftests/run_kselftest.sh: exit with error if tests fail selftests/dma: fix invalid array access in printf selftests/tracing: Add basic test for trace_marker_raw file
2 parents 2ddcf49 + a2f7990 commit 2488655

File tree

6 files changed

+176
-19
lines changed

6 files changed

+176
-19
lines changed

tools/testing/selftests/dma/dma_map_benchmark.c

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -118,7 +118,7 @@ int main(int argc, char **argv)
118118
}
119119

120120
printf("dma mapping benchmark: threads:%d seconds:%d node:%d dir:%s granule: %d\n",
121-
threads, seconds, node, dir[directions], granule);
121+
threads, seconds, node, directions[dir], granule);
122122
printf("average map latency(us):%.1f standard deviation:%.1f\n",
123123
map.avg_map_100ns/10.0, map.map_stddev/10.0);
124124
printf("average unmap latency(us):%.1f standard deviation:%.1f\n",
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

tools/testing/selftests/ftrace/test.d/dynevent/add_remove_fprobe.tc

Lines changed: 4 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -28,25 +28,21 @@ test -d events/fprobes/myevent1
2828
test -d events/fprobes/myevent2
2929

3030
echo 1 > events/fprobes/myevent1/enable
31-
# Make sure the event is attached and is the only one
31+
# Make sure the event is attached.
3232
grep -q $PLACE enabled_functions
3333
cnt=`cat enabled_functions | wc -l`
34-
if [ $cnt -ne $((ocnt + 1)) ]; then
34+
if [ $cnt -eq $ocnt ]; then
3535
exit_fail
3636
fi
3737

3838
echo 1 > events/fprobes/myevent2/enable
39-
# It should till be the only attached function
40-
cnt=`cat enabled_functions | wc -l`
41-
if [ $cnt -ne $((ocnt + 1)) ]; then
42-
exit_fail
43-
fi
39+
cnt2=`cat enabled_functions | wc -l`
4440

4541
echo 1 > events/fprobes/myevent3/enable
4642
# If the function is different, the attached function should be increased
4743
grep -q $PLACE2 enabled_functions
4844
cnt=`cat enabled_functions | wc -l`
49-
if [ $cnt -ne $((ocnt + 2)) ]; then
45+
if [ $cnt -eq $cnt2 ]; then
5046
exit_fail
5147
fi
5248

@@ -56,12 +52,6 @@ echo "-:myevent2" >> dynamic_events
5652
grep -q myevent1 dynamic_events
5753
! grep -q myevent2 dynamic_events
5854

59-
# should still have 2 left
60-
cnt=`cat enabled_functions | wc -l`
61-
if [ $cnt -ne $((ocnt + 2)) ]; then
62-
exit_fail
63-
fi
64-
6555
echo 0 > events/fprobes/enable
6656
echo > dynamic_events
6757

Lines changed: 40 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,40 @@
1+
#!/bin/sh
2+
# SPDX-License-Identifier: GPL-2.0
3+
# description: Generic dynamic event - enable/disable tracepoint probe events
4+
# requires: dynamic_events "t[:[<group>/][<event>]] <tracepoint> [<args>]":README
5+
6+
echo 0 > events/enable
7+
echo > dynamic_events
8+
9+
TRACEPOINT=sched_switch
10+
ENABLEFILE=events/tracepoints/myprobe/enable
11+
12+
:;: "Add tracepoint event on $TRACEPOINT" ;:
13+
14+
echo "t:myprobe ${TRACEPOINT}" >> dynamic_events
15+
16+
:;: "Check enable/disable to ensure it works" ;:
17+
18+
echo 1 > $ENABLEFILE
19+
20+
grep -q $TRACEPOINT trace
21+
22+
echo 0 > $ENABLEFILE
23+
24+
echo > trace
25+
26+
! grep -q $TRACEPOINT trace
27+
28+
:;: "Repeat enable/disable to ensure it works" ;:
29+
30+
echo 1 > $ENABLEFILE
31+
32+
grep -q $TRACEPOINT trace
33+
34+
echo 0 > $ENABLEFILE
35+
36+
echo > trace
37+
38+
! grep -q $TRACEPOINT trace
39+
40+
exit 0

tools/testing/selftests/kselftest/runner.sh

Lines changed: 10 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -44,6 +44,12 @@ tap_timeout()
4444
fi
4545
}
4646

47+
report_failure()
48+
{
49+
echo "not ok $*"
50+
echo "$*" >> "$kselftest_failures_file"
51+
}
52+
4753
run_one()
4854
{
4955
DIR="$1"
@@ -105,7 +111,7 @@ run_one()
105111
echo "# $TEST_HDR_MSG"
106112
if [ ! -e "$TEST" ]; then
107113
echo "# Warning: file $TEST is missing!"
108-
echo "not ok $test_num $TEST_HDR_MSG"
114+
report_failure "$test_num $TEST_HDR_MSG"
109115
else
110116
if [ -x /usr/bin/stdbuf ]; then
111117
stdbuf="/usr/bin/stdbuf --output=L "
@@ -123,7 +129,7 @@ run_one()
123129
interpreter=$(head -n 1 "$TEST" | cut -c 3-)
124130
cmd="$stdbuf $interpreter ./$BASENAME_TEST"
125131
else
126-
echo "not ok $test_num $TEST_HDR_MSG"
132+
report_failure "$test_num $TEST_HDR_MSG"
127133
return
128134
fi
129135
fi
@@ -137,9 +143,9 @@ run_one()
137143
echo "ok $test_num $TEST_HDR_MSG # SKIP"
138144
elif [ $rc -eq $timeout_rc ]; then \
139145
echo "#"
140-
echo "not ok $test_num $TEST_HDR_MSG # TIMEOUT $kselftest_timeout seconds"
146+
report_failure "$test_num $TEST_HDR_MSG # TIMEOUT $kselftest_timeout seconds"
141147
else
142-
echo "not ok $test_num $TEST_HDR_MSG # exit=$rc"
148+
report_failure "$test_num $TEST_HDR_MSG # exit=$rc"
143149
fi)
144150
cd - >/dev/null
145151
fi

tools/testing/selftests/run_kselftest.sh

Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -33,6 +33,7 @@ Usage: $0 [OPTIONS]
3333
-c | --collection COLLECTION Run all tests from COLLECTION
3434
-l | --list List the available collection:test entries
3535
-d | --dry-run Don't actually run any tests
36+
-f | --no-error-on-fail Don't exit with an error just because tests failed
3637
-n | --netns Run each test in namespace
3738
-h | --help Show this usage info
3839
-o | --override-timeout Number of seconds after which we timeout
@@ -44,6 +45,7 @@ COLLECTIONS=""
4445
TESTS=""
4546
dryrun=""
4647
kselftest_override_timeout=""
48+
ERROR_ON_FAIL=true
4749
while true; do
4850
case "$1" in
4951
-s | --summary)
@@ -65,6 +67,9 @@ while true; do
6567
-d | --dry-run)
6668
dryrun="echo"
6769
shift ;;
70+
-f | --no-error-on-fail)
71+
ERROR_ON_FAIL=false
72+
shift ;;
6873
-n | --netns)
6974
RUN_IN_NETNS=1
7075
shift ;;
@@ -105,9 +110,18 @@ if [ -n "$TESTS" ]; then
105110
available="$(echo "$valid" | sed -e 's/ /\n/g')"
106111
fi
107112

113+
kselftest_failures_file="$(mktemp --tmpdir kselftest-failures-XXXXXX)"
114+
export kselftest_failures_file
115+
108116
collections=$(echo "$available" | cut -d: -f1 | sort | uniq)
109117
for collection in $collections ; do
110118
[ -w /dev/kmsg ] && echo "kselftest: Running tests in $collection" >> /dev/kmsg
111119
tests=$(echo "$available" | grep "^$collection:" | cut -d: -f2)
112120
($dryrun cd "$collection" && $dryrun run_many $tests)
113121
done
122+
123+
failures="$(cat "$kselftest_failures_file")"
124+
rm "$kselftest_failures_file"
125+
if "$ERROR_ON_FAIL" && [ "$failures" ]; then
126+
exit 1
127+
fi

0 commit comments

Comments
 (0)