File: python3.exp

package info (click to toggle)
systemtap 5.3-2
  • links: PTS, VCS
  • area: main
  • in suites: forky, sid
  • size: 47,556 kB
  • sloc: cpp: 81,117; ansic: 54,933; xml: 49,795; exp: 43,595; sh: 11,526; python: 5,003; perl: 2,252; tcl: 1,312; makefile: 1,006; javascript: 149; lisp: 105; awk: 101; asm: 91; java: 70; sed: 16
file content (310 lines) | stat: -rw-r--r-- 10,961 bytes parent folder | download | duplicates (4)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
# Test python3 probe support.
set test "python3"
global env
set PYTHON3 $env(PYTHON3)

if {! [installtest_p]} then { untested $test; return }
if {! [python3_p]} then { untested $test; return }
if {! [file exists "$PYTHON3"]} then { untested $test; return }

# To make sure the custom python module is in python's path, we'll
# modify PYTHONPATH.
set env(PYTHONPATH) $env(PY3EXECDIR):$srcdir/$subdir
verbose -log "PYTHONPATH=$env(PYTHONPATH)"
#
# Test python backtraces.
#
# Notice we are using the tcl 'exec' command redirection of '2>@1',
# which is equivalent to the shell's '2>&1'.
if {[catch {exec cp $srcdir/$subdir/celsius.py . 2>@1} out]} {
    verbose -log "python cp failure: $out"
}

# This test won't work if we don't have python's debuginfo
# installed. So, try to compile celsius-bt.stp first to see if we've
# got debuginfo.
spawn stap -p4 $srcdir/$subdir/celsius-bt.stp python3
set compile_errors 0
expect {
    -timeout 240
    -re {^parse error[^\r\n]*\r\n} { incr compile_errors 1; exp_continue }
    -re {^[^\r\n]*compilation failed[^\r\n]*\r\n} {
	incr compile_errors 1; exp_continue }
    -re {^semantic error[^\r\n]*\r\n} { incr compile_errors 1; exp_continue }
    timeout { fail "$test (timeout)" }
    eof { }
}
catch { close }
set res [wait -i $spawn_id]
set res [lindex $res 3]
if { $res != 0 || $compile_errors > 0 } {
    fail "$test: debuginfo check"
    untested $test
    catch {exec rm -f celsius.py}
    return
}
pass "$test: debuginfo check"


set traceback_lines 0
set error_seen 0
set returning_seen 0
spawn stap $srcdir/$subdir/celsius-bt.stp -c "$PYTHON3 -m HelperSDT celsius.py 30" python3
expect {
    -timeout 240
    -re {^30 Celsius is 86.0 Farenheit\r\n} { exp_continue }
    -re {^Traceback[^:]+:\r\n} { exp_continue }
    -re {^[ ]+File "celsius.py", line [0-9]+, in [^\r\n]+\r\n} {
	incr traceback_lines; exp_continue }
    -re {^celsius_to_farenheit returning\r\n} {
	incr returning_seen 1; exp_continue }
    -re {^semantic error:.+\r\n} { incr error_seen; exp_continue }
    timeout { incr error_seen; fail "$test (timeout)" }
}
catch {close}; catch {wait}

if {$traceback_lines == 3} {
    pass "$test: backtrace"
} else {
    if {$error_seen} {
	fail "$test: backtrace (errors)"
    } else {
	fail "$test: backtrace ($traceback_lines vs. 3)"
    }
}
if {$returning_seen == 1} {
    pass "$test: return probe seen"
} else {
    if {$error_seen} {
	fail "$test: return probe seen"
    } else {
	fail "$test: return probe seen ($returning_seen vs. 1)"
    }
}

#
# Test getting the value of python variables.
#
# Notice we are using the tcl 'exec' command redirection of '2>@1',
# which is equivalent to the shell's '2>&1'.
if {[catch {exec cp $srcdir/$subdir/python-var.py . 2>@1} out]} {
    verbose -log "python cp failure: $out"
}

set error_seen 0
# Note that we're incrementing MAXACTION, since we're doing lots of
# actions in each probe.
spawn stap -DMAXACTION=4000 $srcdir/$subdir/python-var.stp -c "$PYTHON3 -m  HelperSDT python-var.py" python3
set types {"none" "type" "bool" "int" "long" "float" "complex" \
	       "string" "unicode" "tuple" "list" "xrange" "dictionary" \
	       "function" "class" "unbound" "instance" "method" "zip" \
	       "file" "ellipsis"}

# Note that several types aren't handled well (or at all) yet:
dict set kfails "none" 1
dict set kfails "type" 1
dict set kfails "bool" 1
dict set kfails "float" 1
dict set kfails "complex" 1
dict set kfails "function" 1
dict set kfails "class" 1
dict set kfails "unbound" 1
dict set kfails "instance" 1
dict set kfails "method" 1
dict set kfails "file" 1
dict set kfails "ellipsis" 1

set globals [dict create]
set locals [dict create]

# Note that the order of dictionary items isn't important, so we have
# to expect the items in any order.
expect {
    -timeout 240

    -re {^g_none = <NoneType object at 0x[0-9a-f]+>\r\n} {
	dict set globals "none" 1; exp_continue }
    -re {^g_type = <type object at 0x[0-9a-f]+>\r\n} {
	dict set globals "type" 1; exp_continue }
    -re {^g_bool = 0x1\r\n} { dict set globals "bool" 1; exp_continue }

    -re {^g_int = 0x9\r\n} { dict set globals "int" 1; exp_continue }
    -re {^g_long = 0x7eadbeeffeedbabe\r\n} {
	dict set globals "long" 1; exp_continue }
    -re {^g_float = <float object at 0x[0-9a-f]+>\r\n} {
	dict set globals "float" 1; exp_continue }
    -re {^g_complex = <complex object at 0x[0-9a-f]+>\r\n} {
	dict set globals "complex" 1; exp_continue }

    -re {^g_string = "regular string"\r\n} {
	dict set globals "string" 1; exp_continue }
    -re {^g_unicode = "unicode string"\r\n} {
	dict set globals "unicode" 1; exp_continue }
    -re {^g_tuple = \(0x0 "abc" 0x2\)\r\n} {
	dict set globals "tuple" 1; exp_continue }
    -re {^g_list = \[0x0 0x1 0x2 0x3\]\r\n} {
	dict set globals "list" 1; exp_continue }
    -re {^Error: Python variable 'g_xrange' cannot be found\r\n} {
	dict set globals "xrange" 1; exp_continue }

    -re {^g_dictionary = \{"Ribs":0x2 "Bacon":0x1 "Ham":0x0\}\r\n} {
	dict set globals "dictionary" 1; exp_continue }
    -re {^g_dictionary = \{"Ribs":0x2 "Ham":0x0 "Bacon":0x1\}\r\n} {
	dict set globals "dictionary" 1; exp_continue }
    -re {^g_dictionary = \{"Bacon":0x1 "Ham":0x0 "Ribs":0x2\}\r\n} {
	dict set globals "dictionary" 1; exp_continue }
    -re {^g_dictionary = \{"Bacon":0x1 "Ribs":0x2 "Ham":0x0\}\r\n} {
	dict set globals "dictionary" 1; exp_continue }
    -re {^g_dictionary = \{"Ham":0x0 "Ribs":0x2 "Bacon":0x1\}\r\n} {
	dict set globals "dictionary" 1; exp_continue }
    -re {^g_dictionary = \{"Ham":0x0 "Bacon":0x1 "Ribs":0x2\}\r\n} {
	dict set globals "dictionary" 1; exp_continue }

    -re {^g_func = <function object at 0x[0-9a-f]+>\r\n} {
	dict set globals "function" 1; exp_continue }
    -re {^g_class = <type object at 0x[0-9a-f]+>\r\n} {
	dict set globals "class" 1; exp_continue }
    -re {^g_unbound_method = <function object at 0x[0-9a-f]+>\r\n} {
	dict set globals "unbound" 1; exp_continue }
    -re {^g_instance = <xqueue object at 0x[0-9a-f]+>\r\n} {
	dict set globals "instance" 1; exp_continue }
    -re {^g_method = <method object at 0x[0-9a-f]+>\r\n} {
	dict set globals "method" 1; exp_continue }

    -re {^g_zip = <zip object at 0x[0-9a-f]+>\r\n} {
	dict set globals "zip" 1; exp_continue }
    -re {^g_file = <[^ ]+ object at 0x[0-9a-f]+>\r\n} {
	dict set globals "file" 1; exp_continue }
    -re {^g_ellipsis = <ellipsis object at 0x[0-9a-f]+>\r\n} {
	dict set globals "ellipsis" 1; exp_continue }

    -re {^l_none = <NoneType object at 0x[0-9a-f]+>\r\n} {
	dict set locals "none" 1; exp_continue }
    -re {^l_type = <type object at 0x[0-9a-f]+>\r\n} {
	dict set locals "type" 1; exp_continue }
    -re {^l_bool = 0x0\r\n} { dict set locals "bool" 1; exp_continue }

    -re {^l_int = 0xf\r\n} { dict set locals "int" 1; exp_continue }
    -re {^l_long = 0x7eedfacecafebeef\r\n} {
	dict set locals "long" 1; exp_continue }
    -re {^l_float = <float object at 0x[0-9a-f]+>\r\n} {
	dict set locals "float" 1; exp_continue }
    -re {^l_complex = <complex object at 0x[0-9a-f]+>\r\n} {
	dict set locals "complex" 1; exp_continue }

    -re {^l_string = "another regular string"\r\n} {
	dict set locals "string" 1; exp_continue }
    -re {^l_unicode = "another unicode string"\r\n} {
	dict set locals "unicode" 1; exp_continue }
    -re {^l_tuple = \("hello" 0x63 "there" 0xbeef\)\r\n} {
	dict set locals "tuple" 1; exp_continue }
    -re {^l_list = \[0x4 0x5 0x6 0x7 0x8 0x9 0xa\]\r\n} {
	dict set locals "list" 1; exp_continue }
    -re {^l_xrange = <NULL>\r\n} {
	dict set locals "xrange" 1; exp_continue }
    -re {^l_xrange = <NULL>\r\n} {
	dict set locals "xrange" 1; exp_continue }
    -re {^Error: Python variable 'l_xrange' cannot be found\r\n} {
	dict set locals "xrange" 1; exp_continue }

    -re {^l_dictionary = \{0x1:"numeric index" "abc":0x3\}\r\n} {
	dict set locals "dictionary" 1; exp_continue }
    -re {^l_dictionary = \{"abc":0x3 0x1:"numeric index"\}\r\n} {
	dict set locals "dictionary" 1; exp_continue }

    -re {^l_func = <function object at 0x[0-9a-f]+>\r\n} {
	dict set locals "function" 1; exp_continue }
    -re {^l_class = <type object at 0x[0-9a-f]+>\r\n} {
	dict set locals "class" 1; exp_continue }
    -re {^l_unbound_method = <[^ ]+ object at 0x[0-9a-f]+>\r\n} {
	dict set locals "unbound" 1; exp_continue }
    -re {^l_instance = <[^ ]+ object at 0x[0-9a-f]+>\r\n} {
	dict set locals "instance" 1; exp_continue }
    -re {^l_method = <[^ ]+ object at 0x[0-9a-f]+>\r\n} {
	dict set locals "method" 1; exp_continue }

    -re {^l_zip = <[^ ]+ object at 0x[0-9a-f]+>\r\n} {
	dict set locals "zip" 1; exp_continue }
    -re {^l_file = <[^ ]+ object at 0x[0-9a-f]+>\r\n} {
	dict set locals "file" 1; exp_continue }
    -re {^l_ellipsis = <ellipsis object at 0x[0-9a-f]+>\r\n} {
	dict set locals "ellipsis" 1; exp_continue }

    -re {[^\r\n]*\r\n} { exp_continue }
    -re {^semantic error:.+\r\n} { incr error_seen; exp_continue }
    timeout { incr error_seen; fail "$test (timeout)" }
}
catch {close}; catch {wait}

foreach type $types {
    if {[dict exists $globals $type]} {
	if {[dict exists $kfails $type]} {
	    kfail "${test}_${type}_support" "$test: global $type"
	} else {
	    pass "$test: global $type"
	}
    } else {
	fail "$test: global $type"
    }
}

foreach type $types {
    if {[dict exists $locals $type]} {
	if {[dict exists $kfails $type]} {
	    kfail "${test}_${type}_support" "$test: local $type"
	} else {
	    pass "$test: local $type"
	}
    } else {
	fail "$test: local $type"
    }
}

#
# Test python backtraces when we're in a class instance.
if {[catch {exec cp $srcdir/$subdir/class.py . 2>@1} out]} {
    verbose -log "python cp failure: $out"
}

set traceback_lines 0
set error_seen 0
set balance1_seen 0
set balance2_seen 0
spawn stap $srcdir/$subdir/class.stp -c "$PYTHON3 -m HelperSDT class.py" \
    python3
expect {
    -timeout 240
    -re {^Checkings current balance is: 10\r\n} { exp_continue }
    -re {^Savings current balance is: 33\r\n} { exp_continue }
    -re {^Traceback[^:]+:\r\n} { exp_continue }
    -re {^[ ]+File "class.py", line [0-9]+, in [^\r\n]+\r\n} {
	incr traceback_lines; exp_continue }
    -re {^balance is 0xa\r\n} { incr balance1_seen; exp_continue }
    -re {^balance is 0x21\r\n} { incr balance2_seen; exp_continue }
    -re {^semantic error:.+\r\n} { incr error_seen; exp_continue }
    timeout { incr error_seen; fail "$test (timeout)" }
}
catch {close}; catch {wait}

if {$traceback_lines == 4} {
    pass "$test: backtrace"
} else {
    if {$error_seen} {
	fail "$test: backtrace (errors)"
    } else {
	fail "$test: backtrace ($traceback_lines vs. 4)"
    }
}
if {$balance1_seen == 1 && $balance2_seen == 1} {
    pass "$test: instance variable"
} else {
    if {$error_seen} {
	fail "$test: instance variable (errors)"
    } else {
	fail "$test: instance variable ($balance1_seen $balance2_seen)"
    }
}

if { $verbose == 0 } {
    catch {exec rm -rf celsius.py python-var.py class.py}
}