]> sourceware.org Git - systemtap.git/blame - testsuite/lib/systemtap.exp
Add 'no-prompt' to the --trust-servers option to bypass prompting the user for confir...
[systemtap.git] / testsuite / lib / systemtap.exp
CommitLineData
814bc89d
FCE
1load_lib site.exp
2
3proc installtest_p {} {
4 global TOOL_OPTIONS
23361495 5 if {[info exists TOOL_OPTIONS] && [string match "*install*" $TOOL_OPTIONS]} {
814bc89d
FCE
6 return 1
7 } else { return 0 }
8}
9
23361495
DB
10
11proc use_server_p {} {
12 global TOOL_OPTIONS
13 if {[info exists TOOL_OPTIONS] && [string match "*server*" $TOOL_OPTIONS]} {
14 return 1
15 } else { return 0 }
16}
17
18
83ff01c2
FCE
19proc utrace_p {} {
20 set path "/proc/kallsyms"
21 if {! [catch {exec grep -q utrace_attach $path} dummy]} {
22 return 1
23 } else {
24 return 0
25 }
26}
f249edcd
JS
27
28
29proc uprobes_p {} {
30 global env
31 if {! [utrace_p]} {
32 return 0
33 }
34 set uprobes $env(SYSTEMTAP_RUNTIME)/uprobes
35 set res [catch "exec make -q -C $uprobes uprobes.ko" output]
36 if {$res != 0} {
0da3e7a0
DB
37 # build as user at $uprobes which will be the source
38 # tree for 'make check' and the install tree for
39 # 'make installcheck'.
40 verbose -log "exec make -C $uprobes"
41 set res [catch "exec make -C $uprobes" output]
42 verbose -log "OUT $output"
43 verbose -log "RC $res"
f249edcd
JS
44 }
45 if {$res == 0} { return 1 } else { return 0 }
46}
83ff01c2
FCE
47
48
814bc89d
FCE
49proc print_systemtap_version {} {
50 set version [exec /bin/uname -r]
51 set location "/boot/vmlinux-$version"
52 if {! [file exists $location]} {
53 # try the debuginfo location
54 set location "/usr/lib/debug/lib/modules/$version/vmlinux"
55 if {! [file exists $location]} { set location "" }
56 }
57
58 print "kernel location: $location"
59 print "kernel version: $version"
60
61 set location [exec /usr/bin/which stap]
62 regexp {version [^)]*} [exec stap -V 2>@ stdout] version
63
64 print "systemtap location: $location"
65 print "systemtap version: $version"
47561106
MW
66
67 set location [exec /usr/bin/which gcc]
68 set version [exec gcc --version | head -1]
69
70 print "gcc location: $location"
71 print "gcc version: $version"
814bc89d
FCE
72}
73
74
75proc setup_systemtap_environment {} {
7d54db1a 76 global srcdir env server_pid net_path
814bc89d
FCE
77
78 # need an absolute SRCDIR for the top-level src/ tree
5ba96b90 79 # XXX: or, we could change nearby uses of ${SRCDIR}/testsuite to ${SRCDIR}
814bc89d
FCE
80 if {[string index $srcdir 0] != "/"} then {
81 set env(SRCDIR) [exec pwd]/$srcdir/..
82 } else {
83 set env(SRCDIR) $srcdir/..
84 }
85
0fbf54d6
MW
86 # Use a local systemtap directory and cache. Add user name so
87 # make check and sudo make check don't clobber each other.
88 set env(SYSTEMTAP_DIR) [exec pwd]/.systemtap-[exec whoami]
5ba96b90 89
bf5e9f81 90 # Start a systemtap server, if requested.
7d54db1a
DB
91 set net_path ""
92 set server_pid 0
d5658775 93 if {[use_server_p]} then {
e26df1cb
DB
94 if {! [setup_server]} then {
95 return 0
96 }
d5658775
DB
97 }
98
5ba96b90
FCE
99 # PATH, SYSTEMTAP_TAPSET, SYSTEMTAP_RUNTIME, LD_LIBRARY_PATH are already set.
100 foreach var {PATH STAP SRCDIR SYSTEMTAP_TAPSET SYSTEMTAP_RUNTIME SYSTEMTAP_DIR LD_LIBRARY_PATH} {
101 if [info exists env($var)] {
102 verbose -log "env $var = $env($var)"
103 }
104 }
e26df1cb
DB
105
106 return 1
814bc89d
FCE
107}
108
72629a44
DB
109# Set up the environment so that tests will be performed using the systemtap
110# client and server.
111proc setup_server {} {
62f9d949 112 global srcdir env server_pid net_path installed_stap
72629a44 113
e26df1cb 114 # Make sure that the necessary resources are available to run the client/server.
0af51b59 115 if {[catch {exec /usr/bin/which avahi-publish-service} dummy]} then {
e26df1cb
DB
116 print "Unable to start a server: avahi-publish-service is not found in PATH"
117 return 0
118 }
119
72629a44
DB
120 # A place for some temporary files and scripts.
121 set net_path [exec pwd]/net
122 exec /bin/mkdir -p $net_path
123
124 # Server management scripts and data are installed if this is an
125 # install test, otherwise there is some setup to do.
edecda6c 126 # Make sure the server management scripts and tools are on the $PATH.
72629a44 127 if {! [installtest_p]} then {
72629a44 128 set env(PATH) "$srcdir/..:[exec pwd]/..:$env(PATH)"
67c7a9ac 129 set env(SYSTEMTAP_SERVER_SCRIPTS) "$srcdir/.."
edecda6c
DB
130 } else {
131 set env(PATH) "$env(PKGLIBDIR):$env(PATH)"
2bdb7139 132 set env(SYSTEMTAP_SERVER_SCRIPTS) $env(PKGLIBDIR)
72629a44
DB
133 }
134
d12a5be6
DB
135 # Erase the old server log file.
136 set logfile "[exec pwd]/server.log"
137 if {[file exists $logfile]} then {
138 exec rm -f $logfile;
139 }
140 # Create a new one and make sure it's world writable.
141 exec touch $logfile
142 exec chmod 666 $logfile
143
72629a44 144 # Try to find or start the server.
62f9d949 145 set server_pid [exec env STAP_PR11197_OVERRIDE=1 env SYSTEMTAP_STAP=[exec which stap] stap-start-server --log=$logfile]
3656df71
DB
146 if { "$server_pid" == "" } then {
147 print "Cannot start a systemtap server"
72629a44 148 set server_pid 0
e26df1cb 149 return 0
72629a44 150 } else {
543bcb4c 151 verbose -log "Started a systemtap server as PID==$server_pid"
72629a44
DB
152 }
153
67050ccc 154 # See what avahi finds
86e56b94 155 catch { exec avahi-browse _stap._tcp -t -r | grep -A4 {^=.*Systemtap.Compile} } looksee
67050ccc
FCE
156 verbose -log "avahi-browse found:\n$looksee"
157
bf5e9f81 158 # Make sure that stap can find the server.
eb3a0eee 159 set lines [exec stap --list-servers=online,compatible 2>@ stdout | wc -l]
bf5e9f81 160 if {$lines < 2} then {
543bcb4c 161 print "Unable to find a systemtap server -- check firewall settings for mDNS"
7ddf5daa
JS
162 shutdown_server
163 return 0
164 }
165
bf5e9f81 166 # Substitute a script on the PATH in place of stap which calls the real
eb3a0eee 167 # stap with the --use-server flag.
bf5e9f81
DB
168 set path "$net_path/stap"
169 set fp [open $path "w"]
170 puts $fp "#!/bin/sh"
eb3a0eee 171 puts $fp "[exec which stap] --use-server \"\$@\""
bf5e9f81
DB
172 close $fp
173 exec chmod +x $path
174
175 # Add the wrapper script to the PATH after creating it
62f9d949 176 set installed_stap [exec which stap]
72629a44 177 set env(PATH) "$net_path:$env(PATH)"
e26df1cb
DB
178
179 return 1
72629a44
DB
180}
181
182proc shutdown_server {} {
183 global server_pid net_path
184
185 if { $server_pid != 0 } then {
543bcb4c 186 verbose -log "Stopping the systemtap server with PID==$server_pid"
72629a44 187 exec stap-stop-server $server_pid
7d54db1a 188 set server_pid 0
72629a44
DB
189 }
190
191 # Remove the temporary stap script
9983df16
DS
192 if [file exists $net_path] {
193 exec /bin/rm -fr $net_path
194 }
b2ca731b
DB
195
196 foreach module [glob -nocomplain [exec pwd]/stap_*.ko] {
197 exec /bin/rm -f $module
198 }
72629a44
DB
199}
200
9446a6d6 201proc get_system_info {} {
47561106 202 global Host Snapshot Distro GCC_Version env
bf4ac953
RM
203
204 set Host [exec /bin/uname -a]
05de43cb
FCE
205 if [file exists ../SNAPSHOT] {
206 set Snapshot [exec /bin/cat ../SNAPSHOT]
207 } elseif [file exists $env(SRCDIR)/../SNAPSHOT] {
9446a6d6
WH
208 set Snapshot [exec /bin/cat $env(SRCDIR)/../SNAPSHOT]
209 } else {
48a00e93 210 regexp {version [^)]*} [exec stap -V 2>@ stdout] version
172d72b3 211 set Snapshot $version
48a00e93 212 }
9446a6d6 213 set Distro "Linux"
172d72b3
FCE
214 if [file exists /usr/bin/lsb_release] {
215 # this produces one line of this format:
216 # Distribution:\tSTRING
217 set Distro [lrange [exec /usr/bin/lsb_release -d] 1 end]
218 } else {
219 foreach f {/etc/fedora-release /etc/enterprise-release /etc/redhat-release /etc/suse-release /etc/debian_version} {
220 if [file exists $f] then {set Distro [exec /bin/cat $f]; break }
221 }
23d89280 222 }
47561106
MW
223 # Easily parsable version first major minor patch level
224 set n [exec echo "__GNUC__ __GNUC_MINOR__ __GNUC_PATCHLEVEL__" | cpp -P]
225 set n [string map {" " "."} $n]
8e02c673 226 set n [string map {"\n" ""} $n]
47561106
MW
227 # Plus full version between square brackets.
228 set full [exec gcc --version | head -1]
229 set GCC_Version "$n \[$full\]"
9446a6d6 230}
814bc89d 231
e26df1cb
DB
232if {! [setup_systemtap_environment]} then {
233 return 0
234}
235
814bc89d 236print_systemtap_version
9446a6d6 237get_system_info
814bc89d 238
03712201 239# PR11798: die if kernel-devel is not sufficient to build any modules
d153cbf8 240if {[catch {exec stap -p4 -e {probe begin {exit()}}} result]} {
03712201
FCE
241 puts "\n\n\n**** failed systemtap kernel-devel smoke test:\n"
242 puts $result
243# puts "****\n"
244# puts $options
245 puts "\n**** aborting testing.\n"
246 exit 1
247}
248
249# PR11798: die also if kernel-debuginfo is not available
250# NB: if one introduced a [kernel_debuginfo_p] proc like the
251# ones for uprobes/utrace above, and sprinkled it throughout,
252# then this wouldn't have to be a failing condition.
d153cbf8 253if {[catch {exec stap -p4 -e {probe syscall.open {println (argstr)}}} result]} {
03712201
FCE
254 puts "\n\n\n**** failed systemtap kernel-debuginfo smoke test:\n"
255 puts $result
256# puts "****\n"
257# puts $options
258 puts "\n**** aborting testing.\n"
259 exit 1
260}
261
262
814bc89d
FCE
263proc systemtap_init {args} {}
264proc systemtap_version {} {}
d5658775 265
7d54db1a 266proc cleanup {} {
d5658775 267 # Stop the stap server, if we started it.
7d54db1a 268 shutdown_server
d5658775 269}
814bc89d 270
0ecbca4c
FCE
271
272proc stap_run_batch {args} {
273 verbose -log "starting $args"
5ba96b90
FCE
274
275 # Many of our test cases use "#! stap ...". Since these lack
276 # /full/paths, they are not really executable. (We can't have
277 # /full/paths because the choice of systemtap interpreter is set
278 # at "make check" time.)
279
280 # So we cheat. If the file begins with "#! stap", we will spawn
281 # stap manually here (relying on $PATH). Otherwise, we presume
282 # the file properly executable.
283
284 set file [open [lindex $args 0] r]
285 set firstbits [gets $file]
286 close $file
287 if [regexp -line {\#! stap (.*)} $firstbits -> stap_args] {
288 verbose -log "spawn1 stap $stap_args [lindex $args 0]"
289 spawn stap $stap_args [lindex $args 0]
290 } else {
291 verbose -log "spawn2 $args"
292 spawn $args
293 }
294
bf4ac953 295 expect {
59cbc061 296 -timeout -1
bf4ac953 297 -re {[^\r]*\r} { verbose -log $expect_out(0,string); exp_continue }
bbbce017 298 eof { }
bbbce017 299 }
0ecbca4c
FCE
300 set results [wait]
301 verbose -log "wait results: $results"
c2d92a15
MH
302 if {[llength $results] >= 5} {
303 # Unexpected output. stap must have crashed
304 return -1
305 } else {
306 return [lindex $results 3]
307 }
68e7e59b 308}
14b31996
WC
309
310proc as_root { command } {
311
312 set effective_pid [exec /usr/bin/id -u]
313
314 if {$effective_pid != 0} {
315 set command "sudo $command"
316 }
674427d3 317 verbose -log "as_root $command"
14b31996 318 set res [catch {eval exec $command} value]
674427d3
FCE
319 verbose -log "OUT $value"
320 verbose -log "RC $res"
14b31996
WC
321 return $res
322 }
bf4ac953
RM
323
324proc sdt_includes {} {
6b51ee12 325 global srcdir env
bf4ac953
RM
326
327 # The wrapper sys/sdt.h for testing STAP_SDT_V[12] is here.
328 set dirs [list $srcdir]
329
330 if {[installtest_p]} {
331 # Use the installed <sys/sdt.h>.
332 lappend dirs $env(SYSTEMTAP_INCLUDES)
333 } else {
334 # Find <sys/sdt.h> in the source tree.
335 lappend dirs $srcdir/../includes
336 # The uninstalled, configured sdt-config.h has to be found here.
831b13d6 337 lappend dirs ../includes/sys
bf4ac953
RM
338 }
339
340 set flags ""
341 foreach dir $dirs {
831b13d6 342 set flags "$flags additional_flags=-isystem${dir}"
bf4ac953
RM
343 }
344
345 return $flags
346}
This page took 0.139524 seconds and 5 git commands to generate.