[PATCH v3 1/1] dts: add text parser for testpmd verbose output
Jeremy Spewock
jspewock at iol.unh.edu
Thu Aug 8 23:49:05 CEST 2024
On Thu, Aug 8, 2024 at 4:36 PM <jspewock at iol.unh.edu> wrote:
>
> From: Jeremy Spewock <jspewock at iol.unh.edu>
>
> Multiple test suites from the old DTS framework rely on being able to
> consume and interpret the verbose output of testpmd. The new framework
> doesn't have an elegant way for handling the verbose output, but test
> suites are starting to be written that rely on it. This patch creates a
> TextParser class that can be used to extract the verbose information
> from any testpmd output and also adjusts the `stop` method of the shell
> to return all output that it collected.
>
> Signed-off-by: Jeremy Spewock <jspewock at iol.unh.edu>
> ---
> dts/framework/parser.py | 30 ++
> dts/framework/remote_session/testpmd_shell.py | 405 +++++++++++++++++-
> dts/framework/utils.py | 1 +
> 3 files changed, 434 insertions(+), 2 deletions(-)
>
> diff --git a/dts/framework/parser.py b/dts/framework/parser.py
> index 741dfff821..0b39025a48 100644
> --- a/dts/framework/parser.py
> +++ b/dts/framework/parser.py
> @@ -160,6 +160,36 @@ def _find(text: str) -> Any:
>
> return ParserFn(TextParser_fn=_find)
>
> + @staticmethod
> + def find_all(
I just realized that I forgot to take this method out since it is no
longer used in this patch now that I removed the idea of a block of
output that contains a burst of packets. The method could still be
useful in the future, but it isn't used anywhere now, so I can remove
it in the next version if no one sees a use for it. I'm also open to
leaving it there for the "just in case" it is needed in the future.
What do you all think?
> + pattern: str | re.Pattern[str],
> + flags: re.RegexFlag = re.RegexFlag(0),
> + ) -> ParserFn:
> + """Makes a parser function that finds all of the regular expression matches in the text.
> +
> + If there are no matches found in the text than None will be returned, otherwise a list
> + containing all matches will be returned. Patterns that contain multiple groups will pack
> + the matches for each group into a tuple.
> +
> + Args:
> + pattern: The regular expression pattern.
> + flags: The regular expression flags. Ignored if the given pattern is already compiled.
> +
> + Returns:
> + A :class:`ParserFn` that can be used as metadata for a dataclass field.
> + """
> + if isinstance(pattern, str):
> + pattern = re.compile(pattern, flags)
> +
> + def _find_all(text: str) -> list[str] | None:
> + m = pattern.findall(text)
> + if len(m) == 0:
> + return None
> +
> + return m
> +
> + return ParserFn(TextParser_fn=_find_all)
> +
<snip>
> 2.45.2
>
More information about the dev
mailing list