summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorMarcus Müller <mmueller@gnuradio.org>2023-12-02 23:42:12 +0100
committerJeff Long <willcode4@gmail.com>2023-12-10 15:05:22 -0500
commit78c56e6db2334348a6bce494a136b1953f568200 (patch)
tree756050e9ee46ffdea20aa41657b5261c84bc0fd6
parentqtgui: Remove unnecessary imports from templates (diff)
downloadgnuradio-78c56e6db2334348a6bce494a136b1953f568200.tar.xz
gnuradio-78c56e6db2334348a6bce494a136b1953f568200.zip
blocks: msq_pair_to_var QA: wait up to 1 s.
Also, fix minor stylistic and include issues Signed-off-by: Marcus Müller <mmueller@gnuradio.org> (cherry picked from commit 2a496672ba8700158fade0b52c6f5d61b0eb4df8) Signed-off-by: Jeff Long <willcode4@gmail.com>
-rwxr-xr-xgr-blocks/python/blocks/qa_msg_pair_to_var.py50
1 files changed, 37 insertions, 13 deletions
diff --git a/gr-blocks/python/blocks/qa_msg_pair_to_var.py b/gr-blocks/python/blocks/qa_msg_pair_to_var.py
index 605160f31..34f788de1 100755
--- a/gr-blocks/python/blocks/qa_msg_pair_to_var.py
+++ b/gr-blocks/python/blocks/qa_msg_pair_to_var.py
@@ -13,12 +13,10 @@ from gnuradio import blocks
from gnuradio import gr_unittest
from gnuradio import gr
import pmt
-import sys
import time
class test_msg_pair_to_var(gr_unittest.TestCase):
-
def setUp(self):
self.backend = gr.dictionary_logger_backend()
gr.logging().add_default_sink(self.backend)
@@ -36,46 +34,72 @@ class test_msg_pair_to_var(gr_unittest.TestCase):
dut = blocks.msg_pair_to_var(test_f)
test_msg = pmt.cons(pmt.intern("foo"), pmt.from_uint64(canary))
- src = blocks.message_strobe(test_msg, 10)
+ src = blocks.message_strobe(test_msg, 50)
self.tb.msg_connect(*(src, pmt.intern("strobe")),
*(dut, blocks.msg_pair_to_var.IN_PORT))
+
+ start_time = time.monotonic_ns()
self.tb.start()
- time.sleep(15e-3)
+
+ # Sleep for at most a second
+ for counter in range(20):
+ time.sleep(50e-3)
+ if self.test_val == canary:
+ break
self.tb.stop()
self.tb.wait()
+ stopped_time = time.monotonic_ns()
+ timecount = round((stopped_time - start_time) * 1e-6)
- self.assertEqual(self.test_val, canary,
- f"Test value {hex(self.test_val)} not found to be canary {hex(canary)}")
+ self.assertEqual(
+ self.test_val,
+ canary,
+ f"Test value {hex(self.test_val)} not found to be canary {hex(canary)} within {timecount} ms",
+ )
def test_exceptions(self):
lark = 0xDEAFBEEF
nightingale = 0xDEAFB16D
- self.test_val = 0
+ self.test_val = False
def test_f(value: int = 0):
if value == nightingale and value != lark:
+ self.test_val = True
raise Exception("It was the nightingale, and not the lark")
dut = blocks.msg_pair_to_var(test_f)
test_msg = pmt.cons(pmt.intern("birb"), pmt.from_uint64(nightingale))
- src = blocks.message_strobe(test_msg, 10)
- self.tb.msg_connect(*(src, pmt.intern("strobe")),
- *(dut, blocks.msg_pair_to_var.IN_PORT))
+ src = blocks.message_strobe(test_msg, 50)
+ self.tb.msg_connect(
+ *(src, pmt.intern("strobe")), *(dut, blocks.msg_pair_to_var.IN_PORT)
+ )
+
+ start_time = time.monotonic_ns()
self.tb.start()
+
+ # Sleep for at most a second
+ for counter in range(19):
+ time.sleep(50e-3)
+ if self.test_val:
+ break
+ # some time for Exception bubbling, which should happen without yields
time.sleep(50e-3)
self.tb.stop()
self.tb.wait()
+ stopped_time = time.monotonic_ns()
+ timecount = round((stopped_time - start_time) * 1e-6)
logged = self.backend.get_map()
- self.assertIn("msg_pair_to_var", logged, "should have logged; didn't.")
+ self.assertIn("msg_pair_to_var", logged, f"should have logged; didn't within {timecount} ms.")
log_entries = logged["msg_pair_to_var"]
for timestamp, entry in log_entries:
self.assertRegex(
entry,
r"Error when calling <function .*\.test_exceptions\..*.test_f.*> with 3736056173" +
r".*reason: It was the nightingale, and not the lark.*",
- f"Log entry '{entry}' from {timestamp} doesn't contain Shakespeare")
+ f"Log entry '{entry}' from {timestamp} doesn't contain Shakespeare",
+ )
-if __name__ == '__main__':
+if __name__ == "__main__":
gr_unittest.run(test_msg_pair_to_var)