2 # SPDX-License-Identifier: GPL-2.0
3 # description: ftrace - test reading of set_ftrace_filter
5 # The set_ftrace_filter file of ftrace is used to list functions as well as
6 # triggers (probes) attached to functions. The code to read this file is not
7 # straight forward and has had various bugs in the past. This test is designed
8 # to add functions and triggers to that file in various ways and read that
9 # file in various ways (cat vs dd).
12 # The triggers are set within the set_ftrace_filter file
13 if [ ! -f set_ftrace_filter ]; then
14 echo "set_ftrace_filter not found? Is dynamic ftrace not set?"
34 FILTER=set_ftrace_filter
38 ALL_FUNCS="#### all functions enabled ####"
41 if ! echo "$1" | grep -q "^$2\$"; then
44 echo "$1" | grep -v "^$2\$"
48 check_set_ftrace_filter() {
50 dd1=`dd if=$FILTER bs=1 | grep -v -e 'records in' -e 'records out' -e 'bytes copied'`
51 dd100=`dd if=$FILTER bs=100 | grep -v -e 'records in' -e 'records out' -e 'bytes copied'`
55 while [ $# -gt 0 ]; do
57 if cat=`test_func "$cat" "$1"`; then
60 if dd1=`test_func "$dd1" "$1"`; then
63 if dd100=`test_func "$dd100" "$1"`; then
69 if [ -n "$cat" ]; then
72 if [ -n "$dd1" ]; then
75 if [ -n "$dd100" ]; then
81 if check_set_ftrace_filter "$ALL_FUNCS"; then
82 fail "Expected only $ALL_FUNCS"
85 echo "$FUNC1:traceoff" > set_ftrace_filter
86 if check_set_ftrace_filter "$ALL_FUNCS" "$FUNC1:traceoff:unlimited"; then
87 fail "Expected $ALL_FUNCS and $FUNC1:traceoff:unlimited"
90 echo "$FUNC1" > set_ftrace_filter
91 if check_set_ftrace_filter "$FUNC1" "$FUNC1:traceoff:unlimited"; then
92 fail "Expected $FUNC1 and $FUNC1:traceoff:unlimited"
95 echo "$FUNC2" >> set_ftrace_filter
96 if check_set_ftrace_filter "$FUNC1" "$FUNC2" "$FUNC1:traceoff:unlimited"; then
97 fail "Expected $FUNC1 $FUNC2 and $FUNC1:traceoff:unlimited"
100 echo "$FUNC2:traceoff" >> set_ftrace_filter
101 if check_set_ftrace_filter "$FUNC1" "$FUNC2" "$FUNC1:traceoff:unlimited" "$FUNC2:traceoff:unlimited"; then
102 fail "Expected $FUNC1 $FUNC2 $FUNC1:traceoff:unlimited and $FUNC2:traceoff:unlimited"
105 echo "$FUNC1" > set_ftrace_filter
106 if check_set_ftrace_filter "$FUNC1" "$FUNC1:traceoff:unlimited" "$FUNC2:traceoff:unlimited"; then
107 fail "Expected $FUNC1 $FUNC1:traceoff:unlimited and $FUNC2:traceoff:unlimited"
110 echo > set_ftrace_filter
111 if check_set_ftrace_filter "$ALL_FUNCS" "$FUNC1:traceoff:unlimited" "$FUNC2:traceoff:unlimited"; then
112 fail "Expected $ALL_FUNCS $FUNC1:traceoff:unlimited and $FUNC2:traceoff:unlimited"
117 if check_set_ftrace_filter "$ALL_FUNCS"; then
118 fail "Expected $ALL_FUNCS"
121 echo "$FUNC1" > set_ftrace_filter
122 if check_set_ftrace_filter "$FUNC1" ; then
123 fail "Expected $FUNC1"
126 echo "$FUNC2" >> set_ftrace_filter
127 if check_set_ftrace_filter "$FUNC1" "$FUNC2" ; then
128 fail "Expected $FUNC1 and $FUNC2"
131 test_actual() { # Compares $TMPDIR/expected with set_ftrace_filter
132 cat set_ftrace_filter | grep -v '#' | cut -d' ' -f1 | cut -d':' -f1 | sort -u > $TMPDIR/actual
133 DIFF=`diff $TMPDIR/actual $TMPDIR/expected`
137 # Set traceoff trigger for all fuctions with "lock" in their name
138 cat available_filter_functions | cut -d' ' -f1 | grep 'lock' | sort -u > $TMPDIR/expected
139 echo '*lock*:traceoff' > set_ftrace_filter
142 # now remove all with 'try' in it, and end with lock
143 grep -v 'try.*lock$' $TMPDIR/expected > $TMPDIR/expected2
144 mv $TMPDIR/expected2 $TMPDIR/expected
145 echo '!*try*lock:traceoff' >> set_ftrace_filter
148 # remove all that start with "m" and end with "lock"
149 grep -v '^m.*lock$' $TMPDIR/expected > $TMPDIR/expected2
150 mv $TMPDIR/expected2 $TMPDIR/expected
151 echo '!m*lock:traceoff' >> set_ftrace_filter
154 # remove all that start with "c" and have "unlock"
155 grep -v '^c.*unlock' $TMPDIR/expected > $TMPDIR/expected2
156 mv $TMPDIR/expected2 $TMPDIR/expected
157 echo '!c*unlock*:traceoff' >> set_ftrace_filter
162 echo '!*:traceoff' >> set_ftrace_filter