Debian Codegraph @

doc/SystemTap_Beginners_Guide/testsuite/systemtap.base/array_slicing.exp

raw
1 set test_name array_slicing
2
3 # basic version of the script to be used. values need to be subbed in
4 # for each test
5 set script { \
6 global val; \
7 probe oneshot { \
8 val[$1, $2] = $3; val[$4,$5] = $6 \
9 print("systemtap starting probe\nsystemtap ending probe\n"); \
10 foreach (a=[b,c] in val[$7,$8]) {print(a)} \
11 print(" end") \
12 } \
13 }
14
15 # this is set up to act like a normal for loop
16 stap_run "$test_name foreach (... val\[*, *\])" "" "11 end" -e $script 2 {"hello"} 1 1 {"hey"} 1 * *
17
18 # testing foreach( a=[b,c] in val[int, int] )
19 stap_run "$test_name foreach (... val\[int, int\])" "" "2 end" -e $script 2 2 2 3 3 3 2 2
20
21 # testing foreach( a=[b,c] in val[string, string] ), where there is a match
22 stap_run "$test_name foreach (... val\[string, string\])" "" "1 end" -e $script {"asdf"} {"jkl"} 1 {"fdsa"} {"lkj"} 2 {"asdf"} {"jkl"}
23
24 # testing foreach( a=[b,c] in val[variable, *] ), where there is a match
25 stap_run "$test_name foreach (... val\[variable, *\])" "" "4 end" -e $script 9 1 4 8 9 9 {val[8,9]} *
26
27 # testing foreach( a=[b,c] in val[string, variable/string] ), where
28 # there is a match
29 stap_run "$test_name foreach (... val\[variable, string\])" "" "asdf end" -e $script {"hi"} {"hello"} {"asdf"} {"hi"} {"hi"} {"hello"} {"hi"} {val["hi","hi"]}
30
31 # testing foreach(... val[c,d]){c++;d++}
32 # in this case, expecting the c++ and d++ to not affect the c and d in
33 # the array slice
34 set script { \
35 global val, c=1, d=3; \
36 probe oneshot { \
37 print("systemtap starting probe\nsystemtap ending probe\n"); \
38 val[1,3]=5; val[2,3]=6; \
39 foreach ([a,b] in val[c,d]){print(val[a,b]);c++;d++} \
40 } \
41 }
42 stap_run "$test_name foreach (... val\[c,d\]) {c++;d++;}" "" "5" -e $script
43
44 # testing foreach(.. val[expression, *])
45 set script { \
46 global val, c=1, d=2; \
47 probe oneshot { \
48 print("systemtap starting probe\nsystemtap ending probe\n"); \
49 val[1,3]=5; val[2,3]=6; \
50 foreach ([a,b] in val[(c==d ? d : c), *]){print(val[a,b])} \
51 } \
52 }
53 stap_run "$test_name foreach (... val\[expression,*\])" "" "5" -e $script
54
55 # testing sorting in foreach loops
56 set script { \
57 global val, stats \
58 probe oneshot { \
59 val[1, 1] = 1; val[3, 3] = 5; val[1, 2] = 2; val[2, 2] = 4; val[2, 1] = 3; \
60 stats [1, 1] <<< 9; \
61 stats [2, 1] <<< 2; stats [2, 1] <<< 6; \
62 stats [23, 1] <<< 5; \
63 print("systemtap starting probe\nsystemtap ending probe\n"); \
64 foreach (c=[a, b] in val[*,*]+) print(c); \
65 foreach (c=[a, b] in val[*,*]-) print(c); \
66 foreach ([a,b] in stats[*,1] @sum-) print(@sum(stats[a,b])); \
67 } \
68 }
69 stap_run "$test_name foreach sorting" "" "1234554321985" -e $script
70
71
72 # testing array slicing with delete statements
73 set script { \
74 global val; \
75 probe oneshot { \
76 val[9, "hello"] = 9; val[300,"there"] = 6; \
77 print("systemtap starting probe\nsystemtap ending probe\n"); \
78 delete val[$1, $2]; \
79 print(val[9, "hello"]);print(val[300, "there"]); exit(); \
80 } \
81 }
82
83 # testing delete val[*,*]
84 stap_run "$test_name delete val\[*,*\]" "" "00" -e $script * *
85
86 # testing delete val[*, string]
87 stap_run "$test_name delete val\[*, string\]" "" "06" -e $script * {"hello"}
88
89 # testing delete val[int,*]
90 stap_run "$test_name delete val\[int, *\]" "" "90" -e $script 300 *
91
92 # testing delete val[expression,*]
93 stap_run "$test_name delete val\[epression, *\]" "" "90" -e $script {(val[9,"hello"] == val[300,"there"] ? 9 : 300)} *
94
95 # testing delete statements on pmaps
96 set script { \
97 global stats \
98 probe oneshot { \
99 stats [1, 1] <<< 9; stats [1, 1] <<< 2; stats [1, 1] <<< 6; \
100 stats [2, 2] <<< 1; \
101 delete stats [1, *]; \
102 print("systemtap starting probe\nsystemtap ending probe\n"); \
103 print (@count(stats[1, 1])); print(@count(stats[2,2])); \
104 } \
105 }
106 stap_run "$test_name delete pmaps" "" "01" -e $script
107
108 # testing membership, [*, *] in foo
109 set script { \
110 global val; \
111 probe oneshot { \
112 val[9,"hello"] = 9; val[300,"there"] = 6; \
113 print("systemtap starting probe\nsystemtap ending probe\n"); \
114 if ([$1, $2] in val) { print("in");} else {print ("not in");} \
115 } \
116 }
117 # testing membership [*,*]
118 stap_run "$test_name membership \[*,*\] in val" "" "in" -e $script * *
119
120 # testing membership [*, string]
121 stap_run "$test_name membership \[*, string\] in val" "" "in" -e $script * {"hello"}
122
123 # testing membership [int,*]
124 stap_run "$test_name membership \[int, *\] in val" "" "not in" -e $script 309 *
125
126 # testing membership [expression,*]
127 stap_run "$test_name membership \[expression,*\] in val" "" "not in" -e $script {(val[9, "hello"] == val[300, "there"]? 9 : 900)} *
128
129 # testing membership with pmaps
130 set script { global stats \
131 probe begin {stats[1,1] <<< 2; exit();} \
132 probe end { \
133 print("systemtap starting probe\nsystemtap ending probe\n"); \
134 print([1, *] in stats); print([2, *] in stats) \
135 } \
136 }
137 stap_run "$test_name membership pmaps" "" "10" -e $script
138
139 # testing membership with pmaps, to make sure it doesn't re-aggregate
140 # in the loop
141 set script { global stats \
142 probe begin {stats[1,1] <<< 2; exit();} \
143 probe end { \
144 print("systemtap starting probe\nsystemtap ending probe\n"); \
145 foreach([x,y] in stats) print([1,*] in stats) \
146 } \
147 }
148 stap_run "$test_name membership pmaps (2)" "" "1" -e $script