def test(self): logging.basicConfig(level=logging.DEBUG) pkts = PcapReader.read("test.pcap") for p in pkts: for layer_name in VALID_LAYER_NAMES: if layer_name == 'lowpan': # we already checked 6lowpan continue layer = getattr(p, layer_name) if hasattr(p._packet, layer_name): if layer_name in REAL_LAYER_NAMES: self.assertTrue(layer) checker = getattr(self, '_test_' + layer_name, None) if checker is None: continue try: checker(p) except Exception: layer.show() raise self._check_missing_fields(p, layer_name, getattr(p._packet, layer_name)) else: if layer_name in REAL_LAYER_NAMES: self.assertFalse(layer)
def __init__(self, test_info_path, wireshark_prefs=None): logging.basicConfig( level=logging.INFO, format='File "%(pathname)s", line %(lineno)d, in %(funcName)s\n' '%(asctime)s - %(levelname)s - %(message)s') ti = TestInfo(test_info_path) if wireshark_prefs is not None: pkts = PcapReader.read(ti.pcap_path, wireshark_prefs) else: pkts = PcapReader.read(ti.pcap_path) print('loaded %d packets from %s' % (len(pkts), ti.pcap_path)) self.pkts = pkts self.test_info = ti self.summary = Summary(pkts, ti) self._vars = {} self._add_initial_vars()