def shutdown(self): log_qemu("Shutting down Qemu after %d execs.." % self.persistent_runs, self.qemu_id) if not self.process: # start() has never been called, all files/shm are closed. return 0 # If Qemu exists, try to graciously read its I/O and SIGTERM it. # If still alive, attempt SIGKILL or loop-wait on kill -9. output = "<no output received>\n" try: self.process.terminate() output = strdump(self.process.communicate(timeout=1)[0], verbatim=True) except: pass if self.process.returncode is None: try: self.process.kill() except: pass log_qemu("Qemu exit code: %s" % str(self.process.returncode), self.qemu_id) header = "\n=================<Qemu %s Console Output>==================\n" % self.qemu_id footer = "====================</Console Output>======================\n" log_qemu(header + output + footer, self.qemu_id) header = "\n=================<Qemu %s Serial Output>==================\n" % self.qemu_id footer = "====================</Serial Output>======================\n" serial_out = strdump(read_binary_file(self.qemu_serial_log), verbatim=True) log_qemu(header + serial_out + footer, self.qemu_id) try: self.kafl_shm.close() except: pass try: self.fs_shm.close() except: pass try: os.close(self.kafl_shm_f) except: pass try: os.close(self.fs_shm_f) except: pass try: if self.stat_fd: self.stat_fd.close() except: pass return self.process.returncode
def __process_node(self, nodefile): node = self.__read_msgpack(nodefile) node_id = int(nodefile.split("_")[-1]) payload = self.__read_payload(node_id, node["info"]["exit_reason"]) sample = strdump(payload) plen = node.get("payload_len", 1) perf = node["info"].get("performance", 0.1) favs = node.get("fav_bits", "") level = node.get("level") exit = node["info"]["exit_reason"] parent = node["info"]["parent"] method = node["info"]["method"] stage = node["state"]["name"] t_total = node["info"]["time"] - self.global_startup t_hours, t_tmp = divmod(t_total, 3600) t_mins, t_secs = divmod(t_tmp, 60) t_str = ('{:02}:{:02}:{:02}'.format(int(t_hours), int(t_mins), int(t_secs))) # score as used by new scheduler/queue sorting score = node.get("score", 0) if stage in ["final"]: score = score / node.get("state_time_havoc", 1) if exit == "regular": if node["state"]["name"] == "final": color = "green" else: color = "blue" elif exit == "crash": color = "red" elif exit == "kasan": color = "orange" elif exit == "timeout": color = "grey" print( "%s: Found %3d from %3d using %s [%s] (favs=%d, stage=%s, exit=%s, lvl=%d, perf=%.2f, score=%.2f, t=%.2f)" % (t_str, node_id, parent, method[:12].ljust(12), sample[:42].ljust(42), len(favs), stage[:8], exit[:1].title(), level, perf, score, node.get("state_time_havoc", 0))) self.dot.add_node(node["id"], label="%s\n[id=%02d, score=%2.2f]\n%s" % (sample[:12], node_id, score, exit), color=color) self.dot.add_edge(parent, node["id"], headlabel=method, arrowhead='open') return True