Skip to content

Commit d8b39e1

Browse files
committed
selftests: ftrace: Add a test to test function triggers to start and stop tracing
This adds a test to test the function tiggers traceon and traceoff to make sure that it starts and stops tracing when a function is hit. The test performs the following: o Enables all events o Writes schedule:traceoff into set_ftrace_filter o Makes sure the tigger exists in the file o Makes sure the trace file no longer grows o Makes sure that tracing_on is now zero o Clears the trace file o Makes sure it's still empty o Removes the trigger o Makes sure tracing is still off (tracing_on is zero) o Writes schedule:traceon into set_ftrace_filter o Makes sure the trace file is no longer empty o Makes sure that tracing_on file is set to one o Removes the trigger o Makes sure the trigger is no longer there o Writes schedule:traceoff:3 into set_ftrace_filter o Makes sure that tracing_on turns off . Writes 1 into tracing_on . Makes sure that it turns off 2 more times o Writes 1 into tracing_on o Makes sure that tracing_on is still a one Signed-off-by: Steven Rostedt (VMware) <rostedt@goodmis.org>
1 parent 43bb45d commit d8b39e1

1 file changed

Lines changed: 171 additions & 0 deletions

File tree

Lines changed: 171 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,171 @@
1+
#!/bin/sh
2+
# description: ftrace - test for function traceon/off 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 enabling and disabling tracing 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 enabling disabling tracing:"
36+
37+
cnt_trace() {
38+
grep -v '^#' trace | wc -l
39+
}
40+
41+
echo '** DISABLE TRACING'
42+
disable_tracing
43+
clear_trace
44+
45+
cnt=`cnt_trace`
46+
if [ $cnt -ne 0 ]; then
47+
fail "Found junk in trace"
48+
fi
49+
50+
51+
echo '** ENABLE EVENTS'
52+
53+
echo 1 > events/enable
54+
55+
echo '** ENABLE TRACING'
56+
enable_tracing
57+
58+
cnt=`cnt_trace`
59+
if [ $cnt -eq 0 ]; then
60+
fail "Nothing found in trace"
61+
fi
62+
63+
# powerpc uses .schedule
64+
func="schedule"
65+
x=`grep '^\.schedule$' available_filter_functions | wc -l`
66+
if [ "$x" -eq 1 ]; then
67+
func=".schedule"
68+
fi
69+
70+
echo '** SET TRACEOFF'
71+
72+
echo "$func:traceoff" > set_ftrace_filter
73+
74+
cnt=`grep schedule set_ftrace_filter | wc -l`
75+
if [ $cnt -ne 1 ]; then
76+
fail "Did not find traceoff trigger"
77+
fi
78+
79+
cnt=`cnt_trace`
80+
sleep $SLEEP_TIME
81+
cnt2=`cnt_trace`
82+
83+
if [ $cnt -ne $cnt2 ]; then
84+
fail "Tracing is not stopped"
85+
fi
86+
87+
on=`cat tracing_on`
88+
if [ $on != "0" ]; then
89+
fail "Tracing is not off"
90+
fi
91+
92+
line1=`cat trace | tail -1`
93+
sleep $SLEEP_TIME
94+
line2=`cat trace | tail -1`
95+
96+
if [ "$line1" != "$line2" ]; then
97+
fail "Tracing file is still changing"
98+
fi
99+
100+
clear_trace
101+
102+
cnt=`cnt_trace`
103+
if [ $cnt -ne 0 ]; then
104+
fail "Tracing is still happeing"
105+
fi
106+
107+
echo "!$func:traceoff" >> set_ftrace_filter
108+
109+
cnt=`grep schedule set_ftrace_filter | wc -l`
110+
if [ $cnt -ne 0 ]; then
111+
fail "traceoff trigger still exists"
112+
fi
113+
114+
on=`cat tracing_on`
115+
if [ $on != "0" ]; then
116+
fail "Tracing is started again"
117+
fi
118+
119+
echo "$func:traceon" > set_ftrace_filter
120+
121+
cnt=`grep schedule set_ftrace_filter | wc -l`
122+
if [ $cnt -ne 1 ]; then
123+
fail "traceon trigger not found"
124+
fi
125+
126+
cnt=`cnt_trace`
127+
if [ $cnt -eq 0 ]; then
128+
fail "Tracing did not start"
129+
fi
130+
131+
on=`cat tracing_on`
132+
if [ $on != "1" ]; then
133+
fail "Tracing was not enabled"
134+
fi
135+
136+
137+
echo "!$func:traceon" >> set_ftrace_filter
138+
139+
cnt=`grep schedule set_ftrace_filter | wc -l`
140+
if [ $cnt -ne 0 ]; then
141+
fail "traceon trigger still exists"
142+
fi
143+
144+
check_sleep() {
145+
val=$1
146+
sleep $SLEEP_TIME
147+
cat set_ftrace_filter
148+
on=`cat tracing_on`
149+
if [ $on != "$val" ]; then
150+
fail "Expected tracing_on to be $val, but it was $on"
151+
fi
152+
}
153+
154+
155+
echo "$func:traceoff:3" > set_ftrace_filter
156+
check_sleep "0"
157+
echo 1 > tracing_on
158+
check_sleep "0"
159+
echo 1 > tracing_on
160+
check_sleep "0"
161+
echo 1 > tracing_on
162+
check_sleep "1"
163+
echo "!$func:traceoff:0" > set_ftrace_filter
164+
165+
if grep -e traceon -e traceoff set_ftrace_filter; then
166+
fail "Tracing on and off triggers still exist"
167+
fi
168+
169+
disable_events
170+
171+
exit 0

0 commit comments

Comments
 (0)