Skip to content

Commit

Permalink
selftests/ftrace: Improve kprobe on module testcase to load/unload mo…
Browse files Browse the repository at this point in the history
…dule

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>
  • Loading branch information
Masami Hiramatsu authored and Shuah Khan (Samsung OSG) committed Oct 24, 2018
1 parent cec3adf commit af2a075
Show file tree
Hide file tree
Showing 2 changed files with 36 additions and 3 deletions.
4 changes: 4 additions & 0 deletions tools/testing/selftests/ftrace/config
Original file line number Diff line number Diff line change
Expand Up @@ -7,3 +7,7 @@ CONFIG_HIST_TRIGGERS=y
CONFIG_PREEMPT_TRACER=y
CONFIG_IRQSOFF_TRACER=y
CONFIG_PREEMPTIRQ_DELAY_TEST=m
CONFIG_MODULES=y
CONFIG_MODULE_UNLOAD=y
CONFIG_SAMPLES=y
CONFIG_SAMPLE_TRACE_PRINTK=m
35 changes: 32 additions & 3 deletions tools/testing/selftests/ftrace/test.d/kprobe/kprobe_module.tc
Original file line number Diff line number Diff line change
Expand Up @@ -4,11 +4,18 @@

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

rmmod trace-printk ||:
if ! modprobe trace-printk ; then
echo "No trace-printk sample module - please make CONFIG_SAMPLE_TRACE_PRINTK=
m"
exit_unresolved;
fi

MOD=trace_printk
FUNC=trace_printk_irq_work

:;: "Add an event on a module function without specifying event name" ;:

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

echo "p:kprobes1/event1 $MOD:$FUNC" > kprobe_events
test -d events/kprobes1/event1 || exit_failure

:;: "Remove target module, but event still be there" ;:
if ! rmmod trace-printk ; then
echo "Failed to unload module - please enable CONFIG_MODULE_UNLOAD"
exit_unresolved;
fi
test -d events/kprobes1/event1

:;: "Check posibility to defining events on unloaded module";:
echo "p:event2 $MOD:$FUNC" >> kprobe_events

:;: "Target is gone, but we can prepare for next time";:
echo 1 > events/kprobes1/event1/enable

:;: "Load module again, which means the event1 should be recorded";:
modprobe trace-printk
grep "event1:" trace

:;: "Remove the module again and check the event is not locked"
rmmod trace-printk
echo 0 > events/kprobes1/event1/enable
echo "-:kprobes1/event1" >> kprobe_events

0 comments on commit af2a075

Please sign in to comment.