3
0
Fork 0
mirror of https://github.com/YosysHQ/sby.git synced 2025-04-06 14:24:08 +00:00

Add support for (re-)running in existing workdir

Signed-off-by: Clifford Wolf <clifford@clifford.at>
This commit is contained in:
Clifford Wolf 2019-03-09 12:42:54 -08:00
parent cef50242df
commit bd4094f216
6 changed files with 62 additions and 20 deletions

View file

@ -32,10 +32,12 @@ exe_paths = dict()
throw_err = False throw_err = False
dump_cfg = False dump_cfg = False
dump_tasks = False dump_tasks = False
reusedir = False
setupmode = False
def usage(): def usage():
print(""" print("""
sby [options] [<jobname>.sby [tasknames]] sby [options] [<jobname>.sby [tasknames] | <dirname>]
-d <dirname> -d <dirname>
set workdir name. default: <jobname> (without .sby) set workdir name. default: <jobname> (without .sby)
@ -69,13 +71,16 @@ sby [options] [<jobname>.sby [tasknames]]
--dumptasks --dumptasks
print the list of tasks print the list of tasks
--setup
set up the working directory and exit
""") """)
sys.exit(1) sys.exit(1)
try: try:
opts, args = getopt.getopt(sys.argv[1:], "d:btfT:E", ["yosys=", opts, args = getopt.getopt(sys.argv[1:], "d:btfT:E", ["yosys=",
"abc=", "smtbmc=", "suprove=", "aigbmc=", "avy=", "btormc=", "abc=", "smtbmc=", "suprove=", "aigbmc=", "avy=", "btormc=",
"dumpcfg", "dumptasks"]) "dumpcfg", "dumptasks", "setup"])
except: except:
usage() usage()
@ -110,12 +115,27 @@ for o, a in opts:
dump_cfg = True dump_cfg = True
elif o == "--dumptasks": elif o == "--dumptasks":
dump_tasks = True dump_tasks = True
elif o == "--setup":
setupmode = True
else: else:
usage() usage()
if len(args) > 0: if len(args) > 0:
sbyfile = args[0] sbyfile = args[0]
if not sbyfile.endswith(".sby"): if os.path.isdir(sbyfile):
workdir = sbyfile
sbyfile += "/config.sby"
reusedir = True
if not opt_force and os.path.exists(workdir + "/model"):
print("ERROR: Use -f to re-run in existing directory.", file=sys.stderr)
sys.exit(1)
if len(args) > 1:
print("ERROR: Can't use tasks when running in existing directory.", file=sys.stderr)
sys.exit(1)
if setupmode:
print("ERROR: Can't use --setup with existing directory.", file=sys.stderr)
sys.exit(1)
elif not sbyfile.endswith(".sby"):
print("ERROR: Sby file does not have .sby file extension.", file=sys.stderr) print("ERROR: Sby file does not have .sby file extension.", file=sys.stderr)
sys.exit(1) sys.exit(1)
@ -278,12 +298,18 @@ def run_job(taskname):
early_log(my_workdir, "Moving direcory '%s' to '%s'." % (my_workdir, "%s.bak%03d" % (my_workdir, backup_idx))) early_log(my_workdir, "Moving direcory '%s' to '%s'." % (my_workdir, "%s.bak%03d" % (my_workdir, backup_idx)))
shutil.move(my_workdir, "%s.bak%03d" % (my_workdir, backup_idx)) shutil.move(my_workdir, "%s.bak%03d" % (my_workdir, backup_idx))
if opt_force: if opt_force and not reusedir:
early_log(my_workdir, "Removing direcory '%s'." % (my_workdir)) early_log(my_workdir, "Removing direcory '%s'." % (my_workdir))
if sbyfile: if sbyfile:
shutil.rmtree(my_workdir, ignore_errors=True) shutil.rmtree(my_workdir, ignore_errors=True)
os.makedirs(my_workdir) if reusedir:
pass
elif os.path.isdir(my_workdir):
print("ERROR: Direcory '%s' already exists." % (my_workdir))
sys.exit(1)
else:
os.makedirs(my_workdir)
else: else:
my_opt_tmpdir = True my_opt_tmpdir = True
@ -302,16 +328,16 @@ def run_job(taskname):
junit_filename = "junit" junit_filename = "junit"
sbyconfig, _ = read_sbyconfig(sbydata, taskname) sbyconfig, _ = read_sbyconfig(sbydata, taskname)
job = SbyJob(sbyconfig, my_workdir, early_logmsgs) job = SbyJob(sbyconfig, my_workdir, early_logmsgs, reusedir)
for k, v in exe_paths.items(): for k, v in exe_paths.items():
job.exe_paths[k] = v job.exe_paths[k] = v
if throw_err: if throw_err:
job.run() job.run(setupmode)
else: else:
try: try:
job.run() job.run(setupmode)
except SbyAbort: except SbyAbort:
pass pass
@ -319,10 +345,13 @@ def run_job(taskname):
job.log("Removing direcory '%s'." % (my_workdir)) job.log("Removing direcory '%s'." % (my_workdir))
shutil.rmtree(my_workdir, ignore_errors=True) shutil.rmtree(my_workdir, ignore_errors=True)
job.log("DONE (%s, rc=%d)" % (job.status, job.retcode)) if setupmode:
job.log("SETUP COMPLETE (rc=%d)" % (job.retcode))
else:
job.log("DONE (%s, rc=%d)" % (job.status, job.retcode))
job.logfile.close() job.logfile.close()
if not my_opt_tmpdir: if not my_opt_tmpdir and not setupmode:
with open("%s/%s.xml" % (job.workdir, junit_filename), "w") as f: with open("%s/%s.xml" % (job.workdir, junit_filename), "w") as f:
junit_errors = 1 if job.retcode == 16 else 0 junit_errors = 1 if job.retcode == 16 else 0
junit_failures = 1 if job.retcode != 0 and junit_errors == 0 else 0 junit_failures = 1 if job.retcode != 0 and junit_errors == 0 else 0

View file

@ -18,7 +18,7 @@
import os, re, resource, sys import os, re, resource, sys
import subprocess, fcntl import subprocess, fcntl
from shutil import copyfile from shutil import copyfile, rmtree
from select import select from select import select
from time import time, localtime from time import time, localtime
@ -133,7 +133,7 @@ class SbyAbort(BaseException):
class SbyJob: class SbyJob:
def __init__(self, sbyconfig, workdir, early_logs): def __init__(self, sbyconfig, workdir, early_logs, reusedir):
self.options = dict() self.options = dict()
self.used_options = set() self.used_options = set()
self.engines = list() self.engines = list()
@ -142,6 +142,7 @@ class SbyJob:
self.verbatim_files = dict() self.verbatim_files = dict()
self.models = dict() self.models = dict()
self.workdir = workdir self.workdir = workdir
self.reusedir = reusedir
self.status = "UNKNOWN" self.status = "UNKNOWN"
self.total_time = 0 self.total_time = 0
self.expect = [] self.expect = []
@ -166,7 +167,7 @@ class SbyJob:
self.summary = list() self.summary = list()
self.logfile = open("%s/logfile.txt" % workdir, "w") self.logfile = open("%s/logfile.txt" % workdir, "a")
for line in early_logs: for line in early_logs:
print(line, file=self.logfile) print(line, file=self.logfile)
@ -223,6 +224,11 @@ class SbyJob:
print("ERROR: %s" % logmessage, file=f) print("ERROR: %s" % logmessage, file=f)
raise SbyAbort(logmessage) raise SbyAbort(logmessage)
def makedirs(self, path):
if self.reusedir and os.path.isdir(path):
rmtree(path, ignore_errors=True)
os.makedirs(path)
def copy_src(self): def copy_src(self):
os.makedirs(self.workdir + "/src") os.makedirs(self.workdir + "/src")
@ -273,7 +279,7 @@ class SbyJob:
self.__dict__["opt_" + option_name] = default_value self.__dict__["opt_" + option_name] = default_value
def make_model(self, model_name): def make_model(self, model_name):
if not os.path.exists("%s/model" % self.workdir): if not os.path.isdir("%s/model" % self.workdir):
os.makedirs("%s/model" % self.workdir) os.makedirs("%s/model" % self.workdir)
if model_name in ["base", "nomem"]: if model_name in ["base", "nomem"]:
@ -411,7 +417,7 @@ class SbyJob:
else: else:
assert 0 assert 0
def run(self): def run(self, setupmode):
mode = None mode = None
key = None key = None
@ -536,7 +542,14 @@ class SbyJob:
if engine[0] not in ["smtbmc", "btor"]: if engine[0] not in ["smtbmc", "btor"]:
self.error("Option skip is only valid for smtbmc and btor engines.") self.error("Option skip is only valid for smtbmc and btor engines.")
self.copy_src() if self.reusedir:
rmtree("%s/model" % self.workdir, ignore_errors=True)
else:
self.copy_src()
if setupmode:
self.retcode = 0
return
if self.opt_mode == "bmc": if self.opt_mode == "bmc":
import sby_mode_bmc import sby_mode_bmc

View file

@ -29,7 +29,7 @@ def run(job):
assert len(engine) > 0 assert len(engine) > 0
job.log("engine_%d: %s" % (engine_idx, " ".join(engine))) job.log("engine_%d: %s" % (engine_idx, " ".join(engine)))
os.makedirs("%s/engine_%d" % (job.workdir, engine_idx)) job.makedirs("%s/engine_%d" % (job.workdir, engine_idx))
if engine[0] == "smtbmc": if engine[0] == "smtbmc":
import sby_engine_smtbmc import sby_engine_smtbmc

View file

@ -28,7 +28,7 @@ def run(job):
assert len(engine) > 0 assert len(engine) > 0
job.log("engine_%d: %s" % (engine_idx, " ".join(engine))) job.log("engine_%d: %s" % (engine_idx, " ".join(engine)))
os.makedirs("%s/engine_%d" % (job.workdir, engine_idx)) job.makedirs("%s/engine_%d" % (job.workdir, engine_idx))
if engine[0] == "smtbmc": if engine[0] == "smtbmc":
import sby_engine_smtbmc import sby_engine_smtbmc

View file

@ -29,7 +29,7 @@ def run(job):
assert len(engine) > 0 assert len(engine) > 0
job.log("engine_%d: %s" % (engine_idx, " ".join(engine))) job.log("engine_%d: %s" % (engine_idx, " ".join(engine)))
os.makedirs("%s/engine_%d" % (job.workdir, engine_idx)) job.makedirs("%s/engine_%d" % (job.workdir, engine_idx))
if engine[0] == "aiger": if engine[0] == "aiger":
import sby_engine_aiger import sby_engine_aiger

View file

@ -36,7 +36,7 @@ def run(job):
assert len(engine) > 0 assert len(engine) > 0
job.log("engine_%d: %s" % (engine_idx, " ".join(engine))) job.log("engine_%d: %s" % (engine_idx, " ".join(engine)))
os.makedirs("%s/engine_%d" % (job.workdir, engine_idx)) job.makedirs("%s/engine_%d" % (job.workdir, engine_idx))
if engine[0] == "smtbmc": if engine[0] == "smtbmc":
import sby_engine_smtbmc import sby_engine_smtbmc