| 1 |
# Test the private keyword feature |
| 2 |
|
| 3 |
if {! [installtest_p]} then { return } |
| 4 |
|
| 5 |
set test "private" |
| 6 |
|
| 7 |
# Setup |
| 8 |
file mkdir "$test" |
| 9 |
file copy "$srcdir/$subdir/${test}.stp" "$test" |
| 10 |
cd "$test" |
| 11 |
|
| 12 |
foreach runtime [get_runtime_list] { |
| 13 |
if {$runtime == ""} {set runtime kernel} |
| 14 |
|
| 15 |
# Subtest |
| 16 |
set subtest "$test private-variable-basic" |
| 17 |
set __counter 0 |
| 18 |
eval spawn "stap --runtime=$runtime -I . -e {probe oneshot \{println(gtest1_getter(), \",\", gtest2_getter())\}}" |
| 19 |
expect { |
| 20 |
-timeout 160 |
| 21 |
-re {^3,7\r\n} { |
| 22 |
incr __counter |
| 23 |
exp_continue |
| 24 |
} |
| 25 |
timeout {fail "$subtest (timeout)"} |
| 26 |
} |
| 27 |
catch {close}; catch {wait} |
| 28 |
if {$__counter == 1} {pass $subtest} else {fail $subtest} |
| 29 |
|
| 30 |
# Subtest |
| 31 |
set subtest "$test private-variable-illegal-access" |
| 32 |
set __counter 0 |
| 33 |
eval spawn "stap --runtime=$runtime -I . -e {probe oneshot \{println(gtest1)\}}" |
| 34 |
expect { |
| 35 |
-timeout 160 |
| 36 |
-re {semantic error: unresolved type : identifier 'gtest1'} { |
| 37 |
incr __counter |
| 38 |
exp_continue |
| 39 |
} |
| 40 |
-re {^[^\r\n]+\r\n} { |
| 41 |
exp_continue |
| 42 |
} |
| 43 |
timeout {fail "$subtest (timeout)"} |
| 44 |
} |
| 45 |
catch {close}; catch {wait} |
| 46 |
if {$__counter == 1} {pass $subtest} else {fail $subtest} |
| 47 |
|
| 48 |
|
| 49 |
# Subtest |
| 50 |
set subtest "$test private-function-basic" |
| 51 |
set __counter 0 |
| 52 |
eval spawn "stap --runtime=$runtime -I . -e {probe oneshot \{println(getthree())\}}" |
| 53 |
expect { |
| 54 |
-timeout 160 |
| 55 |
-re {^3\r\n} { |
| 56 |
incr __counter |
| 57 |
exp_continue |
| 58 |
} |
| 59 |
timeout {fail "$subtest (timeout)"} |
| 60 |
} |
| 61 |
catch {close}; catch {wait} |
| 62 |
if {$__counter == 1} {pass $subtest} else {fail $subtest} |
| 63 |
|
| 64 |
# Subtest |
| 65 |
set subtest "$test private-function-illegal-access" |
| 66 |
set __counter 0 |
| 67 |
eval spawn "stap --runtime=$runtime -I . -e {probe oneshot \{println(three())\}}" |
| 68 |
expect { |
| 69 |
-timeout 160 |
| 70 |
-re {semantic error: unresolved function[^\r\n]+identifier 'three' at} { |
| 71 |
incr __counter |
| 72 |
exp_continue |
| 73 |
} |
| 74 |
-re {^[^\r\n]+\r\n} { |
| 75 |
exp_continue |
| 76 |
} |
| 77 |
timeout {fail "$subtest (timeout)"} |
| 78 |
} |
| 79 |
catch {close}; catch {wait} |
| 80 |
if {$__counter == 1} {pass $subtest} else {fail $subtest} |
| 81 |
|
| 82 |
# Subtest |
| 83 |
set subtest "$test global-variable-access" |
| 84 |
set __counter 0 |
| 85 |
eval spawn "stap --runtime=$runtime -I . -e {probe oneshot \{println(myglobal)\}}" |
| 86 |
expect { |
| 87 |
-timeout 160 |
| 88 |
-re {^11\r\n} { |
| 89 |
incr __counter |
| 90 |
exp_continue |
| 91 |
} |
| 92 |
timeout {fail "$subtest (timeout)"} |
| 93 |
} |
| 94 |
catch {close}; catch {wait} |
| 95 |
if {$__counter == 1} {pass $subtest} else {fail $subtest} |
| 96 |
|
| 97 |
# Subtest |
| 98 |
set subtest "$test global-variable-access-override" |
| 99 |
set __counter 0 |
| 100 |
eval spawn "stap --runtime=$runtime -G myglobal=12 -I . -e {probe oneshot \{println(myglobal)\}}" |
| 101 |
expect { |
| 102 |
-timeout 160 |
| 103 |
-re {^12\r\n} { |
| 104 |
incr __counter |
| 105 |
exp_continue |
| 106 |
} |
| 107 |
timeout {fail "$subtest (timeout)"} |
| 108 |
} |
| 109 |
catch {close}; catch {wait} |
| 110 |
if {$__counter == 1} {pass $subtest} else {fail $subtest} |
| 111 |
|
| 112 |
# Subtest |
| 113 |
# NB: Some kernels fail to load the module, but some just printk that |
| 114 |
# they're ignoring unknown parameters and continue anyway. stapdyn also |
| 115 |
# just warns and continues, so treat either hard error or unmodified pt |
| 116 |
# output as a test PASS. |
| 117 |
set subtest "$test private-variable-override-denied" |
| 118 |
set __counter 0 |
| 119 |
eval spawn "stap --runtime=$runtime -G pt=12 -e {private pt=13; probe oneshot \{println(pt)\}}" |
| 120 |
expect { |
| 121 |
-timeout 160 |
| 122 |
-re {^ERROR: Couldn't insert module[^\r\n]+Unknown symbol in module\r\n} { |
| 123 |
incr __counter |
| 124 |
exp_continue |
| 125 |
} |
| 126 |
-re {^stapdyn: WARNING: Ignoring unknown module option 'pt'\r\n} { |
| 127 |
exp_continue |
| 128 |
} |
| 129 |
-re {^13\r\n} { |
| 130 |
incr __counter |
| 131 |
exp_continue |
| 132 |
} |
| 133 |
-re {^[^\r\n]+\r\n} { |
| 134 |
exp_continue |
| 135 |
} |
| 136 |
timeout {fail "$subtest (timeout)"} |
| 137 |
} |
| 138 |
catch {close}; catch {wait} |
| 139 |
if {$__counter == 1} {pass $subtest} else {fail $subtest} |
| 140 |
|
| 141 |
# Subtest |
| 142 |
set subtest "$test private-function-in-user-script" |
| 143 |
set __counter 0 |
| 144 |
eval spawn "stap --runtime=$runtime -e {private function foo() { println(42) } probe oneshot \{ foo() \}}" |
| 145 |
expect { |
| 146 |
-timeout 160 |
| 147 |
-re {^42\r\n} { |
| 148 |
incr __counter |
| 149 |
exp_continue |
| 150 |
} |
| 151 |
timeout {fail "$subtest (timeout)"} |
| 152 |
} |
| 153 |
catch {close}; catch {wait} |
| 154 |
if {$__counter == 1} {pass $subtest} else {fail $subtest} |
| 155 |
|
| 156 |
# Subtest |
| 157 |
set subtest "$test multiple-private-global-var-decl" |
| 158 |
set __counter 0 |
| 159 |
eval spawn "stap --runtime=$runtime -e {private varA = 41, varB = 42 probe oneshot \{ println(varA, varB) \}}" |
| 160 |
expect { |
| 161 |
-timeout 160 |
| 162 |
-re {^4142\r\n} { |
| 163 |
incr __counter |
| 164 |
exp_continue |
| 165 |
} |
| 166 |
timeout {fail "$subtest (timeout)"} |
| 167 |
} |
| 168 |
catch {close}; catch {wait} |
| 169 |
if {$__counter == 1} {pass $subtest} else {fail $subtest} |
| 170 |
|
| 171 |
# Subtest |
| 172 |
if {$runtime != "dyninst"} { |
| 173 |
set subtest "$test PR13721-workaround-test" |
| 174 |
set __counter 0 |
| 175 |
eval spawn "stap --runtime=$runtime -e {private addr probe begin\{addr\[AF_INET()\]=\"addr\" exit()\}}" |
| 176 |
expect { |
| 177 |
-timeout 160 |
| 178 |
-re {^addr\[2\]="addr"\r\n} { |
| 179 |
incr __counter |
| 180 |
exp_continue |
| 181 |
} |
| 182 |
timeout {fail "$subtest (timeout)"} |
| 183 |
} |
| 184 |
catch {close}; catch {wait} |
| 185 |
if {$__counter == 1} {pass $subtest} else {fail $subtest} |
| 186 |
} |
| 187 |
|
| 188 |
# Subtest |
| 189 |
# PR20307 Make sure a private global variable (defined in a tapset) |
| 190 |
# is resolvable within a probe alias (from that same tapset). |
| 191 |
set subtest "$test PR20307-private-variable-in-tapset-probe-alias" |
| 192 |
set __counter 0 |
| 193 |
eval spawn "stap --runtime=$runtime -I . -e {probe foo \{println(f) exit()\}}" |
| 194 |
expect { |
| 195 |
-timeout 160 |
| 196 |
-re {^7\r\n} { |
| 197 |
incr __counter |
| 198 |
exp_continue |
| 199 |
} |
| 200 |
timeout {fail "$subtest (timeout)"} |
| 201 |
} |
| 202 |
catch {close}; catch {wait} |
| 203 |
if {$__counter == 1} {pass $subtest} else {fail $subtest} |
| 204 |
|
| 205 |
# Subtest |
| 206 |
# Analogy to the above, but for a private global function. |
| 207 |
set subtest "$test private-function-in-tapset-probe-alias" |
| 208 |
set __counter 0 |
| 209 |
eval spawn "stap --runtime=$runtime -I . -e {probe bar \{println(g) exit()\}}" |
| 210 |
expect { |
| 211 |
-timeout 160 |
| 212 |
-re {^3\r\n} { |
| 213 |
incr __counter |
| 214 |
exp_continue |
| 215 |
} |
| 216 |
timeout {fail "$subtest (timeout)"} |
| 217 |
} |
| 218 |
catch {close}; catch {wait} |
| 219 |
if {$__counter == 1} {pass $subtest} else {fail $subtest} |
| 220 |
} |
| 221 |
|
| 222 |
# Cleanup |
| 223 |
cd .. |
| 224 |
file delete -force "$test" |