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