Skip to content

Commit a9064f6

Browse files
committed
selftests: ftrace: Add test to test reading of set_ftrace_file
The set_ftrace_file lists both functions that are filtered, as well as function probes (triggers) that are attached to a function, like traceon or stacktrace, etc. The reading of this file is not as trivial as most pseudo files are, and there's been various bugs that have appeared in the past when there's a mix of probes and functions listed. There's also a difference when reading the file using dd with a block size of 1. This test performs the following: o Resets set_ftrace_filter o Makes sure only "#### all functions enabled ####" is listed (All checks uses cat, and dd with bs=1 and bs=100) o Adds a traceon trigger to schedule o Checks if only "#### all function enabled ####" and the trigger is there. o Adds tracing of schedule o Checks if only schedule and the trigger is there o Adds tracing of do_IRQ as well o Checks if only schedule, do_IRQ and the trigger is there o Adds a traceon trigger to do_IRQ o Checks if only schedule, do_IRQ and both triggers are there o Removes tracing of do_IRQ o Checks if only schedule and both triggers are there o Removes tracing of schedule o Checks if only "#### all functions enabled ####" and both triggers are there o Removes the triggers o Checks if only "#### all functions enabled ####" is there o Adds tracing of schedule o Checks if only schedule is there o Adds tracing of do_IRQ o Checks if only schedule and do_IRQ are there Signed-off-by: Steven Rostedt (VMware) <rostedt@goodmis.org>
1 parent d8b39e1 commit a9064f6

1 file changed

Lines changed: 132 additions & 0 deletions

File tree

Lines changed: 132 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,132 @@
1+
#!/bin/sh
2+
# description: ftrace - test reading of set_ftrace_filter
3+
#
4+
# The set_ftrace_filter file of ftrace is used to list functions as well as
5+
# triggers (probes) attached to functions. The code to read this file is not
6+
# straight forward and has had various bugs in the past. This test is designed
7+
# to add functions and triggers to that file in various ways and read that
8+
# file in various ways (cat vs dd).
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_tracer
19+
reset_ftrace_filter
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+
do_reset
32+
33+
FILTER=set_ftrace_filter
34+
FUNC1="schedule"
35+
FUNC2="do_IRQ"
36+
37+
ALL_FUNCS="#### all functions enabled ####"
38+
39+
test_func() {
40+
if ! echo "$1" | grep -q "^$2\$"; then
41+
return 0
42+
fi
43+
echo "$1" | grep -v "^$2\$"
44+
return 1
45+
}
46+
47+
check_set_ftrace_filter() {
48+
cat=`cat $FILTER`
49+
dd1=`dd if=$FILTER bs=1 | grep -v -e 'records in' -e 'records out' -e 'bytes copied'`
50+
dd100=`dd if=$FILTER bs=100 | grep -v -e 'records in' -e 'records out' -e 'bytes copied'`
51+
52+
echo "Testing '$@'"
53+
54+
while [ $# -gt 0 ]; do
55+
echo "test $1"
56+
if cat=`test_func "$cat" "$1"`; then
57+
return 0
58+
fi
59+
if dd1=`test_func "$dd1" "$1"`; then
60+
return 0
61+
fi
62+
if dd100=`test_func "$dd100" "$1"`; then
63+
return 0
64+
fi
65+
shift
66+
done
67+
68+
if [ -n "$cat" ]; then
69+
return 0
70+
fi
71+
if [ -n "$dd1" ]; then
72+
return 0
73+
fi
74+
if [ -n "$dd100" ]; then
75+
return 0
76+
fi
77+
return 1;
78+
}
79+
80+
if check_set_ftrace_filter "$ALL_FUNCS"; then
81+
fail "Expected only $ALL_FUNCS"
82+
fi
83+
84+
echo "$FUNC1:traceoff" > set_ftrace_filter
85+
if check_set_ftrace_filter "$ALL_FUNCS" "$FUNC1:traceoff:unlimited"; then
86+
fail "Expected $ALL_FUNCS and $FUNC1:traceoff:unlimited"
87+
fi
88+
89+
echo "$FUNC1" > set_ftrace_filter
90+
if check_set_ftrace_filter "$FUNC1" "$FUNC1:traceoff:unlimited"; then
91+
fail "Expected $FUNC1 and $FUNC1:traceoff:unlimited"
92+
fi
93+
94+
echo "$FUNC2" >> set_ftrace_filter
95+
if check_set_ftrace_filter "$FUNC1" "$FUNC2" "$FUNC1:traceoff:unlimited"; then
96+
fail "Expected $FUNC1 $FUNC2 and $FUNC1:traceoff:unlimited"
97+
fi
98+
99+
echo "$FUNC2:traceoff" >> set_ftrace_filter
100+
if check_set_ftrace_filter "$FUNC1" "$FUNC2" "$FUNC1:traceoff:unlimited" "$FUNC2:traceoff:unlimited"; then
101+
fail "Expected $FUNC1 $FUNC2 $FUNC1:traceoff:unlimited and $FUNC2:traceoff:unlimited"
102+
fi
103+
104+
echo "$FUNC1" > set_ftrace_filter
105+
if check_set_ftrace_filter "$FUNC1" "$FUNC1:traceoff:unlimited" "$FUNC2:traceoff:unlimited"; then
106+
fail "Expected $FUNC1 $FUNC1:traceoff:unlimited and $FUNC2:traceoff:unlimited"
107+
fi
108+
109+
echo > set_ftrace_filter
110+
if check_set_ftrace_filter "$ALL_FUNCS" "$FUNC1:traceoff:unlimited" "$FUNC2:traceoff:unlimited"; then
111+
fail "Expected $ALL_FUNCS $FUNC1:traceoff:unlimited and $FUNC2:traceoff:unlimited"
112+
fi
113+
114+
reset_ftrace_filter
115+
116+
if check_set_ftrace_filter "$ALL_FUNCS"; then
117+
fail "Expected $ALL_FUNCS"
118+
fi
119+
120+
echo "$FUNC1" > set_ftrace_filter
121+
if check_set_ftrace_filter "$FUNC1" ; then
122+
fail "Expected $FUNC1"
123+
fi
124+
125+
echo "$FUNC2" >> set_ftrace_filter
126+
if check_set_ftrace_filter "$FUNC1" "$FUNC2" ; then
127+
fail "Expected $FUNC1 and $FUNC2"
128+
fi
129+
130+
do_reset
131+
132+
exit 0

0 commit comments

Comments
 (0)