2015-08-28 13:47:28 +08:00
|
|
|
import sys, os
|
|
|
|
|
2015-10-13 19:57:19 +08:00
|
|
|
from artiq.master.databases import DeviceDB
|
2015-08-28 13:47:28 +08:00
|
|
|
from artiq.master.worker_db import DeviceManager
|
|
|
|
|
2016-04-29 21:05:11 +08:00
|
|
|
import artiq.coredevice.core
|
2015-08-28 13:47:28 +08:00
|
|
|
from artiq.coredevice.core import Core, CompileError
|
|
|
|
|
2016-04-29 21:05:11 +08:00
|
|
|
def _render_diagnostic(diagnostic, colored):
|
|
|
|
return "\n".join(diagnostic.render(only_line=True))
|
|
|
|
|
|
|
|
artiq.coredevice.core._render_diagnostic = _render_diagnostic
|
|
|
|
|
2015-08-28 13:47:28 +08:00
|
|
|
def main():
|
2015-12-26 03:17:26 +08:00
|
|
|
if len(sys.argv) > 1 and sys.argv[1] == "+diag":
|
|
|
|
del sys.argv[1]
|
|
|
|
diag = True
|
|
|
|
else:
|
|
|
|
diag = False
|
|
|
|
|
2015-10-09 06:24:44 +08:00
|
|
|
if len(sys.argv) > 1 and sys.argv[1] == "+compile":
|
|
|
|
del sys.argv[1]
|
|
|
|
compile_only = True
|
|
|
|
else:
|
|
|
|
compile_only = False
|
|
|
|
|
2017-05-18 23:14:20 +08:00
|
|
|
ddb_path = os.path.join(os.path.dirname(sys.argv[1]), "device_db.py")
|
2015-11-24 02:02:34 +08:00
|
|
|
dmgr = DeviceManager(DeviceDB(ddb_path))
|
|
|
|
|
2015-08-28 13:47:28 +08:00
|
|
|
with open(sys.argv[1]) as f:
|
|
|
|
testcase_code = compile(f.read(), f.name, "exec")
|
2015-11-24 02:02:34 +08:00
|
|
|
testcase_vars = {'__name__': 'testbench', 'dmgr': dmgr}
|
2015-08-28 13:47:28 +08:00
|
|
|
exec(testcase_code, testcase_vars)
|
|
|
|
|
|
|
|
try:
|
2015-11-24 02:02:34 +08:00
|
|
|
core = dmgr.get("core")
|
2015-10-09 06:24:44 +08:00
|
|
|
if compile_only:
|
|
|
|
core.compile(testcase_vars["entrypoint"], (), {})
|
|
|
|
else:
|
|
|
|
core.run(testcase_vars["entrypoint"], (), {})
|
|
|
|
print(core.comm.get_log())
|
|
|
|
core.comm.clear_log()
|
2015-08-28 13:47:28 +08:00
|
|
|
except CompileError as error:
|
2015-12-26 03:17:26 +08:00
|
|
|
if not diag:
|
|
|
|
exit(1)
|
2015-08-28 13:47:28 +08:00
|
|
|
|
|
|
|
if __name__ == "__main__":
|
|
|
|
main()
|