summaryrefslogtreecommitdiff
path: root/gr-blocks/python
diff options
context:
space:
mode:
authorClayton Smith <argilo@gmail.com>2020-01-31 21:47:48 -0500
committerMarcus Müller <marcus@hostalia.de>2020-02-04 13:23:17 +0100
commit5b38e99298d47da94e4436d810db550d9e7e4520 (patch)
treece668ac7b3c912b8fa5622cac69bf3340bb3fc87 /gr-blocks/python
parentf46a852dc5fe0992b38916b4613f78290e8c9b14 (diff)
gr-blocks: add tests for throttle
Diffstat (limited to 'gr-blocks/python')
-rw-r--r--gr-blocks/python/blocks/qa_throttle.py49
1 files changed, 45 insertions, 4 deletions
diff --git a/gr-blocks/python/blocks/qa_throttle.py b/gr-blocks/python/blocks/qa_throttle.py
index d86527b380..88495c9cc3 100644
--- a/gr-blocks/python/blocks/qa_throttle.py
+++ b/gr-blocks/python/blocks/qa_throttle.py
@@ -9,8 +9,11 @@
#
+import time
+import pmt
from gnuradio import gr, gr_unittest, blocks
+
class test_throttle(gr_unittest.TestCase):
def setUp(self):
@@ -19,9 +22,47 @@ class test_throttle(gr_unittest.TestCase):
def tearDown(self):
self.tb = None
- def test_01(self):
- # Test that we can make the block
- op = blocks.throttle(gr.sizeof_gr_complex, 1)
+ def test_throttling(self):
+ src_data = (1, 2, 3)
+ src = blocks.vector_source_c(src_data)
+ thr = blocks.throttle(gr.sizeof_gr_complex, 10)
+ dst = blocks.vector_sink_c()
+ self.tb.connect(src, thr, dst)
+
+ start_time = time.perf_counter()
+ self.tb.run()
+ end_time = time.perf_counter()
+
+ total_time = end_time - start_time
+ self.assertGreater(total_time, 0.3)
+ self.assertLess(total_time, 0.4)
+
+ dst_data = dst.data()
+ self.assertEqual(src_data, dst_data)
+
+ def test_rx_rate_tag(self):
+ src_data = (1, 2, 3, 4, 5, 6)
+ tag = gr.tag_t()
+ tag.key = pmt.string_to_symbol("rx_rate")
+ tag.value = pmt.to_pmt(20)
+ tag.offset = 0
+
+ src = blocks.vector_source_c(src_data, tags=(tag,))
+ thr = blocks.throttle(gr.sizeof_gr_complex, 10, ignore_tags=False)
+ dst = blocks.vector_sink_c()
+ self.tb.connect(src, thr, dst)
+
+ start_time = time.perf_counter()
+ self.tb.run()
+ end_time = time.perf_counter()
+
+ total_time = end_time - start_time
+ self.assertGreater(total_time, 0.3)
+ self.assertLess(total_time, 0.4)
+
+ dst_data = dst.data()
+ self.assertEqual(src_data, dst_data)
+
if __name__ == '__main__':
- gr_unittest.run(test_throttle, "test_throttle.xml")
+ gr_unittest.run(test_throttle)