def run(self, setupmode): mode = None key = None with open("{}/config.sby".format(self.workdir), "r") as f: for line in f: raw_line = line if mode in ["options", "engines", "files"]: line = re.sub(r"\s*(\s#.*)?$", "", line) if line == "" or line[0] == "#": continue else: line = line.rstrip() # print(line) if mode is None and (len(line) == 0 or line[0] == "#"): continue match = re.match(r"^\s*\[(.*)\]\s*$", line) if match: entries = match.group(1).split() if len(entries) == 0: self.error("sby file syntax error: {}".format(line)) if entries[0] == "options": mode = "options" if len(self.options) != 0 or len(entries) != 1: self.error( "sby file syntax error: {}".format(line)) continue if entries[0] == "engines": mode = "engines" if len(self.engines) != 0 or len(entries) != 1: self.error( "sby file syntax error: {}".format(line)) continue if entries[0] == "script": mode = "script" if len(self.script) != 0 or len(entries) != 1: self.error( "sby file syntax error: {}".format(line)) continue if entries[0] == "file": mode = "file" if len(entries) != 2: self.error( "sby file syntax error: {}".format(line)) current_verbatim_file = entries[1] if current_verbatim_file in self.verbatim_files: self.error("duplicate file: {}".format(entries[1])) self.verbatim_files[current_verbatim_file] = list() continue if entries[0] == "files": mode = "files" if len(entries) != 1: self.error( "sby file syntax error: {}".format(line)) continue self.error("sby file syntax error: {}".format(line)) if mode == "options": entries = line.split() if len(entries) != 2: self.error("sby file syntax error: {}".format(line)) self.options[entries[0]] = entries[1] continue if mode == "engines": entries = line.split() self.engines.append(entries) continue if mode == "script": self.script.append(line) continue if mode == "files": entries = line.split() if len(entries) == 1: self.files[os.path.basename(entries[0])] = entries[0] elif len(entries) == 2: self.files[entries[0]] = entries[1] else: self.error("sby file syntax error: {}".format(line)) continue if mode == "file": self.verbatim_files[current_verbatim_file].append(raw_line) continue self.error("sby file syntax error: {}".format(line)) self.handle_str_option("mode", None) if self.opt_mode not in ["bmc", "prove", "cover", "live"]: self.error("Invalid mode: {}".format(self.opt_mode)) self.expect = ["PASS"] if "expect" in self.options: self.expect = self.options["expect"].upper().split(",") self.used_options.add("expect") for s in self.expect: if s not in ["PASS", "FAIL", "UNKNOWN", "ERROR", "TIMEOUT"]: self.error("Invalid expect value: {}".format(s)) self.handle_bool_option("multiclock", False) self.handle_bool_option("wait", False) self.handle_int_option("timeout", None) self.handle_str_option("smtc", None) self.handle_int_option("skip", None) self.handle_str_option("tbtop", None) if self.opt_smtc is not None: for engine in self.engines: if engine[0] != "smtbmc": self.error("Option smtc is only valid for smtbmc engine.") if self.opt_skip is not None: if self.opt_skip == 0: self.opt_skip = None else: for engine in self.engines: if engine[0] not in ["smtbmc", "btor"]: self.error( "Option skip is only valid for smtbmc and btor engines." ) if len(self.engines) == 0: self.error("Config file is lacking engine configuration.") if self.reusedir: rmtree("{}/model".format(self.workdir), ignore_errors=True) else: self.copy_src() if setupmode: self.retcode = 0 return if self.opt_mode == "bmc": import sby_mode_bmc sby_mode_bmc.run(self) elif self.opt_mode == "prove": import sby_mode_prove sby_mode_prove.run(self) elif self.opt_mode == "live": import sby_mode_live sby_mode_live.run(self) elif self.opt_mode == "cover": import sby_mode_cover sby_mode_cover.run(self) else: assert False for opt in self.options.keys(): if opt not in self.used_options: self.error("Unused option: {}".format(opt)) self.taskloop() total_clock_time = int(time() - self.start_clock_time) if os.name == "posix": ru = resource.getrusage(resource.RUSAGE_CHILDREN) total_process_time = int((ru.ru_utime + ru.ru_stime) - self.start_process_time) self.total_time = total_process_time self.summary = [ "Elapsed clock time [H:MM:SS (secs)]: {}:{:02d}:{:02d} ({})". format(total_clock_time // (60 * 60), (total_clock_time // 60) % 60, total_clock_time % 60, total_clock_time), "Elapsed process time [H:MM:SS (secs)]: {}:{:02d}:{:02d} ({})". format(total_process_time // (60 * 60), (total_process_time // 60) % 60, total_process_time % 60, total_process_time), ] + self.summary else: self.summary = [ "Elapsed clock time [H:MM:SS (secs)]: {}:{:02d}:{:02d} ({})". format(total_clock_time // (60 * 60), (total_clock_time // 60) % 60, total_clock_time % 60, total_clock_time), "Elapsed process time unvailable on Windows" ] + self.summary for line in self.summary: self.log("summary: {}".format(line)) assert self.status in ["PASS", "FAIL", "UNKNOWN", "ERROR", "TIMEOUT"] if self.status in self.expect: self.retcode = 0 else: if self.status == "PASS": self.retcode = 1 if self.status == "FAIL": self.retcode = 2 if self.status == "UNKNOWN": self.retcode = 4 if self.status == "TIMEOUT": self.retcode = 8 if self.status == "ERROR": self.retcode = 16 with open("{}/{}".format(self.workdir, self.status), "w") as f: for line in self.summary: print(line, file=f)
def run(self): self.handle_str_option("mode", None) assert self.opt_mode in ["bmc", "prove", "cover", "live"] self.expect = ["PASS"] if "expect" in self.options: self.expect = self.options["expect"].upper().split(",") self.used_options.add("expect") for s in self.expect: assert s in ["PASS", "FAIL", "UNKNOWN", "ERROR", "TIMEOUT"] self.handle_bool_option("wait", False) self.handle_int_option("timeout", None) self.handle_str_option("smtc", None) self.handle_str_option("tbtop", None) if self.opt_smtc is not None: for engine in self.engines: assert engine[0] == "smtbmc" self.copy_src() if self.opt_mode == "bmc": import sby_mode_bmc sby_mode_bmc.run(self) elif self.opt_mode == "prove": import sby_mode_prove sby_mode_prove.run(self) elif self.opt_mode == "live": import sby_mode_live sby_mode_live.run(self) elif self.opt_mode == "cover": import sby_mode_cover sby_mode_cover.run(self) else: assert False for opt in self.options.keys(): assert opt in self.used_options self.taskloop() total_clock_time = int(time() - self.start_clock_time) ru = resource.getrusage(resource.RUSAGE_CHILDREN) total_process_time = int((ru.ru_utime + ru.ru_stime) - self.start_process_time) self.summary = [ "Elapsed clock time [H:MM:SS (secs)]: %d:%02d:%02d (%d)" % (total_clock_time // (60 * 60), (total_clock_time // 60) % 60, total_clock_time % 60, total_clock_time), "Elapsed process time [H:MM:SS (secs)]: %d:%02d:%02d (%d)" % (total_process_time // (60 * 60), (total_process_time // 60) % 60, total_process_time % 60, total_process_time), ] + self.summary for line in self.summary: self.log("summary: %s" % line) assert self.status in ["PASS", "FAIL", "UNKNOWN", "ERROR", "TIMEOUT"] if self.status in self.expect: self.retcode = 0 else: if self.status == "PASS": self.retcode = 1 if self.status == "FAIL": self.retcode = 2 if self.status == "ERROR": self.retcode = 3 if self.status == "UNKNOWN": self.retcode = 4 if self.status == "TIMEOUT": self.retcode = 5 with open("%s/%s" % (self.workdir, self.status), "w") as f: for line in self.summary: print(line, file=f)