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
|
set test "modules_out_of_tree"
set am_root [expr 0 == [exec id -u]]
# In this test, we verify support for out-of-tree kernel kernel modules.
# We do this by first compiling our very own kernel module and then
# listing and probing it.
# Create the temporary directory.
#
# Notice we're using a '-' in the directory name. This will help test
# the problem noted in PR19265 comment #1, where systemtap can't find
# out-of-tree modules when the directory has a '-' in the name.
if {[catch {exec mktemp -d -t staptest-XXXXXX} tmpdir]} {
verbose -log "Failed to create temporary directory: $tmpdir"
return
}
# Save the current directory and switch to our temporary directory.
set curdir [pwd]
cd ${tmpdir}
proc test_cleanup {} {
global curdir
global verbose
global tmpdir
# Restore current directory
cd ${curdir}
# Cleanup (if we're not verbose)
if { $verbose == 0 } { catch { exec rm -f ${tmpdir} } }
}
proc write_to_file {file data} {
global test
set data [string map "TEST $test" $data]
set file [open "$file" w]
puts $file $data
close $file
}
write_to_file "stap_$test.c" {
#include <linux/kernel.h>
#include <linux/module.h>
#include <linux/init.h>
MODULE_LICENSE("GPL");
static int __init stap_TEST_init(void) {
return 0;
}
static void __exit stap_TEST_cleanup(void) {
return;
}
module_init(stap_TEST_init);
module_exit(stap_TEST_cleanup);
}
write_to_file "Makefile" {
obj-m := stap_TEST.o
default:
make -C /lib/modules/$(shell uname -r)/build M=$$PWD
}
set modname "stap_${test}.ko"
set modpath "${tmpdir}/${modname}"
set subtest "compilation"
if {[catch {exec make} err] || ![file exists ${modpath}]} {
fail "$test ($subtest)"
test_cleanup
return
}
pass "$test ($subtest)"
set pp "module(\"${modpath}\").function(\"stap_${test}_init\")"
set reg "^module\\\(\"${modpath}\"\\\)"
set reg "$reg\\\.function\\\(\"stap_${test}_init@${tmpdir}/stap_${test}.c:8\"\\\)$"
# Let's try listing a function first
set subtest "listing"
if {[catch {exec stap -l $pp} out] || ![regexp $reg $out]} {
fail "$test ($subtest)"
test_cleanup
return
}
pass "$test ($subtest)"
# OK now let's actually go for a run
set subtest "probing"
if {![installtest_p] || !$am_root || ![module_refresh_p]} {
untested "$test ($subtest)"
} else {
set script_template "probe %s { println(\"hit\") }"
set command "insmod ${modpath} && rmmod ${modpath}"
# Spawn stap
set failed 1
set script [format $script_template $pp]
spawn stap -e $script -c $command
expect {
-timeout 30
hit {
set failed 0
}
timeout {
verbose -log "$test timed out"
kill -INT -[exp_pid] 2
}
}
catch {close}; catch {wait}
if {$failed} {
fail "$test ($subtest)"
} else {
pass "$test ($subtest)"
}
}
# Now let's try the same thing, but with dwarfless-probing.
set subtest "dwarfless probing"
set pp "kprobe.module(\"${modpath}\").function(\"stap_${test}_init\")"
if {![installtest_p] || !$am_root || ![module_refresh_p]} {
untested "$test ($subtest)"
} else {
# Spawn stap
set failed 1
set script [format $script_template $pp]
spawn stap -e $script -c $command
expect {
-timeout 30
hit {
set failed 0
}
timeout {
verbose -log "$test timed out"
kill -INT -[exp_pid] 2
}
}
catch {close}; catch {wait}
if {$failed} {
fail "$test ($subtest)"
} else {
pass "$test ($subtest)"
}
}
# Now let's try with a relative path (instead of an absolute path).
set subtest "relative-path probing"
set pp "module(\"./${modname}\").function(\"stap_${test}_init\")"
if {![installtest_p] || !$am_root || ![module_refresh_p]} {
untested "$test ($subtest)"
} else {
# Spawn stap
set failed 1
set script [format $script_template $pp]
spawn stap -e $script -c $command
expect {
-timeout 30
hit {
set failed 0
}
timeout {
verbose -log "$test timed out"
kill -INT -[exp_pid] 2
}
}
catch {close}; catch {wait}
if {$failed} {
fail "$test ($subtest)"
} else {
pass "$test ($subtest)"
}
}
# Now let's try dwarfless probing with a relative path (instead of an
# absolute path).
set subtest "dwarfless relative-path probing"
set pp "kprobe.module(\"./${modname}\").function(\"stap_${test}_init\")"
if {![installtest_p] || !$am_root || ![module_refresh_p]} {
untested "$test ($subtest)"
} else {
# Spawn stap
set failed 1
set script [format $script_template $pp]
spawn stap -e $script -c $command
expect {
-timeout 30
hit {
set failed 0
}
timeout {
verbose -log "$test timed out"
kill -INT -[exp_pid] 2
}
}
catch {close}; catch {wait}
if {$failed} {
fail "$test ($subtest)"
} else {
pass "$test ($subtest)"
}
}
test_cleanup
|