Debian Codegraph @

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

raw
1 set test "attach_detach"
2 if {![installtest_p]} { untested $test; return }
3
4 set test_script { "
5 probe begin { printf(\"begin probe fired\\n\") }
6 probe timer.s(5) { printf(\"timer probe fired\\n\") }
7 probe end { printf(\"end probe fired\\n\") }
8 " }
9
10 # First, compile a module.
11 stap_compile $test 1 $test_script -m attach_detach
12
13 # stap_compile does pass/fail, but doesn't return a status. So, if
14 # attach_detach.ko exists, it worked.
15 if {! [file exists attach_detach.ko]} {
16 return
17 }
18
19 # Load the module and detach.
20 set subtest "initial load"
21 spawn staprun -L attach_detach.ko
22 set fail 0
23 set pass 0
24 expect {
25 -timeout 120
26 -re "^begin probe fired\r\n" { incr fail; exp_continue }
27 -re "^\r\n" { exp_continue }
28 -re "^Disconnecting from systemtap module.\r\n" {
29 incr pass; exp_continue
30 }
31 -re "^To reconnect, type \"staprun -A attach_detach\"\r\n" {
32 incr pass
33 }
34 eof { fail "$test ($subtest) - EOF"; incr fail }
35 timeout { fail "$test ($subtest) - unexpected timeout"; incr fail }
36 }
37 catch {close}; catch {wait}
38
39 if {$fail == 0 && $pass == 2} {
40 pass "$test ($subtest) - disconnect seen"
41 } else {
42 fail "$test ($subtest) - begin seen ($fail $pass)"
43 }
44
45 # Make sure the module is still loaded.
46 if {[catch { exec lsmod | grep attach_detach >/dev/null }]} {
47 fail "$test ($subtest) - module still present"
48 return
49 }
50 pass "$test ($subtest) - module still present"
51
52 # Attach to the module, then use SIGQUIT to detach again.
53 set subtest "attach and SIGQUIT"
54 spawn staprun -A attach_detach
55 set fail 0
56 set pass 0
57 set timer_probe_seen 0
58 expect {
59 -timeout 120
60 -re "^begin probe fired\r\n" { incr pass; exp_continue }
61 -re "^end probe fired\r\n" { incr fail; exp_continue }
62 -re "^timer probe fired\r\n" {
63 if {!$timer_probe_seen} {
64 set timer_probe_seen 1
65 incr pass
66
67 # Send our staprun process a SIGQUIT, to make it detach.
68 kill SIGQUIT [exp_pid]
69 }
70 exp_continue
71 }
72 -re "^\r\n" { exp_continue }
73 -re "^Disconnecting from systemtap module.\r\n" {
74 incr pass; exp_continue
75 }
76 -re "^To reconnect, type \"staprun -A attach_detach\"\r\n" {
77 incr pass
78 }
79 eof { fail "$test ($subtest) - EOF"; incr fail }
80 timeout { fail "$test ($subtest) - unexpected timeout"; incr fail }
81 }
82 catch {close}; catch {wait}
83
84 if {$fail == 0 && $pass == 4} {
85 pass "$test ($subtest) - disconnect seen"
86 } else {
87 fail "$test ($subtest) - no disconnect seen ($fail $pass)"
88 }
89
90 # Make sure the module is still loaded.
91 if {[catch { exec lsmod | grep attach_detach >/dev/null}]} {
92 fail "$test ($subtest) - module still present"
93 return
94 }
95 pass "$test ($subtest) - module still present"
96
97 # Attach one last time, then use SIGTERM to unload the module and quit.
98 set subtest "attach and SIGTERM"
99 spawn staprun -A attach_detach
100 set fail 0
101 set pass 0
102 set timer_probe_seen 0
103 expect {
104 -timeout 120
105 -re "^begin probe fired\r\n" { incr fail; exp_continue }
106 -re "^end probe fired\r\n" { incr pass }
107 -re "^timer probe fired\r\n" {
108 if {!$timer_probe_seen} {
109 set timer_probe_seen 1
110 incr pass
111
112 # Send our staprun process a SIGTERM, to make it quit and
113 # unload.
114 kill SIGTERM [exp_pid]
115 }
116 exp_continue
117 }
118 -re "^\r\n" { exp_continue }
119 -re "^Disconnecting from systemtap module.\r\n" {
120 incr fail; exp_continue
121 }
122 -re "^To reconnect, type \"staprun -A attach_detach\"\r\n" {
123 incr fail; exp_continue
124 }
125 eof { fail "$test ($subtest) - EOF"; incr fail }
126 timeout { fail "$test ($subtest) - unexpected timeout"; incr fail }
127 }
128 catch {close}; catch {wait}
129
130 if {$fail == 0 && $pass == 2} {
131 pass "$test ($subtest) - quit seen"
132 } else {
133 fail "$test ($subtest) - no quit seen ($fail $pass)"
134 }
135
136 # Make sure the module isn't still loaded.
137 if {[catch { exec lsmod | grep attach_detach >/dev/null}]} {
138 pass "$test ($subtest) - module is gone"
139 } else {
140 fail "$test ($subtest) - module is gone"
141
142 # If for some odd reason the module is still loaded, try to unload
143 # it.
144 catch { exec staprun -d attach_detach }
145 }