diff options
-rw-r--r-- | gr-blocks/python/blocks/qa_throttle.py | 49 |
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) |