| 1 |
foreach py {python python2 python3} { |
| 2 |
set test "dtrace $py" |
| 3 |
set python "/usr/bin/$py" |
| 4 |
if {! [file executable $python]} then { |
| 5 |
unsupported $test |
| 6 |
continue |
| 7 |
} |
| 8 |
|
| 9 |
# Test the dtrace compatible python script |
| 10 |
if {[installtest_p]} { |
| 11 |
set dtrace "$env(SYSTEMTAP_PATH)/dtrace" |
| 12 |
} else { |
| 13 |
set dtrace "../dtrace" |
| 14 |
} |
| 15 |
|
| 16 |
# Create the test .d files |
| 17 |
set dpath "$srcdir/$subdir/dtrace-test.d" |
| 18 |
set ipath "$srcdir/$subdir/dtrace-inc-dtest.h" |
| 19 |
set idpath "$srcdir/$subdir/dtrace-itest.d" |
| 20 |
set pypath "$srcdir/$subdir/dtrace-pypath.d" |
| 21 |
set incpath "$srcdir/$subdir" |
| 22 |
|
| 23 |
|
| 24 |
# clean up junk output from previous runs |
| 25 |
exec bash -c "rm -f dtrace-* .dtrace-*" |
| 26 |
|
| 27 |
# ----------------------------------------------------------------- |
| 28 |
# test command line option and file handling |
| 29 |
|
| 30 |
verbose -log "$dtrace -G -64 -fPIC -s $dpath -o dtrace-XXX.o" |
| 31 |
catch {exec $python $dtrace -G -64 -fPIC -s $dpath -o dtrace-XXX.o} |
| 32 |
if {[file exists dtrace-XXX.o]} then { |
| 33 |
pass "$test -G -64 -fPIC -o dtrace-XXX.o" |
| 34 |
} else { |
| 35 |
fail "$test -G -64 -fPIC -o dtrace-XXX.o" |
| 36 |
} |
| 37 |
exec rm -f dtrace-XXX.o |
| 38 |
|
| 39 |
|
| 40 |
set env(CFLAGS) "-DFOO=\\\"5.5.5\\\" \\\n -DFOO2 \n -DFOO3" |
| 41 |
|
| 42 |
verbose -log "set tricky CFLAGS=$env(CFLAGS)" |
| 43 |
catch { exec sh -c {env | grep -A2 CFLAGS} } nonhex |
| 44 |
verbose -log "nonhexdump $nonhex" |
| 45 |
catch { exec sh -c {env | grep -A2 CFLAGS | od -t x1} } hex |
| 46 |
verbose -log "hexdump $hex" |
| 47 |
|
| 48 |
verbose -log "$dtrace -G -s $dpath -o dtrace-XXX" |
| 49 |
catch {exec $python $dtrace -G -s $dpath -o dtrace-XXX} res |
| 50 |
if {[file exists dtrace-XXX]} then { |
| 51 |
pass "$test -G -o dtrace-XXX" |
| 52 |
} else { |
| 53 |
fail "$test -G -o dtrace-XXX $res" |
| 54 |
} |
| 55 |
exec rm -f dtrace-XXX |
| 56 |
|
| 57 |
unset env(CFLAGS) |
| 58 |
|
| 59 |
verbose -log "$dtrace -h -s $dpath -o dtrace-XXX.h" |
| 60 |
catch {exec $python $dtrace -h -s $dpath -o dtrace-XXX.h} res |
| 61 |
if {[file exists dtrace-XXX.h]} then { |
| 62 |
pass "$test -h -o dtrace-XXX.h" |
| 63 |
} else { |
| 64 |
fail "$test -h -o dtrace-XXX.h $res" |
| 65 |
} |
| 66 |
exec rm -f dtrace-XXX.h |
| 67 |
|
| 68 |
verbose -log "$dtrace -h -s $dpath -o dtrace-XXX" |
| 69 |
catch {exec $python $dtrace -h -s $dpath -o dtrace-XXX} |
| 70 |
if {[file exists dtrace-XXX]} then { |
| 71 |
pass "$test -h -o dtrace-XXX" |
| 72 |
} else { |
| 73 |
fail "$test -h -o dtrace-XXX" |
| 74 |
} |
| 75 |
exec rm -f dtrace-XXX |
| 76 |
|
| 77 |
verbose -log "$dtrace -G -s $dpath -o /tmp/XXX.o" |
| 78 |
catch {exec $python $dtrace -G -s $dpath -o /tmp/XXX.o} res |
| 79 |
if {[file exists /tmp/XXX.o]} then { |
| 80 |
pass "$test -G -o /tmp/XXX.o" |
| 81 |
} else { |
| 82 |
fail "$test -G -o /tmp/XXX.o $res" |
| 83 |
} |
| 84 |
exec rm -f /tmp/XXX.o |
| 85 |
|
| 86 |
# In case $dpath is in a directory structure not readable for the |
| 87 |
# as_non_root()'s user (nobody), we copy the dpath content to a |
| 88 |
# temporary directory with sufficiently relaxed access, and use |
| 89 |
# tmpdir instead of dpath: |
| 90 |
if {[catch {exec mktemp -d staptestXXXXXX} tmpdir]} { |
| 91 |
verbose -log "Failed to create temporary directory: $tmpdir" |
| 92 |
return |
| 93 |
} |
| 94 |
if {[catch {exec bash -c "cp -r $dpath/* $tmpdir/ && chmod -R a+rx $tmpdir"}]} { |
| 95 |
verbose -log "Failed to initialize temporary directory $tmpdir" |
| 96 |
return |
| 97 |
} |
| 98 |
verbose -log "$dtrace -G -s $tmpdir -o /dev/null" |
| 99 |
if [as_non_root "$python $dtrace -G -s $tmpdir -o /dev/null"] { |
| 100 |
fail "$test -G -o /dev/null" |
| 101 |
} else { |
| 102 |
pass "$test -G -o /dev/null" |
| 103 |
} |
| 104 |
if {[catch {exec rm -rf $tmpdir}]} { |
| 105 |
verbose -log "Failed to remove temporary directory $tmpdir" |
| 106 |
return |
| 107 |
} |
| 108 |
|
| 109 |
verbose -log "$dtrace -G -s $dpath -o /tmp/XXX" |
| 110 |
catch {exec $python $dtrace -G -s $dpath -o /tmp/XXX} res |
| 111 |
if {[file exists /tmp/XXX]} then { |
| 112 |
pass "$test -G -o /tmp/XXX" |
| 113 |
} else { |
| 114 |
fail "$test -G -o /tmp/XXX $res" |
| 115 |
} |
| 116 |
exec rm -f /tmp/XXX |
| 117 |
|
| 118 |
verbose -log "$dtrace -h -s $dpath -o /tmp/XXX.h" |
| 119 |
catch {exec $python $dtrace -h -s $dpath -o /tmp/XXX.h} |
| 120 |
if {[file exists /tmp/XXX.h]} then { |
| 121 |
pass "$test -h -o /tmp/XXX.h" |
| 122 |
} else { |
| 123 |
fail "$test -h -o /tmp/XXX.h" |
| 124 |
} |
| 125 |
exec rm -f /tmp/XXX.h |
| 126 |
|
| 127 |
verbose -log "$dtrace -h -s $dpath -o /tmp/XXX" |
| 128 |
catch {exec $python $dtrace -h -s $dpath -o /tmp/XXX} |
| 129 |
if {[file exists /tmp/XXX]} then { |
| 130 |
pass "$test -h -o /tmp/XXX" |
| 131 |
} else { |
| 132 |
fail "$test -h -o /tmp/XXX" |
| 133 |
} |
| 134 |
exec rm -f /tmp/XXX |
| 135 |
|
| 136 |
verbose -log "$dtrace -G -s $dpath" |
| 137 |
catch {exec $python $dtrace -G -s $dpath} |
| 138 |
if {[file exists dtrace-test.o]} then { |
| 139 |
pass "$test -G" |
| 140 |
} else { |
| 141 |
fail "$test -G" |
| 142 |
} |
| 143 |
exec rm -f test.o |
| 144 |
|
| 145 |
verbose -log "$dtrace -h -s $dpath" |
| 146 |
catch {exec $python $dtrace -h -s $dpath} |
| 147 |
if {[file exists dtrace-test.h]} then { |
| 148 |
pass "$test -h" |
| 149 |
} else { |
| 150 |
fail "$test -h" |
| 151 |
} |
| 152 |
exec rm -f test.o |
| 153 |
|
| 154 |
set ok 0 |
| 155 |
verbose -log "CFLAGS=\"MYCFLAGS\" CC=echo $dtrace -G -s $dpath" |
| 156 |
spawn env CFLAGS=MYCFLAGS CC=echo $python $dtrace -G -s $dpath |
| 157 |
expect { |
| 158 |
-re {-g MYCFLAGS} {incr ok} |
| 159 |
} |
| 160 |
catch {close}; catch {wait} |
| 161 |
if { $ok != 0} { |
| 162 |
pass "$test CFLAGS= CC=" |
| 163 |
} else { |
| 164 |
fail "$test CFLAGS= CC=" |
| 165 |
} |
| 166 |
|
| 167 |
# ----------------------------------------------------------------- |
| 168 |
# test -h header file creation |
| 169 |
|
| 170 |
set ok 0 |
| 171 |
verbose -log "$dtrace -C -h -s $dpath -o dtrace-XXX.h" |
| 172 |
catch {exec $python $dtrace -C -h -s $dpath -o dtrace-XXX.h} |
| 173 |
spawn cat dtrace-XXX.h |
| 174 |
expect { |
| 175 |
"short arg1, int arg2, int arg3, int arg4" {incr ok} |
| 176 |
} |
| 177 |
catch {close}; catch {wait} |
| 178 |
if { $ok != 0} { |
| 179 |
pass "$test -C -h -o dtrace-XXX.h" |
| 180 |
} else { |
| 181 |
fail "$test -C -h -o dtrace-XXX.h" |
| 182 |
} |
| 183 |
exec rm -f dtrace-XXX.h |
| 184 |
|
| 185 |
set ok 0 |
| 186 |
verbose -log "$dtrace -C -I$incpath -h -s $idpath -o XXX.h" |
| 187 |
catch {exec $python $dtrace -C -I$incpath -h -s $idpath -o dtrace-XXX.h} |
| 188 |
spawn cat dtrace-XXX.h |
| 189 |
expect { |
| 190 |
-re {DTRACE_PROBE \(tstsyscall, test0\)} {incr ok; exp_continue} |
| 191 |
-re {short arg1, int arg2, int arg3, int arg4} {incr ok; exp_continue} |
| 192 |
-re {DTRACE_PROBE. \(tstsyscall, test., arg1, arg2, arg3, arg4, arg5\)} {incr ok} |
| 193 |
eof { } |
| 194 |
} |
| 195 |
catch {close}; catch {wait} |
| 196 |
if { $ok == 4} { |
| 197 |
pass "$test -C -Iincpath -h -o dtrace-XXX.h" |
| 198 |
} else { |
| 199 |
fail "$test -C -Iincpath -h -o dtrace-XXX.h $ok" |
| 200 |
} |
| 201 |
exec rm -f dtrace-XXX.h |
| 202 |
|
| 203 |
|
| 204 |
# ----------------------------------------------------------------- |
| 205 |
# test --no-pyparsing |
| 206 |
|
| 207 |
set ok 0 |
| 208 |
verbose -log "$dtrace -C --no-pyparsing -I$incpath -h -s $idpath -o dtrace-XXX.h" |
| 209 |
catch {exec $python $dtrace -C --no-pyparsing -I$incpath -h -s $idpath -o dtrace-XXX.h} |
| 210 |
spawn cat dtrace-XXX.h |
| 211 |
expect { |
| 212 |
-re {DTRACE_PROBE \(tstsyscall, test0\)} {incr ok; exp_continue} |
| 213 |
-re {short arg1, int arg2, int arg3, int arg4} {incr ok; exp_continue} |
| 214 |
-re {DTRACE_PROBE. \(tstsyscall, test., arg1, arg2, arg3, arg4, arg5\)} {incr ok} |
| 215 |
eof { } |
| 216 |
} |
| 217 |
catch {close}; catch {wait} |
| 218 |
if { $ok == 4} { |
| 219 |
pass "$test -C --no-pyparsing -Iincpath -h -o dtrace-XXX.h" |
| 220 |
} else { |
| 221 |
fail "$test -C --no-pyparsing -Iincpath -h -o dtrace-XXX.h $ok" |
| 222 |
} |
| 223 |
exec rm -f dtrace-XXX.h |
| 224 |
|
| 225 |
# ----------------------------------------------------------------- |
| 226 |
# test fallback to --no-pyparsing |
| 227 |
|
| 228 |
if {[catch {exec $python -c "import pyparsing"} res]} then { |
| 229 |
untested "$test parser check" |
| 230 |
} else { |
| 231 |
set ok 0 |
| 232 |
verbose -log "$dtrace -C -DDCL_AFTER_PROVIDER -h -s $pypath -o dtrace-XXX.h" |
| 233 |
spawn $python $dtrace -C -DDCL_AFTER_PROVIDER -h -s $pypath -o dtrace-XXX.h |
| 234 |
expect { |
| 235 |
-re {Warning.*syntax error} {incr ok; exp_continue} |
| 236 |
-re {Warning.*--no-pyparsing} {incr ok; exp_continue} |
| 237 |
eof { } |
| 238 |
} |
| 239 |
catch {close}; catch {wait} |
| 240 |
if {[file exists dtrace-XXX.h]} then { |
| 241 |
incr ok; |
| 242 |
} |
| 243 |
if { $ok == 3} { |
| 244 |
pass "$test parser check" |
| 245 |
} else { |
| 246 |
fail "$test parser check $ok" |
| 247 |
} |
| 248 |
exec rm -f dtrace-XXX.h |
| 249 |
} |
| 250 |
# ----------------------------------------------------------------- |
| 251 |
# test -G object file creation |
| 252 |
|
| 253 |
verbose -log "$dtrace -I$incpath -G -s $idpath" |
| 254 |
catch {exec $python $dtrace -G -s $dpath} |
| 255 |
if {[file exists dtrace-test.o]} then { |
| 256 |
pass "$test -Iincpath -G" |
| 257 |
} else { |
| 258 |
fail "$test -Iincpath -G" |
| 259 |
} |
| 260 |
exec rm -f test.o |
| 261 |
|
| 262 |
# ----------------------------------------------------------------- |
| 263 |
# test dtrace for pyparsing / --no-pyparsing compatibility |
| 264 |
|
| 265 |
set ok 0 |
| 266 |
set dfiles {dtrace} |
| 267 |
foreach i $dfiles { |
| 268 |
verbose -log "$dtrace $srcdir/$subdir/$i.d" |
| 269 |
catch {exec $python $dtrace -C -h -s $srcdir/$subdir/$i.d -o $i-1.h} |
| 270 |
catch {exec $python $dtrace -C -h --no-pyparsing -s $srcdir/$subdir/$i.d -o $i-2.h} |
| 271 |
spawn diff -wqs $i-1.h $i-2.h |
| 272 |
expect { |
| 273 |
-re {Files.*identical} {incr ok; exp_continue} |
| 274 |
eof { } |
| 275 |
} |
| 276 |
catch {close}; catch {wait} |
| 277 |
catch {exec $python $dtrace -C -G -s $srcdir/$subdir/$i.d -o $i-1.o} |
| 278 |
catch {exec $python $dtrace -C -G --no-pyparsing -s $srcdir/$subdir/$i.d -o $i-2.o} |
| 279 |
verbose -log "exec nm $i-1.o > $i-1.od" |
| 280 |
catch {exec nm $i-1.o > $i-1.od} |
| 281 |
catch {exec nm $i-2.o > $i-2.od} |
| 282 |
spawn diff -qs $i-1.od $i-2.od |
| 283 |
expect { |
| 284 |
-re {Files.*identical} {incr ok; exp_continue} |
| 285 |
eof { } |
| 286 |
} |
| 287 |
catch {close}; catch {wait} |
| 288 |
catch {exec /bin/rm $i-1.h $i-2.h $i-1.o $i-2.o} |
| 289 |
} |
| 290 |
if { $ok == 2} { |
| 291 |
pass "$test known uses" |
| 292 |
} else { |
| 293 |
fail "$test known uses ${ok}" |
| 294 |
} |
| 295 |
|
| 296 |
# ----------------------------------------------------------------- |
| 297 |
verbose -log "$dtrace -x IGNORED -h -s $dpath" |
| 298 |
catch {exec $python $dtrace -x IGNORED -h -s $dpath} |
| 299 |
if {[file exists dtrace-test.h]} then { |
| 300 |
pass "$test -x IGNORED" |
| 301 |
} else { |
| 302 |
fail "$test -x IGNORED" |
| 303 |
} |
| 304 |
exec rm -f test.o |
| 305 |
|
| 306 |
|
| 307 |
# ----------------------------------------------------------------- |
| 308 |
|
| 309 |
} |
| 310 |
# iteration over python* |