[RFC,v1,1/3] dts: add clearing port stats and verbose mode to testpmd
Checks
Commit Message
From: Jeremy Spewock <jspewock@iol.unh.edu>
Methods currently exist for querying the statistics of a port in
testpmd, but there weren't methods added for clearing the current
statistics on a port. This patch adds methods that allow you to clear
the statistics of a single port or all ports to account for situations
where the user only wants the port statistics after a certain point and
does not care about any existing prior values.
This patch also contains methods for modifying the verbose level of
testpmd so that users are able to utilize the extra information that it
provides.
Depends-on: patch-142762 ("dts: add text parser for testpmd verbose
output")
Signed-off-by: Jeremy Spewock <jspewock@iol.unh.edu>
---
dts/framework/remote_session/testpmd_shell.py | 62 +++++++++++++++++++
1 file changed, 62 insertions(+)
@@ -948,6 +948,68 @@ def extract_verbose_output(output: str) -> list[TestPmdVerboseOutput]:
iter = re.finditer(r"(port \d+/queue \d+:.*?(?=port \d+/queue \d+|$))", output, re.S)
return [TestPmdVerboseOutput.parse(s.group(0)) for s in iter]
+ def clear_port_stats(self, port_id: int, verify: bool = True) -> None:
+ """Clear statistics of a given port.
+
+ Args:
+ port_id: ID of the port to clear the statistics on.
+ verify: If :data:`True` the output of the command will be scanned to verify that it was
+ successful, otherwise failures will be ignored. Defaults to :data:`True`.
+
+ Raises:
+ InteractiveCommandExecutionError: If `verify` is :data:`True` and testpmd fails to
+ clear the statistics of the given port.
+ """
+ clear_output = self.send_command(f"clear port stats {port_id}")
+ if verify and f"NIC statistics for port {port_id} cleared" not in clear_output:
+ raise InteractiveCommandExecutionError(
+ f"Test pmd failed to set clear forwarding stats on port {port_id}"
+ )
+
+ def clear_port_stats_all(self, verify: bool = True) -> None:
+ """Clear the statistics of all ports that testpmd is aware of.
+
+ Args:
+ verify: If :data:`True` the output of the command will be scanned to verify that all
+ ports had their statistics cleared, otherwise failures will be ignored. Defaults to
+ :data:`True`.
+
+ Raises:
+ InteractiveCommandExecutionError: If `verify` is :data:`True` and testpmd fails to
+ clear the statistics of any of its ports.
+ """
+ clear_output = self.send_command("clear port stats all")
+ if verify:
+ if type(self._app_params.ports) is list:
+ for port_id in range(len(self._app_params.ports)):
+ if f"NIC statistics for port {port_id} cleared" not in clear_output:
+ raise InteractiveCommandExecutionError(
+ f"Test pmd failed to set clear forwarding stats on port {port_id}"
+ )
+
+ def set_verbose(self, level: int, verify: bool = True) -> None:
+ """Set debug verbosity level.
+
+ Args:
+ level: 0 - silent except for error
+ 1 - fully verbose except for Tx packets
+ 2 - fully verbose except for Rx packets
+ >2 - fully verbose
+ verify: if :data:`True` an additional command will be sent to verify that verbose level
+ is properly set. Defaults to :data:`True`.
+
+ Raises:
+ InteractiveCommandExecutionError: If `verify` is :data:`True` and verbose level
+ is not correctly set.
+ """
+ verbose_output = self.send_command(f"set verbose {level}")
+ if verify:
+ if "Change verbose level" not in verbose_output:
+ self._logger.debug(f"Failed to set verbose level to {level}: \n{verbose_output}")
+ raise InteractiveCommandExecutionError(
+ f"Testpmd failed to set verbose level to {level}."
+ )
+
def _close(self) -> None:
"""Overrides :meth:`~.interactive_shell.close`."""
self.stop()