| 1 |
set test "pr16719" |
| 2 |
|
| 3 |
if {![installtest_p]} { |
| 4 |
untested "$test" |
| 5 |
return |
| 6 |
} |
| 7 |
|
| 8 |
# This test makes sure that stap doesn't keep unnecessary files open during |
| 9 |
# pass-5 execution. For kernel probing, we check for vmlinux. For userspace |
| 10 |
# probing, we check for the binary or the corresponding debug file. |
| 11 |
|
| 12 |
# Run stap with probe and once we reach pass-5, check in /proc/$pid/[fd,maps] |
| 13 |
# for any opened/mapped file with the given pattern. |
| 14 |
proc run_stap { probe pattern } { |
| 15 |
global test subtest |
| 16 |
|
| 17 |
# Build the stap command |
| 18 |
set script "probe $probe { next }" |
| 19 |
|
| 20 |
# Spawn stap |
| 21 |
eval spawn stap -e {$script} --vp 00003 |
| 22 |
set stap_id $spawn_id |
| 23 |
set failed 1 |
| 24 |
expect { |
| 25 |
-timeout 30 |
| 26 |
-re {systemtap_module_init\(\)\ returned\ 0} { set failed 0 } |
| 27 |
timeout { kill -INT -[exp_pid] 2 } |
| 28 |
eof { kill -INT -[exp_pid] 2 } |
| 29 |
} |
| 30 |
|
| 31 |
# Check if stap was able to start |
| 32 |
if {!$failed} { |
| 33 |
pass "$test ($subtest - started stap)" |
| 34 |
} else { |
| 35 |
fail "$test ($subtest - can't start stap)" |
| 36 |
kill -INT -[exp_pid] 2 |
| 37 |
catch { close }; catch { wait } |
| 38 |
return |
| 39 |
} |
| 40 |
|
| 41 |
# Check /proc/$pid/fd |
| 42 |
foreach file [glob -nocomplain /proc/[exp_pid -i $stap_id]/fd/*] { |
| 43 |
# Make sure it's a symlink |
| 44 |
if {![catch {file readlink $file} link]} { |
| 45 |
# Check that it matches the pattern |
| 46 |
if {[string match $pattern $link]} { |
| 47 |
verbose -log "link $link matches pattern $pattern" |
| 48 |
set failed 1 |
| 49 |
} |
| 50 |
} |
| 51 |
} |
| 52 |
|
| 53 |
if {!$failed} { |
| 54 |
pass "$test ($subtest - fd clean)" |
| 55 |
} else { |
| 56 |
fail "$test ($subtest - found target file in fd)" |
| 57 |
kill -INT -[exp_pid] 2 |
| 58 |
catch { close -i $stap_id }; catch { wait -i $stap_id } |
| 59 |
return |
| 60 |
} |
| 61 |
|
| 62 |
# Check /proc/$pid/maps |
| 63 |
if {[catch {open /proc/[exp_pid -i $stap_id]/maps} chan]} { |
| 64 |
# Can't open maps file |
| 65 |
untested "$test ($subtest - can't open maps file)" |
| 66 |
kill -INT -[exp_pid] 2 |
| 67 |
catch { close -i $stap_id }; catch { wait -i $stap_id } |
| 68 |
return |
| 69 |
} |
| 70 |
|
| 71 |
# Read in maps line by line |
| 72 |
while {[gets $chan line] >= 0} { |
| 73 |
set fields [lreplace "$line" 0 -1] |
| 74 |
set file [lindex $fields 5] |
| 75 |
if {[expr [string length $file] && \ |
| 76 |
[file exists $file] && \ |
| 77 |
[string match $pattern $file]]} { |
| 78 |
verbose -log "file $file matches pattern $pattern" |
| 79 |
set failed 1 |
| 80 |
} |
| 81 |
|
| 82 |
} |
| 83 |
catch {close $chan} |
| 84 |
|
| 85 |
if {!$failed} { |
| 86 |
pass "$test ($subtest - maps clean)" |
| 87 |
} else { |
| 88 |
fail "$test ($subtest - found target file in maps)" |
| 89 |
kill -INT -[exp_pid] 2 |
| 90 |
catch { close -i $stap_id }; catch { wait -i $stap_id } |
| 91 |
return |
| 92 |
} |
| 93 |
|
| 94 |
pass "$test ($subtest)" |
| 95 |
kill -INT -[exp_pid] 2 |
| 96 |
catch { close -i $stap_id }; catch { wait -i $stap_id } |
| 97 |
} |
| 98 |
|
| 99 |
# Kernel check |
| 100 |
# Bad stap would have open /usr/lib/debug/lib/modules/`uname -r`/vmlinux |
| 101 |
set subtest "kernel" |
| 102 |
run_stap {vfs.read} {*/vmlinux} |
| 103 |
|
| 104 |
# Kernel tracepoint check |
| 105 |
# Bad stap would have open /usr/lib/debug/lib/modules/`uname -r`/vmlinux |
| 106 |
# (from getting s.kernel_source_tree in tracepoint_builder::init_dw().) |
| 107 |
set subtest "tracepoint" |
| 108 |
run_stap {kernel.trace("sched_switch")!,never} {*/vmlinux} |
| 109 |
|
| 110 |
# User check |
| 111 |
# Bad stap would have open /bin/ls or /usr/lib/debug/bin/ls.debug |
| 112 |
set subtest "user" |
| 113 |
if {! [uprobes_p]} { untested "$test ($subtest)"; return } |
| 114 |
run_stap {process("/bin/ls").function("main")} {*/bin/ls} |