Skip to content

[testutils] standardize packet payload generation#267

Merged
fruffy merged 2 commits into
p4lang:mainfrom
anovotarsk:anovotarsk/standardize-packet-payloads
Jul 18, 2026
Merged

[testutils] standardize packet payload generation#267
fruffy merged 2 commits into
p4lang:mainfrom
anovotarsk:anovotarsk/standardize-packet-payloads

Conversation

@anovotarsk

@anovotarsk anovotarsk commented Jul 13, 2026

Copy link
Copy Markdown
Contributor

Add a common payload helper for simple packet builders. Support explicit payloads, truncate them to pktlen, and fill remaining space with a consistent incrementing-byte pattern.

Keep protocol-specific payload arguments for compatibility and reject calls that specify both generic and protocol-specific payloads.

Fixes #167

Add a common payload helper for simple packet builders. Support explicit
payloads, truncate them to pktlen, and fill remaining space with a
consistent incrementing-byte pattern.

Keep protocol-specific payload arguments for compatibility and reject
calls that specify both generic and protocol-specific payloads.

Signed-off-by: Artur Novotarskyi <artur.novotarskyi@gmail.com>
Copilot AI review requested due to automatic review settings July 13, 2026 23:29

Copilot AI left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

Pull request overview

This PR standardizes how ptf.testutils “simple_*_packet” builders generate payload bytes by introducing a shared helper that supports explicit payload injection, truncation to pktlen, and deterministic padding for the remainder.

Changes:

  • Added _add_payload_and_padding() helper and refactored multiple packet builders to use it for consistent padding/payload handling.
  • Introduced a new generic payload argument to several builders while keeping legacy protocol-specific payload parameters (and rejecting conflicting usage).
  • Added unit tests covering default payload consistency, payload truncation/padding behavior, and conflicting payload argument validation.

Reviewed changes

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

File Description
src/ptf/testutils.py Introduces _add_payload_and_padding and migrates multiple simple packet builders to use it; adds generic payload support and conflict checks for legacy payload args.
utests/tests/ptf/test_testutils.py Adds tests validating the standardized payload generation behavior and conflict handling.

💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.

Comment thread utests/tests/ptf/test_testutils.py Outdated
Signed-off-by: Artur Novotarskyi <artur.novotarskyi@gmail.com>
@anovotarsk

Copy link
Copy Markdown
Contributor Author

@fruffy Thanks for the review! All checks are green. Could you please merge this PR?

@fruffy
fruffy merged commit 947da5a into p4lang:main Jul 18, 2026
14 checks passed
@anovotarsk
anovotarsk deleted the anovotarsk/standardize-packet-payloads branch July 18, 2026 09:22
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.

Unify test packet payload and allow for manual control

3 participants