in flexsai/p4/backend/json_stage/bmv2stf.py [0:0]
def checkOutputs(self):
if self.options.verbose:
print("Comparing outputs")
direction = "out"
for file in glob(self.filename('*', direction)):
interface = self.interface_of_filename(file)
if os.stat(file).st_size == 0:
packets = []
else:
try:
packets = rdpcap(file)
except:
reportError("Corrupt pcap file", file)
self.showLog()
return FAILURE
# Log packets.
if self.options.observationLog:
observationLog = open(self.options.observationLog, 'w')
for pkt in packets:
observationLog.write('%d %s\n' % (
interface,
''.join(ByteToHex(str(pkt)).split()).upper()))
observationLog.close()
# Check for expected packets.
if interface not in self.expected:
# This continue can falsely make a test succeed, if the
# interface type is not the one stored in expected. We need to
# be more careful on declaring success.
#
# One possible fix is to check for all expected and determine
# which file to look into, or, remove the ones we found from the
# self.expected list, and return success only if the list is
# empty. The latter is what is implemented below.
continue
expected = self.expected[interface]
if len(expected) != len(packets):
reportError("Expected", len(expected), "packets on port", str(interface),
"got", len(packets))
self.showLog()
return FAILURE
for i in range(0, len(expected)):
cmp = self.comparePacket(expected[i], packets[i])
if cmp != SUCCESS:
reportError("Packet", i, "on port", str(interface), "differs")
return FAILURE
# remove successfully checked interfaces
del self.expected[interface]
if len(self.expected) != 0:
# didn't find all the expects we were expecting
reportError("Expected packects on ports", self.expected.keys(), "not received")
return FAILURE
else:
return SUCCESS