Commit | Line | Data |
---|---|---|
a9064f67 | 1 | #!/bin/sh |
b2441318 | 2 | # SPDX-License-Identifier: GPL-2.0 |
a9064f67 SRV |
3 | # description: ftrace - test reading of set_ftrace_filter |
4 | # | |
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). | |
10 | # | |
11 | ||
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?" | |
15 | exit_unsupported | |
16 | fi | |
17 | ||
18 | do_reset() { | |
19 | reset_tracer | |
20 | reset_ftrace_filter | |
21 | disable_events | |
22 | clear_trace | |
23 | enable_tracing | |
24 | } | |
25 | ||
26 | fail() { # mesg | |
27 | do_reset | |
28 | echo $1 | |
29 | exit $FAIL | |
30 | } | |
31 | ||
32 | do_reset | |
33 | ||
34 | FILTER=set_ftrace_filter | |
35 | FUNC1="schedule" | |
36 | FUNC2="do_IRQ" | |
37 | ||
38 | ALL_FUNCS="#### all functions enabled ####" | |
39 | ||
40 | test_func() { | |
41 | if ! echo "$1" | grep -q "^$2\$"; then | |
42 | return 0 | |
43 | fi | |
44 | echo "$1" | grep -v "^$2\$" | |
45 | return 1 | |
46 | } | |
47 | ||
48 | check_set_ftrace_filter() { | |
49 | cat=`cat $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'` | |
52 | ||
53 | echo "Testing '$@'" | |
54 | ||
55 | while [ $# -gt 0 ]; do | |
56 | echo "test $1" | |
57 | if cat=`test_func "$cat" "$1"`; then | |
58 | return 0 | |
59 | fi | |
60 | if dd1=`test_func "$dd1" "$1"`; then | |
61 | return 0 | |
62 | fi | |
63 | if dd100=`test_func "$dd100" "$1"`; then | |
64 | return 0 | |
65 | fi | |
66 | shift | |
67 | done | |
68 | ||
69 | if [ -n "$cat" ]; then | |
70 | return 0 | |
71 | fi | |
72 | if [ -n "$dd1" ]; then | |
73 | return 0 | |
74 | fi | |
75 | if [ -n "$dd100" ]; then | |
76 | return 0 | |
77 | fi | |
78 | return 1; | |
79 | } | |
80 | ||
81 | if check_set_ftrace_filter "$ALL_FUNCS"; then | |
82 | fail "Expected only $ALL_FUNCS" | |
83 | fi | |
84 | ||
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" | |
88 | fi | |
89 | ||
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" | |
93 | fi | |
94 | ||
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" | |
98 | fi | |
99 | ||
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" | |
103 | fi | |
104 | ||
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" | |
108 | fi | |
109 | ||
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" | |
113 | fi | |
114 | ||
115 | reset_ftrace_filter | |
116 | ||
117 | if check_set_ftrace_filter "$ALL_FUNCS"; then | |
118 | fail "Expected $ALL_FUNCS" | |
119 | fi | |
120 | ||
121 | echo "$FUNC1" > set_ftrace_filter | |
122 | if check_set_ftrace_filter "$FUNC1" ; then | |
123 | fail "Expected $FUNC1" | |
124 | fi | |
125 | ||
126 | echo "$FUNC2" >> set_ftrace_filter | |
127 | if check_set_ftrace_filter "$FUNC1" "$FUNC2" ; then | |
128 | fail "Expected $FUNC1 and $FUNC2" | |
129 | fi | |
130 | ||
131 | do_reset | |
132 | ||
133 | exit 0 |