File: array_slicing.exp

package info (click to toggle)
systemtap 4.8-2
  • links: PTS, VCS
  • area: main
  • in suites: bookworm
  • size: 39,000 kB
  • sloc: cpp: 78,785; ansic: 62,419; xml: 49,443; exp: 42,735; sh: 11,254; python: 3,062; perl: 2,252; tcl: 1,305; makefile: 1,072; lisp: 105; awk: 101; asm: 91; java: 56; sed: 16
file content (148 lines) | stat: -rw-r--r-- 5,241 bytes parent folder | download | duplicates (7)
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
set test_name array_slicing

# basic version of the script to be used. values need to be subbed in
# for each test
set script { \
  global val; \
  probe oneshot { \
    val[$1, $2] = $3; val[$4,$5] = $6 \
    print("systemtap starting probe\nsystemtap ending probe\n"); \
    foreach (a=[b,c] in val[$7,$8]) {print(a)} \
    print(" end") \
  } \
}

# this is set up to act like a normal for loop
stap_run "$test_name foreach (... val\[*, *\])" "" "11 end" -e $script 2 {"hello"} 1 1 {"hey"} 1 * *

# testing foreach( a=[b,c] in val[int, int] )
stap_run "$test_name foreach (... val\[int, int\])" "" "2 end"  -e $script 2 2 2 3 3 3 2 2

# testing foreach( a=[b,c] in val[string, string] ), where there is a match
stap_run "$test_name foreach (... val\[string, string\])" "" "1 end"  -e $script {"asdf"} {"jkl"} 1 {"fdsa"} {"lkj"} 2 {"asdf"} {"jkl"}

# testing foreach( a=[b,c] in val[variable, *] ), where there is a match
stap_run "$test_name foreach (... val\[variable, *\])" "" "4 end"  -e $script 9 1 4 8 9 9 {val[8,9]} *

# testing foreach( a=[b,c] in val[string, variable/string] ), where
# there is a match
stap_run "$test_name foreach (... val\[variable, string\])" "" "asdf end"  -e $script {"hi"} {"hello"} {"asdf"} {"hi"} {"hi"} {"hello"} {"hi"} {val["hi","hi"]}

# testing foreach(... val[c,d]){c++;d++}
# in this case, expecting the c++ and d++ to not affect the c and d in
# the array slice
set script { \
  global val, c=1, d=3; \
  probe oneshot { \
    print("systemtap starting probe\nsystemtap ending probe\n"); \
    val[1,3]=5; val[2,3]=6; \
    foreach ([a,b] in val[c,d]){print(val[a,b]);c++;d++} \
  } \
}
stap_run "$test_name foreach (... val\[c,d\]) {c++;d++;}" "" "5" -e $script

# testing foreach(.. val[expression, *])
set script { \
  global val, c=1, d=2; \
  probe oneshot { \
    print("systemtap starting probe\nsystemtap ending probe\n"); \
    val[1,3]=5; val[2,3]=6; \
    foreach ([a,b] in val[(c==d ? d : c), *]){print(val[a,b])} \
  } \
}
stap_run "$test_name foreach (... val\[expression,*\])" "" "5" -e $script

# testing sorting in foreach loops
set script { \
  global val, stats \
  probe oneshot { \
    val[1, 1] = 1; val[3, 3] = 5; val[1, 2] = 2; val[2, 2] = 4; val[2, 1] = 3; \
    stats [1, 1] <<< 9; \
    stats [2, 1] <<< 2; stats [2, 1] <<< 6; \
    stats [23, 1] <<< 5; \
    print("systemtap starting probe\nsystemtap ending probe\n"); \
    foreach (c=[a, b] in val[*,*]+) print(c); \
    foreach (c=[a, b] in val[*,*]-) print(c); \
    foreach ([a,b] in stats[*,1] @sum-) print(@sum(stats[a,b])); \
  } \
}
stap_run "$test_name foreach sorting" "" "1234554321985" -e $script


# testing array slicing with delete statements
set script { \
  global val; \
  probe oneshot { \
    val[9, "hello"] = 9; val[300,"there"] = 6; \
    print("systemtap starting probe\nsystemtap ending probe\n"); \
    delete val[$1, $2]; \
    print(val[9, "hello"]);print(val[300, "there"]); exit(); \
  } \
}

# testing delete val[*,*]
stap_run "$test_name delete val\[*,*\]" "" "00" -e $script * *

# testing delete val[*, string]
stap_run "$test_name delete val\[*, string\]" "" "06" -e $script * {"hello"}

# testing delete val[int,*]
stap_run "$test_name delete val\[int, *\]" "" "90" -e $script 300 *

# testing delete val[expression,*]
stap_run "$test_name delete val\[epression, *\]" "" "90" -e $script {(val[9,"hello"] == val[300,"there"] ? 9 : 300)} *

# testing delete statements on pmaps
set script { \
  global stats \
  probe oneshot { \
    stats [1, 1] <<< 9; stats [1, 1] <<< 2; stats [1, 1] <<< 6; \
    stats [2, 2] <<< 1; \
    delete stats [1, *]; \
    print("systemtap starting probe\nsystemtap ending probe\n"); \
    print (@count(stats[1, 1])); print(@count(stats[2,2])); \
  } \
}
stap_run "$test_name delete pmaps" "" "01" -e $script

# testing membership, [*, *] in foo
set script { \
  global val; \
  probe oneshot { \
    val[9,"hello"] = 9; val[300,"there"] = 6; \
    print("systemtap starting probe\nsystemtap ending probe\n"); \
    if ([$1, $2] in val) { print("in");} else {print ("not in");} \
  } \
}
# testing membership [*,*]
stap_run "$test_name membership \[*,*\] in val" "" "in" -e $script * *

# testing membership [*, string]
stap_run "$test_name membership \[*, string\] in val" "" "in" -e $script * {"hello"}

# testing membership [int,*]
stap_run "$test_name membership \[int, *\] in val" "" "not in" -e $script 309 *

# testing membership [expression,*]
stap_run "$test_name membership \[expression,*\] in val" "" "not in" -e $script {(val[9, "hello"] == val[300, "there"]? 9 : 900)} *

# testing membership with pmaps
set script { global stats \
  probe begin {stats[1,1] <<< 2; exit();} \
  probe end { \
    print("systemtap starting probe\nsystemtap ending probe\n"); \
    print([1, *] in stats); print([2, *] in stats) \
  } \
}
stap_run "$test_name membership pmaps" "" "10" -e $script

# testing membership with pmaps, to make sure it doesn't re-aggregate
# in the loop
set script { global stats \
  probe begin {stats[1,1] <<< 2; exit();} \
  probe end { \
    print("systemtap starting probe\nsystemtap ending probe\n"); \
    foreach([x,y] in stats) print([1,*] in stats) \
  } \
}
stap_run "$test_name membership pmaps (2)" "" "1" -e $script