File: basic

package info (click to toggle)
bpftrace 0.24.1-1.1
  • links: PTS, VCS
  • area: main
  • in suites: forky, sid
  • size: 10,496 kB
  • sloc: cpp: 60,982; ansic: 10,952; python: 953; yacc: 665; sh: 536; lex: 295; makefile: 22
file content (374 lines) | stat: -rw-r--r-- 9,856 bytes parent folder | download
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
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
NAME it shows version
RUN {{BPFTRACE}} --version
EXPECT_REGEX ^bpftrace v\d
TIMEOUT 1

NAME it shows usage with help flag
RUN {{BPFTRACE}} -h
EXPECT USAGE:
TIMEOUT 1

NAME it shows usage with bad flag
RUN {{BPFTRACE}} -idonotexist
EXPECT USAGE:
TIMEOUT 1
WILL_FAIL

NAME errors on non existent file
RUN {{BPFTRACE}} non_existent_file.bt
EXPECT ERROR: failed to open file 'non_existent_file.bt': No such file or directory
TIMEOUT 1
WILL_FAIL

NAME piped script
RUN {{BPFTRACE}} - < runtime/scripts/hello_world.bt
EXPECT hello world!
TIMEOUT 1

NAME it lists kprobes
RUN {{BPFTRACE}} -l | grep kprobes
EXPECT_REGEX kprobe:.*
TIMEOUT 1

NAME it lists kprobes with glob matching
RUN {{BPFTRACE}} -l 'kprobe*'
EXPECT_REGEX kprobe:.*
TIMEOUT 1

NAME it lists kprobes with verbose mode
RUN {{BPFTRACE}} -lv kprobe:*
EXPECT_REGEX [ ]+[a-zA-Z_\*\s]+
REQUIRES_FEATURE btf
TIMEOUT 1

NAME it lists tracepoints
RUN {{BPFTRACE}} -l | grep tracepoint
EXPECT_REGEX tracepoint:.*
TIMEOUT 1

NAME it lists software events
RUN {{BPFTRACE}} -l | grep software
EXPECT_REGEX software:.*
TIMEOUT 1

NAME it lists hardware events
RUN {{BPFTRACE}} -l | grep hardware
EXPECT_REGEX hardware:.*
TIMEOUT 1

NAME it lists fentry
RUN {{BPFTRACE}} -l | grep fentry
EXPECT_REGEX fentry:.*
REQUIRES_FEATURE btf
REQUIRES_FEATURE fentry
TIMEOUT 1

NAME it lists rawtracepoints
RUN {{BPFTRACE}} -l | grep rawtracepoint
EXPECT_REGEX rawtracepoint:.*
TIMEOUT 1

NAME it lists rawtracepoint params
RUN {{BPFTRACE}} -lv "rawtracepoint:*"
EXPECT_REGEX [ ]+[a-zA-Z_\*\s]+
REQUIRES_FEATURE btf
TIMEOUT 1

# The BTF FUNC_PROTOs for rawtracepoint params have an unnecessary initial
# void * and a retval that can't be used so make sure they are not
# included in the listing output
NAME it doesn't list the first rawtracepoint param or retval
RUN {{BPFTRACE}} -lv "rawtracepoint:consume_skb"
EXPECT_NONE void * __data
EXPECT_NONE int retval
REQUIRES_FEATURE btf
TIMEOUT 1

NAME it lists fentry params
RUN {{BPFTRACE}} -lv "fentry:*"
EXPECT_REGEX [ ]+[a-zA-Z_\*\s]+
REQUIRES_FEATURE btf
REQUIRES_FEATURE fentry
TIMEOUT 1

NAME it lists kprobes with regex filter
RUN {{BPFTRACE}} -l "kprobe:*"
EXPECT_REGEX kprobe:.*
TIMEOUT 1

NAME it lists kretprobes with regex filter
RUN {{BPFTRACE}} -l "kretprobe:*"
EXPECT_REGEX kretprobe:.*
TIMEOUT 1

NAME it lists uprobes with regex filter
RUN {{BPFTRACE}} -l "uprobe:./testprogs/syscall:*"
EXPECT_REGEX uprobe:.*
TIMEOUT 1

NAME it lists uretprobes with regex filter
RUN {{BPFTRACE}} -l "uretprobe:./testprogs/syscall:*"
EXPECT_REGEX uretprobe:.*
TIMEOUT 1

NAME it lists tracepoints with regex filter
RUN {{BPFTRACE}} -l "tracepoint:raw_syscalls:*"
EXPECT tracepoint:raw_syscalls:sys_exit
TIMEOUT 1

NAME it lists software events with regex filter
RUN {{BPFTRACE}} -l "software:*"
EXPECT software:cpu:
TIMEOUT 1

NAME it lists hardware events with regex filter
RUN {{BPFTRACE}} -l "hardware:*"
EXPECT hardware:cpu-cycles:
TIMEOUT 1

NAME it lists fentry events with regex filter
RUN {{BPFTRACE}} -l "fentry:*"
EXPECT_REGEX fentry:.*
REQUIRES_FEATURE btf
REQUIRES_FEATURE fentry
TIMEOUT 1

NAME it lists fexit events with regex filter
RUN {{BPFTRACE}} -l "fexit:*"
EXPECT_REGEX fexit:.*
REQUIRES_FEATURE btf
REQUIRES_FEATURE fentry
TIMEOUT 1

NAME it lists interval probes with regex filter
RUN {{BPFTRACE}} -l "interval:*"
EXPECT interval:hz:
EXPECT interval:us:
EXPECT interval:ms:
EXPECT interval:s:
TIMEOUT 1

NAME it lists profile probes with regex filter
RUN {{BPFTRACE}} -l "profile:*"
EXPECT profile:hz:
EXPECT profile:us:
EXPECT profile:ms:
EXPECT profile:s:
TIMEOUT 1

NAME listing with wildcarded probe type
RUN {{BPFTRACE}} -l "*ware:*"
EXPECT_REGEX hardware:.*
EXPECT_REGEX software:.*
TIMEOUT 1

NAME it lists rawtracepoint with regex filter
RUN {{BPFTRACE}} -l "rawtracepoint:*"
EXPECT_REGEX rawtracepoint:.*
TIMEOUT 1

NAME it lists iter with regex filter
RUN {{BPFTRACE}} -l "iter:*"
EXPECT_REGEX iter:.*
TIMEOUT 1

NAME it only lists probes in the program
RUN {{BPFTRACE}} -l -e 'fentry:vmlinux:vfs_read { exit(); }'
EXPECT fentry:vmlinux:vfs_read
EXPECT_NONE fentry:vmlinux:vfs_write

NAME it lists uprobes in the program
RUN {{BPFTRACE}} -l -e 'uretprobe:*:uprobeFunction* { exit(); }' -p {{BEFORE_PID}}
EXPECT_REGEX uretprobe:[\S]+uprobe_test:uprobeFunction1
BEFORE ./testprogs/uprobe_test

NAME it lists multiple probes in the program
RUN {{BPFTRACE}} -l -e 'hardware:cache-misses:10 { exit(); } tracepoint:xdp:mem_connect { exit(); }'
EXPECT hardware:cache-misses:
EXPECT tracepoint:xdp:mem_connect

NAME it lists struct definitions
RUN {{BPFTRACE}} -lv 'struct task_struct'
EXPECT struct task_struct {
TIMEOUT 2

NAME it lists probes in a given file
RUN {{BPFTRACE}} -l runtime/scripts/interval_order.bt
EXPECT interval:ms:
EXPECT interval:s:
EXPECT interval:us:

NAME warning on non existent file
RUN {{BPFTRACE}} -l non_existent_file.bt
EXPECT WARNING: It appears that 'non_existent_file.bt' is a filename but the file does not exist. Treating 'non_existent_file.bt' as a search pattern.
TIMEOUT 1
WILL_FAIL

NAME pid fails validation with leading non-number
RUN {{BPFTRACE}} -p a1111 file.bt
EXPECT ERROR: Failed to parse pid: invalid integer: a1111
TIMEOUT 1
WILL_FAIL

NAME pid fails validation with non-number in between
RUN {{BPFTRACE}} -p 111a1 file.bt
EXPECT ERROR: Failed to parse pid: invalid trailing bytes: 111a1
TIMEOUT 1
WILL_FAIL

NAME pid fails validation with non-numeric argument
RUN {{BPFTRACE}} -p not_a_pid file.bt
EXPECT ERROR: Failed to parse pid: invalid integer: not_a_pid
TIMEOUT 1
WILL_FAIL

NAME pid outside of valid pid range
RUN {{BPFTRACE}} -p 5000000 file.bt
EXPECT ERROR: Pid out of range: 5000000
TIMEOUT 1
WILL_FAIL

NAME libraries under /usr/include are in the search path
RUN {{BPFTRACE}} -e "$(echo "#include <sys/xattr.h>"; echo "begin { }")" 2>&1
EXPECT_NONE file not found
REQUIRES ls /usr/include/sys/xattr.h
TIMEOUT 1

NAME non existent library include fails
RUN {{BPFTRACE}} -e "$(echo "#include <lol/no.h>"; echo "begin { }")" 2>&1
EXPECT definitions.h:2:10: fatal error: 'lol/no.h' file not found
TIMEOUT 1
WILL_FAIL

NAME defines work
RUN {{BPFTRACE}} -e "$(echo '#define _UNDERSCORE 314'; echo 'begin { printf("%d\n", _UNDERSCORE); }')"
EXPECT 314
TIMEOUT 1

NAME clear map
PROG begin { @ = 1; @a[1] = 1; clear(@); clear(@a); printf("ok\n"); }
EXPECT ok
TIMEOUT 1

NAME clear count-map
PROG begin { @ = count(); @a[1] = count(); clear(@); clear(@a); }
EXPECT @: 0
TIMEOUT 1

NAME delete map
PROG begin { @ = 1; @a[1] = 1; @b[1, 2] = 2; if (delete(@)) { printf("ok1\n"); } delete(@a, 1); if (delete(@b, (1, 2))) { printf("ok2\n"); } if (!delete(@b, (5, 6))) { printf("ok3\n"); } }
EXPECT ok1
EXPECT ok2
EXPECT ok3
TIMEOUT 1

NAME delete count-map
PROG begin { @ = count(); @a[1] = count(); delete(@); delete(@a, 1); }
EXPECT @: 0
TIMEOUT 1

NAME delete deprecated
PROG begin { @a[1] = 1; @b[2, "hi"] = 2; delete(@a[1]); delete(@b[2, "hi"]); }
EXPECT_NONE @a[1]: 1
EXPECT_NONE @b[2, hi]: 2
TIMEOUT 1

NAME bad delete warning
PROG begin { @a[1] = 1; delete(@a, 2); }
EXPECT stdin:1:20-33: WARNING: Can't delete map element because it does not exist.
TIMEOUT 1

NAME bad delete no warning
PROG begin { @a[1] = 1; $x = delete(@a, 2); if (1 && !delete(@a, 3)) {} }
EXPECT_NONE stdin:1:20-33: WARNING: Can't delete map element because it does not exist.
TIMEOUT 1

NAME increment/decrement map
PROG begin { @x = 10; printf("%d", @x++); printf(" %d", ++@x); printf(" %d", @x--); printf(" %d\n", --@x); delete(@x); }
EXPECT 10 12 12 10
TIMEOUT 1

NAME parallel map access
RUN {{BPFTRACE}} runtime/scripts/parallel_map_access.bt --no-warnings
EXPECT SUCCESS
TIMEOUT 10

NAME increment/decrement variable
PROG begin { $x = 10; printf("%d", $x++); printf(" %d", ++$x); printf(" %d", $x--); printf(" %d\n", --$x);  }
EXPECT 10 12 12 10
TIMEOUT 1

NAME spawn child
RUN {{BPFTRACE}} -e 'i:ms:500 { printf("%d\n", cpid); }' -c './testprogs/syscall nanosleep 1e9'
EXPECT_REGEX [0-9]+
TIMEOUT 3

NAME info flag
RUN {{BPFTRACE}} --info
EXPECT_REGEX ringbuf: yes
TIMEOUT 1

NAME basic while loop
PROG begin { $a = 0; while ($a <= 100) { @=avg($a++) }  }
EXPECT @: 50
REQUIRES_FEATURE loop

NAME disable warnings
RUN {{BPFTRACE}} --no-warnings -e 'begin { @x = stats(10); print(@x, 2); clear(@x); }' 2>&1| grep -c -E "WARNING|invalid option"
EXPECT_REGEX ^0$
TIMEOUT 1
WILL_FAIL

NAME kaddr fails
PROG begin { print(kaddr("asdfzzzzzzz")) }
EXPECT stdin:1:9-35: ERROR: Failed to resolve kernel symbol: asdfzzzzzzz
       begin { print(kaddr("asdfzzzzzzz")) }
               ~~~~~~~~~~~~~~~~~~~~~~~~~~
TIMEOUT 1
WILL_FAIL

NAME variable strings are memset
PROG begin { $x = "xxxxx"; $x = "a"; @[$x] = 1; $y = "yyyyy"; $y = "a"; @[$y] = 1; printf("len: %d\n", len(@));  }
EXPECT len: 1
TIMEOUT 1

NAME map strings are memset
PROG begin { @x = "xxxxx"; @x = "a"; @[@x] = 1; @y = "yyyyy"; @y = "a"; @[@y] = 1; printf("len: %d\n", len(@));  }
EXPECT len: 1
TIMEOUT 1

NAME print_per_cpu_map_vals
REQUIRES_FEATURE lookup_percpu_elem
PROG begin { @a = avg(5); @c = count(); @s = sum(5); @mn = min(1); @mx = max(-1); print((@a, @c, @s, @mn, @mx));  }
EXPECT (5, 1, 5, 1, -1)
TIMEOUT 3

NAME print large int
PROG begin { $a = 10223372036854775807; print(($a));  }
EXPECT 10223372036854775807
TIMEOUT 1

NAME has_key exists
PROG begin { @a[1] = 0; if (has_key(@a, 1)) { printf("ok\n"); }  }
EXPECT ok

NAME has_key no_exists
PROG begin { @a[1] = 0; if (has_key(@a, 2)) { printf("ok\n"); }  }
EXPECT_NONE ok

NAME has_key complex tuple
PROG begin { @a[1, ("hello", (int8)5)] = 0; if (has_key(@a, (1, ("hello", 5)))) { printf("ok\n"); }  }
EXPECT ok

NAME has_key map value as key
PROG begin { @g = 2; @a[2] = 0; if (has_key(@a, @g)) { printf("ok\n"); }  }
EXPECT ok

NAME exit code
PROG begin { exit(69); }
RETURN_CODE 69
TIMEOUT 1

NAME block expression
PROG begin { let $a = { let $b = 1; $b }; print($a);  }
EXPECT 1