2015-10-12 19:20:04 +08:00
|
|
|
# Copyright (C) 2015 M-Labs Limited
|
2015-09-07 06:08:57 +08:00
|
|
|
# Copyright (C) 2014, 2015 Robert Jordens <jordens@gmail.com>
|
|
|
|
|
2015-06-26 12:19:11 +08:00
|
|
|
import os
|
|
|
|
import sys
|
|
|
|
import unittest
|
|
|
|
import logging
|
2023-04-30 17:16:36 +08:00
|
|
|
from tempfile import TemporaryDirectory
|
2015-06-26 12:19:11 +08:00
|
|
|
|
2015-10-12 19:20:04 +08:00
|
|
|
from artiq.master.databases import DeviceDB, DatasetDB
|
2018-08-09 16:51:12 +08:00
|
|
|
from artiq.master.worker_db import DeviceManager, DatasetManager, DeviceError
|
2015-09-01 12:52:39 +08:00
|
|
|
from artiq.coredevice.core import CompileError
|
2015-07-14 04:08:20 +08:00
|
|
|
from artiq.frontend.artiq_run import DummyScheduler
|
2015-06-26 12:19:11 +08:00
|
|
|
|
|
|
|
|
|
|
|
artiq_root = os.getenv("ARTIQ_ROOT")
|
|
|
|
logger = logging.getLogger(__name__)
|
|
|
|
|
|
|
|
|
|
|
|
@unittest.skipUnless(artiq_root, "no ARTIQ_ROOT")
|
|
|
|
class ExperimentCase(unittest.TestCase):
|
|
|
|
def setUp(self):
|
2023-04-30 17:16:36 +08:00
|
|
|
self.tempdir = TemporaryDirectory(prefix="artiq_hw_test")
|
2017-05-18 23:14:20 +08:00
|
|
|
self.device_db = DeviceDB(os.path.join(artiq_root, "device_db.py"))
|
2016-01-28 05:24:32 +08:00
|
|
|
self.dataset_db = DatasetDB(
|
2023-04-30 17:16:36 +08:00
|
|
|
os.path.join(self.tempdir.name, "dataset_db.mdb"))
|
2016-01-28 05:24:32 +08:00
|
|
|
self.device_mgr = DeviceManager(
|
|
|
|
self.device_db, virtual_devices={"scheduler": DummyScheduler()})
|
2015-10-12 19:20:04 +08:00
|
|
|
self.dataset_mgr = DatasetManager(self.dataset_db)
|
2015-06-26 12:19:11 +08:00
|
|
|
|
2016-02-23 16:00:53 +08:00
|
|
|
def tearDown(self):
|
|
|
|
self.device_mgr.close_devices()
|
2023-04-24 17:34:30 +08:00
|
|
|
self.dataset_db.close_db()
|
2023-04-30 17:16:36 +08:00
|
|
|
self.tempdir.cleanup()
|
2016-02-23 16:00:53 +08:00
|
|
|
|
2016-04-16 19:31:07 +08:00
|
|
|
def create(self, cls, *args, **kwargs):
|
2015-08-28 18:24:57 +08:00
|
|
|
try:
|
2016-04-16 19:31:07 +08:00
|
|
|
exp = cls(
|
2019-03-22 07:09:30 +08:00
|
|
|
(self.device_mgr, self.dataset_mgr, None, {}),
|
2016-04-16 19:31:07 +08:00
|
|
|
*args, **kwargs)
|
2018-08-09 16:51:12 +08:00
|
|
|
except DeviceError as e:
|
2015-08-28 18:24:57 +08:00
|
|
|
# skip if ddb does not match requirements
|
2016-03-10 19:34:06 +08:00
|
|
|
raise unittest.SkipTest(
|
2018-08-09 16:51:12 +08:00
|
|
|
"test device not available: `{}`".format(*e.args))
|
|
|
|
exp.prepare()
|
|
|
|
return exp
|
2015-08-28 18:24:57 +08:00
|
|
|
|
2016-04-16 19:31:07 +08:00
|
|
|
def execute(self, cls, *args, **kwargs):
|
2015-06-26 12:19:11 +08:00
|
|
|
expid = {
|
|
|
|
"file": sys.modules[cls.__module__].__file__,
|
2015-07-15 17:08:12 +08:00
|
|
|
"class_name": cls.__name__,
|
2016-04-16 19:31:07 +08:00
|
|
|
"arguments": dict()
|
2015-06-26 12:19:11 +08:00
|
|
|
}
|
2015-10-12 19:20:04 +08:00
|
|
|
self.device_mgr.virtual_devices["scheduler"].expid = expid
|
2015-06-26 12:19:11 +08:00
|
|
|
try:
|
2016-04-16 19:31:07 +08:00
|
|
|
exp = self.create(cls, *args, **kwargs)
|
2015-06-26 12:19:11 +08:00
|
|
|
exp.run()
|
2023-12-13 14:27:04 +08:00
|
|
|
self.device_mgr.notify_run_end()
|
2015-06-26 12:19:11 +08:00
|
|
|
exp.analyze()
|
2015-07-05 10:05:11 +08:00
|
|
|
return exp
|
2015-09-01 12:52:39 +08:00
|
|
|
except CompileError as error:
|
|
|
|
# Reduce amount of text on terminal.
|
|
|
|
raise error from None
|
2016-03-09 21:34:10 +08:00
|
|
|
except Exception as exn:
|
2016-03-10 00:22:15 +08:00
|
|
|
if hasattr(exn, "artiq_core_exception"):
|
|
|
|
exn.args = "{}\n{}".format(exn.args[0],
|
|
|
|
exn.artiq_core_exception),
|
2016-03-09 21:34:10 +08:00
|
|
|
raise exn
|