From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: from mails.dpdk.org (mails.dpdk.org [217.70.189.124]) by inbox.dpdk.org (Postfix) with ESMTP id 7942443E6F; Tue, 16 Apr 2024 11:03:45 +0200 (CEST) Received: from mails.dpdk.org (localhost [127.0.0.1]) by mails.dpdk.org (Postfix) with ESMTP id 468BD402AE; Tue, 16 Apr 2024 11:03:44 +0200 (CEST) Received: from mail-lf1-f46.google.com (mail-lf1-f46.google.com [209.85.167.46]) by mails.dpdk.org (Postfix) with ESMTP id 468DC4029E for ; Tue, 16 Apr 2024 11:03:43 +0200 (CEST) Received: by mail-lf1-f46.google.com with SMTP id 2adb3069b0e04-518e2283bd3so3120786e87.1 for ; Tue, 16 Apr 2024 02:03:43 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=pantheon.tech; s=google; t=1713258223; x=1713863023; darn=dpdk.org; h=content-transfer-encoding:cc:to:subject:message-id:date:from :in-reply-to:references:mime-version:from:to:cc:subject:date :message-id:reply-to; bh=vVjuuj6kdug3wMTq4uAsysGWKpddmPdRS9lCT6lqMHM=; b=BPN+OFZfCUFoBb5XJnqq23h6Y6oK/HMMLkzJJ7FOKUhLRn80/KJEsY+uizZSi87j6q lK1kD6dfOmfOwnBTo5N9yqQkEbrxVyhq8tz2U7QJjwvFuXbwaYoBcZZcVoFp0sYVFzmJ V1KZ76yqTpr+sInDlgcRldURIBltm0ywFIQ4HOX1lkvuE1aOLlgKk9Jx7BE5Sja4uYaa +jyct8lsni5iywUlX+nchjxciEWkP5+CwFVHu/UxN0bPkOJP40KNmVnyQd5OIsXX4hIt +sXKvNqjva5+T8G7DnPTLqcTaQ2buUB77PpbtnZXoFUcGyvmRgXJPxONGBtRIf92EtKn 9Xsg== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1713258223; x=1713863023; h=content-transfer-encoding:cc:to:subject:message-id:date:from :in-reply-to:references:mime-version:x-gm-message-state:from:to:cc :subject:date:message-id:reply-to; bh=vVjuuj6kdug3wMTq4uAsysGWKpddmPdRS9lCT6lqMHM=; b=Ttr54jVg9SfQTSOuTt8CLI9qBvSrhU+VjT9UTJVBlXaaTgYp5TQp28yu9HUIvVBVOf 4kH3TCBB0yvyv2Pbx1fMzbJ4X7fNfbW2bLNmoiueLElld9feW+mNKRvtXMLLyIeA23qv gD9b3nuLjIJogNM8+DqNqEoH4A/Upx4P8SGimV8Z/omYcenNfMI6hNt5AtgTXpXjIgN9 lWRujsq5+uRORgO+GoHC/RMwg7nMD8zknXRQSLMm/Cm8BMLLRSRK7apF7/LyWpv8oxU2 YXTSmGS15bt/Qu/rkCZ42V+80v0WkLiRQH3bWPp3/3yWzWZdoB0Xtccs5V1MHRBN01z9 BLNA== X-Gm-Message-State: AOJu0YxBMMyGeyB/vHdnU0JCQiVhpRuDCaGPLPyHXdNuWTArOV0gel4I P6udsm/v6ndRv+QABfygmylgiGCIAWhZd6jg/WrNJPhlT25/c+Nly4eIQ2uK6ouxLQqJg4J3SSK 1o/fM4ypMEKqLdoZsJaCCxxuoGfy33DxKYkofnw== X-Google-Smtp-Source: AGHT+IHTSXjXsedQfbYaMab8sgqSS02VapAz79RTO0Fvg/yylhTgZjbByhmUKb9jJo5zJVHoU0GXgVdX/WxN5ujpB54= X-Received: by 2002:a19:5e02:0:b0:517:8e01:266f with SMTP id s2-20020a195e02000000b005178e01266fmr9695706lfb.2.1713258222663; Tue, 16 Apr 2024 02:03:42 -0700 (PDT) MIME-Version: 1.0 References: <20240412111136.3470304-1-luca.vizzarro@arm.com> <20240412111136.3470304-5-luca.vizzarro@arm.com> In-Reply-To: <20240412111136.3470304-5-luca.vizzarro@arm.com> From: =?UTF-8?Q?Juraj_Linke=C5=A1?= Date: Tue, 16 Apr 2024 11:03:31 +0200 Message-ID: Subject: Re: [PATCH 4/5] dts: add `show port info` command to TestPmdShell To: Luca Vizzarro Cc: dev@dpdk.org, Jeremy Spewock , Paul Szczepanek Content-Type: text/plain; charset="UTF-8" Content-Transfer-Encoding: quoted-printable X-BeenThere: dev@dpdk.org X-Mailman-Version: 2.1.29 Precedence: list List-Id: DPDK patches and discussions List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Errors-To: dev-bounces@dpdk.org On Fri, Apr 12, 2024 at 1:11=E2=80=AFPM Luca Vizzarro wrote: > > Add a new TestPmdPort data structure to represent the output > returned by `show port info`, which is implemented as part of > TestPmdShell. > > The TestPmdPort data structure and its derived classes are modelled > based on the relevant testpmd source code. > > This implementation makes extensive use of regular expressions, which > all parse individually. The rationale behind this is to lower the risk > of the testpmd output changing as part of development. Therefore > minimising breakage. > > Bugzilla ID: 1407 > > Signed-off-by: Luca Vizzarro > Reviewed-by: Paul Szczepanek > +@dataclass > +class TestPmdPort(TextParser): This and the classes above are missing docstrings. > @@ -225,6 +664,38 @@ def set_forward_mode(self, mode: TestPmdForwardingMo= des, verify: bool =3D True): > f"Test pmd failed to set fwd mode to {mode.value}" > ) > > + def show_port_info_all(self) -> list[TestPmdPort]: > + """Returns the information of all the ports.""" Can we add sample output so that the format of what we're trying to parse is clear? > + output =3D self.send_command("show port info all") > + > + ports =3D [] > + iter =3D re.finditer(r"\*+.+\*+", output) > + if next(iter, False): # we are slicing retrospectively, skip fi= rst block > + start_pos =3D 0 > + for block in iter: > + end_pos =3D block.start() > + ports.append(TestPmdPort.parse(output[start_pos:end_pos]= )) > + start_pos =3D end_pos > + > + ports.append(TestPmdPort.parse(output[start_pos:])) > + > + return ports Can this be done the same way it's done in the last commit? iter =3D re.finditer(r"(^ #*.+#*$[^#]+)^ #*$", output, re.MULTILINE) return [TestPmdPortStats.parse(block.group(1)) for block in iter] Looks much better. > + > + def show_port_info(self, port_id: int) -> TestPmdPort: > + """Returns the given port information. > + > + Args: > + port_id: The port ID to gather information for. > + > + Raises: > + InteractiveCommandExecutionError: If `port_id` is invalid. > + """ > + output =3D self.send_command(f"show port info {port_id}", skip_f= irst_line=3DTrue) > + if output.startswith("Invalid port"): > + raise InteractiveCommandExecutionError("invalid port given") > + > + return TestPmdPort.parse(output) > + > def close(self) -> None: > """Overrides :meth:`~.interactive_shell.close`.""" > self.send_command("quit", "") > -- > 2.34.1 >