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 375 376 377 378 379 380 381 382 383 384 385 386 387 388 389 390 391 392 393 394 395 396 397 398 399 400 401 402 403 404 405 406 407 408 409 410 411 412 413 414 415 416 417 418 419 420 421 422 423 424 425 426 427 428 429 430 431 432 433 434 435 436 437 438 439 440 441 442 443 444 445 446 447 448 449 450 451 452 453 454 455 456 457 458 459 460 461 462 463 464 465 466 467 468 469 470 471 472 473 474 475 476 477 478 479 480 481 482 483 484 485 486 487 488 489 490 491 492 493 494 495 496 497 498 499 500 501 502 503 504 505 506 507 508 509 510 511 512 513 514 515 516 517 518 519 520 521 522 523 524 525 526 527 528 529 530 531 532 533 534 535 536 537 538 539 540 541 542 543 544 545 546 547 548 549 550 551 552 553 554 555 556 557 558 559 560 561 562 563 564 565 566 567 568 569 570 571 572 573 574 575 576 577 578 579 580 581 582 583 584 585 586 587 588 589 590 591 592 593 594 595 596 597 598 599 600 601 602 603 604 605 606 607 608 609 610 611 612 613 614 615 616 617 618 619 620 621 622 623 624 625 626 627 628 629 630 631 632 633 634 635 636 637 638 639 640 641 642 643 644 645 646 647 648 649 650 651 652 653 654 655 656 657 658 659 660 661
|
NAME fentry
PROG fentry:vfs_read { printf("SUCCESS %d\n", pid); exit(); }
EXPECT_REGEX SUCCESS [0-9][0-9]*
REQUIRES_FEATURE fentry
AFTER ./testprogs/syscall read
NAME fexit
PROG fexit:vfs_read { printf("SUCCESS %d\n", pid); exit(); }
EXPECT_REGEX SUCCESS [0-9][0-9]*
REQUIRES_FEATURE fentry
AFTER ./testprogs/syscall read
NAME fentry_wildcard
PROG fentry:vfs_re*ad { printf("SUCCESS %d\n", pid); exit(); }
EXPECT_REGEX SUCCESS [0-9][0-9]*
REQUIRES_FEATURE fentry
AFTER ./testprogs/syscall read
NAME fentry_module
PROG fentry:vmlinux:vfs_read { printf("SUCCESS %d\n", pid); exit(); }
EXPECT_REGEX SUCCESS [0-9][0-9]*
REQUIRES_FEATURE fentry
AFTER ./testprogs/syscall read
NAME fentry_module_wildcard
PROG fentry:vmlinu*:vfs_read { printf("SUCCESS %d\n", pid); exit(); }
EXPECT_REGEX SUCCESS [0-9][0-9]*
REQUIRES_FEATURE fentry
AFTER ./testprogs/syscall read
# https://github.com/bpftrace/bpftrace/issues/2447
NAME fentry_multiple_attach_point_multiple_functions
PROG begin { @a = 2; @b = 1; @c = 1 } i:s:1 { exit() } fentry:vfs_read, fentry:vfs_open /@a != 0/ { @a -= 1 } fentry:vfs_read /@b == 1/ { @b = 0 } fentry:vfs_open /@c == 1/ { @c = 0 }
EXPECT @a: 0
@b: 0
@c: 0
REQUIRES_FEATURE fentry
# Note: this calls both vfs_read and vfs_open
AFTER ./testprogs/syscall read
NAME fentry args
PROG fentry:vfs_read { printf("%d\n", args.count); exit(); }
EXPECT_REGEX [0-9][0-9]*
REQUIRES_FEATURE fentry
REQUIRES_FEATURE btf
AFTER ./testprogs/syscall read
# Checking backwards compatibility
NAME fentry args as a pointer
PROG fentry:vfs_read { printf("%d\n", args->count); exit(); }
EXPECT_REGEX [0-9][0-9]*
REQUIRES_FEATURE fentry
REQUIRES_FEATURE btf
AFTER ./testprogs/syscall read
NAME fentry func builtin
PROG fentry:vfs_read { printf("func: %s\n", func); exit(); }
EXPECT func: vfs_read
REQUIRES_FEATURE fentry
REQUIRES_FEATURE btf
REQUIRES_FEATURE get_func_ip
AFTER ./testprogs/syscall read
NAME fexit large args
PROG fexit:__sys_bpf { if (args.cmd == 1111 && args.size == 2222 && (int64)retval == -7) { printf("SUCCESS %d\n", pid); exit(); }}
EXPECT_REGEX SUCCESS [0-9][0-9]*
REQUIRES_FEATURE fentry
REQUIRES_FEATURE btf
AFTER ./testprogs/fentry_args 1111 2222
NAME fentry_missing_probes
PROG fentry:vfs_read,fentry:nonsense { exit(); }
EXPECT ERROR: No BTF found for nonsense.
WILL_FAIL
REQUIRES_FEATURE fentry
REQUIRES_FEATURE btf
NAME fentry_warn_missing_probes
PROG config = { missing_probes = "warn" } fentry:vfs_read,fentry:nonsense { exit(); }
EXPECT WARNING: No BTF found for nonsense.
REQUIRES_FEATURE fentry
REQUIRES_FEATURE btf
NAME fentry_ignore_missing_probes
PROG config = { missing_probes = "ignore" } fentry:vfs_read,fentry:nonsense { exit(); }
EXPECT_NONE WARNING: No BTF found for nonsense.
REQUIRES_FEATURE fentry
REQUIRES_FEATURE btf
# Sanity check for kfunc/kretfunc alias
NAME kfunc
PROG kfunc:vfs_read { printf("SUCCESS %d\n", pid); exit(); }
EXPECT_REGEX SUCCESS [0-9][0-9]*
REQUIRES_FEATURE fentry
AFTER ./testprogs/syscall read
NAME kretfunc
PROG kretfunc:vfs_read { printf("SUCCESS %d\n", pid); exit(); }
EXPECT_REGEX SUCCESS [0-9][0-9]*
REQUIRES_FEATURE fentry
AFTER ./testprogs/syscall read
NAME kprobe
PROG kprobe:vfs_read { printf("SUCCESS %d\n", pid); exit(); }
EXPECT_REGEX SUCCESS [0-9][0-9]*
AFTER ./testprogs/syscall read
NAME kprobe_short_name
PROG k:vfs_read { printf("SUCCESS %d\n", pid); exit(); }
EXPECT_REGEX SUCCESS [0-9][0-9]*
AFTER ./testprogs/syscall read
NAME kprobe_order
RUN {{BPFTRACE}} runtime/scripts/kprobe_order.bt
EXPECT_REGEX (first)+ second
AFTER /bin/bash -c "./testprogs/syscall nanosleep 1001";
NAME kprobe_offset
PROG kprobe:vfs_read+0 { printf("SUCCESS %d\n", pid); exit(); }
EXPECT_REGEX SUCCESS [0-9][0-9]*
AFTER ./testprogs/syscall read
NAME kprobe_wildcard
PROG kprobe:vmlinux:vfs_rea* { printf("SUCCESS %d\n", pid); exit(); }
EXPECT_REGEX SUCCESS [0-9][0-9]*
AFTER ./testprogs/syscall read
NAME kprobe_wildcard_multi
RUN {{BPFTRACE}} --unsafe -e 'kprobe:ksys_* { printf("progs: "); system("bpftool prog | grep kprobe | grep ksys_ | wc -l"); exit(); }'
EXPECT progs: 1
REQUIRES bpftool
REQUIRES_FEATURE kprobe_multi
NAME kprobe_wildcard_multi_probe_count
RUN {{BPFTRACE}} -e 'kprobe:vfs_* { exit(); }'
EXPECT_REGEX Attached [0-9][0-9]+ probes
REQUIRES_FEATURE kprobe_multi
NAME kprobe_module
PROG kprobe:vmlinux:vfs_read { printf("SUCCESS %d\n", pid); exit(); }
EXPECT_REGEX SUCCESS [0-9][0-9]*
AFTER ./testprogs/syscall read
NAME kprobe_module_wildcard
PROG kprobe:vmlinu*:vfs_read { printf("SUCCESS %d\n", pid); exit(); }
EXPECT_REGEX SUCCESS [0-9][0-9]*
AFTER ./testprogs/syscall read
NAME kprobe_module_missing
PROG kprobe:nonsense:vfs_read { printf("SUCCESS %d\n", pid); exit(); }
EXPECT ERROR: specified module nonsense in probe kprobe:nonsense:vfs_read is not loaded.
WILL_FAIL
NAME kprobe_wildcard_all_leading_underscore
PROG kprobe:_* { } interval:s:1{ printf("SUCCESS"); exit(); }
EXPECT_REGEX SUCCESS
ENV BPFTRACE_MAX_PROBES=20000
REQUIRES_FEATURE kprobe_multi
NAME kprobe_disallow_rcu_functions
PROG kprobe:rcu_* { printf("SUCCESS %d\n", pid); exit(); }
EXPECT_REGEX ERROR: Probe has no valid attach points.
WILL_FAIL
NAME kprobe_hide_ftrace_invalid_address
RUN {{BPFTRACE}} -l | grep -c __ftrace_invalid_address__ || true
EXPECT 0
NAME kprobe_func_missing
PROG kprobe:vmlinux:nonsense { printf("SUCCESS %d\n", pid); exit(); }
EXPECT ERROR: Unable to attach probe: kprobe:vmlinux:nonsense. If this is expected, set the 'missing_probes' config variable to 'warn'.
WILL_FAIL
NAME kprobe_multi_wildcard
RUN {{BPFTRACE}} --unsafe -e 'kprobe:ksys_* { printf("link: "); system("bpftool link | grep kprobe_multi | wc -l"); exit(); }'
EXPECT link: 1
REQUIRES bpftool
REQUIRES_FEATURE kprobe_multi
NAME uprobe_multi_wildcard
RUN {{BPFTRACE}} --unsafe -e 'uprobe:./testprogs/uprobe_test:uprobeFunction* { printf("link: "); system("bpftool link | grep -E \"uprobe_multi|type 12\" | wc -l"); exit(); }'
EXPECT link: 1
REQUIRES bpftool
REQUIRES_FEATURE uprobe_multi
AFTER ./testprogs/uprobe_test
NAME kprobe_wildcard probe builtin
RUN {{BPFTRACE}} --unsafe -e 'kprobe:ksys_* { @ = probe; printf("progs: "); system("bpftool prog | grep kprobe | grep ksys_ | wc -l"); exit(); }'
EXPECT_REGEX progs: [1-9][0-9]+
REQUIRES bpftool
NAME kprobe_multi_mixed_attachpoint
PROG kprobe:vfs_read,kprobe:nonsense* { printf("SUCCESS\n"); exit(); }
EXPECT SUCCESS
REQUIRES_FEATURE kprobe_multi
AFTER ./testprogs/syscall read
NAME kprobe_offset_module
RUN {{BPFTRACE}} -e 'kprobe:nf_tables_newtable+0x4 { printf("hit\n"); exit(); }'
AFTER nft add table bpftrace
EXPECT hit
ARCH x86_64
REQUIRES lsmod | grep '^nf_tables'
REQUIRES nft --help
# Proxy for testing if running virtualized. The offset is specific to our pre-built kernels.
REQUIRES test -d /mnt/vmtest
CLEANUP nft delete table bpftrace
# Local entry point to nf_tables_newtable is located at offset of 8 bytes in ppc64 and aarch64.
NAME kprobe_offset_module
RUN {{BPFTRACE}} -e 'kprobe:nf_tables_newtable+0x8 { printf("hit\n"); exit(); }'
AFTER nft add table bpftrace
EXPECT hit
ARCH ppc64|ppc64le|aarch64
REQUIRES lsmod | grep '^nf_tables'
REQUIRES nft --help
CLEANUP nft delete table bpftrace
NAME kprobe_offset_module_error
RUN {{BPFTRACE}} -e 'kprobe:nft_trans_alloc_gfp+0x1 { printf("hit\n"); exit(); }'
EXPECT ERROR: Possible attachment attempt in the middle of an instruction, try a different offset.
ARCH x86_64
REQUIRES lsmod | grep '^nf_tables'
WILL_FAIL
NAME kprobe_offset_module_error
RUN {{BPFTRACE}} -e 'kprobe:nft_trans_alloc_gfp+0x1 { printf("hit\n"); exit(); }'
EXPECT ERROR: Unable to attach probe: kprobe:nft_trans_alloc_gfp+0x1. If this is expected, set the 'missing_probes' config variable to 'warn'.
ARCH aarch64|ppc64le|ppc64
REQUIRES lsmod | grep '^nf_tables'
WILL_FAIL
NAME kretprobe
PROG kretprobe:vfs_read { printf("SUCCESS %d\n", pid); exit(); }
EXPECT_REGEX SUCCESS [0-9][0-9]*
AFTER ./testprogs/syscall read
NAME kretprobe_short_name
PROG kr:vfs_read { printf("SUCCESS %d\n", pid); exit(); }
EXPECT_REGEX SUCCESS [0-9][0-9]*
AFTER ./testprogs/syscall read
NAME kretprobe_order
RUN {{BPFTRACE}} runtime/scripts/kretprobe_order.bt
EXPECT_REGEX (first)+ second
AFTER /bin/bash -c "./testprogs/syscall nanosleep 1000";
NAME kretprobe_wildcard
PROG kretprobe:vmlinux:vfs_rea* { printf("SUCCESS %d\n", pid); exit(); }
EXPECT_REGEX SUCCESS [0-9][0-9]*
AFTER ./testprogs/syscall read
NAME kretprobe_wildcard_multi
RUN {{BPFTRACE}} --unsafe -e 'kretprobe:ksys_* { system("bpftool prog | grep kprobe | grep ksys_ | wc -l"); exit(); }'
EXPECT 1
REQUIRES bpftool
REQUIRES_FEATURE kprobe_multi
NAME kretprobe_wildcard_multi_link
RUN {{BPFTRACE}} --unsafe -e 'kretprobe:ksys_* { printf("link: "); system("bpftool link | grep kprobe_multi | wc -l"); exit(); }'
EXPECT link: 1
REQUIRES bpftool
REQUIRES_FEATURE kprobe_multi
NAME uretprobe_multi_wildcard
RUN {{BPFTRACE}} --unsafe -e 'uretprobe:./testprogs/uprobe_test:uprobeFunction* { printf("link: "); system("bpftool link | grep -E \"uprobe_multi|type 12\" | wc -l"); exit(); }'
EXPECT link: 1
REQUIRES bpftool
REQUIRES_FEATURE uprobe_multi
AFTER ./testprogs/uprobe_test
NAME uprobe_multi_wildcard_target_wildcard
RUN {{BPFTRACE}} --unsafe -e 'uretprobe:*:uprobeFunction* { printf("link: "); system("bpftool link | grep -E \"uprobe_multi|type 12\" | wc -l"); exit(); }' -p {{BEFORE_PID}}
EXPECT link: 1
REQUIRES bpftool
REQUIRES_FEATURE uprobe_multi
BEFORE ./testprogs/uprobe_test
# We need to check multiple things for session probes:
# - both entry and exit are hit
# - there is just one BPF program created
# - there is just one BPF link created
# This case combines all of the above by getting the number of progs from the
# entry probe and the number of links from the exit probe and checking for both.
# Note that getting the number of progs/links requires to call bpftool via
# system() call, hence we need --unsafe.
NAME kprobe_session
RUN {{BPFTRACE}} --unsafe -e 'kprobe:ksys_* { @entry = 1; printf("progs: "); system("bpftool prog | grep kprobe | grep ksys_ | wc -l"); } kretprobe:ksys_* { printf("links: "); system("bpftool link | grep kprobe_multi | wc -l"); if (@entry == 1) { exit() } }'
AFTER ./testprogs/syscall read
EXPECT progs: 1
EXPECT links: 1
REQUIRES bpftool
REQUIRES_FEATURE kprobe_session
NAME uprobe
PROG uprobe:/bin/bash:echo_builtin { printf("arg0: %d\n", arg0); exit();}
EXPECT_REGEX arg0: [0-9]*
AFTER /bin/bash -c "echo lala"
NAME uprobe_offset
PROG uprobe:/bin/bash:echo_builtin+0 { printf("arg0: %d\n", arg0); exit();}
EXPECT_REGEX arg0: [0-9]*
AFTER /bin/bash -c "echo lala"
NAME uprobe_offset
PROG uprobe:/bin/bash:"echo_builtin"+0 { printf("arg0: %d\n", arg0); exit();}
EXPECT_REGEX arg0: [0-9]*
AFTER /bin/bash -c "echo lala"
NAME uprobe_offset_fail_size
PROG uprobe:/bin/bash:echo_builtin+1000000 { printf("arg0: %d\n", arg0); exit();}
EXPECT_REGEX Offset outside the function bounds \('echo_builtin' size is*
WILL_FAIL
NAME uprobe_address_fail_resolve
PROG uprobe:/bin/bash:10 { printf("arg0: %d\n", arg0); exit();}
EXPECT ERROR: Could not resolve address: /bin/bash:0xa
WILL_FAIL
NAME uprobe_library
PROG uprobe:libc:fread { printf("size: %d\n", arg1); exit(); }
EXPECT_REGEX size: [0-9]+
AFTER ./testprogs/uprobe_library
REQUIRES_FEATURE libpath_resolv
NAME uprobe_order
RUN {{BPFTRACE}} runtime/scripts/uprobe_order.bt
EXPECT_REGEX (first)+ second
AFTER /bin/bash -c "echo lala";
NAME uprobe_zero_size
PROG uprobe:./testprogs/uprobe_test:_init { printf("arg0: %d\n", arg0); exit();}
EXPECT ERROR: Could not determine boundary for _init (symbol has size 0).
Use --unsafe to force attachment. WARNING: This option could lead to data corruption in the target process.
WILL_FAIL
NAME uprobe_zero_size_unsafe
RUN {{BPFTRACE}} --unsafe -e 'uprobe:./testprogs/uprobe_test:_init { printf("arg0: %d\n", arg0); exit();}'
EXPECT_REGEX arg0: [0-9]*
AFTER ./testprogs/uprobe_test
NAME uprobe_missing_probes
PROG uprobe:./testprogs/uprobe_test:uprobeFunction1,uprobe:./testprogs/uprobe_test:uprobeFunction3 { exit(); }
EXPECT ERROR: Could not resolve symbol: ./testprogs/uprobe_test:uprobeFunction3
AFTER ./testprogs/uprobe_test
WILL_FAIL
NAME uprobe_warn_missing_probes
PROG config = { missing_probes = "warn" } uprobe:./testprogs/uprobe_test:uprobeFunction1,uprobe:./testprogs/uprobe_test:uprobeFunction3 { exit(); }
EXPECT WARNING: Could not resolve symbol: ./testprogs/uprobe_test:uprobeFunction3
AFTER ./testprogs/uprobe_test
NAME uprobe_ignore_missing_probes
PROG config = { missing_probes = "ignore" } uprobe:./testprogs/uprobe_test:uprobeFunction1,uprobe:./testprogs/uprobe_test:uprobeFunction3 { exit(); }
EXPECT_NONE WARNING: Could not resolve symbol: ./testprogs/uprobe_test:uprobeFunction3, skipping probe.
AFTER ./testprogs/uprobe_test
NAME uretprobe
PROG uretprobe:/bin/bash:echo_builtin { printf("readline: %d\n", retval); exit();}
EXPECT_REGEX readline: [0-9]*
AFTER /bin/bash -c "echo lala"
NAME uretprobe_order
RUN {{BPFTRACE}} runtime/scripts/uretprobe_order.bt
EXPECT_REGEX (first)+ second
AFTER /bin/bash -c "echo lala";
NAME tracepoint
PROG tracepoint:syscalls:sys_exit_nanosleep { printf("SUCCESS %d\n", gid); exit(); }
EXPECT_REGEX SUCCESS [0-9][0-9]*
AFTER ./testprogs/syscall nanosleep 1e8
NAME tracepoint_short_name
PROG t:syscalls:sys_exit_nanosleep { printf("SUCCESS %d\n", gid); exit(); }
EXPECT_REGEX SUCCESS [0-9][0-9]*
AFTER ./testprogs/syscall nanosleep 1e8
NAME tracepoint_order
RUN {{BPFTRACE}} runtime/scripts/tracepoint_order.bt
EXPECT_REGEX (first)+ second
AFTER ./testprogs/syscall nanosleep 100000001;
NAME tracepoint_expansion
RUN {{BPFTRACE}} -e 'tracepoint:syscalls:sys_*_nanosleep { printf("hit\n"); }' -c "./testprogs/syscall nanosleep 1e8"
EXPECT hit
NAME tracepoint_missing
PROG t:syscalls:nonsense { print("hit"); exit(); }
EXPECT stdin:1:1-20: ERROR: Tracepoint not found: syscalls:nonsense
EXPECT HINT: If this is expected, set the 'missing_probes' config variable to 'warn' or 'ignore'.
WILL_FAIL
NAME tracepoint_multiattach_missing
PROG t:syscalls:sys_exit_nanosleep,t:syscalls:nonsense { print("hit"); exit(); }
EXPECT stdin:1:31-50: ERROR: Tracepoint not found: syscalls:nonsense
EXPECT HINT: If this is expected, set the 'missing_probes' config variable to 'warn' or 'ignore'.
WILL_FAIL
NAME tracepoint args
PROG tracepoint:syscalls:sys_enter_read { printf("%d\n", args.count); exit(); }
EXPECT_REGEX [0-9][0-9]*
AFTER ./testprogs/syscall read
# Checking backwards compatibility
NAME tracepoint args as pointer
PROG tracepoint:syscalls:sys_enter_read { printf("%d\n", args->count); exit(); }
EXPECT_REGEX [0-9][0-9]*
AFTER ./testprogs/syscall read
# Test that we get at least two characters out
NAME tracepoint_data_loc
PROG tracepoint:irq:irq_handler_entry { print(str(args.name)); exit(); }
EXPECT_REGEX ..+
NAME rawtracepoint
PROG rawtracepoint:sys_exit { printf("SUCCESS %d\n", gid); exit(); }
EXPECT_REGEX SUCCESS [0-9][0-9]*
AFTER ./testprogs/syscall nanosleep 1e8
NAME rawtracepoint_short_name
PROG rt:sys_exit { printf("SUCCESS %d\n", gid); exit(); }
EXPECT_REGEX SUCCESS [0-9][0-9]*
AFTER ./testprogs/syscall nanosleep 1e8
NAME rawtracepoint_missing
PROG rawtracepoint:nonsense { print("hit"); exit(); }
EXPECT_REGEX ERROR: Probe has no valid attach points.
REQUIRES_FEATURE btf
WILL_FAIL
NAME rawtracepoint_wildcard
PROG rawtracepoint:sys_* { printf("SUCCESS %d\n", gid); exit(); }
EXPECT_REGEX SUCCESS [0-9][0-9]*
AFTER ./testprogs/syscall nanosleep
NAME rawtracepoint_module_wildcard
PROG rawtracepoint:vmlinu*:sys_exit { printf("SUCCESS %d\n", gid); exit(); }
EXPECT_REGEX SUCCESS [0-9][0-9]*
AFTER ./testprogs/syscall nanosleep 1e8
NAME rawtracepoint_module_missing
PROG rawtracepoint:nonsense:sys_exit { printf("SUCCESS %d\n", gid); exit(); }
EXPECT ERROR: No BTF found for nonsense:sys_exit.
REQUIRES_FEATURE btf
WILL_FAIL
# Test that we get at least two characters out
NAME rawtracepoint args
PROG rawtracepoint:irq_handler_entry { print(str(((struct irqaction*)args.action)->name)); exit(); }
EXPECT_REGEX ..+
NAME profile
PROG profile:hz:599 { print("hit"); exit(); }
EXPECT hit
NAME profile_short_name
PROG p:hz:599 { print("hit"); exit(); }
EXPECT hit
NAME profile_probe_builtin
PROG profile:hz:599 { print(probe); exit();}
EXPECT profile:hz:599
NAME interval
PROG interval:ms:1 { print("hit"); exit(); }
EXPECT hit
NAME interval_short_name
PROG i:ms:1{ print("hit"); exit();}
EXPECT hit
NAME interval_probe_builtin
PROG interval:ms:1 { print(probe); exit();}
EXPECT interval:ms:1
NAME software
PROG software:cpu-clock:100000 { print("hit"); exit();}
EXPECT hit
NAME software_probe_builtin
PROG software:cpu-clock:100000 { print(probe); exit();}
EXPECT software:cpu-clock:100000
NAME software_alias_probe_builtin
PROG software:cpu:100000 { print(probe); exit();}
EXPECT software:cpu:100000
NAME hardware
REQUIRES ls /sys/devices/cpu/events/cache-misses
PROG hardware:cache-misses:10 { print("hit"); exit(); }
EXPECT hit
NAME hardware_probe_builtin
REQUIRES ls /sys/devices/cpu/events/cache-misses
PROG hardware:cache-misses:10 { print(probe); exit();}
EXPECT hardware:cache-misses:10
NAME probe_builtin_string_compare
PROG uprobe:testprogs/uprobe_test:uprobeFunction* { if (strcontains(probe, "uprobeFunction2")) { print(probe); exit(); } }
AFTER ./testprogs/uprobe_test
EXPECT uprobe:testprogs/uprobe_test:uprobeFunction2
NAME probe_builtin_scratch_buf
PROG config = { on_stack_limit = 0 } software:cpu:100000 { print(probe); exit(); }
EXPECT software:cpu:100000
NAME begin
PROG begin { printf("Hello\n"); }
EXPECT Hello
TIMEOUT 2
NAME end_processing_after_exit
PROG interval:s:1 { exit(); } end { printf("end"); }
EXPECT end
TIMEOUT 2
NAME begin,end
PROG begin,end { printf("Hello\n"); exit(); }
EXPECT Hello
Hello
TIMEOUT 2
NAME bench
RUN {{BPFTRACE}} --test-mode bench -e 'begin { print("begin\n"); } bench:a { @ = count(); } end { print(@); clear(@); }'
EXPECT_REGEX begin\n
@: 1000000\n\n
\+-----------\+--------------\+
\| BENCHMARK \| AVERAGE TIME \|
\+-----------\+--------------\+
\| a \| \d+ns[ ]+\|
\+-----------\+--------------\+
TIMEOUT 2
NAME bench multiple
RUN {{BPFTRACE}} --test-mode bench -e 'begin { printf("begin\n"); } bench:a { @a++; } bench:b { if (@b == 0) { print(@a); } @b++; } bench:c { if(@c == 0) { print(@b); } @c++; } end { print(@c); clear(@a); clear(@b); clear(@c); }'
EXPECT_REGEX begin
@a: 1000000
@b: 1000000
@c: 1000000\n\n
\+-----------\+--------------\+
\| BENCHMARK \| AVERAGE TIME \|
\+-----------\+--------------\+
\| a \| \d+ns[ ]+\|
\| b \| \d+ns[ ]+\|
\| c \| \d+ns[ ]+\|
\+-----------\+--------------\+
TIMEOUT 5
# The "probe" builtin forces bpftrace to generate one BPF function for each
# match and so we should fail on exceeding BPFTRACE_MAX_BPF_PROGS. The error is
# attached to the probe that went over the limit, which in this case is the
# only probe that we specify.
NAME bpf_programs_limit
PROG k:* { @[probe] = count(); }
EXPECT_REGEX stdin:1:1-4: ERROR: Your program is trying to generate more than \d+ BPF programs, which exceeds the current limit of 1024\nk:\* { @\[probe\] = count\(\); }\n~~~\nHINT: You can increase the limit through the BPFTRACE_MAX_BPF_PROGS environment variable.
WILL_FAIL
TIMEOUT 2
NAME sanitise probe name
PROG uprobe:./testprogs/uprobe_namesan:fn* { printf("ok\n"); exit(); }
EXPECT ok
AFTER ./testprogs/uprobe_namesan
NAME pid filter software
RUN {{BPFTRACE}} -e 'software:cpu-clock:10000000 { @[pid] = count(); if (len(@) != 1) { print("bad"); } }' -p {{BEFORE_PID}}
EXPECT_NONE bad
BEFORE ./testprogs/work_loop
TIMEOUT 2
NAME pid filter kprobe
RUN {{BPFTRACE}} -e 'kprobe:do_nanosleep { @[pid] = count(); if (len(@) != 1) { print("bad"); } }' -p {{BEFORE_PID}}
EXPECT_NONE bad
BEFORE ./testprogs/nanosleep_loop
BEFORE ./testprogs/nanosleep_loop
TIMEOUT 2
NAME fentry_order
RUN {{BPFTRACE}} runtime/scripts/fentry_order.bt
EXPECT_REGEX (first)+ second
AFTER ./testprogs/syscall nanosleep 233;
NAME rawtracepoint_order
RUN {{BPFTRACE}} runtime/scripts/rawtracepoint_order.bt
EXPECT_REGEX (first)+ second
AFTER ./testprogs/syscall nanosleep 233;
NAME usdt_order
RUN {{BPFTRACE}} runtime/scripts/usdt_order.bt
EXPECT_REGEX (first)+ second
AFTER ./testprogs/usdt_sized_args
NAME interval_order
RUN {{BPFTRACE}} runtime/scripts/interval_runtime_order.bt
EXPECT_REGEX (first)+ second
NAME hardware_order
REQUIRES ls /sys/devices/cpu/events/cache-misses
RUN {{BPFTRACE}} runtime/scripts/hardware_order.bt
EXPECT_REGEX (first)+ second
NAME profile_order
RUN {{BPFTRACE}} runtime/scripts/profile_order.bt
EXPECT_REGEX (first)+ second
NAME watchpoint_order
RUN {{BPFTRACE}} -e 'watchpoint:increment+arg1:4:w { printf("first") } watchpoint:increment+arg1:4:w { printf(" second\n"); exit(); }' -c ./testprogs/watchpoint_func
EXPECT_REGEX (first)+ second
ARCH aarch64|x86_64
REQUIRES_FEATURE signal
NAME fexit_order
RUN {{BPFTRACE}} runtime/scripts/fexit_order.bt
EXPECT_REGEX (first)+ second
AFTER ./testprogs/syscall nanosleep 233;
REQUIRES_FEATURE fentry
REQUIRES_FEATURE btf
NAME software_order
RUN {{BPFTRACE}} runtime/scripts/software_order.bt
EXPECT_REGEX (first)+ second
NAME signal_order
RUN {{BPFTRACE}} -e 'self:signal:SIGUSR1 { printf("first"); } self:signal:SIGUSR1 { printf(" second\n"); exit(); }'
AFTER kill -s USR1 $(pidof bpftrace)
EXPECT_REGEX (first)+ second
NAME some_missing_probes_default_error
PROG kprobe:vfs_read { exit(); } t:syscalls:nonsense { exit(); }
EXPECT stdin:1:28-48: ERROR: Tracepoint not found: syscalls:nonsense
EXPECT HINT: If this is expected, set the 'missing_probes' config variable to 'warn' or 'ignore'.
WILL_FAIL
NAME missing_probes_multiple_attach_points_default_error
PROG kprobe:vfs_read, kprobe:bad { exit(); }
EXPECT ERROR: Unable to attach probe: kprobe:bad. If this is expected, set the 'missing_probes' config variable to 'warn'.
WILL_FAIL
NAME some_missing_probes_warn
PROG config = { missing_probes=warn } kprobe:vfs_read { exit(); } t:syscalls:nonsense { exit(); }
EXPECT stdin:1:61-81: WARNING: Tracepoint not found: syscalls:nonsense
NAME some_missing_probes_ignore
PROG config = { missing_probes=ignore } kprobe:vfs_read { exit(); } t:syscalls:nonsense { exit(); }
EXPECT_NONE WARNING: Unable to attach probe: tracepoint:syscalls:nonsense. Skipping.
NAME all_missing_probes_warn
PROG config = { missing_probes=warn } kprobe:nonsense { exit(); } t:syscalls:nonsense { exit(); } uprobe:./testprogs/uprobe_test:uprobeFunction3 { exit(); }
EXPECT WARNING: Unable to attach probe: kprobe:nonsense. Skipping.
EXPECT stdin:1:61-81: WARNING: Tracepoint not found: syscalls:nonsense
EXPECT WARNING: Unable to attach probe: uprobe:./testprogs/uprobe_test:uprobeFunction3. Skipping.
EXPECT ERROR: Attachment failed for all probes.
WILL_FAIL
# This is hacky because we can't easily run a separate bpftrace program in BEFORE
# because it would require more hacks in the runtime runner.py
# including waiting for probe attachment in the BEFORE program
NAME attach_to_bpf_program
RUN {{BPFTRACE}} runtime/scripts/bpf_attach.bt & sleep 3 && {{BPFTRACE}} -e 'fentry:bpf:interval_us_* { print(probe); if (@c >= 1) { exit(); } @c = count(); }'
EXPECT_REGEX fentry:bpf:[0-9]+:interval_us_100000_1
EXPECT_REGEX fentry:bpf:[0-9]+:interval_us_100000_2
TIMEOUT 10
|