From 23ab5d2eb7cbbbad81e03dd429ecf31615d4ef3a Mon Sep 17 00:00:00 2001 From: Leon Schuermann Date: Thu, 18 Nov 2021 19:10:21 +0100 Subject: [PATCH] test_stream: allow premature stopping of the stream_collector Support passing a stop_cond function which can cause the stream_collector to exit on a user-defined condition. Signed-off-by: Leon Schuermann --- test/test_stream.py | 9 +++++++++ 1 file changed, 9 insertions(+) diff --git a/test/test_stream.py b/test/test_stream.py index eeec46c..a1a2f51 100644 --- a/test/test_stream.py +++ b/test/test_stream.py @@ -187,6 +187,7 @@ def stream_collector( source, dest=[], expect_npackets=None, + stop_cond=None, seed=42, ready_rand=50, debug_print=False): @@ -194,6 +195,10 @@ def stream_collector( `source`. If `source` has a `last_be` signal, that is respected properly. + `stop_cond` can be passed a function which is invoked whenever the + collector has a chance to cease operations (when a packet has been + fully read). If when invoked it returns true, this function will + exit. """ prng = random.Random(seed) @@ -219,6 +224,10 @@ def stream_collector( # Loop for collecting individual packets, separated by source.last while expect_npackets == None or len(dest) < expect_npackets: + if stop_cond is not None: + if stop_cond(): + break + # Buffer for the current packet collected_bytes = [] param_signal_states = {}