Debian Codegraph @

testsuite/systemtap.unprivileged/unprivileged_probes.exp

raw
1 set test "unprivileged probes"
2
3 if {![installtest_p]} { untested $test; return }
4 if {![uprobes_p]} { untested $test; return }
5
6 set exepath "loop"
7 set sopath "libloop.so"
8 set pypath "test.py"
9
10 # These probe types should be acceptable for unprivileged users
11 set unrestricted_probe_types [list \
12 "begin" \
13 "begin(number)" \
14 "end" \
15 "end(number)" \
16 "error" \
17 "error(number)" \
18 "java(number).class(string).method(string)" \
19 "java(number).class(string).method(string).return" \
20 "java(string).class(string).method(string)" \
21 "java(string).class(string).method(string).return" \
22 "never" \
23 "process.begin" \
24 "process.end" \
25 "process.function(number)" \
26 "process.function(number).call" \
27 "process.function(number).inline" \
28 "process.function(number).return" \
29 "process.function(number).exported" \
30 "process.function(string)" \
31 "process.function(string).call" \
32 "process.function(string).inline" \
33 "process.function(string).label(string)" \
34 "process.function(string).return" \
35 "process.function(string).exported" \
36 "process.function(string).callee(string)" \
37 "process.function(string).callee(string).call" \
38 "process.function(string).callee(string).return" \
39 "process.function(string).callees" \
40 "process.function(string).callees(number)" \
41 "process.plt" \
42 "process.plt.return" \
43 "process.plt(string)" \
44 "process.plt(string).return" \
45 "process.library(string).function(number)" \
46 "process.library(string).function(number).call" \
47 "process.library(string).function(number).inline" \
48 "process.library(string).function(number).return" \
49 "process.library(string).function(number).exported" \
50 "process.library(string).function(string)" \
51 "process.library(string).function(string).call" \
52 "process.library(string).function(string).inline" \
53 "process.library(string).function(string).return" \
54 "process.library(string).function(string).exported" \
55 "process.library(string).function(string).label(string)" \
56 "process.library(string).function(string).callee(string)" \
57 "process.library(string).function(string).callee(string).call" \
58 "process.library(string).function(string).callee(string).return" \
59 "process.library(string).function(string).callees" \
60 "process.library(string).function(string).callees(number)" \
61 "process.library(string).plt" \
62 "process.library(string).plt.return" \
63 "process.library(string).plt(string)" \
64 "process.library(string).plt(string).return" \
65 "process.library(string).mark(string)" \
66 "process.library(string).provider(string).mark(string)" \
67 "process.library(string).statement(number)" \
68 "process.library(string).statement(number).nearest" \
69 "process.library(string).statement(string)" \
70 "process.library(string).statement(string).nearest" \
71 "process.provider(string).mark(string)" \
72 "process.mark(string)" \
73 "process.statement(number)" \
74 "process.statement(number).nearest" \
75 "process.statement(string)" \
76 "process.statement(string).nearest" \
77 "process.syscall" \
78 "process.syscall.return" \
79 "process.thread.begin" \
80 "process.thread.end" \
81 "process(number).begin" \
82 "process(number).end" \
83 "process(number).statement(number).absolute" \
84 "process(number).statement(number).absolute.return" \
85 "process(number).syscall" \
86 "process(number).syscall.return" \
87 "process(number).thread.begin" \
88 "process(number).thread.end" \
89 "process(number).function(number)" \
90 "process(number).function(number).call" \
91 "process(number).function(number).exported" \
92 "process(number).function(number).return" \
93 "process(number).function(string)" \
94 "process(number).function(string).call" \
95 "process(number).function(string).callee(string)" \
96 "process(number).function(string).callee(string).call" \
97 "process(number).function(string).callee(string).return" \
98 "process(number).function(string).callees" \
99 "process(number).function(string).callees(number)" \
100 "process(number).function(string).exported" \
101 "process(number).function(string).inline" \
102 "process(number).function(string).label(string)" \
103 "process(number).function(string).return" \
104 "process(number).mark(string)" \
105 "process(number).plt" \
106 "process(number).plt.return" \
107 "process(number).plt(string)" \
108 "process(number).plt(string).return" \
109 "process(number).provider(string).mark(string)" \
110 "process(number).statement(number)" \
111 "process(number).statement(number).nearest" \
112 "process(number).statement(string)" \
113 "process(number).statement(string).nearest" \
114 "process(string).begin" \
115 "process(string).end" \
116 "process(string).function(number)" \
117 "process(string).function(number).call" \
118 "process(string).function(number).inline" \
119 "process(string).function(number).return" \
120 "process(string).function(number).exported" \
121 "process(string).function(string)" \
122 "process(string).function(string).call" \
123 "process(string).function(string).inline" \
124 "process(string).function(string).label(string)" \
125 "process(string).function(string).return" \
126 "process(string).function(string).exported" \
127 "process(string).function(string).callee(string)" \
128 "process(string).function(string).callee(string).call" \
129 "process(string).function(string).callee(string).return" \
130 "process(string).function(string).callees" \
131 "process(string).function(string).callees(number)" \
132 "process(string).library(string).function(number)" \
133 "process(string).library(string).function(number).call" \
134 "process(string).library(string).function(number).inline" \
135 "process(string).library(string).function(number).return" \
136 "process(string).library(string).function(number).exported" \
137 "process(string).library(string).function(string)" \
138 "process(string).library(string).function(string).call" \
139 "process(string).library(string).function(string).inline" \
140 "process(string).library(string).function(string).return" \
141 "process(string).library(string).function(string).exported" \
142 "process(string).library(string).function(string).label(string)" \
143 "process(string).library(string).function(string).callee(string)" \
144 "process(string).library(string).function(string).callee(string).call" \
145 "process(string).library(string).function(string).callee(string).return" \
146 "process(string).library(string).function(string).callees" \
147 "process(string).library(string).function(string).callees(number)" \
148 "process(string).library(string).mark(string)" \
149 "process(string).library(string).provider(string).mark(string)" \
150 "process(string).library(string).statement(number)" \
151 "process(string).library(string).statement(number).nearest" \
152 "process(string).library(string).statement(string)" \
153 "process(string).library(string).statement(string).nearest" \
154 "process(string).library(string).plt" \
155 "process(string).library(string).plt.return" \
156 "process(string).library(string).plt(string)" \
157 "process(string).library(string).plt(string).return" \
158 "process(string).mark(string)" \
159 "process(string).provider(string).mark(string)" \
160 "process(string).statement(number)" \
161 "process(string).statement(number).nearest" \
162 "process(string).statement(string)" \
163 "process(string).statement(string).nearest" \
164 "process(string).plt" \
165 "process(string).plt.return" \
166 "process(string).plt(string)" \
167 "process(string).plt(string).return" \
168 "process(string).syscall" \
169 "process(string).syscall.return" \
170 "process(string).thread.begin" \
171 "process(string).thread.end" \
172 "timer.hz(number)" \
173 "timer.jiffies(number)" \
174 "timer.jiffies(number).randomize(number)" \
175 "timer.ms(number)" \
176 "timer.ms(number).randomize(number)" \
177 "timer.msec(number)" \
178 "timer.msec(number).randomize(number)" \
179 "timer.ns(number)" \
180 "timer.ns(number).randomize(number)" \
181 "timer.nsec(number)" \
182 "timer.nsec(number).randomize(number)" \
183 "timer.s(number)" \
184 "timer.s(number).randomize(number)" \
185 "timer.sec(number)" \
186 "timer.sec(number).randomize(number)" \
187 "timer.us(number)" \
188 "timer.us(number).randomize(number)" \
189 "timer.usec(number)" \
190 "timer.usec(number).randomize(number)" \
191
192 ]
193
194 # These probes should not be acceptable to pass 2 for unprivileged users
195 set restricted_probe_types [list \
196 "kernel.data(number).length(number).rw" \
197 "kernel.data(number).length(number).write" \
198 "kernel.data(number).rw" \
199 "kernel.data(number).write" \
200 "kernel.data(string).rw" \
201 "kernel.data(string).write" \
202 "kernel.function(number)" \
203 "kernel.function(number).call" \
204 "kernel.function(number).return" \
205 "kernel.function(number).exported" \
206 "kernel.function(number).return.maxactive(number)" \
207 "kernel.function(string)" \
208 "kernel.function(string).call" \
209 "kernel.function(string).inline" \
210 "kernel.function(string).label(string)" \
211 "kernel.function(string).return" \
212 "kernel.function(string).exported" \
213 "kernel.function(string).return.maxactive(number)" \
214 "kernel.function(string).callee(string)" \
215 "kernel.function(string).callee(string).call" \
216 "kernel.function(string).callee(string).return" \
217 "kernel.function(string).callees" \
218 "kernel.function(string).callees(number)" \
219 "kernel.mark(string)" \
220 "kernel.mark(string).format(string)" \
221 "kernel.statement(number)" \
222 "kernel.statement(number).nearest" \
223 "kernel.statement(number).absolute" \
224 "kernel.statement(string)" \
225 "kernel.statement(string).nearest" \
226 "kernel.trace(string)" \
227 "kprobe.function(string)" \
228 "kprobe.function(string).call" \
229 "kprobe.function(string).return" \
230 "kprobe.function(string).return.maxactive(number)" \
231 "kprobe.module(string).function(string)" \
232 "kprobe.module(string).function(string).call" \
233 "kprobe.module(string).function(string).return" \
234 "kprobe.module(string).function(string).return.maxactive(number)" \
235 "kprobe.statement(number).absolute" \
236 "module(string).function(number)" \
237 "module(string).function(number).call" \
238 "module(string).function(number).return" \
239 "module(string).function(number).exported" \
240 "module(string).function(number).return.maxactive(number)" \
241 "module(string).function(string)" \
242 "module(string).function(string).call" \
243 "module(string).function(string).inline" \
244 "module(string).function(string).label(string)" \
245 "module(string).function(string).return" \
246 "module(string).function(string).exported" \
247 "module(string).function(string).return.maxactive(number)" \
248 "module(string).function(string).callee(string)" \
249 "module(string).function(string).callee(string).call" \
250 "module(string).function(string).callee(string).return" \
251 "module(string).function(string).callees" \
252 "module(string).function(string).callees(number)" \
253 "module(string).statement(number)" \
254 "module(string).statement(number).nearest" \
255 "module(string).statement(string)" \
256 "module(string).statement(string).nearest" \
257 "perf.type(number).config(number)" \
258 "perf.type(number).config(number).sample(number)" \
259 "perf.type(number).config(number).hz(number)" \
260 "perf.type(number).config(number).counter(string)" \
261 "perf.type(number).config(number).process" \
262 "perf.type(number).config(number).process(string)" \
263 "perf.type(number).config(number).process(string).counter(string)" \
264 "procfs.read" \
265 "procfs.write" \
266 "procfs.read.maxsize(number)" \
267 "procfs.umask(number).read" \
268 "procfs.umask(number).read.maxsize(number)" \
269 "procfs.umask(number).write" \
270 "procfs(string).read" \
271 "procfs(string).read.maxsize(number)" \
272 "procfs(string).write" \
273 "procfs(string).umask(number).read" \
274 "procfs(string).umask(number).read.maxsize(number)" \
275 "procfs(string).umask(number).write" \
276 "timer.profile.tick" \
277 "netfilter.hook(string).pf(string)" \
278 "netfilter.pf(string).hook(string)" \
279 "netfilter.hook(string).pf(string).priority(string)" \
280 "netfilter.pf(string).hook(string).priority(string)" \
281 "python2.module(string).function(string)" \
282 "python2.module(string).function(string).call" \
283 "python2.module(string).function(string).return" \
284 "python3.module(string).function(string)" \
285 "python3.module(string).function(string).call" \
286 "python3.module(string).function(string).return" \
287 ]
288
289 # Add arguments to a probe type template.
290 proc add_args { probe_type pid } {
291 global exepath sopath
292 global addr_of_bar addr_of_libloopfunc
293
294 set probe "$probe_type"
295
296 # Replace "hz(number)" with "hz(1000)"
297 regsub -all "hz\\(number\\)" $probe "hz(1000)" probe
298 # Replace "ns(number)" with "ns(100000)"
299 regsub -all "ns\\(number\\)" $probe "ns(100000)" probe
300 # Replace "nsec(number)" with "nsec(100000)"
301 regsub -all "nsec\\(number\\)" $probe "nsec(100000)" probe
302 # Replace "us(number)" with "us(100)"
303 regsub -all "us\\(number\\)" $probe "us(100)" probe
304 # Replace "usec(number)" with "usec(100)"
305 regsub -all "usec\\(number\\)" $probe "usec(100)" probe
306 # Replace "process(number)" with "process($pid)"
307 regsub -all "process\\(number\\)" $probe "process($pid)" probe
308
309 # Replace "library(string).function(string).inline" with "library(string).function("ilibloopfunc").inline"
310 regsub -all "library\\(string\\).function\\(string\\).inline" $probe "library(string).function(\"ilibloopfunc\").inline" probe
311
312 # Replace "function(string).inline" with "function("ibar").inline"
313 regsub -all "function\\(string\\).inline" $probe "function(\"ibar\").inline" probe
314
315 # Replace 'library(string).function(string).callee(string)' with
316 # 'library(string).function("libloopfunc").callee("ilibloopfunc")'
317 regsub -all "library\\(string\\).function\\(string\\).callee\\(string\\)" \
318 $probe \
319 "library(string).function(\"libloopfunc\").callee(\"ilibloopfunc\")" \
320 probe
321 # Replace 'library(string).function(string).callees' with
322 # 'library(string).function("libloopfunc").callees'
323 regsub -all "library\\(string\\).function\\(string\\).callees" $probe \
324 "library(string).function(\"libloopfunc\").callees" probe
325
326 # Replace 'function(string).callee(string)' with
327 # 'function("main").callee("ibar")'
328 regsub -all "function\\(string\\).callee\\(string\\)" $probe \
329 "function(\"main\").callee(\"ibar\")" probe
330 # Replace 'function(string).callees' with 'function("main").callees'
331 regsub -all "function\\(string\\).callees" $probe \
332 "function(\"main\").callees" probe
333
334 # Replace 'callees(number)' with 'callees(1)'
335 regsub -all "callees\\(number\\)" $probe "callees(1)" probe
336
337 # Replace "library(string).function(string)" with "library(string.function("libloopfunc")"
338 regsub -all "library\\(string\\).function\\(string\\)" $probe "library(string).function(\"libloopfunc\")" probe
339 # Replace "library(string).function(number)" with "library(string).function($addr_of_libloopfunc)"
340 regsub -all "library\\(string\\).function\\(number\\)" $probe "library(string).function($addr_of_libloopfunc)" probe
341
342 # Replace all python[23] stuff
343 regsub -all "python2.module\\(string\\).function\\(string\\)" \
344 $probe "python2.module(\"test\").function(\"MyFunction\")" probe
345 regsub -all "python3.module\\(string\\).function\\(string\\)" \
346 $probe "python3.module(\"test\").function(\"MyFunction\")" probe
347
348 # Replace "function(string)" with "function("bar")"
349 regsub -all "function\\(string\\)" $probe "function(\"bar\")" probe
350 # Replace "function(number)" with "function($addr_of_bar)"
351 regsub -all "function\\(number\\)" $probe "function($addr_of_bar)" probe
352
353 # Replace "label(string)" with "label("a")"
354 regsub -all "label\\(string\\)" $probe "label(\"a\")" probe
355
356 # Replace "library(string).mark(string)" with "library(string).mark("libloopfunc_enter")"
357 regsub -all "library\\(string\\).mark\\(string\\)" $probe "library(string).mark(\"libloopfunc_enter\")" probe
358 # Replace "library(string).provider(string).mark(string)" with "library(string).provider(string).mark("libloopfunc_enter")"
359 regsub -all "library\\(string\\).provider\\(string\\).mark\\(string\\)" $probe "library(string).provider(string).mark(\"libloopfunc_enter\")" probe
360 # Replace "mark(string)" with "mark("main_enter")"
361 regsub -all "mark\\(string\\)" $probe "mark(\"main_enter\")" probe
362
363 # Replace "library(string).statement(number)" with "library(string).statement($addr_of_libloopfunc)"
364 regsub -all "library\\(string\\).statement\\(number\\)" $probe "library(string).statement($addr_of_libloopfunc)" probe
365 # Replace "library(string).statement(string)" with "library(string).statement("[email protected]:*")"
366 regsub -all "library\\(string\\).statement\\(string\\)" $probe "library(string).statement(\"[email protected]:*\")" probe
367
368 # Replace "statement(number)" with "statement($addr_of_bar)"
369 regsub -all "statement\\(number\\)" $probe "statement($addr_of_bar)" probe
370 # Replace "statement(string)" with "statement("[email protected]:*")"
371 regsub -all "statement\\(string\\)" $probe "statement(\"[email protected]:*\")" probe
372
373 # Replace "library(string)" with "library("$sopath")"
374 regsub -all "library\\(string\\)" $probe "library(\"$sopath\")" probe
375
376 # Replace "provider(string)" with "provider("_test_")"
377 regsub -all "provider\\(string\\)" $probe "provider(\"_test_\")" probe
378
379 # Replace plt with plt("*") (all shlib calls)
380 regsub -all "plt\\(string\\)" $probe "plt(\"*\")" probe
381
382 # Replace java stuff
383 regsub -all "java\\(number\\)" $probe "java(0)" probe
384 regsub -all "java\\(string\\)" $probe "java(\"foobar\")" probe
385 # class and method parms can stay till the last-ditch replacement below
386
387 # Replace "(number)" with "(10)"
388 regsub -all "\\(number\\)" $probe "(10)" probe
389 # Replace "(string)" with "(\"$exepath\")"
390 regsub -all "\\(string\\)" $probe "(\"./$exepath\")" probe
391
392 return "$probe"
393 }
394
395 # Add required extra options according to the probe type.
396 proc extra_options { probe_type } {
397 global exepath
398
399 if {[regexp "^process" $probe_type] ||
400 [regexp "^end" $probe_type] ||
401 [regexp "^error" $probe_type]} {
402 return "-c ./$exepath"
403 }
404 return ""
405 }
406
407 # Test unrestricted probe types
408 proc test_unrestricted_probes { privilege } {
409 global exepath
410 global unrestricted_probe_types tested allowed test
411
412 # Test using --unprivileged and --privilege=stapusr. They should be equivalent
413 set stapusr_options [list --unprivileged --privilege=stapusr ]
414 # Test using no option and --privilege=stapdev. They should be equivalent
415 set stapdev_options [list "" --privilege=stapdev ]
416 # Alternate use of additional settings (e.g. use_alias)
417 set no_yes [list 0 1]
418
419 # Start the test executable in the background
420 set our_pid [exec ./$exepath &]
421 verbose -log "our ./$exepath pid is $our_pid"
422
423 set selector 0
424 foreach probe_type $unrestricted_probe_types {
425 switch $privilege {
426 stapusr {
427 set option [lindex $stapusr_options $selector]
428 }
429 stapdev {
430 set option [lindex $stapdev_options $selector]
431 }
432 default {
433 set option "--privilege=$privilege"
434 }
435 }
436 set use_alias [lindex $no_yes $selector]
437
438 # .plt is only supported on certain arches
439 if {[regexp "\.plt" $probe_type] && ! [plt_probes_p]} {
440 untested "$test: $option $probe_type"
441 set tested($probe_type) 1
442 continue
443 }
444
445 # java support is optional
446 if {[regexp "^java" $probe_type] && ! [java_p]} {
447 untested "$test: $option $probe_type"
448 set tested($probe_type) 1
449 continue
450 }
451
452 # python2 support is optional
453 if {[regexp "^python2" $probe_type] && ! [python2_p]} {
454 untested "$test: $option $probe_type"
455 set tested($probe_type) 1
456 continue
457 }
458
459 # python3 support is optional
460 if {[regexp "^python3" $probe_type] && ! [python3_p]} {
461 untested "$test: $option $probe_type"
462 set tested($probe_type) 1
463 continue
464 }
465
466 # There are currently some known and expected failures
467 switch $probe_type {
468 process.library(string).function(number).inline -
469 process(string).library(string).function(number).inline -
470 process.function(number).inline -
471 process(string).function(number).inline
472 {
473 setup_kfail GCC *-*-*
474 }
475 process.function(number).return -
476 process.function(string).return -
477 process.library(string).function(number).return -
478 process.library(string).function(string).return -
479 process(string).function(number).return -
480 process(string).function(string).return -
481 process(string).library(string).function(number).return -
482 process(string).library(string).function(string).return
483 {
484 if {![uretprobes_p]} { setup_kfail URETPROBES *-*-* }
485 }
486 process(number).statement(number).absolute.return
487 {
488 if {![uretprobes_p]} { setup_kfail URETPROBES *-*-* }
489 if {[inode_uprobes_p]} { setup_kfail INODE_UPROBES *-*-* }
490 }
491 process(number).statement(number).absolute
492 {
493 if {[inode_uprobes_p]} { setup_kfail INODE_UPROBES *-*-* }
494 }
495 }
496
497 # Test the probe type. If successful, the stap rc will be 0.
498 set probe [add_args $probe_type $our_pid]
499
500 if { $use_alias } {
501 set with_alias " with alias"
502 set cmd [concat [list stap -p2 $option -e "probe myalias = $probe { println (\"Hello\"); exit (); } probe myalias {}"] [extra_options $probe_type]]
503 } else {
504 set with_alias ""
505 set cmd [concat [list stap -p2 $option -e "probe $probe { println (\"Hello\"); exit (); }"] [extra_options $probe_type]]
506 }
507
508 verbose -log "eval exec $cmd"
509 if {! [catch {eval exec $cmd} res_stap] == $allowed($probe_type,$privilege)} {
510 verbose -log $res_stap
511 pass "$test: $option $probe_type$with_alias"
512 } else {
513 verbose -log $res_stap
514 fail "$test: $option $probe_type$with_alias"
515 }
516
517 # Indicate that this probe type has been tested
518 set tested($probe_type) 1
519
520 set selector [expr ($selector + 1) % 2]
521 }
522
523 # Kill the the test executable
524 kill -INT $our_pid 5
525 }
526
527 # Test restricted probe types
528 proc test_restricted_probes { privilege } {
529 global exepath
530 global restricted_probe_types tested allowed test
531
532 set error_regexp1 ".*semantic error: probe point is not allowed for --privilege=.*"
533
534 # Test using --unprivileged and --privilege=stapusr. They should be equivalent
535 set stapusr_options [list --unprivileged --privilege=stapusr ]
536 # Test using no option and --privilege=stapdev. They should be equivalent
537 set stapdev_options [list "" --privilege=stapdev ]
538 # Alternate use of additional settings (e.g. use_alias)
539 set no_yes [list 0 1]
540
541 # Start the test executable in the background
542 set our_pid [exec ./$exepath &]
543 verbose -log "our ./$exepath pid is $our_pid"
544
545 set selector 0
546 foreach probe_type $restricted_probe_types {
547 switch $privilege {
548 stapusr {
549 set option [lindex $stapusr_options $selector]
550 }
551 stapdev {
552 set option [lindex $stapdev_options $selector]
553 }
554 default {
555 set option "--privilege=$privilege"
556 }
557 }
558 set use_alias [lindex $no_yes $selector]
559
560 # python2 support is optional
561 if {[regexp "^python2" $probe_type] && ! [python2_p]} {
562 untested "$test: $option $probe_type"
563 set tested($probe_type) 1
564 continue
565 }
566
567 # python3 support is optional
568 if {[regexp "^python3" $probe_type] && ! [python3_p]} {
569 untested "$test: $option $probe_type"
570 set tested($probe_type) 1
571 continue
572 }
573
574 # Test the probe type. Each should fail with the expected message.
575 set probe [add_args $probe_type $our_pid]
576 if { $use_alias } {
577 set with_alias " with alias"
578 set cmd [list stap $option -p2 -e "probe myalias = $probe {} probe myalias {}" ]
579 } else {
580 set with_alias ""
581 set cmd [list stap $option -p2 -e "probe $probe {}" ]
582 }
583 verbose -log "eval exec $cmd"
584 catch {eval exec $cmd} res_stap
585 verbose -log $res_stap
586 if {! [regexp $error_regexp1 $res_stap] == $allowed($probe_type,$privilege)} {
587 pass "$test: $option $probe_type$with_alias"
588 } else {
589 fail "$test: $option $probe_type$with_alias"
590 }
591
592 # Indicate that this probe type has been tested
593 set tested($probe_type) 1
594
595 set selector [expr ($selector + 1) % 2]
596 }
597
598 # Kill the the test executable
599 kill -INT $our_pid 5
600 }
601
602 # Need to build a user shared library.
603 set libflags [sdt_includes]
604 set libflags "$libflags additional_flags=-g"
605 set libflags "$libflags additional_flags=-O"
606 set libflags "$libflags additional_flags=-Wall"
607 set libflags "$libflags additional_flags=-Werror"
608 set libflags "$libflags additional_flags=-I."
609 set libflags "$libflags additional_flags=-shared"
610 set libflags "$libflags additional_flags=-fPIC"
611 set res [target_compile $srcdir/$subdir/libloop.c $sopath executable $libflags ]
612 if { $res == "" } {
613 pass "$test library compile"
614 } else {
615 fail "$test library compile: $res"
616 untested "$test Tests"
617 return
618 }
619
620 # Need to build a user application
621 set exeflags "additional_flags=-g"
622 set exeflags "$exeflags additional_flags=-O"
623 set exeflags "$exeflags additional_flags=-lpthread"
624 set exeflags "$exeflags [sdt_includes]"
625 set exeflags "$exeflags additional_flags=-Wl,-rpath,[pwd]"
626 set exeflags "$exeflags additional_flags=-L[pwd] additional_flags=-lloop"
627 set exeflags "$exeflags compiler=gcc"
628 # ppc64 needs a more restrictive constraint for the probe args
629 if {[regexp "^(x86_64|i.86)$" $::tcl_platform(machine)] == 0} {
630 set exeflags "$exeflags additional_flags=-DSTAP_SDT_ARG_CONSTRAINT=nr"
631 }
632 set res [target_compile $srcdir/$subdir/loop.c $exepath executable "$exeflags"]
633 if { $res == "" } {
634 pass "$test exe compile"
635 } else {
636 fail "$test exe compile: $res"
637 untested "$test Tests"
638 return
639 }
640
641 # Need to copy over the python program. Notice we are using the tcl
642 # 'exec' command redirection of '2>@1', which is equivalent to the
643 # shell's '2>&1'.
644 if {[catch {exec cp $srcdir/$subdir/$pypath . 2>@1} out]} {
645 verbose -log "python cp failure: $out"
646 }
647
648 # Extract needed addresses. Note, some architectures add a '.' to the
649 # function name, so match that optionally.
650 set addr_of_bar [exec objdump -d $exepath | awk {/<\.?bar>:/ { printf "0x%s\n",$1 }}]
651 verbose -log "addr_of_bar: $addr_of_bar"
652 set addr_of_libloopfunc [exec objdump -d $sopath | awk {/<\.?libloopfunc>:/ { printf "0x%s\n",$1 }}]
653 verbose -log "addr_of_libloopfunc: $addr_of_libloopfunc"
654
655 # Obtain a list of all supported probe types from stap
656 verbose -log "eval exec stap --dump-probe-types"
657 catch {eval exec stap --dump-probe-types} res_stap
658 set all_probe_types [split $res_stap "\n"]
659
660 # Initialize each probe type to untested
661 foreach probe_type $all_probe_types {
662 verbose -log $probe_type
663 set tested($probe_type) 0
664 }
665 if {[llength all_probe_types] > 0} {
666 pass "$test: Obtain list of supported probe types"
667 } else {
668 fail "$test: Obtain list of supported probe types"
669 untested "$test Tests"
670 return
671 }
672
673 # Initialize the expected result of running each kind of probe type with various privilege levels.
674 foreach probe_type $unrestricted_probe_types {
675 set allowed($probe_type,stapusr) 1
676 set allowed($probe_type,stapsys) 1
677 set allowed($probe_type,stapdev) 1
678 }
679 foreach probe_type $restricted_probe_types {
680 set allowed($probe_type,stapusr) 0
681 set allowed($probe_type,stapsys) 1
682 set allowed($probe_type,stapdev) 1
683 }
684
685 # Now run the tests
686 test_unrestricted_probes stapusr
687 test_unrestricted_probes stapsys
688 #test_unrestricted_probes stapdev
689 test_restricted_probes stapusr
690 test_restricted_probes stapsys
691 #test_restricted_probes stapdev
692
693 # Generate a failure for each untested probe type
694 foreach probe_type $all_probe_types {
695 set status $tested($probe_type)
696 if {$status != 0} {
697 pass "$test: tested: $probe_type"
698 } else {
699 fail "$test: not tested: $probe_type"
700 }
701 }
702
703 # Cleanup
704 catch {exec rm -f loop}
705 catch {exec rm -f libloop.so}
706 catch {exec rm -f $pypath}