[PATCH 4/5] dts: add `show port info` command to TestPmdShell
Luca Vizzarro
Luca.Vizzarro at arm.com
Tue Apr 16 14:24:15 CEST 2024
On 16/04/2024 10:03, Juraj Linkeš wrote:
>> + at 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?
More information about the dev
mailing list