# `MaeBPF.TestRun`
[🔗](https://github.com/cocoa-xu/MaeBPF/blob/v0.1.0/maebpf/lib/maebpf/test_run.ex#L1)

Direct Linux `BPF_PROG_TEST_RUN` execution for loaded eBPF programs.

Executes a loaded program directly inside the kernel with synthetic input
packet bytes and returns the raw return code, decoded XDP action, average
execution duration in nanoseconds, and modified output packet bytes.

# `result`

```elixir
@type result() :: %{
  retval: non_neg_integer(),
  action: xdp_action(),
  duration_ns: non_neg_integer(),
  data_out: binary()
}
```

# `xdp_action`

```elixir
@type xdp_action() ::
  :aborted | :drop | :pass | :tx | :redirect | {:raw, non_neg_integer()}
```

# `clamp_data_out_size`

```elixir
@spec clamp_data_out_size(non_neg_integer(), non_neg_integer()) :: non_neg_integer()
```

Computes the clamped output buffer size matching the NIF allocation rules:
`min(1 MiB, max(data_in_size + 256, requested))`.

# `decode_cgroup_skb_action`

```elixir
@spec decode_cgroup_skb_action(non_neg_integer()) ::
  :pass | :drop | {:raw, non_neg_integer()}
```

Decodes an integer `cgroup_skb` return value (`1` = `:pass`, `0` = `:drop`)
into its symbolic action atom or `{:raw, retval}`.

# `decode_xdp_action`

```elixir
@spec decode_xdp_action(non_neg_integer()) :: xdp_action()
```

Decodes an integer XDP return value into its symbolic action atom or
`{:raw, retval}` for non-XDP return codes.

# `normalize_opts`

```elixir
@spec normalize_opts(keyword() | map()) :: map()
```

Validates and normalizes `run/4` options into a map passed to the NIF.

# `run`

```elixir
@spec run(reference(), binary(), binary(), keyword() | map()) ::
  {:ok, result()} | {:error, term()}
```

Runs `prog_name` on loaded `object` via `bpf_prog_test_run_opts`.

Options (keyword list or map):
  * `:repeat` - positive integer repetition count (default `1`)
  * `:data_out_size` - requested output buffer size in bytes (clamped to
    `max(byte_size(data_in) + 256, requested)`, capped at 1 MiB)
  * `:cpu` - optional non-negative target CPU index (`BPF_F_TEST_RUN_ON_CPU`)

---

*Consult [api-reference.md](api-reference.md) for complete listing*
