Skip to content

Commit af2a075

Browse files
mhiramatShuah Khan (Samsung OSG)
authored andcommitted
selftests/ftrace: Improve kprobe on module testcase to load/unload module
Improve kprobe events on module testcase to check module load/unload with disabled/enabled events. This also change the target module to trace_printk.ko, so it depends on CONFIG_SAMPLE_TRACE_PRINTK=m. Signed-off-by: Masami Hiramatsu <mhiramat@kernel.org> Signed-off-by: Shuah Khan (Samsung OSG) <shuah@kernel.org>
1 parent cec3adf commit af2a075

2 files changed

Lines changed: 36 additions & 3 deletions

File tree

‎tools/testing/selftests/ftrace/config‎

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -7,3 +7,7 @@ CONFIG_HIST_TRIGGERS=y
77
CONFIG_PREEMPT_TRACER=y
88
CONFIG_IRQSOFF_TRACER=y
99
CONFIG_PREEMPTIRQ_DELAY_TEST=m
10+
CONFIG_MODULES=y
11+
CONFIG_MODULE_UNLOAD=y
12+
CONFIG_SAMPLES=y
13+
CONFIG_SAMPLE_TRACE_PRINTK=m

‎tools/testing/selftests/ftrace/test.d/kprobe/kprobe_module.tc‎

Lines changed: 32 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -4,11 +4,18 @@
44

55
[ -f kprobe_events ] || exit_unsupported # this is configurable
66

7+
rmmod trace-printk ||:
8+
if ! modprobe trace-printk ; then
9+
echo "No trace-printk sample module - please make CONFIG_SAMPLE_TRACE_PRINTK=
10+
m"
11+
exit_unresolved;
12+
fi
13+
14+
MOD=trace_printk
15+
FUNC=trace_printk_irq_work
16+
717
:;: "Add an event on a module function without specifying event name" ;:
818

9-
MOD=`lsmod | head -n 2 | tail -n 1 | cut -f1 -d" "`
10-
FUNC=`grep -m 1 ".* t .*\\[$MOD\\]" /proc/kallsyms | xargs | cut -f3 -d" "`
11-
[ "x" != "x$MOD" -a "y" != "y$FUNC" ] || exit_unresolved
1219
echo "p $MOD:$FUNC" > kprobe_events
1320
PROBE_NAME=`echo $MOD:$FUNC | tr ".:" "_"`
1421
test -d events/kprobes/p_${PROBE_NAME}_0 || exit_failure
@@ -22,3 +29,25 @@ test -d events/kprobes/event1 || exit_failure
2229

2330
echo "p:kprobes1/event1 $MOD:$FUNC" > kprobe_events
2431
test -d events/kprobes1/event1 || exit_failure
32+
33+
:;: "Remove target module, but event still be there" ;:
34+
if ! rmmod trace-printk ; then
35+
echo "Failed to unload module - please enable CONFIG_MODULE_UNLOAD"
36+
exit_unresolved;
37+
fi
38+
test -d events/kprobes1/event1
39+
40+
:;: "Check posibility to defining events on unloaded module";:
41+
echo "p:event2 $MOD:$FUNC" >> kprobe_events
42+
43+
:;: "Target is gone, but we can prepare for next time";:
44+
echo 1 > events/kprobes1/event1/enable
45+
46+
:;: "Load module again, which means the event1 should be recorded";:
47+
modprobe trace-printk
48+
grep "event1:" trace
49+
50+
:;: "Remove the module again and check the event is not locked"
51+
rmmod trace-printk
52+
echo 0 > events/kprobes1/event1/enable
53+
echo "-:kprobes1/event1" >> kprobe_events

0 commit comments

Comments
 (0)