1import ./make-test-python.nix (
2 { pkgs, ... }:
3 {
4 name = "bpf";
5 meta.maintainers = with pkgs.lib.maintainers; [ martinetd ];
6
7 nodes.machine =
8 { pkgs, ... }:
9 {
10 programs.bcc.enable = true;
11 environment.systemPackages = with pkgs; [ bpftrace ];
12 };
13
14 testScript = ''
15 ## bcc
16 # syscount -d 1 stops 1s after probe started so is good for that
17 print(machine.succeed("syscount -d 1"))
18
19 ## bpftrace
20 # list probes
21 machine.succeed("bpftrace -l")
22 # simple BEGIN probe (user probe on bpftrace itself)
23 print(machine.succeed("bpftrace -e 'BEGIN { print(\"ok\\n\"); exit(); }'"))
24 # tracepoint
25 print(machine.succeed("bpftrace -e 'tracepoint:syscalls:sys_enter_* { print(probe); exit() }'"))
26 # kprobe
27 print(machine.succeed("bpftrace -e 'kprobe:schedule { print(probe); exit() }'"))
28 # BTF
29 print(machine.succeed("bpftrace -e 'kprobe:schedule { "
30 " printf(\"tgid: %d\\n\", ((struct task_struct*) curtask)->tgid); exit() "
31 "}'"))
32 # module BTF (bpftrace >= 0.17)
33 # test is currently disabled on aarch64 as kfunc does not work there yet
34 # https://github.com/iovisor/bpftrace/issues/2496
35 print(machine.succeed("uname -m | grep aarch64 || "
36 "bpftrace -e 'kfunc:nft_trans_alloc_gfp { "
37 " printf(\"portid: %d\\n\", args->ctx->portid); "
38 "} BEGIN { exit() }'"))
39 # glibc includes
40 print(machine.succeed("bpftrace -e '#include <errno.h>\n"
41 "BEGIN { printf(\"ok %d\\n\", EINVAL); exit(); }'"))
42 '';
43 }
44)