]>
Commit | Line | Data |
---|---|---|
814bc89d FCE |
1 | load_lib site.exp |
2 | ||
3 | proc 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 | |
11 | proc 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 | ||
814bc89d FCE |
19 | proc print_systemtap_version {} { |
20 | set version [exec /bin/uname -r] | |
21 | set location "/boot/vmlinux-$version" | |
22 | if {! [file exists $location]} { | |
23 | # try the debuginfo location | |
24 | set location "/usr/lib/debug/lib/modules/$version/vmlinux" | |
25 | if {! [file exists $location]} { set location "" } | |
26 | } | |
27 | ||
28 | print "kernel location: $location" | |
29 | print "kernel version: $version" | |
30 | ||
31 | set location [exec /usr/bin/which stap] | |
32 | regexp {version [^)]*} [exec stap -V 2>@ stdout] version | |
33 | ||
34 | print "systemtap location: $location" | |
35 | print "systemtap version: $version" | |
36 | } | |
37 | ||
38 | ||
39 | proc setup_systemtap_environment {} { | |
72629a44 | 40 | global srcdir env |
814bc89d FCE |
41 | |
42 | # need an absolute SRCDIR for the top-level src/ tree | |
5ba96b90 | 43 | # XXX: or, we could change nearby uses of ${SRCDIR}/testsuite to ${SRCDIR} |
814bc89d FCE |
44 | if {[string index $srcdir 0] != "/"} then { |
45 | set env(SRCDIR) [exec pwd]/$srcdir/.. | |
46 | } else { | |
47 | set env(SRCDIR) $srcdir/.. | |
48 | } | |
49 | ||
0fbf54d6 MW |
50 | # Use a local systemtap directory and cache. Add user name so |
51 | # make check and sudo make check don't clobber each other. | |
52 | set env(SYSTEMTAP_DIR) [exec pwd]/.systemtap-[exec whoami] | |
5ba96b90 | 53 | |
d5658775 DB |
54 | # Find or start a systemtap server, if requested. |
55 | if {[use_server_p]} then { | |
72629a44 | 56 | setup_server |
d5658775 DB |
57 | } |
58 | ||
5ba96b90 FCE |
59 | # PATH, SYSTEMTAP_TAPSET, SYSTEMTAP_RUNTIME, LD_LIBRARY_PATH are already set. |
60 | foreach var {PATH STAP SRCDIR SYSTEMTAP_TAPSET SYSTEMTAP_RUNTIME SYSTEMTAP_DIR LD_LIBRARY_PATH} { | |
61 | if [info exists env($var)] { | |
62 | verbose -log "env $var = $env($var)" | |
63 | } | |
64 | } | |
814bc89d FCE |
65 | } |
66 | ||
72629a44 DB |
67 | # Set up the environment so that tests will be performed using the systemtap |
68 | # client and server. | |
69 | proc setup_server {} { | |
70 | global srcdir env server_pid net_path | |
71 | ||
72 | print "Testing using a systemtap server" | |
73 | ||
74 | # A place for some temporary files and scripts. | |
75 | set net_path [exec pwd]/net | |
76 | exec /bin/mkdir -p $net_path | |
77 | ||
78 | # Server management scripts and data are installed if this is an | |
79 | # install test, otherwise there is some setup to do. | |
80 | if {! [installtest_p]} then { | |
81 | # Make sure the server management scripts and tools are on the $PATH. | |
82 | set env(PATH) "$srcdir/..:[exec pwd]/..:$env(PATH)" | |
83 | } | |
84 | ||
85 | # Try to find or start the server. | |
86 | set server_pid [exec stap-find-or-start-server] | |
87 | if { "$server_pid" == "-1" } then { | |
88 | print "Cannot find or start a systemtap server" | |
89 | set server_pid 0 | |
90 | # TODO: How do we abort here? | |
91 | } elseif { "$server_pid" == "0" } then { | |
92 | print "A compatible systemtap server is already available" | |
93 | } else { | |
94 | print "Started a systemtap server as PID==$server_pid" | |
95 | } | |
96 | ||
97 | # Make a copy of 'stap-client' as 'stap' and make sure it's at the | |
98 | # beginning of the $PATH. Do this after starting the server so that | |
99 | # The server does not call this instance of 'stap' | |
100 | if {[installtest_p]} then { | |
101 | exec /bin/cp -p [exec which stap-client] $net_path/stap | |
102 | } else { | |
103 | exec /bin/cp -p $srcdir/../stap-client $net_path/stap | |
104 | } | |
105 | set env(PATH) "$net_path:$env(PATH)" | |
106 | } | |
107 | ||
108 | proc shutdown_server {} { | |
109 | global server_pid net_path | |
110 | ||
111 | if { $server_pid != 0 } then { | |
112 | print "Stopping the systemtap server with PID==$server_pid" | |
113 | exec stap-stop-server $server_pid | |
114 | } | |
115 | ||
116 | # Remove the temporary stap script | |
117 | exec /bin/rm -fr $net_path | |
118 | } | |
119 | ||
9446a6d6 WH |
120 | proc get_system_info {} { |
121 | global Host Snapshot Distro env | |
122 | ||
123 | set Host [exec /bin/uname -a] | |
05de43cb FCE |
124 | if [file exists ../SNAPSHOT] { |
125 | set Snapshot [exec /bin/cat ../SNAPSHOT] | |
126 | } elseif [file exists $env(SRCDIR)/../SNAPSHOT] { | |
9446a6d6 WH |
127 | set Snapshot [exec /bin/cat $env(SRCDIR)/../SNAPSHOT] |
128 | } else { | |
48a00e93 FCE |
129 | regexp {version [^)]*} [exec stap -V 2>@ stdout] version |
130 | set Snapshot $version | |
131 | } | |
9446a6d6 WH |
132 | set Distro "Linux" |
133 | if [file exists /etc/fedora-release] {set Distro [exec /bin/cat /etc/fedora-release]} | |
134 | if [file exists /etc/redhat-release] {set Distro [exec /bin/cat /etc/redhat-release]} | |
135 | if [file exists /etc/suse-release] {set Distro [exec /bin/cat /etc/suse-release]} | |
136 | if [file exists /etc/debian_version] {set Distro [exec /bin/cat /etc/debian_version]} | |
137 | } | |
814bc89d FCE |
138 | |
139 | setup_systemtap_environment | |
140 | print_systemtap_version | |
9446a6d6 | 141 | get_system_info |
814bc89d | 142 | |
814bc89d FCE |
143 | proc systemtap_init {args} {} |
144 | proc systemtap_version {} {} | |
d5658775 DB |
145 | |
146 | proc systemtap_exit {} { | |
d5658775 DB |
147 | # Stop the stap server, if we started it. |
148 | if {[use_server_p]} then { | |
72629a44 | 149 | shutdown_server |
d5658775 DB |
150 | } |
151 | } | |
814bc89d | 152 | |
0ecbca4c FCE |
153 | |
154 | proc stap_run_batch {args} { | |
155 | verbose -log "starting $args" | |
5ba96b90 FCE |
156 | |
157 | # Many of our test cases use "#! stap ...". Since these lack | |
158 | # /full/paths, they are not really executable. (We can't have | |
159 | # /full/paths because the choice of systemtap interpreter is set | |
160 | # at "make check" time.) | |
161 | ||
162 | # So we cheat. If the file begins with "#! stap", we will spawn | |
163 | # stap manually here (relying on $PATH). Otherwise, we presume | |
164 | # the file properly executable. | |
165 | ||
166 | set file [open [lindex $args 0] r] | |
167 | set firstbits [gets $file] | |
168 | close $file | |
169 | if [regexp -line {\#! stap (.*)} $firstbits -> stap_args] { | |
170 | verbose -log "spawn1 stap $stap_args [lindex $args 0]" | |
171 | spawn stap $stap_args [lindex $args 0] | |
172 | } else { | |
173 | verbose -log "spawn2 $args" | |
174 | spawn $args | |
175 | } | |
176 | ||
bbbce017 | 177 | expect { |
59cbc061 | 178 | -timeout -1 |
bbbce017 FCE |
179 | -re {[^\r]*\r} { verbose -log $expect_out(0,string); exp_continue } |
180 | eof { } | |
bbbce017 | 181 | } |
0ecbca4c FCE |
182 | set results [wait] |
183 | verbose -log "wait results: $results" | |
c2d92a15 MH |
184 | if {[llength $results] >= 5} { |
185 | # Unexpected output. stap must have crashed | |
186 | return -1 | |
187 | } else { | |
188 | return [lindex $results 3] | |
189 | } | |
68e7e59b | 190 | } |
14b31996 WC |
191 | |
192 | proc as_root { command } { | |
193 | ||
194 | set effective_pid [exec /usr/bin/id -u] | |
195 | ||
196 | if {$effective_pid != 0} { | |
197 | set command "sudo $command" | |
198 | } | |
674427d3 | 199 | verbose -log "as_root $command" |
14b31996 | 200 | set res [catch {eval exec $command} value] |
674427d3 FCE |
201 | verbose -log "OUT $value" |
202 | verbose -log "RC $res" | |
14b31996 WC |
203 | return $res |
204 | } |