| 1 |
set test "affection" |
| 2 |
|
| 3 |
# Goal: Ensure that the mechanism for figuring out which probes can affect the |
| 4 |
# conditions of which other probes works properly. Also verifies that the probes |
| 5 |
# lock the proper variables. |
| 6 |
|
| 7 |
# Reads output from stap line by line and returns a list of pairs denoting |
| 8 |
# affection. E.g. "1 0 3 4" means that probe 1 affects probe 0 and probe 3 |
| 9 |
# affects probe 4. |
| 10 |
proc parse_affection {output} { |
| 11 |
set ret "" |
| 12 |
set re "probe (\[0-9\]+) can affect condition of probe (\[0-9\]+)" |
| 13 |
foreach line [split $output "\n"] { |
| 14 |
if {[regexp "^$re$" $line dummy pidx1 pidx2]} { |
| 15 |
set ret "$ret $pidx1 $pidx2" |
| 16 |
} |
| 17 |
} |
| 18 |
return [string trimleft $ret] |
| 19 |
} |
| 20 |
|
| 21 |
# Reads output from stap line by line and returns a list of pairs denoting |
| 22 |
# locking. E.g. "1 {var1[r] var2[w]} 2 {}" means that probe 1 read-locks var1 |
| 23 |
# and write-locks var2, while probe 2 locks nothing. |
| 24 |
proc parse_locking {output} { |
| 25 |
set ret "" |
| 26 |
set re "probe (\[0-9\]+) \\('\[^'\]+'\\) locks (.*)" |
| 27 |
foreach line [split $output "\n"] { |
| 28 |
if {[regexp "^$re$" $line dummy pidx vars] && \ |
| 29 |
![string equal $vars "nothing"]} { |
| 30 |
lappend ret $pidx $vars |
| 31 |
} |
| 32 |
} |
| 33 |
return $ret |
| 34 |
} |
| 35 |
|
| 36 |
# Runs a subtest |
| 37 |
# @subtest: the name of the subtest |
| 38 |
# @expected_affection: the affection expected given as a list of pairs |
| 39 |
# @expected_locking: the locking expected given as a list of pairs |
| 40 |
# @script: script to test |
| 41 |
proc run_subtest {subtest expected_affection expected_locking script} { |
| 42 |
global test |
| 43 |
|
| 44 |
verbose -log "running: stap -p3 -vvv -e $script" |
| 45 |
if {[catch {exec stap -p3 -vvv -e $script 2>@1} out]} { |
| 46 |
fail "$test - $subtest (stap -p3)" |
| 47 |
verbose -log "stap output: $out" |
| 48 |
return |
| 49 |
} |
| 50 |
|
| 51 |
set actual_affection [parse_affection $out] |
| 52 |
verbose -log "expected affection: $expected_affection" |
| 53 |
verbose -log "received affection: $actual_affection" |
| 54 |
if {$expected_affection != $actual_affection} { |
| 55 |
fail "$test - $subtest (affection)" |
| 56 |
return |
| 57 |
} |
| 58 |
|
| 59 |
set actual_locking [parse_locking $out] |
| 60 |
verbose -log "expected locking: $expected_locking" |
| 61 |
verbose -log "received locking: $actual_locking" |
| 62 |
if {$expected_locking != $actual_locking} { |
| 63 |
fail "$test - $subtest (locking)" |
| 64 |
return |
| 65 |
} |
| 66 |
|
| 67 |
pass "$test - $subtest" |
| 68 |
} |
| 69 |
|
| 70 |
### SUBTESTS ### |
| 71 |
|
| 72 |
# No affection |
| 73 |
# NB: the [list 0 {enabled[rw]}] means "probe 0 locks var enabled for rw" |
| 74 |
run_subtest "none" "" [list 0 {__global_enabled[rw]}] { |
| 75 |
global enabled = 0 // NB: we try not just 0/1 but other integral values too |
| 76 |
probe timer.s(5) { |
| 77 |
enabled = enabled ? 0 : 100; |
| 78 |
} |
| 79 |
} |
| 80 |
|
| 81 |
# NB: the [list 1 0] means "probe 1 affects condition of probe 0" |
| 82 |
run_subtest "simple1" [list 1 0] [list 0 {__global_enabled[r]} \ |
| 83 |
1 {__global_enabled[rw]}] { |
| 84 |
global enabled = 0 |
| 85 |
probe timer.s(1) if (enabled != 0) { |
| 86 |
next |
| 87 |
} |
| 88 |
probe timer.s(5) { |
| 89 |
enabled = !enabled |
| 90 |
} |
| 91 |
} |
| 92 |
|
| 93 |
run_subtest "simple2" [list 0 1] [list 0 {__global_enabled[rw]} \ |
| 94 |
1 {__global_enabled[r]}] { |
| 95 |
global enabled = 0 |
| 96 |
probe timer.s(5) { |
| 97 |
enabled = enabled ? 0 : -9999 |
| 98 |
} |
| 99 |
probe timer.s(1) if (enabled & 0xFFFF) { |
| 100 |
next |
| 101 |
} |
| 102 |
} |
| 103 |
|
| 104 |
run_subtest "self1" [list 0 0] [list 0 {__global_enabled[rw]}] { |
| 105 |
global enabled = 0 |
| 106 |
probe timer.s(1) if (enabled) { |
| 107 |
enabled = !enabled |
| 108 |
} |
| 109 |
} |
| 110 |
|
| 111 |
run_subtest "self2" [list 0 1 \ |
| 112 |
1 1] \ |
| 113 |
[list 0 {__global_enabled[rw]} \ |
| 114 |
1 {__global_enabled[rw]}] { |
| 115 |
global enabled = 0 |
| 116 |
probe timer.s(5) { |
| 117 |
enabled = !enabled |
| 118 |
} |
| 119 |
probe timer.s(1) if (enabled * 1 != 0) { |
| 120 |
enabled = !enabled |
| 121 |
} |
| 122 |
} |
| 123 |
|
| 124 |
run_subtest "many_vars_1" [list 1 0] [list 0 {__global_var1[r] __global_var2[r] __global_var3[r]} \ |
| 125 |
1 {__global_var1[rw] __global_var2[rw] __global_var3[rw]}] { |
| 126 |
global var1 = 0 |
| 127 |
global var2 = 1 |
| 128 |
global var3 |
| 129 |
probe timer.s(1) if (var1 && (var2 || var3)) { |
| 130 |
next |
| 131 |
} |
| 132 |
probe timer.s(5) { |
| 133 |
var1 = !var1 |
| 134 |
var2 = 0xFFFF // not just boolean range! |
| 135 |
var3 = var1 && var2 |
| 136 |
} |
| 137 |
} |
| 138 |
|
| 139 |
run_subtest "many_vars_2" [list 0 3 \ |
| 140 |
1 3 \ |
| 141 |
2 3] \ |
| 142 |
[list 0 {__global_var1[rw] __global_var2[r] __global_var3[r]} \ |
| 143 |
1 {__global_var1[r] __global_var2[rw] __global_var3[r]} \ |
| 144 |
2 {__global_var1[r] __global_var2[r] __global_var3[rw]} \ |
| 145 |
3 {__global_var1[r] __global_var2[r] __global_var3[r]}] { |
| 146 |
global var1 = 0 |
| 147 |
global var2 = -1 |
| 148 |
global var3 |
| 149 |
probe timer.s(5) { |
| 150 |
var1 = !var1 |
| 151 |
} |
| 152 |
probe timer.s(7) { |
| 153 |
var2 = ~var2 |
| 154 |
} |
| 155 |
probe timer.s(11) { |
| 156 |
var3 = 1-var3 |
| 157 |
} |
| 158 |
probe timer.s(1) if (var1 && (var2 || var3)) { |
| 159 |
next |
| 160 |
} |
| 161 |
} |
| 162 |
|
| 163 |
# NB: This is a tricky test for locking. Probe 1 needs to write-lock var1, but |
| 164 |
# also read-lock var2 which needs to be read during the re-evaluation of probe |
| 165 |
# 0's condition in the epilogue of probe 1. |
| 166 |
run_subtest "many_vars_3" [list 1 0 \ |
| 167 |
2 0] \ |
| 168 |
[list 0 {__global_var1[r] __global_var2[r]} \ |
| 169 |
1 {__global_var1[rw] __global_var2[r]} \ |
| 170 |
2 {__global_var1[r] __global_var2[rw]}] { |
| 171 |
global var1 = 29 |
| 172 |
global var2 = -0x123 |
| 173 |
probe timer.s(1) if (var1 || var2) { |
| 174 |
next |
| 175 |
} |
| 176 |
probe timer.s(2) { |
| 177 |
var1-- |
| 178 |
} |
| 179 |
probe timer.s(3) { |
| 180 |
var2-- |
| 181 |
} |
| 182 |
} |
| 183 |
|
| 184 |
run_subtest "many_probes_1" [list 2 0 \ |
| 185 |
2 1] \ |
| 186 |
[list 0 {__global_var1[r]} \ |
| 187 |
1 {__global_var1[r]} \ |
| 188 |
2 {__global_var1[rw]}] { |
| 189 |
global var1 = 0 |
| 190 |
probe timer.s(5) if (var1) { |
| 191 |
next |
| 192 |
} |
| 193 |
probe timer.s(7) if (!var1) { |
| 194 |
next |
| 195 |
} |
| 196 |
probe timer.s(11) { |
| 197 |
var1 = !var1 |
| 198 |
} |
| 199 |
} |
| 200 |
|
| 201 |
run_subtest "many_probes_2" [list 0 0 \ |
| 202 |
0 3 \ |
| 203 |
1 0 \ |
| 204 |
1 3 \ |
| 205 |
2 1 \ |
| 206 |
2 3] \ |
| 207 |
[list 0 {__global_var1[rw] __global_var2[r] __global_var3[r]} \ |
| 208 |
1 {__global_var1[r] __global_var2[rw] __global_var3[r]} \ |
| 209 |
2 {__global_var1[r] __global_var2[r] __global_var3[rw]} \ |
| 210 |
3 {__global_var1[r] __global_var2[r] __global_var3[r]}] { |
| 211 |
global var1 = 0 |
| 212 |
global var2 = 1 |
| 213 |
global var3 |
| 214 |
probe timer.s(5) if (var1 || var2) { |
| 215 |
var1 = !var1 |
| 216 |
} |
| 217 |
probe timer.s(7) if (var3) { |
| 218 |
var2 = !var2 |
| 219 |
} |
| 220 |
probe timer.s(11) { |
| 221 |
var3 = !var3 |
| 222 |
} |
| 223 |
probe timer.s(1) if (var1 && (var2 || var3)) { |
| 224 |
next |
| 225 |
} |
| 226 |
} |
| 227 |
|
| 228 |
run_subtest "functions_1" [list 1 0] \ |
| 229 |
[list 0 {__global_enabled[r]} \ |
| 230 |
1 {__global_enabled[rw]}] { |
| 231 |
global enabled = 0 |
| 232 |
probe timer.s(1) if (enabled) { |
| 233 |
next |
| 234 |
} |
| 235 |
function toggler() { |
| 236 |
enabled = !enabled |
| 237 |
} |
| 238 |
probe timer.s(5) { |
| 239 |
toggler() |
| 240 |
} |
| 241 |
} |
| 242 |
|
| 243 |
run_subtest "functions_2" [list 1 0] \ |
| 244 |
[list 0 {__global_enabled[r]} \ |
| 245 |
1 {__global_enabled[rw]}] { |
| 246 |
global enabled = 0 |
| 247 |
probe timer.s(1) if (enabled) { |
| 248 |
next |
| 249 |
} |
| 250 |
function realtoggler() { |
| 251 |
enabled = !enabled |
| 252 |
} |
| 253 |
function faketoggler() { |
| 254 |
realtoggler() |
| 255 |
} |
| 256 |
probe timer.s(5) { |
| 257 |
faketoggler() |
| 258 |
} |
| 259 |
} |
| 260 |
|
| 261 |
run_subtest "functions_3" [list 0 1 \ |
| 262 |
1 0 \ |
| 263 |
1 1 \ |
| 264 |
2 0 \ |
| 265 |
2 1] \ |
| 266 |
[list 0 {__global_var1[r] __global_var2[rw]} \ |
| 267 |
1 {__global_var1[rw] __global_var2[r]} \ |
| 268 |
2 {__global_var1[rw] __global_var2[rw]}] { |
| 269 |
global var1 = 0 |
| 270 |
global var2 = 1 |
| 271 |
function toggler1() { |
| 272 |
var2 = !var2 |
| 273 |
} |
| 274 |
probe timer.s(1) if (var1) { |
| 275 |
toggler1() |
| 276 |
} |
| 277 |
function toggler2() { |
| 278 |
var1 = !var1 |
| 279 |
} |
| 280 |
probe timer.s(2) if (!var2 || var1) { |
| 281 |
toggler2() |
| 282 |
} |
| 283 |
probe timer.s(5) { |
| 284 |
toggler1() |
| 285 |
toggler2() |
| 286 |
} |
| 287 |
} |