Dual-mode testing harness comparing pure-Elixir IR simulation (MaeBPF.Sim)
against live Linux kernel BPF_PROG_TEST_RUN (MaeBPF.TestRun).
Modes:
:sim- executes the IR in pure Elixir on both macOS and Linux:kernel- loads the compiled ELF into the Linux kernel, populates any initial:maps, executesBPF_PROG_TEST_RUN, reads back updated maps, and closes the object cleanly:both- executes both:simand:kernelon the same packet and reports action parity (parity: sim.action == kernel.action):auto(default) - runs:simon macOS, and on Linux runs:bothwhenverify_kernel: trueor:simotherwise
Summary
Functions
Decodes a raw kernel BPF_PROG_TEST_RUN return value according to hook.
Resolves the effective execution mode (:sim, :kernel, or :both) given
options and the current host OS.
Executes hook_name of module_or_ir against packet_bin in :auto,
:sim, :kernel, or :both mode.
Like run/4, unwrapping {:ok, result} and raising on execution error or
simulator/kernel parity mismatch in :both mode.
Types
Functions
@spec decode_hook_action(MaeBPF.IR.Program.hook(), non_neg_integer()) :: atom() | {:raw, non_neg_integer()}
Decodes a raw kernel BPF_PROG_TEST_RUN return value according to hook.
Resolves the effective execution mode (:sim, :kernel, or :both) given
options and the current host OS.
@spec run( module() | MaeBPF.IR.Module.t() | map(), atom() | String.t(), binary(), keyword() | map() ) :: {:ok, map()} | {:error, term()}
Executes hook_name of module_or_ir against packet_bin in :auto,
:sim, :kernel, or :both mode.
Options:
:mode-:auto(default),:sim,:kernel, or:both:verify_kernel- whentrueand:modeis:autoon Linux, runs:both(defaultfalse):maps- initial map entries (%{map_id_or_name => ...}) populated for both simulator and kernel runs:repeat-BPF_PROG_TEST_RUNrepetition count (default1):data_out_size- requested output packet buffer size for kernel runs:cpu- optional target CPU index for kernel runs:assert_parity- whentruein:bothmode, returns{:error, {:parity_mismatch, ...}}if simulator and kernel actions differ (defaultfalse)- Simulator state options (
:debug_trace,:debug_sample,:sample,:ringbuf,:ringbuf_capacity,:drops,:sample_seq) are forwarded toMaeBPF.Sim.run/4.
@spec run!( module() | MaeBPF.IR.Module.t() | map(), atom() | String.t(), binary(), keyword() | map() ) :: map()
Like run/4, unwrapping {:ok, result} and raising on execution error or
simulator/kernel parity mismatch in :both mode.