[PATCH v1 2/2] dts: add exception handling to checksum verify method
Luca Vizzarro
Luca.Vizzarro at arm.com
Tue Jul 29 14:40:26 CEST 2025
On 22/07/2025 18:22, Dean Marx wrote:
> --- a/dts/tests/TestSuite_checksum_offload.py
> +++ b/dts/tests/TestSuite_checksum_offload.py
> @@ -89,8 +89,11 @@ def send_packet_and_verify_checksum(
> if testpmd_packet.l4_dport == id:
> is_IP = PacketOffloadFlag.RTE_MBUF_F_RX_IP_CKSUM_GOOD in testpmd_packet.ol_flags
> is_L4 = PacketOffloadFlag.RTE_MBUF_F_RX_L4_CKSUM_GOOD in testpmd_packet.ol_flags
> - self.verify(is_L4 == good_L4, "Layer 4 checksum flag did not match expected checksum flag.")
> - self.verify(is_IP == good_IP, "IP checksum flag did not match expected checksum flag.")
> + try:
> + self.verify(is_L4 == good_L4, "Layer 4 checksum flag did not match expected checksum flag.")
> + self.verify(is_IP == good_IP, "IP checksum flag did not match expected checksum flag.")
> + except NameError:
> + self.verify(False, "Test packet was dropped when it should have been received.")
Doesn't really look like the right approach. As it stands I can't tell
from the code at first glance why are we checking for NameError. I am
guessing this is because is_L4 is_IP weren't set. We shouldn't cause
Python to fail on their inexistence and then recover. We should rather
verify that they exist.
I'd propose to set is_L4 and is_IP to None at the beginning of the
method. Then after the for loop, check that they are not None through
self.verify. If mypy becomes unhappy because it can't compare bool with
bool | None, then verify the non-nullness with an if and do
self.verify(False, ...) as you are doing already. This will guarantee to
mypy that the variables won't be None afterwards.
More information about the dev
mailing list