Skip to content

Commit 43bb45d

Browse files
committed
selftests: ftrace: Add a selftest to test event enable/disable func trigger
This adds a test to enable and disable trace events via the function triggers. It tests enabling and disabling the sched:sched_switch event via the the event_enable and event_disable function triggers attached to the schedule() kernel function. The test does the following: o disable all events o disables or enables the sched_switch event o writes schedule:event_enable/disable:sched:sched_switch into set_ftrace_filter o 5 times it checks to make sure: . Writes 0/1 into the sched_switch/enable . Checks that the sched_switch/enable goes back to 1/0 o Resets the events o writes schedule:event_enable/disable:sched:sched_switch:3 into set_ftrace_filter o Does a loop of 3 to see that sched_switch/enable file gets updated o Makes sure the sched_switch/enable stops getting updated Signed-off-by: Steven Rostedt (VMware) <rostedt@goodmis.org>
1 parent 8e5e19c commit 43bb45d

1 file changed

Lines changed: 113 additions & 0 deletions

File tree

Lines changed: 113 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,113 @@
1+
#!/bin/sh
2+
# description: ftrace - test for function event triggers
3+
#
4+
# Ftrace allows to add triggers to functions, such as enabling or disabling
5+
# tracing, enabling or disabling trace events, or recording a stack trace
6+
# within the ring buffer.
7+
#
8+
# This test is designed to test event triggers
9+
#
10+
11+
# The triggers are set within the set_ftrace_filter file
12+
if [ ! -f set_ftrace_filter ]; then
13+
echo "set_ftrace_filter not found? Is dynamic ftrace not set?"
14+
exit_unsupported
15+
fi
16+
17+
do_reset() {
18+
reset_ftrace_filter
19+
reset_tracer
20+
disable_events
21+
clear_trace
22+
enable_tracing
23+
}
24+
25+
fail() { # mesg
26+
do_reset
27+
echo $1
28+
exit $FAIL
29+
}
30+
31+
SLEEP_TIME=".1"
32+
33+
do_reset
34+
35+
echo "Testing function probes with events:"
36+
37+
EVENT="sched:sched_switch"
38+
EVENT_ENABLE="events/sched/sched_switch/enable"
39+
40+
cnt_trace() {
41+
grep -v '^#' trace | wc -l
42+
}
43+
44+
test_event_enabled() {
45+
val=$1
46+
47+
e=`cat $EVENT_ENABLE`
48+
if [ "$e" != $val ]; then
49+
echo "Expected $val but found $e"
50+
exit -1
51+
fi
52+
}
53+
54+
run_enable_disable() {
55+
enable=$1 # enable
56+
Enable=$2 # Enable
57+
check_disable=$3 # 0
58+
check_enable_star=$4 # 1*
59+
check_disable_star=$5 # 0*
60+
61+
cnt=`cnt_trace`
62+
if [ $cnt -ne 0 ]; then
63+
fail "Found junk in trace file"
64+
fi
65+
66+
echo "$Enable event all the time"
67+
68+
echo $check_disable > $EVENT_ENABLE
69+
sleep $SLEEP_TIME
70+
71+
test_event_enabled $check_disable
72+
73+
echo "schedule:${enable}_event:$EVENT" > set_ftrace_filter
74+
75+
echo " make sure it works 5 times"
76+
77+
for i in `seq 5`; do
78+
sleep $SLEEP_TIME
79+
echo " test $i"
80+
test_event_enabled $check_enable_star
81+
82+
echo $check_disable > $EVENT_ENABLE
83+
done
84+
sleep $SLEEP_TIME
85+
echo " make sure it's still works"
86+
test_event_enabled $check_enable_star
87+
88+
reset_ftrace_filter
89+
90+
echo " make sure it only works 3 times"
91+
92+
echo $check_disable > $EVENT_ENABLE
93+
sleep $SLEEP_TIME
94+
95+
echo "schedule:${enable}_event:$EVENT:3" > set_ftrace_filter
96+
97+
for i in `seq 3`; do
98+
sleep $SLEEP_TIME
99+
echo " test $i"
100+
test_event_enabled $check_enable_star
101+
102+
echo $check_disable > $EVENT_ENABLE
103+
done
104+
105+
sleep $SLEEP_TIME
106+
echo " make sure it stop working"
107+
test_event_enabled $check_disable_star
108+
109+
do_reset
110+
}
111+
112+
run_enable_disable enable Enable 0 "1*" "0*"
113+
run_enable_disable disable Disable 1 "0*" "1*"

0 commit comments

Comments
 (0)