xref: /linux/tools/testing/selftests/ftrace/test.d/kprobe/kprobe_module.tc (revision 2f0f6b0773be0a1ec475097ae54848eea42adc7d)
1#!/bin/sh
2# SPDX-License-Identifier: GPL-2.0
3# description: Kprobe dynamic event - probing module
4# requires: kprobe_events
5
6rmmod trace-printk ||:
7if ! modprobe trace-printk ; then
8  echo "No trace-printk sample module - please make CONFIG_SAMPLE_TRACE_PRINTK=
9m"
10  exit_unresolved;
11fi
12
13MOD=trace_printk
14FUNC=trace_printk_irq_work
15
16:;: "Add an event on a module function without module name" ;:
17
18echo "p:event0 $FUNC" > kprobe_events
19test -d events/kprobes/event0 || exit_failure
20echo "-:kprobes/event0" >> kprobe_events
21
22:;: "Add an event on a module function without specifying event name" ;:
23
24echo "p $MOD:$FUNC" > kprobe_events
25PROBE_NAME=`echo $MOD:$FUNC | tr ".:" "_"`
26test -d events/kprobes/p_${PROBE_NAME}_0 || exit_failure
27
28:;: "Add an event on a module function with new event name" ;:
29
30echo "p:event1 $MOD:$FUNC" > kprobe_events
31test -d events/kprobes/event1 || exit_failure
32
33:;: "Add an event on a module function with new event and group name" ;:
34
35echo "p:kprobes1/event1 $MOD:$FUNC" > kprobe_events
36test -d events/kprobes1/event1 || exit_failure
37
38:;: "Remove target module, but event still be there" ;:
39if ! rmmod trace-printk ; then
40  echo "Failed to unload module - please enable CONFIG_MODULE_UNLOAD"
41  exit_unresolved;
42fi
43test -d events/kprobes1/event1
44
45:;: "Check posibility to defining events on unloaded module";:
46echo "p:event2 $MOD:$FUNC" >> kprobe_events
47
48:;: "Target is gone, but we can prepare for next time";:
49echo 1 > events/kprobes1/event1/enable
50
51:;: "Load module again, which means the event1 should be recorded";:
52modprobe trace-printk
53grep "event1:" trace
54
55:;: "Remove the module again and check the event is not locked"
56rmmod trace-printk
57echo 0 > events/kprobes1/event1/enable
58echo "-:kprobes1/event1" >> kprobe_events
59