[PATCH v2 1/5] dts: add ability to send/receive multiple packets

Juraj Linkeš juraj.linkes at pantheon.tech
Fri Aug 23 12:17:14 CEST 2024


This is a nice improvement. The comment below won't necessarily results 
in any changes, so:
Reviewed-by: Juraj Linkeš <juraj.linkes at pantheon.tech>

> diff --git a/dts/framework/test_suite.py b/dts/framework/test_suite.py

> @@ -303,6 +329,40 @@ def verify_packets(self, expected_packet: Packet, received_packets: list[Packet]
>               )
>               self._fail_test_case_verify("An expected packet not found among received packets.")
>   
> +    def match_all_packets(
> +        self, expected_packets: list[Packet], received_packets: list[Packet]
> +    ) -> None:
> +        """Matches all the expected packets against the received ones.
> +
> +        Matching is performed by counting down the occurrences in a dictionary which keys are the
> +        raw packet bytes. No deep packet comparison is performed. All the unexpected packets (noise)
> +        are automatically ignored.
> +
> +        Args:
> +            expected_packets: The packets we are expecting to receive.
> +            received_packets: All the packets that were received.
> +
> +        Raises:
> +            TestCaseVerifyError: if and not all the `expected_packets` were found in
> +                `received_packets`.
> +        """
> +        expected_packets_counters = Counter(map(raw, expected_packets))
> +        received_packets_counters = Counter(map(raw, received_packets))
> +        # The number of expected packets is subtracted by the number of received packets, ignoring
> +        # any unexpected packets and capping at zero.
> +        missing_packets_counters = expected_packets_counters - received_packets_counters
> +        missing_packets_count = missing_packets_counters.total()
> +        self._logger.debug(
> +            f"match_all_packets: expected {len(expected_packets)}, "
> +            f"received {len(received_packets)}, missing {missing_packets_count}"
> +        )
> +
> +        if missing_packets_count != 0:
> +            self._fail_test_case_verify(
> +                f"Not all packets were received, expected {len(expected_packets)} "
> +                f"but {missing_packets_count} were missing."
> +            )
> +

Is it worthwhile to log the missing packets? It's not necessary, as the 
received packets are logged elsewhere, but it would be convenient. On 
the other hand, it could just unnecessarily bloat logs.



More information about the dev mailing list