Debian Codegraph @

testsuite/lib/stapi.exp

raw
1 set stapi_prompt "stap>"
2 set stapi_spawn_id 0
3
4 # stapi_start ARGS
5 #
6 # Start "stap -i" with ARGS.
7 #
8 # ARGS are the optional additional arguments to pass to systemtap.
9 #
10 # Returns:
11 # 1 if starting systemtap failed,
12 # 0 if systemtap was started.
13
14 proc stapi_start { {args ""} } {
15 global stapi_spawn_id
16 global spawn_id
17
18 if {[info exists stapi_spawn_id] && $stapi_spawn_id != 0} { return }
19 if {![string match "" $args]} {
20 set rc [catch {spawn stap -i $args} out]
21 } else {
22 set rc [catch {spawn stap -i} out]
23 }
24 if {$rc} {
25 verbose -log "$out"
26 fail "Couldn't start \"stap -i\""
27 return 1
28 }
29 pass "Started stap -i"
30 set stapi_spawn_id $spawn_id
31
32 # If the pathnames given to the interactive stap's 'load' command
33 # are long, then readline will try to scroll them, causing lots of
34 # control characters in the output. This confuses us when reading
35 # the output. Instead of trying to interpret the control
36 # characters, just lie and tell the system stap's terminal is
37 # *really* wide, to avoid the need to scroll.
38 stty columns 4096 < $spawn_out(slave,name)
39 return 0
40 }
41
42 # stapi_exit
43 #
44 # Finish up the interactive systemtap.
45
46 proc stapi_exit { } {
47 global stapi_spawn_id
48
49 if {![info exists stapi_spawn_id] || $stapi_spawn_id == 0} { return }
50 catch {
51 send -i $stapi_spawn_id "quit\n"
52 expect {
53 -timeout 5
54 timeout { verbose -log "quit timeout"; kill -INT -[exp_pid] }
55 eof { }
56 }
57 }
58 # again for good measure with KILL after 3s
59 kill -INT -[exp_pid -i $stapi_spawn_id] 3
60 catch {close}; catch {wait}
61 set stapi_spawn_id 0
62 }
63
64 # stapi_test_no_output COMMAND MESSAGE
65 #
66 # Send a command to GDB and verify that this command generated no output.
67 #
68 # COMMAND is the command to execute.
69 # MESSAGE is the message to be used in a pass/fail text. If MESSAGE is
70 # empty, no pass/fail will be reported.
71 #
72 # Returns:
73 # 1 if the test failed,
74 # 0 if the test passes.
75 # -1 if there was an internal error.
76
77 proc stapi_test_no_output { command {message ""} } {
78 global stapi_prompt
79 global stapi_spawn_id
80 set rc 1
81
82 verbose -log "Sending \"$command\" to stapi"
83 if {! [info exists stapi_spawn_id]} { return }
84 send -i $stapi_spawn_id "$command\n"
85 expect {
86 -timeout 5
87 -re "(${command}\r\n$stapi_prompt )$" {
88 set rc 0
89 }
90 eof { verbose -log "\"$command\" EOF"; set rc -1 }
91 timeout { verbose -log "\"$command\" timeout" }
92 }
93 if {![string match "" $message]} {
94 if {!$rc} {
95 pass "$message"
96 } elseif {$rc < 0} {
97 fail "$message (EOF)"
98 } else {
99 fail "$message"
100 }
101 }
102 return $rc
103 }
104
105 # stapi_test_question COMMAND QUESTION RESPONSE MESSAGE
106 #
107 # Send a command to interactive stap (stap -i); expect a question, and
108 # send an answer.
109 #
110 # COMMAND is the command to execute.
111 # QUESTION is a question interactive stap may ask in response to
112 # COMMAND, like "are you sure?"
113 # RESPONSE is the response to send when QUESTION appears.
114 # MESSAGE is the message to be used in a pass/fail text. If MESSAGE is
115 # empty, no pass/fail will be reported.
116 #
117 # Returns:
118 # 1 if the test failed,
119 # 0 if the test passes.
120 # -1 if there was an internal error.
121
122 proc stapi_test_question { command question response {message ""} } {
123 global stapi_prompt
124 global stapi_spawn_id
125 set rc 0
126
127 verbose -log "Sending \"$command\" to stapi"
128 send -i $stapi_spawn_id "$command\n"
129 expect {
130 -timeout 5
131 -re "(${question})$" {
132 send -i $stapi_spawn_id "$response\n"
133 incr rc
134 exp_continue
135 }
136 -re "($response\r\n$stapi_prompt )$" {
137 incr rc
138 }
139 eof { verbose -log "\"$command\" EOF"; set rc -1 }
140 timeout { verbose -log "\"$command\" timeout" }
141 }
142 if {$rc == 2} {
143 set rc 0
144 } elseif {$rc > 0} {
145 set rc 1
146 }
147 if {![string match "" $message]} {
148 if {!$rc} {
149 pass "$message"
150 } elseif {$rc < 0} {
151 fail "$message (EOF)"
152 } else {
153 fail "$message"
154 }
155 }
156 return $rc
157 }
158
159 # stapi_run_batch USE_CACHE
160 #
161 # Call "run" in interactive systemtap to compile a script. This code
162 # is somewhat analagous to stap_run_batch() in
163 # testsuite/lib/systemtap.exp.
164 #
165 # USE_CACHE is set to 0 to indicate the cache should not have been
166 # used when compiling, 1 for cache use.
167 #
168 # Returns:
169 # 2 if the script compiled, but the cache wasn't used appropriately.
170 # 1 if the script couldn't be compiled.
171 # 0 if the test passes.
172 # -1 if there was an internal error.
173 # -2 if there was a timeout error.
174
175 proc stapi_run_batch { {use_cache 0} } {
176 global stapi_prompt
177 global stapi_spawn_id
178
179 verbose -log "Sending \"run\" to stapi"
180 send -i $stapi_spawn_id "run\n"
181 set rc 0
182 set error_seen 0
183 set cache_used 0
184 set eof_seen 0
185 set timeout_seen 0
186 expect {
187 -timeout 600
188 -re "compilation failed" { set error_seen 1; exp_continue }
189 -re "semantic error:" { set error_seen 1; exp_continue }
190 -re {Pass\ ([1234]):[^\r]*\ in\ ([0-9]+)usr/([0-9]+)sys/([0-9]+)real\ ms\.\r\n} {
191 incr rc; exp_continue
192 }
193 -re {Pass\ ([34]): using cached [^\r]+\r\n} {
194 set cache_used 1
195 incr rc; exp_continue
196 }
197 -re {Passes: via server [^\r]* using [^\r]* in [0-9]+usr/[0-9]+sys/[0-9]+real ms\.\r\n} {
198 exp_continue
199 }
200 -re "$stapi_prompt" {
201 # If this is the prompt after the script has been compiled
202 # (we've seen some/all of the "Pass [1234]" lines, then we
203 # can quit (by not calling 'exp_continue').
204 if {$rc > 0} {
205 incr rc
206 } else {
207 exp_continue
208 }
209 }
210 eof { verbose -log "stapi_run_batch EOF"; set eof_seen 1 }
211 timeout { verbose -log "stapi_run_batch timeout"
212 set timeout_seen 1 }
213 }
214
215 if {$eof_seen} {
216 return -1
217 } elseif {$timeout_seen} {
218 return -2
219 } elseif {$rc != 5 || $error_seen} {
220 return 1
221 }
222 # If rc == 5, we've seen 4 "Pass [1234]" lines and then the stap
223 # prompt, the compilation worked.
224 #
225 # But, even if the script compiled correctly, was the cache used
226 # (or not) correctly?
227 if {$cache_used == $use_cache} { return 0 }
228 return 2
229 }