nixpkgs/nixos/tests/bpf.nix
Dominique Martinet 27bb09b95e bpftrace: 0.23.5 -> 0.24.1
This fixes build error due to updaded llvm.

bpftrace 0.24.1 had a couple of regressions, so backport fix and
temporarily raise ulimit in test.
A better solution for ulimit will probably make it in 0.24.2 but
that is likely harmless enough in practice so go ahead as is.

Notes:
- add new xxd build dep to fix build
- INSTALL_TOOL_DOCS was removed, .txt files are now comments in scripts
  themselves
- USE_SYSTEM_LIBBPF is optional right now but needed on master, just set
  it as there is no harm and next auto-update will be less work
2025-10-11 05:49:25 +09:00

48 lines
1.6 KiB
Nix

{ lib, ... }:
{
name = "bpf";
meta.maintainers = with lib.maintainers; [ martinetd ];
nodes.machine =
{ pkgs, ... }:
{
programs.bcc.enable = true;
environment.systemPackages = with pkgs; [ bpftrace ];
};
testScript = ''
## bcc
# syscount -d 1 stops 1s after probe started so is good for that
print(machine.succeed("syscount -d 1"))
## bpftrace
# list probes
machine.succeed("bpftrace -l")
# simple BEGIN probe (user probe on bpftrace itself)
print(machine.succeed("bpftrace -e 'BEGIN { print(\"ok\\n\"); exit(); }'"))
# tracepoint
# workaround: this needs more than the default of 1k FD to attach ~350 probes, bump fd limit
# see https://github.com/bpftrace/bpftrace/issues/2110
print(machine.succeed("""
ulimit -n 2048
bpftrace -e 'tracepoint:syscalls:sys_enter_* { print(probe); exit() }'
"""))
# kprobe
print(machine.succeed("bpftrace -e 'kprobe:schedule { print(probe); exit() }'"))
# BTF
print(machine.succeed("bpftrace -e 'kprobe:schedule { "
" printf(\"tgid: %d\\n\", ((struct task_struct*) curtask)->tgid); exit() "
"}'"))
# module BTF (bpftrace >= 0.17)
# test is currently disabled on aarch64 as kfunc does not work there yet
# https://github.com/iovisor/bpftrace/issues/2496
print(machine.succeed("uname -m | grep aarch64 || "
"bpftrace -e 'kfunc:nft_trans_alloc_gfp { "
" printf(\"portid: %d\\n\", args->ctx->portid); "
"} BEGIN { exit() }'"))
# glibc includes
print(machine.succeed("bpftrace -e '#include <errno.h>\n"
"BEGIN { printf(\"ok %d\\n\", EINVAL); exit(); }'"))
'';
}