Debian Codegraph @

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

raw
1 set test "statement"
2 if {![utrace_p]} { untested "$test"; return }
3
4 catch {exec gcc -g -o $test $srcdir/$subdir/$test.c} err
5 if {$err == "" && [file exists $test]} {
6 pass "$test compile"
7 } else {
8 fail "$test compile"
9 }
10
11 proc expect_probes { function linenos nprobes_expected } {
12 global test subtest
13
14 # if it's not relative, then tack on ':'
15 if {![string match +* $linenos]} {
16 set linenos ":$linenos"
17 }
18
19 set func_script "process(\"%s\").statement(\"%s@%s.c%s\")"
20 set script [format $func_script "./$test" $function "$test" $linenos]
21
22 spawn stap -l $script
23 set probes 0
24 expect {
25 -timeout 30
26 -re {^process\(\"[^\"]*\"\)\.statement\(\"[^\"]*\"\)\r\n} {
27 # " <-- for vim expect syntax highlighting
28 incr probes
29 exp_continue
30 }
31 timeout {
32 fail "$test ($subtest - timeout)"
33 kill -INT -[exp_pid] 2
34 }
35 eof { }
36 }
37 catch {close}; catch {wait}
38 if { $probes != $nprobes_expected } then {
39 fail "$test ($subtest - expected $nprobes_expected probes, got $probes)"
40 } else {
41 pass "$test ($subtest - matched $probes probes)"
42 }
43 }
44
45 proc expect_semerror { function linenos semerror_expected } {
46 global test subtest
47
48 # if it's not relative, then tack on ':'
49 if {![string match +* $linenos]} {
50 set linenos ":$linenos"
51 }
52
53 set func_script "process(\"%s\").statement(\"%s@%s.c%s\")"
54 set script [format $func_script "./$test" $function "$test" $linenos]
55
56 spawn stap -u -p2 -e "probe $script {}"
57 set found_err 0
58 expect {
59 -timeout 30
60 -re "semantic error: $semerror_expected" {
61 # " <-- for vim expect syntax highlighting
62 set found_err 1
63 }
64 timeout {
65 fail "$test ($subtest - timeout)"
66 kill -INT -[exp_pid] 2
67 }
68 eof { }
69 }
70 catch {close}; catch {wait}
71 if { $found_err } then {
72 pass "$test ($subtest - got semantic error)"
73 } else {
74 fail "$test ($subtest - no semantic error)"
75 }
76 }
77
78 # BZ6905 - simple wildcard probing of a specific function
79 set subtest bz6905
80 expect_probes foo * 4
81
82 # BZ10294 - func@file:N equivalent to func@file:N-N
83 set subtest bz10294
84 expect_probes foo 6-6 1
85 expect_probes nonexitent_func * 0
86
87 # BZ14774 - *@file:* matches all the lines
88 set subtest bz14774
89 expect_probes * * 9
90
91 # Now we do some consistent probe checking
92
93 # ABSOLUTE and ENUMERATED should give the same results for wild and single func
94 set subtest "ABSOLUTE - single func"
95 expect_probes foo 5 1
96 set subtest "ABSOLUTE - wild func"
97 expect_probes * 5 1
98 set subtest "ENUMERATED - single func 1"
99 expect_probes foo 5-7 3
100 set subtest "ENUMERATED - single func 2"
101 expect_probes foo 5,6,7 3
102 set subtest "ENUMERATED - single func 3"
103 expect_probes foo 5,6-7 3
104 set subtest "ENUMERATED - wild func 1"
105 expect_probes * 5-7 3
106 set subtest "ENUMERATED - wild func 2"
107 expect_probes * 5,6,7 3
108 set subtest "ENUMERATED - wild func 3"
109 expect_probes * 5-6,7 3
110
111 # But ABSOLUTE and ENUMERATED shouldn't give any results if the linenos fall
112 # outside the given func(s)
113 set subtest "ABSOLUTE - outside single func"
114 expect_probes bar 5 0
115 set subtest "ABSOLUTE - outside wild func"
116 expect_probes {[bm]*} 5 0
117 set subtest "ENUMERATED - outside single func 1"
118 expect_probes bar 5-7 0
119 set subtest "ENUMERATED - outside single func 2"
120 expect_probes bar 5-6,7 0
121 set subtest "ENUMERATED - outside wild func 1"
122 expect_probes {[bm]*} 5-7 0
123 set subtest "ENUMERATED - outside wild func 2"
124 expect_probes {[bm]*} 5,6-7 0
125
126 # RELATIVE and WILDCARD must be applied *per* function
127 set subtest "RELATIVE - single func"
128 expect_probes foo +2 1
129 # the test below only grabs foo and main because bar+2 is invalid, since bar is
130 # all on one line
131 set subtest "RELATIVE - wild func"
132 expect_probes * +2 2
133 set subtest "WILDCARD - single func"
134 expect_probes foo * 4
135 set subtest "WILDCARD - wild func"
136 expect_probes * * 9
137
138 # ABSOLUTE and RELATIVE on a line with no records gives an error with
139 # suggestions
140 set subtest "ABSOLUTE - error for no lines - single func"
141 expect_semerror main 15 "no line records .* \\(try"
142 set subtest "ABSOLUTE - error for no lines - wild func"
143 expect_semerror * 15 "no line records .* \\(try"
144 set subtest "RELATIVE - error for no lines"
145 expect_semerror main +4 "no line records .* \\(try"
146
147 # ENUMERATED on a function is bound by function linenos
148 set subtest "ENUMERATED - out-of-bounds lower 1"
149 expect_probes foo 0-5 2
150 set subtest "ENUMERATED - out-of-bounds lower 2"
151 expect_probes foo 0,1-4,5 2
152 set subtest "ENUMERATED - out-of-bounds lower 3"
153 expect_probes foo 0,1,2,3,4,5 2
154 set subtest "ENUMERATED - out-of-bounds upper 1"
155 expect_probes foo 5-999 3
156 set subtest "ENUMERATED - out-of-bounds upper 2"
157 expect_probes foo 5,6,7,998,999 3
158
159 # ENUMERATED overlapping two functions yields intersection of range and
160 # filtered functions
161 set subtest "ENUMERATED - single func overlapping 1"
162 expect_probes foo 5-13 3
163 set subtest "ENUMERATED - single func overlapping 2"
164 expect_probes foo 5,6-7,8,9,10-12,13 3
165 set subtest "ENUMERATED - single func overlapping 3"
166 expect_probes foo 5,6,7,8,9,10,11,12,13 3
167 set subtest "ENUMERATED - wildcard func overlapping 1"
168 expect_probes * 5-13 6
169 set subtest "ENUMERATED - wildcard func overlapping 2"
170 expect_probes * 5-6,7-13 6
171 set subtest "ENUMERATED - wildcard func overlapping 3"
172 expect_probes * 5,6,7,8,9,10,11,12,13 6
173
174 if {[file exists "$test"]} { file delete "$test" }