Debian Codegraph @

testsuite/systemtap.python/python3.exp

raw
1 # Test python3 probe support.
2 set test "python3"
3 global env
4 set PYTHON3 $env(PYTHON3)
5
6 if {! [installtest_p]} then { untested $test; return }
7 if {! [python3_p]} then { untested $test; return }
8 if {! [file exists "$PYTHON3"]} then { untested $test; return }
9
10 # To make sure the custom python module is in python's path, we'll
11 # modify PYTHONPATH.
12 set env(PYTHONPATH) $env(PY3EXECDIR):$srcdir/$subdir
13 verbose -log "PYTHONPATH=$env(PYTHONPATH)"
14 #
15 # Test python backtraces.
16 #
17 # Notice we are using the tcl 'exec' command redirection of '2>@1',
18 # which is equivalent to the shell's '2>&1'.
19 if {[catch {exec cp $srcdir/$subdir/celsius.py . 2>@1} out]} {
20 verbose -log "python cp failure: $out"
21 }
22
23 # This test won't work if we don't have python's debuginfo
24 # installed. So, try to compile celsius-bt.stp first to see if we've
25 # got debuginfo.
26 spawn stap -p4 $srcdir/$subdir/celsius-bt.stp python3
27 set compile_errors 0
28 expect {
29 -timeout 240
30 -re {^parse error[^\r\n]*\r\n} { incr compile_errors 1; exp_continue }
31 -re {^[^\r\n]*compilation failed[^\r\n]*\r\n} {
32 incr compile_errors 1; exp_continue }
33 -re {^semantic error[^\r\n]*\r\n} { incr compile_errors 1; exp_continue }
34 timeout { fail "$test (timeout)" }
35 eof { }
36 }
37 catch { close }
38 set res [wait -i $spawn_id]
39 set res [lindex $res 3]
40 if { $res != 0 || $compile_errors > 0 } {
41 fail "$test: debuginfo check"
42 untested $test
43 catch {exec rm -f celsius.py}
44 return
45 }
46 pass "$test: debuginfo check"
47
48
49 set traceback_lines 0
50 set error_seen 0
51 set returning_seen 0
52 spawn stap $srcdir/$subdir/celsius-bt.stp -c "$PYTHON3 -m HelperSDT celsius.py 30" python3
53 expect {
54 -timeout 240
55 -re {^30 Celsius is 86.0 Farenheit\r\n} { exp_continue }
56 -re {^Traceback[^:]+:\r\n} { exp_continue }
57 -re {^[ ]+File "celsius.py", line [0-9]+, in [^\r\n]+\r\n} {
58 incr traceback_lines; exp_continue }
59 -re {^celsius_to_farenheit returning\r\n} {
60 incr returning_seen 1; exp_continue }
61 -re {^semantic error:.+\r\n} { incr error_seen; exp_continue }
62 timeout { incr error_seen; fail "$test (timeout)" }
63 }
64 catch {close}; catch {wait}
65
66 if {$traceback_lines == 3} {
67 pass "$test: backtrace"
68 } else {
69 if {$error_seen} {
70 fail "$test: backtrace (errors)"
71 } else {
72 fail "$test: backtrace ($traceback_lines vs. 3)"
73 }
74 }
75 if {$returning_seen == 1} {
76 pass "$test: return probe seen"
77 } else {
78 if {$error_seen} {
79 fail "$test: return probe seen"
80 } else {
81 fail "$test: return probe seen ($returning_seen vs. 1)"
82 }
83 }
84
85 #
86 # Test getting the value of python variables.
87 #
88 # Notice we are using the tcl 'exec' command redirection of '2>@1',
89 # which is equivalent to the shell's '2>&1'.
90 if {[catch {exec cp $srcdir/$subdir/python-var.py . 2>@1} out]} {
91 verbose -log "python cp failure: $out"
92 }
93
94 set error_seen 0
95 # Note that we're incrementing MAXACTION, since we're doing lots of
96 # actions in each probe.
97 spawn stap -DMAXACTION=4000 $srcdir/$subdir/python-var.stp -c "$PYTHON3 -m HelperSDT python-var.py" python3
98 set types {"none" "type" "bool" "int" "long" "float" "complex" \
99 "string" "unicode" "tuple" "list" "xrange" "dictionary" \
100 "function" "class" "unbound" "instance" "method" "zip" \
101 "file" "ellipsis"}
102
103 # Note that several types aren't handled well (or at all) yet:
104 dict set kfails "none" 1
105 dict set kfails "type" 1
106 dict set kfails "bool" 1
107 dict set kfails "float" 1
108 dict set kfails "complex" 1
109 dict set kfails "function" 1
110 dict set kfails "class" 1
111 dict set kfails "unbound" 1
112 dict set kfails "instance" 1
113 dict set kfails "method" 1
114 dict set kfails "file" 1
115 dict set kfails "ellipsis" 1
116
117 set globals [dict create]
118 set locals [dict create]
119
120 # Note that the order of dictionary items isn't important, so we have
121 # to expect the items in any order.
122 expect {
123 -timeout 240
124
125 -re {^g_none = <NoneType object at 0x[0-9a-f]+>\r\n} {
126 dict set globals "none" 1; exp_continue }
127 -re {^g_type = <type object at 0x[0-9a-f]+>\r\n} {
128 dict set globals "type" 1; exp_continue }
129 -re {^g_bool = 0x1\r\n} { dict set globals "bool" 1; exp_continue }
130
131 -re {^g_int = 0x9\r\n} { dict set globals "int" 1; exp_continue }
132 -re {^g_long = 0x7eadbeeffeedbabe\r\n} {
133 dict set globals "long" 1; exp_continue }
134 -re {^g_float = <float object at 0x[0-9a-f]+>\r\n} {
135 dict set globals "float" 1; exp_continue }
136 -re {^g_complex = <complex object at 0x[0-9a-f]+>\r\n} {
137 dict set globals "complex" 1; exp_continue }
138
139 -re {^g_string = "regular string"\r\n} {
140 dict set globals "string" 1; exp_continue }
141 -re {^g_unicode = "unicode string"\r\n} {
142 dict set globals "unicode" 1; exp_continue }
143 -re {^g_tuple = \(0x0 "abc" 0x2\)\r\n} {
144 dict set globals "tuple" 1; exp_continue }
145 -re {^g_list = \[0x0 0x1 0x2 0x3\]\r\n} {
146 dict set globals "list" 1; exp_continue }
147 -re {^Error: Python variable 'g_xrange' cannot be found\r\n} {
148 dict set globals "xrange" 1; exp_continue }
149
150 -re {^g_dictionary = \{"Ribs":0x2 "Bacon":0x1 "Ham":0x0\}\r\n} {
151 dict set globals "dictionary" 1; exp_continue }
152 -re {^g_dictionary = \{"Ribs":0x2 "Ham":0x0 "Bacon":0x1\}\r\n} {
153 dict set globals "dictionary" 1; exp_continue }
154 -re {^g_dictionary = \{"Bacon":0x1 "Ham":0x0 "Ribs":0x2\}\r\n} {
155 dict set globals "dictionary" 1; exp_continue }
156 -re {^g_dictionary = \{"Bacon":0x1 "Ribs":0x2 "Ham":0x0\}\r\n} {
157 dict set globals "dictionary" 1; exp_continue }
158 -re {^g_dictionary = \{"Ham":0x0 "Ribs":0x2 "Bacon":0x1\}\r\n} {
159 dict set globals "dictionary" 1; exp_continue }
160 -re {^g_dictionary = \{"Ham":0x0 "Bacon":0x1 "Ribs":0x2\}\r\n} {
161 dict set globals "dictionary" 1; exp_continue }
162
163 -re {^g_func = <function object at 0x[0-9a-f]+>\r\n} {
164 dict set globals "function" 1; exp_continue }
165 -re {^g_class = <type object at 0x[0-9a-f]+>\r\n} {
166 dict set globals "class" 1; exp_continue }
167 -re {^g_unbound_method = <function object at 0x[0-9a-f]+>\r\n} {
168 dict set globals "unbound" 1; exp_continue }
169 -re {^g_instance = <xqueue object at 0x[0-9a-f]+>\r\n} {
170 dict set globals "instance" 1; exp_continue }
171 -re {^g_method = <method object at 0x[0-9a-f]+>\r\n} {
172 dict set globals "method" 1; exp_continue }
173
174 -re {^g_zip = <zip object at 0x[0-9a-f]+>\r\n} {
175 dict set globals "zip" 1; exp_continue }
176 -re {^g_file = <[^ ]+ object at 0x[0-9a-f]+>\r\n} {
177 dict set globals "file" 1; exp_continue }
178 -re {^g_ellipsis = <ellipsis object at 0x[0-9a-f]+>\r\n} {
179 dict set globals "ellipsis" 1; exp_continue }
180
181 -re {^l_none = <NoneType object at 0x[0-9a-f]+>\r\n} {
182 dict set locals "none" 1; exp_continue }
183 -re {^l_type = <type object at 0x[0-9a-f]+>\r\n} {
184 dict set locals "type" 1; exp_continue }
185 -re {^l_bool = 0x0\r\n} { dict set locals "bool" 1; exp_continue }
186
187 -re {^l_int = 0xf\r\n} { dict set locals "int" 1; exp_continue }
188 -re {^l_long = 0x7eedfacecafebeef\r\n} {
189 dict set locals "long" 1; exp_continue }
190 -re {^l_float = <float object at 0x[0-9a-f]+>\r\n} {
191 dict set locals "float" 1; exp_continue }
192 -re {^l_complex = <complex object at 0x[0-9a-f]+>\r\n} {
193 dict set locals "complex" 1; exp_continue }
194
195 -re {^l_string = "another regular string"\r\n} {
196 dict set locals "string" 1; exp_continue }
197 -re {^l_unicode = "another unicode string"\r\n} {
198 dict set locals "unicode" 1; exp_continue }
199 -re {^l_tuple = \("hello" 0x63 "there" 0xbeef\)\r\n} {
200 dict set locals "tuple" 1; exp_continue }
201 -re {^l_list = \[0x4 0x5 0x6 0x7 0x8 0x9 0xa\]\r\n} {
202 dict set locals "list" 1; exp_continue }
203 -re {^l_xrange = <NULL>\r\n} {
204 dict set locals "xrange" 1; exp_continue }
205 -re {^l_xrange = <NULL>\r\n} {
206 dict set locals "xrange" 1; exp_continue }
207 -re {^Error: Python variable 'l_xrange' cannot be found\r\n} {
208 dict set locals "xrange" 1; exp_continue }
209
210 -re {^l_dictionary = \{0x1:"numeric index" "abc":0x3\}\r\n} {
211 dict set locals "dictionary" 1; exp_continue }
212 -re {^l_dictionary = \{"abc":0x3 0x1:"numeric index"\}\r\n} {
213 dict set locals "dictionary" 1; exp_continue }
214
215 -re {^l_func = <function object at 0x[0-9a-f]+>\r\n} {
216 dict set locals "function" 1; exp_continue }
217 -re {^l_class = <type object at 0x[0-9a-f]+>\r\n} {
218 dict set locals "class" 1; exp_continue }
219 -re {^l_unbound_method = <[^ ]+ object at 0x[0-9a-f]+>\r\n} {
220 dict set locals "unbound" 1; exp_continue }
221 -re {^l_instance = <[^ ]+ object at 0x[0-9a-f]+>\r\n} {
222 dict set locals "instance" 1; exp_continue }
223 -re {^l_method = <[^ ]+ object at 0x[0-9a-f]+>\r\n} {
224 dict set locals "method" 1; exp_continue }
225
226 -re {^l_zip = <[^ ]+ object at 0x[0-9a-f]+>\r\n} {
227 dict set locals "zip" 1; exp_continue }
228 -re {^l_file = <[^ ]+ object at 0x[0-9a-f]+>\r\n} {
229 dict set locals "file" 1; exp_continue }
230 -re {^l_ellipsis = <ellipsis object at 0x[0-9a-f]+>\r\n} {
231 dict set locals "ellipsis" 1; exp_continue }
232
233 -re {[^\r\n]*\r\n} { exp_continue }
234 -re {^semantic error:.+\r\n} { incr error_seen; exp_continue }
235 timeout { incr error_seen; fail "$test (timeout)" }
236 }
237 catch {close}; catch {wait}
238
239 foreach type $types {
240 if {[dict exists $globals $type]} {
241 if {[dict exists $kfails $type]} {
242 kfail "${test}_${type}_support" "$test: global $type"
243 } else {
244 pass "$test: global $type"
245 }
246 } else {
247 fail "$test: global $type"
248 }
249 }
250
251 foreach type $types {
252 if {[dict exists $locals $type]} {
253 if {[dict exists $kfails $type]} {
254 kfail "${test}_${type}_support" "$test: local $type"
255 } else {
256 pass "$test: local $type"
257 }
258 } else {
259 fail "$test: local $type"
260 }
261 }
262
263 #
264 # Test python backtraces when we're in a class instance.
265 if {[catch {exec cp $srcdir/$subdir/class.py . 2>@1} out]} {
266 verbose -log "python cp failure: $out"
267 }
268
269 set traceback_lines 0
270 set error_seen 0
271 set balance1_seen 0
272 set balance2_seen 0
273 spawn stap $srcdir/$subdir/class.stp -c "$PYTHON3 -m HelperSDT class.py" \
274 python3
275 expect {
276 -timeout 240
277 -re {^Checkings current balance is: 10\r\n} { exp_continue }
278 -re {^Savings current balance is: 33\r\n} { exp_continue }
279 -re {^Traceback[^:]+:\r\n} { exp_continue }
280 -re {^[ ]+File "class.py", line [0-9]+, in [^\r\n]+\r\n} {
281 incr traceback_lines; exp_continue }
282 -re {^balance is 0xa\r\n} { incr balance1_seen; exp_continue }
283 -re {^balance is 0x21\r\n} { incr balance2_seen; exp_continue }
284 -re {^semantic error:.+\r\n} { incr error_seen; exp_continue }
285 timeout { incr error_seen; fail "$test (timeout)" }
286 }
287 catch {close}; catch {wait}
288
289 if {$traceback_lines == 4} {
290 pass "$test: backtrace"
291 } else {
292 if {$error_seen} {
293 fail "$test: backtrace (errors)"
294 } else {
295 fail "$test: backtrace ($traceback_lines vs. 4)"
296 }
297 }
298 if {$balance1_seen == 1 && $balance2_seen == 1} {
299 pass "$test: instance variable"
300 } else {
301 if {$error_seen} {
302 fail "$test: instance variable (errors)"
303 } else {
304 fail "$test: instance variable ($balance1_seen $balance2_seen)"
305 }
306 }
307
308 if { $verbose == 0 } {
309 catch {exec rm -rf celsius.py python-var.py class.py}
310 }