summaryrefslogtreecommitdiffstats
path: root/tools/testing/selftests/ftrace/test.d/direct/kprobe-direct.tc
blob: e52e470a1f8f1c874c1cf3dd3578012bd24dcacc (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
#!/bin/sh
# SPDX-License-Identifier: GPL-2.0
# description: Test ftrace direct functions against kprobes
# requires: kprobe_events

rmmod ftrace-direct ||:
if ! modprobe ftrace-direct ; then
  echo "No ftrace-direct sample module - please build with CONFIG_SAMPLE_FTRACE_DIRECT=m"
  exit_unresolved;
fi

echo "Let the module run a little"
sleep 1

grep -q "my_direct_func: waking up" trace

rmmod ftrace-direct

echo 'p:kwake wake_up_process task=$arg1' > kprobe_events

start_direct() {
	echo > trace
	modprobe ftrace-direct
	sleep 1
	grep -q "my_direct_func: waking up" trace
}

stop_direct() {
	rmmod ftrace-direct
}

enable_probe() {
	echo > trace
	echo 1 > events/kprobes/kwake/enable
	sleep 1
	grep -q "kwake:" trace
}

disable_probe() {
	echo 0 > events/kprobes/kwake/enable
}

test_kprobes() {
	# probe -> direct -> no direct > no probe
	enable_probe
	start_direct
	stop_direct
	disable_probe

	# probe -> direct -> no probe > no direct
	enable_probe
	start_direct
	disable_probe
	stop_direct

	# direct -> probe -> no probe > no direct
	start_direct
	enable_probe
	disable_probe
	stop_direct

	# direct -> probe -> no direct > no noprobe
	start_direct
	enable_probe
	stop_direct
	disable_probe
}

test_kprobes

# Now do this with a second registered direct function
echo "Running with another ftrace direct function"

modprobe ftrace-direct-too

test_kprobes

rmmod ftrace-direct-too

echo > kprobe_events