2021-12-04 01:20:26 +00:00
|
|
|
import ./make-test-python.nix ({ pkgs, ... }: {
|
|
|
|
name = "bpf";
|
|
|
|
meta.maintainers = with pkgs.lib.maintainers; [ martinetd ];
|
|
|
|
|
2022-03-20 23:15:30 +00:00
|
|
|
nodes.machine = { pkgs, ... }: {
|
2021-12-04 01:20:26 +00:00
|
|
|
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\"); exit(); }'"))
|
|
|
|
# tracepoint
|
2022-02-11 07:55:34 +00:00
|
|
|
print(machine.succeed("bpftrace -e 'tracepoint:syscalls:sys_enter_* { print(probe); exit() }'"))
|
2021-12-04 01:20:26 +00:00
|
|
|
# kprobe
|
|
|
|
print(machine.succeed("bpftrace -e 'kprobe:schedule { print(probe); exit() }'"))
|
2022-02-11 07:55:34 +00:00
|
|
|
# BTF
|
|
|
|
print(machine.succeed("bpftrace -e 'kprobe:schedule { "
|
|
|
|
" printf(\"tgid: %d\", ((struct task_struct*) curtask)->tgid); exit() "
|
|
|
|
"}'"))
|
2023-02-03 04:44:13 +00:00
|
|
|
# module BTF (bpftrace >= 0.17)
|
2023-02-04 04:58:07 +00:00
|
|
|
# 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); "
|
2023-02-03 04:44:13 +00:00
|
|
|
"} BEGIN { exit() }'"))
|
2021-12-04 01:20:26 +00:00
|
|
|
'';
|
|
|
|
})
|