def create_messages(stream, from_file=False): if from_file is False: stream.seek(0) buf = stream.read() client = DLTClient() client.receiver.buf = ctypes.create_string_buffer(buf) client.receiver.bytesRcvd = len(buf) return client.read_message() _, tmpname = tempfile.mkstemp(suffix=b"") tmpfile = open(tmpname, "wb") tmpfile.write(stream) tmpfile.flush() tmpfile.seek(0) tmpfile.close() atexit.register(os.remove, tmpname) msgs = load(tmpname) return msgs
def run_analyse(self, traces, xunit, no_sort, is_live, testsuite_name="dltlyse"): """Read the DLT trace and call each plugin for each message read""" filters = self.get_filters() # add filter for lifecycle start message in case it is missing # filters == None means no filtering is done at all flt = (DLT_LIFECYCLE_START["apid"].encode("utf-8"), DLT_LIFECYCLE_START["ctid"].encode("utf-8")) if filters and flt not in filters: filters.append(flt) old_lifecycle = None lifecycle = None last_msg = None lifecycle_id = 0 self.traces = traces if is_live: signal.signal(signal.SIGINT, self.stop_signal_handler) for filename in traces: logger.info("Reading trace file '%s'", filename) with self.handle_file_exceptions(filename): tracefile = dlt.load(filename, split=not no_sort, filters=filters, live_run=is_live) self.dlt_file = tracefile msg = None for msg in tracefile: is_start_msg = msg.compare(DLT_LIFECYCLE_START) bufferable_msg = any( msg.compare(trace) for trace in buffer_matches) # Buffer Messages if we find special # marked msgs that should be buffered # don't process these messages yet in this lifecycle if bufferable_msg and len( self._buffered_traces) < MAX_BUFFER_SIZE: self._buffered_traces.append(msg) continue # We found a start message, if this is the first ever then just start a new lifecycle, # process any buffered messages and proceed. If we already have a lifecycle, then end that # lifecycle and proceed as previously stated. if is_start_msg: if lifecycle: lifecycle.set_last_msg(last_msg) self.end_lifecycle(lifecycle, lifecycle.lifecycle_id) lifecycle_id += 1 lifecycle = self.setup_lifecycle( msg=msg, lifecycle_id=lifecycle_id) logger.info("DLT Analysis Starting life cycle %d", lifecycle.lifecycle_id) if not lifecycle: lifecycle = self.setup_lifecycle( msg, lifecycle_id=lifecycle_id, process_buffer=True) self.process_buffer() self.process_message(msg) last_msg = msg if lifecycle: lifecycle.set_last_msg(last_msg) old_lifecycle = lifecycle # If the files only contained bufferable traces less than MAX_BUFFER_SIZE # we create a life_cycle 0 to accommodate these msgs if not lifecycle and self._buffered_traces: lifecycle = self.setup_lifecycle(msg=msg, lifecycle_id=lifecycle_id, process_buffer=True) old_lifecycle = lifecycle if old_lifecycle: self.process_buffer() self.end_lifecycle(old_lifecycle, lifecycle_id) return self.generate_reports(xunit, testsuite_name)