Skip to content

Commit

Permalink
Add CI and documentation for exceptions
Browse files Browse the repository at this point in the history
Signed-off-by: Egor Savkin <es@m-labs.hk>
  • Loading branch information
thomasfire committed Sep 29, 2023
1 parent da0542f commit 732707c
Show file tree
Hide file tree
Showing 5 changed files with 22 additions and 12 deletions.
4 changes: 2 additions & 2 deletions artiq/coredevice/comm_kernel.py
Original file line number Diff line number Diff line change
Expand Up @@ -688,9 +688,9 @@ def read_exception_string():

try:
message = nested_exceptions[0][1].format(*nested_exceptions[0][2])
except Exception as ex:
except:
message = nested_exceptions[0][1]
logger.error("Couldn't format exception message `{}`: {}: {}".format(message, type(ex).__name__, str(ex)))
logger.error("Couldn't format exception message", exc_info=True)

try:
python_exn = python_exn_type(message)
Expand Down
7 changes: 6 additions & 1 deletion artiq/coredevice/exceptions.py
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,12 @@


class CoreException:
"""Information about an exception raised or passed through the core device."""
"""Information about an exception raised or passed through the core device.
If the exception message contains positional format arguments, it
will attempt to substitute them with the provided parameters.
If the substitution fails, the original message will remain unchanged.
"""
def __init__(self, exceptions, exception_info, traceback, stack_pointers):
self.exceptions = exceptions
self.exception_info = exception_info
Expand Down
Binary file removed artiq/examples/kc705_nist_clock/device_map.bin
Binary file not shown.
15 changes: 8 additions & 7 deletions artiq/test/coredevice/test_exceptions.py
Original file line number Diff line number Diff line change
@@ -1,4 +1,3 @@
import logging
import re

from artiq.experiment import *
Expand Down Expand Up @@ -54,7 +53,6 @@ def build(self):
except DeviceError:
self.led = self.get_device("led0")


@kernel
def run(self):
self.core.reset()
Expand All @@ -68,8 +66,9 @@ def test_custom_formatted_kernel_exception(self):
with self.assertLogs() as captured:
with self.assertRaisesRegex(CustomException, r"CustomException\(\d+\): \{foo\}"):
self.execute(KernelFmtException)
self.assertEqual(captured.output, [
"ERROR:artiq.coredevice.comm_kernel:Couldn't format exception message `{foo}`: KeyError: 'foo'"])
captured_lines = captured.output[0].split('\n')
self.assertEqual([captured_lines[0], captured_lines[-1]],
["ERROR:artiq.coredevice.comm_kernel:Couldn't format exception message", "KeyError: 'foo'"])

def test_nested_formatted_kernel_exception(self):
with self.assertLogs() as captured:
Expand All @@ -78,8 +77,9 @@ def test_nested_formatted_kernel_exception(self):
r"CustomException\(\d+\): \{foo\}.*?RTIOUnderflow\(\d+\): \{bar\}.*?RTIOOverflow\(\d+\): \{bizz\}.*?RTIOUnderflow\(\d+\): \{buzz\}",
re.DOTALL)):
self.execute(KernelNestedFmtException)
self.assertEqual(captured.output, [
"ERROR:artiq.coredevice.comm_kernel:Couldn't format exception message `{foo}`: KeyError: 'foo'"])
captured_lines = captured.output[0].split('\n')
self.assertEqual([captured_lines[0], captured_lines[-1]],
["ERROR:artiq.coredevice.comm_kernel:Couldn't format exception message", "KeyError: 'foo'"])

def test_rtio_underflow(self):
with self.assertLogs() as captured:
Expand All @@ -88,4 +88,5 @@ def test_rtio_underflow(self):
r"RTIO underflow at channel 0x\d+?:led\d*?, \d+? mu, slack -\d+? mu.*?RTIOUnderflow\(\d+\): RTIO underflow at channel 0x\d+?:led\d+?, \d+? mu, slack -\d+? mu",
re.DOTALL)):
self.execute(KernelRTIOUnderflow)
self.assertEqual(captured.output, ["WARNING:artiq.coredevice.comm_kernel:sequence error(s) reported during kernel execution"])
self.assertEqual(captured.output[0].split('\n')[0],
"WARNING:artiq.coredevice.comm_kernel:sequence error(s) reported during kernel execution")
8 changes: 6 additions & 2 deletions flake.nix
Original file line number Diff line number Diff line change
Expand Up @@ -521,11 +521,15 @@
# Read "Ok" line when remote successfully locked
read LOCK_OK
export ARTIQ_ROOT=`python -c "import artiq; print(artiq.__path__[0])"`/examples/kc705_nist_clock
export ARTIQ_LOW_LATENCY=1
artiq_rtiomap --device-db $ARTIQ_ROOT/device_db.py device_map.bin
artiq_mkfs -s ip `python -c "import artiq.examples.kc705_nist_clock.device_db as ddb; print(ddb.core_addr)"`/24 -f device_map device_map.bin kc705_nist_clock.config
artiq_flash -t kc705 -H rpi-1 storage -f kc705_nist_clock.config
artiq_flash -t kc705 -H rpi-1 -d ${packages.x86_64-linux.artiq-board-kc705-nist_clock}
sleep 30
export ARTIQ_ROOT=`python -c "import artiq; print(artiq.__path__[0])"`/examples/kc705_nist_clock
export ARTIQ_LOW_LATENCY=1
python -m unittest discover -v artiq.test.coredevice
)
Expand Down

0 comments on commit 732707c

Please sign in to comment.