forked from M-Labs/artiq
1
0
Fork 0

test/coredevice: add tests for exception sync

This commit is contained in:
abdul124 2024-08-30 14:22:53 +08:00 committed by Sébastien Bourdeauducq
parent bd9648d960
commit 99f76a7595
1 changed files with 9 additions and 8 deletions

View File

@ -3,8 +3,9 @@ import artiq.coredevice.exceptions as exceptions
from artiq.experiment import * from artiq.experiment import *
from artiq.test.hardware_testbench import ExperimentCase from artiq.test.hardware_testbench import ExperimentCase
from artiq.compiler.embedding import EmbeddingMap from artiq.language.embedding_map import EmbeddingMap
from artiq.coredevice.core import test_exception_id_sync from artiq.coredevice.core import test_exception_id_sync
from numpy import int32
""" """
Test sync in exceptions raised between host and kernel Test sync in exceptions raised between host and kernel
@ -16,33 +17,34 @@ Considers the following two cases:
Ensures same exception is raised on both kernel and host in either case Ensures same exception is raised on both kernel and host in either case
""" """
exception_names = EmbeddingMap().str_reverse_map exception_names = EmbeddingMap().string_map
@nac3
class _TestExceptionSync(EnvExperiment): class _TestExceptionSync(EnvExperiment):
def build(self): def build(self):
self.setattr_device("core") self.setattr_device("core")
@rpc @rpc
def _raise_exception_host(self, id): def _raise_exception_host(self, id: int32):
exn = exception_names[id].split('.')[-1].split(':')[-1] exn = exception_names[id].split('.')[-1].split(':')[-1]
exn = getattr(exceptions, exn) exn = getattr(exceptions, exn)
raise exn raise exn
@kernel @kernel
def raise_exception_host(self, id): def raise_exception_host(self, id: int32):
self._raise_exception_host(id) self._raise_exception_host(id)
@kernel @kernel
def raise_exception_kernel(self, id): def raise_exception_kernel(self, id: int32):
test_exception_id_sync(id) test_exception_id_sync(id)
class ExceptionTest(ExperimentCase): class ExceptionTest(ExperimentCase):
def test_raise_exceptions_kernel(self): def test_raise_exceptions_kernel(self):
exp = self.create(_TestExceptionSync) exp = self.create(_TestExceptionSync)
for id, name in list(exception_names.items())[::-1]: for id, name in exception_names.items():
name = name.split('.')[-1].split(':')[-1] name = name.split('.')[-1].split(':')[-1]
with self.assertRaises(getattr(exceptions, name)) as ctx: with self.assertRaises(getattr(exceptions, name)) as ctx:
exp.raise_exception_kernel(id) exp.raise_exception_kernel(id)
@ -56,4 +58,3 @@ class ExceptionTest(ExperimentCase):
name = name.split('.')[-1].split(':')[-1] name = name.split('.')[-1].split(':')[-1]
with self.assertRaises(getattr(exceptions, name)) as ctx: with self.assertRaises(getattr(exceptions, name)) as ctx:
exp.raise_exception_host(id) exp.raise_exception_host(id)