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 515BD43E74; Tue, 16 Apr 2024 14:24:19 +0200 (CEST) Received: from mails.dpdk.org (localhost [127.0.0.1]) by mails.dpdk.org (Postfix) with ESMTP id 104754029E; Tue, 16 Apr 2024 14:24:19 +0200 (CEST) Received: from foss.arm.com (foss.arm.com [217.140.110.172]) by mails.dpdk.org (Postfix) with ESMTP id 389C740262 for ; Tue, 16 Apr 2024 14:24:18 +0200 (CEST) Received: from usa-sjc-imap-foss1.foss.arm.com (unknown [10.121.207.14]) by usa-sjc-mx-foss1.foss.arm.com (Postfix) with ESMTP id D7C6A339; Tue, 16 Apr 2024 05:24:45 -0700 (PDT) Received: from [10.1.28.60] (FVFG51LCQ05N.cambridge.arm.com [10.1.28.60]) by usa-sjc-imap-foss1.foss.arm.com (Postfix) with ESMTPSA id 0D2E73F738; Tue, 16 Apr 2024 05:24:16 -0700 (PDT) Message-ID: <4f17ef06-c508-495a-a0f8-a28e9e77a1f9@arm.com> Date: Tue, 16 Apr 2024 13:24:15 +0100 MIME-Version: 1.0 User-Agent: Mozilla Thunderbird Subject: Re: [PATCH 4/5] dts: add `show port info` command to TestPmdShell Content-Language: en-GB To: =?UTF-8?Q?Juraj_Linke=C5=A1?= Cc: dev@dpdk.org, Jeremy Spewock , Paul Szczepanek References: <20240412111136.3470304-1-luca.vizzarro@arm.com> <20240412111136.3470304-5-luca.vizzarro@arm.com> From: Luca Vizzarro In-Reply-To: Content-Type: text/plain; charset=UTF-8; format=flowed Content-Transfer-Encoding: 8bit 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 16/04/2024 10:03, Juraj Linkeš wrote: >> +@dataclass >> +class TestPmdPort(TextParser): > > This and the classes above are missing docstrings. Ack. >> @@ -225,6 +664,38 @@ def set_forward_mode(self, mode: TestPmdForwardingModes, verify: bool = 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? Ack. >> + output = self.send_command("show port info all") >> + >> + ports = [] >> + iter = re.finditer(r"\*+.+\*+", output) >> + if next(iter, False): # we are slicing retrospectively, skip first block >> + start_pos = 0 >> + for block in iter: >> + end_pos = block.start() >> + ports.append(TestPmdPort.parse(output[start_pos:end_pos])) >> + start_pos = 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 = re.finditer(r"(^ #*.+#*$[^#]+)^ #*$", output, re.MULTILINE) > return [TestPmdPortStats.parse(block.group(1)) for block in iter] > > Looks much better. I agree that it looks much better. I gave it a first attempt to come up with a regular expression that is not too complicated and is able to match blocks individually. I've noticed that blocks start with: \n********* Infos for port X ************ but don't have an actual ending delimiter, unlike for the stats. I'll experiment with some look ahead constructs. The easiest solution is to match everything that is not * ([^*]+) but can we be certain that there won't be any asterisk in the actual information?