Added verify to match_all_packets function that if False and there are missing packets causes the function to return False, if all packets are present it returns True.
Signed-off-by: Thomas Wilks <thomas.wi...@arm.com> --- Reviewed-by: Luca Vizzarro <luca.vizza...@arm.com> Reviewed-by: Paul Szczepanek <paul.szczepa...@arm.com> --- dts/framework/test_suite.py | 23 +++++++++++++++++------ 1 file changed, 17 insertions(+), 6 deletions(-) diff --git a/dts/framework/test_suite.py b/dts/framework/test_suite.py index de9f871b3f..f5d3e3e545 100644 --- a/dts/framework/test_suite.py +++ b/dts/framework/test_suite.py @@ -422,8 +422,11 @@ 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: + self, + expected_packets: list[Packet], + received_packets: list[Packet], + verify: bool = True, + ) -> bool: """Matches all the expected packets against the received ones. Matching is performed by counting down the occurrences in a dictionary which keys are the @@ -433,10 +436,14 @@ def match_all_packets( Args: expected_packets: The packets we are expecting to receive. received_packets: All the packets that were received. + verify: If :data:`True`, and there are missing packets an exception will be raised. Raises: TestCaseVerifyError: if and not all the `expected_packets` were found in `received_packets`. + + Returns: + :data:`True` If there are no missing packets. """ expected_packets_counters = Counter(map(raw, expected_packets)) received_packets_counters = Counter(map(raw, received_packets)) @@ -450,10 +457,14 @@ def match_all_packets( ) 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." - ) + if verify: + self._fail_test_case_verify( + f"Not all packets were received, expected {len(expected_packets)} " + f"but {missing_packets_count} were missing." + ) + return False + + return True def _compare_packets(self, expected_packet: Packet, received_packet: Packet) -> bool: self._logger.debug( -- 2.43.0