| 1 |
set test "Server Tests:" |
| 2 |
|
| 3 |
# The setup_server procedure always uses a "fresh" server log file, so |
| 4 |
# we don't need to create an empty log file that this test used to do. |
| 5 |
global server_logfile |
| 6 |
|
| 7 |
# Don't attempt these tests if the client/server are not available |
| 8 |
if {! [setup_server]} then { |
| 9 |
untested "Server Tests" |
| 10 |
return |
| 11 |
} |
| 12 |
|
| 13 |
proc cleanup {} { |
| 14 |
global tmpdir |
| 15 |
catch {exec rm -f foo} |
| 16 |
catch {exec rm -fr $tmpdir} |
| 17 |
shutdown_server |
| 18 |
} |
| 19 |
|
| 20 |
# Whether the server can communicate with the client is tested in client.exp. |
| 21 |
# Test that the the server can handle particular situations of interest. |
| 22 |
|
| 23 |
#------------------------------------------------------- |
| 24 |
# Building and running a simple module. |
| 25 |
set subtest "simple" |
| 26 |
set rc [stap_run_batch $srcdir/systemtap.server/hello.stp --use-server=$server_spec] |
| 27 |
if {$rc == 0} { pass "$test $subtest" } else { fail "$test $subtest" } |
| 28 |
|
| 29 |
#------------------------------------------------------- |
| 30 |
# Try a "stap -L" |
| 31 |
set subtest "listing" |
| 32 |
set rc [stap_run_batch "" -L "syscall.open" --use-server=$server_spec] |
| 33 |
if {$rc == 0} { pass "$test $subtest" } else { fail "$test $subtest" } |
| 34 |
|
| 35 |
#------------------------------------------------------- |
| 36 |
# Build and run a module using "-I" and "-e SCRIPT". |
| 37 |
set subtest "tapset" |
| 38 |
set rc [stap_run_batch "" -I $srcdir/systemtap.server/tapset -e "probe oneshot { foo() }" --use-server=$server_spec] |
| 39 |
if {$rc == 0} { pass "$test $subtest" } else { fail "$test $subtest" } |
| 40 |
|
| 41 |
#------------------------------------------------------- |
| 42 |
# Build a module using stdin. |
| 43 |
set subtest "stdin1" |
| 44 |
set cmd {echo "probe oneshot { exit() }" | stap -vp4 --use-server=$server_spec -} |
| 45 |
verbose -log "executing: $cmd" |
| 46 |
set rc 0 |
| 47 |
if {[catch {eval exec $cmd} err]} { |
| 48 |
if {[lindex $::errorCode 0] eq "CHILDSTATUS"} { |
| 49 |
set rc [lindex $::errorCode 2] |
| 50 |
} |
| 51 |
} |
| 52 |
verbose -log "$err" |
| 53 |
if {$rc} { |
| 54 |
fail "$test $subtest" |
| 55 |
} else { |
| 56 |
pass "$test $subtest" |
| 57 |
} |
| 58 |
|
| 59 |
#------------------------------------------------------- |
| 60 |
# Build another module using stdin. |
| 61 |
set subtest "stdin2" |
| 62 |
set cmd {stap -vp4 --use-server=$server_spec - < $srcdir/systemtap.server/hello.stp} |
| 63 |
verbose -log "executing: $cmd" |
| 64 |
set rc 0 |
| 65 |
if {[catch {eval exec $cmd} err]} { |
| 66 |
if {[lindex $::errorCode 0] eq "CHILDSTATUS"} { |
| 67 |
set rc [lindex $::errorCode 2] |
| 68 |
} |
| 69 |
} |
| 70 |
verbose -log "$err" |
| 71 |
if {$rc} { |
| 72 |
fail "$test $subtest" |
| 73 |
} else { |
| 74 |
pass "$test $subtest" |
| 75 |
} |
| 76 |
|
| 77 |
#------------------------------------------------------- |
| 78 |
# Building, returning and using the uprobes.ko module. |
| 79 |
set subtest "uprobes" |
| 80 |
if {! [uprobes_p]} then { |
| 81 |
untested "$test $subtest tests" |
| 82 |
} else { |
| 83 |
# First compile a test application. |
| 84 |
catch {exec gcc -g -o foo $srcdir/systemtap.base/jennie.c} err |
| 85 |
if {$err == "" && [file exists foo]} { |
| 86 |
pass "$test $subtest compile foo" |
| 87 |
} else { |
| 88 |
fail "$test $subtest compile foo" |
| 89 |
} |
| 90 |
set foo [exec pwd]/foo |
| 91 |
|
| 92 |
if {[inode_uprobes_p]} { |
| 93 |
# Make sure that uprobes.ko is not loaded |
| 94 |
catch {exec /sbin/rmmod uprobes} |
| 95 |
} |
| 96 |
|
| 97 |
# Now use the server to compile the uprobes.stp script |
| 98 |
set failed 1 |
| 99 |
set tmpdir "" |
| 100 |
set cmd [concat stap -p4 $srcdir/$subdir/uprobes.stp $use_server -k -c $foo] |
| 101 |
send_log "executing: $cmd\n" |
| 102 |
eval spawn $cmd |
| 103 |
expect { |
| 104 |
-timeout 150 |
| 105 |
-re {.*Keeping temporary directory \"(.*)\"\r\n} { |
| 106 |
set tmpdir "$expect_out(1,string)" |
| 107 |
set failed 0 |
| 108 |
} |
| 109 |
-re {^.*\r\n} { exp_continue } |
| 110 |
timeout { |
| 111 |
kill -INT -[exp_pid] 2 |
| 112 |
} |
| 113 |
} |
| 114 |
catch {close}; catch {wait} |
| 115 |
if {$failed == 0} { |
| 116 |
pass "$test $subtest -p4" |
| 117 |
} else { |
| 118 |
fail "$test $subtest -p4" |
| 119 |
} |
| 120 |
|
| 121 |
# Make sure that the uprobes.ko module was returned. |
| 122 |
if {"$tmpdir" == "" || [inode_uprobes_p]} { |
| 123 |
untested "$test $subtest uprobes returned" |
| 124 |
} else { |
| 125 |
if {[file exists $tmpdir/server/stap000000/uprobes/uprobes.ko]} { |
| 126 |
pass "$test $subtest uprobes returned" |
| 127 |
} else { |
| 128 |
fail "$test $subtest uprobes returned" |
| 129 |
} |
| 130 |
} |
| 131 |
|
| 132 |
if {! [installtest_p]} { |
| 133 |
untested "$test $subtest -p5"; |
| 134 |
cleanup |
| 135 |
return |
| 136 |
} |
| 137 |
|
| 138 |
# Now do it again, but follow through to phase 5 |
| 139 |
|
| 140 |
if {! [inode_uprobes_p]} { |
| 141 |
# Make sure that uprobes.ko is not loaded |
| 142 |
catch {exec /sbin/rmmod uprobes} |
| 143 |
} |
| 144 |
|
| 145 |
# Now use the server to compile and run the uprobes.stp script |
| 146 |
set failed 1 |
| 147 |
set cmd {stap $srcdir/$subdir/uprobes.stp $use_server -c "$foo 1 2 3 4"} |
| 148 |
send_log "executing: $cmd\n" |
| 149 |
eval spawn $cmd |
| 150 |
set ok 0 |
| 151 |
expect { |
| 152 |
-re {^process[^\r\n]+foo[^\r\n]+main[^\r\n]+arg[cv]=0x[0-9a-f]+\ +arg[cv]=0x[0-9a-f]+\r\n} { incr ok; exp_continue } |
| 153 |
-re {^process[^\r\n]+foo[^\r\n]+main[^\r\n]+return=0x0\r\n} { incr ok; exp_continue } |
| 154 |
-re {^[^\r\n]*\r\n} { exp_continue } |
| 155 |
-timeout 60 |
| 156 |
timeout { } |
| 157 |
eof { } |
| 158 |
} |
| 159 |
catch {close}; catch {wait} |
| 160 |
if {$ok == 10} { |
| 161 |
pass "$test $subtest -p5" |
| 162 |
} else { |
| 163 |
fail "$test $subtest -p5 ($ok)" |
| 164 |
} |
| 165 |
} |
| 166 |
|
| 167 |
#------------------------------------------------------- |
| 168 |
# avahi-daemon restart: PR 15872 |
| 169 |
# Make sure that the server can survive an avahi-daemon restart and still accept requests |
| 170 |
# via avahi. We can only test this is avahi is available. |
| 171 |
if {$avahi_ok_p != 1} { |
| 172 |
set dontTest 1 |
| 173 |
} else { |
| 174 |
set dontTest 0 |
| 175 |
} |
| 176 |
|
| 177 |
if {$dontTest == 1} { |
| 178 |
untested "$test $subtest" |
| 179 |
} else { |
| 180 |
set subtest "server reacts to avahi-daemon restart" |
| 181 |
# Notice we are using the tcl 'exec' command redirection of |
| 182 |
# '2>@1', which is equivalent to the shell's '2>&1'. |
| 183 |
if {[as_root "service avahi-daemon restart 2>@1"]} { |
| 184 |
# If the avahi daemon didn't restart properly, let's try to |
| 185 |
# fix it. If the daemon exits improperly, it can leave its pid |
| 186 |
# file behind which mean it can't be restarted. |
| 187 |
set pid_file "/run/avahi-daemon/pid" |
| 188 |
if {[file exists $pid_file]} { |
| 189 |
verbose -log "Removing the avahi-daemon pid file" |
| 190 |
as_root "rm -f $pid_file" |
| 191 |
|
| 192 |
# Try to restart the daemon again. |
| 193 |
if {[as_root "service avahi-daemon restart 2>@1"]} { |
| 194 |
# Could not restart the avahi daemon |
| 195 |
set dontTest 1 |
| 196 |
} |
| 197 |
} else { |
| 198 |
# Could not restart the avahi daemon |
| 199 |
set dontTest 1 |
| 200 |
} |
| 201 |
} |
| 202 |
|
| 203 |
if {$dontTest == 0} { |
| 204 |
# Give the server time to react |
| 205 |
catch {exec sleep 1} |
| 206 |
} |
| 207 |
} |
| 208 |
|
| 209 |
if {$dontTest == 1} { |
| 210 |
untested "$test $subtest" |
| 211 |
} else { |
| 212 |
set rc [catch {exec grep "Avahi client failure: Daemon connection failed" $server_logfile} result] |
| 213 |
if {$rc != 0} { |
| 214 |
fail "$test $subtest" |
| 215 |
} else { |
| 216 |
pass "$test $subtest" |
| 217 |
} |
| 218 |
} |
| 219 |
|
| 220 |
set subtest "server re-established avahi-daemon connection" |
| 221 |
if {$dontTest == 1} { |
| 222 |
untested "$test $subtest" |
| 223 |
} else { |
| 224 |
set rc [catch {exec grep -c {Adding Avahi service .Systemtap Compile Server.*} $server_logfile} result] |
| 225 |
# Make sure the target line was found more than once. |
| 226 |
if {$rc != 0 || $result < 2} { |
| 227 |
fail "$test $subtest" |
| 228 |
} else { |
| 229 |
pass "$test $subtest" |
| 230 |
} |
| 231 |
} |
| 232 |
|
| 233 |
set subtest "server still serves client requests" |
| 234 |
if {$dontTest == 1 || ! [installtest_p]} then { |
| 235 |
untested "$test $subtest" |
| 236 |
} else { |
| 237 |
# Contact the server directly, so that we know we're getting the one we want. |
| 238 |
set rc [stap_run_batch $srcdir/systemtap.server/hello.stp --use-server=$server_spec] |
| 239 |
if {$rc == 0} { pass "$test $subtest" } else { fail "$test $subtest" } |
| 240 |
} |
| 241 |
|
| 242 |
#------------------------------------------------------- |
| 243 |
cleanup |