Debian Codegraph @

testsuite/systemtap.onthefly/tracepoint_onthefly.exp

raw
1 source $srcdir/$subdir/onthefly_common.tcl
2
3 set test "tracepoint_onthefly"
4 if {![installtest_p]} {
5 untested "$test"
6 return
7 }
8
9 # Goal: Ensure that tracepoints properly support on-the-fly arming/disarming.
10 # The script consists of a sched_process_fork tracepoint whose condition is
11 # toggled by a timer probe. We ensure that the tracepoint will always be
12 # triggered by running 'echo' in a loop in the background. We then analyze the
13 # actual debug statements printed out to ensure the toggled probe is armed and
14 # disarmed as expected.
15
16 # Runs stap on a script with the given arguments
17 proc run_stap {subtest args script} {
18 global test
19
20 # Start the background echos
21 set echo_loop "while \[ true \]; do /bin/echo 1>/dev/null; done"
22 set echo_pid [exec sh -c $echo_loop &]
23
24 # We always need the DEBUG and -g flags
25 set args "$args -D DEBUG_STP_ON_THE_FLY -g"
26
27 # Run stap and catch any errors (we will rethrow it later)
28 set err [catch {eval exec stap -e {$script} $args} out]
29
30 # Kill echo
31 kill -INT $echo_pid 1
32
33 if {$err} {error $out}
34 return $out
35 }
36
37 # Returns a script with some variables replaced.
38 # SUBTEST name of subtest
39 # ENABLED set to 1 to start the target probe as enabled, 0 as disabled
40 # MAXTOGGLES number of times we toggle the target probe condition
41 # TIMER if a number, then it's the period of the timer probe which
42 # toggles the target probes, if set to 'profile' then instead a
43 # timer.profile probe is used to toggle the target probe, if set
44 # to 'hardcore' then both a timer.profile probe and a
45 # kernel.trace("*") probe is used for toggling, if set to 'max'
46 # then a lot of various probe points are used for toggling
47 proc make_script {SUBTEST ENABLED MAXTOGGLES TIMER} {
48 global test
49
50 set script {
51
52 global enabled = ENABLED
53 global toggles = 0
54
55 # Simplification to ensure 'hit' is only printed once. This makes it
56 # easier later on to verify the output.
57 global hit = 0
58
59 probe kernel.trace("sched_process_fork") if (enabled) {
60 if (hit)
61 next
62 hit = 1
63 println("hit")
64 }
65
66 probe timer.us(TIMER) {
67 toggles++
68 hit = 0
69 if (toggles > MAXTOGGLES)
70 exit()
71 else {
72 println("toggling")
73 enabled = !enabled
74 }
75 }
76
77 probe timer.s(360) {
78 println("timed out")
79 exit()
80 }
81 }
82
83 # Set in values
84 #
85 # On ppc64, you can't probe the hcall_* tracepoints (PR17126:
86 # tracepoints.exp testcase causing stalls/hang on ppc64). This was
87 # worked around by making a tracepoint blocklist. However, this
88 # test is using the '-g' (guru) argument to systemtap, which causes
89 # systemtap to ignore the tracepoint blocklist. So, on ppc64, we'll
90 # probe all the kernel tracepoints *except* for the ones starting
91 # with 'h'.
92 set script [string map "TEST $test \
93 SUBTEST $SUBTEST \
94 ENABLED $ENABLED \
95 MAXTOGGLES $MAXTOGGLES" $script]
96 if {[string match $TIMER "profile"]} {
97 set script [string map "timer.us(TIMER) timer.profile" $script]
98 } elseif {[string match $TIMER "hardcore"]} {
99 if {[string match ppc* $::tcl_platform(machine)]} {
100 set script [string map "timer.us(TIMER) \
101 {timer.profile, kernel.trace(\"\[a-gi-z\]*\")}" $script]
102 } else {
103 set script [string map "timer.us(TIMER) \
104 {timer.profile, kernel.trace(\"*\")}" $script]
105 }
106 } elseif {[string match $TIMER "max"]} {
107 if {[string match ppc* $::tcl_platform(machine)]} {
108 set script [string map "timer.us(TIMER) \
109 {begin, end, error, kernel.function(\"*@workqueue.c\"), \
110 process.begin, process.end, kernel.trace(\"\[a-gi-z\]*\"), \
111 process(\"echo\").function(\"*\"), \
112 netfilter.pf(\"NFPROTO_IPV4\").hook(\"NF_INET_LOCAL_IN\")?, \
113 netfilter.pf(\"NFPROTO_IPV4\").hook(\"NF_INET_LOCAL_OUT\")?, \
114 perf.sw.cpu_clock.sample(1000000)?, timer.profile.tick?}" $script]
115 } else {
116 set script [string map "timer.us(TIMER) \
117 {begin, end, error, kernel.function(\"*@workqueue.c\"), \
118 process.begin, process.end, kernel.trace(\"*\"), \
119 process(\"echo\").function(\"*\"), \
120 netfilter.pf(\"NFPROTO_IPV4\").hook(\"NF_INET_LOCAL_IN\")?, \
121 netfilter.pf(\"NFPROTO_IPV4\").hook(\"NF_INET_LOCAL_OUT\")?, \
122 perf.sw.cpu_clock.sample(1000000)?, timer.profile.tick?}" $script]
123 }
124 } else {
125 set script [string map "TIMER $TIMER" $script]
126 }
127
128 return $script
129 }
130
131 # Creates the pattern which will be used by the is_valid_output proc to
132 # determine if the output is valid. In other words, given the initial value of
133 # enabled, the maximum number of toggles, and whether on-the-fly is turned on or
134 # not, this proc determines what the output of stap will be.
135 proc make_pattern {subtest start_enabled maxtoggles} {
136 set pattern ""
137
138 # If we're not starting as enabled, then the kprobes will be registered as
139 # disabled.
140 if {!$start_enabled} {
141 lappend pattern "* not registering (tracepoint) pidx ?"
142 }
143
144 # For each toggle:
145 # - if we were enabled, then we would have had a 'hit' line
146 # - if i == maxtoggles, then we'll exit so nothing more will be printed
147 # - if i < maxtoggles, then the timer probe will output 'toggling' followed
148 # by 'registering' or 'unregistering' lines
149 for {set i 0} {$i <= $maxtoggles} {incr i} {
150 if {$start_enabled} {
151 lappend pattern "hit"
152 }
153 if {$i < $maxtoggles} {
154 lappend pattern "toggling"
155 if {$start_enabled} {
156 set start_enabled 0
157 lappend pattern "* unregistering (tracepoint) pidx ?"
158 } else {
159 set start_enabled 1
160 if {$i < $maxtoggles} {
161 lappend pattern "* registering (tracepoint) pidx ?"
162 }
163 }
164 }
165 }
166
167 return $pattern
168 }
169
170 # Various on-the-fly tests
171
172 # Toggle 0, 1, 2, 3, 4, and 5 times. This is important since we test if the
173 # probes finish well when disabled/enabled.
174
175 setup_kfail 17256 *-*-*
176 run_subtest_valid "otf_finish_at_start_disabled" 0 0 500000
177 run_subtest_valid "otf_finish_at_start_enabled" 1 0 500000
178 setup_kfail 17256 *-*-*
179 run_subtest_valid "otf_start_disabled_iter_1" 0 1 500000
180 setup_kfail 17256 *-*-*
181 run_subtest_valid "otf_start_enabled_iter_1" 1 1 500000
182 setup_kfail 17256 *-*-*
183 run_subtest_valid "otf_start_disabled_iter_2" 0 2 500000
184 setup_kfail 17256 *-*-*
185 run_subtest_valid "otf_start_enabled_iter_2" 1 2 500000
186 setup_kfail 17256 *-*-*
187 run_subtest_valid "otf_start_disabled_iter_3" 0 3 500000
188 setup_kfail 17256 *-*-*
189 run_subtest_valid "otf_start_enabled_iter_3" 1 3 500000
190 setup_kfail 17256 *-*-*
191 run_subtest_valid "otf_start_disabled_iter_4" 0 4 500000
192 setup_kfail 17256 *-*-*
193 run_subtest_valid "otf_start_enabled_iter_4" 1 4 500000
194 setup_kfail 17256 *-*-*
195 run_subtest_valid "otf_start_disabled_iter_5" 0 5 500000
196 setup_kfail 17256 *-*-*
197 run_subtest_valid "otf_start_enabled_iter_5" 1 5 500000
198
199 # Small interval tests
200
201 setup_kfail 17256 *-*-*
202 run_subtest_valid "otf_timer_100ms" 1 5 100000 \
203 -D STP_ON_THE_FLY_INTERVAL=1000000
204 setup_kfail 17256 *-*-*
205 run_subtest_valid "otf_timer_50ms" 1 5 50000 \
206 -D STP_ON_THE_FLY_INTERVAL=1000000
207 setup_kfail 17256 *-*-*
208 run_subtest_valid "otf_timer_10ms" 1 5 10000 \
209 -D STP_ON_THE_FLY_INTERVAL=1000000
210
211 # NB: if we go any shorter, the kernel might not have a chance to run
212 # systemtap_module_refresh() before the next toggling occurs, throwing off the
213 # expected output.
214
215 # Stress tests
216
217 # These tests are not validated, i.e. their outputs are not checked against a
218 # pattern (see NB above why). Instead, they're just meant to stress the
219 # on-the-fly mechanism to ensure stap/the kernel doesn't die. So if stap is
220 # successfully run and terminated, we just default to a pass.
221
222 run_subtest_stress "otf_stress_5ms_iter_50" 1 50 5000 \
223 -D STP_ON_THE_FLY_INTERVAL=100000
224 run_subtest_stress "otf_stress_1ms_iter_50" 1 50 1000 \
225 -D STP_ON_THE_FLY_INTERVAL=100000
226 run_subtest_stress "otf_stress_500us_iter_50" 1 50 500 \
227 -D STP_ON_THE_FLY_INTERVAL=100000
228 run_subtest_stress "otf_stress_100us_iter_50" 1 50 100 \
229 -D STP_ON_THE_FLY_INTERVAL=100000
230
231 run_subtest_stress "otf_stress_prof_iter_2000" 1 2000 profile \
232 -D STP_ON_THE_FLY_INTERVAL=100000
233
234 run_subtest_stress "otf_stress_hard_iter_2000" 1 2000 hardcore \
235 -D STP_ON_THE_FLY_INTERVAL=100000
236
237 # Don't test this until PR17461 is solved.
238 #run_subtest_stress "otf_stress_max_iter_5000" 1 5000 max \
239 # -D STP_ON_THE_FLY_INTERVAL=100000