Skip to content

[p4testgen] Add STF backend for PNA#5570

Merged
smolkaj merged 1 commit intop4lang:mainfrom
smolkaj:pna-testgen-upstream
Apr 6, 2026
Merged

[p4testgen] Add STF backend for PNA#5570
smolkaj merged 1 commit intop4lang:mainfrom
smolkaj:pna-testgen-upstream

Conversation

@smolkaj
Copy link
Copy Markdown
Member

@smolkaj smolkaj commented Mar 28, 2026

Summary

Adds STF output support for the PNA p4testgen target, matching the
existing BMv2 STF backend. This enables:

p4testgen --target dpdk --arch pna --test-backend stf program.p4

The backend handles exact, ternary, LPM, and optional match types.
One .stf file per test case, same format as BMv2's STF output.

New files: backends/p4tools/modules/testgen/targets/pna/backend/stf/stf.{h,cpp}

The Bazel hdrs glob in backends/p4tools/BUILD.bazel is widened
from backend/*.h to backend/**/*.h so the new backend/stf/
subdirectory is picked up. (Enabling PNA itself in the Bazel build
was originally part of this PR but landed separately via #5575.)

Motivation

The 4ward P4 simulator uses
p4testgen to generate STF tests for PNA programs. Without an STF
backend, --test-backend stf fails with "Unsupported device: dpdk".

Testing

Validated in 4ward: 411 p4testgen-generated STF tests across 21 PNA
programs pass with this change.

@fruffy — would appreciate your review on the STF backend approach.
Happy to adjust anything.

@github-actions github-actions bot added the p4tools Topics related to the P4Tools back end label Mar 28, 2026
@smolkaj smolkaj force-pushed the pna-testgen-upstream branch 2 times, most recently from 2b4b49d to aeb383d Compare March 28, 2026 06:15
@fruffy
Copy link
Copy Markdown
Collaborator

fruffy commented Mar 28, 2026

I think we should split this off into a dpdk and 4ward back end, then you can generate packets for the more pure interpretation of the PNA spec that 4ward has, free from the implementation restrictions of the DPDK target.

But let me also revive #4228 and see how this PR influences it.

@smolkaj smolkaj force-pushed the pna-testgen-upstream branch from aeb383d to d213dbd Compare March 29, 2026 08:47
@smolkaj smolkaj changed the title [p4testgen] Add STF backend for PNA, fix drop-by-default [p4testgen] Add STF backend for PNA Mar 29, 2026
@smolkaj
Copy link
Copy Markdown
Member Author

smolkaj commented Mar 29, 2026

Thanks for the feedback @fruffy! I've updated the PR to split out the drop-by-default change (will file that separately once the semantics are settled).

What remains here is just the STF backend for PNA — no behavioral changes to existing code. Happy to rename the backend or restructure if you'd prefer a 4ward-specific target down the line, but the STF output itself is target-agnostic (same format as BMv2's STF backend).

Re #4228 — would love to see that land too. This PR shouldn't conflict with it since we're only adding a new backend under targets/pna/backend/stf/.

@smolkaj smolkaj force-pushed the pna-testgen-upstream branch from d213dbd to 72fccaf Compare March 29, 2026 08:49
smolkaj added a commit to smolkaj/4ward that referenced this pull request Apr 5, 2026
That version is in BCR and has //p4include, testdata exports, and the
macOS fix — everything the smolkaj/p4c fork originally carried. BCR
consumers now get the right p4c transitively without any manual pin,
and bcr_test_module no longer needs a p4c override to mimic the BCR
resolution path.

The git_override stays: fourward-as-root still wants the fork for the
PNA p4testgen STF backend (p4lang/p4c#5570) and drop-by-default fix
(p4lang/p4c#5569), neither of which is in BCR yet. git_override is
only honored for root, so non-root consumers are unaffected.
Adds STF output support for the PNA target, matching the existing BMv2
STF backend. This enables:

    p4testgen --target dpdk --arch pna --test-backend stf program.p4

The backend handles exact, ternary, LPM, and optional match types. One
.stf file per test case, same format as BMv2's STF output.

Also enables PNA in the Bazel build by adding it to TESTGEN_TARGETS.

Signed-off-by: Steffen Smolka <steffen.smolka@gmail.com>
@smolkaj smolkaj force-pushed the pna-testgen-upstream branch from 72fccaf to c346923 Compare April 5, 2026 21:50
@smolkaj smolkaj enabled auto-merge April 5, 2026 21:57
@smolkaj smolkaj added this pull request to the merge queue Apr 5, 2026
Merged via the queue into p4lang:main with commit 891380c Apr 6, 2026
20 checks passed
@smolkaj smolkaj deleted the pna-testgen-upstream branch April 6, 2026 00:22
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

p4tools Topics related to the P4Tools back end

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants