Skip to content

Commit

Permalink
analyzer: explicitly delimit messages (with \x1D).
Browse files Browse the repository at this point in the history
Fixes #461.
whitequark authored and sbourdeauducq committed Jun 7, 2016
1 parent 284d726 commit a801035
Showing 3 changed files with 31 additions and 11 deletions.
2 changes: 1 addition & 1 deletion artiq/compiler/transforms/artiq_ir_generator.py
Original file line number Diff line number Diff line change
@@ -1669,7 +1669,7 @@ def body_gen(index):
self.polymorphic_print([self.visit(prefix)],
separator=" ", suffix="\x1E", as_rtio=True)
self.polymorphic_print([self.visit(arg) for arg in args],
separator=" ", suffix="\n", as_rtio=True)
separator=" ", suffix="\n\x1D", as_rtio=True)
return ir.Constant(None, builtins.TNone())
elif types.is_builtin(typ, "now"):
if len(node.args) == 0 and len(node.keywords) == 0:
15 changes: 6 additions & 9 deletions artiq/coredevice/analyzer.py
Original file line number Diff line number Diff line change
@@ -278,11 +278,9 @@ def __init__(self, vcd_manager, vcd_log_channels):

def process_message(self, message):
if isinstance(message, OutputMessage):
message_payload = _extract_log_chars(message.data)
self.current_entry += message_payload
if len(message_payload) < 4:
channel_name, log_message = \
self.current_entry.split(":", maxsplit=1)
self.current_entry += _extract_log_chars(message.data)
if len(self.current_entry) > 1 and self.current_entry[-1] == "\x1D":
channel_name, log_message = self.current_entry[:-1].split("\x1E", maxsplit=1)
vcd_value = ""
for c in log_message:
vcd_value += "{:08b}".format(ord(c))
@@ -296,10 +294,9 @@ def get_vcd_log_channels(log_channel, messages):
for message in messages:
if (isinstance(message, OutputMessage)
and message.channel == log_channel):
message_payload = _extract_log_chars(message.data)
log_entry += message_payload
if len(message_payload) < 4:
channel_name, log_message = log_entry.split("\x1E", maxsplit=1)
log_entry += _extract_log_chars(message.data)
if len(log_entry) > 1 and log_entry[-1] == "\x1D":
channel_name, log_message = log_entry[:-1].split("\x1E", maxsplit=1)
l = len(log_message)
if channel_name in vcd_log_channels:
if vcd_log_channels[channel_name] < l:
25 changes: 24 additions & 1 deletion artiq/test/coredevice/test_analyzer.py
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
from artiq.experiment import *
from artiq.coredevice.analyzer import (decode_dump, StoppedMessage,
OutputMessage, InputMessage)
OutputMessage, InputMessage,
_extract_log_chars)
from artiq.test.hardware_testbench import ExperimentCase


@@ -26,6 +27,15 @@ def run(self):
self.loop_in.count()


class WriteLog(EnvExperiment):
def build(self):
self.setattr_device("core")

@kernel
def run(self):
rtio_log("foo", 32)


class AnalyzerTest(ExperimentCase):
def test_ttl_pulse(self):
comm = self.device_mgr.get("comm")
@@ -50,3 +60,16 @@ def test_ttl_pulse(self):
self.assertAlmostEqual(
abs(input_messages[0].timestamp - input_messages[1].timestamp),
1000, delta=1)

def test_rtio_log(self):
comm = self.device_mgr.get("comm")

exp = self.create(WriteLog)
comm.get_analyzer_dump() # clear analyzer buffer
exp.run()

dump = decode_dump(comm.get_analyzer_dump())
log = "".join([_extract_log_chars(msg.data)
for msg in dump.messages
if isinstance(msg, OutputMessage) and msg.channel == dump.log_channel])
self.assertEqual(log, "foo\x1E32\n\x1D")

0 comments on commit a801035

Please sign in to comment.