Skip to content

Commit 2a586f1

Browse files
dmarxIOLpaul-szczepanek-arm
authored andcommitted
dts: add flow validation
Add a method for validating flow rules to the testpmd shell class. Implement test case skipping for flow rules that do not pass validation. Signed-off-by: Dean Marx <dmarx@iol.unh.edu> Reviewed-by: Patrick Robb <probb@iol.unh.edu>
1 parent 2f8d320 commit 2a586f1

3 files changed

Lines changed: 38 additions & 1 deletion

File tree

dts/framework/remote_session/testpmd_shell.py

Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1984,6 +1984,21 @@ def flow_create(self, flow_rule: FlowRule, port_id: int) -> int:
19841984
self._logger.debug(f"Failed to create flow rule:\n{flow_output}")
19851985
raise InteractiveCommandExecutionError(f"Failed to create flow rule:\n{flow_output}")
19861986

1987+
def flow_validate(self, flow_rule: FlowRule, port_id: int) -> bool:
1988+
"""Validates a flow rule in the testpmd session.
1989+
1990+
Args:
1991+
flow_rule: :class:`FlowRule` object used for validating testpmd flow rule.
1992+
port_id: Integer representing the port to use.
1993+
1994+
Returns:
1995+
Boolean representing whether rule is valid or not.
1996+
"""
1997+
flow_output = self.send_command(f"flow validate {port_id} {flow_rule}")
1998+
if "Flow rule validated" in flow_output:
1999+
return True
2000+
return False
2001+
19872002
def flow_delete(self, flow_id: int, port_id: int, verify: bool = True) -> None:
19882003
"""Deletes the specified flow rule from the testpmd session.
19892004

dts/framework/test_run.py

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -655,6 +655,9 @@ def next(self) -> State | None:
655655
return self
656656

657657
self.result.update(Result.FAIL, e)
658+
except SkippedTestException as e:
659+
self.logger.info(f"{self.description.capitalize()} SKIPPED: {e}")
660+
self.result.update(Result.SKIP, e)
658661
else:
659662
self.result.update(Result.PASS)
660663
self.logger.info(f"{self.description.capitalize()} PASSED.")

dts/framework/test_suite.py

Lines changed: 20 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -39,7 +39,7 @@
3939
PacketFilteringConfig,
4040
)
4141

42-
from .exception import ConfigurationError, InternalError, TestCaseVerifyError
42+
from .exception import ConfigurationError, InternalError, SkippedTestException, TestCaseVerifyError
4343
from .logger import DTSLogger, get_dts_logger
4444
from .utils import get_packet_summaries, to_pascal_case
4545

@@ -411,6 +411,25 @@ def _fail_test_case_verify(self, failure_description: str) -> None:
411411
self._logger.debug(command_res.command)
412412
raise TestCaseVerifyError(failure_description)
413413

414+
def verify_else_skip(self, condition: bool, skip_reason: str) -> None:
415+
"""Verify `condition` and handle skips.
416+
417+
When `condition` is :data:`False`, raise a skip exception.
418+
419+
Args:
420+
condition: The condition to check.
421+
skip_reason: Description of the reason for skipping.
422+
423+
Raises:
424+
SkippedTestException: `condition` is :data:`False`.
425+
"""
426+
if not condition:
427+
self._skip_test_case_verify(skip_reason)
428+
429+
def _skip_test_case_verify(self, skip_description: str) -> None:
430+
self._logger.debug(f"Test case skipped: {skip_description}")
431+
raise SkippedTestException(skip_description)
432+
414433
def verify_packets(self, expected_packet: Packet, received_packets: list[Packet]) -> None:
415434
"""Verify that `expected_packet` has been received.
416435

0 commit comments

Comments
 (0)