x86/spinlock: Remove obsolete ticket spinlock macros and types
[linux-2.6-microblaze.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 fail() { # mesg
20     echo $1
21     exit_fail
22 }
23
24 SLEEP_TIME=".1"
25
26 echo "Testing function probes with enabling disabling tracing:"
27
28 cnt_trace() {
29     grep -v '^#' trace | wc -l
30 }
31
32 echo '** DISABLE TRACING'
33 disable_tracing
34 clear_trace
35
36 cnt=`cnt_trace`
37 if [ $cnt -ne 0 ]; then
38     fail "Found junk in trace"
39 fi
40
41
42 echo '** ENABLE EVENTS'
43
44 echo 1 > events/sched/enable
45
46 echo '** ENABLE TRACING'
47 enable_tracing
48
49 cnt=`cnt_trace`
50 if [ $cnt -eq 0 ]; then
51    fail "Nothing found in trace"
52 fi
53
54 # powerpc uses .schedule
55 func="schedule"
56 available_file=available_filter_functions
57 if [ -d ../../instances -a -f ../../available_filter_functions ]; then
58    available_file=../../available_filter_functions
59 fi
60 x=`grep '^\.schedule$' available_filter_functions | wc -l`
61 if [ "$x" -eq 1 ]; then
62    func=".schedule"
63 fi
64
65 echo '** SET TRACEOFF'
66
67 echo "$func:traceoff" > set_ftrace_filter
68 if [ -d ../../instances ]; then # Check instances
69     cur=`cat set_ftrace_filter`
70     top=`cat ../../set_ftrace_filter`
71     if [ "$cur" = "$top" ]; then
72         echo "This kernel is too old to support per instance filter"
73         reset_ftrace_filter
74         exit_unsupported
75     fi
76 fi
77
78 cnt=`grep schedule set_ftrace_filter | wc -l`
79 if [ $cnt -ne 1 ]; then
80    fail "Did not find traceoff trigger"
81 fi
82
83 cnt=`cnt_trace`
84 sleep $SLEEP_TIME
85 cnt2=`cnt_trace`
86
87 if [ $cnt -ne $cnt2 ]; then
88    fail "Tracing is not stopped"
89 fi
90
91 on=`cat tracing_on`
92 if [ $on != "0" ]; then
93     fail "Tracing is not off"
94 fi
95
96 csum1=`md5sum trace`
97 sleep $SLEEP_TIME
98 csum2=`md5sum trace`
99
100 if [ "$csum1" != "$csum2" ]; then
101     fail "Tracing file is still changing"
102 fi
103
104 clear_trace
105
106 cnt=`cnt_trace`
107 if [ $cnt -ne 0 ]; then
108     fail "Tracing is still happeing"
109 fi
110
111 echo "!$func:traceoff" >> set_ftrace_filter
112
113 cnt=`grep schedule set_ftrace_filter | wc -l`
114 if [ $cnt -ne 0 ]; then
115     fail "traceoff trigger still exists"
116 fi
117
118 on=`cat tracing_on`
119 if [ $on != "0" ]; then
120     fail "Tracing is started again"
121 fi
122
123 echo "$func:traceon" > set_ftrace_filter
124
125 cnt=`grep schedule set_ftrace_filter | wc -l`
126 if [ $cnt -ne 1 ]; then
127     fail "traceon trigger not found"
128 fi
129
130 cnt=`cnt_trace`
131 if [ $cnt -eq 0 ]; then
132    fail "Tracing did not start"
133 fi
134
135 on=`cat tracing_on`
136 if [ $on != "1" ]; then
137     fail "Tracing was not enabled"
138 fi
139
140
141 echo "!$func:traceon" >> set_ftrace_filter
142
143 cnt=`grep schedule set_ftrace_filter | wc -l`
144 if [ $cnt -ne 0 ]; then
145    fail "traceon trigger still exists"
146 fi
147
148 check_sleep() {
149     val=$1
150     sleep $SLEEP_TIME
151     cat set_ftrace_filter
152     on=`cat tracing_on`
153     if [ $on != "$val" ]; then
154         fail "Expected tracing_on to be $val, but it was $on"
155     fi
156 }
157
158
159 echo "$func:traceoff:3" > set_ftrace_filter
160 check_sleep "0"
161 echo 1 > tracing_on
162 check_sleep "0"
163 echo 1 > tracing_on
164 check_sleep "0"
165 echo 1 > tracing_on
166 check_sleep "1"
167 echo "!$func:traceoff:0" > set_ftrace_filter
168
169 if grep -e traceon -e traceoff set_ftrace_filter; then
170     fail "Tracing on and off triggers still exist"
171 fi
172
173 disable_events
174
175 exit 0