aboutsummaryrefslogtreecommitdiffstats
path: root/test/util.py
diff options
context:
space:
mode:
authorKlement Sekera <ksekera@cisco.com>2016-12-21 08:50:14 +0100
committerDamjan Marion <dmarion.lists@gmail.com>2016-12-23 17:38:33 +0000
commitdab231a11ec96e829b22ff80c612333edc5a93e6 (patch)
treee3440df2b4bc1af7a0e4973c0bfa839572d87c4d /test/util.py
parentfc262a0cf77e3c14ff1d6c006e7eac70999b926f (diff)
make test: improve handling of packet captures
Perform accounting of expected packets based on created packet infos. Use this accounting info to automatically expect (and verify) the correct number of packets to be captured. Automatically retry the read of the capture file if scapy raises an exception while doing so to handle rare cases when capture file is read while only partially written during busy wait. Don't fail assert_nothing_captured if only junk packets arrived. Change-Id: I16ec2e9410ef510d313ec16b7e13c57d0b2a63f5 Signed-off-by: Klement Sekera <ksekera@cisco.com>
Diffstat (limited to 'test/util.py')
-rw-r--r--test/util.py17
1 files changed, 7 insertions, 10 deletions
diff --git a/test/util.py b/test/util.py
index 0ac23760..6658febf 100644
--- a/test/util.py
+++ b/test/util.py
@@ -24,17 +24,14 @@ def ppc(headline, capture, limit=10):
"""
if not capture:
return headline
- result = headline + "\n"
- count = 1
- for p in capture:
- result.append(ppp("Packet #%s:" % count, p))
- count += 1
- if count >= limit:
- break
+ tail = ""
if limit < len(capture):
- result.append(
- "Capture contains %s packets in total, of which %s were printed" %
- (len(capture), limit))
+ tail = "\nPrint limit reached, %s out of %s packets printed" % (
+ len(capture), limit)
+ limit = len(capture)
+ body = "".join([ppp("Packet #%s:" % count, p)
+ for count, p in zip(range(0, limit), capture)])
+ return "%s\n%s%s" % (headline, body, tail)
class NumericConstant(object):