Debian Codegraph @

doc/SystemTap_Beginners_Guide/testsuite/systemtap.clone/probe_by_pid.exp

raw
1 set TEST_BASENAME "probe_by_pid"
2 set TEST_NAME ${TEST_BASENAME}
3 set build_dir ""
4 set test_progs {"probe_by_pid"}
5
6 if {![installtest_p]} { untested $TEST_NAME; return }
7 if {![utrace_p]} { untested $TEST_NAME; return }
8
9 source $srcdir/$subdir/test_progs.tcl
10
11 proc run_test_prog {} {
12 global test_prog
13
14 # Start yet another copy of the test program. This one should be
15 # ignored by stap.
16 spawn $test_prog
17 set id $spawn_id
18
19 # Wait 3 seconds
20 wait_n_secs 3
21
22 # Kill the test program
23 catch {kill -INT -[exp_pid -i $id] 2}
24 catch {close -i $id}; catch {wait -i $id}
25 return 0
26 }
27
28 # Do strict utrace-only tests here...
29
30 # Build base test program
31 set TEST_NAME "probe_by_pid(utrace)"
32 if {[build_test_progs "Makefile.probe_by_pid" $test_progs] == 0} {
33 fail "$TEST_NAME - build failure"
34 cleanup_test_progs
35 # In theory we could go on here and test the uprobe tests, but
36 # let's just quit.
37 return
38 } else {
39 pass "$TEST_NAME - build success"
40 }
41
42 # Run the 1st instance of the test program.
43 verbose -log "running test programs..."
44 set test_prog $build_dir/[lindex $test_progs 0]
45 spawn $test_prog
46 set id1 $spawn_id
47
48 # Run the 2nd instance of the test program.
49 spawn $test_prog
50 set id2 $spawn_id
51 set pid2 [exp_pid -i $id2]
52
53 # Run stap on the 2nd instance.
54 set output_string "${pid2}: 1 begin probes\r\n${pid2}: \[0-9\]+ syscall probes\r\n"
55 stap_run $TEST_NAME run_test_prog $output_string \
56 $srcdir/$subdir/probe_by_pid_utrace.stp $pid2
57
58 # Kill both of the spawned processes
59 catch {kill -INT -[exp_pid -i $id1] 2}
60 catch {close -i $id1}; catch {wait -i $id1}
61 catch {kill -INT -[exp_pid -i $id2] 2}
62 catch {close -i $id2}; catch {wait -i $id2}
63
64 # Here we'd like to test 'process(PID).function(FUNC)', but process
65 # function probes only support .process(PATH).function(FUNC)' probes.
66 # See PR6897 "stap should assert valid PIDs for process(PID) probes"
67 # and PR11644 "process(PID).function/statement probes".
68 #
69 # So, instead we'll use hard-links to try and confuse things. If we
70 # probe 'process(PATH").function("*")' and link PATH to PATH2, do the
71 # probes get hit in PATH2?
72
73 set TEST_NAME "probe_by_pid(function)"
74 if {![uprobes_p]} { untested $TEST_NAME; return }
75 # do uprobes tests here - both function and sdt marker
76
77 # Run the 1st instance of the test program.
78 verbose -log "running test programs..."
79 set test_prog $build_dir/[lindex $test_progs 0]
80 spawn $test_prog
81 set id1 $spawn_id
82
83 # Link...
84 set test_prog2 "${test_prog}2"
85 exec ln $test_prog $test_prog2
86
87 # Run the 2nd instance of the test program.
88 spawn $test_prog2
89 set id2 $spawn_id
90 set pid2 [exp_pid -i $id2]
91
92 # Run stap on the 2nd instance.
93 set output_string "${pid2}: \[0-9\]+ test_function probes\r\n"
94 stap_run $TEST_NAME run_test_prog $output_string \
95 $srcdir/$subdir/probe_by_pid_function.stp -d $test_prog2 $test_prog2
96
97 # Kill both of the spawned processes
98 catch {kill -INT -[exp_pid -i $id1] 2}
99 catch {close -i $id1}; catch {wait -i $id1}
100 catch {kill -INT -[exp_pid -i $id2] 2}
101 catch {close -i $id2}; catch {wait -i $id2}
102
103 # FIXME: we could also test hard-linked paths with
104 # 'process(PATH).mark(MARK)' probes (with and without semaphores).
105
106 # Cleanup
107 cleanup_test_progs