summaryrefslogtreecommitdiffstats
path: root/test/vpp_pg_interface.py
diff options
context:
space:
mode:
authorKlement Sekera <klement@graphiant.com>2022-02-18 10:35:08 +0000
committerKlement Sekera <klement.sekera@gmail.com>2022-02-24 12:51:33 +0000
commit26cd0242c95025e0d644db3a80dfe8dee83b6d7a (patch)
tree40051a3d6efd96a57745f371910116bd9f9f5497 /test/vpp_pg_interface.py
parent40cfc1560ee6fa11e4d6c74e9730541a8a45b68a (diff)
tests: better reporting for unexpected packets
Raise a new UnexpectedPacketErrror, when a packet is captured unexpectedly. This pretty-prints a terse description of said packet. Type: improvement Signed-off-by: Klement Sekera <klement.sekera@gmail.com> Change-Id: Ibac19fc5bbd82a150fec3c90940a37af6344fd4f
Diffstat (limited to 'test/vpp_pg_interface.py')
-rw-r--r--test/vpp_pg_interface.py23
1 files changed, 15 insertions, 8 deletions
diff --git a/test/vpp_pg_interface.py b/test/vpp_pg_interface.py
index 01f10fccfc9..434a3005bd7 100644
--- a/test/vpp_pg_interface.py
+++ b/test/vpp_pg_interface.py
@@ -16,7 +16,7 @@ from scapy.layers.l2 import Ether, ARP
from scapy.layers.inet6 import IPv6, ICMPv6ND_NS, ICMPv6ND_NA,\
ICMPv6NDOptSrcLLAddr, ICMPv6NDOptDstLLAddr, ICMPv6ND_RA, RouterAlert, \
IPv6ExtHdrHopByHop
-from util import ppp, ppc
+from util import ppp, ppc, UnexpectedPacketError
from scapy.utils6 import in6_getnsma, in6_getnsmac, in6_ismaddr
@@ -287,13 +287,19 @@ class VppPGInterface(VppInterface):
remaining_time -= elapsed_time
if capture:
self.generate_debug_aid("count-mismatch")
+ if len(capture) > 0 and 0 == expected_count:
+ rem = f"\n{remark}" if remark else ""
+ raise UnexpectedPacketError(
+ capture[0],
+ f"\n({len(capture)} packets captured in total){rem}")
raise Exception("Captured packets mismatch, captured %s packets, "
"expected %s packets on %s" %
(len(capture.res), expected_count, name))
else:
raise Exception("No packets captured on %s" % name)
- def assert_nothing_captured(self, remark=None, filter_out_fn=is_ipv6_misc):
+ def assert_nothing_captured(self, timeout=1, remark=None,
+ filter_out_fn=is_ipv6_misc):
""" Assert that nothing unfiltered was captured on interface
:param remark: remark printed into debug logs
@@ -303,7 +309,8 @@ class VppPGInterface(VppInterface):
if os.path.isfile(self.out_path):
try:
capture = self.get_capture(
- 0, remark=remark, filter_out_fn=filter_out_fn)
+ 0, timeout=timeout, remark=remark,
+ filter_out_fn=filter_out_fn)
if not capture or len(capture.res) == 0:
# junk filtered out, we're good
return
@@ -311,12 +318,12 @@ class VppPGInterface(VppInterface):
pass
self.generate_debug_aid("empty-assert")
if remark:
- raise AssertionError(
- "Non-empty capture file present for interface %s (%s)" %
- (self.name, remark))
+ raise UnexpectedPacketError(
+ capture[0],
+ f" ({len(capture)} packets captured in total) ({remark})")
else:
- raise AssertionError("Capture file present for interface %s" %
- self.name)
+ raise UnexpectedPacketError(
+ capture[0], f" ({len(capture)} packets captured in total)")
def wait_for_pg_stop(self):
# wait till packet-generator is stopped