History

selftests: ftrace: Add probe event argument syntax testcase

Add a testcase for probe event argument syntax which ensures the kprobe_events interface correctly parses given event arguments. Link: http://lkml.kernel.org/r/152129033679.31874.12705519603869152799.stgit@devbox

Masami Hiramatsu committed 8 years ago

Commit 871bef21 parent c5d343b1 file · +97 −0Browse files

Unified · Split

tools/testing/selftests/ftrace/test.d/kprobe/kprobe_args_syntax.tc+97−0
@@ -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+
7+grep "x8/16/32/64" README > /dev/null || exit_unsupported # version issue
8+
9+echo 0 > events/enable
10+echo > kprobe_events
11+
12+PROBEFUNC="vfs_read"
13+GOODREG=
14+BADREG=
15+GOODSYM="_sdata"
16+if ! grep -qw ${GOODSYM} /proc/kallsyms ; then
17+ GOODSYM=$PROBEFUNC
18+fi
19+BADSYM="deaqswdefr"
20+SYMADDR=0x`grep -w ${GOODSYM} /proc/kallsyms | cut -f 1 -d " "`
21+GOODTYPE="x16"
22+BADTYPE="y16"
23+
24+case `uname -m` in
25+x86_64|i[3456]86)
26+ GOODREG=%ax
27+ BADREG=%ex
28+;;
29+aarch64)
30+ GOODREG=%x0
31+ BADREG=%ax
32+;;
33+arm*)
34+ GOODREG=%r0
35+ BADREG=%ax
36+;;
37+esac
38+
39+test_goodarg() # Good-args
40+{
41+ while [ "$1" ]; do
42+ echo "p ${PROBEFUNC} $1" > kprobe_events
43+ shift 1
44+ done;
45+}
46+
47+test_badarg() # Bad-args
48+{
49+ while [ "$1" ]; do
50+ ! echo "p ${PROBEFUNC} $1" > kprobe_events
51+ shift 1
52+ done;
53+}
54+
55+echo > kprobe_events
56+
57+: "Register access"
58+test_goodarg ${GOODREG}
59+test_badarg ${BADREG}
60+
61+: "Symbol access"
62+test_goodarg "@${GOODSYM}" "@${SYMADDR}" "@${GOODSYM}+10" "@${GOODSYM}-10"
63+test_badarg "@" "@${BADSYM}" "@${GOODSYM}*10" "@${GOODSYM}/10" \
64+ "@${GOODSYM}%10" "@${GOODSYM}&10" "@${GOODSYM}|10"
65+
66+: "Stack access"
67+test_goodarg "\$stack" "\$stack0" "\$stack1"
68+test_badarg "\$stackp" "\$stack0+10" "\$stack1-10"
69+
70+: "Retval access"
71+echo "r ${PROBEFUNC} \$retval" > kprobe_events
72+! echo "p ${PROBEFUNC} \$retval" > kprobe_events
73+
74+: "Comm access"
75+test_goodarg "\$comm"
76+
77+: "Indirect memory access"
78+test_goodarg "+0(${GOODREG})" "-0(${GOODREG})" "+10(\$stack)" \
79+ "+0(\$stack1)" "+10(@${GOODSYM}-10)" "+0(+10(+20(\$stack)))"
80+test_badarg "+(${GOODREG})" "(${GOODREG}+10)" "-(${GOODREG})" "(${GOODREG})" \
81+ "+10(\$comm)" "+0(${GOODREG})+10"
82+
83+: "Name assignment"
84+test_goodarg "varname=${GOODREG}"
85+test_badarg "varname=varname2=${GOODREG}"
86+
87+: "Type syntax"
88+test_goodarg "${GOODREG}:${GOODTYPE}"
89+test_badarg "${GOODREG}::${GOODTYPE}" "${GOODREG}:${BADTYPE}" \
90+ "${GOODTYPE}:${GOODREG}"
91+
92+: "Combination check"
93+
94+test_goodarg "\$comm:string" "+0(\$stack):string"
95+test_badarg "\$comm:x64" "\$stack:string" "${GOODREG}:string"
96+
97+echo > kprobe_events

Keyboard shortcuts

General

Show keyboard shortcuts
?
Focus the current search
/

Issues and pull requests

Open filters
f

Issues, pull requests and Inbox

Select next item
j↓
Select previous item
k↑
Open selected item
Enter
Dismiss filters or clear selection
Esc

Repository code

Go to file
t