Commit 522441ae authored by Dimitris Lampridis's avatar Dimitris Lampridis

tst: improve the HMQ multi sync test

This modification makes sure that all device handles (to the same MT
devid) are opened at the start of the test and kept open for the
duration of the test. This allows catching race conditions between the
read/write pointers in the HMQ buffers (because the read pointer is
initialised to the value of the write pointer when the device handle is
first acquired, so the sooner we open it, the more such errors we will
detect).
parent 2659646e
......@@ -32,10 +32,8 @@ def trtl_binary_hmq_sync(trtl_firmware_dir):
"firmware/hmq-sync/fw-hmq-sync.bin")
def do_sync_mult(q, hmq_orig, msg):
def do_sync_mult(q, hmq, msg):
try:
dev = PyMockTurtle.TrtlDevice(hmq_orig.trtl_dev.device_id)
hmq = dev.cpu[hmq_orig.idx_cpu].hmq[hmq_orig.idx_hmq]
q.put(hmq.sync_msg(msg))
except Exception as e:
print(e)
......@@ -172,14 +170,19 @@ class TestHmq(object):
trtl_cpu.load_application_file(trtl_binary_hmq_sync)
trtl_cpu.enable()
for hmq in trtl_cpu.hmq:
for hmq_orig in trtl_cpu.hmq:
proc = []
sb = hmq.get_stats()
sb = hmq_orig.get_stats()
for msg in trtl_msg:
# Create separate handle/user for each process
dev = PyMockTurtle.TrtlDevice(hmq_orig.trtl_dev.device_id)
hmq = dev.cpu[hmq_orig.idx_cpu].hmq[hmq_orig.idx_hmq]
q = multiprocessing.Queue()
p = multiprocessing.Process(target=do_sync_mult,
args=(q, hmq, msg))
proc.append((q, p, msg))
# Only start once all handles are open
for q, p, msg in proc:
p.start()
for q, p, msg in proc:
msg_r = q.get()
......@@ -192,7 +195,7 @@ class TestHmq(object):
assert msg_r.header.flags == PyMockTurtle.TrtlHmqHeader.TRTL_HMQ_HEADER_FLAG_ACK
for v1, v2 in zip(msg.payload, msg_r.payload):
assert v1 == v2
sa = hmq.get_stats()
sa = hmq_orig.get_stats()
assert sa["message_sent"] - sb["message_sent"] == len(trtl_msg)
assert sa["message_received"] - sb["message_received"] == len(trtl_msg)
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment