From 4e792f525ecef83b61e45b54ebfc833f0b35a1f7 Mon Sep 17 00:00:00 2001 From: Sizhe Zhao Date: Sat, 7 Jun 2025 18:46:07 +0800 Subject: [PATCH] nixosTests.bpf: handleTest -> runTest --- nixos/tests/all-tests.nix | 2 +- nixos/tests/bpf.nix | 80 +++++++++++++++++++-------------------- 2 files changed, 40 insertions(+), 42 deletions(-) diff --git a/nixos/tests/all-tests.nix b/nixos/tests/all-tests.nix index 1127f485c68c..a800736e4b8d 100644 --- a/nixos/tests/all-tests.nix +++ b/nixos/tests/all-tests.nix @@ -269,7 +269,7 @@ in borgbackup = runTest ./borgbackup.nix; borgmatic = runTest ./borgmatic.nix; botamusique = runTest ./botamusique.nix; - bpf = handleTestOn [ "x86_64-linux" "aarch64-linux" ] ./bpf.nix { }; + bpf = runTestOn [ "x86_64-linux" "aarch64-linux" ] ./bpf.nix; bpftune = runTest ./bpftune.nix; breitbandmessung = runTest ./breitbandmessung.nix; broadcast-box = runTest ./broadcast-box.nix; diff --git a/nixos/tests/bpf.nix b/nixos/tests/bpf.nix index 8d871d276d42..1390b75a72ca 100644 --- a/nixos/tests/bpf.nix +++ b/nixos/tests/bpf.nix @@ -1,44 +1,42 @@ -import ./make-test-python.nix ( - { pkgs, ... }: - { - name = "bpf"; - meta.maintainers = with pkgs.lib.maintainers; [ martinetd ]; +{ lib, ... }: +{ + name = "bpf"; + meta.maintainers = with lib.maintainers; [ martinetd ]; - nodes.machine = - { pkgs, ... }: - { - programs.bcc.enable = true; - environment.systemPackages = with pkgs; [ bpftrace ]; - }; + 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")) + 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 - print(machine.succeed("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 \n" - "BEGIN { printf(\"ok %d\\n\", EINVAL); exit(); }'")) - ''; - } -) + ## 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 + print(machine.succeed("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 \n" + "BEGIN { printf(\"ok %d\\n\", EINVAL); exit(); }'")) + ''; +}