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