aboutsummaryrefslogtreecommitdiffstats
path: root/tools
diff options
context:
space:
mode:
authorLinus Torvalds <torvalds@linux-foundation.org>2018-03-23 18:34:18 -0400
committerLinus Torvalds <torvalds@linux-foundation.org>2018-03-23 18:34:18 -0400
commit99fec39e7725d091c94d1bb0242e40c8092994f6 (patch)
tree939bc96eb4de6a5d269b189f45b849d4aa0bc468 /tools
parent86d043d47c91cf40f19d3c0d9b21ec8ccee2826a (diff)
parentdfa453bc90eca0febff33c8d292a656e53702158 (diff)
Merge tag 'trace-v4.16-rc4' of git://git.kernel.org/pub/scm/linux/kernel/git/rostedt/linux-trace
Pull kprobe fixes from Steven Rostedt: "The documentation for kprobe events says that symbol offets can take both a + and - sign to get to befor and after the symbol address. But in actuality, the code does not support the minus. This fixes that issue, and adds a few more selftests to kprobe events" * tag 'trace-v4.16-rc4' of git://git.kernel.org/pub/scm/linux/kernel/git/rostedt/linux-trace: selftests: ftrace: Add a testcase for probepoint selftests: ftrace: Add a testcase for string type with kprobe_event selftests: ftrace: Add probe event argument syntax testcase tracing: probeevent: Fix to support minus offset from symbol
Diffstat (limited to 'tools')
-rw-r--r--tools/testing/selftests/ftrace/test.d/kprobe/kprobe_args_string.tc46
-rw-r--r--tools/testing/selftests/ftrace/test.d/kprobe/kprobe_args_syntax.tc97
-rw-r--r--tools/testing/selftests/ftrace/test.d/kprobe/probepoint.tc43
3 files changed, 186 insertions, 0 deletions
diff --git a/tools/testing/selftests/ftrace/test.d/kprobe/kprobe_args_string.tc b/tools/testing/selftests/ftrace/test.d/kprobe/kprobe_args_string.tc
new file mode 100644
index 000000000000..5ba73035e1d9
--- /dev/null
+++ b/tools/testing/selftests/ftrace/test.d/kprobe/kprobe_args_string.tc
@@ -0,0 +1,46 @@
1#!/bin/sh
2# SPDX-License-Identifier: GPL-2.0
3# description: Kprobe event string type argument
4
5[ -f kprobe_events ] || exit_unsupported # this is configurable
6
7echo 0 > events/enable
8echo > kprobe_events
9
10case `uname -m` in
11x86_64)
12 ARG2=%si
13 OFFS=8
14;;
15i[3456]86)
16 ARG2=%cx
17 OFFS=4
18;;
19aarch64)
20 ARG2=%x1
21 OFFS=8
22;;
23arm*)
24 ARG2=%r1
25 OFFS=4
26;;
27*)
28 echo "Please implement other architecture here"
29 exit_untested
30esac
31
32: "Test get argument (1)"
33echo "p:testprobe create_trace_kprobe arg1=+0(+0(${ARG2})):string" > kprobe_events
34echo 1 > events/kprobes/testprobe/enable
35! echo test >> kprobe_events
36tail -n 1 trace | grep -qe "testprobe.* arg1=\"test\""
37
38echo 0 > events/kprobes/testprobe/enable
39: "Test get argument (2)"
40echo "p:testprobe create_trace_kprobe arg1=+0(+0(${ARG2})):string arg2=+0(+${OFFS}(${ARG2})):string" > kprobe_events
41echo 1 > events/kprobes/testprobe/enable
42! echo test1 test2 >> kprobe_events
43tail -n 1 trace | grep -qe "testprobe.* arg1=\"test1\" arg2=\"test2\""
44
45echo 0 > events/enable
46echo > kprobe_events
diff --git a/tools/testing/selftests/ftrace/test.d/kprobe/kprobe_args_syntax.tc b/tools/testing/selftests/ftrace/test.d/kprobe/kprobe_args_syntax.tc
new file mode 100644
index 000000000000..231bcd2c4eb5
--- /dev/null
+++ b/tools/testing/selftests/ftrace/test.d/kprobe/kprobe_args_syntax.tc
@@ -0,0 +1,97 @@
1#!/bin/sh
2# SPDX-License-Identifier: GPL-2.0
3# description: Kprobe event argument syntax
4
5[ -f kprobe_events ] || exit_unsupported # this is configurable
6
7grep "x8/16/32/64" README > /dev/null || exit_unsupported # version issue
8
9echo 0 > events/enable
10echo > kprobe_events
11
12PROBEFUNC="vfs_read"
13GOODREG=
14BADREG=
15GOODSYM="_sdata"
16if ! grep -qw ${GOODSYM} /proc/kallsyms ; then
17 GOODSYM=$PROBEFUNC
18fi
19BADSYM="deaqswdefr"
20SYMADDR=0x`grep -w ${GOODSYM} /proc/kallsyms | cut -f 1 -d " "`
21GOODTYPE="x16"
22BADTYPE="y16"
23
24case `uname -m` in
25x86_64|i[3456]86)
26 GOODREG=%ax
27 BADREG=%ex
28;;
29aarch64)
30 GOODREG=%x0
31 BADREG=%ax
32;;
33arm*)
34 GOODREG=%r0
35 BADREG=%ax
36;;
37esac
38
39test_goodarg() # Good-args
40{
41 while [ "$1" ]; do
42 echo "p ${PROBEFUNC} $1" > kprobe_events
43 shift 1
44 done;
45}
46
47test_badarg() # Bad-args
48{
49 while [ "$1" ]; do
50 ! echo "p ${PROBEFUNC} $1" > kprobe_events
51 shift 1
52 done;
53}
54
55echo > kprobe_events
56
57: "Register access"
58test_goodarg ${GOODREG}
59test_badarg ${BADREG}
60
61: "Symbol access"
62test_goodarg "@${GOODSYM}" "@${SYMADDR}" "@${GOODSYM}+10" "@${GOODSYM}-10"
63test_badarg "@" "@${BADSYM}" "@${GOODSYM}*10" "@${GOODSYM}/10" \
64 "@${GOODSYM}%10" "@${GOODSYM}&10" "@${GOODSYM}|10"
65
66: "Stack access"
67test_goodarg "\$stack" "\$stack0" "\$stack1"
68test_badarg "\$stackp" "\$stack0+10" "\$stack1-10"
69
70: "Retval access"
71echo "r ${PROBEFUNC} \$retval" > kprobe_events
72! echo "p ${PROBEFUNC} \$retval" > kprobe_events
73
74: "Comm access"
75test_goodarg "\$comm"
76
77: "Indirect memory access"
78test_goodarg "+0(${GOODREG})" "-0(${GOODREG})" "+10(\$stack)" \
79 "+0(\$stack1)" "+10(@${GOODSYM}-10)" "+0(+10(+20(\$stack)))"
80test_badarg "+(${GOODREG})" "(${GOODREG}+10)" "-(${GOODREG})" "(${GOODREG})" \
81 "+10(\$comm)" "+0(${GOODREG})+10"
82
83: "Name assignment"
84test_goodarg "varname=${GOODREG}"
85test_badarg "varname=varname2=${GOODREG}"
86
87: "Type syntax"
88test_goodarg "${GOODREG}:${GOODTYPE}"
89test_badarg "${GOODREG}::${GOODTYPE}" "${GOODREG}:${BADTYPE}" \
90 "${GOODTYPE}:${GOODREG}"
91
92: "Combination check"
93
94test_goodarg "\$comm:string" "+0(\$stack):string"
95test_badarg "\$comm:x64" "\$stack:string" "${GOODREG}:string"
96
97echo > kprobe_events
diff --git a/tools/testing/selftests/ftrace/test.d/kprobe/probepoint.tc b/tools/testing/selftests/ftrace/test.d/kprobe/probepoint.tc
new file mode 100644
index 000000000000..4fda01a08da4
--- /dev/null
+++ b/tools/testing/selftests/ftrace/test.d/kprobe/probepoint.tc
@@ -0,0 +1,43 @@
1#!/bin/sh
2# SPDX-License-Identifier: GPL-2.0
3# description: Kprobe events - probe points
4
5[ -f kprobe_events ] || exit_unsupported # this is configurable
6
7TARGET_FUNC=create_trace_kprobe
8
9dec_addr() { # hexaddr
10 printf "%d" "0x"`echo $1 | tail -c 8`
11}
12
13set_offs() { # prev target next
14 A1=`dec_addr $1`
15 A2=`dec_addr $2`
16 A3=`dec_addr $3`
17 TARGET="0x$2" # an address
18 PREV=`expr $A1 - $A2` # offset to previous symbol
19 NEXT=+`expr $A3 - $A2` # offset to next symbol
20 OVERFLOW=+`printf "0x%x" ${PREV}` # overflow offset to previous symbol
21}
22
23# We have to decode symbol addresses to get correct offsets.
24# If the offset is not an instruction boundary, it cause -EILSEQ.
25set_offs `grep -A1 -B1 ${TARGET_FUNC} /proc/kallsyms | cut -f 1 -d " " | xargs`
26
27UINT_TEST=no
28# printf "%x" -1 returns (unsigned long)-1.
29if [ `printf "%x" -1 | wc -c` != 9 ]; then
30 UINT_TEST=yes
31fi
32
33echo 0 > events/enable
34echo > kprobe_events
35echo "p:testprobe ${TARGET_FUNC}" > kprobe_events
36echo "p:testprobe ${TARGET}" > kprobe_events
37echo "p:testprobe ${TARGET_FUNC}${NEXT}" > kprobe_events
38! echo "p:testprobe ${TARGET_FUNC}${PREV}" > kprobe_events
39if [ "${UINT_TEST}" = yes ]; then
40! echo "p:testprobe ${TARGET_FUNC}${OVERFLOW}" > kprobe_events
41fi
42echo > kprobe_events
43clear_trace