]> sourceware.org Git - systemtap.git/blame - testsuite/lib/systemtap.exp
rebased unwind_branch on top of current master
[systemtap.git] / testsuite / lib / systemtap.exp
CommitLineData
814bc89d
FCE
1load_lib site.exp
2
3proc installtest_p {} {
4 global TOOL_OPTIONS
5 if {[info exists TOOL_OPTIONS] && ($TOOL_OPTIONS == "install")} {
6 return 1
7 } else { return 0 }
8}
9
10proc print_systemtap_version {} {
11 set version [exec /bin/uname -r]
12 set location "/boot/vmlinux-$version"
13 if {! [file exists $location]} {
14 # try the debuginfo location
15 set location "/usr/lib/debug/lib/modules/$version/vmlinux"
16 if {! [file exists $location]} { set location "" }
17 }
18
19 print "kernel location: $location"
20 print "kernel version: $version"
21
22 set location [exec /usr/bin/which stap]
23 regexp {version [^)]*} [exec stap -V 2>@ stdout] version
24
25 print "systemtap location: $location"
26 print "systemtap version: $version"
27}
28
29
30proc setup_systemtap_environment {} {
31 global srcdir prefix env
32
33 # need an absolute SRCDIR for the top-level src/ tree
5ba96b90 34 # XXX: or, we could change nearby uses of ${SRCDIR}/testsuite to ${SRCDIR}
814bc89d
FCE
35 if {[string index $srcdir 0] != "/"} then {
36 set env(SRCDIR) [exec pwd]/$srcdir/..
37 } else {
38 set env(SRCDIR) $srcdir/..
39 }
40
68e7e59b
DS
41 # Use a local systemtap directory and cache
42 set env(SYSTEMTAP_DIR) [exec pwd]/.systemtap
5ba96b90
FCE
43
44 # PATH, SYSTEMTAP_TAPSET, SYSTEMTAP_RUNTIME, LD_LIBRARY_PATH are already set.
45 foreach var {PATH STAP SRCDIR SYSTEMTAP_TAPSET SYSTEMTAP_RUNTIME SYSTEMTAP_DIR LD_LIBRARY_PATH} {
46 if [info exists env($var)] {
47 verbose -log "env $var = $env($var)"
48 }
49 }
814bc89d
FCE
50}
51
9446a6d6
WH
52proc get_system_info {} {
53 global Host Snapshot Distro env
54
55 set Host [exec /bin/uname -a]
05de43cb
FCE
56 if [file exists ../SNAPSHOT] {
57 set Snapshot [exec /bin/cat ../SNAPSHOT]
58 } elseif [file exists $env(SRCDIR)/../SNAPSHOT] {
9446a6d6
WH
59 set Snapshot [exec /bin/cat $env(SRCDIR)/../SNAPSHOT]
60 } else {
aaf2af3e
FCE
61 set Snapshot "unknown"
62 }
9446a6d6
WH
63 set Distro "Linux"
64 if [file exists /etc/fedora-release] {set Distro [exec /bin/cat /etc/fedora-release]}
65 if [file exists /etc/redhat-release] {set Distro [exec /bin/cat /etc/redhat-release]}
66 if [file exists /etc/suse-release] {set Distro [exec /bin/cat /etc/suse-release]}
67 if [file exists /etc/debian_version] {set Distro [exec /bin/cat /etc/debian_version]}
68}
814bc89d
FCE
69
70setup_systemtap_environment
71print_systemtap_version
9446a6d6 72get_system_info
814bc89d 73
814bc89d
FCE
74proc systemtap_init {args} {}
75proc systemtap_version {} {}
76proc systemtap_exit {} {}
77
0ecbca4c
FCE
78
79proc stap_run_batch {args} {
80 verbose -log "starting $args"
5ba96b90
FCE
81
82 # Many of our test cases use "#! stap ...". Since these lack
83 # /full/paths, they are not really executable. (We can't have
84 # /full/paths because the choice of systemtap interpreter is set
85 # at "make check" time.)
86
87 # So we cheat. If the file begins with "#! stap", we will spawn
88 # stap manually here (relying on $PATH). Otherwise, we presume
89 # the file properly executable.
90
91 set file [open [lindex $args 0] r]
92 set firstbits [gets $file]
93 close $file
94 if [regexp -line {\#! stap (.*)} $firstbits -> stap_args] {
95 verbose -log "spawn1 stap $stap_args [lindex $args 0]"
96 spawn stap $stap_args [lindex $args 0]
97 } else {
98 verbose -log "spawn2 $args"
99 spawn $args
100 }
101
bbbce017 102 expect {
59cbc061 103 -timeout -1
bbbce017
FCE
104 -re {[^\r]*\r} { verbose -log $expect_out(0,string); exp_continue }
105 eof { }
bbbce017 106 }
0ecbca4c
FCE
107 set results [wait]
108 verbose -log "wait results: $results"
c2d92a15
MH
109 if {[llength $results] >= 5} {
110 # Unexpected output. stap must have crashed
111 return -1
112 } else {
113 return [lindex $results 3]
114 }
68e7e59b 115}
14b31996
WC
116
117proc as_root { command } {
118
119 set effective_pid [exec /usr/bin/id -u]
120
121 if {$effective_pid != 0} {
122 set command "sudo $command"
123 }
674427d3 124 verbose -log "as_root $command"
14b31996 125 set res [catch {eval exec $command} value]
674427d3
FCE
126 verbose -log "OUT $value"
127 verbose -log "RC $res"
14b31996
WC
128 return $res
129 }
This page took 0.056186 seconds and 5 git commands to generate.