From 9757127f21ebcede6bdf81b5031945df1aac757b Mon Sep 17 00:00:00 2001
From: Marcus Müller <mueller@kit.edu>
Date: Fri, 28 Jul 2017 11:11:56 +0200
Subject: block python gateway: add WORK_CALLED_PRODUCE/_DONE proxy
MIME-Version: 1.0
Content-Type: text/plain; charset=UTF-8
Content-Transfer-Encoding: 8bit

so that we can then have

    def general_work(self, input_items, output_items):
        …
        self.produce(0,2)
        self.produce(1,1)
        return gr.WORK_CALLED_PRODUCE

Includes a unit test.

We need more unit tests. There wasn't a single general block test in
qa_block_gateway.py.
---
 gr-blocks/python/blocks/qa_block_gateway.py | 25 +++++++++++++++++++++++++
 1 file changed, 25 insertions(+)

(limited to 'gr-blocks/python')

diff --git a/gr-blocks/python/blocks/qa_block_gateway.py b/gr-blocks/python/blocks/qa_block_gateway.py
index 1e848cff04..6fdb0090ae 100644
--- a/gr-blocks/python/blocks/qa_block_gateway.py
+++ b/gr-blocks/python/blocks/qa_block_gateway.py
@@ -25,6 +25,19 @@ import pmt
 
 from gnuradio import gr, gr_unittest, blocks
 
+
+class non_sync_block(gr.basic_block):
+    def __init__(self):
+        gr.basic_block.__init__(self,
+            name="non_sync_block",
+            in_sig=[numpy.float32],
+            out_sig=[numpy.float32, numpy.float32])
+    def general_work(self, input_items, output_items):
+        self.consume(0, len(input_items[0]))
+        self.produce(0,2)
+        self.produce(1,1)
+        return gr.WORK_CALLED_PRODUCE
+
 class add_2_f32_1_f32(gr.sync_block):
     def __init__(self):
         gr.sync_block.__init__(
@@ -275,5 +288,17 @@ class test_block_gateway(gr_unittest.TestCase):
         tb.run()
         self.assertEqual(sink.data(), (1, 2, 3, 4, 5, 6, 7, 8, 9, 10))
 
+    def test_non_sync_block(self):
+        tb = gr.top_block ()
+        src = blocks.vector_source_f(range(1000000))
+        sinks = [blocks.vector_sink_f(), blocks.vector_sink_f()]
+        dut = non_sync_block()
+        tb.connect(src, dut)
+        tb.connect((dut,0), sinks[0])
+        tb.connect((dut,1), sinks[1])
+        tb.run ()
+        self.assertEqual(len(sinks[0].data()), 2*len(sinks[1].data()))
+
+
 if __name__ == '__main__':
     gr_unittest.run(test_block_gateway, "test_block_gateway.xml")
-- 
cgit v1.2.3