1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 182 183 184 185 186 187 188 189 190 191 192 193 194 195 196 197 198 199 200 201 202 203 204 205 206 207 208 209 210 211 212 213 214 215 216 217 218 219 220 221 222
|
set test "global_access"
if {![installtest_p]} {untested $test; return}
proc run_test {test script expected} {
set success 0
spawn stap -g -e $script
expect {
-timeout 30
-re "$expected" {pass $test}
default {fail $test}
}
catch { close }; catch { wait }
}
set script1 {
global var
function read:long() %{
/* pragma:read:var */
STAP_RETURN(STAP_GLOBAL_GET_var());
%}
probe begin {
var = 111
println(read())
exit()
}
}
set script2 {
global var[100]
function read:long() %{
/* pragma:read:var */
STAP_RETURN(STAP_GLOBAL_GET_var(1, 1));
%}
probe begin {
var[1,1] = 222
println(read())
exit()
}
}
set script3 {
global var
probe begin {
var = 333
println(%{ /* pragma:read:var */ STAP_GLOBAL_GET_var() %})
exit()
}
}
set script4 {
global var[100]
probe begin {
var[1,1] = 444
println(%{ /* pragma:read:var */ STAP_GLOBAL_GET_var(1,1) %})
exit()
}
}
set script5 {
global var = 0
function write() %{
/* pragma:write:var */
STAP_GLOBAL_SET_var(555);
%}
probe begin {
write()
println(var)
exit()
}
}
set script6 {
global var[100]
function write() %{
/* pragma:write:var */
STAP_GLOBAL_SET_var(1,1,666);
%}
probe begin {
var[1,1] = 0
write()
println(var[1,1])
exit()
}
}
set script7 {
global var = 0
probe begin {
%{ /* pragma:write:var */ STAP_GLOBAL_SET_var(777) %}
println(var)
exit()
}
}
set script8 {
global var[100]
probe begin {
var[1,1] = 0
%{ /* pragma:write:var */ STAP_GLOBAL_SET_var(1,1,888) %}
println(var[1,1])
exit()
}
}
set script9 {
global var = ""
function write() %{
/* pragma:write:var */
STAP_GLOBAL_SET_var("hello");
%}
probe begin {
write()
println(var)
exit()
}
}
set script10 {
global var[100]
function write() %{
/* pragma:write:var */
STAP_GLOBAL_SET_var(1,1,"hello");
%}
probe begin {
var[1,1] = ""
write()
println(var[1,1])
exit()
}
}
set script11 {
global var = ""
probe begin {
%{ /* pragma:write:var */ STAP_GLOBAL_SET_var("hello") %}
println(var)
exit()
}
}
set script12 {
global var[100]
probe begin {
var[1,1] = ""
%{ /* pragma:write:var */ STAP_GLOBAL_SET_var(1,1,"hello") %}
println(var[1,1])
exit()
}
}
set script13 {
global var = "hello"
global var2 = ""
function write() %{
/* pragma:read:var */
/* pragma:write:var2 */
STAP_GLOBAL_SET_var2(STAP_GLOBAL_GET_var());
%}
probe begin {
write()
println(var2)
exit()
}
}
set script14 {
global var[100]
global var2[100]
function write() %{
/* pragma:read:var */
/* pragma:write:var2 */
STAP_GLOBAL_SET_var2(1,1,STAP_GLOBAL_GET_var(1,1));
%}
probe begin {
var[1,1] = "hello"
var2[1,1] = ""
write()
println(var2[1,1])
exit()
}
}
run_test function_read_scalar_integer $script1 111
run_test function_read_map_integer $script2 222
run_test block_read_scalar_integer $script3 333
run_test block_read_map_integer $script4 444
run_test function_write_scalar_integer $script5 555
run_test function_write_map_integer $script6 666
run_test block_write_scalar_integer $script7 777
run_test block_write_map_integer $script8 888
# Note: strings are decayed to pointers when returned from embedded-C
# so we do not try to read them in embedded expressions
run_test function_write_scalar_string $script9 "hello"
run_test function_write_map_string $script10 "hello"
run_test block_write_scalar_string $script11 "hello"
run_test block_write_map_string $script12 "hello"
run_test function_read_scalar_string $script13 "hello"
run_test function_read_map_string $script14 "hello"
|