Debian Codegraph @

doc/SystemTap_Beginners_Guide/testsuite/systemtap.base/utrace_p5.exp

raw
1 # Utrace run (pass 5) tests.
2
3 # Initialize variables
4 set exepath "[pwd]/cat_[pid]"
5 set multi_srcpath "$srcdir/systemtap.base/utrace_p5_multi.c"
6 set multi_exepath "[pwd]/utrace_p5_multi_[pid]"
7 set multi_flags "libs=-lpthread"
8
9 set end_script {
10 global end_probes_fired = 0
11 probe begin { printf("systemtap starting probe\n") }
12 probe process("%s").end { end_probes_fired++ }
13 probe end { printf("systemtap ending probe\n")
14 printf("end probes = %%d\n", end_probes_fired) }
15 }
16 set end_script_output "end probes = 1\r\n"
17
18 set begin_script {
19 global begin_probes_fired = 0
20 probe begin { printf("systemtap starting probe\n") }
21 probe process("%s").begin { begin_probes_fired++ }
22 probe end { printf("systemtap ending probe\n")
23 printf("begin probes = %%d\n", begin_probes_fired) }
24 }
25 set begin_script_output "begin probes = 1\r\n"
26
27 set syscall_script {
28 global syscall_probes_fired = 0
29 probe begin { printf("systemtap starting probe\n") }
30 probe process("%s").syscall { syscall_probes_fired++ }
31 probe end { printf("systemtap ending probe\n")
32 if (syscall_probes_fired > 0) {
33 printf("syscalls = %%d\n", syscall_probes_fired)
34 }
35 }
36 }
37 set syscall_script_output "syscalls = \\d+\r\n"
38
39 set syscall_return_script {
40 global syscall_return_probes_fired = 0
41 probe begin { printf("systemtap starting probe\n") }
42 probe process("%s").syscall.return { syscall_return_probes_fired++ }
43 probe end { printf("systemtap ending probe\n")
44 if (syscall_return_probes_fired > 0) {
45 printf("syscall_returns = %%d\n", syscall_return_probes_fired)
46 }
47 }
48 }
49 set syscall_return_script_output "syscall_returns = \\d+\r\n"
50
51 set thread_begin_script {
52 global thread_begin_probes_fired = 0
53 probe begin { printf("systemtap starting probe\n") }
54 probe process("%s").thread.begin { thread_begin_probes_fired++ }
55 probe end { printf("systemtap ending probe\n")
56 if (thread_begin_probes_fired > 0) {
57 printf("thread_begins = %%d\n", thread_begin_probes_fired)
58 }
59 }
60 }
61 set thread_begin_script_output "thread_begins = \\d+\r\n"
62
63 set thread_end_script {
64 global thread_end_probes_fired = 0
65 probe begin { printf("systemtap starting probe\n") }
66 probe process("%s").thread.end { thread_end_probes_fired++ }
67 probe end { printf("systemtap ending probe\n")
68 if (thread_end_probes_fired > 0) {
69 printf("thread_ends = %%d\n", thread_end_probes_fired)
70 }
71 }
72 }
73 set thread_end_script_output "thread_ends = \\d+\r\n"
74
75 # Script that tests the bug 6841 fix.
76 set bz6841_script {
77 global proc,name
78 probe begin { printf("systemtap starting probe\n") }
79 probe process.syscall {
80 proc[pid()] <<< 1
81 name[pid()] = execname()
82 }
83 probe end { printf("systemtap ending probe\n")
84 foreach(p+ in proc) {
85 printf("%s(%d) issues syscall %d times\n",
86 name[p], p, @sum(proc[p]))
87 }
88 }
89 }
90 set bz6841_script_output ".+ issues syscall \\d+ times\r\n"
91
92 set syscall_parms_script {
93 global syscall_parms_string
94 probe begin { printf("systemtap starting probe\n") }
95 probe process.syscall { syscall_parms_string = $$parms exit() }
96 probe end { printf("systemtap ending probe\n")
97 printf("%s\n",syscall_parms_string)
98 delete syscall_parms_string
99 }
100 }
101 set syscall_parms_script_output "(.+arg\[1-6\]=0x\[0-9a-f\]+)+\r\n"
102
103
104 # Set up our own copy of /bin/cat, to make testing for a particular
105 # executable easy. We can't use 'ln' here, since we might be creating
106 # a cross-device link. We can't use 'ln -s' here, since the kernel
107 # resolves the symbolic link and reports that /bin/cat is being
108 # exec'ed (instead of our local copy).
109 if {[catch {exec cp /bin/cat $exepath} res]} {
110 fail "unable to copy /bin/cat: $res"
111 return
112 }
113
114 # "load" generation function for stap_run. It spawns our own copy of
115 # /bin/cat, waits 5 seconds, then kills it.
116 proc run_cat_5_sec {} {
117 global exepath
118
119 spawn $exepath
120 set exe_id $spawn_id
121 wait_n_secs 5;
122 kill -INT -[exp_pid -i $exe_id] 1
123 catch {close -i $exe_id}
124 catch {wait -i $exe_id}
125 return 0;
126 }
127
128 # Compile our multi-threaded test program.
129 set res [target_compile $multi_srcpath $multi_exepath executable $multi_flags]
130 if { $res != "" } {
131 verbose "target_compile failed: $res" 2
132 fail "unable to compile $multi_srcpath"
133 return
134 }
135
136 # "load" generation function for stap_run. It spawns our
137 # multi-threaded test program and waits for it to finish.
138 proc run_utrace_p5_multi {} {
139 global multi_exepath
140
141 if {[catch {exec $multi_exepath} res]} {
142 verbose "unable to run $multi_exepath: $res"
143 }
144 return 0;
145 }
146
147 set TEST_NAME "UTRACE_P5_01"
148 if {![utrace_p]} {
149 untested "$TEST_NAME : no kernel utrace support found"
150 } elseif {![installtest_p]} {
151 untested "$TEST_NAME"
152 } else {
153 set script [format $end_script $exepath]
154 stap_run $TEST_NAME run_cat_5_sec $end_script_output -e $script
155 }
156
157 set TEST_NAME "UTRACE_P5_01_cmd"
158 if {![utrace_p]} {
159 untested "$TEST_NAME : no kernel utrace support found"
160 } elseif {![installtest_p]} {
161 untested "$TEST_NAME"
162 } else {
163 set script [format $end_script $exepath]
164 foreach runtime [get_runtime_list] {
165 set test "$TEST_NAME"
166 if {$runtime != ""} {
167 set test "${test}_${runtime}"
168 stap_run $test wait_5_secs $end_script_output \
169 -e $script --runtime=$runtime -c "$exepath /dev/null"
170 } else {
171 stap_run $test wait_5_secs $end_script_output \
172 -e $script -c "$exepath /dev/null"
173 }
174 }
175 }
176
177 set TEST_NAME "UTRACE_P5_02"
178 if {![utrace_p]} {
179 untested "$TEST_NAME : no kernel utrace support found"
180 } elseif {![installtest_p]} {
181 untested "$TEST_NAME"
182 } else {
183 set script [format $begin_script $exepath]
184 stap_run $TEST_NAME run_cat_5_sec $begin_script_output -e $script
185 }
186
187 set TEST_NAME "UTRACE_P5_02_cmd"
188 if {![utrace_p]} {
189 untested "$TEST_NAME : no kernel utrace support found"
190 } elseif {![installtest_p]} {
191 untested "$TEST_NAME"
192 } else {
193 set script [format $begin_script $exepath]
194 foreach runtime [get_runtime_list] {
195 set test "$TEST_NAME"
196 if {$runtime != ""} {
197 set test "${test}_${runtime}"
198 stap_run $test wait_5_secs $begin_script_output \
199 -e $script --runtime=$runtime -c "$exepath /dev/null"
200 } else {
201 stap_run $test wait_5_secs $begin_script_output \
202 -e $script -c "$exepath /dev/null"
203 }
204 }
205 }
206
207 set TEST_NAME "UTRACE_P5_03"
208 if {![utrace_p]} {
209 untested "$TEST_NAME : no kernel utrace support found"
210 } elseif {![installtest_p]} {
211 untested "$TEST_NAME"
212 } else {
213 set script [format $syscall_script $exepath]
214 stap_run $TEST_NAME run_cat_5_sec $syscall_script_output -e $script
215 }
216
217 set TEST_NAME "UTRACE_P5_04"
218 if {![utrace_p]} {
219 untested "$TEST_NAME : no kernel utrace support found"
220 } elseif {![installtest_p]} {
221 untested "$TEST_NAME"
222 } else {
223 set script [format $syscall_return_script $exepath]
224 stap_run $TEST_NAME run_cat_5_sec $syscall_return_script_output -e $script
225 }
226
227 set TEST_NAME "UTRACE_P5_05"
228 if {![utrace_p]} {
229 untested "$TEST_NAME : no kernel utrace support found"
230 } elseif {![installtest_p]} {
231 untested "$TEST_NAME"
232 } else {
233 set script [format $thread_begin_script $multi_exepath]
234 stap_run $TEST_NAME run_utrace_p5_multi $thread_begin_script_output \
235 -e $script
236 }
237
238 set TEST_NAME "UTRACE_P5_05_cmd"
239 if {![utrace_p]} {
240 untested "$TEST_NAME : no kernel utrace support found"
241 } elseif {![installtest_p]} {
242 untested "$TEST_NAME"
243 } else {
244 set script [format $thread_begin_script $multi_exepath]
245 foreach runtime [get_runtime_list] {
246 set test "$TEST_NAME"
247 if {$runtime != ""} {
248 set test "${test}_${runtime}"
249 stap_run $test wait_5_secs $thread_begin_script_output \
250 -e $script --runtime=$runtime -c $multi_exepath
251 } else {
252 stap_run $test wait_5_secs $thread_begin_script_output \
253 -e $script -c $multi_exepath
254 }
255 }
256 }
257
258 set TEST_NAME "UTRACE_P5_06"
259 if {![utrace_p]} {
260 untested "$TEST_NAME : no kernel utrace support found"
261 } elseif {![installtest_p]} {
262 untested "$TEST_NAME"
263 } else {
264 set script [format $thread_end_script $multi_exepath]
265 stap_run $TEST_NAME run_utrace_p5_multi $thread_end_script_output \
266 -e $script
267 }
268
269 set TEST_NAME "UTRACE_P5_06_cmd"
270 if {![utrace_p]} {
271 untested "$TEST_NAME : no kernel utrace support found"
272 } elseif {![installtest_p]} {
273 untested "$TEST_NAME"
274 } else {
275 set script [format $thread_end_script $multi_exepath]
276 foreach runtime [get_runtime_list] {
277 set test "$TEST_NAME"
278 if {$runtime != ""} {
279 set test "${test}_${runtime}"
280 stap_run $test wait_5_secs $thread_end_script_output \
281 -e $script --runtime=$runtime -c $multi_exepath
282 } else {
283 stap_run $test wait_5_secs $thread_end_script_output \
284 -e $script -c $multi_exepath
285 }
286 }
287 }
288
289 set TEST_NAME "UTRACE_P5_07"
290 if {![utrace_p]} {
291 untested "$TEST_NAME : no kernel utrace support found"
292 } elseif {![installtest_p]} {
293 untested "$TEST_NAME"
294 } else {
295 stap_run $TEST_NAME run_utrace_p5_multi $bz6841_script_output \
296 -e $bz6841_script
297 }
298
299 set TEST_NAME "UTRACE_P5_08"
300 if {![utrace_p]} {
301 untested "$TEST_NAME : no kernel utrace support found"
302 } elseif {![installtest_p]} {
303 untested "$TEST_NAME"
304 } else {
305 set script [format $syscall_parms_script "%s"]
306 stap_run $TEST_NAME no_load $syscall_parms_script_output -e $script
307 }
308
309 # Cleanup
310 exec rm -f $exepath $multi_exepath