Feat/12079 single port tests v1#7
Conversation
Without the tiny delay TRex would try to access the port it was just using but didn't free yet and would raise an exception.
There was a problem hiding this comment.
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-modeoptions (wired throughpytest_start.sh+conftest.py) and aget_trex_mode()helper for tests to opt into dynamic mode selection. - Refactor TRex-related helpers into
util/trex_util.pyand update multiple tests/profiles to useget_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.
| 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): |
| 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") | ||
|
|
| -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 ;; |
| 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)}", | ||
| ] | ||
| ) |
There was a problem hiding this comment.
This is run by a user in their shell, so it is not a real concert that $USER would be unset.
| class TrexMode(Enum): | ||
| STL = (0,) | ||
| ASTF = (1,) | ||
| STF = 2 |
Adds the option to run all existing ASTF tests in STF mode and to dynamically change TRex modes in general.
pytest_start.shand 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-modeuses the preferred mode when a test has it marked as available, otherwise it falls back to the first mode marked as available.--force-trex-modeuses the forced mode when a test has it marked as available, otherwise it skips the test.Tests need to call
get_trex_modeto use this functionality. Tests that don't do this are unaffected.To achieve this I also:
conftest.pytotrex_util.py