xref: /linux/tools/testing/selftests/ftrace/test.d/dynevent/add_remove_fprobe_module.tc (revision beaba8bfbb91e3bb3133eacacd62fd6fea515e34)
1#!/bin/sh
2# SPDX-License-Identifier: GPL-2.0
3# description: Generic dynamic event - add/remove fprobe events on module
4# requires: dynamic_events "f[:[<group>/][<event>]] <func-name>[%return] [<args>]":README enabled_functions
5
6rmmod trace-events-sample ||:
7if ! modprobe trace-events-sample ; then
8  echo "No trace-events sample module - please make CONFIG_SAMPLE_TRACE_EVENTS=m"
9  exit_unresolved;
10fi
11trap "lsmod | grep -q trace_events_sample && rmmod trace-events-sample" EXIT
12
13echo 0 > events/enable
14echo > dynamic_events
15
16FUNC1='foo_bar*'
17FUNC2='vfs_read'
18
19:;: "Add an event on the test module" ;:
20echo "f:test1 $FUNC1" >> dynamic_events
21echo 1 > events/fprobes/test1/enable
22
23:;: "Ensure it is enabled" ;:
24funcs=`cat enabled_functions | wc -l`
25test $funcs -ne 0
26
27:;: "Check the enabled_functions is cleared on unloading" ;:
28rmmod trace-events-sample
29funcs=`cat enabled_functions | wc -l`
30test $funcs -eq 0
31
32:;: "Check it is kept clean" ;:
33modprobe trace-events-sample
34echo 1 > events/fprobes/test1/enable || echo "OK"
35funcs=`cat enabled_functions | wc -l`
36test $funcs -eq 0
37
38:;: "Add another event not on the test module" ;:
39echo "f:test2 $FUNC2" >> dynamic_events
40echo 1 > events/fprobes/test2/enable
41
42:;: "Ensure it is enabled" ;:
43ofuncs=`cat enabled_functions | wc -l`
44test $ofuncs -ne 0
45
46:;: "Disable and remove the first event"
47echo 0 > events/fprobes/test1/enable
48echo "-:fprobes/test1" >> dynamic_events
49funcs=`cat enabled_functions | wc -l`
50test $ofuncs -eq $funcs
51
52:;: "Disable and remove other events" ;:
53echo 0 > events/fprobes/enable
54echo > dynamic_events
55funcs=`cat enabled_functions | wc -l`
56test $funcs -eq 0
57
58rmmod trace-events-sample
59
60:;: "Add events on kernel and test module" ;:
61modprobe trace-events-sample
62echo "f:test1 $FUNC1" >> dynamic_events
63echo 1 > events/fprobes/test1/enable
64echo "f:test2 $FUNC2" >> dynamic_events
65echo 1 > events/fprobes/test2/enable
66ofuncs=`cat enabled_functions | wc -l`
67test $ofuncs -ne 0
68
69:;: "Unload module (ftrace entry should be removed)" ;:
70rmmod trace-events-sample
71funcs=`cat enabled_functions | wc -l`
72test $funcs -ne 0
73test $ofuncs -ne $funcs
74
75:;: "Disable and remove core-kernel fprobe event" ;:
76echo 0 > events/fprobes/test2/enable
77echo "-:fprobes/test2" >> dynamic_events
78
79:;: "Ensure ftrace is disabled." ;:
80funcs=`cat enabled_functions | wc -l`
81test $funcs -eq 0
82
83echo 0 > events/fprobes/enable
84echo > dynamic_events
85
86trap "" EXIT
87clear_trace
88