Skip to content

Feat/12079 single port tests v1#7

Draft
matyas7dub wants to merge 5 commits into
CESNET:mainfrom
matyas7dub:feat/12079-single-port-tests-v1
Draft

Feat/12079 single port tests v1#7
matyas7dub wants to merge 5 commits into
CESNET:mainfrom
matyas7dub:feat/12079-single-port-tests-v1

Conversation

@matyas7dub

Copy link
Copy Markdown
Collaborator

Adds the option to run all existing ASTF tests in STF mode and to dynamically change TRex modes in general.

pytest_start.sh and pytest have had new flags added that can be used to "prefer" or "force" a certain TRex mode. This can be useful when testing Suricata in an environment with limited hardware resources (port mirroring not set up, only one port available for TRex, ...)

--prefer-trex-mode uses the preferred mode when a test has it marked as available, otherwise it falls back to the first mode marked as available.

--force-trex-mode uses the forced mode when a test has it marked as available, otherwise it skips the test.

Tests need to call get_trex_mode to use this functionality. Tests that don't do this are unaffected.

To achieve this I also:

  • split off TRex related functions from conftest.py to trex_util.py
  • added a default STF config implementation
  • fixed issues with replaying several PCAPs with STL TRex

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 adds a mechanism to select TRex runtime mode (STL/ASTF/STF) per test via new pytest/launcher flags, enabling existing ASTF-style tests to run in STF mode for single-port or constrained environments. It also refactors TRex helper functionality into a shared utility module and improves STF/STL data/config handling (including a default STF profile implementation and more robust multi-PCAP replay behavior).

Changes:

  • Add --prefer-trex-mode / --force-trex-mode options (wired through pytest_start.sh + conftest.py) and a get_trex_mode() helper for tests to opt into dynamic mode selection.
  • Refactor TRex-related helpers into util/trex_util.py and update multiple tests/profiles to use get_trex_mode() and the shared TrexMode definition.
  • Improve STF/STL handling in trex_client_manager.py, including remote file upload paths and a default STF traffic profile generation.

Reviewed changes

Copilot reviewed 12 out of 12 changed files in this pull request and generated 5 comments.

Show a summary per file
File Description
util/trex_util.py New shared TRex helpers: mode parsing/selection and remote rsync/mkdir utilities.
util/config_builder.py Extends config builder to better handle dict values and adjusts YAML output behavior.
assets/trex/traffic_profiles/trex_client_manager.py Refactors TRex mode handling, remote uploads, STF defaults, and STL multi-PCAP replay behavior.
conftest.py Adds new pytest CLI options and removes old PCAP upload helper.
pytest_start.sh Adds wrapper flags for preferring/forcing TRex mode and forwards them to pytest.
tests/web_50_sites/test_web_50_sites.py Switches to shared TrexMode + selects mode via get_trex_mode().
tests/http_simple/test_http_simple.py Switches to shared TrexMode + selects mode via get_trex_mode().
tests/https_simple/test_https_simple.py Switches to shared TrexMode + selects mode via get_trex_mode().
tests/nfs_smb_simple/test_nfs_smb_simple.py Switches to shared TrexMode + selects mode via get_trex_mode().
tests/http_https_smb_simple/test_http_https_smb_simple.py Switches to shared TrexMode + selects mode via get_trex_mode().
tests/pcap_replay/test_pcap_replay.py Updates PCAP upload to use new remote helpers and a simpler remote path reference.
README.md Updates STF profile guidance wording to reflect optional default behavior.

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

Comment thread util/config_builder.py
Comment on lines 72 to 82
if isinstance(value, list):
# force arrays
self.delete_option(key)
for i, item in enumerate(value):
self.set_option(f"{key}[{i}]", item)
elif isinstance(value, Dict):
self.__proc.set_value(key, "dummy-value")
nodes: list[NodeCoords] = list(self.__proc.get_nodes(key))
for nc in nodes:
nc.parent[nc.parentref] = value
elif isinstance(value, str):

Copy link
Copy Markdown
Collaborator Author

Choose a reason for hiding this comment

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

implemented

Comment thread util/trex_util.py
Comment on lines +85 to +90
preferred_mode = request.config.getoption("--prefer-trex-mode")
if preferred_mode is not None:
mode_enum = str_to_trex_mode(preferred_mode)
if mode_enum is None:
raise ValueError(f"{forced_mode} is not a valid TRex mode")

Copy link
Copy Markdown
Collaborator Author

Choose a reason for hiding this comment

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

implemented

Comment thread pytest_start.sh
Comment on lines +51 to +52
-pm | --prefer-trex-mode) trex_mode_flags+="--prefer-trex-mode $2 " shift 2 ;;
-fm | --force-trex-mode) trex_mode_flags+="--force-trex-mode $2 "; shift 2 ;;

Copy link
Copy Markdown
Collaborator Author

Choose a reason for hiding this comment

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

implemented

Comment thread util/trex_util.py
Comment on lines +20 to +33
def send_to_remote(source: Path, hostname: str, destination: Path | None = None):
if destination is None:
destination = source

subprocess.run(
[
"rsync",
"-z",
"--checksum",
"--update",
str(source),
f"{os.environ['USER']}@{hostname}:{str(destination)}",
]
)

Copy link
Copy Markdown
Collaborator Author

Choose a reason for hiding this comment

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

This is run by a user in their shell, so it is not a real concert that $USER would be unset.

Comment thread util/trex_util.py
Comment on lines +11 to +14
class TrexMode(Enum):
STL = (0,)
ASTF = (1,)
STF = 2

Copy link
Copy Markdown
Collaborator Author

Choose a reason for hiding this comment

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

fixed

@matyas7dub matyas7dub marked this pull request as draft June 30, 2026 08:39
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.

2 participants