forked from M-Labs/artiq
compiler.embedding: add tests for quote serialization.
This commit is contained in:
parent
37811f690b
commit
cbd903a9dc
|
@ -0,0 +1,41 @@
|
||||||
|
from artiq.language import *
|
||||||
|
from artiq.test.hardware_testbench import ExperimentCase
|
||||||
|
|
||||||
|
class Roundtrip(EnvExperiment):
|
||||||
|
def build(self):
|
||||||
|
self.attr_device("core")
|
||||||
|
|
||||||
|
@kernel
|
||||||
|
def roundtrip(self, obj, fn):
|
||||||
|
fn(obj)
|
||||||
|
|
||||||
|
class RoundtripTest(ExperimentCase):
|
||||||
|
def assertRoundtrip(self, obj):
|
||||||
|
exp = self.create(Roundtrip)
|
||||||
|
def callback(objcopy) -> TNone:
|
||||||
|
self.assertEqual(obj, objcopy)
|
||||||
|
exp.roundtrip(obj, callback)
|
||||||
|
|
||||||
|
def test_None(self):
|
||||||
|
self.assertRoundtrip(None)
|
||||||
|
|
||||||
|
def test_bool(self):
|
||||||
|
self.assertRoundtrip(True)
|
||||||
|
self.assertRoundtrip(False)
|
||||||
|
|
||||||
|
def test_int(self):
|
||||||
|
self.assertRoundtrip(42)
|
||||||
|
self.assertRoundtrip(int(42, width=64))
|
||||||
|
|
||||||
|
def test_float(self):
|
||||||
|
self.assertRoundtrip(42.0)
|
||||||
|
|
||||||
|
def test_str(self):
|
||||||
|
self.assertRoundtrip("foo")
|
||||||
|
|
||||||
|
def test_list(self):
|
||||||
|
self.assertRoundtrip([10])
|
||||||
|
|
||||||
|
def test_object(self):
|
||||||
|
obj = object()
|
||||||
|
self.assertRoundtrip(obj)
|
|
@ -37,7 +37,16 @@ class ExperimentCase(unittest.TestCase):
|
||||||
self.pdb = FlatFileDB(os.path.join(artiq_root, "pdb.pyon"))
|
self.pdb = FlatFileDB(os.path.join(artiq_root, "pdb.pyon"))
|
||||||
self.rdb = ResultDB()
|
self.rdb = ResultDB()
|
||||||
|
|
||||||
def execute(self, cls, **kwargs):
|
def create(self, cls, **kwargs):
|
||||||
|
try:
|
||||||
|
exp = cls(self.dmgr, self.pdb, self.rdb, **kwargs)
|
||||||
|
exp.prepare()
|
||||||
|
return exp
|
||||||
|
except KeyError as e:
|
||||||
|
# skip if ddb does not match requirements
|
||||||
|
raise unittest.SkipTest(*e.args)
|
||||||
|
|
||||||
|
def execute(self, cls, *args, **kwargs):
|
||||||
expid = {
|
expid = {
|
||||||
"file": sys.modules[cls.__module__].__file__,
|
"file": sys.modules[cls.__module__].__file__,
|
||||||
"class_name": cls.__name__,
|
"class_name": cls.__name__,
|
||||||
|
@ -45,12 +54,7 @@ class ExperimentCase(unittest.TestCase):
|
||||||
}
|
}
|
||||||
self.dmgr.virtual_devices["scheduler"].expid = expid
|
self.dmgr.virtual_devices["scheduler"].expid = expid
|
||||||
try:
|
try:
|
||||||
try:
|
exp = self.create(cls, **kwargs)
|
||||||
exp = cls(self.dmgr, self.pdb, self.rdb, **kwargs)
|
|
||||||
except KeyError as e:
|
|
||||||
# skip if ddb does not match requirements
|
|
||||||
raise unittest.SkipTest(*e.args)
|
|
||||||
exp.prepare()
|
|
||||||
exp.run()
|
exp.run()
|
||||||
exp.analyze()
|
exp.analyze()
|
||||||
return exp
|
return exp
|
||||||
|
|
Loading…
Reference in New Issue