forked from M-Labs/artiq
1
0
Fork 0

artiq_run: use new dpdb, report changed parameters, remove function parameter, support run arguments

This commit is contained in:
Sebastien Bourdeauducq 2015-01-07 19:21:17 +08:00
parent b63b46786e
commit 492ce1632b
1 changed files with 38 additions and 17 deletions

View File

@ -8,23 +8,23 @@ from operator import itemgetter
from artiq.management.file_import import file_import from artiq.management.file_import import file_import
from artiq.language.context import * from artiq.language.context import *
from artiq.management import pyon from artiq.management import pyon
from artiq.management.dpdb import DeviceParamDB from artiq.management.dpdb import DeviceParamDB, DeviceParamSupplier
class ELFRunner(AutoContext): class ELFRunner(AutoContext):
comm = Device("comm") comm = Device("comm")
implicit_core = False implicit_core = False
def run(self, filename, function): def run(self, filename):
with open(filename, "rb") as f: with open(filename, "rb") as f:
binary = f.read() binary = f.read()
comm.load(binary) comm.load(binary)
comm.run(function) comm.run("run")
comm.serve(dict(), dict()) comm.serve(dict(), dict())
def _get_args(): def _get_args():
parser = argparse.ArgumentParser(description="Experiment running tool") parser = argparse.ArgumentParser(description="Local running tool")
parser.add_argument("-d", "--ddb", default="ddb.pyon", parser.add_argument("-d", "--ddb", default="ddb.pyon",
help="device database file") help="device database file")
@ -33,26 +33,36 @@ def _get_args():
parser.add_argument("-e", "--elf", default=False, action="store_true", parser.add_argument("-e", "--elf", default=False, action="store_true",
help="run ELF binary") help="run ELF binary")
parser.add_argument("-f", "--function", default="run",
help="function to run")
parser.add_argument("-u", "--unit", default=None, parser.add_argument("-u", "--unit", default=None,
help="unit to run") help="unit to run")
parser.add_argument("file", parser.add_argument("file",
help="file containing the unit to run") help="file containing the unit to run")
parser.add_argument("arguments", nargs="*",
help="run arguments")
return parser.parse_args() return parser.parse_args()
def _parse_arguments(arguments):
d = {}
for argument in arguments:
name, value = argument.split("=")
d[name] = pyon.decode(value)
return d
def main(): def main():
args = _get_args() args = _get_args()
devices = pyon.load_file(args.ddb) dpdb = DeviceParamDB(args.ddb, args.pdb)
parameters = pyon.load_file(args.pdb) dps = DeviceParamSupplier(dpdb.req_device, dpdb.req_parameter)
dpdb = DeviceParamDB(devices, parameters)
try: try:
if args.elf: if args.elf:
unit_inst = ELFRunner(dpdb) if args.arguments:
unit_inst.run(args.file, args.function) print("Run arguments are not supported in ELF mode")
sys.exit(1)
unit_inst = ELFRunner(dps)
unit_inst.run(args.file)
else: else:
module = file_import(args.file) module = file_import(args.file)
if args.unit is None: if args.unit is None:
@ -75,11 +85,22 @@ def main():
unit = units[0][1] unit = units[0][1]
else: else:
unit = getattr(module, args.unit) unit = getattr(module, args.unit)
unit_inst = unit(dpdb)
f = getattr(unit_inst, args.function) try:
f() arguments = _parse_arguments(args.arguments)
except:
print("Failed to parse run arguments")
sys.exit(1)
unit_inst = unit(dps)
unit_inst.run(**arguments)
if dps.parameter_wb:
print("Modified parameters:")
for requester, name in dps.parameter_wb:
print("{}: {}".format(name, getattr(requester, name)))
finally: finally:
dpdb.close() dps.close()
if __name__ == "__main__": if __name__ == "__main__":
main() main()