summaryrefslogtreecommitdiff
path: root/tools/testing/selftests/ftrace/test.d/ftrace/func_traceonoff_triggers.tc
blob: cdc92a371cd73f78d22c964c2afac13201108597 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
#!/bin/sh
# SPDX-License-Identifier: GPL-2.0
# description: ftrace - test for function traceon/off triggers
# flags: instance
#
# Ftrace allows to add triggers to functions, such as enabling or disabling
# tracing, enabling or disabling trace events, or recording a stack trace
# within the ring buffer.
#
# This test is designed to test enabling and disabling tracing triggers
#

# The triggers are set within the set_ftrace_filter file
if [ ! -f set_ftrace_filter ]; then
    echo "set_ftrace_filter not found? Is dynamic ftrace not set?"
    exit_unsupported
fi

do_reset() {
    reset_ftrace_filter
    reset_tracer
    disable_events
    clear_trace
    enable_tracing
}

fail() { # mesg
    do_reset
    echo $1
    exit $FAIL
}

SLEEP_TIME=".1"

do_reset

echo "Testing function probes with enabling disabling tracing:"

cnt_trace() {
    grep -v '^#' trace | wc -l
}

echo '** DISABLE TRACING'
disable_tracing
clear_trace

cnt=`cnt_trace`
if [ $cnt -ne 0 ]; then
    fail "Found junk in trace"
fi


echo '** ENABLE EVENTS'

echo 1 > events/enable

echo '** ENABLE TRACING'
enable_tracing

cnt=`cnt_trace`
if [ $cnt -eq 0 ]; then
   fail "Nothing found in trace"
fi

# powerpc uses .schedule
func="schedule"
available_file=available_filter_functions
if [ -d ../../instances -a -f ../../available_filter_functions ]; then
   available_file=../../available_filter_functions
fi
x=`grep '^\.schedule$' available_filter_functions | wc -l`
if [ "$x" -eq 1 ]; then
   func=".schedule"
fi

echo '** SET TRACEOFF'

echo "$func:traceoff" > set_ftrace_filter
if [ -d ../../instances ]; then # Check instances
    cur=`cat set_ftrace_filter`
    top=`cat ../../set_ftrace_filter`
    if [ "$cur" = "$top" ]; then
	echo "This kernel is too old to support per instance filter"
	reset_ftrace_filter
	exit_unsupported
    fi
fi

cnt=`grep schedule set_ftrace_filter | wc -l`
if [ $cnt -ne 1 ]; then
   fail "Did not find traceoff trigger"
fi

cnt=`cnt_trace`
sleep $SLEEP_TIME
cnt2=`cnt_trace`

if [ $cnt -ne $cnt2 ]; then
   fail "Tracing is not stopped"
fi

on=`cat tracing_on`
if [ $on != "0" ]; then
    fail "Tracing is not off"
fi

csum1=`md5sum trace`
sleep $SLEEP_TIME
csum2=`md5sum trace`

if [ "$csum1" != "$csum2" ]; then
    fail "Tracing file is still changing"
fi

clear_trace

cnt=`cnt_trace`
if [ $cnt -ne 0 ]; then
    fail "Tracing is still happeing"
fi

echo "!$func:traceoff" >> set_ftrace_filter

cnt=`grep schedule set_ftrace_filter | wc -l`
if [ $cnt -ne 0 ]; then
    fail "traceoff trigger still exists"
fi

on=`cat tracing_on`
if [ $on != "0" ]; then
    fail "Tracing is started again"
fi

echo "$func:traceon" > set_ftrace_filter

cnt=`grep schedule set_ftrace_filter | wc -l`
if [ $cnt -ne 1 ]; then
    fail "traceon trigger not found"
fi

cnt=`cnt_trace`
if [ $cnt -eq 0 ]; then
   fail "Tracing did not start"
fi

on=`cat tracing_on`
if [ $on != "1" ]; then
    fail "Tracing was not enabled"
fi


echo "!$func:traceon" >> set_ftrace_filter

cnt=`grep schedule set_ftrace_filter | wc -l`
if [ $cnt -ne 0 ]; then
   fail "traceon trigger still exists"
fi

check_sleep() {
    val=$1
    sleep $SLEEP_TIME
    cat set_ftrace_filter
    on=`cat tracing_on`
    if [ $on != "$val" ]; then
	fail "Expected tracing_on to be $val, but it was $on"
    fi
}


echo "$func:traceoff:3" > set_ftrace_filter
check_sleep "0"
echo 1 > tracing_on
check_sleep "0"
echo 1 > tracing_on
check_sleep "0"
echo 1 > tracing_on
check_sleep "1"
echo "!$func:traceoff:0" > set_ftrace_filter

if grep -e traceon -e traceoff set_ftrace_filter; then
    fail "Tracing on and off triggers still exist"
fi

disable_events

exit 0