From 31b52ff1b3fc5072bc7edb651a79cfa73b66370c Mon Sep 17 00:00:00 2001 From: whitequark Date: Sun, 25 Jun 2017 04:47:32 +0000 Subject: [PATCH] coredevice: do not desync kernel TCP stream on RPCReturnValueError. And propagate the error upwards instead of trying to squeeze it through the core device in futility. --- artiq/coredevice/comm_kernel.py | 2 ++ artiq/test/coredevice/test_embedding.py | 33 +++++++++++++++++++++---- 2 files changed, 30 insertions(+), 5 deletions(-) diff --git a/artiq/coredevice/comm_kernel.py b/artiq/coredevice/comm_kernel.py index 9165b0062..2731ffd4d 100644 --- a/artiq/coredevice/comm_kernel.py +++ b/artiq/coredevice/comm_kernel.py @@ -524,6 +524,8 @@ class CommKernel: self._write_header(_H2DMsgType.RPC_REPLY) self._write_bytes(return_tags) self._send_rpc_value(bytearray(return_tags), result, result, service) + except RPCReturnValueError as exn: + raise except Exception as exn: logger.debug("rpc service: %d %r %r ! %r", service_id, args, kwargs, exn) diff --git a/artiq/test/coredevice/test_embedding.py b/artiq/test/coredevice/test_embedding.py index bf692311b..fa1102158 100644 --- a/artiq/test/coredevice/test_embedding.py +++ b/artiq/test/coredevice/test_embedding.py @@ -3,6 +3,7 @@ from time import sleep from artiq.experiment import * from artiq.test.hardware_testbench import ExperimentCase +from artiq.coredevice.comm_kernel import RPCReturnValueError class _Roundtrip(EnvExperiment): @@ -96,6 +97,12 @@ class _RPCTypes(EnvExperiment): def return_str(self) -> TStr: return "foo" + def return_bytes(self) -> TBytes: + return b"foo" + + def return_bytearray(self) -> TByteArray: + return bytearray(b"foo") + def return_tuple(self) -> TTuple([TInt32, TInt32]): return (1, 2) @@ -105,6 +112,9 @@ class _RPCTypes(EnvExperiment): def return_range(self) -> TRange32: return range(10) + def return_mismatch(self): + return b"foo" + @kernel def run_recv(self): core_log(self.return_bool()) @@ -112,6 +122,8 @@ class _RPCTypes(EnvExperiment): core_log(self.return_int64()) core_log(self.return_float()) core_log(self.return_str()) + core_log(self.return_bytes()) + core_log(self.return_bytearray()) core_log(self.return_tuple()) core_log(self.return_list()) core_log(self.return_range()) @@ -126,20 +138,31 @@ class _RPCTypes(EnvExperiment): self.accept(0x100000000) self.accept(1.0) self.accept("foo") + self.accept(b"foo") + self.accept(bytearray(b"foo")) self.accept((2, 3)) self.accept([1, 2]) self.accept(range(10)) self.accept(self) - def run(self): - self.run_send() - self.run_recv() + @kernel + def run_mismatch(self): + self.return_mismatch() class RPCTypesTest(ExperimentCase): - def test_args(self): + def test_send(self): exp = self.create(_RPCTypes) - exp.run() + exp.run_send() + + def test_recv(self): + exp = self.create(_RPCTypes) + exp.run_send() + + def test_mismatch(self): + exp = self.create(_RPCTypes) + with self.assertRaises(RPCReturnValueError): + exp.run_mismatch() class _RPCCalls(EnvExperiment):