]> git.proxmox.com Git - mirror_ubuntu-bionic-kernel.git/blame - tools/testing/selftests/ftrace/test.d/ftrace/func_traceonoff_triggers.tc
License cleanup: add SPDX GPL-2.0 license identifier to files with no license
[mirror_ubuntu-bionic-kernel.git] / tools / testing / selftests / ftrace / test.d / ftrace / func_traceonoff_triggers.tc
CommitLineData
d8b39e1d 1#!/bin/sh
b2441318 2# SPDX-License-Identifier: GPL-2.0
d8b39e1d 3# description: ftrace - test for function traceon/off triggers
6df0fee3 4# flags: instance
d8b39e1d
SRV
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
14if [ ! -f set_ftrace_filter ]; then
15 echo "set_ftrace_filter not found? Is dynamic ftrace not set?"
16 exit_unsupported
17fi
18
19do_reset() {
20 reset_ftrace_filter
21 reset_tracer
22 disable_events
23 clear_trace
24 enable_tracing
25}
26
27fail() { # mesg
28 do_reset
29 echo $1
30 exit $FAIL
31}
32
33SLEEP_TIME=".1"
34
35do_reset
36
37echo "Testing function probes with enabling disabling tracing:"
38
39cnt_trace() {
40 grep -v '^#' trace | wc -l
41}
42
43echo '** DISABLE TRACING'
44disable_tracing
45clear_trace
46
47cnt=`cnt_trace`
48if [ $cnt -ne 0 ]; then
49 fail "Found junk in trace"
50fi
51
52
53echo '** ENABLE EVENTS'
54
55echo 1 > events/enable
56
57echo '** ENABLE TRACING'
58enable_tracing
59
60cnt=`cnt_trace`
61if [ $cnt -eq 0 ]; then
62 fail "Nothing found in trace"
63fi
64
65# powerpc uses .schedule
66func="schedule"
565d5576
MH
67available_file=available_filter_functions
68if [ -d ../../instances -a -f ../../available_filter_functions ]; then
69 available_file=../../available_filter_functions
70fi
d8b39e1d
SRV
71x=`grep '^\.schedule$' available_filter_functions | wc -l`
72if [ "$x" -eq 1 ]; then
73 func=".schedule"
74fi
75
76echo '** SET TRACEOFF'
77
78echo "$func:traceoff" > set_ftrace_filter
bc5f1598
MH
79if [ -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
87fi
d8b39e1d
SRV
88
89cnt=`grep schedule set_ftrace_filter | wc -l`
90if [ $cnt -ne 1 ]; then
91 fail "Did not find traceoff trigger"
92fi
93
94cnt=`cnt_trace`
95sleep $SLEEP_TIME
96cnt2=`cnt_trace`
97
98if [ $cnt -ne $cnt2 ]; then
99 fail "Tracing is not stopped"
100fi
101
102on=`cat tracing_on`
103if [ $on != "0" ]; then
104 fail "Tracing is not off"
105fi
106
d87b2917 107csum1=`md5sum trace`
d8b39e1d 108sleep $SLEEP_TIME
d87b2917 109csum2=`md5sum trace`
d8b39e1d 110
d87b2917 111if [ "$csum1" != "$csum2" ]; then
d8b39e1d
SRV
112 fail "Tracing file is still changing"
113fi
114
115clear_trace
116
117cnt=`cnt_trace`
118if [ $cnt -ne 0 ]; then
119 fail "Tracing is still happeing"
120fi
121
122echo "!$func:traceoff" >> set_ftrace_filter
123
124cnt=`grep schedule set_ftrace_filter | wc -l`
125if [ $cnt -ne 0 ]; then
126 fail "traceoff trigger still exists"
127fi
128
129on=`cat tracing_on`
130if [ $on != "0" ]; then
131 fail "Tracing is started again"
132fi
133
134echo "$func:traceon" > set_ftrace_filter
135
136cnt=`grep schedule set_ftrace_filter | wc -l`
137if [ $cnt -ne 1 ]; then
138 fail "traceon trigger not found"
139fi
140
141cnt=`cnt_trace`
142if [ $cnt -eq 0 ]; then
143 fail "Tracing did not start"
144fi
145
146on=`cat tracing_on`
147if [ $on != "1" ]; then
148 fail "Tracing was not enabled"
149fi
150
151
152echo "!$func:traceon" >> set_ftrace_filter
153
154cnt=`grep schedule set_ftrace_filter | wc -l`
155if [ $cnt -ne 0 ]; then
156 fail "traceon trigger still exists"
157fi
158
159check_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
170echo "$func:traceoff:3" > set_ftrace_filter
171check_sleep "0"
172echo 1 > tracing_on
173check_sleep "0"
174echo 1 > tracing_on
175check_sleep "0"
176echo 1 > tracing_on
177check_sleep "1"
178echo "!$func:traceoff:0" > set_ftrace_filter
179
180if grep -e traceon -e traceoff set_ftrace_filter; then
181 fail "Tracing on and off triggers still exist"
182fi
183
184disable_events
185
186exit 0