GNU Linux-libre 4.19.264-gnu1
[releases.git] / tools / testing / selftests / ftrace / test.d / ftrace / func_traceonoff_triggers.tc
1 #!/bin/sh
2 # SPDX-License-Identifier: GPL-2.0
3 # description: ftrace - test for function traceon/off triggers
4 # flags: instance
5 #
6 # Ftrace allows to add triggers to functions, such as enabling or disabling
7 # tracing, enabling or disabling trace events, or recording a stack trace
8 # within the ring buffer.
9 #
10 # This test is designed to test enabling and disabling tracing triggers
11 #
12
13 # The triggers are set within the set_ftrace_filter file
14 if [ ! -f set_ftrace_filter ]; then
15     echo "set_ftrace_filter not found? Is dynamic ftrace not set?"
16     exit_unsupported
17 fi
18
19 do_reset() {
20     reset_ftrace_filter
21     reset_tracer
22     disable_events
23     clear_trace
24     enable_tracing
25 }
26
27 fail() { # mesg
28     do_reset
29     echo $1
30     exit_fail
31 }
32
33 SLEEP_TIME=".1"
34
35 do_reset
36
37 echo "Testing function probes with enabling disabling tracing:"
38
39 cnt_trace() {
40     grep -v '^#' trace | wc -l
41 }
42
43 echo '** DISABLE TRACING'
44 disable_tracing
45 clear_trace
46
47 cnt=`cnt_trace`
48 if [ $cnt -ne 0 ]; then
49     fail "Found junk in trace"
50 fi
51
52
53 echo '** ENABLE EVENTS'
54
55 echo 1 > events/enable
56
57 echo '** ENABLE TRACING'
58 enable_tracing
59
60 cnt=`cnt_trace`
61 if [ $cnt -eq 0 ]; then
62    fail "Nothing found in trace"
63 fi
64
65 # powerpc uses .schedule
66 func="schedule"
67 available_file=available_filter_functions
68 if [ -d ../../instances -a -f ../../available_filter_functions ]; then
69    available_file=../../available_filter_functions
70 fi
71 x=`grep '^\.schedule$' available_filter_functions | wc -l`
72 if [ "$x" -eq 1 ]; then
73    func=".schedule"
74 fi
75
76 echo '** SET TRACEOFF'
77
78 echo "$func:traceoff" > set_ftrace_filter
79 if [ -d ../../instances ]; then # Check instances
80     cur=`cat set_ftrace_filter`
81     top=`cat ../../set_ftrace_filter`
82     if [ "$cur" = "$top" ]; then
83         echo "This kernel is too old to support per instance filter"
84         reset_ftrace_filter
85         exit_unsupported
86     fi
87 fi
88
89 cnt=`grep schedule set_ftrace_filter | wc -l`
90 if [ $cnt -ne 1 ]; then
91    fail "Did not find traceoff trigger"
92 fi
93
94 cnt=`cnt_trace`
95 sleep $SLEEP_TIME
96 cnt2=`cnt_trace`
97
98 if [ $cnt -ne $cnt2 ]; then
99    fail "Tracing is not stopped"
100 fi
101
102 on=`cat tracing_on`
103 if [ $on != "0" ]; then
104     fail "Tracing is not off"
105 fi
106
107 csum1=`md5sum trace`
108 sleep $SLEEP_TIME
109 csum2=`md5sum trace`
110
111 if [ "$csum1" != "$csum2" ]; then
112     fail "Tracing file is still changing"
113 fi
114
115 clear_trace
116
117 cnt=`cnt_trace`
118 if [ $cnt -ne 0 ]; then
119     fail "Tracing is still happeing"
120 fi
121
122 echo "!$func:traceoff" >> set_ftrace_filter
123
124 cnt=`grep schedule set_ftrace_filter | wc -l`
125 if [ $cnt -ne 0 ]; then
126     fail "traceoff trigger still exists"
127 fi
128
129 on=`cat tracing_on`
130 if [ $on != "0" ]; then
131     fail "Tracing is started again"
132 fi
133
134 echo "$func:traceon" > set_ftrace_filter
135
136 cnt=`grep schedule set_ftrace_filter | wc -l`
137 if [ $cnt -ne 1 ]; then
138     fail "traceon trigger not found"
139 fi
140
141 cnt=`cnt_trace`
142 if [ $cnt -eq 0 ]; then
143    fail "Tracing did not start"
144 fi
145
146 on=`cat tracing_on`
147 if [ $on != "1" ]; then
148     fail "Tracing was not enabled"
149 fi
150
151
152 echo "!$func:traceon" >> set_ftrace_filter
153
154 cnt=`grep schedule set_ftrace_filter | wc -l`
155 if [ $cnt -ne 0 ]; then
156    fail "traceon trigger still exists"
157 fi
158
159 check_sleep() {
160     val=$1
161     sleep $SLEEP_TIME
162     cat set_ftrace_filter
163     on=`cat tracing_on`
164     if [ $on != "$val" ]; then
165         fail "Expected tracing_on to be $val, but it was $on"
166     fi
167 }
168
169
170 echo "$func:traceoff:3" > set_ftrace_filter
171 check_sleep "0"
172 echo 1 > tracing_on
173 check_sleep "0"
174 echo 1 > tracing_on
175 check_sleep "0"
176 echo 1 > tracing_on
177 check_sleep "1"
178 echo "!$func:traceoff:0" > set_ftrace_filter
179
180 if grep -e traceon -e traceoff set_ftrace_filter; then
181     fail "Tracing on and off triggers still exist"
182 fi
183
184 disable_events
185
186 exit 0