Commit | Line | Data |
---|---|---|
43bb45da | 1 | #!/bin/sh |
b2441318 | 2 | # SPDX-License-Identifier: GPL-2.0 |
43bb45da | 3 | # description: ftrace - test for function event triggers |
6df0fee3 | 4 | # flags: instance |
43bb45da 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 event 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 events:" | |
38 | ||
39 | EVENT="sched:sched_switch" | |
40 | EVENT_ENABLE="events/sched/sched_switch/enable" | |
41 | ||
42 | cnt_trace() { | |
43 | grep -v '^#' trace | wc -l | |
44 | } | |
45 | ||
46 | test_event_enabled() { | |
47 | val=$1 | |
48 | ||
49 | e=`cat $EVENT_ENABLE` | |
50 | if [ "$e" != $val ]; then | |
51 | echo "Expected $val but found $e" | |
d2ffb8d3 | 52 | exit 1 |
43bb45da SRV |
53 | fi |
54 | } | |
55 | ||
56 | run_enable_disable() { | |
57 | enable=$1 # enable | |
58 | Enable=$2 # Enable | |
59 | check_disable=$3 # 0 | |
60 | check_enable_star=$4 # 1* | |
61 | check_disable_star=$5 # 0* | |
62 | ||
63 | cnt=`cnt_trace` | |
64 | if [ $cnt -ne 0 ]; then | |
65 | fail "Found junk in trace file" | |
66 | fi | |
67 | ||
68 | echo "$Enable event all the time" | |
69 | ||
70 | echo $check_disable > $EVENT_ENABLE | |
71 | sleep $SLEEP_TIME | |
72 | ||
73 | test_event_enabled $check_disable | |
74 | ||
75 | echo "schedule:${enable}_event:$EVENT" > set_ftrace_filter | |
bc5f1598 MH |
76 | if [ -d ../../instances ]; then # Check instances |
77 | cur=`cat set_ftrace_filter` | |
78 | top=`cat ../../set_ftrace_filter` | |
79 | if [ "$cur" = "$top" ]; then | |
80 | echo "This kernel is too old to support per instance filter" | |
81 | reset_ftrace_filter | |
82 | exit_unsupported | |
83 | fi | |
84 | fi | |
43bb45da SRV |
85 | |
86 | echo " make sure it works 5 times" | |
87 | ||
88 | for i in `seq 5`; do | |
89 | sleep $SLEEP_TIME | |
90 | echo " test $i" | |
91 | test_event_enabled $check_enable_star | |
92 | ||
93 | echo $check_disable > $EVENT_ENABLE | |
94 | done | |
95 | sleep $SLEEP_TIME | |
96 | echo " make sure it's still works" | |
97 | test_event_enabled $check_enable_star | |
98 | ||
99 | reset_ftrace_filter | |
100 | ||
101 | echo " make sure it only works 3 times" | |
102 | ||
103 | echo $check_disable > $EVENT_ENABLE | |
104 | sleep $SLEEP_TIME | |
105 | ||
106 | echo "schedule:${enable}_event:$EVENT:3" > set_ftrace_filter | |
107 | ||
108 | for i in `seq 3`; do | |
109 | sleep $SLEEP_TIME | |
110 | echo " test $i" | |
111 | test_event_enabled $check_enable_star | |
112 | ||
113 | echo $check_disable > $EVENT_ENABLE | |
114 | done | |
115 | ||
116 | sleep $SLEEP_TIME | |
117 | echo " make sure it stop working" | |
118 | test_event_enabled $check_disable_star | |
119 | ||
120 | do_reset | |
121 | } | |
122 | ||
123 | run_enable_disable enable Enable 0 "1*" "0*" | |
124 | run_enable_disable disable Disable 1 "0*" "1*" |