Skip to content

(8) feat(dpdk): test EAL harness (with_eal macro + const fn)#1572

Open
daniel-noland wants to merge 2 commits into
pr/daniel-noland/threading-rewritefrom
pr/daniel-noland/dpdk-test-eal
Open

(8) feat(dpdk): test EAL harness (with_eal macro + const fn)#1572
daniel-noland wants to merge 2 commits into
pr/daniel-noland/threading-rewritefrom
pr/daniel-noland/dpdk-test-eal

Conversation

@daniel-noland
Copy link
Copy Markdown
Collaborator

@daniel-noland daniel-noland commented May 31, 2026

Stack (8). Base: pr/daniel-noland/threading-rewrite.

DPDK test plumbing that the rest of the ACL stack relies on, kept separate so it
reviews on its own:

  • refactor(dpdk/acl): make compute_min_input_size a const fn.
  • feat(dpdk): test_support::start_eal + #[with_eal] attribute macro
    (dpdk-test-macros), so EAL-dependent tests can opt in declaratively.

No new abstractions, no behavior change to shipping code.

Review stack (merge bottom -> top):

Lets callers derive the rte_acl input-buffer size requirement from a
const FIELD_DEFS array at compile time -- useful for feeding into a
const generic (e.g. the STRIDE on a DPDK-backed Lookup type alias)
rather than rediscovering it at runtime.

The runtime path through AclBuildConfig::new still calls into the
same helper and caches the result; only the surface broadens from
fn to const fn (with the for-loop rewritten as a while-let-i index
walk that const-fn-eval can chew on).  Existing FieldExtentOverflow
validation is preserved; in a const context overflow becomes a
compile error instead of UB.

Adds one test exercising the const path: const MIN_INPUT_SIZE =
AclBuildConfig::compute_min_input_size(&DEFS); plus the assertion
that the runtime path returns the same value.

just fmt; cargo check -p dataplane-dpdk --all-targets passes.
Introduces shared EAL test scaffolding for downstream crates that
need to exercise rte_acl, mempools, or any other DPDK runtime under
`#[test]`.  Two pieces, both behind the new dpdk `test` feature so
production builds remain unchanged:

- dpdk-test-macros: proc-macro crate exposing #[with_eal], which
  injects `let _eal = <dpdk_crate>::test_support::start_eal();` at
  the top of a #[test] function.  Resolves the dpdk crate's path via
  proc-macro-crate so the macro works in-tree (`crate`), under the
  workspace alias (`::dpdk`), or with the canonical name
  (`::dataplane_dpdk`).
- dpdk::test_support: hosts a shared OnceLock<Eal> initialized with
  --no-huge / --no-pci / --in-memory and the cpu-affinity-aware
  --lcores derivation that was previously inline in acl/mod.rs.
  Once-per-process by construction; safe under nextest's per-test
  forking and single-process runners alike.

dpdk/src/acl/mod.rs picks up the new macro: every test in the module
loses its `let _eal = start_eal();` prologue and gains a #[with_eal]
attribute above #[test].  The inline start_eal helper and the
module-scoped OnceLock<Eal> static go away.

dpdk/Cargo.toml grows the `test` feature (turns on dpdk-test-macros
plus the id and nix runtime helpers that test_support needs) and a
self-referencing dev-dep `dataplane-dpdk = { path = ".", features =
["test"] }` so dpdk's own tests see the macro surface.

just fmt; cargo check --workspace --all-targets passes.
Copy link
Copy Markdown
Contributor

Copilot AI left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Pull request overview

Adds shared DPDK EAL initialization support for tests (via a start_eal() helper and a #[with_eal] proc-macro), and refactors an ACL helper to be usable in const contexts.

Changes:

  • Introduces dpdk::test_support::start_eal() (OnceLock-backed) to initialize EAL once per process with test-friendly flags.
  • Adds dataplane-dpdk-test-macros providing #[with_eal], and wires it into dataplane-dpdk behind a test feature.
  • Refactors AclBuildConfig::compute_min_input_size to a const fn and adds a const-context unit test; updates ACL tests to use the macro and simplifies some call sites.

Reviewed changes

Copilot reviewed 8 out of 9 changed files in this pull request and generated 1 comment.

Show a summary per file
File Description
dpdk/src/test_support.rs New shared EAL init helper for tests.
dpdk/src/lib.rs Exposes test_support in tests / test feature; re-exports #[with_eal] under feature = "test".
dpdk/src/acl/mod.rs Updates ACL unit tests to use #[with_eal]; minor doc/example tweak.
dpdk/src/acl/config.rs Makes compute_min_input_size const-friendly and adds a const-context test.
dpdk/Cargo.toml Adds test feature and optional deps/macro wiring for test harness support.
dpdk-test-macros/src/lib.rs Implements the #[with_eal] attribute macro.
dpdk-test-macros/Cargo.toml New proc-macro crate manifest.
Cargo.toml Adds new workspace member + workspace dependency entry.
Cargo.lock Locks new proc-macro crate and updated dependency graph.

Comment thread dpdk/src/acl/config.rs
Comment on lines +908 to 913
/// Compute DPDK's minimum input buffer size.
///
/// See [`min_input_size`][AclBuildConfig::min_input_size] for the
/// formula and rationale. Factored out so that `new` can call it
/// once and cache the result; the public accessor returns the cached
/// value.
///
/// Precondition: all fields' `offset + 4` fit in `u32`. This is
/// guaranteed by the `FieldExtentOverflow` check in
/// [`new`][AclBuildConfig::new], so the plain `+` below cannot
/// overflow.
fn compute_min_input_size(field_defs: &[FieldDef; N]) -> usize {
/// `offset + 4` must fit in `u32`; [`AclBuildConfig::new`] validates this.
#[must_use]
pub const fn compute_min_input_size(field_defs: &[FieldDef; N]) -> usize {
let mut max_load_end: u32 = 0;
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants